-/* $OpenBSD: ameth_lib.c,v 1.25 2022/01/10 12:10:26 tb Exp $ */
+/* $OpenBSD: ameth_lib.c,v 1.26 2022/06/27 12:36:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
ameth->pkey_ctrl = pkey_ctrl;
}
+void
+EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
+ int (*pkey_security_bits)(const EVP_PKEY *pkey))
+{
+ ameth->pkey_security_bits = pkey_security_bits;
+}
+
void
EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
int (*pkey_check)(const EVP_PKEY *pk))
-/* $OpenBSD: asn1_locl.h,v 1.33 2022/06/25 15:39:12 jsing Exp $ */
+/* $OpenBSD: asn1_locl.h,v 1.34 2022/06/27 12:36:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
int (*pkey_size)(const EVP_PKEY *pk);
int (*pkey_bits)(const EVP_PKEY *pk);
+ int (*pkey_security_bits)(const EVP_PKEY *pk);
int (*param_decode)(EVP_PKEY *pkey, const unsigned char **pder,
int derlen);
-/* $OpenBSD: dh_ameth.c,v 1.23 2022/01/20 11:00:34 inoguchi Exp $ */
+/* $OpenBSD: dh_ameth.c,v 1.24 2022/06/27 12:36:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
return BN_num_bits(pkey->pkey.dh->p);
}
+static int
+dh_security_bits(const EVP_PKEY *pkey)
+{
+ return DH_security_bits(pkey->pkey.dh);
+}
+
static int
dh_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
{
.pkey_size = int_dh_size,
.pkey_bits = dh_bits,
+ .pkey_security_bits = dh_security_bits,
.param_decode = dh_param_decode,
.param_encode = dh_param_encode,
-/* $OpenBSD: dsa_ameth.c,v 1.36 2022/05/07 10:31:28 tb Exp $ */
+/* $OpenBSD: dsa_ameth.c,v 1.37 2022/06/27 12:36:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
return BN_num_bits(pkey->pkey.dsa->p);
}
+static int
+dsa_security_bits(const EVP_PKEY *pkey)
+{
+ return DSA_security_bits(pkey->pkey.dsa);
+}
+
static int
dsa_missing_parameters(const EVP_PKEY *pkey)
{
.pkey_size = int_dsa_size,
.pkey_bits = dsa_bits,
+ .pkey_security_bits = dsa_security_bits,
.param_decode = dsa_param_decode,
.param_encode = dsa_param_encode,
-/* $OpenBSD: ec_ameth.c,v 1.32 2022/05/24 20:00:15 tb Exp $ */
+/* $OpenBSD: ec_ameth.c,v 1.33 2022/06/27 12:36:05 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
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)
{
.pkey_size = int_ec_size,
.pkey_bits = ec_bits,
+ .pkey_security_bits = ec_security_bits,
.param_decode = eckey_param_decode,
.param_encode = eckey_param_encode,
-/* $OpenBSD: evp.h,v 1.100 2022/05/05 08:48:50 tb Exp $ */
+/* $OpenBSD: evp.h,v 1.101 2022/06/27 12:36:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int EVP_PKEY_id(const EVP_PKEY *pkey);
int EVP_PKEY_base_id(const EVP_PKEY *pkey);
int EVP_PKEY_bits(const EVP_PKEY *pkey);
+#ifdef LIBRESSL_INTERNAL
+int EVP_PKEY_security_bits(const EVP_PKEY *pkey);
+#endif
int EVP_PKEY_size(const EVP_PKEY *pkey);
int EVP_PKEY_set_type(EVP_PKEY *pkey, int type);
int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len);
void (*pkey_free)(EVP_PKEY *pkey));
void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
int (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2));
+#ifdef LIBRESSL_INTERNAL
+void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
+ int (*pkey_security_bits)(const EVP_PKEY *pkey));
+#endif
void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
int (*pkey_check)(const EVP_PKEY *pk));
-/* $OpenBSD: p_lib.c,v 1.28 2022/01/20 11:06:24 inoguchi Exp $ */
+/* $OpenBSD: p_lib.c,v 1.29 2022/06/27 12:36:05 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
return 0;
}
+int
+EVP_PKEY_security_bits(const EVP_PKEY *pkey)
+{
+ if (pkey == NULL)
+ return 0;
+ if (pkey->ameth == NULL || pkey->ameth->pkey_security_bits == NULL)
+ return -2;
+
+ return pkey->ameth->pkey_security_bits(pkey);
+}
+
int
EVP_PKEY_size(const EVP_PKEY *pkey)
{
-/* $OpenBSD: rsa_ameth.c,v 1.25 2022/01/10 11:52:43 tb Exp $ */
+/* $OpenBSD: rsa_ameth.c,v 1.26 2022/06/27 12:36:06 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
return BN_num_bits(pkey->pkey.rsa->n);
}
+static int
+rsa_security_bits(const EVP_PKEY *pkey)
+{
+ return RSA_security_bits(pkey->pkey.rsa);
+}
+
static void
int_rsa_free(EVP_PKEY *pkey)
{
.pkey_size = int_rsa_size,
.pkey_bits = rsa_bits,
+ .pkey_security_bits = rsa_security_bits,
.sig_print = rsa_sig_print,