diff options
Diffstat (limited to 'libtomcrypt/pk')
-rw-r--r-- | libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c | 2 | ||||
-rw-r--r-- | libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c | 2 | ||||
-rw-r--r-- | libtomcrypt/pk/dsa/dsa_export.c | 8 | ||||
-rw-r--r-- | libtomcrypt/pk/dsa/dsa_import.c | 8 | ||||
-rw-r--r-- | libtomcrypt/pk/rsa/rsa_export.c | 8 | ||||
-rw-r--r-- | libtomcrypt/pk/rsa/rsa_import.c | 8 |
6 files changed, 30 insertions, 6 deletions
diff --git a/libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c b/libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c index 3ebb8ea..c5bd894 100644 --- a/libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c +++ b/libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c @@ -48,7 +48,7 @@ @return CRYPT_OK on success */ int der_decode_subject_public_key_info(const unsigned char *in, unsigned long inlen, - unsigned int algorithm, void* public_key, unsigned long* public_key_len, + const struct algo_properties_st *algorithm, void* public_key, unsigned long* public_key_len, unsigned long parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len) { int err, len; diff --git a/libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c b/libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c index 4c7e966..7db7a5e 100644 --- a/libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c +++ b/libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c @@ -48,7 +48,7 @@ @return CRYPT_OK on success */ int der_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen, - unsigned int algorithm, void* public_key, unsigned long public_key_len, + const struct algo_properties_st *algorithm, void* public_key, unsigned long public_key_len, unsigned long parameters_type, void* parameters, unsigned long parameters_len) { int err; diff --git a/libtomcrypt/pk/dsa/dsa_export.c b/libtomcrypt/pk/dsa/dsa_export.c index 01569e7..ad2991f 100644 --- a/libtomcrypt/pk/dsa/dsa_export.c +++ b/libtomcrypt/pk/dsa/dsa_export.c @@ -9,6 +9,7 @@ * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" +#include <ncr-int.h> /** @file dsa_export.c @@ -30,11 +31,16 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, { unsigned long zero = 0; int err; + const struct algo_properties_st *algo = _ncr_algo_to_properties(NCR_ALG_DSA); LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); + if (algo == NULL) { + return CRYPT_INVALID_ARG; + } + /* can we store the static header? */ if (type == PK_PRIVATE && key->type != PK_PRIVATE) { return CRYPT_PK_TYPE_MISMATCH; @@ -83,7 +89,7 @@ int dsa_export(unsigned char *out, unsigned long *outlen, int type, int_list[2].type = LTC_ASN1_INTEGER; err = der_encode_subject_public_key_info(out, outlen, - PKA_DSA, tmp, tmplen, + algo, tmp, tmplen, LTC_ASN1_SEQUENCE, int_list, sizeof(int_list) / diff --git a/libtomcrypt/pk/dsa/dsa_import.c b/libtomcrypt/pk/dsa/dsa_import.c index cf21e3b..5a60937 100644 --- a/libtomcrypt/pk/dsa/dsa_import.c +++ b/libtomcrypt/pk/dsa/dsa_import.c @@ -9,6 +9,7 @@ * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" +#include <ncr-int.h> /** @file dsa_import.c @@ -29,10 +30,15 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key * key) int err; unsigned long zero = 0; unsigned char *tmpbuf = NULL; + const struct algo_properties_st *algo = _ncr_algo_to_properties(NCR_ALG_DSA); LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); + if (algo == NULL) { + return CRYPT_INVALID_ARG; + } + /* init key */ if (mp_init_multi(&key->p, &key->g, &key->q, &key->x, &key->y, NULL) != CRYPT_OK) { @@ -65,7 +71,7 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key * key) } err = der_decode_subject_public_key_info(in, inlen, - PKA_DSA, tmpbuf, + algo, tmpbuf, &tmpbuf_len, LTC_ASN1_SEQUENCE, params, 3); diff --git a/libtomcrypt/pk/rsa/rsa_export.c b/libtomcrypt/pk/rsa/rsa_export.c index 483af19..cb667a4 100644 --- a/libtomcrypt/pk/rsa/rsa_export.c +++ b/libtomcrypt/pk/rsa/rsa_export.c @@ -31,6 +31,8 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, { unsigned long zero = 0; int err; + const struct algo_properties_st *algo = _ncr_algo_to_properties(NCR_ALG_RSA); + LTC_ARGCHK(out != NULL); LTC_ARGCHK(outlen != NULL); LTC_ARGCHK(key != NULL); @@ -40,6 +42,10 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, return CRYPT_PK_INVALID_TYPE; } + if (algo == NULL) { + return CRYPT_INVALID_ARG; + } + if (type == PK_PRIVATE) { /* private key */ /* output is @@ -75,7 +81,7 @@ int rsa_export(unsigned char *out, unsigned long *outlen, int type, } err = der_encode_subject_public_key_info(out, outlen, - PKA_RSA, tmp, tmplen, + algo, tmp, tmplen, LTC_ASN1_NULL, NULL, 0); diff --git a/libtomcrypt/pk/rsa/rsa_import.c b/libtomcrypt/pk/rsa/rsa_import.c index de8a103..6a42b07 100644 --- a/libtomcrypt/pk/rsa/rsa_import.c +++ b/libtomcrypt/pk/rsa/rsa_import.c @@ -9,6 +9,7 @@ * Tom St Denis, tomstdenis@gmail.com, http://libtom.org */ #include "tomcrypt.h" +#include <ncr-int.h> /** @file rsa_import.c @@ -30,10 +31,15 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key * key) mp_int zero; unsigned char *tmpbuf = NULL; unsigned long tmpbuf_len; + const struct algo_properties_st *algo = _ncr_algo_to_properties(NCR_ALG_RSA); LTC_ARGCHK(in != NULL); LTC_ARGCHK(key != NULL); + if (algo == NULL) { + return CRYPT_INVALID_ARG; + } + /* init key */ if ((err = mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP, &key->p, &key->q, @@ -50,7 +56,7 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key * key) } err = der_decode_subject_public_key_info(in, inlen, - PKA_RSA, tmpbuf, &tmpbuf_len, + algo, tmpbuf, &tmpbuf_len, LTC_ASN1_NULL, NULL, 0); if (err == CRYPT_OK) { /* SubjectPublicKeyInfo format */ |