From 45bb7f0ae87ddf787dd06d515db9afb04a74bf6c Mon Sep 17 00:00:00 2001 From: miod <> Date: Sun, 27 Apr 2014 20:26:49 +0000 Subject: Use C99 initializers for the various FOO_METHOD structs. More readable, and avoid unreadable/unmaintainable constructs like that: const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = { EVP_PKEY_CMAC, EVP_PKEY_CMAC, 0, "CMAC", "OpenSSL CMAC method", 0,0,0,0, 0,0,0, cmac_size, 0, 0,0,0,0,0,0,0, cmac_key_free, 0, 0,0 }; ok matthew@ deraadt@ --- src/lib/libcrypto/rsa/rsa_ameth.c | 60 +++++++++++++++++++-------------------- src/lib/libcrypto/rsa/rsa_eay.c | 27 +++++++----------- src/lib/libcrypto/rsa/rsa_null.c | 25 ++++++---------- src/lib/libcrypto/rsa/rsa_pmeth.c | 45 ++++++++++------------------- 4 files changed, 64 insertions(+), 93 deletions(-) (limited to 'src/lib/libcrypto/rsa') diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c index fdd11835ad..f0a346a70e 100644 --- a/src/lib/libcrypto/rsa/rsa_ameth.c +++ b/src/lib/libcrypto/rsa/rsa_ameth.c @@ -657,42 +657,40 @@ static int rsa_item_sign(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn, return 2; } -const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] = +const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[] = { { - { - EVP_PKEY_RSA, - EVP_PKEY_RSA, - ASN1_PKEY_SIGPARAM_NULL, + .pkey_id = EVP_PKEY_RSA, + .pkey_base_id = EVP_PKEY_RSA, + .pkey_flags = ASN1_PKEY_SIGPARAM_NULL, - "RSA", - "OpenSSL RSA method", + .pem_str = "RSA", + .info = "OpenSSL RSA method", - rsa_pub_decode, - rsa_pub_encode, - rsa_pub_cmp, - rsa_pub_print, + .pub_decode = rsa_pub_decode, + .pub_encode = rsa_pub_encode, + .pub_cmp = rsa_pub_cmp, + .pub_print = rsa_pub_print, - rsa_priv_decode, - rsa_priv_encode, - rsa_priv_print, + .priv_decode = rsa_priv_decode, + .priv_encode = rsa_priv_encode, + .priv_print = rsa_priv_print, - int_rsa_size, - rsa_bits, + .pkey_size = int_rsa_size, + .pkey_bits = rsa_bits, - 0,0,0,0,0,0, + .sig_print = rsa_sig_print, - rsa_sig_print, - int_rsa_free, - rsa_pkey_ctrl, - old_rsa_priv_decode, - old_rsa_priv_encode, - rsa_item_verify, - rsa_item_sign - }, + .pkey_free = int_rsa_free, + .pkey_ctrl = rsa_pkey_ctrl, + .old_priv_decode = old_rsa_priv_decode, + .old_priv_encode = old_rsa_priv_encode, + .item_verify = rsa_item_verify, + .item_sign = rsa_item_sign + }, - { - EVP_PKEY_RSA2, - EVP_PKEY_RSA, - ASN1_PKEY_ALIAS - } - }; + { + .pkey_id = EVP_PKEY_RSA2, + .pkey_base_id = EVP_PKEY_RSA, + .pkey_flags = ASN1_PKEY_ALIAS + } +}; diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index dcf0c16a8f..845e28877e 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c @@ -128,22 +128,17 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx); static int RSA_eay_init(RSA *rsa); static int RSA_eay_finish(RSA *rsa); -static RSA_METHOD rsa_pkcs1_eay_meth={ - "Eric Young's PKCS#1 RSA", - RSA_eay_public_encrypt, - RSA_eay_public_decrypt, /* signature verification */ - RSA_eay_private_encrypt, /* signing */ - RSA_eay_private_decrypt, - RSA_eay_mod_exp, - BN_mod_exp_mont, /* XXX probably we should not use Montgomery if e == 3 */ - RSA_eay_init, - RSA_eay_finish, - 0, /* flags */ - NULL, - 0, /* rsa_sign */ - 0, /* rsa_verify */ - NULL /* rsa_keygen */ - }; +static RSA_METHOD rsa_pkcs1_eay_meth = { + .name = "Eric Young's PKCS#1 RSA", + .rsa_pub_enc = RSA_eay_public_encrypt, + .rsa_pub_dec = RSA_eay_public_decrypt, /* signature verification */ + .rsa_priv_enc = RSA_eay_private_encrypt, /* signing */ + .rsa_priv_dec = RSA_eay_private_decrypt, + .rsa_mod_exp = RSA_eay_mod_exp, + .bn_mod_exp = BN_mod_exp_mont, /* XXX probably we should not use Montgomery if e == 3 */ + .init = RSA_eay_init, + .finish = RSA_eay_finish, +}; const RSA_METHOD *RSA_PKCS1_SSLeay(void) { diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c index 2f2202f142..5b9317cb6c 100644 --- a/src/lib/libcrypto/rsa/rsa_null.c +++ b/src/lib/libcrypto/rsa/rsa_null.c @@ -82,22 +82,15 @@ static int RSA_null_mod_exp(const BIGNUM *r0, const BIGNUM *i, RSA *rsa); #endif static int RSA_null_init(RSA *rsa); static int RSA_null_finish(RSA *rsa); -static RSA_METHOD rsa_null_meth={ - "Null RSA", - RSA_null_public_encrypt, - RSA_null_public_decrypt, - RSA_null_private_encrypt, - RSA_null_private_decrypt, - NULL, - NULL, - RSA_null_init, - RSA_null_finish, - 0, - NULL, - NULL, - NULL, - NULL - }; +static RSA_METHOD rsa_null_meth = { + .name = "Null RSA", + .rsa_pub_enc = RSA_null_public_encrypt, + .rsa_pub_dec = RSA_null_public_decrypt, + .rsa_priv_enc = RSA_null_private_encrypt, + .rsa_priv_dec = RSA_null_private_decrypt, + .init = RSA_null_init, + .finish = RSA_null_finish, +}; const RSA_METHOD *RSA_null_method(void) { diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c index adec632b3b..09ef090172 100644 --- a/src/lib/libcrypto/rsa/rsa_pmeth.c +++ b/src/lib/libcrypto/rsa/rsa_pmeth.c @@ -609,41 +609,26 @@ static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return ret; } -const EVP_PKEY_METHOD rsa_pkey_meth = - { - EVP_PKEY_RSA, - EVP_PKEY_FLAG_AUTOARGLEN, - pkey_rsa_init, - pkey_rsa_copy, - pkey_rsa_cleanup, - - 0,0, - - 0, - pkey_rsa_keygen, - - 0, - pkey_rsa_sign, - - 0, - pkey_rsa_verify, - - 0, - pkey_rsa_verifyrecover, +const EVP_PKEY_METHOD rsa_pkey_meth = { + .pkey_id = EVP_PKEY_RSA, + .flags = EVP_PKEY_FLAG_AUTOARGLEN, + .init = pkey_rsa_init, + .copy = pkey_rsa_copy, + .cleanup = pkey_rsa_cleanup, - 0,0,0,0, + .keygen = pkey_rsa_keygen, - 0, - pkey_rsa_encrypt, + .sign = pkey_rsa_sign, - 0, - pkey_rsa_decrypt, + .verify = pkey_rsa_verify, - 0,0, + .verify_recover = pkey_rsa_verifyrecover, - pkey_rsa_ctrl, - pkey_rsa_ctrl_str + .encrypt = pkey_rsa_encrypt, + .decrypt = pkey_rsa_decrypt, - }; + .ctrl = pkey_rsa_ctrl, + .ctrl_str = pkey_rsa_ctrl_str +}; -- cgit v1.2.3-55-g6feb