From eb5c5266934eca378b83a81d22f0c1ac7f26f093 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 24 Aug 2018 20:17:33 +0000 Subject: [PATCH] After removing support for broken PKCS#8 formats (it was high time), we can add const to PKCS8_pkey_get0(). In order for this to work, we need to sprinkle a few consts here and there. tested in a bulk by sthen ok jsing --- lib/libcrypto/asn1/p8_pkey.c | 6 +++--- lib/libcrypto/dh/dh_ameth.c | 4 ++-- lib/libcrypto/dsa/dsa_ameth.c | 4 ++-- lib/libcrypto/ec/ec_ameth.c | 4 ++-- lib/libcrypto/evp/evp_pkey.c | 4 ++-- lib/libcrypto/gost/gostr341001_ameth.c | 6 +++--- lib/libcrypto/x509/x509.h | 13 +++++-------- 7 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/libcrypto/asn1/p8_pkey.c b/lib/libcrypto/asn1/p8_pkey.c index 8f5e303e417..d2f8e6b0557 100644 --- a/lib/libcrypto/asn1/p8_pkey.c +++ b/lib/libcrypto/asn1/p8_pkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: p8_pkey.c,v 1.18 2018/08/24 20:07:41 tb Exp $ */ +/* $OpenBSD: p8_pkey.c,v 1.19 2018/08/24 20:17:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -154,8 +154,8 @@ PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version, } int -PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) +PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk, + int *ppklen, const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8) { if (ppkalg != NULL) *ppkalg = p8->pkeyalg->algorithm; diff --git a/lib/libcrypto/dh/dh_ameth.c b/lib/libcrypto/dh/dh_ameth.c index 6fadfda2d38..6c6b8455fe3 100644 --- a/lib/libcrypto/dh/dh_ameth.c +++ b/lib/libcrypto/dh/dh_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh_ameth.c,v 1.15 2018/05/01 19:01:27 tb Exp $ */ +/* $OpenBSD: dh_ameth.c,v 1.16 2018/08/24 20:17:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -187,7 +187,7 @@ dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) 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/lib/libcrypto/dsa/dsa_ameth.c b/lib/libcrypto/dsa/dsa_ameth.c index 2d62aaa582b..6c1062d9757 100644 --- a/lib/libcrypto/dsa/dsa_ameth.c +++ b/lib/libcrypto/dsa/dsa_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_ameth.c,v 1.24 2018/05/01 19:01:27 tb Exp $ */ +/* $OpenBSD: dsa_ameth.c,v 1.25 2018/08/24 20:17:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -186,7 +186,7 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) int ptype; const void *pval; const ASN1_STRING *pstr; - X509_ALGOR *palg; + const X509_ALGOR *palg; ASN1_INTEGER *privkey = NULL; BN_CTX *ctx = NULL; DSA *dsa = NULL; diff --git a/lib/libcrypto/ec/ec_ameth.c b/lib/libcrypto/ec/ec_ameth.c index 4c4542dee58..0071826deaa 100644 --- a/lib/libcrypto/ec/ec_ameth.c +++ b/lib/libcrypto/ec/ec_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_ameth.c,v 1.23 2018/07/15 16:27:39 tb Exp $ */ +/* $OpenBSD: ec_ameth.c,v 1.24 2018/08/24 20:17:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -238,7 +238,7 @@ eckey_priv_decode(EVP_PKEY * pkey, PKCS8_PRIV_KEY_INFO * p8) 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/lib/libcrypto/evp/evp_pkey.c b/lib/libcrypto/evp/evp_pkey.c index aa075d63925..68948f5fa6d 100644 --- a/lib/libcrypto/evp/evp_pkey.c +++ b/lib/libcrypto/evp/evp_pkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: evp_pkey.c,v 1.21 2018/08/24 20:07:41 tb Exp $ */ +/* $OpenBSD: evp_pkey.c,v 1.22 2018/08/24 20:17:33 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 1999. */ @@ -70,7 +70,7 @@ EVP_PKEY * EVP_PKCS82PKEY(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/lib/libcrypto/gost/gostr341001_ameth.c b/lib/libcrypto/gost/gostr341001_ameth.c index 086e371057e..9b17b2e2c7e 100644 --- a/lib/libcrypto/gost/gostr341001_ameth.c +++ b/lib/libcrypto/gost/gostr341001_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gostr341001_ameth.c,v 1.13 2018/06/10 14:39:49 jsing Exp $ */ +/* $OpenBSD: gostr341001_ameth.c,v 1.14 2018/08/24 20:17:33 tb Exp $ */ /* * Copyright (c) 2014 Dmitry Eremin-Solenikov * Copyright (c) 2005-2006 Cryptocom LTD @@ -400,8 +400,8 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf) int priv_len = 0; BIGNUM *pk_num = NULL; int ret = 0; - X509_ALGOR *palg = NULL; - ASN1_OBJECT *palg_obj = NULL; + const X509_ALGOR *palg = NULL; + const ASN1_OBJECT *palg_obj = NULL; ASN1_INTEGER *priv_key = NULL; GOST_KEY *ec; int ptype = V_ASN1_UNDEF; diff --git a/lib/libcrypto/x509/x509.h b/lib/libcrypto/x509/x509.h index 6c1f8eb6e94..ab1f9b46b18 100644 --- a/lib/libcrypto/x509/x509.h +++ b/lib/libcrypto/x509/x509.h @@ -1,4 +1,4 @@ -/* $OpenBSD: x509.h,v 1.72 2018/08/24 20:07:42 tb Exp $ */ +/* $OpenBSD: x509.h,v 1.73 2018/08/24 20:17:33 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1290,13 +1290,10 @@ extern const ASN1_ITEM PKCS8_PRIV_KEY_INFO_it; EVP_PKEY *EVP_PKCS82PKEY(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, - const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, - PKCS8_PRIV_KEY_INFO *p8); +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(const ASN1_OBJECT **ppkalg, const unsigned char **pk, + int *ppklen, 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); int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, -- 2.20.1