summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid von Oheimb <David.von.Oheimb@siemens.com>2019-01-15 21:51:25 +0100
committerMatt Caswell <matt@openssl.org>2019-03-06 16:10:09 +0000
commit9fdcc21fdc9d148f78d9cd5be34030f38cc45812 (patch)
tree20cba464edf2befc97c1888631dd782cba830c89
parent27d5631236325c3fd8a3bd06af282ac496aac64b (diff)
constify *_dup() and *i2d_*() and related functions as far as possible, introducing DECLARE_ASN1_DUP_FUNCTION
Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/8029)
-rw-r--r--crypto/asn1/a_dup.c4
-rw-r--r--crypto/asn1/a_i2d_fp.c8
-rw-r--r--crypto/asn1/asn1_locl.h10
-rw-r--r--crypto/asn1/asn_mime.c2
-rw-r--r--crypto/asn1/bio_ndef.c1
-rw-r--r--crypto/asn1/i2d_pr.c2
-rw-r--r--crypto/asn1/i2d_pu.c2
-rw-r--r--crypto/asn1/n_pkey.c12
-rw-r--r--crypto/asn1/tasn_dec.c6
-rw-r--r--crypto/asn1/tasn_enc.c90
-rw-r--r--crypto/asn1/tasn_fre.c2
-rw-r--r--crypto/asn1/tasn_prn.c52
-rw-r--r--crypto/asn1/tasn_typ.c4
-rw-r--r--crypto/asn1/tasn_utl.c82
-rw-r--r--crypto/asn1/x_bignum.c8
-rw-r--r--crypto/asn1/x_int64.c16
-rw-r--r--crypto/asn1/x_long.c8
-rw-r--r--crypto/cms/cms_dd.c4
-rw-r--r--crypto/cms/cms_enc.c2
-rw-r--r--crypto/cms/cms_env.c8
-rw-r--r--crypto/cms/cms_io.c1
-rw-r--r--crypto/cms/cms_kari.c2
-rw-r--r--crypto/cms/cms_lcl.h14
-rw-r--r--crypto/cms/cms_lib.c1
-rw-r--r--crypto/cms/cms_pwri.c2
-rw-r--r--crypto/dh/dh_ameth.c2
-rw-r--r--crypto/dh/dh_asn1.c4
-rw-r--r--crypto/dh/dh_pmeth.c2
-rw-r--r--crypto/dsa/dsa_asn1.c10
-rw-r--r--crypto/dsa/dsa_pmeth.c2
-rw-r--r--crypto/ec/ec_asn1.c22
-rw-r--r--crypto/ec/ec_pmeth.c2
-rw-r--r--crypto/ess/ess_asn1.c10
-rw-r--r--crypto/evp/encode.c2
-rw-r--r--crypto/evp/evp_pkey.c2
-rw-r--r--crypto/evp/mac_lib.c2
-rw-r--r--crypto/evp/p_lib.c8
-rw-r--r--crypto/evp/pkey_mac.c2
-rw-r--r--crypto/evp/pmeth_lib.c8
-rw-r--r--crypto/include/internal/evp_int.h2
-rw-r--r--crypto/ocsp/v3_ocsp.c6
-rw-r--r--crypto/pem/pem_pk8.c24
-rw-r--r--crypto/pkcs12/p12_utl.c4
-rw-r--r--crypto/pkcs7/pk7_lib.c1
-rw-r--r--crypto/rsa/rsa_asn1.c8
-rw-r--r--crypto/rsa/rsa_pmeth.c2
-rw-r--r--crypto/sm2/sm2_pmeth.c2
-rw-r--r--crypto/ts/ts_asn1.c44
-rw-r--r--crypto/x509/x_all.c68
-rw-r--r--crypto/x509/x_name.c27
-rw-r--r--crypto/x509/x_pubkey.c36
-rw-r--r--crypto/x509/x_x509.c5
-rw-r--r--crypto/x509v3/v3_genn.c2
-rw-r--r--doc/man3/ASN1_STRING_length.pod2
-rw-r--r--doc/man3/EVP_PKEY_CTX_ctrl.pod3
-rw-r--r--doc/man3/EVP_PKEY_CTX_new.pod2
-rw-r--r--doc/man3/EVP_PKEY_set1_RSA.pod8
-rw-r--r--doc/man3/PEM_read_bio_PrivateKey.pod7
-rw-r--r--doc/man3/SSL_SESSION_free.pod2
-rw-r--r--doc/man3/SSL_new.pod3
-rw-r--r--doc/man3/X509_PUBKEY_new.pod6
-rw-r--r--doc/man3/X509_dup.pod4
-rw-r--r--doc/man3/d2i_PKCS8PrivateKey_bio.pod8
-rw-r--r--doc/man3/d2i_PrivateKey.pod4
-rw-r--r--doc/man3/d2i_X509.pod3
-rw-r--r--include/openssl/asn1.h105
-rw-r--r--include/openssl/asn1t.h75
-rw-r--r--include/openssl/cms.h2
-rw-r--r--include/openssl/dh.h12
-rw-r--r--include/openssl/dsa.h17
-rw-r--r--include/openssl/ec.h15
-rw-r--r--include/openssl/ess.h47
-rw-r--r--include/openssl/evp.h54
-rw-r--r--include/openssl/objects.h2
-rw-r--r--include/openssl/ocsp.h2
-rw-r--r--include/openssl/pem.h16
-rw-r--r--include/openssl/pkcs12.h4
-rw-r--r--include/openssl/pkcs7.h6
-rw-r--r--include/openssl/rsa.h8
-rw-r--r--include/openssl/ssl.h4
-rw-r--r--include/openssl/ts.h78
-rw-r--r--include/openssl/x509.h98
-rw-r--r--include/openssl/x509v3.h4
-rw-r--r--ssl/ssl_asn1.c10
-rw-r--r--ssl/ssl_locl.h2
-rw-r--r--ssl/ssl_sess.c4
-rw-r--r--test/x509aux.c2
-rw-r--r--util/perl/OpenSSL/ParseC.pm60
88 files changed, 680 insertions, 651 deletions
diff --git a/crypto/asn1/a_dup.c b/crypto/asn1/a_dup.c
index 4d22168714..b5df08e3e2 100644
--- a/crypto/asn1/a_dup.c
+++ b/crypto/asn1/a_dup.c
@@ -13,7 +13,7 @@
#ifndef NO_OLD_ASN1
-void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
+void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, const void *x)
{
unsigned char *b, *p;
const unsigned char *p2;
@@ -46,7 +46,7 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
* decode.
*/
-void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
+void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
{
unsigned char *b = NULL;
const unsigned char *p;
diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c
index 2527c25ae1..e718bf4cb1 100644
--- a/crypto/asn1/a_i2d_fp.c
+++ b/crypto/asn1/a_i2d_fp.c
@@ -15,7 +15,7 @@
#ifndef NO_OLD_ASN1
# ifndef OPENSSL_NO_STDIO
-int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
+int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, const void *x)
{
BIO *b;
int ret;
@@ -31,7 +31,7 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
}
# endif
-int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
+int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, const void *x)
{
char *b;
unsigned char *p;
@@ -68,7 +68,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
#endif
#ifndef OPENSSL_NO_STDIO
-int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
+int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, const void *x)
{
BIO *b;
int ret;
@@ -84,7 +84,7 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
}
#endif
-int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
+int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x)
{
unsigned char *b = NULL;
int i, j = 0, n, ret = 1;
diff --git a/crypto/asn1/asn1_locl.h b/crypto/asn1/asn1_locl.h
index e3221d6f9f..5720c9096a 100644
--- a/crypto/asn1/asn1_locl.h
+++ b/crypto/asn1/asn1_locl.h
@@ -9,6 +9,9 @@
/* Internal ASN1 structures and functions: not for application use */
+typedef const ASN1_VALUE const_ASN1_VALUE;
+SKM_DEFINE_STACK_OF(const_ASN1_VALUE, const ASN1_VALUE, ASN1_VALUE)
+
int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d);
int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d);
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d);
@@ -46,19 +49,22 @@ DEFINE_STACK_OF(MIME_HEADER)
void asn1_string_embed_free(ASN1_STRING *a, int embed);
int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
+int asn1_get_choice_selector_const(const ASN1_VALUE **pval, const ASN1_ITEM *it);
int asn1_set_choice_selector(ASN1_VALUE **pval, int value,
const ASN1_ITEM *it);
ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
+const ASN1_VALUE **asn1_get_const_field_ptr(const ASN1_VALUE **pval,
+ const ASN1_TEMPLATE *tt);
-const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
+const ASN1_TEMPLATE *asn1_do_adb(const ASN1_VALUE *val, const ASN1_TEMPLATE *tt,
int nullerr);
int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
-int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
+int asn1_enc_restore(int *len, unsigned char **out, const ASN1_VALUE **pval,
const ASN1_ITEM *it);
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
const ASN1_ITEM *it);
diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c
index d99f0ef31d..5c3493832b 100644
--- a/crypto/asn1/asn_mime.c
+++ b/crypto/asn1/asn_mime.c
@@ -64,6 +64,7 @@ static void mime_hdr_free(MIME_HEADER *hdr);
/* Output an ASN1 structure in BER format streaming if necessary */
+/* unfortunately cannot constify this due to CMS_stream() and PKCS7_stream() */
int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
const ASN1_ITEM *it)
{
@@ -311,6 +312,7 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
/* Handle output of ASN1 data */
+/* cannot constify val because of CMS_dataFinal() */
static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
const ASN1_ITEM *it)
{
diff --git a/crypto/asn1/bio_ndef.c b/crypto/asn1/bio_ndef.c
index 015c54dfcf..d3be967f04 100644
--- a/crypto/asn1/bio_ndef.c
+++ b/crypto/asn1/bio_ndef.c
@@ -49,6 +49,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg);
static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen,
void *parg);
+/* unfortunately cannot constify this due to CMS_stream() and PKCS7_stream() */
BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
{
NDEF_SUPPORT *ndef_aux = NULL;
diff --git a/crypto/asn1/i2d_pr.c b/crypto/asn1/i2d_pr.c
index e8b1dd214c..7133d3da9c 100644
--- a/crypto/asn1/i2d_pr.c
+++ b/crypto/asn1/i2d_pr.c
@@ -14,7 +14,7 @@
#include "internal/asn1_int.h"
#include "internal/evp_int.h"
-int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
+int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp)
{
if (a->ameth && a->ameth->old_priv_encode) {
return a->ameth->old_priv_encode(a, pp);
diff --git a/crypto/asn1/i2d_pu.c b/crypto/asn1/i2d_pu.c
index ff15282202..8195dda881 100644
--- a/crypto/asn1/i2d_pu.c
+++ b/crypto/asn1/i2d_pu.c
@@ -16,7 +16,7 @@
#include <openssl/dsa.h>
#include <openssl/ec.h>
-int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
+int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp)
{
switch (EVP_PKEY_id(a)) {
#ifndef OPENSSL_NO_RSA
diff --git a/crypto/asn1/n_pkey.c b/crypto/asn1/n_pkey.c
index 3c83e4bf05..12592d09c9 100644
--- a/crypto/asn1/n_pkey.c
+++ b/crypto/asn1/n_pkey.c
@@ -43,9 +43,9 @@ ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG)
} static_ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY)
-DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
-DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY)
-IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY)
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_ENCRYPTED_PKEY)
+DECLARE_ASN1_ENCODE_FUNCTIONS_name(NETSCAPE_ENCRYPTED_PKEY, NETSCAPE_ENCRYPTED_PKEY)
+IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_ENCRYPTED_PKEY)
ASN1_SEQUENCE(NETSCAPE_PKEY) = {
ASN1_EMBED(NETSCAPE_PKEY, version, INT32),
@@ -53,9 +53,9 @@ ASN1_SEQUENCE(NETSCAPE_PKEY) = {
ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING)
} static_ASN1_SEQUENCE_END(NETSCAPE_PKEY)
-DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
-DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
-IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
+DECLARE_ASN1_FUNCTIONS(NETSCAPE_PKEY)
+DECLARE_ASN1_ENCODE_FUNCTIONS_name(NETSCAPE_PKEY, NETSCAPE_PKEY)
+IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_PKEY)
# endif /* OPENSSL_NO_RC4 */
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index 03d02b7ac6..87c01f0beb 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -316,7 +316,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
if (tt->flags & ASN1_TFLG_ADB_MASK) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
- seqtt = asn1_do_adb(pval, tt, 0);
+ seqtt = asn1_do_adb(*pval, tt, 0);
if (seqtt == NULL)
continue;
pseqval = asn1_get_field_ptr(pval, seqtt);
@@ -328,7 +328,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
- seqtt = asn1_do_adb(pval, tt, 1);
+ seqtt = asn1_do_adb(*pval, tt, 1);
if (seqtt == NULL)
goto err;
pseqval = asn1_get_field_ptr(pval, seqtt);
@@ -394,7 +394,7 @@ static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
*/
for (; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
- seqtt = asn1_do_adb(pval, tt, 1);
+ seqtt = asn1_do_adb(*pval, tt, 1);
if (seqtt == NULL)
goto err;
if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index 411b53e062..8ab9c370fd 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -16,16 +16,17 @@
#include "internal/asn1_int.h"
#include "asn1_locl.h"
-static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
+static int asn1_i2d_ex_primitive(const ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass);
-static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
+static int asn1_set_seq_out(STACK_OF(const_ASN1_VALUE) *sk,
+ unsigned char **out,
int skcontlen, const ASN1_ITEM *item,
int do_sort, int iclass);
-static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
+static int asn1_template_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *tt, int tag, int aclass);
-static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
+static int asn1_item_flags_i2d(const ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags);
-static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
+static int asn1_ex_i2c(const ASN1_VALUE **pval, unsigned char *cout, int *putype,
const ASN1_ITEM *it);
/*
@@ -33,13 +34,13 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
* indefinite length constructed encoding, where appropriate
*/
-int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
+int ASN1_item_ndef_i2d(const ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it)
{
return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
}
-int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
+int ASN1_item_i2d(const ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
{
return asn1_item_flags_i2d(val, out, it, 0);
}
@@ -51,7 +52,7 @@ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
* allocated and populated with the encoding.
*/
-static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
+static int asn1_item_flags_i2d(const ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags)
{
if (out && !*out) {
@@ -79,20 +80,22 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
* performs the normal item handling: it can be used in external types.
*/
-int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
+int ASN1_item_ex_i2d(const ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass)
{
const ASN1_TEMPLATE *tt = NULL;
int i, seqcontlen, seqlen, ndef = 1;
const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs;
- ASN1_aux_cb *asn1_cb = 0;
+ ASN1_aux_const_cb *asn1_cb = NULL;
if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
return 0;
- if (aux && aux->asn1_cb)
- asn1_cb = aux->asn1_cb;
+ if (aux != NULL) {
+ asn1_cb = ((aux->flags & ASN1_AFLG_CONST_CB) != 0) ? aux->asn1_const_cb
+ : (ASN1_aux_const_cb *)aux->asn1_cb; /* backward compatibility */
+ }
switch (it->itype) {
@@ -108,12 +111,12 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
case ASN1_ITYPE_CHOICE:
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
return