X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fevp%2Fp_lib.c;h=2760d7b1ed86f901d74e25d8e4c3f7c3a5edc58d;hb=a8b728445c6d2d3f1d3ef568b8bff2b651aa0b52;hp=ac0556b48808bd1e2cf6adfc6d200de48bcdb73a;hpb=14a7cfb32a0347a4bc620ae1b552b21c4c1e270b;p=openssl.git diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index ac0556b488..2760d7b1ed 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -117,7 +117,7 @@ int EVP_PKEY_size(EVP_PKEY *pkey) if (pkey->type == EVP_PKEY_DSA) return(DSA_size(pkey->pkey.dsa)); #endif -#ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_ECDSA if (pkey->type == EVP_PKEY_EC) return(ECDSA_size(pkey->pkey.eckey)); #endif @@ -137,8 +137,8 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) return(ret); } #endif -#ifndef OPENSSL_NO_ECDSA - if (pkey->type == EVP_PKEY_ECDSA) +#ifndef OPENSSL_NO_EC + if (pkey->type == EVP_PKEY_EC) { int ret = pkey->save_parameters; @@ -150,7 +150,7 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) return(0); } -int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from) +int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) { if (to->type != from->type) { @@ -182,7 +182,7 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from) } #endif #ifndef OPENSSL_NO_EC - if (to->type == EVP_PKEY_ECDSA) + if (to->type == EVP_PKEY_EC) { if (to->pkey.eckey->group != NULL) EC_GROUP_free(to->pkey.eckey->group); @@ -198,7 +198,7 @@ err: return(0); } -int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) +int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) { #ifndef OPENSSL_NO_DSA if (pkey->type == EVP_PKEY_DSA) @@ -221,7 +221,7 @@ int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) return(0); } -int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) +int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { #ifndef OPENSSL_NO_DSA if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) @@ -237,6 +237,61 @@ int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) return(-1); } +int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b) + { + if (a->type != b->type) + return -1; + + /* XXXXX + We should really check for != 0, but cmp_paramters doesn't compare EC + groups, and I'm currently unsure how to handle that case... Except for + adding such functionality to cmp_parameters, but that would require + things like EC_GROUP_cmp(), which I'm not currently ready to write. + -- Richard Levitte */ + if (EVP_PKEY_cmp_parameters(a, b) == 1) + return 1; + + switch (a->type) + { +#ifndef OPENSSL_NO_RSA + case EVP_PKEY_RSA: + if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0 + || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0) + return 0; + break; +#endif +#ifndef OPENSSL_NO_DSA + case EVP_PKEY_DSA: + if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0) + return 0; + break; +#endif +#ifndef OPENSSL_NO_EC + case EVP_PKEY_EC: + { + int r = EC_POINT_cmp(b->pkey.eckey->group, + b->pkey.eckey->pub_key,a->pkey.eckey->pub_key,NULL); + if (r != 0) + { + if (r == 1) + return 0; + else + return -2; + } + } + break; +#endif +#ifndef OPENSSL_NO_DH + case EVP_PKEY_DH: + return -2; +#endif + default: + return -2; + } + + return 1; + } + EVP_PKEY *EVP_PKEY_new(void) { EVP_PKEY *ret;