summaryrefslogtreecommitdiffstats
path: root/libtomcrypt/pk/pkcs1
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 10:40:37 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-07-07 10:41:04 +0200
commit115f165b6e3bb74f45e13a65c5f4f82f28664a2c (patch)
treeec55b63c736b5bef6061202c8bd31b08796fa2dc /libtomcrypt/pk/pkcs1
parent58a20b797e5a987fc8f7c5bea3be24d754908bf5 (diff)
downloadcryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.tar.gz
cryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.tar.xz
cryptodev-linux-115f165b6e3bb74f45e13a65c5f4f82f28664a2c.zip
Added a modified libtomcrypt with DSA and RSA algorithms.
Diffstat (limited to 'libtomcrypt/pk/pkcs1')
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c28
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c4
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c3
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c20
-rw-r--r--libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c20
5 files changed, 18 insertions, 57 deletions
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c b/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
index 1ae57bb..01fe231 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_mgf1.c
@@ -9,6 +9,7 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
+#include <ncr_int.h>
/**
@file pkcs_1_mgf1.c
@@ -33,7 +34,6 @@ int pkcs_1_mgf1(int hash_idx,
unsigned long hLen, x;
ulong32 counter;
int err;
- hash_state *md;
unsigned char *buf;
LTC_ARGCHK(seed != NULL);
@@ -45,18 +45,11 @@ int pkcs_1_mgf1(int hash_idx,
}
/* get hash output size */
- hLen = hash_descriptor[hash_idx].hashsize;
+ hLen = _ncr_algo_digest_size(hash_idx);
/* allocate memory */
- md = XMALLOC(sizeof(hash_state));
buf = XMALLOC(hLen);
- if (md == NULL || buf == NULL) {
- if (md != NULL) {
- XFREE(md);
- }
- if (buf != NULL) {
- XFREE(buf);
- }
+ if (buf == NULL) {
return CRYPT_MEM;
}
@@ -68,17 +61,8 @@ int pkcs_1_mgf1(int hash_idx,
STORE32H(counter, buf);
++counter;
- /* get hash of seed || counter */
- if ((err = hash_descriptor[hash_idx].init(md)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(md, seed, seedlen)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(md, buf, 4)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].done(md, buf)) != CRYPT_OK) {
+ err = hash_memory_multi(hash_idx, buf, &hLen, seed, seedlen, buf, (unsigned long) 4, NULL, 0);
+ if (err != CRYPT_OK) {
goto LBL_ERR;
}
@@ -92,11 +76,9 @@ int pkcs_1_mgf1(int hash_idx,
LBL_ERR:
#ifdef LTC_CLEAN_STACK
zeromem(buf, hLen);
- zeromem(md, sizeof(hash_state));
#endif
XFREE(buf);
- XFREE(md);
return err;
}
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
index cbed794..4114c56 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.c
@@ -9,6 +9,7 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
+#include <ncr_int.h>
/**
@file pkcs_1_oaep_decode.c
@@ -52,7 +53,8 @@ int pkcs_1_oaep_decode(const unsigned char *msg, unsigned long msglen,
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
return err;
}
- hLen = hash_descriptor[hash_idx].hashsize;
+
+ hLen = _ncr_algo_digest_size(hash_idx);
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
/* test hash/message size */
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c
index 795a71f..ccee5cf 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.c
@@ -9,6 +9,7 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
+#include <ncr_int.h>
/**
@file pkcs_1_oaep_encode.c
@@ -47,7 +48,7 @@ int pkcs_1_oaep_encode(const unsigned char *msg, unsigned long msglen,
return err;
}
- hLen = hash_descriptor[hash_idx].hashsize;
+ hLen = _ncr_algo_digest_size(hash_idx);
modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
/* test message size */
diff --git a/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c b/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
index 7ca284c..5a26654 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.c
@@ -9,6 +9,7 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
+#include <ncr_int.h>
/**
@file pkcs_1_pss_decode.c
@@ -37,7 +38,6 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
unsigned char *DB, *mask, *salt, *hash;
unsigned long x, y, hLen, modulus_len;
int err;
- hash_state md;
LTC_ARGCHK(msghash != NULL);
LTC_ARGCHK(res != NULL);
@@ -50,7 +50,7 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
return err;
}
- hLen = hash_descriptor[hash_idx].hashsize;
+ hLen = _ncr_algo_digest_size(hash_idx);
modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
/* check sizes */
@@ -131,20 +131,8 @@ int pkcs_1_pss_decode(const unsigned char *msghash, unsigned long msghashlen,
}
/* M = (eight) 0x00 || msghash || salt, mask = H(M) */
- if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- zeromem(mask, 8);
- if ((err = hash_descriptor[hash_idx].process(&md, mask, 8)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(&md, DB+x, saltlen)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].done(&md, mask)) != CRYPT_OK) {
+ err = hash_memory_multi(hash_idx, 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 7eaa307..382820d 100644
--- a/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c
+++ b/libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.c
@@ -9,6 +9,7 @@
* Tom St Denis, tomstdenis@gmail.com, http://libtom.org
*/
#include "tomcrypt.h"
+#include <ncr_int.h>
/**
@file pkcs_1_pss_encode.c
@@ -36,7 +37,6 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
unsigned char *DB, *mask, *salt, *hash;
unsigned long x, y, hLen, modulus_len;
int err;
- hash_state md;
LTC_ARGCHK(msghash != NULL);
LTC_ARGCHK(out != NULL);
@@ -47,7 +47,7 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
return err;
}
- hLen = hash_descriptor[hash_idx].hashsize;
+ hLen = _ncr_algo_digest_size(hash_idx);
modulus_len = (modulus_bitlen>>3) + (modulus_bitlen & 7 ? 1 : 0);
/* check sizes */
@@ -83,20 +83,8 @@ int pkcs_1_pss_encode(const unsigned char *msghash, unsigned long msghashlen,
}
/* M = (eight) 0x00 || msghash || salt, hash = H(M) */
- if ((err = hash_descriptor[hash_idx].init(&md)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- zeromem(DB, 8);
- if ((err = hash_descriptor[hash_idx].process(&md, DB, 8)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(&md, msghash, msghashlen)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].process(&md, salt, saltlen)) != CRYPT_OK) {
- goto LBL_ERR;
- }
- if ((err = hash_descriptor[hash_idx].done(&md, hash)) != CRYPT_OK) {
+ err = hash_memory_multi(hash_idx, hash, &hLen, DB, 8, msghash, (unsigned long)msghashlen, salt, (unsigned long)saltlen, NULL, 0);
+ if (err != CRYPT_OK) {
goto LBL_ERR;
}