summaryrefslogtreecommitdiffstats
path: root/libtomcrypt/pk/asn1/der
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/asn1/der
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/asn1/der')
-rw-r--r--libtomcrypt/pk/asn1/der/integer/der_decode_integer.c10
-rw-r--r--libtomcrypt/pk/asn1/der/integer/der_encode_integer.c14
-rw-r--r--libtomcrypt/pk/asn1/der/integer/der_length_integer.c2
-rw-r--r--libtomcrypt/pk/asn1/der/sequence/der_decode_sequence_flexi.c13
-rw-r--r--libtomcrypt/pk/asn1/der/sequence/der_sequence_free.c4
5 files changed, 25 insertions, 18 deletions
diff --git a/libtomcrypt/pk/asn1/der/integer/der_decode_integer.c b/libtomcrypt/pk/asn1/der/integer/der_decode_integer.c
index 328280d..d7b13cf 100644
--- a/libtomcrypt/pk/asn1/der/integer/der_decode_integer.c
+++ b/libtomcrypt/pk/asn1/der/integer/der_decode_integer.c
@@ -25,7 +25,7 @@
@param num The first mp_int to decode
@return CRYPT_OK if successful
*/
-int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num)
+int der_decode_integer(const unsigned char *in, unsigned long inlen, mp_int_t num)
{
unsigned long x, y, z;
int err;
@@ -87,16 +87,16 @@ int der_decode_integer(const unsigned char *in, unsigned long inlen, void *num)
/* see if it's negative */
if (in[x] & 0x80) {
- void *tmp;
+ mp_int tmp;
if (mp_init(&tmp) != CRYPT_OK) {
return CRYPT_MEM;
}
- if (mp_2expt(tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, tmp, num) != CRYPT_OK) {
- mp_clear(tmp);
+ if (mp_2expt(&tmp, mp_count_bits(num)) != CRYPT_OK || mp_sub(num, &tmp, num) != CRYPT_OK) {
+ mp_clear(&tmp);
return CRYPT_MEM;
}
- mp_clear(tmp);
+ mp_clear(&tmp);
}
return CRYPT_OK;
diff --git a/libtomcrypt/pk/asn1/der/integer/der_encode_integer.c b/libtomcrypt/pk/asn1/der/integer/der_encode_integer.c
index c1d0612..830446a 100644
--- a/libtomcrypt/pk/asn1/der/integer/der_encode_integer.c
+++ b/libtomcrypt/pk/asn1/der/integer/der_encode_integer.c
@@ -26,7 +26,7 @@
@param outlen [in/out] The max size and resulting size of the DER encoded integers
@return CRYPT_OK if successful
*/
-int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
+int der_encode_integer(mp_int_t num, unsigned char *out, unsigned long *outlen)
{
unsigned long tmplen, y;
int err, leading_zero;
@@ -96,7 +96,7 @@ int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
return err;
}
} else if (mp_iszero(num) != LTC_MP_YES) {
- void *tmp;
+ mp_int tmp;
/* negative */
if (mp_init(&tmp) != CRYPT_OK) {
@@ -107,15 +107,15 @@ int der_encode_integer(void *num, unsigned char *out, unsigned long *outlen)
y = mp_count_bits(num);
y = y + (8 - (y & 7));
if (((mp_cnt_lsb(num)+1)==mp_count_bits(num)) && ((mp_count_bits(num)&7)==0)) y -= 8;
- if (mp_2expt(tmp, y) != CRYPT_OK || mp_add(tmp, num, tmp) != CRYPT_OK) {
- mp_clear(tmp);
+ if (mp_2expt(&tmp, y) != CRYPT_OK || mp_add(&tmp, num, &tmp) != CRYPT_OK) {
+ mp_clear(&tmp);
return CRYPT_MEM;
}
- if ((err = mp_to_unsigned_bin(tmp, out)) != CRYPT_OK) {
- mp_clear(tmp);
+ if ((err = mp_to_unsigned_bin(&tmp, out)) != CRYPT_OK) {
+ mp_clear(&tmp);
return err;
}
- mp_clear(tmp);
+ mp_clear(&tmp);
}
/* we good */
diff --git a/libtomcrypt/pk/asn1/der/integer/der_length_integer.c b/libtomcrypt/pk/asn1/der/integer/der_length_integer.c
index 9320b03..40addd5 100644
--- a/libtomcrypt/pk/asn1/der/integer/der_length_integer.c
+++ b/libtomcrypt/pk/asn1/der/integer/der_length_integer.c
@@ -23,7 +23,7 @@
@param outlen [out] The length of the DER encoding for the given integer
@return CRYPT_OK if successful
*/
-int der_length_integer(void *num, unsigned long *outlen)
+int der_length_integer(mp_int_t num, unsigned long *outlen)
{
unsigned long z, len;
int leading_zero;
diff --git a/libtomcrypt/pk/asn1/der/sequence/der_decode_sequence_flexi.c b/libtomcrypt/pk/asn1/der/sequence/der_decode_sequence_flexi.c
index 607d5eb..2e72dbd 100644
--- a/libtomcrypt/pk/asn1/der/sequence/der_decode_sequence_flexi.c
+++ b/libtomcrypt/pk/asn1/der/sequence/der_decode_sequence_flexi.c
@@ -122,17 +122,24 @@ int der_decode_sequence_flexi(const unsigned char *in, unsigned long *inlen, ltc
/* init field */
l->type = LTC_ASN1_INTEGER;
l->size = 1;
- if ((err = mp_init(&l->data)) != CRYPT_OK) {
+
+ l->data = XMALLOC(sizeof(mp_int));
+ if (l->data == NULL) {
+ err = CRYPT_MEM;
+ goto error;
+ }
+
+ if ((err = mp_init((mp_int_t)l->data)) != CRYPT_OK) {
goto error;
}
/* decode field */
- if ((err = der_decode_integer(in, *inlen, l->data)) != CRYPT_OK) {
+ if ((err = der_decode_integer(in, *inlen, (mp_int_t)l->data)) != CRYPT_OK) {
goto error;
}
/* calc length of object */
- if ((err = der_length_integer(l->data, &len)) != CRYPT_OK) {
+ if ((err = der_length_integer((mp_int_t)l->data, &len)) != CRYPT_OK) {
goto error;
}
break;
diff --git a/libtomcrypt/pk/asn1/der/sequence/der_sequence_free.c b/libtomcrypt/pk/asn1/der/sequence/der_sequence_free.c
index a6769b3..a0e0d2d 100644
--- a/libtomcrypt/pk/asn1/der/sequence/der_sequence_free.c
+++ b/libtomcrypt/pk/asn1/der/sequence/der_sequence_free.c
@@ -47,13 +47,13 @@ void der_sequence_free(ltc_asn1_list *in)
case LTC_ASN1_SET:
case LTC_ASN1_SETOF:
case LTC_ASN1_SEQUENCE: break;
- case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); } break;
+ case LTC_ASN1_INTEGER : if (in->data != NULL) { mp_clear(in->data); XFREE(in->data); } break;
default : if (in->data != NULL) { XFREE(in->data); }
}
/* move to next and free current */
l = in->next;
- free(in);
+ XFREE(in);
in = l;
}
}