Constify private key decode.
authorDr. Stephen Henson <steve@openssl.org>
Tue, 16 Aug 2016 23:21:55 +0000 (00:21 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Wed, 17 Aug 2016 11:01:29 +0000 (12:01 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/asn1/ameth_lib.c
crypto/asn1/p8_pkey.c
crypto/dh/dh_ameth.c
crypto/dsa/dsa_ameth.c
crypto/ec/ec_ameth.c
crypto/ec/ecx_meth.c
crypto/evp/evp_pkey.c
crypto/include/internal/asn1_int.h
crypto/rsa/rsa_ameth.c
include/openssl/evp.h
include/openssl/x509.h

index d5a024776ff7525aca4964dea97a9cfcc1524659..1d32f5d95cc25dd2b032abf33b18516d7941466b 100644 (file)
@@ -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),
index b8cc0b140759c29d3def01dfbcfec2aa19dcac53..dbee827e0d3788f1ee3f78ab4738d7c896a25f0f 100644 (file)
@@ -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;
index e9f761a453d8ecc7942be4ca6c1b40655059e4a9..cd77867dee9f7cdfab49054415f1f96f56e623dc 100644 (file)
@@ -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;
index ba442cf71c5451ec153700a58b48fe6f815c9493..7c0428d3f64085c9f49af0651f780ae5dce27165 100644 (file)
@@ -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;
 
index 4baadfb61746a10d57e18144d9957cd671572d46..a899932ee19b77820df2cab35f7a7b8bffacc216 100644 (file)
@@ -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;
index f7179511ddd3ce4f7dee0c931bc039219d597c67..06e3911340d8f9fd0901c093f85718c6196074b4 100644 (file)
@@ -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))
index 82ab1ef0af71e5043f166f4fef6f5e2ad2cb2008..81bffa6d91ada0154bb568be4bb0e1eed365252b 100644 (file)
 
 /* 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))
index f4c71fc861f5cc567057ff2e3e52422852841bea..f70e3b47ba326bf04de7f418ec62fb2a2f19f9aa 100644 (file)
@@ -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);
index d55cf330b9a2230b59d1c8b55baf9a7a78e635a6..5694140af82429d10af28979b43853668456219a 100644 (file)
@@ -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;
index 46a2e263a219bfcf82f0328f666851190b54052c..3727545208bfbaac78341c194ca5d313bd3e09ff 100644 (file)
@@ -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),
index b09208477a92fa904788414980bdac1c4fe4c135..f8d188147be3b60a072d69e6c0aa2196ebc91ec6 100644 (file)
@@ -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);