Added support for different encryption schemes to private/public keys

This commit is contained in:
Martin Willi
2010-08-10 18:46:30 +02:00
parent 3547a9b87d
commit 33ddaaabec
19 changed files with 100 additions and 24 deletions
@@ -314,11 +314,18 @@ METHOD(private_key_t, sign, bool,
}
METHOD(private_key_t, decrypt, bool,
private_gmp_rsa_private_key_t *this, chunk_t crypto, chunk_t *plain)
private_gmp_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
{
chunk_t em, stripped;
bool success = FALSE;
if (scheme != ENCRYPT_RSA_PKCS1)
{
DBG1(DBG_LIB, "encryption scheme %N not supported",
encryption_scheme_names, scheme);
return FALSE;
}
/* rsa decryption using PKCS#1 RSADP */
stripped = em = rsadp(this, crypto);
@@ -309,20 +309,20 @@ METHOD(public_key_t, verify, bool,
#define MIN_PS_PADDING 8
METHOD(public_key_t, encrypt_, bool,
private_gmp_rsa_public_key_t *this, chunk_t plain, chunk_t *crypto)
private_gmp_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
{
chunk_t em;
u_char *pos;
int padding, i;
rng_t *rng;
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
if (rng == NULL)
if (scheme != ENCRYPT_RSA_PKCS1)
{
DBG1(DBG_LIB, "no random generator available");
DBG1(DBG_LIB, "encryption scheme %N not supported",
encryption_scheme_names, scheme);
return FALSE;
}
/* number of pseudo-random padding octets */
padding = this->k - plain.len - 3;
if (padding < MIN_PS_PADDING)
@@ -331,6 +331,12 @@ METHOD(public_key_t, encrypt_, bool,
MIN_PS_PADDING);
return FALSE;
}
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
if (rng == NULL)
{
DBG1(DBG_LIB, "no random generator available");
return FALSE;
}
/* padding according to PKCS#1 7.2.1 (RSAES-PKCS1-v1.5-ENCRYPT) */
DBG2(DBG_LIB, "padding %u bytes of data to the rsa modulus size of"