simplifications
authorBodo Möller <bodo@openssl.org>
Wed, 20 Feb 2002 13:08:17 +0000 (13:08 +0000)
committerBodo Möller <bodo@openssl.org>
Wed, 20 Feb 2002 13:08:17 +0000 (13:08 +0000)
Submitted by: Nils Larsch

crypto/ecdsa/ecs_asn1.c
crypto/ecdsa/ecs_ossl.c

index 542a987bc26e78814e95ae6824fb2b0a75ab8ff9..886cd01db202f3c6cd78db420eaf9184554e82e6 100644 (file)
 
 static point_conversion_form_t POINT_CONVERSION_FORM = POINT_CONVERSION_COMPRESSED;
 
-/* Override the default new methods */
-static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
-{
-       if(operation == ASN1_OP_NEW_PRE) {
-               ECDSA_SIG *sig;
-               sig = OPENSSL_malloc(sizeof(ECDSA_SIG));
-               if (sig == NULL)
-               {
-                       ECDSAerr(ECDSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
-                       return 0;
-               }
-               sig->r = NULL;
-               sig->s = NULL;
-               *pval = (ASN1_VALUE *)sig;
-               return 2;
-       }
-       return 1;
-}
-
-ASN1_SEQUENCE_cb(ECDSA_SIG, sig_cb) = {
+ASN1_SEQUENCE(ECDSA_SIG) = {
        ASN1_SIMPLE(ECDSA_SIG, r, CBIGNUM),
        ASN1_SIMPLE(ECDSA_SIG, s, CBIGNUM)
-} ASN1_SEQUENCE_END_cb(ECDSA_SIG, ECDSA_SIG)
+} ASN1_SEQUENCE_END(ECDSA_SIG)
 
 IMPLEMENT_ASN1_FUNCTIONS_const(ECDSA_SIG)
 
@@ -439,9 +420,7 @@ ECDSA         *ECDSA_x9_62parameters2ecdsa(const X9_62_EC_PARAMETERS *params, EC
                if ((point = EC_POINT_new(ret->group)) == NULL) goto err;
        }
        else OPENSSL_ECDSA_ABORT(ECDSA_R_WRONG_FIELD_IDENTIFIER)
-       /* FIXME!!!  It seems like the comparison of data with 0 isn't the
-          intended thing. */
-       if (params->curve->seed != NULL && params->curve->seed->data != 0)
+       if (params->curve->seed != NULL)
        {
                if (ret->seed != NULL)
                        OPENSSL_free(ret->seed);
index 5a36707cfbd38b885859a87acd5a883b8b556bdf..a79b0c2fe29ffef01387029160fc7d490296bd6a 100644 (file)
@@ -285,16 +285,20 @@ static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dgst_len, ECDSA *
                reason = ECDSA_R_SIGNATURE_MALLOC_FAILED;
                goto err;
        }
-       ret->r = r;
-       ret->s = s;
+       if (BN_copy(ret->r, r) == NULL || BN_copy(ret->s, s) == NULL)
+       {
+               ECDSA_SIG_free(ret);
+               ret = NULL;
+               reason = ERR_R_BN_LIB;
+       }
        
 err:
        if (!ret)
                {
                ECDSAerr(ECDSA_F_ECDSA_DO_SIGN,reason);
-               BN_free(r);
-               BN_free(s);
                }
+       if (r     != NULL) BN_clear_free(r);
+       if (s     != NULL) BN_clear_free(s);
        if (ctx   != NULL) BN_CTX_free(ctx);
        if (m     != NULL) BN_clear_free(m);
        if (tmp   != NULL) BN_clear_free(tmp);