Browse Source

no need for der_decode_subject_public_key_info_ex

Karel Miko 8 years ago
parent
commit
fd7c2b8c1f

+ 1 - 6
src/headers/tomcrypt_pk.h

@@ -574,12 +574,7 @@ int der_encode_subject_public_key_info(unsigned char *out, unsigned long *outlen
 
 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 der_decode_subject_public_key_info_ex(const unsigned char *in, unsigned long inlen,
-        unsigned int algorithm, void* public_key, unsigned long* public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long parameters_len,
-        unsigned long *parameters_outsize);
+        unsigned long parameters_type, void* parameters, unsigned long *parameters_len);
 #endif /* LTC_SOURCE */
 
 /* SET */

+ 5 - 13
src/pk/asn1/der/sequence/der_decode_subject_public_key_info.c

@@ -33,21 +33,12 @@
    @param public_key_len        [in/out] The length of the public key buffer and the written length
    @param parameters_type       The parameters' type out of the enum ltc_asn1_type
    @param parameters            The parameters to include
-   @param parameters_len        The number of parameters to include
+   @param parameters_len        [in/out]The number of parameters to include
    @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)
-{
-   return der_decode_subject_public_key_info_ex(in, inlen, algorithm, public_key, public_key_len,
-                                                parameters_type, parameters, parameters_len, NULL);
-}
-
-int der_decode_subject_public_key_info_ex(const unsigned char *in, unsigned long inlen,
-        unsigned int algorithm, void* public_key, unsigned long* public_key_len,
-        unsigned long parameters_type, void* parameters, unsigned long parameters_len,
-        unsigned long *parameters_outsize)
+        unsigned long parameters_type, void* parameters, unsigned long *parameters_len)
 {
    int err;
    unsigned long len;
@@ -60,6 +51,7 @@ int der_decode_subject_public_key_info_ex(const unsigned char *in, unsigned long
    LTC_ARGCHK(in    != NULL);
    LTC_ARGCHK(inlen != 0);
    LTC_ARGCHK(public_key_len != NULL);
+   LTC_ARGCHK(parameters_len != NULL);
 
    err = pk_get_oid(algorithm, &oid);
    if (err != CRYPT_OK) {
@@ -75,7 +67,7 @@ int der_decode_subject_public_key_info_ex(const unsigned char *in, unsigned long
 
    /* 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, (ltc_asn1_type)parameters_type, parameters, parameters_len);
+   LTC_SET_ASN1(alg_id, 1, (ltc_asn1_type)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
@@ -88,7 +80,7 @@ int der_decode_subject_public_key_info_ex(const unsigned char *in, unsigned long
            goto LBL_ERR;
    }
 
-   if (parameters_outsize) *parameters_outsize = alg_id[1].size;
+   *parameters_len = alg_id[1].size;
 
    if ((alg_id[0].size != oid.OIDlen) ||
         XMEMCMP(oid.OID, alg_id[0].data, oid.OIDlen * sizeof(oid.OID[0]))) {

+ 3 - 2
src/pk/dsa/dsa_import.c

@@ -25,7 +25,7 @@
 int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
 {
    int           err, stat;
-   unsigned long zero = 0;
+   unsigned long zero = 0, len;
    unsigned char* tmpbuf = NULL;
    unsigned char flags[1];
 
@@ -102,9 +102,10 @@ int dsa_import(const unsigned char *in, unsigned long inlen, dsa_key *key)
          goto LBL_ERR;
       }
 
+      len = 3;
       err = der_decode_subject_public_key_info(in, inlen, PKA_DSA,
                                                tmpbuf, &tmpbuf_len,
-                                               LTC_ASN1_SEQUENCE, params, 3);
+                                               LTC_ASN1_SEQUENCE, params, &len);
       if (err != CRYPT_OK) {
          XFREE(tmpbuf);
          goto LBL_ERR;

+ 3 - 2
src/pk/rsa/rsa_import.c

@@ -27,7 +27,7 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
    int           err;
    void         *zero;
    unsigned char *tmpbuf=NULL;
-   unsigned long tmpbuf_len;
+   unsigned long tmpbuf_len, len;
 
    LTC_ARGCHK(in          != NULL);
    LTC_ARGCHK(key         != NULL);
@@ -47,9 +47,10 @@ int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key)
        goto LBL_ERR;
    }
 
+   len = 0;
    err = der_decode_subject_public_key_info(in, inlen,
         PKA_RSA, tmpbuf, &tmpbuf_len,
-        LTC_ASN1_NULL, NULL, 0);
+        LTC_ASN1_NULL, NULL, &len);
 
    if (err == CRYPT_OK) { /* SubjectPublicKeyInfo format */
 

+ 3 - 2
src/pk/rsa/rsa_import_x509.c

@@ -26,7 +26,7 @@ int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key)
 {
    int           err;
    unsigned char *tmpbuf;
-   unsigned long tmpbuf_len, tmp_inlen;
+   unsigned long tmpbuf_len, tmp_inlen, len;
    ltc_asn1_list *decoded_list = NULL, *l;
 
    LTC_ARGCHK(in          != NULL);
@@ -77,9 +77,10 @@ int rsa_import_x509(const unsigned char *in, unsigned long inlen, rsa_key *key)
                      l->child->type == LTC_ASN1_SEQUENCE && l->child->child &&
                      l->child->child->type == LTC_ASN1_OBJECT_IDENTIFIER && l->child->next &&
                      l->child->next->type == LTC_ASN1_BIT_STRING) {
+                  len = 0;
                   err = der_decode_subject_public_key_info(l->data, l->size,
                        PKA_RSA, tmpbuf, &tmpbuf_len,
-                       LTC_ASN1_NULL, NULL, 0);
+                       LTC_ASN1_NULL, NULL, &len);
                   if (err == CRYPT_OK) {
                      /* now it should be SEQUENCE { INTEGER, INTEGER } */
                      if ((err = der_decode_sequence_multi(tmpbuf, tmpbuf_len,