From 514a0e99c176081e1cb610a3e8dabf4d2da38dab Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 21 Jul 2010 18:04:21 +0200 Subject: der_en/decode_subject_public_key_info were moved to x509/ subdirectory. --- Makefile | 4 +- .../sequence/der_decode_subject_public_key_info.c | 97 ---------------------- .../sequence/der_encode_subject_public_key_info.c | 69 --------------- .../der/x509/der_decode_subject_public_key_info.c | 97 ++++++++++++++++++++++ .../der/x509/der_encode_subject_public_key_info.c | 69 +++++++++++++++ 5 files changed, 168 insertions(+), 168 deletions(-) delete mode 100644 libtomcrypt/pk/asn1/der/sequence/der_decode_subject_public_key_info.c delete mode 100644 libtomcrypt/pk/asn1/der/sequence/der_encode_subject_public_key_info.c create mode 100644 libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c create mode 100644 libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c diff --git a/Makefile b/Makefile index 6b97a6a..0b031d4 100644 --- a/Makefile +++ b/Makefile @@ -63,8 +63,8 @@ TOMCRYPT_OBJECTS = libtomcrypt/misc/zeromem.o libtomcrypt/misc/crypt/crypt_argch libtomcrypt/pk/pkcs1/pkcs_1_i2osp.o libtomcrypt/pk/pkcs1/pkcs_1_mgf1.o libtomcrypt/pk/pkcs1/pkcs_1_oaep_decode.o \ libtomcrypt/pk/pkcs1/pkcs_1_oaep_encode.o libtomcrypt/pk/pkcs1/pkcs_1_os2ip.o libtomcrypt/pk/pkcs1/pkcs_1_pss_decode.o \ libtomcrypt/pk/pkcs1/pkcs_1_pss_encode.o libtomcrypt/pk/pkcs1/pkcs_1_v1_5_decode.o libtomcrypt/pk/pkcs1/pkcs_1_v1_5_encode.o \ - libtomcrypt/misc/pk_get_oid.o libtomcrypt/pk/asn1/der/sequence/der_encode_subject_public_key_info.o \ - libtomcrypt/pk/asn1/der/sequence/der_decode_subject_public_key_info.o + libtomcrypt/misc/pk_get_oid.o libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.o \ + libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.o cryptodev-objs = cryptodev_main.o cryptodev_cipher.o ncr.o \ ncr-data.o ncr-key.o ncr-limits.o ncr-sessions.o ncr-pk.o \ diff --git a/libtomcrypt/pk/asn1/der/sequence/der_decode_subject_public_key_info.c b/libtomcrypt/pk/asn1/der/sequence/der_decode_subject_public_key_info.c deleted file mode 100644 index 6c97e96..0000000 --- a/libtomcrypt/pk/asn1/der/sequence/der_decode_subject_public_key_info.c +++ /dev/null @@ -1,97 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - * - */ -#include "tomcrypt.h" -/** - @file der_encode_sequence_multi.c - ASN.1 DER, encode a Subject Public Key structure --nmav -*/ - -#ifdef LTC_DER - -/* AlgorithmIdentifier := SEQUENCE { - * algorithm OBJECT IDENTIFIER, - * parameters ANY DEFINED BY algorithm - * } - * - * SubjectPublicKeyInfo := SEQUENCE { - * algorithm AlgorithmIdentifier, - * subjectPublicKey BIT STRING - * } - */ -/** - Encode a SEQUENCE type using a VA list - @param out [out] Destination for data - @param outlen [in/out] Length of buffer and resulting length of output - @remark <...> is of the form (int, unsigned long, void*) - @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, - unsigned long parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len) -{ - int err, len; - oid_st oid; - unsigned char *tmpbuf; - unsigned long tmpoid[16]; - ltc_asn1_list alg_id[2]; - ltc_asn1_list subject_pubkey[2]; - - LTC_ARGCHK(in != NULL); - LTC_ARGCHK(inlen != 0); - - err = pk_get_oid(algorithm, &oid); - if (err != CRYPT_OK) { - return err; - } - - /* see if the OpenSSL DER format RSA public key will work */ - tmpbuf = XCALLOC(1, MAX_RSA_SIZE*8); - if (tmpbuf == NULL) { - err = CRYPT_MEM; - goto LBL_ERR; - } - - /* this includes the internal hash ID and optional params (NULL in this case) */ - LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0])); - LTC_SET_ASN1(alg_id, 1, parameters_type, parameters, parameters_len); - - /* the actual format of the SSL DER key is odd, it stores a RSAPublicKey in a **BIT** string ... so we have to extract it - then proceed to convert bit to octet - */ - LTC_SET_ASN1(subject_pubkey, 0, LTC_ASN1_SEQUENCE, alg_id, 2); - LTC_SET_ASN1(subject_pubkey, 1, LTC_ASN1_BIT_STRING, tmpbuf, MAX_RSA_SIZE*8); - - err=der_decode_sequence(in, inlen, subject_pubkey, 2UL); - if (err != CRYPT_OK) { - goto LBL_ERR; - } - - len = subject_pubkey[1].size/8; - if (*public_key_len > len) { - memcpy(public_key, subject_pubkey[1].data, len); - *public_key_len = len; - } else { - *public_key_len = len; - err = CRYPT_BUFFER_OVERFLOW; - goto LBL_ERR; - } - - err = CRYPT_OK; - -LBL_ERR: - - XFREE(tmpbuf); - - return err; -} - -#endif - - diff --git a/libtomcrypt/pk/asn1/der/sequence/der_encode_subject_public_key_info.c b/libtomcrypt/pk/asn1/der/sequence/der_encode_subject_public_key_info.c deleted file mode 100644 index e37c4b4..0000000 --- a/libtomcrypt/pk/asn1/der/sequence/der_encode_subject_public_key_info.c +++ /dev/null @@ -1,69 +0,0 @@ -/* LibTomCrypt, modular cryptographic library -- Tom St Denis - * - * LibTomCrypt is a library that provides various cryptographic - * algorithms in a highly modular and flexible manner. - * - * The library is free for all purposes without any express - * guarantee it works. - * - */ -#include "tomcrypt.h" - -/** - @file der_encode_sequence_multi.c - ASN.1 DER, encode a Subject Public Key structure --nmav -*/ - -#ifdef LTC_DER - -/* AlgorithmIdentifier := SEQUENCE { - * algorithm OBJECT IDENTIFIER, - * parameters ANY DEFINED BY algorithm - * } - * - * SubjectPublicKeyInfo := SEQUENCE { - * algorithm AlgorithmIdentifier, - * subjectPublicKey BIT STRING - * } - */ -/** - Encode a SEQUENCE type using a VA list - @param out [out] Destination for data - @param outlen [in/out] Length of buffer and resulting length of output - @remark <...> is of the form (int, unsigned long, void*) - @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, - unsigned long parameters_type, void* parameters, unsigned long parameters_len) -{ - int err; - ltc_asn1_list alg_id[2]; - oid_st oid; - - LTC_ARGCHK(out != NULL); - LTC_ARGCHK(outlen != NULL); - - err = pk_get_oid(algorithm, &oid); - if (err != CRYPT_OK) { - return err; - } - - alg_id[0].data = oid.OID; - alg_id[0].size = oid.OIDlen; - alg_id[0].type = LTC_ASN1_OBJECT_IDENTIFIER; - - alg_id[1].data = parameters; - alg_id[1].size = parameters_len; - alg_id[1].type = parameters_type; - - return der_encode_sequence_multi(out, outlen, - LTC_ASN1_SEQUENCE, (unsigned long)sizeof(alg_id)/sizeof(alg_id[0]), alg_id, - LTC_ASN1_BIT_STRING, (unsigned long)(public_key_len*8), public_key, - LTC_ASN1_EOL, 0UL, NULL); - -} - -#endif - - 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 new file mode 100644 index 0000000..6c97e96 --- /dev/null +++ b/libtomcrypt/pk/asn1/der/x509/der_decode_subject_public_key_info.c @@ -0,0 +1,97 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + */ +#include "tomcrypt.h" +/** + @file der_encode_sequence_multi.c + ASN.1 DER, encode a Subject Public Key structure --nmav +*/ + +#ifdef LTC_DER + +/* AlgorithmIdentifier := SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters ANY DEFINED BY algorithm + * } + * + * SubjectPublicKeyInfo := SEQUENCE { + * algorithm AlgorithmIdentifier, + * subjectPublicKey BIT STRING + * } + */ +/** + Encode a SEQUENCE type using a VA list + @param out [out] Destination for data + @param outlen [in/out] Length of buffer and resulting length of output + @remark <...> is of the form (int, unsigned long, void*) + @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, + unsigned long parameters_type, ltc_asn1_list* parameters, unsigned long parameters_len) +{ + int err, len; + oid_st oid; + unsigned char *tmpbuf; + unsigned long tmpoid[16]; + ltc_asn1_list alg_id[2]; + ltc_asn1_list subject_pubkey[2]; + + LTC_ARGCHK(in != NULL); + LTC_ARGCHK(inlen != 0); + + err = pk_get_oid(algorithm, &oid); + if (err != CRYPT_OK) { + return err; + } + + /* see if the OpenSSL DER format RSA public key will work */ + tmpbuf = XCALLOC(1, MAX_RSA_SIZE*8); + if (tmpbuf == NULL) { + err = CRYPT_MEM; + goto LBL_ERR; + } + + /* this includes the internal hash ID and optional params (NULL in this case) */ + LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0])); + LTC_SET_ASN1(alg_id, 1, parameters_type, parameters, parameters_len); + + /* the actual format of the SSL DER key is odd, it stores a RSAPublicKey in a **BIT** string ... so we have to extract it + then proceed to convert bit to octet + */ + LTC_SET_ASN1(subject_pubkey, 0, LTC_ASN1_SEQUENCE, alg_id, 2); + LTC_SET_ASN1(subject_pubkey, 1, LTC_ASN1_BIT_STRING, tmpbuf, MAX_RSA_SIZE*8); + + err=der_decode_sequence(in, inlen, subject_pubkey, 2UL); + if (err != CRYPT_OK) { + goto LBL_ERR; + } + + len = subject_pubkey[1].size/8; + if (*public_key_len > len) { + memcpy(public_key, subject_pubkey[1].data, len); + *public_key_len = len; + } else { + *public_key_len = len; + err = CRYPT_BUFFER_OVERFLOW; + goto LBL_ERR; + } + + err = CRYPT_OK; + +LBL_ERR: + + XFREE(tmpbuf); + + return err; +} + +#endif + + 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 new file mode 100644 index 0000000..e37c4b4 --- /dev/null +++ b/libtomcrypt/pk/asn1/der/x509/der_encode_subject_public_key_info.c @@ -0,0 +1,69 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + */ +#include "tomcrypt.h" + +/** + @file der_encode_sequence_multi.c + ASN.1 DER, encode a Subject Public Key structure --nmav +*/ + +#ifdef LTC_DER + +/* AlgorithmIdentifier := SEQUENCE { + * algorithm OBJECT IDENTIFIER, + * parameters ANY DEFINED BY algorithm + * } + * + * SubjectPublicKeyInfo := SEQUENCE { + * algorithm AlgorithmIdentifier, + * subjectPublicKey BIT STRING + * } + */ +/** + Encode a SEQUENCE type using a VA list + @param out [out] Destination for data + @param outlen [in/out] Length of buffer and resulting length of output + @remark <...> is of the form (int, unsigned long, void*) + @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, + unsigned long parameters_type, void* parameters, unsigned long parameters_len) +{ + int err; + ltc_asn1_list alg_id[2]; + oid_st oid; + + LTC_ARGCHK(out != NULL); + LTC_ARGCHK(outlen != NULL); + + err = pk_get_oid(algorithm, &oid); + if (err != CRYPT_OK) { + return err; + } + + alg_id[0].data = oid.OID; + alg_id[0].size = oid.OIDlen; + alg_id[0].type = LTC_ASN1_OBJECT_IDENTIFIER; + + alg_id[1].data = parameters; + alg_id[1].size = parameters_len; + alg_id[1].type = parameters_type; + + return der_encode_sequence_multi(out, outlen, + LTC_ASN1_SEQUENCE, (unsigned long)sizeof(alg_id)/sizeof(alg_id[0]), alg_id, + LTC_ASN1_BIT_STRING, (unsigned long)(public_key_len*8), public_key, + LTC_ASN1_EOL, 0UL, NULL); + +} + +#endif + + -- cgit