diff options
author | Miloslav Trmač <mitr@redhat.com> | 2010-07-24 02:36:48 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2010-07-24 04:25:24 +0200 |
commit | 6962f9b991bd1c47d1e501e19875372d0301ca53 (patch) | |
tree | 13d68a3b8554d2c62d9ca69ebb90c7cacbd65291 | |
parent | 82c206a8e9d16e439c64d9afbf5afabd9ed1f0ce (diff) | |
download | cryptodev-linux-6962f9b991bd1c47d1e501e19875372d0301ca53.tar.gz cryptodev-linux-6962f9b991bd1c47d1e501e19875372d0301ca53.tar.xz cryptodev-linux-6962f9b991bd1c47d1e501e19875372d0301ca53.zip |
Use algo_properties_st in pkcs_1_oaep_encode
-rw-r--r-- | libtomcrypt/headers/tomcrypt_pkcs.h | 4 | ||||
-rw-r--r-- | libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c | 16 | ||||
-rw-r--r-- | libtomcrypt/pk/rsa/rsa_encrypt_key.c | 4 |
3 files changed, 13 insertions, 11 deletions
diff --git a/libtomcrypt/headers/tomcrypt_pkcs.h b/libtomcrypt/headers/tomcrypt_pkcs.h index 8e43942..9cfa81d 100644 --- a/libtomcrypt/headers/tomcrypt_pkcs.h +++ b/libtomcrypt/headers/tomcrypt_pkcs.h @@ -3,6 +3,8 @@ /* ===> LTC_PKCS #1 -- RSA Cryptography <=== */ #ifdef LTC_PKCS_1 +struct algo_properties_st; + enum ltc_pkcs_1_v1_5_blocks { LTC_LTC_PKCS_1_EMSA = 1, /* Block type 1 (LTC_PKCS #1 v1.5 signature padding) */ @@ -42,7 +44,7 @@ int pkcs_1_v1_5_decode(const unsigned char *msg, /* *** v2.1 padding */ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, const unsigned char *lparam, unsigned long lparamlen, - unsigned long modulus_bitlen, int hash_idx, + unsigned long modulus_bitlen, const struct algo_properties_st *hash, unsigned char *out, unsigned long *outlen); int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen, diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c index ccee5cf..46dc91e 100644 --- a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c +++ b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c @@ -25,14 +25,14 @@ @param lparam A session or system parameter (can be NULL) @param lparamlen The length of the lparam data @param modulus_bitlen The bit length of the RSA modulus - @param hash_idx The index of the hash desired + @param hash The desired hash @param out [out] The destination for the encoded data @param outlen [in/out] The max size and resulting size of the encoded data @return CRYPT_OK if successful */ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, const unsigned char *lparam, unsigned long lparamlen, - unsigned long modulus_bitlen, int hash_idx, + unsigned long modulus_bitlen, const struct algo_properties_st *hash, unsigned char *out, unsigned long *outlen) { unsigned char *DB, *seed, *mask; @@ -44,11 +44,11 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, LTC_ARGCHK(outlen != NULL); /* test valid hash */ - if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { + if ((err = hash_is_valid(hash->algo)) != CRYPT_OK) { return err; } - hLen = _ncr_algo_digest_size(hash_idx); + hLen = _ncr_algo_digest_size(hash->algo); modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0); /* test message size */ @@ -77,12 +77,12 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, /* DB == lhash || PS || 0x01 || M, PS == k - mlen - 2hlen - 2 zeroes */ x = modulus_len; if (lparam != NULL) { - if ((err = hash_memory(hash_idx, lparam, lparamlen, DB, &x)) != CRYPT_OK) { + if ((err = hash_memory(hash->algo, lparam, lparamlen, DB, &x)) != CRYPT_OK) { goto LBL_ERR; } } else { /* can't pass hash_memory a NULL so use DB with zero length */ - if ((err = hash_memory(hash_idx, DB, 0, DB, &x)) != CRYPT_OK) { + if ((err = hash_memory(hash->algo, DB, 0, DB, &x)) != CRYPT_OK) { goto LBL_ERR; } } @@ -104,7 +104,7 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, get_random_bytes(seed, hLen); /* compute MGF1 of seed (k - hlen - 1) */ - if ((err = pkcs_1_mgf1(hash_idx, seed, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) { + if ((err = pkcs_1_mgf1(hash->algo, seed, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) { goto LBL_ERR; } @@ -114,7 +114,7 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen, } /* compute MGF1 of maskedDB (hLen) */ - if ((err = pkcs_1_mgf1(hash_idx, DB, modulus_len - hLen - 1, mask, hLen)) != CRYPT_OK) { + if ((err = pkcs_1_mgf1(hash->algo, DB, modulus_len - hLen - 1, mask, hLen)) != CRYPT_OK) { goto LBL_ERR; } diff --git a/libtomcrypt/pk/rsa/rsa_encrypt_key.c b/libtomcrypt/pk/rsa/rsa_encrypt_key.c index 9e4573b..9fea75a 100644 --- a/libtomcrypt/pk/rsa/rsa_encrypt_key.c +++ b/libtomcrypt/pk/rsa/rsa_encrypt_key.c @@ -71,8 +71,8 @@ int rsa_encrypt_key_ex(const unsigned char *in, unsigned long inlen, /* OAEP pad the key */ x = *outlen; if ((err = pkcs_1_oaep_encode(in, inlen, lparam, - lparamlen, modulus_bitlen, hash->algo, - out, &x)) != CRYPT_OK) { + lparamlen, modulus_bitlen, hash, + out, &x)) != CRYPT_OK) { return err; } } else { |