Add OPENSSL_NO_ECDH guards
[oweals/openssl.git] / crypto / ec / ec_ameth.c
index f024f904975e9a7fe542d6ed6dbd634c307f38d4..62ea5a984f93005833fc31a1471d65f62f3f7aa2 100644 (file)
@@ -356,6 +356,7 @@ static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
                EC_KEY_set_enc_flags(ec_key, old_flags);
                OPENSSL_free(ep);
                ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB);
+               return 0;
        }
        /* restore old encoding flags */
        EC_KEY_set_enc_flags(ec_key, old_flags);
@@ -395,6 +396,22 @@ static int ec_bits(const EVP_PKEY *pkey)
        return ret;
        }
 
+static int ec_security_bits(const EVP_PKEY *pkey)
+       {
+       int ecbits = ec_bits(pkey);
+       if (ecbits >= 512)
+               return 256;
+       if (ecbits >= 384)
+               return 192;
+       if (ecbits >= 256)
+               return 128;
+       if (ecbits >= 224)
+               return 112;
+       if (ecbits >= 160)
+               return 80;
+       return ecbits / 2;
+       }
+
 static int ec_missing_parameters(const EVP_PKEY *pkey)
        {
        if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
@@ -456,14 +473,16 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
        if (ktype > 0)
                {
                public_key = EC_KEY_get0_public_key(x);
-               if ((pub_key = EC_POINT_point2bn(group, public_key,
-                       EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
+               if (public_key != NULL)
                        {
-                       reason = ERR_R_EC_LIB;
-                       goto err;
-                       }
-               if (pub_key)
+                       if ((pub_key = EC_POINT_point2bn(group, public_key,
+                               EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
+                               {
+                               reason = ERR_R_EC_LIB;
+                               goto err;
+                               }
                        buf_len = (size_t)BN_num_bytes(pub_key);
+                       }
                }
 
        if (ktype == 2)
@@ -630,7 +649,7 @@ static int ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
 #endif
 
                case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
-               *(int *)arg2 = NID_sha1;
+               *(int *)arg2 = NID_sha256;
                return 2;
 
                default:
@@ -659,6 +678,7 @@ const EVP_PKEY_ASN1_METHOD eckey_asn1_meth =
 
        int_ec_size,
        ec_bits,
+       ec_security_bits,
 
        eckey_param_decode,
        eckey_param_encode,