summaryrefslogtreecommitdiffstats
path: root/libtomcrypt/pk/pkcs1
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-07-24 11:54:02 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-24 11:54:02 +0200
commit951eda087f418c2a5ced189fa9d64c8616634dd0 (patch)
tree72050e803bfce0e4c8454011078f10435bb66f04 /libtomcrypt/pk/pkcs1
parentc13723d4a2a9627f4cd85d47954ab1fd3a115dbd (diff)
downloadcryptodev-linux-951eda087f418c2a5ced189fa9d64c8616634dd0.tar.gz
cryptodev-linux-951eda087f418c2a5ced189fa9d64c8616634dd0.tar.xz
cryptodev-linux-951eda087f418c2a5ced189fa9d64c8616634dd0.zip
Use of algo_properties to avoid linear search on a table for each property.
Diffstat (limited to 'libtomcrypt/pk/pkcs1')
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c10
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c16
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c16
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c12
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c12
5 files changed, 33 insertions, 33 deletions
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c b/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
index 01fe231..b09dd11 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
@@ -22,12 +22,12 @@
Perform LTC_PKCS #1 MGF1 (internal)
@param seed The seed for MGF1
@param seedlen The length of the seed
- @param hash_idx The index of the hash desired
+ @param hash The desired hash
@param mask [out] The destination
@param masklen The length of the mask desired
@return CRYPT_OK if successful
*/
-int pkcs_1_mgf1(int hash_idx,
+int pkcs_1_mgf1(const struct algo_properties_st *hash,
const unsigned char *seed, unsigned long seedlen,
unsigned char *mask, unsigned long masklen)
{
@@ -40,12 +40,12 @@ int pkcs_1_mgf1(int hash_idx,
LTC_ARGCHK(mask != NULL);
/* ensure valid hash */
- if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+ if ((err = hash_is_valid(hash)) != CRYPT_OK) {
return err;
}
/* get hash output size */
- hLen = _ncr_algo_digest_size(hash_idx);
+ hLen = hash->digest_size;
/* allocate memory */
buf = XMALLOC(hLen);
@@ -61,7 +61,7 @@ int pkcs_1_mgf1(int hash_idx,
STORE32H(counter, buf);
++counter;
- err = hash_memory_multi(hash_idx, buf, &hLen, seed, seedlen, buf, (unsigned long) 4, NULL, 0);
+ err = hash_memory_multi(hash, buf, &hLen, seed, seedlen, buf, (unsigned long) 4, NULL, 0);
if (err != CRYPT_OK) {
goto LBL_ERR;
}
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
index 4114c56..60f76a0 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
@@ -25,7 +25,7 @@
@param lparam The session or system data (can be NULL)
@param lparamlen The length of the lparam
@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] Destination of decoding
@param outlen [in/out] The max size and resulting size of the decoding
@param res [out] Result of decoding, 1==valid, 0==invalid
@@ -33,7 +33,7 @@
*/
int pkcs_1_oaep_decode(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 *res)
{
@@ -50,11 +50,11 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
*res = 0;
/* test valid hash */
- if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
+ if ((err = hash_is_valid(hash)) != CRYPT_OK) {
return err;
}
- hLen = _ncr_algo_digest_size(hash_idx);
+ hLen = hash->digest_size;
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
/* test hash/message size */
@@ -103,7 +103,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
x += modulus_len - hLen - 1;
/* 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, DB, modulus_len - hLen - 1, mask, hLen)) != CRYPT_OK) {
goto LBL_ERR;
}
@@ -113,7 +113,7 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
}
/* 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, seed, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
goto LBL_ERR;
}
@@ -127,12 +127,12 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
/* compute lhash and store it in seed [reuse temps!] */
x = modulus_len;
if (lparam != NULL) {
- if ((err = hash_memory(hash_idx, lparam, lparamlen, seed, &x)) != CRYPT_OK) {
+ if ((err = hash_memory(hash, lparam, lparamlen, seed, &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, seed, &x)) != CRYPT_OK) {
+ if ((err = hash_memory(hash, DB, 0, seed, &x)) != CRYPT_OK) {
goto LBL_ERR;
}
}
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c
index ccee5cf..c56e3b1 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)) != CRYPT_OK) {
return err;
}
- hLen = _ncr_algo_digest_size(hash_idx);
+ hLen = hash->digest_size;
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, 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, 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, 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, DB, modulus_len - hLen - 1, mask, hLen)) != CRYPT_OK) {
goto LBL_ERR;
}
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c b/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
index 5a26654..293d84f 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
@@ -25,14 +25,14 @@
@param sig The signature data (encoded data)
@param siglen The length of the signature data (octets)
@param saltlen The length of the salt used (octets)
- @param hash_idx The index of the hash desired
+ @param hash_algo The desired hash
@param modulus_bitlen The bit length of the RSA modulus
@param res [out] The result of the comparison, 1==valid, 0==invalid
@return CRYPT_OK if successful (even if the comparison failed)
*/
int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
const unsigned char *sig, unsigned long siglen,
- unsigned long saltlen, int hash_idx,
+ unsigned long saltlen, const struct algo_properties_st *hash_algo,
unsigned long modulus_bitlen, int *res)
{
unsigned char *DB, *mask, *salt, *hash;
@@ -46,11 +46,11 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
*res = 0;
/* ensure hash is valid */
- 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 = hash_algo->digest_size;
modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
/* check sizes */
@@ -102,7 +102,7 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
}
/* generate mask of length modulus_len - hLen - 1 from hash */
- if ((err = pkcs_1_mgf1(hash_idx, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+ if ((err = pkcs_1_mgf1(hash_algo, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
goto LBL_ERR;
}
@@ -131,7 +131,7 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
}
/* M = (eight) 0x00 || msghash || salt, mask = H(M) */
- err = hash_memory_multi(hash_idx, mask, &hLen, mask, 8, msghash, (unsigned long)msghashlen, DB+x, (unsigned long)saltlen, NULL, 0);
+ err = hash_memory_multi(hash_algo, mask, &hLen, mask, 8, msghash, (unsigned long)msghashlen, DB+x, (unsigned long)saltlen, NULL, 0);
if (err != CRYPT_OK) {
goto LBL_ERR;
}
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c b/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c
index 382820d..d747b49 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c
@@ -23,14 +23,14 @@
@param msghash The hash to encode
@param msghashlen The length of the hash (octets)
@param saltlen The length of the salt desired (octets)
- @param hash_idx The index of the hash desired
+ @param hash_algo The desired hash
@param modulus_bitlen The bit length of the RSA modulus
@param out [out] The destination of the encoding
@param outlen [in/out] The max size and resulting size of the encoded data
@return CRYPT_OK if successful
*/
int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
- unsigned long saltlen, int hash_idx,
+ unsigned long saltlen, const struct algo_properties_st *hash_algo,
unsigned long modulus_bitlen,
unsigned char *out, unsigned long *outlen)
{
@@ -43,11 +43,11 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
LTC_ARGCHK(outlen != NULL);
/* ensure hash and PRNG are valid */
- 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 = hash_algo->digest_size;
modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
/* check sizes */
@@ -83,7 +83,7 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
}
/* M = (eight) 0x00 || msghash || salt, hash = H(M) */
- err = hash_memory_multi(hash_idx, hash, &hLen, DB, 8, msghash, (unsigned long)msghashlen, salt, (unsigned long)saltlen, NULL, 0);
+ err = hash_memory_multi(hash_algo, hash, &hLen, DB, 8, msghash, (unsigned long)msghashlen, salt, (unsigned long)saltlen, NULL, 0);
if (err != CRYPT_OK) {
goto LBL_ERR;
}
@@ -97,7 +97,7 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
x += saltlen;
/* generate mask of length modulus_len - hLen - 1 from hash */
- if ((err = pkcs_1_mgf1(hash_idx, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
+ if ((err = pkcs_1_mgf1(hash_algo, hash, hLen, mask, modulus_len - hLen - 1)) != CRYPT_OK) {
goto LBL_ERR;
}