From: Dr. Stephen Henson Date: Tue, 16 Aug 2016 23:21:55 +0000 (+0100) Subject: Constify private key decode. X-Git-Tag: OpenSSL_1_1_0~162 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=245c6bc33b1481052f347f316cec16888aa1be85;p=oweals%2Fopenssl.git Constify private key decode. Reviewed-by: Richard Levitte --- diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index d5a024776f..1d32f5d95c 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -324,7 +324,7 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, int (*priv_decode) (EVP_PKEY *pk, - PKCS8_PRIV_KEY_INFO + const PKCS8_PRIV_KEY_INFO *p8inf), int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), diff --git a/crypto/asn1/p8_pkey.c b/crypto/asn1/p8_pkey.c index b8cc0b1407..dbee827e0d 100644 --- a/crypto/asn1/p8_pkey.c +++ b/crypto/asn1/p8_pkey.c @@ -50,9 +50,9 @@ int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, return 1; } -int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, +int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) + const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8) { if (ppkalg) *ppkalg = p8->pkeyalg->algorithm; diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index e9f761a453..cd77867dee 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -147,14 +147,14 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) * explicitly included and the pubkey must be recalculated. */ -static int dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) +static int dh_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p, *pm; int pklen, pmlen; int ptype; const void *pval; const ASN1_STRING *pstr; - X509_ALGOR *palg; + const X509_ALGOR *palg; ASN1_INTEGER *privkey = NULL; DH *dh = NULL; diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index ba442cf71c..7c0428d3f6 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -130,14 +130,14 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey) * AlgorithmIdentifier the pubkey must be recalculated. */ -static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) +static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p, *pm; int pklen, pmlen; int ptype; const void *pval; const ASN1_STRING *pstr; - X509_ALGOR *palg; + const X509_ALGOR *palg; ASN1_INTEGER *privkey = NULL; BN_CTX *ctx = NULL; diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index 4baadfb617..a899932ee1 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -179,13 +179,13 @@ static int eckey_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) return -2; } -static int eckey_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) +static int eckey_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p = NULL; const void *pval; int ptype, pklen; EC_KEY *eckey = NULL; - X509_ALGOR *palg; + const X509_ALGOR *palg; if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) return 0; diff --git a/crypto/ec/ecx_meth.c b/crypto/ec/ecx_meth.c index f7179511dd..06e3911340 100644 --- a/crypto/ec/ecx_meth.c +++ b/crypto/ec/ecx_meth.c @@ -32,7 +32,7 @@ typedef enum { } ecx_key_op_t; /* Setup EVP_PKEY using public, private or generation */ -static int ecx_key_op(EVP_PKEY *pkey, X509_ALGOR *palg, +static int ecx_key_op(EVP_PKEY *pkey, const X509_ALGOR *palg, const unsigned char *p, int plen, ecx_key_op_t op) { X25519_KEY *xkey; @@ -135,12 +135,12 @@ static int ecx_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) return !CRYPTO_memcmp(akey->pubkey, bkey->pubkey, X25519_KEYLEN); } -static int ecx_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) +static int ecx_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p; int plen; ASN1_OCTET_STRING *oct = NULL; - X509_ALGOR *palg; + const X509_ALGOR *palg; int rv; if (!PKCS8_pkey_get0(NULL, &p, &plen, &palg, p8)) diff --git a/crypto/evp/evp_pkey.c b/crypto/evp/evp_pkey.c index 82ab1ef0af..81bffa6d91 100644 --- a/crypto/evp/evp_pkey.c +++ b/crypto/evp/evp_pkey.c @@ -18,10 +18,10 @@ /* Extract a private key from a PKCS8 structure */ -EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) +EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8) { EVP_PKEY *pkey = NULL; - ASN1_OBJECT *algoid; + const ASN1_OBJECT *algoid; char obj_tmp[80]; if (!PKCS8_pkey_get0(&algoid, NULL, NULL, NULL, p8)) diff --git a/crypto/include/internal/asn1_int.h b/crypto/include/internal/asn1_int.h index f4c71fc861..f70e3b47ba 100644 --- a/crypto/include/internal/asn1_int.h +++ b/crypto/include/internal/asn1_int.h @@ -22,7 +22,7 @@ struct evp_pkey_asn1_method_st { int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b); int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); - int (*priv_decode) (EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf); + int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf); int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk); int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx); diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index d55cf330b9..5694140af8 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -101,7 +101,7 @@ static int rsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) return 1; } -static int rsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) +static int rsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8) { const unsigned char *p; int pklen; diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 46a2e263a2..3727545208 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -1068,7 +1068,7 @@ void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth, int (*pkey_bits) (const EVP_PKEY *pk)); void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth, int (*priv_decode) (EVP_PKEY *pk, - PKCS8_PRIV_KEY_INFO + const PKCS8_PRIV_KEY_INFO *p8inf), int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk), diff --git a/include/openssl/x509.h b/include/openssl/x509.h index b09208477a..f8d188147b 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -961,15 +961,15 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) -EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); +EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version, int ptype, void *pval, unsigned char *penc, int penclen); -int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, +int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8); + const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); const STACK_OF(X509_ATTRIBUTE) * PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8);