summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c6
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c4
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c8
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c33
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c6
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c10
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c10
-rw-r--r--src/lib/libcrypto/asn1/a_int.c14
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c30
-rw-r--r--src/lib/libcrypto/asn1/a_object.c29
-rw-r--r--src/lib/libcrypto/asn1/a_set.c17
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c14
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c10
-rw-r--r--src/lib/libcrypto/asn1/a_time_tm.c5
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c27
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c124
-rw-r--r--src/lib/libcrypto/asn1/asn1_gen.c76
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c10
-rw-r--r--src/lib/libcrypto/asn1/asn_mime.c46
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c6
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c24
-rw-r--r--src/lib/libcrypto/asn1/bio_ndef.c4
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c11
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c14
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c7
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c13
-rw-r--r--src/lib/libcrypto/asn1/f_int.c13
-rw-r--r--src/lib/libcrypto/asn1/f_string.c13
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c4
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c4
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c24
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c12
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c12
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/t_req.c6
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c6
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c146
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c8
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c5
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/x_info.c4
-rw-r--r--src/lib/libcrypto/asn1/x_long.c6
-rw-r--r--src/lib/libcrypto/asn1/x_name.c8
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c8
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c25
-rw-r--r--src/lib/libcrypto/bio/b_sock.c34
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c4
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c4
-rw-r--r--src/lib/libcrypto/bio/bio_err.c36
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c24
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c8
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c24
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c30
-rw-r--r--src/lib/libcrypto/bio/bss_file.c18
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c8
-rw-r--r--src/lib/libcrypto/bn/bn_add.c4
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c13
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c8
-rw-r--r--src/lib/libcrypto/bn/bn_div.c6
-rw-r--r--src/lib/libcrypto/bn/bn_err.c44
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c19
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c4
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c6
-rw-r--r--src/lib/libcrypto/bn/bn_gf2m.c19
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c11
-rw-r--r--src/lib/libcrypto/bn/bn_mod.c4
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c6
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c4
-rw-r--r--src/lib/libcrypto/bn/bn_print.c8
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c14
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c4
-rw-r--r--src/lib/libcrypto/bn/bn_sqrt.c14
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c9
-rw-r--r--src/lib/libcrypto/buffer/buf_str.c8
-rw-r--r--src/lib/libcrypto/buffer/buffer.c12
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c17
-rw-r--r--src/lib/libcrypto/comp/comp_err.c7
-rw-r--r--src/lib/libcrypto/conf/conf_def.c47
-rw-r--r--src/lib/libcrypto/conf/conf_err.c25
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c31
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c15
-rw-r--r--src/lib/libcrypto/cryptlib.c18
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c30
-rw-r--r--src/lib/libcrypto/dh/dh_err.c27
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c6
-rw-r--r--src/lib/libcrypto/dh/dh_key.c12
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c8
-rw-r--r--src/lib/libcrypto/dh/dh_pmeth.c6
-rw-r--r--src/lib/libcrypto/dh/dh_prn.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_ameth.c46
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c35
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c8
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c16
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c11
-rw-r--r--src/lib/libcrypto/dsa/dsa_prn.c6
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c40
-rw-r--r--src/lib/libcrypto/dso/dso_err.c52
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c71
-rw-r--r--src/lib/libcrypto/ec/ec2_mult.c4
-rw-r--r--src/lib/libcrypto/ec/ec2_oct.c38
-rw-r--r--src/lib/libcrypto/ec/ec2_smpl.c12
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c44
-rw-r--r--src/lib/libcrypto/ec/ec_asn1.c220
-rw-r--r--src/lib/libcrypto/ec/ec_check.c14
-rw-r--r--src/lib/libcrypto/ec/ec_curve.c26
-rw-r--r--src/lib/libcrypto/ec/ec_err.c142
-rw-r--r--src/lib/libcrypto/ec/ec_key.c32
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c98
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c60
-rw-r--r--src/lib/libcrypto/ec/ec_oct.c24
-rw-r--r--src/lib/libcrypto/ec/ec_pmeth.c16
-rw-r--r--src/lib/libcrypto/ec/eck_prn.c10
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c14
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c8
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp224.c30
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp256.c30
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp521.c28
-rw-r--r--src/lib/libcrypto/ec/ecp_nistz256.c43
-rw-r--r--src/lib/libcrypto/ec/ecp_oct.c44
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c16
-rw-r--r--src/lib/libcrypto/ecdh/ech_err.c6
-rw-r--r--src/lib/libcrypto/ecdh/ech_key.c27
-rw-r--r--src/lib/libcrypto/ecdh/ech_lib.c6
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_err.c8
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_lib.c7
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c85
-rw-r--r--src/lib/libcrypto/engine/eng_aesni.c4
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c14
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c54
-rw-r--r--src/lib/libcrypto/engine/eng_err.c42
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c5
-rw-r--r--src/lib/libcrypto/engine/eng_init.c11
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c13
-rw-r--r--src/lib/libcrypto/engine/eng_list.c48
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c35
-rw-r--r--src/lib/libcrypto/engine/eng_table.c5
-rw-r--r--src/lib/libcrypto/engine/tb_asnmth.c5
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c5
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c5
-rw-r--r--src/lib/libcrypto/engine/tb_pkmeth.c5
-rw-r--r--src/lib/libcrypto/err/err.c4
-rw-r--r--src/lib/libcrypto/err/err.h40
-rw-r--r--src/lib/libcrypto/evp/digest.c29
-rw-r--r--src/lib/libcrypto/evp/e_aes.c18
-rw-r--r--src/lib/libcrypto/evp/e_camellia.c5
-rw-r--r--src/lib/libcrypto/evp/e_chacha20poly1305.c22
-rw-r--r--src/lib/libcrypto/evp/e_gost2814789.c18
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c7
-rw-r--r--src/lib/libcrypto/evp/evp_aead.c10
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c59
-rw-r--r--src/lib/libcrypto/evp/evp_err.c99
-rw-r--r--src/lib/libcrypto/evp/evp_key.c6
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c10
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c17
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c25
-rw-r--r--src/lib/libcrypto/evp/m_sigver.c4
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c13
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c36
-rw-r--r--src/lib/libcrypto/evp/p_dec.c4
-rw-r--r--src/lib/libcrypto/evp/p_enc.c4
-rw-r--r--src/lib/libcrypto/evp/p_lib.c20
-rw-r--r--src/lib/libcrypto/evp/p_open.c6
-rw-r--r--src/lib/libcrypto/evp/p_sign.c6
-rw-r--r--src/lib/libcrypto/evp/p_verify.c7
-rw-r--r--src/lib/libcrypto/evp/pmeth_fn.c67
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c18
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c24
-rw-r--r--src/lib/libcrypto/ex_data.c20
-rw-r--r--src/lib/libcrypto/gost/gost89imit_pmeth.c18
-rw-r--r--src/lib/libcrypto/gost/gost_err.c35
-rw-r--r--src/lib/libcrypto/gost/gostr341001.c33
-rw-r--r--src/lib/libcrypto/gost/gostr341001_ameth.c59
-rw-r--r--src/lib/libcrypto/gost/gostr341001_key.c29
-rw-r--r--src/lib/libcrypto/gost/gostr341001_pmeth.c52
-rw-r--r--src/lib/libcrypto/hmac/hmac.c7
-rw-r--r--src/lib/libcrypto/objects/o_names.c6
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c18
-rw-r--r--src/lib/libcrypto/objects/obj_err.c10
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c6
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_cl.c29
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_err.c22
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ht.c13
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_lib.c12
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_srv.c8
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_vfy.c46
-rw-r--r--src/lib/libcrypto/pem/pem_err.c43
-rw-r--r--src/lib/libcrypto/pem/pem_info.c25
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c69
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c4
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c13
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c13
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c10
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c4
-rw-r--r--src/lib/libcrypto/pem/pvkfmt.c68
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c40
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c12
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c5
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c27
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c9
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c6
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c14
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c35
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c9
-rw-r--r--src/lib/libcrypto/pkcs12/p12_p8e.c8
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c12
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c134
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c61
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c81
-rw-r--r--src/lib/libcrypto/rand/rand_err.c6
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c32
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c23
-rw-r--r--src/lib/libcrypto/rsa/rsa_crpt.c7
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c72
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c61
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c7
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c10
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c18
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c35
-rw-r--r--src/lib/libcrypto/rsa/rsa_pmeth.c33
-rw-r--r--src/lib/libcrypto/rsa/rsa_prn.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_pss.c32
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c16
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c32
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c18
-rw-r--r--src/lib/libcrypto/rsa/rsa_x931.c15
-rw-r--r--src/lib/libcrypto/ts/ts_asn1.c17
-rw-r--r--src/lib/libcrypto/ts/ts_conf.c5
-rw-r--r--src/lib/libcrypto/ts/ts_err.c54
-rw-r--r--src/lib/libcrypto/ts/ts_req_utils.c10
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_sign.c62
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_utils.c26
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_verify.c42
-rw-r--r--src/lib/libcrypto/ts/ts_verify_ctx.c4
-rw-r--r--src/lib/libcrypto/ui/ui_err.c15
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c52
-rw-r--r--src/lib/libcrypto/x509/by_dir.c24
-rw-r--r--src/lib/libcrypto/x509/by_file.c27
-rw-r--r--src/lib/libcrypto/x509/by_mem.c4
-rw-r--r--src/lib/libcrypto/x509/x509_att.c22
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c11
-rw-r--r--src/lib/libcrypto/x509/x509_err.c48
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c21
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c4
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c4
-rw-r--r--src/lib/libcrypto/x509/x509_req.c19
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c10
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c12
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c48
-rw-r--r--src/lib/libcrypto/x509/x509name.c13
-rw-r--r--src/lib/libcrypto/x509/x509spki.c9
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c17
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c49
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c7
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c37
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c49
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c20
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c11
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c9
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c23
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c16
-rw-r--r--src/lib/libcrypto/x509v3/v3_ncons.c7
-rw-r--r--src/lib/libcrypto/x509v3/v3_ocsp.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_pci.c52
-rw-r--r--src/lib/libcrypto/x509v3/v3_pcons.c11
-rw-r--r--src/lib/libcrypto/x509v3/v3_pmaps.c6
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c12
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c12
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c23
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c48
-rw-r--r--src/lib/libssl/bio_ssl.c4
-rw-r--r--src/lib/libssl/ssl_cert.c4
275 files changed, 2400 insertions, 3892 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index c847b471d6..9ba77d6958 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_bitstr.c,v 1.23 2015/09/29 13:54:40 jsing Exp $ */ 1/* $OpenBSD: a_bitstr.c,v 1.24 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -176,7 +176,7 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len)
176 return (ret); 176 return (ret);
177 177
178err: 178err:
179 ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i); 179 ASN1error(i);
180 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 180 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
181 ASN1_BIT_STRING_free(ret); 181 ASN1_BIT_STRING_free(ret);
182 return (NULL); 182 return (NULL);
@@ -206,7 +206,7 @@ ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
206 return(1); /* Don't need to set */ 206 return(1); /* Don't need to set */
207 c = OPENSSL_realloc_clean(a->data, a->length, w + 1); 207 c = OPENSSL_realloc_clean(a->data, a->length, w + 1);
208 if (c == NULL) { 208 if (c == NULL) {
209 ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE); 209 ASN1error(ERR_R_MALLOC_FAILURE);
210 return 0; 210 return 0;
211 } 211 }
212 if (w + 1 - a->length > 0) 212 if (w + 1 - a->length > 0)
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
index d5a0c0c8a4..e8469bec65 100644
--- a/src/lib/libcrypto/asn1/a_bool.c
+++ b/src/lib/libcrypto/asn1/a_bool.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_bool.c,v 1.7 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: a_bool.c,v 1.8 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,6 +110,6 @@ d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)
110 return (ret); 110 return (ret);
111 111
112err: 112err:
113 ASN1err(ASN1_F_D2I_ASN1_BOOLEAN, i); 113 ASN1error(i);
114 return (ret); 114 return (ret);
115} 115}
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
index 727ad3ed9b..f3fe234851 100644
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_bytes.c,v 1.18 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: a_bytes.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -123,7 +123,7 @@ d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
123 return (ret); 123 return (ret);
124 124
125err: 125err:
126 ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES, i); 126 ASN1error(i);
127 if (a == NULL || *a != ret) 127 if (a == NULL || *a != ret)
128 ASN1_STRING_free(ret); 128 ASN1_STRING_free(ret);
129 return (NULL); 129 return (NULL);
@@ -235,7 +235,7 @@ d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
235err: 235err:
236 if (a == NULL || *a != ret) 236 if (a == NULL || *a != ret)
237 ASN1_STRING_free(ret); 237 ASN1_STRING_free(ret);
238 ASN1err(ASN1_F_D2I_ASN1_BYTES, i); 238 ASN1error(i);
239 return (NULL); 239 return (NULL);
240} 240}
241 241
@@ -299,7 +299,7 @@ asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
299 return (1); 299 return (1);
300 300
301err: 301err:
302 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE, c->error); 302 ASN1error(c->error);
303 ASN1_STRING_free(os); 303 ASN1_STRING_free(os);
304 free(b.data); 304 free(b.data);
305 return (0); 305 return (0);
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
index c00b304c61..390a1072d5 100644
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ b/src/lib/libcrypto/asn1/a_d2i_fp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_d2i_fp.c,v 1.15 2016/05/20 15:46:21 bcook Exp $ */ 1/* $OpenBSD: a_d2i_fp.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -74,7 +74,7 @@ ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x)
74 void *ret; 74 void *ret;
75 75
76 if ((b = BIO_new(BIO_s_file())) == NULL) { 76 if ((b = BIO_new(BIO_s_file())) == NULL) {
77 ASN1err(ASN1_F_ASN1_D2I_FP, ERR_R_BUF_LIB); 77 ASN1error(ERR_R_BUF_LIB);
78 return (NULL); 78 return (NULL);
79 } 79 }
80 BIO_set_fp(b, in, BIO_NOCLOSE); 80 BIO_set_fp(b, in, BIO_NOCLOSE);
@@ -134,7 +134,7 @@ ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
134 char *ret; 134 char *ret;
135 135
136 if ((b = BIO_new(BIO_s_file())) == NULL) { 136 if ((b = BIO_new(BIO_s_file())) == NULL) {
137 ASN1err(ASN1_F_ASN1_ITEM_D2I_FP, ERR_R_BUF_LIB); 137 ASN1error(ERR_R_BUF_LIB);
138 return (NULL); 138 return (NULL);
139 } 139 }
140 BIO_set_fp(b, in, BIO_NOCLOSE); 140 BIO_set_fp(b, in, BIO_NOCLOSE);
@@ -159,7 +159,7 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
159 159
160 b = BUF_MEM_new(); 160 b = BUF_MEM_new();
161 if (b == NULL) { 161 if (b == NULL) {
162 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); 162 ASN1error(ERR_R_MALLOC_FAILURE);
163 return -1; 163 return -1;
164 } 164 }
165 165
@@ -170,20 +170,17 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
170 170
171 if (len + want < len || 171 if (len + want < len ||
172 !BUF_MEM_grow_clean(b, len + want)) { 172 !BUF_MEM_grow_clean(b, len + want)) {
173 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 173 ASN1error(ERR_R_MALLOC_FAILURE);
174 ERR_R_MALLOC_FAILURE);
175 goto err; 174 goto err;
176 } 175 }
177 i = BIO_read(in, &(b->data[len]), want); 176 i = BIO_read(in, &(b->data[len]), want);
178 if ((i < 0) && ((len - off) == 0)) { 177 if ((i < 0) && ((len - off) == 0)) {
179 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 178 ASN1error(ASN1_R_NOT_ENOUGH_DATA);
180 ASN1_R_NOT_ENOUGH_DATA);
181 goto err; 179 goto err;
182 } 180 }
183 if (i > 0) { 181 if (i > 0) {
184 if (len + i < len) { 182 if (len + i < len) {
185 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 183 ASN1error(ASN1_R_TOO_LONG);
186 ASN1_R_TOO_LONG);
187 goto err; 184 goto err;
188 } 185 }
189 len += i; 186 len += i;
@@ -211,8 +208,7 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
211 /* no data body so go round again */ 208 /* no data body so go round again */
212 eos++; 209 eos++;
213 if (eos < 0) { 210 if (eos < 0) {
214 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 211 ASN1error(ASN1_R_HEADER_TOO_LONG);
215 ASN1_R_HEADER_TOO_LONG);
216 goto err; 212 goto err;
217 } 213 }
218 want = HEADER_SIZE; 214 want = HEADER_SIZE;
@@ -232,8 +228,7 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
232 want -= (len - off); 228 want -= (len - off);
233 if (want > INT_MAX /* BIO_read takes an int length */ || 229 if (want > INT_MAX /* BIO_read takes an int length */ ||
234 len+want < len) { 230 len+want < len) {
235 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 231 ASN1error(ASN1_R_TOO_LONG);
236 ASN1_R_TOO_LONG);
237 goto err; 232 goto err;
238 } 233 }
239 while (want > 0) { 234 while (want > 0) {
@@ -246,16 +241,14 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
246 size_t chunk = want > chunk_max ? chunk_max : want; 241 size_t chunk = want > chunk_max ? chunk_max : want;
247 242
248 if (!BUF_MEM_grow_clean(b, len + chunk)) { 243 if (!BUF_MEM_grow_clean(b, len + chunk)) {
249 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 244 ASN1error(ERR_R_MALLOC_FAILURE);
250 ERR_R_MALLOC_FAILURE);
251 goto err; 245 goto err;
252 } 246 }
253 want -= chunk; 247 want -= chunk;
254 while (chunk > 0) { 248 while (chunk > 0) {
255 i = BIO_read(in, &(b->data[len]), chunk); 249 i = BIO_read(in, &(b->data[len]), chunk);
256 if (i <= 0) { 250 if (i <= 0) {
257 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 251 ASN1error(ASN1_R_NOT_ENOUGH_DATA);
258 ASN1_R_NOT_ENOUGH_DATA);
259 goto err; 252 goto err;
260 } 253 }
261 /* 254 /*
@@ -270,7 +263,7 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
270 } 263 }
271 } 264 }
272 if (off + c.slen < off) { 265 if (off + c.slen < off) {
273 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); 266 ASN1error(ASN1_R_TOO_LONG);
274 goto err; 267 goto err;
275 } 268 }
276 off += c.slen; 269 off += c.slen;
@@ -282,7 +275,7 @@ asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
282 } 275 }
283 276
284 if (off > INT_MAX) { 277 if (off > INT_MAX) {
285 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); 278 ASN1error(ASN1_R_TOO_LONG);
286 goto err; 279 goto err;
287 } 280 }
288 281
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
index 79cd1d4586..2e17a1e219 100644
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_dup.c,v 1.13 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: a_dup.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -77,7 +77,7 @@ ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
77 i = i2d(x, NULL); 77 i = i2d(x, NULL);
78 b = malloc(i + 10); 78 b = malloc(i + 10);
79 if (b == NULL) { 79 if (b == NULL) {
80 ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE); 80 ASN1error(ERR_R_MALLOC_FAILURE);
81 return (NULL); 81 return (NULL);
82 } 82 }
83 p = b; 83 p = b;
@@ -108,7 +108,7 @@ ASN1_item_dup(const ASN1_ITEM *it, void *x)
108 108
109 i = ASN1_item_i2d(x, &b, it); 109 i = ASN1_item_i2d(x, &b, it);
110 if (b == NULL) { 110 if (b == NULL) {
111 ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE); 111 ASN1error(ERR_R_MALLOC_FAILURE);
112 return (NULL); 112 return (NULL);
113 } 113 }
114 p = b; 114 p = b;
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index 142f6ed575..23875958bf 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_enum.c,v 1.17 2015/09/30 18:45:56 jsing Exp $ */ 1/* $OpenBSD: a_enum.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -81,7 +81,7 @@ ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
81 a->data = calloc(1, sizeof(long) + 1); 81 a->data = calloc(1, sizeof(long) + 1);
82 } 82 }
83 if (a->data == NULL) { 83 if (a->data == NULL) {
84 ASN1err(ASN1_F_ASN1_ENUMERATED_SET, ERR_R_MALLOC_FAILURE); 84 ASN1error(ERR_R_MALLOC_FAILURE);
85 return (0); 85 return (0);
86 } 86 }
87 d = v; 87 d = v;
@@ -144,7 +144,7 @@ BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
144 else 144 else
145 ret = ai; 145 ret = ai;
146 if (ret == NULL) { 146 if (ret == NULL) {
147 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_NESTED_ASN1_ERROR); 147 ASN1error(ERR_R_NESTED_ASN1_ERROR);
148 goto err; 148 goto err;
149 } 149 }
150 if (BN_is_negative(bn)) 150 if (BN_is_negative(bn))
@@ -156,7 +156,7 @@ BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
156 if (ret->length < len + 4) { 156 if (ret->length < len + 4) {
157 unsigned char *new_data = realloc(ret->data, len + 4); 157 unsigned char *new_data = realloc(ret->data, len + 4);
158 if (!new_data) { 158 if (!new_data) {
159 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); 159 ASN1error(ERR_R_MALLOC_FAILURE);
160 goto err; 160 goto err;
161 } 161 }
162 ret->data = new_data; 162 ret->data = new_data;
@@ -182,7 +182,7 @@ ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
182 BIGNUM *ret; 182 BIGNUM *ret;
183 183
184 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL) 184 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
185 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN, ASN1_R_BN_LIB); 185 ASN1error(ASN1_R_BN_LIB);
186 else if (ai->type == V_ASN1_NEG_ENUMERATED) 186 else if (ai->type == V_ASN1_NEG_ENUMERATED)
187 BN_set_negative(ret, 1); 187 BN_set_negative(ret, 1);
188 return (ret); 188 return (ret);
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
index 424068d784..6398978aac 100644
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_i2d_fp.c,v 1.14 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: a_i2d_fp.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -71,7 +71,7 @@ ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
71 int ret; 71 int ret;
72 72
73 if ((b = BIO_new(BIO_s_file())) == NULL) { 73 if ((b = BIO_new(BIO_s_file())) == NULL) {
74 ASN1err(ASN1_F_ASN1_I2D_FP, ERR_R_BUF_LIB); 74 ASN1error(ERR_R_BUF_LIB);
75 return (0); 75 return (0);
76 } 76 }
77 BIO_set_fp(b, out, BIO_NOCLOSE); 77 BIO_set_fp(b, out, BIO_NOCLOSE);
@@ -90,7 +90,7 @@ ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
90 n = i2d(x, NULL); 90 n = i2d(x, NULL);
91 b = malloc(n); 91 b = malloc(n);
92 if (b == NULL) { 92 if (b == NULL) {
93 ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE); 93 ASN1error(ERR_R_MALLOC_FAILURE);
94 return (0); 94 return (0);
95 } 95 }
96 96
@@ -121,7 +121,7 @@ ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
121 int ret; 121 int ret;
122 122
123 if ((b = BIO_new(BIO_s_file())) == NULL) { 123 if ((b = BIO_new(BIO_s_file())) == NULL) {
124 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB); 124 ASN1error(ERR_R_BUF_LIB);
125 return (0); 125 return (0);
126 } 126 }
127 BIO_set_fp(b, out, BIO_NOCLOSE); 127 BIO_set_fp(b, out, BIO_NOCLOSE);
@@ -138,7 +138,7 @@ ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
138 138
139 n = ASN1_item_i2d(x, &b, it); 139 n = ASN1_item_i2d(x, &b, it);
140 if (b == NULL) { 140 if (b == NULL) {
141 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO, ERR_R_MALLOC_FAILURE); 141 ASN1error(ERR_R_MALLOC_FAILURE);
142 return (0); 142 return (0);
143 } 143 }
144 144
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index 5c0103ba36..95d0f6dbb2 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_int.c,v 1.30 2015/09/30 17:30:15 jsing Exp $ */ 1/* $OpenBSD: a_int.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -266,7 +266,7 @@ c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, long len)
266 return (ret); 266 return (ret);
267 267
268err: 268err:
269 ASN1err(ASN1_F_C2I_ASN1_INTEGER, i); 269 ASN1error(i);
270 if (a == NULL || *a != ret) 270 if (a == NULL || *a != ret)
271 ASN1_INTEGER_free(ret); 271 ASN1_INTEGER_free(ret);
272 return (NULL); 272 return (NULL);
@@ -332,7 +332,7 @@ d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, long length)
332 return (ret); 332 return (ret);
333 333
334err: 334err:
335 ASN1err(ASN1_F_D2I_ASN1_UINTEGER, i); 335 ASN1error(i);
336 if (a == NULL || *a != ret) 336 if (a == NULL || *a != ret)
337 ASN1_INTEGER_free(ret); 337 ASN1_INTEGER_free(ret);
338 return (NULL); 338 return (NULL);
@@ -353,7 +353,7 @@ ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
353 a->data = calloc(1, sizeof(long) + 1); 353 a->data = calloc(1, sizeof(long) + 1);
354 } 354 }
355 if (a->data == NULL) { 355 if (a->data == NULL) {
356 ASN1err(ASN1_F_ASN1_INTEGER_SET, ERR_R_MALLOC_FAILURE); 356 ASN1error(ERR_R_MALLOC_FAILURE);
357 return (0); 357 return (0);
358 } 358 }
359 d = v; 359 d = v;
@@ -416,7 +416,7 @@ BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
416 else 416 else
417 ret = ai; 417 ret = ai;
418 if (ret == NULL) { 418 if (ret == NULL) {
419 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_NESTED_ASN1_ERROR); 419 ASN1error(ERR_R_NESTED_ASN1_ERROR);
420 goto err; 420 goto err;
421 } 421 }
422 if (BN_is_negative(bn)) 422 if (BN_is_negative(bn))
@@ -428,7 +428,7 @@ BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
428 if (ret->length < len + 4) { 428 if (ret->length < len + 4) {
429 unsigned char *new_data = realloc(ret->data, len + 4); 429 unsigned char *new_data = realloc(ret->data, len + 4);
430 if (!new_data) { 430 if (!new_data) {
431 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); 431 ASN1error(ERR_R_MALLOC_FAILURE);
432 goto err; 432 goto err;
433 } 433 }
434 ret->data = new_data; 434 ret->data = new_data;
@@ -454,7 +454,7 @@ ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
454 BIGNUM *ret; 454 BIGNUM *ret;
455 455
456 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL) 456 if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
457 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN, ASN1_R_BN_LIB); 457 ASN1error(ASN1_R_BN_LIB);
458 else if (ai->type == V_ASN1_NEG_INTEGER) 458 else if (ai->type == V_ASN1_NEG_INTEGER)
459 BN_set_negative(ret, 1); 459 BN_set_negative(ret, 1);
460 return (ret); 460 return (ret);
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index e715fe7348..b7cfba379a 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_mbstr.c,v 1.22 2015/07/16 02:18:58 miod Exp $ */ 1/* $OpenBSD: a_mbstr.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -113,8 +113,7 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
113 switch (inform) { 113 switch (inform) {
114 case MBSTRING_BMP: 114 case MBSTRING_BMP:
115 if (len & 1) { 115 if (len & 1) {
116 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 116 ASN1error(ASN1_R_INVALID_BMPSTRING_LENGTH);
117 ASN1_R_INVALID_BMPSTRING_LENGTH);
118 return -1; 117 return -1;
119 } 118 }
120 nchar = len >> 1; 119 nchar = len >> 1;
@@ -122,8 +121,7 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
122 121
123 case MBSTRING_UNIV: 122 case MBSTRING_UNIV:
124 if (len & 3) { 123 if (len & 3) {
125 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 124 ASN1error(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
126 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
127 return -1; 125 return -1;
128 } 126 }
129 nchar = len >> 2; 127 nchar = len >> 2;
@@ -134,8 +132,7 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
134 /* This counts the characters and does utf8 syntax checking */ 132 /* This counts the characters and does utf8 syntax checking */
135 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); 133 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
136 if (ret < 0) { 134 if (ret < 0) {
137 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 135 ASN1error(ASN1_R_INVALID_UTF8STRING);
138 ASN1_R_INVALID_UTF8STRING);
139 return -1; 136 return -1;
140 } 137 }
141 break; 138 break;
@@ -145,25 +142,25 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
145 break; 142 break;
146 143
147 default: 144 default:
148 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT); 145 ASN1error(ASN1_R_UNKNOWN_FORMAT);
149 return -1; 146 return -1;
150 } 147 }
151 148
152 if ((minsize > 0) && (nchar < minsize)) { 149 if ((minsize > 0) && (nchar < minsize)) {
153 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); 150 ASN1error(ASN1_R_STRING_TOO_SHORT);
154 ERR_asprintf_error_data("minsize=%ld", minsize); 151 ERR_asprintf_error_data("minsize=%ld", minsize);
155 return -1; 152 return -1;
156 } 153 }
157 154
158 if ((maxsize > 0) && (nchar > maxsize)) { 155 if ((maxsize > 0) && (nchar > maxsize)) {
159 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); 156 ASN1error(ASN1_R_STRING_TOO_LONG);
160 ERR_asprintf_error_data("maxsize=%ld", maxsize); 157 ERR_asprintf_error_data("maxsize=%ld", maxsize);
161 return -1; 158 return -1;
162 } 159 }
163 160
164 /* Now work out minimal type (if any) */ 161 /* Now work out minimal type (if any) */
165 if (traverse_string(in, len, inform, type_str, &mask) < 0) { 162 if (traverse_string(in, len, inform, type_str, &mask) < 0) {
166 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS); 163 ASN1error(ASN1_R_ILLEGAL_CHARACTERS);
167 return -1; 164 return -1;
168 } 165 }
169 166
@@ -201,8 +198,7 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
201 free_out = 1; 198 free_out = 1;
202 dest = ASN1_STRING_type_new(str_type); 199 dest = ASN1_STRING_type_new(str_type);
203 if (!dest) { 200 if (!dest) {
204 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 201 ASN1error(ERR_R_MALLOC_FAILURE);
205 ERR_R_MALLOC_FAILURE);
206 return -1; 202 return -1;
207 } 203 }
208 *out = dest; 204 *out = dest;
@@ -210,8 +206,7 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
210 /* If both the same type just copy across */ 206 /* If both the same type just copy across */
211 if (inform == outform) { 207 if (inform == outform) {
212 if (!ASN1_STRING_set(dest, in, len)) { 208 if (!ASN1_STRING_set(dest, in, len)) {
213 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 209 ASN1error(ERR_R_MALLOC_FAILURE);
214 ERR_R_MALLOC_FAILURE);
215 goto err; 210 goto err;
216 } 211 }
217 return str_type; 212 return str_type;
@@ -237,15 +232,14 @@ ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
237 case MBSTRING_UTF8: 232 case MBSTRING_UTF8:
238 outlen = 0; 233 outlen = 0;
239 if (traverse_string(in, len, inform, out_utf8, &outlen) < 0) { 234 if (traverse_string(in, len, inform, out_utf8, &outlen) < 0) {
240 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 235 ASN1error(ASN1_R_ILLEGAL_CHARACTERS);
241 ASN1_R_ILLEGAL_CHARACTERS);
242 goto err; 236 goto err;
243 } 237 }
244 cpyfunc = cpy_utf8; 238 cpyfunc = cpy_utf8;
245 break; 239 break;
246 } 240 }
247 if (!(p = malloc(outlen + 1))) { 241 if (!(p = malloc(outlen + 1))) {
248 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ERR_R_MALLOC_FAILURE); 242 ASN1error(ERR_R_MALLOC_FAILURE);
249 goto err; 243 goto err;
250 } 244 }
251 dest->length = outlen; 245 dest->length = outlen;
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index 44694d2ba7..711b01f149 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_object.c,v 1.28 2016/11/06 17:04:48 bcook Exp $ */ 1/* $OpenBSD: a_object.c,v 1.29 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -109,12 +109,12 @@ a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
109 if ((c >= '0') && (c <= '2')) { 109 if ((c >= '0') && (c <= '2')) {
110 first= c-'0'; 110 first= c-'0';
111 } else { 111 } else {
112 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE); 112 ASN1error(ASN1_R_FIRST_NUM_TOO_LARGE);
113 goto err; 113 goto err;
114 } 114 }
115 115
116 if (num <= 0) { 116 if (num <= 0) {
117 ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER); 117 ASN1error(ASN1_R_MISSING_SECOND_NUMBER);
118 goto err; 118 goto err;
119 } 119 }
120 c = *(p++); 120 c = *(p++);
@@ -123,8 +123,7 @@ a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
123 if (num <= 0) 123 if (num <= 0)
124 break; 124 break;
125 if ((c != '.') && (c != ' ')) { 125 if ((c != '.') && (c != ' ')) {
126 ASN1err(ASN1_F_A2D_ASN1_OBJECT, 126 ASN1error(ASN1_R_INVALID_SEPARATOR);
127 ASN1_R_INVALID_SEPARATOR);
128 goto err; 127 goto err;
129 } 128 }
130 l = 0; 129 l = 0;
@@ -137,8 +136,7 @@ a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
137 if ((c == ' ') || (c == '.')) 136 if ((c == ' ') || (c == '.'))
138 break; 137 break;
139 if ((c < '0') || (c > '9')) { 138 if ((c < '0') || (c > '9')) {
140 ASN1err(ASN1_F_A2D_ASN1_OBJECT, 139 ASN1error(ASN1_R_INVALID_DIGIT);
141 ASN1_R_INVALID_DIGIT);
142 goto err; 140 goto err;
143 } 141 }
144 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) { 142 if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {
@@ -157,8 +155,7 @@ a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
157 } 155 }
158 if (len == 0) { 156 if (len == 0) {
159 if ((first < 2) && (l >= 40)) { 157 if ((first < 2) && (l >= 40)) {
160 ASN1err(ASN1_F_A2D_ASN1_OBJECT, 158 ASN1error(ASN1_R_SECOND_NUMBER_TOO_LARGE);
161 ASN1_R_SECOND_NUMBER_TOO_LARGE);
162 goto err; 159 goto err;
163 } 160 }
164 if (use_bn) { 161 if (use_bn) {
@@ -194,8 +191,7 @@ a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
194 } 191 }
195 if (out != NULL) { 192 if (out != NULL) {
196 if (len + i > olen) { 193 if (len + i > olen) {
197 ASN1err(ASN1_F_A2D_ASN1_OBJECT, 194 ASN1error(ASN1_R_BUFFER_TOO_SMALL);
198 ASN1_R_BUFFER_TOO_SMALL);
199 goto err; 195 goto err;
200 } 196 }
201 while (--i > 0) 197 while (--i > 0)
@@ -277,7 +273,7 @@ d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length)
277 return ret; 273 return ret;
278 274
279err: 275err:
280 ASN1err(ASN1_F_D2I_ASN1_OBJECT, i); 276 ASN1error(i);
281 return (NULL); 277 return (NULL);
282} 278}
283 279
@@ -297,7 +293,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
297 */ 293 */
298 if (len <= 0 || len > INT_MAX || pp == NULL || (p = *pp) == NULL || 294 if (len <= 0 || len > INT_MAX || pp == NULL || (p = *pp) == NULL ||
299 p[len - 1] & 0x80) { 295 p[len - 1] & 0x80) {
300 ASN1err(ASN1_F_C2I_ASN1_OBJECT, ASN1_R_INVALID_OBJECT_ENCODING); 296 ASN1error(ASN1_R_INVALID_OBJECT_ENCODING);
301 return (NULL); 297 return (NULL);
302 } 298 }
303 299
@@ -305,8 +301,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
305 length = (int)len; 301 length = (int)len;
306 for (i = 0; i < length; i++, p++) { 302 for (i = 0; i < length; i++, p++) {
307 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) { 303 if (*p == 0x80 && (!i || !(p[-1] & 0x80))) {
308 ASN1err(ASN1_F_C2I_ASN1_OBJECT, 304 ASN1error(ASN1_R_INVALID_OBJECT_ENCODING);
309 ASN1_R_INVALID_OBJECT_ENCODING);
310 return (NULL); 305 return (NULL);
311 } 306 }
312 } 307 }
@@ -330,7 +325,7 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len)
330 325
331 data = malloc(length); 326 data = malloc(length);
332 if (data == NULL) { 327 if (data == NULL) {
333 ASN1err(ASN1_F_C2I_ASN1_OBJECT, ERR_R_MALLOC_FAILURE); 328 ASN1error(ERR_R_MALLOC_FAILURE);
334 goto err; 329 goto err;
335 } 330 }
336 331
@@ -362,7 +357,7 @@ ASN1_OBJECT_new(void)
362 357
363 ret = malloc(sizeof(ASN1_OBJECT)); 358 ret = malloc(sizeof(ASN1_OBJECT));
364 if (ret == NULL) { 359 if (ret == NULL) {
365 ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE); 360 ASN1error(ERR_R_MALLOC_FAILURE);
366 return (NULL); 361 return (NULL);
367 } 362 }
368 ret->length = 0; 363 ret->length = 0;
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
index 63d55c3714..4d5cae337b 100644
--- a/src/lib/libcrypto/asn1/a_set.c
+++ b/src/lib/libcrypto/asn1/a_set.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_set.c,v 1.17 2015/03/19 14:00:22 tedu Exp $ */ 1/* $OpenBSD: a_set.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -125,7 +125,7 @@ i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d,
125 /* In this array we will store the SET blobs */ 125 /* In this array we will store the SET blobs */
126 rgSetBlob = reallocarray(NULL, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB)); 126 rgSetBlob = reallocarray(NULL, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB));
127 if (rgSetBlob == NULL) { 127 if (rgSetBlob == NULL) {
128 ASN1err(ASN1_F_I2D_ASN1_SET, ERR_R_MALLOC_FAILURE); 128 ASN1error(ERR_R_MALLOC_FAILURE);
129 return 0; 129 return 0;
130 } 130 }
131 131
@@ -146,7 +146,7 @@ i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d,
146 qsort(rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp); 146 qsort(rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp);
147 if ((pTempMem = malloc(totSize)) == NULL) { 147 if ((pTempMem = malloc(totSize)) == NULL) {
148 free(rgSetBlob); 148 free(rgSetBlob);
149 ASN1err(ASN1_F_I2D_ASN1_SET, ERR_R_MALLOC_FAILURE); 149 ASN1error(ERR_R_MALLOC_FAILURE);
150 return 0; 150 return 0;
151 } 151 }
152 152
@@ -175,7 +175,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length,
175 175
176 if (a == NULL || (*a) == NULL) { 176 if (a == NULL || (*a) == NULL) {
177 if ((ret = sk_OPENSSL_BLOCK_new_null()) == NULL) { 177 if ((ret = sk_OPENSSL_BLOCK_new_null()) == NULL) {
178 ASN1err(ASN1_F_D2I_ASN1_SET, ERR_R_MALLOC_FAILURE); 178 ASN1error(ERR_R_MALLOC_FAILURE);
179 goto err; 179 goto err;
180 } 180 }
181 } else 181 } else
@@ -188,15 +188,15 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length,
188 if (c.inf & 0x80) 188 if (c.inf & 0x80)
189 goto err; 189 goto err;
190 if (ex_class != c.xclass) { 190 if (ex_class != c.xclass) {
191 ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_BAD_CLASS); 191 ASN1error(ASN1_R_BAD_CLASS);
192 goto err; 192 goto err;
193 } 193 }
194 if (ex_tag != c.tag) { 194 if (ex_tag != c.tag) {
195 ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_BAD_TAG); 195 ASN1error(ASN1_R_BAD_TAG);
196 goto err; 196 goto err;
197 } 197 }
198 if (c.slen + c.p > c.max) { 198 if (c.slen + c.p > c.max) {
199 ASN1err(ASN1_F_D2I_ASN1_SET, ASN1_R_LENGTH_ERROR); 199 ASN1error(ASN1_R_LENGTH_ERROR);
200 goto err; 200 goto err;
201 } 201 }
202 /* check for infinite constructed - it can be as long 202 /* check for infinite constructed - it can be as long
@@ -211,8 +211,7 @@ d2i_ASN1_SET(STACK_OF(OPENSSL_BLOCK) **a, const unsigned char **pp, long length,
211 if (M_ASN1_D2I_end_sequence()) 211 if (M_ASN1_D2I_end_sequence())
212 break; 212 break;
213 if ((s = d2i(NULL, &c.p, c.slen)) == NULL) { 213 if ((s = d2i(NULL, &c.p, c.slen)) == NULL) {
214 ASN1err(ASN1_F_D2I_ASN1_SET, 214 ASN1error(ASN1_R_ERROR_PARSING_SET_ELEMENT);
215 ASN1_R_ERROR_PARSING_SET_ELEMENT);
216 asn1_add_error(*pp, (int)(c.p - *pp)); 215 asn1_add_error(*pp, (int)(c.p - *pp));
217 goto err; 216 goto err;
218 } 217 }
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 195daa3b9f..4e545eb719 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_sign.c,v 1.21 2015/09/10 15:56:24 jsing Exp $ */ 1/* $OpenBSD: a_sign.c,v 1.22 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -153,8 +153,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
153 pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); 153 pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx);
154 154
155 if (!type || !pkey) { 155 if (!type || !pkey) {
156 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, 156 ASN1error(ASN1_R_CONTEXT_NOT_INITIALISED);
157 ASN1_R_CONTEXT_NOT_INITIALISED);
158 return 0; 157 return 0;
159 } 158 }
160 159
@@ -170,7 +169,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
170 * 3: ASN1 method sets algorithm identifiers: just sign. 169 * 3: ASN1 method sets algorithm identifiers: just sign.
171 */ 170 */
172 if (rv <= 0) 171 if (rv <= 0)
173 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); 172 ASN1error(ERR_R_EVP_LIB);
174 if (rv <= 1) 173 if (rv <= 1)
175 goto err; 174 goto err;
176 } else 175 } else
@@ -181,8 +180,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
181 if (!pkey->ameth || 180 if (!pkey->ameth ||
182 !OBJ_find_sigid_by_algs(&signid, 181 !OBJ_find_sigid_by_algs(&signid,
183 EVP_MD_nid(type), pkey->ameth->pkey_id)) { 182 EVP_MD_nid(type), pkey->ameth->pkey_id)) {
184 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, 183 ASN1error(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
185 ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
186 return 0; 184 return 0;
187 } 185 }
188 } else 186 } else
@@ -207,14 +205,14 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
207 buf_out = malloc(outl); 205 buf_out = malloc(outl);
208 if ((buf_in == NULL) || (buf_out == NULL)) { 206 if ((buf_in == NULL) || (buf_out == NULL)) {
209 outl = 0; 207 outl = 0;
210 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_MALLOC_FAILURE); 208 ASN1error(ERR_R_MALLOC_FAILURE);
211 goto err; 209 goto err;
212 } 210 }
213 211
214 if (!EVP_DigestSignUpdate(ctx, buf_in, inl) || 212 if (!EVP_DigestSignUpdate(ctx, buf_in, inl) ||
215 !EVP_DigestSignFinal(ctx, buf_out, &outl)) { 213 !EVP_DigestSignFinal(ctx, buf_out, &outl)) {
216 outl = 0; 214 outl = 0;
217 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB); 215 ASN1error(ERR_R_EVP_LIB);
218 goto err; 216 goto err;
219 } 217 }
220 free(signature->data); 218 free(signature->data);
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
index f325d91924..0585f7050b 100644
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_strnid.c,v 1.20 2017/01/21 04:31:25 jsing Exp $ */ 1/* $OpenBSD: a_strnid.c,v 1.21 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -258,14 +258,13 @@ ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask,
258 if (!stable) 258 if (!stable)
259 stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); 259 stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp);
260 if (!stable) { 260 if (!stable) {
261 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); 261 ASN1error(ERR_R_MALLOC_FAILURE);
262 return 0; 262 return 0;
263 } 263 }
264 if (!(tmp = ASN1_STRING_TABLE_get(nid))) { 264 if (!(tmp = ASN1_STRING_TABLE_get(nid))) {
265 tmp = malloc(sizeof(ASN1_STRING_TABLE)); 265 tmp = malloc(sizeof(ASN1_STRING_TABLE));
266 if (!tmp) { 266 if (!tmp) {
267 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, 267 ASN1error(ERR_R_MALLOC_FAILURE);
268 ERR_R_MALLOC_FAILURE);
269 return 0; 268 return 0;
270 } 269 }
271 tmp->flags = flags | STABLE_FLAGS_MALLOC; 270 tmp->flags = flags | STABLE_FLAGS_MALLOC;
@@ -280,8 +279,7 @@ ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, unsigned long mask,
280 if (new_nid) { 279 if (new_nid) {
281 if (sk_ASN1_STRING_TABLE_push(stable, tmp) == 0) { 280 if (sk_ASN1_STRING_TABLE_push(stable, tmp) == 0) {
282 free(tmp); 281 free(tmp);
283 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, 282 ASN1error(ERR_R_MALLOC_FAILURE);
284 ERR_R_MALLOC_FAILURE);
285 return 0; 283 return 0;
286 } 284 }
287 } 285 }
diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c
index fcd3acf9c8..b2f65045b5 100644
--- a/src/lib/libcrypto/asn1/a_time_tm.c
+++ b/src/lib/libcrypto/asn1/a_time_tm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_time_tm.c,v 1.10 2016/11/04 18:07:23 beck Exp $ */ 1/* $OpenBSD: a_time_tm.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -267,8 +267,7 @@ ASN1_TIME_adj_internal(ASN1_TIME *s, time_t t, int offset_day, long offset_sec,
267 return (NULL); 267 return (NULL);
268 } 268 }
269 if (p == NULL) { 269 if (p == NULL) {
270 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, 270 ASN1error(ASN1_R_ILLEGAL_TIME_VALUE);
271 ASN1_R_ILLEGAL_TIME_VALUE);
272 return (NULL); 271 return (NULL);
273 } 272 }
274 273
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index 12b76501e0..8f8e58c095 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_verify.c,v 1.22 2015/09/10 15:56:24 jsing Exp $ */ 1/* $OpenBSD: a_verify.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -82,14 +82,13 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
82 int mdnid, pknid; 82 int mdnid, pknid;
83 83
84 if (!pkey) { 84 if (!pkey) {
85 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER); 85 ASN1error(ERR_R_PASSED_NULL_PARAMETER);
86 return -1; 86 return -1;
87 } 87 }
88 88
89 if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7) 89 if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
90 { 90 {
91 ASN1err(ASN1_F_ASN1_VERIFY, 91 ASN1error(ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
92 ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
93 return -1; 92 return -1;
94 } 93 }
95 94
@@ -97,14 +96,12 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
97 96
98 /* Convert signature OID into digest and public key OIDs */ 97 /* Convert signature OID into digest and public key OIDs */
99 if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) { 98 if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->algorithm), &mdnid, &pknid)) {
100 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, 99 ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
101 ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
102 goto err; 100 goto err;
103 } 101 }
104 if (mdnid == NID_undef) { 102 if (mdnid == NID_undef) {
105 if (!pkey->ameth || !pkey->ameth->item_verify) { 103 if (!pkey->ameth || !pkey->ameth->item_verify) {
106 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, 104 ASN1error(ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
107 ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
108 goto err; 105 goto err;
109 } 106 }
110 ret = pkey->ameth->item_verify(&ctx, it, asn, a, 107 ret = pkey->ameth->item_verify(&ctx, it, asn, a,
@@ -120,20 +117,18 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
120 const EVP_MD *type; 117 const EVP_MD *type;
121 type = EVP_get_digestbynid(mdnid); 118 type = EVP_get_digestbynid(mdnid);
122 if (type == NULL) { 119 if (type == NULL) {
123 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, 120 ASN1error(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
124 ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
125 goto err; 121 goto err;
126 } 122 }
127 123
128 /* Check public key OID matches public key type */ 124 /* Check public key OID matches public key type */
129 if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) { 125 if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
130 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, 126 ASN1error(ASN1_R_WRONG_PUBLIC_KEY_TYPE);
131 ASN1_R_WRONG_PUBLIC_KEY_TYPE);
132 goto err; 127 goto err;
133 } 128 }
134 129
135 if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) { 130 if (!EVP_DigestVerifyInit(&ctx, NULL, type, NULL, pkey)) {
136 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); 131 ASN1error(ERR_R_EVP_LIB);
137 ret = 0; 132 ret = 0;
138 goto err; 133 goto err;
139 } 134 }
@@ -143,12 +138,12 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
143 inl = ASN1_item_i2d(asn, &buf_in, it); 138 inl = ASN1_item_i2d(asn, &buf_in, it);
144 139
145 if (buf_in == NULL) { 140 if (buf_in == NULL) {
146 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_MALLOC_FAILURE); 141 ASN1error(ERR_R_MALLOC_FAILURE);
147 goto err; 142 goto err;
148 } 143 }
149 144
150 if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) { 145 if (!EVP_DigestVerifyUpdate(&ctx, buf_in, inl)) {
151 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); 146 ASN1error(ERR_R_EVP_LIB);
152 ret = 0; 147 ret = 0;
153 goto err; 148 goto err;
154 } 149 }
@@ -158,7 +153,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
158 153
159 if (EVP_DigestVerifyFinal(&ctx, signature->data, 154 if (EVP_DigestVerifyFinal(&ctx, signature->data,
160 (size_t)signature->length) <= 0) { 155 (size_t)signature->length) <= 0) {
161 ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_EVP_LIB); 156 ASN1error(ERR_R_EVP_LIB);
162 ret = 0; 157 ret = 0;
163 goto err; 158 goto err;
164 } 159 }
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
index 8fd5cf6765..0c827a9236 100644
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ b/src/lib/libcrypto/asn1/asn1_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_err.c,v 1.19 2015/02/15 14:35:30 miod Exp $ */ 1/* $OpenBSD: asn1_err.c,v 1.20 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,127 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASN1,0,reason)
73 73
74static ERR_STRING_DATA ASN1_str_functs[] = { 74static ERR_STRING_DATA ASN1_str_functs[] = {
75 {ERR_FUNC(ASN1_F_A2D_ASN1_OBJECT), "a2d_ASN1_OBJECT"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"},
77 {ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"},
78 {ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"},
79 {ERR_FUNC(ASN1_F_APPEND_EXP), "APPEND_EXP"},
80 {ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"},
81 {ERR_FUNC(ASN1_F_ASN1_CB), "ASN1_CB"},
82 {ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"},
83 {ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"},
84 {ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"},
85 {ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"},
86 {ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"},
87 {ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "ASN1_D2I_READ_BIO"},
88 {ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"},
89 {ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"},
90 {ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"},
91 {ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"},
92 {ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"},
93 {ERR_FUNC(ASN1_F_ASN1_EX_C2I), "ASN1_EX_C2I"},
94 {ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"},
95 {ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_ADJ), "ASN1_GENERALIZEDTIME_adj"},
96 {ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"},
97 {ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"},
98 {ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"},
99 {ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_NEW"},
100 {ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"},
101 {ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
102 {ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"},
103 {ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"},
104 {ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"},
105 {ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"},
106 {ERR_FUNC(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW), "ASN1_ITEM_EX_COMBINE_NEW"},
107 {ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"},
108 {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"},
109 {ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"},
110 {ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"},
111 {ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN), "ASN1_item_sign"},
112 {ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN_CTX), "ASN1_item_sign_ctx"},
113 {ERR_FUNC(ASN1_F_ASN1_ITEM_UNPACK), "ASN1_item_unpack"},
114 {ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"},
115 {ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"},
116 {ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
117 {ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "ASN1_OUTPUT_DATA"},
118 {ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"},
119 {ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_new"},
120 {ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET), "ASN1_PKCS5_PBE_SET"},
121 {ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"},
122 {ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"},
123 {ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"},
124 {ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "ASN1_STR2TYPE"},
125 {ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"},
126 {ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"},
127 {ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"},
128 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"},
129 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"},
130 {ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "ASN1_TEMPLATE_NOEXP_D2I"},
131 {ERR_FUNC(ASN1_F_ASN1_TIME_ADJ), "ASN1_TIME_adj"},
132 {ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"},
133 {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), "ASN1_TYPE_get_int_octetstring"},
134 {ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"},
135 {ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"},
136 {ERR_FUNC(ASN1_F_ASN1_UTCTIME_ADJ), "ASN1_UTCTIME_adj"},
137 {ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"},
138 {ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
139 {ERR_FUNC(ASN1_F_B64_READ_ASN1), "B64_READ_ASN1"},
140 {ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_WRITE_ASN1"},
141 {ERR_FUNC(ASN1_F_BIO_NEW_NDEF), "BIO_new_NDEF"},
142 {ERR_FUNC(ASN1_F_BITSTR_CB), "BITSTR_CB"},
143 {ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"},
144 {ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"},
145 {ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"},
146 {ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"},
147 {ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"},
148 {ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"},
149 {ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"},
150 {ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"},
151 {ERR_FUNC(ASN1_F_D2I_ASN1_BYTES), "d2i_ASN1_bytes"},
152 {ERR_FUNC(ASN1_F_D2I_ASN1_GENERALIZEDTIME), "D2I_ASN1_GENERALIZEDTIME"},
153 {ERR_FUNC(ASN1_F_D2I_ASN1_HEADER), "D2I_ASN1_HEADER"},
154 {ERR_FUNC(ASN1_F_D2I_ASN1_INTEGER), "D2I_ASN1_INTEGER"},
155 {ERR_FUNC(ASN1_F_D2I_ASN1_OBJECT), "d2i_ASN1_OBJECT"},
156 {ERR_FUNC(ASN1_F_D2I_ASN1_SET), "d2i_ASN1_SET"},
157 {ERR_FUNC(ASN1_F_D2I_ASN1_TYPE_BYTES), "d2i_ASN1_type_bytes"},
158 {ERR_FUNC(ASN1_F_D2I_ASN1_UINTEGER), "d2i_ASN1_UINTEGER"},
159 {ERR_FUNC(ASN1_F_D2I_ASN1_UTCTIME), "D2I_ASN1_UTCTIME"},
160 {ERR_FUNC(ASN1_F_D2I_AUTOPRIVATEKEY), "d2i_AutoPrivateKey"},
161 {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA), "d2i_Netscape_RSA"},
162 {ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"},
163 {ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"},
164 {ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"},
165 {ERR_FUNC(ASN1_F_D2I_RSA_NET), "d2i_RSA_NET"},
166 {ERR_FUNC(ASN1_F_D2I_RSA_NET_2), "D2I_RSA_NET_2"},
167 {ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"},
168 {ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"},
169 {ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"},
170 {ERR_FUNC(ASN1_F_I2D_ASN1_BIO_STREAM), "i2d_ASN1_bio_stream"},
171 {ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"},
172 {ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"},
173 {ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"},
174 {ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"},
175 {ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"},
176 {ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"},
177 {ERR_FUNC(ASN1_F_I2D_RSA_NET), "i2d_RSA_NET"},
178 {ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"},
179 {ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"},
180 {ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"},
181 {ERR_FUNC(ASN1_F_PARSE_TAGGING), "PARSE_TAGGING"},
182 {ERR_FUNC(ASN1_F_PKCS5_PBE2_SET_IV), "PKCS5_pbe2_set_iv"},
183 {ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"},
184 {ERR_FUNC(ASN1_F_PKCS5_PBE_SET0_ALGOR), "PKCS5_pbe_set0_algor"},
185 {ERR_FUNC(ASN1_F_PKCS5_PBKDF2_SET), "PKCS5_pbkdf2_set"},
186 {ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"},
187 {ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"},
188 {ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"},
189 {ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
190 {ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
191 {ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "X509_NAME_ENCODE"},
192 {ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "X509_NAME_EX_D2I"},
193 {ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "X509_NAME_EX_NEW"},
194 {ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"},
195 {ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"},
196 {0, NULL} 76 {0, NULL}
197}; 77};
198 78
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index e899337b6f..f84cc6136b 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_gen.c,v 1.15 2015/12/12 21:03:52 beck Exp $ */ 1/* $OpenBSD: asn1_gen.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -160,8 +160,7 @@ ASN1_generate_v3(char *str, X509V3_CTX *cnf)
160 if ((asn1_tags.utype == V_ASN1_SEQUENCE) || 160 if ((asn1_tags.utype == V_ASN1_SEQUENCE) ||
161 (asn1_tags.utype == V_ASN1_SET)) { 161 (asn1_tags.utype == V_ASN1_SET)) {
162 if (!cnf) { 162 if (!cnf) {
163 ASN1err(ASN1_F_ASN1_GENERATE_V3, 163 ASN1error(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
164 ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
165 return NULL; 164 return NULL;
166 } 165 }
167 ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); 166 ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);
@@ -290,7 +289,7 @@ asn1_cb(const char *elem, int len, void *bitstr)
290 utype = asn1_str2tag(elem, len); 289 utype = asn1_str2tag(elem, len);
291 290
292 if (utype == -1) { 291 if (utype == -1) {
293 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); 292 ASN1error(ASN1_R_UNKNOWN_TAG);
294 ERR_asprintf_error_data("tag=%s", elem); 293 ERR_asprintf_error_data("tag=%s", elem);
295 return -1; 294 return -1;
296 } 295 }
@@ -301,7 +300,7 @@ asn1_cb(const char *elem, int len, void *bitstr)
301 arg->str = vstart; 300 arg->str = vstart;
302 /* If no value and not end of string, error */ 301 /* If no value and not end of string, error */
303 if (!vstart && elem[len]) { 302 if (!vstart && elem[len]) {
304 ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); 303 ASN1error(ASN1_R_MISSING_VALUE);
305 return -1; 304 return -1;
306 } 305 }
307 return 0; 306 return 0;
@@ -312,7 +311,7 @@ asn1_cb(const char *elem, int len, void *bitstr)
312 case ASN1_GEN_FLAG_IMP: 311 case ASN1_GEN_FLAG_IMP:
313 /* Check for illegal multiple IMPLICIT tagging */ 312 /* Check for illegal multiple IMPLICIT tagging */
314 if (arg->imp_tag != -1) { 313 if (arg->imp_tag != -1) {
315 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); 314 ASN1error(ASN1_R_ILLEGAL_NESTED_TAGGING);
316 return -1; 315 return -1;
317 } 316 }
318 if (!parse_tagging(vstart, vlen, &arg->imp_tag, 317 if (!parse_tagging(vstart, vlen, &arg->imp_tag,
@@ -349,7 +348,7 @@ asn1_cb(const char *elem, int len, void *bitstr)
349 348
350 case ASN1_GEN_FLAG_FORMAT: 349 case ASN1_GEN_FLAG_FORMAT:
351 if (vstart == NULL) { 350 if (vstart == NULL) {
352 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_FORMAT); 351 ASN1error(ASN1_R_ILLEGAL_FORMAT);
353 return -1; 352 return -1;
354 } 353 }
355 if (!strncmp(vstart, "ASCII", 5)) 354 if (!strncmp(vstart, "ASCII", 5))
@@ -361,7 +360,7 @@ asn1_cb(const char *elem, int len, void *bitstr)
361 else if (!strncmp(vstart, "BITLIST", 7)) 360 else if (!strncmp(vstart, "BITLIST", 7))
362 arg->format = ASN1_GEN_FORMAT_BITLIST; 361 arg->format = ASN1_GEN_FORMAT_BITLIST;
363 else { 362 else {
364 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); 363 ASN1error(ASN1_R_UNKOWN_FORMAT);
365 return -1; 364 return -1;
366 } 365 }
367 break; 366 break;
@@ -384,7 +383,7 @@ parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
384 if (eptr && *eptr && (eptr > vstart + vlen)) 383 if (eptr && *eptr && (eptr > vstart + vlen))
385 return 0; 384 return 0;
386 if (tag_num < 0) { 385 if (tag_num < 0) {
387 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); 386 ASN1error(ASN1_R_INVALID_NUMBER);
388 return 0; 387 return 0;
389 } 388 }
390 *ptag = tag_num; 389 *ptag = tag_num;
@@ -413,7 +412,7 @@ parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
413 break; 412 break;
414 413
415 default: 414 default:
416 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER); 415 ASN1error(ASN1_R_INVALID_MODIFIER);
417 ERR_asprintf_error_data("Char=%c", *eptr); 416 ERR_asprintf_error_data("Char=%c", *eptr);
418 return 0; 417 return 0;
419 break; 418 break;
@@ -497,12 +496,12 @@ append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed,
497 496
498 /* Can only have IMPLICIT if permitted */ 497 /* Can only have IMPLICIT if permitted */
499 if ((arg->imp_tag != -1) && !imp_ok) { 498 if ((arg->imp_tag != -1) && !imp_ok) {
500 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); 499 ASN1error(ASN1_R_ILLEGAL_IMPLICIT_TAG);
501 return 0; 500 return 0;
502 } 501 }
503 502
504 if (arg->exp_count == ASN1_FLAG_EXP_MAX) { 503 if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
505 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); 504 ASN1error(ASN1_R_DEPTH_EXCEEDED);
506 return 0; 505 return 0;
507 } 506 }
508 507
@@ -614,7 +613,7 @@ asn1_str2type(const char *str, int format, int utype)
614 int no_unused = 1; 613 int no_unused = 1;
615 614
616 if (!(atmp = ASN1_TYPE_new())) { 615 if (!(atmp = ASN1_TYPE_new())) {
617 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 616 ASN1error(ERR_R_MALLOC_FAILURE);
618 return NULL; 617 return NULL;
619 } 618 }
620 619
@@ -625,22 +624,21 @@ asn1_str2type(const char *str, int format, int utype)
625 624
626 case V_ASN1_NULL: 625 case V_ASN1_NULL:
627 if (str && *str) { 626 if (str && *str) {
628 ASN1err(ASN1_F_ASN1_STR2TYPE, 627 ASN1error(ASN1_R_ILLEGAL_NULL_VALUE);
629 ASN1_R_ILLEGAL_NULL_VALUE);
630 goto bad_form; 628 goto bad_form;
631 } 629 }
632 break; 630 break;
633 631
634 case V_ASN1_BOOLEAN: 632 case V_ASN1_BOOLEAN:
635 if (format != ASN1_GEN_FORMAT_ASCII) { 633 if (format != ASN1_GEN_FORMAT_ASCII) {
636 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); 634 ASN1error(ASN1_R_NOT_ASCII_FORMAT);
637 goto bad_form; 635 goto bad_form;
638 } 636 }
639 vtmp.name = NULL; 637 vtmp.name = NULL;
640 vtmp.section = NULL; 638 vtmp.section = NULL;
641 vtmp.value = (char *)str; 639 vtmp.value = (char *)str;
642 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) { 640 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
643 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); 641 ASN1error(ASN1_R_ILLEGAL_BOOLEAN);
644 goto bad_str; 642 goto bad_str;
645 } 643 }
646 break; 644 break;
@@ -648,25 +646,23 @@ asn1_str2type(const char *str, int format, int utype)
648 case V_ASN1_INTEGER: 646 case V_ASN1_INTEGER:
649 case V_ASN1_ENUMERATED: 647 case V_ASN1_ENUMERATED:
650 if (format != ASN1_GEN_FORMAT_ASCII) { 648 if (format != ASN1_GEN_FORMAT_ASCII) {
651 ASN1err(ASN1_F_ASN1_STR2TYPE, 649 ASN1error(ASN1_R_INTEGER_NOT_ASCII_FORMAT);
652 ASN1_R_INTEGER_NOT_ASCII_FORMAT);
653 goto bad_form; 650 goto bad_form;
654 } 651 }
655 if (!(atmp->value.integer = 652 if (!(atmp->value.integer =
656 s2i_ASN1_INTEGER(NULL, (char *)str))) { 653 s2i_ASN1_INTEGER(NULL, (char *)str))) {
657 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); 654 ASN1error(ASN1_R_ILLEGAL_INTEGER);
658 goto bad_str; 655 goto bad_str;
659 } 656 }
660 break; 657 break;
661 658
662 case V_ASN1_OBJECT: 659 case V_ASN1_OBJECT:
663 if (format != ASN1_GEN_FORMAT_ASCII) { 660 if (format != ASN1_GEN_FORMAT_ASCII) {
664 ASN1err(ASN1_F_ASN1_STR2TYPE, 661 ASN1error(ASN1_R_OBJECT_NOT_ASCII_FORMAT);
665 ASN1_R_OBJECT_NOT_ASCII_FORMAT);
666 goto bad_form; 662 goto bad_form;
667 } 663 }
668 if (!(atmp->value.object = OBJ_txt2obj(str, 0))) { 664 if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
669 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); 665 ASN1error(ASN1_R_ILLEGAL_OBJECT);
670 goto bad_str; 666 goto bad_str;
671 } 667 }
672 break; 668 break;
@@ -674,22 +670,20 @@ asn1_str2type(const char *str, int format, int utype)
674 case V_ASN1_UTCTIME: 670 case V_ASN1_UTCTIME:
675 case V_ASN1_GENERALIZEDTIME: 671 case V_ASN1_GENERALIZEDTIME:
676 if (format != ASN1_GEN_FORMAT_ASCII) { 672 if (format != ASN1_GEN_FORMAT_ASCII) {
677 ASN1err(ASN1_F_ASN1_STR2TYPE, 673 ASN1error(ASN1_R_TIME_NOT_ASCII_FORMAT);
678 ASN1_R_TIME_NOT_ASCII_FORMAT);
679 goto bad_form; 674 goto bad_form;
680 } 675 }
681 if (!(atmp->value.asn1_string = ASN1_STRING_new())) { 676 if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
682 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 677 ASN1error(ERR_R_MALLOC_FAILURE);
683 goto bad_str; 678 goto bad_str;
684 } 679 }
685 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) { 680 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
686 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 681 ASN1error(ERR_R_MALLOC_FAILURE);
687 goto bad_str; 682 goto bad_str;
688 } 683 }
689 atmp->value.asn1_string->type = utype; 684 atmp->value.asn1_string->type = utype;
690 if (!ASN1_TIME_check(atmp->value.asn1_string)) { 685 if (!ASN1_TIME_check(atmp->value.asn1_string)) {
691 ASN1err(ASN1_F_ASN1_STR2TYPE, 686 ASN1error(ASN1_R_ILLEGAL_TIME_VALUE);
692 ASN1_R_ILLEGAL_TIME_VALUE);
693 goto bad_str; 687 goto bad_str;
694 } 688 }
695 break; 689 break;
@@ -709,14 +703,14 @@ asn1_str2type(const char *str, int format, int utype)
709 else if (format == ASN1_GEN_FORMAT_UTF8) 703 else if (format == ASN1_GEN_FORMAT_UTF8)
710 format = MBSTRING_UTF8; 704 format = MBSTRING_UTF8;
711 else { 705 else {
712 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); 706 ASN1error(ASN1_R_ILLEGAL_FORMAT);
713 goto bad_form; 707 goto bad_form;
714 } 708 }
715 709
716 if (ASN1_mbstring_copy(&atmp->value.asn1_string, 710 if (ASN1_mbstring_copy(&atmp->value.asn1_string,
717 (unsigned char *)str, -1, format, 711 (unsigned char *)str, -1, format,
718 ASN1_tag2bit(utype)) <= 0) { 712 ASN1_tag2bit(utype)) <= 0) {
719 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 713 ASN1error(ERR_R_MALLOC_FAILURE);
720 goto bad_str; 714 goto bad_str;
721 } 715 }
722 break; 716 break;
@@ -724,15 +718,14 @@ asn1_str2type(const char *str, int format, int utype)
724 case V_ASN1_BIT_STRING: 718 case V_ASN1_BIT_STRING:
725 case V_ASN1_OCTET_STRING: 719 case V_ASN1_OCTET_STRING:
726 if (!(atmp->value.asn1_string = ASN1_STRING_new())) { 720 if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
727 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 721 ASN1error(ERR_R_MALLOC_FAILURE);
728 goto bad_form; 722 goto bad_form;
729 } 723 }
730 724
731 if (format == ASN1_GEN_FORMAT_HEX) { 725 if (format == ASN1_GEN_FORMAT_HEX) {
732 726
733 if (!(rdata = string_to_hex((char *)str, &rdlen))) { 727 if (!(rdata = string_to_hex((char *)str, &rdlen))) {
734 ASN1err(ASN1_F_ASN1_STR2TYPE, 728 ASN1error(ASN1_R_ILLEGAL_HEX);
735 ASN1_R_ILLEGAL_HEX);
736 goto bad_str; 729 goto bad_str;
737 } 730 }
738 731
@@ -743,23 +736,20 @@ asn1_str2type(const char *str, int format, int utype)
743 } else if (format == ASN1_GEN_FORMAT_ASCII) { 736 } else if (format == ASN1_GEN_FORMAT_ASCII) {
744 if (ASN1_STRING_set(atmp->value.asn1_string, str, 737 if (ASN1_STRING_set(atmp->value.asn1_string, str,
745 -1) == 0) { 738 -1) == 0) {
746 ASN1err(ASN1_F_ASN1_STR2TYPE, 739 ASN1error(ERR_R_MALLOC_FAILURE);
747 ERR_R_MALLOC_FAILURE);
748 goto bad_str; 740 goto bad_str;
749 } 741 }
750 } else if ((format == ASN1_GEN_FORMAT_BITLIST) && 742 } else if ((format == ASN1_GEN_FORMAT_BITLIST) &&
751 (utype == V_ASN1_BIT_STRING)) { 743 (utype == V_ASN1_BIT_STRING)) {
752 if (!CONF_parse_list(str, ',', 1, bitstr_cb, 744 if (!CONF_parse_list(str, ',', 1, bitstr_cb,
753 atmp->value.bit_string)) { 745 atmp->value.bit_string)) {
754 ASN1err(ASN1_F_ASN1_STR2TYPE, 746 ASN1error(ASN1_R_LIST_ERROR);
755 ASN1_R_LIST_ERROR);
756 goto bad_str; 747 goto bad_str;
757 } 748 }
758 no_unused = 0; 749 no_unused = 0;
759 750
760 } else { 751 } else {
761 ASN1err(ASN1_F_ASN1_STR2TYPE, 752 ASN1error(ASN1_R_ILLEGAL_BITSTRING_FORMAT);
762 ASN1_R_ILLEGAL_BITSTRING_FORMAT);
763 goto bad_form; 753 goto bad_form;
764 } 754 }
765 755
@@ -773,7 +763,7 @@ asn1_str2type(const char *str, int format, int utype)
773 break; 763 break;
774 764
775 default: 765 default:
776 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); 766 ASN1error(ASN1_R_UNSUPPORTED_TYPE);
777 goto bad_str; 767 goto bad_str;
778 break; 768 break;
779 } 769 }
@@ -800,11 +790,11 @@ bitstr_cb(const char *elem, int len, void *bitstr)
800 if (eptr && *eptr && (eptr != elem + len)) 790 if (eptr && *eptr && (eptr != elem + len))
801 return 0; 791 return 0;
802 if (bitnum < 0) { 792 if (bitnum < 0) {
803 ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); 793 ASN1error(ASN1_R_INVALID_NUMBER);
804 return 0; 794 return 0;
805 } 795 }
806 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) { 796 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
807 ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); 797 ASN1error(ERR_R_MALLOC_FAILURE);
808 return 0; 798 return 0;
809 } 799 }
810 return 1; 800 return 1;
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 444a34c072..a90873d54a 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1_lib.c,v 1.37 2016/03/06 18:05:00 beck Exp $ */ 1/* $OpenBSD: asn1_lib.c,v 1.38 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -140,7 +140,7 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
140 goto err; 140 goto err;
141 141
142 if (*plength > (omax - (p - *pp))) { 142 if (*plength > (omax - (p - *pp))) {
143 ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG); 143 ASN1error(ASN1_R_TOO_LONG);
144 /* Set this so that even if things are not long enough 144 /* Set this so that even if things are not long enough
145 * the values are set correctly */ 145 * the values are set correctly */
146 ret |= 0x80; 146 ret |= 0x80;
@@ -149,7 +149,7 @@ ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
149 return (ret | inf); 149 return (ret | inf);
150 150
151err: 151err:
152 ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_HEADER_TOO_LONG); 152 ASN1error(ASN1_R_HEADER_TOO_LONG);
153 return (0x80); 153 return (0x80);
154} 154}
155 155
@@ -385,7 +385,7 @@ ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
385 unsigned char *tmp; 385 unsigned char *tmp;
386 tmp = realloc(str->data, len + 1); 386 tmp = realloc(str->data, len + 1);
387 if (tmp == NULL) { 387 if (tmp == NULL) {
388 ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); 388 ASN1error(ERR_R_MALLOC_FAILURE);
389 return (0); 389 return (0);
390 } 390 }
391 str->data = tmp; 391 str->data = tmp;
@@ -421,7 +421,7 @@ ASN1_STRING_type_new(int type)
421 421
422 ret = malloc(sizeof(ASN1_STRING)); 422 ret = malloc(sizeof(ASN1_STRING));
423 if (ret == NULL) { 423 if (ret == NULL) {
424 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE); 424 ASN1error(ERR_R_MALLOC_FAILURE);
425 return (NULL); 425 return (NULL);
426 } 426 }
427 ret->length = 0; 427 ret->length = 0;
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c
index 1d82f1a76f..6bad111775 100644
--- a/src/lib/libcrypto/asn1/asn_mime.c
+++ b/src/lib/libcrypto/asn1/asn_mime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_mime.c,v 1.26 2015/02/22 15:19:56 jsing Exp $ */ 1/* $OpenBSD: asn_mime.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -122,8 +122,7 @@ i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
122 BIO *bio, *tbio; 122 BIO *bio, *tbio;
123 bio = BIO_new_NDEF(out, val, it); 123 bio = BIO_new_NDEF(out, val, it);
124 if (!bio) { 124 if (!bio) {
125 ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM, 125 ASN1error(ERR_R_MALLOC_FAILURE);
126 ERR_R_MALLOC_FAILURE);
127 return 0; 126 return 0;
128 } 127 }
129 SMIME_crlf_copy(in, bio, flags); 128 SMIME_crlf_copy(in, bio, flags);
@@ -154,7 +153,7 @@ B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
154 153
155 b64 = BIO_new(BIO_f_base64()); 154 b64 = BIO_new(BIO_f_base64());
156 if (!b64) { 155 if (!b64) {
157 ASN1err(ASN1_F_B64_WRITE_ASN1, ERR_R_MALLOC_FAILURE); 156 ASN1error(ERR_R_MALLOC_FAILURE);
158 return 0; 157 return 0;
159 } 158 }
160 /* prepend the b64 BIO so all data is base64 encoded. 159 /* prepend the b64 BIO so all data is base64 encoded.
@@ -187,13 +186,13 @@ b64_read_asn1(BIO *bio, const ASN1_ITEM *it)
187 BIO *b64; 186 BIO *b64;
188 ASN1_VALUE *val; 187 ASN1_VALUE *val;
189 if (!(b64 = BIO_new(BIO_f_base64()))) { 188 if (!(b64 = BIO_new(BIO_f_base64()))) {
190 ASN1err(ASN1_F_B64_READ_ASN1, ERR_R_MALLOC_FAILURE); 189 ASN1error(ERR_R_MALLOC_FAILURE);
191 return 0; 190 return 0;
192 } 191 }
193 bio = BIO_push(b64, bio); 192 bio = BIO_push(b64, bio);
194 val = ASN1_item_d2i_bio(it, bio, NULL); 193 val = ASN1_item_d2i_bio(it, bio, NULL);
195 if (!val) 194 if (!val)
196 ASN1err(ASN1_F_B64_READ_ASN1, ASN1_R_DECODE_ERROR); 195 ASN1error(ASN1_R_DECODE_ERROR);
197 (void)BIO_flush(bio); 196 (void)BIO_flush(bio);
198 bio = BIO_pop(bio); 197 bio = BIO_pop(bio);
199 BIO_free(b64); 198 BIO_free(b64);
@@ -388,8 +387,7 @@ asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
388 } 387 }
389 388
390 if (!aux || !aux->asn1_cb) { 389 if (!aux || !aux->asn1_cb) {
391 ASN1err(ASN1_F_ASN1_OUTPUT_DATA, 390 ASN1error(ASN1_R_STREAMING_NOT_SUPPORTED);
392 ASN1_R_STREAMING_NOT_SUPPORTED);
393 return 0; 391 return 0;
394 } 392 }
395 393
@@ -440,13 +438,13 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
440 *bcont = NULL; 438 *bcont = NULL;
441 439
442 if (!(headers = mime_parse_hdr(bio))) { 440 if (!(headers = mime_parse_hdr(bio))) {
443 ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_MIME_PARSE_ERROR); 441 ASN1error(ASN1_R_MIME_PARSE_ERROR);
444 return NULL; 442 return NULL;
445 } 443 }
446 444
447 if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { 445 if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
448 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 446 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
449 ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_NO_CONTENT_TYPE); 447 ASN1error(ASN1_R_NO_CONTENT_TYPE);
450 return NULL; 448 return NULL;
451 } 449 }
452 450
@@ -457,15 +455,13 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
457 prm = mime_param_find(hdr, "boundary"); 455 prm = mime_param_find(hdr, "boundary");
458 if (!prm || !prm->param_value) { 456 if (!prm || !prm->param_value) {
459 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 457 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
460 ASN1err(ASN1_F_SMIME_READ_ASN1, 458 ASN1error(ASN1_R_NO_MULTIPART_BOUNDARY);
461 ASN1_R_NO_MULTIPART_BOUNDARY);
462 return NULL; 459 return NULL;
463 } 460 }
464 ret = multi_split(bio, prm->param_value, &parts); 461 ret = multi_split(bio, prm->param_value, &parts);
465 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 462 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
466 if (!ret || (sk_BIO_num(parts) != 2) ) { 463 if (!ret || (sk_BIO_num(parts) != 2) ) {
467 ASN1err(ASN1_F_SMIME_READ_ASN1, 464 ASN1error(ASN1_R_NO_MULTIPART_BODY_FAILURE);
468 ASN1_R_NO_MULTIPART_BODY_FAILURE);
469 sk_BIO_pop_free(parts, BIO_vfree); 465 sk_BIO_pop_free(parts, BIO_vfree);
470 return NULL; 466 return NULL;
471 } 467 }
@@ -474,8 +470,7 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
474 asnin = sk_BIO_value(parts, 1); 470 asnin = sk_BIO_value(parts, 1);
475 471
476 if (!(headers = mime_parse_hdr(asnin))) { 472 if (!(headers = mime_parse_hdr(asnin))) {
477 ASN1err(ASN1_F_SMIME_READ_ASN1, 473 ASN1error(ASN1_R_MIME_SIG_PARSE_ERROR);
478 ASN1_R_MIME_SIG_PARSE_ERROR);
479 sk_BIO_pop_free(parts, BIO_vfree); 474 sk_BIO_pop_free(parts, BIO_vfree);
480 return NULL; 475 return NULL;
481 } 476 }
@@ -486,15 +481,13 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
486 !hdr->value) { 481 !hdr->value) {
487 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 482 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
488 sk_BIO_pop_free(parts, BIO_vfree); 483 sk_BIO_pop_free(parts, BIO_vfree);
489 ASN1err(ASN1_F_SMIME_READ_ASN1, 484 ASN1error(ASN1_R_NO_SIG_CONTENT_TYPE);
490 ASN1_R_NO_SIG_CONTENT_TYPE);
491 return NULL; 485 return NULL;
492 } 486 }
493 487
494 if (strcmp(hdr->value, "application/x-pkcs7-signature") && 488 if (strcmp(hdr->value, "application/x-pkcs7-signature") &&
495 strcmp(hdr->value, "application/pkcs7-signature")) { 489 strcmp(hdr->value, "application/pkcs7-signature")) {
496 ASN1err(ASN1_F_SMIME_READ_ASN1, 490 ASN1error(ASN1_R_SIG_INVALID_MIME_TYPE);
497 ASN1_R_SIG_INVALID_MIME_TYPE);
498 ERR_asprintf_error_data("type: %s", hdr->value); 491 ERR_asprintf_error_data("type: %s", hdr->value);
499 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 492 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
500 sk_BIO_pop_free(parts, BIO_vfree); 493 sk_BIO_pop_free(parts, BIO_vfree);
@@ -503,8 +496,7 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
503 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 496 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
504 /* Read in ASN1 */ 497 /* Read in ASN1 */
505 if (!(val = b64_read_asn1(asnin, it))) { 498 if (!(val = b64_read_asn1(asnin, it))) {
506 ASN1err(ASN1_F_SMIME_READ_ASN1, 499 ASN1error(ASN1_R_ASN1_SIG_PARSE_ERROR);
507 ASN1_R_ASN1_SIG_PARSE_ERROR);
508 sk_BIO_pop_free(parts, BIO_vfree); 500 sk_BIO_pop_free(parts, BIO_vfree);
509 return NULL; 501 return NULL;
510 } 502 }
@@ -521,7 +513,7 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
521 513
522 if (strcmp (hdr->value, "application/x-pkcs7-mime") && 514 if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
523 strcmp (hdr->value, "application/pkcs7-mime")) { 515 strcmp (hdr->value, "application/pkcs7-mime")) {
524 ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_INVALID_MIME_TYPE); 516 ASN1error(ASN1_R_INVALID_MIME_TYPE);
525 ERR_asprintf_error_data("type: %s", hdr->value); 517 ERR_asprintf_error_data("type: %s", hdr->value);
526 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 518 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
527 return NULL; 519 return NULL;
@@ -530,7 +522,7 @@ SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it)
530 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 522 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
531 523
532 if (!(val = b64_read_asn1(bio, it))) { 524 if (!(val = b64_read_asn1(bio, it))) {
533 ASN1err(ASN1_F_SMIME_READ_ASN1, ASN1_R_ASN1_PARSE_ERROR); 525 ASN1error(ASN1_R_ASN1_PARSE_ERROR);
534 return NULL; 526 return NULL;
535 } 527 }
536 return val; 528 return val;
@@ -583,16 +575,16 @@ SMIME_text(BIO *in, BIO *out)
583 MIME_HEADER *hdr; 575 MIME_HEADER *hdr;
584 576
585 if (!(headers = mime_parse_hdr(in))) { 577 if (!(headers = mime_parse_hdr(in))) {
586 ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR); 578 ASN1error(ASN1_R_MIME_PARSE_ERROR);
587 return 0; 579 return 0;
588 } 580 }
589 if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { 581 if (!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
590 ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE); 582 ASN1error(ASN1_R_MIME_NO_CONTENT_TYPE);
591 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 583 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
592 return 0; 584 return 0;
593 } 585 }
594 if (strcmp (hdr->value, "text/plain")) { 586 if (strcmp (hdr->value, "text/plain")) {
595 ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_INVALID_MIME_TYPE); 587 ASN1error(ASN1_R_INVALID_MIME_TYPE);
596 ERR_asprintf_error_data("type: %s", hdr->value); 588 ERR_asprintf_error_data("type: %s", hdr->value);
597 sk_MIME_HEADER_pop_free(headers, mime_hdr_free); 589 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
598 return 0; 590 return 0;
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
index 76b6405212..7bf493e288 100644
--- a/src/lib/libcrypto/asn1/asn_moid.c
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_moid.c,v 1.12 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: asn_moid.c,v 1.13 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -79,13 +79,13 @@ oid_module_init(CONF_IMODULE *md, const CONF *cnf)
79 79
80 oid_section = CONF_imodule_get_value(md); 80 oid_section = CONF_imodule_get_value(md);
81 if (!(sktmp = NCONF_get_section(cnf, oid_section))) { 81 if (!(sktmp = NCONF_get_section(cnf, oid_section))) {
82 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); 82 ASN1error(ASN1_R_ERROR_LOADING_SECTION);
83 return 0; 83 return 0;
84 } 84 }
85 for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { 85 for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
86 oval = sk_CONF_VALUE_value(sktmp, i); 86 oval = sk_CONF_VALUE_value(sktmp, i);
87 if (!do_create(oval->value, oval->name)) { 87 if (!do_create(oval->value, oval->name)) {
88 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); 88 ASN1error(ASN1_R_ADDING_OBJECT);
89 return 0; 89 return 0;
90 } 90 }
91 } 91 }
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
index 65f4b9bf97..09d150583a 100644
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn_pack.c,v 1.15 2015/12/23 20:37:23 mmcc Exp $ */ 1/* $OpenBSD: asn_pack.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -77,7 +77,7 @@ ASN1_seq_unpack(const unsigned char *buf, int len, d2i_of_void *d2i,
77 pbuf = buf; 77 pbuf = buf;
78 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, 78 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
79 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) 79 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
80 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR); 80 ASN1error(ASN1_R_DECODE_ERROR);
81 return sk; 81 return sk;
82} 82}
83 83
@@ -94,11 +94,11 @@ ASN1_seq_pack(STACK_OF(OPENSSL_BLOCK) *safes, i2d_of_void *i2d,
94 94
95 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE, 95 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
96 V_ASN1_UNIVERSAL, IS_SEQUENCE))) { 96 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
97 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR); 97 ASN1error(ASN1_R_ENCODE_ERROR);
98 return NULL; 98 return NULL;
99 } 99 }
100 if (!(safe = malloc(safelen))) { 100 if (!(safe = malloc(safelen))) {
101 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE); 101 ASN1error(ERR_R_MALLOC_FAILURE);
102 return NULL; 102 return NULL;
103 } 103 }
104 p = safe; 104 p = safe;
@@ -121,7 +121,7 @@ ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
121 121
122 p = oct->data; 122 p = oct->data;
123 if (!(ret = d2i(NULL, &p, oct->length))) 123 if (!(ret = d2i(NULL, &p, oct->length)))
124 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); 124 ASN1error(ASN1_R_DECODE_ERROR);
125 return ret; 125 return ret;
126} 126}
127 127
@@ -135,18 +135,18 @@ ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
135 135
136 if (!oct || !*oct) { 136 if (!oct || !*oct) {
137 if (!(octmp = ASN1_STRING_new())) { 137 if (!(octmp = ASN1_STRING_new())) {
138 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); 138 ASN1error(ERR_R_MALLOC_FAILURE);
139 return NULL; 139 return NULL;
140 } 140 }
141 } else 141 } else
142 octmp = *oct; 142 octmp = *oct;
143 143
144 if (!(octmp->length = i2d(obj, NULL))) { 144 if (!(octmp->length = i2d(obj, NULL))) {
145 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); 145 ASN1error(ASN1_R_ENCODE_ERROR);
146 goto err; 146 goto err;
147 } 147 }
148 if (!(p = malloc (octmp->length))) { 148 if (!(p = malloc (octmp->length))) {
149 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); 149 ASN1error(ERR_R_MALLOC_FAILURE);
150 goto err; 150 goto err;
151 } 151 }
152 octmp->data = p; 152 octmp->data = p;
@@ -174,7 +174,7 @@ ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
174 174
175 if (!oct || !*oct) { 175 if (!oct || !*oct) {
176 if (!(octmp = ASN1_STRING_new ())) { 176 if (!(octmp = ASN1_STRING_new ())) {
177 ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE); 177 ASN1error(ERR_R_MALLOC_FAILURE);
178 return NULL; 178 return NULL;
179 } 179 }
180 } else 180 } else
@@ -184,11 +184,11 @@ ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
184 octmp->data = NULL; 184 octmp->data = NULL;
185 185
186 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { 186 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
187 ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR); 187 ASN1error(ASN1_R_ENCODE_ERROR);
188 goto err; 188 goto err;
189 } 189 }
190 if (!octmp->data) { 190 if (!octmp->data) {
191 ASN1err(ASN1_F_ASN1_ITEM_PACK, ERR_R_MALLOC_FAILURE); 191 ASN1error(ERR_R_MALLOC_FAILURE);
192 goto err; 192 goto err;
193 } 193 }
194 if (oct) 194 if (oct)
@@ -210,6 +210,6 @@ ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
210 210
211 p = oct->data; 211 p = oct->data;
212 if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) 212 if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
213 ASN1err(ASN1_F_ASN1_ITEM_UNPACK, ASN1_R_DECODE_ERROR); 213 ASN1error(ASN1_R_DECODE_ERROR);
214 return ret; 214 return ret;
215} 215}
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c
index 1a23c27d04..890b141304 100644
--- a/src/lib/libcrypto/asn1/bio_ndef.c
+++ b/src/lib/libcrypto/asn1/bio_ndef.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_ndef.c,v 1.9 2014/07/25 06:05:32 doug Exp $ */ 1/* $OpenBSD: bio_ndef.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -106,7 +106,7 @@ BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
106 ASN1_STREAM_ARG sarg; 106 ASN1_STREAM_ARG sarg;
107 107
108 if (!aux || !aux->asn1_cb) { 108 if (!aux || !aux->asn1_cb) {
109 ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); 109 ASN1error(ASN1_R_STREAMING_NOT_SUPPORTED);
110 return NULL; 110 return NULL;
111 } 111 }
112 ndef_aux = malloc(sizeof(NDEF_SUPPORT)); 112 ndef_aux = malloc(sizeof(NDEF_SUPPORT));
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
index 68d02177c4..7a5880a8cd 100644
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d2i_pr.c,v 1.14 2015/03/19 14:00:22 tedu Exp $ */ 1/* $OpenBSD: d2i_pr.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,7 +80,7 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
80 80
81 if ((a == NULL) || (*a == NULL)) { 81 if ((a == NULL) || (*a == NULL)) {
82 if ((ret = EVP_PKEY_new()) == NULL) { 82 if ((ret = EVP_PKEY_new()) == NULL) {
83 ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_EVP_LIB); 83 ASN1error(ERR_R_EVP_LIB);
84 return (NULL); 84 return (NULL);
85 } 85 }
86 } else { 86 } else {
@@ -94,7 +94,7 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
94 } 94 }
95 95
96 if (!EVP_PKEY_set_type(ret, type)) { 96 if (!EVP_PKEY_set_type(ret, type)) {
97 ASN1err(ASN1_F_D2I_PRIVATEKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 97 ASN1error(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
98 goto err; 98 goto err;
99 } 99 }
100 100
@@ -109,7 +109,7 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
109 ret = EVP_PKCS82PKEY(p8); 109 ret = EVP_PKCS82PKEY(p8);
110 PKCS8_PRIV_KEY_INFO_free(p8); 110 PKCS8_PRIV_KEY_INFO_free(p8);
111 } else { 111 } else {
112 ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB); 112 ASN1error(ERR_R_ASN1_LIB);
113 goto err; 113 goto err;
114 } 114 }
115 } 115 }
@@ -153,8 +153,7 @@ d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length)
153 153
154 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); 154 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
155 if (!p8) { 155 if (!p8) {
156 ASN1err(ASN1_F_D2I_AUTOPRIVATEKEY, 156 ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
157 ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
158 return NULL; 157 return NULL;
159 } 158 }
160 ret = EVP_PKCS82PKEY(p8); 159 ret = EVP_PKCS82PKEY(p8);
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
index e917356254..3750265e7f 100644
--- a/src/lib/libcrypto/asn1/d2i_pu.c
+++ b/src/lib/libcrypto/asn1/d2i_pu.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d2i_pu.c,v 1.13 2015/03/19 14:00:22 tedu Exp $ */ 1/* $OpenBSD: d2i_pu.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -83,14 +83,14 @@ d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
83 83
84 if ((a == NULL) || (*a == NULL)) { 84 if ((a == NULL) || (*a == NULL)) {
85 if ((ret = EVP_PKEY_new()) == NULL) { 85 if ((ret = EVP_PKEY_new()) == NULL) {
86 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); 86 ASN1error(ERR_R_EVP_LIB);
87 return (NULL); 87 return (NULL);
88 } 88 }
89 } else 89 } else
90 ret = *a; 90 ret = *a;
91 91
92 if (!EVP_PKEY_set_type(ret, type)) { 92 if (!EVP_PKEY_set_type(ret, type)) {
93 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); 93 ASN1error(ERR_R_EVP_LIB);
94 goto err; 94 goto err;
95 } 95 }
96 96
@@ -99,7 +99,7 @@ d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
99 case EVP_PKEY_RSA: 99 case EVP_PKEY_RSA:
100 if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, pp, length)) == 100 if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, pp, length)) ==
101 NULL) { 101 NULL) {
102 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); 102 ASN1error(ERR_R_ASN1_LIB);
103 goto err; 103 goto err;
104 } 104 }
105 break; 105 break;
@@ -107,7 +107,7 @@ d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
107#ifndef OPENSSL_NO_DSA 107#ifndef OPENSSL_NO_DSA
108 case EVP_PKEY_DSA: 108 case EVP_PKEY_DSA:
109 if (!d2i_DSAPublicKey(&(ret->pkey.dsa), pp, length)) { 109 if (!d2i_DSAPublicKey(&(ret->pkey.dsa), pp, length)) {
110 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); 110 ASN1error(ERR_R_ASN1_LIB);
111 goto err; 111 goto err;
112 } 112 }
113 break; 113 break;
@@ -115,13 +115,13 @@ d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
115#ifndef OPENSSL_NO_EC 115#ifndef OPENSSL_NO_EC
116 case EVP_PKEY_EC: 116 case EVP_PKEY_EC:
117 if (!o2i_ECPublicKey(&(ret->pkey.ec), pp, length)) { 117 if (!o2i_ECPublicKey(&(ret->pkey.ec), pp, length)) {
118 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB); 118 ASN1error(ERR_R_ASN1_LIB);
119 goto err; 119 goto err;
120 } 120 }
121 break; 121 break;
122#endif 122#endif
123 default: 123 default:
124 ASN1err(ASN1_F_D2I_PUBLICKEY, ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 124 ASN1error(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
125 goto err; 125 goto err;
126 /* break; */ 126 /* break; */
127 } 127 }
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
index 1f36cebad7..83228bb5d2 100644
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_asn1.c,v 1.18 2015/09/30 19:07:08 jsing Exp $ */ 1/* $OpenBSD: evp_asn1.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -87,7 +87,7 @@ ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len)
87 87
88 if ((a->type != V_ASN1_OCTET_STRING) || 88 if ((a->type != V_ASN1_OCTET_STRING) ||
89 (a->value.octet_string == NULL)) { 89 (a->value.octet_string == NULL)) {
90 ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING, ASN1_R_DATA_IS_WRONG); 90 ASN1error(ASN1_R_DATA_IS_WRONG);
91 return (-1); 91 return (-1);
92 } 92 }
93 p = ASN1_STRING_data(a->value.octet_string); 93 p = ASN1_STRING_data(a->value.octet_string);
@@ -192,8 +192,7 @@ ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
192 memcpy(data, ASN1_STRING_data(os), n); 192 memcpy(data, ASN1_STRING_data(os), n);
193 if (0) { 193 if (0) {
194err: 194err:
195 ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING, 195 ASN1error(ASN1_R_DATA_IS_WRONG);
196 ASN1_R_DATA_IS_WRONG);
197 } 196 }
198 ASN1_OCTET_STRING_free(os); 197 ASN1_OCTET_STRING_free(os);
199 ASN1_INTEGER_free(ai); 198 ASN1_INTEGER_free(ai);
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
index 7f064edb04..64feb97dc4 100644
--- a/src/lib/libcrypto/asn1/f_enum.c
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: f_enum.c,v 1.14 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: f_enum.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -150,16 +150,14 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
150 k = 0; 150 k = 0;
151 i -= again; 151 i -= again;
152 if (i % 2 != 0) { 152 if (i % 2 != 0) {
153 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, 153 ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
154 ASN1_R_ODD_NUMBER_OF_CHARS);
155 goto err; 154 goto err;
156 } 155 }
157 i /= 2; 156 i /= 2;
158 if (num + i > slen) { 157 if (num + i > slen) {
159 sp = realloc(s, num + i); 158 sp = realloc(s, num + i);
160 if (sp == NULL) { 159 if (sp == NULL) {
161 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, 160 ASN1error(ERR_R_MALLOC_FAILURE);
162 ERR_R_MALLOC_FAILURE);
163 goto err; 161 goto err;
164 } 162 }
165 s = sp; 163 s = sp;
@@ -175,8 +173,7 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
175 else if ((m >= 'A') && (m <= 'F')) 173 else if ((m >= 'A') && (m <= 'F'))
176 m = m - 'A' + 10; 174 m = m - 'A' + 10;
177 else { 175 else {
178 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, 176 ASN1error(ASN1_R_NON_HEX_CHARACTERS);
179 ASN1_R_NON_HEX_CHARACTERS);
180 goto err; 177 goto err;
181 } 178 }
182 s[num + j] <<= 4; 179 s[num + j] <<= 4;
@@ -194,7 +191,7 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
194 return (1); 191 return (1);
195 192
196err_sl: 193err_sl:
197 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ASN1_R_SHORT_LINE); 194 ASN1error(ASN1_R_SHORT_LINE);
198err: 195err:
199 free(s); 196 free(s);
200 return (ret); 197 return (ret);
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
index 0ec29f5769..75168872b3 100644
--- a/src/lib/libcrypto/asn1/f_int.c
+++ b/src/lib/libcrypto/asn1/f_int.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: f_int.c,v 1.17 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: f_int.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -153,16 +153,14 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
153 k = 0; 153 k = 0;
154 i -= again; 154 i -= again;
155 if (i % 2 != 0) { 155 if (i % 2 != 0) {
156 ASN1err(ASN1_F_A2I_ASN1_INTEGER, 156 ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
157 ASN1_R_ODD_NUMBER_OF_CHARS);
158 goto err; 157 goto err;
159 } 158 }
160 i /= 2; 159 i /= 2;
161 if (num + i > slen) { 160 if (num + i > slen) {
162 sp = OPENSSL_realloc_clean(s, slen, num + i); 161 sp = OPENSSL_realloc_clean(s, slen, num + i);
163 if (sp == NULL) { 162 if (sp == NULL) {
164 ASN1err(ASN1_F_A2I_ASN1_INTEGER, 163 ASN1error(ERR_R_MALLOC_FAILURE);
165 ERR_R_MALLOC_FAILURE);
166 goto err; 164 goto err;
167 } 165 }
168 s = sp; 166 s = sp;
@@ -178,8 +176,7 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
178 else if ((m >= 'A') && (m <= 'F')) 176 else if ((m >= 'A') && (m <= 'F'))
179 m = m - 'A' + 10; 177 m = m - 'A' + 10;
180 else { 178 else {
181 ASN1err(ASN1_F_A2I_ASN1_INTEGER, 179 ASN1error(ASN1_R_NON_HEX_CHARACTERS);
182 ASN1_R_NON_HEX_CHARACTERS);
183 goto err; 180 goto err;
184 } 181 }
185 s[num + j] <<= 4; 182 s[num + j] <<= 4;
@@ -197,7 +194,7 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
197 return (1); 194 return (1);
198 195
199err_sl: 196err_sl:
200 ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE); 197 ASN1error(ASN1_R_SHORT_LINE);
201err: 198err:
202 free(s); 199 free(s);
203 return (ret); 200 return (ret);
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
index 14cd1a906a..138044e063 100644
--- a/src/lib/libcrypto/asn1/f_string.c
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: f_string.c,v 1.16 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: f_string.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -146,16 +146,14 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
146 k = 0; 146 k = 0;
147 i -= again; 147 i -= again;
148 if (i % 2 != 0) { 148 if (i % 2 != 0) {
149 ASN1err(ASN1_F_A2I_ASN1_STRING, 149 ASN1error(ASN1_R_ODD_NUMBER_OF_CHARS);
150 ASN1_R_ODD_NUMBER_OF_CHARS);
151 goto err; 150 goto err;
152 } 151 }
153 i /= 2; 152 i /= 2;
154 if (num + i > slen) { 153 if (num + i > slen) {
155 sp = realloc(s, num + i); 154 sp = realloc(s, num + i);
156 if (sp == NULL) { 155 if (sp == NULL) {
157 ASN1err(ASN1_F_A2I_ASN1_STRING, 156 ASN1error(ERR_R_MALLOC_FAILURE);
158 ERR_R_MALLOC_FAILURE);
159 goto err; 157 goto err;
160 } 158 }
161 s = sp; 159 s = sp;
@@ -171,8 +169,7 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
171 else if ((m >= 'A') && (m <= 'F')) 169 else if ((m >= 'A') && (m <= 'F'))
172 m = m - 'A' + 10; 170 m = m - 'A' + 10;
173 else { 171 else {
174 ASN1err(ASN1_F_A2I_ASN1_STRING, 172 ASN1error(ASN1_R_NON_HEX_CHARACTERS);
175 ASN1_R_NON_HEX_CHARACTERS);
176 goto err; 173 goto err;
177 } 174 }
178 s[num + j] <<= 4; 175 s[num + j] <<= 4;
@@ -190,7 +187,7 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
190 return (1); 187 return (1);
191 188
192err_sl: 189err_sl:
193 ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); 190 ASN1error(ASN1_R_SHORT_LINE);
194err: 191err:
195 free(s); 192 free(s);
196 return (ret); 193 return (ret);
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c
index 5fa34678b6..0b545aeb49 100644
--- a/src/lib/libcrypto/asn1/i2d_pr.c
+++ b/src/lib/libcrypto/asn1/i2d_pr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: i2d_pr.c,v 1.10 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: i2d_pr.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -76,6 +76,6 @@ i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
76 PKCS8_PRIV_KEY_INFO_free(p8); 76 PKCS8_PRIV_KEY_INFO_free(p8);
77 return ret; 77 return ret;
78 } 78 }
79 ASN1err(ASN1_F_I2D_PRIVATEKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); 79 ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
80 return (-1); 80 return (-1);
81} 81}
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
index 6e485ea325..9baa84967b 100644
--- a/src/lib/libcrypto/asn1/i2d_pu.c
+++ b/src/lib/libcrypto/asn1/i2d_pu.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: i2d_pu.c,v 1.10 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: i2d_pu.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -92,7 +92,7 @@ i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
92 return (i2o_ECPublicKey(a->pkey.ec, pp)); 92 return (i2o_ECPublicKey(a->pkey.ec, pp));
93#endif 93#endif
94 default: 94 default:
95 ASN1err(ASN1_F_I2D_PUBLICKEY, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); 95 ASN1error(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
96 return (-1); 96 return (-1);
97 } 97 }
98} 98}
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index 1e73c82d09..d2fabf6e87 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: n_pkey.c,v 1.30 2015/10/16 15:15:39 jsing Exp $ */ 1/* $OpenBSD: n_pkey.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -260,7 +260,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
260 260
261 /* Since its RC4 encrypted length is actual length */ 261 /* Since its RC4 encrypted length is actual length */
262 if ((zz = malloc(rsalen)) == NULL) { 262 if ((zz = malloc(rsalen)) == NULL) {
263 ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE); 263 ASN1error(ERR_R_MALLOC_FAILURE);
264 goto err; 264 goto err;
265 } 265 }
266 266
@@ -269,12 +269,12 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
269 i2d_RSAPrivateKey(a, &zz); 269 i2d_RSAPrivateKey(a, &zz);
270 270
271 if ((zz = malloc(pkeylen)) == NULL) { 271 if ((zz = malloc(pkeylen)) == NULL) {
272 ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE); 272 ASN1error(ERR_R_MALLOC_FAILURE);
273 goto err; 273 goto err;
274 } 274 }
275 275
276 if (!ASN1_STRING_set(enckey->os, "private-key", -1)) { 276 if (!ASN1_STRING_set(enckey->os, "private-key", -1)) {
277 ASN1err(ASN1_F_I2D_RSA_NET, ERR_R_MALLOC_FAILURE); 277 ASN1error(ERR_R_MALLOC_FAILURE);
278 goto err; 278 goto err;
279 } 279 }
280 enckey->enckey->digest->data = zz; 280 enckey->enckey->digest->data = zz;
@@ -287,7 +287,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
287 cb = EVP_read_pw_string; 287 cb = EVP_read_pw_string;
288 i = cb((char *)buf, sizeof(buf), "Enter Private Key password:", 1); 288 i = cb((char *)buf, sizeof(buf), "Enter Private Key password:", 1);
289 if (i != 0) { 289 if (i != 0) {
290 ASN1err(ASN1_F_I2D_RSA_NET, ASN1_R_BAD_PASSWORD_READ); 290 ASN1error(ASN1_R_BAD_PASSWORD_READ);
291 goto err; 291 goto err;
292 } 292 }
293 i = strlen((char *)buf); 293 i = strlen((char *)buf);
@@ -340,19 +340,18 @@ d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
340 340
341 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); 341 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
342 if (!enckey) { 342 if (!enckey) {
343 ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_DECODING_ERROR); 343 ASN1error(ASN1_R_DECODING_ERROR);
344 return NULL; 344 return NULL;
345 } 345 }
346 346
347 /* XXX 11 == strlen("private-key") */ 347 /* XXX 11 == strlen("private-key") */
348 if (enckey->os->length != 11 || 348 if (enckey->os->length != 11 ||
349 memcmp("private-key", enckey->os->data, 11) != 0) { 349 memcmp("private-key", enckey->os->data, 11) != 0) {
350 ASN1err(ASN1_F_D2I_RSA_NET, ASN1_R_PRIVATE_KEY_HEADER_MISSING); 350 ASN1error(ASN1_R_PRIVATE_KEY_HEADER_MISSING);
351 goto err; 351 goto err;
352 } 352 }
353 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { 353 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) {
354 ASN1err(ASN1_F_D2I_RSA_NET, 354 ASN1error(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
355 ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
356 goto err; 355 goto err;
357 } 356 }
358 if (cb == NULL) 357 if (cb == NULL)
@@ -384,7 +383,7 @@ d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
384 383
385 i=cb((char *)buf, sizeof(buf), "Enter Private Key password:",0); 384 i=cb((char *)buf, sizeof(buf), "Enter Private Key password:",0);
386 if (i != 0) { 385 if (i != 0) {
387 ASN1err(ASN1_F_D2I_RSA_NET_2, ASN1_R_BAD_PASSWORD_READ); 386 ASN1error(ASN1_R_BAD_PASSWORD_READ);
388 goto err; 387 goto err;
389 } 388 }
390 389
@@ -411,15 +410,14 @@ d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
411 zz = os->data; 410 zz = os->data;
412 411
413 if ((pkey = d2i_NETSCAPE_PKEY(NULL, &zz, os->length)) == NULL) { 412 if ((pkey = d2i_NETSCAPE_PKEY(NULL, &zz, os->length)) == NULL) {
414 ASN1err(ASN1_F_D2I_RSA_NET_2, 413 ASN1error(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
415 ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
416 goto err; 414 goto err;
417 } 415 }
418 416
419 zz = pkey->private_key->data; 417 zz = pkey->private_key->data;
420 if ((ret = d2i_RSAPrivateKey(a, &zz, 418 if ((ret = d2i_RSAPrivateKey(a, &zz,
421 pkey->private_key->length)) == NULL) { 419 pkey->private_key->length)) == NULL) {
422 ASN1err(ASN1_F_D2I_RSA_NET_2, ASN1_R_UNABLE_TO_DECODE_RSA_KEY); 420 ASN1error(ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
423 goto err; 421 goto err;
424 } 422 }
425 423
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
index e0609e02e9..8fd416a3e5 100644
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_pbe.c,v 1.21 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: p5_pbe.c,v 1.22 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -127,19 +127,19 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
127 127
128 pbe = PBEPARAM_new(); 128 pbe = PBEPARAM_new();
129 if (!pbe) { 129 if (!pbe) {
130 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); 130 ASN1error(ERR_R_MALLOC_FAILURE);
131 goto err; 131 goto err;
132 } 132 }
133 if (iter <= 0) 133 if (iter <= 0)
134 iter = PKCS5_DEFAULT_ITER; 134 iter = PKCS5_DEFAULT_ITER;
135 if (!ASN1_INTEGER_set(pbe->iter, iter)) { 135 if (!ASN1_INTEGER_set(pbe->iter, iter)) {
136 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); 136 ASN1error(ERR_R_MALLOC_FAILURE);
137 goto err; 137 goto err;
138 } 138 }
139 if (!saltlen) 139 if (!saltlen)
140 saltlen = PKCS5_SALT_LEN; 140 saltlen = PKCS5_SALT_LEN;
141 if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) { 141 if (!ASN1_STRING_set(pbe->salt, NULL, saltlen)) {
142 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); 142 ASN1error(ERR_R_MALLOC_FAILURE);
143 goto err; 143 goto err;
144 } 144 }
145 sstr = ASN1_STRING_data(pbe->salt); 145 sstr = ASN1_STRING_data(pbe->salt);
@@ -149,7 +149,7 @@ PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter,
149 arc4random_buf(sstr, saltlen); 149 arc4random_buf(sstr, saltlen);
150 150
151 if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) { 151 if (!ASN1_item_pack(pbe, &PBEPARAM_it, &pbe_str)) {
152 ASN1err(ASN1_F_PKCS5_PBE_SET0_ALGOR, ERR_R_MALLOC_FAILURE); 152 ASN1error(ERR_R_MALLOC_FAILURE);
153 goto err; 153 goto err;
154 } 154 }
155 155
@@ -174,7 +174,7 @@ PKCS5_pbe_set(int alg, int iter, const unsigned char *salt, int saltlen)
174 X509_ALGOR *ret; 174 X509_ALGOR *ret;
175 ret = X509_ALGOR_new(); 175 ret = X509_ALGOR_new();
176 if (!ret) { 176 if (!ret) {
177 ASN1err(ASN1_F_PKCS5_PBE_SET, ERR_R_MALLOC_FAILURE); 177 ASN1error(ERR_R_MALLOC_FAILURE);
178 return NULL; 178 return NULL;
179 } 179 }
180 180
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
index 155e2b0b3e..0105c59549 100644
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_pbev2.c,v 1.24 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: p5_pbev2.c,v 1.25 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999-2004. 3 * project 1999-2004.
4 */ 4 */
@@ -193,8 +193,7 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
193 193
194 alg_nid = EVP_CIPHER_type(cipher); 194 alg_nid = EVP_CIPHER_type(cipher);
195 if (alg_nid == NID_undef) { 195 if (alg_nid == NID_undef) {
196 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, 196 ASN1error(ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
197 ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
198 goto err; 197 goto err;
199 } 198 }
200 obj = OBJ_nid2obj(alg_nid); 199 obj = OBJ_nid2obj(alg_nid);
@@ -223,8 +222,7 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
223 if (!EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0)) 222 if (!EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0))
224 goto err; 223 goto err;
225 if (EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { 224 if (EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
226 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, 225 ASN1error(ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
227 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
228 EVP_CIPHER_CTX_cleanup(&ctx); 226 EVP_CIPHER_CTX_cleanup(&ctx);
229 goto err; 227 goto err;
230 } 228 }
@@ -275,7 +273,7 @@ PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, unsigned char *salt,
275 return ret; 273 return ret;
276 274
277merr: 275merr:
278 ASN1err(ASN1_F_PKCS5_PBE2_SET_IV, ERR_R_MALLOC_FAILURE); 276 ASN1error(ERR_R_MALLOC_FAILURE);
279 277
280err: 278err:
281 PBE2PARAM_free(pbe2); 279 PBE2PARAM_free(pbe2);
@@ -367,7 +365,7 @@ PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, int prf_nid,
367 return keyfunc; 365 return keyfunc;
368 366
369merr: 367merr:
370 ASN1err(ASN1_F_PKCS5_PBKDF2_SET, ERR_R_MALLOC_FAILURE); 368 ASN1error(ERR_R_MALLOC_FAILURE);
371 PBKDF2PARAM_free(kdf); 369 PBKDF2PARAM_free(kdf);
372 X509_ALGOR_free(keyfunc); 370 X509_ALGOR_free(keyfunc);
373 return NULL; 371 return NULL;
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index 67116361a5..c8122442bb 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_crl.c,v 1.16 2014/07/12 16:33:25 miod Exp $ */ 1/* $OpenBSD: t_crl.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -72,7 +72,7 @@ X509_CRL_print_fp(FILE *fp, X509_CRL *x)
72 int ret; 72 int ret;
73 73
74 if ((b = BIO_new(BIO_s_file())) == NULL) { 74 if ((b = BIO_new(BIO_s_file())) == NULL) {
75 X509err(X509_F_X509_CRL_PRINT_FP, ERR_R_BUF_LIB); 75 X509error(ERR_R_BUF_LIB);
76 return (0); 76 return (0);
77 } 77 }
78 BIO_set_fp(b, fp, BIO_NOCLOSE); 78 BIO_set_fp(b, fp, BIO_NOCLOSE);
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index 8db456708a..a9b14fed73 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_req.c,v 1.18 2015/07/29 14:58:34 jsing Exp $ */ 1/* $OpenBSD: t_req.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -81,7 +81,7 @@ X509_REQ_print_fp(FILE *fp, X509_REQ *x)
81 int ret; 81 int ret;
82 82
83 if ((b = BIO_new(BIO_s_file())) == NULL) { 83 if ((b = BIO_new(BIO_s_file())) == NULL) {
84 X509err(X509_F_X509_REQ_PRINT_FP, ERR_R_BUF_LIB); 84 X509error(ERR_R_BUF_LIB);
85 return (0); 85 return (0);
86 } 86 }
87 BIO_set_fp(b, fp, BIO_NOCLOSE); 87 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -256,7 +256,7 @@ get_next:
256 return (1); 256 return (1);
257 257
258err: 258err:
259 X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB); 259 X509error(ERR_R_BUF_LIB);
260 return (0); 260 return (0);
261} 261}
262 262
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index 1c83fc5608..14cbabedc7 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t_x509.c,v 1.26 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: t_x509.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -92,7 +92,7 @@ X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag)
92 int ret; 92 int ret;
93 93
94 if ((b = BIO_new(BIO_s_file())) == NULL) { 94 if ((b = BIO_new(BIO_s_file())) == NULL) {
95 X509err(X509_F_X509_PRINT_EX_FP, ERR_R_BUF_LIB); 95 X509error(ERR_R_BUF_LIB);
96 return (0); 96 return (0);
97 } 97 }
98 BIO_set_fp(b, fp, BIO_NOCLOSE); 98 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -530,7 +530,7 @@ X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
530 ret = 1; 530 ret = 1;
531 if (0) { 531 if (0) {
532err: 532err:
533 X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB); 533 X509error(ERR_R_BUF_LIB);
534 } 534 }
535 free(b); 535 free(b);
536 return (ret); 536 return (ret);
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index de78164995..3f680c60fd 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_dec.c,v 1.33 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: tasn_dec.c,v 1.34 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -189,8 +189,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
189 * template itself. 189 * template itself.
190 */ 190 */
191 if ((tag != -1) || opt) { 191 if ((tag != -1) || opt) {
192 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 192 ASN1error(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
193 ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
194 goto err; 193 goto err;
195 } 194 }
196 return asn1_template_ex_d2i(pval, in, len, 195 return asn1_template_ex_d2i(pval, in, len,
@@ -206,8 +205,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
206 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, 205 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
207 &p, len, -1, 0, 1, ctx); 206 &p, len, -1, 0, 1, ctx);
208 if (!ret) { 207 if (!ret) {
209 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 208 ASN1error(ERR_R_NESTED_ASN1_ERROR);
210 ERR_R_NESTED_ASN1_ERROR);
211 goto err; 209 goto err;
212 } 210 }
213 211
@@ -216,8 +214,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
216 /* If OPTIONAL, assume this is OK */ 214 /* If OPTIONAL, assume this is OK */
217 if (opt) 215 if (opt)
218 return -1; 216 return -1;
219 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 217 ASN1error(ASN1_R_MSTRING_NOT_UNIVERSAL);
220 ASN1_R_MSTRING_NOT_UNIVERSAL);
221 goto err; 218 goto err;
222 } 219 }
223 /* Check tag matches bit map */ 220 /* Check tag matches bit map */
@@ -225,8 +222,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
225 /* If OPTIONAL, assume this is OK */ 222 /* If OPTIONAL, assume this is OK */
226 if (opt) 223 if (opt)
227 return -1; 224 return -1;
228 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 225 ASN1error(ASN1_R_MSTRING_WRONG_TAG);
229 ASN1_R_MSTRING_WRONG_TAG);
230 goto err; 226 goto err;
231 } 227 }
232 return asn1_d2i_ex_primitive(pval, in, len, 228 return asn1_d2i_ex_primitive(pval, in, len,
@@ -252,8 +248,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
252 asn1_set_choice_selector(pval, -1, it); 248 asn1_set_choice_selector(pval, -1, it);
253 } 249 }
254 } else if (!ASN1_item_ex_new(pval, it)) { 250 } else if (!ASN1_item_ex_new(pval, it)) {
255 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 251 ASN1error(ERR_R_NESTED_ASN1_ERROR);
256 ERR_R_NESTED_ASN1_ERROR);
257 goto err; 252 goto err;
258 } 253 }
259 /* CHOICE type, try each possibility in turn */ 254 /* CHOICE type, try each possibility in turn */
@@ -272,8 +267,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
272 break; 267 break;
273 /* Otherwise must be an ASN1 parsing error */ 268 /* Otherwise must be an ASN1 parsing error */
274 errtt = tt; 269 errtt = tt;
275 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 270 ASN1error(ERR_R_NESTED_ASN1_ERROR);
276 ERR_R_NESTED_ASN1_ERROR);
277 goto err; 271 goto err;
278 } 272 }
279 273
@@ -285,8 +279,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
285 ASN1_item_ex_free(pval, it); 279 ASN1_item_ex_free(pval, it);
286 return -1; 280 return -1;
287 } 281 }
288 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 282 ASN1error(ASN1_R_NO_MATCHING_CHOICE_TYPE);
289 ASN1_R_NO_MATCHING_CHOICE_TYPE);
290 goto err; 283 goto err;
291 } 284 }
292 285
@@ -310,8 +303,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
310 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, 303 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
311 &p, len, tag, aclass, opt, ctx); 304 &p, len, tag, aclass, opt, ctx);
312 if (!ret) { 305 if (!ret) {
313 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 306 ASN1error(ERR_R_NESTED_ASN1_ERROR);
314 ERR_R_NESTED_ASN1_ERROR);
315 goto err; 307 goto err;
316 } else if (ret == -1) 308 } else if (ret == -1)
317 return -1; 309 return -1;
@@ -323,14 +315,12 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
323 else 315 else
324 seq_nolen = seq_eoc; 316 seq_nolen = seq_eoc;
325 if (!cst) { 317 if (!cst) {
326 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 318 ASN1error(ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
327 ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
328 goto err; 319 goto err;
329 } 320 }
330 321
331 if (!*pval && !ASN1_item_ex_new(pval, it)) { 322 if (!*pval && !ASN1_item_ex_new(pval, it)) {
332 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 323 ASN1error(ERR_R_NESTED_ASN1_ERROR);
333 ERR_R_NESTED_ASN1_ERROR);
334 goto err; 324 goto err;
335 } 325 }
336 326
@@ -364,8 +354,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
364 q = p; 354 q = p;
365 if (asn1_check_eoc(&p, len)) { 355 if (asn1_check_eoc(&p, len)) {
366 if (!seq_eoc) { 356 if (!seq_eoc) {
367 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 357 ASN1error(ASN1_R_UNEXPECTED_EOC);
368 ASN1_R_UNEXPECTED_EOC);
369 goto err; 358 goto err;
370 } 359 }
371 len -= p - q; 360 len -= p - q;
@@ -404,13 +393,12 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
404 393
405 /* Check for EOC if expecting one */ 394 /* Check for EOC if expecting one */
406 if (seq_eoc && !asn1_check_eoc(&p, len)) { 395 if (seq_eoc && !asn1_check_eoc(&p, len)) {
407 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); 396 ASN1error(ASN1_R_MISSING_EOC);
408 goto err; 397 goto err;
409 } 398 }
410 /* Check all data read */ 399 /* Check all data read */
411 if (!seq_nolen && len) { 400 if (!seq_nolen && len) {
412 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 401 ASN1error(ASN1_R_SEQUENCE_LENGTH_MISMATCH);
413 ASN1_R_SEQUENCE_LENGTH_MISMATCH);
414 goto err; 402 goto err;
415 } 403 }
416 404
@@ -429,14 +417,13 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
429 ASN1_template_free(pseqval, seqtt); 417 ASN1_template_free(pseqval, seqtt);
430 } else { 418 } else {
431 errtt = seqtt; 419 errtt = seqtt;
432 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 420 ASN1error(ASN1_R_FIELD_MISSING);
433 ASN1_R_FIELD_MISSING);
434 goto err; 421 goto err;
435 } 422 }
436 } 423 }
437 /* Save encoding */ 424 /* Save encoding */
438 if (!asn1_enc_save(pval, *in, p - *in, it)) { 425 if (!asn1_enc_save(pval, *in, p - *in, it)) {
439 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_MALLOC_FAILURE); 426 ASN1error(ERR_R_MALLOC_FAILURE);
440 goto auxerr; 427 goto auxerr;
441 } 428 }
442 *in = p; 429 *in = p;
@@ -449,7 +436,7 @@ ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
449 } 436 }
450 437
451auxerr: 438auxerr:
452 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); 439 ASN1error(ASN1_R_AUX_ERROR);
453err: 440err:
454 if (combine == 0) 441 if (combine == 0)
455 ASN1_item_ex_free(pval, it); 442 ASN1_item_ex_free(pval, it);
@@ -493,21 +480,18 @@ asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
493 &p, inlen, tt->tag, aclass, opt, ctx); 480 &p, inlen, tt->tag, aclass, opt, ctx);
494 q = p; 481 q = p;
495 if (!ret) { 482 if (!ret) {
496 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, 483 ASN1error(ERR_R_NESTED_ASN1_ERROR);
497 ERR_R_NESTED_ASN1_ERROR);
498 return 0; 484 return 0;
499 } else if (ret == -1) 485 } else if (ret == -1)
500 return -1; 486 return -1;
501 if (!cst) { 487 if (!cst) {
502 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, 488 ASN1error(ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
503 ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
504 return 0; 489 return 0;
505 } 490 }
506 /* We've found the field so it can't be OPTIONAL now */ 491 /* We've found the field so it can't be OPTIONAL now */
507 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); 492 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
508 if (!ret) { 493 if (!ret) {
509 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, 494 ASN1error(ERR_R_NESTED_ASN1_ERROR);
510 ERR_R_NESTED_ASN1_ERROR);
511 return 0; 495 return 0;
512 } 496 }
513 /* We read the field in OK so update length */ 497 /* We read the field in OK so update length */
@@ -515,16 +499,14 @@ asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen,
515 if (exp_eoc) { 499 if (exp_eoc) {
516 /* If NDEF we must have an EOC here */ 500 /* If NDEF we must have an EOC here */
517 if (!asn1_check_eoc(&p, len)) { 501 if (!asn1_check_eoc(&p, len)) {
518 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, 502 ASN1error(ASN1_R_MISSING_EOC);
519 ASN1_R_MISSING_EOC);
520 goto err; 503 goto err;
521 } 504 }
522 } else { 505 } else {
523 /* Otherwise we must hit the EXPLICIT tag end or its 506 /* Otherwise we must hit the EXPLICIT tag end or its
524 * an error */ 507 * an error */
525 if (len) { 508 if (len) {
526 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, 509 ASN1error(ASN1_R_EXPLICIT_LENGTH_MISMATCH);
527 ASN1_R_EXPLICIT_LENGTH_MISMATCH);
528 goto err; 510 goto err;
529 } 511 }
530 } 512 }
@@ -574,8 +556,7 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
574 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, 556 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
575 &p, len, sktag, skaclass, opt, ctx); 557 &p, len, sktag, skaclass, opt, ctx);
576 if (!ret) { 558 if (!ret) {
577 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 559 ASN1error(ERR_R_NESTED_ASN1_ERROR);
578 ERR_R_NESTED_ASN1_ERROR);
579 return 0; 560 return 0;
580 } else if (ret == -1) 561 } else if (ret == -1)
581 return -1; 562 return -1;
@@ -594,8 +575,7 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
594 } 575 }
595 576
596 if (!*val) { 577 if (!*val) {
597 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 578 ASN1error(ERR_R_MALLOC_FAILURE);
598 ERR_R_MALLOC_FAILURE);
599 goto err; 579 goto err;
600 } 580 }
601 581
@@ -606,8 +586,7 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
606 /* See if EOC found */ 586 /* See if EOC found */
607 if (asn1_check_eoc(&p, len)) { 587 if (asn1_check_eoc(&p, len)) {
608 if (!sk_eoc) { 588 if (!sk_eoc) {
609 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 589 ASN1error(ASN1_R_UNEXPECTED_EOC);
610 ASN1_R_UNEXPECTED_EOC);
611 goto err; 590 goto err;
612 } 591 }
613 len -= p - q; 592 len -= p - q;
@@ -617,21 +596,18 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
617 skfield = NULL; 596 skfield = NULL;
618 if (!ASN1_item_ex_d2i(&skfield, &p, len, 597 if (!ASN1_item_ex_d2i(&skfield, &p, len,
619 tt->item, -1, 0, 0, ctx)) { 598 tt->item, -1, 0, 0, ctx)) {
620 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 599 ASN1error(ERR_R_NESTED_ASN1_ERROR);
621 ERR_R_NESTED_ASN1_ERROR);
622 goto err; 600 goto err;
623 } 601 }
624 len -= p - q; 602 len -= p - q;
625 if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, 603 if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
626 skfield)) { 604 skfield)) {
627 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 605 ASN1error(ERR_R_MALLOC_FAILURE);
628 ERR_R_MALLOC_FAILURE);
629 goto err; 606 goto err;
630 } 607 }
631 } 608 }
632 if (sk_eoc) { 609 if (sk_eoc) {
633 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 610 ASN1error(ASN1_R_MISSING_EOC);
634 ASN1_R_MISSING_EOC);
635 goto err; 611 goto err;
636 } 612 }
637 } else if (flags & ASN1_TFLG_IMPTAG) { 613 } else if (flags & ASN1_TFLG_IMPTAG) {
@@ -639,8 +615,7 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
639 ret = ASN1_item_ex_d2i(val, &p, len, 615 ret = ASN1_item_ex_d2i(val, &p, len,
640 tt->item, tt->tag, aclass, opt, ctx); 616 tt->item, tt->tag, aclass, opt, ctx);
641 if (!ret) { 617 if (!ret) {
642 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 618 ASN1error(ERR_R_NESTED_ASN1_ERROR);
643 ERR_R_NESTED_ASN1_ERROR);
644 goto err; 619 goto err;
645 } else if (ret == -1) 620 } else if (ret == -1)
646 return -1; 621 return -1;
@@ -649,8 +624,7 @@ asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
649 ret = ASN1_item_ex_d2i(val, &p, len, tt->item, 624 ret = ASN1_item_ex_d2i(val, &p, len, tt->item,
650 -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx); 625 -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);
651 if (!ret) { 626 if (!ret) {
652 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, 627 ASN1error(ERR_R_NESTED_ASN1_ERROR);
653 ERR_R_NESTED_ASN1_ERROR);
654 goto err; 628 goto err;
655 } else if (ret == -1) 629 } else if (ret == -1)
656 return -1; 630 return -1;
@@ -681,7 +655,7 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
681 buf.data = NULL; 655 buf.data = NULL;
682 656
683 if (!pval) { 657 if (!pval) {
684 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); 658 ASN1error(ASN1_R_ILLEGAL_NULL);
685 return 0; /* Should never happen */ 659 return 0; /* Should never happen */
686 } 660 }
687 661
@@ -695,21 +669,18 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
695 /* If type is ANY need to figure out type from tag */ 669 /* If type is ANY need to figure out type from tag */
696 unsigned char oclass; 670 unsigned char oclass;
697 if (tag >= 0) { 671 if (tag >= 0) {
698 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, 672 ASN1error(ASN1_R_ILLEGAL_TAGGED_ANY);
699 ASN1_R_ILLEGAL_TAGGED_ANY);
700 return 0; 673 return 0;
701 } 674 }
702 if (opt) { 675 if (opt) {
703 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, 676 ASN1error(ASN1_R_ILLEGAL_OPTIONAL_ANY);
704 ASN1_R_ILLEGAL_OPTIONAL_ANY);
705 return 0; 677 return 0;
706 } 678 }
707 p = *in; 679 p = *in;
708 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, 680 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
709 &p, inlen, -1, 0, 0, ctx); 681 &p, inlen, -1, 0, 0, ctx);
710 if (!ret) { 682 if (!ret) {
711 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, 683 ASN1error(ERR_R_NESTED_ASN1_ERROR);
712 ERR_R_NESTED_ASN1_ERROR);
713 return 0; 684 return 0;
714 } 685 }
715 if (oclass != V_ASN1_UNIVERSAL) 686 if (oclass != V_ASN1_UNIVERSAL)
@@ -724,7 +695,7 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
724 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, 695 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
725 &p, inlen, tag, aclass, opt, ctx); 696 &p, inlen, tag, aclass, opt, ctx);
726 if (!ret) { 697 if (!ret) {
727 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); 698 ASN1error(ERR_R_NESTED_ASN1_ERROR);
728 return 0; 699 return 0;
729 } else if (ret == -1) 700 } else if (ret == -1)
730 return -1; 701 return -1;
@@ -740,8 +711,7 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
740 } 711 }
741 /* SEQUENCE and SET must be constructed */ 712 /* SEQUENCE and SET must be constructed */
742 else if (!cst) { 713 else if (!cst) {
743 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, 714 ASN1error(ASN1_R_TYPE_NOT_CONSTRUCTED);
744 ASN1_R_TYPE_NOT_CONSTRUCTED);
745 return 0; 715 return 0;
746 } 716 }
747 717
@@ -770,8 +740,7 @@ asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long inlen,
770 len = buf.length; 740 len = buf.length;
771 /* Append a final null to string */ 741 /* Append a final null to string */
772 if (!BUF_MEM_grow_clean(&buf, len + 1)) { 742 if (!BUF_MEM_grow_clean(&buf, len + 1)) {
773 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, 743 ASN1error(ERR_R_MALLOC_FAILURE);
774 ERR_R_MALLOC_FAILURE);
775 return 0; 744 return 0;
776 } 745 }
777 buf.data[len] = 0; 746 buf.data[len] = 0;
@@ -836,8 +805,7 @@ asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
836 805
837 case V_ASN1_NULL: 806 case V_ASN1_NULL:
838 if (len) { 807 if (len) {
839 ASN1err(ASN1_F_ASN1_EX_C2I, 808 ASN1error(ASN1_R_NULL_IS_WRONG_LENGTH);
840 ASN1_R_NULL_IS_WRONG_LENGTH);
841 goto err; 809 goto err;
842 } 810 }
843 *pval = (ASN1_VALUE *)1; 811 *pval = (ASN1_VALUE *)1;
@@ -845,8 +813,7 @@ asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
845 813
846 case V_ASN1_BOOLEAN: 814 case V_ASN1_BOOLEAN:
847 if (len != 1) { 815 if (len != 1) {
848 ASN1err(ASN1_F_ASN1_EX_C2I, 816 ASN1error(ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
849 ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
850 goto err; 817 goto err;
851 } else { 818 } else {
852 ASN1_BOOLEAN *tbool; 819 ASN1_BOOLEAN *tbool;
@@ -888,21 +855,18 @@ asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
888 case V_ASN1_SEQUENCE: 855 case V_ASN1_SEQUENCE:
889 default: 856 default:
890 if (utype == V_ASN1_BMPSTRING && (len & 1)) { 857 if (utype == V_ASN1_BMPSTRING && (len & 1)) {
891 ASN1err(ASN1_F_ASN1_EX_C2I, 858 ASN1error(ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
892 ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
893 goto err; 859 goto err;
894 } 860 }
895 if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) { 861 if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
896 ASN1err(ASN1_F_ASN1_EX_C2I, 862 ASN1error(ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
897 ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
898 goto err; 863 goto err;
899 } 864 }
900 /* All based on ASN1_STRING and handled the same */ 865 /* All based on ASN1_STRING and handled the same */
901 if (!*pval) { 866 if (!*pval) {
902 stmp = ASN1_STRING_type_new(utype); 867 stmp = ASN1_STRING_type_new(utype);
903 if (!stmp) { 868 if (!stmp) {
904 ASN1err(ASN1_F_ASN1_EX_C2I, 869 ASN1error(ERR_R_MALLOC_FAILURE);
905 ERR_R_MALLOC_FAILURE);
906 goto err; 870 goto err;
907 } 871 }
908 *pval = (ASN1_VALUE *)stmp; 872 *pval = (ASN1_VALUE *)stmp;
@@ -918,8 +882,7 @@ asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
918 *free_cont = 0; 882 *free_cont = 0;
919 } else { 883 } else {
920 if (!ASN1_STRING_set(stmp, cont, len)) { 884 if (!ASN1_STRING_set(stmp, cont, len)) {
921 ASN1err(ASN1_F_ASN1_EX_C2I, 885 ASN1error(ERR_R_MALLOC_FAILURE);
922 ERR_R_MALLOC_FAILURE);
923 ASN1_STRING_free(stmp); 886 ASN1_STRING_free(stmp);
924 *pval = NULL; 887 *pval = NULL;
925 goto err; 888 goto err;
@@ -979,7 +942,7 @@ asn1_find_end(const unsigned char **in, long len, char inf)
979 /* Just read in a header: only care about the length */ 942 /* Just read in a header: only care about the length */
980 if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, 943 if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
981 -1, 0, 0, NULL)) { 944 -1, 0, 0, NULL)) {
982 ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); 945 ASN1error(ERR_R_NESTED_ASN1_ERROR);
983 return 0; 946 return 0;
984 } 947 }
985 if (inf) 948 if (inf)
@@ -989,7 +952,7 @@ asn1_find_end(const unsigned char **in, long len, char inf)
989 len -= p - q; 952 len -= p - q;
990 } 953 }
991 if (expected_eoc) { 954 if (expected_eoc) {
992 ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); 955 ASN1error(ASN1_R_MISSING_EOC);
993 return 0; 956 return 0;
994 } 957 }
995 *in = p; 958 *in = p;
@@ -1033,8 +996,7 @@ asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
1033 /* EOC is illegal outside indefinite length 996 /* EOC is illegal outside indefinite length
1034 * constructed form */ 997 * constructed form */
1035 if (!inf) { 998 if (!inf) {
1036 ASN1err(ASN1_F_ASN1_COLLECT, 999 ASN1error(ASN1_R_UNEXPECTED_EOC);
1037 ASN1_R_UNEXPECTED_EOC);
1038 return 0; 1000 return 0;
1039 } 1001 }
1040 inf = 0; 1002 inf = 0;
@@ -1043,15 +1005,14 @@ asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
1043 1005
1044 if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, 1006 if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
1045 len, tag, aclass, 0, NULL)) { 1007 len, tag, aclass, 0, NULL)) {
1046 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); 1008 ASN1error(ERR_R_NESTED_ASN1_ERROR);
1047 return 0; 1009 return 0;
1048 } 1010 }
1049 1011
1050 /* If indefinite length constructed update max length */ 1012 /* If indefinite length constructed update max length */
1051 if (cst) { 1013 if (cst) {
1052 if (depth >= ASN1_MAX_STRING_NEST) { 1014 if (depth >= ASN1_MAX_STRING_NEST) {
1053 ASN1err(ASN1_F_ASN1_COLLECT, 1015 ASN1error(ASN1_R_NESTED_ASN1_STRING);
1054 ASN1_R_NESTED_ASN1_STRING);
1055 return 0; 1016 return 0;
1056 } 1017 }
1057 if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, 1018 if (!asn1_collect(buf, &p, plen, ininf, tag, aclass,
@@ -1062,7 +1023,7 @@ asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, char inf,
1062 len -= p - q; 1023 len -= p - q;
1063 } 1024 }
1064 if (inf) { 1025 if (inf) {
1065 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); 1026 ASN1error(ASN1_R_MISSING_EOC);
1066 return 0; 1027 return 0;
1067 } 1028 }
1068 *in = p; 1029 *in = p;
@@ -1076,7 +1037,7 @@ collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
1076 if (buf) { 1037 if (buf) {
1077 len = buf->length; 1038 len = buf->length;
1078 if (!BUF_MEM_grow_clean(buf, len + plen)) { 1039 if (!BUF_MEM_grow_clean(buf, len + plen)) {
1079 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); 1040 ASN1error(ERR_R_MALLOC_FAILURE);
1080 return 0; 1041 return 0;
1081 } 1042 }
1082 memcpy(buf->data + len, *p, plen); 1043 memcpy(buf->data + len, *p, plen);
@@ -1141,8 +1102,7 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1141 * header can't exceed total amount of data available. 1102 * header can't exceed total amount of data available.
1142 */ 1103 */
1143 if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { 1104 if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
1144 ASN1err(ASN1_F_ASN1_CHECK_TLEN, 1105 ASN1error(ASN1_R_TOO_LONG);
1145 ASN1_R_TOO_LONG);
1146 asn1_tlc_clear(ctx); 1106 asn1_tlc_clear(ctx);
1147 return 0; 1107 return 0;
1148 } 1108 }
@@ -1150,7 +1110,7 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1150 } 1110 }
1151 1111
1152 if (i & 0x80) { 1112 if (i & 0x80) {
1153 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); 1113 ASN1error(ASN1_R_BAD_OBJECT_HEADER);
1154 asn1_tlc_clear(ctx); 1114 asn1_tlc_clear(ctx);
1155 return 0; 1115 return 0;
1156 } 1116 }
@@ -1162,7 +1122,7 @@ asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf,
1162 if (opt) 1122 if (opt)
1163 return -1; 1123 return -1;
1164 asn1_tlc_clear(ctx); 1124 asn1_tlc_clear(ctx);
1165 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); 1125 ASN1error(ASN1_R_WRONG_TAG);
1166 return 0; 1126 return 0;
1167 } 1127 }
1168 /* We have a tag and class match: 1128 /* We have a tag and class match:
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index 491de0131e..e9bbc05e08 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_new.c,v 1.16 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: tasn_new.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -190,7 +190,7 @@ asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
190 return 1; 190 return 1;
191 191
192memerr: 192memerr:
193 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); 193 ASN1error(ERR_R_MALLOC_FAILURE);
194#ifdef CRYPTO_MDEBUG 194#ifdef CRYPTO_MDEBUG
195 if (it->sname) 195 if (it->sname)
196 CRYPTO_pop_info(); 196 CRYPTO_pop_info();
@@ -198,7 +198,7 @@ memerr:
198 return 0; 198 return 0;
199 199
200auxerr: 200auxerr:
201 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR); 201 ASN1error(ASN1_R_AUX_ERROR);
202 ASN1_item_ex_free(pval, it); 202 ASN1_item_ex_free(pval, it);
203#ifdef CRYPTO_MDEBUG 203#ifdef CRYPTO_MDEBUG
204 if (it->sname) 204 if (it->sname)
@@ -266,7 +266,7 @@ ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
266 STACK_OF(ASN1_VALUE) *skval; 266 STACK_OF(ASN1_VALUE) *skval;
267 skval = sk_ASN1_VALUE_new_null(); 267 skval = sk_ASN1_VALUE_new_null();
268 if (!skval) { 268 if (!skval) {
269 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); 269 ASN1error(ERR_R_MALLOC_FAILURE);
270 ret = 0; 270 ret = 0;
271 goto done; 271 goto done;
272 } 272 }
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
index 80e7fbb890..7cccd56a16 100644
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_prn.c,v 1.15 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: tasn_prn.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -87,7 +87,7 @@ ASN1_PCTX_new(void)
87 ASN1_PCTX *ret; 87 ASN1_PCTX *ret;
88 ret = malloc(sizeof(ASN1_PCTX)); 88 ret = malloc(sizeof(ASN1_PCTX));
89 if (ret == NULL) { 89 if (ret == NULL) {
90 ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); 90 ASN1error(ERR_R_MALLOC_FAILURE);
91 return NULL; 91 return NULL;
92 } 92 }
93 ret->flags = 0; 93 ret->flags = 0;
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
index 529aaf6116..391ef01a57 100644
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tasn_utl.c,v 1.11 2015/07/25 17:07:17 jsing Exp $ */ 1/* $OpenBSD: tasn_utl.c,v 1.12 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -275,7 +275,6 @@ asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
275err: 275err:
276 /* FIXME: should log the value or OID of unsupported type */ 276 /* FIXME: should log the value or OID of unsupported type */
277 if (nullerr) 277 if (nullerr)
278 ASN1err(ASN1_F_ASN1_DO_ADB, 278 ASN1error(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
279 ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
280 return NULL; 279 return NULL;
281} 280}
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index eeff341d7d..d8f24ca10b 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_crl.c,v 1.26 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: x_crl.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -535,7 +535,7 @@ X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
535 if (!inf->revoked) 535 if (!inf->revoked)
536 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); 536 inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
537 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { 537 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
538 ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); 538 ASN1error(ERR_R_MALLOC_FAILURE);
539 return 0; 539 return 0;
540 } 540 }
541 inf->enc.modified = 1; 541 inf->enc.modified = 1;
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
index 05ac364fa7..c476923158 100644
--- a/src/lib/libcrypto/asn1/x_info.c
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_info.c,v 1.16 2016/03/11 07:08:44 mmcc Exp $ */ 1/* $OpenBSD: x_info.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -70,7 +70,7 @@ X509_INFO_new(void)
70 70
71 ret = malloc(sizeof(X509_INFO)); 71 ret = malloc(sizeof(X509_INFO));
72 if (ret == NULL) { 72 if (ret == NULL) {
73 ASN1err(ASN1_F_X509_INFO_NEW, ERR_R_MALLOC_FAILURE); 73 ASN1error(ERR_R_MALLOC_FAILURE);
74 return (NULL); 74 return (NULL);
75 } 75 }
76 76
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
index 90a41129bc..9df3a3181a 100644
--- a/src/lib/libcrypto/asn1/x_long.c
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_long.c,v 1.10 2015/07/25 17:07:17 jsing Exp $ */ 1/* $OpenBSD: x_long.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -173,7 +173,7 @@ long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
173 unsigned long utmp = 0; 173 unsigned long utmp = 0;
174 char *cp = (char *)pval; 174 char *cp = (char *)pval;
175 if (len > (int)sizeof(long)) { 175 if (len > (int)sizeof(long)) {
176 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 176 ASN1error(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
177 return 0; 177 return 0;
178 } 178 }
179 /* Is it negative? */ 179 /* Is it negative? */
@@ -195,7 +195,7 @@ long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype,
195 ltmp = -ltmp; 195 ltmp = -ltmp;
196 } 196 }
197 if (ltmp == it->size) { 197 if (ltmp == it->size) {
198 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 198 ASN1error(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
199 return 0; 199 return 0;
200 } 200 }
201 memcpy(cp, &ltmp, sizeof(long)); 201 memcpy(cp, &ltmp, sizeof(long));
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index 87bcc2c5ba..30fef39fb7 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_name.c,v 1.32 2016/12/30 16:04:34 jsing Exp $ */ 1/* $OpenBSD: x_name.c,v 1.33 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -257,7 +257,7 @@ x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
257 return 1; 257 return 1;
258 258
259memerr: 259memerr:
260 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); 260 ASN1error(ERR_R_MALLOC_FAILURE);
261 if (ret) { 261 if (ret) {
262 if (ret->entries) 262 if (ret->entries)
263 sk_X509_NAME_ENTRY_free(ret->entries); 263 sk_X509_NAME_ENTRY_free(ret->entries);
@@ -339,7 +339,7 @@ x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len,
339err: 339err:
340 if (nm.x != NULL) 340 if (nm.x != NULL)
341 X509_NAME_free(nm.x); 341 X509_NAME_free(nm.x);
342 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); 342 ASN1error(ERR_R_NESTED_ASN1_ERROR);
343 return 0; 343 return 0;
344} 344}
345 345
@@ -424,7 +424,7 @@ x509_name_encode(X509_NAME *a)
424memerr: 424memerr:
425 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, 425 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,
426 local_sk_X509_NAME_ENTRY_free); 426 local_sk_X509_NAME_ENTRY_free);
427 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); 427 ASN1error(ERR_R_MALLOC_FAILURE);
428 return -1; 428 return -1;
429} 429}
430 430
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index 701db0fc6d..c946281f4a 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pkey.c,v 1.19 2015/09/30 18:41:06 jsing Exp $ */ 1/* $OpenBSD: x_pkey.c,v 1.20 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -70,16 +70,16 @@ X509_PKEY_new(void)
70 X509_PKEY *ret = NULL; 70 X509_PKEY *ret = NULL;
71 71
72 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) { 72 if ((ret = malloc(sizeof(X509_PKEY))) == NULL) {
73 ASN1err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE); 73 ASN1error(ERR_R_MALLOC_FAILURE);
74 goto err; 74 goto err;
75 } 75 }
76 ret->version = 0; 76 ret->version = 0;
77 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) { 77 if ((ret->enc_algor = X509_ALGOR_new()) == NULL) {
78 ASN1err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE); 78 ASN1error(ERR_R_MALLOC_FAILURE);
79 goto err; 79 goto err;
80 } 80 }
81 if ((ret->enc_pkey = ASN1_OCTET_STRING_new()) == NULL) { 81 if ((ret->enc_pkey = ASN1_OCTET_STRING_new()) == NULL) {
82 ASN1err(ASN1_F_X509_PKEY_NEW, ERR_R_MALLOC_FAILURE); 82 ASN1error(ERR_R_MALLOC_FAILURE);
83 goto err; 83 goto err;
84 } 84 }
85 ret->dec_pkey = NULL; 85 ret->dec_pkey = NULL;
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 3bdbb5a536..738507bbb6 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x_pubkey.c,v 1.25 2015/02/11 04:00:39 jsing Exp $ */ 1/* $OpenBSD: x_pubkey.c,v 1.26 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -149,17 +149,15 @@ X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
149 if (pkey->ameth) { 149 if (pkey->ameth) {
150 if (pkey->ameth->pub_encode) { 150 if (pkey->ameth->pub_encode) {
151 if (!pkey->ameth->pub_encode(pk, pkey)) { 151 if (!pkey->ameth->pub_encode(pk, pkey)) {
152 X509err(X509_F_X509_PUBKEY_SET, 152 X509error(X509_R_PUBLIC_KEY_ENCODE_ERROR);
153 X509_R_PUBLIC_KEY_ENCODE_ERROR);
154 goto error; 153 goto error;
155 } 154 }
156 } else { 155 } else {
157 X509err(X509_F_X509_PUBKEY_SET, 156 X509error(X509_R_METHOD_NOT_SUPPORTED);
158 X509_R_METHOD_NOT_SUPPORTED);
159 goto error; 157 goto error;
160 } 158 }
161 } else { 159 } else {
162 X509err(X509_F_X509_PUBKEY_SET, X509_R_UNSUPPORTED_ALGORITHM); 160 X509error(X509_R_UNSUPPORTED_ALGORITHM);
163 goto error; 161 goto error;
164 } 162 }
165 163
@@ -193,23 +191,22 @@ X509_PUBKEY_get(X509_PUBKEY *key)
193 goto error; 191 goto error;
194 192
195 if ((ret = EVP_PKEY_new()) == NULL) { 193 if ((ret = EVP_PKEY_new()) == NULL) {
196 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); 194 X509error(ERR_R_MALLOC_FAILURE);
197 goto error; 195 goto error;
198 } 196 }
199 197
200 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) { 198 if (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm))) {
201 X509err(X509_F_X509_PUBKEY_GET, X509_R_UNSUPPORTED_ALGORITHM); 199 X509error(X509_R_UNSUPPORTED_ALGORITHM);
202 goto error; 200 goto error;
203 } 201 }
204 202
205 if (ret->ameth->pub_decode) { 203 if (ret->ameth->pub_decode) {
206 if (!ret->ameth->pub_decode(ret, key)) { 204 if (!ret->ameth->pub_decode(ret, key)) {
207 X509err(X509_F_X509_PUBKEY_GET, 205 X509error(X509_R_PUBLIC_KEY_DECODE_ERROR);
208 X509_R_PUBLIC_KEY_DECODE_ERROR);
209 goto error; 206 goto error;
210 } 207 }
211 } else { 208 } else {
212 X509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED); 209 X509error(X509_R_METHOD_NOT_SUPPORTED);
213 goto error; 210 goto error;
214 } 211 }
215 212
@@ -304,7 +301,7 @@ i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
304 return 0; 301 return 0;
305 pktmp = EVP_PKEY_new(); 302 pktmp = EVP_PKEY_new();
306 if (!pktmp) { 303 if (!pktmp) {
307 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); 304 ASN1error(ERR_R_MALLOC_FAILURE);
308 return 0; 305 return 0;
309 } 306 }
310 EVP_PKEY_set1_RSA(pktmp, a); 307 EVP_PKEY_set1_RSA(pktmp, a);
@@ -346,7 +343,7 @@ i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
346 return 0; 343 return 0;
347 pktmp = EVP_PKEY_new(); 344 pktmp = EVP_PKEY_new();
348 if (!pktmp) { 345 if (!pktmp) {
349 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); 346 ASN1error(ERR_R_MALLOC_FAILURE);
350 return 0; 347 return 0;
351 } 348 }
352 EVP_PKEY_set1_DSA(pktmp, a); 349 EVP_PKEY_set1_DSA(pktmp, a);
@@ -387,7 +384,7 @@ i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
387 if (!a) 384 if (!a)
388 return (0); 385 return (0);
389 if ((pktmp = EVP_PKEY_new()) == NULL) { 386 if ((pktmp = EVP_PKEY_new()) == NULL) {
390 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE); 387 ASN1error(ERR_R_MALLOC_FAILURE);
391 return (0); 388 return (0);
392 } 389 }
393 EVP_PKEY_set1_EC_KEY(pktmp, a); 390 EVP_PKEY_set1_EC_KEY(pktmp, a);
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index db8a30538c..0cc570b66f 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: b_sock.c,v 1.62 2016/12/20 23:14:37 beck Exp $ */ 1/* $OpenBSD: b_sock.c,v 1.63 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -89,13 +89,12 @@ BIO_get_host_ip(const char *str, unsigned char *ip)
89 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); 89 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
90 he = BIO_gethostbyname(str); 90 he = BIO_gethostbyname(str);
91 if (he == NULL) { 91 if (he == NULL) {
92 BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP); 92 BIOerror(BIO_R_BAD_HOSTNAME_LOOKUP);
93 goto err; 93 goto err;
94 } 94 }
95 95
96 if (he->h_addrtype != AF_INET) { 96 if (he->h_addrtype != AF_INET) {
97 BIOerr(BIO_F_BIO_GET_HOST_IP, 97 BIOerror(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
98 BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
99 goto err; 98 goto err;
100 } 99 }
101 for (i = 0; i < 4; i++) 100 for (i = 0; i < 4; i++)
@@ -123,7 +122,7 @@ BIO_get_port(const char *str, unsigned short *port_ptr)
123 int error; 122 int error;
124 123
125 if (str == NULL) { 124 if (str == NULL) {
126 BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_SPECIFIED); 125 BIOerror(BIO_R_NO_PORT_SPECIFIED);
127 return (0); 126 return (0);
128 } 127 }
129 128
@@ -162,7 +161,7 @@ BIO_socket_ioctl(int fd, long type, void *arg)
162 161
163 ret = ioctl(fd, type, arg); 162 ret = ioctl(fd, type, arg);
164 if (ret < 0) 163 if (ret < 0)
165 SYSerr(SYS_F_IOCTLSOCKET, errno); 164 SYSerror(errno);
166 return (ret); 165 return (ret);
167} 166}
168 167
@@ -258,10 +257,9 @@ BIO_get_accept_socket(char *host, int bind_mode)
258again: 257again:
259 s = socket(server.sa.sa_family, SOCK_STREAM, IPPROTO_TCP); 258 s = socket(server.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
260 if (s == -1) { 259 if (s == -1) {
261 SYSerr(SYS_F_SOCKET, errno); 260 SYSerror(errno);
262 ERR_asprintf_error_data("port='%s'", host); 261 ERR_asprintf_error_data("port='%s'", host);
263 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, 262 BIOerror(BIO_R_UNABLE_TO_CREATE_SOCKET);
264 BIO_R_UNABLE_TO_CREATE_SOCKET);
265 goto err; 263 goto err;
266 } 264 }
267 265
@@ -301,17 +299,15 @@ again:
301 } 299 }
302 /* else error */ 300 /* else error */
303 } 301 }
304 SYSerr(SYS_F_BIND, err_num); 302 SYSerror(err_num);
305 ERR_asprintf_error_data("port='%s'", host); 303 ERR_asprintf_error_data("port='%s'", host);
306 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, 304 BIOerror(BIO_R_UNABLE_TO_BIND_SOCKET);
307 BIO_R_UNABLE_TO_BIND_SOCKET);
308 goto err; 305 goto err;
309 } 306 }
310 if (listen(s, SOMAXCONN) == -1) { 307 if (listen(s, SOMAXCONN) == -1) {
311 SYSerr(SYS_F_BIND, errno); 308 SYSerror(errno);
312 ERR_asprintf_error_data("port='%s'", host); 309 ERR_asprintf_error_data("port='%s'", host);
313 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, 310 BIOerror(BIO_R_UNABLE_TO_LISTEN_SOCKET);
314 BIO_R_UNABLE_TO_LISTEN_SOCKET);
315 goto err; 311 goto err;
316 } 312 }
317 ret = 1; 313 ret = 1;
@@ -347,8 +343,8 @@ BIO_accept(int sock, char **addr)
347 if (ret == -1) { 343 if (ret == -1) {
348 if (BIO_sock_should_retry(ret)) 344 if (BIO_sock_should_retry(ret))
349 return -2; 345 return -2;
350 SYSerr(SYS_F_ACCEPT, errno); 346 SYSerror(errno);
351 BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR); 347 BIOerror(BIO_R_ACCEPT_ERROR);
352 goto end; 348 goto end;
353 } 349 }
354 350
@@ -371,7 +367,7 @@ BIO_accept(int sock, char **addr)
371 ret = -1; 367 ret = -1;
372 free(p); 368 free(p);
373 *addr = NULL; 369 *addr = NULL;
374 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); 370 BIOerror(ERR_R_MALLOC_FAILURE);
375 goto end; 371 goto end;
376 } 372 }
377 p = tmp; 373 p = tmp;
@@ -387,7 +383,7 @@ BIO_accept(int sock, char **addr)
387 if ((p = malloc(24)) == NULL) { 383 if ((p = malloc(24)) == NULL) {
388 close(ret); 384 close(ret);
389 ret = -1; 385 ret = -1;
390 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); 386 BIOerror(ERR_R_MALLOC_FAILURE);
391 goto end; 387 goto end;
392 } 388 }
393 *addr = p; 389 *addr = p;
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index 588cc48a28..30765b03ca 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_buff.c,v 1.23 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: bf_buff.c,v 1.24 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -445,7 +445,7 @@ buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
445 } 445 }
446 return (ret); 446 return (ret);
447malloc_error: 447malloc_error:
448 BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE); 448 BIOerror(ERR_R_MALLOC_FAILURE);
449 return (0); 449 return (0);
450} 450}
451 451
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
index 7978fdb347..5d9ec0f025 100644
--- a/src/lib/libcrypto/bio/bf_lbuf.c
+++ b/src/lib/libcrypto/bio/bf_lbuf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bf_lbuf.c,v 1.13 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: bf_lbuf.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -343,7 +343,7 @@ linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
343 } 343 }
344 return (ret); 344 return (ret);
345malloc_error: 345malloc_error:
346 BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE); 346 BIOerror(ERR_R_MALLOC_FAILURE);
347 return (0); 347 return (0);
348} 348}
349 349
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
index 80788585ba..2920e32103 100644
--- a/src/lib/libcrypto/bio/bio_err.c
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_err.c,v 1.16 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: bio_err.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,39 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason)
73 73
74static ERR_STRING_DATA BIO_str_functs[] = { 74static ERR_STRING_DATA BIO_str_functs[] = {
75 {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
77 {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
78 {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
79 {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
80 {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
81 {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
82 {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
83 {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
84 {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
85 {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
86 {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
87 {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
88 {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
89 {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
90 {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
91 {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
92 {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
93 {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
94 {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
95 {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
96 {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
97 {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
98 {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
99 {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
100 {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
101 {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
102 {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
103 {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
104 {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
105 {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
106 {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
107 {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
108 {0, NULL} 76 {0, NULL}
109}; 77};
110 78
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index 0be56aacde..86ccbdc202 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_lib.c,v 1.22 2015/02/10 11:22:21 jsing Exp $ */ 1/* $OpenBSD: bio_lib.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -71,7 +71,7 @@ BIO_new(BIO_METHOD *method)
71 71
72 ret = malloc(sizeof(BIO)); 72 ret = malloc(sizeof(BIO));
73 if (ret == NULL) { 73 if (ret == NULL) {
74 BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); 74 BIOerror(ERR_R_MALLOC_FAILURE);
75 return (NULL); 75 return (NULL);
76 } 76 }
77 if (!BIO_set(ret, method)) { 77 if (!BIO_set(ret, method)) {
@@ -200,7 +200,7 @@ BIO_read(BIO *b, void *out, int outl)
200 long (*cb)(BIO *, int, const char *, int, long, long); 200 long (*cb)(BIO *, int, const char *, int, long, long);
201 201
202 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { 202 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
203 BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD); 203 BIOerror(BIO_R_UNSUPPORTED_METHOD);
204 return (-2); 204 return (-2);
205 } 205 }
206 206
@@ -210,7 +210,7 @@ BIO_read(BIO *b, void *out, int outl)
210 return (i); 210 return (i);
211 211
212 if (!b->init) { 212 if (!b->init) {
213 BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED); 213 BIOerror(BIO_R_UNINITIALIZED);
214 return (-2); 214 return (-2);
215 } 215 }
216 216
@@ -236,7 +236,7 @@ BIO_write(BIO *b, const void *in, int inl)
236 236
237 cb = b->callback; 237 cb = b->callback;
238 if ((b->method == NULL) || (b->method->bwrite == NULL)) { 238 if ((b->method == NULL) || (b->method->bwrite == NULL)) {
239 BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD); 239 BIOerror(BIO_R_UNSUPPORTED_METHOD);
240 return (-2); 240 return (-2);
241 } 241 }
242 242
@@ -245,7 +245,7 @@ BIO_write(BIO *b, const void *in, int inl)
245 return (i); 245 return (i);
246 246
247 if (!b->init) { 247 if (!b->init) {
248 BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED); 248 BIOerror(BIO_R_UNINITIALIZED);
249 return (-2); 249 return (-2);
250 } 250 }
251 251
@@ -267,7 +267,7 @@ BIO_puts(BIO *b, const char *in)
267 long (*cb)(BIO *, int, const char *, int, long, long); 267 long (*cb)(BIO *, int, const char *, int, long, long);
268 268
269 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { 269 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
270 BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD); 270 BIOerror(BIO_R_UNSUPPORTED_METHOD);
271 return (-2); 271 return (-2);
272 } 272 }
273 273
@@ -278,7 +278,7 @@ BIO_puts(BIO *b, const char *in)
278 return (i); 278 return (i);
279 279
280 if (!b->init) { 280 if (!b->init) {
281 BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED); 281 BIOerror(BIO_R_UNINITIALIZED);
282 return (-2); 282 return (-2);
283 } 283 }
284 284
@@ -299,7 +299,7 @@ BIO_gets(BIO *b, char *in, int inl)
299 long (*cb)(BIO *, int, const char *, int, long, long); 299 long (*cb)(BIO *, int, const char *, int, long, long);
300 300
301 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { 301 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {
302 BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD); 302 BIOerror(BIO_R_UNSUPPORTED_METHOD);
303 return (-2); 303 return (-2);
304 } 304 }
305 305
@@ -310,7 +310,7 @@ BIO_gets(BIO *b, char *in, int inl)
310 return (i); 310 return (i);
311 311
312 if (!b->init) { 312 if (!b->init) {
313 BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED); 313 BIOerror(BIO_R_UNINITIALIZED);
314 return (-2); 314 return (-2);
315 } 315 }
316 316
@@ -364,7 +364,7 @@ BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
364 return (0); 364 return (0);
365 365
366 if ((b->method == NULL) || (b->method->ctrl == NULL)) { 366 if ((b->method == NULL) || (b->method->ctrl == NULL)) {
367 BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD); 367 BIOerror(BIO_R_UNSUPPORTED_METHOD);
368 return (-2); 368 return (-2);
369 } 369 }
370 370
@@ -392,7 +392,7 @@ BIO_callback_ctrl(BIO *b, int cmd,
392 return (0); 392 return (0);
393 393
394 if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { 394 if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) {
395 BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD); 395 BIOerror(BIO_R_UNSUPPORTED_METHOD);
396 return (-2); 396 return (-2);
397 } 397 }
398 398
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
index 4e3c982c2d..20508a7d5e 100644
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_acpt.c,v 1.26 2015/07/18 22:09:30 beck Exp $ */ 1/* $OpenBSD: bss_acpt.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -201,7 +201,7 @@ again:
201 switch (c->state) { 201 switch (c->state) {
202 case ACPT_S_BEFORE: 202 case ACPT_S_BEFORE:
203 if (c->param_addr == NULL) { 203 if (c->param_addr == NULL) {
204 BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED); 204 BIOerror(BIO_R_NO_ACCEPT_PORT_SPECIFIED);
205 return (-1); 205 return (-1);
206 } 206 }
207 s = BIO_get_accept_socket(c->param_addr, c->bind_mode); 207 s = BIO_get_accept_socket(c->param_addr, c->bind_mode);
@@ -211,7 +211,7 @@ again:
211 if (c->accept_nbio) { 211 if (c->accept_nbio) {
212 if (!BIO_socket_nbio(s, 1)) { 212 if (!BIO_socket_nbio(s, 1)) {
213 close(s); 213 close(s);
214 BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); 214 BIOerror(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
215 return (-1); 215 return (-1);
216 } 216 }
217 } 217 }
@@ -248,7 +248,7 @@ again:
248 248
249 if (c->nbio) { 249 if (c->nbio) {
250 if (!BIO_socket_nbio(i, 1)) { 250 if (!BIO_socket_nbio(i, 1)) {
251 BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); 251 BIOerror(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
252 goto err; 252 goto err;
253 } 253 }
254 } 254 }
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
index c817910d93..20eb9a9829 100644
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ b/src/lib/libcrypto/bio/bss_bio.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_bio.c,v 1.22 2015/12/23 20:37:23 mmcc Exp $ */ 1/* $OpenBSD: bss_bio.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -348,7 +348,7 @@ bio_write(BIO *bio, const char *buf, int num_)
348 b->request = 0; 348 b->request = 0;
349 if (b->closed) { 349 if (b->closed) {
350 /* we already closed */ 350 /* we already closed */
351 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); 351 BIOerror(BIO_R_BROKEN_PIPE);
352 return -1; 352 return -1;
353 } 353 }
354 354
@@ -425,7 +425,7 @@ bio_nwrite0(BIO *bio, char **buf)
425 425
426 b->request = 0; 426 b->request = 0;
427 if (b->closed) { 427 if (b->closed) {
428 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); 428 BIOerror(BIO_R_BROKEN_PIPE);
429 return -1; 429 return -1;
430 } 430 }
431 431
@@ -491,10 +491,10 @@ bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
491 491
492 case BIO_C_SET_WRITE_BUF_SIZE: 492 case BIO_C_SET_WRITE_BUF_SIZE:
493 if (b->peer) { 493 if (b->peer) {
494 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); 494 BIOerror(BIO_R_IN_USE);
495 ret = 0; 495 ret = 0;
496 } else if (num == 0) { 496 } else if (num == 0) {
497 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); 497 BIOerror(BIO_R_INVALID_ARGUMENT);
498 ret = 0; 498 ret = 0;
499 } else { 499 } else {
500 size_t new_size = num; 500 size_t new_size = num;
@@ -679,14 +679,14 @@ bio_make_pair(BIO *bio1, BIO *bio2)
679 b2 = bio2->ptr; 679 b2 = bio2->ptr;
680 680
681 if (b1->peer != NULL || b2->peer != NULL) { 681 if (b1->peer != NULL || b2->peer != NULL) {
682 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); 682 BIOerror(BIO_R_IN_USE);
683 return 0; 683 return 0;
684 } 684 }
685 685
686 if (b1->buf == NULL) { 686 if (b1->buf == NULL) {
687 b1->buf = malloc(b1->size); 687 b1->buf = malloc(b1->size);
688 if (b1->buf == NULL) { 688 if (b1->buf == NULL) {
689 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 689 BIOerror(ERR_R_MALLOC_FAILURE);
690 return 0; 690 return 0;
691 } 691 }
692 b1->len = 0; 692 b1->len = 0;
@@ -696,7 +696,7 @@ bio_make_pair(BIO *bio1, BIO *bio2)
696 if (b2->buf == NULL) { 696 if (b2->buf == NULL) {
697 b2->buf = malloc(b2->size); 697 b2->buf = malloc(b2->size);
698 if (b2->buf == NULL) { 698 if (b2->buf == NULL) {
699 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 699 BIOerror(ERR_R_MALLOC_FAILURE);
700 return 0; 700 return 0;
701 } 701 }
702 b2->len = 0; 702 b2->len = 0;
@@ -822,7 +822,7 @@ BIO_nread0(BIO *bio, char **buf)
822 long ret; 822 long ret;
823 823
824 if (!bio->init) { 824 if (!bio->init) {
825 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); 825 BIOerror(BIO_R_UNINITIALIZED);
826 return -2; 826 return -2;
827 } 827 }
828 828
@@ -839,7 +839,7 @@ BIO_nread(BIO *bio, char **buf, int num)
839 int ret; 839 int ret;
840 840
841 if (!bio->init) { 841 if (!bio->init) {
842 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); 842 BIOerror(BIO_R_UNINITIALIZED);
843 return -2; 843 return -2;
844 } 844 }
845 845
@@ -855,7 +855,7 @@ BIO_nwrite0(BIO *bio, char **buf)
855 long ret; 855 long ret;
856 856
857 if (!bio->init) { 857 if (!bio->init) {
858 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); 858 BIOerror(BIO_R_UNINITIALIZED);
859 return -2; 859 return -2;
860 } 860 }
861 861
@@ -872,7 +872,7 @@ BIO_nwrite(BIO *bio, char **buf, int num)
872 int ret; 872 int ret;
873 873
874 if (!bio->init) { 874 if (!bio->init) {
875 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); 875 BIOerror(BIO_R_UNINITIALIZED);
876 return -2; 876 return -2;
877 } 877 }
878 878
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index 7f50936677..555273882c 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_conn.c,v 1.32 2014/11/26 05:37:26 bcook Exp $ */ 1/* $OpenBSD: bss_conn.c,v 1.33 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -134,7 +134,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
134 case BIO_CONN_S_BEFORE: 134 case BIO_CONN_S_BEFORE:
135 p = c->param_hostname; 135 p = c->param_hostname;
136 if (p == NULL) { 136 if (p == NULL) {
137 BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED); 137 BIOerror(BIO_R_NO_HOSTNAME_SPECIFIED);
138 goto exit_loop; 138 goto exit_loop;
139 } 139 }
140 for (; *p != '\0'; p++) { 140 for (; *p != '\0'; p++) {
@@ -157,7 +157,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
157 } 157 }
158 158
159 if (c->param_port == NULL) { 159 if (c->param_port == NULL) {
160 BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED); 160 BIOerror(BIO_R_NO_PORT_SPECIFIED);
161 ERR_asprintf_error_data("host=%s", 161 ERR_asprintf_error_data("host=%s",
162 c->param_hostname); 162 c->param_hostname);
163 goto exit_loop; 163 goto exit_loop;
@@ -195,11 +195,10 @@ conn_state(BIO *b, BIO_CONNECT *c)
195 195
196 ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL); 196 ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
197 if (ret == -1) { 197 if (ret == -1) {
198 SYSerr(SYS_F_SOCKET, errno); 198 SYSerror(errno);
199 ERR_asprintf_error_data("host=%s:%s", 199 ERR_asprintf_error_data("host=%s:%s",
200 c->param_hostname, c->param_port); 200 c->param_hostname, c->param_port);
201 BIOerr(BIO_F_CONN_STATE, 201 BIOerror(BIO_R_UNABLE_TO_CREATE_SOCKET);
202 BIO_R_UNABLE_TO_CREATE_SOCKET);
203 goto exit_loop; 202 goto exit_loop;
204 } 203 }
205 b->num = ret; 204 b->num = ret;
@@ -209,8 +208,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
209 case BIO_CONN_S_NBIO: 208 case BIO_CONN_S_NBIO:
210 if (c->nbio) { 209 if (c->nbio) {
211 if (!BIO_socket_nbio(b->num, 1)) { 210 if (!BIO_socket_nbio(b->num, 1)) {
212 BIOerr(BIO_F_CONN_STATE, 211 BIOerror(BIO_R_ERROR_SETTING_NBIO);
213 BIO_R_ERROR_SETTING_NBIO);
214 ERR_asprintf_error_data("host=%s:%s", 212 ERR_asprintf_error_data("host=%s:%s",
215 c->param_hostname, c->param_port); 213 c->param_hostname, c->param_port);
216 goto exit_loop; 214 goto exit_loop;
@@ -222,10 +220,10 @@ conn_state(BIO *b, BIO_CONNECT *c)
222 i = 1; 220 i = 1;
223 i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i)); 221 i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i));
224 if (i < 0) { 222 if (i < 0) {
225 SYSerr(SYS_F_SOCKET, errno); 223 SYSerror(errno);
226 ERR_asprintf_error_data("host=%s:%s", 224 ERR_asprintf_error_data("host=%s:%s",
227 c->param_hostname, c->param_port); 225 c->param_hostname, c->param_port);
228 BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE); 226 BIOerror(BIO_R_KEEPALIVE);
229 goto exit_loop; 227 goto exit_loop;
230 } 228 }
231#endif 229#endif
@@ -243,11 +241,10 @@ conn_state(BIO *b, BIO_CONNECT *c)
243 c->state = BIO_CONN_S_BLOCKED_CONNECT; 241 c->state = BIO_CONN_S_BLOCKED_CONNECT;
244 b->retry_reason = BIO_RR_CONNECT; 242 b->retry_reason = BIO_RR_CONNECT;
245 } else { 243 } else {
246 SYSerr(SYS_F_CONNECT, errno); 244 SYSerror(errno);
247 ERR_asprintf_error_data("host=%s:%s", 245 ERR_asprintf_error_data("host=%s:%s",
248 c->param_hostname, c->param_port); 246 c->param_hostname, c->param_port);
249 BIOerr(BIO_F_CONN_STATE, 247 BIOerror(BIO_R_CONNECT_ERROR);
250 BIO_R_CONNECT_ERROR);
251 } 248 }
252 goto exit_loop; 249 goto exit_loop;
253 } else 250 } else
@@ -258,11 +255,10 @@ conn_state(BIO *b, BIO_CONNECT *c)
258 i = BIO_sock_error(b->num); 255 i = BIO_sock_error(b->num);
259 if (i) { 256 if (i) {
260 BIO_clear_retry_flags(b); 257 BIO_clear_retry_flags(b);
261 SYSerr(SYS_F_CONNECT, i); 258 SYSerror(i);
262 ERR_asprintf_error_data("host=%s:%s", 259 ERR_asprintf_error_data("host=%s:%s",
263 c->param_hostname, c->param_port); 260 c->param_hostname, c->param_port);
264 BIOerr(BIO_F_CONN_STATE, 261 BIOerror(BIO_R_NBIO_CONNECT_ERROR);
265 BIO_R_NBIO_CONNECT_ERROR);
266 ret = 0; 262 ret = 0;
267 goto exit_loop; 263 goto exit_loop;
268 } else 264 } else
@@ -533,7 +529,7 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
533 case BIO_CTRL_SET_CALLBACK: 529 case BIO_CTRL_SET_CALLBACK:
534 { 530 {
535#if 0 /* FIXME: Should this be used? -- Richard Levitte */ 531#if 0 /* FIXME: Should this be used? -- Richard Levitte */
536 BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 532 BIOerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
537 ret = -1; 533 ret = -1;
538#else 534#else
539 ret = 0; 535 ret = 0;
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index c710076fea..01f4a3ff3b 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_file.c,v 1.31 2014/11/11 19:26:12 miod Exp $ */ 1/* $OpenBSD: bss_file.c,v 1.32 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -119,12 +119,12 @@ BIO_new_file(const char *filename, const char *mode)
119 file = fopen(filename, mode); 119 file = fopen(filename, mode);
120 120
121 if (file == NULL) { 121 if (file == NULL) {
122 SYSerr(SYS_F_FOPEN, errno); 122 SYSerror(errno);
123 ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode); 123 ERR_asprintf_error_data("fopen('%s', '%s')", filename, mode);
124 if (errno == ENOENT) 124 if (errno == ENOENT)
125 BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); 125 BIOerror(BIO_R_NO_SUCH_FILE);
126 else 126 else
127 BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); 127 BIOerror(ERR_R_SYS_LIB);
128 return (NULL); 128 return (NULL);
129 } 129 }
130 if ((ret = BIO_new(BIO_s_file())) == NULL) { 130 if ((ret = BIO_new(BIO_s_file())) == NULL) {
@@ -188,8 +188,8 @@ file_read(BIO *b, char *out, int outl)
188 if (b->init && out != NULL) { 188 if (b->init && out != NULL) {
189 ret = fread(out, 1, outl, (FILE *)b->ptr); 189 ret = fread(out, 1, outl, (FILE *)b->ptr);
190 if (ret == 0 && ferror((FILE *)b->ptr)) { 190 if (ret == 0 && ferror((FILE *)b->ptr)) {
191 SYSerr(SYS_F_FREAD, errno); 191 SYSerror(errno);
192 BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); 192 BIOerror(ERR_R_SYS_LIB);
193 ret = -1; 193 ret = -1;
194 } 194 }
195 } 195 }
@@ -246,15 +246,15 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr)
246 else if (num & BIO_FP_READ) 246 else if (num & BIO_FP_READ)
247 strlcpy(p, "r", sizeof p); 247 strlcpy(p, "r", sizeof p);
248 else { 248 else {
249 BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); 249 BIOerror(BIO_R_BAD_FOPEN_MODE);
250 ret = 0; 250 ret = 0;
251 break; 251 break;
252 } 252 }
253 fp = fopen(ptr, p); 253 fp = fopen(ptr, p);
254 if (fp == NULL) { 254 if (fp == NULL) {
255 SYSerr(SYS_F_FOPEN, errno); 255 SYSerror(errno);
256 ERR_asprintf_error_data("fopen('%s', '%s')", ptr, p); 256 ERR_asprintf_error_data("fopen('%s', '%s')", ptr, p);
257 BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); 257 BIOerror(ERR_R_SYS_LIB);
258 ret = 0; 258 ret = 0;
259 break; 259 break;
260 } 260 }
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
index 119bd672f6..be491ca152 100644
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ b/src/lib/libcrypto/bio/bss_mem.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bss_mem.c,v 1.14 2015/03/21 08:05:20 doug Exp $ */ 1/* $OpenBSD: bss_mem.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -101,7 +101,7 @@ BIO_new_mem_buf(void *buf, int len)
101 size_t sz; 101 size_t sz;
102 102
103 if (!buf) { 103 if (!buf) {
104 BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); 104 BIOerror(BIO_R_NULL_PARAMETER);
105 return NULL; 105 return NULL;
106 } 106 }
107 sz = (len < 0) ? strlen(buf) : (size_t)len; 107 sz = (len < 0) ? strlen(buf) : (size_t)len;
@@ -183,12 +183,12 @@ mem_write(BIO *b, const char *in, int inl)
183 183
184 bm = (BUF_MEM *)b->ptr; 184 bm = (BUF_MEM *)b->ptr;
185 if (in == NULL) { 185 if (in == NULL) {
186 BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER); 186 BIOerror(BIO_R_NULL_PARAMETER);
187 goto end; 187 goto end;
188 } 188 }
189 189
190 if (b->flags & BIO_FLAGS_MEM_RDONLY) { 190 if (b->flags & BIO_FLAGS_MEM_RDONLY) {
191 BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO); 191 BIOerror(BIO_R_WRITE_TO_READ_ONLY_BIO);
192 goto end; 192 goto end;
193 } 193 }
194 194
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c
index ebc9b9b56b..334fb4f5d4 100644
--- a/src/lib/libcrypto/bn/bn_add.c
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_add.c,v 1.10 2014/10/28 07:35:58 jsg Exp $ */ 1/* $OpenBSD: bn_add.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -182,7 +182,7 @@ BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
182 182
183 if (dif < 0) /* hmm... should not be happening */ 183 if (dif < 0) /* hmm... should not be happening */
184 { 184 {
185 BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3); 185 BNerror(BN_R_ARG2_LT_ARG3);
186 return (0); 186 return (0);
187 } 187 }
188 188
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
index 28c6276751..ecd6718279 100644
--- a/src/lib/libcrypto/bn/bn_blind.c
+++ b/src/lib/libcrypto/bn/bn_blind.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_blind.c,v 1.16 2017/01/21 11:00:46 beck Exp $ */ 1/* $OpenBSD: bn_blind.c,v 1.17 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -144,7 +144,7 @@ BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
144 bn_check_top(mod); 144 bn_check_top(mod);
145 145
146 if ((ret = calloc(1, sizeof(BN_BLINDING))) == NULL) { 146 if ((ret = calloc(1, sizeof(BN_BLINDING))) == NULL) {
147 BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE); 147 BNerror(ERR_R_MALLOC_FAILURE);
148 return (NULL); 148 return (NULL);
149 } 149 }
150 if (A != NULL) { 150 if (A != NULL) {
@@ -194,7 +194,7 @@ BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
194 int ret = 0; 194 int ret = 0;
195 195
196 if ((b->A == NULL) || (b->Ai == NULL)) { 196 if ((b->A == NULL) || (b->Ai == NULL)) {
197 BNerr(BN_F_BN_BLINDING_UPDATE, BN_R_NOT_INITIALIZED); 197 BNerror(BN_R_NOT_INITIALIZED);
198 goto err; 198 goto err;
199 } 199 }
200 200
@@ -235,7 +235,7 @@ BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
235 bn_check_top(n); 235 bn_check_top(n);
236 236
237 if ((b->A == NULL) || (b->Ai == NULL)) { 237 if ((b->A == NULL) || (b->Ai == NULL)) {
238 BNerr(BN_F_BN_BLINDING_CONVERT_EX, BN_R_NOT_INITIALIZED); 238 BNerror(BN_R_NOT_INITIALIZED);
239 return (0); 239 return (0);
240 } 240 }
241 241
@@ -273,7 +273,7 @@ BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
273 ret = BN_mod_mul(n, n, r, b->mod, ctx); 273 ret = BN_mod_mul(n, n, r, b->mod, ctx);
274 else { 274 else {
275 if (b->Ai == NULL) { 275 if (b->Ai == NULL) {
276 BNerr(BN_F_BN_BLINDING_INVERT_EX, BN_R_NOT_INITIALIZED); 276 BNerror(BN_R_NOT_INITIALIZED);
277 return (0); 277 return (0);
278 } 278 }
279 ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx); 279 ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);
@@ -356,8 +356,7 @@ BN_BLINDING_create_param(BN_BLINDING *b, const BIGNUM *e, BIGNUM *m,
356 unsigned long error = ERR_peek_last_error(); 356 unsigned long error = ERR_peek_last_error();
357 if (ERR_GET_REASON(error) == BN_R_NO_INVERSE) { 357 if (ERR_GET_REASON(error) == BN_R_NO_INVERSE) {
358 if (retry_counter-- == 0) { 358 if (retry_counter-- == 0) {
359 BNerr(BN_F_BN_BLINDING_CREATE_PARAM, 359 BNerror(BN_R_TOO_MANY_ITERATIONS);
360 BN_R_TOO_MANY_ITERATIONS);
361 goto err; 360 goto err;
362 } 361 }
363 ERR_clear_error(); 362 ERR_clear_error();
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
index eb2d6a43b3..1237ac1365 100644
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_ctx.c,v 1.14 2015/02/10 09:50:12 miod Exp $ */ 1/* $OpenBSD: bn_ctx.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Ulf Moeller for the OpenSSL project. */ 2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ==================================================================== 3/* ====================================================================
4 * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. 4 * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved.
@@ -225,7 +225,7 @@ BN_CTX_new(void)
225{ 225{
226 BN_CTX *ret = malloc(sizeof(BN_CTX)); 226 BN_CTX *ret = malloc(sizeof(BN_CTX));
227 if (!ret) { 227 if (!ret) {
228 BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE); 228 BNerror(ERR_R_MALLOC_FAILURE);
229 return NULL; 229 return NULL;
230 } 230 }
231 231
@@ -274,7 +274,7 @@ BN_CTX_start(BN_CTX *ctx)
274 ctx->err_stack++; 274 ctx->err_stack++;
275 /* (Try to) get a new frame pointer */ 275 /* (Try to) get a new frame pointer */
276 else if (!BN_STACK_push(&ctx->stack, ctx->used)) { 276 else if (!BN_STACK_push(&ctx->stack, ctx->used)) {
277 BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES); 277 BNerror(BN_R_TOO_MANY_TEMPORARY_VARIABLES);
278 ctx->err_stack++; 278 ctx->err_stack++;
279 } 279 }
280 CTXDBG_EXIT(ctx); 280 CTXDBG_EXIT(ctx);
@@ -312,7 +312,7 @@ BN_CTX_get(BN_CTX *ctx)
312 /* Setting too_many prevents repeated "get" attempts from 312 /* Setting too_many prevents repeated "get" attempts from
313 * cluttering the error stack. */ 313 * cluttering the error stack. */
314 ctx->too_many = 1; 314 ctx->too_many = 1;
315 BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES); 315 BNerror(BN_R_TOO_MANY_TEMPORARY_VARIABLES);
316 return NULL; 316 return NULL;
317 } 317 }
318 /* OK, make sure the returned bignum is "zero" */ 318 /* OK, make sure the returned bignum is "zero" */
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index a8f7c9f384..f3a97bcc8d 100644
--- a/src/lib/libcrypto/bn/bn_div.c
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_div.c,v 1.24 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_div.c,v 1.25 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -131,7 +131,7 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
131 * in the case of 'num', so don't just rely on bn_check_top() for this one 131 * in the case of 'num', so don't just rely on bn_check_top() for this one
132 * (bn_check_top() works only for BN_DEBUG builds) */ 132 * (bn_check_top() works only for BN_DEBUG builds) */
133 if (num->top > 0 && num->d[num->top - 1] == 0) { 133 if (num->top > 0 && num->d[num->top - 1] == 0) {
134 BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED); 134 BNerror(BN_R_NOT_INITIALIZED);
135 return 0; 135 return 0;
136 } 136 }
137 137
@@ -146,7 +146,7 @@ BN_div_internal(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor
146 bn_check_top(divisor); 146 bn_check_top(divisor);
147 147
148 if (BN_is_zero(divisor)) { 148 if (BN_is_zero(divisor)) {
149 BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO); 149 BNerror(BN_R_DIV_BY_ZERO);
150 return (0); 150 return (0);
151 } 151 }
152 152
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
index 149e58eafc..a693a8cbf8 100644
--- a/src/lib/libcrypto/bn/bn_err.c
+++ b/src/lib/libcrypto/bn/bn_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_err.c,v 1.13 2015/10/21 19:02:22 miod Exp $ */ 1/* $OpenBSD: bn_err.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,47 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BN,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BN,0,reason)
73 73
74static ERR_STRING_DATA BN_str_functs[]= { 74static ERR_STRING_DATA BN_str_functs[]= {
75 {ERR_FUNC(BN_F_BNRAND), "BNRAND"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(BN_F_BN_BLINDING_CONVERT_EX), "BN_BLINDING_convert_ex"},
77 {ERR_FUNC(BN_F_BN_BLINDING_CREATE_PARAM), "BN_BLINDING_create_param"},
78 {ERR_FUNC(BN_F_BN_BLINDING_INVERT_EX), "BN_BLINDING_invert_ex"},
79 {ERR_FUNC(BN_F_BN_BLINDING_NEW), "BN_BLINDING_new"},
80 {ERR_FUNC(BN_F_BN_BLINDING_UPDATE), "BN_BLINDING_update"},
81 {ERR_FUNC(BN_F_BN_BN2DEC), "BN_bn2dec"},
82 {ERR_FUNC(BN_F_BN_BN2HEX), "BN_bn2hex"},
83 {ERR_FUNC(BN_F_BN_CTX_GET), "BN_CTX_get"},
84 {ERR_FUNC(BN_F_BN_CTX_NEW), "BN_CTX_new"},
85 {ERR_FUNC(BN_F_BN_CTX_START), "BN_CTX_start"},
86 {ERR_FUNC(BN_F_BN_DIV), "BN_div"},
87 {ERR_FUNC(BN_F_BN_DIV_NO_BRANCH), "BN_div_no_branch"},
88 {ERR_FUNC(BN_F_BN_DIV_RECP), "BN_div_recp"},
89 {ERR_FUNC(BN_F_BN_EXP), "BN_exp"},
90 {ERR_FUNC(BN_F_BN_EXPAND2), "bn_expand2"},
91 {ERR_FUNC(BN_F_BN_EXPAND_INTERNAL), "BN_EXPAND_INTERNAL"},
92 {ERR_FUNC(BN_F_BN_GENERATE_PRIME_EX), "BN_generate_prime_ex"},
93 {ERR_FUNC(BN_F_BN_GF2M_MOD), "BN_GF2m_mod"},
94 {ERR_FUNC(BN_F_BN_GF2M_MOD_EXP), "BN_GF2m_mod_exp"},
95 {ERR_FUNC(BN_F_BN_GF2M_MOD_MUL), "BN_GF2m_mod_mul"},
96 {ERR_FUNC(BN_F_BN_GF2M_MOD_SOLVE_QUAD), "BN_GF2m_mod_solve_quad"},
97 {ERR_FUNC(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR), "BN_GF2m_mod_solve_quad_arr"},
98 {ERR_FUNC(BN_F_BN_GF2M_MOD_SQR), "BN_GF2m_mod_sqr"},
99 {ERR_FUNC(BN_F_BN_GF2M_MOD_SQRT), "BN_GF2m_mod_sqrt"},
100 {ERR_FUNC(BN_F_BN_MOD_EXP2_MONT), "BN_mod_exp2_mont"},
101 {ERR_FUNC(BN_F_BN_MOD_EXP_MONT), "BN_mod_exp_mont"},
102 {ERR_FUNC(BN_F_BN_MOD_EXP_MONT_CONSTTIME), "BN_mod_exp_mont_consttime"},
103 {ERR_FUNC(BN_F_BN_MOD_EXP_MONT_WORD), "BN_mod_exp_mont_word"},
104 {ERR_FUNC(BN_F_BN_MOD_EXP_RECP), "BN_mod_exp_recp"},
105 {ERR_FUNC(BN_F_BN_MOD_EXP_SIMPLE), "BN_mod_exp_simple"},
106 {ERR_FUNC(BN_F_BN_MOD_INVERSE), "BN_mod_inverse"},
107 {ERR_FUNC(BN_F_BN_MOD_INVERSE_NO_BRANCH), "BN_mod_inverse_no_branch"},
108 {ERR_FUNC(BN_F_BN_MOD_LSHIFT_QUICK), "BN_mod_lshift_quick"},
109 {ERR_FUNC(BN_F_BN_MOD_MUL_RECIPROCAL), "BN_mod_mul_reciprocal"},
110 {ERR_FUNC(BN_F_BN_MOD_SQRT), "BN_mod_sqrt"},
111 {ERR_FUNC(BN_F_BN_MPI2BN), "BN_mpi2bn"},
112 {ERR_FUNC(BN_F_BN_NEW), "BN_new"},
113 {ERR_FUNC(BN_F_BN_RAND), "BN_rand"},
114 {ERR_FUNC(BN_F_BN_RAND_RANGE), "BN_rand_range"},
115 {ERR_FUNC(BN_F_BN_USUB), "BN_usub"},
116 {0, NULL} 76 {0, NULL}
117}; 77};
118 78
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index f650e94b09..d388758927 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.29 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.30 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -129,7 +129,7 @@ BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
129 129
130 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { 130 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
131 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 131 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
132 BNerr(BN_F_BN_EXP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 132 BNerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
133 return -1; 133 return -1;
134 } 134 }
135 135
@@ -263,7 +263,7 @@ BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
263 263
264 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { 264 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
265 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 265 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
266 BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 266 BNerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
267 return -1; 267 return -1;
268 } 268 }
269 269
@@ -405,7 +405,7 @@ BN_mod_exp_mont_internal(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, const BIG
405 bn_check_top(m); 405 bn_check_top(m);
406 406
407 if (!BN_is_odd(m)) { 407 if (!BN_is_odd(m)) {
408 BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS); 408 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
409 return (0); 409 return (0);
410 } 410 }
411 411
@@ -662,8 +662,7 @@ BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
662 bn_check_top(m); 662 bn_check_top(m);
663 663
664 if (!BN_is_odd(m)) { 664 if (!BN_is_odd(m)) {
665 BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, 665 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
666 BN_R_CALLED_WITH_EVEN_MODULUS);
667 return (0); 666 return (0);
668 } 667 }
669 668
@@ -938,8 +937,7 @@ BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, const BIGNUM *m,
938 937
939 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { 938 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
940 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 939 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
941 BNerr(BN_F_BN_MOD_EXP_MONT_WORD, 940 BNerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
942 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
943 return -1; 941 return -1;
944 } 942 }
945 943
@@ -947,7 +945,7 @@ BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p, const BIGNUM *m,
947 bn_check_top(m); 945 bn_check_top(m);
948 946
949 if (!BN_is_odd(m)) { 947 if (!BN_is_odd(m)) {
950 BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS); 948 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
951 return (0); 949 return (0);
952 } 950 }
953 if (m->top == 1) 951 if (m->top == 1)
@@ -1076,8 +1074,7 @@ BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
1076 1074
1077 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) { 1075 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {
1078 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 1076 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */
1079 BNerr(BN_F_BN_MOD_EXP_SIMPLE, 1077 BNerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1080 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1081 return -1; 1078 return -1;
1082 } 1079 }
1083 1080
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
index 1d938d3818..372e1ee4ee 100644
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ b/src/lib/libcrypto/bn/bn_exp2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp2.c,v 1.11 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_exp2.c,v 1.12 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -137,7 +137,7 @@ BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
137 bn_check_top(m); 137 bn_check_top(m);
138 138
139 if (!(m->d[0] & 1)) { 139 if (!(m->d[0] & 1)) {
140 BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS); 140 BNerror(BN_R_CALLED_WITH_EVEN_MODULUS);
141 return (0); 141 return (0);
142 } 142 }
143 bits1 = BN_num_bits(p1); 143 bits1 = BN_num_bits(p1);
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
index e2574c3304..469ae752fb 100644
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ b/src/lib/libcrypto/bn/bn_gcd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_gcd.c,v 1.14 2017/01/25 06:15:44 beck Exp $ */ 1/* $OpenBSD: bn_gcd.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -527,7 +527,7 @@ BN_mod_inverse_internal(BIGNUM *in, const BIGNUM *a, const BIGNUM *n, BN_CTX *ct
527 goto err; 527 goto err;
528 } 528 }
529 } else { 529 } else {
530 BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE); 530 BNerror(BN_R_NO_INVERSE);
531 goto err; 531 goto err;
532 } 532 }
533 ret = R; 533 ret = R;
@@ -709,7 +709,7 @@ BN_mod_inverse_no_branch(BIGNUM *in, const BIGNUM *a, const BIGNUM *n,
709 goto err; 709 goto err;
710 } 710 }
711 } else { 711 } else {
712 BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE); 712 BNerror(BN_R_NO_INVERSE);
713 goto err; 713 goto err;
714 } 714 }
715 ret = R; 715 ret = R;
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c
index 62395f60eb..8562b3f87e 100644
--- a/src/lib/libcrypto/bn/bn_gf2m.c
+++ b/src/lib/libcrypto/bn/bn_gf2m.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_gf2m.c,v 1.22 2016/09/03 14:37:00 bcook Exp $ */ 1/* $OpenBSD: bn_gf2m.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -470,7 +470,7 @@ BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
470 bn_check_top(p); 470 bn_check_top(p);
471 ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0])); 471 ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0]));
472 if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) { 472 if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) {
473 BNerr(BN_F_BN_GF2M_MOD, BN_R_INVALID_LENGTH); 473 BNerror(BN_R_INVALID_LENGTH);
474 return 0; 474 return 0;
475 } 475 }
476 ret = BN_GF2m_mod_arr(r, a, arr); 476 ret = BN_GF2m_mod_arr(r, a, arr);
@@ -553,7 +553,7 @@ BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p,
553 goto err; 553 goto err;
554 ret = BN_GF2m_poly2arr(p, arr, max); 554 ret = BN_GF2m_poly2arr(p, arr, max);
555 if (!ret || ret > max) { 555 if (!ret || ret > max) {
556 BNerr(BN_F_BN_GF2M_MOD_MUL, BN_R_INVALID_LENGTH); 556 BNerror(BN_R_INVALID_LENGTH);
557 goto err; 557 goto err;
558 } 558 }
559 ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx); 559 ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
@@ -615,7 +615,7 @@ BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
615 goto err; 615 goto err;
616 ret = BN_GF2m_poly2arr(p, arr, max); 616 ret = BN_GF2m_poly2arr(p, arr, max);
617 if (!ret || ret > max) { 617 if (!ret || ret > max) {
618 BNerr(BN_F_BN_GF2M_MOD_SQR, BN_R_INVALID_LENGTH); 618 BNerror(BN_R_INVALID_LENGTH);
619 goto err; 619 goto err;
620 } 620 }
621 ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx); 621 ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
@@ -1052,7 +1052,7 @@ BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p,
1052 goto err; 1052 goto err;
1053 ret = BN_GF2m_poly2arr(p, arr, max); 1053 ret = BN_GF2m_poly2arr(p, arr, max);
1054 if (!ret || ret > max) { 1054 if (!ret || ret > max) {
1055 BNerr(BN_F_BN_GF2M_MOD_EXP, BN_R_INVALID_LENGTH); 1055 BNerror(BN_R_INVALID_LENGTH);
1056 goto err; 1056 goto err;
1057 } 1057 }
1058 ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx); 1058 ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx);
@@ -1114,7 +1114,7 @@ BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
1114 goto err; 1114 goto err;
1115 ret = BN_GF2m_poly2arr(p, arr, max); 1115 ret = BN_GF2m_poly2arr(p, arr, max);
1116 if (!ret || ret > max) { 1116 if (!ret || ret > max) {
1117 BNerr(BN_F_BN_GF2M_MOD_SQRT, BN_R_INVALID_LENGTH); 1117 BNerror(BN_R_INVALID_LENGTH);
1118 goto err; 1118 goto err;
1119 } 1119 }
1120 ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx); 1120 ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
@@ -1206,8 +1206,7 @@ BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[],
1206 count++; 1206 count++;
1207 } while (BN_is_zero(w) && (count < MAX_ITERATIONS)); 1207 } while (BN_is_zero(w) && (count < MAX_ITERATIONS));
1208 if (BN_is_zero(w)) { 1208 if (BN_is_zero(w)) {
1209 BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, 1209 BNerror(BN_R_TOO_MANY_ITERATIONS);
1210 BN_R_TOO_MANY_ITERATIONS);
1211 goto err; 1210 goto err;
1212 } 1211 }
1213 } 1212 }
@@ -1217,7 +1216,7 @@ BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[],
1217 if (!BN_GF2m_add(w, z, w)) 1216 if (!BN_GF2m_add(w, z, w))
1218 goto err; 1217 goto err;
1219 if (BN_GF2m_cmp(w, a)) { 1218 if (BN_GF2m_cmp(w, a)) {
1220 BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, BN_R_NO_SOLUTION); 1219 BNerror(BN_R_NO_SOLUTION);
1221 goto err; 1220 goto err;
1222 } 1221 }
1223 1222
@@ -1251,7 +1250,7 @@ BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
1251 goto err; 1250 goto err;
1252 ret = BN_GF2m_poly2arr(p, arr, max); 1251 ret = BN_GF2m_poly2arr(p, arr, max);
1253 if (!ret || ret > max) { 1252 if (!ret || ret > max) {
1254 BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD, BN_R_INVALID_LENGTH); 1253 BNerror(BN_R_INVALID_LENGTH);
1255 goto err; 1254 goto err;
1256 } 1255 }
1257 ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx); 1256 ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx);
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 17f4ae89da..f2736e31c3 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.36 2016/03/15 20:50:22 krw Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.37 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -249,7 +249,7 @@ BN_new(void)
249 BIGNUM *ret; 249 BIGNUM *ret;
250 250
251 if ((ret = malloc(sizeof(BIGNUM))) == NULL) { 251 if ((ret = malloc(sizeof(BIGNUM))) == NULL) {
252 BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE); 252 BNerror(ERR_R_MALLOC_FAILURE);
253 return (NULL); 253 return (NULL);
254 } 254 }
255 ret->flags = BN_FLG_MALLOCED; 255 ret->flags = BN_FLG_MALLOCED;
@@ -273,17 +273,16 @@ bn_expand_internal(const BIGNUM *b, int words)
273 bn_check_top(b); 273 bn_check_top(b);
274 274
275 if (words > (INT_MAX/(4*BN_BITS2))) { 275 if (words > (INT_MAX/(4*BN_BITS2))) {
276 BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); 276 BNerror(BN_R_BIGNUM_TOO_LONG);
277 return NULL; 277 return NULL;
278 } 278 }
279 if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { 279 if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
280 BNerr(BN_F_BN_EXPAND_INTERNAL, 280 BNerror(BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
281 BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
282 return (NULL); 281 return (NULL);
283 } 282 }
284 a = A = reallocarray(NULL, words, sizeof(BN_ULONG)); 283 a = A = reallocarray(NULL, words, sizeof(BN_ULONG));
285 if (A == NULL) { 284 if (A == NULL) {
286 BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); 285 BNerror(ERR_R_MALLOC_FAILURE);
287 return (NULL); 286 return (NULL);
288 } 287 }
289#if 1 288#if 1
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c
index 4c30c098d4..897ff434e9 100644
--- a/src/lib/libcrypto/bn/bn_mod.c
+++ b/src/lib/libcrypto/bn/bn_mod.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mod.c,v 1.11 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_mod.c,v 1.12 2017/01/29 17:49:22 beck Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. */ 3 * for the OpenSSL project. */
4/* ==================================================================== 4/* ====================================================================
@@ -278,7 +278,7 @@ BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
278 /* max_shift >= 0 */ 278 /* max_shift >= 0 */
279 279
280 if (max_shift < 0) { 280 if (max_shift < 0) {
281 BNerr(BN_F_BN_MOD_LSHIFT_QUICK, BN_R_INPUT_NOT_REDUCED); 281 BNerror(BN_R_INPUT_NOT_REDUCED);
282 return 0; 282 return 0;
283 } 283 }
284 284
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
index cf4c7d8d24..4801192b50 100644
--- a/src/lib/libcrypto/bn/bn_mpi.c
+++ b/src/lib/libcrypto/bn/bn_mpi.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mpi.c,v 1.7 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: bn_mpi.c,v 1.8 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -98,13 +98,13 @@ BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a)
98 int neg = 0; 98 int neg = 0;
99 99
100 if (n < 4) { 100 if (n < 4) {
101 BNerr(BN_F_BN_MPI2BN, BN_R_INVALID_LENGTH); 101 BNerror(BN_R_INVALID_LENGTH);
102 return (NULL); 102 return (NULL);
103 } 103 }
104 len = ((long)d[0] << 24) | ((long)d[1] << 16) | ((int)d[2] << 8) | 104 len = ((long)d[0] << 24) | ((long)d[1] << 16) | ((int)d[2] << 8) |
105 (int)d[3]; 105 (int)d[3];
106 if ((len + 4) != n) { 106 if ((len + 4) != n) {
107 BNerr(BN_F_BN_MPI2BN, BN_R_ENCODING_ERROR); 107 BNerror(BN_R_ENCODING_ERROR);
108 return (NULL); 108 return (NULL);
109 } 109 }
110 110
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index ec8217ef69..e78c5686ab 100644
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_prime.c,v 1.17 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_prime.c,v 1.18 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -173,7 +173,7 @@ BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, const BIGNUM *add,
173 * There are no prime numbers smaller than 2, and the smallest 173 * There are no prime numbers smaller than 2, and the smallest
174 * safe prime (7) spans three bits. 174 * safe prime (7) spans three bits.
175 */ 175 */
176 BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL); 176 BNerror(BN_R_BITS_TOO_SMALL);
177 return 0; 177 return 0;
178 } 178 }
179 179
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index f526065592..de67c03c14 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_print.c,v 1.30 2016/10/17 03:30:14 guenther Exp $ */ 1/* $OpenBSD: bn_print.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,7 +80,7 @@ BN_bn2hex(const BIGNUM *a)
80 80
81 buf = malloc(BN_is_negative(a) + a->top * BN_BYTES * 2 + 2); 81 buf = malloc(BN_is_negative(a) + a->top * BN_BYTES * 2 + 2);
82 if (buf == NULL) { 82 if (buf == NULL) {
83 BNerr(BN_F_BN_BN2HEX, ERR_R_MALLOC_FAILURE); 83 BNerror(ERR_R_MALLOC_FAILURE);
84 goto err; 84 goto err;
85 } 85 }
86 p = buf; 86 p = buf;
@@ -118,7 +118,7 @@ BN_bn2dec(const BIGNUM *a)
118 if (BN_is_zero(a)) { 118 if (BN_is_zero(a)) {
119 buf = malloc(BN_is_negative(a) + 2); 119 buf = malloc(BN_is_negative(a) + 2);
120 if (buf == NULL) { 120 if (buf == NULL) {
121 BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE); 121 BNerror(ERR_R_MALLOC_FAILURE);
122 goto err; 122 goto err;
123 } 123 }
124 p = buf; 124 p = buf;
@@ -140,7 +140,7 @@ BN_bn2dec(const BIGNUM *a)
140 bn_data = reallocarray(NULL, bn_data_num, sizeof(BN_ULONG)); 140 bn_data = reallocarray(NULL, bn_data_num, sizeof(BN_ULONG));
141 buf = malloc(num + 3); 141 buf = malloc(num + 3);
142 if ((buf == NULL) || (bn_data == NULL)) { 142 if ((buf == NULL) || (bn_data == NULL)) {
143 BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE); 143 BNerror(ERR_R_MALLOC_FAILURE);
144 goto err; 144 goto err;
145 } 145 }
146 if ((t = BN_dup(a)) == NULL) 146 if ((t = BN_dup(a)) == NULL)
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index 783f6c22f8..812fa6a575 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_rand.c,v 1.18 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: bn_rand.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -125,7 +125,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
125 int ret = 0, bit, bytes, mask; 125 int ret = 0, bit, bytes, mask;
126 126
127 if (rnd == NULL) { 127 if (rnd == NULL) {
128 BNerr(BN_F_BNRAND, ERR_R_PASSED_NULL_PARAMETER); 128 BNerror(ERR_R_PASSED_NULL_PARAMETER);
129 return (0); 129 return (0);
130 } 130 }
131 131
@@ -140,7 +140,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
140 140
141 buf = malloc(bytes); 141 buf = malloc(bytes);
142 if (buf == NULL) { 142 if (buf == NULL) {
143 BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE); 143 BNerror(ERR_R_MALLOC_FAILURE);
144 goto err; 144 goto err;
145 } 145 }
146 146
@@ -224,7 +224,7 @@ bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
224 int count = 100; 224 int count = 100;
225 225
226 if (range->neg || BN_is_zero(range)) { 226 if (range->neg || BN_is_zero(range)) {
227 BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE); 227 BNerror(BN_R_INVALID_RANGE);
228 return 0; 228 return 0;
229 } 229 }
230 230
@@ -254,8 +254,7 @@ bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
254 } 254 }
255 255
256 if (!--count) { 256 if (!--count) {
257 BNerr(BN_F_BN_RAND_RANGE, 257 BNerror(BN_R_TOO_MANY_ITERATIONS);
258 BN_R_TOO_MANY_ITERATIONS);
259 return 0; 258 return 0;
260 } 259 }
261 260
@@ -267,8 +266,7 @@ bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
267 return 0; 266 return 0;
268 267
269 if (!--count) { 268 if (!--count) {
270 BNerr(BN_F_BN_RAND_RANGE, 269 BNerror(BN_R_TOO_MANY_ITERATIONS);
271 BN_R_TOO_MANY_ITERATIONS);
272 return 0; 270 return 0;
273 } 271 }
274 } while (BN_cmp(r, range) >= 0); 272 } while (BN_cmp(r, range) >= 0);
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index aae7c7ef85..6588d33033 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_recp.c,v 1.14 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: bn_recp.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -212,7 +212,7 @@ BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, BN_RECP_CTX *recp,
212 j = 0; 212 j = 0;
213 while (BN_ucmp(r, &(recp->N)) >= 0) { 213 while (BN_ucmp(r, &(recp->N)) >= 0) {
214 if (j++ > 2) { 214 if (j++ > 2) {
215 BNerr(BN_F_BN_DIV_RECP, BN_R_BAD_RECIPROCAL); 215 BNerror(BN_R_BAD_RECIPROCAL);
216 goto err; 216 goto err;
217 } 217 }
218 if (!BN_usub(r, r, &(recp->N))) 218 if (!BN_usub(r, r, &(recp->N)))
diff --git a/src/lib/libcrypto/bn/bn_sqrt.c b/src/lib/libcrypto/bn/bn_sqrt.c
index 5928dfc79d..8514f23a27 100644
--- a/src/lib/libcrypto/bn/bn_sqrt.c
+++ b/src/lib/libcrypto/bn/bn_sqrt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_sqrt.c,v 1.8 2017/01/21 09:38:58 beck Exp $ */ 1/* $OpenBSD: bn_sqrt.c,v 1.9 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * and Bodo Moeller for the OpenSSL project. */ 3 * and Bodo Moeller for the OpenSSL project. */
4/* ==================================================================== 4/* ====================================================================
@@ -89,7 +89,7 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
89 return ret; 89 return ret;
90 } 90 }
91 91
92 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME); 92 BNerror(BN_R_P_IS_NOT_PRIME);
93 return (NULL); 93 return (NULL);
94 } 94 }
95 95
@@ -250,7 +250,7 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
250 goto end; 250 goto end;
251 if (r == 0) { 251 if (r == 0) {
252 /* m divides p */ 252 /* m divides p */
253 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME); 253 BNerror(BN_R_P_IS_NOT_PRIME);
254 goto end; 254 goto end;
255 } 255 }
256 } 256 }
@@ -262,7 +262,7 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
262 * Even if p is not prime, we should have found some y 262 * Even if p is not prime, we should have found some y
263 * such that r == -1. 263 * such that r == -1.
264 */ 264 */
265 BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS); 265 BNerror(BN_R_TOO_MANY_ITERATIONS);
266 goto end; 266 goto end;
267 } 267 }
268 268
@@ -275,7 +275,7 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
275 if (!BN_mod_exp_ct(y, y, q, p, ctx)) 275 if (!BN_mod_exp_ct(y, y, q, p, ctx))
276 goto end; 276 goto end;
277 if (BN_is_one(y)) { 277 if (BN_is_one(y)) {
278 BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME); 278 BNerror(BN_R_P_IS_NOT_PRIME);
279 goto end; 279 goto end;
280 } 280 }
281 281
@@ -359,7 +359,7 @@ BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
359 while (!BN_is_one(t)) { 359 while (!BN_is_one(t)) {
360 i++; 360 i++;
361 if (i == e) { 361 if (i == e) {
362 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE); 362 BNerror(BN_R_NOT_A_SQUARE);
363 goto end; 363 goto end;
364 } 364 }
365 if (!BN_mod_mul(t, t, t, p, ctx)) 365 if (!BN_mod_mul(t, t, t, p, ctx))
@@ -392,7 +392,7 @@ vrfy:
392 err = 1; 392 err = 1;
393 393
394 if (!err && 0 != BN_cmp(x, A)) { 394 if (!err && 0 != BN_cmp(x, A)) {
395 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE); 395 BNerror(BN_R_NOT_A_SQUARE);
396 err = 1; 396 err = 1;
397 } 397 }
398 } 398 }
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c
index 8256e89843..dd5cc5e173 100644
--- a/src/lib/libcrypto/buffer/buf_err.c
+++ b/src/lib/libcrypto/buffer/buf_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: buf_err.c,v 1.10 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: buf_err.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,12 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BUF,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BUF,0,reason)
73 73
74static ERR_STRING_DATA BUF_str_functs[] = { 74static ERR_STRING_DATA BUF_str_functs[] = {
75 {ERR_FUNC(BUF_F_BUF_MEMDUP), "BUF_memdup"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"},
77 {ERR_FUNC(BUF_F_BUF_MEM_GROW_CLEAN), "BUF_MEM_grow_clean"},
78 {ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"},
79 {ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"},
80 {ERR_FUNC(BUF_F_BUF_STRNDUP), "BUF_strndup"},
81 {0, NULL} 76 {0, NULL}
82}; 77};
83 78
diff --git a/src/lib/libcrypto/buffer/buf_str.c b/src/lib/libcrypto/buffer/buf_str.c
index f7e4c0b966..a9ab87a09f 100644
--- a/src/lib/libcrypto/buffer/buf_str.c
+++ b/src/lib/libcrypto/buffer/buf_str.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: buf_str.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: buf_str.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Bob Beck 3 * Copyright (c) 2014 Bob Beck
4 * 4 *
@@ -35,7 +35,7 @@ BUF_strdup(const char *str)
35 35
36 if (str != NULL) { 36 if (str != NULL) {
37 if (!(ret = strdup(str))) 37 if (!(ret = strdup(str)))
38 BUFerr(BUF_F_BUF_STRDUP, ERR_R_MALLOC_FAILURE); 38 BUFerror(ERR_R_MALLOC_FAILURE);
39 } 39 }
40 return ret; 40 return ret;
41} 41}
@@ -47,7 +47,7 @@ BUF_strndup(const char *str, size_t siz)
47 47
48 if (str != NULL) { 48 if (str != NULL) {
49 if (!(ret = strndup(str, siz))) 49 if (!(ret = strndup(str, siz)))
50 BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); 50 BUFerror(ERR_R_MALLOC_FAILURE);
51 } 51 }
52 return ret; 52 return ret;
53} 53}
@@ -59,7 +59,7 @@ BUF_memdup(const void *data, size_t siz)
59 59
60 if (data != NULL) { 60 if (data != NULL) {
61 if (!(ret = malloc(siz))) 61 if (!(ret = malloc(siz)))
62 BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE); 62 BUFerror(ERR_R_MALLOC_FAILURE);
63 else 63 else
64 (void) memcpy(ret, data, siz); 64 (void) memcpy(ret, data, siz);
65 } 65 }
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
index ac3729d52b..e32abb14f3 100644
--- a/src/lib/libcrypto/buffer/buffer.c
+++ b/src/lib/libcrypto/buffer/buffer.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: buffer.c,v 1.21 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: buffer.c,v 1.22 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -75,7 +75,7 @@ BUF_MEM_new(void)
75 75
76 ret = malloc(sizeof(BUF_MEM)); 76 ret = malloc(sizeof(BUF_MEM));
77 if (ret == NULL) { 77 if (ret == NULL) {
78 BUFerr(BUF_F_BUF_MEM_NEW, ERR_R_MALLOC_FAILURE); 78 BUFerror(ERR_R_MALLOC_FAILURE);
79 return (NULL); 79 return (NULL);
80 } 80 }
81 ret->length = 0; 81 ret->length = 0;
@@ -114,13 +114,13 @@ BUF_MEM_grow(BUF_MEM *str, size_t len)
114 } 114 }
115 /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ 115 /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
116 if (len > LIMIT_BEFORE_EXPANSION) { 116 if (len > LIMIT_BEFORE_EXPANSION) {
117 BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE); 117 BUFerror(ERR_R_MALLOC_FAILURE);
118 return 0; 118 return 0;
119 } 119 }
120 n = (len + 3) / 3 * 4; 120 n = (len + 3) / 3 * 4;
121 ret = realloc(str->data, n); 121 ret = realloc(str->data, n);
122 if (ret == NULL) { 122 if (ret == NULL) {
123 BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE); 123 BUFerror(ERR_R_MALLOC_FAILURE);
124 len = 0; 124 len = 0;
125 } else { 125 } else {
126 str->data = ret; 126 str->data = ret;
@@ -149,7 +149,7 @@ BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
149 } 149 }
150 /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */ 150 /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
151 if (len > LIMIT_BEFORE_EXPANSION) { 151 if (len > LIMIT_BEFORE_EXPANSION) {
152 BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE); 152 BUFerror(ERR_R_MALLOC_FAILURE);
153 return 0; 153 return 0;
154 } 154 }
155 n = (len + 3) / 3 * 4; 155 n = (len + 3) / 3 * 4;
@@ -161,7 +161,7 @@ BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
161 free(str->data); 161 free(str->data);
162 } 162 }
163 if (ret == NULL) { 163 if (ret == NULL) {
164 BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE); 164 BUFerror(ERR_R_MALLOC_FAILURE);
165 len = 0; 165 len = 0;
166 } else { 166 } else {
167 str->data = ret; 167 str->data = ret;
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index d9a3359313..1802cffd99 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: c_zlib.c,v 1.18 2015/12/23 20:37:23 mmcc Exp $ */ 1/* $OpenBSD: c_zlib.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
@@ -257,7 +257,7 @@ bio_zlib_new(BIO *bi)
257 257
258 ctx = malloc(sizeof(BIO_ZLIB_CTX)); 258 ctx = malloc(sizeof(BIO_ZLIB_CTX));
259 if (!ctx) { 259 if (!ctx) {
260 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); 260 COMPerror(ERR_R_MALLOC_FAILURE);
261 return 0; 261 return 0;
262 } 262 }
263 ctx->ibuf = NULL; 263 ctx->ibuf = NULL;
@@ -324,7 +324,7 @@ bio_zlib_read(BIO *b, char *out, int outl)
324 if (!ctx->ibuf) { 324 if (!ctx->ibuf) {
325 ctx->ibuf = malloc(ctx->ibufsize); 325 ctx->ibuf = malloc(ctx->ibufsize);
326 if (!ctx->ibuf) { 326 if (!ctx->ibuf) {
327 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE); 327 COMPerror(ERR_R_MALLOC_FAILURE);
328 return 0; 328 return 0;
329 } 329 }
330 inflateInit(zin); 330 inflateInit(zin);
@@ -340,8 +340,7 @@ bio_zlib_read(BIO *b, char *out, int outl)
340 while (zin->avail_in) { 340 while (zin->avail_in) {
341 ret = inflate(zin, 0); 341 ret = inflate(zin, 0);
342 if ((ret != Z_OK) && (ret != Z_STREAM_END)) { 342 if ((ret != Z_OK) && (ret != Z_STREAM_END)) {
343 COMPerr(COMP_F_BIO_ZLIB_READ, 343 COMPerror(COMP_R_ZLIB_INFLATE_ERROR);
344 COMP_R_ZLIB_INFLATE_ERROR);
345 ERR_asprintf_error_data("zlib error:%s", 344 ERR_asprintf_error_data("zlib error:%s",
346 zError(ret)); 345 zError(ret));
347 return 0; 346 return 0;
@@ -386,7 +385,7 @@ bio_zlib_write(BIO *b, const char *in, int inl)
386 ctx->obuf = malloc(ctx->obufsize); 385 ctx->obuf = malloc(ctx->obufsize);
387 /* Need error here */ 386 /* Need error here */
388 if (!ctx->obuf) { 387 if (!ctx->obuf) {
389 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE); 388 COMPerror(ERR_R_MALLOC_FAILURE);
390 return 0; 389 return 0;
391 } 390 }
392 ctx->optr = ctx->obuf; 391 ctx->optr = ctx->obuf;
@@ -427,8 +426,7 @@ bio_zlib_write(BIO *b, const char *in, int inl)
427 /* Compress some more */ 426 /* Compress some more */
428 ret = deflate(zout, 0); 427 ret = deflate(zout, 0);
429 if (ret != Z_OK) { 428 if (ret != Z_OK) {
430 COMPerr(COMP_F_BIO_ZLIB_WRITE, 429 COMPerror(COMP_R_ZLIB_DEFLATE_ERROR);
431 COMP_R_ZLIB_DEFLATE_ERROR);
432 ERR_asprintf_error_data("zlib error:%s", zError(ret)); 430 ERR_asprintf_error_data("zlib error:%s", zError(ret));
433 return 0; 431 return 0;
434 } 432 }
@@ -477,8 +475,7 @@ bio_zlib_flush(BIO *b)
477 if (ret == Z_STREAM_END) 475 if (ret == Z_STREAM_END)
478 ctx->odone = 1; 476 ctx->odone = 1;
479 else if (ret != Z_OK) { 477 else if (ret != Z_OK) {
480 COMPerr(COMP_F_BIO_ZLIB_FLUSH, 478 COMPerror(COMP_R_ZLIB_DEFLATE_ERROR);
481 COMP_R_ZLIB_DEFLATE_ERROR);
482 ERR_asprintf_error_data("zlib error:%s", zError(ret)); 479 ERR_asprintf_error_data("zlib error:%s", zError(ret));
483 return 0; 480 return 0;
484 } 481 }
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
index 3f796d4069..be8a8fc708 100644
--- a/src/lib/libcrypto/comp/comp_err.c
+++ b/src/lib/libcrypto/comp/comp_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: comp_err.c,v 1.9 2014/11/03 16:58:28 tedu Exp $ */ 1/* $OpenBSD: comp_err.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -67,10 +67,7 @@
67#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason) 67#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason)
68 68
69static ERR_STRING_DATA COMP_str_functs[] = { 69static ERR_STRING_DATA COMP_str_functs[] = {
70 {ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"}, 70 {ERR_FUNC(0xfff), "CRYPTO_internal"},
71 {ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"},
72 {ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"},
73 {ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"},
74 {0, NULL} 71 {0, NULL}
75}; 72};
76 73
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
index e11ef95e43..4099ffc66c 100644
--- a/src/lib/libcrypto/conf/conf_def.c
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_def.c,v 1.31 2015/07/18 22:42:09 beck Exp $ */ 1/* $OpenBSD: conf_def.c,v 1.32 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -195,9 +195,9 @@ def_load(CONF *conf, const char *name, long *line)
195 in = BIO_new_file(name, "rb"); 195 in = BIO_new_file(name, "rb");
196 if (in == NULL) { 196 if (in == NULL) {
197 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) 197 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
198 CONFerr(CONF_F_DEF_LOAD, CONF_R_NO_SUCH_FILE); 198 CONFerror(CONF_R_NO_SUCH_FILE);
199 else 199 else
200 CONFerr(CONF_F_DEF_LOAD, ERR_R_SYS_LIB); 200 CONFerror(ERR_R_SYS_LIB);
201 return 0; 201 return 0;
202 } 202 }
203 203
@@ -224,25 +224,24 @@ def_load_bio(CONF *conf, BIO *in, long *line)
224 void *h = (void *)(conf->data); 224 void *h = (void *)(conf->data);
225 225
226 if ((buff = BUF_MEM_new()) == NULL) { 226 if ((buff = BUF_MEM_new()) == NULL) {
227 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB); 227 CONFerror(ERR_R_BUF_LIB);
228 goto err; 228 goto err;
229 } 229 }
230 230
231 section = strdup("default"); 231 section = strdup("default");
232 if (section == NULL) { 232 if (section == NULL) {
233 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); 233 CONFerror(ERR_R_MALLOC_FAILURE);
234 goto err; 234 goto err;
235 } 235 }
236 236
237 if (_CONF_new_data(conf) == 0) { 237 if (_CONF_new_data(conf) == 0) {
238 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); 238 CONFerror(ERR_R_MALLOC_FAILURE);
239 goto err; 239 goto err;
240 } 240 }
241 241
242 sv = _CONF_new_section(conf, section); 242 sv = _CONF_new_section(conf, section);
243 if (sv == NULL) { 243 if (sv == NULL) {
244 CONFerr(CONF_F_DEF_LOAD_BIO, 244 CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
245 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
246 goto err; 245 goto err;
247 } 246 }
248 247
@@ -250,7 +249,7 @@ def_load_bio(CONF *conf, BIO *in, long *line)
250 again = 0; 249 again = 0;
251 for (;;) { 250 for (;;) {
252 if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) { 251 if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {
253 CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB); 252 CONFerror(ERR_R_BUF_LIB);
254 goto err; 253 goto err;
255 } 254 }
256 p = &(buff->data[bufnum]); 255 p = &(buff->data[bufnum]);
@@ -316,8 +315,7 @@ again:
316 ss = p; 315 ss = p;
317 goto again; 316 goto again;
318 } 317 }
319 CONFerr(CONF_F_DEF_LOAD_BIO, 318 CONFerror(CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
320 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
321 goto err; 319 goto err;
322 } 320 }
323 *end = '\0'; 321 *end = '\0';
@@ -326,8 +324,7 @@ again:
326 if ((sv = _CONF_get_section(conf, section)) == NULL) 324 if ((sv = _CONF_get_section(conf, section)) == NULL)
327 sv = _CONF_new_section(conf, section); 325 sv = _CONF_new_section(conf, section);
328 if (sv == NULL) { 326 if (sv == NULL) {
329 CONFerr(CONF_F_DEF_LOAD_BIO, 327 CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
330 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
331 goto err; 328 goto err;
332 } 329 }
333 continue; 330 continue;
@@ -344,8 +341,7 @@ again:
344 } 341 }
345 p = eat_ws(conf, end); 342 p = eat_ws(conf, end);
346 if (*p != '=') { 343 if (*p != '=') {
347 CONFerr(CONF_F_DEF_LOAD_BIO, 344 CONFerror(CONF_R_MISSING_EQUAL_SIGN);
348 CONF_R_MISSING_EQUAL_SIGN);
349 goto err; 345 goto err;
350 } 346 }
351 *end = '\0'; 347 *end = '\0';
@@ -360,8 +356,7 @@ again:
360 *p = '\0'; 356 *p = '\0';
361 357
362 if (!(v = malloc(sizeof(CONF_VALUE)))) { 358 if (!(v = malloc(sizeof(CONF_VALUE)))) {
363 CONFerr(CONF_F_DEF_LOAD_BIO, 359 CONFerror(ERR_R_MALLOC_FAILURE);
364 ERR_R_MALLOC_FAILURE);
365 goto err; 360 goto err;
366 } 361 }
367 if (psection == NULL) 362 if (psection == NULL)
@@ -369,8 +364,7 @@ again:
369 v->name = strdup(pname); 364 v->name = strdup(pname);
370 v->value = NULL; 365 v->value = NULL;
371 if (v->name == NULL) { 366 if (v->name == NULL) {
372 CONFerr(CONF_F_DEF_LOAD_BIO, 367 CONFerror(ERR_R_MALLOC_FAILURE);
373 ERR_R_MALLOC_FAILURE);
374 goto err; 368 goto err;
375 } 369 }
376 if (!str_copy(conf, psection, &(v->value), start)) 370 if (!str_copy(conf, psection, &(v->value), start))
@@ -381,16 +375,14 @@ again:
381 == NULL) 375 == NULL)
382 tv = _CONF_new_section(conf, psection); 376 tv = _CONF_new_section(conf, psection);
383 if (tv == NULL) { 377 if (tv == NULL) {
384 CONFerr(CONF_F_DEF_LOAD_BIO, 378 CONFerror(CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
385 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
386 goto err; 379 goto err;
387 } 380 }
388 } else 381 } else
389 tv = sv; 382 tv = sv;
390 383
391 if (_CONF_add_string(conf, tv, v) == 0) { 384 if (_CONF_add_string(conf, tv, v) == 0) {
392 CONFerr(CONF_F_DEF_LOAD_BIO, 385 CONFerror(ERR_R_MALLOC_FAILURE);
393 ERR_R_MALLOC_FAILURE);
394 goto err; 386 goto err;
395 } 387 }
396 v = NULL; 388 v = NULL;
@@ -549,8 +541,7 @@ str_copy(CONF *conf, char *section, char **pto, char *from)
549 rp = e; 541 rp = e;
550 if (q) { 542 if (q) {
551 if (r != q) { 543 if (r != q) {
552 CONFerr(CONF_F_STR_COPY, 544 CONFerror(CONF_R_NO_CLOSE_BRACE);
553 CONF_R_NO_CLOSE_BRACE);
554 goto err; 545 goto err;
555 } 546 }
556 e++; 547 e++;
@@ -569,14 +560,12 @@ str_copy(CONF *conf, char *section, char **pto, char *from)
569 *rrp = rr; 560 *rrp = rr;
570 *rp = r; 561 *rp = r;
571 if (p == NULL) { 562 if (p == NULL) {
572 CONFerr(CONF_F_STR_COPY, 563 CONFerror(CONF_R_VARIABLE_HAS_NO_VALUE);
573 CONF_R_VARIABLE_HAS_NO_VALUE);
574 goto err; 564 goto err;
575 } 565 }
576 if (!BUF_MEM_grow_clean(buf, 566 if (!BUF_MEM_grow_clean(buf,
577 (strlen(p) + buf->length - (e - from)))) { 567 (strlen(p) + buf->length - (e - from)))) {
578 CONFerr(CONF_F_STR_COPY, 568 CONFerror(CONF_R_MODULE_INITIALIZATION_ERROR);
579 CONF_R_MODULE_INITIALIZATION_ERROR);
580 goto err; 569 goto err;
581 } 570 }
582 while (*p) 571 while (*p)
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
index a1a7cbe42e..dbb373ae85 100644
--- a/src/lib/libcrypto/conf/conf_err.c
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_err.c,v 1.12 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: conf_err.c,v 1.13 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,28 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CONF,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CONF,0,reason)
73 73
74static ERR_STRING_DATA CONF_str_functs[]= { 74static ERR_STRING_DATA CONF_str_functs[]= {
75 {ERR_FUNC(CONF_F_CONF_DUMP_FP), "CONF_dump_fp"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(CONF_F_CONF_LOAD), "CONF_load"},
77 {ERR_FUNC(CONF_F_CONF_LOAD_BIO), "CONF_load_bio"},
78 {ERR_FUNC(CONF_F_CONF_LOAD_FP), "CONF_load_fp"},
79 {ERR_FUNC(CONF_F_CONF_MODULES_LOAD), "CONF_modules_load"},
80 {ERR_FUNC(CONF_F_CONF_PARSE_LIST), "CONF_parse_list"},
81 {ERR_FUNC(CONF_F_DEF_LOAD), "DEF_LOAD"},
82 {ERR_FUNC(CONF_F_DEF_LOAD_BIO), "DEF_LOAD_BIO"},
83 {ERR_FUNC(CONF_F_MODULE_INIT), "MODULE_INIT"},
84 {ERR_FUNC(CONF_F_MODULE_LOAD_DSO), "MODULE_LOAD_DSO"},
85 {ERR_FUNC(CONF_F_MODULE_RUN), "MODULE_RUN"},
86 {ERR_FUNC(CONF_F_NCONF_DUMP_BIO), "NCONF_dump_bio"},
87 {ERR_FUNC(CONF_F_NCONF_DUMP_FP), "NCONF_dump_fp"},
88 {ERR_FUNC(CONF_F_NCONF_GET_NUMBER), "NCONF_get_number"},
89 {ERR_FUNC(CONF_F_NCONF_GET_NUMBER_E), "NCONF_get_number_e"},
90 {ERR_FUNC(CONF_F_NCONF_GET_SECTION), "NCONF_get_section"},
91 {ERR_FUNC(CONF_F_NCONF_GET_STRING), "NCONF_get_string"},
92 {ERR_FUNC(CONF_F_NCONF_LOAD), "NCONF_load"},
93 {ERR_FUNC(CONF_F_NCONF_LOAD_BIO), "NCONF_load_bio"},
94 {ERR_FUNC(CONF_F_NCONF_LOAD_FP), "NCONF_load_fp"},
95 {ERR_FUNC(CONF_F_NCONF_NEW), "NCONF_new"},
96 {ERR_FUNC(CONF_F_STR_COPY), "STR_COPY"},
97 {0, NULL} 76 {0, NULL}
98}; 77};
99 78
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
index c7e026e725..995ba3ef67 100644
--- a/src/lib/libcrypto/conf/conf_lib.c
+++ b/src/lib/libcrypto/conf/conf_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_lib.c,v 1.14 2016/08/05 17:25:51 deraadt Exp $ */ 1/* $OpenBSD: conf_lib.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -94,7 +94,7 @@ LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
94 94
95 in = BIO_new_file(file, "rb"); 95 in = BIO_new_file(file, "rb");
96 if (in == NULL) { 96 if (in == NULL) {
97 CONFerr(CONF_F_CONF_LOAD, ERR_R_SYS_LIB); 97 CONFerror(ERR_R_SYS_LIB);
98 return NULL; 98 return NULL;
99 } 99 }
100 100
@@ -111,7 +111,7 @@ LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
111 LHASH_OF(CONF_VALUE) *ltmp; 111 LHASH_OF(CONF_VALUE) *ltmp;
112 112
113 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { 113 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
114 CONFerr(CONF_F_CONF_LOAD_FP, ERR_R_BUF_LIB); 114 CONFerror(ERR_R_BUF_LIB);
115 return NULL; 115 return NULL;
116 } 116 }
117 ltmp = CONF_load_bio(conf, btmp, eline); 117 ltmp = CONF_load_bio(conf, btmp, eline);
@@ -196,7 +196,7 @@ CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out)
196 int ret; 196 int ret;
197 197
198 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { 198 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
199 CONFerr(CONF_F_CONF_DUMP_FP, ERR_R_BUF_LIB); 199 CONFerror(ERR_R_BUF_LIB);
200 return 0; 200 return 0;
201 } 201 }
202 ret = CONF_dump_bio(conf, btmp); 202 ret = CONF_dump_bio(conf, btmp);
@@ -229,7 +229,7 @@ NCONF_new(CONF_METHOD *meth)
229 229
230 ret = meth->create(meth); 230 ret = meth->create(meth);
231 if (ret == NULL) { 231 if (ret == NULL) {
232 CONFerr(CONF_F_NCONF_NEW, ERR_R_MALLOC_FAILURE); 232 CONFerror(ERR_R_MALLOC_FAILURE);
233 return (NULL); 233 return (NULL);
234 } 234 }
235 235
@@ -256,7 +256,7 @@ int
256NCONF_load(CONF *conf, const char *file, long *eline) 256NCONF_load(CONF *conf, const char *file, long *eline)
257{ 257{
258 if (conf == NULL) { 258 if (conf == NULL) {
259 CONFerr(CONF_F_NCONF_LOAD, CONF_R_NO_CONF); 259 CONFerror(CONF_R_NO_CONF);
260 return 0; 260 return 0;
261 } 261 }
262 262
@@ -270,7 +270,7 @@ NCONF_load_fp(CONF *conf, FILE *fp, long *eline)
270 int ret; 270 int ret;
271 271
272 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { 272 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
273 CONFerr(CONF_F_NCONF_LOAD_FP, ERR_R_BUF_LIB); 273 CONFerror(ERR_R_BUF_LIB);
274 return 0; 274 return 0;
275 } 275 }
276 ret = NCONF_load_bio(conf, btmp, eline); 276 ret = NCONF_load_bio(conf, btmp, eline);
@@ -282,7 +282,7 @@ int
282NCONF_load_bio(CONF *conf, BIO *bp, long *eline) 282NCONF_load_bio(CONF *conf, BIO *bp, long *eline)
283{ 283{
284 if (conf == NULL) { 284 if (conf == NULL) {
285 CONFerr(CONF_F_NCONF_LOAD_BIO, CONF_R_NO_CONF); 285 CONFerror(CONF_R_NO_CONF);
286 return 0; 286 return 0;
287 } 287 }
288 288
@@ -293,12 +293,12 @@ STACK_OF(CONF_VALUE) *
293NCONF_get_section(const CONF *conf, const char *section) 293NCONF_get_section(const CONF *conf, const char *section)
294{ 294{
295 if (conf == NULL) { 295 if (conf == NULL) {
296 CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_CONF); 296 CONFerror(CONF_R_NO_CONF);
297 return NULL; 297 return NULL;
298 } 298 }
299 299
300 if (section == NULL) { 300 if (section == NULL) {
301 CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_SECTION); 301 CONFerror(CONF_R_NO_SECTION);
302 return NULL; 302 return NULL;
303 } 303 }
304 304
@@ -316,11 +316,10 @@ NCONF_get_string(const CONF *conf, const char *group, const char *name)
316 return s; 316 return s;
317 317
318 if (conf == NULL) { 318 if (conf == NULL) {
319 CONFerr(CONF_F_NCONF_GET_STRING, 319 CONFerror(CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
320 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
321 return NULL; 320 return NULL;
322 } 321 }
323 CONFerr(CONF_F_NCONF_GET_STRING, CONF_R_NO_VALUE); 322 CONFerror(CONF_R_NO_VALUE);
324 ERR_asprintf_error_data("group=%s name=%s", 323 ERR_asprintf_error_data("group=%s name=%s",
325 group ? group : "", name); 324 group ? group : "", name);
326 return NULL; 325 return NULL;
@@ -333,7 +332,7 @@ NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
333 char *str; 332 char *str;
334 333
335 if (result == NULL) { 334 if (result == NULL) {
336 CONFerr(CONF_F_NCONF_GET_NUMBER_E, ERR_R_PASSED_NULL_PARAMETER); 335 CONFerror(ERR_R_PASSED_NULL_PARAMETER);
337 return 0; 336 return 0;
338 } 337 }
339 338
@@ -356,7 +355,7 @@ NCONF_dump_fp(const CONF *conf, FILE *out)
356 BIO *btmp; 355 BIO *btmp;
357 int ret; 356 int ret;
358 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { 357 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
359 CONFerr(CONF_F_NCONF_DUMP_FP, ERR_R_BUF_LIB); 358 CONFerror(ERR_R_BUF_LIB);
360 return 0; 359 return 0;
361 } 360 }
362 ret = NCONF_dump_bio(conf, btmp); 361 ret = NCONF_dump_bio(conf, btmp);
@@ -368,7 +367,7 @@ int
368NCONF_dump_bio(const CONF *conf, BIO *out) 367NCONF_dump_bio(const CONF *conf, BIO *out)
369{ 368{
370 if (conf == NULL) { 369 if (conf == NULL) {
371 CONFerr(CONF_F_NCONF_DUMP_BIO, CONF_R_NO_CONF); 370 CONFerror(CONF_R_NO_CONF);
372 return 0; 371 return 0;
373 } 372 }
374 373
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
index cb54cc2a87..9f252385e8 100644
--- a/src/lib/libcrypto/conf/conf_mod.c
+++ b/src/lib/libcrypto/conf/conf_mod.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_mod.c,v 1.26 2015/04/11 16:03:21 deraadt Exp $ */ 1/* $OpenBSD: conf_mod.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -211,7 +211,7 @@ module_run(const CONF *cnf, char *name, char *value, unsigned long flags)
211 211
212 if (!md) { 212 if (!md) {
213 if (!(flags & CONF_MFLAGS_SILENT)) { 213 if (!(flags & CONF_MFLAGS_SILENT)) {
214 CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME); 214 CONFerror(CONF_R_UNKNOWN_MODULE_NAME);
215 ERR_asprintf_error_data("module=%s", name); 215 ERR_asprintf_error_data("module=%s", name);
216 } 216 }
217 return -1; 217 return -1;
@@ -221,8 +221,7 @@ module_run(const CONF *cnf, char *name, char *value, unsigned long flags)
221 221
222 if (ret <= 0) { 222 if (ret <= 0) {
223 if (!(flags & CONF_MFLAGS_SILENT)) { 223 if (!(flags & CONF_MFLAGS_SILENT)) {
224 CONFerr(CONF_F_MODULE_RUN, 224 CONFerror(CONF_R_MODULE_INITIALIZATION_ERROR);
225 CONF_R_MODULE_INITIALIZATION_ERROR);
226 ERR_asprintf_error_data 225 ERR_asprintf_error_data
227 ("module=%s, value=%s, retcode=%-8d", 226 ("module=%s, value=%s, retcode=%-8d",
228 name, value, ret); 227 name, value, ret);
@@ -271,7 +270,7 @@ module_load_dso(const CONF *cnf, char *name, char *value, unsigned long flags)
271err: 270err:
272 if (dso) 271 if (dso)
273 DSO_free(dso); 272 DSO_free(dso);
274 CONFerr(CONF_F_MODULE_LOAD_DSO, errcode); 273 CONFerror(errcode);
275 ERR_asprintf_error_data("module=%s, path=%s", name, path); 274 ERR_asprintf_error_data("module=%s, path=%s", name, path);
276 return NULL; 275 return NULL;
277} 276}
@@ -368,13 +367,13 @@ module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf)
368 if (initialized_modules == NULL) { 367 if (initialized_modules == NULL) {
369 initialized_modules = sk_CONF_IMODULE_new_null(); 368 initialized_modules = sk_CONF_IMODULE_new_null();
370 if (!initialized_modules) { 369 if (!initialized_modules) {
371 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); 370 CONFerror(ERR_R_MALLOC_FAILURE);
372 goto err; 371 goto err;
373 } 372 }
374 } 373 }
375 374
376 if (!sk_CONF_IMODULE_push(initialized_modules, imod)) { 375 if (!sk_CONF_IMODULE_push(initialized_modules, imod)) {
377 CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); 376 CONFerror(ERR_R_MALLOC_FAILURE);
378 goto err; 377 goto err;
379 } 378 }
380 379
@@ -566,7 +565,7 @@ CONF_parse_list(const char *list_, int sep, int nospc,
566 const char *lstart, *tmpend, *p; 565 const char *lstart, *tmpend, *p;
567 566
568 if (list_ == NULL) { 567 if (list_ == NULL) {
569 CONFerr(CONF_F_CONF_PARSE_LIST, CONF_R_LIST_CANNOT_BE_NULL); 568 CONFerror(CONF_R_LIST_CANNOT_BE_NULL);
570 return 0; 569 return 0;
571 } 570 }
572 571
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index 8dec9caa93..1bc245ed0a 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cryptlib.c,v 1.39 2016/11/04 17:30:30 miod Exp $ */ 1/* $OpenBSD: cryptlib.c,v 1.40 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -210,11 +210,11 @@ CRYPTO_get_new_lockid(char *name)
210 210
211 if ((app_locks == NULL) && 211 if ((app_locks == NULL) &&
212 ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) { 212 ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) {
213 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); 213 CRYPTOerror(ERR_R_MALLOC_FAILURE);
214 return (0); 214 return (0);
215 } 215 }
216 if (name == NULL || (str = strdup(name)) == NULL) { 216 if (name == NULL || (str = strdup(name)) == NULL) {
217 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); 217 CRYPTOerror(ERR_R_MALLOC_FAILURE);
218 return (0); 218 return (0);
219 } 219 }
220 i = sk_OPENSSL_STRING_push(app_locks, str); 220 i = sk_OPENSSL_STRING_push(app_locks, str);
@@ -238,32 +238,28 @@ CRYPTO_get_new_dynlockid(void)
238 CRYPTO_dynlock *pointer = NULL; 238 CRYPTO_dynlock *pointer = NULL;
239 239
240 if (dynlock_create_callback == NULL) { 240 if (dynlock_create_callback == NULL) {
241 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, 241 CRYPTOerror(CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
242 CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK);
243 return (0); 242 return (0);
244 } 243 }
245 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); 244 CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK);
246 if ((dyn_locks == NULL) && 245 if ((dyn_locks == NULL) &&
247 ((dyn_locks = sk_CRYPTO_dynlock_new_null()) == NULL)) { 246 ((dyn_locks = sk_CRYPTO_dynlock_new_null()) == NULL)) {
248 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); 247 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
249 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, 248 CRYPTOerror(ERR_R_MALLOC_FAILURE);
250 ERR_R_MALLOC_FAILURE);
251 return (0); 249 return (0);
252 } 250 }
253 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); 251 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
254 252
255 pointer = malloc(sizeof(CRYPTO_dynlock)); 253 pointer = malloc(sizeof(CRYPTO_dynlock));
256 if (pointer == NULL) { 254 if (pointer == NULL) {
257 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, 255 CRYPTOerror(ERR_R_MALLOC_FAILURE);
258 ERR_R_MALLOC_FAILURE);
259 return (0); 256 return (0);
260 } 257 }
261 pointer->references = 1; 258 pointer->references = 1;
262 pointer->data = dynlock_create_callback(__FILE__, __LINE__); 259 pointer->data = dynlock_create_callback(__FILE__, __LINE__);
263 if (pointer->data == NULL) { 260 if (pointer->data == NULL) {
264 free(pointer); 261 free(pointer);
265 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, 262 CRYPTOerror(ERR_R_MALLOC_FAILURE);
266 ERR_R_MALLOC_FAILURE);
267 return (0); 263 return (0);
268 } 264 }
269 265
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 24c8bb25ec..0402092a4f 100644
--- a/src/lib/libcrypto/dh/dh_ameth.c
+++ b/src/lib/libcrypto/dh/dh_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_ameth.c,v 1.13 2015/01/08 01:44:29 doug Exp $ */ 1/* $OpenBSD: dh_ameth.c,v 1.14 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -89,7 +89,7 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
89 X509_ALGOR_get0(NULL, &ptype, &pval, palg); 89 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
90 90
91 if (ptype != V_ASN1_SEQUENCE) { 91 if (ptype != V_ASN1_SEQUENCE) {
92 DHerr(DH_F_DH_PUB_DECODE, DH_R_PARAMETER_ENCODING_ERROR); 92 DHerror(DH_R_PARAMETER_ENCODING_ERROR);
93 goto err; 93 goto err;
94 } 94 }
95 95
@@ -98,18 +98,18 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
98 pmlen = pstr->length; 98 pmlen = pstr->length;
99 99
100 if (!(dh = d2i_DHparams(NULL, &pm, pmlen))) { 100 if (!(dh = d2i_DHparams(NULL, &pm, pmlen))) {
101 DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); 101 DHerror(DH_R_DECODE_ERROR);
102 goto err; 102 goto err;
103 } 103 }
104 104
105 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) { 105 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) {
106 DHerr(DH_F_DH_PUB_DECODE, DH_R_DECODE_ERROR); 106 DHerror(DH_R_DECODE_ERROR);
107 goto err; 107 goto err;
108 } 108 }
109 109
110 /* We have parameters now set public key */ 110 /* We have parameters now set public key */
111 if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { 111 if (!(dh->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) {
112 DHerr(DH_F_DH_PUB_DECODE, DH_R_BN_DECODE_ERROR); 112 DHerror(DH_R_BN_DECODE_ERROR);
113 goto err; 113 goto err;
114 } 114 }
115 115
@@ -138,13 +138,13 @@ dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
138 138
139 str = ASN1_STRING_new(); 139 str = ASN1_STRING_new();
140 if (str == NULL) { 140 if (str == NULL) {
141 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 141 DHerror(ERR_R_MALLOC_FAILURE);
142 goto err; 142 goto err;
143 } 143 }
144 144
145 str->length = i2d_DHparams(dh, &str->data); 145 str->length = i2d_DHparams(dh, &str->data);
146 if (str->length <= 0) { 146 if (str->length <= 0) {
147 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 147 DHerror(ERR_R_MALLOC_FAILURE);
148 goto err; 148 goto err;
149 } 149 }
150 ptype = V_ASN1_SEQUENCE; 150 ptype = V_ASN1_SEQUENCE;
@@ -158,7 +158,7 @@ dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
158 ASN1_INTEGER_free(pub_key); 158 ASN1_INTEGER_free(pub_key);
159 159
160 if (penclen <= 0) { 160 if (penclen <= 0) {
161 DHerr(DH_F_DH_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 161 DHerror(ERR_R_MALLOC_FAILURE);
162 goto err; 162 goto err;
163 } 163 }
164 164
@@ -209,7 +209,7 @@ dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
209 goto decerr; 209 goto decerr;
210 /* We have parameters now set private key */ 210 /* We have parameters now set private key */
211 if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { 211 if (!(dh->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
212 DHerr(DH_F_DH_PRIV_DECODE, DH_R_BN_ERROR); 212 DHerror(DH_R_BN_ERROR);
213 goto dherr; 213 goto dherr;
214 } 214 }
215 /* Calculate public key */ 215 /* Calculate public key */
@@ -223,7 +223,7 @@ dh_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
223 return 1; 223 return 1;
224 224
225decerr: 225decerr:
226 DHerr(DH_F_DH_PRIV_DECODE, EVP_R_DECODE_ERROR); 226 DHerror(EVP_R_DECODE_ERROR);
227dherr: 227dherr:
228 DH_free(dh); 228 DH_free(dh);
229 return 0; 229 return 0;
@@ -240,13 +240,13 @@ dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
240 params = ASN1_STRING_new(); 240 params = ASN1_STRING_new();
241 241
242 if (!params) { 242 if (!params) {
243 DHerr(DH_F_DH_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 243 DHerror(ERR_R_MALLOC_FAILURE);
244 goto err; 244 goto err;
245 } 245 }
246 246
247 params->length = i2d_DHparams(pkey->pkey.dh, &params->data); 247 params->length = i2d_DHparams(pkey->pkey.dh, &params->data);
248 if (params->length <= 0) { 248 if (params->length <= 0) {
249 DHerr(DH_F_DH_PRIV_ENCODE,ERR_R_MALLOC_FAILURE); 249 DHerror(ERR_R_MALLOC_FAILURE);
250 goto err; 250 goto err;
251 } 251 }
252 params->type = V_ASN1_SEQUENCE; 252 params->type = V_ASN1_SEQUENCE;
@@ -255,7 +255,7 @@ dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
255 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dh->priv_key, NULL); 255 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dh->priv_key, NULL);
256 256
257 if (!prkey) { 257 if (!prkey) {
258 DHerr(DH_F_DH_PRIV_ENCODE, DH_R_BN_ERROR); 258 DHerror(DH_R_BN_ERROR);
259 goto err; 259 goto err;
260 } 260 }
261 261
@@ -294,7 +294,7 @@ dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
294 DH *dh; 294 DH *dh;
295 295
296 if (!(dh = d2i_DHparams(NULL, pder, derlen))) { 296 if (!(dh = d2i_DHparams(NULL, pder, derlen))) {
297 DHerr(DH_F_DH_PARAM_DECODE, ERR_R_DH_LIB); 297 DHerror(ERR_R_DH_LIB);
298 return 0; 298 return 0;
299 } 299 }
300 EVP_PKEY_assign_DH(pkey, dh); 300 EVP_PKEY_assign_DH(pkey, dh);
@@ -374,7 +374,7 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
374 ret = 1; 374 ret = 1;
375 if (0) { 375 if (0) {
376err: 376err:
377 DHerr(DH_F_DO_DH_PRINT,reason); 377 DHerror(reason);
378 } 378 }
379 free(m); 379 free(m);
380 return(ret); 380 return(ret);
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
index 3774ba3c45..497f88436e 100644
--- a/src/lib/libcrypto/dh/dh_err.c
+++ b/src/lib/libcrypto/dh/dh_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_err.c,v 1.15 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: dh_err.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -71,27 +71,10 @@
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DH,func,0) 71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DH,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DH,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DH,0,reason)
73 73
74static ERR_STRING_DATA DH_str_functs[]= 74static ERR_STRING_DATA DH_str_functs[]= {
75 { 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76{ERR_FUNC(DH_F_COMPUTE_KEY), "COMPUTE_KEY"}, 76 {0, NULL}
77{ERR_FUNC(DH_F_DHPARAMS_PRINT_FP), "DHparams_print_fp"}, 77};
78{ERR_FUNC(DH_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"},
79{ERR_FUNC(DH_F_DH_COMPUTE_KEY), "DH_compute_key"},
80{ERR_FUNC(DH_F_DH_GENERATE_KEY), "DH_generate_key"},
81{ERR_FUNC(DH_F_DH_GENERATE_PARAMETERS_EX), "DH_generate_parameters_ex"},
82{ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"},
83{ERR_FUNC(DH_F_DH_PARAM_DECODE), "DH_PARAM_DECODE"},
84{ERR_FUNC(DH_F_DH_PRIV_DECODE), "DH_PRIV_DECODE"},
85{ERR_FUNC(DH_F_DH_PRIV_ENCODE), "DH_PRIV_ENCODE"},
86{ERR_FUNC(DH_F_DH_PUB_DECODE), "DH_PUB_DECODE"},
87{ERR_FUNC(DH_F_DH_PUB_ENCODE), "DH_PUB_ENCODE"},
88{ERR_FUNC(DH_F_DO_DH_PRINT), "DO_DH_PRINT"},
89{ERR_FUNC(DH_F_GENERATE_KEY), "GENERATE_KEY"},
90{ERR_FUNC(DH_F_GENERATE_PARAMETERS), "GENERATE_PARAMETERS"},
91{ERR_FUNC(DH_F_PKEY_DH_DERIVE), "PKEY_DH_DERIVE"},
92{ERR_FUNC(DH_F_PKEY_DH_KEYGEN), "PKEY_DH_KEYGEN"},
93{0,NULL}
94 };
95 78
96static ERR_STRING_DATA DH_str_reasons[]= 79static ERR_STRING_DATA DH_str_reasons[]=
97 { 80 {
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
index de566802d3..99394113ee 100644
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ b/src/lib/libcrypto/dh/dh_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_gen.c,v 1.15 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: dh_gen.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -127,7 +127,7 @@ dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
127 goto err; 127 goto err;
128 128
129 if (generator <= 1) { 129 if (generator <= 1) {
130 DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR); 130 DHerror(DH_R_BAD_GENERATOR);
131 goto err; 131 goto err;
132 } 132 }
133 if (generator == DH_GENERATOR_2) { 133 if (generator == DH_GENERATOR_2) {
@@ -167,7 +167,7 @@ dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
167 ok = 1; 167 ok = 1;
168err: 168err:
169 if (ok == -1) { 169 if (ok == -1) {
170 DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB); 170 DHerror(ERR_R_BN_LIB);
171 ok = 0; 171 ok = 0;
172 } 172 }
173 173
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index 5b365cdd06..63d38771c3 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_key.c,v 1.26 2017/01/21 09:38:58 beck Exp $ */ 1/* $OpenBSD: dh_key.c,v 1.27 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -165,7 +165,7 @@ generate_key(DH *dh)
165 ok = 1; 165 ok = 1;
166err: 166err:
167 if (ok != 1) 167 if (ok != 1)
168 DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB); 168 DHerror(ERR_R_BN_LIB);
169 169
170 if (pub_key != NULL && dh->pub_key == NULL) 170 if (pub_key != NULL && dh->pub_key == NULL)
171 BN_free(pub_key); 171 BN_free(pub_key);
@@ -185,7 +185,7 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
185 int check_result; 185 int check_result;
186 186
187 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) { 187 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
188 DHerr(DH_F_COMPUTE_KEY, DH_R_MODULUS_TOO_LARGE); 188 DHerror(DH_R_MODULUS_TOO_LARGE);
189 goto err; 189 goto err;
190 } 190 }
191 191
@@ -197,7 +197,7 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
197 goto err; 197 goto err;
198 198
199 if (dh->priv_key == NULL) { 199 if (dh->priv_key == NULL) {
200 DHerr(DH_F_COMPUTE_KEY, DH_R_NO_PRIVATE_VALUE); 200 DHerror(DH_R_NO_PRIVATE_VALUE);
201 goto err; 201 goto err;
202 } 202 }
203 203
@@ -212,13 +212,13 @@ compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
212 } 212 }
213 213
214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) { 214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) {
215 DHerr(DH_F_COMPUTE_KEY, DH_R_INVALID_PUBKEY); 215 DHerror(DH_R_INVALID_PUBKEY);
216 goto err; 216 goto err;
217 } 217 }
218 218
219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx, 219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx,
220 mont)) { 220 mont)) {
221 DHerr(DH_F_COMPUTE_KEY, ERR_R_BN_LIB); 221 DHerror(ERR_R_BN_LIB);
222 goto err; 222 goto err;
223 } 223 }
224 224
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index defe1c74b4..d45dc17168 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_lib.c,v 1.21 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.22 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -121,7 +121,7 @@ DH_new_method(ENGINE *engine)
121 121
122 ret = malloc(sizeof(DH)); 122 ret = malloc(sizeof(DH));
123 if (ret == NULL) { 123 if (ret == NULL) {
124 DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE); 124 DHerror(ERR_R_MALLOC_FAILURE);
125 return NULL; 125 return NULL;
126 } 126 }
127 127
@@ -129,7 +129,7 @@ DH_new_method(ENGINE *engine)
129#ifndef OPENSSL_NO_ENGINE 129#ifndef OPENSSL_NO_ENGINE
130 if (engine) { 130 if (engine) {
131 if (!ENGINE_init(engine)) { 131 if (!ENGINE_init(engine)) {
132 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); 132 DHerror(ERR_R_ENGINE_LIB);
133 free(ret); 133 free(ret);
134 return NULL; 134 return NULL;
135 } 135 }
@@ -139,7 +139,7 @@ DH_new_method(ENGINE *engine)
139 if(ret->engine) { 139 if(ret->engine) {
140 ret->meth = ENGINE_get_DH(ret->engine); 140 ret->meth = ENGINE_get_DH(ret->engine);
141 if (!ret->meth) { 141 if (!ret->meth) {
142 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); 142 DHerror(ERR_R_ENGINE_LIB);
143 ENGINE_finish(ret->engine); 143 ENGINE_finish(ret->engine);
144 free(ret); 144 free(ret);
145 return NULL; 145 return NULL;
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c
index 6d750eb30d..24d16ff5d3 100644
--- a/src/lib/libcrypto/dh/dh_pmeth.c
+++ b/src/lib/libcrypto/dh/dh_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_pmeth.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dh_pmeth.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -215,7 +215,7 @@ pkey_dh_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
215 DH *dh = NULL; 215 DH *dh = NULL;
216 216
217 if (ctx->pkey == NULL) { 217 if (ctx->pkey == NULL) {
218 DHerr(DH_F_PKEY_DH_KEYGEN, DH_R_NO_PARAMETERS_SET); 218 DHerror(DH_R_NO_PARAMETERS_SET);
219 return 0; 219 return 0;
220 } 220 }
221 dh = DH_new(); 221 dh = DH_new();
@@ -234,7 +234,7 @@ pkey_dh_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
234 int ret; 234 int ret;
235 235
236 if (!ctx->pkey || !ctx->peerkey) { 236 if (!ctx->pkey || !ctx->peerkey) {
237 DHerr(DH_F_PKEY_DH_DERIVE, DH_R_KEYS_NOT_SET); 237 DHerror(DH_R_KEYS_NOT_SET);
238 return 0; 238 return 0;
239 } 239 }
240 ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key, 240 ret = DH_compute_key(key, ctx->peerkey->pkey.dh->pub_key,
diff --git a/src/lib/libcrypto/dh/dh_prn.c b/src/lib/libcrypto/dh/dh_prn.c
index 73d0476e21..56a96f8631 100644
--- a/src/lib/libcrypto/dh/dh_prn.c
+++ b/src/lib/libcrypto/dh/dh_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_prn.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dh_prn.c,v 1.6 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -69,7 +69,7 @@ DHparams_print_fp(FILE *fp, const DH *x)
69 int ret; 69 int ret;
70 70
71 if ((b = BIO_new(BIO_s_file())) == NULL) { 71 if ((b = BIO_new(BIO_s_file())) == NULL) {
72 DHerr(DH_F_DHPARAMS_PRINT_FP, ERR_R_BUF_LIB); 72 DHerror(ERR_R_BUF_LIB);
73 return 0; 73 return 0;
74 } 74 }
75 BIO_set_fp(b,fp,BIO_NOCLOSE); 75 BIO_set_fp(b,fp,BIO_NOCLOSE);
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c
index b589d39892..92f543de9e 100644
--- a/src/lib/libcrypto/dsa/dsa_ameth.c
+++ b/src/lib/libcrypto/dsa/dsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_ameth.c,v 1.22 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: dsa_ameth.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -92,26 +92,26 @@ dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
92 pmlen = pstr->length; 92 pmlen = pstr->length;
93 93
94 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) { 94 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) {
95 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR); 95 DSAerror(DSA_R_DECODE_ERROR);
96 goto err; 96 goto err;
97 } 97 }
98 } else if (ptype == V_ASN1_NULL || ptype == V_ASN1_UNDEF) { 98 } else if (ptype == V_ASN1_NULL || ptype == V_ASN1_UNDEF) {
99 if (!(dsa = DSA_new())) { 99 if (!(dsa = DSA_new())) {
100 DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE); 100 DSAerror(ERR_R_MALLOC_FAILURE);
101 goto err; 101 goto err;
102 } 102 }
103 } else { 103 } else {
104 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR); 104 DSAerror(DSA_R_PARAMETER_ENCODING_ERROR);
105 goto err; 105 goto err;
106 } 106 }
107 107
108 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) { 108 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) {
109 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR); 109 DSAerror(DSA_R_DECODE_ERROR);
110 goto err; 110 goto err;
111 } 111 }
112 112
113 if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) { 113 if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) {
114 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR); 114 DSAerror(DSA_R_BN_DECODE_ERROR);
115 goto err; 115 goto err;
116 } 116 }
117 117
@@ -141,12 +141,12 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
141 141
142 str = ASN1_STRING_new(); 142 str = ASN1_STRING_new();
143 if (str == NULL) { 143 if (str == NULL) {
144 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 144 DSAerror(ERR_R_MALLOC_FAILURE);
145 goto err; 145 goto err;
146 } 146 }
147 str->length = i2d_DSAparams(dsa, &str->data); 147 str->length = i2d_DSAparams(dsa, &str->data);
148 if (str->length <= 0) { 148 if (str->length <= 0) {
149 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 149 DSAerror(ERR_R_MALLOC_FAILURE);
150 ASN1_STRING_free(str); 150 ASN1_STRING_free(str);
151 goto err; 151 goto err;
152 } 152 }
@@ -160,7 +160,7 @@ dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
160 penclen = i2d_DSAPublicKey(dsa, &penc); 160 penclen = i2d_DSAPublicKey(dsa, &penc);
161 161
162 if (penclen <= 0) { 162 if (penclen <= 0) {
163 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE); 163 DSAerror(ERR_R_MALLOC_FAILURE);
164 goto err; 164 goto err;
165 } 165 }
166 166
@@ -211,21 +211,21 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
211 goto decerr; 211 goto decerr;
212 /* We have parameters now set private key */ 212 /* We have parameters now set private key */
213 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { 213 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
214 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); 214 DSAerror(DSA_R_BN_ERROR);
215 goto dsaerr; 215 goto dsaerr;
216 } 216 }
217 /* Calculate public key */ 217 /* Calculate public key */
218 if (!(dsa->pub_key = BN_new())) { 218 if (!(dsa->pub_key = BN_new())) {
219 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); 219 DSAerror(ERR_R_MALLOC_FAILURE);
220 goto dsaerr; 220 goto dsaerr;
221 } 221 }
222 if (!(ctx = BN_CTX_new())) { 222 if (!(ctx = BN_CTX_new())) {
223 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); 223 DSAerror(ERR_R_MALLOC_FAILURE);
224 goto dsaerr; 224 goto dsaerr;
225 } 225 }
226 226
227 if (!BN_mod_exp_ct(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { 227 if (!BN_mod_exp_ct(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {
228 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); 228 DSAerror(DSA_R_BN_ERROR);
229 goto dsaerr; 229 goto dsaerr;
230 } 230 }
231 231
@@ -236,7 +236,7 @@ dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
236 goto done; 236 goto done;
237 237
238decerr: 238decerr:
239 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR); 239 DSAerror(DSA_R_DECODE_ERROR);
240dsaerr: 240dsaerr:
241 DSA_free(dsa); 241 DSA_free(dsa);
242done: 242done:
@@ -255,13 +255,13 @@ dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
255 255
256 params = ASN1_STRING_new(); 256 params = ASN1_STRING_new();
257 if (!params) { 257 if (!params) {
258 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 258 DSAerror(ERR_R_MALLOC_FAILURE);
259 goto err; 259 goto err;
260 } 260 }
261 261
262 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data); 262 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
263 if (params->length <= 0) { 263 if (params->length <= 0) {
264 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 264 DSAerror(ERR_R_MALLOC_FAILURE);
265 goto err; 265 goto err;
266 } 266 }
267 params->type = V_ASN1_SEQUENCE; 267 params->type = V_ASN1_SEQUENCE;
@@ -269,7 +269,7 @@ dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
269 /* Get private key into integer */ 269 /* Get private key into integer */
270 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL); 270 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);
271 if (!prkey) { 271 if (!prkey) {
272 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_BN_ERROR); 272 DSAerror(DSA_R_BN_ERROR);
273 goto err; 273 goto err;
274 } 274 }
275 275
@@ -407,7 +407,7 @@ do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
407 407
408 m = malloc(buf_len + 10); 408 m = malloc(buf_len + 10);
409 if (m == NULL) { 409 if (m == NULL) {
410 DSAerr(DSA_F_DO_DSA_PRINT, ERR_R_MALLOC_FAILURE); 410 DSAerror(ERR_R_MALLOC_FAILURE);
411 goto err; 411 goto err;
412 } 412 }
413 413
@@ -441,7 +441,7 @@ dsa_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
441 DSA *dsa; 441 DSA *dsa;
442 442
443 if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) { 443 if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) {
444 DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB); 444 DSAerror(ERR_R_DSA_LIB);
445 return 0; 445 return 0;
446 } 446 }
447 EVP_PKEY_assign_DSA(pkey, dsa); 447 EVP_PKEY_assign_DSA(pkey, dsa);
@@ -480,7 +480,7 @@ old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
480 BIGNUM *j, *p1, *newp1; 480 BIGNUM *j, *p1, *newp1;
481 481
482 if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) { 482 if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) {
483 DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB); 483 DSAerror(ERR_R_DSA_LIB);
484 return 0; 484 return 0;
485 } 485 }
486 486
@@ -507,7 +507,7 @@ old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
507 if (BN_mul(newp1, dsa->q, j, ctx) == 0) 507 if (BN_mul(newp1, dsa->q, j, ctx) == 0)
508 goto err; 508 goto err;
509 if (BN_cmp(newp1, p1) != 0) { 509 if (BN_cmp(newp1, p1) != 0) {
510 DSAerr(DSA_F_DSA_PARAM_DECODE, DSA_R_BAD_Q_VALUE); 510 DSAerror(DSA_R_BAD_Q_VALUE);
511 goto err; 511 goto err;
512 } 512 }
513 513
@@ -516,7 +516,7 @@ old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
516 */ 516 */
517 517
518 if (BN_is_prime_ex(dsa->q, BN_prime_checks, ctx, NULL) == 0) { 518 if (BN_is_prime_ex(dsa->q, BN_prime_checks, ctx, NULL) == 0) {
519 DSAerr(DSA_F_DSA_PARAM_DECODE, DSA_R_BAD_Q_VALUE); 519 DSAerror(DSA_R_BAD_Q_VALUE);
520 goto err; 520 goto err;
521 } 521 }
522 522
@@ -561,7 +561,7 @@ dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig,
561 update_buflen(dsa_sig->s, &buf_len); 561 update_buflen(dsa_sig->s, &buf_len);
562 m = malloc(buf_len + 10); 562 m = malloc(buf_len + 10);
563 if (m == NULL) { 563 if (m == NULL) {
564 DSAerr(DSA_F_DSA_SIG_PRINT, ERR_R_MALLOC_FAILURE); 564 DSAerror(ERR_R_MALLOC_FAILURE);
565 goto err; 565 goto err;
566 } 566 }
567 567
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 5a1c7ceb71..d7b77470bd 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_asn1.c,v 1.18 2016/12/30 15:28:42 jsing Exp $ */ 1/* $OpenBSD: dsa_asn1.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -73,7 +73,7 @@ sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
73 73
74 sig = malloc(sizeof(DSA_SIG)); 74 sig = malloc(sizeof(DSA_SIG));
75 if (!sig) { 75 if (!sig) {
76 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE); 76 DSAerror(ERR_R_MALLOC_FAILURE);
77 return 0; 77 return 0;
78 } 78 }
79 sig->r = NULL; 79 sig->r = NULL;
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
index b116b643c3..2dcddcbf77 100644
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_err.c,v 1.14 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: dsa_err.c,v 1.15 2017/01/29 17:49:22 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -71,35 +71,10 @@
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSA,func,0) 71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSA,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSA,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSA,0,reason)
73 73
74static ERR_STRING_DATA DSA_str_functs[]= 74static ERR_STRING_DATA DSA_str_functs[]= {
75 { 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"}, 76 {0, NULL}
77{ERR_FUNC(DSA_F_DO_DSA_PRINT), "DO_DSA_PRINT"}, 77};
78{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
79{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
80{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
81{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
82{ERR_FUNC(DSA_F_DSA_GENERATE_KEY), "DSA_generate_key"},
83{ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS_EX), "DSA_generate_parameters_ex"},
84{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
85{ERR_FUNC(DSA_F_DSA_PARAM_DECODE), "DSA_PARAM_DECODE"},
86{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
87{ERR_FUNC(DSA_F_DSA_PRIV_DECODE), "DSA_PRIV_DECODE"},
88{ERR_FUNC(DSA_F_DSA_PRIV_ENCODE), "DSA_PRIV_ENCODE"},
89{ERR_FUNC(DSA_F_DSA_PUB_DECODE), "DSA_PUB_DECODE"},
90{ERR_FUNC(DSA_F_DSA_PUB_ENCODE), "DSA_PUB_ENCODE"},
91{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
92{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
93{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
94{ERR_FUNC(DSA_F_DSA_SIG_PRINT), "DSA_SIG_PRINT"},
95{ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"},
96{ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"},
97{ERR_FUNC(DSA_F_OLD_DSA_PRIV_DECODE), "OLD_DSA_PRIV_DECODE"},
98{ERR_FUNC(DSA_F_PKEY_DSA_CTRL), "PKEY_DSA_CTRL"},
99{ERR_FUNC(DSA_F_PKEY_DSA_KEYGEN), "PKEY_DSA_KEYGEN"},
100{ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"},
101{0,NULL}
102 };
103 78
104static ERR_STRING_DATA DSA_str_reasons[]= 79static ERR_STRING_DATA DSA_str_reasons[]=
105 { 80 {
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 8016f2f7cb..58af74889c 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_lib.c,v 1.22 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.23 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -126,14 +126,14 @@ DSA_new_method(ENGINE *engine)
126 126
127 ret = malloc(sizeof(DSA)); 127 ret = malloc(sizeof(DSA));
128 if (ret == NULL) { 128 if (ret == NULL) {
129 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 129 DSAerror(ERR_R_MALLOC_FAILURE);
130 return NULL; 130 return NULL;
131 } 131 }
132 ret->meth = DSA_get_default_method(); 132 ret->meth = DSA_get_default_method();
133#ifndef OPENSSL_NO_ENGINE 133#ifndef OPENSSL_NO_ENGINE
134 if (engine) { 134 if (engine) {
135 if (!ENGINE_init(engine)) { 135 if (!ENGINE_init(engine)) {
136 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); 136 DSAerror(ERR_R_ENGINE_LIB);
137 free(ret); 137 free(ret);
138 return NULL; 138 return NULL;
139 } 139 }
@@ -143,7 +143,7 @@ DSA_new_method(ENGINE *engine)
143 if (ret->engine) { 143 if (ret->engine) {
144 ret->meth = ENGINE_get_DSA(ret->engine); 144 ret->meth = ENGINE_get_DSA(ret->engine);
145 if (!ret->meth) { 145 if (!ret->meth) {
146 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); 146 DSAerror(ERR_R_ENGINE_LIB);
147 ENGINE_finish(ret->engine); 147 ENGINE_finish(ret->engine);
148 free(ret); 148 free(ret);
149 return NULL; 149 return NULL;
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
index f806cd645a..f1013fe547 100644
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_ossl.c,v 1.29 2017/01/21 11:00:46 beck Exp $ */ 1/* $OpenBSD: dsa_ossl.c,v 1.30 2017/01/29 17:49:22 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -169,7 +169,7 @@ redo:
169 169
170err: 170err:
171 if (!ret) { 171 if (!ret) {
172 DSAerr(DSA_F_DSA_DO_SIGN, reason); 172 DSAerror(reason);
173 BN_free(r); 173 BN_free(r);
174 BN_free(s); 174 BN_free(s);
175 } 175 }
@@ -188,7 +188,7 @@ dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
188 int ret = 0; 188 int ret = 0;
189 189
190 if (!dsa->p || !dsa->q || !dsa->g) { 190 if (!dsa->p || !dsa->q || !dsa->g) {
191 DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS); 191 DSAerror(DSA_R_MISSING_PARAMETERS);
192 return 0; 192 return 0;
193 } 193 }
194 194
@@ -259,7 +259,7 @@ dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
259 ret = 1; 259 ret = 1;
260err: 260err:
261 if (!ret) { 261 if (!ret) {
262 DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB); 262 DSAerror(ERR_R_BN_LIB);
263 BN_clear_free(r); 263 BN_clear_free(r);
264 } 264 }
265 if (ctx_in == NULL) 265 if (ctx_in == NULL)
@@ -277,19 +277,19 @@ dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)
277 int ret = -1, i; 277 int ret = -1, i;
278 278
279 if (!dsa->p || !dsa->q || !dsa->g) { 279 if (!dsa->p || !dsa->q || !dsa->g) {
280 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS); 280 DSAerror(DSA_R_MISSING_PARAMETERS);
281 return -1; 281 return -1;
282 } 282 }
283 283
284 i = BN_num_bits(dsa->q); 284 i = BN_num_bits(dsa->q);
285 /* fips 186-3 allows only different sizes for q */ 285 /* fips 186-3 allows only different sizes for q */
286 if (i != 160 && i != 224 && i != 256) { 286 if (i != 160 && i != 224 && i != 256) {
287 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE); 287 DSAerror(DSA_R_BAD_Q_VALUE);
288 return -1; 288 return -1;
289 } 289 }
290 290
291 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) { 291 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
292 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE); 292 DSAerror(DSA_R_MODULUS_TOO_LARGE);
293 return -1; 293 return -1;
294 } 294 }
295 BN_init(&u1); 295 BN_init(&u1);
@@ -363,7 +363,7 @@ dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)
363 363
364err: 364err:
365 if (ret < 0) 365 if (ret < 0)
366 DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); 366 DSAerror(ERR_R_BN_LIB);
367 BN_CTX_free(ctx); 367 BN_CTX_free(ctx);
368 BN_free(&u1); 368 BN_free(&u1);
369 BN_free(&u2); 369 BN_free(&u2);
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
index c7a2edfc94..780b070a72 100644
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ b/src/lib/libcrypto/dsa/dsa_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_pmeth.c,v 1.10 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dsa_pmeth.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -191,7 +191,7 @@ pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
191 case NID_sha256: 191 case NID_sha256:
192 break; 192 break;
193 default: 193 default:
194 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE); 194 DSAerror(DSA_R_INVALID_DIGEST_TYPE);
195 return 0; 195 return 0;
196 } 196 }
197 dctx->md = p2; 197 dctx->md = p2;
@@ -208,7 +208,7 @@ pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
208 case NID_sha512: 208 case NID_sha512:
209 break; 209 break;
210 default: 210 default:
211 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE); 211 DSAerror(DSA_R_INVALID_DIGEST_TYPE);
212 return 0; 212 return 0;
213 } 213 }
214 dctx->md = p2; 214 dctx->md = p2;
@@ -220,8 +220,7 @@ pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
220 return 1; 220 return 1;
221 221
222 case EVP_PKEY_CTRL_PEER_KEY: 222 case EVP_PKEY_CTRL_PEER_KEY:
223 DSAerr(DSA_F_PKEY_DSA_CTRL, 223 DSAerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
224 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
225 return -2; 224 return -2;
226 default: 225 default:
227 return -2; 226 return -2;
@@ -303,7 +302,7 @@ pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
303 DSA *dsa = NULL; 302 DSA *dsa = NULL;
304 303
305 if (ctx->pkey == NULL) { 304 if (ctx->pkey == NULL) {
306 DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET); 305 DSAerror(DSA_R_NO_PARAMETERS_SET);
307 return 0; 306 return 0;
308 } 307 }
309 dsa = DSA_new(); 308 dsa = DSA_new();
diff --git a/src/lib/libcrypto/dsa/dsa_prn.c b/src/lib/libcrypto/dsa/dsa_prn.c
index 60f4e6c760..fb5e35f909 100644
--- a/src/lib/libcrypto/dsa/dsa_prn.c
+++ b/src/lib/libcrypto/dsa/dsa_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_prn.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dsa_prn.c,v 1.6 2017/01/29 17:49:22 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -69,7 +69,7 @@ DSA_print_fp(FILE *fp, const DSA *x, int off)
69 int ret; 69 int ret;
70 70
71 if ((b = BIO_new(BIO_s_file())) == NULL) { 71 if ((b = BIO_new(BIO_s_file())) == NULL) {
72 DSAerr(DSA_F_DSA_PRINT_FP, ERR_R_BUF_LIB); 72 DSAerror(ERR_R_BUF_LIB);
73 return 0; 73 return 0;
74 } 74 }
75 BIO_set_fp(b, fp, BIO_NOCLOSE); 75 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -85,7 +85,7 @@ DSAparams_print_fp(FILE *fp, const DSA *x)
85 int ret; 85 int ret;
86 86
87 if ((b = BIO_new(BIO_s_file())) == NULL) { 87 if ((b = BIO_new(BIO_s_file())) == NULL) {
88 DSAerr(DSA_F_DSAPARAMS_PRINT_FP, ERR_R_BUF_LIB); 88 DSAerror(ERR_R_BUF_LIB);
89 return 0; 89 return 0;
90 } 90 }
91 BIO_set_fp(b, fp, BIO_NOCLOSE); 91 BIO_set_fp(b, fp, BIO_NOCLOSE);
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
index f22e641bab..95afd26b82 100644
--- a/src/lib/libcrypto/dso/dso_dlfcn.c
+++ b/src/lib/libcrypto/dso/dso_dlfcn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dso_dlfcn.c,v 1.28 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: dso_dlfcn.c,v 1.29 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -119,7 +119,7 @@ dlfcn_load(DSO *dso)
119 int flags = RTLD_LAZY; 119 int flags = RTLD_LAZY;
120 120
121 if (filename == NULL) { 121 if (filename == NULL) {
122 DSOerr(DSO_F_DLFCN_LOAD, DSO_R_NO_FILENAME); 122 DSOerror(DSO_R_NO_FILENAME);
123 goto err; 123 goto err;
124 } 124 }
125 125
@@ -127,13 +127,13 @@ dlfcn_load(DSO *dso)
127 flags |= RTLD_GLOBAL; 127 flags |= RTLD_GLOBAL;
128 ptr = dlopen(filename, flags); 128 ptr = dlopen(filename, flags);
129 if (ptr == NULL) { 129 if (ptr == NULL) {
130 DSOerr(DSO_F_DLFCN_LOAD, DSO_R_LOAD_FAILED); 130 DSOerror(DSO_R_LOAD_FAILED);
131 ERR_asprintf_error_data("filename(%s): %s", filename, 131 ERR_asprintf_error_data("filename(%s): %s", filename,
132 dlerror()); 132 dlerror());
133 goto err; 133 goto err;
134 } 134 }
135 if (!sk_void_push(dso->meth_data, (char *)ptr)) { 135 if (!sk_void_push(dso->meth_data, (char *)ptr)) {
136 DSOerr(DSO_F_DLFCN_LOAD, DSO_R_STACK_ERROR); 136 DSOerror(DSO_R_STACK_ERROR);
137 goto err; 137 goto err;
138 } 138 }
139 /* Success */ 139 /* Success */
@@ -153,14 +153,14 @@ dlfcn_unload(DSO *dso)
153{ 153{
154 void *ptr; 154 void *ptr;
155 if (dso == NULL) { 155 if (dso == NULL) {
156 DSOerr(DSO_F_DLFCN_UNLOAD, ERR_R_PASSED_NULL_PARAMETER); 156 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
157 return (0); 157 return (0);
158 } 158 }
159 if (sk_void_num(dso->meth_data) < 1) 159 if (sk_void_num(dso->meth_data) < 1)
160 return (1); 160 return (1);
161 ptr = sk_void_pop(dso->meth_data); 161 ptr = sk_void_pop(dso->meth_data);
162 if (ptr == NULL) { 162 if (ptr == NULL) {
163 DSOerr(DSO_F_DLFCN_UNLOAD, DSO_R_NULL_HANDLE); 163 DSOerror(DSO_R_NULL_HANDLE);
164 /* Should push the value back onto the stack in 164 /* Should push the value back onto the stack in
165 * case of a retry. */ 165 * case of a retry. */
166 sk_void_push(dso->meth_data, ptr); 166 sk_void_push(dso->meth_data, ptr);
@@ -177,21 +177,21 @@ dlfcn_bind_var(DSO *dso, const char *symname)
177 void *ptr, *sym; 177 void *ptr, *sym;
178 178
179 if ((dso == NULL) || (symname == NULL)) { 179 if ((dso == NULL) || (symname == NULL)) {
180 DSOerr(DSO_F_DLFCN_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER); 180 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
181 return (NULL); 181 return (NULL);
182 } 182 }
183 if (sk_void_num(dso->meth_data) < 1) { 183 if (sk_void_num(dso->meth_data) < 1) {
184 DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_STACK_ERROR); 184 DSOerror(DSO_R_STACK_ERROR);
185 return (NULL); 185 return (NULL);
186 } 186 }
187 ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); 187 ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
188 if (ptr == NULL) { 188 if (ptr == NULL) {
189 DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_NULL_HANDLE); 189 DSOerror(DSO_R_NULL_HANDLE);
190 return (NULL); 190 return (NULL);
191 } 191 }
192 sym = dlsym(ptr, symname); 192 sym = dlsym(ptr, symname);
193 if (sym == NULL) { 193 if (sym == NULL) {
194 DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_SYM_FAILURE); 194 DSOerror(DSO_R_SYM_FAILURE);
195 ERR_asprintf_error_data("symname(%s): %s", symname, dlerror()); 195 ERR_asprintf_error_data("symname(%s): %s", symname, dlerror());
196 return (NULL); 196 return (NULL);
197 } 197 }
@@ -208,21 +208,21 @@ dlfcn_bind_func(DSO *dso, const char *symname)
208 } u; 208 } u;
209 209
210 if ((dso == NULL) || (symname == NULL)) { 210 if ((dso == NULL) || (symname == NULL)) {
211 DSOerr(DSO_F_DLFCN_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); 211 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
212 return (NULL); 212 return (NULL);
213 } 213 }
214 if (sk_void_num(dso->meth_data) < 1) { 214 if (sk_void_num(dso->meth_data) < 1) {
215 DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_STACK_ERROR); 215 DSOerror(DSO_R_STACK_ERROR);
216 return (NULL); 216 return (NULL);
217 } 217 }
218 ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); 218 ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
219 if (ptr == NULL) { 219 if (ptr == NULL) {
220 DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_NULL_HANDLE); 220 DSOerror(DSO_R_NULL_HANDLE);
221 return (NULL); 221 return (NULL);
222 } 222 }
223 u.dlret = dlsym(ptr, symname); 223 u.dlret = dlsym(ptr, symname);
224 if (u.dlret == NULL) { 224 if (u.dlret == NULL) {
225 DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_SYM_FAILURE); 225 DSOerror(DSO_R_SYM_FAILURE);
226 ERR_asprintf_error_data("symname(%s): %s", symname, dlerror()); 226 ERR_asprintf_error_data("symname(%s): %s", symname, dlerror());
227 return (NULL); 227 return (NULL);
228 } 228 }
@@ -235,8 +235,7 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2)
235 char *merged; 235 char *merged;
236 236
237 if (!filespec1 && !filespec2) { 237 if (!filespec1 && !filespec2) {
238 DSOerr(DSO_F_DLFCN_MERGER, 238 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
239 ERR_R_PASSED_NULL_PARAMETER);
240 return (NULL); 239 return (NULL);
241 } 240 }
242 /* If the first file specification is a rooted path, it rules. 241 /* If the first file specification is a rooted path, it rules.
@@ -244,7 +243,7 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2)
244 if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) { 243 if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) {
245 merged = strdup(filespec1); 244 merged = strdup(filespec1);
246 if (!merged) { 245 if (!merged) {
247 DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); 246 DSOerror(ERR_R_MALLOC_FAILURE);
248 return (NULL); 247 return (NULL);
249 } 248 }
250 } 249 }
@@ -252,7 +251,7 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2)
252 else if (!filespec1) { 251 else if (!filespec1) {
253 merged = strdup(filespec2); 252 merged = strdup(filespec2);
254 if (!merged) { 253 if (!merged) {
255 DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); 254 DSOerror(ERR_R_MALLOC_FAILURE);
256 return (NULL); 255 return (NULL);
257 } 256 }
258 } else 257 } else
@@ -273,7 +272,7 @@ dlfcn_merger(DSO *dso, const char *filespec1, const char *filespec2)
273 } 272 }
274 merged = malloc(len + 2); 273 merged = malloc(len + 2);
275 if (!merged) { 274 if (!merged) {
276 DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); 275 DSOerror(ERR_R_MALLOC_FAILURE);
277 return (NULL); 276 return (NULL);
278 } 277 }
279 strlcpy(merged, filespec2, len + 2); 278 strlcpy(merged, filespec2, len + 2);
@@ -306,8 +305,7 @@ dlfcn_name_converter(DSO *dso, const char *filename)
306 } 305 }
307 306
308 if (translated == NULL) 307 if (translated == NULL)
309 DSOerr(DSO_F_DLFCN_NAME_CONVERTER, 308 DSOerror(DSO_R_NAME_TRANSLATION_FAILED);
310 DSO_R_NAME_TRANSLATION_FAILED);
311 return (translated); 309 return (translated);
312} 310}
313 311
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c
index b8514a4aef..be6375a3a7 100644
--- a/src/lib/libcrypto/dso/dso_err.c
+++ b/src/lib/libcrypto/dso/dso_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dso_err.c,v 1.8 2014/07/10 22:45:56 jsing Exp $ */ 1/* $OpenBSD: dso_err.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,55 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason)
73 73
74static ERR_STRING_DATA DSO_str_functs[]= { 74static ERR_STRING_DATA DSO_str_functs[]= {
75 {ERR_FUNC(DSO_F_BEOS_BIND_FUNC), "BEOS_BIND_FUNC"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(DSO_F_BEOS_BIND_VAR), "BEOS_BIND_VAR"},
77 {ERR_FUNC(DSO_F_BEOS_LOAD), "BEOS_LOAD"},
78 {ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER), "BEOS_NAME_CONVERTER"},
79 {ERR_FUNC(DSO_F_BEOS_UNLOAD), "BEOS_UNLOAD"},
80 {ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"},
81 {ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"},
82 {ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"},
83 {ERR_FUNC(DSO_F_DLFCN_MERGER), "DLFCN_MERGER"},
84 {ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"},
85 {ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"},
86 {ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"},
87 {ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"},
88 {ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"},
89 {ERR_FUNC(DSO_F_DL_MERGER), "DL_MERGER"},
90 {ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"},
91 {ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"},
92 {ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"},
93 {ERR_FUNC(DSO_F_DSO_BIND_VAR), "DSO_bind_var"},
94 {ERR_FUNC(DSO_F_DSO_CONVERT_FILENAME), "DSO_convert_filename"},
95 {ERR_FUNC(DSO_F_DSO_CTRL), "DSO_ctrl"},
96 {ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"},
97 {ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"},
98 {ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"},
99 {ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP), "DSO_global_lookup"},
100 {ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"},
101 {ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"},
102 {ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"},
103 {ERR_FUNC(DSO_F_DSO_PATHBYADDR), "DSO_pathbyaddr"},
104 {ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"},
105 {ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"},
106 {ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"},
107 {ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC), "GLOBAL_LOOKUP_FUNC"},
108 {ERR_FUNC(DSO_F_PATHBYADDR), "PATHBYADDR"},
109 {ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"},
110 {ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"},
111 {ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"},
112 {ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"},
113 {ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"},
114 {ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"},
115 {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP), "WIN32_GLOBALLOOKUP"},
116 {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC), "WIN32_GLOBALLOOKUP_FUNC"},
117 {ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"},
118 {ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"},
119 {ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"},
120 {ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"},
121 {ERR_FUNC(DSO_F_WIN32_PATHBYADDR), "WIN32_PATHBYADDR"},
122 {ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"},
123 {ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"},
124 {0, NULL} 76 {0, NULL}
125}; 77};
126 78
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
index 3002e4d99c..7902fbcc6e 100644
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dso_lib.c,v 1.18 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: dso_lib.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -111,13 +111,13 @@ DSO_new_method(DSO_METHOD *meth)
111 default_DSO_meth = DSO_METHOD_openssl(); 111 default_DSO_meth = DSO_METHOD_openssl();
112 ret = calloc(1, sizeof(DSO)); 112 ret = calloc(1, sizeof(DSO));
113 if (ret == NULL) { 113 if (ret == NULL) {
114 DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); 114 DSOerror(ERR_R_MALLOC_FAILURE);
115 return (NULL); 115 return (NULL);
116 } 116 }
117 ret->meth_data = sk_void_new_null(); 117 ret->meth_data = sk_void_new_null();
118 if (ret->meth_data == NULL) { 118 if (ret->meth_data == NULL) {
119 /* sk_new doesn't generate any errors so we do */ 119 /* sk_new doesn't generate any errors so we do */
120 DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE); 120 DSOerror(ERR_R_MALLOC_FAILURE);
121 free(ret); 121 free(ret);
122 return (NULL); 122 return (NULL);
123 } 123 }
@@ -139,7 +139,7 @@ DSO_free(DSO *dso)
139 int i; 139 int i;
140 140
141 if (dso == NULL) { 141 if (dso == NULL) {
142 DSOerr(DSO_F_DSO_FREE, ERR_R_PASSED_NULL_PARAMETER); 142 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
143 return (0); 143 return (0);
144 } 144 }
145 145
@@ -148,12 +148,12 @@ DSO_free(DSO *dso)
148 return (1); 148 return (1);
149 149
150 if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) { 150 if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
151 DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED); 151 DSOerror(DSO_R_UNLOAD_FAILED);
152 return (0); 152 return (0);
153 } 153 }
154 154
155 if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) { 155 if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
156 DSOerr(DSO_F_DSO_FREE, DSO_R_FINISH_FAILED); 156 DSOerror(DSO_R_FINISH_FAILED);
157 return (0); 157 return (0);
158 } 158 }
159 159
@@ -175,7 +175,7 @@ int
175DSO_up_ref(DSO *dso) 175DSO_up_ref(DSO *dso)
176{ 176{
177 if (dso == NULL) { 177 if (dso == NULL) {
178 DSOerr(DSO_F_DSO_UP_REF, ERR_R_PASSED_NULL_PARAMETER); 178 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
179 return (0); 179 return (0);
180 } 180 }
181 181
@@ -192,40 +192,40 @@ DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
192 if (dso == NULL) { 192 if (dso == NULL) {
193 ret = DSO_new_method(meth); 193 ret = DSO_new_method(meth);
194 if (ret == NULL) { 194 if (ret == NULL) {
195 DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); 195 DSOerror(ERR_R_MALLOC_FAILURE);
196 goto err; 196 goto err;
197 } 197 }
198 allocated = 1; 198 allocated = 1;
199 /* Pass the provided flags to the new DSO object */ 199 /* Pass the provided flags to the new DSO object */
200 if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { 200 if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {
201 DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); 201 DSOerror(DSO_R_CTRL_FAILED);
202 goto err; 202 goto err;
203 } 203 }
204 } else 204 } else
205 ret = dso; 205 ret = dso;
206 /* Don't load if we're currently already loaded */ 206 /* Don't load if we're currently already loaded */
207 if (ret->filename != NULL) { 207 if (ret->filename != NULL) {
208 DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); 208 DSOerror(DSO_R_DSO_ALREADY_LOADED);
209 goto err; 209 goto err;
210 } 210 }
211 /* filename can only be NULL if we were passed a dso that already has 211 /* filename can only be NULL if we were passed a dso that already has
212 * one set. */ 212 * one set. */
213 if (filename != NULL) 213 if (filename != NULL)
214 if (!DSO_set_filename(ret, filename)) { 214 if (!DSO_set_filename(ret, filename)) {
215 DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); 215 DSOerror(DSO_R_SET_FILENAME_FAILED);
216 goto err; 216 goto err;
217 } 217 }
218 filename = ret->filename; 218 filename = ret->filename;
219 if (filename == NULL) { 219 if (filename == NULL) {
220 DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); 220 DSOerror(DSO_R_NO_FILENAME);
221 goto err; 221 goto err;
222 } 222 }
223 if (ret->meth->dso_load == NULL) { 223 if (ret->meth->dso_load == NULL) {
224 DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); 224 DSOerror(DSO_R_UNSUPPORTED);
225 goto err; 225 goto err;
226 } 226 }
227 if (!ret->meth->dso_load(ret)) { 227 if (!ret->meth->dso_load(ret)) {
228 DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); 228 DSOerror(DSO_R_LOAD_FAILED);
229 goto err; 229 goto err;
230 } 230 }
231 /* Load succeeded */ 231 /* Load succeeded */
@@ -243,15 +243,15 @@ DSO_bind_var(DSO *dso, const char *symname)
243 void *ret = NULL; 243 void *ret = NULL;
244 244
245 if ((dso == NULL) || (symname == NULL)) { 245 if ((dso == NULL) || (symname == NULL)) {
246 DSOerr(DSO_F_DSO_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER); 246 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
247 return (NULL); 247 return (NULL);
248 } 248 }
249 if (dso->meth->dso_bind_var == NULL) { 249 if (dso->meth->dso_bind_var == NULL) {
250 DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_UNSUPPORTED); 250 DSOerror(DSO_R_UNSUPPORTED);
251 return (NULL); 251 return (NULL);
252 } 252 }
253 if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) { 253 if ((ret = dso->meth->dso_bind_var(dso, symname)) == NULL) {
254 DSOerr(DSO_F_DSO_BIND_VAR, DSO_R_SYM_FAILURE); 254 DSOerror(DSO_R_SYM_FAILURE);
255 return (NULL); 255 return (NULL);
256 } 256 }
257 /* Success */ 257 /* Success */
@@ -264,15 +264,15 @@ DSO_bind_func(DSO *dso, const char *symname)
264 DSO_FUNC_TYPE ret = NULL; 264 DSO_FUNC_TYPE ret = NULL;
265 265
266 if ((dso == NULL) || (symname == NULL)) { 266 if ((dso == NULL) || (symname == NULL)) {
267 DSOerr(DSO_F_DSO_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER); 267 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
268 return (NULL); 268 return (NULL);
269 } 269 }
270 if (dso->meth->dso_bind_func == NULL) { 270 if (dso->meth->dso_bind_func == NULL) {
271 DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_UNSUPPORTED); 271 DSOerror(DSO_R_UNSUPPORTED);
272 return (NULL); 272 return (NULL);
273 } 273 }
274 if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) { 274 if ((ret = dso->meth->dso_bind_func(dso, symname)) == NULL) {
275 DSOerr(DSO_F_DSO_BIND_FUNC, DSO_R_SYM_FAILURE); 275 DSOerror(DSO_R_SYM_FAILURE);
276 return (NULL); 276 return (NULL);
277 } 277 }
278 /* Success */ 278 /* Success */
@@ -291,7 +291,7 @@ long
291DSO_ctrl(DSO *dso, int cmd, long larg, void *parg) 291DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
292{ 292{
293 if (dso == NULL) { 293 if (dso == NULL) {
294 DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER); 294 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
295 return (-1); 295 return (-1);
296 } 296 }
297 /* We should intercept certain generic commands and only pass control 297 /* We should intercept certain generic commands and only pass control
@@ -310,7 +310,7 @@ DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)
310 break; 310 break;
311 } 311 }
312 if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) { 312 if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {
313 DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED); 313 DSOerror(DSO_R_UNSUPPORTED);
314 return (-1); 314 return (-1);
315 } 315 }
316 return (dso->meth->dso_ctrl(dso, cmd, larg, parg)); 316 return (dso->meth->dso_ctrl(dso, cmd, larg, parg));
@@ -321,8 +321,7 @@ DSO_set_name_converter(DSO *dso, DSO_NAME_CONVERTER_FUNC cb,
321 DSO_NAME_CONVERTER_FUNC *oldcb) 321 DSO_NAME_CONVERTER_FUNC *oldcb)
322{ 322{
323 if (dso == NULL) { 323 if (dso == NULL) {
324 DSOerr(DSO_F_DSO_SET_NAME_CONVERTER, 324 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
325 ERR_R_PASSED_NULL_PARAMETER);
326 return (0); 325 return (0);
327 } 326 }
328 if (oldcb) 327 if (oldcb)
@@ -335,7 +334,7 @@ const char *
335DSO_get_filename(DSO *dso) 334DSO_get_filename(DSO *dso)
336{ 335{
337 if (dso == NULL) { 336 if (dso == NULL) {
338 DSOerr(DSO_F_DSO_GET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 337 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
339 return (NULL); 338 return (NULL);
340 } 339 }
341 return (dso->filename); 340 return (dso->filename);
@@ -347,17 +346,17 @@ DSO_set_filename(DSO *dso, const char *filename)
347 char *copied; 346 char *copied;
348 347
349 if ((dso == NULL) || (filename == NULL)) { 348 if ((dso == NULL) || (filename == NULL)) {
350 DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 349 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
351 return (0); 350 return (0);
352 } 351 }
353 if (dso->loaded_filename) { 352 if (dso->loaded_filename) {
354 DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED); 353 DSOerror(DSO_R_DSO_ALREADY_LOADED);
355 return (0); 354 return (0);
356 } 355 }
357 /* We'll duplicate filename */ 356 /* We'll duplicate filename */
358 copied = strdup(filename); 357 copied = strdup(filename);
359 if (copied == NULL) { 358 if (copied == NULL) {
360 DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); 359 DSOerror(ERR_R_MALLOC_FAILURE);
361 return (0); 360 return (0);
362 } 361 }
363 free(dso->filename); 362 free(dso->filename);
@@ -371,7 +370,7 @@ DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
371 char *result = NULL; 370 char *result = NULL;
372 371
373 if (dso == NULL || filespec1 == NULL) { 372 if (dso == NULL || filespec1 == NULL) {
374 DSOerr(DSO_F_DSO_MERGE, ERR_R_PASSED_NULL_PARAMETER); 373 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
375 return (NULL); 374 return (NULL);
376 } 375 }
377 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { 376 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
@@ -390,13 +389,13 @@ DSO_convert_filename(DSO *dso, const char *filename)
390 char *result = NULL; 389 char *result = NULL;
391 390
392 if (dso == NULL) { 391 if (dso == NULL) {
393 DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_PASSED_NULL_PARAMETER); 392 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
394 return (NULL); 393 return (NULL);
395 } 394 }
396 if (filename == NULL) 395 if (filename == NULL)
397 filename = dso->filename; 396 filename = dso->filename;
398 if (filename == NULL) { 397 if (filename == NULL) {
399 DSOerr(DSO_F_DSO_CONVERT_FILENAME, DSO_R_NO_FILENAME); 398 DSOerror(DSO_R_NO_FILENAME);
400 return (NULL); 399 return (NULL);
401 } 400 }
402 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) { 401 if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
@@ -408,8 +407,7 @@ DSO_convert_filename(DSO *dso, const char *filename)
408 if (result == NULL) { 407 if (result == NULL) {
409 result = strdup(filename); 408 result = strdup(filename);
410 if (result == NULL) { 409 if (result == NULL) {
411 DSOerr(DSO_F_DSO_CONVERT_FILENAME, 410 DSOerror(ERR_R_MALLOC_FAILURE);
412 ERR_R_MALLOC_FAILURE);
413 return (NULL); 411 return (NULL);
414 } 412 }
415 } 413 }
@@ -420,8 +418,7 @@ const char *
420DSO_get_loaded_filename(DSO *dso) 418DSO_get_loaded_filename(DSO *dso)
421{ 419{
422 if (dso == NULL) { 420 if (dso == NULL) {
423 DSOerr(DSO_F_DSO_GET_LOADED_FILENAME, 421 DSOerror(ERR_R_PASSED_NULL_PARAMETER);
424 ERR_R_PASSED_NULL_PARAMETER);
425 return (NULL); 422 return (NULL);
426 } 423 }
427 return (dso->loaded_filename); 424 return (dso->loaded_filename);
@@ -434,7 +431,7 @@ DSO_pathbyaddr(void *addr, char *path, int sz)
434 if (meth == NULL) 431 if (meth == NULL)
435 meth = DSO_METHOD_openssl(); 432 meth = DSO_METHOD_openssl();
436 if (meth->pathbyaddr == NULL) { 433 if (meth->pathbyaddr == NULL) {
437 DSOerr(DSO_F_DSO_PATHBYADDR, DSO_R_UNSUPPORTED); 434 DSOerror(DSO_R_UNSUPPORTED);
438 return -1; 435 return -1;
439 } 436 }
440 return (*meth->pathbyaddr)(addr, path, sz); 437 return (*meth->pathbyaddr)(addr, path, sz);
@@ -447,7 +444,7 @@ DSO_global_lookup(const char *name)
447 if (meth == NULL) 444 if (meth == NULL)
448 meth = DSO_METHOD_openssl(); 445 meth = DSO_METHOD_openssl();
449 if (meth->globallookup == NULL) { 446 if (meth->globallookup == NULL) {
450 DSOerr(DSO_F_DSO_GLOBAL_LOOKUP, DSO_R_UNSUPPORTED); 447 DSOerror(DSO_R_UNSUPPORTED);
451 return NULL; 448 return NULL;
452 } 449 }
453 return (*meth->globallookup)(name); 450 return (*meth->globallookup)(name);
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c
index 3812611702..1c8bb18076 100644
--- a/src/lib/libcrypto/ec/ec2_mult.c
+++ b/src/lib/libcrypto/ec/ec2_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_mult.c,v 1.8 2016/03/12 21:44:11 bcook Exp $ */ 1/* $OpenBSD: ec2_mult.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -267,7 +267,7 @@ ec_GF2m_montgomery_point_multiply(const EC_GROUP *group, EC_POINT *r,
267 BN_ULONG mask, word; 267 BN_ULONG mask, word;
268 268
269 if (r == point) { 269 if (r == point) {
270 ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT); 270 ECerror(EC_R_INVALID_ARGUMENT);
271 return 0; 271 return 0;
272 } 272 }
273 /* if result should be point at infinity */ 273 /* if result should be point at infinity */
diff --git a/src/lib/libcrypto/ec/ec2_oct.c b/src/lib/libcrypto/ec/ec2_oct.c
index 72690b1bc7..f434d726d2 100644
--- a/src/lib/libcrypto/ec/ec2_oct.c
+++ b/src/lib/libcrypto/ec/ec2_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_oct.c,v 1.7 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ec2_oct.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -138,9 +138,9 @@ ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point
138 if (ERR_GET_LIB(err) == ERR_LIB_BN && 138 if (ERR_GET_LIB(err) == ERR_LIB_BN &&
139 ERR_GET_REASON(err) == BN_R_NO_SOLUTION) { 139 ERR_GET_REASON(err) == BN_R_NO_SOLUTION) {
140 ERR_clear_error(); 140 ERR_clear_error();
141 ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 141 ECerror(EC_R_INVALID_COMPRESSED_POINT);
142 } else 142 } else
143 ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB); 143 ECerror(ERR_R_BN_LIB);
144 goto err; 144 goto err;
145 } 145 }
146 z0 = (BN_is_odd(z)) ? 1 : 0; 146 z0 = (BN_is_odd(z)) ? 1 : 0;
@@ -182,14 +182,14 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
182 if ((form != POINT_CONVERSION_COMPRESSED) 182 if ((form != POINT_CONVERSION_COMPRESSED)
183 && (form != POINT_CONVERSION_UNCOMPRESSED) 183 && (form != POINT_CONVERSION_UNCOMPRESSED)
184 && (form != POINT_CONVERSION_HYBRID)) { 184 && (form != POINT_CONVERSION_HYBRID)) {
185 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_INVALID_FORM); 185 ECerror(EC_R_INVALID_FORM);
186 goto err; 186 goto err;
187 } 187 }
188 if (EC_POINT_is_at_infinity(group, point) > 0) { 188 if (EC_POINT_is_at_infinity(group, point) > 0) {
189 /* encodes to a single 0 octet */ 189 /* encodes to a single 0 octet */
190 if (buf != NULL) { 190 if (buf != NULL) {
191 if (len < 1) { 191 if (len < 1) {
192 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 192 ECerror(EC_R_BUFFER_TOO_SMALL);
193 return 0; 193 return 0;
194 } 194 }
195 buf[0] = 0; 195 buf[0] = 0;
@@ -204,7 +204,7 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
204 /* if 'buf' is NULL, just return required length */ 204 /* if 'buf' is NULL, just return required length */
205 if (buf != NULL) { 205 if (buf != NULL) {
206 if (len < ret) { 206 if (len < ret) {
207 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 207 ECerror(EC_R_BUFFER_TOO_SMALL);
208 goto err; 208 goto err;
209 } 209 }
210 if (ctx == NULL) { 210 if (ctx == NULL) {
@@ -235,7 +235,7 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
235 235
236 skip = field_len - BN_num_bytes(x); 236 skip = field_len - BN_num_bytes(x);
237 if (skip > field_len) { 237 if (skip > field_len) {
238 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 238 ECerror(ERR_R_INTERNAL_ERROR);
239 goto err; 239 goto err;
240 } 240 }
241 while (skip > 0) { 241 while (skip > 0) {
@@ -245,14 +245,14 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
245 skip = BN_bn2bin(x, buf + i); 245 skip = BN_bn2bin(x, buf + i);
246 i += skip; 246 i += skip;
247 if (i != 1 + field_len) { 247 if (i != 1 + field_len) {
248 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 248 ECerror(ERR_R_INTERNAL_ERROR);
249 goto err; 249 goto err;
250 } 250 }
251 if (form == POINT_CONVERSION_UNCOMPRESSED || 251 if (form == POINT_CONVERSION_UNCOMPRESSED ||
252 form == POINT_CONVERSION_HYBRID) { 252 form == POINT_CONVERSION_HYBRID) {
253 skip = field_len - BN_num_bytes(y); 253 skip = field_len - BN_num_bytes(y);
254 if (skip > field_len) { 254 if (skip > field_len) {
255 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 255 ECerror(ERR_R_INTERNAL_ERROR);
256 goto err; 256 goto err;
257 } 257 }
258 while (skip > 0) { 258 while (skip > 0) {
@@ -263,7 +263,7 @@ ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,
263 i += skip; 263 i += skip;
264 } 264 }
265 if (i != ret) { 265 if (i != ret) {
266 ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 266 ECerror(ERR_R_INTERNAL_ERROR);
267 goto err; 267 goto err;
268 } 268 }
269 } 269 }
@@ -295,7 +295,7 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
295 int ret = 0; 295 int ret = 0;
296 296
297 if (len == 0) { 297 if (len == 0) {
298 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL); 298 ECerror(EC_R_BUFFER_TOO_SMALL);
299 return 0; 299 return 0;
300 } 300 }
301 form = buf[0]; 301 form = buf[0];
@@ -304,16 +304,16 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
304 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED) && 304 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED) &&
305 (form != POINT_CONVERSION_UNCOMPRESSED) && 305 (form != POINT_CONVERSION_UNCOMPRESSED) &&
306 (form != POINT_CONVERSION_HYBRID)) { 306 (form != POINT_CONVERSION_HYBRID)) {
307 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 307 ECerror(EC_R_INVALID_ENCODING);
308 return 0; 308 return 0;
309 } 309 }
310 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) { 310 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {
311 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 311 ECerror(EC_R_INVALID_ENCODING);
312 return 0; 312 return 0;
313 } 313 }
314 if (form == 0) { 314 if (form == 0) {
315 if (len != 1) { 315 if (len != 1) {
316 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 316 ECerror(EC_R_INVALID_ENCODING);
317 return 0; 317 return 0;
318 } 318 }
319 return EC_POINT_set_to_infinity(group, point); 319 return EC_POINT_set_to_infinity(group, point);
@@ -323,7 +323,7 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
323 1 + 2 * field_len; 323 1 + 2 * field_len;
324 324
325 if (len != enc_len) { 325 if (len != enc_len) {
326 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 326 ECerror(EC_R_INVALID_ENCODING);
327 return 0; 327 return 0;
328 } 328 }
329 if (ctx == NULL) { 329 if (ctx == NULL) {
@@ -342,7 +342,7 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
342 if (!BN_bin2bn(buf + 1, field_len, x)) 342 if (!BN_bin2bn(buf + 1, field_len, x))
343 goto err; 343 goto err;
344 if (BN_ucmp(x, &group->field) >= 0) { 344 if (BN_ucmp(x, &group->field) >= 0) {
345 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 345 ECerror(EC_R_INVALID_ENCODING);
346 goto err; 346 goto err;
347 } 347 }
348 if (form == POINT_CONVERSION_COMPRESSED) { 348 if (form == POINT_CONVERSION_COMPRESSED) {
@@ -352,14 +352,14 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
352 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) 352 if (!BN_bin2bn(buf + 1 + field_len, field_len, y))
353 goto err; 353 goto err;
354 if (BN_ucmp(y, &group->field) >= 0) { 354 if (BN_ucmp(y, &group->field) >= 0) {
355 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 355 ECerror(EC_R_INVALID_ENCODING);
356 goto err; 356 goto err;
357 } 357 }
358 if (form == POINT_CONVERSION_HYBRID) { 358 if (form == POINT_CONVERSION_HYBRID) {
359 if (!group->meth->field_div(group, yxi, y, x, ctx)) 359 if (!group->meth->field_div(group, yxi, y, x, ctx))
360 goto err; 360 goto err;
361 if (y_bit != BN_is_odd(yxi)) { 361 if (y_bit != BN_is_odd(yxi)) {
362 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 362 ECerror(EC_R_INVALID_ENCODING);
363 goto err; 363 goto err;
364 } 364 }
365 } 365 }
@@ -369,7 +369,7 @@ ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
369 369
370 /* test required by X9.62 */ 370 /* test required by X9.62 */
371 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) { 371 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {
372 ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE); 372 ECerror(EC_R_POINT_IS_NOT_ON_CURVE);
373 goto err; 373 goto err;
374 } 374 }
375 ret = 1; 375 ret = 1;
diff --git a/src/lib/libcrypto/ec/ec2_smpl.c b/src/lib/libcrypto/ec/ec2_smpl.c
index 43f0afd5ae..6157599990 100644
--- a/src/lib/libcrypto/ec/ec2_smpl.c
+++ b/src/lib/libcrypto/ec/ec2_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_smpl.c,v 1.14 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ec2_smpl.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -212,7 +212,7 @@ ec_GF2m_simple_group_set_curve(EC_GROUP * group,
212 goto err; 212 goto err;
213 i = BN_GF2m_poly2arr(&group->field, group->poly, 6) - 1; 213 i = BN_GF2m_poly2arr(&group->field, group->poly, 6) - 1;
214 if ((i != 5) && (i != 3)) { 214 if ((i != 5) && (i != 3)) {
215 ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE, EC_R_UNSUPPORTED_FIELD); 215 ECerror(EC_R_UNSUPPORTED_FIELD);
216 goto err; 216 goto err;
217 } 217 }
218 /* group->a */ 218 /* group->a */
@@ -286,7 +286,7 @@ ec_GF2m_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
286 if (ctx == NULL) { 286 if (ctx == NULL) {
287 ctx = new_ctx = BN_CTX_new(); 287 ctx = new_ctx = BN_CTX_new();
288 if (ctx == NULL) { 288 if (ctx == NULL) {
289 ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE); 289 ECerror(ERR_R_MALLOC_FAILURE);
290 goto err; 290 goto err;
291 } 291 }
292 } 292 }
@@ -383,7 +383,7 @@ ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * p
383{ 383{
384 int ret = 0; 384 int ret = 0;
385 if (x == NULL || y == NULL) { 385 if (x == NULL || y == NULL) {
386 ECerr(EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES, ERR_R_PASSED_NULL_PARAMETER); 386 ECerror(ERR_R_PASSED_NULL_PARAMETER);
387 return 0; 387 return 0;
388 } 388 }
389 if (!BN_copy(&point->X, x)) 389 if (!BN_copy(&point->X, x))
@@ -413,11 +413,11 @@ ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group,
413 int ret = 0; 413 int ret = 0;
414 414
415 if (EC_POINT_is_at_infinity(group, point) > 0) { 415 if (EC_POINT_is_at_infinity(group, point) > 0) {
416 ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY); 416 ECerror(EC_R_POINT_AT_INFINITY);
417 return 0; 417 return 0;
418 } 418 }
419 if (BN_cmp(&point->Z, BN_value_one())) { 419 if (BN_cmp(&point->Z, BN_value_one())) {
420 ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 420 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
421 return 0; 421 return 0;
422 } 422 }
423 if (x != NULL) { 423 if (x != NULL) {
diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c
index 0dab68d5fe..8d0cdb733b 100644
--- a/src/lib/libcrypto/ec/ec_ameth.c
+++ b/src/lib/libcrypto/ec/ec_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_ameth.c,v 1.17 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: ec_ameth.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -74,7 +74,7 @@ eckey_param2type(int *pptype, void **ppval, EC_KEY * ec_key)
74 const EC_GROUP *group; 74 const EC_GROUP *group;
75 int nid; 75 int nid;
76 if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) { 76 if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL) {
77 ECerr(EC_F_ECKEY_PARAM2TYPE, EC_R_MISSING_PARAMETERS); 77 ECerror(EC_R_MISSING_PARAMETERS);
78 return 0; 78 return 0;
79 } 79 }
80 if (EC_GROUP_get_asn1_flag(group) && 80 if (EC_GROUP_get_asn1_flag(group) &&
@@ -91,7 +91,7 @@ eckey_param2type(int *pptype, void **ppval, EC_KEY * ec_key)
91 pstr->length = i2d_ECParameters(ec_key, &pstr->data); 91 pstr->length = i2d_ECParameters(ec_key, &pstr->data);
92 if (pstr->length <= 0) { 92 if (pstr->length <= 0) {
93 ASN1_STRING_free(pstr); 93 ASN1_STRING_free(pstr);
94 ECerr(EC_F_ECKEY_PARAM2TYPE, ERR_R_EC_LIB); 94 ECerror(ERR_R_EC_LIB);
95 return 0; 95 return 0;
96 } 96 }
97 *ppval = pstr; 97 *ppval = pstr;
@@ -110,7 +110,7 @@ eckey_pub_encode(X509_PUBKEY * pk, const EVP_PKEY * pkey)
110 int penclen; 110 int penclen;
111 111
112 if (!eckey_param2type(&ptype, &pval, ec_key)) { 112 if (!eckey_param2type(&ptype, &pval, ec_key)) {
113 ECerr(EC_F_ECKEY_PUB_ENCODE, ERR_R_EC_LIB); 113 ECerror(ERR_R_EC_LIB);
114 return 0; 114 return 0;
115 } 115 }
116 penclen = i2o_ECPublicKey(ec_key, NULL); 116 penclen = i2o_ECPublicKey(ec_key, NULL);
@@ -148,7 +148,7 @@ eckey_type2param(int ptype, void *pval)
148 pm = pstr->data; 148 pm = pstr->data;
149 pmlen = pstr->length; 149 pmlen = pstr->length;
150 if (!(eckey = d2i_ECParameters(NULL, &pm, pmlen))) { 150 if (!(eckey = d2i_ECParameters(NULL, &pm, pmlen))) {
151 ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR); 151 ECerror(EC_R_DECODE_ERROR);
152 goto ecerr; 152 goto ecerr;
153 } 153 }
154 } else if (ptype == V_ASN1_OBJECT) { 154 } else if (ptype == V_ASN1_OBJECT) {
@@ -160,7 +160,7 @@ eckey_type2param(int ptype, void *pval)
160 * asn1 OID 160 * asn1 OID
161 */ 161 */
162 if ((eckey = EC_KEY_new()) == NULL) { 162 if ((eckey = EC_KEY_new()) == NULL) {
163 ECerr(EC_F_ECKEY_TYPE2PARAM, ERR_R_MALLOC_FAILURE); 163 ECerror(ERR_R_MALLOC_FAILURE);
164 goto ecerr; 164 goto ecerr;
165 } 165 }
166 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid)); 166 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));
@@ -171,7 +171,7 @@ eckey_type2param(int ptype, void *pval)
171 goto ecerr; 171 goto ecerr;
172 EC_GROUP_free(group); 172 EC_GROUP_free(group);
173 } else { 173 } else {
174 ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR); 174 ECerror(EC_R_DECODE_ERROR);
175 goto ecerr; 175 goto ecerr;
176 } 176 }
177 177
@@ -199,12 +199,12 @@ eckey_pub_decode(EVP_PKEY * pkey, X509_PUBKEY * pubkey)
199 eckey = eckey_type2param(ptype, pval); 199 eckey = eckey_type2param(ptype, pval);
200 200
201 if (!eckey) { 201 if (!eckey) {
202 ECerr(EC_F_ECKEY_PUB_DECODE, ERR_R_EC_LIB); 202 ECerror(ERR_R_EC_LIB);
203 return 0; 203 return 0;
204 } 204 }
205 /* We have parameters now set public key */ 205 /* We have parameters now set public key */
206 if (!o2i_ECPublicKey(&eckey, &p, pklen)) { 206 if (!o2i_ECPublicKey(&eckey, &p, pklen)) {
207 ECerr(EC_F_ECKEY_PUB_DECODE, EC_R_DECODE_ERROR); 207 ECerror(EC_R_DECODE_ERROR);
208 goto ecerr; 208 goto ecerr;
209 } 209 }
210 EVP_PKEY_assign_EC_KEY(pkey, eckey); 210 EVP_PKEY_assign_EC_KEY(pkey, eckey);
@@ -251,7 +251,7 @@ eckey_priv_decode(EVP_PKEY * pkey, PKCS8_PRIV_KEY_INFO * p8)
251 251
252 /* We have parameters now set private key */ 252 /* We have parameters now set private key */
253 if (!d2i_ECPrivateKey(&eckey, &p, pklen)) { 253 if (!d2i_ECPrivateKey(&eckey, &p, pklen)) {
254 ECerr(EC_F_ECKEY_PRIV_DECODE, EC_R_DECODE_ERROR); 254 ECerror(EC_R_DECODE_ERROR);
255 goto ecerr; 255 goto ecerr;
256 } 256 }
257 /* calculate public key (if necessary) */ 257 /* calculate public key (if necessary) */
@@ -266,23 +266,23 @@ eckey_priv_decode(EVP_PKEY * pkey, PKCS8_PRIV_KEY_INFO * p8)
266 group = EC_KEY_get0_group(eckey); 266 group = EC_KEY_get0_group(eckey);
267 pub_key = EC_POINT_new(group); 267 pub_key = EC_POINT_new(group);
268 if (pub_key == NULL) { 268 if (pub_key == NULL) {
269 ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB); 269 ECerror(ERR_R_EC_LIB);
270 goto ecliberr; 270 goto ecliberr;
271 } 271 }
272 if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group))) { 272 if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group))) {
273 EC_POINT_free(pub_key); 273 EC_POINT_free(pub_key);
274 ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB); 274 ECerror(ERR_R_EC_LIB);
275 goto ecliberr; 275 goto ecliberr;
276 } 276 }
277 priv_key = EC_KEY_get0_private_key(eckey); 277 priv_key = EC_KEY_get0_private_key(eckey);
278 if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, NULL)) { 278 if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, NULL)) {
279 EC_POINT_free(pub_key); 279 EC_POINT_free(pub_key);
280 ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB); 280 ECerror(ERR_R_EC_LIB);
281 goto ecliberr; 281 goto ecliberr;
282 } 282 }
283 if (EC_KEY_set_public_key(eckey, pub_key) == 0) { 283 if (EC_KEY_set_public_key(eckey, pub_key) == 0) {
284 EC_POINT_free(pub_key); 284 EC_POINT_free(pub_key);
285 ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB); 285 ECerror(ERR_R_EC_LIB);
286 goto ecliberr; 286 goto ecliberr;
287 } 287 }
288 EC_POINT_free(pub_key); 288 EC_POINT_free(pub_key);
@@ -291,7 +291,7 @@ eckey_priv_decode(EVP_PKEY * pkey, PKCS8_PRIV_KEY_INFO * p8)
291 return 1; 291 return 1;
292 292
293ecliberr: 293ecliberr:
294 ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB); 294 ECerror(ERR_R_EC_LIB);
295ecerr: 295ecerr:
296 if (eckey) 296 if (eckey)
297 EC_KEY_free(eckey); 297 EC_KEY_free(eckey);
@@ -310,7 +310,7 @@ eckey_priv_encode(PKCS8_PRIV_KEY_INFO * p8, const EVP_PKEY * pkey)
310 ec_key = pkey->pkey.ec; 310 ec_key = pkey->pkey.ec;
311 311
312 if (!eckey_param2type(&ptype, &pval, ec_key)) { 312 if (!eckey_param2type(&ptype, &pval, ec_key)) {
313 ECerr(EC_F_ECKEY_PRIV_ENCODE, EC_R_DECODE_ERROR); 313 ECerror(EC_R_DECODE_ERROR);
314 return 0; 314 return 0;
315 } 315 }
316 /* set the private key */ 316 /* set the private key */
@@ -325,20 +325,20 @@ eckey_priv_encode(PKCS8_PRIV_KEY_INFO * p8, const EVP_PKEY * pkey)
325 eplen = i2d_ECPrivateKey(ec_key, NULL); 325 eplen = i2d_ECPrivateKey(ec_key, NULL);
326 if (!eplen) { 326 if (!eplen) {
327 EC_KEY_set_enc_flags(ec_key, old_flags); 327 EC_KEY_set_enc_flags(ec_key, old_flags);
328 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB); 328 ECerror(ERR_R_EC_LIB);
329 return 0; 329 return 0;
330 } 330 }
331 ep = malloc(eplen); 331 ep = malloc(eplen);
332 if (!ep) { 332 if (!ep) {
333 EC_KEY_set_enc_flags(ec_key, old_flags); 333 EC_KEY_set_enc_flags(ec_key, old_flags);
334 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 334 ECerror(ERR_R_MALLOC_FAILURE);
335 return 0; 335 return 0;
336 } 336 }
337 p = ep; 337 p = ep;
338 if (!i2d_ECPrivateKey(ec_key, &p)) { 338 if (!i2d_ECPrivateKey(ec_key, &p)) {
339 EC_KEY_set_enc_flags(ec_key, old_flags); 339 EC_KEY_set_enc_flags(ec_key, old_flags);
340 free(ep); 340 free(ep);
341 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB); 341 ECerror(ERR_R_EC_LIB);
342 return 0; 342 return 0;
343 } 343 }
344 /* restore old encoding flags */ 344 /* restore old encoding flags */
@@ -483,7 +483,7 @@ do_EC_KEY_print(BIO * bp, const EC_KEY * x, int off, int ktype)
483 ret = 1; 483 ret = 1;
484err: 484err:
485 if (!ret) 485 if (!ret)
486 ECerr(EC_F_DO_EC_KEY_PRINT, reason); 486 ECerror(reason);
487 BN_free(pub_key); 487 BN_free(pub_key);
488 BN_free(order); 488 BN_free(order);
489 BN_CTX_free(ctx); 489 BN_CTX_free(ctx);
@@ -497,7 +497,7 @@ eckey_param_decode(EVP_PKEY * pkey,
497{ 497{
498 EC_KEY *eckey; 498 EC_KEY *eckey;
499 if (!(eckey = d2i_ECParameters(NULL, pder, derlen))) { 499 if (!(eckey = d2i_ECParameters(NULL, pder, derlen))) {
500 ECerr(EC_F_ECKEY_PARAM_DECODE, ERR_R_EC_LIB); 500 ECerror(ERR_R_EC_LIB);
501 return 0; 501 return 0;
502 } 502 }
503 EVP_PKEY_assign_EC_KEY(pkey, eckey); 503 EVP_PKEY_assign_EC_KEY(pkey, eckey);
@@ -538,7 +538,7 @@ old_ec_priv_decode(EVP_PKEY * pkey,
538{ 538{
539 EC_KEY *ec; 539 EC_KEY *ec;
540 if (!(ec = d2i_ECPrivateKey(NULL, pder, derlen))) { 540 if (!(ec = d2i_ECPrivateKey(NULL, pder, derlen))) {
541 ECerr(EC_F_OLD_EC_PRIV_DECODE, EC_R_DECODE_ERROR); 541 ECerror(EC_R_DECODE_ERROR);
542 return 0; 542 return 0;
543 } 543 }
544 EVP_PKEY_assign_EC_KEY(pkey, ec); 544 EVP_PKEY_assign_EC_KEY(pkey, ec);
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c
index 3234e7a6f2..dddf71c6e5 100644
--- a/src/lib/libcrypto/ec/ec_asn1.c
+++ b/src/lib/libcrypto/ec/ec_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_asn1.c,v 1.22 2016/03/20 16:50:29 krw Exp $ */ 1/* $OpenBSD: ec_asn1.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -96,7 +96,7 @@ EC_GROUP_get_trinomial_basis(const EC_GROUP * group, unsigned int *k)
96 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) != 96 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
97 NID_X9_62_characteristic_two_field 97 NID_X9_62_characteristic_two_field
98 || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] == 0))) { 98 || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] == 0))) {
99 ECerr(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 99 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
100 return 0; 100 return 0;
101 } 101 }
102 if (k) 102 if (k)
@@ -114,7 +114,7 @@ EC_GROUP_get_pentanomial_basis(const EC_GROUP * group, unsigned int *k1,
114 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) != 114 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
115 NID_X9_62_characteristic_two_field 115 NID_X9_62_characteristic_two_field
116 || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] != 0) && (group->poly[3] != 0) && (group->poly[4] == 0))) { 116 || !((group->poly[0] != 0) && (group->poly[1] != 0) && (group->poly[2] != 0) && (group->poly[3] != 0) && (group->poly[4] == 0))) {
117 ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 117 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
118 return 0; 118 return 0;
119 } 119 }
120 if (k1) 120 if (k1)
@@ -696,29 +696,29 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
696 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); 696 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
697 /* set OID for the field */ 697 /* set OID for the field */
698 if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) { 698 if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) {
699 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB); 699 ECerror(ERR_R_OBJ_LIB);
700 goto err; 700 goto err;
701 } 701 }
702 if (nid == NID_X9_62_prime_field) { 702 if (nid == NID_X9_62_prime_field) {
703 if ((tmp = BN_new()) == NULL) { 703 if ((tmp = BN_new()) == NULL) {
704 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); 704 ECerror(ERR_R_MALLOC_FAILURE);
705 goto err; 705 goto err;
706 } 706 }
707 /* the parameters are specified by the prime number p */ 707 /* the parameters are specified by the prime number p */
708 if (!EC_GROUP_get_curve_GFp(group, tmp, NULL, NULL, NULL)) { 708 if (!EC_GROUP_get_curve_GFp(group, tmp, NULL, NULL, NULL)) {
709 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB); 709 ECerror(ERR_R_EC_LIB);
710 goto err; 710 goto err;
711 } 711 }
712 /* set the prime number */ 712 /* set the prime number */
713 field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL); 713 field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL);
714 if (field->p.prime == NULL) { 714 if (field->p.prime == NULL) {
715 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB); 715 ECerror(ERR_R_ASN1_LIB);
716 goto err; 716 goto err;
717 } 717 }
718 } else /* nid == NID_X9_62_characteristic_two_field */ 718 } else /* nid == NID_X9_62_characteristic_two_field */
719#ifdef OPENSSL_NO_EC2M 719#ifdef OPENSSL_NO_EC2M
720 { 720 {
721 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, EC_R_GF2M_NOT_SUPPORTED); 721 ECerror(EC_R_GF2M_NOT_SUPPORTED);
722 goto err; 722 goto err;
723 } 723 }
724#else 724#else
@@ -730,7 +730,7 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
730 char_two = field->p.char_two; 730 char_two = field->p.char_two;
731 731
732 if (char_two == NULL) { 732 if (char_two == NULL) {
733 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); 733 ECerror(ERR_R_MALLOC_FAILURE);
734 goto err; 734 goto err;
735 } 735 }
736 char_two->m = (long) EC_GROUP_get_degree(group); 736 char_two->m = (long) EC_GROUP_get_degree(group);
@@ -738,12 +738,12 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
738 field_type = EC_GROUP_get_basis_type(group); 738 field_type = EC_GROUP_get_basis_type(group);
739 739
740 if (field_type == 0) { 740 if (field_type == 0) {
741 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB); 741 ECerror(ERR_R_EC_LIB);
742 goto err; 742 goto err;
743 } 743 }
744 /* set base type OID */ 744 /* set base type OID */
745 if ((char_two->type = OBJ_nid2obj(field_type)) == NULL) { 745 if ((char_two->type = OBJ_nid2obj(field_type)) == NULL) {
746 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB); 746 ECerror(ERR_R_OBJ_LIB);
747 goto err; 747 goto err;
748 } 748 }
749 if (field_type == NID_X9_62_tpBasis) { 749 if (field_type == NID_X9_62_tpBasis) {
@@ -754,12 +754,11 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
754 754
755 char_two->p.tpBasis = ASN1_INTEGER_new(); 755 char_two->p.tpBasis = ASN1_INTEGER_new();
756 if (!char_two->p.tpBasis) { 756 if (!char_two->p.tpBasis) {
757 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); 757 ECerror(ERR_R_MALLOC_FAILURE);
758 goto err; 758 goto err;
759 } 759 }
760 if (!ASN1_INTEGER_set(char_two->p.tpBasis, (long) k)) { 760 if (!ASN1_INTEGER_set(char_two->p.tpBasis, (long) k)) {
761 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, 761 ECerror(ERR_R_ASN1_LIB);
762 ERR_R_ASN1_LIB);
763 goto err; 762 goto err;
764 } 763 }
765 } else if (field_type == NID_X9_62_ppBasis) { 764 } else if (field_type == NID_X9_62_ppBasis) {
@@ -770,7 +769,7 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
770 769
771 char_two->p.ppBasis = X9_62_PENTANOMIAL_new(); 770 char_two->p.ppBasis = X9_62_PENTANOMIAL_new();
772 if (!char_two->p.ppBasis) { 771 if (!char_two->p.ppBasis) {
773 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); 772 ECerror(ERR_R_MALLOC_FAILURE);
774 goto err; 773 goto err;
775 } 774 }
776 /* set k? values */ 775 /* set k? values */
@@ -781,7 +780,7 @@ ec_asn1_group2fieldid(const EC_GROUP * group, X9_62_FIELDID * field)
781 /* for ONB the parameters are (asn1) NULL */ 780 /* for ONB the parameters are (asn1) NULL */
782 char_two->p.onBasis = ASN1_NULL_new(); 781 char_two->p.onBasis = ASN1_NULL_new();
783 if (!char_two->p.onBasis) { 782 if (!char_two->p.onBasis) {
784 ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE); 783 ECerror(ERR_R_MALLOC_FAILURE);
785 goto err; 784 goto err;
786 } 785 }
787 } 786 }
@@ -809,7 +808,7 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
809 return 0; 808 return 0;
810 809
811 if ((tmp_1 = BN_new()) == NULL || (tmp_2 = BN_new()) == NULL) { 810 if ((tmp_1 = BN_new()) == NULL || (tmp_2 = BN_new()) == NULL) {
812 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_MALLOC_FAILURE); 811 ECerror(ERR_R_MALLOC_FAILURE);
813 goto err; 812 goto err;
814 } 813 }
815 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group)); 814 nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
@@ -817,14 +816,14 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
817 /* get a and b */ 816 /* get a and b */
818 if (nid == NID_X9_62_prime_field) { 817 if (nid == NID_X9_62_prime_field) {
819 if (!EC_GROUP_get_curve_GFp(group, NULL, tmp_1, tmp_2, NULL)) { 818 if (!EC_GROUP_get_curve_GFp(group, NULL, tmp_1, tmp_2, NULL)) {
820 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_EC_LIB); 819 ECerror(ERR_R_EC_LIB);
821 goto err; 820 goto err;
822 } 821 }
823 } 822 }
824#ifndef OPENSSL_NO_EC2M 823#ifndef OPENSSL_NO_EC2M
825 else { /* nid == NID_X9_62_characteristic_two_field */ 824 else { /* nid == NID_X9_62_characteristic_two_field */
826 if (!EC_GROUP_get_curve_GF2m(group, NULL, tmp_1, tmp_2, NULL)) { 825 if (!EC_GROUP_get_curve_GF2m(group, NULL, tmp_1, tmp_2, NULL)) {
827 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_EC_LIB); 826 ECerror(ERR_R_EC_LIB);
828 goto err; 827 goto err;
829 } 828 }
830 } 829 }
@@ -838,12 +837,11 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
838 len_1 = 1; 837 len_1 = 1;
839 } else { 838 } else {
840 if ((buffer_1 = malloc(len_1)) == NULL) { 839 if ((buffer_1 = malloc(len_1)) == NULL) {
841 ECerr(EC_F_EC_ASN1_GROUP2CURVE, 840 ECerror(ERR_R_MALLOC_FAILURE);
842 ERR_R_MALLOC_FAILURE);
843 goto err; 841 goto err;
844 } 842 }
845 if ((len_1 = BN_bn2bin(tmp_1, buffer_1)) == 0) { 843 if ((len_1 = BN_bn2bin(tmp_1, buffer_1)) == 0) {
846 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_BN_LIB); 844 ECerror(ERR_R_BN_LIB);
847 goto err; 845 goto err;
848 } 846 }
849 a_buf = buffer_1; 847 a_buf = buffer_1;
@@ -855,12 +853,11 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
855 len_2 = 1; 853 len_2 = 1;
856 } else { 854 } else {
857 if ((buffer_2 = malloc(len_2)) == NULL) { 855 if ((buffer_2 = malloc(len_2)) == NULL) {
858 ECerr(EC_F_EC_ASN1_GROUP2CURVE, 856 ECerror(ERR_R_MALLOC_FAILURE);
859 ERR_R_MALLOC_FAILURE);
860 goto err; 857 goto err;
861 } 858 }
862 if ((len_2 = BN_bn2bin(tmp_2, buffer_2)) == 0) { 859 if ((len_2 = BN_bn2bin(tmp_2, buffer_2)) == 0) {
863 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_BN_LIB); 860 ECerror(ERR_R_BN_LIB);
864 goto err; 861 goto err;
865 } 862 }
866 b_buf = buffer_2; 863 b_buf = buffer_2;
@@ -869,21 +866,21 @@ ec_asn1_group2curve(const EC_GROUP * group, X9_62_CURVE * curve)
869 /* set a and b */ 866 /* set a and b */
870 if (!ASN1_STRING_set(curve->a, a_buf, len_1) || 867 if (!ASN1_STRING_set(curve->a, a_buf, len_1) ||
871 !ASN1_STRING_set(curve->b, b_buf, len_2)) { 868 !ASN1_STRING_set(curve->b, b_buf, len_2)) {
872 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_ASN1_LIB); 869 ECerror(ERR_R_ASN1_LIB);
873 goto err; 870 goto err;
874 } 871 }
875 /* set the seed (optional) */ 872 /* set the seed (optional) */
876 if (group->seed) { 873 if (group->seed) {
877 if (!curve->seed) 874 if (!curve->seed)
878 if ((curve->seed = ASN1_BIT_STRING_new()) == NULL) { 875 if ((curve->seed = ASN1_BIT_STRING_new()) == NULL) {
879 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_MALLOC_FAILURE); 876 ECerror(ERR_R_MALLOC_FAILURE);
880 goto err; 877 goto err;
881 } 878 }
882 curve->seed->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); 879 curve->seed->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
883 curve->seed->flags |= ASN1_STRING_FLAG_BITS_LEFT; 880 curve->seed->flags |= ASN1_STRING_FLAG_BITS_LEFT;
884 if (!ASN1_BIT_STRING_set(curve->seed, group->seed, 881 if (!ASN1_BIT_STRING_set(curve->seed, group->seed,
885 (int) group->seed_len)) { 882 (int) group->seed_len)) {
886 ECerr(EC_F_EC_ASN1_GROUP2CURVE, ERR_R_ASN1_LIB); 883 ECerror(ERR_R_ASN1_LIB);
887 goto err; 884 goto err;
888 } 885 }
889 } else { 886 } else {
@@ -915,13 +912,12 @@ ec_asn1_group2parameters(const EC_GROUP * group, ECPARAMETERS * param)
915 point_conversion_form_t form; 912 point_conversion_form_t form;
916 913
917 if ((tmp = BN_new()) == NULL) { 914 if ((tmp = BN_new()) == NULL) {
918 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); 915 ECerror(ERR_R_MALLOC_FAILURE);
919 goto err; 916 goto err;
920 } 917 }
921 if (param == NULL) { 918 if (param == NULL) {
922 if ((ret = ECPARAMETERS_new()) == NULL) { 919 if ((ret = ECPARAMETERS_new()) == NULL) {
923 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, 920 ECerror(ERR_R_MALLOC_FAILURE);
924 ERR_R_MALLOC_FAILURE);
925 goto err; 921 goto err;
926 } 922 }
927 } else 923 } else
@@ -932,57 +928,57 @@ ec_asn1_group2parameters(const EC_GROUP * group, ECPARAMETERS * param)
932 928
933 /* set the fieldID */ 929 /* set the fieldID */
934 if (!ec_asn1_group2fieldid(group, ret->fieldID)) { 930 if (!ec_asn1_group2fieldid(group, ret->fieldID)) {
935 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 931 ECerror(ERR_R_EC_LIB);
936 goto err; 932 goto err;
937 } 933 }
938 /* set the curve */ 934 /* set the curve */
939 if (!ec_asn1_group2curve(group, ret->curve)) { 935 if (!ec_asn1_group2curve(group, ret->curve)) {
940 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 936 ECerror(ERR_R_EC_LIB);
941 goto err; 937 goto err;
942 } 938 }
943 /* set the base point */ 939 /* set the base point */
944 if ((point = EC_GROUP_get0_generator(group)) == NULL) { 940 if ((point = EC_GROUP_get0_generator(group)) == NULL) {
945 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, EC_R_UNDEFINED_GENERATOR); 941 ECerror(EC_R_UNDEFINED_GENERATOR);
946 goto err; 942 goto err;
947 } 943 }
948 form = EC_GROUP_get_point_conversion_form(group); 944 form = EC_GROUP_get_point_conversion_form(group);
949 945
950 len = EC_POINT_point2oct(group, point, form, NULL, len, NULL); 946 len = EC_POINT_point2oct(group, point, form, NULL, len, NULL);
951 if (len == 0) { 947 if (len == 0) {
952 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 948 ECerror(ERR_R_EC_LIB);
953 goto err; 949 goto err;
954 } 950 }
955 if ((buffer = malloc(len)) == NULL) { 951 if ((buffer = malloc(len)) == NULL) {
956 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); 952 ECerror(ERR_R_MALLOC_FAILURE);
957 goto err; 953 goto err;
958 } 954 }
959 if (!EC_POINT_point2oct(group, point, form, buffer, len, NULL)) { 955 if (!EC_POINT_point2oct(group, point, form, buffer, len, NULL)) {
960 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 956 ECerror(ERR_R_EC_LIB);
961 goto err; 957 goto err;
962 } 958 }
963 if (ret->base == NULL && (ret->base = ASN1_OCTET_STRING_new()) == NULL) { 959 if (ret->base == NULL && (ret->base = ASN1_OCTET_STRING_new()) == NULL) {
964 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); 960 ECerror(ERR_R_MALLOC_FAILURE);
965 goto err; 961 goto err;
966 } 962 }
967 if (!ASN1_OCTET_STRING_set(ret->base, buffer, len)) { 963 if (!ASN1_OCTET_STRING_set(ret->base, buffer, len)) {
968 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_ASN1_LIB); 964 ECerror(ERR_R_ASN1_LIB);
969 goto err; 965 goto err;
970 } 966 }
971 /* set the order */ 967 /* set the order */
972 if (!EC_GROUP_get_order(group, tmp, NULL)) { 968 if (!EC_GROUP_get_order(group, tmp, NULL)) {
973 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 969 ECerror(ERR_R_EC_LIB);
974 goto err; 970 goto err;
975 } 971 }
976 ret->order = BN_to_ASN1_INTEGER(tmp, ret->order); 972 ret->order = BN_to_ASN1_INTEGER(tmp, ret->order);
977 if (ret->order == NULL) { 973 if (ret->order == NULL) {
978 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_ASN1_LIB); 974 ECerror(ERR_R_ASN1_LIB);
979 goto err; 975 goto err;
980 } 976 }
981 /* set the cofactor (optional) */ 977 /* set the cofactor (optional) */
982 if (EC_GROUP_get_cofactor(group, tmp, NULL)) { 978 if (EC_GROUP_get_cofactor(group, tmp, NULL)) {
983 ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor); 979 ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor);
984 if (ret->cofactor == NULL) { 980 if (ret->cofactor == NULL) {
985 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_ASN1_LIB); 981 ECerror(ERR_R_ASN1_LIB);
986 goto err; 982 goto err;
987 } 983 }
988 } 984 }
@@ -1006,8 +1002,7 @@ ec_asn1_group2pkparameters(const EC_GROUP * group, ECPKPARAMETERS * params)
1006 1002
1007 if (ret == NULL) { 1003 if (ret == NULL) {
1008 if ((ret = ECPKPARAMETERS_new()) == NULL) { 1004 if ((ret = ECPKPARAMETERS_new()) == NULL) {
1009 ECerr(EC_F_EC_ASN1_GROUP2PKPARAMETERS, 1005 ECerror(ERR_R_MALLOC_FAILURE);
1010 ERR_R_MALLOC_FAILURE);
1011 return NULL; 1006 return NULL;
1012 } 1007 }
1013 } else { 1008 } else {
@@ -1056,24 +1051,24 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1056 1051
1057 if (!params->fieldID || !params->fieldID->fieldType || 1052 if (!params->fieldID || !params->fieldID->fieldType ||
1058 !params->fieldID->p.ptr) { 1053 !params->fieldID->p.ptr) {
1059 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1054 ECerror(EC_R_ASN1_ERROR);
1060 goto err; 1055 goto err;
1061 } 1056 }
1062 /* now extract the curve parameters a and b */ 1057 /* now extract the curve parameters a and b */
1063 if (!params->curve || !params->curve->a || 1058 if (!params->curve || !params->curve->a ||
1064 !params->curve->a->data || !params->curve->b || 1059 !params->curve->a->data || !params->curve->b ||
1065 !params->curve->b->data) { 1060 !params->curve->b->data) {
1066 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1061 ECerror(EC_R_ASN1_ERROR);
1067 goto err; 1062 goto err;
1068 } 1063 }
1069 a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL); 1064 a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);
1070 if (a == NULL) { 1065 if (a == NULL) {
1071 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB); 1066 ECerror(ERR_R_BN_LIB);
1072 goto err; 1067 goto err;
1073 } 1068 }
1074 b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL); 1069 b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);
1075 if (b == NULL) { 1070 if (b == NULL) {
1076 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB); 1071 ECerror(ERR_R_BN_LIB);
1077 goto err; 1072 goto err;
1078 } 1073 }
1079 /* get the field parameters */ 1074 /* get the field parameters */
@@ -1081,7 +1076,7 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1081 if (tmp == NID_X9_62_characteristic_two_field) 1076 if (tmp == NID_X9_62_characteristic_two_field)
1082#ifdef OPENSSL_NO_EC2M 1077#ifdef OPENSSL_NO_EC2M
1083 { 1078 {
1084 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_GF2M_NOT_SUPPORTED); 1079 ECerror(EC_R_GF2M_NOT_SUPPORTED);
1085 goto err; 1080 goto err;
1086 } 1081 }
1087#else 1082#else
@@ -1092,11 +1087,11 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1092 1087
1093 field_bits = char_two->m; 1088 field_bits = char_two->m;
1094 if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) { 1089 if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
1095 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE); 1090 ECerror(EC_R_FIELD_TOO_LARGE);
1096 goto err; 1091 goto err;
1097 } 1092 }
1098 if ((p = BN_new()) == NULL) { 1093 if ((p = BN_new()) == NULL) {
1099 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE); 1094 ECerror(ERR_R_MALLOC_FAILURE);
1100 goto err; 1095 goto err;
1101 } 1096 }
1102 /* get the base type */ 1097 /* get the base type */
@@ -1106,13 +1101,13 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1106 long tmp_long; 1101 long tmp_long;
1107 1102
1108 if (!char_two->p.tpBasis) { 1103 if (!char_two->p.tpBasis) {
1109 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1104 ECerror(EC_R_ASN1_ERROR);
1110 goto err; 1105 goto err;
1111 } 1106 }
1112 tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis); 1107 tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);
1113 1108
1114 if (!(char_two->m > tmp_long && tmp_long > 0)) { 1109 if (!(char_two->m > tmp_long && tmp_long > 0)) {
1115 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_TRINOMIAL_BASIS); 1110 ECerror(EC_R_INVALID_TRINOMIAL_BASIS);
1116 goto err; 1111 goto err;
1117 } 1112 }
1118 /* create the polynomial */ 1113 /* create the polynomial */
@@ -1127,11 +1122,11 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1127 1122
1128 penta = char_two->p.ppBasis; 1123 penta = char_two->p.ppBasis;
1129 if (!penta) { 1124 if (!penta) {
1130 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1125 ECerror(EC_R_ASN1_ERROR);
1131 goto err; 1126 goto err;
1132 } 1127 }
1133 if (!(char_two->m > penta->k3 && penta->k3 > penta->k2 && penta->k2 > penta->k1 && penta->k1 > 0)) { 1128 if (!(char_two->m > penta->k3 && penta->k3 > penta->k2 && penta->k2 > penta->k1 && penta->k1 > 0)) {
1134 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_PENTANOMIAL_BASIS); 1129 ECerror(EC_R_INVALID_PENTANOMIAL_BASIS);
1135 goto err; 1130 goto err;
1136 } 1131 }
1137 /* create the polynomial */ 1132 /* create the polynomial */
@@ -1146,10 +1141,10 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1146 if (!BN_set_bit(p, 0)) 1141 if (!BN_set_bit(p, 0))
1147 goto err; 1142 goto err;
1148 } else if (tmp == NID_X9_62_onBasis) { 1143 } else if (tmp == NID_X9_62_onBasis) {
1149 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_NOT_IMPLEMENTED); 1144 ECerror(EC_R_NOT_IMPLEMENTED);
1150 goto err; 1145 goto err;
1151 } else { /* error */ 1146 } else { /* error */
1152 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1147 ECerror(EC_R_ASN1_ERROR);
1153 goto err; 1148 goto err;
1154 } 1149 }
1155 1150
@@ -1161,40 +1156,39 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1161 /* we have a curve over a prime field */ 1156 /* we have a curve over a prime field */
1162 /* extract the prime number */ 1157 /* extract the prime number */
1163 if (!params->fieldID->p.prime) { 1158 if (!params->fieldID->p.prime) {
1164 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1159 ECerror(EC_R_ASN1_ERROR);
1165 goto err; 1160 goto err;
1166 } 1161 }
1167 p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL); 1162 p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);
1168 if (p == NULL) { 1163 if (p == NULL) {
1169 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB); 1164 ECerror(ERR_R_ASN1_LIB);
1170 goto err; 1165 goto err;
1171 } 1166 }
1172 if (BN_is_negative(p) || BN_is_zero(p)) { 1167 if (BN_is_negative(p) || BN_is_zero(p)) {
1173 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD); 1168 ECerror(EC_R_INVALID_FIELD);
1174 goto err; 1169 goto err;
1175 } 1170 }
1176 field_bits = BN_num_bits(p); 1171 field_bits = BN_num_bits(p);
1177 if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) { 1172 if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
1178 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE); 1173 ECerror(EC_R_FIELD_TOO_LARGE);
1179 goto err; 1174 goto err;
1180 } 1175 }
1181 /* create the EC_GROUP structure */ 1176 /* create the EC_GROUP structure */
1182 ret = EC_GROUP_new_curve_GFp(p, a, b, NULL); 1177 ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);
1183 } else { 1178 } else {
1184 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD); 1179 ECerror(EC_R_INVALID_FIELD);
1185 goto err; 1180 goto err;
1186 } 1181 }
1187 1182
1188 if (ret == NULL) { 1183 if (ret == NULL) {
1189 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB); 1184 ECerror(ERR_R_EC_LIB);
1190 goto err; 1185 goto err;
1191 } 1186 }
1192 /* extract seed (optional) */ 1187 /* extract seed (optional) */
1193 if (params->curve->seed != NULL) { 1188 if (params->curve->seed != NULL) {
1194 free(ret->seed); 1189 free(ret->seed);
1195 if (!(ret->seed = malloc(params->curve->seed->length))) { 1190 if (!(ret->seed = malloc(params->curve->seed->length))) {
1196 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, 1191 ECerror(ERR_R_MALLOC_FAILURE);
1197 ERR_R_MALLOC_FAILURE);
1198 goto err; 1192 goto err;
1199 } 1193 }
1200 memcpy(ret->seed, params->curve->seed->data, 1194 memcpy(ret->seed, params->curve->seed->data,
@@ -1202,7 +1196,7 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1202 ret->seed_len = params->curve->seed->length; 1196 ret->seed_len = params->curve->seed->length;
1203 } 1197 }
1204 if (!params->order || !params->base || !params->base->data) { 1198 if (!params->order || !params->base || !params->base->data) {
1205 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR); 1199 ECerror(EC_R_ASN1_ERROR);
1206 goto err; 1200 goto err;
1207 } 1201 }
1208 if ((point = EC_POINT_new(ret)) == NULL) 1202 if ((point = EC_POINT_new(ret)) == NULL)
@@ -1215,20 +1209,20 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1215 /* extract the ec point */ 1209 /* extract the ec point */
1216 if (!EC_POINT_oct2point(ret, point, params->base->data, 1210 if (!EC_POINT_oct2point(ret, point, params->base->data,
1217 params->base->length, NULL)) { 1211 params->base->length, NULL)) {
1218 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB); 1212 ECerror(ERR_R_EC_LIB);
1219 goto err; 1213 goto err;
1220 } 1214 }
1221 /* extract the order */ 1215 /* extract the order */
1222 if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) { 1216 if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {
1223 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB); 1217 ECerror(ERR_R_ASN1_LIB);
1224 goto err; 1218 goto err;
1225 } 1219 }
1226 if (BN_is_negative(a) || BN_is_zero(a)) { 1220 if (BN_is_negative(a) || BN_is_zero(a)) {
1227 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER); 1221 ECerror(EC_R_INVALID_GROUP_ORDER);
1228 goto err; 1222 goto err;
1229 } 1223 }
1230 if (BN_num_bits(a) > (int) field_bits + 1) { /* Hasse bound */ 1224 if (BN_num_bits(a) > (int) field_bits + 1) { /* Hasse bound */
1231 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER); 1225 ECerror(EC_R_INVALID_GROUP_ORDER);
1232 goto err; 1226 goto err;
1233 } 1227 }
1234 /* extract the cofactor (optional) */ 1228 /* extract the cofactor (optional) */
@@ -1236,12 +1230,12 @@ ec_asn1_parameters2group(const ECPARAMETERS * params)
1236 BN_free(b); 1230 BN_free(b);
1237 b = NULL; 1231 b = NULL;
1238 } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) { 1232 } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
1239 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB); 1233 ECerror(ERR_R_ASN1_LIB);
1240 goto err; 1234 goto err;
1241 } 1235 }
1242 /* set the generator, order and cofactor (if present) */ 1236 /* set the generator, order and cofactor (if present) */
1243 if (!EC_GROUP_set_generator(ret, point, a, b)) { 1237 if (!EC_GROUP_set_generator(ret, point, a, b)) {
1244 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB); 1238 ECerror(ERR_R_EC_LIB);
1245 goto err; 1239 goto err;
1246 } 1240 }
1247 ok = 1; 1241 ok = 1;
@@ -1264,15 +1258,13 @@ ec_asn1_pkparameters2group(const ECPKPARAMETERS * params)
1264 int tmp = 0; 1258 int tmp = 0;
1265 1259
1266 if (params == NULL) { 1260 if (params == NULL) {
1267 ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, 1261 ECerror(EC_R_MISSING_PARAMETERS);
1268 EC_R_MISSING_PARAMETERS);
1269 return NULL; 1262 return NULL;
1270 } 1263 }
1271 if (params->type == 0) {/* the curve is given by an OID */ 1264 if (params->type == 0) {/* the curve is given by an OID */
1272 tmp = OBJ_obj2nid(params->value.named_curve); 1265 tmp = OBJ_obj2nid(params->value.named_curve);
1273 if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) { 1266 if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) {
1274 ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, 1267 ECerror(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
1275 EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
1276 return NULL; 1268 return NULL;
1277 } 1269 }
1278 EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE); 1270 EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE);
@@ -1280,14 +1272,14 @@ ec_asn1_pkparameters2group(const ECPKPARAMETERS * params)
1280 * ECPARAMETERS structure */ 1272 * ECPARAMETERS structure */
1281 ret = ec_asn1_parameters2group(params->value.parameters); 1273 ret = ec_asn1_parameters2group(params->value.parameters);
1282 if (!ret) { 1274 if (!ret) {
1283 ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, ERR_R_EC_LIB); 1275 ECerror(ERR_R_EC_LIB);
1284 return NULL; 1276 return NULL;
1285 } 1277 }
1286 EC_GROUP_set_asn1_flag(ret, 0x0); 1278 EC_GROUP_set_asn1_flag(ret, 0x0);
1287 } else if (params->type == 2) { /* implicitlyCA */ 1279 } else if (params->type == 2) { /* implicitlyCA */
1288 return NULL; 1280 return NULL;
1289 } else { 1281 } else {
1290 ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_ASN1_ERROR); 1282 ECerror(EC_R_ASN1_ERROR);
1291 return NULL; 1283 return NULL;
1292 } 1284 }
1293 1285
@@ -1303,11 +1295,11 @@ d2i_ECPKParameters(EC_GROUP ** a, const unsigned char **in, long len)
1303 ECPKPARAMETERS *params = NULL; 1295 ECPKPARAMETERS *params = NULL;
1304 1296
1305 if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) { 1297 if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) {
1306 ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_D2I_ECPKPARAMETERS_FAILURE); 1298 ECerror(EC_R_D2I_ECPKPARAMETERS_FAILURE);
1307 goto err; 1299 goto err;
1308 } 1300 }
1309 if ((group = ec_asn1_pkparameters2group(params)) == NULL) { 1301 if ((group = ec_asn1_pkparameters2group(params)) == NULL) {
1310 ECerr(EC_F_D2I_ECPKPARAMETERS, EC_R_PKPARAMETERS2GROUP_FAILURE); 1302 ECerror(EC_R_PKPARAMETERS2GROUP_FAILURE);
1311 goto err; 1303 goto err;
1312 } 1304 }
1313 1305
@@ -1327,11 +1319,11 @@ i2d_ECPKParameters(const EC_GROUP * a, unsigned char **out)
1327 int ret = 0; 1319 int ret = 0;
1328 ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL); 1320 ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL);
1329 if (tmp == NULL) { 1321 if (tmp == NULL) {
1330 ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_GROUP2PKPARAMETERS_FAILURE); 1322 ECerror(EC_R_GROUP2PKPARAMETERS_FAILURE);
1331 return 0; 1323 return 0;
1332 } 1324 }
1333 if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) { 1325 if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) {
1334 ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_I2D_ECPKPARAMETERS_FAILURE); 1326 ECerror(EC_R_I2D_ECPKPARAMETERS_FAILURE);
1335 ECPKPARAMETERS_free(tmp); 1327 ECPKPARAMETERS_free(tmp);
1336 return 0; 1328 return 0;
1337 } 1329 }
@@ -1348,17 +1340,17 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1348 EC_PRIVATEKEY *priv_key = NULL; 1340 EC_PRIVATEKEY *priv_key = NULL;
1349 1341
1350 if ((priv_key = EC_PRIVATEKEY_new()) == NULL) { 1342 if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
1351 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); 1343 ECerror(ERR_R_MALLOC_FAILURE);
1352 return NULL; 1344 return NULL;
1353 } 1345 }
1354 if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL) { 1346 if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL) {
1355 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); 1347 ECerror(ERR_R_EC_LIB);
1356 EC_PRIVATEKEY_free(priv_key); 1348 EC_PRIVATEKEY_free(priv_key);
1357 return NULL; 1349 return NULL;
1358 } 1350 }
1359 if (a == NULL || *a == NULL) { 1351 if (a == NULL || *a == NULL) {
1360 if ((ret = EC_KEY_new()) == NULL) { 1352 if ((ret = EC_KEY_new()) == NULL) {
1361 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); 1353 ECerror(ERR_R_MALLOC_FAILURE);
1362 goto err; 1354 goto err;
1363 } 1355 }
1364 } else 1356 } else
@@ -1369,7 +1361,7 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1369 ret->group = ec_asn1_pkparameters2group(priv_key->parameters); 1361 ret->group = ec_asn1_pkparameters2group(priv_key->parameters);
1370 } 1362 }
1371 if (ret->group == NULL) { 1363 if (ret->group == NULL) {
1372 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); 1364 ECerror(ERR_R_EC_LIB);
1373 goto err; 1365 goto err;
1374 } 1366 }
1375 ret->version = priv_key->version; 1367 ret->version = priv_key->version;
@@ -1380,13 +1372,11 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1380 ASN1_STRING_length(priv_key->privateKey), 1372 ASN1_STRING_length(priv_key->privateKey),
1381 ret->priv_key); 1373 ret->priv_key);
1382 if (ret->priv_key == NULL) { 1374 if (ret->priv_key == NULL) {
1383 ECerr(EC_F_D2I_ECPRIVATEKEY, 1375 ECerror(ERR_R_BN_LIB);
1384 ERR_R_BN_LIB);
1385 goto err; 1376 goto err;
1386 } 1377 }
1387 } else { 1378 } else {
1388 ECerr(EC_F_D2I_ECPRIVATEKEY, 1379 ECerror(EC_R_MISSING_PRIVATE_KEY);
1389 EC_R_MISSING_PRIVATE_KEY);
1390 goto err; 1380 goto err;
1391 } 1381 }
1392 1382
@@ -1397,7 +1387,7 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1397 EC_POINT_clear_free(ret->pub_key); 1387 EC_POINT_clear_free(ret->pub_key);
1398 ret->pub_key = EC_POINT_new(ret->group); 1388 ret->pub_key = EC_POINT_new(ret->group);
1399 if (ret->pub_key == NULL) { 1389 if (ret->pub_key == NULL) {
1400 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); 1390 ECerror(ERR_R_EC_LIB);
1401 goto err; 1391 goto err;
1402 } 1392 }
1403 pub_oct = ASN1_STRING_data(priv_key->publicKey); 1393 pub_oct = ASN1_STRING_data(priv_key->publicKey);
@@ -1406,7 +1396,7 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
1406 ret->conv_form = (point_conversion_form_t) (pub_oct[0] & ~0x01); 1396 ret->conv_form = (point_conversion_form_t) (pub_oct[0] & ~0x01);
1407 if (!EC_POINT_oct2point(ret->group, ret->pub_key, 1397 if (!EC_POINT_oct2point(ret->group, ret->pub_key,
1408 pub_oct, pub_oct_len, NULL)) { 1398 pub_oct, pub_oct_len, NULL)) {
1409 ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB); 1399 ECerror(ERR_R_EC_LIB);
1410 goto err; 1400 goto err;
1411 } 1401 }
1412 } 1402 }
@@ -1434,13 +1424,11 @@ i2d_ECPrivateKey(EC_KEY * a, unsigned char **out)
1434 EC_PRIVATEKEY *priv_key = NULL; 1424 EC_PRIVATEKEY *priv_key = NULL;
1435 1425
1436 if (a == NULL || a->group == NULL || a->priv_key == NULL) { 1426 if (a == NULL || a->group == NULL || a->priv_key == NULL) {
1437 ECerr(EC_F_I2D_ECPRIVATEKEY, 1427 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1438 ERR_R_PASSED_NULL_PARAMETER);
1439 goto err; 1428 goto err;
1440 } 1429 }
1441 if ((priv_key = EC_PRIVATEKEY_new()) == NULL) { 1430 if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
1442 ECerr(EC_F_I2D_ECPRIVATEKEY, 1431 ECerror(ERR_R_MALLOC_FAILURE);
1443 ERR_R_MALLOC_FAILURE);
1444 goto err; 1432 goto err;
1445 } 1433 }
1446 priv_key->version = a->version; 1434 priv_key->version = a->version;
@@ -1448,30 +1436,28 @@ i2d_ECPrivateKey(EC_KEY * a, unsigned char **out)
1448 buf_len = (size_t) BN_num_bytes(a->priv_key); 1436 buf_len = (size_t) BN_num_bytes(a->priv_key);
1449 buffer = malloc(buf_len); 1437 buffer = malloc(buf_len);
1450 if (buffer == NULL) { 1438 if (buffer == NULL) {
1451 ECerr(EC_F_I2D_ECPRIVATEKEY, 1439 ECerror(ERR_R_MALLOC_FAILURE);
1452 ERR_R_MALLOC_FAILURE);
1453 goto err; 1440 goto err;
1454 } 1441 }
1455 if (!BN_bn2bin(a->priv_key, buffer)) { 1442 if (!BN_bn2bin(a->priv_key, buffer)) {
1456 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_BN_LIB); 1443 ECerror(ERR_R_BN_LIB);
1457 goto err; 1444 goto err;
1458 } 1445 }
1459 if (!ASN1_STRING_set(priv_key->privateKey, buffer, buf_len)) { 1446 if (!ASN1_STRING_set(priv_key->privateKey, buffer, buf_len)) {
1460 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB); 1447 ECerror(ERR_R_ASN1_LIB);
1461 goto err; 1448 goto err;
1462 } 1449 }
1463 if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) { 1450 if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) {
1464 if ((priv_key->parameters = ec_asn1_group2pkparameters( 1451 if ((priv_key->parameters = ec_asn1_group2pkparameters(
1465 a->group, priv_key->parameters)) == NULL) { 1452 a->group, priv_key->parameters)) == NULL) {
1466 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); 1453 ECerror(ERR_R_EC_LIB);
1467 goto err; 1454 goto err;
1468 } 1455 }
1469 } 1456 }
1470 if (!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key != NULL) { 1457 if (!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key != NULL) {
1471 priv_key->publicKey = ASN1_BIT_STRING_new(); 1458 priv_key->publicKey = ASN1_BIT_STRING_new();
1472 if (priv_key->publicKey == NULL) { 1459 if (priv_key->publicKey == NULL) {
1473 ECerr(EC_F_I2D_ECPRIVATEKEY, 1460 ECerror(ERR_R_MALLOC_FAILURE);
1474 ERR_R_MALLOC_FAILURE);
1475 goto err; 1461 goto err;
1476 } 1462 }
1477 tmp_len = EC_POINT_point2oct(a->group, a->pub_key, 1463 tmp_len = EC_POINT_point2oct(a->group, a->pub_key,
@@ -1480,7 +1466,7 @@ i2d_ECPrivateKey(EC_KEY * a, unsigned char **out)
1480 if (tmp_len > buf_len) { 1466 if (tmp_len > buf_len) {
1481 unsigned char *tmp_buffer = realloc(buffer, tmp_len); 1467 unsigned char *tmp_buffer = realloc(buffer, tmp_len);
1482 if (!tmp_buffer) { 1468 if (!tmp_buffer) {
1483 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); 1469 ECerror(ERR_R_MALLOC_FAILURE);
1484 goto err; 1470 goto err;
1485 } 1471 }
1486 buffer = tmp_buffer; 1472 buffer = tmp_buffer;
@@ -1488,19 +1474,19 @@ i2d_ECPrivateKey(EC_KEY * a, unsigned char **out)
1488 } 1474 }
1489 if (!EC_POINT_point2oct(a->group, a->pub_key, 1475 if (!EC_POINT_point2oct(a->group, a->pub_key,
1490 a->conv_form, buffer, buf_len, NULL)) { 1476 a->conv_form, buffer, buf_len, NULL)) {
1491 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); 1477 ECerror(ERR_R_EC_LIB);
1492 goto err; 1478 goto err;
1493 } 1479 }
1494 priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); 1480 priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
1495 priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT; 1481 priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
1496 if (!ASN1_STRING_set(priv_key->publicKey, buffer, 1482 if (!ASN1_STRING_set(priv_key->publicKey, buffer,
1497 buf_len)) { 1483 buf_len)) {
1498 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB); 1484 ECerror(ERR_R_ASN1_LIB);
1499 goto err; 1485 goto err;
1500 } 1486 }
1501 } 1487 }
1502 if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) { 1488 if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) {
1503 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB); 1489 ECerror(ERR_R_EC_LIB);
1504 goto err; 1490 goto err;
1505 } 1491 }
1506 ok = 1; 1492 ok = 1;
@@ -1515,7 +1501,7 @@ int
1515i2d_ECParameters(EC_KEY * a, unsigned char **out) 1501i2d_ECParameters(EC_KEY * a, unsigned char **out)
1516{ 1502{
1517 if (a == NULL) { 1503 if (a == NULL) {
1518 ECerr(EC_F_I2D_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER); 1504 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1519 return 0; 1505 return 0;
1520 } 1506 }
1521 return i2d_ECPKParameters(a->group, out); 1507 return i2d_ECPKParameters(a->group, out);
@@ -1527,19 +1513,19 @@ d2i_ECParameters(EC_KEY ** a, const unsigned char **in, long len)
1527 EC_KEY *ret; 1513 EC_KEY *ret;
1528 1514
1529 if (in == NULL || *in == NULL) { 1515 if (in == NULL || *in == NULL) {
1530 ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER); 1516 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1531 return NULL; 1517 return NULL;
1532 } 1518 }
1533 if (a == NULL || *a == NULL) { 1519 if (a == NULL || *a == NULL) {
1534 if ((ret = EC_KEY_new()) == NULL) { 1520 if ((ret = EC_KEY_new()) == NULL) {
1535 ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_MALLOC_FAILURE); 1521 ECerror(ERR_R_MALLOC_FAILURE);
1536 return NULL; 1522 return NULL;
1537 } 1523 }
1538 } else 1524 } else
1539 ret = *a; 1525 ret = *a;
1540 1526
1541 if (!d2i_ECPKParameters(&ret->group, in, len)) { 1527 if (!d2i_ECPKParameters(&ret->group, in, len)) {
1542 ECerr(EC_F_D2I_ECPARAMETERS, ERR_R_EC_LIB); 1528 ECerror(ERR_R_EC_LIB);
1543 if (a == NULL || *a != ret) 1529 if (a == NULL || *a != ret)
1544 EC_KEY_free(ret); 1530 EC_KEY_free(ret);
1545 return NULL; 1531 return NULL;
@@ -1560,17 +1546,17 @@ o2i_ECPublicKey(EC_KEY ** a, const unsigned char **in, long len)
1560 * sorry, but a EC_GROUP-structur is necessary to set the 1546 * sorry, but a EC_GROUP-structur is necessary to set the
1561 * public key 1547 * public key
1562 */ 1548 */
1563 ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER); 1549 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1564 return 0; 1550 return 0;
1565 } 1551 }
1566 ret = *a; 1552 ret = *a;
1567 if (ret->pub_key == NULL && 1553 if (ret->pub_key == NULL &&
1568 (ret->pub_key = EC_POINT_new(ret->group)) == NULL) { 1554 (ret->pub_key = EC_POINT_new(ret->group)) == NULL) {
1569 ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_MALLOC_FAILURE); 1555 ECerror(ERR_R_MALLOC_FAILURE);
1570 return 0; 1556 return 0;
1571 } 1557 }
1572 if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) { 1558 if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) {
1573 ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB); 1559 ECerror(ERR_R_EC_LIB);
1574 return 0; 1560 return 0;
1575 } 1561 }
1576 /* save the point conversion form */ 1562 /* save the point conversion form */
@@ -1586,7 +1572,7 @@ i2o_ECPublicKey(EC_KEY * a, unsigned char **out)
1586 int new_buffer = 0; 1572 int new_buffer = 0;
1587 1573
1588 if (a == NULL) { 1574 if (a == NULL) {
1589 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER); 1575 ECerror(ERR_R_PASSED_NULL_PARAMETER);
1590 return 0; 1576 return 0;
1591 } 1577 }
1592 buf_len = EC_POINT_point2oct(a->group, a->pub_key, 1578 buf_len = EC_POINT_point2oct(a->group, a->pub_key,
@@ -1598,14 +1584,14 @@ i2o_ECPublicKey(EC_KEY * a, unsigned char **out)
1598 1584
1599 if (*out == NULL) { 1585 if (*out == NULL) {
1600 if ((*out = malloc(buf_len)) == NULL) { 1586 if ((*out = malloc(buf_len)) == NULL) {
1601 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE); 1587 ECerror(ERR_R_MALLOC_FAILURE);
1602 return 0; 1588 return 0;
1603 } 1589 }
1604 new_buffer = 1; 1590 new_buffer = 1;
1605 } 1591 }
1606 if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form, 1592 if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
1607 *out, buf_len, NULL)) { 1593 *out, buf_len, NULL)) {
1608 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB); 1594 ECerror(ERR_R_EC_LIB);
1609 if (new_buffer) { 1595 if (new_buffer) {
1610 free(*out); 1596 free(*out);
1611 *out = NULL; 1597 *out = NULL;
diff --git a/src/lib/libcrypto/ec/ec_check.c b/src/lib/libcrypto/ec/ec_check.c
index 21072305d5..bbb03498ac 100644
--- a/src/lib/libcrypto/ec/ec_check.c
+++ b/src/lib/libcrypto/ec/ec_check.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_check.c,v 1.5 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ec_check.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -67,7 +67,7 @@ EC_GROUP_check(const EC_GROUP * group, BN_CTX * ctx)
67 if (ctx == NULL) { 67 if (ctx == NULL) {
68 ctx = new_ctx = BN_CTX_new(); 68 ctx = new_ctx = BN_CTX_new();
69 if (ctx == NULL) { 69 if (ctx == NULL) {
70 ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE); 70 ECerror(ERR_R_MALLOC_FAILURE);
71 goto err; 71 goto err;
72 } 72 }
73 } 73 }
@@ -77,16 +77,16 @@ EC_GROUP_check(const EC_GROUP * group, BN_CTX * ctx)
77 77
78 /* check the discriminant */ 78 /* check the discriminant */
79 if (!EC_GROUP_check_discriminant(group, ctx)) { 79 if (!EC_GROUP_check_discriminant(group, ctx)) {
80 ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO); 80 ECerror(EC_R_DISCRIMINANT_IS_ZERO);
81 goto err; 81 goto err;
82 } 82 }
83 /* check the generator */ 83 /* check the generator */
84 if (group->generator == NULL) { 84 if (group->generator == NULL) {
85 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR); 85 ECerror(EC_R_UNDEFINED_GENERATOR);
86 goto err; 86 goto err;
87 } 87 }
88 if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) { 88 if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) {
89 ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE); 89 ECerror(EC_R_POINT_IS_NOT_ON_CURVE);
90 goto err; 90 goto err;
91 } 91 }
92 /* check the order of the generator */ 92 /* check the order of the generator */
@@ -95,13 +95,13 @@ EC_GROUP_check(const EC_GROUP * group, BN_CTX * ctx)
95 if (!EC_GROUP_get_order(group, order, ctx)) 95 if (!EC_GROUP_get_order(group, order, ctx))
96 goto err; 96 goto err;
97 if (BN_is_zero(order)) { 97 if (BN_is_zero(order)) {
98 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER); 98 ECerror(EC_R_UNDEFINED_ORDER);
99 goto err; 99 goto err;
100 } 100 }
101 if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) 101 if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx))
102 goto err; 102 goto err;
103 if (EC_POINT_is_at_infinity(group, point) <= 0) { 103 if (EC_POINT_is_at_infinity(group, point) <= 0) {
104 ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER); 104 ECerror(EC_R_INVALID_GROUP_ORDER);
105 goto err; 105 goto err;
106 } 106 }
107 ret = 1; 107 ret = 1;
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c
index c8eee285b6..1ee2a7c8e8 100644
--- a/src/lib/libcrypto/ec/ec_curve.c
+++ b/src/lib/libcrypto/ec/ec_curve.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_curve.c,v 1.14 2016/11/04 17:33:19 miod Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -3168,7 +3168,7 @@ ec_group_new_from_data(const ec_list_element curve)
3168 const unsigned char *params; 3168 const unsigned char *params;
3169 3169
3170 if ((ctx = BN_CTX_new()) == NULL) { 3170 if ((ctx = BN_CTX_new()) == NULL) {
3171 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE); 3171 ECerror(ERR_R_MALLOC_FAILURE);
3172 goto err; 3172 goto err;
3173 } 3173 }
3174 data = curve.data; 3174 data = curve.data;
@@ -3180,19 +3180,19 @@ ec_group_new_from_data(const ec_list_element curve)
3180 if (!(p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) || 3180 if (!(p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) ||
3181 !(a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) || 3181 !(a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) ||
3182 !(b = BN_bin2bn(params + 2 * param_len, param_len, NULL))) { 3182 !(b = BN_bin2bn(params + 2 * param_len, param_len, NULL))) {
3183 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); 3183 ECerror(ERR_R_BN_LIB);
3184 goto err; 3184 goto err;
3185 } 3185 }
3186 if (curve.meth != 0) { 3186 if (curve.meth != 0) {
3187 meth = curve.meth(); 3187 meth = curve.meth();
3188 if (((group = EC_GROUP_new(meth)) == NULL) || 3188 if (((group = EC_GROUP_new(meth)) == NULL) ||
3189 (!(group->meth->group_set_curve(group, p, a, b, ctx)))) { 3189 (!(group->meth->group_set_curve(group, p, a, b, ctx)))) {
3190 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3190 ECerror(ERR_R_EC_LIB);
3191 goto err; 3191 goto err;
3192 } 3192 }
3193 } else if (data->field_type == NID_X9_62_prime_field) { 3193 } else if (data->field_type == NID_X9_62_prime_field) {
3194 if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) { 3194 if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) {
3195 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3195 ECerror(ERR_R_EC_LIB);
3196 goto err; 3196 goto err;
3197 } 3197 }
3198 } 3198 }
@@ -3200,37 +3200,37 @@ ec_group_new_from_data(const ec_list_element curve)
3200 else { /* field_type == 3200 else { /* field_type ==
3201 * NID_X9_62_characteristic_two_field */ 3201 * NID_X9_62_characteristic_two_field */
3202 if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) { 3202 if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) {
3203 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3203 ECerror(ERR_R_EC_LIB);
3204 goto err; 3204 goto err;
3205 } 3205 }
3206 } 3206 }
3207#endif 3207#endif
3208 3208
3209 if ((P = EC_POINT_new(group)) == NULL) { 3209 if ((P = EC_POINT_new(group)) == NULL) {
3210 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3210 ECerror(ERR_R_EC_LIB);
3211 goto err; 3211 goto err;
3212 } 3212 }
3213 if (!(x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) 3213 if (!(x = BN_bin2bn(params + 3 * param_len, param_len, NULL))
3214 || !(y = BN_bin2bn(params + 4 * param_len, param_len, NULL))) { 3214 || !(y = BN_bin2bn(params + 4 * param_len, param_len, NULL))) {
3215 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); 3215 ECerror(ERR_R_BN_LIB);
3216 goto err; 3216 goto err;
3217 } 3217 }
3218 if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) { 3218 if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) {
3219 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3219 ECerror(ERR_R_EC_LIB);
3220 goto err; 3220 goto err;
3221 } 3221 }
3222 if (!(order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) 3222 if (!(order = BN_bin2bn(params + 5 * param_len, param_len, NULL))
3223 || !BN_set_word(x, (BN_ULONG) data->cofactor)) { 3223 || !BN_set_word(x, (BN_ULONG) data->cofactor)) {
3224 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB); 3224 ECerror(ERR_R_BN_LIB);
3225 goto err; 3225 goto err;
3226 } 3226 }
3227 if (!EC_GROUP_set_generator(group, P, order, x)) { 3227 if (!EC_GROUP_set_generator(group, P, order, x)) {
3228 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3228 ECerror(ERR_R_EC_LIB);
3229 goto err; 3229 goto err;
3230 } 3230 }
3231 if (seed_len) { 3231 if (seed_len) {
3232 if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) { 3232 if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) {
3233 ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB); 3233 ECerror(ERR_R_EC_LIB);
3234 goto err; 3234 goto err;
3235 } 3235 }
3236 } 3236 }
@@ -3266,7 +3266,7 @@ EC_GROUP_new_by_curve_name(int nid)
3266 break; 3266 break;
3267 } 3267 }
3268 if (ret == NULL) { 3268 if (ret == NULL) {
3269 ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_UNKNOWN_GROUP); 3269 ECerror(EC_R_UNKNOWN_GROUP);
3270 return NULL; 3270 return NULL;
3271 } 3271 }
3272 EC_GROUP_set_curve_name(ret, nid); 3272 EC_GROUP_set_curve_name(ret, nid);
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c
index 0ba510adae..fa5deceda5 100644
--- a/src/lib/libcrypto/ec/ec_err.c
+++ b/src/lib/libcrypto/ec/ec_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_err.c,v 1.9 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_err.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -71,144 +71,8 @@
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_EC,func,0) 71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_EC,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EC,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EC,0,reason)
73 73
74static ERR_STRING_DATA EC_str_functs[] = 74static ERR_STRING_DATA EC_str_functs[] = {
75{ 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(EC_F_BN_TO_FELEM), "BN_TO_FELEM"},
77 {ERR_FUNC(EC_F_COMPUTE_WNAF), "COMPUTE_WNAF"},
78 {ERR_FUNC(EC_F_D2I_ECPARAMETERS), "d2i_ECParameters"},
79 {ERR_FUNC(EC_F_D2I_ECPKPARAMETERS), "d2i_ECPKParameters"},
80 {ERR_FUNC(EC_F_D2I_ECPRIVATEKEY), "d2i_ECPrivateKey"},
81 {ERR_FUNC(EC_F_DO_EC_KEY_PRINT), "DO_EC_KEY_PRINT"},
82 {ERR_FUNC(EC_F_ECKEY_PARAM2TYPE), "ECKEY_PARAM2TYPE"},
83 {ERR_FUNC(EC_F_ECKEY_PARAM_DECODE), "ECKEY_PARAM_DECODE"},
84 {ERR_FUNC(EC_F_ECKEY_PRIV_DECODE), "ECKEY_PRIV_DECODE"},
85 {ERR_FUNC(EC_F_ECKEY_PRIV_ENCODE), "ECKEY_PRIV_ENCODE"},
86 {ERR_FUNC(EC_F_ECKEY_PUB_DECODE), "ECKEY_PUB_DECODE"},
87 {ERR_FUNC(EC_F_ECKEY_PUB_ENCODE), "ECKEY_PUB_ENCODE"},
88 {ERR_FUNC(EC_F_ECKEY_TYPE2PARAM), "ECKEY_TYPE2PARAM"},
89 {ERR_FUNC(EC_F_ECPARAMETERS_PRINT), "ECParameters_print"},
90 {ERR_FUNC(EC_F_ECPARAMETERS_PRINT_FP), "ECParameters_print_fp"},
91 {ERR_FUNC(EC_F_ECPKPARAMETERS_PRINT), "ECPKParameters_print"},
92 {ERR_FUNC(EC_F_ECPKPARAMETERS_PRINT_FP), "ECPKParameters_print_fp"},
93 {ERR_FUNC(EC_F_ECP_NIST_MOD_192), "ECP_NIST_MOD_192"},
94 {ERR_FUNC(EC_F_ECP_NIST_MOD_224), "ECP_NIST_MOD_224"},
95 {ERR_FUNC(EC_F_ECP_NIST_MOD_256), "ECP_NIST_MOD_256"},
96 {ERR_FUNC(EC_F_ECP_NIST_MOD_521), "ECP_NIST_MOD_521"},
97 {ERR_FUNC(EC_F_EC_ASN1_GROUP2CURVE), "EC_ASN1_GROUP2CURVE"},
98 {ERR_FUNC(EC_F_EC_ASN1_GROUP2FIELDID), "EC_ASN1_GROUP2FIELDID"},
99 {ERR_FUNC(EC_F_EC_ASN1_GROUP2PARAMETERS), "EC_ASN1_GROUP2PARAMETERS"},
100 {ERR_FUNC(EC_F_EC_ASN1_GROUP2PKPARAMETERS), "EC_ASN1_GROUP2PKPARAMETERS"},
101 {ERR_FUNC(EC_F_EC_ASN1_PARAMETERS2GROUP), "EC_ASN1_PARAMETERS2GROUP"},
102 {ERR_FUNC(EC_F_EC_ASN1_PKPARAMETERS2GROUP), "EC_ASN1_PKPARAMETERS2GROUP"},
103 {ERR_FUNC(EC_F_EC_EX_DATA_SET_DATA), "EC_EX_DATA_set_data"},
104 {ERR_FUNC(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY), "EC_GF2M_MONTGOMERY_POINT_MULTIPLY"},
105 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT), "ec_GF2m_simple_group_check_discriminant"},
106 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE), "ec_GF2m_simple_group_set_curve"},
107 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_OCT2POINT), "ec_GF2m_simple_oct2point"},
108 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT2OCT), "ec_GF2m_simple_point2oct"},
109 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES), "ec_GF2m_simple_point_get_affine_coordinates"},
110 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES), "ec_GF2m_simple_point_set_affine_coordinates"},
111 {ERR_FUNC(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES), "ec_GF2m_simple_set_compressed_coordinates"},
112 {ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_DECODE), "ec_GFp_mont_field_decode"},
113 {ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_ENCODE), "ec_GFp_mont_field_encode"},
114 {ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_MUL), "ec_GFp_mont_field_mul"},
115 {ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE), "ec_GFp_mont_field_set_to_one"},
116 {ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SQR), "ec_GFp_mont_field_sqr"},
117 {ERR_FUNC(EC_F_EC_GFP_MONT_GROUP_SET_CURVE), "ec_GFp_mont_group_set_curve"},
118 {ERR_FUNC(EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP), "EC_GFP_MONT_GROUP_SET_CURVE_GFP"},
119 {ERR_FUNC(EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE), "ec_GFp_nistp224_group_set_curve"},
120 {ERR_FUNC(EC_F_EC_GFP_NISTP224_POINTS_MUL), "ec_GFp_nistp224_points_mul"},
121 {ERR_FUNC(EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES), "ec_GFp_nistp224_point_get_affine_coordinates"},
122 {ERR_FUNC(EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE), "ec_GFp_nistp256_group_set_curve"},
123 {ERR_FUNC(EC_F_EC_GFP_NISTP256_POINTS_MUL), "ec_GFp_nistp256_points_mul"},
124 {ERR_FUNC(EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES), "ec_GFp_nistp256_point_get_affine_coordinates"},
125 {ERR_FUNC(EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE), "ec_GFp_nistp521_group_set_curve"},
126 {ERR_FUNC(EC_F_EC_GFP_NISTP521_POINTS_MUL), "ec_GFp_nistp521_points_mul"},
127 {ERR_FUNC(EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES), "ec_GFp_nistp521_point_get_affine_coordinates"},
128 {ERR_FUNC(EC_F_EC_GFP_NIST_FIELD_MUL), "ec_GFp_nist_field_mul"},
129 {ERR_FUNC(EC_F_EC_GFP_NIST_FIELD_SQR), "ec_GFp_nist_field_sqr"},
130 {ERR_FUNC(EC_F_EC_GFP_NIST_GROUP_SET_CURVE), "ec_GFp_nist_group_set_curve"},
131 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT), "ec_GFp_simple_group_check_discriminant"},
132 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE), "ec_GFp_simple_group_set_curve"},
133 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP), "EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP"},
134 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR), "EC_GFP_SIMPLE_GROUP_SET_GENERATOR"},
135 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE), "ec_GFp_simple_make_affine"},
136 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_OCT2POINT), "ec_GFp_simple_oct2point"},
137 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT2OCT), "ec_GFp_simple_point2oct"},
138 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE), "ec_GFp_simple_points_make_affine"},
139 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES), "ec_GFp_simple_point_get_affine_coordinates"},
140 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP), "EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP"},
141 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES), "ec_GFp_simple_point_set_affine_coordinates"},
142 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP), "EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP"},
143 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES), "ec_GFp_simple_set_compressed_coordinates"},
144 {ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP), "EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP"},
145 {ERR_FUNC(EC_F_EC_GROUP_CHECK), "EC_GROUP_check"},
146 {ERR_FUNC(EC_F_EC_GROUP_CHECK_DISCRIMINANT), "EC_GROUP_check_discriminant"},
147 {ERR_FUNC(EC_F_EC_GROUP_COPY), "EC_GROUP_copy"},
148 {ERR_FUNC(EC_F_EC_GROUP_GET0_GENERATOR), "EC_GROUP_get0_generator"},
149 {ERR_FUNC(EC_F_EC_GROUP_GET_COFACTOR), "EC_GROUP_get_cofactor"},
150 {ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GF2M), "EC_GROUP_get_curve_GF2m"},
151 {ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GFP), "EC_GROUP_get_curve_GFp"},
152 {ERR_FUNC(EC_F_EC_GROUP_GET_DEGREE), "EC_GROUP_get_degree"},
153 {ERR_FUNC(EC_F_EC_GROUP_GET_ORDER), "EC_GROUP_get_order"},
154 {ERR_FUNC(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS), "EC_GROUP_get_pentanomial_basis"},
155 {ERR_FUNC(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS), "EC_GROUP_get_trinomial_basis"},
156 {ERR_FUNC(EC_F_EC_GROUP_NEW), "EC_GROUP_new"},
157 {ERR_FUNC(EC_F_EC_GROUP_NEW_BY_CURVE_NAME), "EC_GROUP_new_by_curve_name"},
158 {ERR_FUNC(EC_F_EC_GROUP_NEW_FROM_DATA), "EC_GROUP_NEW_FROM_DATA"},
159 {ERR_FUNC(EC_F_EC_GROUP_PRECOMPUTE_MULT), "EC_GROUP_precompute_mult"},
160 {ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GF2M), "EC_GROUP_set_curve_GF2m"},
161 {ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GFP), "EC_GROUP_set_curve_GFp"},
162 {ERR_FUNC(EC_F_EC_GROUP_SET_EXTRA_DATA), "EC_GROUP_SET_EXTRA_DATA"},
163 {ERR_FUNC(EC_F_EC_GROUP_SET_GENERATOR), "EC_GROUP_set_generator"},
164 {ERR_FUNC(EC_F_EC_KEY_CHECK_KEY), "EC_KEY_check_key"},
165 {ERR_FUNC(EC_F_EC_KEY_COPY), "EC_KEY_copy"},
166 {ERR_FUNC(EC_F_EC_KEY_GENERATE_KEY), "EC_KEY_generate_key"},
167 {ERR_FUNC(EC_F_EC_KEY_NEW), "EC_KEY_new"},
168 {ERR_FUNC(EC_F_EC_KEY_PRINT), "EC_KEY_print"},
169 {ERR_FUNC(EC_F_EC_KEY_PRINT_FP), "EC_KEY_print_fp"},
170 {ERR_FUNC(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES), "EC_KEY_set_public_key_affine_coordinates"},
171 {ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"},
172 {ERR_FUNC(EC_F_EC_POINT_ADD), "EC_POINT_add"},
173 {ERR_FUNC(EC_F_EC_POINT_CMP), "EC_POINT_cmp"},
174 {ERR_FUNC(EC_F_EC_POINT_COPY), "EC_POINT_copy"},
175 {ERR_FUNC(EC_F_EC_POINT_DBL), "EC_POINT_dbl"},
176 {ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M), "EC_POINT_get_affine_coordinates_GF2m"},
177 {ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP), "EC_POINT_get_affine_coordinates_GFp"},
178 {ERR_FUNC(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_get_Jprojective_coordinates_GFp"},
179 {ERR_FUNC(EC_F_EC_POINT_INVERT), "EC_POINT_invert"},
180 {ERR_FUNC(EC_F_EC_POINT_IS_AT_INFINITY), "EC_POINT_is_at_infinity"},
181 {ERR_FUNC(EC_F_EC_POINT_IS_ON_CURVE), "EC_POINT_is_on_curve"},
182 {ERR_FUNC(EC_F_EC_POINT_MAKE_AFFINE), "EC_POINT_make_affine"},
183 {ERR_FUNC(EC_F_EC_POINT_MUL), "EC_POINT_mul"},
184 {ERR_FUNC(EC_F_EC_POINT_NEW), "EC_POINT_new"},
185 {ERR_FUNC(EC_F_EC_POINT_OCT2POINT), "EC_POINT_oct2point"},
186 {ERR_FUNC(EC_F_EC_POINT_POINT2OCT), "EC_POINT_point2oct"},
187 {ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M), "EC_POINT_set_affine_coordinates_GF2m"},
188 {ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP), "EC_POINT_set_affine_coordinates_GFp"},
189 {ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M), "EC_POINT_set_compressed_coordinates_GF2m"},
190 {ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP), "EC_POINT_set_compressed_coordinates_GFp"},
191 {ERR_FUNC(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_set_Jprojective_coordinates_GFp"},
192 {ERR_FUNC(EC_F_EC_POINT_SET_TO_INFINITY), "EC_POINT_set_to_infinity"},
193 {ERR_FUNC(EC_F_EC_PRE_COMP_DUP), "EC_PRE_COMP_DUP"},
194 {ERR_FUNC(EC_F_EC_PRE_COMP_NEW), "EC_PRE_COMP_NEW"},
195 {ERR_FUNC(EC_F_EC_WNAF_MUL), "ec_wNAF_mul"},
196 {ERR_FUNC(EC_F_EC_WNAF_PRECOMPUTE_MULT), "ec_wNAF_precompute_mult"},
197 {ERR_FUNC(EC_F_I2D_ECPARAMETERS), "i2d_ECParameters"},
198 {ERR_FUNC(EC_F_I2D_ECPKPARAMETERS), "i2d_ECPKParameters"},
199 {ERR_FUNC(EC_F_I2D_ECPRIVATEKEY), "i2d_ECPrivateKey"},
200 {ERR_FUNC(EC_F_I2O_ECPUBLICKEY), "i2o_ECPublicKey"},
201 {ERR_FUNC(EC_F_NISTP224_PRE_COMP_NEW), "NISTP224_PRE_COMP_NEW"},
202 {ERR_FUNC(EC_F_NISTP256_PRE_COMP_NEW), "NISTP256_PRE_COMP_NEW"},
203 {ERR_FUNC(EC_F_NISTP521_PRE_COMP_NEW), "NISTP521_PRE_COMP_NEW"},
204 {ERR_FUNC(EC_F_O2I_ECPUBLICKEY), "o2i_ECPublicKey"},
205 {ERR_FUNC(EC_F_OLD_EC_PRIV_DECODE), "OLD_EC_PRIV_DECODE"},
206 {ERR_FUNC(EC_F_PKEY_EC_CTRL), "PKEY_EC_CTRL"},
207 {ERR_FUNC(EC_F_PKEY_EC_CTRL_STR), "PKEY_EC_CTRL_STR"},
208 {ERR_FUNC(EC_F_PKEY_EC_DERIVE), "PKEY_EC_DERIVE"},
209 {ERR_FUNC(EC_F_PKEY_EC_KEYGEN), "PKEY_EC_KEYGEN"},
210 {ERR_FUNC(EC_F_PKEY_EC_PARAMGEN), "PKEY_EC_PARAMGEN"},
211 {ERR_FUNC(EC_F_PKEY_EC_SIGN), "PKEY_EC_SIGN"},
212 {0, NULL} 76 {0, NULL}
213}; 77};
214 78
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index fa962e4d0f..5a23a9823d 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -75,7 +75,7 @@ EC_KEY_new(void)
75 75
76 ret = malloc(sizeof(EC_KEY)); 76 ret = malloc(sizeof(EC_KEY));
77 if (ret == NULL) { 77 if (ret == NULL) {
78 ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE); 78 ECerror(ERR_R_MALLOC_FAILURE);
79 return (NULL); 79 return (NULL);
80 } 80 }
81 ret->version = 1; 81 ret->version = 1;
@@ -133,7 +133,7 @@ EC_KEY_copy(EC_KEY * dest, const EC_KEY * src)
133 EC_EXTRA_DATA *d; 133 EC_EXTRA_DATA *d;
134 134
135 if (dest == NULL || src == NULL) { 135 if (dest == NULL || src == NULL) {
136 ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER); 136 ECerror(ERR_R_PASSED_NULL_PARAMETER);
137 return NULL; 137 return NULL;
138 } 138 }
139 /* copy the parameters */ 139 /* copy the parameters */
@@ -217,7 +217,7 @@ EC_KEY_generate_key(EC_KEY * eckey)
217 EC_POINT *pub_key = NULL; 217 EC_POINT *pub_key = NULL;
218 218
219 if (!eckey || !eckey->group) { 219 if (!eckey || !eckey->group) {
220 ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER); 220 ECerror(ERR_R_PASSED_NULL_PARAMETER);
221 return 0; 221 return 0;
222 } 222 }
223 if ((order = BN_new()) == NULL) 223 if ((order = BN_new()) == NULL)
@@ -274,11 +274,11 @@ EC_KEY_check_key(const EC_KEY * eckey)
274 EC_POINT *point = NULL; 274 EC_POINT *point = NULL;
275 275
276 if (!eckey || !eckey->group || !eckey->pub_key) { 276 if (!eckey || !eckey->group || !eckey->pub_key) {
277 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); 277 ECerror(ERR_R_PASSED_NULL_PARAMETER);
278 return 0; 278 return 0;
279 } 279 }
280 if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key) > 0) { 280 if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key) > 0) {
281 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); 281 ECerror(EC_R_POINT_AT_INFINITY);
282 goto err; 282 goto err;
283 } 283 }
284 if ((ctx = BN_CTX_new()) == NULL) 284 if ((ctx = BN_CTX_new()) == NULL)
@@ -288,21 +288,21 @@ EC_KEY_check_key(const EC_KEY * eckey)
288 288
289 /* testing whether the pub_key is on the elliptic curve */ 289 /* testing whether the pub_key is on the elliptic curve */
290 if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) { 290 if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) {
291 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); 291 ECerror(EC_R_POINT_IS_NOT_ON_CURVE);
292 goto err; 292 goto err;
293 } 293 }
294 /* testing whether pub_key * order is the point at infinity */ 294 /* testing whether pub_key * order is the point at infinity */
295 order = &eckey->group->order; 295 order = &eckey->group->order;
296 if (BN_is_zero(order)) { 296 if (BN_is_zero(order)) {
297 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); 297 ECerror(EC_R_INVALID_GROUP_ORDER);
298 goto err; 298 goto err;
299 } 299 }
300 if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) { 300 if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) {
301 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB); 301 ECerror(ERR_R_EC_LIB);
302 goto err; 302 goto err;
303 } 303 }
304 if (EC_POINT_is_at_infinity(eckey->group, point) <= 0) { 304 if (EC_POINT_is_at_infinity(eckey->group, point) <= 0) {
305 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER); 305 ECerror(EC_R_WRONG_ORDER);
306 goto err; 306 goto err;
307 } 307 }
308 /* 308 /*
@@ -311,17 +311,17 @@ EC_KEY_check_key(const EC_KEY * eckey)
311 */ 311 */
312 if (eckey->priv_key) { 312 if (eckey->priv_key) {
313 if (BN_cmp(eckey->priv_key, order) >= 0) { 313 if (BN_cmp(eckey->priv_key, order) >= 0) {
314 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER); 314 ECerror(EC_R_WRONG_ORDER);
315 goto err; 315 goto err;
316 } 316 }
317 if (!EC_POINT_mul(eckey->group, point, eckey->priv_key, 317 if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
318 NULL, NULL, ctx)) { 318 NULL, NULL, ctx)) {
319 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB); 319 ECerror(ERR_R_EC_LIB);
320 goto err; 320 goto err;
321 } 321 }
322 if (EC_POINT_cmp(eckey->group, point, eckey->pub_key, 322 if (EC_POINT_cmp(eckey->group, point, eckey->pub_key,
323 ctx) != 0) { 323 ctx) != 0) {
324 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY); 324 ECerror(EC_R_INVALID_PRIVATE_KEY);
325 goto err; 325 goto err;
326 } 326 }
327 } 327 }
@@ -341,8 +341,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
341 int ok = 0, tmp_nid, is_char_two = 0; 341 int ok = 0, tmp_nid, is_char_two = 0;
342 342
343 if (!key || !key->group || !x || !y) { 343 if (!key || !key->group || !x || !y) {
344 ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, 344 ECerror(ERR_R_PASSED_NULL_PARAMETER);
345 ERR_R_PASSED_NULL_PARAMETER);
346 return 0; 345 return 0;
347 } 346 }
348 ctx = BN_CTX_new(); 347 ctx = BN_CTX_new();
@@ -387,8 +386,7 @@ EC_KEY_set_public_key_affine_coordinates(EC_KEY * key, BIGNUM * x, BIGNUM * y)
387 * out of range. 386 * out of range.
388 */ 387 */
389 if (BN_cmp(x, tx) || BN_cmp(y, ty)) { 388 if (BN_cmp(x, tx) || BN_cmp(y, ty)) {
390 ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, 389 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
391 EC_R_COORDINATES_OUT_OF_RANGE);
392 goto err; 390 goto err;
393 } 391 }
394 if (!EC_KEY_set_public_key(key, point)) 392 if (!EC_KEY_set_public_key(key, point))
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 976091f4c9..baddbf6dc8 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.22 2016/09/03 12:10:40 beck Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -78,16 +78,16 @@ EC_GROUP_new(const EC_METHOD * meth)
78 EC_GROUP *ret; 78 EC_GROUP *ret;
79 79
80 if (meth == NULL) { 80 if (meth == NULL) {
81 ECerr(EC_F_EC_GROUP_NEW, EC_R_SLOT_FULL); 81 ECerror(EC_R_SLOT_FULL);
82 return NULL; 82 return NULL;
83 } 83 }
84 if (meth->group_init == 0) { 84 if (meth->group_init == 0) {
85 ECerr(EC_F_EC_GROUP_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 85 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
86 return NULL; 86 return NULL;
87 } 87 }
88 ret = malloc(sizeof *ret); 88 ret = malloc(sizeof *ret);
89 if (ret == NULL) { 89 if (ret == NULL) {
90 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE); 90 ECerror(ERR_R_MALLOC_FAILURE);
91 return NULL; 91 return NULL;
92 } 92 }
93 ret->meth = meth; 93 ret->meth = meth;
@@ -166,11 +166,11 @@ EC_GROUP_copy(EC_GROUP * dest, const EC_GROUP * src)
166 EC_EXTRA_DATA *d; 166 EC_EXTRA_DATA *d;
167 167
168 if (dest->meth->group_copy == 0) { 168 if (dest->meth->group_copy == 0) {
169 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 169 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
170 return 0; 170 return 0;
171 } 171 }
172 if (dest->meth != src->meth) { 172 if (dest->meth != src->meth) {
173 ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS); 173 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
174 return 0; 174 return 0;
175 } 175 }
176 if (dest == src) 176 if (dest == src)
@@ -262,7 +262,7 @@ EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
262 const BIGNUM *order, const BIGNUM *cofactor) 262 const BIGNUM *order, const BIGNUM *cofactor)
263{ 263{
264 if (generator == NULL) { 264 if (generator == NULL) {
265 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER); 265 ECerror(ERR_R_PASSED_NULL_PARAMETER);
266 return 0; 266 return 0;
267 } 267 }
268 if (group->generator == NULL) { 268 if (group->generator == NULL) {
@@ -398,7 +398,7 @@ EC_GROUP_set_curve_GFp(EC_GROUP * group, const BIGNUM * p, const BIGNUM * a,
398 const BIGNUM * b, BN_CTX * ctx) 398 const BIGNUM * b, BN_CTX * ctx)
399{ 399{
400 if (group->meth->group_set_curve == 0) { 400 if (group->meth->group_set_curve == 0) {
401 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 401 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
402 return 0; 402 return 0;
403 } 403 }
404 return group->meth->group_set_curve(group, p, a, b, ctx); 404 return group->meth->group_set_curve(group, p, a, b, ctx);
@@ -410,7 +410,7 @@ EC_GROUP_get_curve_GFp(const EC_GROUP * group, BIGNUM * p, BIGNUM * a,
410 BIGNUM * b, BN_CTX * ctx) 410 BIGNUM * b, BN_CTX * ctx)
411{ 411{
412 if (group->meth->group_get_curve == 0) { 412 if (group->meth->group_get_curve == 0) {
413 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 413 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
414 return 0; 414 return 0;
415 } 415 }
416 return group->meth->group_get_curve(group, p, a, b, ctx); 416 return group->meth->group_get_curve(group, p, a, b, ctx);
@@ -422,7 +422,7 @@ EC_GROUP_set_curve_GF2m(EC_GROUP * group, const BIGNUM * p, const BIGNUM * a,
422 const BIGNUM * b, BN_CTX * ctx) 422 const BIGNUM * b, BN_CTX * ctx)
423{ 423{
424 if (group->meth->group_set_curve == 0) { 424 if (group->meth->group_set_curve == 0) {
425 ECerr(EC_F_EC_GROUP_SET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 425 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
426 return 0; 426 return 0;
427 } 427 }
428 return group->meth->group_set_curve(group, p, a, b, ctx); 428 return group->meth->group_set_curve(group, p, a, b, ctx);
@@ -434,7 +434,7 @@ EC_GROUP_get_curve_GF2m(const EC_GROUP * group, BIGNUM * p, BIGNUM * a,
434 BIGNUM * b, BN_CTX * ctx) 434 BIGNUM * b, BN_CTX * ctx)
435{ 435{
436 if (group->meth->group_get_curve == 0) { 436 if (group->meth->group_get_curve == 0) {
437 ECerr(EC_F_EC_GROUP_GET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 437 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
438 return 0; 438 return 0;
439 } 439 }
440 return group->meth->group_get_curve(group, p, a, b, ctx); 440 return group->meth->group_get_curve(group, p, a, b, ctx);
@@ -445,7 +445,7 @@ int
445EC_GROUP_get_degree(const EC_GROUP * group) 445EC_GROUP_get_degree(const EC_GROUP * group)
446{ 446{
447 if (group->meth->group_get_degree == 0) { 447 if (group->meth->group_get_degree == 0) {
448 ECerr(EC_F_EC_GROUP_GET_DEGREE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 448 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
449 return 0; 449 return 0;
450 } 450 }
451 return group->meth->group_get_degree(group); 451 return group->meth->group_get_degree(group);
@@ -456,7 +456,7 @@ int
456EC_GROUP_check_discriminant(const EC_GROUP * group, BN_CTX * ctx) 456EC_GROUP_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
457{ 457{
458 if (group->meth->group_check_discriminant == 0) { 458 if (group->meth->group_check_discriminant == 0) {
459 ECerr(EC_F_EC_GROUP_CHECK_DISCRIMINANT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 459 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
460 return 0; 460 return 0;
461 } 461 }
462 return group->meth->group_check_discriminant(group, ctx); 462 return group->meth->group_check_discriminant(group, ctx);
@@ -553,7 +553,7 @@ EC_EX_DATA_set_data(EC_EXTRA_DATA ** ex_data, void *data,
553 for (d = *ex_data; d != NULL; d = d->next) { 553 for (d = *ex_data; d != NULL; d = d->next) {
554 if (d->dup_func == dup_func && d->free_func == free_func && 554 if (d->dup_func == dup_func && d->free_func == free_func &&
555 d->clear_free_func == clear_free_func) { 555 d->clear_free_func == clear_free_func) {
556 ECerr(EC_F_EC_EX_DATA_SET_DATA, EC_R_SLOT_FULL); 556 ECerror(EC_R_SLOT_FULL);
557 return 0; 557 return 0;
558 } 558 }
559 } 559 }
@@ -699,16 +699,16 @@ EC_POINT_new(const EC_GROUP * group)
699 EC_POINT *ret; 699 EC_POINT *ret;
700 700
701 if (group == NULL) { 701 if (group == NULL) {
702 ECerr(EC_F_EC_POINT_NEW, ERR_R_PASSED_NULL_PARAMETER); 702 ECerror(ERR_R_PASSED_NULL_PARAMETER);
703 return NULL; 703 return NULL;
704 } 704 }
705 if (group->meth->point_init == 0) { 705 if (group->meth->point_init == 0) {
706 ECerr(EC_F_EC_POINT_NEW, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 706 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
707 return NULL; 707 return NULL;
708 } 708 }
709 ret = malloc(sizeof *ret); 709 ret = malloc(sizeof *ret);
710 if (ret == NULL) { 710 if (ret == NULL) {
711 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE); 711 ECerror(ERR_R_MALLOC_FAILURE);
712 return NULL; 712 return NULL;
713 } 713 }
714 ret->meth = group->meth; 714 ret->meth = group->meth;
@@ -752,11 +752,11 @@ int
752EC_POINT_copy(EC_POINT * dest, const EC_POINT * src) 752EC_POINT_copy(EC_POINT * dest, const EC_POINT * src)
753{ 753{
754 if (dest->meth->point_copy == 0) { 754 if (dest->meth->point_copy == 0) {
755 ECerr(EC_F_EC_POINT_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 755 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
756 return 0; 756 return 0;
757 } 757 }
758 if (dest->meth != src->meth) { 758 if (dest->meth != src->meth) {
759 ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS); 759 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
760 return 0; 760 return 0;
761 } 761 }
762 if (dest == src) 762 if (dest == src)
@@ -797,11 +797,11 @@ int
797EC_POINT_set_to_infinity(const EC_GROUP * group, EC_POINT * point) 797EC_POINT_set_to_infinity(const EC_GROUP * group, EC_POINT * point)
798{ 798{
799 if (group->meth->point_set_to_infinity == 0) { 799 if (group->meth->point_set_to_infinity == 0) {
800 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 800 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
801 return 0; 801 return 0;
802 } 802 }
803 if (group->meth != point->meth) { 803 if (group->meth != point->meth) {
804 ECerr(EC_F_EC_POINT_SET_TO_INFINITY, EC_R_INCOMPATIBLE_OBJECTS); 804 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
805 return 0; 805 return 0;
806 } 806 }
807 return group->meth->point_set_to_infinity(group, point); 807 return group->meth->point_set_to_infinity(group, point);
@@ -813,11 +813,11 @@ EC_POINT_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
813 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx) 813 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)
814{ 814{
815 if (group->meth->point_set_Jprojective_coordinates_GFp == 0) { 815 if (group->meth->point_set_Jprojective_coordinates_GFp == 0) {
816 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 816 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
817 return 0; 817 return 0;
818 } 818 }
819 if (group->meth != point->meth) { 819 if (group->meth != point->meth) {
820 ECerr(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 820 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
821 return 0; 821 return 0;
822 } 822 }
823 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); 823 return group->meth->point_set_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
@@ -829,11 +829,11 @@ EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
829 const EC_POINT *point, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx) 829 const EC_POINT *point, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx)
830{ 830{
831 if (group->meth->point_get_Jprojective_coordinates_GFp == 0) { 831 if (group->meth->point_get_Jprojective_coordinates_GFp == 0) {
832 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 832 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
833 return 0; 833 return 0;
834 } 834 }
835 if (group->meth != point->meth) { 835 if (group->meth != point->meth) {
836 ECerr(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 836 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
837 return 0; 837 return 0;
838 } 838 }
839 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx); 839 return group->meth->point_get_Jprojective_coordinates_GFp(group, point, x, y, z, ctx);
@@ -845,11 +845,11 @@ EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
845 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) 845 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
846{ 846{
847 if (group->meth->point_set_affine_coordinates == 0) { 847 if (group->meth->point_set_affine_coordinates == 0) {
848 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 848 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
849 return 0; 849 return 0;
850 } 850 }
851 if (group->meth != point->meth) { 851 if (group->meth != point->meth) {
852 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 852 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
853 return 0; 853 return 0;
854 } 854 }
855 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx); 855 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
@@ -861,11 +861,11 @@ EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
861 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) 861 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
862{ 862{
863 if (group->meth->point_set_affine_coordinates == 0) { 863 if (group->meth->point_set_affine_coordinates == 0) {
864 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 864 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
865 return 0; 865 return 0;
866 } 866 }
867 if (group->meth != point->meth) { 867 if (group->meth != point->meth) {
868 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS); 868 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
869 return 0; 869 return 0;
870 } 870 }
871 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx); 871 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
@@ -877,11 +877,11 @@ EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point
877 BIGNUM *x, BIGNUM *y, BN_CTX *ctx) 877 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
878{ 878{
879 if (group->meth->point_get_affine_coordinates == 0) { 879 if (group->meth->point_get_affine_coordinates == 0) {
880 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 880 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
881 return 0; 881 return 0;
882 } 882 }
883 if (group->meth != point->meth) { 883 if (group->meth != point->meth) {
884 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 884 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
885 return 0; 885 return 0;
886 } 886 }
887 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx); 887 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
@@ -893,11 +893,11 @@ EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *poin
893 BIGNUM *x, BIGNUM *y, BN_CTX *ctx) 893 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
894{ 894{
895 if (group->meth->point_get_affine_coordinates == 0) { 895 if (group->meth->point_get_affine_coordinates == 0) {
896 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 896 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
897 return 0; 897 return 0;
898 } 898 }
899 if (group->meth != point->meth) { 899 if (group->meth != point->meth) {
900 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS); 900 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
901 return 0; 901 return 0;
902 } 902 }
903 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx); 903 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
@@ -909,11 +909,11 @@ EC_POINT_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,
909 const EC_POINT *b, BN_CTX *ctx) 909 const EC_POINT *b, BN_CTX *ctx)
910{ 910{
911 if (group->meth->add == 0) { 911 if (group->meth->add == 0) {
912 ECerr(EC_F_EC_POINT_ADD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 912 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
913 return 0; 913 return 0;
914 } 914 }
915 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth)) { 915 if ((group->meth != r->meth) || (r->meth != a->meth) || (a->meth != b->meth)) {
916 ECerr(EC_F_EC_POINT_ADD, EC_R_INCOMPATIBLE_OBJECTS); 916 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
917 return 0; 917 return 0;
918 } 918 }
919 return group->meth->add(group, r, a, b, ctx); 919 return group->meth->add(group, r, a, b, ctx);
@@ -924,11 +924,11 @@ int
924EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx) 924EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
925{ 925{
926 if (group->meth->dbl == 0) { 926 if (group->meth->dbl == 0) {
927 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 927 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
928 return 0; 928 return 0;
929 } 929 }
930 if ((group->meth != r->meth) || (r->meth != a->meth)) { 930 if ((group->meth != r->meth) || (r->meth != a->meth)) {
931 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS); 931 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
932 return 0; 932 return 0;
933 } 933 }
934 return group->meth->dbl(group, r, a, ctx); 934 return group->meth->dbl(group, r, a, ctx);
@@ -939,11 +939,11 @@ int
939EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx) 939EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
940{ 940{
941 if (group->meth->invert == 0) { 941 if (group->meth->invert == 0) {
942 ECerr(EC_F_EC_POINT_INVERT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 942 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
943 return 0; 943 return 0;
944 } 944 }
945 if (group->meth != a->meth) { 945 if (group->meth != a->meth) {
946 ECerr(EC_F_EC_POINT_INVERT, EC_R_INCOMPATIBLE_OBJECTS); 946 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
947 return 0; 947 return 0;
948 } 948 }
949 return group->meth->invert(group, a, ctx); 949 return group->meth->invert(group, a, ctx);
@@ -954,11 +954,11 @@ int
954EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) 954EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
955{ 955{
956 if (group->meth->is_at_infinity == 0) { 956 if (group->meth->is_at_infinity == 0) {
957 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 957 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
958 return 0; 958 return 0;
959 } 959 }
960 if (group->meth != point->meth) { 960 if (group->meth != point->meth) {
961 ECerr(EC_F_EC_POINT_IS_AT_INFINITY, EC_R_INCOMPATIBLE_OBJECTS); 961 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
962 return 0; 962 return 0;
963 } 963 }
964 return group->meth->is_at_infinity(group, point); 964 return group->meth->is_at_infinity(group, point);
@@ -969,11 +969,11 @@ int
969EC_POINT_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ctx) 969EC_POINT_is_on_curve(const EC_GROUP * group, const EC_POINT * point, BN_CTX * ctx)
970{ 970{
971 if (group->meth->is_on_curve == 0) { 971 if (group->meth->is_on_curve == 0) {
972 ECerr(EC_F_EC_POINT_IS_ON_CURVE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 972 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
973 return 0; 973 return 0;
974 } 974 }
975 if (group->meth != point->meth) { 975 if (group->meth != point->meth) {
976 ECerr(EC_F_EC_POINT_IS_ON_CURVE, EC_R_INCOMPATIBLE_OBJECTS); 976 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
977 return 0; 977 return 0;
978 } 978 }
979 return group->meth->is_on_curve(group, point, ctx); 979 return group->meth->is_on_curve(group, point, ctx);
@@ -985,11 +985,11 @@ EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b,
985 BN_CTX * ctx) 985 BN_CTX * ctx)
986{ 986{
987 if (group->meth->point_cmp == 0) { 987 if (group->meth->point_cmp == 0) {
988 ECerr(EC_F_EC_POINT_CMP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 988 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
989 return -1; 989 return -1;
990 } 990 }
991 if ((group->meth != a->meth) || (a->meth != b->meth)) { 991 if ((group->meth != a->meth) || (a->meth != b->meth)) {
992 ECerr(EC_F_EC_POINT_CMP, EC_R_INCOMPATIBLE_OBJECTS); 992 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
993 return -1; 993 return -1;
994 } 994 }
995 return group->meth->point_cmp(group, a, b, ctx); 995 return group->meth->point_cmp(group, a, b, ctx);
@@ -1000,11 +1000,11 @@ int
1000EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) 1000EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
1001{ 1001{
1002 if (group->meth->make_affine == 0) { 1002 if (group->meth->make_affine == 0) {
1003 ECerr(EC_F_EC_POINT_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 1003 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1004 return 0; 1004 return 0;
1005 } 1005 }
1006 if (group->meth != point->meth) { 1006 if (group->meth != point->meth) {
1007 ECerr(EC_F_EC_POINT_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS); 1007 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
1008 return 0; 1008 return 0;
1009 } 1009 }
1010 return group->meth->make_affine(group, point, ctx); 1010 return group->meth->make_affine(group, point, ctx);
@@ -1018,12 +1018,12 @@ EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
1018 size_t i; 1018 size_t i;
1019 1019
1020 if (group->meth->points_make_affine == 0) { 1020 if (group->meth->points_make_affine == 0) {
1021 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 1021 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1022 return 0; 1022 return 0;
1023 } 1023 }
1024 for (i = 0; i < num; i++) { 1024 for (i = 0; i < num; i++) {
1025 if (group->meth != points[i]->meth) { 1025 if (group->meth != points[i]->meth) {
1026 ECerr(EC_F_EC_POINTS_MAKE_AFFINE, EC_R_INCOMPATIBLE_OBJECTS); 1026 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
1027 return 0; 1027 return 0;
1028 } 1028 }
1029 } 1029 }
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index e428ac586b..e44104d21c 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.20 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -107,7 +107,7 @@ ec_pre_comp_new(const EC_GROUP * group)
107 107
108 ret = malloc(sizeof(EC_PRE_COMP)); 108 ret = malloc(sizeof(EC_PRE_COMP));
109 if (!ret) { 109 if (!ret) {
110 ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 110 ECerror(ERR_R_MALLOC_FAILURE);
111 return ret; 111 return ret;
112 } 112 }
113 ret->group = group; 113 ret->group = group;
@@ -205,7 +205,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
205 if (BN_is_zero(scalar)) { 205 if (BN_is_zero(scalar)) {
206 r = malloc(1); 206 r = malloc(1);
207 if (!r) { 207 if (!r) {
208 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE); 208 ECerror(ERR_R_MALLOC_FAILURE);
209 goto err; 209 goto err;
210 } 210 }
211 r[0] = 0; 211 r[0] = 0;
@@ -215,7 +215,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
215 if (w <= 0 || w > 7) { 215 if (w <= 0 || w > 7) {
216 /* 'signed char' can represent integers with 216 /* 'signed char' can represent integers with
217 * absolute values less than 2^7 */ 217 * absolute values less than 2^7 */
218 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 218 ECerror(ERR_R_INTERNAL_ERROR);
219 goto err; 219 goto err;
220 } 220 }
221 bit = 1 << w; /* at most 128 */ 221 bit = 1 << w; /* at most 128 */
@@ -226,7 +226,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
226 sign = -1; 226 sign = -1;
227 } 227 }
228 if (scalar->d == NULL || scalar->top == 0) { 228 if (scalar->d == NULL || scalar->top == 0) {
229 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 229 ECerror(ERR_R_INTERNAL_ERROR);
230 goto err; 230 goto err;
231 } 231 }
232 len = BN_num_bits(scalar); 232 len = BN_num_bits(scalar);
@@ -235,7 +235,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
235 * set to the actual length, i.e. at most 235 * set to the actual length, i.e. at most
236 * BN_num_bits(scalar) + 1) */ 236 * BN_num_bits(scalar) + 1) */
237 if (r == NULL) { 237 if (r == NULL) {
238 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE); 238 ECerror(ERR_R_MALLOC_FAILURE);
239 goto err; 239 goto err;
240 } 240 }
241 window_val = scalar->d[0] & mask; 241 window_val = scalar->d[0] & mask;
@@ -269,7 +269,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
269 } 269 }
270 270
271 if (digit <= -bit || digit >= bit || !(digit & 1)) { 271 if (digit <= -bit || digit >= bit || !(digit & 1)) {
272 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 272 ECerror(ERR_R_INTERNAL_ERROR);
273 goto err; 273 goto err;
274 } 274 }
275 window_val -= digit; 275 window_val -= digit;
@@ -280,7 +280,7 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
280 * be 2^w 280 * be 2^w
281 */ 281 */
282 if (window_val != 0 && window_val != next_bit && window_val != bit) { 282 if (window_val != 0 && window_val != next_bit && window_val != bit) {
283 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 283 ECerror(ERR_R_INTERNAL_ERROR);
284 goto err; 284 goto err;
285 } 285 }
286 } 286 }
@@ -290,13 +290,13 @@ compute_wNAF(const BIGNUM * scalar, int w, size_t * ret_len)
290 window_val += bit * BN_is_bit_set(scalar, j + w); 290 window_val += bit * BN_is_bit_set(scalar, j + w);
291 291
292 if (window_val > next_bit) { 292 if (window_val > next_bit) {
293 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 293 ECerror(ERR_R_INTERNAL_ERROR);
294 goto err; 294 goto err;
295 } 295 }
296 } 296 }
297 297
298 if (j > len + 1) { 298 if (j > len + 1) {
299 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 299 ECerror(ERR_R_INTERNAL_ERROR);
300 goto err; 300 goto err;
301 } 301 }
302 len = j; 302 len = j;
@@ -363,7 +363,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
363 int ret = 0; 363 int ret = 0;
364 364
365 if (group->meth != r->meth) { 365 if (group->meth != r->meth) {
366 ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); 366 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
367 return 0; 367 return 0;
368 } 368 }
369 if ((scalar == NULL) && (num == 0)) { 369 if ((scalar == NULL) && (num == 0)) {
@@ -371,7 +371,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
371 } 371 }
372 for (i = 0; i < num; i++) { 372 for (i = 0; i < num; i++) {
373 if (group->meth != points[i]->meth) { 373 if (group->meth != points[i]->meth) {
374 ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); 374 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
375 return 0; 375 return 0;
376 } 376 }
377 } 377 }
@@ -384,7 +384,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
384 if (scalar != NULL) { 384 if (scalar != NULL) {
385 generator = EC_GROUP_get0_generator(group); 385 generator = EC_GROUP_get0_generator(group);
386 if (generator == NULL) { 386 if (generator == NULL) {
387 ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); 387 ECerror(EC_R_UNDEFINED_GENERATOR);
388 goto err; 388 goto err;
389 } 389 }
390 /* look if we can use precomputed multiples of generator */ 390 /* look if we can use precomputed multiples of generator */
@@ -413,7 +413,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
413 413
414 /* check that pre_comp looks sane */ 414 /* check that pre_comp looks sane */
415 if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { 415 if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {
416 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 416 ECerror(ERR_R_INTERNAL_ERROR);
417 goto err; 417 goto err;
418 } 418 }
419 } else { 419 } else {
@@ -429,7 +429,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
429 /* includes space for pivot */ 429 /* includes space for pivot */
430 wNAF = reallocarray(NULL, (totalnum + 1), sizeof wNAF[0]); 430 wNAF = reallocarray(NULL, (totalnum + 1), sizeof wNAF[0]);
431 if (wNAF == NULL) { 431 if (wNAF == NULL) {
432 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 432 ECerror(ERR_R_MALLOC_FAILURE);
433 goto err; 433 goto err;
434 } 434 }
435 435
@@ -440,7 +440,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
440 val_sub = reallocarray(NULL, totalnum, sizeof val_sub[0]); 440 val_sub = reallocarray(NULL, totalnum, sizeof val_sub[0]);
441 441
442 if (wsize == NULL || wNAF_len == NULL || val_sub == NULL) { 442 if (wsize == NULL || wNAF_len == NULL || val_sub == NULL) {
443 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 443 ECerror(ERR_R_MALLOC_FAILURE);
444 goto err; 444 goto err;
445 } 445 }
446 446
@@ -466,7 +466,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
466 466
467 if (pre_comp == NULL) { 467 if (pre_comp == NULL) {
468 if (num_scalar != 1) { 468 if (num_scalar != 1) {
469 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 469 ECerror(ERR_R_INTERNAL_ERROR);
470 goto err; 470 goto err;
471 } 471 }
472 /* we have already generated a wNAF for 'scalar' */ 472 /* we have already generated a wNAF for 'scalar' */
@@ -474,7 +474,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
474 size_t tmp_len = 0; 474 size_t tmp_len = 0;
475 475
476 if (num_scalar != 0) { 476 if (num_scalar != 0) {
477 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 477 ECerror(ERR_R_INTERNAL_ERROR);
478 goto err; 478 goto err;
479 } 479 }
480 /* 480 /*
@@ -524,7 +524,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
524 */ 524 */
525 numblocks = (tmp_len + blocksize - 1) / blocksize; 525 numblocks = (tmp_len + blocksize - 1) / blocksize;
526 if (numblocks > pre_comp->numblocks) { 526 if (numblocks > pre_comp->numblocks) {
527 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 527 ECerror(ERR_R_INTERNAL_ERROR);
528 goto err; 528 goto err;
529 } 529 }
530 totalnum = num + numblocks; 530 totalnum = num + numblocks;
@@ -537,7 +537,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
537 if (i < totalnum - 1) { 537 if (i < totalnum - 1) {
538 wNAF_len[i] = blocksize; 538 wNAF_len[i] = blocksize;
539 if (tmp_len < blocksize) { 539 if (tmp_len < blocksize) {
540 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 540 ECerror(ERR_R_INTERNAL_ERROR);
541 goto err; 541 goto err;
542 } 542 }
543 tmp_len -= blocksize; 543 tmp_len -= blocksize;
@@ -553,7 +553,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
553 wNAF[i + 1] = NULL; 553 wNAF[i + 1] = NULL;
554 wNAF[i] = malloc(wNAF_len[i]); 554 wNAF[i] = malloc(wNAF_len[i]);
555 if (wNAF[i] == NULL) { 555 if (wNAF[i] == NULL) {
556 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 556 ECerror(ERR_R_MALLOC_FAILURE);
557 goto err; 557 goto err;
558 } 558 }
559 memcpy(wNAF[i], pp, wNAF_len[i]); 559 memcpy(wNAF[i], pp, wNAF_len[i]);
@@ -561,7 +561,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
561 max_len = wNAF_len[i]; 561 max_len = wNAF_len[i];
562 562
563 if (*tmp_points == NULL) { 563 if (*tmp_points == NULL) {
564 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 564 ECerror(ERR_R_INTERNAL_ERROR);
565 goto err; 565 goto err;
566 } 566 }
567 val_sub[i] = tmp_points; 567 val_sub[i] = tmp_points;
@@ -579,7 +579,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
579 */ 579 */
580 val = reallocarray(NULL, (num_val + 1), sizeof val[0]); 580 val = reallocarray(NULL, (num_val + 1), sizeof val[0]);
581 if (val == NULL) { 581 if (val == NULL) {
582 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 582 ECerror(ERR_R_MALLOC_FAILURE);
583 goto err; 583 goto err;
584 } 584 }
585 val[num_val] = NULL; /* pivot element */ 585 val[num_val] = NULL; /* pivot element */
@@ -596,7 +596,7 @@ ec_wNAF_mul(const EC_GROUP * group, EC_POINT * r, const BIGNUM * scalar,
596 } 596 }
597 } 597 }
598 if (!(v == val + num_val)) { 598 if (!(v == val + num_val)) {
599 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 599 ECerror(ERR_R_INTERNAL_ERROR);
600 goto err; 600 goto err;
601 } 601 }
602 if (!(tmp = EC_POINT_new(group))) 602 if (!(tmp = EC_POINT_new(group)))
@@ -743,7 +743,7 @@ ec_wNAF_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
743 743
744 generator = EC_GROUP_get0_generator(group); 744 generator = EC_GROUP_get0_generator(group);
745 if (generator == NULL) { 745 if (generator == NULL) {
746 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR); 746 ECerror(EC_R_UNDEFINED_GENERATOR);
747 goto err; 747 goto err;
748 } 748 }
749 if (ctx == NULL) { 749 if (ctx == NULL) {
@@ -758,7 +758,7 @@ ec_wNAF_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
758 if (!EC_GROUP_get_order(group, order, ctx)) 758 if (!EC_GROUP_get_order(group, order, ctx))
759 goto err; 759 goto err;
760 if (BN_is_zero(order)) { 760 if (BN_is_zero(order)) {
761 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER); 761 ECerror(EC_R_UNKNOWN_ORDER);
762 goto err; 762 goto err;
763 } 763 }
764 bits = BN_num_bits(order); 764 bits = BN_num_bits(order);
@@ -786,20 +786,20 @@ ec_wNAF_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
786 786
787 points = reallocarray(NULL, (num + 1), sizeof(EC_POINT *)); 787 points = reallocarray(NULL, (num + 1), sizeof(EC_POINT *));
788 if (!points) { 788 if (!points) {
789 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); 789 ECerror(ERR_R_MALLOC_FAILURE);
790 goto err; 790 goto err;
791 } 791 }
792 var = points; 792 var = points;
793 var[num] = NULL; /* pivot */ 793 var[num] = NULL; /* pivot */
794 for (i = 0; i < num; i++) { 794 for (i = 0; i < num; i++) {
795 if ((var[i] = EC_POINT_new(group)) == NULL) { 795 if ((var[i] = EC_POINT_new(group)) == NULL) {
796 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); 796 ECerror(ERR_R_MALLOC_FAILURE);
797 goto err; 797 goto err;
798 } 798 }
799 } 799 }
800 800
801 if (!(tmp_point = EC_POINT_new(group)) || !(base = EC_POINT_new(group))) { 801 if (!(tmp_point = EC_POINT_new(group)) || !(base = EC_POINT_new(group))) {
802 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); 802 ECerror(ERR_R_MALLOC_FAILURE);
803 goto err; 803 goto err;
804 } 804 }
805 if (!EC_POINT_copy(base, generator)) 805 if (!EC_POINT_copy(base, generator))
@@ -829,7 +829,7 @@ ec_wNAF_precompute_mult(EC_GROUP * group, BN_CTX * ctx)
829 size_t k; 829 size_t k;
830 830
831 if (blocksize <= 2) { 831 if (blocksize <= 2) {
832 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_INTERNAL_ERROR); 832 ECerror(ERR_R_INTERNAL_ERROR);
833 goto err; 833 goto err;
834 } 834 }
835 if (!EC_POINT_dbl(group, base, tmp_point, ctx)) 835 if (!EC_POINT_dbl(group, base, tmp_point, ctx))
diff --git a/src/lib/libcrypto/ec/ec_oct.c b/src/lib/libcrypto/ec/ec_oct.c
index 82124a8f80..f44b174fd7 100644
--- a/src/lib/libcrypto/ec/ec_oct.c
+++ b/src/lib/libcrypto/ec/ec_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_oct.c,v 1.4 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ec_oct.c,v 1.5 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -76,11 +76,11 @@ EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP * group, EC_POINT * point
76{ 76{
77 if (group->meth->point_set_compressed_coordinates == 0 77 if (group->meth->point_set_compressed_coordinates == 0
78 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { 78 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
79 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 79 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
80 return 0; 80 return 0;
81 } 81 }
82 if (group->meth != point->meth) { 82 if (group->meth != point->meth) {
83 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 83 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
84 return 0; 84 return 0;
85 } 85 }
86 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { 86 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
@@ -90,7 +90,7 @@ EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP * group, EC_POINT * point
90 else 90 else
91#ifdef OPENSSL_NO_EC2M 91#ifdef OPENSSL_NO_EC2M
92 { 92 {
93 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_GF2M_NOT_SUPPORTED); 93 ECerror(EC_R_GF2M_NOT_SUPPORTED);
94 return 0; 94 return 0;
95 } 95 }
96#else 96#else
@@ -108,11 +108,11 @@ EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP * group, EC_POINT * poin
108{ 108{
109 if (group->meth->point_set_compressed_coordinates == 0 109 if (group->meth->point_set_compressed_coordinates == 0
110 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { 110 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
111 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 111 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
112 return 0; 112 return 0;
113 } 113 }
114 if (group->meth != point->meth) { 114 if (group->meth != point->meth) {
115 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS); 115 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
116 return 0; 116 return 0;
117 } 117 }
118 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { 118 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
@@ -134,11 +134,11 @@ EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point,
134{ 134{
135 if (group->meth->point2oct == 0 135 if (group->meth->point2oct == 0
136 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { 136 && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
137 ECerr(EC_F_EC_POINT_POINT2OCT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 137 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
138 return 0; 138 return 0;
139 } 139 }
140 if (group->meth != point->meth) { 140 if (group->meth != point->meth) {
141 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_INCOMPATIBLE_OBJECTS); 141 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
142 return 0; 142 return 0;
143 } 143 }
144 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { 144 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
@@ -148,7 +148,7 @@ EC_POINT_point2oct(const EC_GROUP *group, const EC_POINT *point,
148 else 148 else
149#ifdef OPENSSL_NO_EC2M 149#ifdef OPENSSL_NO_EC2M
150 { 150 {
151 ECerr(EC_F_EC_POINT_POINT2OCT, EC_R_GF2M_NOT_SUPPORTED); 151 ECerror(EC_R_GF2M_NOT_SUPPORTED);
152 return 0; 152 return 0;
153 } 153 }
154#else 154#else
@@ -166,11 +166,11 @@ EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
166{ 166{
167 if (group->meth->oct2point == 0 && 167 if (group->meth->oct2point == 0 &&
168 !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) { 168 !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {
169 ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 169 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
170 return 0; 170 return 0;
171 } 171 }
172 if (group->meth != point->meth) { 172 if (group->meth != point->meth) {
173 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS); 173 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
174 return 0; 174 return 0;
175 } 175 }
176 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) { 176 if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
@@ -180,7 +180,7 @@ EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
180 else 180 else
181#ifdef OPENSSL_NO_EC2M 181#ifdef OPENSSL_NO_EC2M
182 { 182 {
183 ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED); 183 ECerror(EC_R_GF2M_NOT_SUPPORTED);
184 return 0; 184 return 0;
185 } 185 }
186#else 186#else
diff --git a/src/lib/libcrypto/ec/ec_pmeth.c b/src/lib/libcrypto/ec/ec_pmeth.c
index a52bff1f2f..08172fe0c6 100644
--- a/src/lib/libcrypto/ec/ec_pmeth.c
+++ b/src/lib/libcrypto/ec/ec_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_pmeth.c,v 1.9 2015/06/20 14:19:39 jsing Exp $ */ 1/* $OpenBSD: ec_pmeth.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -132,7 +132,7 @@ pkey_ec_sign(EVP_PKEY_CTX * ctx, unsigned char *sig, size_t * siglen,
132 *siglen = ECDSA_size(ec); 132 *siglen = ECDSA_size(ec);
133 return 1; 133 return 1;
134 } else if (*siglen < (size_t) ECDSA_size(ec)) { 134 } else if (*siglen < (size_t) ECDSA_size(ec)) {
135 ECerr(EC_F_PKEY_EC_SIGN, EC_R_BUFFER_TOO_SMALL); 135 ECerror(EC_R_BUFFER_TOO_SMALL);
136 return 0; 136 return 0;
137 } 137 }
138 if (dctx->md) 138 if (dctx->md)
@@ -175,7 +175,7 @@ pkey_ec_derive(EVP_PKEY_CTX * ctx, unsigned char *key, size_t * keylen)
175 size_t outlen; 175 size_t outlen;
176 const EC_POINT *pubkey = NULL; 176 const EC_POINT *pubkey = NULL;
177 if (!ctx->pkey || !ctx->peerkey) { 177 if (!ctx->pkey || !ctx->peerkey) {
178 ECerr(EC_F_PKEY_EC_DERIVE, EC_R_KEYS_NOT_SET); 178 ECerror(EC_R_KEYS_NOT_SET);
179 return 0; 179 return 0;
180 } 180 }
181 if (!key) { 181 if (!key) {
@@ -209,7 +209,7 @@ pkey_ec_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2)
209 case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID: 209 case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID:
210 group = EC_GROUP_new_by_curve_name(p1); 210 group = EC_GROUP_new_by_curve_name(p1);
211 if (group == NULL) { 211 if (group == NULL) {
212 ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_CURVE); 212 ECerror(EC_R_INVALID_CURVE);
213 return 0; 213 return 0;
214 } 214 }
215 EC_GROUP_free(dctx->gen_group); 215 EC_GROUP_free(dctx->gen_group);
@@ -223,7 +223,7 @@ pkey_ec_ctrl(EVP_PKEY_CTX * ctx, int type, int p1, void *p2)
223 EVP_MD_type((const EVP_MD *) p2) != NID_sha256 && 223 EVP_MD_type((const EVP_MD *) p2) != NID_sha256 &&
224 EVP_MD_type((const EVP_MD *) p2) != NID_sha384 && 224 EVP_MD_type((const EVP_MD *) p2) != NID_sha384 &&
225 EVP_MD_type((const EVP_MD *) p2) != NID_sha512) { 225 EVP_MD_type((const EVP_MD *) p2) != NID_sha512) {
226 ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_DIGEST_TYPE); 226 ECerror(EC_R_INVALID_DIGEST_TYPE);
227 return 0; 227 return 0;
228 } 228 }
229 dctx->md = p2; 229 dctx->md = p2;
@@ -254,7 +254,7 @@ pkey_ec_ctrl_str(EVP_PKEY_CTX * ctx,
254 if (nid == NID_undef) 254 if (nid == NID_undef)
255 nid = OBJ_ln2nid(value); 255 nid = OBJ_ln2nid(value);
256 if (nid == NID_undef) { 256 if (nid == NID_undef) {
257 ECerr(EC_F_PKEY_EC_CTRL_STR, EC_R_INVALID_CURVE); 257 ECerror(EC_R_INVALID_CURVE);
258 return 0; 258 return 0;
259 } 259 }
260 return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid); 260 return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid);
@@ -269,7 +269,7 @@ pkey_ec_paramgen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey)
269 EC_PKEY_CTX *dctx = ctx->data; 269 EC_PKEY_CTX *dctx = ctx->data;
270 int ret = 0; 270 int ret = 0;
271 if (dctx->gen_group == NULL) { 271 if (dctx->gen_group == NULL) {
272 ECerr(EC_F_PKEY_EC_PARAMGEN, EC_R_NO_PARAMETERS_SET); 272 ECerror(EC_R_NO_PARAMETERS_SET);
273 return 0; 273 return 0;
274 } 274 }
275 ec = EC_KEY_new(); 275 ec = EC_KEY_new();
@@ -288,7 +288,7 @@ pkey_ec_keygen(EVP_PKEY_CTX * ctx, EVP_PKEY * pkey)
288{ 288{
289 EC_KEY *ec = NULL; 289 EC_KEY *ec = NULL;
290 if (ctx->pkey == NULL) { 290 if (ctx->pkey == NULL) {
291 ECerr(EC_F_PKEY_EC_KEYGEN, EC_R_NO_PARAMETERS_SET); 291 ECerror(EC_R_NO_PARAMETERS_SET);
292 return 0; 292 return 0;
293 } 293 }
294 ec = EC_KEY_new(); 294 ec = EC_KEY_new();
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c
index 06cdd69591..653d78e5cd 100644
--- a/src/lib/libcrypto/ec/eck_prn.c
+++ b/src/lib/libcrypto/ec/eck_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eck_prn.c,v 1.11 2015/06/20 14:17:07 jsing Exp $ */ 1/* $OpenBSD: eck_prn.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -78,7 +78,7 @@ ECPKParameters_print_fp(FILE * fp, const EC_GROUP * x, int off)
78 int ret; 78 int ret;
79 79
80 if ((b = BIO_new(BIO_s_file())) == NULL) { 80 if ((b = BIO_new(BIO_s_file())) == NULL) {
81 ECerr(EC_F_ECPKPARAMETERS_PRINT_FP, ERR_R_BUF_LIB); 81 ECerror(ERR_R_BUF_LIB);
82 return (0); 82 return (0);
83 } 83 }
84 BIO_set_fp(b, fp, BIO_NOCLOSE); 84 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -94,7 +94,7 @@ EC_KEY_print_fp(FILE * fp, const EC_KEY * x, int off)
94 int ret; 94 int ret;
95 95
96 if ((b = BIO_new(BIO_s_file())) == NULL) { 96 if ((b = BIO_new(BIO_s_file())) == NULL) {
97 ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB); 97 ECerror(ERR_R_BIO_LIB);
98 return (0); 98 return (0);
99 } 99 }
100 BIO_set_fp(b, fp, BIO_NOCLOSE); 100 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -110,7 +110,7 @@ ECParameters_print_fp(FILE * fp, const EC_KEY * x)
110 int ret; 110 int ret;
111 111
112 if ((b = BIO_new(BIO_s_file())) == NULL) { 112 if ((b = BIO_new(BIO_s_file())) == NULL) {
113 ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB); 113 ECerror(ERR_R_BIO_LIB);
114 return (0); 114 return (0);
115 } 115 }
116 BIO_set_fp(b, fp, BIO_NOCLOSE); 116 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -323,7 +323,7 @@ ECPKParameters_print(BIO * bp, const EC_GROUP * x, int off)
323 ret = 1; 323 ret = 1;
324err: 324err:
325 if (!ret) 325 if (!ret)
326 ECerr(EC_F_ECPKPARAMETERS_PRINT, reason); 326 ECerror(reason);
327 BN_free(p); 327 BN_free(p);
328 BN_free(a); 328 BN_free(a);
329 BN_free(b); 329 BN_free(b);
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index a3ad4e1ce9..68fc26de1e 100644
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_mont.c,v 1.10 2015/02/13 00:46:03 beck Exp $ */ 1/* $OpenBSD: ecp_mont.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -203,7 +203,7 @@ ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
203 if (mont == NULL) 203 if (mont == NULL)
204 goto err; 204 goto err;
205 if (!BN_MONT_CTX_set(mont, p, ctx)) { 205 if (!BN_MONT_CTX_set(mont, p, ctx)) {
206 ECerr(EC_F_EC_GFP_MONT_GROUP_SET_CURVE, ERR_R_BN_LIB); 206 ECerror(ERR_R_BN_LIB);
207 goto err; 207 goto err;
208 } 208 }
209 one = BN_new(); 209 one = BN_new();
@@ -238,7 +238,7 @@ ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
238 const BIGNUM *b, BN_CTX *ctx) 238 const BIGNUM *b, BN_CTX *ctx)
239{ 239{
240 if (group->field_data1 == NULL) { 240 if (group->field_data1 == NULL) {
241 ECerr(EC_F_EC_GFP_MONT_FIELD_MUL, EC_R_NOT_INITIALIZED); 241 ECerror(EC_R_NOT_INITIALIZED);
242 return 0; 242 return 0;
243 } 243 }
244 return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx); 244 return BN_mod_mul_montgomery(r, a, b, group->field_data1, ctx);
@@ -250,7 +250,7 @@ ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
250 BN_CTX *ctx) 250 BN_CTX *ctx)
251{ 251{
252 if (group->field_data1 == NULL) { 252 if (group->field_data1 == NULL) {
253 ECerr(EC_F_EC_GFP_MONT_FIELD_SQR, EC_R_NOT_INITIALIZED); 253 ECerror(EC_R_NOT_INITIALIZED);
254 return 0; 254 return 0;
255 } 255 }
256 return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx); 256 return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);
@@ -262,7 +262,7 @@ ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
262 BN_CTX *ctx) 262 BN_CTX *ctx)
263{ 263{
264 if (group->field_data1 == NULL) { 264 if (group->field_data1 == NULL) {
265 ECerr(EC_F_EC_GFP_MONT_FIELD_ENCODE, EC_R_NOT_INITIALIZED); 265 ECerror(EC_R_NOT_INITIALIZED);
266 return 0; 266 return 0;
267 } 267 }
268 return BN_to_montgomery(r, a, (BN_MONT_CTX *) group->field_data1, ctx); 268 return BN_to_montgomery(r, a, (BN_MONT_CTX *) group->field_data1, ctx);
@@ -274,7 +274,7 @@ ec_GFp_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
274 BN_CTX *ctx) 274 BN_CTX *ctx)
275{ 275{
276 if (group->field_data1 == NULL) { 276 if (group->field_data1 == NULL) {
277 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED); 277 ECerror(EC_R_NOT_INITIALIZED);
278 return 0; 278 return 0;
279 } 279 }
280 return BN_from_montgomery(r, a, group->field_data1, ctx); 280 return BN_from_montgomery(r, a, group->field_data1, ctx);
@@ -285,7 +285,7 @@ int
285ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx) 285ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
286{ 286{
287 if (group->field_data2 == NULL) { 287 if (group->field_data2 == NULL) {
288 ECerr(EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE, EC_R_NOT_INITIALIZED); 288 ECerror(EC_R_NOT_INITIALIZED);
289 return 0; 289 return 0;
290 } 290 }
291 if (!BN_copy(r, group->field_data2)) 291 if (!BN_copy(r, group->field_data2))
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
index a33f9d9e39..24cba64d2e 100644
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nist.c,v 1.9 2014/07/12 16:03:37 miod Exp $ */ 1/* $OpenBSD: ecp_nist.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -145,7 +145,7 @@ ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
145 else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0) 145 else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0)
146 group->field_mod_func = BN_nist_mod_521; 146 group->field_mod_func = BN_nist_mod_521;
147 else { 147 else {
148 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_NIST_PRIME); 148 ECerror(EC_R_NOT_A_NIST_PRIME);
149 goto err; 149 goto err;
150 } 150 }
151 151
@@ -166,7 +166,7 @@ ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
166 BN_CTX *ctx_new = NULL; 166 BN_CTX *ctx_new = NULL;
167 167
168 if (!group || !r || !a || !b) { 168 if (!group || !r || !a || !b) {
169 ECerr(EC_F_EC_GFP_NIST_FIELD_MUL, ERR_R_PASSED_NULL_PARAMETER); 169 ECerror(ERR_R_PASSED_NULL_PARAMETER);
170 goto err; 170 goto err;
171 } 171 }
172 if (!ctx) 172 if (!ctx)
@@ -193,7 +193,7 @@ ec_GFp_nist_field_sqr(const EC_GROUP * group, BIGNUM * r, const BIGNUM * a,
193 BN_CTX *ctx_new = NULL; 193 BN_CTX *ctx_new = NULL;
194 194
195 if (!group || !r || !a) { 195 if (!group || !r || !a) {
196 ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER); 196 ECerror(EC_R_PASSED_NULL_PARAMETER);
197 goto err; 197 goto err;
198 } 198 }
199 if (!ctx) 199 if (!ctx)
diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c
index 0976f24a9f..38dd83b6d9 100644
--- a/src/lib/libcrypto/ec/ecp_nistp224.c
+++ b/src/lib/libcrypto/ec/ecp_nistp224.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp224.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp224.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Emilia Kasper (Google) for the OpenSSL project. 3 * Written by Emilia Kasper (Google) for the OpenSSL project.
4 */ 4 */
@@ -319,11 +319,11 @@ BN_to_felem(felem out, const BIGNUM * bn)
319 memset(b_out, 0, sizeof b_out); 319 memset(b_out, 0, sizeof b_out);
320 num_bytes = BN_num_bytes(bn); 320 num_bytes = BN_num_bytes(bn);
321 if (num_bytes > sizeof b_out) { 321 if (num_bytes > sizeof b_out) {
322 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 322 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
323 return 0; 323 return 0;
324 } 324 }
325 if (BN_is_negative(bn)) { 325 if (BN_is_negative(bn)) {
326 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 326 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
327 return 0; 327 return 0;
328 } 328 }
329 num_bytes = BN_bn2bin(bn, b_in); 329 num_bytes = BN_bn2bin(bn, b_in);
@@ -1191,7 +1191,7 @@ nistp224_pre_comp_new()
1191 NISTP224_PRE_COMP *ret = NULL; 1191 NISTP224_PRE_COMP *ret = NULL;
1192 ret = malloc(sizeof *ret); 1192 ret = malloc(sizeof *ret);
1193 if (!ret) { 1193 if (!ret) {
1194 ECerr(EC_F_NISTP224_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1194 ECerror(ERR_R_MALLOC_FAILURE);
1195 return ret; 1195 return ret;
1196 } 1196 }
1197 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp)); 1197 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp));
@@ -1277,8 +1277,7 @@ ec_GFp_nistp224_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1277 BN_bin2bn(nistp224_curve_params[2], sizeof(felem_bytearray), curve_b); 1277 BN_bin2bn(nistp224_curve_params[2], sizeof(felem_bytearray), curve_b);
1278 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) || 1278 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) ||
1279 (BN_cmp(curve_b, b))) { 1279 (BN_cmp(curve_b, b))) {
1280 ECerr(EC_F_EC_GFP_NISTP224_GROUP_SET_CURVE, 1280 ECerror(EC_R_WRONG_CURVE_PARAMETERS);
1281 EC_R_WRONG_CURVE_PARAMETERS);
1282 goto err; 1281 goto err;
1283 } 1282 }
1284 group->field_mod_func = BN_nist_mod_224; 1283 group->field_mod_func = BN_nist_mod_224;
@@ -1299,8 +1298,7 @@ ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP * group,
1299 widefelem tmp; 1298 widefelem tmp;
1300 1299
1301 if (EC_POINT_is_at_infinity(group, point) > 0) { 1300 if (EC_POINT_is_at_infinity(group, point) > 0) {
1302 ECerr(EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES, 1301 ECerror(EC_R_POINT_AT_INFINITY);
1303 EC_R_POINT_AT_INFINITY);
1304 return 0; 1302 return 0;
1305 } 1303 }
1306 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) || 1304 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) ||
@@ -1314,8 +1312,7 @@ ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP * group,
1314 felem_contract(x_out, x_in); 1312 felem_contract(x_out, x_in);
1315 if (x != NULL) { 1313 if (x != NULL) {
1316 if (!felem_to_BN(x, x_out)) { 1314 if (!felem_to_BN(x, x_out)) {
1317 ECerr(EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES, 1315 ECerror(ERR_R_BN_LIB);
1318 ERR_R_BN_LIB);
1319 return 0; 1316 return 0;
1320 } 1317 }
1321 } 1318 }
@@ -1326,8 +1323,7 @@ ec_GFp_nistp224_point_get_affine_coordinates(const EC_GROUP * group,
1326 felem_contract(y_out, y_in); 1323 felem_contract(y_out, y_in);
1327 if (y != NULL) { 1324 if (y != NULL) {
1328 if (!felem_to_BN(y, y_out)) { 1325 if (!felem_to_BN(y, y_out)) {
1329 ECerr(EC_F_EC_GFP_NISTP224_POINT_GET_AFFINE_COORDINATES, 1326 ECerror(ERR_R_BN_LIB);
1330 ERR_R_BN_LIB);
1331 return 0; 1327 return 0;
1332 } 1328 }
1333 } 1329 }
@@ -1410,7 +1406,7 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1410 if (!felem_to_BN(x, g_pre_comp[0][1][0]) || 1406 if (!felem_to_BN(x, g_pre_comp[0][1][0]) ||
1411 !felem_to_BN(y, g_pre_comp[0][1][1]) || 1407 !felem_to_BN(y, g_pre_comp[0][1][1]) ||
1412 !felem_to_BN(z, g_pre_comp[0][1][2])) { 1408 !felem_to_BN(z, g_pre_comp[0][1][2])) {
1413 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB); 1409 ECerror(ERR_R_BN_LIB);
1414 goto err; 1410 goto err;
1415 } 1411 }
1416 if (!EC_POINT_set_Jprojective_coordinates_GFp(group, 1412 if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
@@ -1443,7 +1439,7 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1443 (num_points * 17 + 1), sizeof(felem)); 1439 (num_points * 17 + 1), sizeof(felem));
1444 } 1440 }
1445 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) { 1441 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) {
1446 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1442 ECerror(ERR_R_MALLOC_FAILURE);
1447 goto err; 1443 goto err;
1448 } 1444 }
1449 /* 1445 /*
@@ -1471,7 +1467,7 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1471 * don't guarantee constant-timeness 1467 * don't guarantee constant-timeness
1472 */ 1468 */
1473 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) { 1469 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) {
1474 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB); 1470 ECerror(ERR_R_BN_LIB);
1475 goto err; 1471 goto err;
1476 } 1472 }
1477 num_bytes = BN_bn2bin(tmp_scalar, tmp); 1473 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -1513,7 +1509,7 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1513 * constant-timeness 1509 * constant-timeness
1514 */ 1510 */
1515 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) { 1511 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) {
1516 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB); 1512 ECerror(ERR_R_BN_LIB);
1517 goto err; 1513 goto err;
1518 } 1514 }
1519 num_bytes = BN_bn2bin(tmp_scalar, tmp); 1515 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -1537,7 +1533,7 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r,
1537 felem_contract(z_in, z_out); 1533 felem_contract(z_in, z_out);
1538 if ((!felem_to_BN(x, x_in)) || (!felem_to_BN(y, y_in)) || 1534 if ((!felem_to_BN(x, x_in)) || (!felem_to_BN(y, y_in)) ||
1539 (!felem_to_BN(z, z_in))) { 1535 (!felem_to_BN(z, z_in))) {
1540 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_BN_LIB); 1536 ECerror(ERR_R_BN_LIB);
1541 goto err; 1537 goto err;
1542 } 1538 }
1543 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx); 1539 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c
index be1d2a5402..4771a92efd 100644
--- a/src/lib/libcrypto/ec/ecp_nistp256.c
+++ b/src/lib/libcrypto/ec/ecp_nistp256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp256.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp256.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -156,11 +156,11 @@ BN_to_felem(felem out, const BIGNUM * bn)
156 memset(b_out, 0, sizeof b_out); 156 memset(b_out, 0, sizeof b_out);
157 num_bytes = BN_num_bytes(bn); 157 num_bytes = BN_num_bytes(bn);
158 if (num_bytes > sizeof b_out) { 158 if (num_bytes > sizeof b_out) {
159 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 159 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
160 return 0; 160 return 0;
161 } 161 }
162 if (BN_is_negative(bn)) { 162 if (BN_is_negative(bn)) {
163 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 163 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
164 return 0; 164 return 0;
165 } 165 }
166 num_bytes = BN_bn2bin(bn, b_in); 166 num_bytes = BN_bn2bin(bn, b_in);
@@ -1740,7 +1740,7 @@ nistp256_pre_comp_new()
1740 NISTP256_PRE_COMP *ret = NULL; 1740 NISTP256_PRE_COMP *ret = NULL;
1741 ret = malloc(sizeof *ret); 1741 ret = malloc(sizeof *ret);
1742 if (!ret) { 1742 if (!ret) {
1743 ECerr(EC_F_NISTP256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1743 ECerror(ERR_R_MALLOC_FAILURE);
1744 return ret; 1744 return ret;
1745 } 1745 }
1746 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp)); 1746 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp));
@@ -1826,8 +1826,7 @@ ec_GFp_nistp256_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1826 BN_bin2bn(nistp256_curve_params[2], sizeof(felem_bytearray), curve_b); 1826 BN_bin2bn(nistp256_curve_params[2], sizeof(felem_bytearray), curve_b);
1827 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) || 1827 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) ||
1828 (BN_cmp(curve_b, b))) { 1828 (BN_cmp(curve_b, b))) {
1829 ECerr(EC_F_EC_GFP_NISTP256_GROUP_SET_CURVE, 1829 ECerror(EC_R_WRONG_CURVE_PARAMETERS);
1830 EC_R_WRONG_CURVE_PARAMETERS);
1831 goto err; 1830 goto err;
1832 } 1831 }
1833 group->field_mod_func = BN_nist_mod_256; 1832 group->field_mod_func = BN_nist_mod_256;
@@ -1849,8 +1848,7 @@ ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP * group,
1849 longfelem tmp; 1848 longfelem tmp;
1850 1849
1851 if (EC_POINT_is_at_infinity(group, point) > 0) { 1850 if (EC_POINT_is_at_infinity(group, point) > 0) {
1852 ECerr(EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES, 1851 ECerror(EC_R_POINT_AT_INFINITY);
1853 EC_R_POINT_AT_INFINITY);
1854 return 0; 1852 return 0;
1855 } 1853 }
1856 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) || 1854 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) ||
@@ -1864,8 +1862,7 @@ ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP * group,
1864 felem_contract(x_out, x_in); 1862 felem_contract(x_out, x_in);
1865 if (x != NULL) { 1863 if (x != NULL) {
1866 if (!smallfelem_to_BN(x, x_out)) { 1864 if (!smallfelem_to_BN(x, x_out)) {
1867 ECerr(EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES, 1865 ECerror(ERR_R_BN_LIB);
1868 ERR_R_BN_LIB);
1869 return 0; 1866 return 0;
1870 } 1867 }
1871 } 1868 }
@@ -1876,8 +1873,7 @@ ec_GFp_nistp256_point_get_affine_coordinates(const EC_GROUP * group,
1876 felem_contract(y_out, y_in); 1873 felem_contract(y_out, y_in);
1877 if (y != NULL) { 1874 if (y != NULL) {
1878 if (!smallfelem_to_BN(y, y_out)) { 1875 if (!smallfelem_to_BN(y, y_out)) {
1879 ECerr(EC_F_EC_GFP_NISTP256_POINT_GET_AFFINE_COORDINATES, 1876 ECerror(ERR_R_BN_LIB);
1880 ERR_R_BN_LIB);
1881 return 0; 1877 return 0;
1882 } 1878 }
1883 } 1879 }
@@ -1960,7 +1956,7 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
1960 if (!smallfelem_to_BN(x, g_pre_comp[0][1][0]) || 1956 if (!smallfelem_to_BN(x, g_pre_comp[0][1][0]) ||
1961 !smallfelem_to_BN(y, g_pre_comp[0][1][1]) || 1957 !smallfelem_to_BN(y, g_pre_comp[0][1][1]) ||
1962 !smallfelem_to_BN(z, g_pre_comp[0][1][2])) { 1958 !smallfelem_to_BN(z, g_pre_comp[0][1][2])) {
1963 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB); 1959 ECerror(ERR_R_BN_LIB);
1964 goto err; 1960 goto err;
1965 } 1961 }
1966 if (!EC_POINT_set_Jprojective_coordinates_GFp(group, 1962 if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
@@ -1993,7 +1989,7 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
1993 (num_points * 17 + 1), sizeof(smallfelem)); 1989 (num_points * 17 + 1), sizeof(smallfelem));
1994 } 1990 }
1995 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_smallfelems == NULL))) { 1991 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_smallfelems == NULL))) {
1996 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1992 ECerror(ERR_R_MALLOC_FAILURE);
1997 goto err; 1993 goto err;
1998 } 1994 }
1999 /* 1995 /*
@@ -2024,7 +2020,7 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
2024 * don't guarantee constant-timeness 2020 * don't guarantee constant-timeness
2025 */ 2021 */
2026 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) { 2022 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) {
2027 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB); 2023 ECerror(ERR_R_BN_LIB);
2028 goto err; 2024 goto err;
2029 } 2025 }
2030 num_bytes = BN_bn2bin(tmp_scalar, tmp); 2026 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -2066,7 +2062,7 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
2066 * constant-timeness 2062 * constant-timeness
2067 */ 2063 */
2068 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) { 2064 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) {
2069 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB); 2065 ECerror(ERR_R_BN_LIB);
2070 goto err; 2066 goto err;
2071 } 2067 }
2072 num_bytes = BN_bn2bin(tmp_scalar, tmp); 2068 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -2090,7 +2086,7 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r,
2090 felem_contract(z_in, z_out); 2086 felem_contract(z_in, z_out);
2091 if ((!smallfelem_to_BN(x, x_in)) || (!smallfelem_to_BN(y, y_in)) || 2087 if ((!smallfelem_to_BN(x, x_in)) || (!smallfelem_to_BN(y, y_in)) ||
2092 (!smallfelem_to_BN(z, z_in))) { 2088 (!smallfelem_to_BN(z, z_in))) {
2093 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_BN_LIB); 2089 ECerror(ERR_R_BN_LIB);
2094 goto err; 2090 goto err;
2095 } 2091 }
2096 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx); 2092 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c
index cfa13b41f8..22bafe392f 100644
--- a/src/lib/libcrypto/ec/ecp_nistp521.c
+++ b/src/lib/libcrypto/ec/ecp_nistp521.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp521.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ecp_nistp521.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -182,11 +182,11 @@ BN_to_felem(felem out, const BIGNUM * bn)
182 memset(b_out, 0, sizeof b_out); 182 memset(b_out, 0, sizeof b_out);
183 num_bytes = BN_num_bytes(bn); 183 num_bytes = BN_num_bytes(bn);
184 if (num_bytes > sizeof b_out) { 184 if (num_bytes > sizeof b_out) {
185 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 185 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
186 return 0; 186 return 0;
187 } 187 }
188 if (BN_is_negative(bn)) { 188 if (BN_is_negative(bn)) {
189 ECerr(EC_F_BN_TO_FELEM, EC_R_BIGNUM_OUT_OF_RANGE); 189 ECerror(EC_R_BIGNUM_OUT_OF_RANGE);
190 return 0; 190 return 0;
191 } 191 }
192 num_bytes = BN_bn2bin(bn, b_in); 192 num_bytes = BN_bn2bin(bn, b_in);
@@ -1631,7 +1631,7 @@ nistp521_pre_comp_new()
1631 NISTP521_PRE_COMP *ret = NULL; 1631 NISTP521_PRE_COMP *ret = NULL;
1632 ret = malloc(sizeof(NISTP521_PRE_COMP)); 1632 ret = malloc(sizeof(NISTP521_PRE_COMP));
1633 if (!ret) { 1633 if (!ret) {
1634 ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1634 ECerror(ERR_R_MALLOC_FAILURE);
1635 return ret; 1635 return ret;
1636 } 1636 }
1637 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp)); 1637 memset(ret->g_pre_comp, 0, sizeof(ret->g_pre_comp));
@@ -1717,8 +1717,7 @@ ec_GFp_nistp521_group_set_curve(EC_GROUP * group, const BIGNUM * p,
1717 BN_bin2bn(nistp521_curve_params[2], sizeof(felem_bytearray), curve_b); 1717 BN_bin2bn(nistp521_curve_params[2], sizeof(felem_bytearray), curve_b);
1718 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) || 1718 if ((BN_cmp(curve_p, p)) || (BN_cmp(curve_a, a)) ||
1719 (BN_cmp(curve_b, b))) { 1719 (BN_cmp(curve_b, b))) {
1720 ECerr(EC_F_EC_GFP_NISTP521_GROUP_SET_CURVE, 1720 ECerror(EC_R_WRONG_CURVE_PARAMETERS);
1721 EC_R_WRONG_CURVE_PARAMETERS);
1722 goto err; 1721 goto err;
1723 } 1722 }
1724 group->field_mod_func = BN_nist_mod_521; 1723 group->field_mod_func = BN_nist_mod_521;
@@ -1739,8 +1738,7 @@ ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP * group,
1739 largefelem tmp; 1738 largefelem tmp;
1740 1739
1741 if (EC_POINT_is_at_infinity(group, point) > 0) { 1740 if (EC_POINT_is_at_infinity(group, point) > 0) {
1742 ECerr(EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES, 1741 ECerror(EC_R_POINT_AT_INFINITY);
1743 EC_R_POINT_AT_INFINITY);
1744 return 0; 1742 return 0;
1745 } 1743 }
1746 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) || 1744 if ((!BN_to_felem(x_in, &point->X)) || (!BN_to_felem(y_in, &point->Y)) ||
@@ -1754,7 +1752,7 @@ ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP * group,
1754 felem_contract(x_out, x_in); 1752 felem_contract(x_out, x_in);
1755 if (x != NULL) { 1753 if (x != NULL) {
1756 if (!felem_to_BN(x, x_out)) { 1754 if (!felem_to_BN(x, x_out)) {
1757 ECerr(EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB); 1755 ECerror(ERR_R_BN_LIB);
1758 return 0; 1756 return 0;
1759 } 1757 }
1760 } 1758 }
@@ -1765,7 +1763,7 @@ ec_GFp_nistp521_point_get_affine_coordinates(const EC_GROUP * group,
1765 felem_contract(y_out, y_in); 1763 felem_contract(y_out, y_in);
1766 if (y != NULL) { 1764 if (y != NULL) {
1767 if (!felem_to_BN(y, y_out)) { 1765 if (!felem_to_BN(y, y_out)) {
1768 ECerr(EC_F_EC_GFP_NISTP521_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB); 1766 ECerror(ERR_R_BN_LIB);
1769 return 0; 1767 return 0;
1770 } 1768 }
1771 } 1769 }
@@ -1847,7 +1845,7 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1847 if (!felem_to_BN(x, g_pre_comp[1][0]) || 1845 if (!felem_to_BN(x, g_pre_comp[1][0]) ||
1848 !felem_to_BN(y, g_pre_comp[1][1]) || 1846 !felem_to_BN(y, g_pre_comp[1][1]) ||
1849 !felem_to_BN(z, g_pre_comp[1][2])) { 1847 !felem_to_BN(z, g_pre_comp[1][2])) {
1850 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB); 1848 ECerror(ERR_R_BN_LIB);
1851 goto err; 1849 goto err;
1852 } 1850 }
1853 if (!EC_POINT_set_Jprojective_coordinates_GFp(group, 1851 if (!EC_POINT_set_Jprojective_coordinates_GFp(group,
@@ -1880,7 +1878,7 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1880 (num_points * 17 + 1), sizeof(felem)); 1878 (num_points * 17 + 1), sizeof(felem));
1881 } 1879 }
1882 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) { 1880 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) {
1883 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1881 ECerror(ERR_R_MALLOC_FAILURE);
1884 goto err; 1882 goto err;
1885 } 1883 }
1886 /* 1884 /*
@@ -1911,7 +1909,7 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1911 * don't guarantee constant-timeness 1909 * don't guarantee constant-timeness
1912 */ 1910 */
1913 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) { 1911 if (!BN_nnmod(tmp_scalar, p_scalar, &group->order, ctx)) {
1914 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB); 1912 ECerror(ERR_R_BN_LIB);
1915 goto err; 1913 goto err;
1916 } 1914 }
1917 num_bytes = BN_bn2bin(tmp_scalar, tmp); 1915 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -1953,7 +1951,7 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1953 * constant-timeness 1951 * constant-timeness
1954 */ 1952 */
1955 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) { 1953 if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) {
1956 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB); 1954 ECerror(ERR_R_BN_LIB);
1957 goto err; 1955 goto err;
1958 } 1956 }
1959 num_bytes = BN_bn2bin(tmp_scalar, tmp); 1957 num_bytes = BN_bn2bin(tmp_scalar, tmp);
@@ -1977,7 +1975,7 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r,
1977 felem_contract(z_in, z_out); 1975 felem_contract(z_in, z_out);
1978 if ((!felem_to_BN(x, x_in)) || (!felem_to_BN(y, y_in)) || 1976 if ((!felem_to_BN(x, x_in)) || (!felem_to_BN(y, y_in)) ||
1979 (!felem_to_BN(z, z_in))) { 1977 (!felem_to_BN(z, z_in))) {
1980 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_BN_LIB); 1978 ECerror(ERR_R_BN_LIB);
1981 goto err; 1979 goto err;
1982 } 1980 }
1983 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx); 1981 ret = EC_POINT_set_Jprojective_coordinates_GFp(group, r, x, y, z, ctx);
diff --git a/src/lib/libcrypto/ec/ecp_nistz256.c b/src/lib/libcrypto/ec/ecp_nistz256.c
index b9ad89c1d3..848f15cb17 100644
--- a/src/lib/libcrypto/ec/ecp_nistz256.c
+++ b/src/lib/libcrypto/ec/ecp_nistz256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistz256.c,v 1.1 2016/11/04 17:33:19 miod Exp $ */ 1/* $OpenBSD: ecp_nistz256.c,v 1.2 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (c) 2014, Intel Corporation. 2/* Copyright (c) 2014, Intel Corporation.
3 * 3 *
4 * Permission to use, copy, modify, and/or distribute this software for any 4 * Permission to use, copy, modify, and/or distribute this software for any
@@ -311,7 +311,7 @@ static int
311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS]) 311ecp_nistz256_set_words(BIGNUM *a, BN_ULONG words[P256_LIMBS])
312{ 312{
313 if (bn_wexpand(a, P256_LIMBS) == NULL) { 313 if (bn_wexpand(a, P256_LIMBS) == NULL) {
314 ECerr(EC_F_ECP_NISTZ256_SET_WORDS, ERR_R_MALLOC_FAILURE); 314 ECerror(ERR_R_MALLOC_FAILURE);
315 return 0; 315 return 0;
316 } 316 }
317 memcpy(a->d, words, sizeof(BN_ULONG) * P256_LIMBS); 317 memcpy(a->d, words, sizeof(BN_ULONG) * P256_LIMBS);
@@ -441,7 +441,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
441 if (posix_memalign((void **)&table, 64, num * sizeof(*table)) != 0 || 441 if (posix_memalign((void **)&table, 64, num * sizeof(*table)) != 0 ||
442 (p_str = reallocarray(NULL, num, sizeof(*p_str))) == NULL || 442 (p_str = reallocarray(NULL, num, sizeof(*p_str))) == NULL ||
443 (scalars = reallocarray(NULL, num, sizeof(*scalars))) == NULL) { 443 (scalars = reallocarray(NULL, num, sizeof(*scalars))) == NULL) {
444 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_MALLOC_FAILURE); 444 ECerror(ERR_R_MALLOC_FAILURE);
445 goto err; 445 goto err;
446 } 446 }
447 447
@@ -458,8 +458,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
458 if ((mod = BN_CTX_get(ctx)) == NULL) 458 if ((mod = BN_CTX_get(ctx)) == NULL)
459 goto err; 459 goto err;
460 if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) { 460 if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) {
461 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, 461 ECerror(ERR_R_BN_LIB);
462 ERR_R_BN_LIB);
463 goto err; 462 goto err;
464 } 463 }
465 scalars[i] = mod; 464 scalars[i] = mod;
@@ -496,8 +495,7 @@ ecp_nistz256_windowed_mul(const EC_GROUP *group, P256_POINT *r,
496 &point[i]->Y) || 495 &point[i]->Y) ||
497 !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z, 496 !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z,
498 &point[i]->Z)) { 497 &point[i]->Z)) {
499 ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, 498 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
500 EC_R_COORDINATES_OUT_OF_RANGE);
501 goto err; 499 goto err;
502 } 500 }
503 501
@@ -623,8 +621,7 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
623 621
624 generator = EC_GROUP_get0_generator(group); 622 generator = EC_GROUP_get0_generator(group);
625 if (generator == NULL) { 623 if (generator == NULL) {
626 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, 624 ECerror(EC_R_UNDEFINED_GENERATOR);
627 EC_R_UNDEFINED_GENERATOR);
628 return 0; 625 return 0;
629 } 626 }
630 627
@@ -655,12 +652,12 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
655 goto err; 652 goto err;
656 653
657 if (BN_is_zero(order)) { 654 if (BN_is_zero(order)) {
658 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, EC_R_UNKNOWN_ORDER); 655 ECerror(EC_R_UNKNOWN_ORDER);
659 goto err; 656 goto err;
660 } 657 }
661 658
662 if (posix_memalign((void **)&precomp, 64, 37 * sizeof(*precomp)) != 0) { 659 if (posix_memalign((void **)&precomp, 64, 37 * sizeof(*precomp)) != 0) {
663 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, ERR_R_MALLOC_FAILURE); 660 ECerror(ERR_R_MALLOC_FAILURE);
664 goto err; 661 goto err;
665 } 662 }
666 663
@@ -690,8 +687,7 @@ ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
690 precomp[j][k].X, &P->X) || 687 precomp[j][k].X, &P->X) ||
691 !ecp_nistz256_bignum_to_field_elem( 688 !ecp_nistz256_bignum_to_field_elem(
692 precomp[j][k].Y, &P->Y)) { 689 precomp[j][k].Y, &P->Y)) {
693 ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, 690 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
694 EC_R_COORDINATES_OUT_OF_RANGE);
695 goto err; 691 goto err;
696 } 692 }
697 for (i = 0; i < 7; i++) { 693 for (i = 0; i < 7; i++) {
@@ -783,7 +779,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
783 BIGNUM *tmp_scalar; 779 BIGNUM *tmp_scalar;
784 780
785 if (group->meth != r->meth) { 781 if (group->meth != r->meth) {
786 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); 782 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
787 return 0; 783 return 0;
788 } 784 }
789 785
@@ -792,8 +788,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
792 788
793 for (j = 0; j < num; j++) { 789 for (j = 0; j < num; j++) {
794 if (group->meth != points[j]->meth) { 790 if (group->meth != points[j]->meth) {
795 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 791 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
796 EC_R_INCOMPATIBLE_OBJECTS);
797 return 0; 792 return 0;
798 } 793 }
799 } 794 }
@@ -809,8 +804,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
809 if (scalar) { 804 if (scalar) {
810 generator = EC_GROUP_get0_generator(group); 805 generator = EC_GROUP_get0_generator(group);
811 if (generator == NULL) { 806 if (generator == NULL) {
812 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 807 ECerror(EC_R_UNDEFINED_GENERATOR);
813 EC_R_UNDEFINED_GENERATOR);
814 goto err; 808 goto err;
815 } 809 }
816 810
@@ -860,8 +854,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
860 854
861 if (!BN_nnmod(tmp_scalar, scalar, &group->order, 855 if (!BN_nnmod(tmp_scalar, scalar, &group->order,
862 ctx)) { 856 ctx)) {
863 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 857 ECerror(ERR_R_BN_LIB);
864 ERR_R_BN_LIB);
865 goto err; 858 goto err;
866 } 859 }
867 scalar = tmp_scalar; 860 scalar = tmp_scalar;
@@ -955,8 +948,7 @@ ecp_nistz256_points_mul(const EC_GROUP *group, EC_POINT *r,
955 new_scalars = reallocarray(NULL, num + 1, sizeof(BIGNUM *)); 948 new_scalars = reallocarray(NULL, num + 1, sizeof(BIGNUM *));
956 new_points = reallocarray(NULL, num + 1, sizeof(EC_POINT *)); 949 new_points = reallocarray(NULL, num + 1, sizeof(EC_POINT *));
957 if (new_scalars == NULL || new_points == NULL) { 950 if (new_scalars == NULL || new_points == NULL) {
958 ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, 951 ECerror(ERR_R_MALLOC_FAILURE);
959 ERR_R_MALLOC_FAILURE);
960 goto err; 952 goto err;
961 } 953 }
962 954
@@ -1011,15 +1003,14 @@ ecp_nistz256_get_affine(const EC_GROUP *group, const EC_POINT *point,
1011 BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS]; 1003 BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS];
1012 1004
1013 if (EC_POINT_is_at_infinity(group, point)) { 1005 if (EC_POINT_is_at_infinity(group, point)) {
1014 ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, EC_R_POINT_AT_INFINITY); 1006 ECerror(EC_R_POINT_AT_INFINITY);
1015 return 0; 1007 return 0;
1016 } 1008 }
1017 1009
1018 if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) || 1010 if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) ||
1019 !ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) || 1011 !ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) ||
1020 !ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) { 1012 !ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) {
1021 ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, 1013 ECerror(EC_R_COORDINATES_OUT_OF_RANGE);
1022 EC_R_COORDINATES_OUT_OF_RANGE);
1023 return 0; 1014 return 0;
1024 } 1015 }
1025 1016
@@ -1066,7 +1057,7 @@ ecp_nistz256_pre_comp_new(const EC_GROUP *group)
1066 1057
1067 ret = (EC_PRE_COMP *)malloc(sizeof(EC_PRE_COMP)); 1058 ret = (EC_PRE_COMP *)malloc(sizeof(EC_PRE_COMP));
1068 if (ret == NULL) { 1059 if (ret == NULL) {
1069 ECerr(EC_F_ECP_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1060 ECerror(ERR_R_MALLOC_FAILURE);
1070 return ret; 1061 return ret;
1071 } 1062 }
1072 1063
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c
index 994f0b08b1..b93b516907 100644
--- a/src/lib/libcrypto/ec/ecp_oct.c
+++ b/src/lib/libcrypto/ec/ecp_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_oct.c,v 1.7 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ecp_oct.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -155,9 +155,9 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP * group,
155 155
156 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) { 156 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {
157 ERR_clear_error(); 157 ERR_clear_error();
158 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 158 ECerror(EC_R_INVALID_COMPRESSED_POINT);
159 } else 159 } else
160 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB); 160 ECerror(ERR_R_BN_LIB);
161 goto err; 161 goto err;
162 } 162 }
163 if (y_bit != BN_is_odd(y)) { 163 if (y_bit != BN_is_odd(y)) {
@@ -169,20 +169,20 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP * group,
169 goto err; 169 goto err;
170 170
171 if (kron == 1) 171 if (kron == 1)
172 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSION_BIT); 172 ECerror(EC_R_INVALID_COMPRESSION_BIT);
173 else 173 else
174 /* 174 /*
175 * BN_mod_sqrt() should have cought this 175 * BN_mod_sqrt() should have cought this
176 * error (not a square) 176 * error (not a square)
177 */ 177 */
178 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 178 ECerror(EC_R_INVALID_COMPRESSED_POINT);
179 goto err; 179 goto err;
180 } 180 }
181 if (!BN_usub(y, &group->field, y)) 181 if (!BN_usub(y, &group->field, y))
182 goto err; 182 goto err;
183 } 183 }
184 if (y_bit != BN_is_odd(y)) { 184 if (y_bit != BN_is_odd(y)) {
185 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_INTERNAL_ERROR); 185 ECerror(ERR_R_INTERNAL_ERROR);
186 goto err; 186 goto err;
187 } 187 }
188 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) 188 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
@@ -210,14 +210,14 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
210 if ((form != POINT_CONVERSION_COMPRESSED) 210 if ((form != POINT_CONVERSION_COMPRESSED)
211 && (form != POINT_CONVERSION_UNCOMPRESSED) 211 && (form != POINT_CONVERSION_UNCOMPRESSED)
212 && (form != POINT_CONVERSION_HYBRID)) { 212 && (form != POINT_CONVERSION_HYBRID)) {
213 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM); 213 ECerror(EC_R_INVALID_FORM);
214 goto err; 214 goto err;
215 } 215 }
216 if (EC_POINT_is_at_infinity(group, point) > 0) { 216 if (EC_POINT_is_at_infinity(group, point) > 0) {
217 /* encodes to a single 0 octet */ 217 /* encodes to a single 0 octet */
218 if (buf != NULL) { 218 if (buf != NULL) {
219 if (len < 1) { 219 if (len < 1) {
220 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 220 ECerror(EC_R_BUFFER_TOO_SMALL);
221 return 0; 221 return 0;
222 } 222 }
223 buf[0] = 0; 223 buf[0] = 0;
@@ -231,7 +231,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
231 /* if 'buf' is NULL, just return required length */ 231 /* if 'buf' is NULL, just return required length */
232 if (buf != NULL) { 232 if (buf != NULL) {
233 if (len < ret) { 233 if (len < ret) {
234 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 234 ECerror(EC_R_BUFFER_TOO_SMALL);
235 goto err; 235 goto err;
236 } 236 }
237 if (ctx == NULL) { 237 if (ctx == NULL) {
@@ -258,7 +258,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
258 258
259 skip = field_len - BN_num_bytes(x); 259 skip = field_len - BN_num_bytes(x);
260 if (skip > field_len) { 260 if (skip > field_len) {
261 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 261 ECerror(ERR_R_INTERNAL_ERROR);
262 goto err; 262 goto err;
263 } 263 }
264 while (skip > 0) { 264 while (skip > 0) {
@@ -268,13 +268,13 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
268 skip = BN_bn2bin(x, buf + i); 268 skip = BN_bn2bin(x, buf + i);
269 i += skip; 269 i += skip;
270 if (i != 1 + field_len) { 270 if (i != 1 + field_len) {
271 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 271 ECerror(ERR_R_INTERNAL_ERROR);
272 goto err; 272 goto err;
273 } 273 }
274 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID) { 274 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID) {
275 skip = field_len - BN_num_bytes(y); 275 skip = field_len - BN_num_bytes(y);
276 if (skip > field_len) { 276 if (skip > field_len) {
277 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 277 ECerror(ERR_R_INTERNAL_ERROR);
278 goto err; 278 goto err;
279 } 279 }
280 while (skip > 0) { 280 while (skip > 0) {
@@ -285,7 +285,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
285 i += skip; 285 i += skip;
286 } 286 }
287 if (i != ret) { 287 if (i != ret) {
288 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 288 ECerror(ERR_R_INTERNAL_ERROR);
289 goto err; 289 goto err;
290 } 290 }
291 } 291 }
@@ -314,7 +314,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
314 int ret = 0; 314 int ret = 0;
315 315
316 if (len == 0) { 316 if (len == 0) {
317 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL); 317 ECerror(EC_R_BUFFER_TOO_SMALL);
318 return 0; 318 return 0;
319 } 319 }
320 form = buf[0]; 320 form = buf[0];
@@ -323,16 +323,16 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
323 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED) 323 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
324 && (form != POINT_CONVERSION_UNCOMPRESSED) 324 && (form != POINT_CONVERSION_UNCOMPRESSED)
325 && (form != POINT_CONVERSION_HYBRID)) { 325 && (form != POINT_CONVERSION_HYBRID)) {
326 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 326 ECerror(EC_R_INVALID_ENCODING);
327 return 0; 327 return 0;
328 } 328 }
329 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) { 329 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {
330 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 330 ECerror(EC_R_INVALID_ENCODING);
331 return 0; 331 return 0;
332 } 332 }
333 if (form == 0) { 333 if (form == 0) {
334 if (len != 1) { 334 if (len != 1) {
335 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 335 ECerror(EC_R_INVALID_ENCODING);
336 return 0; 336 return 0;
337 } 337 }
338 return EC_POINT_set_to_infinity(group, point); 338 return EC_POINT_set_to_infinity(group, point);
@@ -341,7 +341,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
341 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len; 341 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
342 342
343 if (len != enc_len) { 343 if (len != enc_len) {
344 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 344 ECerror(EC_R_INVALID_ENCODING);
345 return 0; 345 return 0;
346 } 346 }
347 if (ctx == NULL) { 347 if (ctx == NULL) {
@@ -358,7 +358,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
358 if (!BN_bin2bn(buf + 1, field_len, x)) 358 if (!BN_bin2bn(buf + 1, field_len, x))
359 goto err; 359 goto err;
360 if (BN_ucmp(x, &group->field) >= 0) { 360 if (BN_ucmp(x, &group->field) >= 0) {
361 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 361 ECerror(EC_R_INVALID_ENCODING);
362 goto err; 362 goto err;
363 } 363 }
364 if (form == POINT_CONVERSION_COMPRESSED) { 364 if (form == POINT_CONVERSION_COMPRESSED) {
@@ -368,12 +368,12 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
368 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) 368 if (!BN_bin2bn(buf + 1 + field_len, field_len, y))
369 goto err; 369 goto err;
370 if (BN_ucmp(y, &group->field) >= 0) { 370 if (BN_ucmp(y, &group->field) >= 0) {
371 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 371 ECerror(EC_R_INVALID_ENCODING);
372 goto err; 372 goto err;
373 } 373 }
374 if (form == POINT_CONVERSION_HYBRID) { 374 if (form == POINT_CONVERSION_HYBRID) {
375 if (y_bit != BN_is_odd(y)) { 375 if (y_bit != BN_is_odd(y)) {
376 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 376 ECerror(EC_R_INVALID_ENCODING);
377 goto err; 377 goto err;
378 } 378 }
379 } 379 }
@@ -383,7 +383,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
383 383
384 /* test required by X9.62 */ 384 /* test required by X9.62 */
385 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) { 385 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {
386 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE); 386 ECerror(EC_R_POINT_IS_NOT_ON_CURVE);
387 goto err; 387 goto err;
388 } 388 }
389 ret = 1; 389 ret = 1;
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index f497657463..ddba49c693 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_smpl.c,v 1.16 2017/01/21 11:00:47 beck Exp $ */ 1/* $OpenBSD: ecp_smpl.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -180,7 +180,7 @@ ec_GFp_simple_group_set_curve(EC_GROUP * group,
180 180
181 /* p must be a prime > 3 */ 181 /* p must be a prime > 3 */
182 if (BN_num_bits(p) <= 2 || !BN_is_odd(p)) { 182 if (BN_num_bits(p) <= 2 || !BN_is_odd(p)) {
183 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, EC_R_INVALID_FIELD); 183 ECerror(EC_R_INVALID_FIELD);
184 return 0; 184 return 0;
185 } 185 }
186 if (ctx == NULL) { 186 if (ctx == NULL) {
@@ -289,7 +289,7 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP * group, BN_CTX * ctx)
289 if (ctx == NULL) { 289 if (ctx == NULL) {
290 ctx = new_ctx = BN_CTX_new(); 290 ctx = new_ctx = BN_CTX_new();
291 if (ctx == NULL) { 291 if (ctx == NULL) {
292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE); 292 ECerror(ERR_R_MALLOC_FAILURE);
293 goto err; 293 goto err;
294 } 294 }
295 } 295 }
@@ -516,7 +516,7 @@ ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP * group, EC_POINT * po
516{ 516{
517 if (x == NULL || y == NULL) { 517 if (x == NULL || y == NULL) {
518 /* unlike for projective coordinates, we do not tolerate this */ 518 /* unlike for projective coordinates, we do not tolerate this */
519 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES, ERR_R_PASSED_NULL_PARAMETER); 519 ECerror(ERR_R_PASSED_NULL_PARAMETER);
520 return 0; 520 return 0;
521 } 521 }
522 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx); 522 return EC_POINT_set_Jprojective_coordinates_GFp(group, point, x, y, BN_value_one(), ctx);
@@ -533,7 +533,7 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POIN
533 int ret = 0; 533 int ret = 0;
534 534
535 if (EC_POINT_is_at_infinity(group, point) > 0) { 535 if (EC_POINT_is_at_infinity(group, point) > 0) {
536 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY); 536 ECerror(EC_R_POINT_AT_INFINITY);
537 return 0; 537 return 0;
538 } 538 }
539 if (ctx == NULL) { 539 if (ctx == NULL) {
@@ -583,7 +583,7 @@ ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP * group, const EC_POIN
583 } 583 }
584 } else { 584 } else {
585 if (!BN_mod_inverse_ct(Z_1, Z_, &group->field, ctx)) { 585 if (!BN_mod_inverse_ct(Z_1, Z_, &group->field, ctx)) {
586 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB); 586 ECerror(ERR_R_BN_LIB);
587 goto err; 587 goto err;
588 } 588 }
589 if (group->meth->field_encode == 0) { 589 if (group->meth->field_encode == 0) {
@@ -1210,7 +1210,7 @@ ec_GFp_simple_make_affine(const EC_GROUP * group, EC_POINT * point, BN_CTX * ctx
1210 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) 1210 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
1211 goto err; 1211 goto err;
1212 if (!point->Z_is_one) { 1212 if (!point->Z_is_one) {
1213 ECerr(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE, ERR_R_INTERNAL_ERROR); 1213 ECerror(ERR_R_INTERNAL_ERROR);
1214 goto err; 1214 goto err;
1215 } 1215 }
1216 ret = 1; 1216 ret = 1;
@@ -1313,7 +1313,7 @@ ec_GFp_simple_points_make_affine(const EC_GROUP * group, size_t num, EC_POINT *
1313 /* invert heap[1] */ 1313 /* invert heap[1] */
1314 if (!BN_is_zero(heap[1])) { 1314 if (!BN_is_zero(heap[1])) {
1315 if (!BN_mod_inverse_ct(heap[1], heap[1], &group->field, ctx)) { 1315 if (!BN_mod_inverse_ct(heap[1], heap[1], &group->field, ctx)) {
1316 ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB); 1316 ECerror(ERR_R_BN_LIB);
1317 goto err; 1317 goto err;
1318 } 1318 }
1319 } 1319 }
diff --git a/src/lib/libcrypto/ecdh/ech_err.c b/src/lib/libcrypto/ecdh/ech_err.c
index afe5ff3af8..149c2a8505 100644
--- a/src/lib/libcrypto/ecdh/ech_err.c
+++ b/src/lib/libcrypto/ecdh/ech_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_err.c,v 1.5 2015/09/13 11:49:44 jsing Exp $ */ 1/* $OpenBSD: ech_err.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,9 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDH,0,reason)
73 73
74static ERR_STRING_DATA ECDH_str_functs[]= { 74static ERR_STRING_DATA ECDH_str_functs[]= {
75 {ERR_FUNC(ECDH_F_ECDH_CHECK), "ECDH_CHECK"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(ECDH_F_ECDH_COMPUTE_KEY), "ECDH_compute_key"},
77 {ERR_FUNC(ECDH_F_ECDH_DATA_NEW_METHOD), "ECDH_DATA_new_method"},
78 {0, NULL} 76 {0, NULL}
79}; 77};
80 78
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c
index 33ee244499..5c2dc70b63 100644
--- a/src/lib/libcrypto/ecdh/ech_key.c
+++ b/src/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.6 2015/09/18 13:04:41 bcook Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -106,7 +106,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
106 106
107 if (outlen > INT_MAX) { 107 if (outlen > INT_MAX) {
108 /* Sort of, anyway. */ 108 /* Sort of, anyway. */
109 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); 109 ECDHerror(ERR_R_MALLOC_FAILURE);
110 return -1; 110 return -1;
111 } 111 }
112 112
@@ -120,19 +120,18 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
120 120
121 priv_key = EC_KEY_get0_private_key(ecdh); 121 priv_key = EC_KEY_get0_private_key(ecdh);
122 if (priv_key == NULL) { 122 if (priv_key == NULL) {
123 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_NO_PRIVATE_VALUE); 123 ECDHerror(ECDH_R_NO_PRIVATE_VALUE);
124 goto err; 124 goto err;
125 } 125 }
126 126
127 group = EC_KEY_get0_group(ecdh); 127 group = EC_KEY_get0_group(ecdh);
128 if ((tmp = EC_POINT_new(group)) == NULL) { 128 if ((tmp = EC_POINT_new(group)) == NULL) {
129 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); 129 ECDHerror(ERR_R_MALLOC_FAILURE);
130 goto err; 130 goto err;
131 } 131 }
132 132
133 if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) { 133 if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx)) {
134 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, 134 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
135 ECDH_R_POINT_ARITHMETIC_FAILURE);
136 goto err; 135 goto err;
137 } 136 }
138 137
@@ -140,8 +139,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
140 NID_X9_62_prime_field) { 139 NID_X9_62_prime_field) {
141 if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, 140 if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y,
142 ctx)) { 141 ctx)) {
143 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, 142 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
144 ECDH_R_POINT_ARITHMETIC_FAILURE);
145 goto err; 143 goto err;
146 } 144 }
147 } 145 }
@@ -149,8 +147,7 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
149 else { 147 else {
150 if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, 148 if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y,
151 ctx)) { 149 ctx)) {
152 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, 150 ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
153 ECDH_R_POINT_ARITHMETIC_FAILURE);
154 goto err; 151 goto err;
155 } 152 }
156 } 153 }
@@ -159,28 +156,28 @@ ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
159 buflen = ECDH_size(ecdh); 156 buflen = ECDH_size(ecdh);
160 len = BN_num_bytes(x); 157 len = BN_num_bytes(x);
161 if (len > buflen) { 158 if (len > buflen) {
162 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_INTERNAL_ERROR); 159 ECDHerror(ERR_R_INTERNAL_ERROR);
163 goto err; 160 goto err;
164 } 161 }
165 if (KDF == NULL && outlen < buflen) { 162 if (KDF == NULL && outlen < buflen) {
166 /* The resulting key would be truncated. */ 163 /* The resulting key would be truncated. */
167 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KEY_TRUNCATION); 164 ECDHerror(ECDH_R_KEY_TRUNCATION);
168 goto err; 165 goto err;
169 } 166 }
170 if ((buf = malloc(buflen)) == NULL) { 167 if ((buf = malloc(buflen)) == NULL) {
171 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_MALLOC_FAILURE); 168 ECDHerror(ERR_R_MALLOC_FAILURE);
172 goto err; 169 goto err;
173 } 170 }
174 171
175 memset(buf, 0, buflen - len); 172 memset(buf, 0, buflen - len);
176 if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) { 173 if (len != (size_t)BN_bn2bin(x, buf + buflen - len)) {
177 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ERR_R_BN_LIB); 174 ECDHerror(ERR_R_BN_LIB);
178 goto err; 175 goto err;
179 } 176 }
180 177
181 if (KDF != NULL) { 178 if (KDF != NULL) {
182 if (KDF(buf, buflen, out, &outlen) == NULL) { 179 if (KDF(buf, buflen, out, &outlen) == NULL) {
183 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY, ECDH_R_KDF_FAILED); 180 ECDHerror(ECDH_R_KDF_FAILED);
184 goto err; 181 goto err;
185 } 182 }
186 ret = outlen; 183 ret = outlen;
diff --git a/src/lib/libcrypto/ecdh/ech_lib.c b/src/lib/libcrypto/ecdh/ech_lib.c
index bb70d2d95f..06e6a1ee22 100644
--- a/src/lib/libcrypto/ecdh/ech_lib.c
+++ b/src/lib/libcrypto/ecdh/ech_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_lib.c,v 1.11 2015/09/13 12:03:07 jsing Exp $ */ 1/* $OpenBSD: ech_lib.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -125,7 +125,7 @@ ECDH_DATA_new_method(ENGINE *engine)
125 125
126 ret = malloc(sizeof(ECDH_DATA)); 126 ret = malloc(sizeof(ECDH_DATA));
127 if (ret == NULL) { 127 if (ret == NULL) {
128 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 128 ECDHerror(ERR_R_MALLOC_FAILURE);
129 return (NULL); 129 return (NULL);
130 } 130 }
131 131
@@ -139,7 +139,7 @@ ECDH_DATA_new_method(ENGINE *engine)
139 if (ret->engine) { 139 if (ret->engine) {
140 ret->meth = ENGINE_get_ECDH(ret->engine); 140 ret->meth = ENGINE_get_ECDH(ret->engine);
141 if (!ret->meth) { 141 if (!ret->meth) {
142 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); 142 ECDHerror(ERR_R_ENGINE_LIB);
143 ENGINE_finish(ret->engine); 143 ENGINE_finish(ret->engine);
144 free(ret); 144 free(ret);
145 return NULL; 145 return NULL;
diff --git a/src/lib/libcrypto/ecdsa/ecs_err.c b/src/lib/libcrypto/ecdsa/ecs_err.c
index 26efc135e3..9c5a546746 100644
--- a/src/lib/libcrypto/ecdsa/ecs_err.c
+++ b/src/lib/libcrypto/ecdsa/ecs_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_err.c,v 1.4 2015/02/08 13:35:07 jsing Exp $ */ 1/* $OpenBSD: ecs_err.c,v 1.5 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,11 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDSA,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECDSA,0,reason)
73 73
74static ERR_STRING_DATA ECDSA_str_functs[]= { 74static ERR_STRING_DATA ECDSA_str_functs[]= {
75 {ERR_FUNC(ECDSA_F_ECDSA_CHECK), "ECDSA_CHECK"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(ECDSA_F_ECDSA_DATA_NEW_METHOD), "ECDSA_DATA_NEW_METHOD"},
77 {ERR_FUNC(ECDSA_F_ECDSA_DO_SIGN), "ECDSA_do_sign"},
78 {ERR_FUNC(ECDSA_F_ECDSA_DO_VERIFY), "ECDSA_do_verify"},
79 {ERR_FUNC(ECDSA_F_ECDSA_SIGN_SETUP), "ECDSA_sign_setup"},
80 {0, NULL} 76 {0, NULL}
81}; 77};
82 78
diff --git a/src/lib/libcrypto/ecdsa/ecs_lib.c b/src/lib/libcrypto/ecdsa/ecs_lib.c
index 1ba788b4f0..ca0f51b366 100644
--- a/src/lib/libcrypto/ecdsa/ecs_lib.c
+++ b/src/lib/libcrypto/ecdsa/ecs_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_lib.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: ecs_lib.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -113,7 +113,7 @@ ECDSA_DATA_new_method(ENGINE *engine)
113 113
114 ret = malloc(sizeof(ECDSA_DATA)); 114 ret = malloc(sizeof(ECDSA_DATA));
115 if (ret == NULL) { 115 if (ret == NULL) {
116 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 116 ECDSAerror(ERR_R_MALLOC_FAILURE);
117 return (NULL); 117 return (NULL);
118 } 118 }
119 119
@@ -127,8 +127,7 @@ ECDSA_DATA_new_method(ENGINE *engine)
127 if (ret->engine) { 127 if (ret->engine) {
128 ret->meth = ENGINE_get_ECDSA(ret->engine); 128 ret->meth = ENGINE_get_ECDSA(ret->engine);
129 if (!ret->meth) { 129 if (!ret->meth) {
130 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, 130 ECDSAerror(ERR_R_ENGINE_LIB);
131 ERR_R_ENGINE_LIB);
132 ENGINE_finish(ret->engine); 131 ENGINE_finish(ret->engine);
133 free(ret); 132 free(ret);
134 return NULL; 133 return NULL;
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index 637da6535f..c7f4bcbe03 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_ossl.c,v 1.8 2017/01/21 11:00:47 beck Exp $ */ 1/* $OpenBSD: ecs_ossl.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -95,14 +95,13 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
95 int ret = 0; 95 int ret = 0;
96 96
97 if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) { 97 if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {
98 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER); 98 ECDSAerror(ERR_R_PASSED_NULL_PARAMETER);
99 return 0; 99 return 0;
100 } 100 }
101 101
102 if (ctx_in == NULL) { 102 if (ctx_in == NULL) {
103 if ((ctx = BN_CTX_new()) == NULL) { 103 if ((ctx = BN_CTX_new()) == NULL) {
104 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, 104 ECDSAerror(ERR_R_MALLOC_FAILURE);
105 ERR_R_MALLOC_FAILURE);
106 return 0; 105 return 0;
107 } 106 }
108 } else 107 } else
@@ -113,15 +112,15 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
113 order = BN_new(); 112 order = BN_new();
114 X = BN_new(); 113 X = BN_new();
115 if (!k || !r || !order || !X) { 114 if (!k || !r || !order || !X) {
116 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE); 115 ECDSAerror(ERR_R_MALLOC_FAILURE);
117 goto err; 116 goto err;
118 } 117 }
119 if ((tmp_point = EC_POINT_new(group)) == NULL) { 118 if ((tmp_point = EC_POINT_new(group)) == NULL) {
120 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB); 119 ECDSAerror(ERR_R_EC_LIB);
121 goto err; 120 goto err;
122 } 121 }
123 if (!EC_GROUP_get_order(group, order, ctx)) { 122 if (!EC_GROUP_get_order(group, order, ctx)) {
124 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB); 123 ECDSAerror(ERR_R_EC_LIB);
125 goto err; 124 goto err;
126 } 125 }
127 126
@@ -129,8 +128,7 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
129 /* get random k */ 128 /* get random k */
130 do 129 do
131 if (!BN_rand_range(k, order)) { 130 if (!BN_rand_range(k, order)) {
132 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, 131 ECDSAerror(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);
133 ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);
134 goto err; 132 goto err;
135 } 133 }
136 while (BN_is_zero(k)); 134 while (BN_is_zero(k));
@@ -148,15 +146,14 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
148 146
149 /* compute r the x-coordinate of generator * k */ 147 /* compute r the x-coordinate of generator * k */
150 if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) { 148 if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {
151 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB); 149 ECDSAerror(ERR_R_EC_LIB);
152 goto err; 150 goto err;
153 } 151 }
154 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == 152 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
155 NID_X9_62_prime_field) { 153 NID_X9_62_prime_field) {
156 if (!EC_POINT_get_affine_coordinates_GFp(group, 154 if (!EC_POINT_get_affine_coordinates_GFp(group,
157 tmp_point, X, NULL, ctx)) { 155 tmp_point, X, NULL, ctx)) {
158 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, 156 ECDSAerror(ERR_R_EC_LIB);
159 ERR_R_EC_LIB);
160 goto err; 157 goto err;
161 } 158 }
162 } 159 }
@@ -165,21 +162,20 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
165 { 162 {
166 if (!EC_POINT_get_affine_coordinates_GF2m(group, 163 if (!EC_POINT_get_affine_coordinates_GF2m(group,
167 tmp_point, X, NULL, ctx)) { 164 tmp_point, X, NULL, ctx)) {
168 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, 165 ECDSAerror(ERR_R_EC_LIB);
169 ERR_R_EC_LIB);
170 goto err; 166 goto err;
171 } 167 }
172 } 168 }
173#endif 169#endif
174 if (!BN_nnmod(r, X, order, ctx)) { 170 if (!BN_nnmod(r, X, order, ctx)) {
175 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); 171 ECDSAerror(ERR_R_BN_LIB);
176 goto err; 172 goto err;
177 } 173 }
178 } while (BN_is_zero(r)); 174 } while (BN_is_zero(r));
179 175
180 /* compute the inverse of k */ 176 /* compute the inverse of k */
181 if (!BN_mod_inverse_ct(k, k, order, ctx)) { 177 if (!BN_mod_inverse_ct(k, k, order, ctx)) {
182 ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); 178 ECDSAerror(ERR_R_BN_LIB);
183 goto err; 179 goto err;
184 } 180 }
185 /* clear old values if necessary */ 181 /* clear old values if necessary */
@@ -222,25 +218,25 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len,
222 priv_key = EC_KEY_get0_private_key(eckey); 218 priv_key = EC_KEY_get0_private_key(eckey);
223 219
224 if (group == NULL || priv_key == NULL || ecdsa == NULL) { 220 if (group == NULL || priv_key == NULL || ecdsa == NULL) {
225 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_PASSED_NULL_PARAMETER); 221 ECDSAerror(ERR_R_PASSED_NULL_PARAMETER);
226 return NULL; 222 return NULL;
227 } 223 }
228 224
229 ret = ECDSA_SIG_new(); 225 ret = ECDSA_SIG_new();
230 if (!ret) { 226 if (!ret) {
231 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); 227 ECDSAerror(ERR_R_MALLOC_FAILURE);
232 return NULL; 228 return NULL;
233 } 229 }
234 s = ret->s; 230 s = ret->s;
235 231
236 if ((ctx = BN_CTX_new()) == NULL || (order = BN_new()) == NULL || 232 if ((ctx = BN_CTX_new()) == NULL || (order = BN_new()) == NULL ||
237 (tmp = BN_new()) == NULL || (m = BN_new()) == NULL) { 233 (tmp = BN_new()) == NULL || (m = BN_new()) == NULL) {
238 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_MALLOC_FAILURE); 234 ECDSAerror(ERR_R_MALLOC_FAILURE);
239 goto err; 235 goto err;
240 } 236 }
241 237
242 if (!EC_GROUP_get_order(group, order, ctx)) { 238 if (!EC_GROUP_get_order(group, order, ctx)) {
243 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_EC_LIB); 239 ECDSAerror(ERR_R_EC_LIB);
244 goto err; 240 goto err;
245 } 241 }
246 i = BN_num_bits(order); 242 i = BN_num_bits(order);
@@ -250,49 +246,46 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len,
250 if (8 * dgst_len > i) 246 if (8 * dgst_len > i)
251 dgst_len = (i + 7)/8; 247 dgst_len = (i + 7)/8;
252 if (!BN_bin2bn(dgst, dgst_len, m)) { 248 if (!BN_bin2bn(dgst, dgst_len, m)) {
253 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); 249 ECDSAerror(ERR_R_BN_LIB);
254 goto err; 250 goto err;
255 } 251 }
256 /* If still too long truncate remaining bits with a shift */ 252 /* If still too long truncate remaining bits with a shift */
257 if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { 253 if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
258 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); 254 ECDSAerror(ERR_R_BN_LIB);
259 goto err; 255 goto err;
260 } 256 }
261 do { 257 do {
262 if (in_kinv == NULL || in_r == NULL) { 258 if (in_kinv == NULL || in_r == NULL) {
263 if (!ECDSA_sign_setup(eckey, ctx, &kinv, &ret->r)) { 259 if (!ECDSA_sign_setup(eckey, ctx, &kinv, &ret->r)) {
264 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, 260 ECDSAerror(ERR_R_ECDSA_LIB);
265 ERR_R_ECDSA_LIB);
266 goto err; 261 goto err;
267 } 262 }
268 ckinv = kinv; 263 ckinv = kinv;
269 } else { 264 } else {
270 ckinv = in_kinv; 265 ckinv = in_kinv;
271 if (BN_copy(ret->r, in_r) == NULL) { 266 if (BN_copy(ret->r, in_r) == NULL) {
272 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, 267 ECDSAerror(ERR_R_MALLOC_FAILURE);
273 ERR_R_MALLOC_FAILURE);
274 goto err; 268 goto err;
275 } 269 }
276 } 270 }
277 271
278 if (!BN_mod_mul(tmp, priv_key, ret->r, order, ctx)) { 272 if (!BN_mod_mul(tmp, priv_key, ret->r, order, ctx)) {
279 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); 273 ECDSAerror(ERR_R_BN_LIB);
280 goto err; 274 goto err;
281 } 275 }
282 if (!BN_mod_add_quick(s, tmp, m, order)) { 276 if (!BN_mod_add_quick(s, tmp, m, order)) {
283 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); 277 ECDSAerror(ERR_R_BN_LIB);
284 goto err; 278 goto err;
285 } 279 }
286 if (!BN_mod_mul(s, s, ckinv, order, ctx)) { 280 if (!BN_mod_mul(s, s, ckinv, order, ctx)) {
287 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, ERR_R_BN_LIB); 281 ECDSAerror(ERR_R_BN_LIB);
288 goto err; 282 goto err;
289 } 283 }
290 if (BN_is_zero(s)) { 284 if (BN_is_zero(s)) {
291 /* if kinv and r have been supplied by the caller 285 /* if kinv and r have been supplied by the caller
292 * don't to generate new kinv and r values */ 286 * don't to generate new kinv and r values */
293 if (in_kinv != NULL && in_r != NULL) { 287 if (in_kinv != NULL && in_r != NULL) {
294 ECDSAerr(ECDSA_F_ECDSA_DO_SIGN, 288 ECDSAerror(ECDSA_R_NEED_NEW_SETUP_VALUES);
295 ECDSA_R_NEED_NEW_SETUP_VALUES);
296 goto err; 289 goto err;
297 } 290 }
298 } else 291 } else
@@ -329,13 +322,13 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
329 /* check input values */ 322 /* check input values */
330 if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL || 323 if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||
331 (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) { 324 (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {
332 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS); 325 ECDSAerror(ECDSA_R_MISSING_PARAMETERS);
333 return -1; 326 return -1;
334 } 327 }
335 328
336 ctx = BN_CTX_new(); 329 ctx = BN_CTX_new();
337 if (!ctx) { 330 if (!ctx) {
338 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); 331 ECDSAerror(ERR_R_MALLOC_FAILURE);
339 return -1; 332 return -1;
340 } 333 }
341 BN_CTX_start(ctx); 334 BN_CTX_start(ctx);
@@ -345,25 +338,25 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
345 m = BN_CTX_get(ctx); 338 m = BN_CTX_get(ctx);
346 X = BN_CTX_get(ctx); 339 X = BN_CTX_get(ctx);
347 if (!X) { 340 if (!X) {
348 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 341 ECDSAerror(ERR_R_BN_LIB);
349 goto err; 342 goto err;
350 } 343 }
351 344
352 if (!EC_GROUP_get_order(group, order, ctx)) { 345 if (!EC_GROUP_get_order(group, order, ctx)) {
353 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); 346 ECDSAerror(ERR_R_EC_LIB);
354 goto err; 347 goto err;
355 } 348 }
356 349
357 if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || 350 if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
358 BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) || 351 BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||
359 BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) { 352 BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {
360 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_BAD_SIGNATURE); 353 ECDSAerror(ECDSA_R_BAD_SIGNATURE);
361 ret = 0; /* signature is invalid */ 354 ret = 0; /* signature is invalid */
362 goto err; 355 goto err;
363 } 356 }
364 /* calculate tmp1 = inv(S) mod order */ 357 /* calculate tmp1 = inv(S) mod order */
365 if (!BN_mod_inverse_ct(u2, sig->s, order, ctx)) { 358 if (!BN_mod_inverse_ct(u2, sig->s, order, ctx)) {
366 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 359 ECDSAerror(ERR_R_BN_LIB);
367 goto err; 360 goto err;
368 } 361 }
369 /* digest -> m */ 362 /* digest -> m */
@@ -374,38 +367,38 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
374 if (8 * dgst_len > i) 367 if (8 * dgst_len > i)
375 dgst_len = (i + 7)/8; 368 dgst_len = (i + 7)/8;
376 if (!BN_bin2bn(dgst, dgst_len, m)) { 369 if (!BN_bin2bn(dgst, dgst_len, m)) {
377 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 370 ECDSAerror(ERR_R_BN_LIB);
378 goto err; 371 goto err;
379 } 372 }
380 /* If still too long truncate remaining bits with a shift */ 373 /* If still too long truncate remaining bits with a shift */
381 if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) { 374 if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {
382 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 375 ECDSAerror(ERR_R_BN_LIB);
383 goto err; 376 goto err;
384 } 377 }
385 /* u1 = m * tmp mod order */ 378 /* u1 = m * tmp mod order */
386 if (!BN_mod_mul(u1, m, u2, order, ctx)) { 379 if (!BN_mod_mul(u1, m, u2, order, ctx)) {
387 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 380 ECDSAerror(ERR_R_BN_LIB);
388 goto err; 381 goto err;
389 } 382 }
390 /* u2 = r * w mod q */ 383 /* u2 = r * w mod q */
391 if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) { 384 if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {
392 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 385 ECDSAerror(ERR_R_BN_LIB);
393 goto err; 386 goto err;
394 } 387 }
395 388
396 if ((point = EC_POINT_new(group)) == NULL) { 389 if ((point = EC_POINT_new(group)) == NULL) {
397 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE); 390 ECDSAerror(ERR_R_MALLOC_FAILURE);
398 goto err; 391 goto err;
399 } 392 }
400 if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) { 393 if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {
401 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); 394 ECDSAerror(ERR_R_EC_LIB);
402 goto err; 395 goto err;
403 } 396 }
404 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == 397 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
405 NID_X9_62_prime_field) { 398 NID_X9_62_prime_field) {
406 if (!EC_POINT_get_affine_coordinates_GFp(group, 399 if (!EC_POINT_get_affine_coordinates_GFp(group,
407 point, X, NULL, ctx)) { 400 point, X, NULL, ctx)) {
408 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); 401 ECDSAerror(ERR_R_EC_LIB);
409 goto err; 402 goto err;
410 } 403 }
411 } 404 }
@@ -414,13 +407,13 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
414 { 407 {
415 if (!EC_POINT_get_affine_coordinates_GF2m(group, 408 if (!EC_POINT_get_affine_coordinates_GF2m(group,
416 point, X, NULL, ctx)) { 409 point, X, NULL, ctx)) {
417 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB); 410 ECDSAerror(ERR_R_EC_LIB);
418 goto err; 411 goto err;
419 } 412 }
420 } 413 }
421#endif 414#endif
422 if (!BN_nnmod(u1, X, order, ctx)) { 415 if (!BN_nnmod(u1, X, order, ctx)) {
423 ECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB); 416 ECDSAerror(ERR_R_BN_LIB);
424 goto err; 417 goto err;
425 } 418 }
426 /* if the signature is correct u1 is equal to sig->r */ 419 /* if the signature is correct u1 is equal to sig->r */
diff --git a/src/lib/libcrypto/engine/eng_aesni.c b/src/lib/libcrypto/engine/eng_aesni.c
index 92794f6086..cd14bbc8cd 100644
--- a/src/lib/libcrypto/engine/eng_aesni.c
+++ b/src/lib/libcrypto/engine/eng_aesni.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_aesni.c,v 1.9 2016/11/04 17:30:30 miod Exp $ */ 1/* $OpenBSD: eng_aesni.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Support for Intel AES-NI intruction set 3 * Support for Intel AES-NI intruction set
4 * Author: Huang Ying <ying.huang@intel.com> 4 * Author: Huang Ying <ying.huang@intel.com>
@@ -411,7 +411,7 @@ aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *user_key,
411 ret = aesni_set_decrypt_key(user_key, ctx->key_len * 8, key); 411 ret = aesni_set_decrypt_key(user_key, ctx->key_len * 8, key);
412 412
413 if (ret < 0) { 413 if (ret < 0) {
414 EVPerr(EVP_F_AESNI_INIT_KEY, EVP_R_AES_KEY_SETUP_FAILED); 414 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
415 return 0; 415 return 0;
416 } 416 }
417 417
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
index acdebda6a6..2ac077d492 100644
--- a/src/lib/libcrypto/engine/eng_cnf.c
+++ b/src/lib/libcrypto/engine/eng_cnf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_cnf.c,v 1.13 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_cnf.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -115,8 +115,7 @@ int_engine_configure(char *name, char *value, const CONF *cnf)
115 ecmds = NCONF_get_section(cnf, value); 115 ecmds = NCONF_get_section(cnf, value);
116 116
117 if (!ecmds) { 117 if (!ecmds) {
118 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, 118 ENGINEerror(ENGINE_R_ENGINE_SECTION_ERROR);
119 ENGINE_R_ENGINE_SECTION_ERROR);
120 return 0; 119 return 0;
121 } 120 }
122 121
@@ -175,8 +174,7 @@ int_engine_configure(char *name, char *value, const CONF *cnf)
175 if (!int_engine_init(e)) 174 if (!int_engine_init(e))
176 goto err; 175 goto err;
177 } else if (do_init != 0) { 176 } else if (do_init != 0) {
178 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, 177 ENGINEerror(ENGINE_R_INVALID_INIT_VALUE);
179 ENGINE_R_INVALID_INIT_VALUE);
180 goto err; 178 goto err;
181 } 179 }
182 } 180 }
@@ -196,8 +194,7 @@ int_engine_configure(char *name, char *value, const CONF *cnf)
196 194
197err: 195err:
198 if (ret != 1) { 196 if (ret != 1) {
199 ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, 197 ENGINEerror(ENGINE_R_ENGINE_CONFIGURATION_ERROR);
200 ENGINE_R_ENGINE_CONFIGURATION_ERROR);
201 if (ecmd) 198 if (ecmd)
202 ERR_asprintf_error_data( 199 ERR_asprintf_error_data(
203 "section=%s, name=%s, value=%s", 200 "section=%s, name=%s, value=%s",
@@ -224,8 +221,7 @@ int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
224 elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); 221 elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
225 222
226 if (!elist) { 223 if (!elist) {
227 ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, 224 ENGINEerror(ENGINE_R_ENGINES_SECTION_ERROR);
228 ENGINE_R_ENGINES_SECTION_ERROR);
229 return 0; 225 return 0;
230 } 226 }
231 227
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
index bf832dc626..1a3c25fbae 100644
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_ctrl.c,v 1.10 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_ctrl.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -125,8 +125,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
125 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || 125 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
126 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) { 126 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) {
127 if (s == NULL) { 127 if (s == NULL) {
128 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 128 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
129 ERR_R_PASSED_NULL_PARAMETER);
130 return -1; 129 return -1;
131 } 130 }
132 } 131 }
@@ -134,8 +133,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
134 if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) { 133 if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) {
135 if ((e->cmd_defns == NULL) || 134 if ((e->cmd_defns == NULL) ||
136 ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) { 135 ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) {
137 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 136 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
138 ENGINE_R_INVALID_CMD_NAME);
139 return -1; 137 return -1;
140 } 138 }
141 return e->cmd_defns[idx].cmd_num; 139 return e->cmd_defns[idx].cmd_num;
@@ -144,8 +142,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
144 * valie command number - so we need to conduct a search. */ 142 * valie command number - so we need to conduct a search. */
145 if ((e->cmd_defns == NULL) || 143 if ((e->cmd_defns == NULL) ||
146 ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) { 144 ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) {
147 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 145 ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER);
148 ENGINE_R_INVALID_CMD_NUMBER);
149 return -1; 146 return -1;
150 } 147 }
151 /* Now the logic splits depending on command type */ 148 /* Now the logic splits depending on command type */
@@ -188,7 +185,7 @@ int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
188 } 185 }
189 186
190 /* Shouldn't really be here ... */ 187 /* Shouldn't really be here ... */
191 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, ENGINE_R_INTERNAL_LIST_ERROR); 188 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
192 return -1; 189 return -1;
193} 190}
194 191
@@ -198,7 +195,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
198 int ctrl_exists, ref_exists; 195 int ctrl_exists, ref_exists;
199 196
200 if (e == NULL) { 197 if (e == NULL) {
201 ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER); 198 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
202 return 0; 199 return 0;
203 } 200 }
204 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 201 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -206,7 +203,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
206 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 203 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
207 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); 204 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
208 if (!ref_exists) { 205 if (!ref_exists) {
209 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE); 206 ENGINEerror(ENGINE_R_NO_REFERENCE);
210 return 0; 207 return 0;
211 } 208 }
212 /* Intercept any "root-level" commands before trying to hand them on to 209 /* Intercept any "root-level" commands before trying to hand them on to
@@ -225,8 +222,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
225 if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) 222 if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
226 return int_ctrl_helper(e, cmd, i, p, f); 223 return int_ctrl_helper(e, cmd, i, p, f);
227 if (!ctrl_exists) { 224 if (!ctrl_exists) {
228 ENGINEerr(ENGINE_F_ENGINE_CTRL, 225 ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION);
229 ENGINE_R_NO_CONTROL_FUNCTION);
230 /* For these cmd-related functions, failure is indicated 226 /* For these cmd-related functions, failure is indicated
231 * by a -1 return value (because 0 is used as a valid 227 * by a -1 return value (because 0 is used as a valid
232 * return in some places). */ 228 * return in some places). */
@@ -237,7 +233,7 @@ ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
237 } 233 }
238 /* Anything else requires a ctrl() handler to exist. */ 234 /* Anything else requires a ctrl() handler to exist. */
239 if (!ctrl_exists) { 235 if (!ctrl_exists) {
240 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION); 236 ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION);
241 return 0; 237 return 0;
242 } 238 }
243 return e->ctrl(e, cmd, i, p, f); 239 return e->ctrl(e, cmd, i, p, f);
@@ -250,8 +246,7 @@ ENGINE_cmd_is_executable(ENGINE *e, int cmd)
250 246
251 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, 247 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd,
252 NULL, NULL)) < 0) { 248 NULL, NULL)) < 0) {
253 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, 249 ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER);
254 ENGINE_R_INVALID_CMD_NUMBER);
255 return 0; 250 return 0;
256 } 251 }
257 if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) && 252 if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
@@ -268,8 +263,7 @@ ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p,
268 int num; 263 int num;
269 264
270 if ((e == NULL) || (cmd_name == NULL)) { 265 if ((e == NULL) || (cmd_name == NULL)) {
271 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, 266 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
272 ERR_R_PASSED_NULL_PARAMETER);
273 return 0; 267 return 0;
274 } 268 }
275 if ((e->ctrl == NULL) || 269 if ((e->ctrl == NULL) ||
@@ -285,7 +279,7 @@ ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p,
285 ERR_clear_error(); 279 ERR_clear_error();
286 return 1; 280 return 1;
287 } 281 }
288 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, ENGINE_R_INVALID_CMD_NAME); 282 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
289 return 0; 283 return 0;
290 } 284 }
291 285
@@ -306,8 +300,7 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
306 char *ptr; 300 char *ptr;
307 301
308 if ((e == NULL) || (cmd_name == NULL)) { 302 if ((e == NULL) || (cmd_name == NULL)) {
309 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 303 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
310 ERR_R_PASSED_NULL_PARAMETER);
311 return 0; 304 return 0;
312 } 305 }
313 if ((e->ctrl == NULL) || 306 if ((e->ctrl == NULL) ||
@@ -323,29 +316,25 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
323 ERR_clear_error(); 316 ERR_clear_error();
324 return 1; 317 return 1;
325 } 318 }
326 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 319 ENGINEerror(ENGINE_R_INVALID_CMD_NAME);
327 ENGINE_R_INVALID_CMD_NAME);
328 return 0; 320 return 0;
329 } 321 }
330 if (!ENGINE_cmd_is_executable(e, num)) { 322 if (!ENGINE_cmd_is_executable(e, num)) {
331 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 323 ENGINEerror(ENGINE_R_CMD_NOT_EXECUTABLE);
332 ENGINE_R_CMD_NOT_EXECUTABLE);
333 return 0; 324 return 0;
334 } 325 }
335 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, 326 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
336 NULL, NULL)) < 0) { 327 NULL, NULL)) < 0) {
337 /* Shouldn't happen, given that ENGINE_cmd_is_executable() 328 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
338 * returned success. */ 329 * returned success. */
339 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 330 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
340 ENGINE_R_INTERNAL_LIST_ERROR);
341 return 0; 331 return 0;
342 } 332 }
343 /* If the command takes no input, there must be no input. And vice 333 /* If the command takes no input, there must be no input. And vice
344 * versa. */ 334 * versa. */
345 if (flags & ENGINE_CMD_FLAG_NO_INPUT) { 335 if (flags & ENGINE_CMD_FLAG_NO_INPUT) {
346 if (arg != NULL) { 336 if (arg != NULL) {
347 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 337 ENGINEerror(ENGINE_R_COMMAND_TAKES_NO_INPUT);
348 ENGINE_R_COMMAND_TAKES_NO_INPUT);
349 return 0; 338 return 0;
350 } 339 }
351 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 340 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
@@ -359,8 +348,7 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
359 } 348 }
360 /* So, we require input */ 349 /* So, we require input */
361 if (arg == NULL) { 350 if (arg == NULL) {
362 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 351 ENGINEerror(ENGINE_R_COMMAND_TAKES_INPUT);
363 ENGINE_R_COMMAND_TAKES_INPUT);
364 return 0; 352 return 0;
365 } 353 }
366 /* If it takes string input, that's easy */ 354 /* If it takes string input, that's easy */
@@ -375,14 +363,12 @@ ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
375 * should never happen though, because ENGINE_cmd_is_executable() was 363 * should never happen though, because ENGINE_cmd_is_executable() was
376 * used. */ 364 * used. */
377 if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) { 365 if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) {
378 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 366 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
379 ENGINE_R_INTERNAL_LIST_ERROR);
380 return 0; 367 return 0;
381 } 368 }
382 l = strtol(arg, &ptr, 10); 369 l = strtol(arg, &ptr, 10);
383 if ((arg == ptr) || (*ptr != '\0')) { 370 if ((arg == ptr) || (*ptr != '\0')) {
384 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 371 ENGINEerror(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
385 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
386 return 0; 372 return 0;
387 } 373 }
388 /* Force the result of the control command to 0 or 1, for the reasons 374 /* Force the result of the control command to 0 or 1, for the reasons
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
index d65efde991..b604cbba9e 100644
--- a/src/lib/libcrypto/engine/eng_err.c
+++ b/src/lib/libcrypto/engine/eng_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_err.c,v 1.10 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: eng_err.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,45 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason)
73 73
74static ERR_STRING_DATA ENGINE_str_functs[] = { 74static ERR_STRING_DATA ENGINE_str_functs[] = {
75 {ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"},
77 {ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"},
78 {ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"},
79 {ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"},
80 {ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"},
81 {ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"},
82 {ERR_FUNC(ENGINE_F_ENGINE_CTRL), "ENGINE_ctrl"},
83 {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"},
84 {ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"},
85 {ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
86 {ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"},
87 {ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
88 {ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"},
89 {ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
90 {ERR_FUNC(ENGINE_F_ENGINE_GET_NEXT), "ENGINE_get_next"},
91 {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH), "ENGINE_get_pkey_asn1_meth"},
92 {ERR_FUNC(ENGINE_F_ENGINE_GET_PKEY_METH), "ENGINE_get_pkey_meth"},
93 {ERR_FUNC(ENGINE_F_ENGINE_GET_PREV), "ENGINE_get_prev"},
94 {ERR_FUNC(ENGINE_F_ENGINE_INIT), "ENGINE_init"},
95 {ERR_FUNC(ENGINE_F_ENGINE_LIST_ADD), "ENGINE_LIST_ADD"},
96 {ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
97 {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
98 {ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
99 {ERR_FUNC(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT), "ENGINE_load_ssl_client_cert"},
100 {ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
101 {ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
102 {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
103 {ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_TYPE), "ENGINE_SET_DEFAULT_TYPE"},
104 {ERR_FUNC(ENGINE_F_ENGINE_SET_ID), "ENGINE_set_id"},
105 {ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"},
106 {ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"},
107 {ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"},
108 {ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"},
109 {ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"},
110 {ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"},
111 {ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"},
112 {ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"},
113 {ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"},
114 {0, NULL} 76 {0, NULL}
115}; 77};
116 78
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
index b54757d8ad..c97695a7d3 100644
--- a/src/lib/libcrypto/engine/eng_fat.c
+++ b/src/lib/libcrypto/engine/eng_fat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_fat.c,v 1.15 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_fat.c,v 1.16 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -147,8 +147,7 @@ ENGINE_set_default_string(ENGINE *e, const char *def_list)
147 unsigned int flags = 0; 147 unsigned int flags = 0;
148 148
149 if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) { 149 if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) {
150 ENGINEerr(ENGINE_F_ENGINE_SET_DEFAULT_STRING, 150 ENGINEerror(ENGINE_R_INVALID_STRING);
151 ENGINE_R_INVALID_STRING);
152 ERR_asprintf_error_data("str=%s",def_list); 151 ERR_asprintf_error_data("str=%s",def_list);
153 return 0; 152 return 0;
154 } 153 }
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c
index b50e22594c..75d6698c70 100644
--- a/src/lib/libcrypto/engine/eng_init.c
+++ b/src/lib/libcrypto/engine/eng_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_init.c,v 1.7 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_init.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -106,8 +106,7 @@ engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
106 106
107 /* Release the structural reference too */ 107 /* Release the structural reference too */
108 if (!engine_free_util(e, 0)) { 108 if (!engine_free_util(e, 0)) {
109 ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, 109 ENGINEerror(ENGINE_R_FINISH_FAILED);
110 ENGINE_R_FINISH_FAILED);
111 return 0; 110 return 0;
112 } 111 }
113 return to_return; 112 return to_return;
@@ -120,7 +119,7 @@ ENGINE_init(ENGINE *e)
120 int ret; 119 int ret;
121 120
122 if (e == NULL) { 121 if (e == NULL) {
123 ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER); 122 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
124 return 0; 123 return 0;
125 } 124 }
126 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 125 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -136,14 +135,14 @@ ENGINE_finish(ENGINE *e)
136 int to_return = 1; 135 int to_return = 1;
137 136
138 if (e == NULL) { 137 if (e == NULL) {
139 ENGINEerr(ENGINE_F_ENGINE_FINISH, ERR_R_PASSED_NULL_PARAMETER); 138 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
140 return 0; 139 return 0;
141 } 140 }
142 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 141 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
143 to_return = engine_unlocked_finish(e, 1); 142 to_return = engine_unlocked_finish(e, 1);
144 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 143 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
145 if (!to_return) { 144 if (!to_return) {
146 ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED); 145 ENGINEerror(ENGINE_R_FINISH_FAILED);
147 return 0; 146 return 0;
148 } 147 }
149 return to_return; 148 return to_return;
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
index f5f54fc657..d2da29fe69 100644
--- a/src/lib/libcrypto/engine/eng_lib.c
+++ b/src/lib/libcrypto/engine/eng_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_lib.c,v 1.11 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_lib.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -72,7 +72,7 @@ ENGINE_new(void)
72 72
73 ret = malloc(sizeof(ENGINE)); 73 ret = malloc(sizeof(ENGINE));
74 if (ret == NULL) { 74 if (ret == NULL) {
75 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE); 75 ENGINEerror(ERR_R_MALLOC_FAILURE);
76 return NULL; 76 return NULL;
77 } 77 }
78 memset(ret, 0, sizeof(ENGINE)); 78 memset(ret, 0, sizeof(ENGINE));
@@ -113,8 +113,7 @@ engine_free_util(ENGINE *e, int locked)
113 int i; 113 int i;
114 114
115 if (e == NULL) { 115 if (e == NULL) {
116 ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL, 116 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
117 ERR_R_PASSED_NULL_PARAMETER);
118 return 0; 117 return 0;
119 } 118 }
120 if (locked) 119 if (locked)
@@ -245,8 +244,7 @@ int
245ENGINE_set_id(ENGINE *e, const char *id) 244ENGINE_set_id(ENGINE *e, const char *id)
246{ 245{
247 if (id == NULL) { 246 if (id == NULL) {
248 ENGINEerr(ENGINE_F_ENGINE_SET_ID, 247 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
249 ERR_R_PASSED_NULL_PARAMETER);
250 return 0; 248 return 0;
251 } 249 }
252 e->id = id; 250 e->id = id;
@@ -257,8 +255,7 @@ int
257ENGINE_set_name(ENGINE *e, const char *name) 255ENGINE_set_name(ENGINE *e, const char *name)
258{ 256{
259 if (name == NULL) { 257 if (name == NULL) {
260 ENGINEerr(ENGINE_F_ENGINE_SET_NAME, 258 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
261 ERR_R_PASSED_NULL_PARAMETER);
262 return 0; 259 return 0;
263 } 260 }
264 e->name = name; 261 e->name = name;
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
index fc1d16b183..8bb1bc58f2 100644
--- a/src/lib/libcrypto/engine/eng_list.c
+++ b/src/lib/libcrypto/engine/eng_list.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_list.c,v 1.21 2015/07/19 00:56:48 bcook Exp $ */ 1/* $OpenBSD: eng_list.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -105,8 +105,7 @@ engine_list_add(ENGINE *e)
105 ENGINE *iterator = NULL; 105 ENGINE *iterator = NULL;
106 106
107 if (e == NULL) { 107 if (e == NULL) {
108 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, 108 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
109 ERR_R_PASSED_NULL_PARAMETER);
110 return 0; 109 return 0;
111 } 110 }
112 iterator = engine_list_head; 111 iterator = engine_list_head;
@@ -115,15 +114,13 @@ engine_list_add(ENGINE *e)
115 iterator = iterator->next; 114 iterator = iterator->next;
116 } 115 }
117 if (conflict) { 116 if (conflict) {
118 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, 117 ENGINEerror(ENGINE_R_CONFLICTING_ENGINE_ID);
119 ENGINE_R_CONFLICTING_ENGINE_ID);
120 return 0; 118 return 0;
121 } 119 }
122 if (engine_list_head == NULL) { 120 if (engine_list_head == NULL) {
123 /* We are adding to an empty list. */ 121 /* We are adding to an empty list. */
124 if (engine_list_tail) { 122 if (engine_list_tail) {
125 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, 123 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
126 ENGINE_R_INTERNAL_LIST_ERROR);
127 return 0; 124 return 0;
128 } 125 }
129 engine_list_head = e; 126 engine_list_head = e;
@@ -135,8 +132,7 @@ engine_list_add(ENGINE *e)
135 /* We are adding to the tail of an existing list. */ 132 /* We are adding to the tail of an existing list. */
136 if ((engine_list_tail == NULL) || 133 if ((engine_list_tail == NULL) ||
137 (engine_list_tail->next != NULL)) { 134 (engine_list_tail->next != NULL)) {
138 ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, 135 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
139 ENGINE_R_INTERNAL_LIST_ERROR);
140 return 0; 136 return 0;
141 } 137 }
142 engine_list_tail->next = e; 138 engine_list_tail->next = e;
@@ -158,8 +154,7 @@ engine_list_remove(ENGINE *e)
158 ENGINE *iterator; 154 ENGINE *iterator;
159 155
160 if (e == NULL) { 156 if (e == NULL) {
161 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, 157 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
162 ERR_R_PASSED_NULL_PARAMETER);
163 return 0; 158 return 0;
164 } 159 }
165 /* We need to check that e is in our linked list! */ 160 /* We need to check that e is in our linked list! */
@@ -167,8 +162,7 @@ engine_list_remove(ENGINE *e)
167 while (iterator && (iterator != e)) 162 while (iterator && (iterator != e))
168 iterator = iterator->next; 163 iterator = iterator->next;
169 if (iterator == NULL) { 164 if (iterator == NULL) {
170 ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, 165 ENGINEerror(ENGINE_R_ENGINE_IS_NOT_IN_LIST);
171 ENGINE_R_ENGINE_IS_NOT_IN_LIST);
172 return 0; 166 return 0;
173 } 167 }
174 /* un-link e from the chain. */ 168 /* un-link e from the chain. */
@@ -223,8 +217,7 @@ ENGINE_get_next(ENGINE *e)
223 ENGINE *ret = NULL; 217 ENGINE *ret = NULL;
224 218
225 if (e == NULL) { 219 if (e == NULL) {
226 ENGINEerr(ENGINE_F_ENGINE_GET_NEXT, 220 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
227 ERR_R_PASSED_NULL_PARAMETER);
228 return 0; 221 return 0;
229 } 222 }
230 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 223 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -246,8 +239,7 @@ ENGINE_get_prev(ENGINE *e)
246 ENGINE *ret = NULL; 239 ENGINE *ret = NULL;
247 240
248 if (e == NULL) { 241 if (e == NULL) {
249 ENGINEerr(ENGINE_F_ENGINE_GET_PREV, 242 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
250 ERR_R_PASSED_NULL_PARAMETER);
251 return 0; 243 return 0;
252 } 244 }
253 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 245 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -270,18 +262,15 @@ ENGINE_add(ENGINE *e)
270 int to_return = 1; 262 int to_return = 1;
271 263
272 if (e == NULL) { 264 if (e == NULL) {
273 ENGINEerr(ENGINE_F_ENGINE_ADD, 265 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
274 ERR_R_PASSED_NULL_PARAMETER);
275 return 0; 266 return 0;
276 } 267 }
277 if ((e->id == NULL) || (e->name == NULL)) { 268 if ((e->id == NULL) || (e->name == NULL)) {
278 ENGINEerr(ENGINE_F_ENGINE_ADD, 269 ENGINEerror(ENGINE_R_ID_OR_NAME_MISSING);
279 ENGINE_R_ID_OR_NAME_MISSING);
280 } 270 }
281 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 271 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
282 if (!engine_list_add(e)) { 272 if (!engine_list_add(e)) {
283 ENGINEerr(ENGINE_F_ENGINE_ADD, 273 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
284 ENGINE_R_INTERNAL_LIST_ERROR);
285 to_return = 0; 274 to_return = 0;
286 } 275 }
287 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 276 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
@@ -295,14 +284,12 @@ ENGINE_remove(ENGINE *e)
295 int to_return = 1; 284 int to_return = 1;
296 285
297 if (e == NULL) { 286 if (e == NULL) {
298 ENGINEerr(ENGINE_F_ENGINE_REMOVE, 287 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
299 ERR_R_PASSED_NULL_PARAMETER);
300 return 0; 288 return 0;
301 } 289 }
302 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 290 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
303 if (!engine_list_remove(e)) { 291 if (!engine_list_remove(e)) {
304 ENGINEerr(ENGINE_F_ENGINE_REMOVE, 292 ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR);
305 ENGINE_R_INTERNAL_LIST_ERROR);
306 to_return = 0; 293 to_return = 0;
307 } 294 }
308 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 295 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
@@ -350,8 +337,7 @@ ENGINE_by_id(const char *id)
350 ENGINE *iterator; 337 ENGINE *iterator;
351 338
352 if (id == NULL) { 339 if (id == NULL) {
353 ENGINEerr(ENGINE_F_ENGINE_BY_ID, 340 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
354 ERR_R_PASSED_NULL_PARAMETER);
355 return NULL; 341 return NULL;
356 } 342 }
357 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 343 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -378,7 +364,7 @@ ENGINE_by_id(const char *id)
378 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 364 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
379 365
380 if (iterator == NULL) { 366 if (iterator == NULL) {
381 ENGINEerr(ENGINE_F_ENGINE_BY_ID, ENGINE_R_NO_SUCH_ENGINE); 367 ENGINEerror(ENGINE_R_NO_SUCH_ENGINE);
382 ERR_asprintf_error_data("id=%s", id); 368 ERR_asprintf_error_data("id=%s", id);
383 } 369 }
384 return iterator; 370 return iterator;
@@ -388,7 +374,7 @@ int
388ENGINE_up_ref(ENGINE *e) 374ENGINE_up_ref(ENGINE *e)
389{ 375{
390 if (e == NULL) { 376 if (e == NULL) {
391 ENGINEerr(ENGINE_F_ENGINE_UP_REF, ERR_R_PASSED_NULL_PARAMETER); 377 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
392 return 0; 378 return 0;
393 } 379 }
394 CRYPTO_add(&e->struct_ref, 1, CRYPTO_LOCK_ENGINE); 380 CRYPTO_add(&e->struct_ref, 1, CRYPTO_LOCK_ENGINE);
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
index 74b1ce03b7..a0320e973f 100644
--- a/src/lib/libcrypto/engine/eng_pkey.c
+++ b/src/lib/libcrypto/engine/eng_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_pkey.c,v 1.6 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_pkey.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -108,27 +108,23 @@ ENGINE_load_private_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method,
108 EVP_PKEY *pkey; 108 EVP_PKEY *pkey;
109 109
110 if (e == NULL) { 110 if (e == NULL) {
111 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 111 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
112 ERR_R_PASSED_NULL_PARAMETER);
113 return 0; 112 return 0;
114 } 113 }
115 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 114 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
116 if (e->funct_ref == 0) { 115 if (e->funct_ref == 0) {
117 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 116 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
118 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 117 ENGINEerror(ENGINE_R_NOT_INITIALISED);
119 ENGINE_R_NOT_INITIALISED);
120 return 0; 118 return 0;
121 } 119 }
122 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 120 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
123 if (!e->load_privkey) { 121 if (!e->load_privkey) {
124 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 122 ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION);
125 ENGINE_R_NO_LOAD_FUNCTION);
126 return 0; 123 return 0;
127 } 124 }
128 pkey = e->load_privkey(e, key_id, ui_method, callback_data); 125 pkey = e->load_privkey(e, key_id, ui_method, callback_data);
129 if (!pkey) { 126 if (!pkey) {
130 ENGINEerr(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY, 127 ENGINEerror(ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
131 ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
132 return 0; 128 return 0;
133 } 129 }
134 return pkey; 130 return pkey;
@@ -141,27 +137,23 @@ ENGINE_load_public_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method,
141 EVP_PKEY *pkey; 137 EVP_PKEY *pkey;
142 138
143 if (e == NULL) { 139 if (e == NULL) {
144 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 140 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
145 ERR_R_PASSED_NULL_PARAMETER);
146 return 0; 141 return 0;
147 } 142 }
148 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 143 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
149 if (e->funct_ref == 0) { 144 if (e->funct_ref == 0) {
150 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 145 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
151 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 146 ENGINEerror(ENGINE_R_NOT_INITIALISED);
152 ENGINE_R_NOT_INITIALISED);
153 return 0; 147 return 0;
154 } 148 }
155 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 149 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
156 if (!e->load_pubkey) { 150 if (!e->load_pubkey) {
157 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 151 ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION);
158 ENGINE_R_NO_LOAD_FUNCTION);
159 return 0; 152 return 0;
160 } 153 }
161 pkey = e->load_pubkey(e, key_id, ui_method, callback_data); 154 pkey = e->load_pubkey(e, key_id, ui_method, callback_data);
162 if (!pkey) { 155 if (!pkey) {
163 ENGINEerr(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY, 156 ENGINEerror(ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
164 ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
165 return 0; 157 return 0;
166 } 158 }
167 return pkey; 159 return pkey;
@@ -173,21 +165,18 @@ ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, STACK_OF(X509_NAME) *ca_dn,
173 UI_METHOD *ui_method, void *callback_data) 165 UI_METHOD *ui_method, void *callback_data)
174{ 166{
175 if (e == NULL) { 167 if (e == NULL) {
176 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 168 ENGINEerror(ERR_R_PASSED_NULL_PARAMETER);
177 ERR_R_PASSED_NULL_PARAMETER);
178 return 0; 169 return 0;
179 } 170 }
180 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 171 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
181 if (e->funct_ref == 0) { 172 if (e->funct_ref == 0) {
182 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 173 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
183 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 174 ENGINEerror(ENGINE_R_NOT_INITIALISED);
184 ENGINE_R_NOT_INITIALISED);
185 return 0; 175 return 0;
186 } 176 }
187 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 177 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
188 if (!e->load_ssl_client_cert) { 178 if (!e->load_ssl_client_cert) {
189 ENGINEerr(ENGINE_F_ENGINE_LOAD_SSL_CLIENT_CERT, 179 ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION);
190 ENGINE_R_NO_LOAD_FUNCTION);
191 return 0; 180 return 0;
192 } 181 }
193 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother, 182 return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother,
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
index 342c76fa1b..a8aded5aaf 100644
--- a/src/lib/libcrypto/engine/eng_table.c
+++ b/src/lib/libcrypto/engine/eng_table.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: eng_table.c,v 1.8 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: eng_table.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -172,8 +172,7 @@ engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
172 fnd->uptodate = 0; 172 fnd->uptodate = 0;
173 if (setdefault) { 173 if (setdefault) {
174 if (!engine_unlocked_init(e)) { 174 if (!engine_unlocked_init(e)) {
175 ENGINEerr(ENGINE_F_ENGINE_TABLE_REGISTER, 175 ENGINEerror(ENGINE_R_INIT_FAILED);
176 ENGINE_R_INIT_FAILED);
177 goto end; 176 goto end;
178 } 177 }
179 if (fnd->funct) 178 if (fnd->funct)
diff --git a/src/lib/libcrypto/engine/tb_asnmth.c b/src/lib/libcrypto/engine/tb_asnmth.c
index 3ba5541933..51e5198b40 100644
--- a/src/lib/libcrypto/engine/tb_asnmth.c
+++ b/src/lib/libcrypto/engine/tb_asnmth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tb_asnmth.c,v 1.5 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: tb_asnmth.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -135,8 +135,7 @@ ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid)
135 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e); 135 ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e);
136 136
137 if (!fn || !fn(e, &ret, NULL, nid)) { 137 if (!fn || !fn(e, &ret, NULL, nid)) {
138 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_ASN1_METH, 138 ENGINEerror(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
139 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
140 return NULL; 139 return NULL;
141 } 140 }
142 return ret; 141 return ret;
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
index a888d7a958..ed87ff199e 100644
--- a/src/lib/libcrypto/engine/tb_cipher.c
+++ b/src/lib/libcrypto/engine/tb_cipher.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tb_cipher.c,v 1.7 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: tb_cipher.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -130,8 +130,7 @@ ENGINE_get_cipher(ENGINE *e, int nid)
130 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); 130 ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e);
131 131
132 if (!fn || !fn(e, &ret, NULL, nid)) { 132 if (!fn || !fn(e, &ret, NULL, nid)) {
133 ENGINEerr(ENGINE_F_ENGINE_GET_CIPHER, 133 ENGINEerror(ENGINE_R_UNIMPLEMENTED_CIPHER);
134 ENGINE_R_UNIMPLEMENTED_CIPHER);
135 return NULL; 134 return NULL;
136 } 135 }
137 return ret; 136 return ret;
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
index f7720d39e7..f1a2e8a6b3 100644
--- a/src/lib/libcrypto/engine/tb_digest.c
+++ b/src/lib/libcrypto/engine/tb_digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tb_digest.c,v 1.7 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: tb_digest.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -130,8 +130,7 @@ ENGINE_get_digest(ENGINE *e, int nid)
130 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); 130 ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e);
131 131
132 if (!fn || !fn(e, &ret, NULL, nid)) { 132 if (!fn || !fn(e, &ret, NULL, nid)) {
133 ENGINEerr(ENGINE_F_ENGINE_GET_DIGEST, 133 ENGINEerror(ENGINE_R_UNIMPLEMENTED_DIGEST);
134 ENGINE_R_UNIMPLEMENTED_DIGEST);
135 return NULL; 134 return NULL;
136 } 135 }
137 return ret; 136 return ret;
diff --git a/src/lib/libcrypto/engine/tb_pkmeth.c b/src/lib/libcrypto/engine/tb_pkmeth.c
index 3840434262..05566a3464 100644
--- a/src/lib/libcrypto/engine/tb_pkmeth.c
+++ b/src/lib/libcrypto/engine/tb_pkmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tb_pkmeth.c,v 1.5 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: tb_pkmeth.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -131,8 +131,7 @@ ENGINE_get_pkey_meth(ENGINE *e, int nid)
131 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); 131 ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e);
132 132
133 if (!fn || !fn(e, &ret, NULL, nid)) { 133 if (!fn || !fn(e, &ret, NULL, nid)) {
134 ENGINEerr(ENGINE_F_ENGINE_GET_PKEY_METH, 134 ENGINEerror(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
135 ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD);
136 return NULL; 135 return NULL;
137 } 136 }
138 return ret; 137 return ret;
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index f06320247c..292805433d 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: err.c,v 1.41 2014/11/09 19:17:13 miod Exp $ */ 1/* $OpenBSD: err.c,v 1.42 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -566,7 +566,7 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
566 * others will be displayed numerically by ERR_error_string. 566 * others will be displayed numerically by ERR_error_string.
567 * It is crucial that we have something for each reason code 567 * It is crucial that we have something for each reason code
568 * that occurs in ERR_str_reasons, or bogus reason strings 568 * that occurs in ERR_str_reasons, or bogus reason strings
569 * will be returned for SYSerr(), which always gets an errno 569 * will be returned for SYSerror(which always gets an errno
570 * value and never one of those 'standard' reason codes. */ 570 * value and never one of those 'standard' reason codes. */
571 571
572static void 572static void
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
index f34db75d6f..672dead06b 100644
--- a/src/lib/libcrypto/err/err.h
+++ b/src/lib/libcrypto/err/err.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: err.h,v 1.23 2017/01/26 12:07:06 beck Exp $ */ 1/* $OpenBSD: err.h,v 1.24 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -199,6 +199,7 @@ typedef struct err_state_st {
199 199
200#define ERR_LIB_USER 128 200#define ERR_LIB_USER 128
201 201
202#ifndef LIBRESSL_INTERNAL
202#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__) 203#define SYSerr(f,r) ERR_PUT_error(ERR_LIB_SYS,(f),(r),__FILE__,__LINE__)
203#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__) 204#define BNerr(f,r) ERR_PUT_error(ERR_LIB_BN,(f),(r),__FILE__,__LINE__)
204#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__) 205#define RSAerr(f,r) ERR_PUT_error(ERR_LIB_RSA,(f),(r),__FILE__,__LINE__)
@@ -232,10 +233,45 @@ typedef struct err_state_st {
232#define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) 233#define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__)
233#define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) 234#define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__)
234#define GOSTerr(f,r) ERR_PUT_error(ERR_LIB_GOST,(f),(r),__FILE__,__LINE__) 235#define GOSTerr(f,r) ERR_PUT_error(ERR_LIB_GOST,(f),(r),__FILE__,__LINE__)
235#ifndef LIBRESSL_INTERNAL
236#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__) 236#define SSLerr(f,r) ERR_PUT_error(ERR_LIB_SSL,(f),(r),__FILE__,__LINE__)
237#endif 237#endif
238 238
239#ifdef LIBRESSL_INTERNAL
240#define SYSerror(r) ERR_PUT_error(ERR_LIB_SYS,(0xfff),(r),__FILE__,__LINE__)
241#define BNerror(r) ERR_PUT_error(ERR_LIB_BN,(0xfff),(r),__FILE__,__LINE__)
242#define RSAerror(r) ERR_PUT_error(ERR_LIB_RSA,(0xfff),(r),__FILE__,__LINE__)
243#define DHerror(r) ERR_PUT_error(ERR_LIB_DH,(0xfff),(r),__FILE__,__LINE__)
244#define EVPerror(r) ERR_PUT_error(ERR_LIB_EVP,(0xfff),(r),__FILE__,__LINE__)
245#define BUFerror(r) ERR_PUT_error(ERR_LIB_BUF,(0xfff),(r),__FILE__,__LINE__)
246#define OBJerror(r) ERR_PUT_error(ERR_LIB_OBJ,(0xfff),(r),__FILE__,__LINE__)
247#define PEMerror(r) ERR_PUT_error(ERR_LIB_PEM,(0xfff),(r),__FILE__,__LINE__)
248#define DSAerror(r) ERR_PUT_error(ERR_LIB_DSA,(0xfff),(r),__FILE__,__LINE__)
249#define X509error(r) ERR_PUT_error(ERR_LIB_X509,(0xfff),(r),__FILE__,__LINE__)
250#define ASN1error(r) ERR_PUT_error(ERR_LIB_ASN1,(0xfff),(r),__FILE__,__LINE__)
251#define CONFerror(r) ERR_PUT_error(ERR_LIB_CONF,(0xfff),(r),__FILE__,__LINE__)
252#define CRYPTOerror(r) ERR_PUT_error(ERR_LIB_CRYPTO,(0xfff),(r),__FILE__,__LINE__)
253#define ECerror(r) ERR_PUT_error(ERR_LIB_EC,(0xfff),(r),__FILE__,__LINE__)
254#define BIOerror(r) ERR_PUT_error(ERR_LIB_BIO,(0xfff),(r),__FILE__,__LINE__)
255#define PKCS7error(r) ERR_PUT_error(ERR_LIB_PKCS7,(0xfff),(r),__FILE__,__LINE__)
256#define X509V3error(r) ERR_PUT_error(ERR_LIB_X509V3,(0xfff),(r),__FILE__,__LINE__)
257#define PKCS12error(r) ERR_PUT_error(ERR_LIB_PKCS12,(0xfff),(r),__FILE__,__LINE__)
258#define RANDerror(r) ERR_PUT_error(ERR_LIB_RAND,(0xfff),(r),__FILE__,__LINE__)
259#define DSOerror(r) ERR_PUT_error(ERR_LIB_DSO,(0xfff),(r),__FILE__,__LINE__)
260#define ENGINEerror(r) ERR_PUT_error(ERR_LIB_ENGINE,(0xfff),(r),__FILE__,__LINE__)
261#define OCSPerror(r) ERR_PUT_error(ERR_LIB_OCSP,(0xfff),(r),__FILE__,__LINE__)
262#define UIerror(r) ERR_PUT_error(ERR_LIB_UI,(0xfff),(r),__FILE__,__LINE__)
263#define COMPerror(r) ERR_PUT_error(ERR_LIB_COMP,(0xfff),(r),__FILE__,__LINE__)
264#define ECDSAerror(r) ERR_PUT_error(ERR_LIB_ECDSA,(0xfff),(r),__FILE__,__LINE__)
265#define ECDHerror(r) ERR_PUT_error(ERR_LIB_ECDH,(0xfff),(r),__FILE__,__LINE__)
266#define STOREerror(r) ERR_PUT_error(ERR_LIB_STORE,(0xfff),(r),__FILE__,__LINE__)
267#define FIPSerror(r) ERR_PUT_error(ERR_LIB_FIPS,(0xfff),(r),__FILE__,__LINE__)
268#define CMSerror(r) ERR_PUT_error(ERR_LIB_CMS,(0xfff),(r),__FILE__,__LINE__)
269#define TSerror(r) ERR_PUT_error(ERR_LIB_TS,(0xfff),(r),__FILE__,__LINE__)
270#define HMACerror(r) ERR_PUT_error(ERR_LIB_HMAC,(0xfff),(r),__FILE__,__LINE__)
271#define JPAKEerror(r) ERR_PUT_error(ERR_LIB_JPAKE,(0xfff),(r),__FILE__,__LINE__)
272#define GOSTerror(r) ERR_PUT_error(ERR_LIB_GOST,(0xfff),(r),__FILE__,__LINE__)
273#endif
274
239#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \ 275#define ERR_PACK(l,f,r) (((((unsigned long)l)&0xffL)<<24L)| \
240 ((((unsigned long)f)&0xfffL)<<12L)| \ 276 ((((unsigned long)f)&0xfffL)<<12L)| \
241 ((((unsigned long)r)&0xfffL))) 277 ((((unsigned long)r)&0xfffL)))
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index 6d8ed9b499..ee1f955959 100644
--- a/src/lib/libcrypto/evp/digest.c
+++ b/src/lib/libcrypto/evp/digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: digest.c,v 1.26 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: digest.c,v 1.27 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -162,8 +162,7 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
162 ENGINE_finish(ctx->engine); 162 ENGINE_finish(ctx->engine);
163 if (impl) { 163 if (impl) {
164 if (!ENGINE_init(impl)) { 164 if (!ENGINE_init(impl)) {
165 EVPerr(EVP_F_EVP_DIGESTINIT_EX, 165 EVPerror(EVP_R_INITIALIZATION_ERROR);
166 EVP_R_INITIALIZATION_ERROR);
167 return 0; 166 return 0;
168 } 167 }
169 } else 168 } else
@@ -174,8 +173,7 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
174 const EVP_MD *d = ENGINE_get_digest(impl, type->type); 173 const EVP_MD *d = ENGINE_get_digest(impl, type->type);
175 if (!d) { 174 if (!d) {
176 /* Same comment from evp_enc.c */ 175 /* Same comment from evp_enc.c */
177 EVPerr(EVP_F_EVP_DIGESTINIT_EX, 176 EVPerror(EVP_R_INITIALIZATION_ERROR);
178 EVP_R_INITIALIZATION_ERROR);
179 ENGINE_finish(impl); 177 ENGINE_finish(impl);
180 return 0; 178 return 0;
181 } 179 }
@@ -188,7 +186,7 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
188 } else 186 } else
189 ctx->engine = NULL; 187 ctx->engine = NULL;
190 } else if (!ctx->digest) { 188 } else if (!ctx->digest) {
191 EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET); 189 EVPerror(EVP_R_NO_DIGEST_SET);
192 return 0; 190 return 0;
193 } 191 }
194#endif 192#endif
@@ -206,8 +204,7 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
206 if (ctx->md_data == NULL) { 204 if (ctx->md_data == NULL) {
207 EVP_PKEY_CTX_free(ctx->pctx); 205 EVP_PKEY_CTX_free(ctx->pctx);
208 ctx->pctx = NULL; 206 ctx->pctx = NULL;
209 EVPerr(EVP_F_EVP_DIGESTINIT_EX, 207 EVPerror(ERR_R_MALLOC_FAILURE);
210 ERR_R_MALLOC_FAILURE);
211 return 0; 208 return 0;
212 } 209 }
213 } 210 }
@@ -251,7 +248,7 @@ EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
251 int ret; 248 int ret;
252 249
253 if ((size_t)ctx->digest->md_size > EVP_MAX_MD_SIZE) { 250 if ((size_t)ctx->digest->md_size > EVP_MAX_MD_SIZE) {
254 EVPerr(EVP_F_EVP_DIGESTFINAL_EX, EVP_R_TOO_LARGE); 251 EVPerror(EVP_R_TOO_LARGE);
255 return 0; 252 return 0;
256 } 253 }
257 ret = ctx->digest->final(ctx, md); 254 ret = ctx->digest->final(ctx, md);
@@ -278,13 +275,13 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
278 unsigned char *tmp_buf; 275 unsigned char *tmp_buf;
279 276
280 if ((in == NULL) || (in->digest == NULL)) { 277 if ((in == NULL) || (in->digest == NULL)) {
281 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED); 278 EVPerror(EVP_R_INPUT_NOT_INITIALIZED);
282 return 0; 279 return 0;
283 } 280 }
284#ifndef OPENSSL_NO_ENGINE 281#ifndef OPENSSL_NO_ENGINE
285 /* Make sure it's safe to copy a digest context using an ENGINE */ 282 /* Make sure it's safe to copy a digest context using an ENGINE */
286 if (in->engine && !ENGINE_init(in->engine)) { 283 if (in->engine && !ENGINE_init(in->engine)) {
287 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB); 284 EVPerror(ERR_R_ENGINE_LIB);
288 return 0; 285 return 0;
289 } 286 }
290#endif 287#endif
@@ -303,8 +300,7 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
303 else { 300 else {
304 out->md_data = malloc(out->digest->ctx_size); 301 out->md_data = malloc(out->digest->ctx_size);
305 if (!out->md_data) { 302 if (!out->md_data) {
306 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, 303 EVPerror(ERR_R_MALLOC_FAILURE);
307 ERR_R_MALLOC_FAILURE);
308 return 0; 304 return 0;
309 } 305 }
310 } 306 }
@@ -386,19 +382,18 @@ EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
386 int ret; 382 int ret;
387 383
388 if (!ctx->digest) { 384 if (!ctx->digest) {
389 EVPerr(EVP_F_EVP_MD_CTX_CTRL, EVP_R_NO_CIPHER_SET); 385 EVPerror(EVP_R_NO_CIPHER_SET);
390 return 0; 386 return 0;
391 } 387 }
392 388
393 if (!ctx->digest->md_ctrl) { 389 if (!ctx->digest->md_ctrl) {
394 EVPerr(EVP_F_EVP_MD_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED); 390 EVPerror(EVP_R_CTRL_NOT_IMPLEMENTED);
395 return 0; 391 return 0;
396 } 392 }
397 393
398 ret = ctx->digest->md_ctrl(ctx, type, arg, ptr); 394 ret = ctx->digest->md_ctrl(ctx, type, arg, ptr);
399 if (ret == -1) { 395 if (ret == -1) {
400 EVPerr(EVP_F_EVP_MD_CTX_CTRL, 396 EVPerror(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
401 EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
402 return 0; 397 return 0;
403 } 398 }
404 return ret; 399 return ret;
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index b20543a90c..71a18363f1 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes.c,v 1.31 2016/11/04 17:30:30 miod Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.32 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -225,7 +225,7 @@ aesni_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
225 } 225 }
226 226
227 if (ret < 0) { 227 if (ret < 0) {
228 EVPerr(EVP_F_AESNI_INIT_KEY, EVP_R_AES_KEY_SETUP_FAILED); 228 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
229 return 0; 229 return 0;
230 } 230 }
231 231
@@ -563,7 +563,7 @@ aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
563 } 563 }
564 564
565 if (ret < 0) { 565 if (ret < 0) {
566 EVPerr(EVP_F_AES_INIT_KEY, EVP_R_AES_KEY_SETUP_FAILED); 566 EVPerror(EVP_R_AES_KEY_SETUP_FAILED);
567 return 0; 567 return 0;
568 } 568 }
569 569
@@ -1378,7 +1378,7 @@ aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const unsigned char *key, size_t key_len,
1378 1378
1379 /* EVP_AEAD_CTX_init should catch this. */ 1379 /* EVP_AEAD_CTX_init should catch this. */
1380 if (key_bits != 128 && key_bits != 256) { 1380 if (key_bits != 128 && key_bits != 256) {
1381 EVPerr(EVP_F_AEAD_AES_GCM_INIT, EVP_R_BAD_KEY_LENGTH); 1381 EVPerror(EVP_R_BAD_KEY_LENGTH);
1382 return 0; 1382 return 0;
1383 } 1383 }
1384 1384
@@ -1386,7 +1386,7 @@ aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const unsigned char *key, size_t key_len,
1386 tag_len = EVP_AEAD_AES_GCM_TAG_LEN; 1386 tag_len = EVP_AEAD_AES_GCM_TAG_LEN;
1387 1387
1388 if (tag_len > EVP_AEAD_AES_GCM_TAG_LEN) { 1388 if (tag_len > EVP_AEAD_AES_GCM_TAG_LEN) {
1389 EVPerr(EVP_F_AEAD_AES_GCM_INIT, EVP_R_TAG_TOO_LARGE); 1389 EVPerror(EVP_R_TAG_TOO_LARGE);
1390 return 0; 1390 return 0;
1391 } 1391 }
1392 1392
@@ -1432,7 +1432,7 @@ aead_aes_gcm_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
1432 size_t bulk = 0; 1432 size_t bulk = 0;
1433 1433
1434 if (max_out_len < in_len + gcm_ctx->tag_len) { 1434 if (max_out_len < in_len + gcm_ctx->tag_len) {
1435 EVPerr(EVP_F_AEAD_AES_GCM_SEAL, EVP_R_BUFFER_TOO_SMALL); 1435 EVPerror(EVP_R_BUFFER_TOO_SMALL);
1436 return 0; 1436 return 0;
1437 } 1437 }
1438 1438
@@ -1471,14 +1471,14 @@ aead_aes_gcm_open(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
1471 size_t bulk = 0; 1471 size_t bulk = 0;
1472 1472
1473 if (in_len < gcm_ctx->tag_len) { 1473 if (in_len < gcm_ctx->tag_len) {
1474 EVPerr(EVP_F_AEAD_AES_GCM_OPEN, EVP_R_BAD_DECRYPT); 1474 EVPerror(EVP_R_BAD_DECRYPT);
1475 return 0; 1475 return 0;
1476 } 1476 }
1477 1477
1478 plaintext_len = in_len - gcm_ctx->tag_len; 1478 plaintext_len = in_len - gcm_ctx->tag_len;
1479 1479
1480 if (max_out_len < plaintext_len) { 1480 if (max_out_len < plaintext_len) {
1481 EVPerr(EVP_F_AEAD_AES_GCM_OPEN, EVP_R_BUFFER_TOO_SMALL); 1481 EVPerror(EVP_R_BUFFER_TOO_SMALL);
1482 return 0; 1482 return 0;
1483 } 1483 }
1484 1484
@@ -1500,7 +1500,7 @@ aead_aes_gcm_open(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
1500 1500
1501 CRYPTO_gcm128_tag(&gcm, tag, gcm_ctx->tag_len); 1501 CRYPTO_gcm128_tag(&gcm, tag, gcm_ctx->tag_len);
1502 if (timingsafe_memcmp(tag, in + plaintext_len, gcm_ctx->tag_len) != 0) { 1502 if (timingsafe_memcmp(tag, in + plaintext_len, gcm_ctx->tag_len) != 0) {
1503 EVPerr(EVP_F_AEAD_AES_GCM_OPEN, EVP_R_BAD_DECRYPT); 1503 EVPerror(EVP_R_BAD_DECRYPT);
1504 return 0; 1504 return 0;
1505 } 1505 }
1506 1506
diff --git a/src/lib/libcrypto/evp/e_camellia.c b/src/lib/libcrypto/evp/e_camellia.c
index e3424cfe94..fd12cf9c50 100644
--- a/src/lib/libcrypto/evp/e_camellia.c
+++ b/src/lib/libcrypto/evp/e_camellia.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_camellia.c,v 1.7 2015/02/10 09:50:12 miod Exp $ */ 1/* $OpenBSD: e_camellia.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -114,8 +114,7 @@ camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
114 ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data); 114 ret = Camellia_set_key(key, ctx->key_len * 8, ctx->cipher_data);
115 115
116 if (ret < 0) { 116 if (ret < 0) {
117 EVPerr(EVP_F_CAMELLIA_INIT_KEY, 117 EVPerror(EVP_R_CAMELLIA_KEY_SETUP_FAILED);
118 EVP_R_CAMELLIA_KEY_SETUP_FAILED);
119 return 0; 118 return 0;
120 } 119 }
121 120
diff --git a/src/lib/libcrypto/evp/e_chacha20poly1305.c b/src/lib/libcrypto/evp/e_chacha20poly1305.c
index e5395ad8ca..e135f9a104 100644
--- a/src/lib/libcrypto/evp/e_chacha20poly1305.c
+++ b/src/lib/libcrypto/evp/e_chacha20poly1305.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_chacha20poly1305.c,v 1.14 2016/04/28 16:06:53 jsing Exp $ */ 1/* $OpenBSD: e_chacha20poly1305.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2015 Reyk Floter <reyk@openbsd.org> 4 * Copyright (c) 2015 Reyk Floter <reyk@openbsd.org>
@@ -59,7 +59,7 @@ aead_chacha20_poly1305_init(EVP_AEAD_CTX *ctx, const unsigned char *key,
59 tag_len = POLY1305_TAG_LEN; 59 tag_len = POLY1305_TAG_LEN;
60 60
61 if (tag_len > POLY1305_TAG_LEN) { 61 if (tag_len > POLY1305_TAG_LEN) {
62 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_INIT, EVP_R_TOO_LARGE); 62 EVPerror(EVP_R_TOO_LARGE);
63 return 0; 63 return 0;
64 } 64 }
65 65
@@ -142,18 +142,17 @@ aead_chacha20_poly1305_seal(const EVP_AEAD_CTX *ctx, unsigned char *out,
142 * Casting to uint64_t inside the conditional is not sufficient to stop 142 * Casting to uint64_t inside the conditional is not sufficient to stop
143 * the warning. */ 143 * the warning. */
144 if (in_len_64 >= (1ULL << 32) * 64 - 64) { 144 if (in_len_64 >= (1ULL << 32) * 64 - 64) {
145 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_SEAL, EVP_R_TOO_LARGE); 145 EVPerror(EVP_R_TOO_LARGE);
146 return 0; 146 return 0;
147 } 147 }
148 148
149 if (max_out_len < in_len + c20_ctx->tag_len) { 149 if (max_out_len < in_len + c20_ctx->tag_len) {
150 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_SEAL, 150 EVPerror(EVP_R_BUFFER_TOO_SMALL);
151 EVP_R_BUFFER_TOO_SMALL);
152 return 0; 151 return 0;
153 } 152 }
154 153
155 if (nonce_len != ctx->aead->nonce_len) { 154 if (nonce_len != ctx->aead->nonce_len) {
156 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_SEAL, EVP_R_IV_TOO_LARGE); 155 EVPerror(EVP_R_IV_TOO_LARGE);
157 return 0; 156 return 0;
158 } 157 }
159 158
@@ -216,7 +215,7 @@ aead_chacha20_poly1305_open(const EVP_AEAD_CTX *ctx, unsigned char *out,
216 uint64_t ctr = 0; 215 uint64_t ctr = 0;
217 216
218 if (in_len < c20_ctx->tag_len) { 217 if (in_len < c20_ctx->tag_len) {
219 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_OPEN, EVP_R_BAD_DECRYPT); 218 EVPerror(EVP_R_BAD_DECRYPT);
220 return 0; 219 return 0;
221 } 220 }
222 221
@@ -228,20 +227,19 @@ aead_chacha20_poly1305_open(const EVP_AEAD_CTX *ctx, unsigned char *out,
228 * Casting to uint64_t inside the conditional is not sufficient to stop 227 * Casting to uint64_t inside the conditional is not sufficient to stop
229 * the warning. */ 228 * the warning. */
230 if (in_len_64 >= (1ULL << 32) * 64 - 64) { 229 if (in_len_64 >= (1ULL << 32) * 64 - 64) {
231 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_OPEN, EVP_R_TOO_LARGE); 230 EVPerror(EVP_R_TOO_LARGE);
232 return 0; 231 return 0;
233 } 232 }
234 233
235 if (nonce_len != ctx->aead->nonce_len) { 234 if (nonce_len != ctx->aead->nonce_len) {
236 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_OPEN, EVP_R_IV_TOO_LARGE); 235 EVPerror(EVP_R_IV_TOO_LARGE);
237 return 0; 236 return 0;
238 } 237 }
239 238
240 plaintext_len = in_len - c20_ctx->tag_len; 239 plaintext_len = in_len - c20_ctx->tag_len;
241 240
242 if (max_out_len < plaintext_len) { 241 if (max_out_len < plaintext_len) {
243 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_OPEN, 242 EVPerror(EVP_R_BUFFER_TOO_SMALL);
244 EVP_R_BUFFER_TOO_SMALL);
245 return 0; 243 return 0;
246 } 244 }
247 245
@@ -276,7 +274,7 @@ aead_chacha20_poly1305_open(const EVP_AEAD_CTX *ctx, unsigned char *out,
276 CRYPTO_poly1305_finish(&poly1305, mac); 274 CRYPTO_poly1305_finish(&poly1305, mac);
277 275
278 if (timingsafe_memcmp(mac, in + plaintext_len, c20_ctx->tag_len) != 0) { 276 if (timingsafe_memcmp(mac, in + plaintext_len, c20_ctx->tag_len) != 0) {
279 EVPerr(EVP_F_AEAD_CHACHA20_POLY1305_OPEN, EVP_R_BAD_DECRYPT); 277 EVPerror(EVP_R_BAD_DECRYPT);
280 return 0; 278 return 0;
281 } 279 }
282 280
diff --git a/src/lib/libcrypto/evp/e_gost2814789.c b/src/lib/libcrypto/evp/e_gost2814789.c
index e2235a64b5..730de4fed1 100644
--- a/src/lib/libcrypto/evp/e_gost2814789.c
+++ b/src/lib/libcrypto/evp/e_gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_gost2814789.c,v 1.3 2014/11/18 05:30:07 miod Exp $ */ 1/* $OpenBSD: e_gost2814789.c,v 1.4 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -107,13 +107,12 @@ gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
107 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new(); 107 GOST_CIPHER_PARAMS *gcp = GOST_CIPHER_PARAMS_new();
108 108
109 if (gcp == NULL) { 109 if (gcp == NULL) {
110 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, 110 GOSTerror(ERR_R_MALLOC_FAILURE);
111 ERR_R_MALLOC_FAILURE);
112 return 0; 111 return 0;
113 } 112 }
114 if (ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len) == 0) { 113 if (ASN1_OCTET_STRING_set(gcp->iv, ctx->iv, ctx->cipher->iv_len) == 0) {
115 GOST_CIPHER_PARAMS_free(gcp); 114 GOST_CIPHER_PARAMS_free(gcp);
116 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 115 GOSTerror(ERR_R_ASN1_LIB);
117 return 0; 116 return 0;
118 } 117 }
119 ASN1_OBJECT_free(gcp->enc_param_set); 118 ASN1_OBJECT_free(gcp->enc_param_set);
@@ -123,8 +122,7 @@ gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
123 p = buf = malloc(len); 122 p = buf = malloc(len);
124 if (buf == NULL) { 123 if (buf == NULL) {
125 GOST_CIPHER_PARAMS_free(gcp); 124 GOST_CIPHER_PARAMS_free(gcp);
126 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, 125 GOSTerror(ERR_R_MALLOC_FAILURE);
127 ERR_R_MALLOC_FAILURE);
128 return 0; 126 return 0;
129 } 127 }
130 i2d_GOST_CIPHER_PARAMS(gcp, &p); 128 i2d_GOST_CIPHER_PARAMS(gcp, &p);
@@ -133,14 +131,13 @@ gost2814789_set_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
133 os = ASN1_OCTET_STRING_new(); 131 os = ASN1_OCTET_STRING_new();
134 if (os == NULL) { 132 if (os == NULL) {
135 free(buf); 133 free(buf);
136 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, 134 GOSTerror(ERR_R_MALLOC_FAILURE);
137 ERR_R_MALLOC_FAILURE);
138 return 0; 135 return 0;
139 } 136 }
140 if (ASN1_OCTET_STRING_set(os, buf, len) == 0) { 137 if (ASN1_OCTET_STRING_set(os, buf, len) == 0) {
141 ASN1_OCTET_STRING_free(os); 138 ASN1_OCTET_STRING_free(os);
142 free(buf); 139 free(buf);
143 GOSTerr(GOST_F_GOST89_SET_ASN1_PARAMETERS, ERR_R_ASN1_LIB); 140 GOSTerror(ERR_R_ASN1_LIB);
144 return 0; 141 return 0;
145 } 142 }
146 free(buf); 143 free(buf);
@@ -169,8 +166,7 @@ gost2814789_get_asn1_params(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
169 len = gcp->iv->length; 166 len = gcp->iv->length;
170 if (len != ctx->cipher->iv_len) { 167 if (len != ctx->cipher->iv_len) {
171 GOST_CIPHER_PARAMS_free(gcp); 168 GOST_CIPHER_PARAMS_free(gcp);
172 GOSTerr(GOST_F_GOST89_GET_ASN1_PARAMETERS, 169 GOSTerror(GOST_R_INVALID_IV_LENGTH);
173 GOST_R_INVALID_IV_LENGTH);
174 return -1; 170 return -1;
175 } 171 }
176 172
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
index 9052195ac2..de1b24a306 100644
--- a/src/lib/libcrypto/evp/e_rc2.c
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_rc2.c,v 1.11 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: e_rc2.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -171,7 +171,7 @@ rc2_magic_to_meth(int i)
171 else if (i == RC2_40_MAGIC) 171 else if (i == RC2_40_MAGIC)
172 return 40; 172 return 40;
173 else { 173 else {
174 EVPerr(EVP_F_RC2_MAGIC_TO_METH, EVP_R_UNSUPPORTED_KEY_SIZE); 174 EVPerror(EVP_R_UNSUPPORTED_KEY_SIZE);
175 return (0); 175 return (0);
176 } 176 }
177} 177}
@@ -188,8 +188,7 @@ rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
188 if (type != NULL) { 188 if (type != NULL) {
189 l = EVP_CIPHER_CTX_iv_length(c); 189 l = EVP_CIPHER_CTX_iv_length(c);
190 if (l > sizeof(iv)) { 190 if (l > sizeof(iv)) {
191 EVPerr(EVP_F_RC2_GET_ASN1_TYPE_AND_IV, 191 EVPerror(EVP_R_IV_TOO_LARGE);
192 EVP_R_IV_TOO_LARGE);
193 return -1; 192 return -1;
194 } 193 }
195 i = ASN1_TYPE_get_int_octetstring(type, &num, iv, l); 194 i = ASN1_TYPE_get_int_octetstring(type, &num, iv, l);
diff --git a/src/lib/libcrypto/evp/evp_aead.c b/src/lib/libcrypto/evp/evp_aead.c
index 197b7f515f..40471b0022 100644
--- a/src/lib/libcrypto/evp/evp_aead.c
+++ b/src/lib/libcrypto/evp/evp_aead.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_aead.c,v 1.5 2014/06/21 15:30:36 jsing Exp $ */ 1/* $OpenBSD: evp_aead.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -53,7 +53,7 @@ EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
53{ 53{
54 ctx->aead = aead; 54 ctx->aead = aead;
55 if (key_len != aead->key_len) { 55 if (key_len != aead->key_len) {
56 EVPerr(EVP_F_EVP_AEAD_CTX_INIT, EVP_R_UNSUPPORTED_KEY_SIZE); 56 EVPerror(EVP_R_UNSUPPORTED_KEY_SIZE);
57 return 0; 57 return 0;
58 } 58 }
59 return aead->init(ctx, key, key_len, tag_len); 59 return aead->init(ctx, key, key_len, tag_len);
@@ -96,12 +96,12 @@ EVP_AEAD_CTX_seal(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
96 96
97 /* Overflow. */ 97 /* Overflow. */
98 if (possible_out_len < in_len) { 98 if (possible_out_len < in_len) {
99 EVPerr(EVP_F_AEAD_CTX_SEAL, EVP_R_TOO_LARGE); 99 EVPerror(EVP_R_TOO_LARGE);
100 goto error; 100 goto error;
101 } 101 }
102 102
103 if (!check_alias(in, in_len, out)) { 103 if (!check_alias(in, in_len, out)) {
104 EVPerr(EVP_F_AEAD_CTX_SEAL, EVP_R_OUTPUT_ALIASES_INPUT); 104 EVPerror(EVP_R_OUTPUT_ALIASES_INPUT);
105 goto error; 105 goto error;
106 } 106 }
107 107
@@ -125,7 +125,7 @@ EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, unsigned char *out, size_t *out_len,
125 size_t ad_len) 125 size_t ad_len)
126{ 126{
127 if (!check_alias(in, in_len, out)) { 127 if (!check_alias(in, in_len, out)) {
128 EVPerr(EVP_F_AEAD_CTX_OPEN, EVP_R_OUTPUT_ALIASES_INPUT); 128 EVPerror(EVP_R_OUTPUT_ALIASES_INPUT);
129 goto error; 129 goto error;
130 } 130 }
131 131
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 0dfb7a5dc3..d0a5eb2d5f 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.35 2016/09/09 00:03:22 bcook Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.36 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -130,8 +130,7 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
130#ifndef OPENSSL_NO_ENGINE 130#ifndef OPENSSL_NO_ENGINE
131 if (impl) { 131 if (impl) {
132 if (!ENGINE_init(impl)) { 132 if (!ENGINE_init(impl)) {
133 EVPerr(EVP_F_EVP_CIPHERINIT_EX, 133 EVPerror(EVP_R_INITIALIZATION_ERROR);
134 EVP_R_INITIALIZATION_ERROR);
135 return 0; 134 return 0;
136 } 135 }
137 } else 136 } else
@@ -142,8 +141,7 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
142 const EVP_CIPHER *c = 141 const EVP_CIPHER *c =
143 ENGINE_get_cipher(impl, cipher->nid); 142 ENGINE_get_cipher(impl, cipher->nid);
144 if (!c) { 143 if (!c) {
145 EVPerr(EVP_F_EVP_CIPHERINIT_EX, 144 EVPerror(EVP_R_INITIALIZATION_ERROR);
146 EVP_R_INITIALIZATION_ERROR);
147 return 0; 145 return 0;
148 } 146 }
149 /* We'll use the ENGINE's private cipher definition */ 147 /* We'll use the ENGINE's private cipher definition */
@@ -160,8 +158,7 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
160 if (ctx->cipher->ctx_size) { 158 if (ctx->cipher->ctx_size) {
161 ctx->cipher_data = malloc(ctx->cipher->ctx_size); 159 ctx->cipher_data = malloc(ctx->cipher->ctx_size);
162 if (!ctx->cipher_data) { 160 if (!ctx->cipher_data) {
163 EVPerr(EVP_F_EVP_CIPHERINIT_EX, 161 EVPerror(ERR_R_MALLOC_FAILURE);
164 ERR_R_MALLOC_FAILURE);
165 return 0; 162 return 0;
166 } 163 }
167 } else { 164 } else {
@@ -171,13 +168,12 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
171 ctx->flags = 0; 168 ctx->flags = 0;
172 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) { 169 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
173 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) { 170 if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) {
174 EVPerr(EVP_F_EVP_CIPHERINIT_EX, 171 EVPerror(EVP_R_INITIALIZATION_ERROR);
175 EVP_R_INITIALIZATION_ERROR);
176 return 0; 172 return 0;
177 } 173 }
178 } 174 }
179 } else if (!ctx->cipher) { 175 } else if (!ctx->cipher) {
180 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET); 176 EVPerror(EVP_R_NO_CIPHER_SET);
181 return 0; 177 return 0;
182 } 178 }
183#ifndef OPENSSL_NO_ENGINE 179#ifndef OPENSSL_NO_ENGINE
@@ -187,7 +183,7 @@ skip_to_init:
187 if (ctx->cipher->block_size != 1 && 183 if (ctx->cipher->block_size != 1 &&
188 ctx->cipher->block_size != 8 && 184 ctx->cipher->block_size != 8 &&
189 ctx->cipher->block_size != 16) { 185 ctx->cipher->block_size != 16) {
190 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_BAD_BLOCK_LENGTH); 186 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
191 return 0; 187 return 0;
192 } 188 }
193 189
@@ -208,8 +204,7 @@ skip_to_init:
208 204
209 if ((size_t)EVP_CIPHER_CTX_iv_length(ctx) > 205 if ((size_t)EVP_CIPHER_CTX_iv_length(ctx) >
210 sizeof(ctx->iv)) { 206 sizeof(ctx->iv)) {
211 EVPerr(EVP_F_EVP_CIPHERINIT_EX, 207 EVPerror(EVP_R_IV_TOO_LARGE);
212 EVP_R_IV_TOO_LARGE);
213 return 0; 208 return 0;
214 } 209 }
215 if (iv) 210 if (iv)
@@ -336,7 +331,7 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
336 i = ctx->buf_len; 331 i = ctx->buf_len;
337 bl = ctx->cipher->block_size; 332 bl = ctx->cipher->block_size;
338 if ((size_t)bl > sizeof(ctx->buf)) { 333 if ((size_t)bl > sizeof(ctx->buf)) {
339 EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_BAD_BLOCK_LENGTH); 334 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
340 *outl = 0; 335 *outl = 0;
341 return 0; 336 return 0;
342 } 337 }
@@ -401,7 +396,7 @@ EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
401 396
402 b = ctx->cipher->block_size; 397 b = ctx->cipher->block_size;
403 if (b > sizeof ctx->buf) { 398 if (b > sizeof ctx->buf) {
404 EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX, EVP_R_BAD_BLOCK_LENGTH); 399 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
405 return 0; 400 return 0;
406 } 401 }
407 if (b == 1) { 402 if (b == 1) {
@@ -411,8 +406,7 @@ EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
411 bl = ctx->buf_len; 406 bl = ctx->buf_len;
412 if (ctx->flags & EVP_CIPH_NO_PADDING) { 407 if (ctx->flags & EVP_CIPH_NO_PADDING) {
413 if (bl) { 408 if (bl) {
414 EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX, 409 EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
415 EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
416 return 0; 410 return 0;
417 } 411 }
418 *outl = 0; 412 *outl = 0;
@@ -458,7 +452,7 @@ EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
458 452
459 b = ctx->cipher->block_size; 453 b = ctx->cipher->block_size;
460 if (b > sizeof ctx->final) { 454 if (b > sizeof ctx->final) {
461 EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_BAD_BLOCK_LENGTH); 455 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
462 return 0; 456 return 0;
463 } 457 }
464 458
@@ -519,8 +513,7 @@ EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
519 b = ctx->cipher->block_size; 513 b = ctx->cipher->block_size;
520 if (ctx->flags & EVP_CIPH_NO_PADDING) { 514 if (ctx->flags & EVP_CIPH_NO_PADDING) {
521 if (ctx->buf_len) { 515 if (ctx->buf_len) {
522 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, 516 EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
523 EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
524 return 0; 517 return 0;
525 } 518 }
526 *outl = 0; 519 *outl = 0;
@@ -528,24 +521,21 @@ EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
528 } 521 }
529 if (b > 1) { 522 if (b > 1) {
530 if (ctx->buf_len || !ctx->final_used) { 523 if (ctx->buf_len || !ctx->final_used) {
531 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, 524 EVPerror(EVP_R_WRONG_FINAL_BLOCK_LENGTH);
532 EVP_R_WRONG_FINAL_BLOCK_LENGTH);
533 return (0); 525 return (0);
534 } 526 }
535 if (b > sizeof ctx->final) { 527 if (b > sizeof ctx->final) {
536 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, 528 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
537 EVP_R_BAD_BLOCK_LENGTH);
538 return 0; 529 return 0;
539 } 530 }
540 n = ctx->final[b - 1]; 531 n = ctx->final[b - 1];
541 if (n == 0 || n > (int)b) { 532 if (n == 0 || n > (int)b) {
542 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT); 533 EVPerror(EVP_R_BAD_DECRYPT);
543 return (0); 534 return (0);
544 } 535 }
545 for (i = 0; i < n; i++) { 536 for (i = 0; i < n; i++) {
546 if (ctx->final[--b] != n) { 537 if (ctx->final[--b] != n) {
547 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, 538 EVPerror(EVP_R_BAD_DECRYPT);
548 EVP_R_BAD_DECRYPT);
549 return (0); 539 return (0);
550 } 540 }
551 } 541 }
@@ -600,7 +590,7 @@ EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
600 c->key_len = keylen; 590 c->key_len = keylen;
601 return 1; 591 return 1;
602 } 592 }
603 EVPerr(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH, EVP_R_INVALID_KEY_LENGTH); 593 EVPerror(EVP_R_INVALID_KEY_LENGTH);
604 return 0; 594 return 0;
605} 595}
606 596
@@ -620,19 +610,18 @@ EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
620 int ret; 610 int ret;
621 611
622 if (!ctx->cipher) { 612 if (!ctx->cipher) {
623 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET); 613 EVPerror(EVP_R_NO_CIPHER_SET);
624 return 0; 614 return 0;
625 } 615 }
626 616
627 if (!ctx->cipher->ctrl) { 617 if (!ctx->cipher->ctrl) {
628 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED); 618 EVPerror(EVP_R_CTRL_NOT_IMPLEMENTED);
629 return 0; 619 return 0;
630 } 620 }
631 621
632 ret = ctx->cipher->ctrl(ctx, type, arg, ptr); 622 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
633 if (ret == -1) { 623 if (ret == -1) {
634 EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, 624 EVPerror(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
635 EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED);
636 return 0; 625 return 0;
637 } 626 }
638 return ret; 627 return ret;
@@ -651,13 +640,13 @@ int
651EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) 640EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
652{ 641{
653 if ((in == NULL) || (in->cipher == NULL)) { 642 if ((in == NULL) || (in->cipher == NULL)) {
654 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, EVP_R_INPUT_NOT_INITIALIZED); 643 EVPerror(EVP_R_INPUT_NOT_INITIALIZED);
655 return 0; 644 return 0;
656 } 645 }
657#ifndef OPENSSL_NO_ENGINE 646#ifndef OPENSSL_NO_ENGINE
658 /* Make sure it's safe to copy a cipher context using an ENGINE */ 647 /* Make sure it's safe to copy a cipher context using an ENGINE */
659 if (in->engine && !ENGINE_init(in->engine)) { 648 if (in->engine && !ENGINE_init(in->engine)) {
660 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_ENGINE_LIB); 649 EVPerror(ERR_R_ENGINE_LIB);
661 return 0; 650 return 0;
662 } 651 }
663#endif 652#endif
@@ -668,7 +657,7 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
668 if (in->cipher_data && in->cipher->ctx_size) { 657 if (in->cipher_data && in->cipher->ctx_size) {
669 out->cipher_data = malloc(in->cipher->ctx_size); 658 out->cipher_data = malloc(in->cipher->ctx_size);
670 if (!out->cipher_data) { 659 if (!out->cipher_data) {
671 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_MALLOC_FAILURE); 660 EVPerror(ERR_R_MALLOC_FAILURE);
672 return 0; 661 return 0;
673 } 662 }
674 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size); 663 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
index dadd5365a0..1e1cc8350b 100644
--- a/src/lib/libcrypto/evp/evp_err.c
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_err.c,v 1.21 2015/02/15 14:35:30 miod Exp $ */ 1/* $OpenBSD: evp_err.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,102 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EVP,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_EVP,0,reason)
73 73
74static ERR_STRING_DATA EVP_str_functs[] = { 74static ERR_STRING_DATA EVP_str_functs[] = {
75 {ERR_FUNC(EVP_F_AEAD_AES_GCM_INIT), "AEAD_AES_GCM_INIT"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(EVP_F_AEAD_AES_GCM_OPEN), "AEAD_AES_GCM_OPEN"},
77 {ERR_FUNC(EVP_F_AEAD_AES_GCM_SEAL), "AEAD_AES_GCM_SEAL"},
78 {ERR_FUNC(EVP_F_AEAD_CHACHA20_POLY1305_INIT), "AEAD_CHACHA20_POLY1305_INIT"},
79 {ERR_FUNC(EVP_F_AEAD_CHACHA20_POLY1305_OPEN), "AEAD_CHACHA20_POLY1305_OPEN"},
80 {ERR_FUNC(EVP_F_AEAD_CHACHA20_POLY1305_SEAL), "AEAD_CHACHA20_POLY1305_SEAL"},
81 {ERR_FUNC(EVP_F_AEAD_CTX_OPEN), "AEAD_CTX_OPEN"},
82 {ERR_FUNC(EVP_F_AEAD_CTX_SEAL), "AEAD_CTX_SEAL"},
83 {ERR_FUNC(EVP_F_AESNI_INIT_KEY), "AESNI_INIT_KEY"},
84 {ERR_FUNC(EVP_F_AESNI_XTS_CIPHER), "AESNI_XTS_CIPHER"},
85 {ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
86 {ERR_FUNC(EVP_F_AES_XTS), "AES_XTS"},
87 {ERR_FUNC(EVP_F_AES_XTS_CIPHER), "AES_XTS_CIPHER"},
88 {ERR_FUNC(EVP_F_ALG_MODULE_INIT), "ALG_MODULE_INIT"},
89 {ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY), "CAMELLIA_INIT_KEY"},
90 {ERR_FUNC(EVP_F_CMAC_INIT), "CMAC_INIT"},
91 {ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"},
92 {ERR_FUNC(EVP_F_DO_SIGVER_INIT), "DO_SIGVER_INIT"},
93 {ERR_FUNC(EVP_F_DSAPKEY2PKCS8), "DSAPKEY2PKCS8"},
94 {ERR_FUNC(EVP_F_DSA_PKEY2PKCS8), "DSA_PKEY2PKCS8"},
95 {ERR_FUNC(EVP_F_ECDSA_PKEY2PKCS8), "ECDSA_PKEY2PKCS8"},
96 {ERR_FUNC(EVP_F_ECKEY_PKEY2PKCS8), "ECKEY_PKEY2PKCS8"},
97 {ERR_FUNC(EVP_F_EVP_AEAD_CTX_INIT), "EVP_AEAD_CTX_init"},
98 {ERR_FUNC(EVP_F_EVP_AEAD_CTX_OPEN), "EVP_AEAD_CTX_open"},
99 {ERR_FUNC(EVP_F_EVP_AEAD_CTX_SEAL), "EVP_AEAD_CTX_seal"},
100 {ERR_FUNC(EVP_F_EVP_BYTESTOKEY), "EVP_BytesToKey"},
101 {ERR_FUNC(EVP_F_EVP_CIPHERINIT_EX), "EVP_CipherInit_ex"},
102 {ERR_FUNC(EVP_F_EVP_CIPHER_CTX_COPY), "EVP_CIPHER_CTX_copy"},
103 {ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL), "EVP_CIPHER_CTX_ctrl"},
104 {ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH), "EVP_CIPHER_CTX_set_key_length"},
105 {ERR_FUNC(EVP_F_EVP_CIPHER_GET_ASN1_IV), "EVP_CIPHER_get_asn1_iv"},
106 {ERR_FUNC(EVP_F_EVP_CIPHER_SET_ASN1_IV), "EVP_CIPHER_set_asn1_iv"},
107 {ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX), "EVP_DecryptFinal_ex"},
108 {ERR_FUNC(EVP_F_EVP_DECRYPTUPDATE), "EVP_DecryptUpdate"},
109 {ERR_FUNC(EVP_F_EVP_DIGESTFINAL_EX), "EVP_DigestFinal_ex"},
110 {ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"},
111 {ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX), "EVP_EncryptFinal_ex"},
112 {ERR_FUNC(EVP_F_EVP_ENCRYPTUPDATE), "EVP_EncryptUpdate"},
113 {ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX), "EVP_MD_CTX_copy_ex"},
114 {ERR_FUNC(EVP_F_EVP_MD_CTX_CTRL), "EVP_MD_CTX_ctrl"},
115 {ERR_FUNC(EVP_F_EVP_MD_SIZE), "EVP_MD_size"},
116 {ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
117 {ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD), "EVP_PBE_alg_add"},
118 {ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD_TYPE), "EVP_PBE_alg_add_type"},
119 {ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT), "EVP_PBE_CipherInit"},
120 {ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"},
121 {ERR_FUNC(EVP_F_EVP_PKCS82PKEY_BROKEN), "EVP_PKCS82PKEY_BROKEN"},
122 {ERR_FUNC(EVP_F_EVP_PKEY2PKCS8_BROKEN), "EVP_PKEY2PKCS8_broken"},
123 {ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"},
124 {ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL), "EVP_PKEY_CTX_ctrl"},
125 {ERR_FUNC(EVP_F_EVP_PKEY_CTX_CTRL_STR), "EVP_PKEY_CTX_ctrl_str"},
126 {ERR_FUNC(EVP_F_EVP_PKEY_CTX_DUP), "EVP_PKEY_CTX_dup"},
127 {ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"},
128 {ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_INIT), "EVP_PKEY_decrypt_init"},
129 {ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT_OLD), "EVP_PKEY_decrypt_old"},
130 {ERR_FUNC(EVP_F_EVP_PKEY_DERIVE), "EVP_PKEY_derive"},
131 {ERR_FUNC(EVP_F_EVP_PKEY_DERIVE_INIT), "EVP_PKEY_derive_init"},
132 {ERR_FUNC(EVP_F_EVP_PKEY_DERIVE_SET_PEER), "EVP_PKEY_derive_set_peer"},
133 {ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT), "EVP_PKEY_encrypt"},
134 {ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT_INIT), "EVP_PKEY_encrypt_init"},
135 {ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT_OLD), "EVP_PKEY_encrypt_old"},
136 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH), "EVP_PKEY_get1_DH"},
137 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA), "EVP_PKEY_get1_DSA"},
138 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_ECDSA), "EVP_PKEY_GET1_ECDSA"},
139 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_EC_KEY), "EVP_PKEY_get1_EC_KEY"},
140 {ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA), "EVP_PKEY_get1_RSA"},
141 {ERR_FUNC(EVP_F_EVP_PKEY_KEYGEN), "EVP_PKEY_keygen"},
142 {ERR_FUNC(EVP_F_EVP_PKEY_KEYGEN_INIT), "EVP_PKEY_keygen_init"},
143 {ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"},
144 {ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN), "EVP_PKEY_paramgen"},
145 {ERR_FUNC(EVP_F_EVP_PKEY_PARAMGEN_INIT), "EVP_PKEY_paramgen_init"},
146 {ERR_FUNC(EVP_F_EVP_PKEY_SIGN), "EVP_PKEY_sign"},
147 {ERR_FUNC(EVP_F_EVP_PKEY_SIGN_INIT), "EVP_PKEY_sign_init"},
148 {ERR_FUNC(EVP_F_EVP_PKEY_VERIFY), "EVP_PKEY_verify"},
149 {ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_INIT), "EVP_PKEY_verify_init"},
150 {ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_RECOVER), "EVP_PKEY_verify_recover"},
151 {ERR_FUNC(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT), "EVP_PKEY_verify_recover_init"},
152 {ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"},
153 {ERR_FUNC(EVP_F_EVP_SIGNFINAL), "EVP_SignFinal"},
154 {ERR_FUNC(EVP_F_EVP_VERIFYFINAL), "EVP_VerifyFinal"},
155 {ERR_FUNC(EVP_F_FIPS_CIPHERINIT), "FIPS_CIPHERINIT"},
156 {ERR_FUNC(EVP_F_FIPS_CIPHER_CTX_COPY), "FIPS_CIPHER_CTX_COPY"},
157 {ERR_FUNC(EVP_F_FIPS_CIPHER_CTX_CTRL), "FIPS_CIPHER_CTX_CTRL"},
158 {ERR_FUNC(EVP_F_FIPS_CIPHER_CTX_SET_KEY_LENGTH), "FIPS_CIPHER_CTX_SET_KEY_LENGTH"},
159 {ERR_FUNC(EVP_F_FIPS_DIGESTINIT), "FIPS_DIGESTINIT"},
160 {ERR_FUNC(EVP_F_FIPS_MD_CTX_COPY), "FIPS_MD_CTX_COPY"},
161 {ERR_FUNC(EVP_F_HMAC_INIT_EX), "HMAC_Init_ex"},
162 {ERR_FUNC(EVP_F_INT_CTX_NEW), "INT_CTX_NEW"},
163 {ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN), "PKCS5_PBE_keyivgen"},
164 {ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN), "PKCS5_v2_PBE_keyivgen"},
165 {ERR_FUNC(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN), "PKCS5_V2_PBKDF2_KEYIVGEN"},
166 {ERR_FUNC(EVP_F_PKCS8_SET_BROKEN), "PKCS8_set_broken"},
167 {ERR_FUNC(EVP_F_PKEY_SET_TYPE), "PKEY_SET_TYPE"},
168 {ERR_FUNC(EVP_F_RC2_GET_ASN1_TYPE_AND_IV), "RC2_GET_ASN1_TYPE_AND_IV"},
169 {ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"},
170 {ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"},
171 {0, NULL} 76 {0, NULL}
172}; 77};
173 78
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
index 2c76743e42..33de513ef2 100644
--- a/src/lib/libcrypto/evp/evp_key.c
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_key.c,v 1.23 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: evp_key.c,v 1.24 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -135,11 +135,11 @@ EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
135 niv = type->iv_len; 135 niv = type->iv_len;
136 136
137 if ((size_t)nkey > EVP_MAX_KEY_LENGTH) { 137 if ((size_t)nkey > EVP_MAX_KEY_LENGTH) {
138 EVPerr(EVP_F_EVP_BYTESTOKEY, EVP_R_BAD_KEY_LENGTH); 138 EVPerror(EVP_R_BAD_KEY_LENGTH);
139 return 0; 139 return 0;
140 } 140 }
141 if ((size_t)niv > EVP_MAX_IV_LENGTH) { 141 if ((size_t)niv > EVP_MAX_IV_LENGTH) {
142 EVPerr(EVP_F_EVP_BYTESTOKEY, EVP_R_IV_TOO_LARGE); 142 EVPerror(EVP_R_IV_TOO_LARGE);
143 return 0; 143 return 0;
144 } 144 }
145 145
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index 491c8d6f67..ad97a3b7b9 100644
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_lib.c,v 1.14 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: evp_lib.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -100,8 +100,7 @@ EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
100 if (type != NULL) { 100 if (type != NULL) {
101 l = EVP_CIPHER_CTX_iv_length(c); 101 l = EVP_CIPHER_CTX_iv_length(c);
102 if (l > sizeof(c->iv)) { 102 if (l > sizeof(c->iv)) {
103 EVPerr(EVP_F_EVP_CIPHER_GET_ASN1_IV, 103 EVPerror(EVP_R_IV_TOO_LARGE);
104 EVP_R_IV_TOO_LARGE);
105 return 0; 104 return 0;
106 } 105 }
107 i = ASN1_TYPE_get_octetstring(type, c->oiv, l); 106 i = ASN1_TYPE_get_octetstring(type, c->oiv, l);
@@ -122,8 +121,7 @@ EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
122 if (type != NULL) { 121 if (type != NULL) {
123 j = EVP_CIPHER_CTX_iv_length(c); 122 j = EVP_CIPHER_CTX_iv_length(c);
124 if (j > sizeof(c->iv)) { 123 if (j > sizeof(c->iv)) {
125 EVPerr(EVP_F_EVP_CIPHER_SET_ASN1_IV, 124 EVPerror(EVP_R_IV_TOO_LARGE);
126 EVP_R_IV_TOO_LARGE);
127 return 0; 125 return 0;
128 } 126 }
129 i = ASN1_TYPE_set_octetstring(type, c->oiv, j); 127 i = ASN1_TYPE_set_octetstring(type, c->oiv, j);
@@ -291,7 +289,7 @@ int
291EVP_MD_size(const EVP_MD *md) 289EVP_MD_size(const EVP_MD *md)
292{ 290{
293 if (!md) { 291 if (!md) {
294 EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL); 292 EVPerror(EVP_R_MESSAGE_DIGEST_IS_NULL);
295 return -1; 293 return -1;
296 } 294 }
297 return md->md_size; 295 return md->md_size;
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
index c7f0c7749a..de08c8d78c 100644
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_pbe.c,v 1.24 2017/01/21 04:38:23 jsing Exp $ */ 1/* $OpenBSD: evp_pbe.c,v 1.25 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -128,7 +128,7 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
128 if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj), 128 if (!EVP_PBE_find(EVP_PBE_TYPE_OUTER, OBJ_obj2nid(pbe_obj),
129 &cipher_nid, &md_nid, &keygen)) { 129 &cipher_nid, &md_nid, &keygen)) {
130 char obj_tmp[80]; 130 char obj_tmp[80];
131 EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_PBE_ALGORITHM); 131 EVPerror(EVP_R_UNKNOWN_PBE_ALGORITHM);
132 if (!pbe_obj) 132 if (!pbe_obj)
133 strlcpy(obj_tmp, "NULL", sizeof obj_tmp); 133 strlcpy(obj_tmp, "NULL", sizeof obj_tmp);
134 else 134 else
@@ -147,7 +147,7 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
147 else { 147 else {
148 cipher = EVP_get_cipherbynid(cipher_nid); 148 cipher = EVP_get_cipherbynid(cipher_nid);
149 if (!cipher) { 149 if (!cipher) {
150 EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_CIPHER); 150 EVPerror(EVP_R_UNKNOWN_CIPHER);
151 return 0; 151 return 0;
152 } 152 }
153 } 153 }
@@ -157,13 +157,13 @@ EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
157 else { 157 else {
158 md = EVP_get_digestbynid(md_nid); 158 md = EVP_get_digestbynid(md_nid);
159 if (!md) { 159 if (!md) {
160 EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_DIGEST); 160 EVPerror(EVP_R_UNKNOWN_DIGEST);
161 return 0; 161 return 0;
162 } 162 }
163 } 163 }
164 164
165 if (!keygen(ctx, pass, passlen, param, cipher, md, en_de)) { 165 if (!keygen(ctx, pass, passlen, param, cipher, md, en_de)) {
166 EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_KEYGEN_FAILURE); 166 EVPerror(EVP_R_KEYGEN_FAILURE);
167 return 0; 167 return 0;
168 } 168 }
169 return 1; 169 return 1;
@@ -222,14 +222,13 @@ EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid,
222 if (pbe_algs == NULL) { 222 if (pbe_algs == NULL) {
223 pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); 223 pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp);
224 if (pbe_algs == NULL) { 224 if (pbe_algs == NULL) {
225 EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, 225 EVPerror(ERR_R_MALLOC_FAILURE);
226 ERR_R_MALLOC_FAILURE);
227 return 0; 226 return 0;
228 } 227 }
229 } 228 }
230 pbe_tmp = malloc(sizeof(EVP_PBE_CTL)); 229 pbe_tmp = malloc(sizeof(EVP_PBE_CTL));
231 if (pbe_tmp == NULL) { 230 if (pbe_tmp == NULL) {
232 EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE); 231 EVPerror(ERR_R_MALLOC_FAILURE);
233 return 0; 232 return 0;
234 } 233 }
235 pbe_tmp->pbe_type = pbe_type; 234 pbe_tmp->pbe_type = pbe_type;
@@ -240,7 +239,7 @@ EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid,
240 239
241 if (sk_EVP_PBE_CTL_push(pbe_algs, pbe_tmp) == 0) { 240 if (sk_EVP_PBE_CTL_push(pbe_algs, pbe_tmp) == 0) {
242 free(pbe_tmp); 241 free(pbe_tmp);
243 EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE, ERR_R_MALLOC_FAILURE); 242 EVPerror(ERR_R_MALLOC_FAILURE);
244 return 0; 243 return 0;
245 } 244 }
246 return 1; 245 return 1;
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
index 689ff596ce..4dcd2a15a9 100644
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_pkey.c,v 1.18 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: evp_pkey.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -77,13 +77,12 @@ EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
77 return NULL; 77 return NULL;
78 78
79 if (!(pkey = EVP_PKEY_new())) { 79 if (!(pkey = EVP_PKEY_new())) {
80 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_MALLOC_FAILURE); 80 EVPerror(ERR_R_MALLOC_FAILURE);
81 return NULL; 81 return NULL;
82 } 82 }
83 83
84 if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(algoid))) { 84 if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(algoid))) {
85 EVPerr(EVP_F_EVP_PKCS82PKEY, 85 EVPerror(EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
86 EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
87 i2t_ASN1_OBJECT(obj_tmp, 80, algoid); 86 i2t_ASN1_OBJECT(obj_tmp, 80, algoid);
88 ERR_asprintf_error_data("TYPE=%s", obj_tmp); 87 ERR_asprintf_error_data("TYPE=%s", obj_tmp);
89 goto error; 88 goto error;
@@ -91,12 +90,11 @@ EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
91 90
92 if (pkey->ameth->priv_decode) { 91 if (pkey->ameth->priv_decode) {
93 if (!pkey->ameth->priv_decode(pkey, p8)) { 92 if (!pkey->ameth->priv_decode(pkey, p8)) {
94 EVPerr(EVP_F_EVP_PKCS82PKEY, 93 EVPerror(EVP_R_PRIVATE_KEY_DECODE_ERROR);
95 EVP_R_PRIVATE_KEY_DECODE_ERROR);
96 goto error; 94 goto error;
97 } 95 }
98 } else { 96 } else {
99 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_METHOD_NOT_SUPPORTED); 97 EVPerror(EVP_R_METHOD_NOT_SUPPORTED);
100 goto error; 98 goto error;
101 } 99 }
102 100
@@ -121,7 +119,7 @@ EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
121 PKCS8_PRIV_KEY_INFO *p8; 119 PKCS8_PRIV_KEY_INFO *p8;
122 120
123 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { 121 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
124 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, ERR_R_MALLOC_FAILURE); 122 EVPerror(ERR_R_MALLOC_FAILURE);
125 return NULL; 123 return NULL;
126 } 124 }
127 p8->broken = broken; 125 p8->broken = broken;
@@ -129,18 +127,15 @@ EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
129 if (pkey->ameth) { 127 if (pkey->ameth) {
130 if (pkey->ameth->priv_encode) { 128 if (pkey->ameth->priv_encode) {
131 if (!pkey->ameth->priv_encode(p8, pkey)) { 129 if (!pkey->ameth->priv_encode(p8, pkey)) {
132 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, 130 EVPerror(EVP_R_PRIVATE_KEY_ENCODE_ERROR);
133 EVP_R_PRIVATE_KEY_ENCODE_ERROR);
134 goto error; 131 goto error;
135 } 132 }
136 } else { 133 } else {
137 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, 134 EVPerror(EVP_R_METHOD_NOT_SUPPORTED);
138 EVP_R_METHOD_NOT_SUPPORTED);
139 goto error; 135 goto error;
140 } 136 }
141 } else { 137 } else {
142 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, 138 EVPerror(EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
143 EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
144 goto error; 139 goto error;
145 } 140 }
146 return p8; 141 return p8;
@@ -166,7 +161,7 @@ PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
166 break; 161 break;
167 162
168 default: 163 default:
169 EVPerr(EVP_F_PKCS8_SET_BROKEN, EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE); 164 EVPerror(EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
170 return NULL; 165 return NULL;
171 } 166 }
172} 167}
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c
index 579325be67..6e955d9480 100644
--- a/src/lib/libcrypto/evp/m_sigver.c
+++ b/src/lib/libcrypto/evp/m_sigver.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: m_sigver.c,v 1.5 2015/12/14 03:37:27 beck Exp $ */ 1/* $OpenBSD: m_sigver.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -81,7 +81,7 @@ do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
81 } 81 }
82 82
83 if (type == NULL) { 83 if (type == NULL) {
84 EVPerr(EVP_F_DO_SIGVER_INIT, EVP_R_NO_DEFAULT_DIGEST); 84 EVPerror(EVP_R_NO_DEFAULT_DIGEST);
85 return 0; 85 return 0;
86 } 86 }
87 87
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
index 1d02cbf4a6..75a631bf98 100644
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt.c,v 1.17 2016/11/08 20:01:06 miod Exp $ */ 1/* $OpenBSD: p5_crpt.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -90,7 +90,7 @@ PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
90 /* Extract useful info from parameter */ 90 /* Extract useful info from parameter */
91 if (param == NULL || param->type != V_ASN1_SEQUENCE || 91 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
92 param->value.sequence == NULL) { 92 param->value.sequence == NULL) {
93 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_DECODE_ERROR); 93 EVPerror(EVP_R_DECODE_ERROR);
94 return 0; 94 return 0;
95 } 95 }
96 96
@@ -100,15 +100,14 @@ PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
100 100
101 pbuf = param->value.sequence->data; 101 pbuf = param->value.sequence->data;
102 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) { 102 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) {
103 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_DECODE_ERROR); 103 EVPerror(EVP_R_DECODE_ERROR);
104 return 0; 104 return 0;
105 } 105 }
106 106
107 if (!pbe->iter) 107 if (!pbe->iter)
108 iter = 1; 108 iter = 1;
109 else if ((iter = ASN1_INTEGER_get(pbe->iter)) <= 0) { 109 else if ((iter = ASN1_INTEGER_get(pbe->iter)) <= 0) {
110 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, 110 EVPerror(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
111 EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
112 return 0; 111 return 0;
113 } 112 }
114 salt = pbe->salt->data; 113 salt = pbe->salt->data;
@@ -138,12 +137,12 @@ PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
138 goto err; 137 goto err;
139 } 138 }
140 if ((size_t)EVP_CIPHER_key_length(cipher) > sizeof(md_tmp)) { 139 if ((size_t)EVP_CIPHER_key_length(cipher) > sizeof(md_tmp)) {
141 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_BAD_KEY_LENGTH); 140 EVPerror(EVP_R_BAD_KEY_LENGTH);
142 goto err; 141 goto err;
143 } 142 }
144 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); 143 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
145 if ((size_t)EVP_CIPHER_iv_length(cipher) > 16) { 144 if ((size_t)EVP_CIPHER_iv_length(cipher) > 16) {
146 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_IV_TOO_LARGE); 145 EVPerror(EVP_R_IV_TOO_LARGE);
147 goto err; 146 goto err;
148 } 147 }
149 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), 148 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
index 44e8b331fb..4bef287706 100644
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt2.c,v 1.22 2016/11/08 20:01:06 miod Exp $ */ 1/* $OpenBSD: p5_crpt2.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -175,22 +175,21 @@ PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
175 175
176 if (param == NULL || param->type != V_ASN1_SEQUENCE || 176 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
177 param->value.sequence == NULL) { 177 param->value.sequence == NULL) {
178 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_DECODE_ERROR); 178 EVPerror(EVP_R_DECODE_ERROR);
179 goto err; 179 goto err;
180 } 180 }
181 181
182 pbuf = param->value.sequence->data; 182 pbuf = param->value.sequence->data;
183 plen = param->value.sequence->length; 183 plen = param->value.sequence->length;
184 if (!(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) { 184 if (!(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
185 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_DECODE_ERROR); 185 EVPerror(EVP_R_DECODE_ERROR);
186 goto err; 186 goto err;
187 } 187 }
188 188
189 /* See if we recognise the key derivation function */ 189 /* See if we recognise the key derivation function */
190 190
191 if (OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) { 191 if (OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
192 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, 192 EVPerror(EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
193 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
194 goto err; 193 goto err;
195 } 194 }
196 195
@@ -200,8 +199,7 @@ PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
200 cipher = EVP_get_cipherbyobj(pbe2->encryption->algorithm); 199 cipher = EVP_get_cipherbyobj(pbe2->encryption->algorithm);
201 200
202 if (!cipher) { 201 if (!cipher) {
203 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, 202 EVPerror(EVP_R_UNSUPPORTED_CIPHER);
204 EVP_R_UNSUPPORTED_CIPHER);
205 goto err; 203 goto err;
206 } 204 }
207 205
@@ -209,8 +207,7 @@ PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
209 if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de)) 207 if (!EVP_CipherInit_ex(ctx, cipher, NULL, NULL, NULL, en_de))
210 goto err; 208 goto err;
211 if (EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) { 209 if (EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
212 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, 210 EVPerror(EVP_R_CIPHER_PARAMETER_ERROR);
213 EVP_R_CIPHER_PARAMETER_ERROR);
214 goto err; 211 goto err;
215 } 212 }
216 rv = PKCS5_v2_PBKDF2_keyivgen(ctx, pass, passlen, 213 rv = PKCS5_v2_PBKDF2_keyivgen(ctx, pass, passlen,
@@ -235,19 +232,19 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
235 const EVP_MD *prfmd; 232 const EVP_MD *prfmd;
236 233
237 if (EVP_CIPHER_CTX_cipher(ctx) == NULL) { 234 if (EVP_CIPHER_CTX_cipher(ctx) == NULL) {
238 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_NO_CIPHER_SET); 235 EVPerror(EVP_R_NO_CIPHER_SET);
239 return 0; 236 return 0;
240 } 237 }
241 keylen = EVP_CIPHER_CTX_key_length(ctx); 238 keylen = EVP_CIPHER_CTX_key_length(ctx);
242 if (keylen > sizeof key) { 239 if (keylen > sizeof key) {
243 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_BAD_KEY_LENGTH); 240 EVPerror(EVP_R_BAD_KEY_LENGTH);
244 return 0; 241 return 0;
245 } 242 }
246 243
247 /* Decode parameter */ 244 /* Decode parameter */
248 245
249 if (!param || (param->type != V_ASN1_SEQUENCE)) { 246 if (!param || (param->type != V_ASN1_SEQUENCE)) {
250 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR); 247 EVPerror(EVP_R_DECODE_ERROR);
251 return 0; 248 return 0;
252 } 249 }
253 250
@@ -255,7 +252,7 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
255 plen = param->value.sequence->length; 252 plen = param->value.sequence->length;
256 253
257 if (!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) { 254 if (!(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
258 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR); 255 EVPerror(EVP_R_DECODE_ERROR);
259 return 0; 256 return 0;
260 } 257 }
261 258
@@ -263,8 +260,7 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
263 260
264 if (kdf->keylength && 261 if (kdf->keylength &&
265 (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)){ 262 (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)){
266 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, 263 EVPerror(EVP_R_UNSUPPORTED_KEYLENGTH);
267 EVP_R_UNSUPPORTED_KEYLENGTH);
268 goto err; 264 goto err;
269 } 265 }
270 266
@@ -274,19 +270,18 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
274 prf_nid = NID_hmacWithSHA1; 270 prf_nid = NID_hmacWithSHA1;
275 271
276 if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, prf_nid, NULL, &hmac_md_nid, 0)) { 272 if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, prf_nid, NULL, &hmac_md_nid, 0)) {
277 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF); 273 EVPerror(EVP_R_UNSUPPORTED_PRF);
278 goto err; 274 goto err;
279 } 275 }
280 276
281 prfmd = EVP_get_digestbynid(hmac_md_nid); 277 prfmd = EVP_get_digestbynid(hmac_md_nid);
282 if (prfmd == NULL) { 278 if (prfmd == NULL) {
283 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF); 279 EVPerror(EVP_R_UNSUPPORTED_PRF);
284 goto err; 280 goto err;
285 } 281 }
286 282
287 if (kdf->salt->type != V_ASN1_OCTET_STRING) { 283 if (kdf->salt->type != V_ASN1_OCTET_STRING) {
288 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, 284 EVPerror(EVP_R_UNSUPPORTED_SALT_TYPE);
289 EVP_R_UNSUPPORTED_SALT_TYPE);
290 goto err; 285 goto err;
291 } 286 }
292 287
@@ -294,8 +289,7 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
294 salt = kdf->salt->value.octet_string->data; 289 salt = kdf->salt->value.octet_string->data;
295 saltlen = kdf->salt->value.octet_string->length; 290 saltlen = kdf->salt->value.octet_string->length;
296 if ((iter = ASN1_INTEGER_get(kdf->iter)) <= 0) { 291 if ((iter = ASN1_INTEGER_get(kdf->iter)) <= 0) {
297 EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, 292 EVPerror(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
298 EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
299 goto err; 293 goto err;
300 } 294 }
301 if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd, 295 if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd,
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
index 2244ae8c62..c827c5e4c2 100644
--- a/src/lib/libcrypto/evp/p_dec.c
+++ b/src/lib/libcrypto/evp/p_dec.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_dec.c,v 1.10 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: p_dec.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -78,7 +78,7 @@ EVP_PKEY_decrypt_old(unsigned char *key, const unsigned char *ek, int ekl,
78#ifndef OPENSSL_NO_RSA 78#ifndef OPENSSL_NO_RSA
79 if (priv->type != EVP_PKEY_RSA) { 79 if (priv->type != EVP_PKEY_RSA) {
80#endif 80#endif
81 EVPerr(EVP_F_EVP_PKEY_DECRYPT_OLD, EVP_R_PUBLIC_KEY_NOT_RSA); 81 EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA);
82#ifndef OPENSSL_NO_RSA 82#ifndef OPENSSL_NO_RSA
83 goto err; 83 goto err;
84 } 84 }
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
index 63d2649f6e..49c46f1a70 100644
--- a/src/lib/libcrypto/evp/p_enc.c
+++ b/src/lib/libcrypto/evp/p_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_enc.c,v 1.10 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: p_enc.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -78,7 +78,7 @@ EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key, int key_len,
78#ifndef OPENSSL_NO_RSA 78#ifndef OPENSSL_NO_RSA
79 if (pubk->type != EVP_PKEY_RSA) { 79 if (pubk->type != EVP_PKEY_RSA) {
80#endif 80#endif
81 EVPerr(EVP_F_EVP_PKEY_ENCRYPT_OLD, EVP_R_PUBLIC_KEY_NOT_RSA); 81 EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA);
82#ifndef OPENSSL_NO_RSA 82#ifndef OPENSSL_NO_RSA
83 goto err; 83 goto err;
84 } 84 }
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index e172c34894..0d4cd26d45 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_lib.c,v 1.16 2014/07/12 22:26:01 miod Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -128,14 +128,12 @@ int
128EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) 128EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
129{ 129{
130 if (to->type != from->type) { 130 if (to->type != from->type) {
131 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, 131 EVPerror(EVP_R_DIFFERENT_KEY_TYPES);
132 EVP_R_DIFFERENT_KEY_TYPES);
133 goto err; 132 goto err;
134 } 133 }
135 134
136 if (EVP_PKEY_missing_parameters(from)) { 135 if (EVP_PKEY_missing_parameters(from)) {
137 EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, 136 EVPerror(EVP_R_MISSING_PARAMETERS);
138 EVP_R_MISSING_PARAMETERS);
139 goto err; 137 goto err;
140 } 138 }
141 if (from->ameth && from->ameth->param_copy) 139 if (from->ameth && from->ameth->param_copy)
@@ -192,7 +190,7 @@ EVP_PKEY_new(void)
192 190
193 ret = malloc(sizeof(EVP_PKEY)); 191 ret = malloc(sizeof(EVP_PKEY));
194 if (ret == NULL) { 192 if (ret == NULL) {
195 EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); 193 EVPerror(ERR_R_MALLOC_FAILURE);
196 return (NULL); 194 return (NULL);
197 } 195 }
198 ret->type = EVP_PKEY_NONE; 196 ret->type = EVP_PKEY_NONE;
@@ -240,7 +238,7 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
240 ENGINE_finish(e); 238 ENGINE_finish(e);
241#endif 239#endif
242 if (!ameth) { 240 if (!ameth) {
243 EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_UNSUPPORTED_ALGORITHM); 241 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
244 return 0; 242 return 0;
245 } 243 }
246 if (pkey) { 244 if (pkey) {
@@ -294,7 +292,7 @@ RSA *
294EVP_PKEY_get1_RSA(EVP_PKEY *pkey) 292EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
295{ 293{
296 if (pkey->type != EVP_PKEY_RSA) { 294 if (pkey->type != EVP_PKEY_RSA) {
297 EVPerr(EVP_F_EVP_PKEY_GET1_RSA, EVP_R_EXPECTING_AN_RSA_KEY); 295 EVPerror(EVP_R_EXPECTING_AN_RSA_KEY);
298 return NULL; 296 return NULL;
299 } 297 }
300 RSA_up_ref(pkey->pkey.rsa); 298 RSA_up_ref(pkey->pkey.rsa);
@@ -316,7 +314,7 @@ DSA *
316EVP_PKEY_get1_DSA(EVP_PKEY *pkey) 314EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
317{ 315{
318 if (pkey->type != EVP_PKEY_DSA) { 316 if (pkey->type != EVP_PKEY_DSA) {
319 EVPerr(EVP_F_EVP_PKEY_GET1_DSA, EVP_R_EXPECTING_A_DSA_KEY); 317 EVPerror(EVP_R_EXPECTING_A_DSA_KEY);
320 return NULL; 318 return NULL;
321 } 319 }
322 DSA_up_ref(pkey->pkey.dsa); 320 DSA_up_ref(pkey->pkey.dsa);
@@ -339,7 +337,7 @@ EC_KEY *
339EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey) 337EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
340{ 338{
341 if (pkey->type != EVP_PKEY_EC) { 339 if (pkey->type != EVP_PKEY_EC) {
342 EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY); 340 EVPerror(EVP_R_EXPECTING_A_EC_KEY);
343 return NULL; 341 return NULL;
344 } 342 }
345 EC_KEY_up_ref(pkey->pkey.ec); 343 EC_KEY_up_ref(pkey->pkey.ec);
@@ -363,7 +361,7 @@ DH *
363EVP_PKEY_get1_DH(EVP_PKEY *pkey) 361EVP_PKEY_get1_DH(EVP_PKEY *pkey)
364{ 362{
365 if (pkey->type != EVP_PKEY_DH) { 363 if (pkey->type != EVP_PKEY_DH) {
366 EVPerr(EVP_F_EVP_PKEY_GET1_DH, EVP_R_EXPECTING_A_DH_KEY); 364 EVPerror(EVP_R_EXPECTING_A_DH_KEY);
367 return NULL; 365 return NULL;
368 } 366 }
369 DH_up_ref(pkey->pkey.dh); 367 DH_up_ref(pkey->pkey.dh);
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index 002a6dea70..1eb238dfde 100644
--- a/src/lib/libcrypto/evp/p_open.c
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_open.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: p_open.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -86,7 +86,7 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
86 return 1; 86 return 1;
87 87
88 if (priv->type != EVP_PKEY_RSA) { 88 if (priv->type != EVP_PKEY_RSA) {
89 EVPerr(EVP_F_EVP_OPENINIT, EVP_R_PUBLIC_KEY_NOT_RSA); 89 EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA);
90 goto err; 90 goto err;
91 } 91 }
92 92
@@ -94,7 +94,7 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
94 key = malloc(size + 2); 94 key = malloc(size + 2);
95 if (key == NULL) { 95 if (key == NULL) {
96 /* ERROR */ 96 /* ERROR */
97 EVPerr(EVP_F_EVP_OPENINIT, ERR_R_MALLOC_FAILURE); 97 EVPerror(ERR_R_MALLOC_FAILURE);
98 goto err; 98 goto err;
99 } 99 }
100 100
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c
index 4058d47f07..6312924518 100644
--- a/src/lib/libcrypto/evp/p_sign.c
+++ b/src/lib/libcrypto/evp/p_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_sign.c,v 1.13 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: p_sign.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,12 +110,12 @@ err:
110 } 110 }
111 } 111 }
112 if (!ok) { 112 if (!ok) {
113 EVPerr(EVP_F_EVP_SIGNFINAL, EVP_R_WRONG_PUBLIC_KEY_TYPE); 113 EVPerror(EVP_R_WRONG_PUBLIC_KEY_TYPE);
114 return (0); 114 return (0);
115 } 115 }
116 116
117 if (ctx->digest->sign == NULL) { 117 if (ctx->digest->sign == NULL) {
118 EVPerr(EVP_F_EVP_SIGNFINAL, EVP_R_NO_SIGN_FUNCTION_CONFIGURED); 118 EVPerror(EVP_R_NO_SIGN_FUNCTION_CONFIGURED);
119 return (0); 119 return (0);
120 } 120 }
121 return(ctx->digest->sign(ctx->digest->type, m, m_len, sigret, siglen, 121 return(ctx->digest->sign(ctx->digest->type, m, m_len, sigret, siglen,
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
index e653fcf6a5..7dd752c4fb 100644
--- a/src/lib/libcrypto/evp/p_verify.c
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_verify.c,v 1.12 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: p_verify.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -105,12 +105,11 @@ err:
105 } 105 }
106 } 106 }
107 if (!ok) { 107 if (!ok) {
108 EVPerr(EVP_F_EVP_VERIFYFINAL, EVP_R_WRONG_PUBLIC_KEY_TYPE); 108 EVPerror(EVP_R_WRONG_PUBLIC_KEY_TYPE);
109 return (-1); 109 return (-1);
110 } 110 }
111 if (ctx->digest->verify == NULL) { 111 if (ctx->digest->verify == NULL) {
112 EVPerr(EVP_F_EVP_VERIFYFINAL, 112 EVPerror(EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
113 EVP_R_NO_VERIFY_FUNCTION_CONFIGURED);
114 return (0); 113 return (0);
115 } 114 }
116 115
diff --git a/src/lib/libcrypto/evp/pmeth_fn.c b/src/lib/libcrypto/evp/pmeth_fn.c
index 4cf18a0be1..c9117eedd4 100644
--- a/src/lib/libcrypto/evp/pmeth_fn.c
+++ b/src/lib/libcrypto/evp/pmeth_fn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_fn.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */ 1/* $OpenBSD: pmeth_fn.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -76,7 +76,7 @@
76 } \ 76 } \
77 else if (*arglen < pksize) \ 77 else if (*arglen < pksize) \
78 { \ 78 { \
79 EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\ 79 EVPerror(EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/\
80 return 0; \ 80 return 0; \
81 } \ 81 } \
82 } 82 }
@@ -87,8 +87,7 @@ EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx)
87 int ret; 87 int ret;
88 88
89 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { 89 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) {
90 EVPerr(EVP_F_EVP_PKEY_SIGN_INIT, 90 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
91 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
92 return -2; 91 return -2;
93 } 92 }
94 ctx->operation = EVP_PKEY_OP_SIGN; 93 ctx->operation = EVP_PKEY_OP_SIGN;
@@ -105,12 +104,11 @@ EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
105 const unsigned char *tbs, size_t tbslen) 104 const unsigned char *tbs, size_t tbslen)
106{ 105{
107 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) { 106 if (!ctx || !ctx->pmeth || !ctx->pmeth->sign) {
108 EVPerr(EVP_F_EVP_PKEY_SIGN, 107 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
109 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
110 return -2; 108 return -2;
111 } 109 }
112 if (ctx->operation != EVP_PKEY_OP_SIGN) { 110 if (ctx->operation != EVP_PKEY_OP_SIGN) {
113 EVPerr(EVP_F_EVP_PKEY_SIGN, EVP_R_OPERATON_NOT_INITIALIZED); 111 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
114 return -1; 112 return -1;
115 } 113 }
116 M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN) 114 M_check_autoarg(ctx, sig, siglen, EVP_F_EVP_PKEY_SIGN)
@@ -123,8 +121,7 @@ EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx)
123 int ret; 121 int ret;
124 122
125 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { 123 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) {
126 EVPerr(EVP_F_EVP_PKEY_VERIFY_INIT, 124 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
127 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
128 return -2; 125 return -2;
129 } 126 }
130 ctx->operation = EVP_PKEY_OP_VERIFY; 127 ctx->operation = EVP_PKEY_OP_VERIFY;
@@ -141,12 +138,11 @@ EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
141 const unsigned char *tbs, size_t tbslen) 138 const unsigned char *tbs, size_t tbslen)
142{ 139{
143 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) { 140 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify) {
144 EVPerr(EVP_F_EVP_PKEY_VERIFY, 141 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
145 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
146 return -2; 142 return -2;
147 } 143 }
148 if (ctx->operation != EVP_PKEY_OP_VERIFY) { 144 if (ctx->operation != EVP_PKEY_OP_VERIFY) {
149 EVPerr(EVP_F_EVP_PKEY_VERIFY, EVP_R_OPERATON_NOT_INITIALIZED); 145 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
150 return -1; 146 return -1;
151 } 147 }
152 return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen); 148 return ctx->pmeth->verify(ctx, sig, siglen, tbs, tbslen);
@@ -158,8 +154,7 @@ EVP_PKEY_verify_recover_init(EVP_PKEY_CTX *ctx)
158 int ret; 154 int ret;
159 155
160 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { 156 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) {
161 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER_INIT, 157 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
162 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
163 return -2; 158 return -2;
164 } 159 }
165 ctx->operation = EVP_PKEY_OP_VERIFYRECOVER; 160 ctx->operation = EVP_PKEY_OP_VERIFYRECOVER;
@@ -176,13 +171,11 @@ EVP_PKEY_verify_recover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen,
176 const unsigned char *sig, size_t siglen) 171 const unsigned char *sig, size_t siglen)
177{ 172{
178 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) { 173 if (!ctx || !ctx->pmeth || !ctx->pmeth->verify_recover) {
179 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, 174 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
180 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
181 return -2; 175 return -2;
182 } 176 }
183 if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) { 177 if (ctx->operation != EVP_PKEY_OP_VERIFYRECOVER) {
184 EVPerr(EVP_F_EVP_PKEY_VERIFY_RECOVER, 178 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
185 EVP_R_OPERATON_NOT_INITIALIZED);
186 return -1; 179 return -1;
187 } 180 }
188 M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER) 181 M_check_autoarg(ctx, rout, routlen, EVP_F_EVP_PKEY_VERIFY_RECOVER)
@@ -195,8 +188,7 @@ EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
195 int ret; 188 int ret;
196 189
197 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { 190 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) {
198 EVPerr(EVP_F_EVP_PKEY_ENCRYPT_INIT, 191 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
199 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
200 return -2; 192 return -2;
201 } 193 }
202 ctx->operation = EVP_PKEY_OP_ENCRYPT; 194 ctx->operation = EVP_PKEY_OP_ENCRYPT;
@@ -213,12 +205,11 @@ EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
213 const unsigned char *in, size_t inlen) 205 const unsigned char *in, size_t inlen)
214{ 206{
215 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) { 207 if (!ctx || !ctx->pmeth || !ctx->pmeth->encrypt) {
216 EVPerr(EVP_F_EVP_PKEY_ENCRYPT, 208 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
217 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
218 return -2; 209 return -2;
219 } 210 }
220 if (ctx->operation != EVP_PKEY_OP_ENCRYPT) { 211 if (ctx->operation != EVP_PKEY_OP_ENCRYPT) {
221 EVPerr(EVP_F_EVP_PKEY_ENCRYPT, EVP_R_OPERATON_NOT_INITIALIZED); 212 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
222 return -1; 213 return -1;
223 } 214 }
224 M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT) 215 M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_ENCRYPT)
@@ -231,8 +222,7 @@ EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
231 int ret; 222 int ret;
232 223
233 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { 224 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) {
234 EVPerr(EVP_F_EVP_PKEY_DECRYPT_INIT, 225 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
235 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
236 return -2; 226 return -2;
237 } 227 }
238 ctx->operation = EVP_PKEY_OP_DECRYPT; 228 ctx->operation = EVP_PKEY_OP_DECRYPT;
@@ -249,12 +239,11 @@ EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
249 const unsigned char *in, size_t inlen) 239 const unsigned char *in, size_t inlen)
250{ 240{
251 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) { 241 if (!ctx || !ctx->pmeth || !ctx->pmeth->decrypt) {
252 EVPerr(EVP_F_EVP_PKEY_DECRYPT, 242 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
253 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
254 return -2; 243 return -2;
255 } 244 }
256 if (ctx->operation != EVP_PKEY_OP_DECRYPT) { 245 if (ctx->operation != EVP_PKEY_OP_DECRYPT) {
257 EVPerr(EVP_F_EVP_PKEY_DECRYPT, EVP_R_OPERATON_NOT_INITIALIZED); 246 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
258 return -1; 247 return -1;
259 } 248 }
260 M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT) 249 M_check_autoarg(ctx, out, outlen, EVP_F_EVP_PKEY_DECRYPT)
@@ -267,8 +256,7 @@ EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)
267 int ret; 256 int ret;
268 257
269 if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { 258 if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) {
270 EVPerr(EVP_F_EVP_PKEY_DERIVE_INIT, 259 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
271 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
272 return -2; 260 return -2;
273 } 261 }
274 ctx->operation = EVP_PKEY_OP_DERIVE; 262 ctx->operation = EVP_PKEY_OP_DERIVE;
@@ -288,15 +276,13 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
288 if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive || 276 if (!ctx || !ctx->pmeth || !(ctx->pmeth->derive ||
289 ctx->pmeth->encrypt || ctx->pmeth->decrypt) || 277 ctx->pmeth->encrypt || ctx->pmeth->decrypt) ||
290 !ctx->pmeth->ctrl) { 278 !ctx->pmeth->ctrl) {
291 EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, 279 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
292 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
293 return -2; 280 return -2;
294 } 281 }
295 if (ctx->operation != EVP_PKEY_OP_DERIVE && 282 if (ctx->operation != EVP_PKEY_OP_DERIVE &&
296 ctx->operation != EVP_PKEY_OP_ENCRYPT && 283 ctx->operation != EVP_PKEY_OP_ENCRYPT &&
297 ctx->operation != EVP_PKEY_OP_DECRYPT) { 284 ctx->operation != EVP_PKEY_OP_DECRYPT) {
298 EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, 285 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
299 EVP_R_OPERATON_NOT_INITIALIZED);
300 return -1; 286 return -1;
301 } 287 }
302 288
@@ -309,13 +295,12 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
309 return 1; 295 return 1;
310 296
311 if (!ctx->pkey) { 297 if (!ctx->pkey) {
312 EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, EVP_R_NO_KEY_SET); 298 EVPerror(EVP_R_NO_KEY_SET);
313 return -1; 299 return -1;
314 } 300 }
315 301
316 if (ctx->pkey->type != peer->type) { 302 if (ctx->pkey->type != peer->type) {
317 EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, 303 EVPerror(EVP_R_DIFFERENT_KEY_TYPES);
318 EVP_R_DIFFERENT_KEY_TYPES);
319 return -1; 304 return -1;
320 } 305 }
321 306
@@ -326,8 +311,7 @@ EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
326 * -2 is OK for us here, as well as 1, so we can check for 0 only. */ 311 * -2 is OK for us here, as well as 1, so we can check for 0 only. */
327 if (!EVP_PKEY_missing_parameters(peer) && 312 if (!EVP_PKEY_missing_parameters(peer) &&
328 !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) { 313 !EVP_PKEY_cmp_parameters(ctx->pkey, peer)) {
329 EVPerr(EVP_F_EVP_PKEY_DERIVE_SET_PEER, 314 EVPerror(EVP_R_DIFFERENT_PARAMETERS);
330 EVP_R_DIFFERENT_PARAMETERS);
331 return -1; 315 return -1;
332 } 316 }
333 317
@@ -349,12 +333,11 @@ int
349EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen) 333EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *pkeylen)
350{ 334{
351 if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) { 335 if (!ctx || !ctx->pmeth || !ctx->pmeth->derive) {
352 EVPerr(EVP_F_EVP_PKEY_DERIVE, 336 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
353 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
354 return -2; 337 return -2;
355 } 338 }
356 if (ctx->operation != EVP_PKEY_OP_DERIVE) { 339 if (ctx->operation != EVP_PKEY_OP_DERIVE) {
357 EVPerr(EVP_F_EVP_PKEY_DERIVE, EVP_R_OPERATON_NOT_INITIALIZED); 340 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
358 return -1; 341 return -1;
359 } 342 }
360 M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE) 343 M_check_autoarg(ctx, key, pkeylen, EVP_F_EVP_PKEY_DERIVE)
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index 29f533625a..d1cbdc409f 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.5 2014/07/12 16:03:37 miod Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -72,8 +72,7 @@ EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)
72 int ret; 72 int ret;
73 73
74 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) { 74 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
75 EVPerr(EVP_F_EVP_PKEY_PARAMGEN_INIT, 75 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
76 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
77 return -2; 76 return -2;
78 } 77 }
79 ctx->operation = EVP_PKEY_OP_PARAMGEN; 78 ctx->operation = EVP_PKEY_OP_PARAMGEN;
@@ -91,13 +90,12 @@ EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
91 int ret; 90 int ret;
92 91
93 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) { 92 if (!ctx || !ctx->pmeth || !ctx->pmeth->paramgen) {
94 EVPerr(EVP_F_EVP_PKEY_PARAMGEN, 93 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
95 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
96 return -2; 94 return -2;
97 } 95 }
98 96
99 if (ctx->operation != EVP_PKEY_OP_PARAMGEN) { 97 if (ctx->operation != EVP_PKEY_OP_PARAMGEN) {
100 EVPerr(EVP_F_EVP_PKEY_PARAMGEN, EVP_R_OPERATON_NOT_INITIALIZED); 98 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
101 return -1; 99 return -1;
102 } 100 }
103 101
@@ -121,8 +119,7 @@ EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx)
121 int ret; 119 int ret;
122 120
123 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) { 121 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
124 EVPerr(EVP_F_EVP_PKEY_KEYGEN_INIT, 122 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
125 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
126 return -2; 123 return -2;
127 } 124 }
128 ctx->operation = EVP_PKEY_OP_KEYGEN; 125 ctx->operation = EVP_PKEY_OP_KEYGEN;
@@ -140,12 +137,11 @@ EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
140 int ret; 137 int ret;
141 138
142 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) { 139 if (!ctx || !ctx->pmeth || !ctx->pmeth->keygen) {
143 EVPerr(EVP_F_EVP_PKEY_KEYGEN, 140 EVPerror(EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
144 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
145 return -2; 141 return -2;
146 } 142 }
147 if (ctx->operation != EVP_PKEY_OP_KEYGEN) { 143 if (ctx->operation != EVP_PKEY_OP_KEYGEN) {
148 EVPerr(EVP_F_EVP_PKEY_KEYGEN, EVP_R_OPERATON_NOT_INITIALIZED); 144 EVPerror(EVP_R_OPERATON_NOT_INITIALIZED);
149 return -1; 145 return -1;
150 } 146 }
151 147
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index 1d64edcbeb..fc5f4ef91e 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_lib.c,v 1.12 2017/01/21 04:38:23 jsing Exp $ */ 1/* $OpenBSD: pmeth_lib.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -166,7 +166,7 @@ int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
166 /* Try to find an ENGINE which implements this method */ 166 /* Try to find an ENGINE which implements this method */
167 if (e) { 167 if (e) {
168 if (!ENGINE_init(e)) { 168 if (!ENGINE_init(e)) {
169 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB); 169 EVPerror(ERR_R_ENGINE_LIB);
170 return NULL; 170 return NULL;
171 } 171 }
172 } else 172 } else
@@ -183,7 +183,7 @@ int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
183 pmeth = EVP_PKEY_meth_find(id); 183 pmeth = EVP_PKEY_meth_find(id);
184 184
185 if (pmeth == NULL) { 185 if (pmeth == NULL) {
186 EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM); 186 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
187 return NULL; 187 return NULL;
188 } 188 }
189 189
@@ -193,7 +193,7 @@ int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
193 if (e) 193 if (e)
194 ENGINE_finish(e); 194 ENGINE_finish(e);
195#endif 195#endif
196 EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE); 196 EVPerror(ERR_R_MALLOC_FAILURE);
197 return NULL; 197 return NULL;
198 } 198 }
199 ret->engine = e; 199 ret->engine = e;
@@ -336,7 +336,7 @@ EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
336#ifndef OPENSSL_NO_ENGINE 336#ifndef OPENSSL_NO_ENGINE
337 /* Make sure it's safe to copy a pkey context using an ENGINE */ 337 /* Make sure it's safe to copy a pkey context using an ENGINE */
338 if (pctx->engine && !ENGINE_init(pctx->engine)) { 338 if (pctx->engine && !ENGINE_init(pctx->engine)) {
339 EVPerr(EVP_F_EVP_PKEY_CTX_DUP, ERR_R_ENGINE_LIB); 339 EVPerror(ERR_R_ENGINE_LIB);
340 return 0; 340 return 0;
341 } 341 }
342#endif 342#endif
@@ -409,26 +409,26 @@ EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
409 int ret; 409 int ret;
410 410
411 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) { 411 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
412 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); 412 EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
413 return -2; 413 return -2;
414 } 414 }
415 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype)) 415 if ((keytype != -1) && (ctx->pmeth->pkey_id != keytype))
416 return -1; 416 return -1;
417 417
418 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) { 418 if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
419 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_NO_OPERATION_SET); 419 EVPerror(EVP_R_NO_OPERATION_SET);
420 return -1; 420 return -1;
421 } 421 }
422 422
423 if ((optype != -1) && !(ctx->operation & optype)) { 423 if ((optype != -1) && !(ctx->operation & optype)) {
424 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_INVALID_OPERATION); 424 EVPerror(EVP_R_INVALID_OPERATION);
425 return -1; 425 return -1;
426 } 426 }
427 427
428 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2); 428 ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
429 429
430 if (ret == -2) 430 if (ret == -2)
431 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED); 431 EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
432 432
433 return ret; 433 return ret;
434 434
@@ -438,15 +438,13 @@ int
438EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value) 438EVP_PKEY_CTX_ctrl_str(EVP_PKEY_CTX *ctx, const char *name, const char *value)
439{ 439{
440 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) { 440 if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl_str) {
441 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, 441 EVPerror(EVP_R_COMMAND_NOT_SUPPORTED);
442 EVP_R_COMMAND_NOT_SUPPORTED);
443 return -2; 442 return -2;
444 } 443 }
445 if (!strcmp(name, "digest")) { 444 if (!strcmp(name, "digest")) {
446 const EVP_MD *md; 445 const EVP_MD *md;
447 if (!value || !(md = EVP_get_digestbyname(value))) { 446 if (!value || !(md = EVP_get_digestbyname(value))) {
448 EVPerr(EVP_F_EVP_PKEY_CTX_CTRL_STR, 447 EVPerror(EVP_R_INVALID_DIGEST);
449 EVP_R_INVALID_DIGEST);
450 return 0; 448 return 0;
451 } 449 }
452 return EVP_PKEY_CTX_set_signature_md(ctx, md); 450 return EVP_PKEY_CTX_set_signature_md(ctx, md);
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
index 231e5df8a3..63885af3af 100644
--- a/src/lib/libcrypto/ex_data.c
+++ b/src/lib/libcrypto/ex_data.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ex_data.c,v 1.18 2015/02/10 11:22:21 jsing Exp $ */ 1/* $OpenBSD: ex_data.c,v 1.19 2017/01/29 17:49:22 beck Exp $ */
2 2
3/* 3/*
4 * Overhaul notes; 4 * Overhaul notes;
@@ -332,7 +332,7 @@ def_get_class(int class_index)
332 } 332 }
333 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); 333 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
334 if (!p) 334 if (!p)
335 CRYPTOerr(CRYPTO_F_DEF_GET_CLASS, ERR_R_MALLOC_FAILURE); 335 CRYPTOerror(ERR_R_MALLOC_FAILURE);
336 return p; 336 return p;
337} 337}
338 338
@@ -346,7 +346,7 @@ def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
346 CRYPTO_EX_DATA_FUNCS *a = malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); 346 CRYPTO_EX_DATA_FUNCS *a = malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
347 347
348 if (!a) { 348 if (!a) {
349 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); 349 CRYPTOerror(ERR_R_MALLOC_FAILURE);
350 return -1; 350 return -1;
351 } 351 }
352 a->argl = argl; 352 a->argl = argl;
@@ -357,7 +357,7 @@ def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
357 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); 357 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
358 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num) { 358 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num) {
359 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL)) { 359 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL)) {
360 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); 360 CRYPTOerror(ERR_R_MALLOC_FAILURE);
361 free(a); 361 free(a);
362 goto err; 362 goto err;
363 } 363 }
@@ -434,7 +434,7 @@ int_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
434skip: 434skip:
435 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); 435 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
436 if ((mx > 0) && !storage) { 436 if ((mx > 0) && !storage) {
437 CRYPTOerr(CRYPTO_F_INT_NEW_EX_DATA, ERR_R_MALLOC_FAILURE); 437 CRYPTOerror(ERR_R_MALLOC_FAILURE);
438 return 0; 438 return 0;
439 } 439 }
440 for (i = 0; i < mx; i++) { 440 for (i = 0; i < mx; i++) {
@@ -478,7 +478,7 @@ int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from)
478skip: 478skip:
479 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); 479 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
480 if ((mx > 0) && !storage) { 480 if ((mx > 0) && !storage) {
481 CRYPTOerr(CRYPTO_F_INT_DUP_EX_DATA, ERR_R_MALLOC_FAILURE); 481 CRYPTOerror(ERR_R_MALLOC_FAILURE);
482 return 0; 482 return 0;
483 } 483 }
484 for (i = 0; i < mx; i++) { 484 for (i = 0; i < mx; i++) {
@@ -515,7 +515,7 @@ int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
515skip: 515skip:
516 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); 516 CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA);
517 if ((mx > 0) && !storage) { 517 if ((mx > 0) && !storage) {
518 CRYPTOerr(CRYPTO_F_INT_FREE_EX_DATA, ERR_R_MALLOC_FAILURE); 518 CRYPTOerror(ERR_R_MALLOC_FAILURE);
519 return; 519 return;
520 } 520 }
521 for (i = 0; i < mx; i++) { 521 for (i = 0; i < mx; i++) {
@@ -605,8 +605,7 @@ CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
605 605
606 if (ad->sk == NULL) { 606 if (ad->sk == NULL) {
607 if ((ad->sk = sk_void_new_null()) == NULL) { 607 if ((ad->sk = sk_void_new_null()) == NULL) {
608 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, 608 CRYPTOerror(ERR_R_MALLOC_FAILURE);
609 ERR_R_MALLOC_FAILURE);
610 return (0); 609 return (0);
611 } 610 }
612 } 611 }
@@ -614,8 +613,7 @@ CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val)
614 613
615 while (i <= idx) { 614 while (i <= idx) {
616 if (!sk_void_push(ad->sk, NULL)) { 615 if (!sk_void_push(ad->sk, NULL)) {
617 CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, 616 CRYPTOerror(ERR_R_MALLOC_FAILURE);
618 ERR_R_MALLOC_FAILURE);
619 return (0); 617 return (0);
620 } 618 }
621 i++; 619 i++;
diff --git a/src/lib/libcrypto/gost/gost89imit_pmeth.c b/src/lib/libcrypto/gost/gost89imit_pmeth.c
index 00eaf1decc..1959b36163 100644
--- a/src/lib/libcrypto/gost/gost89imit_pmeth.c
+++ b/src/lib/libcrypto/gost/gost89imit_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gost89imit_pmeth.c,v 1.3 2014/11/13 20:29:55 miod Exp $ */ 1/* $OpenBSD: gost89imit_pmeth.c,v 1.4 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -110,13 +110,13 @@ pkey_gost_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
110 unsigned char *keydata; 110 unsigned char *keydata;
111 111
112 if (!data->key_set) { 112 if (!data->key_set) {
113 GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, GOST_R_MAC_KEY_NOT_SET); 113 GOSTerror(GOST_R_MAC_KEY_NOT_SET);
114 return 0; 114 return 0;
115 } 115 }
116 116
117 keydata = malloc(32); 117 keydata = malloc(32);
118 if (keydata == NULL) { 118 if (keydata == NULL) {
119 GOSTerr(GOST_F_PKEY_GOST_MAC_KEYGEN, ERR_R_MALLOC_FAILURE); 119 GOSTerror(ERR_R_MALLOC_FAILURE);
120 return 0; 120 return 0;
121 } 121 }
122 memcpy(keydata, data->key, 32); 122 memcpy(keydata, data->key, 32);
@@ -133,8 +133,7 @@ pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
133 switch (type) { 133 switch (type) {
134 case EVP_PKEY_CTRL_MD: 134 case EVP_PKEY_CTRL_MD:
135 if (EVP_MD_type(p2) != NID_id_Gost28147_89_MAC) { 135 if (EVP_MD_type(p2) != NID_id_Gost28147_89_MAC) {
136 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, 136 GOSTerror(GOST_R_INVALID_DIGEST_TYPE);
137 GOST_R_INVALID_DIGEST_TYPE);
138 return 0; 137 return 0;
139 } 138 }
140 data->md = p2; 139 data->md = p2;
@@ -142,8 +141,7 @@ pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
142 141
143 case EVP_PKEY_CTRL_SET_MAC_KEY: 142 case EVP_PKEY_CTRL_SET_MAC_KEY:
144 if (p1 != 32) { 143 if (p1 != 32) {
145 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, 144 GOSTerror(GOST_R_INVALID_MAC_KEY_LENGTH);
146 GOST_R_INVALID_MAC_KEY_LENGTH);
147 return 0; 145 return 0;
148 } 146 }
149 147
@@ -159,14 +157,12 @@ pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
159 if (!data->key_set) { 157 if (!data->key_set) {
160 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); 158 EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx);
161 if (pkey == NULL) { 159 if (pkey == NULL) {
162 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, 160 GOSTerror(GOST_R_MAC_KEY_NOT_SET);
163 GOST_R_MAC_KEY_NOT_SET);
164 return 0; 161 return 0;
165 } 162 }
166 key = EVP_PKEY_get0(pkey); 163 key = EVP_PKEY_get0(pkey);
167 if (key == NULL) { 164 if (key == NULL) {
168 GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, 165 GOSTerror(GOST_R_MAC_KEY_NOT_SET);
169 GOST_R_MAC_KEY_NOT_SET);
170 return 0; 166 return 0;
171 } 167 }
172 } else { 168 } else {
diff --git a/src/lib/libcrypto/gost/gost_err.c b/src/lib/libcrypto/gost/gost_err.c
index b4e061f985..3bf60ff063 100644
--- a/src/lib/libcrypto/gost/gost_err.c
+++ b/src/lib/libcrypto/gost/gost_err.c
@@ -68,37 +68,10 @@
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_GOST,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_GOST,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_GOST,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_GOST,0,reason)
70 70
71static ERR_STRING_DATA GOST_str_functs[]= 71static ERR_STRING_DATA GOST_str_functs[]= {
72 { 72 {ERR_FUNC(0xfff), "CRYPTO_internal"},
73{ERR_FUNC(GOST_F_DECODE_GOST01_ALGOR_PARAMS), "DECODE_GOST01_ALGOR_PARAMS"}, 73 {0, NULL}
74{ERR_FUNC(GOST_F_ENCODE_GOST01_ALGOR_PARAMS), "ENCODE_GOST01_ALGOR_PARAMS"}, 74};
75{ERR_FUNC(GOST_F_GOST2001_COMPUTE_PUBLIC), "GOST2001_COMPUTE_PUBLIC"},
76{ERR_FUNC(GOST_F_GOST2001_DO_SIGN), "GOST2001_DO_SIGN"},
77{ERR_FUNC(GOST_F_GOST2001_DO_VERIFY), "GOST2001_DO_VERIFY"},
78{ERR_FUNC(GOST_F_GOST2001_KEYGEN), "GOST2001_KEYGEN"},
79{ERR_FUNC(GOST_F_GOST89_GET_ASN1_PARAMETERS), "GOST89_GET_ASN1_PARAMETERS"},
80{ERR_FUNC(GOST_F_GOST89_SET_ASN1_PARAMETERS), "GOST89_SET_ASN1_PARAMETERS"},
81{ERR_FUNC(GOST_F_GOST_KEY_CHECK_KEY), "GOST_KEY_check_key"},
82{ERR_FUNC(GOST_F_GOST_KEY_NEW), "GOST_KEY_new"},
83{ERR_FUNC(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES), "GOST_KEY_set_public_key_affine_coordinates"},
84{ERR_FUNC(GOST_F_PARAM_COPY_GOST01), "PARAM_COPY_GOST01"},
85{ERR_FUNC(GOST_F_PARAM_DECODE_GOST01), "PARAM_DECODE_GOST01"},
86{ERR_FUNC(GOST_F_PKEY_GOST01_CTRL), "PKEY_GOST01_CTRL"},
87{ERR_FUNC(GOST_F_PKEY_GOST01_DECRYPT), "PKEY_GOST01_DECRYPT"},
88{ERR_FUNC(GOST_F_PKEY_GOST01_DERIVE), "PKEY_GOST01_DERIVE"},
89{ERR_FUNC(GOST_F_PKEY_GOST01_ENCRYPT), "PKEY_GOST01_ENCRYPT"},
90{ERR_FUNC(GOST_F_PKEY_GOST01_PARAMGEN), "PKEY_GOST01_PARAMGEN"},
91{ERR_FUNC(GOST_F_PKEY_GOST01_SIGN), "PKEY_GOST01_SIGN"},
92{ERR_FUNC(GOST_F_PKEY_GOST_MAC_CTRL), "PKEY_GOST_MAC_CTRL"},
93{ERR_FUNC(GOST_F_PKEY_GOST_MAC_KEYGEN), "PKEY_GOST_MAC_KEYGEN"},
94{ERR_FUNC(GOST_F_PRIV_DECODE_GOST01), "PRIV_DECODE_GOST01"},
95{ERR_FUNC(GOST_F_PUB_DECODE_GOST01), "PUB_DECODE_GOST01"},
96{ERR_FUNC(GOST_F_PUB_ENCODE_GOST01), "PUB_ENCODE_GOST01"},
97{ERR_FUNC(GOST_F_PUB_PRINT_GOST01), "PUB_PRINT_GOST01"},
98{ERR_FUNC(GOST_F_UNPACK_SIGNATURE_CP), "UNPACK_SIGNATURE_CP"},
99{ERR_FUNC(GOST_F_UNPACK_SIGNATURE_LE), "UNPACK_SIGNATURE_LE"},
100{0,NULL}
101 };
102 75
103static ERR_STRING_DATA GOST_str_reasons[]= 76static ERR_STRING_DATA GOST_str_reasons[]=
104 { 77 {
diff --git a/src/lib/libcrypto/gost/gostr341001.c b/src/lib/libcrypto/gost/gostr341001.c
index 39749394af..ba70d5f1fc 100644
--- a/src/lib/libcrypto/gost/gostr341001.c
+++ b/src/lib/libcrypto/gost/gostr341001.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001.c,v 1.6 2017/01/21 11:00:47 beck Exp $ */ 1/* $OpenBSD: gostr341001.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -109,14 +109,12 @@ gost2001_compute_public(GOST_KEY *ec)
109 int ok = 0; 109 int ok = 0;
110 110
111 if (group == NULL) { 111 if (group == NULL) {
112 GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, 112 GOSTerror(GOST_R_KEY_IS_NOT_INITIALIZED);
113 GOST_R_KEY_IS_NOT_INITIALIZED);
114 return 0; 113 return 0;
115 } 114 }
116 ctx = BN_CTX_new(); 115 ctx = BN_CTX_new();
117 if (ctx == NULL) { 116 if (ctx == NULL) {
118 GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, 117 GOSTerror(ERR_R_MALLOC_FAILURE);
119 ERR_R_MALLOC_FAILURE);
120 return 0; 118 return 0;
121 } 119 }
122 BN_CTX_start(ctx); 120 BN_CTX_start(ctx);
@@ -134,7 +132,7 @@ gost2001_compute_public(GOST_KEY *ec)
134 132
135 if (ok == 0) { 133 if (ok == 0) {
136err: 134err:
137 GOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC, ERR_R_EC_LIB); 135 GOSTerror(ERR_R_EC_LIB);
138 } 136 }
139 EC_POINT_free(pub_key); 137 EC_POINT_free(pub_key);
140 if (ctx != NULL) { 138 if (ctx != NULL) {
@@ -158,13 +156,13 @@ gost2001_do_sign(BIGNUM *md, GOST_KEY *eckey)
158 int ok = 0; 156 int ok = 0;
159 157
160 if (ctx == NULL) { 158 if (ctx == NULL) {
161 GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_MALLOC_FAILURE); 159 GOSTerror(ERR_R_MALLOC_FAILURE);
162 return NULL; 160 return NULL;
163 } 161 }
164 BN_CTX_start(ctx); 162 BN_CTX_start(ctx);
165 newsig = ECDSA_SIG_new(); 163 newsig = ECDSA_SIG_new();
166 if (newsig == NULL) { 164 if (newsig == NULL) {
167 GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_MALLOC_FAILURE); 165 GOSTerror(ERR_R_MALLOC_FAILURE);
168 goto err; 166 goto err;
169 } 167 }
170 s = newsig->s; 168 s = newsig->s;
@@ -190,8 +188,7 @@ gost2001_do_sign(BIGNUM *md, GOST_KEY *eckey)
190 do { 188 do {
191 do { 189 do {
192 if (!BN_rand_range(k, order)) { 190 if (!BN_rand_range(k, order)) {
193 GOSTerr(GOST_F_GOST2001_DO_SIGN, 191 GOSTerror(GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
194 GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
195 goto err; 192 goto err;
196 } 193 }
197 /* 194 /*
@@ -206,12 +203,12 @@ gost2001_do_sign(BIGNUM *md, GOST_KEY *eckey)
206 goto err; 203 goto err;
207 204
208 if (EC_POINT_mul(group, C, k, NULL, NULL, ctx) == 0) { 205 if (EC_POINT_mul(group, C, k, NULL, NULL, ctx) == 0) {
209 GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); 206 GOSTerror(ERR_R_EC_LIB);
210 goto err; 207 goto err;
211 } 208 }
212 if (EC_POINT_get_affine_coordinates_GFp(group, C, X, 209 if (EC_POINT_get_affine_coordinates_GFp(group, C, X,
213 NULL, ctx) == 0) { 210 NULL, ctx) == 0) {
214 GOSTerr(GOST_F_GOST2001_DO_SIGN, ERR_R_EC_LIB); 211 GOSTerror(ERR_R_EC_LIB);
215 goto err; 212 goto err;
216 } 213 }
217 if (BN_nnmod(r, X, order, ctx) == 0) 214 if (BN_nnmod(r, X, order, ctx) == 0)
@@ -285,8 +282,7 @@ gost2001_do_verify(BIGNUM *md, ECDSA_SIG *sig, GOST_KEY *ec)
285 pub_key = GOST_KEY_get0_public_key(ec); 282 pub_key = GOST_KEY_get0_public_key(ec);
286 if (BN_is_zero(sig->s) || BN_is_zero(sig->r) || 283 if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||
287 BN_cmp(sig->s, order) >= 1 || BN_cmp(sig->r, order) >= 1) { 284 BN_cmp(sig->s, order) >= 1 || BN_cmp(sig->r, order) >= 1) {
288 GOSTerr(GOST_F_GOST2001_DO_VERIFY, 285 GOSTerror(GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
289 GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
290 goto err; 286 goto err;
291 } 287 }
292 288
@@ -305,17 +301,17 @@ gost2001_do_verify(BIGNUM *md, ECDSA_SIG *sig, GOST_KEY *ec)
305 if ((C = EC_POINT_new(group)) == NULL) 301 if ((C = EC_POINT_new(group)) == NULL)
306 goto err; 302 goto err;
307 if (EC_POINT_mul(group, C, z1, pub_key, z2, ctx) == 0) { 303 if (EC_POINT_mul(group, C, z1, pub_key, z2, ctx) == 0) {
308 GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); 304 GOSTerror(ERR_R_EC_LIB);
309 goto err; 305 goto err;
310 } 306 }
311 if (EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx) == 0) { 307 if (EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx) == 0) {
312 GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB); 308 GOSTerror(ERR_R_EC_LIB);
313 goto err; 309 goto err;
314 } 310 }
315 if (BN_mod_ct(R, X, order, ctx) == 0) 311 if (BN_mod_ct(R, X, order, ctx) == 0)
316 goto err; 312 goto err;
317 if (BN_cmp(R, sig->r) != 0) { 313 if (BN_cmp(R, sig->r) != 0) {
318 GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH); 314 GOSTerror(GOST_R_SIGNATURE_MISMATCH);
319 } else { 315 } else {
320 ok = 1; 316 ok = 1;
321 } 317 }
@@ -385,8 +381,7 @@ gost2001_keygen(GOST_KEY *ec)
385 381
386 do { 382 do {
387 if (BN_rand_range(d, order) == 0) { 383 if (BN_rand_range(d, order) == 0) {
388 GOSTerr(GOST_F_GOST2001_KEYGEN, 384 GOSTerror(GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
389 GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);
390 goto err; 385 goto err;
391 } 386 }
392 } while (BN_is_zero(d)); 387 } while (BN_is_zero(d));
diff --git a/src/lib/libcrypto/gost/gostr341001_ameth.c b/src/lib/libcrypto/gost/gostr341001_ameth.c
index bb569ea846..b6958c77d5 100644
--- a/src/lib/libcrypto/gost/gostr341001_ameth.c
+++ b/src/lib/libcrypto/gost/gostr341001_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_ameth.c,v 1.10 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: gostr341001_ameth.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -86,8 +86,7 @@ decode_gost01_algor_params(EVP_PKEY *pkey, const unsigned char **p, int len)
86 86
87 gkp = d2i_GOST_KEY_PARAMS(NULL, p, len); 87 gkp = d2i_GOST_KEY_PARAMS(NULL, p, len);
88 if (gkp == NULL) { 88 if (gkp == NULL) {
89 GOSTerr(GOST_F_DECODE_GOST01_ALGOR_PARAMS, 89 GOSTerror(GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
90 GOST_R_BAD_PKEY_PARAMETERS_FORMAT);
91 return 0; 90 return 0;
92 } 91 }
93 param_nid = OBJ_obj2nid(gkp->key_params); 92 param_nid = OBJ_obj2nid(gkp->key_params);
@@ -125,8 +124,7 @@ encode_gost01_algor_params(const EVP_PKEY *key)
125 int pkey_param_nid = NID_undef; 124 int pkey_param_nid = NID_undef;
126 125
127 if (params == NULL || gkp == NULL) { 126 if (params == NULL || gkp == NULL) {
128 GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, 127 GOSTerror(ERR_R_MALLOC_FAILURE);
129 ERR_R_MALLOC_FAILURE);
130 ASN1_STRING_free(params); 128 ASN1_STRING_free(params);
131 params = NULL; 129 params = NULL;
132 goto err; 130 goto err;
@@ -139,8 +137,7 @@ encode_gost01_algor_params(const EVP_PKEY *key)
139 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */ 137 /*gkp->cipher_params = OBJ_nid2obj(cipher_param_nid); */
140 params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data); 138 params->length = i2d_GOST_KEY_PARAMS(gkp, &params->data);
141 if (params->length <= 0) { 139 if (params->length <= 0) {
142 GOSTerr(GOST_F_ENCODE_GOST01_ALGOR_PARAMS, 140 GOSTerror(ERR_R_MALLOC_FAILURE);
143 ERR_R_MALLOC_FAILURE);
144 ASN1_STRING_free(params); 141 ASN1_STRING_free(params);
145 params = NULL; 142 params = NULL;
146 goto err; 143 goto err;
@@ -206,8 +203,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
206 (void)EVP_PKEY_assign_GOST(pk, NULL); 203 (void)EVP_PKEY_assign_GOST(pk, NULL);
207 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); 204 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
208 if (ptype != V_ASN1_SEQUENCE) { 205 if (ptype != V_ASN1_SEQUENCE) {
209 GOSTerr(GOST_F_PUB_DECODE_GOST01, 206 GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT);
210 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
211 return 0; 207 return 0;
212 } 208 }
213 p = pval->data; 209 p = pval->data;
@@ -216,7 +212,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
216 212
217 octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len); 213 octet = d2i_ASN1_OCTET_STRING(NULL, &pubkey_buf, pub_len);
218 if (octet == NULL) { 214 if (octet == NULL) {
219 GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 215 GOSTerror(ERR_R_MALLOC_FAILURE);
220 return 0; 216 return 0;
221 } 217 }
222 len = octet->length / 2; 218 len = octet->length / 2;
@@ -228,7 +224,7 @@ pub_decode_gost01(EVP_PKEY *pk, X509_PUBKEY *pub)
228 224
229 ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y); 225 ret = GOST_KEY_set_public_key_affine_coordinates(pk->pkey.gost, X, Y);
230 if (ret == 0) 226 if (ret == 0)
231 GOSTerr(GOST_F_PUB_DECODE_GOST01, ERR_R_EC_LIB); 227 GOSTerror(ERR_R_EC_LIB);
232 228
233 BN_free(X); 229 BN_free(X);
234 BN_free(Y); 230 BN_free(Y);
@@ -263,19 +259,19 @@ pub_encode_gost01(X509_PUBKEY *pub, const EVP_PKEY *pk)
263 259
264 pub_key = GOST_KEY_get0_public_key(ec); 260 pub_key = GOST_KEY_get0_public_key(ec);
265 if (pub_key == NULL) { 261 if (pub_key == NULL) {
266 GOSTerr(GOST_F_PUB_ENCODE_GOST01, GOST_R_PUBLIC_KEY_UNDEFINED); 262 GOSTerror(GOST_R_PUBLIC_KEY_UNDEFINED);
267 goto err; 263 goto err;
268 } 264 }
269 265
270 octet = ASN1_OCTET_STRING_new(); 266 octet = ASN1_OCTET_STRING_new();
271 if (octet == NULL) { 267 if (octet == NULL) {
272 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); 268 GOSTerror(ERR_R_MALLOC_FAILURE);
273 goto err; 269 goto err;
274 } 270 }
275 271
276 ret = ASN1_STRING_set(octet, NULL, 2 * key_size); 272 ret = ASN1_STRING_set(octet, NULL, 2 * key_size);
277 if (ret == 0) { 273 if (ret == 0) {
278 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_INTERNAL_ERROR); 274 GOSTerror(ERR_R_INTERNAL_ERROR);
279 goto err; 275 goto err;
280 } 276 }
281 277
@@ -284,13 +280,13 @@ pub_encode_gost01(X509_PUBKEY *pub, const EVP_PKEY *pk)
284 X = BN_new(); 280 X = BN_new();
285 Y = BN_new(); 281 Y = BN_new();
286 if (X == NULL || Y == NULL) { 282 if (X == NULL || Y == NULL) {
287 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_MALLOC_FAILURE); 283 GOSTerror(ERR_R_MALLOC_FAILURE);
288 goto err; 284 goto err;
289 } 285 }
290 286
291 if (EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec), 287 if (EC_POINT_get_affine_coordinates_GFp(GOST_KEY_get0_group(ec),
292 pub_key, X, Y, NULL) == 0) { 288 pub_key, X, Y, NULL) == 0) {
293 GOSTerr(GOST_F_PUB_ENCODE_GOST01, ERR_R_EC_LIB); 289 GOSTerror(ERR_R_EC_LIB);
294 goto err; 290 goto err;
295 } 291 }
296 292
@@ -340,7 +336,7 @@ pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)
340 const EC_GROUP *group; 336 const EC_GROUP *group;
341 337
342 if (ctx == NULL) { 338 if (ctx == NULL) {
343 GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_MALLOC_FAILURE); 339 GOSTerror(ERR_R_MALLOC_FAILURE);
344 return 0; 340 return 0;
345 } 341 }
346 BN_CTX_start(ctx); 342 BN_CTX_start(ctx);
@@ -352,7 +348,7 @@ pub_print_gost01(BIO *out, const EVP_PKEY *pkey, int indent, ASN1_PCTX *pctx)
352 group = GOST_KEY_get0_group(pkey->pkey.gost); 348 group = GOST_KEY_get0_group(pkey->pkey.gost);
353 if (EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y, 349 if (EC_POINT_get_affine_coordinates_GFp(group, pubkey, X, Y,
354 ctx) == 0) { 350 ctx) == 0) {
355 GOSTerr(GOST_F_PUB_PRINT_GOST01, ERR_R_EC_LIB); 351 GOSTerror(ERR_R_EC_LIB);
356 goto err; 352 goto err;
357 } 353 }
358 if (BIO_indent(out, indent, 128) == 0) 354 if (BIO_indent(out, indent, 128) == 0)
@@ -416,8 +412,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
416 (void)EVP_PKEY_assign_GOST(pk, NULL); 412 (void)EVP_PKEY_assign_GOST(pk, NULL);
417 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg); 413 X509_ALGOR_get0(NULL, &ptype, (void **)&pval, palg);
418 if (ptype != V_ASN1_SEQUENCE) { 414 if (ptype != V_ASN1_SEQUENCE) {
419 GOSTerr(GOST_F_PUB_DECODE_GOST01, 415 GOSTerror(GOST_R_BAD_KEY_PARAMETERS_FORMAT);
420 GOST_R_BAD_KEY_PARAMETERS_FORMAT);
421 return 0; 416 return 0;
422 } 417 }
423 p = pval->data; 418 p = pval->data;
@@ -432,7 +427,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
432 d2i_ASN1_OCTET_STRING(NULL, &p, priv_len); 427 d2i_ASN1_OCTET_STRING(NULL, &p, priv_len);
433 428
434 if (s == NULL || s->length != 32) { 429 if (s == NULL || s->length != 32) {
435 GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); 430 GOSTerror(EVP_R_DECODE_ERROR);
436 ASN1_STRING_free(s); 431 ASN1_STRING_free(s);
437 return 0; 432 return 0;
438 } 433 }
@@ -448,7 +443,7 @@ priv_decode_gost01(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)
448 ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL); 443 ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL);
449 ASN1_INTEGER_free(priv_key); 444 ASN1_INTEGER_free(priv_key);
450 if (ret == 0) { 445 if (ret == 0) {
451 GOSTerr(GOST_F_PRIV_DECODE_GOST01, EVP_R_DECODE_ERROR); 446 GOSTerror(EVP_R_DECODE_ERROR);
452 return 0; 447 return 0;
453 } 448 }
454 } 449 }
@@ -533,7 +528,7 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
533 528
534 /* Compatibility */ 529 /* Compatibility */
535 if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) { 530 if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
536 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 531 GOSTerror(ERR_R_MALLOC_FAILURE);
537 return 0; 532 return 0;
538 } 533 }
539 nid = OBJ_obj2nid(obj); 534 nid = OBJ_obj2nid(obj);
@@ -541,20 +536,19 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
541 536
542 ec = GOST_KEY_new(); 537 ec = GOST_KEY_new();
543 if (ec == NULL) { 538 if (ec == NULL) {
544 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_MALLOC_FAILURE); 539 GOSTerror(ERR_R_MALLOC_FAILURE);
545 return 0; 540 return 0;
546 } 541 }
547 group = EC_GROUP_new_by_curve_name(nid); 542 group = EC_GROUP_new_by_curve_name(nid);
548 if (group == NULL) { 543 if (group == NULL) {
549 GOSTerr(GOST_F_PARAM_DECODE_GOST01, 544 GOSTerror(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
550 EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
551 GOST_KEY_free(ec); 545 GOST_KEY_free(ec);
552 return 0; 546 return 0;
553 } 547 }
554 548
555 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE); 549 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
556 if (GOST_KEY_set_group(ec, group) == 0) { 550 if (GOST_KEY_set_group(ec, group) == 0) {
557 GOSTerr(GOST_F_PARAM_DECODE_GOST01, ERR_R_EC_LIB); 551 GOSTerror(ERR_R_EC_LIB);
558 EC_GROUP_free(group); 552 EC_GROUP_free(group);
559 GOST_KEY_free(ec); 553 GOST_KEY_free(ec);
560 return 0; 554 return 0;
@@ -562,7 +556,7 @@ param_decode_gost01(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
562 EC_GROUP_free(group); 556 EC_GROUP_free(group);
563 if (GOST_KEY_set_digest(ec, 557 if (GOST_KEY_set_digest(ec,
564 NID_id_GostR3411_94_CryptoProParamSet) == 0) { 558 NID_id_GostR3411_94_CryptoProParamSet) == 0) {
565 GOSTerr(GOST_F_PARAM_DECODE_GOST01, GOST_R_INVALID_DIGEST_TYPE); 559 GOSTerror(GOST_R_INVALID_DIGEST_TYPE);
566 GOST_KEY_free(ec); 560 GOST_KEY_free(ec);
567 return 0; 561 return 0;
568 } 562 }
@@ -594,20 +588,17 @@ param_copy_gost01(EVP_PKEY *to, const EVP_PKEY *from)
594 int ret = 1; 588 int ret = 1;
595 589
596 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) { 590 if (EVP_PKEY_base_id(from) != EVP_PKEY_base_id(to)) {
597 GOSTerr(GOST_F_PARAM_COPY_GOST01, 591 GOSTerror(GOST_R_INCOMPATIBLE_ALGORITHMS);
598 GOST_R_INCOMPATIBLE_ALGORITHMS);
599 return 0; 592 return 0;
600 } 593 }
601 if (efrom == NULL) { 594 if (efrom == NULL) {
602 GOSTerr(GOST_F_PARAM_COPY_GOST01, 595 GOSTerror(GOST_R_KEY_PARAMETERS_MISSING);
603 GOST_R_KEY_PARAMETERS_MISSING);
604 return 0; 596 return 0;
605 } 597 }
606 if (eto == NULL) { 598 if (eto == NULL) {
607 eto = GOST_KEY_new(); 599 eto = GOST_KEY_new();
608 if (eto == NULL) { 600 if (eto == NULL) {
609 GOSTerr(GOST_F_PARAM_COPY_GOST01, 601 GOSTerror(ERR_R_MALLOC_FAILURE);
610 ERR_R_MALLOC_FAILURE);
611 return 0; 602 return 0;
612 } 603 }
613 if (EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto) == 0) { 604 if (EVP_PKEY_assign(to, EVP_PKEY_base_id(from), eto) == 0) {
diff --git a/src/lib/libcrypto/gost/gostr341001_key.c b/src/lib/libcrypto/gost/gostr341001_key.c
index 894a189e3b..0a42a15378 100644
--- a/src/lib/libcrypto/gost/gostr341001_key.c
+++ b/src/lib/libcrypto/gost/gostr341001_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_key.c,v 1.6 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: gostr341001_key.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -78,7 +78,7 @@ GOST_KEY_new(void)
78 78
79 ret = malloc(sizeof(GOST_KEY)); 79 ret = malloc(sizeof(GOST_KEY));
80 if (ret == NULL) { 80 if (ret == NULL) {
81 GOSTerr(GOST_F_GOST_KEY_NEW, ERR_R_MALLOC_FAILURE); 81 GOSTerror(ERR_R_MALLOC_FAILURE);
82 return (NULL); 82 return (NULL);
83 } 83 }
84 ret->group = NULL; 84 ret->group = NULL;
@@ -118,11 +118,11 @@ GOST_KEY_check_key(const GOST_KEY *key)
118 EC_POINT *point = NULL; 118 EC_POINT *point = NULL;
119 119
120 if (key == NULL || key->group == NULL || key->pub_key == NULL) { 120 if (key == NULL || key->group == NULL || key->pub_key == NULL) {
121 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); 121 GOSTerror(ERR_R_PASSED_NULL_PARAMETER);
122 return 0; 122 return 0;
123 } 123 }
124 if (EC_POINT_is_at_infinity(key->group, key->pub_key) != 0) { 124 if (EC_POINT_is_at_infinity(key->group, key->pub_key) != 0) {
125 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY); 125 GOSTerror(EC_R_POINT_AT_INFINITY);
126 goto err; 126 goto err;
127 } 127 }
128 if ((ctx = BN_CTX_new()) == NULL) 128 if ((ctx = BN_CTX_new()) == NULL)
@@ -132,23 +132,23 @@ GOST_KEY_check_key(const GOST_KEY *key)
132 132
133 /* testing whether the pub_key is on the elliptic curve */ 133 /* testing whether the pub_key is on the elliptic curve */
134 if (EC_POINT_is_on_curve(key->group, key->pub_key, ctx) == 0) { 134 if (EC_POINT_is_on_curve(key->group, key->pub_key, ctx) == 0) {
135 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE); 135 GOSTerror(EC_R_POINT_IS_NOT_ON_CURVE);
136 goto err; 136 goto err;
137 } 137 }
138 /* testing whether pub_key * order is the point at infinity */ 138 /* testing whether pub_key * order is the point at infinity */
139 if ((order = BN_new()) == NULL) 139 if ((order = BN_new()) == NULL)
140 goto err; 140 goto err;
141 if (EC_GROUP_get_order(key->group, order, ctx) == 0) { 141 if (EC_GROUP_get_order(key->group, order, ctx) == 0) {
142 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER); 142 GOSTerror(EC_R_INVALID_GROUP_ORDER);
143 goto err; 143 goto err;
144 } 144 }
145 if (EC_POINT_mul(key->group, point, NULL, key->pub_key, order, 145 if (EC_POINT_mul(key->group, point, NULL, key->pub_key, order,
146 ctx) == 0) { 146 ctx) == 0) {
147 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); 147 GOSTerror(ERR_R_EC_LIB);
148 goto err; 148 goto err;
149 } 149 }
150 if (EC_POINT_is_at_infinity(key->group, point) == 0) { 150 if (EC_POINT_is_at_infinity(key->group, point) == 0) {
151 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); 151 GOSTerror(EC_R_WRONG_ORDER);
152 goto err; 152 goto err;
153 } 153 }
154 /* 154 /*
@@ -157,17 +157,16 @@ GOST_KEY_check_key(const GOST_KEY *key)
157 */ 157 */
158 if (key->priv_key != NULL) { 158 if (key->priv_key != NULL) {
159 if (BN_cmp(key->priv_key, order) >= 0) { 159 if (BN_cmp(key->priv_key, order) >= 0) {
160 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, EC_R_WRONG_ORDER); 160 GOSTerror(EC_R_WRONG_ORDER);
161 goto err; 161 goto err;
162 } 162 }
163 if (EC_POINT_mul(key->group, point, key->priv_key, NULL, NULL, 163 if (EC_POINT_mul(key->group, point, key->priv_key, NULL, NULL,
164 ctx) == 0) { 164 ctx) == 0) {
165 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, ERR_R_EC_LIB); 165 GOSTerror(ERR_R_EC_LIB);
166 goto err; 166 goto err;
167 } 167 }
168 if (EC_POINT_cmp(key->group, point, key->pub_key, ctx) != 0) { 168 if (EC_POINT_cmp(key->group, point, key->pub_key, ctx) != 0) {
169 GOSTerr(GOST_F_GOST_KEY_CHECK_KEY, 169 GOSTerror(EC_R_INVALID_PRIVATE_KEY);
170 EC_R_INVALID_PRIVATE_KEY);
171 goto err; 170 goto err;
172 } 171 }
173 } 172 }
@@ -188,8 +187,7 @@ GOST_KEY_set_public_key_affine_coordinates(GOST_KEY *key, BIGNUM *x, BIGNUM *y)
188 int ok = 0; 187 int ok = 0;
189 188
190 if (key == NULL || key->group == NULL || x == NULL || y == NULL) { 189 if (key == NULL || key->group == NULL || x == NULL || y == NULL) {
191 GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, 190 GOSTerror(ERR_R_PASSED_NULL_PARAMETER);
192 ERR_R_PASSED_NULL_PARAMETER);
193 return 0; 191 return 0;
194 } 192 }
195 ctx = BN_CTX_new(); 193 ctx = BN_CTX_new();
@@ -215,8 +213,7 @@ GOST_KEY_set_public_key_affine_coordinates(GOST_KEY *key, BIGNUM *x, BIGNUM *y)
215 * out of range. 213 * out of range.
216 */ 214 */
217 if (BN_cmp(x, tx) != 0 || BN_cmp(y, ty) != 0) { 215 if (BN_cmp(x, tx) != 0 || BN_cmp(y, ty) != 0) {
218 GOSTerr(GOST_F_GOST_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES, 216 GOSTerror(EC_R_COORDINATES_OUT_OF_RANGE);
219 EC_R_COORDINATES_OUT_OF_RANGE);
220 goto err; 217 goto err;
221 } 218 }
222 if (GOST_KEY_set_public_key(key, point) == 0) 219 if (GOST_KEY_set_public_key(key, point) == 0)
diff --git a/src/lib/libcrypto/gost/gostr341001_pmeth.c b/src/lib/libcrypto/gost/gostr341001_pmeth.c
index 30a066612f..0eb1d873de 100644
--- a/src/lib/libcrypto/gost/gostr341001_pmeth.c
+++ b/src/lib/libcrypto/gost/gostr341001_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_pmeth.c,v 1.13 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: gostr341001_pmeth.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -73,7 +73,7 @@ unpack_signature_cp(const unsigned char *sig, size_t siglen)
73 73
74 s = ECDSA_SIG_new(); 74 s = ECDSA_SIG_new();
75 if (s == NULL) { 75 if (s == NULL) {
76 GOSTerr(GOST_F_UNPACK_SIGNATURE_CP, ERR_R_MALLOC_FAILURE); 76 GOSTerror(ERR_R_MALLOC_FAILURE);
77 return NULL; 77 return NULL;
78 } 78 }
79 BN_bin2bn(sig, siglen / 2, s->s); 79 BN_bin2bn(sig, siglen / 2, s->s);
@@ -106,7 +106,7 @@ unpack_signature_le(const unsigned char *sig, size_t siglen)
106 106
107 s = ECDSA_SIG_new(); 107 s = ECDSA_SIG_new();
108 if (s == NULL) { 108 if (s == NULL) {
109 GOSTerr(GOST_F_UNPACK_SIGNATURE_LE, ERR_R_MALLOC_FAILURE); 109 GOSTerror(ERR_R_MALLOC_FAILURE);
110 return NULL; 110 return NULL;
111 } 111 }
112 GOST_le2bn(sig, siglen / 2, s->r); 112 GOST_le2bn(sig, siglen / 2, s->r);
@@ -190,7 +190,7 @@ pkey_gost01_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
190 190
191 if (data->sign_param_nid == NID_undef || 191 if (data->sign_param_nid == NID_undef ||
192 data->digest_nid == NID_undef) { 192 data->digest_nid == NID_undef) {
193 GOSTerr(GOST_F_PKEY_GOST01_PARAMGEN, GOST_R_NO_PARAMETERS_SET); 193 GOSTerror(GOST_R_NO_PARAMETERS_SET);
194 return 0; 194 return 0;
195 } 195 }
196 196
@@ -246,11 +246,11 @@ pkey_gost01_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
246 *siglen = 2 * size; 246 *siglen = 2 * size;
247 return 1; 247 return 1;
248 } else if (*siglen < 2 * size) { 248 } else if (*siglen < 2 * size) {
249 GOSTerr(GOST_F_PKEY_GOST01_SIGN, EC_R_BUFFER_TOO_SMALL); 249 GOSTerror(EC_R_BUFFER_TOO_SMALL);
250 return 0; 250 return 0;
251 } 251 }
252 if (tbs_len != 32 && tbs_len != 64) { 252 if (tbs_len != 32 && tbs_len != 64) {
253 GOSTerr(GOST_F_PKEY_GOST01_SIGN, EVP_R_BAD_BLOCK_LENGTH); 253 GOSTerror(EVP_R_BAD_BLOCK_LENGTH);
254 return 0; 254 return 0;
255 } 255 }
256 md = GOST_le2bn(tbs, tbs_len, NULL); 256 md = GOST_le2bn(tbs, tbs_len, NULL);
@@ -386,8 +386,7 @@ pkey_gost01_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_len,
386 } 386 }
387 gkt = d2i_GOST_KEY_TRANSPORT(NULL, (const unsigned char **)&p, in_len); 387 gkt = d2i_GOST_KEY_TRANSPORT(NULL, (const unsigned char **)&p, in_len);
388 if (gkt == NULL) { 388 if (gkt == NULL) {
389 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 389 GOSTerror(GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
390 GOST_R_ERROR_PARSING_KEY_TRANSPORT_INFO);
391 return -1; 390 return -1;
392 } 391 }
393 392
@@ -395,50 +394,44 @@ pkey_gost01_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key, size_t *key_len,
395 eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key); 394 eph_key = X509_PUBKEY_get(gkt->key_agreement_info->ephem_key);
396 if (eph_key != NULL) { 395 if (eph_key != NULL) {
397 if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0) { 396 if (EVP_PKEY_derive_set_peer(pctx, eph_key) <= 0) {
398 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 397 GOSTerror(GOST_R_INCOMPATIBLE_PEER_KEY);
399 GOST_R_INCOMPATIBLE_PEER_KEY);
400 goto err; 398 goto err;
401 } 399 }
402 } else { 400 } else {
403 /* Set control "public key from client certificate used" */ 401 /* Set control "public key from client certificate used" */
404 if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, 402 if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3,
405 NULL) <= 0) { 403 NULL) <= 0) {
406 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 404 GOSTerror(GOST_R_CTRL_CALL_FAILED);
407 GOST_R_CTRL_CALL_FAILED);
408 goto err; 405 goto err;
409 } 406 }
410 } 407 }
411 peerkey = EVP_PKEY_CTX_get0_peerkey(pctx); 408 peerkey = EVP_PKEY_CTX_get0_peerkey(pctx);
412 if (peerkey == NULL) { 409 if (peerkey == NULL) {
413 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, GOST_R_NO_PEER_KEY); 410 GOSTerror(GOST_R_NO_PEER_KEY);
414 goto err; 411 goto err;
415 } 412 }
416 413
417 nid = OBJ_obj2nid(gkt->key_agreement_info->cipher); 414 nid = OBJ_obj2nid(gkt->key_agreement_info->cipher);
418 415
419 if (gkt->key_agreement_info->eph_iv->length != 8) { 416 if (gkt->key_agreement_info->eph_iv->length != 8) {
420 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 417 GOSTerror(GOST_R_INVALID_IV_LENGTH);
421 GOST_R_INVALID_IV_LENGTH);
422 goto err; 418 goto err;
423 } 419 }
424 memcpy(wrappedKey, gkt->key_agreement_info->eph_iv->data, 8); 420 memcpy(wrappedKey, gkt->key_agreement_info->eph_iv->data, 8);
425 if (gkt->key_info->encrypted_key->length != 32) { 421 if (gkt->key_info->encrypted_key->length != 32) {
426 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 422 GOSTerror(EVP_R_BAD_KEY_LENGTH);
427 EVP_R_BAD_KEY_LENGTH);
428 goto err; 423 goto err;
429 } 424 }
430 memcpy(wrappedKey + 8, gkt->key_info->encrypted_key->data, 32); 425 memcpy(wrappedKey + 8, gkt->key_info->encrypted_key->data, 32);
431 if (gkt->key_info->imit->length != 4) { 426 if (gkt->key_info->imit->length != 4) {
432 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 427 GOSTerror(ERR_R_INTERNAL_ERROR);
433 ERR_R_INTERNAL_ERROR);
434 goto err; 428 goto err;
435 } 429 }
436 memcpy(wrappedKey + 40, gkt->key_info->imit->data, 4); 430 memcpy(wrappedKey + 40, gkt->key_info->imit->data, 4);
437 if (gost01_VKO_key(peerkey, priv, wrappedKey, sharedKey) <= 0) 431 if (gost01_VKO_key(peerkey, priv, wrappedKey, sharedKey) <= 0)
438 goto err; 432 goto err;
439 if (gost_key_unwrap_crypto_pro(nid, sharedKey, wrappedKey, key) == 0) { 433 if (gost_key_unwrap_crypto_pro(nid, sharedKey, wrappedKey, key) == 0) {
440 GOSTerr(GOST_F_PKEY_GOST01_DECRYPT, 434 GOSTerror(GOST_R_ERROR_COMPUTING_SHARED_KEY);
441 GOST_R_ERROR_COMPUTING_SHARED_KEY);
442 goto err; 435 goto err;
443 } 436 }
444 437
@@ -462,7 +455,7 @@ pkey_gost01_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
462 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx); 455 struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
463 456
464 if (data->shared_ukm == NULL) { 457 if (data->shared_ukm == NULL) {
465 GOSTerr(GOST_F_PKEY_GOST01_DERIVE, GOST_R_UKM_NOT_SET); 458 GOSTerror(GOST_R_UKM_NOT_SET);
466 return 0; 459 return 0;
467 } 460 }
468 461
@@ -500,8 +493,7 @@ pkey_gost01_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out, size_t *out_len,
500 if (sec_key) { 493 if (sec_key) {
501 key_is_ephemeral = 0; 494 key_is_ephemeral = 0;
502 if (GOST_KEY_get0_private_key(sec_key->pkey.gost) == 0) { 495 if (GOST_KEY_get0_private_key(sec_key->pkey.gost) == 0) {
503 GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, 496 GOSTerror(GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR);
504 GOST_R_NO_PRIVATE_PART_OF_NON_EPHEMERAL_KEYPAIR);
505 goto err; 497 goto err;
506 } 498 }
507 } else { 499 } else {
@@ -548,8 +540,7 @@ pkey_gost01_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out, size_t *out_len,
548 if (key_is_ephemeral) { 540 if (key_is_ephemeral) {
549 if (X509_PUBKEY_set(&gkt->key_agreement_info->ephem_key, 541 if (X509_PUBKEY_set(&gkt->key_agreement_info->ephem_key,
550 out != NULL ? sec_key : pubk) == 0) { 542 out != NULL ? sec_key : pubk) == 0) {
551 GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, 543 GOSTerror(GOST_R_CANNOT_PACK_EPHEMERAL_KEY);
552 GOST_R_CANNOT_PACK_EPHEMERAL_KEY);
553 goto err; 544 goto err;
554 } 545 }
555 } 546 }
@@ -561,8 +552,7 @@ pkey_gost01_encrypt(EVP_PKEY_CTX *pctx, unsigned char *out, size_t *out_len,
561 /* Set control "public key from client certificate used" */ 552 /* Set control "public key from client certificate used" */
562 if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3, 553 if (EVP_PKEY_CTX_ctrl(pctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 3,
563 NULL) <= 0) { 554 NULL) <= 0) {
564 GOSTerr(GOST_F_PKEY_GOST01_ENCRYPT, 555 GOSTerror(GOST_R_CTRL_CALL_FAILED);
565 GOST_R_CTRL_CALL_FAILED);
566 goto err; 556 goto err;
567 } 557 }
568 } 558 }
@@ -588,8 +578,7 @@ pkey_gost01_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
588 case EVP_PKEY_CTRL_MD: 578 case EVP_PKEY_CTRL_MD:
589 if (EVP_MD_type(p2) != 579 if (EVP_MD_type(p2) !=
590 GostR3410_get_md_digest(pctx->digest_nid)) { 580 GostR3410_get_md_digest(pctx->digest_nid)) {
591 GOSTerr(GOST_F_PKEY_GOST01_CTRL, 581 GOSTerror(GOST_R_INVALID_DIGEST_TYPE);
592 GOST_R_INVALID_DIGEST_TYPE);
593 return 0; 582 return 0;
594 } 583 }
595 pctx->md = p2; 584 pctx->md = p2;
@@ -609,8 +598,7 @@ pkey_gost01_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
609 char *ukm = malloc(p1); 598 char *ukm = malloc(p1);
610 599
611 if (ukm == NULL) { 600 if (ukm == NULL) {
612 GOSTerr(GOST_F_PKEY_GOST01_CTRL, 601 GOSTerror(ERR_R_MALLOC_FAILURE);
613 ERR_R_MALLOC_FAILURE);
614 return 0; 602 return 0;
615 } 603 }
616 memcpy(ukm, p2, p1); 604 memcpy(ukm, p2, p1);
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
index 155e32a540..8fd980b052 100644
--- a/src/lib/libcrypto/hmac/hmac.c
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hmac.c,v 1.22 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: hmac.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,7 +80,7 @@ HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
80 reset = 1; 80 reset = 1;
81 j = EVP_MD_block_size(md); 81 j = EVP_MD_block_size(md);
82 if ((size_t)j > sizeof(ctx->key)) { 82 if ((size_t)j > sizeof(ctx->key)) {
83 EVPerr(EVP_F_HMAC_INIT_EX, EVP_R_BAD_BLOCK_LENGTH); 83 EVPerror(EVP_R_BAD_BLOCK_LENGTH);
84 goto err; 84 goto err;
85 } 85 }
86 if (j < len) { 86 if (j < len) {
@@ -93,8 +93,7 @@ HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
93 goto err; 93 goto err;
94 } else { 94 } else {
95 if ((size_t)len > sizeof(ctx->key)) { 95 if ((size_t)len > sizeof(ctx->key)) {
96 EVPerr(EVP_F_HMAC_INIT_EX, 96 EVPerror(EVP_R_BAD_KEY_LENGTH);
97 EVP_R_BAD_KEY_LENGTH);
98 goto err; 97 goto err;
99 } 98 }
100 memcpy(ctx->key, key, len); 99 memcpy(ctx->key, key, len);
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index 81240db204..a9e5f859d5 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: o_names.c,v 1.21 2015/07/18 21:21:28 beck Exp $ */ 1/* $OpenBSD: o_names.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2#include <stdio.h> 2#include <stdio.h>
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
@@ -67,7 +67,7 @@ OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
67 for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) { 67 for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
68 name_funcs = malloc(sizeof(NAME_FUNCS)); 68 name_funcs = malloc(sizeof(NAME_FUNCS));
69 if (!name_funcs) { 69 if (!name_funcs) {
70 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); 70 OBJerror(ERR_R_MALLOC_FAILURE);
71 return (0); 71 return (0);
72 } 72 }
73 name_funcs->hash_func = lh_strhash; 73 name_funcs->hash_func = lh_strhash;
@@ -75,7 +75,7 @@ OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
75 name_funcs->free_func = NULL; 75 name_funcs->free_func = NULL;
76 if (sk_NAME_FUNCS_push(name_funcs_stack, name_funcs) == 0) { 76 if (sk_NAME_FUNCS_push(name_funcs_stack, name_funcs) == 0) {
77 free(name_funcs); 77 free(name_funcs);
78 OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); 78 OBJerror(ERR_R_MALLOC_FAILURE);
79 return (0); 79 return (0);
80 } 80 }
81 } 81 }
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index e1dacc0d39..5b7fac0588 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_dat.c,v 1.38 2017/01/21 04:44:43 jsing Exp $ */ 1/* $OpenBSD: obj_dat.c,v 1.39 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -329,7 +329,7 @@ OBJ_add_object(const ASN1_OBJECT *obj)
329 return (o->nid); 329 return (o->nid);
330 330
331err2: 331err2:
332 OBJerr(OBJ_F_OBJ_ADD_OBJECT, ERR_R_MALLOC_FAILURE); 332 OBJerror(ERR_R_MALLOC_FAILURE);
333err: 333err:
334 for (i = ADDED_DATA; i <= ADDED_NID; i++) 334 for (i = ADDED_DATA; i <= ADDED_NID; i++)
335 free(ao[i]); 335 free(ao[i]);
@@ -345,7 +345,7 @@ OBJ_nid2obj(int n)
345 345
346 if ((n >= 0) && (n < NUM_NID)) { 346 if ((n >= 0) && (n < NUM_NID)) {
347 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { 347 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
348 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID); 348 OBJerror(OBJ_R_UNKNOWN_NID);
349 return (NULL); 349 return (NULL);
350 } 350 }
351 return ((ASN1_OBJECT *)&(nid_objs[n])); 351 return ((ASN1_OBJECT *)&(nid_objs[n]));
@@ -359,7 +359,7 @@ OBJ_nid2obj(int n)
359 if (adp != NULL) 359 if (adp != NULL)
360 return (adp->obj); 360 return (adp->obj);
361 else { 361 else {
362 OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID); 362 OBJerror(OBJ_R_UNKNOWN_NID);
363 return (NULL); 363 return (NULL);
364 } 364 }
365 } 365 }
@@ -373,7 +373,7 @@ OBJ_nid2sn(int n)
373 373
374 if ((n >= 0) && (n < NUM_NID)) { 374 if ((n >= 0) && (n < NUM_NID)) {
375 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { 375 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
376 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID); 376 OBJerror(OBJ_R_UNKNOWN_NID);
377 return (NULL); 377 return (NULL);
378 } 378 }
379 return (nid_objs[n].sn); 379 return (nid_objs[n].sn);
@@ -387,7 +387,7 @@ OBJ_nid2sn(int n)
387 if (adp != NULL) 387 if (adp != NULL)
388 return (adp->obj->sn); 388 return (adp->obj->sn);
389 else { 389 else {
390 OBJerr(OBJ_F_OBJ_NID2SN, OBJ_R_UNKNOWN_NID); 390 OBJerror(OBJ_R_UNKNOWN_NID);
391 return (NULL); 391 return (NULL);
392 } 392 }
393 } 393 }
@@ -401,7 +401,7 @@ OBJ_nid2ln(int n)
401 401
402 if ((n >= 0) && (n < NUM_NID)) { 402 if ((n >= 0) && (n < NUM_NID)) {
403 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) { 403 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
404 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID); 404 OBJerror(OBJ_R_UNKNOWN_NID);
405 return (NULL); 405 return (NULL);
406 } 406 }
407 return (nid_objs[n].ln); 407 return (nid_objs[n].ln);
@@ -415,7 +415,7 @@ OBJ_nid2ln(int n)
415 if (adp != NULL) 415 if (adp != NULL)
416 return (adp->obj->ln); 416 return (adp->obj->ln);
417 else { 417 else {
418 OBJerr(OBJ_F_OBJ_NID2LN, OBJ_R_UNKNOWN_NID); 418 OBJerror(OBJ_R_UNKNOWN_NID);
419 return (NULL); 419 return (NULL);
420 } 420 }
421 } 421 }
@@ -799,7 +799,7 @@ OBJ_create(const char *oid, const char *sn, const char *ln)
799 return (0); 799 return (0);
800 800
801 if ((buf = malloc(i)) == NULL) { 801 if ((buf = malloc(i)) == NULL) {
802 OBJerr(OBJ_F_OBJ_CREATE, ERR_R_MALLOC_FAILURE); 802 OBJerror(ERR_R_MALLOC_FAILURE);
803 return (0); 803 return (0);
804 } 804 }
805 i = a2d_ASN1_OBJECT(buf, i, oid, -1); 805 i = a2d_ASN1_OBJECT(buf, i, oid, -1);
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
index 9cea59b785..e1413190eb 100644
--- a/src/lib/libcrypto/objects/obj_err.c
+++ b/src/lib/libcrypto/objects/obj_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_err.c,v 1.11 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: obj_err.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,13 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OBJ,0,reason)
73 73
74static ERR_STRING_DATA OBJ_str_functs[] = { 74static ERR_STRING_DATA OBJ_str_functs[] = {
75 {ERR_FUNC(OBJ_F_OBJ_ADD_OBJECT), "OBJ_add_object"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(OBJ_F_OBJ_CREATE), "OBJ_create"},
77 {ERR_FUNC(OBJ_F_OBJ_DUP), "OBJ_dup"},
78 {ERR_FUNC(OBJ_F_OBJ_NAME_NEW_INDEX), "OBJ_NAME_new_index"},
79 {ERR_FUNC(OBJ_F_OBJ_NID2LN), "OBJ_nid2ln"},
80 {ERR_FUNC(OBJ_F_OBJ_NID2OBJ), "OBJ_nid2obj"},
81 {ERR_FUNC(OBJ_F_OBJ_NID2SN), "OBJ_nid2sn"},
82 {0, NULL} 76 {0, NULL}
83}; 77};
84 78
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 247bafbe01..53f3bb9ebe 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: obj_lib.c,v 1.13 2014/10/07 04:59:25 miod Exp $ */ 1/* $OpenBSD: obj_lib.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -79,7 +79,7 @@ OBJ_dup(const ASN1_OBJECT *o)
79 79
80 r = ASN1_OBJECT_new(); 80 r = ASN1_OBJECT_new();
81 if (r == NULL) { 81 if (r == NULL) {
82 OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB); 82 OBJerror(ERR_R_ASN1_LIB);
83 return (NULL); 83 return (NULL);
84 } 84 }
85 data = malloc(o->length); 85 data = malloc(o->length);
@@ -110,7 +110,7 @@ OBJ_dup(const ASN1_OBJECT *o)
110 return (r); 110 return (r);
111 111
112err: 112err:
113 OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE); 113 OBJerror(ERR_R_MALLOC_FAILURE);
114 free(ln); 114 free(ln);
115 free(sn); 115 free(sn);
116 free(data); 116 free(data);
diff --git a/src/lib/libcrypto/ocsp/ocsp_cl.c b/src/lib/libcrypto/ocsp/ocsp_cl.c
index 6b8fb87880..04ea6866a5 100644
--- a/src/lib/libcrypto/ocsp/ocsp_cl.c
+++ b/src/lib/libcrypto/ocsp/ocsp_cl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_cl.c,v 1.13 2016/12/30 15:31:58 jsing Exp $ */ 1/* $OpenBSD: ocsp_cl.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL 2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */ 3 * project. */
4 4
@@ -159,8 +159,7 @@ OCSP_request_sign(OCSP_REQUEST *req, X509 *signer, EVP_PKEY *key,
159 goto err; 159 goto err;
160 if (key) { 160 if (key) {
161 if (!X509_check_private_key(signer, key)) { 161 if (!X509_check_private_key(signer, key)) {
162 OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, 162 OCSPerror(OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
163 OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
164 goto err; 163 goto err;
165 } 164 }
166 if (!OCSP_REQUEST_sign(req, key, dgst)) 165 if (!OCSP_REQUEST_sign(req, key, dgst))
@@ -202,13 +201,11 @@ OCSP_response_get1_basic(OCSP_RESPONSE *resp)
202 201
203 rb = resp->responseBytes; 202 rb = resp->responseBytes;
204 if (!rb) { 203 if (!rb) {
205 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, 204 OCSPerror(OCSP_R_NO_RESPONSE_DATA);
206 OCSP_R_NO_RESPONSE_DATA);
207 return NULL; 205 return NULL;
208 } 206 }
209 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) { 207 if (OBJ_obj2nid(rb->responseType) != NID_id_pkix_OCSP_basic) {
210 OCSPerr(OCSP_F_OCSP_RESPONSE_GET1_BASIC, 208 OCSPerror(OCSP_R_NOT_BASIC_RESPONSE);
211 OCSP_R_NOT_BASIC_RESPONSE);
212 return NULL; 209 return NULL;
213 } 210 }
214 211
@@ -341,16 +338,14 @@ OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
341 /* Check thisUpdate is valid and not more than nsec in the future */ 338 /* Check thisUpdate is valid and not more than nsec in the future */
342 if (ASN1_time_parse(thisupd->data, thisupd->length, &tm_this, 339 if (ASN1_time_parse(thisupd->data, thisupd->length, &tm_this,
343 V_ASN1_GENERALIZEDTIME) != V_ASN1_GENERALIZEDTIME) { 340 V_ASN1_GENERALIZEDTIME) != V_ASN1_GENERALIZEDTIME) {
344 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 341 OCSPerror(OCSP_R_ERROR_IN_THISUPDATE_FIELD);
345 OCSP_R_ERROR_IN_THISUPDATE_FIELD);
346 return 0; 342 return 0;
347 } else { 343 } else {
348 t_tmp = t_now + nsec; 344 t_tmp = t_now + nsec;
349 if (gmtime_r(&t_tmp, &tm_tmp) == NULL) 345 if (gmtime_r(&t_tmp, &tm_tmp) == NULL)
350 return 0; 346 return 0;
351 if (ASN1_time_tm_cmp(&tm_this, &tm_tmp) > 0) { 347 if (ASN1_time_tm_cmp(&tm_this, &tm_tmp) > 0) {
352 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 348 OCSPerror(OCSP_R_STATUS_NOT_YET_VALID);
353 OCSP_R_STATUS_NOT_YET_VALID);
354 return 0; 349 return 0;
355 } 350 }
356 351
@@ -363,8 +358,7 @@ OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
363 if (gmtime_r(&t_tmp, &tm_tmp) == NULL) 358 if (gmtime_r(&t_tmp, &tm_tmp) == NULL)
364 return 0; 359 return 0;
365 if (ASN1_time_tm_cmp(&tm_this, &tm_tmp) < 0) { 360 if (ASN1_time_tm_cmp(&tm_this, &tm_tmp) < 0) {
366 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 361 OCSPerror(OCSP_R_STATUS_TOO_OLD);
367 OCSP_R_STATUS_TOO_OLD);
368 return 0; 362 return 0;
369 } 363 }
370 } 364 }
@@ -376,24 +370,21 @@ OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
376 /* Check nextUpdate is valid and not more than nsec in the past */ 370 /* Check nextUpdate is valid and not more than nsec in the past */
377 if (ASN1_time_parse(nextupd->data, nextupd->length, &tm_next, 371 if (ASN1_time_parse(nextupd->data, nextupd->length, &tm_next,
378 V_ASN1_GENERALIZEDTIME) != V_ASN1_GENERALIZEDTIME) { 372 V_ASN1_GENERALIZEDTIME) != V_ASN1_GENERALIZEDTIME) {
379 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 373 OCSPerror(OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
380 OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
381 return 0; 374 return 0;
382 } else { 375 } else {
383 t_tmp = t_now - nsec; 376 t_tmp = t_now - nsec;
384 if (gmtime_r(&t_tmp, &tm_tmp) == NULL) 377 if (gmtime_r(&t_tmp, &tm_tmp) == NULL)
385 return 0; 378 return 0;
386 if (ASN1_time_tm_cmp(&tm_next, &tm_tmp) < 0) { 379 if (ASN1_time_tm_cmp(&tm_next, &tm_tmp) < 0) {
387 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 380 OCSPerror(OCSP_R_STATUS_EXPIRED);
388 OCSP_R_STATUS_EXPIRED);
389 return 0; 381 return 0;
390 } 382 }
391 } 383 }
392 384
393 /* Also don't allow nextUpdate to precede thisUpdate */ 385 /* Also don't allow nextUpdate to precede thisUpdate */
394 if (ASN1_time_tm_cmp(&tm_next, &tm_this) < 0) { 386 if (ASN1_time_tm_cmp(&tm_next, &tm_this) < 0) {
395 OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, 387 OCSPerror(OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
396 OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
397 return 0; 388 return 0;
398 } 389 }
399 390
diff --git a/src/lib/libcrypto/ocsp/ocsp_err.c b/src/lib/libcrypto/ocsp/ocsp_err.c
index af781074b6..9e3237f6a4 100644
--- a/src/lib/libcrypto/ocsp/ocsp_err.c
+++ b/src/lib/libcrypto/ocsp/ocsp_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_err.c,v 1.7 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: ocsp_err.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,25 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OCSP,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_OCSP,0,reason)
73 73
74static ERR_STRING_DATA OCSP_str_functs[]= { 74static ERR_STRING_DATA OCSP_str_functs[]= {
75 {ERR_FUNC(OCSP_F_ASN1_STRING_ENCODE), "ASN1_STRING_encode"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(OCSP_F_D2I_OCSP_NONCE), "D2I_OCSP_NONCE"},
77 {ERR_FUNC(OCSP_F_OCSP_BASIC_ADD1_STATUS), "OCSP_basic_add1_status"},
78 {ERR_FUNC(OCSP_F_OCSP_BASIC_SIGN), "OCSP_basic_sign"},
79 {ERR_FUNC(OCSP_F_OCSP_BASIC_VERIFY), "OCSP_basic_verify"},
80 {ERR_FUNC(OCSP_F_OCSP_CERT_ID_NEW), "OCSP_cert_id_new"},
81 {ERR_FUNC(OCSP_F_OCSP_CHECK_DELEGATED), "OCSP_CHECK_DELEGATED"},
82 {ERR_FUNC(OCSP_F_OCSP_CHECK_IDS), "OCSP_CHECK_IDS"},
83 {ERR_FUNC(OCSP_F_OCSP_CHECK_ISSUER), "OCSP_CHECK_ISSUER"},
84 {ERR_FUNC(OCSP_F_OCSP_CHECK_VALIDITY), "OCSP_check_validity"},
85 {ERR_FUNC(OCSP_F_OCSP_MATCH_ISSUERID), "OCSP_MATCH_ISSUERID"},
86 {ERR_FUNC(OCSP_F_OCSP_PARSE_URL), "OCSP_parse_url"},
87 {ERR_FUNC(OCSP_F_OCSP_REQUEST_SIGN), "OCSP_request_sign"},
88 {ERR_FUNC(OCSP_F_OCSP_REQUEST_VERIFY), "OCSP_request_verify"},
89 {ERR_FUNC(OCSP_F_OCSP_RESPONSE_GET1_BASIC), "OCSP_response_get1_basic"},
90 {ERR_FUNC(OCSP_F_OCSP_SENDREQ_BIO), "OCSP_sendreq_bio"},
91 {ERR_FUNC(OCSP_F_OCSP_SENDREQ_NBIO), "OCSP_sendreq_nbio"},
92 {ERR_FUNC(OCSP_F_PARSE_HTTP_LINE1), "PARSE_HTTP_LINE1"},
93 {ERR_FUNC(OCSP_F_REQUEST_VERIFY), "REQUEST_VERIFY"},
94 {0, NULL} 76 {0, NULL}
95}; 77};
96 78
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c
index 61af3717b7..b9c969928a 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ht.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ht.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_ht.c,v 1.23 2016/11/05 15:21:20 miod Exp $ */ 1/* $OpenBSD: ocsp_ht.c,v 1.24 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -207,8 +207,7 @@ parse_http_line1(char *line)
207 for (p = line; *p && !isspace((unsigned char)*p); p++) 207 for (p = line; *p && !isspace((unsigned char)*p); p++)
208 continue; 208 continue;
209 if (!*p) { 209 if (!*p) {
210 OCSPerr(OCSP_F_PARSE_HTTP_LINE1, 210 OCSPerror(OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
211 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
212 return 0; 211 return 0;
213 } 212 }
214 213
@@ -216,8 +215,7 @@ parse_http_line1(char *line)
216 while (*p && isspace((unsigned char)*p)) 215 while (*p && isspace((unsigned char)*p))
217 p++; 216 p++;
218 if (!*p) { 217 if (!*p) {
219 OCSPerr(OCSP_F_PARSE_HTTP_LINE1, 218 OCSPerror(OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
220 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
221 return 0; 219 return 0;
222 } 220 }
223 221
@@ -225,8 +223,7 @@ parse_http_line1(char *line)
225 for (q = p; *q && !isspace((unsigned char)*q); q++) 223 for (q = p; *q && !isspace((unsigned char)*q); q++)
226 continue; 224 continue;
227 if (!*q) { 225 if (!*q) {
228 OCSPerr(OCSP_F_PARSE_HTTP_LINE1, 226 OCSPerror(OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
229 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
230 return 0; 227 return 0;
231 } 228 }
232 229
@@ -251,7 +248,7 @@ parse_http_line1(char *line)
251 *r = 0; 248 *r = 0;
252 } 249 }
253 if (retcode != 200) { 250 if (retcode != 200) {
254 OCSPerr(OCSP_F_PARSE_HTTP_LINE1, OCSP_R_SERVER_RESPONSE_ERROR); 251 OCSPerror(OCSP_R_SERVER_RESPONSE_ERROR);
255 if (!*q) 252 if (!*q)
256 ERR_asprintf_error_data("Code=%s", p); 253 ERR_asprintf_error_data("Code=%s", p);
257 else 254 else
diff --git a/src/lib/libcrypto/ocsp/ocsp_lib.c b/src/lib/libcrypto/ocsp/ocsp_lib.c
index 4a109b5513..d56a002096 100644
--- a/src/lib/libcrypto/ocsp/ocsp_lib.c
+++ b/src/lib/libcrypto/ocsp/ocsp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_lib.c,v 1.19 2016/12/21 18:13:59 beck Exp $ */ 1/* $OpenBSD: ocsp_lib.c,v 1.20 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL 2/* Written by Tom Titchener <Tom_Titchener@groove.net> for the OpenSSL
3 * project. */ 3 * project. */
4 4
@@ -115,7 +115,7 @@ OCSP_cert_id_new(const EVP_MD *dgst, X509_NAME *issuerName,
115 if (alg->algorithm != NULL) 115 if (alg->algorithm != NULL)
116 ASN1_OBJECT_free(alg->algorithm); 116 ASN1_OBJECT_free(alg->algorithm);
117 if ((nid = EVP_MD_type(dgst)) == NID_undef) { 117 if ((nid = EVP_MD_type(dgst)) == NID_undef) {
118 OCSPerr(OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_UNKNOWN_NID); 118 OCSPerror(OCSP_R_UNKNOWN_NID);
119 goto err; 119 goto err;
120 } 120 }
121 if (!(alg->algorithm = OBJ_nid2obj(nid))) 121 if (!(alg->algorithm = OBJ_nid2obj(nid)))
@@ -144,7 +144,7 @@ OCSP_cert_id_new(const EVP_MD *dgst, X509_NAME *issuerName,
144 return cid; 144 return cid;
145 145
146digerr: 146digerr:
147 OCSPerr(OCSP_F_OCSP_CERT_ID_NEW, OCSP_R_DIGEST_ERR); 147 OCSPerror(OCSP_R_DIGEST_ERR);
148err: 148err:
149 if (cid) 149 if (cid)
150 OCSP_CERTID_free(cid); 150 OCSP_CERTID_free(cid);
@@ -193,11 +193,11 @@ OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
193 } else if (strncmp(url, "http://", 7) == 0) 193 } else if (strncmp(url, "http://", 7) == 0)
194 host = strdup(url + 7); 194 host = strdup(url + 7);
195 else { 195 else {
196 OCSPerr(OCSP_F_OCSP_PARSE_URL, OCSP_R_ERROR_PARSING_URL); 196 OCSPerror(OCSP_R_ERROR_PARSING_URL);
197 return 0; 197 return 0;
198 } 198 }
199 if (host == NULL) { 199 if (host == NULL) {
200 OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE); 200 OCSPerror(ERR_R_MALLOC_FAILURE);
201 return 0; 201 return 0;
202 } 202 }
203 203
@@ -221,7 +221,7 @@ OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
221 free(host); 221 free(host);
222 free(path); 222 free(path);
223 free(port); 223 free(port);
224 OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE); 224 OCSPerror(ERR_R_MALLOC_FAILURE);
225 return 0; 225 return 0;
226 } 226 }
227 227
diff --git a/src/lib/libcrypto/ocsp/ocsp_srv.c b/src/lib/libcrypto/ocsp/ocsp_srv.c
index ee4a5dd6db..a9e0aaab2f 100644
--- a/src/lib/libcrypto/ocsp/ocsp_srv.c
+++ b/src/lib/libcrypto/ocsp/ocsp_srv.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_srv.c,v 1.9 2016/12/30 15:31:58 jsing Exp $ */ 1/* $OpenBSD: ocsp_srv.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -168,8 +168,7 @@ OCSP_basic_add1_status(OCSP_BASICRESP *rsp, OCSP_CERTID *cid, int status,
168 switch (cs->type = status) { 168 switch (cs->type = status) {
169 case V_OCSP_CERTSTATUS_REVOKED: 169 case V_OCSP_CERTSTATUS_REVOKED:
170 if (!revtime) { 170 if (!revtime) {
171 OCSPerr(OCSP_F_OCSP_BASIC_ADD1_STATUS, 171 OCSPerror(OCSP_R_NO_REVOKED_TIME);
172 OCSP_R_NO_REVOKED_TIME);
173 goto err; 172 goto err;
174 } 173 }
175 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new())) 174 if (!(cs->value.revoked = ri = OCSP_REVOKEDINFO_new()))
@@ -226,8 +225,7 @@ OCSP_basic_sign(OCSP_BASICRESP *brsp, X509 *signer, EVP_PKEY *key,
226 OCSP_RESPID *rid; 225 OCSP_RESPID *rid;
227 226
228 if (!X509_check_private_key(signer, key)) { 227 if (!X509_check_private_key(signer, key)) {
229 OCSPerr(OCSP_F_OCSP_BASIC_SIGN, 228 OCSPerror(OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
230 OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
231 goto err; 229 goto err;
232 } 230 }
233 231
diff --git a/src/lib/libcrypto/ocsp/ocsp_vfy.c b/src/lib/libcrypto/ocsp/ocsp_vfy.c
index 80dd54e958..ebdd826878 100644
--- a/src/lib/libcrypto/ocsp/ocsp_vfy.c
+++ b/src/lib/libcrypto/ocsp/ocsp_vfy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ocsp_vfy.c,v 1.14 2016/11/05 13:27:53 miod Exp $ */ 1/* $OpenBSD: ocsp_vfy.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -86,8 +86,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
86 86
87 ret = ocsp_find_signer(&signer, bs, certs, st, flags); 87 ret = ocsp_find_signer(&signer, bs, certs, st, flags);
88 if (!ret) { 88 if (!ret) {
89 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, 89 OCSPerror(OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
90 OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
91 goto end; 90 goto end;
92 } 91 }
93 if ((ret == 2) && (flags & OCSP_TRUSTOTHER)) 92 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
@@ -101,8 +100,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
101 EVP_PKEY_free(skey); 100 EVP_PKEY_free(skey);
102 } 101 }
103 if (!skey || ret <= 0) { 102 if (!skey || ret <= 0) {
104 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, 103 OCSPerror(OCSP_R_SIGNATURE_FAILURE);
105 OCSP_R_SIGNATURE_FAILURE);
106 goto end; 104 goto end;
107 } 105 }
108 } 106 }
@@ -116,8 +114,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
116 for (i = 0; i < sk_X509_num(certs); i++) { 114 for (i = 0; i < sk_X509_num(certs); i++) {
117 if (!sk_X509_push(untrusted, 115 if (!sk_X509_push(untrusted,
118 sk_X509_value(certs, i))) { 116 sk_X509_value(certs, i))) {
119 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, 117 OCSPerror(ERR_R_MALLOC_FAILURE);
120 ERR_R_MALLOC_FAILURE);
121 goto end; 118 goto end;
122 } 119 }
123 } 120 }
@@ -126,7 +123,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
126 init_res = X509_STORE_CTX_init(&ctx, st, signer, untrusted); 123 init_res = X509_STORE_CTX_init(&ctx, st, signer, untrusted);
127 if (!init_res) { 124 if (!init_res) {
128 ret = -1; 125 ret = -1;
129 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, ERR_R_X509_LIB); 126 OCSPerror(ERR_R_X509_LIB);
130 goto end; 127 goto end;
131 } 128 }
132 129
@@ -141,8 +138,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
141 X509_STORE_CTX_cleanup(&ctx); 138 X509_STORE_CTX_cleanup(&ctx);
142 if (ret <= 0) { 139 if (ret <= 0) {
143 i = X509_STORE_CTX_get_error(&ctx); 140 i = X509_STORE_CTX_get_error(&ctx);
144 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, 141 OCSPerror(OCSP_R_CERTIFICATE_VERIFY_ERROR);
145 OCSP_R_CERTIFICATE_VERIFY_ERROR);
146 ERR_asprintf_error_data("Verify error:%s", 142 ERR_asprintf_error_data("Verify error:%s",
147 X509_verify_cert_error_string(i)); 143 X509_verify_cert_error_string(i));
148 goto end; 144 goto end;
@@ -169,8 +165,7 @@ OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, X509_STORE *st,
169 x = sk_X509_value(chain, sk_X509_num(chain) - 1); 165 x = sk_X509_value(chain, sk_X509_num(chain) - 1);
170 if (X509_check_trust(x, NID_OCSP_sign, 0) != 166 if (X509_check_trust(x, NID_OCSP_sign, 0) !=
171 X509_TRUST_TRUSTED) { 167 X509_TRUST_TRUSTED) {
172 OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, 168 OCSPerror(OCSP_R_ROOT_CA_NOT_TRUSTED);
173 OCSP_R_ROOT_CA_NOT_TRUSTED);
174 goto end; 169 goto end;
175 } 170 }
176 ret = 1; 171 ret = 1;
@@ -245,8 +240,7 @@ ocsp_check_issuer(OCSP_BASICRESP *bs, STACK_OF(X509) *chain,
245 sresp = bs->tbsResponseData->responses; 240 sresp = bs->tbsResponseData->responses;
246 241
247 if (sk_X509_num(chain) <= 0) { 242 if (sk_X509_num(chain) <= 0) {
248 OCSPerr(OCSP_F_OCSP_CHECK_ISSUER, 243 OCSPerror(OCSP_R_NO_CERTIFICATES_IN_CHAIN);
249 OCSP_R_NO_CERTIFICATES_IN_CHAIN);
250 return -1; 244 return -1;
251 } 245 }
252 246
@@ -288,8 +282,7 @@ ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret)
288 282
289 idcount = sk_OCSP_SINGLERESP_num(sresp); 283 idcount = sk_OCSP_SINGLERESP_num(sresp);
290 if (idcount <= 0) { 284 if (idcount <= 0) {
291 OCSPerr(OCSP_F_OCSP_CHECK_IDS, 285 OCSPerror(OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
292 OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
293 return -1; 286 return -1;
294 } 287 }
295 288
@@ -323,8 +316,7 @@ ocsp_match_issuerid(X509 *cert, OCSP_CERTID *cid,
323 316
324 if (!(dgst = 317 if (!(dgst =
325 EVP_get_digestbyobj(cid->hashAlgorithm->algorithm))) { 318 EVP_get_digestbyobj(cid->hashAlgorithm->algorithm))) {
326 OCSPerr(OCSP_F_OCSP_MATCH_ISSUERID, 319 OCSPerror(OCSP_R_UNKNOWN_MESSAGE_DIGEST);
327 OCSP_R_UNKNOWN_MESSAGE_DIGEST);
328 return -1; 320 return -1;
329 } 321 }
330 322
@@ -365,7 +357,7 @@ ocsp_check_delegated(X509 *x, int flags)
365 X509_check_purpose(x, -1, 0); 357 X509_check_purpose(x, -1, 0);
366 if ((x->ex_flags & EXFLAG_XKUSAGE) && (x->ex_xkusage & XKU_OCSP_SIGN)) 358 if ((x->ex_flags & EXFLAG_XKUSAGE) && (x->ex_xkusage & XKU_OCSP_SIGN))
367 return 1; 359 return 1;
368 OCSPerr(OCSP_F_OCSP_CHECK_DELEGATED, OCSP_R_MISSING_OCSPSIGNING_USAGE); 360 OCSPerror(OCSP_R_MISSING_OCSPSIGNING_USAGE);
369 return 0; 361 return 0;
370} 362}
371 363
@@ -384,20 +376,18 @@ OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store,
384 X509_STORE_CTX ctx; 376 X509_STORE_CTX ctx;
385 377
386 if (!req->optionalSignature) { 378 if (!req->optionalSignature) {
387 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_REQUEST_NOT_SIGNED); 379 OCSPerror(OCSP_R_REQUEST_NOT_SIGNED);
388 return 0; 380 return 0;
389 } 381 }
390 gen = req->tbsRequest->requestorName; 382 gen = req->tbsRequest->requestorName;
391 if (!gen || gen->type != GEN_DIRNAME) { 383 if (!gen || gen->type != GEN_DIRNAME) {
392 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, 384 OCSPerror(OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
393 OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
394 return 0; 385 return 0;
395 } 386 }
396 nm = gen->d.directoryName; 387 nm = gen->d.directoryName;
397 ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags); 388 ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags);
398 if (ret <= 0) { 389 if (ret <= 0) {
399 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, 390 OCSPerror(OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
400 OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
401 return 0; 391 return 0;
402 } 392 }
403 if ((ret == 2) && (flags & OCSP_TRUSTOTHER)) 393 if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
@@ -409,8 +399,7 @@ OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store,
409 ret = OCSP_REQUEST_verify(req, skey); 399 ret = OCSP_REQUEST_verify(req, skey);
410 EVP_PKEY_free(skey); 400 EVP_PKEY_free(skey);
411 if (ret <= 0) { 401 if (ret <= 0) {
412 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, 402 OCSPerror(OCSP_R_SIGNATURE_FAILURE);
413 OCSP_R_SIGNATURE_FAILURE);
414 return 0; 403 return 0;
415 } 404 }
416 } 405 }
@@ -424,7 +413,7 @@ OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store,
424 init_res = X509_STORE_CTX_init(&ctx, store, signer, 413 init_res = X509_STORE_CTX_init(&ctx, store, signer,
425 req->optionalSignature->certs); 414 req->optionalSignature->certs);
426 if (!init_res) { 415 if (!init_res) {
427 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, ERR_R_X509_LIB); 416 OCSPerror(ERR_R_X509_LIB);
428 return 0; 417 return 0;
429 } 418 }
430 419
@@ -439,8 +428,7 @@ OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store,
439 X509_STORE_CTX_cleanup(&ctx); 428 X509_STORE_CTX_cleanup(&ctx);
440 if (ret <= 0) { 429 if (ret <= 0) {
441 ret = X509_STORE_CTX_get_error(&ctx); 430 ret = X509_STORE_CTX_get_error(&ctx);
442 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, 431 OCSPerror(OCSP_R_CERTIFICATE_VERIFY_ERROR);
443 OCSP_R_CERTIFICATE_VERIFY_ERROR);
444 ERR_asprintf_error_data("Verify error:%s", 432 ERR_asprintf_error_data("Verify error:%s",
445 X509_verify_cert_error_string(ret)); 433 X509_verify_cert_error_string(ret));
446 return 0; 434 return 0;
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index c3d0fa3576..8d3c278b54 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_err.c,v 1.11 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: pem_err.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,46 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason)
73 73
74static ERR_STRING_DATA PEM_str_functs[] = { 74static ERR_STRING_DATA PEM_str_functs[] = {
75 {ERR_FUNC(PEM_F_B2I_DSS), "B2I_DSS"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(PEM_F_B2I_PVK_BIO), "b2i_PVK_bio"},
77 {ERR_FUNC(PEM_F_B2I_RSA), "B2I_RSA"},
78 {ERR_FUNC(PEM_F_CHECK_BITLEN_DSA), "CHECK_BITLEN_DSA"},
79 {ERR_FUNC(PEM_F_CHECK_BITLEN_RSA), "CHECK_BITLEN_RSA"},
80 {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
81 {ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
82 {ERR_FUNC(PEM_F_DO_B2I), "DO_B2I"},
83 {ERR_FUNC(PEM_F_DO_B2I_BIO), "DO_B2I_BIO"},
84 {ERR_FUNC(PEM_F_DO_BLOB_HEADER), "DO_BLOB_HEADER"},
85 {ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"},
86 {ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"},
87 {ERR_FUNC(PEM_F_DO_PVK_BODY), "DO_PVK_BODY"},
88 {ERR_FUNC(PEM_F_DO_PVK_HEADER), "DO_PVK_HEADER"},
89 {ERR_FUNC(PEM_F_I2B_PVK), "I2B_PVK"},
90 {ERR_FUNC(PEM_F_I2B_PVK_BIO), "i2b_PVK_bio"},
91 {ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
92 {ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
93 {ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
94 {ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"},
95 {ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"},
96 {ERR_FUNC(PEM_F_PEM_DEF_CALLBACK), "PEM_def_callback"},
97 {ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"},
98 {ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
99 {ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"},
100 {ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"},
101 {ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
102 {ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
103 {ERR_FUNC(PEM_F_PEM_READ_BIO_PARAMETERS), "PEM_read_bio_Parameters"},
104 {ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"},
105 {ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"},
106 {ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
107 {ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"},
108 {ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
109 {ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
110 {ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
111 {ERR_FUNC(PEM_F_PEM_WRITE_PRIVATEKEY), "PEM_WRITE_PRIVATEKEY"},
112 {ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
113 {ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
114 {ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
115 {0, NULL} 76 {0, NULL}
116}; 77};
117 78
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 191e3b5b10..f02aaa8bb4 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_info.c,v 1.21 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: pem_info.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -83,7 +83,7 @@ PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
83 STACK_OF(X509_INFO) *ret; 83 STACK_OF(X509_INFO) *ret;
84 84
85 if ((b = BIO_new(BIO_s_file())) == NULL) { 85 if ((b = BIO_new(BIO_s_file())) == NULL) {
86 PEMerr(PEM_F_PEM_X509_INFO_READ, ERR_R_BUF_LIB); 86 PEMerror(ERR_R_BUF_LIB);
87 return (0); 87 return (0);
88 } 88 }
89 BIO_set_fp(b, fp, BIO_NOCLOSE); 89 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -109,8 +109,7 @@ PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
109 109
110 if (sk == NULL) { 110 if (sk == NULL) {
111 if ((ret = sk_X509_INFO_new_null()) == NULL) { 111 if ((ret = sk_X509_INFO_new_null()) == NULL) {
112 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, 112 PEMerror(ERR_R_MALLOC_FAILURE);
113 ERR_R_MALLOC_FAILURE);
114 return 0; 113 return 0;
115 } 114 }
116 } else 115 } else
@@ -249,13 +248,11 @@ start:
249 if (ptype) { 248 if (ptype) {
250 if (!d2i_PrivateKey(ptype, pp, &p, 249 if (!d2i_PrivateKey(ptype, pp, &p,
251 len)) { 250 len)) {
252 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, 251 PEMerror(ERR_R_ASN1_LIB);
253 ERR_R_ASN1_LIB);
254 goto err; 252 goto err;
255 } 253 }
256 } else if (d2i(pp, &p, len) == NULL) { 254 } else if (d2i(pp, &p, len) == NULL) {
257 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, 255 PEMerror(ERR_R_ASN1_LIB);
258 ERR_R_ASN1_LIB);
259 goto err; 256 goto err;
260 } 257 }
261 } else { /* encrypted RSA data */ 258 } else { /* encrypted RSA data */
@@ -323,8 +320,7 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
323 if (enc != NULL) { 320 if (enc != NULL) {
324 objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc)); 321 objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc));
325 if (objstr == NULL) { 322 if (objstr == NULL) {
326 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, 323 PEMerror(PEM_R_UNSUPPORTED_CIPHER);
327 PEM_R_UNSUPPORTED_CIPHER);
328 goto err; 324 goto err;
329 } 325 }
330 } 326 }
@@ -337,8 +333,7 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
337 if (xi->x_pkey != NULL) { 333 if (xi->x_pkey != NULL) {
338 if ((xi->enc_data != NULL) && (xi->enc_len > 0) ) { 334 if ((xi->enc_data != NULL) && (xi->enc_len > 0) ) {
339 if (enc == NULL) { 335 if (enc == NULL) {
340 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, 336 PEMerror(PEM_R_CIPHER_IS_NULL);
341 PEM_R_CIPHER_IS_NULL);
342 goto err; 337 goto err;
343 } 338 }
344 339
@@ -355,16 +350,14 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
355 objstr = OBJ_nid2sn( 350 objstr = OBJ_nid2sn(
356 EVP_CIPHER_nid(xi->enc_cipher.cipher)); 351 EVP_CIPHER_nid(xi->enc_cipher.cipher));
357 if (objstr == NULL) { 352 if (objstr == NULL) {
358 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, 353 PEMerror(PEM_R_UNSUPPORTED_CIPHER);
359 PEM_R_UNSUPPORTED_CIPHER);
360 goto err; 354 goto err;
361 } 355 }
362 356
363 /* create the right magic header stuff */ 357 /* create the right magic header stuff */
364 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > 358 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 >
365 sizeof buf) { 359 sizeof buf) {
366 PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, 360 PEMerror(ASN1_R_BUFFER_TOO_SMALL);
367 ASN1_R_BUFFER_TOO_SMALL);
368 goto err; 361 goto err;
369 } 362 }
370 buf[0] = '\0'; 363 buf[0] = '\0';
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 7178c8744f..b2c72e1d76 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_lib.c,v 1.43 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.44 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -112,8 +112,7 @@ PEM_def_callback(char *buf, int num, int w, void *key)
112 for (;;) { 112 for (;;) {
113 i = EVP_read_pw_string_min(buf, MIN_LENGTH, num, prompt, w); 113 i = EVP_read_pw_string_min(buf, MIN_LENGTH, num, prompt, w);
114 if (i != 0) { 114 if (i != 0) {
115 PEMerr(PEM_F_PEM_DEF_CALLBACK, 115 PEMerror(PEM_R_PROBLEMS_GETTING_PASSWORD);
116 PEM_R_PROBLEMS_GETTING_PASSWORD);
117 memset(buf, 0, num); 116 memset(buf, 0, num);
118 return (-1); 117 return (-1);
119 } 118 }
@@ -176,7 +175,7 @@ PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x,
176 void *ret; 175 void *ret;
177 176
178 if ((b = BIO_new(BIO_s_file())) == NULL) { 177 if ((b = BIO_new(BIO_s_file())) == NULL) {
179 PEMerr(PEM_F_PEM_ASN1_READ, ERR_R_BUF_LIB); 178 PEMerror(ERR_R_BUF_LIB);
180 return (0); 179 return (0);
181 } 180 }
182 BIO_set_fp(b, fp, BIO_NOCLOSE); 181 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -323,7 +322,7 @@ PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x,
323 int ret; 322 int ret;
324 323
325 if ((b = BIO_new(BIO_s_file())) == NULL) { 324 if ((b = BIO_new(BIO_s_file())) == NULL) {
326 PEMerr(PEM_F_PEM_ASN1_WRITE, ERR_R_BUF_LIB); 325 PEMerror(ERR_R_BUF_LIB);
327 return (0); 326 return (0);
328 } 327 }
329 BIO_set_fp(b, fp, BIO_NOCLOSE); 328 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -348,14 +347,13 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
348 if (enc != NULL) { 347 if (enc != NULL) {
349 objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc)); 348 objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc));
350 if (objstr == NULL) { 349 if (objstr == NULL) {
351 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, 350 PEMerror(PEM_R_UNSUPPORTED_CIPHER);
352 PEM_R_UNSUPPORTED_CIPHER);
353 goto err; 351 goto err;
354 } 352 }
355 } 353 }
356 354
357 if ((dsize = i2d(x, NULL)) < 0) { 355 if ((dsize = i2d(x, NULL)) < 0) {
358 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, ERR_R_ASN1_LIB); 356 PEMerror(ERR_R_ASN1_LIB);
359 dsize = 0; 357 dsize = 0;
360 goto err; 358 goto err;
361 } 359 }
@@ -363,7 +361,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
363 /* actually it needs the cipher block size extra... */ 361 /* actually it needs the cipher block size extra... */
364 data = malloc(dsize + 20); 362 data = malloc(dsize + 20);
365 if (data == NULL) { 363 if (data == NULL) {
366 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, ERR_R_MALLOC_FAILURE); 364 PEMerror(ERR_R_MALLOC_FAILURE);
367 goto err; 365 goto err;
368 } 366 }
369 p = data; 367 p = data;
@@ -376,14 +374,13 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
376 else 374 else
377 klen = (*callback)(buf, PEM_BUFSIZE, 1, u); 375 klen = (*callback)(buf, PEM_BUFSIZE, 1, u);
378 if (klen <= 0) { 376 if (klen <= 0) {
379 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, 377 PEMerror(PEM_R_READ_KEY);
380 PEM_R_READ_KEY);
381 goto err; 378 goto err;
382 } 379 }
383 kstr = (unsigned char *)buf; 380 kstr = (unsigned char *)buf;
384 } 381 }
385 if ((size_t)enc->iv_len > sizeof(iv)) { 382 if ((size_t)enc->iv_len > sizeof(iv)) {
386 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, EVP_R_IV_TOO_LARGE); 383 PEMerror(EVP_R_IV_TOO_LARGE);
387 goto err; 384 goto err;
388 } 385 }
389 arc4random_buf(iv, enc->iv_len); /* Generate a salt */ 386 arc4random_buf(iv, enc->iv_len); /* Generate a salt */
@@ -397,8 +394,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
397 explicit_bzero(buf, PEM_BUFSIZE); 394 explicit_bzero(buf, PEM_BUFSIZE);
398 395
399 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) { 396 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) {
400 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, 397 PEMerror(ASN1_R_BUFFER_TOO_SMALL);
401 ASN1_R_BUFFER_TOO_SMALL);
402 goto err; 398 goto err;
403 } 399 }
404 400
@@ -455,7 +451,7 @@ PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
455 else 451 else
456 klen = callback(buf, PEM_BUFSIZE, 0, u); 452 klen = callback(buf, PEM_BUFSIZE, 0, u);
457 if (klen <= 0) { 453 if (klen <= 0) {
458 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_PASSWORD_READ); 454 PEMerror(PEM_R_BAD_PASSWORD_READ);
459 return (0); 455 return (0);
460 } 456 }
461 if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]), 457 if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]),
@@ -474,7 +470,7 @@ PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
474 explicit_bzero((char *)buf, sizeof(buf)); 470 explicit_bzero((char *)buf, sizeof(buf));
475 explicit_bzero((char *)key, sizeof(key)); 471 explicit_bzero((char *)key, sizeof(key));
476 if (!o) { 472 if (!o) {
477 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT); 473 PEMerror(PEM_R_BAD_DECRYPT);
478 return (0); 474 return (0);
479 } 475 }
480 *plen = j + i; 476 *plen = j + i;
@@ -492,7 +488,7 @@ PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
492 if ((header == NULL) || (*header == '\0') || (*header == '\n')) 488 if ((header == NULL) || (*header == '\0') || (*header == '\n'))
493 return (1); 489 return (1);
494 if (strncmp(header, "Proc-Type: ", 11) != 0) { 490 if (strncmp(header, "Proc-Type: ", 11) != 0) {
495 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_PROC_TYPE); 491 PEMerror(PEM_R_NOT_PROC_TYPE);
496 return (0); 492 return (0);
497 } 493 }
498 header += 11; 494 header += 11;
@@ -503,18 +499,18 @@ PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
503 return (0); 499 return (0);
504 header++; 500 header++;
505 if (strncmp(header, "ENCRYPTED", 9) != 0) { 501 if (strncmp(header, "ENCRYPTED", 9) != 0) {
506 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_ENCRYPTED); 502 PEMerror(PEM_R_NOT_ENCRYPTED);
507 return (0); 503 return (0);
508 } 504 }
509 for (; (*header != '\n') && (*header != '\0'); header++) 505 for (; (*header != '\n') && (*header != '\0'); header++)
510 ; 506 ;
511 if (*header == '\0') { 507 if (*header == '\0') {
512 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_SHORT_HEADER); 508 PEMerror(PEM_R_SHORT_HEADER);
513 return (0); 509 return (0);
514 } 510 }
515 header++; 511 header++;
516 if (strncmp(header, "DEK-Info: ", 10) != 0) { 512 if (strncmp(header, "DEK-Info: ", 10) != 0) {
517 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, PEM_R_NOT_DEK_INFO); 513 PEMerror(PEM_R_NOT_DEK_INFO);
518 return (0); 514 return (0);
519 } 515 }
520 header += 10; 516 header += 10;
@@ -533,8 +529,7 @@ PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
533 header++; 529 header++;
534 530
535 if (enc == NULL) { 531 if (enc == NULL) {
536 PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO, 532 PEMerror(PEM_R_UNSUPPORTED_ENCRYPTION);
537 PEM_R_UNSUPPORTED_ENCRYPTION);
538 return (0); 533 return (0);
539 } 534 }
540 if (!load_iv(header_pp, &(cipher->iv[0]), enc->iv_len)) 535 if (!load_iv(header_pp, &(cipher->iv[0]), enc->iv_len))
@@ -561,7 +556,7 @@ load_iv(char **fromp, unsigned char *to, int num)
561 else if ((*from >= 'a') && (*from <= 'f')) 556 else if ((*from >= 'a') && (*from <= 'f'))
562 v = *from - 'a' + 10; 557 v = *from - 'a' + 10;
563 else { 558 else {
564 PEMerr(PEM_F_LOAD_IV, PEM_R_BAD_IV_CHARS); 559 PEMerror(PEM_R_BAD_IV_CHARS);
565 return (0); 560 return (0);
566 } 561 }
567 from++; 562 from++;
@@ -579,7 +574,7 @@ PEM_write(FILE *fp, char *name, char *header, unsigned char *data, long len)
579 int ret; 574 int ret;
580 575
581 if ((b = BIO_new(BIO_s_file())) == NULL) { 576 if ((b = BIO_new(BIO_s_file())) == NULL) {
582 PEMerr(PEM_F_PEM_WRITE, ERR_R_BUF_LIB); 577 PEMerror(ERR_R_BUF_LIB);
583 return (0); 578 return (0);
584 } 579 }
585 BIO_set_fp(b, fp, BIO_NOCLOSE); 580 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -645,7 +640,7 @@ err:
645 explicit_bzero(buf, PEM_BUFSIZE * 8); 640 explicit_bzero(buf, PEM_BUFSIZE * 8);
646 free(buf); 641 free(buf);
647 } 642 }
648 PEMerr(PEM_F_PEM_WRITE_BIO, reason); 643 PEMerror(reason);
649 return (0); 644 return (0);
650} 645}
651 646
@@ -656,7 +651,7 @@ PEM_read(FILE *fp, char **name, char **header, unsigned char **data, long *len)
656 int ret; 651 int ret;
657 652
658 if ((b = BIO_new(BIO_s_file())) == NULL) { 653 if ((b = BIO_new(BIO_s_file())) == NULL) {
659 PEMerr(PEM_F_PEM_READ, ERR_R_BUF_LIB); 654 PEMerror(ERR_R_BUF_LIB);
660 return (0); 655 return (0);
661 } 656 }
662 BIO_set_fp(b, fp, BIO_NOCLOSE); 657 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -683,7 +678,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
683 BUF_MEM_free(nameB); 678 BUF_MEM_free(nameB);
684 BUF_MEM_free(headerB); 679 BUF_MEM_free(headerB);
685 BUF_MEM_free(dataB); 680 BUF_MEM_free(dataB);
686 PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE); 681 PEMerror(ERR_R_MALLOC_FAILURE);
687 return (0); 682 return (0);
688 } 683 }
689 684
@@ -692,7 +687,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
692 i = BIO_gets(bp, buf, 254); 687 i = BIO_gets(bp, buf, 254);
693 688
694 if (i <= 0) { 689 if (i <= 0) {
695 PEMerr(PEM_F_PEM_READ_BIO, PEM_R_NO_START_LINE); 690 PEMerror(PEM_R_NO_START_LINE);
696 goto err; 691 goto err;
697 } 692 }
698 693
@@ -707,8 +702,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
707 if (strncmp(&(buf[11 + i - 6]), "-----\n", 6) != 0) 702 if (strncmp(&(buf[11 + i - 6]), "-----\n", 6) != 0)
708 continue; 703 continue;
709 if (!BUF_MEM_grow(nameB, i + 9)) { 704 if (!BUF_MEM_grow(nameB, i + 9)) {
710 PEMerr(PEM_F_PEM_READ_BIO, 705 PEMerror(ERR_R_MALLOC_FAILURE);
711 ERR_R_MALLOC_FAILURE);
712 goto err; 706 goto err;
713 } 707 }
714 memcpy(nameB->data, &(buf[11]), i - 6); 708 memcpy(nameB->data, &(buf[11]), i - 6);
@@ -718,7 +712,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
718 } 712 }
719 hl = 0; 713 hl = 0;
720 if (!BUF_MEM_grow(headerB, 256)) { 714 if (!BUF_MEM_grow(headerB, 256)) {
721 PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE); 715 PEMerror(ERR_R_MALLOC_FAILURE);
722 goto err; 716 goto err;
723 } 717 }
724 headerB->data[0] = '\0'; 718 headerB->data[0] = '\0';
@@ -735,7 +729,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
735 if (buf[0] == '\n') 729 if (buf[0] == '\n')
736 break; 730 break;
737 if (!BUF_MEM_grow(headerB, hl + i + 9)) { 731 if (!BUF_MEM_grow(headerB, hl + i + 9)) {
738 PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE); 732 PEMerror(ERR_R_MALLOC_FAILURE);
739 goto err; 733 goto err;
740 } 734 }
741 if (strncmp(buf, "-----END ", 9) == 0) { 735 if (strncmp(buf, "-----END ", 9) == 0) {
@@ -749,7 +743,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
749 743
750 bl = 0; 744 bl = 0;
751 if (!BUF_MEM_grow(dataB, 1024)) { 745 if (!BUF_MEM_grow(dataB, 1024)) {
752 PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE); 746 PEMerror(ERR_R_MALLOC_FAILURE);
753 goto err; 747 goto err;
754 } 748 }
755 dataB->data[0] = '\0'; 749 dataB->data[0] = '\0';
@@ -771,8 +765,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
771 if (i > 65) 765 if (i > 65)
772 break; 766 break;
773 if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) { 767 if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) {
774 PEMerr(PEM_F_PEM_READ_BIO, 768 PEMerror(ERR_R_MALLOC_FAILURE);
775 ERR_R_MALLOC_FAILURE);
776 goto err; 769 goto err;
777 } 770 }
778 memcpy(&(dataB->data[bl]), buf, i); 771 memcpy(&(dataB->data[bl]), buf, i);
@@ -802,7 +795,7 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
802 if ((strncmp(buf, "-----END ", 9) != 0) || 795 if ((strncmp(buf, "-----END ", 9) != 0) ||
803 (strncmp(nameB->data, &(buf[9]), i) != 0) || 796 (strncmp(nameB->data, &(buf[9]), i) != 0) ||
804 (strncmp(&(buf[9 + i]), "-----\n", 6) != 0)) { 797 (strncmp(&(buf[9 + i]), "-----\n", 6) != 0)) {
805 PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_END_LINE); 798 PEMerror(PEM_R_BAD_END_LINE);
806 goto err; 799 goto err;
807 } 800 }
808 801
@@ -811,12 +804,12 @@ PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
811 (unsigned char *)dataB->data, &bl, 804 (unsigned char *)dataB->data, &bl,
812 (unsigned char *)dataB->data, bl); 805 (unsigned char *)dataB->data, bl);
813 if (i < 0) { 806 if (i < 0) {
814 PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_BASE64_DECODE); 807 PEMerror(PEM_R_BAD_BASE64_DECODE);
815 goto err; 808 goto err;
816 } 809 }
817 i = EVP_DecodeFinal(&ctx, (unsigned char *)&(dataB->data[bl]), &k); 810 i = EVP_DecodeFinal(&ctx, (unsigned char *)&(dataB->data[bl]), &k);
818 if (i < 0) { 811 if (i < 0) {
819 PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_BASE64_DECODE); 812 PEMerror(PEM_R_BAD_BASE64_DECODE);
820 goto err; 813 goto err;
821 } 814 }
822 bl += k; 815 bl += k;
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
index ccd2b893d5..21498cb6b5 100644
--- a/src/lib/libcrypto/pem/pem_oth.c
+++ b/src/lib/libcrypto/pem/pem_oth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_oth.c,v 1.7 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_oth.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -81,7 +81,7 @@ PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
81 p = data; 81 p = data;
82 ret = d2i(x, &p, len); 82 ret = d2i(x, &p, len);
83 if (ret == NULL) 83 if (ret == NULL)
84 PEMerr(PEM_F_PEM_ASN1_READ_BIO, ERR_R_ASN1_LIB); 84 PEMerror(ERR_R_ASN1_LIB);
85 free(data); 85 free(data);
86 return (ret); 86 return (ret);
87} 87}
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
index 4b3578f971..43581905f0 100644
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ b/src/lib/libcrypto/pem/pem_pk8.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pk8.c,v 1.12 2016/09/04 16:10:38 jsing Exp $ */ 1/* $OpenBSD: pem_pk8.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -116,8 +116,7 @@ do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
116 int ret; 116 int ret;
117 117
118 if (!(p8inf = EVP_PKEY2PKCS8(x))) { 118 if (!(p8inf = EVP_PKEY2PKCS8(x))) {
119 PEMerr(PEM_F_DO_PK8PKEY, 119 PEMerror(PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
120 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
121 return 0; 120 return 0;
122 } 121 }
123 if (enc || (nid != -1)) { 122 if (enc || (nid != -1)) {
@@ -127,7 +126,7 @@ do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
127 else 126 else
128 klen = cb(buf, PEM_BUFSIZE, 1, u); 127 klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if (klen <= 0) { 128 if (klen <= 0) {
130 PEMerr(PEM_F_DO_PK8PKEY, PEM_R_READ_KEY); 129 PEMerror(PEM_R_READ_KEY);
131 PKCS8_PRIV_KEY_INFO_free(p8inf); 130 PKCS8_PRIV_KEY_INFO_free(p8inf);
132 return 0; 131 return 0;
133 } 132 }
@@ -171,7 +170,7 @@ d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
171 else 170 else
172 klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u); 171 klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
173 if (klen <= 0) { 172 if (klen <= 0) {
174 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ); 173 PEMerror(PEM_R_BAD_PASSWORD_READ);
175 X509_SIG_free(p8); 174 X509_SIG_free(p8);
176 return NULL; 175 return NULL;
177 } 176 }
@@ -227,7 +226,7 @@ do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
227 int ret; 226 int ret;
228 227
229 if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { 228 if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
230 PEMerr(PEM_F_DO_PK8PKEY_FP, ERR_R_BUF_LIB); 229 PEMerror(ERR_R_BUF_LIB);
231 return (0); 230 return (0);
232 } 231 }
233 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u); 232 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
@@ -242,7 +241,7 @@ d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
242 EVP_PKEY *ret; 241 EVP_PKEY *ret;
243 242
244 if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { 243 if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
245 PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP, ERR_R_BUF_LIB); 244 PEMerror(ERR_R_BUF_LIB);
246 return NULL; 245 return NULL;
247 } 246 }
248 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u); 247 ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index afb476f818..6651ef9419 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pkey.c,v 1.21 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: pem_pkey.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -116,8 +116,7 @@ PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
116 else 116 else
117 klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u); 117 klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
118 if (klen <= 0) { 118 if (klen <= 0) {
119 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, 119 PEMerror(PEM_R_BAD_PASSWORD_READ);
120 PEM_R_BAD_PASSWORD_READ);
121 X509_SIG_free(p8); 120 X509_SIG_free(p8);
122 goto err; 121 goto err;
123 } 122 }
@@ -141,7 +140,7 @@ PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
141 140
142p8err: 141p8err:
143 if (ret == NULL) 142 if (ret == NULL)
144 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB); 143 PEMerror(ERR_R_ASN1_LIB);
145err: 144err:
146 free(nm); 145 free(nm);
147 explicit_bzero(data, len); 146 explicit_bzero(data, len);
@@ -199,7 +198,7 @@ PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
199 198
200err: 199err:
201 if (ret == NULL) 200 if (ret == NULL)
202 PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS, ERR_R_ASN1_LIB); 201 PEMerror(ERR_R_ASN1_LIB);
203 free(nm); 202 free(nm);
204 free(data); 203 free(data);
205 return (ret); 204 return (ret);
@@ -226,7 +225,7 @@ PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
226 EVP_PKEY *ret; 225 EVP_PKEY *ret;
227 226
228 if ((b = BIO_new(BIO_s_file())) == NULL) { 227 if ((b = BIO_new(BIO_s_file())) == NULL) {
229 PEMerr(PEM_F_PEM_READ_PRIVATEKEY, ERR_R_BUF_LIB); 228 PEMerror(ERR_R_BUF_LIB);
230 return (0); 229 return (0);
231 } 230 }
232 BIO_set_fp(b, fp, BIO_NOCLOSE); 231 BIO_set_fp(b, fp, BIO_NOCLOSE);
@@ -243,7 +242,7 @@ PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
243 int ret; 242 int ret;
244 243
245 if ((b = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) { 244 if ((b = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) {
246 PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY, ERR_R_BUF_LIB); 245 PEMerror(ERR_R_BUF_LIB);
247 return 0; 246 return 0;
248 } 247 }
249 ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u); 248 ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 79162b32d7..c6d61fff0f 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_seal.c,v 1.23 2016/11/05 11:32:45 miod Exp $ */ 1/* $OpenBSD: pem_seal.c,v 1.24 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -97,7 +97,7 @@ PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
97 97
98 for (i = 0; i < npubk; i++) { 98 for (i = 0; i < npubk; i++) {
99 if (pubk[i]->type != EVP_PKEY_RSA) { 99 if (pubk[i]->type != EVP_PKEY_RSA) {
100 PEMerr(PEM_F_PEM_SEALINIT, PEM_R_PUBLIC_KEY_NO_RSA); 100 PEMerror(PEM_R_PUBLIC_KEY_NO_RSA);
101 goto err; 101 goto err;
102 } 102 }
103 j = RSA_size(pubk[i]->pkey.rsa); 103 j = RSA_size(pubk[i]->pkey.rsa);
@@ -106,7 +106,7 @@ PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
106 } 106 }
107 s = reallocarray(NULL, max, 2); 107 s = reallocarray(NULL, max, 2);
108 if (s == NULL) { 108 if (s == NULL) {
109 PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE); 109 PEMerror(ERR_R_MALLOC_FAILURE);
110 goto err; 110 goto err;
111 } 111 }
112 112
@@ -170,7 +170,7 @@ PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
170 unsigned int i; 170 unsigned int i;
171 171
172 if (priv->type != EVP_PKEY_RSA) { 172 if (priv->type != EVP_PKEY_RSA) {
173 PEMerr(PEM_F_PEM_SEALFINAL, PEM_R_PUBLIC_KEY_NO_RSA); 173 PEMerror(PEM_R_PUBLIC_KEY_NO_RSA);
174 goto err; 174 goto err;
175 } 175 }
176 i = RSA_size(priv->pkey.rsa); 176 i = RSA_size(priv->pkey.rsa);
@@ -178,7 +178,7 @@ PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
178 i = 100; 178 i = 100;
179 s = reallocarray(NULL, i, 2); 179 s = reallocarray(NULL, i, 2);
180 if (s == NULL) { 180 if (s == NULL) {
181 PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE); 181 PEMerror(ERR_R_MALLOC_FAILURE);
182 goto err; 182 goto err;
183 } 183 }
184 184
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
index aab8c4d6b8..a225e8970f 100644
--- a/src/lib/libcrypto/pem/pem_sign.c
+++ b/src/lib/libcrypto/pem/pem_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_sign.c,v 1.12 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_sign.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -87,7 +87,7 @@ PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
87 87
88 m = malloc(EVP_PKEY_size(pkey) + 2); 88 m = malloc(EVP_PKEY_size(pkey) + 2);
89 if (m == NULL) { 89 if (m == NULL) {
90 PEMerr(PEM_F_PEM_SIGNFINAL, ERR_R_MALLOC_FAILURE); 90 PEMerror(ERR_R_MALLOC_FAILURE);
91 goto err; 91 goto err;
92 } 92 }
93 93
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c
index 0a33a24b9f..5ed8df585f 100644
--- a/src/lib/libcrypto/pem/pvkfmt.c
+++ b/src/lib/libcrypto/pem/pvkfmt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pvkfmt.c,v 1.17 2017/01/21 09:38:59 beck Exp $ */ 1/* $OpenBSD: pvkfmt.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -157,15 +157,13 @@ do_blob_header(const unsigned char **in, unsigned int length,
157 /* bType */ 157 /* bType */
158 if (*p == MS_PUBLICKEYBLOB) { 158 if (*p == MS_PUBLICKEYBLOB) {
159 if (*pispub == 0) { 159 if (*pispub == 0) {
160 PEMerr(PEM_F_DO_BLOB_HEADER, 160 PEMerror(PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
161 PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
162 return 0; 161 return 0;
163 } 162 }
164 *pispub = 1; 163 *pispub = 1;
165 } else if (*p == MS_PRIVATEKEYBLOB) { 164 } else if (*p == MS_PRIVATEKEYBLOB) {
166 if (*pispub == 1) { 165 if (*pispub == 1) {
167 PEMerr(PEM_F_DO_BLOB_HEADER, 166 PEMerror(PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
168 PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
169 return 0; 167 return 0;
170 } 168 }
171 *pispub = 0; 169 *pispub = 0;
@@ -174,7 +172,7 @@ do_blob_header(const unsigned char **in, unsigned int length,
174 p++; 172 p++;
175 /* Version */ 173 /* Version */
176 if (*p++ != 0x2) { 174 if (*p++ != 0x2) {
177 PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_VERSION_NUMBER); 175 PEMerror(PEM_R_BAD_VERSION_NUMBER);
178 return 0; 176 return 0;
179 } 177 }
180 /* Ignore reserved, aiKeyAlg */ 178 /* Ignore reserved, aiKeyAlg */
@@ -182,7 +180,7 @@ do_blob_header(const unsigned char **in, unsigned int length,
182 *pmagic = read_ledword(&p); 180 *pmagic = read_ledword(&p);
183 *pbitlen = read_ledword(&p); 181 *pbitlen = read_ledword(&p);
184 if (*pbitlen > 65536) { 182 if (*pbitlen > 65536) {
185 PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_INCONSISTENT_HEADER); 183 PEMerror(PEM_R_INCONSISTENT_HEADER);
186 return 0; 184 return 0;
187 } 185 }
188 *pisdss = 0; 186 *pisdss = 0;
@@ -192,8 +190,7 @@ do_blob_header(const unsigned char **in, unsigned int length,
192 *pisdss = 1; 190 *pisdss = 1;
193 case MS_RSA1MAGIC: 191 case MS_RSA1MAGIC:
194 if (*pispub == 0) { 192 if (*pispub == 0) {
195 PEMerr(PEM_F_DO_BLOB_HEADER, 193 PEMerror(PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
196 PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
197 return 0; 194 return 0;
198 } 195 }
199 break; 196 break;
@@ -202,14 +199,13 @@ do_blob_header(const unsigned char **in, unsigned int length,
202 *pisdss = 1; 199 *pisdss = 1;
203 case MS_RSA2MAGIC: 200 case MS_RSA2MAGIC:
204 if (*pispub == 1) { 201 if (*pispub == 1) {
205 PEMerr(PEM_F_DO_BLOB_HEADER, 202 PEMerror(PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
206 PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
207 return 0; 203 return 0;
208 } 204 }
209 break; 205 break;
210 206
211 default: 207 default:
212 PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_MAGIC_NUMBER); 208 PEMerror(PEM_R_BAD_MAGIC_NUMBER);
213 return -1; 209 return -1;
214 } 210 }
215 *in = p; 211 *in = p;
@@ -256,12 +252,12 @@ do_b2i(const unsigned char **in, unsigned int length, int ispub)
256 int isdss; 252 int isdss;
257 253
258 if (do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0) { 254 if (do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0) {
259 PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_HEADER_PARSE_ERROR); 255 PEMerror(PEM_R_KEYBLOB_HEADER_PARSE_ERROR);
260 return NULL; 256 return NULL;
261 } 257 }
262 length -= 16; 258 length -= 16;
263 if (length < blob_length(bitlen, isdss, ispub)) { 259 if (length < blob_length(bitlen, isdss, ispub)) {
264 PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_TOO_SHORT); 260 PEMerror(PEM_R_KEYBLOB_TOO_SHORT);
265 return NULL; 261 return NULL;
266 } 262 }
267 if (isdss) 263 if (isdss)
@@ -280,7 +276,7 @@ do_b2i_bio(BIO *in, int ispub)
280 EVP_PKEY *ret = NULL; 276 EVP_PKEY *ret = NULL;
281 277
282 if (BIO_read(in, hdr_buf, 16) != 16) { 278 if (BIO_read(in, hdr_buf, 16) != 16) {
283 PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT); 279 PEMerror(PEM_R_KEYBLOB_TOO_SHORT);
284 return NULL; 280 return NULL;
285 } 281 }
286 p = hdr_buf; 282 p = hdr_buf;
@@ -290,12 +286,12 @@ do_b2i_bio(BIO *in, int ispub)
290 length = blob_length(bitlen, isdss, ispub); 286 length = blob_length(bitlen, isdss, ispub);
291 buf = malloc(length); 287 buf = malloc(length);
292 if (!buf) { 288 if (!buf) {
293 PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE); 289 PEMerror(ERR_R_MALLOC_FAILURE);
294 goto err; 290 goto err;
295 } 291 }
296 p = buf; 292 p = buf;
297 if (BIO_read(in, buf, length) != (int)length) { 293 if (BIO_read(in, buf, length) != (int)length) {
298 PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT); 294 PEMerror(PEM_R_KEYBLOB_TOO_SHORT);
299 goto err; 295 goto err;
300 } 296 }
301 297
@@ -354,7 +350,7 @@ b2i_dss(const unsigned char **in, unsigned int length, unsigned int bitlen,
354 return ret; 350 return ret;
355 351
356memerr: 352memerr:
357 PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE); 353 PEMerror(ERR_R_MALLOC_FAILURE);
358 DSA_free(dsa); 354 DSA_free(dsa);
359 EVP_PKEY_free(ret); 355 EVP_PKEY_free(ret);
360 BN_CTX_free(ctx); 356 BN_CTX_free(ctx);
@@ -404,7 +400,7 @@ b2i_rsa(const unsigned char **in, unsigned int length, unsigned int bitlen,
404 return ret; 400 return ret;
405 401
406memerr: 402memerr:
407 PEMerr(PEM_F_B2I_RSA, ERR_R_MALLOC_FAILURE); 403 PEMerror(ERR_R_MALLOC_FAILURE);
408 RSA_free(rsa); 404 RSA_free(rsa);
409 EVP_PKEY_free(ret); 405 EVP_PKEY_free(ret);
410 return NULL; 406 return NULL;
@@ -566,7 +562,7 @@ check_bitlen_dsa(DSA *dsa, int ispub, unsigned int *pmagic)
566 return bitlen; 562 return bitlen;
567 563
568badkey: 564badkey:
569 PEMerr(PEM_F_CHECK_BITLEN_DSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS); 565 PEMerror(PEM_R_UNSUPPORTED_KEY_COMPONENTS);
570 return 0; 566 return 0;
571} 567}
572 568
@@ -600,7 +596,7 @@ check_bitlen_rsa(RSA *rsa, int ispub, unsigned int *pmagic)
600 return bitlen; 596 return bitlen;
601 597
602badkey: 598badkey:
603 PEMerr(PEM_F_CHECK_BITLEN_RSA, PEM_R_UNSUPPORTED_KEY_COMPONENTS); 599 PEMerror(PEM_R_UNSUPPORTED_KEY_COMPONENTS);
604 return 0; 600 return 0;
605} 601}
606 602
@@ -665,19 +661,19 @@ do_PVK_header(const unsigned char **in, unsigned int length, int skip_magic,
665 661
666 if (skip_magic) { 662 if (skip_magic) {
667 if (length < 20) { 663 if (length < 20) {
668 PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); 664 PEMerror(PEM_R_PVK_TOO_SHORT);
669 return 0; 665 return 0;
670 } 666 }
671 length -= 20; 667 length -= 20;
672 } else { 668 } else {
673 if (length < 24) { 669 if (length < 24) {
674 PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT); 670 PEMerror(PEM_R_PVK_TOO_SHORT);
675 return 0; 671 return 0;
676 } 672 }
677 length -= 24; 673 length -= 24;
678 pvk_magic = read_ledword(&p); 674 pvk_magic = read_ledword(&p);
679 if (pvk_magic != MS_PVKMAGIC) { 675 if (pvk_magic != MS_PVKMAGIC) {
680 PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER); 676 PEMerror(PEM_R_BAD_MAGIC_NUMBER);
681 return 0; 677 return 0;
682 } 678 }
683 } 679 }
@@ -688,12 +684,12 @@ do_PVK_header(const unsigned char **in, unsigned int length, int skip_magic,
688 *psaltlen = read_ledword(&p); 684 *psaltlen = read_ledword(&p);
689 *pkeylen = read_ledword(&p); 685 *pkeylen = read_ledword(&p);
690 if (*psaltlen > 65536 || *pkeylen > 65536) { 686 if (*psaltlen > 65536 || *pkeylen > 65536) {
691 PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_ERROR_CONVERTING_PRIVATE_KEY); 687 PEMerror(PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
692 return 0; 688 return 0;
693 } 689 }
694 690
695 if (is_encrypted && !*psaltlen) { 691 if (is_encrypted && !*psaltlen) {
696 PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER); 692 PEMerror(PEM_R_INCONSISTENT_HEADER);
697 return 0; 693 return 0;
698 } 694 }
699 695
@@ -740,12 +736,12 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
740 else 736 else
741 inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u); 737 inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
742 if (inlen <= 0) { 738 if (inlen <= 0) {
743 PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_PASSWORD_READ); 739 PEMerror(PEM_R_BAD_PASSWORD_READ);
744 goto err; 740 goto err;
745 } 741 }
746 enctmp = malloc(keylen + 8); 742 enctmp = malloc(keylen + 8);
747 if (!enctmp) { 743 if (!enctmp) {
748 PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE); 744 PEMerror(ERR_R_MALLOC_FAILURE);
749 goto err; 745 goto err;
750 } 746 }
751 if (!derive_pvk_key(keybuf, p, saltlen, (unsigned char *)psbuf, 747 if (!derive_pvk_key(keybuf, p, saltlen, (unsigned char *)psbuf,
@@ -757,7 +753,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
757 memcpy(enctmp, p, 8); 753 memcpy(enctmp, p, 8);
758 p += 8; 754 p += 8;
759 if (keylen < 8) { 755 if (keylen < 8) {
760 PEMerr(PEM_F_DO_PVK_BODY, PEM_R_PVK_TOO_SHORT); 756 PEMerror(PEM_R_PVK_TOO_SHORT);
761 goto err; 757 goto err;
762 } 758 }
763 inlen = keylen - 8; 759 inlen = keylen - 8;
@@ -783,7 +779,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
783 goto err; 779 goto err;
784 magic = read_ledword((const unsigned char **)&q); 780 magic = read_ledword((const unsigned char **)&q);
785 if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) { 781 if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC) {
786 PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT); 782 PEMerror(PEM_R_BAD_DECRYPT);
787 goto err; 783 goto err;
788 } 784 }
789 } else 785 } else
@@ -811,7 +807,7 @@ b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
811 unsigned int saltlen, keylen; 807 unsigned int saltlen, keylen;
812 808
813 if (BIO_read(in, pvk_hdr, 24) != 24) { 809 if (BIO_read(in, pvk_hdr, 24) != 24) {
814 PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT); 810 PEMerror(PEM_R_PVK_DATA_TOO_SHORT);
815 return NULL; 811 return NULL;
816 } 812 }
817 p = pvk_hdr; 813 p = pvk_hdr;
@@ -821,12 +817,12 @@ b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
821 buflen = keylen + saltlen; 817 buflen = keylen + saltlen;
822 buf = malloc(buflen); 818 buf = malloc(buflen);
823 if (!buf) { 819 if (!buf) {
824 PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE); 820 PEMerror(ERR_R_MALLOC_FAILURE);
825 return 0; 821 return 0;
826 } 822 }
827 p = buf; 823 p = buf;
828 if (BIO_read(in, buf, buflen) != buflen) { 824 if (BIO_read(in, buf, buflen) != buflen) {
829 PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT); 825 PEMerror(PEM_R_PVK_DATA_TOO_SHORT);
830 goto err; 826 goto err;
831 } 827 }
832 ret = do_PVK_body(&p, saltlen, keylen, cb, u); 828 ret = do_PVK_body(&p, saltlen, keylen, cb, u);
@@ -861,7 +857,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
861 else { 857 else {
862 p = malloc(outlen); 858 p = malloc(outlen);
863 if (!p) { 859 if (!p) {
864 PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE); 860 PEMerror(ERR_R_MALLOC_FAILURE);
865 return -1; 861 return -1;
866 } 862 }
867 *out = p; 863 *out = p;
@@ -893,7 +889,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
893 else 889 else
894 inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u); 890 inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);
895 if (inlen <= 0) { 891 if (inlen <= 0) {
896 PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ); 892 PEMerror(PEM_R_BAD_PASSWORD_READ);
897 goto error; 893 goto error;
898 } 894 }
899 if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN, 895 if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,
@@ -930,7 +926,7 @@ i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u)
930 wrlen = BIO_write(out, tmp, outlen); 926 wrlen = BIO_write(out, tmp, outlen);
931 free(tmp); 927 free(tmp);
932 if (wrlen == outlen) { 928 if (wrlen == outlen) {
933 PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE); 929 PEMerror(PEM_R_BIO_WRITE_FAILURE);
934 return outlen; 930 return outlen;
935 } 931 }
936 return -1; 932 return -1;
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
index 954ca03ebb..5642a141f5 100644
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ b/src/lib/libcrypto/pkcs12/p12_add.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_add.c,v 1.14 2016/12/30 15:34:35 jsing Exp $ */ 1/* $OpenBSD: p12_add.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -70,20 +70,17 @@ PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid1, int nid2)
70 PKCS12_SAFEBAG *safebag; 70 PKCS12_SAFEBAG *safebag;
71 71
72 if (!(bag = PKCS12_BAGS_new())) { 72 if (!(bag = PKCS12_BAGS_new())) {
73 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, 73 PKCS12error(ERR_R_MALLOC_FAILURE);
74 ERR_R_MALLOC_FAILURE);
75 return NULL; 74 return NULL;
76 } 75 }
77 bag->type = OBJ_nid2obj(nid1); 76 bag->type = OBJ_nid2obj(nid1);
78 if (!ASN1_item_pack(obj, it, &bag->value.octet)) { 77 if (!ASN1_item_pack(obj, it, &bag->value.octet)) {
79 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, 78 PKCS12error(ERR_R_MALLOC_FAILURE);
80 ERR_R_MALLOC_FAILURE);
81 PKCS12_BAGS_free(bag); 79 PKCS12_BAGS_free(bag);
82 return NULL; 80 return NULL;
83 } 81 }
84 if (!(safebag = PKCS12_SAFEBAG_new())) { 82 if (!(safebag = PKCS12_SAFEBAG_new())) {
85 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, 83 PKCS12error(ERR_R_MALLOC_FAILURE);
86 ERR_R_MALLOC_FAILURE);
87 PKCS12_BAGS_free(bag); 84 PKCS12_BAGS_free(bag);
88 return NULL; 85 return NULL;
89 } 86 }
@@ -100,7 +97,7 @@ PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
100 PKCS12_SAFEBAG *bag; 97 PKCS12_SAFEBAG *bag;
101 98
102 if (!(bag = PKCS12_SAFEBAG_new())) { 99 if (!(bag = PKCS12_SAFEBAG_new())) {
103 PKCS12err(PKCS12_F_PKCS12_MAKE_KEYBAG, ERR_R_MALLOC_FAILURE); 100 PKCS12error(ERR_R_MALLOC_FAILURE);
104 return NULL; 101 return NULL;
105 } 102 }
106 bag->type = OBJ_nid2obj(NID_keyBag); 103 bag->type = OBJ_nid2obj(NID_keyBag);
@@ -119,7 +116,7 @@ PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, int passlen,
119 116
120 /* Set up the safe bag */ 117 /* Set up the safe bag */
121 if (!(bag = PKCS12_SAFEBAG_new())) { 118 if (!(bag = PKCS12_SAFEBAG_new())) {
122 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); 119 PKCS12error(ERR_R_MALLOC_FAILURE);
123 return NULL; 120 return NULL;
124 } 121 }
125 122
@@ -132,7 +129,7 @@ PKCS12_MAKE_SHKEYBAG(int pbe_nid, const char *pass, int passlen,
132 129
133 if (!(bag->value.shkeybag = PKCS8_encrypt(pbe_nid, pbe_ciph, pass, 130 if (!(bag->value.shkeybag = PKCS8_encrypt(pbe_nid, pbe_ciph, pass,
134 passlen, salt, saltlen, iter, p8))) { 131 passlen, salt, saltlen, iter, p8))) {
135 PKCS12err(PKCS12_F_PKCS12_MAKE_SHKEYBAG, ERR_R_MALLOC_FAILURE); 132 PKCS12error(ERR_R_MALLOC_FAILURE);
136 PKCS12_SAFEBAG_free(bag); 133 PKCS12_SAFEBAG_free(bag);
137 return NULL; 134 return NULL;
138 } 135 }
@@ -147,18 +144,17 @@ PKCS12_pack_p7data(STACK_OF(PKCS12_SAFEBAG) *sk)
147 PKCS7 *p7; 144 PKCS7 *p7;
148 145
149 if (!(p7 = PKCS7_new())) { 146 if (!(p7 = PKCS7_new())) {
150 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); 147 PKCS12error(ERR_R_MALLOC_FAILURE);
151 return NULL; 148 return NULL;
152 } 149 }
153 p7->type = OBJ_nid2obj(NID_pkcs7_data); 150 p7->type = OBJ_nid2obj(NID_pkcs7_data);
154 if (!(p7->d.data = ASN1_OCTET_STRING_new())) { 151 if (!(p7->d.data = ASN1_OCTET_STRING_new())) {
155 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, ERR_R_MALLOC_FAILURE); 152 PKCS12error(ERR_R_MALLOC_FAILURE);
156 goto err; 153 goto err;
157 } 154 }
158 155
159 if (!ASN1_item_pack(sk, &PKCS12_SAFEBAGS_it, &p7->d.data)) { 156 if (!ASN1_item_pack(sk, &PKCS12_SAFEBAGS_it, &p7->d.data)) {
160 PKCS12err(PKCS12_F_PKCS12_PACK_P7DATA, 157 PKCS12error(PKCS12_R_CANT_PACK_STRUCTURE);
161 PKCS12_R_CANT_PACK_STRUCTURE);
162 goto err; 158 goto err;
163 } 159 }
164 return p7; 160 return p7;
@@ -173,8 +169,7 @@ STACK_OF(PKCS12_SAFEBAG) *
173PKCS12_unpack_p7data(PKCS7 *p7) 169PKCS12_unpack_p7data(PKCS7 *p7)
174{ 170{
175 if (!PKCS7_type_is_data(p7)) { 171 if (!PKCS7_type_is_data(p7)) {
176 PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA, 172 PKCS12error(PKCS12_R_CONTENT_TYPE_NOT_DATA);
177 PKCS12_R_CONTENT_TYPE_NOT_DATA);
178 return NULL; 173 return NULL;
179 } 174 }
180 return ASN1_item_unpack(p7->d.data, &PKCS12_SAFEBAGS_it); 175 return ASN1_item_unpack(p7->d.data, &PKCS12_SAFEBAGS_it);
@@ -191,12 +186,11 @@ PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
191 const EVP_CIPHER *pbe_ciph; 186 const EVP_CIPHER *pbe_ciph;
192 187
193 if (!(p7 = PKCS7_new())) { 188 if (!(p7 = PKCS7_new())) {
194 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); 189 PKCS12error(ERR_R_MALLOC_FAILURE);
195 return NULL; 190 return NULL;
196 } 191 }
197 if (!PKCS7_set_type(p7, NID_pkcs7_encrypted)) { 192 if (!PKCS7_set_type(p7, NID_pkcs7_encrypted)) {
198 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, 193 PKCS12error(PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
199 PKCS12_R_ERROR_SETTING_ENCRYPTED_DATA_TYPE);
200 goto err; 194 goto err;
201 } 195 }
202 196
@@ -208,7 +202,7 @@ PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
208 pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); 202 pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
209 203
210 if (!pbe) { 204 if (!pbe) {
211 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE); 205 PKCS12error(ERR_R_MALLOC_FAILURE);
212 goto err; 206 goto err;
213 } 207 }
214 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm); 208 X509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);
@@ -216,8 +210,7 @@ PKCS12_pack_p7encdata(int pbe_nid, const char *pass, int passlen,
216 ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data); 210 ASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);
217 if (!(p7->d.encrypted->enc_data->enc_data = PKCS12_item_i2d_encrypt( 211 if (!(p7->d.encrypted->enc_data->enc_data = PKCS12_item_i2d_encrypt(
218 pbe, &PKCS12_SAFEBAGS_it, pass, passlen, bags, 1))) { 212 pbe, &PKCS12_SAFEBAGS_it, pass, passlen, bags, 1))) {
219 PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, 213 PKCS12error(PKCS12_R_ENCRYPT_ERROR);
220 PKCS12_R_ENCRYPT_ERROR);
221 goto err; 214 goto err;
222 } 215 }
223 216
@@ -257,8 +250,7 @@ STACK_OF(PKCS7) *
257PKCS12_unpack_authsafes(PKCS12 *p12) 250PKCS12_unpack_authsafes(PKCS12 *p12)
258{ 251{
259 if (!PKCS7_type_is_data(p12->authsafes)) { 252 if (!PKCS7_type_is_data(p12->authsafes)) {
260 PKCS12err(PKCS12_F_PKCS12_UNPACK_AUTHSAFES, 253 PKCS12error(PKCS12_R_CONTENT_TYPE_NOT_DATA);
261 PKCS12_R_CONTENT_TYPE_NOT_DATA);
262 return NULL; 254 return NULL;
263 } 255 }
264 return ASN1_item_unpack(p12->authsafes->d.data, 256 return ASN1_item_unpack(p12->authsafes->d.data,
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
index f2d635fc62..d1f7d71fd3 100644
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_crpt.c,v 1.13 2016/11/08 20:01:06 miod Exp $ */ 1/* $OpenBSD: p12_crpt.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -82,20 +82,20 @@ PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
82 /* Extract useful info from parameter */ 82 /* Extract useful info from parameter */
83 if (param == NULL || param->type != V_ASN1_SEQUENCE || 83 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
84 param->value.sequence == NULL) { 84 param->value.sequence == NULL) {
85 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR); 85 PKCS12error(PKCS12_R_DECODE_ERROR);
86 return 0; 86 return 0;
87 } 87 }
88 88
89 pbuf = param->value.sequence->data; 89 pbuf = param->value.sequence->data;
90 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) { 90 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) {
91 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR); 91 PKCS12error(PKCS12_R_DECODE_ERROR);
92 return 0; 92 return 0;
93 } 93 }
94 94
95 if (!pbe->iter) 95 if (!pbe->iter)
96 iter = 1; 96 iter = 1;
97 else if ((iter = ASN1_INTEGER_get(pbe->iter)) <= 0) { 97 else if ((iter = ASN1_INTEGER_get(pbe->iter)) <= 0) {
98 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_DECODE_ERROR); 98 PKCS12error(PKCS12_R_DECODE_ERROR);
99 PBEPARAM_free(pbe); 99 PBEPARAM_free(pbe);
100 return 0; 100 return 0;
101 } 101 }
@@ -103,13 +103,13 @@ PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
103 saltlen = pbe->salt->length; 103 saltlen = pbe->salt->length;
104 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID, 104 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_KEY_ID,
105 iter, EVP_CIPHER_key_length(cipher), key, md)) { 105 iter, EVP_CIPHER_key_length(cipher), key, md)) {
106 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_KEY_GEN_ERROR); 106 PKCS12error(PKCS12_R_KEY_GEN_ERROR);
107 PBEPARAM_free(pbe); 107 PBEPARAM_free(pbe);
108 return 0; 108 return 0;
109 } 109 }
110 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID, 110 if (!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_IV_ID,
111 iter, EVP_CIPHER_iv_length(cipher), iv, md)) { 111 iter, EVP_CIPHER_iv_length(cipher), iv, md)) {
112 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN, PKCS12_R_IV_GEN_ERROR); 112 PKCS12error(PKCS12_R_IV_GEN_ERROR);
113 PBEPARAM_free(pbe); 113 PBEPARAM_free(pbe);
114 return 0; 114 return 0;
115 } 115 }
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
index bef4d54cd9..af2c6afc37 100644
--- a/src/lib/libcrypto/pkcs12/p12_crt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_crt.c,v 1.16 2015/02/14 12:43:07 miod Exp $ */ 1/* $OpenBSD: p12_crt.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -104,8 +104,7 @@ PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
104 mac_iter = 1; 104 mac_iter = 1;
105 105
106 if (!pkey && !cert && !ca) { 106 if (!pkey && !cert && !ca) {
107 PKCS12err(PKCS12_F_PKCS12_CREATE, 107 PKCS12error(PKCS12_R_INVALID_NULL_ARGUMENT);
108 PKCS12_R_INVALID_NULL_ARGUMENT);
109 return NULL; 108 return NULL;
110 } 109 }
111 110
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
index ad4e0bc660..ca08ee55d5 100644
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_decr.c,v 1.17 2015/09/30 18:41:06 jsing Exp $ */ 1/* $OpenBSD: p12_decr.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -79,20 +79,19 @@ PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, int passlen,
79 if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen, 79 if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen,
80 algor->parameter, &ctx, en_de)) { 80 algor->parameter, &ctx, en_de)) {
81 out = NULL; 81 out = NULL;
82 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, 82 PKCS12error(PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
83 PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);
84 goto err; 83 goto err;
85 } 84 }
86 85
87 if (!(out = malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { 86 if (!(out = malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
88 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_MALLOC_FAILURE); 87 PKCS12error(ERR_R_MALLOC_FAILURE);
89 goto err; 88 goto err;
90 } 89 }
91 90
92 if (!EVP_CipherUpdate(&ctx, out, &i, in, inlen)) { 91 if (!EVP_CipherUpdate(&ctx, out, &i, in, inlen)) {
93 free(out); 92 free(out);
94 out = NULL; 93 out = NULL;
95 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_EVP_LIB); 94 PKCS12error(ERR_R_EVP_LIB);
96 goto err; 95 goto err;
97 } 96 }
98 97
@@ -100,8 +99,7 @@ PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, int passlen,
100 if (!EVP_CipherFinal_ex(&ctx, out + i, &i)) { 99 if (!EVP_CipherFinal_ex(&ctx, out + i, &i)) {
101 free(out); 100 free(out);
102 out = NULL; 101 out = NULL;
103 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, 102 PKCS12error(PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
104 PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
105 goto err; 103 goto err;
106 } 104 }
107 outlen += i; 105 outlen += i;
@@ -131,8 +129,7 @@ PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
131 129
132 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length, 130 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length,
133 &out, &outlen, 0)) { 131 &out, &outlen, 0)) {
134 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, 132 PKCS12error(PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
135 PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
136 return NULL; 133 return NULL;
137 } 134 }
138 p = out; 135 p = out;
@@ -140,8 +137,7 @@ PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
140 if (zbuf) 137 if (zbuf)
141 explicit_bzero(out, outlen); 138 explicit_bzero(out, outlen);
142 if (!ret) 139 if (!ret)
143 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, 140 PKCS12error(PKCS12_R_DECODE_ERROR);
144 PKCS12_R_DECODE_ERROR);
145 free(out); 141 free(out);
146 return ret; 142 return ret;
147} 143}
@@ -160,20 +156,17 @@ PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
160 int inlen; 156 int inlen;
161 157
162 if (!(oct = ASN1_OCTET_STRING_new ())) { 158 if (!(oct = ASN1_OCTET_STRING_new ())) {
163 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, 159 PKCS12error(ERR_R_MALLOC_FAILURE);
164 ERR_R_MALLOC_FAILURE);
165 return NULL; 160 return NULL;
166 } 161 }
167 inlen = ASN1_item_i2d(obj, &in, it); 162 inlen = ASN1_item_i2d(obj, &in, it);
168 if (!in) { 163 if (!in) {
169 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, 164 PKCS12error(PKCS12_R_ENCODE_ERROR);
170 PKCS12_R_ENCODE_ERROR);
171 goto err; 165 goto err;
172 } 166 }
173 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data, 167 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data,
174 &oct->length, 1)) { 168 &oct->length, 1)) {
175 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT, 169 PKCS12error(PKCS12_R_ENCRYPT_ERROR);
176 PKCS12_R_ENCRYPT_ERROR);
177 goto err; 170 goto err;
178 } 171 }
179 if (zbuf) 172 if (zbuf)
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
index cd01196b6f..637c430bf4 100644
--- a/src/lib/libcrypto/pkcs12/p12_init.c
+++ b/src/lib/libcrypto/pkcs12/p12_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_init.c,v 1.10 2015/09/30 18:41:06 jsing Exp $ */ 1/* $OpenBSD: p12_init.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -69,7 +69,7 @@ PKCS12_init(int mode)
69 PKCS12 *pkcs12; 69 PKCS12 *pkcs12;
70 70
71 if (!(pkcs12 = PKCS12_new())) { 71 if (!(pkcs12 = PKCS12_new())) {
72 PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); 72 PKCS12error(ERR_R_MALLOC_FAILURE);
73 return NULL; 73 return NULL;
74 } 74 }
75 ASN1_INTEGER_set(pkcs12->version, 3); 75 ASN1_INTEGER_set(pkcs12->version, 3);
@@ -78,13 +78,12 @@ PKCS12_init(int mode)
78 case NID_pkcs7_data: 78 case NID_pkcs7_data:
79 if (!(pkcs12->authsafes->d.data = 79 if (!(pkcs12->authsafes->d.data =
80 ASN1_OCTET_STRING_new())) { 80 ASN1_OCTET_STRING_new())) {
81 PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE); 81 PKCS12error(ERR_R_MALLOC_FAILURE);
82 goto err; 82 goto err;
83 } 83 }
84 break; 84 break;
85 default: 85 default:
86 PKCS12err(PKCS12_F_PKCS12_INIT, 86 PKCS12error(PKCS12_R_UNSUPPORTED_PKCS12_MODE);
87 PKCS12_R_UNSUPPORTED_PKCS12_MODE);
88 goto err; 87 goto err;
89 } 88 }
90 89
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index 891f764c23..fd710771a5 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_key.c,v 1.24 2016/11/05 13:02:34 miod Exp $ */ 1/* $OpenBSD: p12_key.c,v 1.25 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -81,7 +81,7 @@ PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
81 unipass = NULL; 81 unipass = NULL;
82 uniplen = 0; 82 uniplen = 0;
83 } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) { 83 } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) {
84 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC, ERR_R_MALLOC_FAILURE); 84 PKCS12error(ERR_R_MALLOC_FAILURE);
85 return 0; 85 return 0;
86 } 86 }
87 ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, 87 ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen,
@@ -186,7 +186,7 @@ PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
186 } 186 }
187 187
188err: 188err:
189 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE); 189 PKCS12error(ERR_R_MALLOC_FAILURE);
190 190
191end: 191end:
192 free(Ai); 192 free(Ai);
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
index eb2c3a76d5..102ca3563b 100644
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ b/src/lib/libcrypto/pkcs12/p12_kiss.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_kiss.c,v 1.18 2016/12/30 15:08:22 jsing Exp $ */ 1/* $OpenBSD: p12_kiss.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -87,8 +87,7 @@ PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
87 /* Check for NULL PKCS12 structure */ 87 /* Check for NULL PKCS12 structure */
88 88
89 if (!p12) { 89 if (!p12) {
90 PKCS12err(PKCS12_F_PKCS12_PARSE, 90 PKCS12error(PKCS12_R_INVALID_NULL_PKCS12_POINTER);
91 PKCS12_R_INVALID_NULL_PKCS12_POINTER);
92 return 0; 91 return 0;
93 } 92 }
94 93
@@ -111,24 +110,23 @@ PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
111 else if (PKCS12_verify_mac(p12, "", 0)) 110 else if (PKCS12_verify_mac(p12, "", 0))
112 pass = ""; 111 pass = "";
113 else { 112 else {
114 PKCS12err(PKCS12_F_PKCS12_PARSE, 113 PKCS12error(PKCS12_R_MAC_VERIFY_FAILURE);
115 PKCS12_R_MAC_VERIFY_FAILURE);
116 goto err; 114 goto err;
117 } 115 }
118 } else if (!PKCS12_verify_mac(p12, pass, -1)) { 116 } else if (!PKCS12_verify_mac(p12, pass, -1)) {
119 PKCS12err(PKCS12_F_PKCS12_PARSE, PKCS12_R_MAC_VERIFY_FAILURE); 117 PKCS12error(PKCS12_R_MAC_VERIFY_FAILURE);
120 goto err; 118 goto err;
121 } 119 }
122 120
123 /* Allocate stack for other certificates */ 121 /* Allocate stack for other certificates */
124 ocerts = sk_X509_new_null(); 122 ocerts = sk_X509_new_null();
125 if (!ocerts) { 123 if (!ocerts) {
126 PKCS12err(PKCS12_F_PKCS12_PARSE, ERR_R_MALLOC_FAILURE); 124 PKCS12error(ERR_R_MALLOC_FAILURE);
127 return 0; 125 return 0;
128 } 126 }
129 127
130 if (!parse_pk12 (p12, pass, -1, pkey, ocerts)) { 128 if (!parse_pk12 (p12, pass, -1, pkey, ocerts)) {
131 PKCS12err(PKCS12_F_PKCS12_PARSE, PKCS12_R_PARSE_ERROR); 129 PKCS12error(PKCS12_R_PARSE_ERROR);
132 goto err; 130 goto err;
133 } 131 }
134 132
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
index 56a4964a34..f3132ec75f 100644
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_mutl.c,v 1.22 2016/11/08 20:01:06 miod Exp $ */ 1/* $OpenBSD: p12_mutl.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -80,8 +80,7 @@ PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
80 int md_size; 80 int md_size;
81 81
82 if (!PKCS7_type_is_data(p12->authsafes)) { 82 if (!PKCS7_type_is_data(p12->authsafes)) {
83 PKCS12err(PKCS12_F_PKCS12_GEN_MAC, 83 PKCS12error(PKCS12_R_CONTENT_TYPE_NOT_DATA);
84 PKCS12_R_CONTENT_TYPE_NOT_DATA);
85 return 0; 84 return 0;
86 } 85 }
87 86
@@ -90,13 +89,12 @@ PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
90 if (!p12->mac->iter) 89 if (!p12->mac->iter)
91 iter = 1; 90 iter = 1;
92 else if ((iter = ASN1_INTEGER_get(p12->mac->iter)) <= 0) { 91 else if ((iter = ASN1_INTEGER_get(p12->mac->iter)) <= 0) {
93 PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_DECODE_ERROR); 92 PKCS12error(PKCS12_R_DECODE_ERROR);
94 return 0; 93 return 0;
95 } 94 }
96 if (!(md_type = EVP_get_digestbyobj( 95 if (!(md_type = EVP_get_digestbyobj(
97 p12->mac->dinfo->algor->algorithm))) { 96 p12->mac->dinfo->algor->algorithm))) {
98 PKCS12err(PKCS12_F_PKCS12_GEN_MAC, 97 PKCS12error(PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
99 PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
100 return 0; 98 return 0;
101 } 99 }
102 md_size = EVP_MD_size(md_type); 100 md_size = EVP_MD_size(md_type);
@@ -104,7 +102,7 @@ PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
104 return 0; 102 return 0;
105 if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, 103 if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
106 md_size, key, md_type)) { 104 md_size, key, md_type)) {
107 PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR); 105 PKCS12error(PKCS12_R_KEY_GEN_ERROR);
108 return 0; 106 return 0;
109 } 107 }
110 HMAC_CTX_init(&hmac); 108 HMAC_CTX_init(&hmac);
@@ -127,12 +125,11 @@ PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen)
127 unsigned int maclen; 125 unsigned int maclen;
128 126
129 if (p12->mac == NULL) { 127 if (p12->mac == NULL) {
130 PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, PKCS12_R_MAC_ABSENT); 128 PKCS12error(PKCS12_R_MAC_ABSENT);
131 return 0; 129 return 0;
132 } 130 }
133 if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) { 131 if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) {
134 PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC, 132 PKCS12error(PKCS12_R_MAC_GENERATION_ERROR);
135 PKCS12_R_MAC_GENERATION_ERROR);
136 return 0; 133 return 0;
137 } 134 }
138 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length) || 135 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length) ||
@@ -154,17 +151,15 @@ PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, unsigned char *salt,
154 md_type = EVP_sha1(); 151 md_type = EVP_sha1();
155 if (PKCS12_setup_mac(p12, iter, salt, saltlen, md_type) == 152 if (PKCS12_setup_mac(p12, iter, salt, saltlen, md_type) ==
156 PKCS12_ERROR) { 153 PKCS12_ERROR) {
157 PKCS12err(PKCS12_F_PKCS12_SET_MAC, PKCS12_R_MAC_SETUP_ERROR); 154 PKCS12error(PKCS12_R_MAC_SETUP_ERROR);
158 return 0; 155 return 0;
159 } 156 }
160 if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) { 157 if (!PKCS12_gen_mac(p12, pass, passlen, mac, &maclen)) {
161 PKCS12err(PKCS12_F_PKCS12_SET_MAC, 158 PKCS12error(PKCS12_R_MAC_GENERATION_ERROR);
162 PKCS12_R_MAC_GENERATION_ERROR);
163 return 0; 159 return 0;
164 } 160 }
165 if (!(ASN1_STRING_set(p12->mac->dinfo->digest, mac, maclen))) { 161 if (!(ASN1_STRING_set(p12->mac->dinfo->digest, mac, maclen))) {
166 PKCS12err(PKCS12_F_PKCS12_SET_MAC, 162 PKCS12error(PKCS12_R_MAC_STRING_SET_ERROR);
167 PKCS12_R_MAC_STRING_SET_ERROR);
168 return 0; 163 return 0;
169 } 164 }
170 return 1; 165 return 1;
@@ -179,20 +174,18 @@ PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
179 return PKCS12_ERROR; 174 return PKCS12_ERROR;
180 if (iter > 1) { 175 if (iter > 1) {
181 if (!(p12->mac->iter = ASN1_INTEGER_new())) { 176 if (!(p12->mac->iter = ASN1_INTEGER_new())) {
182 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, 177 PKCS12error(ERR_R_MALLOC_FAILURE);
183 ERR_R_MALLOC_FAILURE);
184 return 0; 178 return 0;
185 } 179 }
186 if (!ASN1_INTEGER_set(p12->mac->iter, iter)) { 180 if (!ASN1_INTEGER_set(p12->mac->iter, iter)) {
187 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, 181 PKCS12error(ERR_R_MALLOC_FAILURE);
188 ERR_R_MALLOC_FAILURE);
189 return 0; 182 return 0;
190 } 183 }
191 } 184 }
192 if (!saltlen) 185 if (!saltlen)
193 saltlen = PKCS12_SALT_LEN; 186 saltlen = PKCS12_SALT_LEN;
194 if (!(p12->mac->salt->data = malloc(saltlen))) { 187 if (!(p12->mac->salt->data = malloc(saltlen))) {
195 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); 188 PKCS12error(ERR_R_MALLOC_FAILURE);
196 return 0; 189 return 0;
197 } 190 }
198 p12->mac->salt->length = saltlen; 191 p12->mac->salt->length = saltlen;
@@ -202,7 +195,7 @@ PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
202 memcpy (p12->mac->salt->data, salt, saltlen); 195 memcpy (p12->mac->salt->data, salt, saltlen);
203 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type)); 196 p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
204 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) { 197 if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
205 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); 198 PKCS12error(ERR_R_MALLOC_FAILURE);
206 return 0; 199 return 0;
207 } 200 }
208 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL; 201 p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
index 7803721a26..63b3df17ad 100644
--- a/src/lib/libcrypto/pkcs12/p12_npas.c
+++ b/src/lib/libcrypto/pkcs12/p12_npas.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_npas.c,v 1.11 2016/12/30 15:08:22 jsing Exp $ */ 1/* $OpenBSD: p12_npas.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -81,20 +81,19 @@ PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
81 /* Check for NULL PKCS12 structure */ 81 /* Check for NULL PKCS12 structure */
82 82
83 if (!p12) { 83 if (!p12) {
84 PKCS12err(PKCS12_F_PKCS12_NEWPASS, 84 PKCS12error(PKCS12_R_INVALID_NULL_PKCS12_POINTER);
85 PKCS12_R_INVALID_NULL_PKCS12_POINTER);
86 return 0; 85 return 0;
87 } 86 }
88 87
89 /* Check the mac */ 88 /* Check the mac */
90 89
91 if (!PKCS12_verify_mac(p12, oldpass, -1)) { 90 if (!PKCS12_verify_mac(p12, oldpass, -1)) {
92 PKCS12err(PKCS12_F_PKCS12_NEWPASS, PKCS12_R_MAC_VERIFY_FAILURE); 91 PKCS12error(PKCS12_R_MAC_VERIFY_FAILURE);
93 return 0; 92 return 0;
94 } 93 }
95 94
96 if (!newpass_p12(p12, oldpass, newpass)) { 95 if (!newpass_p12(p12, oldpass, newpass)) {
97 PKCS12err(PKCS12_F_PKCS12_NEWPASS, PKCS12_R_PARSE_ERROR); 96 PKCS12error(PKCS12_R_PARSE_ERROR);
98 return 0; 97 return 0;
99 } 98 }
100 99
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c
index e39d5975d5..5e3fc6486a 100644
--- a/src/lib/libcrypto/pkcs12/p12_p8e.c
+++ b/src/lib/libcrypto/pkcs12/p12_p8e.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_p8e.c,v 1.7 2016/12/30 15:34:35 jsing Exp $ */ 1/* $OpenBSD: p12_p8e.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -70,7 +70,7 @@ PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass,
70 X509_ALGOR *pbe; 70 X509_ALGOR *pbe;
71 71
72 if (!(p8 = X509_SIG_new())) { 72 if (!(p8 = X509_SIG_new())) {
73 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_MALLOC_FAILURE); 73 PKCS12error(ERR_R_MALLOC_FAILURE);
74 goto err; 74 goto err;
75 } 75 }
76 76
@@ -79,7 +79,7 @@ PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass,
79 else 79 else
80 pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); 80 pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen);
81 if (!pbe) { 81 if (!pbe) {
82 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); 82 PKCS12error(ERR_R_ASN1_LIB);
83 goto err; 83 goto err;
84 } 84 }
85 X509_ALGOR_free(p8->algor); 85 X509_ALGOR_free(p8->algor);
@@ -88,7 +88,7 @@ PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass,
88 p8->digest = PKCS12_item_i2d_encrypt(pbe, 88 p8->digest = PKCS12_item_i2d_encrypt(pbe,
89 &PKCS8_PRIV_KEY_INFO_it, pass, passlen, p8inf, 1); 89 &PKCS8_PRIV_KEY_INFO_it, pass, passlen, p8inf, 1);
90 if (!p8->digest) { 90 if (!p8->digest) {
91 PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); 91 PKCS12error(PKCS12_R_ENCRYPT_ERROR);
92 goto err; 92 goto err;
93 } 93 }
94 94
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
index 07722f98e1..f882ba7795 100644
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_attr.c,v 1.11 2016/12/30 15:38:13 jsing Exp $ */ 1/* $OpenBSD: pk7_attr.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -71,8 +71,7 @@ PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
71{ 71{
72 ASN1_STRING *seq; 72 ASN1_STRING *seq;
73 if (!(seq = ASN1_STRING_new())) { 73 if (!(seq = ASN1_STRING_new())) {
74 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP, 74 PKCS7error(ERR_R_MALLOC_FAILURE);
75 ERR_R_MALLOC_FAILURE);
76 return 0; 75 return 0;
77 } 76 }
78 seq->length = ASN1_item_i2d((ASN1_VALUE *)cap, &seq->data, 77 seq->length = ASN1_item_i2d((ASN1_VALUE *)cap, &seq->data,
@@ -103,7 +102,7 @@ PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
103 X509_ALGOR *alg; 102 X509_ALGOR *alg;
104 103
105 if (!(alg = X509_ALGOR_new())) { 104 if (!(alg = X509_ALGOR_new())) {
106 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); 105 PKCS7error(ERR_R_MALLOC_FAILURE);
107 return 0; 106 return 0;
108 } 107 }
109 ASN1_OBJECT_free(alg->algorithm); 108 ASN1_OBJECT_free(alg->algorithm);
@@ -127,7 +126,7 @@ PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
127 return 1; 126 return 1;
128 127
129err: 128err:
130 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP, ERR_R_MALLOC_FAILURE); 129 PKCS7error(ERR_R_MALLOC_FAILURE);
131 X509_ALGOR_free(alg); 130 X509_ALGOR_free(alg);
132 return 0; 131 return 0;
133} 132}
@@ -147,8 +146,7 @@ int
147PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) 146PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t)
148{ 147{
149 if (!t && !(t = X509_gmtime_adj(NULL, 0))) { 148 if (!t && !(t = X509_gmtime_adj(NULL, 0))) {
150 PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME, 149 PKCS7error(ERR_R_MALLOC_FAILURE);
151 ERR_R_MALLOC_FAILURE);
152 return 0; 150 return 0;
153 } 151 }
154 return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, 152 return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime,
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index e84eee6d8f..484620a686 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.40 2016/12/30 15:38:13 jsing Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.41 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,14 +110,13 @@ PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
110 BIO *btmp; 110 BIO *btmp;
111 const EVP_MD *md; 111 const EVP_MD *md;
112 if ((btmp = BIO_new(BIO_f_md())) == NULL) { 112 if ((btmp = BIO_new(BIO_f_md())) == NULL) {
113 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, ERR_R_BIO_LIB); 113 PKCS7error(ERR_R_BIO_LIB);
114 goto err; 114 goto err;
115 } 115 }
116 116
117 md = EVP_get_digestbyobj(alg->algorithm); 117 md = EVP_get_digestbyobj(alg->algorithm);
118 if (md == NULL) { 118 if (md == NULL) {
119 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, 119 PKCS7error(PKCS7_R_UNKNOWN_DIGEST_TYPE);
120 PKCS7_R_UNKNOWN_DIGEST_TYPE);
121 goto err; 120 goto err;
122 } 121 }
123 122
@@ -125,7 +124,7 @@ PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
125 if (*pbio == NULL) 124 if (*pbio == NULL)
126 *pbio = btmp; 125 *pbio = btmp;
127 else if (!BIO_push(*pbio, btmp)) { 126 else if (!BIO_push(*pbio, btmp)) {
128 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST, ERR_R_BIO_LIB); 127 PKCS7error(ERR_R_BIO_LIB);
129 goto err; 128 goto err;
130 } 129 }
131 btmp = NULL; 130 btmp = NULL;
@@ -160,7 +159,7 @@ pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, unsigned char *key, int keylen)
160 159
161 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT, 160 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
162 EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) { 161 EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0) {
163 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR); 162 PKCS7error(PKCS7_R_CTRL_ERROR);
164 goto err; 163 goto err;
165 } 164 }
166 165
@@ -170,7 +169,7 @@ pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri, unsigned char *key, int keylen)
170 ek = malloc(eklen); 169 ek = malloc(eklen);
171 170
172 if (ek == NULL) { 171 if (ek == NULL) {
173 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, ERR_R_MALLOC_FAILURE); 172 PKCS7error(ERR_R_MALLOC_FAILURE);
174 goto err; 173 goto err;
175 } 174 }
176 175
@@ -209,7 +208,7 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
209 208
210 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT, 209 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
211 EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0) { 210 EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0) {
212 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, PKCS7_R_CTRL_ERROR); 211 PKCS7error(PKCS7_R_CTRL_ERROR);
213 goto err; 212 goto err;
214 } 213 }
215 214
@@ -219,14 +218,14 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
219 218
220 ek = malloc(eklen); 219 ek = malloc(eklen);
221 if (ek == NULL) { 220 if (ek == NULL) {
222 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_MALLOC_FAILURE); 221 PKCS7error(ERR_R_MALLOC_FAILURE);
223 goto err; 222 goto err;
224 } 223 }
225 224
226 if (EVP_PKEY_decrypt(pctx, ek, &eklen, 225 if (EVP_PKEY_decrypt(pctx, ek, &eklen,
227 ri->enc_key->data, ri->enc_key->length) <= 0) { 226 ri->enc_key->data, ri->enc_key->length) <= 0) {
228 ret = 0; 227 ret = 0;
229 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_EVP_LIB); 228 PKCS7error(ERR_R_EVP_LIB);
230 goto err; 229 goto err;
231 } 230 }
232 231
@@ -262,7 +261,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
262 ASN1_OCTET_STRING *os = NULL; 261 ASN1_OCTET_STRING *os = NULL;
263 262
264 if (p7 == NULL) { 263 if (p7 == NULL) {
265 PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_INVALID_NULL_POINTER); 264 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
266 return NULL; 265 return NULL;
267 } 266 }
268 267
@@ -279,7 +278,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
279 * an error. 278 * an error.
280 */ 279 */
281 if (p7->d.ptr == NULL) { 280 if (p7->d.ptr == NULL) {
282 PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_NO_CONTENT); 281 PKCS7error(PKCS7_R_NO_CONTENT);
283 return NULL; 282 return NULL;
284 } 283 }
285 284
@@ -297,8 +296,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
297 xalg = p7->d.signed_and_enveloped->enc_data->algorithm; 296 xalg = p7->d.signed_and_enveloped->enc_data->algorithm;
298 evp_cipher = p7->d.signed_and_enveloped->enc_data->cipher; 297 evp_cipher = p7->d.signed_and_enveloped->enc_data->cipher;
299 if (evp_cipher == NULL) { 298 if (evp_cipher == NULL) {
300 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 299 PKCS7error(PKCS7_R_CIPHER_NOT_INITIALIZED);
301 PKCS7_R_CIPHER_NOT_INITIALIZED);
302 goto err; 300 goto err;
303 } 301 }
304 break; 302 break;
@@ -307,8 +305,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
307 xalg = p7->d.enveloped->enc_data->algorithm; 305 xalg = p7->d.enveloped->enc_data->algorithm;
308 evp_cipher = p7->d.enveloped->enc_data->cipher; 306 evp_cipher = p7->d.enveloped->enc_data->cipher;
309 if (evp_cipher == NULL) { 307 if (evp_cipher == NULL) {
310 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 308 PKCS7error(PKCS7_R_CIPHER_NOT_INITIALIZED);
311 PKCS7_R_CIPHER_NOT_INITIALIZED);
312 goto err; 309 goto err;
313 } 310 }
314 break; 311 break;
@@ -319,8 +316,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
319 case NID_pkcs7_data: 316 case NID_pkcs7_data:
320 break; 317 break;
321 default: 318 default:
322 PKCS7err(PKCS7_F_PKCS7_DATAINIT, 319 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
323 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
324 goto err; 320 goto err;
325 } 321 }
326 322
@@ -338,7 +334,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
338 EVP_CIPHER_CTX *ctx; 334 EVP_CIPHER_CTX *ctx;
339 335
340 if ((btmp = BIO_new(BIO_f_cipher())) == NULL) { 336 if ((btmp = BIO_new(BIO_f_cipher())) == NULL) {
341 PKCS7err(PKCS7_F_PKCS7_DATAINIT, ERR_R_BIO_LIB); 337 PKCS7error(ERR_R_BIO_LIB);
342 goto err; 338 goto err;
343 } 339 }
344 BIO_get_cipher_ctx(btmp, &ctx); 340 BIO_get_cipher_ctx(btmp, &ctx);
@@ -440,13 +436,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
440 int eklen = 0, tkeylen = 0; 436 int eklen = 0, tkeylen = 0;
441 437
442 if (p7 == NULL) { 438 if (p7 == NULL) {
443 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 439 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
444 PKCS7_R_INVALID_NULL_POINTER);
445 return NULL; 440 return NULL;
446 } 441 }
447 442
448 if (p7->d.ptr == NULL) { 443 if (p7->d.ptr == NULL) {
449 PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_CONTENT); 444 PKCS7error(PKCS7_R_NO_CONTENT);
450 return NULL; 445 return NULL;
451 } 446 }
452 447
@@ -465,8 +460,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
465 enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm; 460 enc_alg = p7->d.signed_and_enveloped->enc_data->algorithm;
466 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm); 461 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm);
467 if (evp_cipher == NULL) { 462 if (evp_cipher == NULL) {
468 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 463 PKCS7error(PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
469 PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
470 goto err; 464 goto err;
471 } 465 }
472 break; 466 break;
@@ -476,14 +470,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
476 data_body = p7->d.enveloped->enc_data->enc_data; 470 data_body = p7->d.enveloped->enc_data->enc_data;
477 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm); 471 evp_cipher = EVP_get_cipherbyobj(enc_alg->algorithm);
478 if (evp_cipher == NULL) { 472 if (evp_cipher == NULL) {
479 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 473 PKCS7error(PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
480 PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
481 goto err; 474 goto err;
482 } 475 }
483 break; 476 break;
484 default: 477 default:
485 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 478 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
486 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
487 goto err; 479 goto err;
488 } 480 }
489 481
@@ -492,16 +484,14 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
492 for (i = 0; i < sk_X509_ALGOR_num(md_sk); i++) { 484 for (i = 0; i < sk_X509_ALGOR_num(md_sk); i++) {
493 xa = sk_X509_ALGOR_value(md_sk, i); 485 xa = sk_X509_ALGOR_value(md_sk, i);
494 if ((btmp = BIO_new(BIO_f_md())) == NULL) { 486 if ((btmp = BIO_new(BIO_f_md())) == NULL) {
495 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 487 PKCS7error(ERR_R_BIO_LIB);
496 ERR_R_BIO_LIB);
497 goto err; 488 goto err;
498 } 489 }
499 490
500 j = OBJ_obj2nid(xa->algorithm); 491 j = OBJ_obj2nid(xa->algorithm);
501 evp_md = EVP_get_digestbynid(j); 492 evp_md = EVP_get_digestbynid(j);
502 if (evp_md == NULL) { 493 if (evp_md == NULL) {
503 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 494 PKCS7error(PKCS7_R_UNKNOWN_DIGEST_TYPE);
504 PKCS7_R_UNKNOWN_DIGEST_TYPE);
505 goto err; 495 goto err;
506 } 496 }
507 497
@@ -516,7 +506,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
516 506
517 if (evp_cipher != NULL) { 507 if (evp_cipher != NULL) {
518 if ((etmp = BIO_new(BIO_f_cipher())) == NULL) { 508 if ((etmp = BIO_new(BIO_f_cipher())) == NULL) {
519 PKCS7err(PKCS7_F_PKCS7_DATADECODE, ERR_R_BIO_LIB); 509 PKCS7error(ERR_R_BIO_LIB);
520 goto err; 510 goto err;
521 } 511 }
522 512
@@ -534,8 +524,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
534 ri = NULL; 524 ri = NULL;
535 } 525 }
536 if (ri == NULL) { 526 if (ri == NULL) {
537 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 527 PKCS7error(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
538 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
539 goto err; 528 goto err;
540 } 529 }
541 } 530 }
@@ -659,14 +648,12 @@ PKCS7_find_digest(EVP_MD_CTX **pmd, BIO *bio, int nid)
659 for (;;) { 648 for (;;) {
660 bio = BIO_find_type(bio, BIO_TYPE_MD); 649 bio = BIO_find_type(bio, BIO_TYPE_MD);
661 if (bio == NULL) { 650 if (bio == NULL) {
662 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST, 651 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
663 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
664 return NULL; 652 return NULL;
665 } 653 }
666 BIO_get_md_ctx(bio, pmd); 654 BIO_get_md_ctx(bio, pmd);
667 if (*pmd == NULL) { 655 if (*pmd == NULL) {
668 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST, 656 PKCS7error(ERR_R_INTERNAL_ERROR);
669 ERR_R_INTERNAL_ERROR);
670 return NULL; 657 return NULL;
671 } 658 }
672 if (EVP_MD_CTX_type(*pmd) == nid) 659 if (EVP_MD_CTX_type(*pmd) == nid)
@@ -685,19 +672,18 @@ do_pkcs7_signed_attrib(PKCS7_SIGNER_INFO *si, EVP_MD_CTX *mctx)
685 /* Add signing time if not already present */ 672 /* Add signing time if not already present */
686 if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime)) { 673 if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime)) {
687 if (!PKCS7_add0_attrib_signing_time(si, NULL)) { 674 if (!PKCS7_add0_attrib_signing_time(si, NULL)) {
688 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, 675 PKCS7error(ERR_R_MALLOC_FAILURE);
689 ERR_R_MALLOC_FAILURE);
690 return 0; 676 return 0;
691 } 677 }
692 } 678 }
693 679
694 /* Add digest */ 680 /* Add digest */
695 if (!EVP_DigestFinal_ex(mctx, md_data, &md_len)) { 681 if (!EVP_DigestFinal_ex(mctx, md_data, &md_len)) {
696 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_EVP_LIB); 682 PKCS7error(ERR_R_EVP_LIB);
697 return 0; 683 return 0;
698 } 684 }
699 if (!PKCS7_add1_attrib_digest(si, md_data, md_len)) { 685 if (!PKCS7_add1_attrib_digest(si, md_data, md_len)) {
700 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_MALLOC_FAILURE); 686 PKCS7error(ERR_R_MALLOC_FAILURE);
701 return 0; 687 return 0;
702 } 688 }
703 689
@@ -722,13 +708,12 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
722 ASN1_OCTET_STRING *os = NULL; 708 ASN1_OCTET_STRING *os = NULL;
723 709
724 if (p7 == NULL) { 710 if (p7 == NULL) {
725 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 711 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
726 PKCS7_R_INVALID_NULL_POINTER);
727 return 0; 712 return 0;
728 } 713 }
729 714
730 if (p7->d.ptr == NULL) { 715 if (p7->d.ptr == NULL) {
731 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_NO_CONTENT); 716 PKCS7error(PKCS7_R_NO_CONTENT);
732 return 0; 717 return 0;
733 } 718 }
734 719
@@ -747,8 +732,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
747 if (!os) { 732 if (!os) {
748 os = ASN1_OCTET_STRING_new(); 733 os = ASN1_OCTET_STRING_new();
749 if (!os) { 734 if (!os) {
750 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 735 PKCS7error(ERR_R_MALLOC_FAILURE);
751 ERR_R_MALLOC_FAILURE);
752 goto err; 736 goto err;
753 } 737 }
754 p7->d.signed_and_enveloped->enc_data->enc_data = os; 738 p7->d.signed_and_enveloped->enc_data->enc_data = os;
@@ -760,8 +744,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
760 if (!os) { 744 if (!os) {
761 os = ASN1_OCTET_STRING_new(); 745 os = ASN1_OCTET_STRING_new();
762 if (!os) { 746 if (!os) {
763 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 747 PKCS7error(ERR_R_MALLOC_FAILURE);
764 ERR_R_MALLOC_FAILURE);
765 goto err; 748 goto err;
766 } 749 }
767 p7->d.enveloped->enc_data->enc_data = os; 750 p7->d.enveloped->enc_data->enc_data = os;
@@ -771,7 +754,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
771 si_sk = p7->d.sign->signer_info; 754 si_sk = p7->d.sign->signer_info;
772 os = PKCS7_get_octet_string(p7->d.sign->contents); 755 os = PKCS7_get_octet_string(p7->d.sign->contents);
773 if (!PKCS7_is_detached(p7) && os == NULL) { 756 if (!PKCS7_is_detached(p7) && os == NULL) {
774 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR); 757 PKCS7error(PKCS7_R_DECODE_ERROR);
775 goto err; 758 goto err;
776 } 759 }
777 /* If detached data then the content is excluded */ 760 /* If detached data then the content is excluded */
@@ -785,7 +768,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
785 case NID_pkcs7_digest: 768 case NID_pkcs7_digest:
786 os = PKCS7_get_octet_string(p7->d.digest->contents); 769 os = PKCS7_get_octet_string(p7->d.digest->contents);
787 if (os == NULL) { 770 if (os == NULL) {
788 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_DECODE_ERROR); 771 PKCS7error(PKCS7_R_DECODE_ERROR);
789 goto err; 772 goto err;
790 } 773 }
791 /* If detached data then the content is excluded */ 774 /* If detached data then the content is excluded */
@@ -798,8 +781,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
798 break; 781 break;
799 782
800 default: 783 default:
801 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 784 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
802 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
803 goto err; 785 goto err;
804 } 786 }
805 787
@@ -836,8 +818,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
836 818
837 if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen, 819 if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen,
838 si->pkey)) { 820 si->pkey)) {
839 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 821 PKCS7error(ERR_R_EVP_LIB);
840 ERR_R_EVP_LIB);
841 goto err; 822 goto err;
842 } 823 }
843 ASN1_STRING_set0(si->enc_digest, abuf, abuflen); 824 ASN1_STRING_set0(si->enc_digest, abuf, abuflen);
@@ -870,8 +851,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
870 851
871 btmp = BIO_find_type(bio, BIO_TYPE_MEM); 852 btmp = BIO_find_type(bio, BIO_TYPE_MEM);
872 if (btmp == NULL) { 853 if (btmp == NULL) {
873 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 854 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
874 PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
875 goto err; 855 goto err;
876 } 856 }
877 contlen = BIO_get_mem_data(btmp, &cont); 857 contlen = BIO_get_mem_data(btmp, &cont);
@@ -910,7 +890,7 @@ PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
910 890
911 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, 891 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
912 EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0) { 892 EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0) {
913 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR); 893 PKCS7error(PKCS7_R_CTRL_ERROR);
914 goto err; 894 goto err;
915 } 895 }
916 896
@@ -932,7 +912,7 @@ PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
932 912
933 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN, 913 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
934 EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0) { 914 EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0) {
935 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR); 915 PKCS7error(PKCS7_R_CTRL_ERROR);
936 goto err; 916 goto err;
937 } 917 }
938 918
@@ -958,13 +938,12 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
958 X509 *x509; 938 X509 *x509;
959 939
960 if (p7 == NULL) { 940 if (p7 == NULL) {
961 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, 941 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
962 PKCS7_R_INVALID_NULL_POINTER);
963 return 0; 942 return 0;
964 } 943 }
965 944
966 if (p7->d.ptr == NULL) { 945 if (p7->d.ptr == NULL) {
967 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_NO_CONTENT); 946 PKCS7error(PKCS7_R_NO_CONTENT);
968 return 0; 947 return 0;
969 } 948 }
970 949
@@ -973,7 +952,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
973 } else if (PKCS7_type_is_signedAndEnveloped(p7)) { 952 } else if (PKCS7_type_is_signedAndEnveloped(p7)) {
974 cert = p7->d.signed_and_enveloped->cert; 953 cert = p7->d.signed_and_enveloped->cert;
975 } else { 954 } else {
976 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_WRONG_PKCS7_TYPE); 955 PKCS7error(PKCS7_R_WRONG_PKCS7_TYPE);
977 goto err; 956 goto err;
978 } 957 }
979 /* XXXX */ 958 /* XXXX */
@@ -983,14 +962,13 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
983 962
984 /* were we able to find the cert in passed to us */ 963 /* were we able to find the cert in passed to us */
985 if (x509 == NULL) { 964 if (x509 == NULL) {
986 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, 965 PKCS7error(PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
987 PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
988 goto err; 966 goto err;
989 } 967 }
990 968
991 /* Lets verify */ 969 /* Lets verify */
992 if (!X509_STORE_CTX_init(ctx, cert_store, x509, cert)) { 970 if (!X509_STORE_CTX_init(ctx, cert_store, x509, cert)) {
993 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, ERR_R_X509_LIB); 971 PKCS7error(ERR_R_X509_LIB);
994 goto err; 972 goto err;
995 } 973 }
996 if (X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN) == 0) { 974 if (X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN) == 0) {
@@ -999,7 +977,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
999 } 977 }
1000 i = X509_verify_cert(ctx); 978 i = X509_verify_cert(ctx);
1001 if (i <= 0) { 979 if (i <= 0) {
1002 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, ERR_R_X509_LIB); 980 PKCS7error(ERR_R_X509_LIB);
1003 X509_STORE_CTX_cleanup(ctx); 981 X509_STORE_CTX_cleanup(ctx);
1004 goto err; 982 goto err;
1005 } 983 }
@@ -1026,8 +1004,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1026 1004
1027 if (!PKCS7_type_is_signed(p7) && 1005 if (!PKCS7_type_is_signed(p7) &&
1028 !PKCS7_type_is_signedAndEnveloped(p7)) { 1006 !PKCS7_type_is_signedAndEnveloped(p7)) {
1029 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1007 PKCS7error(PKCS7_R_WRONG_PKCS7_TYPE);
1030 PKCS7_R_WRONG_PKCS7_TYPE);
1031 goto err; 1008 goto err;
1032 } 1009 }
1033 1010
@@ -1037,14 +1014,12 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1037 for (;;) { 1014 for (;;) {
1038 if ((btmp == NULL) || 1015 if ((btmp == NULL) ||
1039 ((btmp = BIO_find_type(btmp, BIO_TYPE_MD)) == NULL)) { 1016 ((btmp = BIO_find_type(btmp, BIO_TYPE_MD)) == NULL)) {
1040 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1017 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1041 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1042 goto err; 1018 goto err;
1043 } 1019 }
1044 BIO_get_md_ctx(btmp, &mdc); 1020 BIO_get_md_ctx(btmp, &mdc);
1045 if (mdc == NULL) { 1021 if (mdc == NULL) {
1046 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1022 PKCS7error(ERR_R_INTERNAL_ERROR);
1047 ERR_R_INTERNAL_ERROR);
1048 goto err; 1023 goto err;
1049 } 1024 }
1050 if (EVP_MD_CTX_type(mdc) == md_type) 1025 if (EVP_MD_CTX_type(mdc) == md_type)
@@ -1073,14 +1048,12 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1073 goto err; 1048 goto err;
1074 message_digest = PKCS7_digest_from_attributes(sk); 1049 message_digest = PKCS7_digest_from_attributes(sk);
1075 if (!message_digest) { 1050 if (!message_digest) {
1076 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1051 PKCS7error(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1077 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1078 goto err; 1052 goto err;
1079 } 1053 }
1080 if ((message_digest->length != (int)md_len) || 1054 if ((message_digest->length != (int)md_len) ||
1081 (memcmp(message_digest->data, md_dat, md_len))) { 1055 (memcmp(message_digest->data, md_dat, md_len))) {
1082 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1056 PKCS7error(PKCS7_R_DIGEST_FAILURE);
1083 PKCS7_R_DIGEST_FAILURE);
1084 ret = -1; 1057 ret = -1;
1085 goto err; 1058 goto err;
1086 } 1059 }
@@ -1092,7 +1065,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1092 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf, 1065 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
1093 &PKCS7_ATTR_VERIFY_it); 1066 &PKCS7_ATTR_VERIFY_it);
1094 if (alen <= 0) { 1067 if (alen <= 0) {
1095 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, ERR_R_ASN1_LIB); 1068 PKCS7error(ERR_R_ASN1_LIB);
1096 ret = -1; 1069 ret = -1;
1097 goto err; 1070 goto err;
1098 } 1071 }
@@ -1112,8 +1085,7 @@ PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, X509 *x509)
1112 i = EVP_VerifyFinal(&mdc_tmp, os->data, os->length, pkey); 1085 i = EVP_VerifyFinal(&mdc_tmp, os->data, os->length, pkey);
1113 EVP_PKEY_free(pkey); 1086 EVP_PKEY_free(pkey);
1114 if (i <= 0) { 1087 if (i <= 0) {
1115 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, 1088 PKCS7error(PKCS7_R_SIGNATURE_FAILURE);
1116 PKCS7_R_SIGNATURE_FAILURE);
1117 ret = -1; 1089 ret = -1;
1118 goto err; 1090 goto err;
1119 } else 1091 } else
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index b3dc068f3d..dc407dad55 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_lib.c,v 1.18 2015/09/30 18:41:06 jsing Exp $ */ 1/* $OpenBSD: pk7_lib.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -83,8 +83,7 @@ PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
83 p7->d.sign->contents->d.data = NULL; 83 p7->d.sign->contents->d.data = NULL;
84 } 84 }
85 } else { 85 } else {
86 PKCS7err(PKCS7_F_PKCS7_CTRL, 86 PKCS7error(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
87 PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
88 ret = 0; 87 ret = 0;
89 } 88 }
90 break; 89 break;
@@ -97,14 +96,13 @@ PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
97 96
98 p7->detached = ret; 97 p7->detached = ret;
99 } else { 98 } else {
100 PKCS7err(PKCS7_F_PKCS7_CTRL, 99 PKCS7error(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
101 PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
102 ret = 0; 100 ret = 0;
103 } 101 }
104 102
105 break; 103 break;
106 default: 104 default:
107 PKCS7err(PKCS7_F_PKCS7_CTRL, PKCS7_R_UNKNOWN_OPERATION); 105 PKCS7error(PKCS7_R_UNKNOWN_OPERATION);
108 ret = 0; 106 ret = 0;
109 } 107 }
110 return (ret); 108 return (ret);
@@ -151,8 +149,7 @@ PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
151 case NID_pkcs7_signedAndEnveloped: 149 case NID_pkcs7_signedAndEnveloped:
152 case NID_pkcs7_encrypted: 150 case NID_pkcs7_encrypted:
153 default: 151 default:
154 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT, 152 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
155 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
156 goto err; 153 goto err;
157 } 154 }
158 return (1); 155 return (1);
@@ -222,8 +219,7 @@ PKCS7_set_type(PKCS7 *p7, int type)
222 goto err; 219 goto err;
223 break; 220 break;
224 default: 221 default:
225 PKCS7err(PKCS7_F_PKCS7_SET_TYPE, 222 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
226 PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
227 goto err; 223 goto err;
228 } 224 }
229 return (1); 225 return (1);
@@ -258,7 +254,7 @@ PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
258 md_sk = p7->d.signed_and_enveloped->md_algs; 254 md_sk = p7->d.signed_and_enveloped->md_algs;
259 break; 255 break;
260 default: 256 default:
261 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER, PKCS7_R_WRONG_CONTENT_TYPE); 257 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
262 return (0); 258 return (0);
263 } 259 }
264 260
@@ -278,8 +274,7 @@ PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
278 if (!(alg = X509_ALGOR_new()) || 274 if (!(alg = X509_ALGOR_new()) ||
279 !(alg->parameter = ASN1_TYPE_new())) { 275 !(alg->parameter = ASN1_TYPE_new())) {
280 X509_ALGOR_free(alg); 276 X509_ALGOR_free(alg);
281 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER, 277 PKCS7error(ERR_R_MALLOC_FAILURE);
282 ERR_R_MALLOC_FAILURE);
283 return (0); 278 return (0);
284 } 279 }
285 alg->algorithm = OBJ_nid2obj(nid); 280 alg->algorithm = OBJ_nid2obj(nid);
@@ -310,15 +305,14 @@ PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
310 sk = &(p7->d.signed_and_enveloped->cert); 305 sk = &(p7->d.signed_and_enveloped->cert);
311 break; 306 break;
312 default: 307 default:
313 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE, 308 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
314 PKCS7_R_WRONG_CONTENT_TYPE);
315 return (0); 309 return (0);
316 } 310 }
317 311
318 if (*sk == NULL) 312 if (*sk == NULL)
319 *sk = sk_X509_new_null(); 313 *sk = sk_X509_new_null();
320 if (*sk == NULL) { 314 if (*sk == NULL) {
321 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE, ERR_R_MALLOC_FAILURE); 315 PKCS7error(ERR_R_MALLOC_FAILURE);
322 return 0; 316 return 0;
323 } 317 }
324 CRYPTO_add(&x509->references, 1, CRYPTO_LOCK_X509); 318 CRYPTO_add(&x509->references, 1, CRYPTO_LOCK_X509);
@@ -344,14 +338,14 @@ PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
344 sk = &(p7->d.signed_and_enveloped->crl); 338 sk = &(p7->d.signed_and_enveloped->crl);
345 break; 339 break;
346 default: 340 default:
347 PKCS7err(PKCS7_F_PKCS7_ADD_CRL, PKCS7_R_WRONG_CONTENT_TYPE); 341 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
348 return (0); 342 return (0);
349 } 343 }
350 344
351 if (*sk == NULL) 345 if (*sk == NULL)
352 *sk = sk_X509_CRL_new_null(); 346 *sk = sk_X509_CRL_new_null();
353 if (*sk == NULL) { 347 if (*sk == NULL) {
354 PKCS7err(PKCS7_F_PKCS7_ADD_CRL, ERR_R_MALLOC_FAILURE); 348 PKCS7error(ERR_R_MALLOC_FAILURE);
355 return 0; 349 return 0;
356 } 350 }
357 351
@@ -398,13 +392,11 @@ PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
398 if (ret > 0) 392 if (ret > 0)
399 return 1; 393 return 1;
400 if (ret != -2) { 394 if (ret != -2) {
401 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET, 395 PKCS7error(PKCS7_R_SIGNING_CTRL_FAILURE);
402 PKCS7_R_SIGNING_CTRL_FAILURE);
403 return 0; 396 return 0;
404 } 397 }
405 } 398 }
406 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET, 399 PKCS7error(PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
407 PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
408err: 400err:
409 return 0; 401 return 0;
410} 402}
@@ -420,8 +412,7 @@ PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, const EVP_MD *dgst)
420 goto err; 412 goto err;
421 dgst = EVP_get_digestbynid(def_nid); 413 dgst = EVP_get_digestbynid(def_nid);
422 if (dgst == NULL) { 414 if (dgst == NULL) {
423 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNATURE, 415 PKCS7error(PKCS7_R_NO_DEFAULT_DIGEST);
424 PKCS7_R_NO_DEFAULT_DIGEST);
425 goto err; 416 goto err;
426 } 417 }
427 } 418 }
@@ -444,8 +435,7 @@ PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md)
444{ 435{
445 if (PKCS7_type_is_digest(p7)) { 436 if (PKCS7_type_is_digest(p7)) {
446 if (!(p7->d.digest->md->parameter = ASN1_TYPE_new())) { 437 if (!(p7->d.digest->md->parameter = ASN1_TYPE_new())) {
447 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST, 438 PKCS7error(ERR_R_MALLOC_FAILURE);
448 ERR_R_MALLOC_FAILURE);
449 return 0; 439 return 0;
450 } 440 }
451 p7->d.digest->md->parameter->type = V_ASN1_NULL; 441 p7->d.digest->md->parameter->type = V_ASN1_NULL;
@@ -453,7 +443,7 @@ PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md)
453 return 1; 443 return 1;
454 } 444 }
455 445
456 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST, PKCS7_R_WRONG_CONTENT_TYPE); 446 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
457 return 1; 447 return 1;
458} 448}
459 449
@@ -522,8 +512,7 @@ PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
522 sk = p7->d.enveloped->recipientinfo; 512 sk = p7->d.enveloped->recipientinfo;
523 break; 513 break;
524 default: 514 default:
525 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO, 515 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
526 PKCS7_R_WRONG_CONTENT_TYPE);
527 return (0); 516 return (0);
528 } 517 }
529 518
@@ -551,21 +540,18 @@ PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
551 pkey = X509_get_pubkey(x509); 540 pkey = X509_get_pubkey(x509);
552 541
553 if (!pkey || !pkey->ameth || !pkey->ameth->pkey_ctrl) { 542 if (!pkey || !pkey->ameth || !pkey->ameth->pkey_ctrl) {
554 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET, 543 PKCS7error(PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
555 PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
556 goto err; 544 goto err;
557 } 545 }
558 546
559 ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_ENCRYPT, 547 ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_ENCRYPT,
560 0, p7i); 548 0, p7i);
561 if (ret == -2) { 549 if (ret == -2) {
562 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET, 550 PKCS7error(PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
563 PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
564 goto err; 551 goto err;
565 } 552 }
566 if (ret <= 0) { 553 if (ret <= 0) {
567 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET, 554 PKCS7error(PKCS7_R_ENCRYPTION_CTRL_FAILURE);
568 PKCS7_R_ENCRYPTION_CTRL_FAILURE);
569 goto err; 555 goto err;
570 } 556 }
571 557
@@ -607,15 +593,14 @@ PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
607 ec = p7->d.enveloped->enc_data; 593 ec = p7->d.enveloped->enc_data;
608 break; 594 break;
609 default: 595 default:
610 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER, PKCS7_R_WRONG_CONTENT_TYPE); 596 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
611 return (0); 597 return (0);
612 } 598 }
613 599
614 /* Check cipher OID exists and has data in it*/ 600 /* Check cipher OID exists and has data in it*/
615 i = EVP_CIPHER_type(cipher); 601 i = EVP_CIPHER_type(cipher);
616 if (i == NID_undef) { 602 if (i == NID_undef) {
617 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER, 603 PKCS7error(PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
618 PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
619 return (0); 604 return (0);
620 } 605 }
621 606
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
index a2f23b37f3..bf9f2dd82a 100644
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_smime.c,v 1.21 2016/11/05 15:19:07 miod Exp $ */ 1/* $OpenBSD: pk7_smime.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -74,7 +74,7 @@ PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data,
74 int i; 74 int i;
75 75
76 if (!(p7 = PKCS7_new())) { 76 if (!(p7 = PKCS7_new())) {
77 PKCS7err(PKCS7_F_PKCS7_SIGN, ERR_R_MALLOC_FAILURE); 77 PKCS7error(ERR_R_MALLOC_FAILURE);
78 return NULL; 78 return NULL;
79 } 79 }
80 80
@@ -85,7 +85,7 @@ PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data,
85 goto err; 85 goto err;
86 86
87 if (pkey && !PKCS7_sign_add_signer(p7, signcert, pkey, NULL, flags)) { 87 if (pkey && !PKCS7_sign_add_signer(p7, signcert, pkey, NULL, flags)) {
88 PKCS7err(PKCS7_F_PKCS7_SIGN, PKCS7_R_PKCS7_ADD_SIGNER_ERROR); 88 PKCS7error(PKCS7_R_PKCS7_ADD_SIGNER_ERROR);
89 goto err; 89 goto err;
90 } 90 }
91 91
@@ -117,7 +117,7 @@ PKCS7_final(PKCS7 *p7, BIO *data, int flags)
117 int ret = 0; 117 int ret = 0;
118 118
119 if (!(p7bio = PKCS7_dataInit(p7, NULL))) { 119 if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
120 PKCS7err(PKCS7_F_PKCS7_FINAL, ERR_R_MALLOC_FAILURE); 120 PKCS7error(ERR_R_MALLOC_FAILURE);
121 return 0; 121 return 0;
122 } 122 }
123 123
@@ -126,7 +126,7 @@ PKCS7_final(PKCS7 *p7, BIO *data, int flags)
126 (void)BIO_flush(p7bio); 126 (void)BIO_flush(p7bio);
127 127
128 if (!PKCS7_dataFinal(p7, p7bio)) { 128 if (!PKCS7_dataFinal(p7, p7bio)) {
129 PKCS7err(PKCS7_F_PKCS7_FINAL, PKCS7_R_PKCS7_DATASIGN); 129 PKCS7error(PKCS7_R_PKCS7_DATASIGN);
130 goto err; 130 goto err;
131 } 131 }
132 132
@@ -164,14 +164,12 @@ PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey,
164 STACK_OF(X509_ALGOR) *smcap = NULL; 164 STACK_OF(X509_ALGOR) *smcap = NULL;
165 165
166 if (!X509_check_private_key(signcert, pkey)) { 166 if (!X509_check_private_key(signcert, pkey)) {
167 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER, 167 PKCS7error(PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
168 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
169 return NULL; 168 return NULL;
170 } 169 }
171 170
172 if (!(si = PKCS7_add_signature(p7, signcert, pkey, md))) { 171 if (!(si = PKCS7_add_signature(p7, signcert, pkey, md))) {
173 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER, 172 PKCS7error(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
174 PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
175 return NULL; 173 return NULL;
176 } 174 }
177 175
@@ -186,8 +184,7 @@ PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, EVP_PKEY *pkey,
186 /* Add SMIMECapabilities */ 184 /* Add SMIMECapabilities */
187 if (!(flags & PKCS7_NOSMIMECAP)) { 185 if (!(flags & PKCS7_NOSMIMECAP)) {
188 if (!(smcap = sk_X509_ALGOR_new_null())) { 186 if (!(smcap = sk_X509_ALGOR_new_null())) {
189 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER, 187 PKCS7error(ERR_R_MALLOC_FAILURE);
190 ERR_R_MALLOC_FAILURE);
191 goto err; 188 goto err;
192 } 189 }
193 if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) || 190 if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1) ||
@@ -253,8 +250,7 @@ pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
253 if (osdig) 250 if (osdig)
254 return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length); 251 return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length);
255 252
256 PKCS7err(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST, 253 PKCS7error(PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND);
257 PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND);
258 return 0; 254 return 0;
259} 255}
260 256
@@ -273,18 +269,18 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
273 BIO *tmpin, *tmpout; 269 BIO *tmpin, *tmpout;
274 270
275 if (!p7) { 271 if (!p7) {
276 PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_INVALID_NULL_POINTER); 272 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
277 return 0; 273 return 0;
278 } 274 }
279 275
280 if (!PKCS7_type_is_signed(p7)) { 276 if (!PKCS7_type_is_signed(p7)) {
281 PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_WRONG_CONTENT_TYPE); 277 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
282 return 0; 278 return 0;
283 } 279 }
284 280
285 /* Check for no data and no content: no data to verify signature */ 281 /* Check for no data and no content: no data to verify signature */
286 if (PKCS7_get_detached(p7) && !indata) { 282 if (PKCS7_get_detached(p7) && !indata) {
287 PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_NO_CONTENT); 283 PKCS7error(PKCS7_R_NO_CONTENT);
288 return 0; 284 return 0;
289 } 285 }
290 286
@@ -294,14 +290,14 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
294 */ 290 */
295 /* Check for data and content: two sets of data */ 291 /* Check for data and content: two sets of data */
296 if (!PKCS7_get_detached(p7) && indata) { 292 if (!PKCS7_get_detached(p7) && indata) {
297 PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_CONTENT_AND_DATA_PRESENT); 293 PKCS7error(PKCS7_R_CONTENT_AND_DATA_PRESENT);
298 return 0; 294 return 0;
299 } 295 }
300 296
301 sinfos = PKCS7_get_signer_info(p7); 297 sinfos = PKCS7_get_signer_info(p7);
302 298
303 if (!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) { 299 if (!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
304 PKCS7err(PKCS7_F_PKCS7_VERIFY, PKCS7_R_NO_SIGNATURES_ON_DATA); 300 PKCS7error(PKCS7_R_NO_SIGNATURES_ON_DATA);
305 return 0; 301 return 0;
306 } 302 }
307 303
@@ -319,8 +315,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
319 if (!(flags & PKCS7_NOCHAIN)) { 315 if (!(flags & PKCS7_NOCHAIN)) {
320 if (!X509_STORE_CTX_init(&cert_ctx, store, 316 if (!X509_STORE_CTX_init(&cert_ctx, store,
321 signer, p7->d.sign->cert)) { 317 signer, p7->d.sign->cert)) {
322 PKCS7err(PKCS7_F_PKCS7_VERIFY, 318 PKCS7error(ERR_R_X509_LIB);
323 ERR_R_X509_LIB);
324 sk_X509_free(signers); 319 sk_X509_free(signers);
325 return 0; 320 return 0;
326 } 321 }
@@ -331,7 +326,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
331 } 326 }
332 } else if (!X509_STORE_CTX_init(&cert_ctx, store, 327 } else if (!X509_STORE_CTX_init(&cert_ctx, store,
333 signer, NULL)) { 328 signer, NULL)) {
334 PKCS7err(PKCS7_F_PKCS7_VERIFY, ERR_R_X509_LIB); 329 PKCS7error(ERR_R_X509_LIB);
335 sk_X509_free(signers); 330 sk_X509_free(signers);
336 return 0; 331 return 0;
337 } 332 }
@@ -342,8 +337,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
342 j = X509_STORE_CTX_get_error(&cert_ctx); 337 j = X509_STORE_CTX_get_error(&cert_ctx);
343 X509_STORE_CTX_cleanup(&cert_ctx); 338 X509_STORE_CTX_cleanup(&cert_ctx);
344 if (i <= 0) { 339 if (i <= 0) {
345 PKCS7err(PKCS7_F_PKCS7_VERIFY, 340 PKCS7error(PKCS7_R_CERTIFICATE_VERIFY_ERROR);
346 PKCS7_R_CERTIFICATE_VERIFY_ERROR);
347 ERR_asprintf_error_data("Verify error:%s", 341 ERR_asprintf_error_data("Verify error:%s",
348 X509_verify_cert_error_string(j)); 342 X509_verify_cert_error_string(j));
349 sk_X509_free(signers); 343 sk_X509_free(signers);
@@ -366,7 +360,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
366 len = BIO_get_mem_data(indata, &ptr); 360 len = BIO_get_mem_data(indata, &ptr);
367 tmpin = BIO_new_mem_buf(ptr, len); 361 tmpin = BIO_new_mem_buf(ptr, len);
368 if (tmpin == NULL) { 362 if (tmpin == NULL) {
369 PKCS7err(PKCS7_F_PKCS7_VERIFY, ERR_R_MALLOC_FAILURE); 363 PKCS7error(ERR_R_MALLOC_FAILURE);
370 return 0; 364 return 0;
371 } 365 }
372 } else 366 } else
@@ -378,7 +372,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
378 372
379 if (flags & PKCS7_TEXT) { 373 if (flags & PKCS7_TEXT) {
380 if (!(tmpout = BIO_new(BIO_s_mem()))) { 374 if (!(tmpout = BIO_new(BIO_s_mem()))) {
381 PKCS7err(PKCS7_F_PKCS7_VERIFY, ERR_R_MALLOC_FAILURE); 375 PKCS7error(ERR_R_MALLOC_FAILURE);
382 goto err; 376 goto err;
383 } 377 }
384 BIO_set_mem_eof_return(tmpout, 0); 378 BIO_set_mem_eof_return(tmpout, 0);
@@ -396,8 +390,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
396 390
397 if (flags & PKCS7_TEXT) { 391 if (flags & PKCS7_TEXT) {
398 if (!SMIME_text(tmpout, out)) { 392 if (!SMIME_text(tmpout, out)) {
399 PKCS7err(PKCS7_F_PKCS7_VERIFY, 393 PKCS7error(PKCS7_R_SMIME_TEXT_ERROR);
400 PKCS7_R_SMIME_TEXT_ERROR);
401 BIO_free(tmpout); 394 BIO_free(tmpout);
402 goto err; 395 goto err;
403 } 396 }
@@ -411,8 +404,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
411 signer = sk_X509_value (signers, i); 404 signer = sk_X509_value (signers, i);
412 j = PKCS7_signatureVerify(p7bio, p7, si, signer); 405 j = PKCS7_signatureVerify(p7bio, p7, si, signer);
413 if (j <= 0) { 406 if (j <= 0) {
414 PKCS7err(PKCS7_F_PKCS7_VERIFY, 407 PKCS7error(PKCS7_R_SIGNATURE_FAILURE);
415 PKCS7_R_SIGNATURE_FAILURE);
416 goto err; 408 goto err;
417 } 409 }
418 } 410 }
@@ -441,26 +433,24 @@ PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
441 int i; 433 int i;
442 434
443 if (!p7) { 435 if (!p7) {
444 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, 436 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
445 PKCS7_R_INVALID_NULL_POINTER);
446 return NULL; 437 return NULL;
447 } 438 }
448 439
449 if (!PKCS7_type_is_signed(p7)) { 440 if (!PKCS7_type_is_signed(p7)) {
450 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, 441 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
451 PKCS7_R_WRONG_CONTENT_TYPE);
452 return NULL; 442 return NULL;
453 } 443 }
454 444
455 /* Collect all the signers together */ 445 /* Collect all the signers together */
456 sinfos = PKCS7_get_signer_info(p7); 446 sinfos = PKCS7_get_signer_info(p7);
457 if (sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) { 447 if (sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
458 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, PKCS7_R_NO_SIGNERS); 448 PKCS7error(PKCS7_R_NO_SIGNERS);
459 return 0; 449 return 0;
460 } 450 }
461 451
462 if (!(signers = sk_X509_new_null())) { 452 if (!(signers = sk_X509_new_null())) {
463 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, ERR_R_MALLOC_FAILURE); 453 PKCS7error(ERR_R_MALLOC_FAILURE);
464 return NULL; 454 return NULL;
465 } 455 }
466 456
@@ -477,8 +467,7 @@ PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
477 X509_find_by_issuer_and_serial(p7->d.sign->cert, 467 X509_find_by_issuer_and_serial(p7->d.sign->cert,
478 ias->issuer, ias->serial); 468 ias->issuer, ias->serial);
479 if (!signer) { 469 if (!signer) {
480 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS, 470 PKCS7error(PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
481 PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
482 sk_X509_free(signers); 471 sk_X509_free(signers);
483 return 0; 472 return 0;
484 } 473 }
@@ -503,22 +492,21 @@ PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
503 X509 *x509; 492 X509 *x509;
504 493
505 if (!(p7 = PKCS7_new())) { 494 if (!(p7 = PKCS7_new())) {
506 PKCS7err(PKCS7_F_PKCS7_ENCRYPT, ERR_R_MALLOC_FAILURE); 495 PKCS7error(ERR_R_MALLOC_FAILURE);
507 return NULL; 496 return NULL;
508 } 497 }
509 498
510 if (!PKCS7_set_type(p7, NID_pkcs7_enveloped)) 499 if (!PKCS7_set_type(p7, NID_pkcs7_enveloped))
511 goto err; 500 goto err;
512 if (!PKCS7_set_cipher(p7, cipher)) { 501 if (!PKCS7_set_cipher(p7, cipher)) {
513 PKCS7err(PKCS7_F_PKCS7_ENCRYPT, PKCS7_R_ERROR_SETTING_CIPHER); 502 PKCS7error(PKCS7_R_ERROR_SETTING_CIPHER);
514 goto err; 503 goto err;
515 } 504 }
516 505
517 for (i = 0; i < sk_X509_num(certs); i++) { 506 for (i = 0; i < sk_X509_num(certs); i++) {
518 x509 = sk_X509_value(certs, i); 507 x509 = sk_X509_value(certs, i);
519 if (!PKCS7_add_recipient(p7, x509)) { 508 if (!PKCS7_add_recipient(p7, x509)) {
520 PKCS7err(PKCS7_F_PKCS7_ENCRYPT, 509 PKCS7error(PKCS7_R_ERROR_ADDING_RECIPIENT);
521 PKCS7_R_ERROR_ADDING_RECIPIENT);
522 goto err; 510 goto err;
523 } 511 }
524 } 512 }
@@ -543,23 +531,22 @@ PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
543 char buf[4096]; 531 char buf[4096];
544 532
545 if (!p7) { 533 if (!p7) {
546 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_INVALID_NULL_POINTER); 534 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
547 return 0; 535 return 0;
548 } 536 }
549 537
550 if (!PKCS7_type_is_enveloped(p7)) { 538 if (!PKCS7_type_is_enveloped(p7)) {
551 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_WRONG_CONTENT_TYPE); 539 PKCS7error(PKCS7_R_WRONG_CONTENT_TYPE);
552 return 0; 540 return 0;
553 } 541 }
554 542
555 if (cert && !X509_check_private_key(cert, pkey)) { 543 if (cert && !X509_check_private_key(cert, pkey)) {
556 PKCS7err(PKCS7_F_PKCS7_DECRYPT, 544 PKCS7error(PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
557 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
558 return 0; 545 return 0;
559 } 546 }
560 547
561 if (!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) { 548 if (!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
562 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR); 549 PKCS7error(PKCS7_R_DECRYPT_ERROR);
563 return 0; 550 return 0;
564 } 551 }
565 552
@@ -568,7 +555,7 @@ PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
568 555
569 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ 556 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
570 if (!(tmpbuf = BIO_new(BIO_f_buffer()))) { 557 if (!(tmpbuf = BIO_new(BIO_f_buffer()))) {
571 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); 558 PKCS7error(ERR_R_MALLOC_FAILURE);
572 BIO_free_all(tmpmem); 559 BIO_free_all(tmpmem);
573 return 0; 560 return 0;
574 } 561 }
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
index 3f91fcb37b..1ac00be773 100644
--- a/src/lib/libcrypto/rand/rand_err.c
+++ b/src/lib/libcrypto/rand/rand_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rand_err.c,v 1.14 2014/07/10 22:45:57 jsing Exp $ */ 1/* $OpenBSD: rand_err.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,9 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason)
73 73
74static ERR_STRING_DATA RAND_str_functs[] = { 74static ERR_STRING_DATA RAND_str_functs[] = {
75 {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"},
77 {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"},
78 {0, NULL} 76 {0, NULL}
79}; 77};
80 78
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index aa911251cc..ec8a71b7b9 100644
--- a/src/lib/libcrypto/rsa/rsa_ameth.c
+++ b/src/lib/libcrypto/rsa/rsa_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_ameth.c,v 1.17 2016/12/30 15:47:07 jsing Exp $ */ 1/* $OpenBSD: rsa_ameth.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -96,7 +96,7 @@ rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
96 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, NULL, pubkey)) 96 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, NULL, pubkey))
97 return 0; 97 return 0;
98 if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen))) { 98 if (!(rsa = d2i_RSAPublicKey(NULL, &p, pklen))) {
99 RSAerr(RSA_F_RSA_PUB_DECODE, ERR_R_RSA_LIB); 99 RSAerror(ERR_R_RSA_LIB);
100 return 0; 100 return 0;
101 } 101 }
102 EVP_PKEY_assign_RSA (pkey, rsa); 102 EVP_PKEY_assign_RSA (pkey, rsa);
@@ -118,7 +118,7 @@ old_rsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
118 RSA *rsa; 118 RSA *rsa;
119 119
120 if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen))) { 120 if (!(rsa = d2i_RSAPrivateKey (NULL, pder, derlen))) {
121 RSAerr(RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB); 121 RSAerror(ERR_R_RSA_LIB);
122 return 0; 122 return 0;
123 } 123 }
124 EVP_PKEY_assign_RSA(pkey, rsa); 124 EVP_PKEY_assign_RSA(pkey, rsa);
@@ -140,13 +140,13 @@ rsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
140 rklen = i2d_RSAPrivateKey(pkey->pkey.rsa, &rk); 140 rklen = i2d_RSAPrivateKey(pkey->pkey.rsa, &rk);
141 141
142 if (rklen <= 0) { 142 if (rklen <= 0) {
143 RSAerr(RSA_F_RSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 143 RSAerror(ERR_R_MALLOC_FAILURE);
144 return 0; 144 return 0;
145 } 145 }
146 146
147 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_rsaEncryption), 0, 147 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_rsaEncryption), 0,
148 V_ASN1_NULL, NULL, rk, rklen)) { 148 V_ASN1_NULL, NULL, rk, rklen)) {
149 RSAerr(RSA_F_RSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); 149 RSAerror(ERR_R_MALLOC_FAILURE);
150 return 0; 150 return 0;
151 } 151 }
152 152
@@ -216,7 +216,7 @@ do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
216 216
217 m = malloc(buf_len + 10); 217 m = malloc(buf_len + 10);
218 if (m == NULL) { 218 if (m == NULL) {
219 RSAerr(RSA_F_DO_RSA_PRINT, ERR_R_MALLOC_FAILURE); 219 RSAerror(ERR_R_MALLOC_FAILURE);
220 goto err; 220 goto err;
221 } 221 }
222 222
@@ -450,7 +450,7 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
450 450
451 /* Sanity check: make sure it is PSS */ 451 /* Sanity check: make sure it is PSS */
452 if (OBJ_obj2nid(sigalg->algorithm) != NID_rsassaPss) { 452 if (OBJ_obj2nid(sigalg->algorithm) != NID_rsassaPss) {
453 RSAerr(RSA_F_RSA_ITEM_VERIFY, RSA_R_UNSUPPORTED_SIGNATURE_TYPE); 453 RSAerror(RSA_R_UNSUPPORTED_SIGNATURE_TYPE);
454 return -1; 454 return -1;
455 } 455 }
456 456
@@ -458,25 +458,22 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
458 pss = rsa_pss_decode(sigalg, &maskHash); 458 pss = rsa_pss_decode(sigalg, &maskHash);
459 459
460 if (pss == NULL) { 460 if (pss == NULL) {
461 RSAerr(RSA_F_RSA_ITEM_VERIFY, RSA_R_INVALID_PSS_PARAMETERS); 461 RSAerror(RSA_R_INVALID_PSS_PARAMETERS);
462 goto err; 462 goto err;
463 } 463 }
464 /* Check mask and lookup mask hash algorithm */ 464 /* Check mask and lookup mask hash algorithm */
465 if (pss->maskGenAlgorithm) { 465 if (pss->maskGenAlgorithm) {
466 if (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) != NID_mgf1) { 466 if (OBJ_obj2nid(pss->maskGenAlgorithm->algorithm) != NID_mgf1) {
467 RSAerr(RSA_F_RSA_ITEM_VERIFY, 467 RSAerror(RSA_R_UNSUPPORTED_MASK_ALGORITHM);
468 RSA_R_UNSUPPORTED_MASK_ALGORITHM);
469 goto err; 468 goto err;
470 } 469 }
471 if (!maskHash) { 470 if (!maskHash) {
472 RSAerr(RSA_F_RSA_ITEM_VERIFY, 471 RSAerror(RSA_R_UNSUPPORTED_MASK_PARAMETER);
473 RSA_R_UNSUPPORTED_MASK_PARAMETER);
474 goto err; 472 goto err;
475 } 473 }
476 mgf1md = EVP_get_digestbyobj(maskHash->algorithm); 474 mgf1md = EVP_get_digestbyobj(maskHash->algorithm);
477 if (mgf1md == NULL) { 475 if (mgf1md == NULL) {
478 RSAerr(RSA_F_RSA_ITEM_VERIFY, 476 RSAerror(RSA_R_UNKNOWN_MASK_DIGEST);
479 RSA_R_UNKNOWN_MASK_DIGEST);
480 goto err; 477 goto err;
481 } 478 }
482 } else 479 } else
@@ -485,7 +482,7 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
485 if (pss->hashAlgorithm) { 482 if (pss->hashAlgorithm) {
486 md = EVP_get_digestbyobj(pss->hashAlgorithm->algorithm); 483 md = EVP_get_digestbyobj(pss->hashAlgorithm->algorithm);
487 if (md == NULL) { 484 if (md == NULL) {
488 RSAerr(RSA_F_RSA_ITEM_VERIFY, RSA_R_UNKNOWN_PSS_DIGEST); 485 RSAerror(RSA_R_UNKNOWN_PSS_DIGEST);
489 goto err; 486 goto err;
490 } 487 }
491 } else 488 } else
@@ -498,8 +495,7 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
498 * RSA routines will trap other invalid values anyway. 495 * RSA routines will trap other invalid values anyway.
499 */ 496 */
500 if (saltlen < 0) { 497 if (saltlen < 0) {
501 RSAerr(RSA_F_RSA_ITEM_VERIFY, 498 RSAerror(RSA_R_INVALID_SALT_LENGTH);
502 RSA_R_INVALID_SALT_LENGTH);
503 goto err; 499 goto err;
504 } 500 }
505 } else 501 } else
@@ -509,7 +505,7 @@ rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
509 * and PKCS#1 says we should reject any other value anyway. 505 * and PKCS#1 says we should reject any other value anyway.
510 */ 506 */
511 if (pss->trailerField && ASN1_INTEGER_get(pss->trailerField) != 1) { 507 if (pss->trailerField && ASN1_INTEGER_get(pss->trailerField) != 1) {
512 RSAerr(RSA_F_RSA_ITEM_VERIFY, RSA_R_INVALID_TRAILER); 508 RSAerror(RSA_R_INVALID_TRAILER);
513 goto err; 509 goto err;
514 } 510 }
515 511
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c
index dd9104f304..5345d31df9 100644
--- a/src/lib/libcrypto/rsa/rsa_chk.c
+++ b/src/lib/libcrypto/rsa/rsa_chk.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_chk.c,v 1.12 2017/01/25 06:15:44 beck Exp $ */ 1/* $OpenBSD: rsa_chk.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -63,7 +63,7 @@ RSA_check_key(const RSA *key)
63 int ret = 1; 63 int ret = 1;
64 64
65 if (!key->p || !key->q || !key->n || !key->e || !key->d) { 65 if (!key->p || !key->q || !key->n || !key->e || !key->d) {
66 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_VALUE_MISSING); 66 RSAerror(RSA_R_VALUE_MISSING);
67 return 0; 67 return 0;
68 } 68 }
69 69
@@ -76,7 +76,7 @@ RSA_check_key(const RSA *key)
76 if (i == NULL || j == NULL || k == NULL || l == NULL || m == NULL || 76 if (i == NULL || j == NULL || k == NULL || l == NULL || m == NULL ||
77 ctx == NULL) { 77 ctx == NULL) {
78 ret = -1; 78 ret = -1;
79 RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); 79 RSAerror(ERR_R_MALLOC_FAILURE);
80 goto err; 80 goto err;
81 } 81 }
82 82
@@ -86,7 +86,7 @@ RSA_check_key(const RSA *key)
86 ret = r; 86 ret = r;
87 if (r != 0) 87 if (r != 0)
88 goto err; 88 goto err;
89 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); 89 RSAerror(RSA_R_P_NOT_PRIME);
90 } 90 }
91 91
92 /* q prime? */ 92 /* q prime? */
@@ -95,7 +95,7 @@ RSA_check_key(const RSA *key)
95 ret = r; 95 ret = r;
96 if (r != 0) 96 if (r != 0)
97 goto err; 97 goto err;
98 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); 98 RSAerror(RSA_R_Q_NOT_PRIME);
99 } 99 }
100 100
101 /* n = p*q? */ 101 /* n = p*q? */
@@ -107,7 +107,7 @@ RSA_check_key(const RSA *key)
107 107
108 if (BN_cmp(i, key->n) != 0) { 108 if (BN_cmp(i, key->n) != 0) {
109 ret = 0; 109 ret = 0;
110 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); 110 RSAerror(RSA_R_N_DOES_NOT_EQUAL_P_Q);
111 } 111 }
112 112
113 /* d*e = 1 mod lcm(p-1,q-1)? */ 113 /* d*e = 1 mod lcm(p-1,q-1)? */
@@ -148,7 +148,7 @@ RSA_check_key(const RSA *key)
148 148
149 if (!BN_is_one(i)) { 149 if (!BN_is_one(i)) {
150 ret = 0; 150 ret = 0;
151 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); 151 RSAerror(RSA_R_D_E_NOT_CONGRUENT_TO_1);
152 } 152 }
153 153
154 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) { 154 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {
@@ -167,8 +167,7 @@ RSA_check_key(const RSA *key)
167 167
168 if (BN_cmp(j, key->dmp1) != 0) { 168 if (BN_cmp(j, key->dmp1) != 0) {
169 ret = 0; 169 ret = 0;
170 RSAerr(RSA_F_RSA_CHECK_KEY, 170 RSAerror(RSA_R_DMP1_NOT_CONGRUENT_TO_D);
171 RSA_R_DMP1_NOT_CONGRUENT_TO_D);
172 } 171 }
173 172
174 /* dmq1 = d mod (q-1)? */ 173 /* dmq1 = d mod (q-1)? */
@@ -186,8 +185,7 @@ RSA_check_key(const RSA *key)
186 185
187 if (BN_cmp(j, key->dmq1) != 0) { 186 if (BN_cmp(j, key->dmq1) != 0) {
188 ret = 0; 187 ret = 0;
189 RSAerr(RSA_F_RSA_CHECK_KEY, 188 RSAerror(RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
190 RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
191 } 189 }
192 190
193 /* iqmp = q^-1 mod p? */ 191 /* iqmp = q^-1 mod p? */
@@ -198,8 +196,7 @@ RSA_check_key(const RSA *key)
198 196
199 if (BN_cmp(i, key->iqmp) != 0) { 197 if (BN_cmp(i, key->iqmp) != 0) {
200 ret = 0; 198 ret = 0;
201 RSAerr(RSA_F_RSA_CHECK_KEY, 199 RSAerror(RSA_R_IQMP_NOT_INVERSE_OF_Q);
202 RSA_R_IQMP_NOT_INVERSE_OF_Q);
203 } 200 }
204 } 201 }
205 202
diff --git a/src/lib/libcrypto/rsa/rsa_crpt.c b/src/lib/libcrypto/rsa/rsa_crpt.c
index 8063a83263..f0c925602f 100644
--- a/src/lib/libcrypto/rsa/rsa_crpt.c
+++ b/src/lib/libcrypto/rsa/rsa_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_crpt.c,v 1.17 2017/01/21 11:00:47 beck Exp $ */ 1/* $OpenBSD: rsa_crpt.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -187,8 +187,7 @@ RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
187 if (rsa->e == NULL) { 187 if (rsa->e == NULL) {
188 e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx); 188 e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx);
189 if (e == NULL) { 189 if (e == NULL) {
190 RSAerr(RSA_F_RSA_SETUP_BLINDING, 190 RSAerror(RSA_R_NO_PUBLIC_EXPONENT);
191 RSA_R_NO_PUBLIC_EXPONENT);
192 goto err; 191 goto err;
193 } 192 }
194 } else 193 } else
@@ -201,7 +200,7 @@ RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
201 rsa->_method_mod_n); 200 rsa->_method_mod_n);
202 201
203 if (ret == NULL) { 202 if (ret == NULL) {
204 RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_BN_LIB); 203 RSAerror(ERR_R_BN_LIB);
205 goto err; 204 goto err;
206 } 205 }
207 CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret)); 206 CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret));
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index c4da147ddf..90a3be8dd3 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_eay.c,v 1.45 2017/01/21 10:38:29 beck Exp $ */ 1/* $OpenBSD: rsa_eay.c,v 1.46 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -160,19 +160,19 @@ RSA_eay_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
160 BN_CTX *ctx = NULL; 160 BN_CTX *ctx = NULL;
161 161
162 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) { 162 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {
163 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE); 163 RSAerror(RSA_R_MODULUS_TOO_LARGE);
164 return -1; 164 return -1;
165 } 165 }
166 166
167 if (BN_ucmp(rsa->n, rsa->e) <= 0) { 167 if (BN_ucmp(rsa->n, rsa->e) <= 0) {
168 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE); 168 RSAerror(RSA_R_BAD_E_VALUE);
169 return -1; 169 return -1;
170 } 170 }
171 171
172 /* for large moduli, enforce exponent limit */ 172 /* for large moduli, enforce exponent limit */
173 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) { 173 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {
174 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) { 174 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {
175 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE); 175 RSAerror(RSA_R_BAD_E_VALUE);
176 return -1; 176 return -1;
177 } 177 }
178 } 178 }
@@ -187,7 +187,7 @@ RSA_eay_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
187 buf = malloc(num); 187 buf = malloc(num);
188 188
189 if (f == NULL || ret == NULL || buf == NULL) { 189 if (f == NULL || ret == NULL || buf == NULL) {
190 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE); 190 RSAerror(ERR_R_MALLOC_FAILURE);
191 goto err; 191 goto err;
192 } 192 }
193 193
@@ -207,8 +207,7 @@ RSA_eay_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
207 i = RSA_padding_add_none(buf, num, from, flen); 207 i = RSA_padding_add_none(buf, num, from, flen);
208 break; 208 break;
209 default: 209 default:
210 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, 210 RSAerror(RSA_R_UNKNOWN_PADDING_TYPE);
211 RSA_R_UNKNOWN_PADDING_TYPE);
212 goto err; 211 goto err;
213 } 212 }
214 if (i <= 0) 213 if (i <= 0)
@@ -219,8 +218,7 @@ RSA_eay_public_encrypt(int flen, const unsigned char *from, unsigned char *to,
219 218
220 if (BN_ucmp(f, rsa->n) >= 0) { 219 if (BN_ucmp(f, rsa->n) >= 0) {
221 /* usually the padding functions would catch this */ 220 /* usually the padding functions would catch this */
222 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, 221 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
223 RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
224 goto err; 222 goto err;
225 } 223 }
226 224
@@ -374,7 +372,7 @@ RSA_eay_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
374 buf = malloc(num); 372 buf = malloc(num);
375 373
376 if (f == NULL || ret == NULL || buf == NULL) { 374 if (f == NULL || ret == NULL || buf == NULL) {
377 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE); 375 RSAerror(ERR_R_MALLOC_FAILURE);
378 goto err; 376 goto err;
379 } 377 }
380 378
@@ -390,8 +388,7 @@ RSA_eay_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
390 break; 388 break;
391 case RSA_SSLV23_PADDING: 389 case RSA_SSLV23_PADDING:
392 default: 390 default:
393 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, 391 RSAerror(RSA_R_UNKNOWN_PADDING_TYPE);
394 RSA_R_UNKNOWN_PADDING_TYPE);
395 goto err; 392 goto err;
396 } 393 }
397 if (i <= 0) 394 if (i <= 0)
@@ -402,24 +399,21 @@ RSA_eay_private_encrypt(int flen, const unsigned char *from, unsigned char *to,
402 399
403 if (BN_ucmp(f, rsa->n) >= 0) { 400 if (BN_ucmp(f, rsa->n) >= 0) {
404 /* usually the padding functions would catch this */ 401 /* usually the padding functions would catch this */
405 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, 402 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
406 RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
407 goto err; 403 goto err;
408 } 404 }
409 405
410 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) { 406 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {
411 blinding = rsa_get_blinding(rsa, &local_blinding, ctx); 407 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
412 if (blinding == NULL) { 408 if (blinding == NULL) {
413 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, 409 RSAerror(ERR_R_INTERNAL_ERROR);
414 ERR_R_INTERNAL_ERROR);
415 goto err; 410 goto err;
416 } 411 }
417 } 412 }
418 413
419 if (blinding != NULL) { 414 if (blinding != NULL) {
420 if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) { 415 if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {
421 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, 416 RSAerror(ERR_R_MALLOC_FAILURE);
422 ERR_R_MALLOC_FAILURE);
423 goto err; 417 goto err;
424 } 418 }
425 if (!rsa_blinding_convert(blinding, f, unblind, ctx)) 419 if (!rsa_blinding_convert(blinding, f, unblind, ctx))
@@ -509,15 +503,14 @@ RSA_eay_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
509 buf = malloc(num); 503 buf = malloc(num);
510 504
511 if (!f || !ret || !buf) { 505 if (!f || !ret || !buf) {
512 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE); 506 RSAerror(ERR_R_MALLOC_FAILURE);
513 goto err; 507 goto err;
514 } 508 }
515 509
516 /* This check was for equality but PGP does evil things 510 /* This check was for equality but PGP does evil things
517 * and chops off the top '0' bytes */ 511 * and chops off the top '0' bytes */
518 if (flen > num) { 512 if (flen > num) {
519 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 513 RSAerror(RSA_R_DATA_GREATER_THAN_MOD_LEN);
520 RSA_R_DATA_GREATER_THAN_MOD_LEN);
521 goto err; 514 goto err;
522 } 515 }
523 516
@@ -526,24 +519,21 @@ RSA_eay_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
526 goto err; 519 goto err;
527 520
528 if (BN_ucmp(f, rsa->n) >= 0) { 521 if (BN_ucmp(f, rsa->n) >= 0) {
529 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 522 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
530 RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
531 goto err; 523 goto err;
532 } 524 }
533 525
534 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) { 526 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {
535 blinding = rsa_get_blinding(rsa, &local_blinding, ctx); 527 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
536 if (blinding == NULL) { 528 if (blinding == NULL) {
537 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 529 RSAerror(ERR_R_INTERNAL_ERROR);
538 ERR_R_INTERNAL_ERROR);
539 goto err; 530 goto err;
540 } 531 }
541 } 532 }
542 533
543 if (blinding != NULL) { 534 if (blinding != NULL) {
544 if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) { 535 if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {
545 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 536 RSAerror(ERR_R_MALLOC_FAILURE);
546 ERR_R_MALLOC_FAILURE);
547 goto err; 537 goto err;
548 } 538 }
549 if (!rsa_blinding_convert(blinding, f, unblind, ctx)) 539 if (!rsa_blinding_convert(blinding, f, unblind, ctx))
@@ -596,13 +586,11 @@ RSA_eay_private_decrypt(int flen, const unsigned char *from, unsigned char *to,
596 r = RSA_padding_check_none(to, num, buf, j, num); 586 r = RSA_padding_check_none(to, num, buf, j, num);
597 break; 587 break;
598 default: 588 default:
599 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 589 RSAerror(RSA_R_UNKNOWN_PADDING_TYPE);
600 RSA_R_UNKNOWN_PADDING_TYPE);
601 goto err; 590 goto err;
602 } 591 }
603 if (r < 0) 592 if (r < 0)
604 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, 593 RSAerror(RSA_R_PADDING_CHECK_FAILED);
605 RSA_R_PADDING_CHECK_FAILED);
606 594
607err: 595err:
608 if (ctx != NULL) { 596 if (ctx != NULL) {
@@ -628,19 +616,19 @@ RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
628 BN_CTX *ctx = NULL; 616 BN_CTX *ctx = NULL;
629 617
630 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) { 618 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {
631 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE); 619 RSAerror(RSA_R_MODULUS_TOO_LARGE);
632 return -1; 620 return -1;
633 } 621 }
634 622
635 if (BN_ucmp(rsa->n, rsa->e) <= 0) { 623 if (BN_ucmp(rsa->n, rsa->e) <= 0) {
636 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE); 624 RSAerror(RSA_R_BAD_E_VALUE);
637 return -1; 625 return -1;
638 } 626 }
639 627
640 /* for large moduli, enforce exponent limit */ 628 /* for large moduli, enforce exponent limit */
641 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) { 629 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {
642 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) { 630 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {
643 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE); 631 RSAerror(RSA_R_BAD_E_VALUE);
644 return -1; 632 return -1;
645 } 633 }
646 } 634 }
@@ -655,15 +643,14 @@ RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
655 buf = malloc(num); 643 buf = malloc(num);
656 644
657 if (!f || !ret || !buf) { 645 if (!f || !ret || !buf) {
658 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE); 646 RSAerror(ERR_R_MALLOC_FAILURE);
659 goto err; 647 goto err;
660 } 648 }
661 649
662 /* This check was for equality but PGP does evil things 650 /* This check was for equality but PGP does evil things
663 * and chops off the top '0' bytes */ 651 * and chops off the top '0' bytes */
664 if (flen > num) { 652 if (flen > num) {
665 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, 653 RSAerror(RSA_R_DATA_GREATER_THAN_MOD_LEN);
666 RSA_R_DATA_GREATER_THAN_MOD_LEN);
667 goto err; 654 goto err;
668 } 655 }
669 656
@@ -671,8 +658,7 @@ RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
671 goto err; 658 goto err;
672 659
673 if (BN_ucmp(f, rsa->n) >= 0) { 660 if (BN_ucmp(f, rsa->n) >= 0) {
674 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, 661 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
675 RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
676 goto err; 662 goto err;
677 } 663 }
678 664
@@ -703,13 +689,11 @@ RSA_eay_public_decrypt(int flen, const unsigned char *from, unsigned char *to,
703 r = RSA_padding_check_none(to, num, buf, i, num); 689 r = RSA_padding_check_none(to, num, buf, i, num);
704 break; 690 break;
705 default: 691 default:
706 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, 692 RSAerror(RSA_R_UNKNOWN_PADDING_TYPE);
707 RSA_R_UNKNOWN_PADDING_TYPE);
708 goto err; 693 goto err;
709 } 694 }
710 if (r < 0) 695 if (r < 0)
711 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, 696 RSAerror(RSA_R_PADDING_CHECK_FAILED);
712 RSA_R_PADDING_CHECK_FAILED);
713 697
714err: 698err:
715 if (ctx != NULL) { 699 if (ctx != NULL) {
@@ -735,7 +719,7 @@ RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
735 m1 = BN_CTX_get(ctx); 719 m1 = BN_CTX_get(ctx);
736 vrfy = BN_CTX_get(ctx); 720 vrfy = BN_CTX_get(ctx);
737 if (r1 == NULL || m1 == NULL || vrfy == NULL) { 721 if (r1 == NULL || m1 == NULL || vrfy == NULL) {
738 RSAerr(RSA_F_RSA_EAY_MOD_EXP, ERR_R_MALLOC_FAILURE); 722 RSAerror(ERR_R_MALLOC_FAILURE);
739 goto err; 723 goto err;
740 } 724 }
741 725
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
index 81622c6099..c2b197c581 100644
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ b/src/lib/libcrypto/rsa/rsa_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_err.c,v 1.16 2015/02/15 14:35:30 miod Exp $ */ 1/* $OpenBSD: rsa_err.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,64 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RSA,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RSA,0,reason)
73 73
74static ERR_STRING_DATA RSA_str_functs[] = { 74static ERR_STRING_DATA RSA_str_functs[] = {
75 {ERR_FUNC(RSA_F_CHECK_PADDING_MD), "CHECK_PADDING_MD"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(RSA_F_DO_RSA_PRINT), "DO_RSA_PRINT"},
77 {ERR_FUNC(RSA_F_INT_RSA_VERIFY), "INT_RSA_VERIFY"},
78 {ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"},
79 {ERR_FUNC(RSA_F_OLD_RSA_PRIV_DECODE), "OLD_RSA_PRIV_DECODE"},
80 {ERR_FUNC(RSA_F_PKEY_RSA_CTRL), "PKEY_RSA_CTRL"},
81 {ERR_FUNC(RSA_F_PKEY_RSA_CTRL_STR), "PKEY_RSA_CTRL_STR"},
82 {ERR_FUNC(RSA_F_PKEY_RSA_SIGN), "PKEY_RSA_SIGN"},
83 {ERR_FUNC(RSA_F_PKEY_RSA_VERIFY), "PKEY_RSA_VERIFY"},
84 {ERR_FUNC(RSA_F_PKEY_RSA_VERIFYRECOVER), "PKEY_RSA_VERIFYRECOVER"},
85 {ERR_FUNC(RSA_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"},
86 {ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"},
87 {ERR_FUNC(RSA_F_RSA_EAY_MOD_EXP), "RSA_EAY_MOD_EXP"},
88 {ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"},
89 {ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"},
90 {ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"},
91 {ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"},
92 {ERR_FUNC(RSA_F_RSA_GENERATE_KEY), "RSA_generate_key"},
93 {ERR_FUNC(RSA_F_RSA_GENERATE_KEY_EX), "RSA_generate_key_ex"},
94 {ERR_FUNC(RSA_F_RSA_ITEM_VERIFY), "RSA_ITEM_VERIFY"},
95 {ERR_FUNC(RSA_F_RSA_MEMORY_LOCK), "RSA_memory_lock"},
96 {ERR_FUNC(RSA_F_RSA_NEW_METHOD), "RSA_new_method"},
97 {ERR_FUNC(RSA_F_RSA_NULL), "RSA_NULL"},
98 {ERR_FUNC(RSA_F_RSA_NULL_MOD_EXP), "RSA_NULL_MOD_EXP"},
99 {ERR_FUNC(RSA_F_RSA_NULL_PRIVATE_DECRYPT), "RSA_NULL_PRIVATE_DECRYPT"},
100 {ERR_FUNC(RSA_F_RSA_NULL_PRIVATE_ENCRYPT), "RSA_NULL_PRIVATE_ENCRYPT"},
101 {ERR_FUNC(RSA_F_RSA_NULL_PUBLIC_DECRYPT), "RSA_NULL_PUBLIC_DECRYPT"},
102 {ERR_FUNC(RSA_F_RSA_NULL_PUBLIC_ENCRYPT), "RSA_NULL_PUBLIC_ENCRYPT"},
103 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_NONE), "RSA_padding_add_none"},
104 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP), "RSA_padding_add_PKCS1_OAEP"},
105 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS), "RSA_padding_add_PKCS1_PSS"},
106 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1), "RSA_padding_add_PKCS1_PSS_mgf1"},
107 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1), "RSA_padding_add_PKCS1_type_1"},
108 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2), "RSA_padding_add_PKCS1_type_2"},
109 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_SSLV23), "RSA_padding_add_SSLv23"},
110 {ERR_FUNC(RSA_F_RSA_PADDING_ADD_X931), "RSA_padding_add_X931"},
111 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_NONE), "RSA_padding_check_none"},
112 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP), "RSA_padding_check_PKCS1_OAEP"},
113 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1), "RSA_padding_check_PKCS1_type_1"},
114 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2), "RSA_padding_check_PKCS1_type_2"},
115 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_SSLV23), "RSA_padding_check_SSLv23"},
116 {ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"},
117 {ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"},
118 {ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"},
119 {ERR_FUNC(RSA_F_RSA_PRIVATE_DECRYPT), "RSA_private_decrypt"},
120 {ERR_FUNC(RSA_F_RSA_PRIVATE_ENCRYPT), "RSA_private_encrypt"},
121 {ERR_FUNC(RSA_F_RSA_PRIV_DECODE), "RSA_PRIV_DECODE"},
122 {ERR_FUNC(RSA_F_RSA_PRIV_ENCODE), "RSA_PRIV_ENCODE"},
123 {ERR_FUNC(RSA_F_RSA_PUBLIC_DECRYPT), "RSA_public_decrypt"},
124 {ERR_FUNC(RSA_F_RSA_PUBLIC_ENCRYPT), "RSA_public_encrypt"},
125 {ERR_FUNC(RSA_F_RSA_PUB_DECODE), "RSA_PUB_DECODE"},
126 {ERR_FUNC(RSA_F_RSA_SETUP_BLINDING), "RSA_setup_blinding"},
127 {ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"},
128 {ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"},
129 {ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"},
130 {ERR_FUNC(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING), "RSA_verify_ASN1_OCTET_STRING"},
131 {ERR_FUNC(RSA_F_RSA_VERIFY_PKCS1_PSS), "RSA_verify_PKCS1_PSS"},
132 {ERR_FUNC(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1), "RSA_verify_PKCS1_PSS_mgf1"},
133 {0, NULL} 76 {0, NULL}
134}; 77};
135 78
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index e09dccb4a8..596eb8eb78 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_gen.c,v 1.21 2017/01/25 06:15:44 beck Exp $ */ 1/* $OpenBSD: rsa_gen.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -162,8 +162,7 @@ rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
162 ++degenerate < 3); 162 ++degenerate < 3);
163 if (degenerate == 3) { 163 if (degenerate == 3) {
164 ok = 0; /* we set our own err */ 164 ok = 0; /* we set our own err */
165 RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, 165 RSAerror(RSA_R_KEY_SIZE_TOO_SMALL);
166 RSA_R_KEY_SIZE_TOO_SMALL);
167 goto err; 166 goto err;
168 } 167 }
169 if (!BN_sub(r2, rsa->q, BN_value_one())) 168 if (!BN_sub(r2, rsa->q, BN_value_one()))
@@ -219,7 +218,7 @@ rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
219 ok = 1; 218 ok = 1;
220err: 219err:
221 if (ok == -1) { 220 if (ok == -1) {
222 RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN); 221 RSAerror(ERR_LIB_BN);
223 ok = 0; 222 ok = 0;
224 } 223 }
225 if (ctx != NULL) { 224 if (ctx != NULL) {
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 51dc94a134..31ea418427 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_lib.c,v 1.30 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: rsa_lib.c,v 1.31 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -132,7 +132,7 @@ RSA_new_method(ENGINE *engine)
132 132
133 ret = malloc(sizeof(RSA)); 133 ret = malloc(sizeof(RSA));
134 if (ret == NULL) { 134 if (ret == NULL) {
135 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 135 RSAerror(ERR_R_MALLOC_FAILURE);
136 return NULL; 136 return NULL;
137 } 137 }
138 138
@@ -140,7 +140,7 @@ RSA_new_method(ENGINE *engine)
140#ifndef OPENSSL_NO_ENGINE 140#ifndef OPENSSL_NO_ENGINE
141 if (engine) { 141 if (engine) {
142 if (!ENGINE_init(engine)) { 142 if (!ENGINE_init(engine)) {
143 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); 143 RSAerror(ERR_R_ENGINE_LIB);
144 free(ret); 144 free(ret);
145 return NULL; 145 return NULL;
146 } 146 }
@@ -150,7 +150,7 @@ RSA_new_method(ENGINE *engine)
150 if (ret->engine) { 150 if (ret->engine) {
151 ret->meth = ENGINE_get_RSA(ret->engine); 151 ret->meth = ENGINE_get_RSA(ret->engine);
152 if (!ret->meth) { 152 if (!ret->meth) {
153 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); 153 RSAerror(ERR_R_ENGINE_LIB);
154 ENGINE_finish(ret->engine); 154 ENGINE_finish(ret->engine);
155 free(ret); 155 free(ret);
156 return NULL; 156 return NULL;
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c
index 5222b3c1eb..13d3449a9f 100644
--- a/src/lib/libcrypto/rsa/rsa_none.c
+++ b/src/lib/libcrypto/rsa/rsa_none.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_none.c,v 1.10 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: rsa_none.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -68,14 +68,12 @@ RSA_padding_add_none(unsigned char *to, int tlen, const unsigned char *from,
68 int flen) 68 int flen)
69{ 69{
70 if (flen > tlen) { 70 if (flen > tlen) {
71 RSAerr(RSA_F_RSA_PADDING_ADD_NONE, 71 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
72 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
73 return 0; 72 return 0;
74 } 73 }
75 74
76 if (flen < tlen) { 75 if (flen < tlen) {
77 RSAerr(RSA_F_RSA_PADDING_ADD_NONE, 76 RSAerror(RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
78 RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
79 return 0; 77 return 0;
80 } 78 }
81 79
@@ -88,7 +86,7 @@ RSA_padding_check_none(unsigned char *to, int tlen, const unsigned char *from,
88 int flen, int num) 86 int flen, int num)
89{ 87{
90 if (flen > tlen) { 88 if (flen > tlen) {
91 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE, RSA_R_DATA_TOO_LARGE); 89 RSAerror(RSA_R_DATA_TOO_LARGE);
92 return -1; 90 return -1;
93 } 91 }
94 92
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index 86e2bfc34f..cd7af203b7 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_oaep.c,v 1.25 2015/06/20 12:01:14 jsing Exp $ */ 1/* $OpenBSD: rsa_oaep.c,v 1.26 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Ulf Moeller. This software is distributed on an "AS IS" 2/* Written by Ulf Moeller. This software is distributed on an "AS IS"
3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ 3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */
4 4
@@ -44,14 +44,12 @@ RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
44 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH]; 44 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
45 45
46 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) { 46 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) {
47 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, 47 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
48 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
49 return 0; 48 return 0;
50 } 49 }
51 50
52 if (emlen < 2 * SHA_DIGEST_LENGTH + 1) { 51 if (emlen < 2 * SHA_DIGEST_LENGTH + 1) {
53 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, 52 RSAerror(RSA_R_KEY_SIZE_TOO_SMALL);
54 RSA_R_KEY_SIZE_TOO_SMALL);
55 return 0; 53 return 0;
56 } 54 }
57 55
@@ -69,7 +67,7 @@ RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
69 67
70 dbmask = malloc(emlen - SHA_DIGEST_LENGTH); 68 dbmask = malloc(emlen - SHA_DIGEST_LENGTH);
71 if (dbmask == NULL) { 69 if (dbmask == NULL) {
72 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 70 RSAerror(ERR_R_MALLOC_FAILURE);
73 return 0; 71 return 0;
74 } 72 }
75 73
@@ -126,8 +124,7 @@ RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
126 dblen = num - SHA_DIGEST_LENGTH; 124 dblen = num - SHA_DIGEST_LENGTH;
127 db = malloc(dblen + num); 125 db = malloc(dblen + num);
128 if (db == NULL) { 126 if (db == NULL) {
129 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, 127 RSAerror(ERR_R_MALLOC_FAILURE);
130 ERR_R_MALLOC_FAILURE);
131 return -1; 128 return -1;
132 } 129 }
133 130
@@ -167,8 +164,7 @@ RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
167 164
168 mlen = dblen - ++i; 165 mlen = dblen - ++i;
169 if (tlen < mlen) { 166 if (tlen < mlen) {
170 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, 167 RSAerror(RSA_R_DATA_TOO_LARGE);
171 RSA_R_DATA_TOO_LARGE);
172 mlen = -1; 168 mlen = -1;
173 } else 169 } else
174 memcpy(to, db + i, mlen); 170 memcpy(to, db + i, mlen);
@@ -182,7 +178,7 @@ decoding_err:
182 * To avoid chosen ciphertext attacks, the error message should not 178 * To avoid chosen ciphertext attacks, the error message should not
183 * reveal which kind of decoding error happened 179 * reveal which kind of decoding error happened
184 */ 180 */
185 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); 181 RSAerror(RSA_R_OAEP_DECODING_ERROR);
186 free(db); 182 free(db);
187 return -1; 183 return -1;
188} 184}
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
index 6c3e7fb846..6de263113f 100644
--- a/src/lib/libcrypto/rsa/rsa_pk1.c
+++ b/src/lib/libcrypto/rsa/rsa_pk1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pk1.c,v 1.14 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: rsa_pk1.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -72,8 +72,7 @@ RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
72 unsigned char *p; 72 unsigned char *p;
73 73
74 if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) { 74 if (flen > (tlen - RSA_PKCS1_PADDING_SIZE)) {
75 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1, 75 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
76 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
77 return 0; 76 return 0;
78 } 77 }
79 78
@@ -101,8 +100,7 @@ RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
101 100
102 p = from; 101 p = from;
103 if (num != flen + 1 || *(p++) != 01) { 102 if (num != flen + 1 || *(p++) != 01) {
104 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 103 RSAerror(RSA_R_BLOCK_TYPE_IS_NOT_01);
105 RSA_R_BLOCK_TYPE_IS_NOT_01);
106 return -1; 104 return -1;
107 } 105 }
108 106
@@ -115,8 +113,7 @@ RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
115 p++; 113 p++;
116 break; 114 break;
117 } else { 115 } else {
118 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 116 RSAerror(RSA_R_BAD_FIXED_HEADER_DECRYPT);
119 RSA_R_BAD_FIXED_HEADER_DECRYPT);
120 return -1; 117 return -1;
121 } 118 }
122 } 119 }
@@ -124,21 +121,18 @@ RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
124 } 121 }
125 122
126 if (i == j) { 123 if (i == j) {
127 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 124 RSAerror(RSA_R_NULL_BEFORE_BLOCK_MISSING);
128 RSA_R_NULL_BEFORE_BLOCK_MISSING);
129 return -1; 125 return -1;
130 } 126 }
131 127
132 if (i < 8) { 128 if (i < 8) {
133 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 129 RSAerror(RSA_R_BAD_PAD_BYTE_COUNT);
134 RSA_R_BAD_PAD_BYTE_COUNT);
135 return -1; 130 return -1;
136 } 131 }
137 i++; /* Skip over the '\0' */ 132 i++; /* Skip over the '\0' */
138 j -= i; 133 j -= i;
139 if (j > tlen) { 134 if (j > tlen) {
140 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, 135 RSAerror(RSA_R_DATA_TOO_LARGE);
141 RSA_R_DATA_TOO_LARGE);
142 return -1; 136 return -1;
143 } 137 }
144 memcpy(to, p, j); 138 memcpy(to, p, j);
@@ -154,8 +148,7 @@ RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
154 unsigned char *p; 148 unsigned char *p;
155 149
156 if (flen > tlen - 11) { 150 if (flen > tlen - 11) {
157 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2, 151 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
158 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
159 return 0; 152 return 0;
160 } 153 }
161 154
@@ -189,8 +182,7 @@ RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
189 182
190 p = from; 183 p = from;
191 if (num != flen + 1 || *(p++) != 02) { 184 if (num != flen + 1 || *(p++) != 02) {
192 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, 185 RSAerror(RSA_R_BLOCK_TYPE_IS_NOT_02);
193 RSA_R_BLOCK_TYPE_IS_NOT_02);
194 return -1; 186 return -1;
195 } 187 }
196 188
@@ -201,21 +193,18 @@ RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
201 break; 193 break;
202 194
203 if (i == j) { 195 if (i == j) {
204 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, 196 RSAerror(RSA_R_NULL_BEFORE_BLOCK_MISSING);
205 RSA_R_NULL_BEFORE_BLOCK_MISSING);
206 return -1; 197 return -1;
207 } 198 }
208 199
209 if (i < 8) { 200 if (i < 8) {
210 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, 201 RSAerror(RSA_R_BAD_PAD_BYTE_COUNT);
211 RSA_R_BAD_PAD_BYTE_COUNT);
212 return -1; 202 return -1;
213 } 203 }
214 i++; /* Skip over the '\0' */ 204 i++; /* Skip over the '\0' */
215 j -= i; 205 j -= i;
216 if (j > tlen) { 206 if (j > tlen) {
217 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, 207 RSAerror(RSA_R_DATA_TOO_LARGE);
218 RSA_R_DATA_TOO_LARGE);
219 return -1; 208 return -1;
220 } 209 }
221 memcpy(to, p, j); 210 memcpy(to, p, j);
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c
index 4b7fc09514..2ef1f3c64a 100644
--- a/src/lib/libcrypto/rsa/rsa_pmeth.c
+++ b/src/lib/libcrypto/rsa/rsa_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pmeth.c,v 1.18 2016/10/19 16:49:11 jsing Exp $ */ 1/* $OpenBSD: rsa_pmeth.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -170,8 +170,7 @@ pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
170 170
171 if (rctx->md) { 171 if (rctx->md) {
172 if (tbslen != (size_t)EVP_MD_size(rctx->md)) { 172 if (tbslen != (size_t)EVP_MD_size(rctx->md)) {
173 RSAerr(RSA_F_PKEY_RSA_SIGN, 173 RSAerror(RSA_R_INVALID_DIGEST_LENGTH);
174 RSA_R_INVALID_DIGEST_LENGTH);
175 return -1; 174 return -1;
176 } 175 }
177 176
@@ -228,13 +227,11 @@ pkey_rsa_verifyrecover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen,
228 ret--; 227 ret--;
229 if (rctx->tbuf[ret] != 228 if (rctx->tbuf[ret] !=
230 RSA_X931_hash_id(EVP_MD_type(rctx->md))) { 229 RSA_X931_hash_id(EVP_MD_type(rctx->md))) {
231 RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER, 230 RSAerror(RSA_R_ALGORITHM_MISMATCH);
232 RSA_R_ALGORITHM_MISMATCH);
233 return 0; 231 return 0;
234 } 232 }
235 if (ret != EVP_MD_size(rctx->md)) { 233 if (ret != EVP_MD_size(rctx->md)) {
236 RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER, 234 RSAerror(RSA_R_INVALID_DIGEST_LENGTH);
237 RSA_R_INVALID_DIGEST_LENGTH);
238 return 0; 235 return 0;
239 } 236 }
240 if (rout) 237 if (rout)
@@ -342,14 +339,13 @@ check_padding_md(const EVP_MD *md, int padding)
342 return 1; 339 return 1;
343 340
344 if (padding == RSA_NO_PADDING) { 341 if (padding == RSA_NO_PADDING) {
345 RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_PADDING_MODE); 342 RSAerror(RSA_R_INVALID_PADDING_MODE);
346 return 0; 343 return 0;
347 } 344 }
348 345
349 if (padding == RSA_X931_PADDING) { 346 if (padding == RSA_X931_PADDING) {
350 if (RSA_X931_hash_id(EVP_MD_type(md)) == -1) { 347 if (RSA_X931_hash_id(EVP_MD_type(md)) == -1) {
351 RSAerr(RSA_F_CHECK_PADDING_MD, 348 RSAerror(RSA_R_INVALID_X931_DIGEST);
352 RSA_R_INVALID_X931_DIGEST);
353 return 0; 349 return 0;
354 } 350 }
355 return 1; 351 return 1;
@@ -385,8 +381,7 @@ pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
385 return 1; 381 return 1;
386 } 382 }
387bad_pad: 383bad_pad:
388 RSAerr(RSA_F_PKEY_RSA_CTRL, 384 RSAerror(RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
389 RSA_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
390 return -2; 385 return -2;
391 386
392 case EVP_PKEY_CTRL_GET_RSA_PADDING: 387 case EVP_PKEY_CTRL_GET_RSA_PADDING:
@@ -396,7 +391,7 @@ bad_pad:
396 case EVP_PKEY_CTRL_RSA_PSS_SALTLEN: 391 case EVP_PKEY_CTRL_RSA_PSS_SALTLEN:
397 case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN: 392 case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
398 if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) { 393 if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) {
399 RSAerr(RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_PSS_SALTLEN); 394 RSAerror(RSA_R_INVALID_PSS_SALTLEN);
400 return -2; 395 return -2;
401 } 396 }
402 if (type == EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN) 397 if (type == EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN)
@@ -410,7 +405,7 @@ bad_pad:
410 405
411 case EVP_PKEY_CTRL_RSA_KEYGEN_BITS: 406 case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
412 if (p1 < 256) { 407 if (p1 < 256) {
413 RSAerr(RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_KEYBITS); 408 RSAerror(RSA_R_INVALID_KEYBITS);
414 return -2; 409 return -2;
415 } 410 }
416 rctx->nbits = p1; 411 rctx->nbits = p1;
@@ -431,7 +426,7 @@ bad_pad:
431 case EVP_PKEY_CTRL_RSA_MGF1_MD: 426 case EVP_PKEY_CTRL_RSA_MGF1_MD:
432 case EVP_PKEY_CTRL_GET_RSA_MGF1_MD: 427 case EVP_PKEY_CTRL_GET_RSA_MGF1_MD:
433 if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) { 428 if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) {
434 RSAerr(RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_MGF1_MD); 429 RSAerror(RSA_R_INVALID_MGF1_MD);
435 return -2; 430 return -2;
436 } 431 }
437 if (type == EVP_PKEY_CTRL_GET_RSA_MGF1_MD) { 432 if (type == EVP_PKEY_CTRL_GET_RSA_MGF1_MD) {
@@ -449,8 +444,7 @@ bad_pad:
449 case EVP_PKEY_CTRL_PKCS7_SIGN: 444 case EVP_PKEY_CTRL_PKCS7_SIGN:
450 return 1; 445 return 1;
451 case EVP_PKEY_CTRL_PEER_KEY: 446 case EVP_PKEY_CTRL_PEER_KEY:
452 RSAerr(RSA_F_PKEY_RSA_CTRL, 447 RSAerror(RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
453 RSA_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
454 return -2; 448 return -2;
455 449
456 default: 450 default:
@@ -465,7 +459,7 @@ pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
465 char *ep; 459 char *ep;
466 460
467 if (!value) { 461 if (!value) {
468 RSAerr(RSA_F_PKEY_RSA_CTRL_STR, RSA_R_VALUE_MISSING); 462 RSAerror(RSA_R_VALUE_MISSING);
469 return 0; 463 return 0;
470 } 464 }
471 if (!strcmp(type, "rsa_padding_mode")) { 465 if (!strcmp(type, "rsa_padding_mode")) {
@@ -485,8 +479,7 @@ pkey_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
485 else if (!strcmp(value, "pss")) 479 else if (!strcmp(value, "pss"))
486 pm = RSA_PKCS1_PSS_PADDING; 480 pm = RSA_PKCS1_PSS_PADDING;
487 else { 481 else {
488 RSAerr(RSA_F_PKEY_RSA_CTRL_STR, 482 RSAerror(RSA_R_UNKNOWN_PADDING_TYPE);
489 RSA_R_UNKNOWN_PADDING_TYPE);
490 return -2; 483 return -2;
491 } 484 }
492 return EVP_PKEY_CTX_set_rsa_padding(ctx, pm); 485 return EVP_PKEY_CTX_set_rsa_padding(ctx, pm);
diff --git a/src/lib/libcrypto/rsa/rsa_prn.c b/src/lib/libcrypto/rsa/rsa_prn.c
index db82dab5be..c46b08c00d 100644
--- a/src/lib/libcrypto/rsa/rsa_prn.c
+++ b/src/lib/libcrypto/rsa/rsa_prn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_prn.c,v 1.6 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: rsa_prn.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -69,7 +69,7 @@ RSA_print_fp(FILE *fp, const RSA *x, int off)
69 int ret; 69 int ret;
70 70
71 if ((b = BIO_new(BIO_s_file())) == NULL) { 71 if ((b = BIO_new(BIO_s_file())) == NULL) {
72 RSAerr(RSA_F_RSA_PRINT_FP, ERR_R_BUF_LIB); 72 RSAerror(ERR_R_BUF_LIB);
73 return 0; 73 return 0;
74 } 74 }
75 BIO_set_fp(b, fp, BIO_NOCLOSE); 75 BIO_set_fp(b, fp, BIO_NOCLOSE);
diff --git a/src/lib/libcrypto/rsa/rsa_pss.c b/src/lib/libcrypto/rsa/rsa_pss.c
index 5e137a3090..870f634b8d 100644
--- a/src/lib/libcrypto/rsa/rsa_pss.c
+++ b/src/lib/libcrypto/rsa/rsa_pss.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pss.c,v 1.11 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: rsa_pss.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -107,16 +107,14 @@ RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
107 else if (sLen == -2) 107 else if (sLen == -2)
108 sLen = -2; 108 sLen = -2;
109 else if (sLen < -2) { 109 else if (sLen < -2) {
110 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 110 RSAerror(RSA_R_SLEN_CHECK_FAILED);
111 RSA_R_SLEN_CHECK_FAILED);
112 goto err; 111 goto err;
113 } 112 }
114 113
115 MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; 114 MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;
116 emLen = RSA_size(rsa); 115 emLen = RSA_size(rsa);
117 if (EM[0] & (0xFF << MSBits)) { 116 if (EM[0] & (0xFF << MSBits)) {
118 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 117 RSAerror(RSA_R_FIRST_OCTET_INVALID);
119 RSA_R_FIRST_OCTET_INVALID);
120 goto err; 118 goto err;
121 } 119 }
122 if (MSBits == 0) { 120 if (MSBits == 0) {
@@ -125,19 +123,18 @@ RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
125 } 123 }
126 if (emLen < (hLen + sLen + 2)) { 124 if (emLen < (hLen + sLen + 2)) {
127 /* sLen can be small negative */ 125 /* sLen can be small negative */
128 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_DATA_TOO_LARGE); 126 RSAerror(RSA_R_DATA_TOO_LARGE);
129 goto err; 127 goto err;
130 } 128 }
131 if (EM[emLen - 1] != 0xbc) { 129 if (EM[emLen - 1] != 0xbc) {
132 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 130 RSAerror(RSA_R_LAST_OCTET_INVALID);
133 RSA_R_LAST_OCTET_INVALID);
134 goto err; 131 goto err;
135 } 132 }
136 maskedDBLen = emLen - hLen - 1; 133 maskedDBLen = emLen - hLen - 1;
137 H = EM + maskedDBLen; 134 H = EM + maskedDBLen;
138 DB = malloc(maskedDBLen); 135 DB = malloc(maskedDBLen);
139 if (!DB) { 136 if (!DB) {
140 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE); 137 RSAerror(ERR_R_MALLOC_FAILURE);
141 goto err; 138 goto err;
142 } 139 }
143 if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0) 140 if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0)
@@ -149,13 +146,11 @@ RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
149 for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) 146 for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++)
150 ; 147 ;
151 if (DB[i++] != 0x1) { 148 if (DB[i++] != 0x1) {
152 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 149 RSAerror(RSA_R_SLEN_RECOVERY_FAILED);
153 RSA_R_SLEN_RECOVERY_FAILED);
154 goto err; 150 goto err;
155 } 151 }
156 if (sLen >= 0 && (maskedDBLen - i) != sLen) { 152 if (sLen >= 0 && (maskedDBLen - i) != sLen) {
157 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, 153 RSAerror(RSA_R_SLEN_CHECK_FAILED);
158 RSA_R_SLEN_CHECK_FAILED);
159 goto err; 154 goto err;
160 } 155 }
161 if (!EVP_DigestInit_ex(&ctx, Hash, NULL) || 156 if (!EVP_DigestInit_ex(&ctx, Hash, NULL) ||
@@ -169,7 +164,7 @@ RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
169 if (!EVP_DigestFinal_ex(&ctx, H_, NULL)) 164 if (!EVP_DigestFinal_ex(&ctx, H_, NULL))
170 goto err; 165 goto err;
171 if (memcmp(H_, H, hLen)) { 166 if (memcmp(H_, H, hLen)) {
172 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_BAD_SIGNATURE); 167 RSAerror(RSA_R_BAD_SIGNATURE);
173 ret = 0; 168 ret = 0;
174 } else 169 } else
175 ret = 1; 170 ret = 1;
@@ -218,8 +213,7 @@ RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
218 else if (sLen == -2) 213 else if (sLen == -2)
219 sLen = -2; 214 sLen = -2;
220 else if (sLen < -2) { 215 else if (sLen < -2) {
221 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1, 216 RSAerror(RSA_R_SLEN_CHECK_FAILED);
222 RSA_R_SLEN_CHECK_FAILED);
223 goto err; 217 goto err;
224 } 218 }
225 219
@@ -232,15 +226,13 @@ RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
232 if (sLen == -2) 226 if (sLen == -2)
233 sLen = emLen - hLen - 2; 227 sLen = emLen - hLen - 2;
234 else if (emLen < (hLen + sLen + 2)) { 228 else if (emLen < (hLen + sLen + 2)) {
235 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1, 229 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
236 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
237 goto err; 230 goto err;
238 } 231 }
239 if (sLen > 0) { 232 if (sLen > 0) {
240 salt = malloc(sLen); 233 salt = malloc(sLen);
241 if (!salt) { 234 if (!salt) {
242 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1, 235 RSAerror(ERR_R_MALLOC_FAILURE);
243 ERR_R_MALLOC_FAILURE);
244 goto err; 236 goto err;
245 } 237 }
246 arc4random_buf(salt, sLen); 238 arc4random_buf(salt, sLen);
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index 5dbc10dbb2..179217c236 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_saos.c,v 1.19 2015/09/30 18:41:06 jsing Exp $ */ 1/* $OpenBSD: rsa_saos.c,v 1.20 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,13 +80,12 @@ RSA_sign_ASN1_OCTET_STRING(int type, const unsigned char *m, unsigned int m_len,
80 i = i2d_ASN1_OCTET_STRING(&sig, NULL); 80 i = i2d_ASN1_OCTET_STRING(&sig, NULL);
81 j = RSA_size(rsa); 81 j = RSA_size(rsa);
82 if (i > (j - RSA_PKCS1_PADDING_SIZE)) { 82 if (i > (j - RSA_PKCS1_PADDING_SIZE)) {
83 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, 83 RSAerror(RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
84 RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
85 return 0; 84 return 0;
86 } 85 }
87 s = malloc(j + 1); 86 s = malloc(j + 1);
88 if (s == NULL) { 87 if (s == NULL) {
89 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); 88 RSAerror(ERR_R_MALLOC_FAILURE);
90 return 0; 89 return 0;
91 } 90 }
92 p = s; 91 p = s;
@@ -112,15 +111,13 @@ RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
112 ASN1_OCTET_STRING *sig = NULL; 111 ASN1_OCTET_STRING *sig = NULL;
113 112
114 if (siglen != (unsigned int)RSA_size(rsa)) { 113 if (siglen != (unsigned int)RSA_size(rsa)) {
115 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, 114 RSAerror(RSA_R_WRONG_SIGNATURE_LENGTH);
116 RSA_R_WRONG_SIGNATURE_LENGTH);
117 return 0; 115 return 0;
118 } 116 }
119 117
120 s = malloc(siglen); 118 s = malloc(siglen);
121 if (s == NULL) { 119 if (s == NULL) {
122 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, 120 RSAerror(ERR_R_MALLOC_FAILURE);
123 ERR_R_MALLOC_FAILURE);
124 goto err; 121 goto err;
125 } 122 }
126 i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING); 123 i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);
@@ -135,8 +132,7 @@ RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
135 132
136 if ((unsigned int)sig->length != m_len || 133 if ((unsigned int)sig->length != m_len ||
137 memcmp(m, sig->data, m_len) != 0) { 134 memcmp(m, sig->data, m_len) != 0) {
138 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, 135 RSAerror(RSA_R_BAD_SIGNATURE);
139 RSA_R_BAD_SIGNATURE);
140 } else 136 } else
141 ret = 1; 137 ret = 1;
142err: 138err:
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 7be08f544b..52cbc3dfe3 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_sign.c,v 1.25 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: rsa_sign.c,v 1.26 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -88,7 +88,7 @@ RSA_sign(int type, const unsigned char *m, unsigned int m_len,
88 /* Special case: SSL signature, just check the length */ 88 /* Special case: SSL signature, just check the length */
89 if (type == NID_md5_sha1) { 89 if (type == NID_md5_sha1) {
90 if (m_len != SSL_SIG_LENGTH) { 90 if (m_len != SSL_SIG_LENGTH) {
91 RSAerr(RSA_F_RSA_SIGN, RSA_R_INVALID_MESSAGE_LENGTH); 91 RSAerror(RSA_R_INVALID_MESSAGE_LENGTH);
92 return 0; 92 return 0;
93 } 93 }
94 i = SSL_SIG_LENGTH; 94 i = SSL_SIG_LENGTH;
@@ -97,12 +97,11 @@ RSA_sign(int type, const unsigned char *m, unsigned int m_len,
97 sig.algor = &algor; 97 sig.algor = &algor;
98 sig.algor->algorithm = OBJ_nid2obj(type); 98 sig.algor->algorithm = OBJ_nid2obj(type);
99 if (sig.algor->algorithm == NULL) { 99 if (sig.algor->algorithm == NULL) {
100 RSAerr(RSA_F_RSA_SIGN, RSA_R_UNKNOWN_ALGORITHM_TYPE); 100 RSAerror(RSA_R_UNKNOWN_ALGORITHM_TYPE);
101 return 0; 101 return 0;
102 } 102 }
103 if (sig.algor->algorithm->length == 0) { 103 if (sig.algor->algorithm->length == 0) {
104 RSAerr(RSA_F_RSA_SIGN, 104 RSAerror(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
105 RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
106 return 0; 105 return 0;
107 } 106 }
108 parameter.type = V_ASN1_NULL; 107 parameter.type = V_ASN1_NULL;
@@ -117,13 +116,13 @@ RSA_sign(int type, const unsigned char *m, unsigned int m_len,
117 } 116 }
118 j = RSA_size(rsa); 117 j = RSA_size(rsa);
119 if (i > j - RSA_PKCS1_PADDING_SIZE) { 118 if (i > j - RSA_PKCS1_PADDING_SIZE) {
120 RSAerr(RSA_F_RSA_SIGN, RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); 119 RSAerror(RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
121 return 0; 120 return 0;
122 } 121 }
123 if (type != NID_md5_sha1) { 122 if (type != NID_md5_sha1) {
124 tmps = malloc(j + 1); 123 tmps = malloc(j + 1);
125 if (tmps == NULL) { 124 if (tmps == NULL) {
126 RSAerr(RSA_F_RSA_SIGN, ERR_R_MALLOC_FAILURE); 125 RSAerror(ERR_R_MALLOC_FAILURE);
127 return 0; 126 return 0;
128 } 127 }
129 p = tmps; 128 p = tmps;
@@ -153,7 +152,7 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
153 X509_SIG *sig = NULL; 152 X509_SIG *sig = NULL;
154 153
155 if (siglen != (unsigned int)RSA_size(rsa)) { 154 if (siglen != (unsigned int)RSA_size(rsa)) {
156 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_WRONG_SIGNATURE_LENGTH); 155 RSAerror(RSA_R_WRONG_SIGNATURE_LENGTH);
157 return 0; 156 return 0;
158 } 157 }
159 158
@@ -168,11 +167,11 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
168 167
169 s = malloc(siglen); 168 s = malloc(siglen);
170 if (s == NULL) { 169 if (s == NULL) {
171 RSAerr(RSA_F_INT_RSA_VERIFY, ERR_R_MALLOC_FAILURE); 170 RSAerror(ERR_R_MALLOC_FAILURE);
172 goto err; 171 goto err;
173 } 172 }
174 if (dtype == NID_md5_sha1 && m_len != SSL_SIG_LENGTH) { 173 if (dtype == NID_md5_sha1 && m_len != SSL_SIG_LENGTH) {
175 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_INVALID_MESSAGE_LENGTH); 174 RSAerror(RSA_R_INVALID_MESSAGE_LENGTH);
176 goto err; 175 goto err;
177 } 176 }
178 i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING); 177 i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);
@@ -183,7 +182,7 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
183 /* Special case: SSL signature */ 182 /* Special case: SSL signature */
184 if (dtype == NID_md5_sha1) { 183 if (dtype == NID_md5_sha1) {
185 if (i != SSL_SIG_LENGTH || memcmp(s, m, SSL_SIG_LENGTH)) 184 if (i != SSL_SIG_LENGTH || memcmp(s, m, SSL_SIG_LENGTH))
186 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE); 185 RSAerror(RSA_R_BAD_SIGNATURE);
187 else 186 else
188 ret = 1; 187 ret = 1;
189 } else { 188 } else {
@@ -196,7 +195,7 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
196 195
197 /* Excess data can be used to create forgeries */ 196 /* Excess data can be used to create forgeries */
198 if (p != s + i) { 197 if (p != s + i) {
199 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE); 198 RSAerror(RSA_R_BAD_SIGNATURE);
200 goto err; 199 goto err;
201 } 200 }
202 201
@@ -204,14 +203,14 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
204 create forgeries */ 203 create forgeries */
205 if (sig->algor->parameter && 204 if (sig->algor->parameter &&
206 ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL) { 205 ASN1_TYPE_get(sig->algor->parameter) != V_ASN1_NULL) {
207 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE); 206 RSAerror(RSA_R_BAD_SIGNATURE);
208 goto err; 207 goto err;
209 } 208 }
210 209
211 sigtype = OBJ_obj2nid(sig->algor->algorithm); 210 sigtype = OBJ_obj2nid(sig->algor->algorithm);
212 211
213 if (sigtype != dtype) { 212 if (sigtype != dtype) {
214 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_ALGORITHM_MISMATCH); 213 RSAerror(RSA_R_ALGORITHM_MISMATCH);
215 goto err; 214 goto err;
216 } 215 }
217 if (rm) { 216 if (rm) {
@@ -219,8 +218,7 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
219 218
220 md = EVP_get_digestbynid(dtype); 219 md = EVP_get_digestbynid(dtype);
221 if (md && (EVP_MD_size(md) != sig->digest->length)) 220 if (md && (EVP_MD_size(md) != sig->digest->length))
222 RSAerr(RSA_F_INT_RSA_VERIFY, 221 RSAerror(RSA_R_INVALID_DIGEST_LENGTH);
223 RSA_R_INVALID_DIGEST_LENGTH);
224 else { 222 else {
225 memcpy(rm, sig->digest->data, 223 memcpy(rm, sig->digest->data,
226 sig->digest->length); 224 sig->digest->length);
@@ -229,7 +227,7 @@ int_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
229 } 227 }
230 } else if ((unsigned int)sig->digest->length != m_len || 228 } else if ((unsigned int)sig->digest->length != m_len ||
231 memcmp(m, sig->digest->data, m_len) != 0) { 229 memcmp(m, sig->digest->data, m_len) != 0) {
232 RSAerr(RSA_F_INT_RSA_VERIFY, RSA_R_BAD_SIGNATURE); 230 RSAerror(RSA_R_BAD_SIGNATURE);
233 } else 231 } else
234 ret = 1; 232 ret = 1;
235 } 233 }
diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c
index 73262f29c1..60fc8ec94f 100644
--- a/src/lib/libcrypto/rsa/rsa_ssl.c
+++ b/src/lib/libcrypto/rsa/rsa_ssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_ssl.c,v 1.14 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: rsa_ssl.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -72,8 +72,7 @@ RSA_padding_add_SSLv23(unsigned char *to, int tlen, const unsigned char *from,
72 unsigned char *p; 72 unsigned char *p;
73 73
74 if (flen > tlen - 11) { 74 if (flen > tlen - 11) {
75 RSAerr(RSA_F_RSA_PADDING_ADD_SSLV23, 75 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
76 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
77 return 0; 76 return 0;
78 } 77 }
79 78
@@ -109,12 +108,11 @@ RSA_padding_check_SSLv23(unsigned char *to, int tlen, const unsigned char *from,
109 108
110 p = from; 109 p = from;
111 if (flen < 10) { 110 if (flen < 10) {
112 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL); 111 RSAerror(RSA_R_DATA_TOO_SMALL);
113 return -1; 112 return -1;
114 } 113 }
115 if (num != flen + 1 || *(p++) != 02) { 114 if (num != flen + 1 || *(p++) != 02) {
116 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, 115 RSAerror(RSA_R_BLOCK_TYPE_IS_NOT_02);
117 RSA_R_BLOCK_TYPE_IS_NOT_02);
118 return -1; 116 return -1;
119 } 117 }
120 118
@@ -125,8 +123,7 @@ RSA_padding_check_SSLv23(unsigned char *to, int tlen, const unsigned char *from,
125 break; 123 break;
126 124
127 if (i == j || i < 8) { 125 if (i == j || i < 8) {
128 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, 126 RSAerror(RSA_R_NULL_BEFORE_BLOCK_MISSING);
129 RSA_R_NULL_BEFORE_BLOCK_MISSING);
130 return -1; 127 return -1;
131 } 128 }
132 for (k = -9; k < -1; k++) { 129 for (k = -9; k < -1; k++) {
@@ -134,15 +131,14 @@ RSA_padding_check_SSLv23(unsigned char *to, int tlen, const unsigned char *from,
134 break; 131 break;
135 } 132 }
136 if (k == -1) { 133 if (k == -1) {
137 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, 134 RSAerror(RSA_R_SSLV3_ROLLBACK_ATTACK);
138 RSA_R_SSLV3_ROLLBACK_ATTACK);
139 return -1; 135 return -1;
140 } 136 }
141 137
142 i++; /* Skip over the '\0' */ 138 i++; /* Skip over the '\0' */
143 j -= i; 139 j -= i;
144 if (j > tlen) { 140 if (j > tlen) {
145 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_LARGE); 141 RSAerror(RSA_R_DATA_TOO_LARGE);
146 return -1; 142 return -1;
147 } 143 }
148 memcpy(to, p, j); 144 memcpy(to, p, j);
diff --git a/src/lib/libcrypto/rsa/rsa_x931.c b/src/lib/libcrypto/rsa/rsa_x931.c
index 2993b4028d..3579735ab2 100644
--- a/src/lib/libcrypto/rsa/rsa_x931.c
+++ b/src/lib/libcrypto/rsa/rsa_x931.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_x931.c,v 1.9 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: rsa_x931.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -78,8 +78,7 @@ RSA_padding_add_X931(unsigned char *to, int tlen, const unsigned char *from,
78 j = tlen - flen - 2; 78 j = tlen - flen - 2;
79 79
80 if (j < 0) { 80 if (j < 0) {
81 RSAerr(RSA_F_RSA_PADDING_ADD_X931, 81 RSAerror(RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
82 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
83 return -1; 82 return -1;
84 } 83 }
85 84
@@ -110,7 +109,7 @@ RSA_padding_check_X931(unsigned char *to, int tlen, const unsigned char *from,
110 const unsigned char *p = from; 109 const unsigned char *p = from;
111 110
112 if (num != flen || (*p != 0x6A && *p != 0x6B)) { 111 if (num != flen || (*p != 0x6A && *p != 0x6B)) {
113 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_HEADER); 112 RSAerror(RSA_R_INVALID_HEADER);
114 return -1; 113 return -1;
115 } 114 }
116 115
@@ -121,15 +120,13 @@ RSA_padding_check_X931(unsigned char *to, int tlen, const unsigned char *from,
121 if (c == 0xBA) 120 if (c == 0xBA)
122 break; 121 break;
123 if (c != 0xBB) { 122 if (c != 0xBB) {
124 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, 123 RSAerror(RSA_R_INVALID_PADDING);
125 RSA_R_INVALID_PADDING);
126 return -1; 124 return -1;
127 } 125 }
128 } 126 }
129 127
130 if (i == 0) { 128 if (i == 0) {
131 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, 129 RSAerror(RSA_R_INVALID_PADDING);
132 RSA_R_INVALID_PADDING);
133 return -1; 130 return -1;
134 } 131 }
135 132
@@ -138,7 +135,7 @@ RSA_padding_check_X931(unsigned char *to, int tlen, const unsigned char *from,
138 j = flen - 2; 135 j = flen - 2;
139 136
140 if (j < 0 || p[j] != 0xCC) { 137 if (j < 0 || p[j] != 0xCC) {
141 RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_TRAILER); 138 RSAerror(RSA_R_INVALID_TRAILER);
142 return -1; 139 return -1;
143 } 140 }
144 141
diff --git a/src/lib/libcrypto/ts/ts_asn1.c b/src/lib/libcrypto/ts/ts_asn1.c
index 49232d8073..bc89f1368a 100644
--- a/src/lib/libcrypto/ts/ts_asn1.c
+++ b/src/lib/libcrypto/ts/ts_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_asn1.c,v 1.10 2016/11/04 18:35:30 jsing Exp $ */ 1/* $OpenBSD: ts_asn1.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Nils Larsch for the OpenSSL project 2004. 2/* Written by Nils Larsch for the OpenSSL project 2004.
3 */ 3 */
4/* ==================================================================== 4/* ====================================================================
@@ -541,19 +541,18 @@ ts_resp_set_tst_info(TS_RESP *a)
541 541
542 if (a->token) { 542 if (a->token) {
543 if (status != 0 && status != 1) { 543 if (status != 0 && status != 1) {
544 TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_PRESENT); 544 TSerror(TS_R_TOKEN_PRESENT);
545 return 0; 545 return 0;
546 } 546 }
547 if (a->tst_info != NULL) 547 if (a->tst_info != NULL)
548 TS_TST_INFO_free(a->tst_info); 548 TS_TST_INFO_free(a->tst_info);
549 a->tst_info = PKCS7_to_TS_TST_INFO(a->token); 549 a->tst_info = PKCS7_to_TS_TST_INFO(a->token);
550 if (!a->tst_info) { 550 if (!a->tst_info) {
551 TSerr(TS_F_TS_RESP_SET_TST_INFO, 551 TSerror(TS_R_PKCS7_TO_TS_TST_INFO_FAILED);
552 TS_R_PKCS7_TO_TS_TST_INFO_FAILED);
553 return 0; 552 return 0;
554 } 553 }
555 } else if (status == 0 || status == 1) { 554 } else if (status == 0 || status == 1) {
556 TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_NOT_PRESENT); 555 TSerror(TS_R_TOKEN_NOT_PRESENT);
557 return 0; 556 return 0;
558 } 557 }
559 558
@@ -858,13 +857,13 @@ PKCS7_to_TS_TST_INFO(PKCS7 *token)
858 const unsigned char *p; 857 const unsigned char *p;
859 858
860 if (!PKCS7_type_is_signed(token)) { 859 if (!PKCS7_type_is_signed(token)) {
861 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE); 860 TSerror(TS_R_BAD_PKCS7_TYPE);
862 return NULL; 861 return NULL;
863 } 862 }
864 863
865 /* Content must be present. */ 864 /* Content must be present. */
866 if (PKCS7_get_detached(token)) { 865 if (PKCS7_get_detached(token)) {
867 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT); 866 TSerror(TS_R_DETACHED_CONTENT);
868 return NULL; 867 return NULL;
869 } 868 }
870 869
@@ -872,14 +871,14 @@ PKCS7_to_TS_TST_INFO(PKCS7 *token)
872 pkcs7_signed = token->d.sign; 871 pkcs7_signed = token->d.sign;
873 enveloped = pkcs7_signed->contents; 872 enveloped = pkcs7_signed->contents;
874 if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) { 873 if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) {
875 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE); 874 TSerror(TS_R_BAD_PKCS7_TYPE);
876 return NULL; 875 return NULL;
877 } 876 }
878 877
879 /* We have a DER encoded TST_INFO as the signed data. */ 878 /* We have a DER encoded TST_INFO as the signed data. */
880 tst_info_wrapper = enveloped->d.other; 879 tst_info_wrapper = enveloped->d.other;
881 if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) { 880 if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) {
882 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE); 881 TSerror(TS_R_BAD_TYPE);
883 return NULL; 882 return NULL;
884 } 883 }
885 884
diff --git a/src/lib/libcrypto/ts/ts_conf.c b/src/lib/libcrypto/ts/ts_conf.c
index bb98a6ff4c..c223aa3d46 100644
--- a/src/lib/libcrypto/ts/ts_conf.c
+++ b/src/lib/libcrypto/ts/ts_conf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_conf.c,v 1.9 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: ts_conf.c,v 1.10 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -245,8 +245,7 @@ TS_CONF_set_default_engine(const char *name)
245 245
246err: 246err:
247 if (!ret) { 247 if (!ret) {
248 TSerr(TS_F_TS_CONF_SET_DEFAULT_ENGINE, 248 TSerror(TS_R_COULD_NOT_SET_ENGINE);
249 TS_R_COULD_NOT_SET_ENGINE);
250 ERR_asprintf_error_data("engine:%s", name); 249 ERR_asprintf_error_data("engine:%s", name);
251 } 250 }
252 if (e) 251 if (e)
diff --git a/src/lib/libcrypto/ts/ts_err.c b/src/lib/libcrypto/ts/ts_err.c
index f71be883f8..4b89909384 100644
--- a/src/lib/libcrypto/ts/ts_err.c
+++ b/src/lib/libcrypto/ts/ts_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_err.c,v 1.4 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: ts_err.c,v 1.5 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,57 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_TS,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_TS,0,reason)
73 73
74static ERR_STRING_DATA TS_str_functs[] = { 74static ERR_STRING_DATA TS_str_functs[] = {
75 {ERR_FUNC(TS_F_D2I_TS_RESP), "d2i_TS_RESP"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(TS_F_DEF_SERIAL_CB), "DEF_SERIAL_CB"},
77 {ERR_FUNC(TS_F_DEF_TIME_CB), "DEF_TIME_CB"},
78 {ERR_FUNC(TS_F_ESS_ADD_SIGNING_CERT), "ESS_ADD_SIGNING_CERT"},
79 {ERR_FUNC(TS_F_ESS_CERT_ID_NEW_INIT), "ESS_CERT_ID_NEW_INIT"},
80 {ERR_FUNC(TS_F_ESS_SIGNING_CERT_NEW_INIT), "ESS_SIGNING_CERT_NEW_INIT"},
81 {ERR_FUNC(TS_F_INT_TS_RESP_VERIFY_TOKEN), "INT_TS_RESP_VERIFY_TOKEN"},
82 {ERR_FUNC(TS_F_PKCS7_TO_TS_TST_INFO), "PKCS7_to_TS_TST_INFO"},
83 {ERR_FUNC(TS_F_TS_ACCURACY_SET_MICROS), "TS_ACCURACY_set_micros"},
84 {ERR_FUNC(TS_F_TS_ACCURACY_SET_MILLIS), "TS_ACCURACY_set_millis"},
85 {ERR_FUNC(TS_F_TS_ACCURACY_SET_SECONDS), "TS_ACCURACY_set_seconds"},
86 {ERR_FUNC(TS_F_TS_CHECK_IMPRINTS), "TS_CHECK_IMPRINTS"},
87 {ERR_FUNC(TS_F_TS_CHECK_NONCES), "TS_CHECK_NONCES"},
88 {ERR_FUNC(TS_F_TS_CHECK_POLICY), "TS_CHECK_POLICY"},
89 {ERR_FUNC(TS_F_TS_CHECK_SIGNING_CERTS), "TS_CHECK_SIGNING_CERTS"},
90 {ERR_FUNC(TS_F_TS_CHECK_STATUS_INFO), "TS_CHECK_STATUS_INFO"},
91 {ERR_FUNC(TS_F_TS_COMPUTE_IMPRINT), "TS_COMPUTE_IMPRINT"},
92 {ERR_FUNC(TS_F_TS_CONF_SET_DEFAULT_ENGINE), "TS_CONF_set_default_engine"},
93 {ERR_FUNC(TS_F_TS_GET_STATUS_TEXT), "TS_GET_STATUS_TEXT"},
94 {ERR_FUNC(TS_F_TS_MSG_IMPRINT_SET_ALGO), "TS_MSG_IMPRINT_set_algo"},
95 {ERR_FUNC(TS_F_TS_REQ_SET_MSG_IMPRINT), "TS_REQ_set_msg_imprint"},
96 {ERR_FUNC(TS_F_TS_REQ_SET_NONCE), "TS_REQ_set_nonce"},
97 {ERR_FUNC(TS_F_TS_REQ_SET_POLICY_ID), "TS_REQ_set_policy_id"},
98 {ERR_FUNC(TS_F_TS_RESP_CREATE_RESPONSE), "TS_RESP_create_response"},
99 {ERR_FUNC(TS_F_TS_RESP_CREATE_TST_INFO), "TS_RESP_CREATE_TST_INFO"},
100 {ERR_FUNC(TS_F_TS_RESP_CTX_ADD_FAILURE_INFO), "TS_RESP_CTX_add_failure_info"},
101 {ERR_FUNC(TS_F_TS_RESP_CTX_ADD_MD), "TS_RESP_CTX_add_md"},
102 {ERR_FUNC(TS_F_TS_RESP_CTX_ADD_POLICY), "TS_RESP_CTX_add_policy"},
103 {ERR_FUNC(TS_F_TS_RESP_CTX_NEW), "TS_RESP_CTX_new"},
104 {ERR_FUNC(TS_F_TS_RESP_CTX_SET_ACCURACY), "TS_RESP_CTX_set_accuracy"},
105 {ERR_FUNC(TS_F_TS_RESP_CTX_SET_CERTS), "TS_RESP_CTX_set_certs"},
106 {ERR_FUNC(TS_F_TS_RESP_CTX_SET_DEF_POLICY), "TS_RESP_CTX_set_def_policy"},
107 {ERR_FUNC(TS_F_TS_RESP_CTX_SET_SIGNER_CERT), "TS_RESP_CTX_set_signer_cert"},
108 {ERR_FUNC(TS_F_TS_RESP_CTX_SET_STATUS_INFO), "TS_RESP_CTX_set_status_info"},
109 {ERR_FUNC(TS_F_TS_RESP_GET_POLICY), "TS_RESP_GET_POLICY"},
110 {ERR_FUNC(TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION), "TS_RESP_SET_GENTIME_WITH_PRECISION"},
111 {ERR_FUNC(TS_F_TS_RESP_SET_STATUS_INFO), "TS_RESP_set_status_info"},
112 {ERR_FUNC(TS_F_TS_RESP_SET_TST_INFO), "TS_RESP_set_tst_info"},
113 {ERR_FUNC(TS_F_TS_RESP_SIGN), "TS_RESP_SIGN"},
114 {ERR_FUNC(TS_F_TS_RESP_VERIFY_SIGNATURE), "TS_RESP_verify_signature"},
115 {ERR_FUNC(TS_F_TS_RESP_VERIFY_TOKEN), "TS_RESP_verify_token"},
116 {ERR_FUNC(TS_F_TS_TST_INFO_SET_ACCURACY), "TS_TST_INFO_set_accuracy"},
117 {ERR_FUNC(TS_F_TS_TST_INFO_SET_MSG_IMPRINT), "TS_TST_INFO_set_msg_imprint"},
118 {ERR_FUNC(TS_F_TS_TST_INFO_SET_NONCE), "TS_TST_INFO_set_nonce"},
119 {ERR_FUNC(TS_F_TS_TST_INFO_SET_POLICY_ID), "TS_TST_INFO_set_policy_id"},
120 {ERR_FUNC(TS_F_TS_TST_INFO_SET_SERIAL), "TS_TST_INFO_set_serial"},
121 {ERR_FUNC(TS_F_TS_TST_INFO_SET_TIME), "TS_TST_INFO_set_time"},
122 {ERR_FUNC(TS_F_TS_TST_INFO_SET_TSA), "TS_TST_INFO_set_tsa"},
123 {ERR_FUNC(TS_F_TS_VERIFY), "TS_VERIFY"},
124 {ERR_FUNC(TS_F_TS_VERIFY_CERT), "TS_VERIFY_CERT"},
125 {ERR_FUNC(TS_F_TS_VERIFY_CTX_NEW), "TS_VERIFY_CTX_new"},
126 {0, NULL} 76 {0, NULL}
127}; 77};
128 78
diff --git a/src/lib/libcrypto/ts/ts_req_utils.c b/src/lib/libcrypto/ts/ts_req_utils.c
index ab813b2b42..bd707c228f 100644
--- a/src/lib/libcrypto/ts/ts_req_utils.c
+++ b/src/lib/libcrypto/ts/ts_req_utils.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_req_utils.c,v 1.4 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: ts_req_utils.c,v 1.5 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -84,7 +84,7 @@ TS_REQ_set_msg_imprint(TS_REQ *a, TS_MSG_IMPRINT *msg_imprint)
84 return 1; 84 return 1;
85 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint); 85 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
86 if (new_msg_imprint == NULL) { 86 if (new_msg_imprint == NULL) {
87 TSerr(TS_F_TS_REQ_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE); 87 TSerror(ERR_R_MALLOC_FAILURE);
88 return 0; 88 return 0;
89 } 89 }
90 TS_MSG_IMPRINT_free(a->msg_imprint); 90 TS_MSG_IMPRINT_free(a->msg_imprint);
@@ -107,7 +107,7 @@ TS_MSG_IMPRINT_set_algo(TS_MSG_IMPRINT *a, X509_ALGOR *alg)
107 return 1; 107 return 1;
108 new_alg = X509_ALGOR_dup(alg); 108 new_alg = X509_ALGOR_dup(alg);
109 if (new_alg == NULL) { 109 if (new_alg == NULL) {
110 TSerr(TS_F_TS_MSG_IMPRINT_SET_ALGO, ERR_R_MALLOC_FAILURE); 110 TSerror(ERR_R_MALLOC_FAILURE);
111 return 0; 111 return 0;
112 } 112 }
113 X509_ALGOR_free(a->hash_algo); 113 X509_ALGOR_free(a->hash_algo);
@@ -142,7 +142,7 @@ TS_REQ_set_policy_id(TS_REQ *a, ASN1_OBJECT *policy)
142 return 1; 142 return 1;
143 new_policy = OBJ_dup(policy); 143 new_policy = OBJ_dup(policy);
144 if (new_policy == NULL) { 144 if (new_policy == NULL) {
145 TSerr(TS_F_TS_REQ_SET_POLICY_ID, ERR_R_MALLOC_FAILURE); 145 TSerror(ERR_R_MALLOC_FAILURE);
146 return 0; 146 return 0;
147 } 147 }
148 ASN1_OBJECT_free(a->policy_id); 148 ASN1_OBJECT_free(a->policy_id);
@@ -165,7 +165,7 @@ TS_REQ_set_nonce(TS_REQ *a, const ASN1_INTEGER *nonce)
165 return 1; 165 return 1;
166 new_nonce = ASN1_INTEGER_dup(nonce); 166 new_nonce = ASN1_INTEGER_dup(nonce);
167 if (new_nonce == NULL) { 167 if (new_nonce == NULL) {
168 TSerr(TS_F_TS_REQ_SET_NONCE, ERR_R_MALLOC_FAILURE); 168 TSerror(ERR_R_MALLOC_FAILURE);
169 return 0; 169 return 0;
170 } 170 }
171 ASN1_INTEGER_free(a->nonce); 171 ASN1_INTEGER_free(a->nonce);
diff --git a/src/lib/libcrypto/ts/ts_rsp_sign.c b/src/lib/libcrypto/ts/ts_rsp_sign.c
index f9e8c53cc8..57e2d7f348 100644
--- a/src/lib/libcrypto/ts/ts_rsp_sign.c
+++ b/src/lib/libcrypto/ts/ts_rsp_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_rsp_sign.c,v 1.20 2016/03/11 07:08:45 mmcc Exp $ */ 1/* $OpenBSD: ts_rsp_sign.c,v 1.21 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -103,7 +103,7 @@ def_serial_cb(struct TS_resp_ctx *ctx, void *data)
103 return serial; 103 return serial;
104 104
105err: 105err:
106 TSerr(TS_F_DEF_SERIAL_CB, ERR_R_MALLOC_FAILURE); 106 TSerror(ERR_R_MALLOC_FAILURE);
107 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, 107 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
108 "Error during serial number generation."); 108 "Error during serial number generation.");
109 return NULL; 109 return NULL;
@@ -116,7 +116,7 @@ def_time_cb(struct TS_resp_ctx *ctx, void *data, time_t *sec, long *usec)
116 struct timeval tv; 116 struct timeval tv;
117 117
118 if (gettimeofday(&tv, NULL) != 0) { 118 if (gettimeofday(&tv, NULL) != 0) {
119 TSerr(TS_F_DEF_TIME_CB, TS_R_TIME_SYSCALL_ERROR); 119 TSerror(TS_R_TIME_SYSCALL_ERROR);
120 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, 120 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
121 "Time is not available."); 121 "Time is not available.");
122 TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE); 122 TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
@@ -147,7 +147,7 @@ TS_RESP_CTX_new(void)
147 TS_RESP_CTX *ctx; 147 TS_RESP_CTX *ctx;
148 148
149 if (!(ctx = calloc(1, sizeof(TS_RESP_CTX)))) { 149 if (!(ctx = calloc(1, sizeof(TS_RESP_CTX)))) {
150 TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE); 150 TSerror(ERR_R_MALLOC_FAILURE);
151 return NULL; 151 return NULL;
152 } 152 }
153 153
@@ -181,8 +181,7 @@ int
181TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer) 181TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer)
182{ 182{
183 if (X509_check_purpose(signer, X509_PURPOSE_TIMESTAMP_SIGN, 0) != 1) { 183 if (X509_check_purpose(signer, X509_PURPOSE_TIMESTAMP_SIGN, 0) != 1) {
184 TSerr(TS_F_TS_RESP_CTX_SET_SIGNER_CERT, 184 TSerror(TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE);
185 TS_R_INVALID_SIGNER_CERTIFICATE_PURPOSE);
186 return 0; 185 return 0;
187 } 186 }
188 X509_free(ctx->signer_cert); 187 X509_free(ctx->signer_cert);
@@ -211,7 +210,7 @@ TS_RESP_CTX_set_def_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *def_policy)
211 return 1; 210 return 1;
212 211
213err: 212err:
214 TSerr(TS_F_TS_RESP_CTX_SET_DEF_POLICY, ERR_R_MALLOC_FAILURE); 213 TSerror(ERR_R_MALLOC_FAILURE);
215 return 0; 214 return 0;
216} 215}
217 216
@@ -227,7 +226,7 @@ TS_RESP_CTX_set_certs(TS_RESP_CTX *ctx, STACK_OF(X509) *certs)
227 if (!certs) 226 if (!certs)
228 return 1; 227 return 1;
229 if (!(ctx->certs = sk_X509_dup(certs))) { 228 if (!(ctx->certs = sk_X509_dup(certs))) {
230 TSerr(TS_F_TS_RESP_CTX_SET_CERTS, ERR_R_MALLOC_FAILURE); 229 TSerror(ERR_R_MALLOC_FAILURE);
231 return 0; 230 return 0;
232 } 231 }
233 for (i = 0; i < sk_X509_num(ctx->certs); ++i) { 232 for (i = 0; i < sk_X509_num(ctx->certs); ++i) {
@@ -254,7 +253,7 @@ TS_RESP_CTX_add_policy(TS_RESP_CTX *ctx, ASN1_OBJECT *policy)
254 return 1; 253 return 1;
255 254
256err: 255err:
257 TSerr(TS_F_TS_RESP_CTX_ADD_POLICY, ERR_R_MALLOC_FAILURE); 256 TSerror(ERR_R_MALLOC_FAILURE);
258 ASN1_OBJECT_free(copy); 257 ASN1_OBJECT_free(copy);
259 return 0; 258 return 0;
260} 259}
@@ -272,7 +271,7 @@ TS_RESP_CTX_add_md(TS_RESP_CTX *ctx, const EVP_MD *md)
272 return 1; 271 return 1;
273 272
274err: 273err:
275 TSerr(TS_F_TS_RESP_CTX_ADD_MD, ERR_R_MALLOC_FAILURE); 274 TSerror(ERR_R_MALLOC_FAILURE);
276 return 0; 275 return 0;
277} 276}
278 277
@@ -302,7 +301,7 @@ TS_RESP_CTX_set_accuracy(TS_RESP_CTX *ctx, int secs, int millis, int micros)
302 301
303err: 302err:
304 TS_RESP_CTX_accuracy_free(ctx); 303 TS_RESP_CTX_accuracy_free(ctx);
305 TSerr(TS_F_TS_RESP_CTX_SET_ACCURACY, ERR_R_MALLOC_FAILURE); 304 TSerror(ERR_R_MALLOC_FAILURE);
306 return 0; 305 return 0;
307} 306}
308 307
@@ -353,7 +352,7 @@ TS_RESP_CTX_set_status_info(TS_RESP_CTX *ctx, int status, const char *text)
353 352
354err: 353err:
355 if (!ret) 354 if (!ret)
356 TSerr(TS_F_TS_RESP_CTX_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE); 355 TSerror(ERR_R_MALLOC_FAILURE);
357 TS_STATUS_INFO_free(si); 356 TS_STATUS_INFO_free(si);
358 ASN1_UTF8STRING_free(utf8_text); 357 ASN1_UTF8STRING_free(utf8_text);
359 return ret; 358 return ret;
@@ -384,7 +383,7 @@ TS_RESP_CTX_add_failure_info(TS_RESP_CTX *ctx, int failure)
384 return 1; 383 return 1;
385 384
386err: 385err:
387 TSerr(TS_F_TS_RESP_CTX_ADD_FAILURE_INFO, ERR_R_MALLOC_FAILURE); 386 TSerror(ERR_R_MALLOC_FAILURE);
388 return 0; 387 return 0;
389} 388}
390 389
@@ -421,7 +420,7 @@ TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio)
421 420
422 /* Creating the response object. */ 421 /* Creating the response object. */
423 if (!(ctx->response = TS_RESP_new())) { 422 if (!(ctx->response = TS_RESP_new())) {
424 TSerr(TS_F_TS_RESP_CREATE_RESPONSE, ERR_R_MALLOC_FAILURE); 423 TSerror(ERR_R_MALLOC_FAILURE);
425 goto end; 424 goto end;
426 } 425 }
427 426
@@ -463,7 +462,7 @@ TS_RESP_create_response(TS_RESP_CTX *ctx, BIO *req_bio)
463 462
464end: 463end:
465 if (!result) { 464 if (!result) {
466 TSerr(TS_F_TS_RESP_CREATE_RESPONSE, TS_R_RESPONSE_SETUP_ERROR); 465 TSerror(TS_R_RESPONSE_SETUP_ERROR);
467 if (ctx->response != NULL) { 466 if (ctx->response != NULL) {
468 if (TS_RESP_CTX_set_status_info_cond(ctx, 467 if (TS_RESP_CTX_set_status_info_cond(ctx,
469 TS_STATUS_REJECTION, "Error during response " 468 TS_STATUS_REJECTION, "Error during response "
@@ -567,7 +566,7 @@ TS_RESP_get_policy(TS_RESP_CTX *ctx)
567 int i; 566 int i;
568 567
569 if (ctx->default_policy == NULL) { 568 if (ctx->default_policy == NULL) {
570 TSerr(TS_F_TS_RESP_GET_POLICY, TS_R_INVALID_NULL_POINTER); 569 TSerror(TS_R_INVALID_NULL_POINTER);
571 return NULL; 570 return NULL;
572 } 571 }
573 /* Return the default policy if none is requested or the default is 572 /* Return the default policy if none is requested or the default is
@@ -582,7 +581,7 @@ TS_RESP_get_policy(TS_RESP_CTX *ctx)
582 policy = current; 581 policy = current;
583 } 582 }
584 if (!policy) { 583 if (!policy) {
585 TSerr(TS_F_TS_RESP_GET_POLICY, TS_R_UNACCEPTABLE_POLICY); 584 TSerror(TS_R_UNACCEPTABLE_POLICY);
586 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION, 585 TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
587 "Requested policy is not " 586 "Requested policy is not "
588 "supported."); 587 "supported.");
@@ -665,7 +664,7 @@ end:
665 if (!result) { 664 if (!result) {
666 TS_TST_INFO_free(tst_info); 665 TS_TST_INFO_free(tst_info);
667 tst_info = NULL; 666 tst_info = NULL;
668 TSerr(TS_F_TS_RESP_CREATE_TST_INFO, TS_R_TST_INFO_SETUP_ERROR); 667 TSerror(TS_R_TST_INFO_SETUP_ERROR);
669 TS_RESP_CTX_set_status_info_cond(ctx, TS_STATUS_REJECTION, 668 TS_RESP_CTX_set_status_info_cond(ctx, TS_STATUS_REJECTION,
670 "Error during TSTInfo " 669 "Error during TSTInfo "
671 "generation."); 670 "generation.");
@@ -716,14 +715,13 @@ TS_RESP_sign(TS_RESP_CTX *ctx)
716 715
717 /* Check if signcert and pkey match. */ 716 /* Check if signcert and pkey match. */
718 if (!X509_check_private_key(ctx->signer_cert, ctx->signer_key)) { 717 if (!X509_check_private_key(ctx->signer_cert, ctx->signer_key)) {
719 TSerr(TS_F_TS_RESP_SIGN, 718 TSerror(TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
720 TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
721 goto err; 719 goto err;
722 } 720 }
723 721
724 /* Create a new PKCS7 signed object. */ 722 /* Create a new PKCS7 signed object. */
725 if (!(p7 = PKCS7_new())) { 723 if (!(p7 = PKCS7_new())) {
726 TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE); 724 TSerror(ERR_R_MALLOC_FAILURE);
727 goto err; 725 goto err;
728 } 726 }
729 if (!PKCS7_set_type(p7, NID_pkcs7_signed)) 727 if (!PKCS7_set_type(p7, NID_pkcs7_signed))
@@ -747,7 +745,7 @@ TS_RESP_sign(TS_RESP_CTX *ctx)
747 /* Add a new signer info. */ 745 /* Add a new signer info. */
748 if (!(si = PKCS7_add_signature(p7, ctx->signer_cert, 746 if (!(si = PKCS7_add_signature(p7, ctx->signer_cert,
749 ctx->signer_key, EVP_sha1()))) { 747 ctx->signer_key, EVP_sha1()))) {
750 TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNATURE_ERROR); 748 TSerror(TS_R_PKCS7_ADD_SIGNATURE_ERROR);
751 goto err; 749 goto err;
752 } 750 }
753 751
@@ -755,7 +753,7 @@ TS_RESP_sign(TS_RESP_CTX *ctx)
755 oid = OBJ_nid2obj(NID_id_smime_ct_TSTInfo); 753 oid = OBJ_nid2obj(NID_id_smime_ct_TSTInfo);
756 if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, 754 if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
757 V_ASN1_OBJECT, oid)) { 755 V_ASN1_OBJECT, oid)) {
758 TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR); 756 TSerror(TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR);
759 goto err; 757 goto err;
760 } 758 }
761 759
@@ -767,7 +765,7 @@ TS_RESP_sign(TS_RESP_CTX *ctx)
767 765
768 /* Add SigningCertificate signed attribute to the signer info. */ 766 /* Add SigningCertificate signed attribute to the signer info. */
769 if (!ESS_add_signing_cert(si, sc)) { 767 if (!ESS_add_signing_cert(si, sc)) {
770 TSerr(TS_F_TS_RESP_SIGN, TS_R_ESS_ADD_SIGNING_CERT_ERROR); 768 TSerror(TS_R_ESS_ADD_SIGNING_CERT_ERROR);
771 goto err; 769 goto err;
772 } 770 }
773 771
@@ -777,19 +775,19 @@ TS_RESP_sign(TS_RESP_CTX *ctx)
777 775
778 /* Add the DER encoded tst_info to the PKCS7 structure. */ 776 /* Add the DER encoded tst_info to the PKCS7 structure. */
779 if (!(p7bio = PKCS7_dataInit(p7, NULL))) { 777 if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
780 TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE); 778 TSerror(ERR_R_MALLOC_FAILURE);
781 goto err; 779 goto err;
782 } 780 }
783 781
784 /* Convert tst_info to DER. */ 782 /* Convert tst_info to DER. */
785 if (!i2d_TS_TST_INFO_bio(p7bio, ctx->tst_info)) { 783 if (!i2d_TS_TST_INFO_bio(p7bio, ctx->tst_info)) {
786 TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN); 784 TSerror(TS_R_TS_DATASIGN);
787 goto err; 785 goto err;
788 } 786 }
789 787
790 /* Create the signature and add it to the signer info. */ 788 /* Create the signature and add it to the signer info. */
791 if (!PKCS7_dataFinal(p7, p7bio)) { 789 if (!PKCS7_dataFinal(p7, p7bio)) {
792 TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN); 790 TSerror(TS_R_TS_DATASIGN);
793 goto err; 791 goto err;
794 } 792 }
795 793
@@ -840,7 +838,7 @@ ESS_SIGNING_CERT_new_init(X509 *signcert, STACK_OF(X509) *certs)
840 838
841err: 839err:
842 ESS_SIGNING_CERT_free(sc); 840 ESS_SIGNING_CERT_free(sc);
843 TSerr(TS_F_ESS_SIGNING_CERT_NEW_INIT, ERR_R_MALLOC_FAILURE); 841 TSerror(ERR_R_MALLOC_FAILURE);
844 return NULL; 842 return NULL;
845} 843}
846 844
@@ -886,7 +884,7 @@ ESS_CERT_ID_new_init(X509 *cert, int issuer_needed)
886err: 884err:
887 GENERAL_NAME_free(name); 885 GENERAL_NAME_free(name);
888 ESS_CERT_ID_free(cid); 886 ESS_CERT_ID_free(cid);
889 TSerr(TS_F_ESS_CERT_ID_NEW_INIT, ERR_R_MALLOC_FAILURE); 887 TSerror(ERR_R_MALLOC_FAILURE);
890 return NULL; 888 return NULL;
891} 889}
892 890
@@ -928,13 +926,13 @@ ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)
928 926
929 len = i2d_ESS_SIGNING_CERT(sc, NULL); 927 len = i2d_ESS_SIGNING_CERT(sc, NULL);
930 if (!(pp = malloc(len))) { 928 if (!(pp = malloc(len))) {
931 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); 929 TSerror(ERR_R_MALLOC_FAILURE);
932 goto err; 930 goto err;
933 } 931 }
934 p = pp; 932 p = pp;
935 i2d_ESS_SIGNING_CERT(sc, &p); 933 i2d_ESS_SIGNING_CERT(sc, &p);
936 if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) { 934 if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) {
937 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); 935 TSerror(ERR_R_MALLOC_FAILURE);
938 goto err; 936 goto err;
939 } 937 }
940 free(pp); 938 free(pp);
@@ -1017,6 +1015,6 @@ TS_RESP_set_genTime_with_precision(ASN1_GENERALIZEDTIME *asn1_time,
1017 return asn1_time; 1015 return asn1_time;
1018 1016
1019err: 1017err:
1020 TSerr(TS_F_TS_RESP_SET_GENTIME_WITH_PRECISION, TS_R_COULD_NOT_SET_TIME); 1018 TSerror(TS_R_COULD_NOT_SET_TIME);
1021 return NULL; 1019 return NULL;
1022} 1020}
diff --git a/src/lib/libcrypto/ts/ts_rsp_utils.c b/src/lib/libcrypto/ts/ts_rsp_utils.c
index 39eb2a2963..5638331d17 100644
--- a/src/lib/libcrypto/ts/ts_rsp_utils.c
+++ b/src/lib/libcrypto/ts/ts_rsp_utils.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_rsp_utils.c,v 1.5 2015/07/29 14:58:34 jsing Exp $ */ 1/* $OpenBSD: ts_rsp_utils.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -74,7 +74,7 @@ TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
74 return 1; 74 return 1;
75 new_status_info = TS_STATUS_INFO_dup(status_info); 75 new_status_info = TS_STATUS_INFO_dup(status_info);
76 if (new_status_info == NULL) { 76 if (new_status_info == NULL) {
77 TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE); 77 TSerror(ERR_R_MALLOC_FAILURE);
78 return 0; 78 return 0;
79 } 79 }
80 TS_STATUS_INFO_free(a->status_info); 80 TS_STATUS_INFO_free(a->status_info);
@@ -133,7 +133,7 @@ TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
133 return 1; 133 return 1;
134 new_policy = OBJ_dup(policy); 134 new_policy = OBJ_dup(policy);
135 if (new_policy == NULL) { 135 if (new_policy == NULL) {
136 TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE); 136 TSerror(ERR_R_MALLOC_FAILURE);
137 return 0; 137 return 0;
138 } 138 }
139 ASN1_OBJECT_free(a->policy_id); 139 ASN1_OBJECT_free(a->policy_id);
@@ -156,7 +156,7 @@ TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
156 return 1; 156 return 1;
157 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint); 157 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
158 if (new_msg_imprint == NULL) { 158 if (new_msg_imprint == NULL) {
159 TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE); 159 TSerror(ERR_R_MALLOC_FAILURE);
160 return 0; 160 return 0;
161 } 161 }
162 TS_MSG_IMPRINT_free(a->msg_imprint); 162 TS_MSG_IMPRINT_free(a->msg_imprint);
@@ -179,7 +179,7 @@ TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
179 return 1; 179 return 1;
180 new_serial = ASN1_INTEGER_dup(serial); 180 new_serial = ASN1_INTEGER_dup(serial);
181 if (new_serial == NULL) { 181 if (new_serial == NULL) {
182 TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE); 182 TSerror(ERR_R_MALLOC_FAILURE);
183 return 0; 183 return 0;
184 } 184 }
185 ASN1_INTEGER_free(a->serial); 185 ASN1_INTEGER_free(a->serial);
@@ -202,7 +202,7 @@ TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
202 return 1; 202 return 1;
203 new_time = ASN1_STRING_dup(gtime); 203 new_time = ASN1_STRING_dup(gtime);
204 if (new_time == NULL) { 204 if (new_time == NULL) {
205 TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE); 205 TSerror(ERR_R_MALLOC_FAILURE);
206 return 0; 206 return 0;
207 } 207 }
208 ASN1_GENERALIZEDTIME_free(a->time); 208 ASN1_GENERALIZEDTIME_free(a->time);
@@ -225,7 +225,7 @@ TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
225 return 1; 225 return 1;
226 new_accuracy = TS_ACCURACY_dup(accuracy); 226 new_accuracy = TS_ACCURACY_dup(accuracy);
227 if (new_accuracy == NULL) { 227 if (new_accuracy == NULL) {
228 TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE); 228 TSerror(ERR_R_MALLOC_FAILURE);
229 return 0; 229 return 0;
230 } 230 }
231 TS_ACCURACY_free(a->accuracy); 231 TS_ACCURACY_free(a->accuracy);
@@ -248,7 +248,7 @@ TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
248 return 1; 248 return 1;
249 new_seconds = ASN1_INTEGER_dup(seconds); 249 new_seconds = ASN1_INTEGER_dup(seconds);
250 if (new_seconds == NULL) { 250 if (new_seconds == NULL) {
251 TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE); 251 TSerror(ERR_R_MALLOC_FAILURE);
252 return 0; 252 return 0;
253 } 253 }
254 ASN1_INTEGER_free(a->seconds); 254 ASN1_INTEGER_free(a->seconds);
@@ -272,8 +272,7 @@ TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
272 if (millis != NULL) { 272 if (millis != NULL) {
273 new_millis = ASN1_INTEGER_dup(millis); 273 new_millis = ASN1_INTEGER_dup(millis);
274 if (new_millis == NULL) { 274 if (new_millis == NULL) {
275 TSerr(TS_F_TS_ACCURACY_SET_MILLIS, 275 TSerror(ERR_R_MALLOC_FAILURE);
276 ERR_R_MALLOC_FAILURE);
277 return 0; 276 return 0;
278 } 277 }
279 } 278 }
@@ -298,8 +297,7 @@ TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
298 if (micros != NULL) { 297 if (micros != NULL) {
299 new_micros = ASN1_INTEGER_dup(micros); 298 new_micros = ASN1_INTEGER_dup(micros);
300 if (new_micros == NULL) { 299 if (new_micros == NULL) {
301 TSerr(TS_F_TS_ACCURACY_SET_MICROS, 300 TSerror(ERR_R_MALLOC_FAILURE);
302 ERR_R_MALLOC_FAILURE);
303 return 0; 301 return 0;
304 } 302 }
305 } 303 }
@@ -336,7 +334,7 @@ TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
336 return 1; 334 return 1;
337 new_nonce = ASN1_INTEGER_dup(nonce); 335 new_nonce = ASN1_INTEGER_dup(nonce);
338 if (new_nonce == NULL) { 336 if (new_nonce == NULL) {
339 TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE); 337 TSerror(ERR_R_MALLOC_FAILURE);
340 return 0; 338 return 0;
341 } 339 }
342 ASN1_INTEGER_free(a->nonce); 340 ASN1_INTEGER_free(a->nonce);
@@ -359,7 +357,7 @@ TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
359 return 1; 357 return 1;
360 new_tsa = GENERAL_NAME_dup(tsa); 358 new_tsa = GENERAL_NAME_dup(tsa);
361 if (new_tsa == NULL) { 359 if (new_tsa == NULL) {
362 TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE); 360 TSerror(ERR_R_MALLOC_FAILURE);
363 return 0; 361 return 0;
364 } 362 }
365 GENERAL_NAME_free(a->tsa); 363 GENERAL_NAME_free(a->tsa);
diff --git a/src/lib/libcrypto/ts/ts_rsp_verify.c b/src/lib/libcrypto/ts/ts_rsp_verify.c
index 020658bb02..36ead0671a 100644
--- a/src/lib/libcrypto/ts/ts_rsp_verify.c
+++ b/src/lib/libcrypto/ts/ts_rsp_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_rsp_verify.c,v 1.17 2016/11/05 15:19:07 miod Exp $ */ 1/* $OpenBSD: ts_rsp_verify.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -155,28 +155,27 @@ TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs,
155 155
156 /* Some sanity checks first. */ 156 /* Some sanity checks first. */
157 if (!token) { 157 if (!token) {
158 TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_INVALID_NULL_POINTER); 158 TSerror(TS_R_INVALID_NULL_POINTER);
159 goto err; 159 goto err;
160 } 160 }
161 161
162 /* Check for the correct content type */ 162 /* Check for the correct content type */
163 if (!PKCS7_type_is_signed(token)) { 163 if (!PKCS7_type_is_signed(token)) {
164 TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_WRONG_CONTENT_TYPE); 164 TSerror(TS_R_WRONG_CONTENT_TYPE);
165 goto err; 165 goto err;
166 } 166 }
167 167
168 /* Check if there is one and only one signer. */ 168 /* Check if there is one and only one signer. */
169 sinfos = PKCS7_get_signer_info(token); 169 sinfos = PKCS7_get_signer_info(token);
170 if (!sinfos || sk_PKCS7_SIGNER_INFO_num(sinfos) != 1) { 170 if (!sinfos || sk_PKCS7_SIGNER_INFO_num(sinfos) != 1) {
171 TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, 171 TSerror(TS_R_THERE_MUST_BE_ONE_SIGNER);
172 TS_R_THERE_MUST_BE_ONE_SIGNER);
173 goto err; 172 goto err;
174 } 173 }
175 si = sk_PKCS7_SIGNER_INFO_value(sinfos, 0); 174 si = sk_PKCS7_SIGNER_INFO_value(sinfos, 0);
176 175
177 /* Check for no content: no data to verify signature. */ 176 /* Check for no content: no data to verify signature. */
178 if (PKCS7_get_detached(token)) { 177 if (PKCS7_get_detached(token)) {
179 TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_NO_CONTENT); 178 TSerror(TS_R_NO_CONTENT);
180 goto err; 179 goto err;
181 } 180 }
182 181
@@ -206,7 +205,7 @@ TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs,
206 /* Verifying the signature. */ 205 /* Verifying the signature. */
207 j = PKCS7_signatureVerify(p7bio, token, si, signer); 206 j = PKCS7_signatureVerify(p7bio, token, si, signer);
208 if (j <= 0) { 207 if (j <= 0) {
209 TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_SIGNATURE_FAILURE); 208 TSerror(TS_R_SIGNATURE_FAILURE);
210 goto err; 209 goto err;
211 } 210 }
212 211
@@ -241,7 +240,7 @@ TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer,
241 /* chain is an out argument. */ 240 /* chain is an out argument. */
242 *chain = NULL; 241 *chain = NULL;
243 if (X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted) == 0) { 242 if (X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted) == 0) {
244 TSerr(TS_F_TS_VERIFY_CERT, ERR_R_X509_LIB); 243 TSerror(ERR_R_X509_LIB);
245 goto err; 244 goto err;
246 } 245 }
247 if (X509_STORE_CTX_set_purpose(&cert_ctx, 246 if (X509_STORE_CTX_set_purpose(&cert_ctx,
@@ -251,7 +250,7 @@ TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer,
251 if (i <= 0) { 250 if (i <= 0) {
252 int j = X509_STORE_CTX_get_error(&cert_ctx); 251 int j = X509_STORE_CTX_get_error(&cert_ctx);
253 252
254 TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); 253 TSerror(TS_R_CERTIFICATE_VERIFY_ERROR);
255 ERR_asprintf_error_data("Verify error:%s", 254 ERR_asprintf_error_data("Verify error:%s",
256 X509_verify_cert_error_string(j)); 255 X509_verify_cert_error_string(j));
257 goto err; 256 goto err;
@@ -298,8 +297,7 @@ TS_check_signing_certs(PKCS7_SIGNER_INFO *si, STACK_OF(X509) *chain)
298 297
299err: 298err:
300 if (!ret) 299 if (!ret)
301 TSerr(TS_F_TS_CHECK_SIGNING_CERTS, 300 TSerror(TS_R_ESS_SIGNING_CERTIFICATE_ERROR);
302 TS_R_ESS_SIGNING_CERTIFICATE_ERROR);
303 ESS_SIGNING_CERT_free(ss); 301 ESS_SIGNING_CERT_free(ss);
304 return ret; 302 return ret;
305} 303}
@@ -446,7 +444,7 @@ int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token,
446 /* Check version number of response. */ 444 /* Check version number of response. */
447 if ((ctx->flags & TS_VFY_VERSION) && 445 if ((ctx->flags & TS_VFY_VERSION) &&
448 TS_TST_INFO_get_version(tst_info) != 1) { 446 TS_TST_INFO_get_version(tst_info) != 1) {
449 TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_UNSUPPORTED_VERSION); 447 TSerror(TS_R_UNSUPPORTED_VERSION);
450 goto err; 448 goto err;
451 } 449 }
452 450
@@ -476,14 +474,14 @@ int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token,
476 /* Check whether TSA name and signer certificate match. */ 474 /* Check whether TSA name and signer certificate match. */
477 if ((ctx->flags & TS_VFY_SIGNER) && 475 if ((ctx->flags & TS_VFY_SIGNER) &&
478 tsa_name && !TS_check_signer_name(tsa_name, signer)) { 476 tsa_name && !TS_check_signer_name(tsa_name, signer)) {
479 TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_NAME_MISMATCH); 477 TSerror(TS_R_TSA_NAME_MISMATCH);
480 goto err; 478 goto err;
481 } 479 }
482 480
483 /* Check whether the TSA is the expected one. */ 481 /* Check whether the TSA is the expected one. */
484 if ((ctx->flags & TS_VFY_TSA_NAME) && 482 if ((ctx->flags & TS_VFY_TSA_NAME) &&
485 !TS_check_signer_name(ctx->tsa_name, signer)) { 483 !TS_check_signer_name(ctx->tsa_name, signer)) {
486 TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_UNTRUSTED); 484 TSerror(TS_R_TSA_UNTRUSTED);
487 goto err; 485 goto err;
488 } 486 }
489 487
@@ -541,7 +539,7 @@ TS_check_status_info(TS_RESP *response)
541 strlcpy(failure_text, "unspecified", TS_STATUS_BUF_SIZE); 539 strlcpy(failure_text, "unspecified", TS_STATUS_BUF_SIZE);
542 540
543 /* Making up the error string. */ 541 /* Making up the error string. */
544 TSerr(TS_F_TS_CHECK_STATUS_INFO, TS_R_NO_TIME_STAMP_TOKEN); 542 TSerror(TS_R_NO_TIME_STAMP_TOKEN);
545 ERR_asprintf_error_data 543 ERR_asprintf_error_data
546 ("status code: %s, status text: %s, failure codes: %s", 544 ("status code: %s, status text: %s, failure codes: %s",
547 status_text, 545 status_text,
@@ -567,7 +565,7 @@ TS_get_status_text(STACK_OF(ASN1_UTF8STRING) *text)
567 } 565 }
568 /* Allocate memory (closing '\0' included). */ 566 /* Allocate memory (closing '\0' included). */
569 if (!(result = malloc(length))) { 567 if (!(result = malloc(length))) {
570 TSerr(TS_F_TS_GET_STATUS_TEXT, ERR_R_MALLOC_FAILURE); 568 TSerror(ERR_R_MALLOC_FAILURE);
571 return NULL; 569 return NULL;
572 } 570 }
573 /* Concatenate the descriptions. */ 571 /* Concatenate the descriptions. */
@@ -587,7 +585,7 @@ TS_check_policy(ASN1_OBJECT *req_oid, TS_TST_INFO *tst_info)
587 ASN1_OBJECT *resp_oid = TS_TST_INFO_get_policy_id(tst_info); 585 ASN1_OBJECT *resp_oid = TS_TST_INFO_get_policy_id(tst_info);
588 586
589 if (OBJ_cmp(req_oid, resp_oid) != 0) { 587 if (OBJ_cmp(req_oid, resp_oid) != 0) {
590 TSerr(TS_F_TS_CHECK_POLICY, TS_R_POLICY_MISMATCH); 588 TSerror(TS_R_POLICY_MISMATCH);
591 return 0; 589 return 0;
592 } 590 }
593 591
@@ -614,7 +612,7 @@ TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, X509_ALGOR **md_alg,
614 612
615 /* Getting the MD object. */ 613 /* Getting the MD object. */
616 if (!(md = EVP_get_digestbyobj((*md_alg)->algorithm))) { 614 if (!(md = EVP_get_digestbyobj((*md_alg)->algorithm))) {
617 TSerr(TS_F_TS_COMPUTE_IMPRINT, TS_R_UNSUPPORTED_MD_ALGORITHM); 615 TSerror(TS_R_UNSUPPORTED_MD_ALGORITHM);
618 goto err; 616 goto err;
619 } 617 }
620 618
@@ -624,7 +622,7 @@ TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, X509_ALGOR **md_alg,
624 goto err; 622 goto err;
625 *imprint_len = length; 623 *imprint_len = length;
626 if (!(*imprint = malloc(*imprint_len))) { 624 if (!(*imprint = malloc(*imprint_len))) {
627 TSerr(TS_F_TS_COMPUTE_IMPRINT, ERR_R_MALLOC_FAILURE); 625 TSerror(ERR_R_MALLOC_FAILURE);
628 goto err; 626 goto err;
629 } 627 }
630 628
@@ -675,7 +673,7 @@ TS_check_imprints(X509_ALGOR *algor_a, unsigned char *imprint_a, unsigned len_a,
675 673
676err: 674err:
677 if (!ret) 675 if (!ret)
678 TSerr(TS_F_TS_CHECK_IMPRINTS, TS_R_MESSAGE_IMPRINT_MISMATCH); 676 TSerror(TS_R_MESSAGE_IMPRINT_MISMATCH);
679 return ret; 677 return ret;
680} 678}
681 679
@@ -686,13 +684,13 @@ TS_check_nonces(const ASN1_INTEGER *a, TS_TST_INFO *tst_info)
686 684
687 /* Error if nonce is missing. */ 685 /* Error if nonce is missing. */
688 if (!b) { 686 if (!b) {
689 TSerr(TS_F_TS_CHECK_NONCES, TS_R_NONCE_NOT_RETURNED); 687 TSerror(TS_R_NONCE_NOT_RETURNED);
690 return 0; 688 return 0;
691 } 689 }
692 690
693 /* No error if a nonce is returned without being requested. */ 691 /* No error if a nonce is returned without being requested. */
694 if (ASN1_INTEGER_cmp(a, b) != 0) { 692 if (ASN1_INTEGER_cmp(a, b) != 0) {
695 TSerr(TS_F_TS_CHECK_NONCES, TS_R_NONCE_MISMATCH); 693 TSerror(TS_R_NONCE_MISMATCH);
696 return 0; 694 return 0;
697 } 695 }
698 696
diff --git a/src/lib/libcrypto/ts/ts_verify_ctx.c b/src/lib/libcrypto/ts/ts_verify_ctx.c
index 7dda76e7d9..7608a7d109 100644
--- a/src/lib/libcrypto/ts/ts_verify_ctx.c
+++ b/src/lib/libcrypto/ts/ts_verify_ctx.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_verify_ctx.c,v 1.8 2015/02/10 09:46:30 miod Exp $ */ 1/* $OpenBSD: ts_verify_ctx.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2003. 3 * project 2003.
4 */ 4 */
@@ -68,7 +68,7 @@ TS_VERIFY_CTX_new(void)
68 TS_VERIFY_CTX *ctx = calloc(1, sizeof(TS_VERIFY_CTX)); 68 TS_VERIFY_CTX *ctx = calloc(1, sizeof(TS_VERIFY_CTX));
69 69
70 if (!ctx) 70 if (!ctx)
71 TSerr(TS_F_TS_VERIFY_CTX_NEW, ERR_R_MALLOC_FAILURE); 71 TSerror(ERR_R_MALLOC_FAILURE);
72 72
73 return ctx; 73 return ctx;
74} 74}
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
index 576f334796..8451d63253 100644
--- a/src/lib/libcrypto/ui/ui_err.c
+++ b/src/lib/libcrypto/ui/ui_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_err.c,v 1.8 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: ui_err.c,v 1.9 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,18 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_UI,0,reason)
73 73
74static ERR_STRING_DATA UI_str_functs[] = { 74static ERR_STRING_DATA UI_str_functs[] = {
75 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_BOOLEAN), "GENERAL_ALLOCATE_BOOLEAN"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_PROMPT), "GENERAL_ALLOCATE_PROMPT"},
77 {ERR_FUNC(UI_F_GENERAL_ALLOCATE_STRING), "GENERAL_ALLOCATE_STRING"},
78 {ERR_FUNC(UI_F_UI_CTRL), "UI_ctrl"},
79 {ERR_FUNC(UI_F_UI_DUP_ERROR_STRING), "UI_dup_error_string"},
80 {ERR_FUNC(UI_F_UI_DUP_INFO_STRING), "UI_dup_info_string"},
81 {ERR_FUNC(UI_F_UI_DUP_INPUT_BOOLEAN), "UI_dup_input_boolean"},
82 {ERR_FUNC(UI_F_UI_DUP_INPUT_STRING), "UI_dup_input_string"},
83 {ERR_FUNC(UI_F_UI_DUP_VERIFY_STRING), "UI_dup_verify_string"},
84 {ERR_FUNC(UI_F_UI_GET0_RESULT), "UI_get0_result"},
85 {ERR_FUNC(UI_F_UI_NEW_METHOD), "UI_new_method"},
86 {ERR_FUNC(UI_F_UI_SET_RESULT), "UI_set_result"},
87 {0, NULL} 76 {0, NULL}
88}; 77};
89 78
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
index 80f0992ddd..e551030729 100644
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_lib.c,v 1.31 2016/04/28 16:42:28 tedu Exp $ */ 1/* $OpenBSD: ui_lib.c,v 1.32 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -81,7 +81,7 @@ UI_new_method(const UI_METHOD *method)
81 81
82 ret = malloc(sizeof(UI)); 82 ret = malloc(sizeof(UI));
83 if (ret == NULL) { 83 if (ret == NULL) {
84 UIerr(UI_F_UI_NEW_METHOD, ERR_R_MALLOC_FAILURE); 84 UIerror(ERR_R_MALLOC_FAILURE);
85 return NULL; 85 return NULL;
86 } 86 }
87 if (method == NULL) 87 if (method == NULL)
@@ -143,11 +143,10 @@ general_allocate_prompt(UI *ui, const char *prompt, int prompt_freeable,
143 UI_STRING *ret = NULL; 143 UI_STRING *ret = NULL;
144 144
145 if (prompt == NULL) { 145 if (prompt == NULL) {
146 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, 146 UIerror(ERR_R_PASSED_NULL_PARAMETER);
147 ERR_R_PASSED_NULL_PARAMETER);
148 } else if ((type == UIT_PROMPT || type == UIT_VERIFY || 147 } else if ((type == UIT_PROMPT || type == UIT_VERIFY ||
149 type == UIT_BOOLEAN) && result_buf == NULL) { 148 type == UIT_BOOLEAN) && result_buf == NULL) {
150 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT, UI_R_NO_RESULT_BUFFER); 149 UIerror(UI_R_NO_RESULT_BUFFER);
151 } else if ((ret = malloc(sizeof(UI_STRING)))) { 150 } else if ((ret = malloc(sizeof(UI_STRING)))) {
152 ret->out_string = prompt; 151 ret->out_string = prompt;
153 ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0; 152 ret->flags = prompt_freeable ? OUT_STRING_FREEABLE : 0;
@@ -192,16 +191,13 @@ general_allocate_boolean(UI *ui, const char *prompt, const char *action_desc,
192 const char *p; 191 const char *p;
193 192
194 if (ok_chars == NULL) { 193 if (ok_chars == NULL) {
195 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, 194 UIerror(ERR_R_PASSED_NULL_PARAMETER);
196 ERR_R_PASSED_NULL_PARAMETER);
197 } else if (cancel_chars == NULL) { 195 } else if (cancel_chars == NULL) {
198 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, 196 UIerror(ERR_R_PASSED_NULL_PARAMETER);
199 ERR_R_PASSED_NULL_PARAMETER);
200 } else { 197 } else {
201 for (p = ok_chars; *p; p++) { 198 for (p = ok_chars; *p; p++) {
202 if (strchr(cancel_chars, *p)) { 199 if (strchr(cancel_chars, *p)) {
203 UIerr(UI_F_GENERAL_ALLOCATE_BOOLEAN, 200 UIerror(UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
204 UI_R_COMMON_OK_AND_CANCEL_CHARACTERS);
205 } 201 }
206 } 202 }
207 203
@@ -247,7 +243,7 @@ UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf,
247 if (prompt) { 243 if (prompt) {
248 prompt_copy = strdup(prompt); 244 prompt_copy = strdup(prompt);
249 if (prompt_copy == NULL) { 245 if (prompt_copy == NULL) {
250 UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE); 246 UIerror(ERR_R_MALLOC_FAILURE);
251 return 0; 247 return 0;
252 } 248 }
253 } 249 }
@@ -272,7 +268,7 @@ UI_dup_verify_string(UI *ui, const char *prompt, int flags,
272 if (prompt) { 268 if (prompt) {
273 prompt_copy = strdup(prompt); 269 prompt_copy = strdup(prompt);
274 if (prompt_copy == NULL) { 270 if (prompt_copy == NULL) {
275 UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE); 271 UIerror(ERR_R_MALLOC_FAILURE);
276 return -1; 272 return -1;
277 } 273 }
278 } 274 }
@@ -300,28 +296,28 @@ UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
300 if (prompt) { 296 if (prompt) {
301 prompt_copy = strdup(prompt); 297 prompt_copy = strdup(prompt);
302 if (prompt_copy == NULL) { 298 if (prompt_copy == NULL) {
303 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); 299 UIerror(ERR_R_MALLOC_FAILURE);
304 goto err; 300 goto err;
305 } 301 }
306 } 302 }
307 if (action_desc) { 303 if (action_desc) {
308 action_desc_copy = strdup(action_desc); 304 action_desc_copy = strdup(action_desc);
309 if (action_desc_copy == NULL) { 305 if (action_desc_copy == NULL) {
310 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); 306 UIerror(ERR_R_MALLOC_FAILURE);
311 goto err; 307 goto err;
312 } 308 }
313 } 309 }
314 if (ok_chars) { 310 if (ok_chars) {
315 ok_chars_copy = strdup(ok_chars); 311 ok_chars_copy = strdup(ok_chars);
316 if (ok_chars_copy == NULL) { 312 if (ok_chars_copy == NULL) {
317 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); 313 UIerror(ERR_R_MALLOC_FAILURE);
318 goto err; 314 goto err;
319 } 315 }
320 } 316 }
321 if (cancel_chars) { 317 if (cancel_chars) {
322 cancel_chars_copy = strdup(cancel_chars); 318 cancel_chars_copy = strdup(cancel_chars);
323 if (cancel_chars_copy == NULL) { 319 if (cancel_chars_copy == NULL) {
324 UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); 320 UIerror(ERR_R_MALLOC_FAILURE);
325 goto err; 321 goto err;
326 } 322 }
327 } 323 }
@@ -352,7 +348,7 @@ UI_dup_info_string(UI *ui, const char *text)
352 if (text) { 348 if (text) {
353 text_copy = strdup(text); 349 text_copy = strdup(text);
354 if (text_copy == NULL) { 350 if (text_copy == NULL) {
355 UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE); 351 UIerror(ERR_R_MALLOC_FAILURE);
356 return -1; 352 return -1;
357 } 353 }
358 } 354 }
@@ -375,7 +371,7 @@ UI_dup_error_string(UI *ui, const char *text)
375 if (text) { 371 if (text) {
376 text_copy = strdup(text); 372 text_copy = strdup(text);
377 if (text_copy == NULL) { 373 if (text_copy == NULL) {
378 UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE); 374 UIerror(ERR_R_MALLOC_FAILURE);
379 return -1; 375 return -1;
380 } 376 }
381 } 377 }
@@ -426,11 +422,11 @@ const char *
426UI_get0_result(UI *ui, int i) 422UI_get0_result(UI *ui, int i)
427{ 423{
428 if (i < 0) { 424 if (i < 0) {
429 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_SMALL); 425 UIerror(UI_R_INDEX_TOO_SMALL);
430 return NULL; 426 return NULL;
431 } 427 }
432 if (i >= sk_UI_STRING_num(ui->strings)) { 428 if (i >= sk_UI_STRING_num(ui->strings)) {
433 UIerr(UI_F_UI_GET0_RESULT, UI_R_INDEX_TOO_LARGE); 429 UIerror(UI_R_INDEX_TOO_LARGE);
434 return NULL; 430 return NULL;
435 } 431 }
436 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i)); 432 return UI_get0_result_string(sk_UI_STRING_value(ui->strings, i));
@@ -514,7 +510,7 @@ int
514UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void)) 510UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void))
515{ 511{
516 if (ui == NULL) { 512 if (ui == NULL) {
517 UIerr(UI_F_UI_CTRL, ERR_R_PASSED_NULL_PARAMETER); 513 UIerror(ERR_R_PASSED_NULL_PARAMETER);
518 return -1; 514 return -1;
519 } 515 }
520 switch (cmd) { 516 switch (cmd) {
@@ -532,7 +528,7 @@ UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f) (void))
532 default: 528 default:
533 break; 529 break;
534 } 530 }
535 UIerr(UI_F_UI_CTRL, UI_R_UNKNOWN_CONTROL_COMMAND); 531 UIerror(UI_R_UNKNOWN_CONTROL_COMMAND);
536 return -1; 532 return -1;
537} 533}
538 534
@@ -831,8 +827,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result)
831 case UIT_VERIFY: 827 case UIT_VERIFY:
832 if (l < uis->_.string_data.result_minsize) { 828 if (l < uis->_.string_data.result_minsize) {
833 ui->flags |= UI_FLAG_REDOABLE; 829 ui->flags |= UI_FLAG_REDOABLE;
834 UIerr(UI_F_UI_SET_RESULT, 830 UIerror(UI_R_RESULT_TOO_SMALL);
835 UI_R_RESULT_TOO_SMALL);
836 ERR_asprintf_error_data 831 ERR_asprintf_error_data
837 ("You must type in %d to %d characters", 832 ("You must type in %d to %d characters",
838 uis->_.string_data.result_minsize, 833 uis->_.string_data.result_minsize,
@@ -841,8 +836,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result)
841 } 836 }
842 if (l > uis->_.string_data.result_maxsize) { 837 if (l > uis->_.string_data.result_maxsize) {
843 ui->flags |= UI_FLAG_REDOABLE; 838 ui->flags |= UI_FLAG_REDOABLE;
844 UIerr(UI_F_UI_SET_RESULT, 839 UIerror(UI_R_RESULT_TOO_LARGE);
845 UI_R_RESULT_TOO_LARGE);
846 ERR_asprintf_error_data 840 ERR_asprintf_error_data
847 ("You must type in %d to %d characters", 841 ("You must type in %d to %d characters",
848 uis->_.string_data.result_minsize, 842 uis->_.string_data.result_minsize,
@@ -850,7 +844,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result)
850 return -1; 844 return -1;
851 } 845 }
852 if (!uis->result_buf) { 846 if (!uis->result_buf) {
853 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER); 847 UIerror(UI_R_NO_RESULT_BUFFER);
854 return -1; 848 return -1;
855 } 849 }
856 strlcpy(uis->result_buf, result, 850 strlcpy(uis->result_buf, result,
@@ -861,7 +855,7 @@ UI_set_result(UI *ui, UI_STRING *uis, const char *result)
861 const char *p; 855 const char *p;
862 856
863 if (!uis->result_buf) { 857 if (!uis->result_buf) {
864 UIerr(UI_F_UI_SET_RESULT, UI_R_NO_RESULT_BUFFER); 858 UIerror(UI_R_NO_RESULT_BUFFER);
865 return -1; 859 return -1;
866 } 860 }
867 uis->result_buf[0] = '\0'; 861 uis->result_buf[0] = '\0';
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
index 7b7d14a950..01a302b538 100644
--- a/src/lib/libcrypto/x509/by_dir.c
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_dir.c,v 1.37 2015/04/11 16:03:21 deraadt Exp $ */ 1/* $OpenBSD: by_dir.c,v 1.38 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -133,7 +133,7 @@ dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
133 ret = add_cert_dir(ld, X509_get_default_cert_dir(), 133 ret = add_cert_dir(ld, X509_get_default_cert_dir(),
134 X509_FILETYPE_PEM); 134 X509_FILETYPE_PEM);
135 if (!ret) { 135 if (!ret) {
136 X509err(X509_F_DIR_CTRL, X509_R_LOADING_CERT_DIR); 136 X509error(X509_R_LOADING_CERT_DIR);
137 } 137 }
138 } else 138 } else
139 ret = add_cert_dir(ld, argp, (int)argl); 139 ret = add_cert_dir(ld, argp, (int)argl);
@@ -205,7 +205,7 @@ add_cert_dir(BY_DIR *ctx, const char *dir, int type)
205 ptrdiff_t len; 205 ptrdiff_t len;
206 206
207 if (dir == NULL || !*dir) { 207 if (dir == NULL || !*dir) {
208 X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY); 208 X509error(X509_R_INVALID_DIRECTORY);
209 return 0; 209 return 0;
210 } 210 }
211 211
@@ -230,25 +230,25 @@ add_cert_dir(BY_DIR *ctx, const char *dir, int type)
230 if (ctx->dirs == NULL) { 230 if (ctx->dirs == NULL) {
231 ctx->dirs = sk_BY_DIR_ENTRY_new_null(); 231 ctx->dirs = sk_BY_DIR_ENTRY_new_null();
232 if (!ctx->dirs) { 232 if (!ctx->dirs) {
233 X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); 233 X509error(ERR_R_MALLOC_FAILURE);
234 return 0; 234 return 0;
235 } 235 }
236 } 236 }
237 ent = malloc(sizeof(BY_DIR_ENTRY)); 237 ent = malloc(sizeof(BY_DIR_ENTRY));
238 if (!ent) { 238 if (!ent) {
239 X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); 239 X509error(ERR_R_MALLOC_FAILURE);
240 return 0; 240 return 0;
241 } 241 }
242 ent->dir_type = type; 242 ent->dir_type = type;
243 ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); 243 ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
244 ent->dir = strndup(ss, (size_t)len); 244 ent->dir = strndup(ss, (size_t)len);
245 if (!ent->dir || !ent->hashes) { 245 if (!ent->dir || !ent->hashes) {
246 X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); 246 X509error(ERR_R_MALLOC_FAILURE);
247 by_dir_entry_free(ent); 247 by_dir_entry_free(ent);
248 return 0; 248 return 0;
249 } 249 }
250 if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { 250 if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
251 X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); 251 X509error(ERR_R_MALLOC_FAILURE);
252 by_dir_entry_free(ent); 252 by_dir_entry_free(ent);
253 return 0; 253 return 0;
254 } 254 }
@@ -294,12 +294,12 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
294 stmp.data.crl = &data.crl.st_crl; 294 stmp.data.crl = &data.crl.st_crl;
295 postfix="r"; 295 postfix="r";
296 } else { 296 } else {
297 X509err(X509_F_GET_CERT_BY_SUBJECT, X509_R_WRONG_LOOKUP_TYPE); 297 X509error(X509_R_WRONG_LOOKUP_TYPE);
298 goto finish; 298 goto finish;
299 } 299 }
300 300
301 if ((b = BUF_MEM_new()) == NULL) { 301 if ((b = BUF_MEM_new()) == NULL) {
302 X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_BUF_LIB); 302 X509error(ERR_R_BUF_LIB);
303 goto finish; 303 goto finish;
304 } 304 }
305 305
@@ -313,7 +313,7 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
313 ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); 313 ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i);
314 j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1; 314 j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1;
315 if (!BUF_MEM_grow(b, j)) { 315 if (!BUF_MEM_grow(b, j)) {
316 X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); 316 X509error(ERR_R_MALLOC_FAILURE);
317 goto finish; 317 goto finish;
318 } 318 }
319 if (type == X509_LU_CRL && ent->hashes) { 319 if (type == X509_LU_CRL && ent->hashes) {
@@ -381,7 +381,7 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
381 if (!hent) { 381 if (!hent) {
382 hent = malloc(sizeof(BY_DIR_HASH)); 382 hent = malloc(sizeof(BY_DIR_HASH));
383 if (!hent) { 383 if (!hent) {
384 X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); 384 X509error(ERR_R_MALLOC_FAILURE);
385 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); 385 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
386 ok = 0; 386 ok = 0;
387 goto finish; 387 goto finish;
@@ -389,7 +389,7 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
389 hent->hash = h; 389 hent->hash = h;
390 hent->suffix = k; 390 hent->suffix = k;
391 if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { 391 if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) {
392 X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); 392 X509error(ERR_R_MALLOC_FAILURE);
393 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); 393 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
394 free(hent); 394 free(hent);
395 ok = 0; 395 ok = 0;
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c
index 377b3b0a8b..b2c8ef6cfa 100644
--- a/src/lib/libcrypto/x509/by_file.c
+++ b/src/lib/libcrypto/x509/by_file.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_file.c,v 1.20 2016/03/11 07:08:45 mmcc Exp $ */ 1/* $OpenBSD: by_file.c,v 1.21 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -102,8 +102,7 @@ by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
102 X509_get_default_cert_file(), 102 X509_get_default_cert_file(),
103 X509_FILETYPE_PEM) != 0); 103 X509_FILETYPE_PEM) != 0);
104 if (!ok) { 104 if (!ok) {
105 X509err(X509_F_BY_FILE_CTRL, 105 X509error(X509_R_LOADING_DEFAULTS);
106 X509_R_LOADING_DEFAULTS);
107 } 106 }
108 } else { 107 } else {
109 if (argl == X509_FILETYPE_PEM) 108 if (argl == X509_FILETYPE_PEM)
@@ -131,7 +130,7 @@ X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
131 in = BIO_new(BIO_s_file_internal()); 130 in = BIO_new(BIO_s_file_internal());
132 131
133 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { 132 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
134 X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_SYS_LIB); 133 X509error(ERR_R_SYS_LIB);
135 goto err; 134 goto err;
136 } 135 }
137 136
@@ -144,8 +143,7 @@ X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
144 ERR_clear_error(); 143 ERR_clear_error();
145 break; 144 break;
146 } else { 145 } else {
147 X509err(X509_F_X509_LOAD_CERT_FILE, 146 X509error(ERR_R_PEM_LIB);
148 ERR_R_PEM_LIB);
149 goto err; 147 goto err;
150 } 148 }
151 } 149 }
@@ -160,7 +158,7 @@ X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
160 } else if (type == X509_FILETYPE_ASN1) { 158 } else if (type == X509_FILETYPE_ASN1) {
161 x = d2i_X509_bio(in, NULL); 159 x = d2i_X509_bio(in, NULL);
162 if (x == NULL) { 160 if (x == NULL) {
163 X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_ASN1_LIB); 161 X509error(ERR_R_ASN1_LIB);
164 goto err; 162 goto err;
165 } 163 }
166 i = X509_STORE_add_cert(ctx->store_ctx, x); 164 i = X509_STORE_add_cert(ctx->store_ctx, x);
@@ -168,7 +166,7 @@ X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
168 goto err; 166 goto err;
169 ret = i; 167 ret = i;
170 } else { 168 } else {
171 X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_BAD_X509_FILETYPE); 169 X509error(X509_R_BAD_X509_FILETYPE);
172 goto err; 170 goto err;
173 } 171 }
174err: 172err:
@@ -190,7 +188,7 @@ X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
190 in = BIO_new(BIO_s_file_internal()); 188 in = BIO_new(BIO_s_file_internal());
191 189
192 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { 190 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
193 X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB); 191 X509error(ERR_R_SYS_LIB);
194 goto err; 192 goto err;
195 } 193 }
196 194
@@ -203,8 +201,7 @@ X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
203 ERR_clear_error(); 201 ERR_clear_error();
204 break; 202 break;
205 } else { 203 } else {
206 X509err(X509_F_X509_LOAD_CRL_FILE, 204 X509error(ERR_R_PEM_LIB);
207 ERR_R_PEM_LIB);
208 goto err; 205 goto err;
209 } 206 }
210 } 207 }
@@ -219,7 +216,7 @@ X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
219 } else if (type == X509_FILETYPE_ASN1) { 216 } else if (type == X509_FILETYPE_ASN1) {
220 x = d2i_X509_CRL_bio(in, NULL); 217 x = d2i_X509_CRL_bio(in, NULL);
221 if (x == NULL) { 218 if (x == NULL) {
222 X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB); 219 X509error(ERR_R_ASN1_LIB);
223 goto err; 220 goto err;
224 } 221 }
225 i = X509_STORE_add_crl(ctx->store_ctx, x); 222 i = X509_STORE_add_crl(ctx->store_ctx, x);
@@ -227,7 +224,7 @@ X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
227 goto err; 224 goto err;
228 ret = i; 225 ret = i;
229 } else { 226 } else {
230 X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE); 227 X509error(X509_R_BAD_X509_FILETYPE);
231 goto err; 228 goto err;
232 } 229 }
233err: 230err:
@@ -248,13 +245,13 @@ X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
248 return X509_load_cert_file(ctx, file, type); 245 return X509_load_cert_file(ctx, file, type);
249 in = BIO_new_file(file, "r"); 246 in = BIO_new_file(file, "r");
250 if (!in) { 247 if (!in) {
251 X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB); 248 X509error(ERR_R_SYS_LIB);
252 return 0; 249 return 0;
253 } 250 }
254 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); 251 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
255 BIO_free(in); 252 BIO_free(in);
256 if (!inf) { 253 if (!inf) {
257 X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB); 254 X509error(ERR_R_PEM_LIB);
258 return 0; 255 return 0;
259 } 256 }
260 for (i = 0; i < sk_X509_INFO_num(inf); i++) { 257 for (i = 0; i < sk_X509_INFO_num(inf); i++) {
diff --git a/src/lib/libcrypto/x509/by_mem.c b/src/lib/libcrypto/x509/by_mem.c
index ecab813406..34d4040d84 100644
--- a/src/lib/libcrypto/x509/by_mem.c
+++ b/src/lib/libcrypto/x509/by_mem.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: by_mem.c,v 1.3 2015/02/05 01:33:22 reyk Exp $ */ 1/* $OpenBSD: by_mem.c,v 1.4 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -129,7 +129,7 @@ by_mem_ctrl(X509_LOOKUP *lu, int cmd, const char *buf,
129 ok = count != 0; 129 ok = count != 0;
130 done: 130 done:
131 if (count == 0) 131 if (count == 0)
132 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); 132 X509error(ERR_R_PEM_LIB);
133 if (inf != NULL) 133 if (inf != NULL)
134 sk_X509_INFO_pop_free(inf, X509_INFO_free); 134 sk_X509_INFO_pop_free(inf, X509_INFO_free);
135 if (in != NULL) 135 if (in != NULL)
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
index ab11e79b0a..7304118eb3 100644
--- a/src/lib/libcrypto/x509/x509_att.c
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_att.c,v 1.14 2016/03/21 04:05:33 mmcc Exp $ */ 1/* $OpenBSD: x509_att.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -131,7 +131,7 @@ X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, X509_ATTRIBUTE *attr)
131 STACK_OF(X509_ATTRIBUTE) *sk = NULL; 131 STACK_OF(X509_ATTRIBUTE) *sk = NULL;
132 132
133 if (x == NULL) { 133 if (x == NULL) {
134 X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_PASSED_NULL_PARAMETER); 134 X509error(ERR_R_PASSED_NULL_PARAMETER);
135 return (NULL); 135 return (NULL);
136 } 136 }
137 137
@@ -150,7 +150,7 @@ X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, X509_ATTRIBUTE *attr)
150 return (sk); 150 return (sk);
151 151
152err: 152err:
153 X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_MALLOC_FAILURE); 153 X509error(ERR_R_MALLOC_FAILURE);
154err2: 154err2:
155 if (new_attr != NULL) 155 if (new_attr != NULL)
156 X509_ATTRIBUTE_free(new_attr); 156 X509_ATTRIBUTE_free(new_attr);
@@ -231,8 +231,7 @@ X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, int atrtype,
231 231
232 obj = OBJ_nid2obj(nid); 232 obj = OBJ_nid2obj(nid);
233 if (obj == NULL) { 233 if (obj == NULL) {
234 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID, 234 X509error(X509_R_UNKNOWN_NID);
235 X509_R_UNKNOWN_NID);
236 return (NULL); 235 return (NULL);
237 } 236 }
238 ret = X509_ATTRIBUTE_create_by_OBJ(attr, obj, atrtype, data, len); 237 ret = X509_ATTRIBUTE_create_by_OBJ(attr, obj, atrtype, data, len);
@@ -249,8 +248,7 @@ X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, const ASN1_OBJECT *obj,
249 248
250 if ((attr == NULL) || (*attr == NULL)) { 249 if ((attr == NULL) || (*attr == NULL)) {
251 if ((ret = X509_ATTRIBUTE_new()) == NULL) { 250 if ((ret = X509_ATTRIBUTE_new()) == NULL) {
252 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ, 251 X509error(ERR_R_MALLOC_FAILURE);
253 ERR_R_MALLOC_FAILURE);
254 return (NULL); 252 return (NULL);
255 } 253 }
256 } else 254 } else
@@ -280,8 +278,7 @@ X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, const char *atrname,
280 278
281 obj = OBJ_txt2obj(atrname, 0); 279 obj = OBJ_txt2obj(atrname, 0);
282 if (obj == NULL) { 280 if (obj == NULL) {
283 X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT, 281 X509error(X509_R_INVALID_FIELD_NAME);
284 X509_R_INVALID_FIELD_NAME);
285 ERR_asprintf_error_data("name=%s", atrname); 282 ERR_asprintf_error_data("name=%s", atrname);
286 return (NULL); 283 return (NULL);
287 } 284 }
@@ -314,8 +311,7 @@ X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data,
314 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, 311 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
315 OBJ_obj2nid(attr->object)); 312 OBJ_obj2nid(attr->object));
316 if (!stmp) { 313 if (!stmp) {
317 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, 314 X509error(ERR_R_ASN1_LIB);
318 ERR_R_ASN1_LIB);
319 return 0; 315 return 0;
320 } 316 }
321 atype = stmp->type; 317 atype = stmp->type;
@@ -352,7 +348,7 @@ X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data,
352err: 348err:
353 ASN1_TYPE_free(ttmp); 349 ASN1_TYPE_free(ttmp);
354 ASN1_STRING_free(stmp); 350 ASN1_STRING_free(stmp);
355 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); 351 X509error(ERR_R_MALLOC_FAILURE);
356 return 0; 352 return 0;
357} 353}
358 354
@@ -383,7 +379,7 @@ X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype, void *data)
383 if (!ttmp) 379 if (!ttmp)
384 return NULL; 380 return NULL;
385 if (atrtype != ASN1_TYPE_get(ttmp)){ 381 if (atrtype != ASN1_TYPE_get(ttmp)){
386 X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE); 382 X509error(X509_R_WRONG_TYPE);
387 return NULL; 383 return NULL;
388 } 384 }
389 return ttmp->value.ptr; 385 return ttmp->value.ptr;
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
index 407e1e07ad..72fbef1544 100644
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_cmp.c,v 1.26 2015/07/29 14:58:34 jsing Exp $ */ 1/* $OpenBSD: x509_cmp.c,v 1.27 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -351,16 +351,13 @@ X509_check_private_key(X509 *x, EVP_PKEY *k)
351 case 1: 351 case 1:
352 break; 352 break;
353 case 0: 353 case 0:
354 X509err(X509_F_X509_CHECK_PRIVATE_KEY, 354 X509error(X509_R_KEY_VALUES_MISMATCH);
355 X509_R_KEY_VALUES_MISMATCH);
356 break; 355 break;
357 case -1: 356 case -1:
358 X509err(X509_F_X509_CHECK_PRIVATE_KEY, 357 X509error(X509_R_KEY_TYPE_MISMATCH);
359 X509_R_KEY_TYPE_MISMATCH);
360 break; 358 break;
361 case -2: 359 case -2:
362 X509err(X509_F_X509_CHECK_PRIVATE_KEY, 360 X509error(X509_R_UNKNOWN_KEY_TYPE);
363 X509_R_UNKNOWN_KEY_TYPE);
364 } 361 }
365 EVP_PKEY_free(xk); 362 EVP_PKEY_free(xk);
366 if (ret > 0) 363 if (ret > 0)
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
index 6a15ac9fd0..3b321376ad 100644
--- a/src/lib/libcrypto/x509/x509_err.c
+++ b/src/lib/libcrypto/x509/x509_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_err.c,v 1.12 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: x509_err.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -72,51 +72,7 @@
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason) 72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason)
73 73
74static ERR_STRING_DATA X509_str_functs[] = { 74static ERR_STRING_DATA X509_str_functs[] = {
75 {ERR_FUNC(X509_F_ADD_CERT_DIR), "ADD_CERT_DIR"}, 75 {ERR_FUNC(0xfff), "CRYPTO_internal"},
76 {ERR_FUNC(X509_F_BY_FILE_CTRL), "BY_FILE_CTRL"},
77 {ERR_FUNC(X509_F_CHECK_POLICY), "CHECK_POLICY"},
78 {ERR_FUNC(X509_F_DIR_CTRL), "DIR_CTRL"},
79 {ERR_FUNC(X509_F_GET_CERT_BY_SUBJECT), "GET_CERT_BY_SUBJECT"},
80 {ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_DECODE), "NETSCAPE_SPKI_b64_decode"},
81 {ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_ENCODE), "NETSCAPE_SPKI_b64_encode"},
82 {ERR_FUNC(X509_F_X509AT_ADD1_ATTR), "X509at_add1_attr"},
83 {ERR_FUNC(X509_F_X509V3_ADD_EXT), "X509v3_add_ext"},
84 {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_NID), "X509_ATTRIBUTE_create_by_NID"},
85 {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ), "X509_ATTRIBUTE_create_by_OBJ"},
86 {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT), "X509_ATTRIBUTE_create_by_txt"},
87 {ERR_FUNC(X509_F_X509_ATTRIBUTE_GET0_DATA), "X509_ATTRIBUTE_get0_data"},
88 {ERR_FUNC(X509_F_X509_ATTRIBUTE_SET1_DATA), "X509_ATTRIBUTE_set1_data"},
89 {ERR_FUNC(X509_F_X509_CHECK_PRIVATE_KEY), "X509_check_private_key"},
90 {ERR_FUNC(X509_F_X509_CRL_PRINT_FP), "X509_CRL_print_fp"},
91 {ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_NID), "X509_EXTENSION_create_by_NID"},
92 {ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_OBJ), "X509_EXTENSION_create_by_OBJ"},
93 {ERR_FUNC(X509_F_X509_GET_PUBKEY_PARAMETERS), "X509_get_pubkey_parameters"},
94 {ERR_FUNC(X509_F_X509_LOAD_CERT_CRL_FILE), "X509_load_cert_crl_file"},
95 {ERR_FUNC(X509_F_X509_LOAD_CERT_FILE), "X509_load_cert_file"},
96 {ERR_FUNC(X509_F_X509_LOAD_CRL_FILE), "X509_load_crl_file"},
97 {ERR_FUNC(X509_F_X509_NAME_ADD_ENTRY), "X509_NAME_add_entry"},
98 {ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_NID), "X509_NAME_ENTRY_create_by_NID"},
99 {ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT), "X509_NAME_ENTRY_create_by_txt"},
100 {ERR_FUNC(X509_F_X509_NAME_ENTRY_SET_OBJECT), "X509_NAME_ENTRY_set_object"},
101 {ERR_FUNC(X509_F_X509_NAME_ONELINE), "X509_NAME_oneline"},
102 {ERR_FUNC(X509_F_X509_NAME_PRINT), "X509_NAME_print"},
103 {ERR_FUNC(X509_F_X509_PRINT_EX_FP), "X509_print_ex_fp"},
104 {ERR_FUNC(X509_F_X509_PUBKEY_GET), "X509_PUBKEY_get"},
105 {ERR_FUNC(X509_F_X509_PUBKEY_SET), "X509_PUBKEY_set"},
106 {ERR_FUNC(X509_F_X509_REQ_CHECK_PRIVATE_KEY), "X509_REQ_check_private_key"},
107 {ERR_FUNC(X509_F_X509_REQ_PRINT_EX), "X509_REQ_print_ex"},
108 {ERR_FUNC(X509_F_X509_REQ_PRINT_FP), "X509_REQ_print_fp"},
109 {ERR_FUNC(X509_F_X509_REQ_TO_X509), "X509_REQ_to_X509"},
110 {ERR_FUNC(X509_F_X509_STORE_ADD_CERT), "X509_STORE_add_cert"},
111 {ERR_FUNC(X509_F_X509_STORE_ADD_CRL), "X509_STORE_add_crl"},
112 {ERR_FUNC(X509_F_X509_STORE_CTX_GET1_ISSUER), "X509_STORE_CTX_get1_issuer"},
113 {ERR_FUNC(X509_F_X509_STORE_CTX_INIT), "X509_STORE_CTX_init"},
114 {ERR_FUNC(X509_F_X509_STORE_CTX_NEW), "X509_STORE_CTX_new"},
115 {ERR_FUNC(X509_F_X509_STORE_CTX_PURPOSE_INHERIT), "X509_STORE_CTX_purpose_inherit"},
116 {ERR_FUNC(X509_F_X509_TO_X509_REQ), "X509_to_X509_REQ"},
117 {ERR_FUNC(X509_F_X509_TRUST_ADD), "X509_TRUST_add"},
118 {ERR_FUNC(X509_F_X509_TRUST_SET), "X509_TRUST_set"},
119 {ERR_FUNC(X509_F_X509_VERIFY_CERT), "X509_verify_cert"},
120 {0, NULL} 76 {0, NULL}
121}; 77};
122 78
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index d8d0bb4147..6cde29fefc 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_lu.c,v 1.22 2016/11/13 08:47:54 miod Exp $ */ 1/* $OpenBSD: x509_lu.c,v 1.23 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -349,7 +349,7 @@ X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
349 return 0; 349 return 0;
350 obj = malloc(sizeof(X509_OBJECT)); 350 obj = malloc(sizeof(X509_OBJECT));
351 if (obj == NULL) { 351 if (obj == NULL) {
352 X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); 352 X509error(ERR_R_MALLOC_FAILURE);
353 return 0; 353 return 0;
354 } 354 }
355 obj->type = X509_LU_X509; 355 obj->type = X509_LU_X509;
@@ -360,13 +360,11 @@ X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
360 X509_OBJECT_up_ref_count(obj); 360 X509_OBJECT_up_ref_count(obj);
361 361
362 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { 362 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
363 X509err(X509_F_X509_STORE_ADD_CERT, 363 X509error(X509_R_CERT_ALREADY_IN_HASH_TABLE);
364 X509_R_CERT_ALREADY_IN_HASH_TABLE);
365 ret = 0; 364 ret = 0;
366 } else { 365 } else {
367 if (sk_X509_OBJECT_push(ctx->objs, obj) == 0) { 366 if (sk_X509_OBJECT_push(ctx->objs, obj) == 0) {
368 X509err(X509_F_X509_STORE_ADD_CERT, 367 X509error(ERR_R_MALLOC_FAILURE);
369 ERR_R_MALLOC_FAILURE);
370 ret = 0; 368 ret = 0;
371 } 369 }
372 } 370 }
@@ -394,7 +392,7 @@ X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
394 return 0; 392 return 0;
395 obj = malloc(sizeof(X509_OBJECT)); 393 obj = malloc(sizeof(X509_OBJECT));
396 if (obj == NULL) { 394 if (obj == NULL) {
397 X509err(X509_F_X509_STORE_ADD_CRL, ERR_R_MALLOC_FAILURE); 395 X509error(ERR_R_MALLOC_FAILURE);
398 return 0; 396 return 0;
399 } 397 }
400 obj->type = X509_LU_CRL; 398 obj->type = X509_LU_CRL;
@@ -405,13 +403,11 @@ X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
405 X509_OBJECT_up_ref_count(obj); 403 X509_OBJECT_up_ref_count(obj);
406 404
407 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { 405 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
408 X509err(X509_F_X509_STORE_ADD_CRL, 406 X509error(X509_R_CERT_ALREADY_IN_HASH_TABLE);
409 X509_R_CERT_ALREADY_IN_HASH_TABLE);
410 ret = 0; 407 ret = 0;
411 } else { 408 } else {
412 if (sk_X509_OBJECT_push(ctx->objs, obj) == 0) { 409 if (sk_X509_OBJECT_push(ctx->objs, obj) == 0) {
413 X509err(X509_F_X509_STORE_ADD_CRL, 410 X509error(ERR_R_MALLOC_FAILURE);
414 ERR_R_MALLOC_FAILURE);
415 ret = 0; 411 ret = 0;
416 } 412 }
417 } 413 }
@@ -678,8 +674,7 @@ X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
678 if (ok != X509_LU_X509) { 674 if (ok != X509_LU_X509) {
679 if (ok == X509_LU_RETRY) { 675 if (ok == X509_LU_RETRY) {
680 X509_OBJECT_free_contents(&obj); 676 X509_OBJECT_free_contents(&obj);
681 X509err(X509_F_X509_STORE_CTX_GET1_ISSUER, 677 X509error(X509_R_SHOULD_RETRY);
682 X509_R_SHOULD_RETRY);
683 return -1; 678 return -1;
684 } else if (ok != X509_LU_FAIL) { 679 } else if (ok != X509_LU_FAIL) {
685 X509_OBJECT_free_contents(&obj); 680 X509_OBJECT_free_contents(&obj);
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
index f7f2a380a1..b34f25b013 100644
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ b/src/lib/libcrypto/x509/x509_obj.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_obj.c,v 1.16 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: x509_obj.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -172,7 +172,7 @@ X509_NAME_oneline(X509_NAME *a, char *buf, int len)
172 return (p); 172 return (p);
173 173
174err: 174err:
175 X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE); 175 X509error(ERR_R_MALLOC_FAILURE);
176 if (b != NULL) 176 if (b != NULL)
177 BUF_MEM_free(b); 177 BUF_MEM_free(b);
178 return (NULL); 178 return (NULL);
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
index 76faa29b7f..525163bc3e 100644
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ b/src/lib/libcrypto/x509/x509_r2x.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_r2x.c,v 1.10 2015/09/30 17:30:16 jsing Exp $ */ 1/* $OpenBSD: x509_r2x.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -74,7 +74,7 @@ X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
74 X509_NAME *xn; 74 X509_NAME *xn;
75 75
76 if ((ret = X509_new()) == NULL) { 76 if ((ret = X509_new()) == NULL) {
77 X509err(X509_F_X509_REQ_TO_X509, ERR_R_MALLOC_FAILURE); 77 X509error(ERR_R_MALLOC_FAILURE);
78 goto err; 78 goto err;
79 } 79 }
80 80
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index e6fc3c5df8..f87b35c706 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_req.c,v 1.19 2016/12/30 15:24:51 jsing Exp $ */ 1/* $OpenBSD: x509_req.c,v 1.20 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,7 +80,7 @@ X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
80 80
81 ret = X509_REQ_new(); 81 ret = X509_REQ_new();
82 if (ret == NULL) { 82 if (ret == NULL) {
83 X509err(X509_F_X509_TO_X509_REQ, ERR_R_MALLOC_FAILURE); 83 X509error(ERR_R_MALLOC_FAILURE);
84 goto err; 84 goto err;
85 } 85 }
86 86
@@ -133,31 +133,26 @@ X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)
133 ok = 1; 133 ok = 1;
134 break; 134 break;
135 case 0: 135 case 0:
136 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, 136 X509error(X509_R_KEY_VALUES_MISMATCH);
137 X509_R_KEY_VALUES_MISMATCH);
138 break; 137 break;
139 case -1: 138 case -1:
140 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, 139 X509error(X509_R_KEY_TYPE_MISMATCH);
141 X509_R_KEY_TYPE_MISMATCH);
142 break; 140 break;
143 case -2: 141 case -2:
144#ifndef OPENSSL_NO_EC 142#ifndef OPENSSL_NO_EC
145 if (k->type == EVP_PKEY_EC) { 143 if (k->type == EVP_PKEY_EC) {
146 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, 144 X509error(ERR_R_EC_LIB);
147 ERR_R_EC_LIB);
148 break; 145 break;
149 } 146 }
150#endif 147#endif
151#ifndef OPENSSL_NO_DH 148#ifndef OPENSSL_NO_DH
152 if (k->type == EVP_PKEY_DH) { 149 if (k->type == EVP_PKEY_DH) {
153 /* No idea */ 150 /* No idea */
154 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, 151 X509error(X509_R_CANT_CHECK_DH_KEY);
155 X509_R_CANT_CHECK_DH_KEY);
156 break; 152 break;
157 } 153 }
158#endif 154#endif
159 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, 155 X509error(X509_R_UNKNOWN_KEY_TYPE);
160 X509_R_UNKNOWN_KEY_TYPE);
161 } 156 }
162 157
163 EVP_PKEY_free(xk); 158 EVP_PKEY_free(xk);
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index 5be7abdf08..9af74de1ca 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_trs.c,v 1.21 2016/11/06 10:31:34 beck Exp $ */ 1/* $OpenBSD: x509_trs.c,v 1.22 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -178,7 +178,7 @@ int
178X509_TRUST_set(int *t, int trust) 178X509_TRUST_set(int *t, int trust)
179{ 179{
180 if (X509_TRUST_get_by_id(trust) == -1) { 180 if (X509_TRUST_get_by_id(trust) == -1) {
181 X509err(X509_F_X509_TRUST_SET, X509_R_INVALID_TRUST); 181 X509error(X509_R_INVALID_TRUST);
182 return 0; 182 return 0;
183 } 183 }
184 *t = trust; 184 *t = trust;
@@ -202,14 +202,14 @@ X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
202 /* Need a new entry */ 202 /* Need a new entry */
203 if (idx == -1) { 203 if (idx == -1) {
204 if (!(trtmp = malloc(sizeof(X509_TRUST)))) { 204 if (!(trtmp = malloc(sizeof(X509_TRUST)))) {
205 X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); 205 X509error(ERR_R_MALLOC_FAILURE);
206 return 0; 206 return 0;
207 } 207 }
208 trtmp->flags = X509_TRUST_DYNAMIC; 208 trtmp->flags = X509_TRUST_DYNAMIC;
209 } else { 209 } else {
210 trtmp = X509_TRUST_get0(idx); 210 trtmp = X509_TRUST_get0(idx);
211 if (trtmp == NULL) { 211 if (trtmp == NULL) {
212 X509err(X509_F_X509_TRUST_ADD, X509_R_INVALID_TRUST); 212 X509error(X509_R_INVALID_TRUST);
213 return 0; 213 return 0;
214 } 214 }
215 } 215 }
@@ -246,7 +246,7 @@ err:
246 free(name_dup); 246 free(name_dup);
247 if (idx == -1) 247 if (idx == -1)
248 free(trtmp); 248 free(trtmp);
249 X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); 249 X509error(ERR_R_MALLOC_FAILURE);
250 return 0; 250 return 0;
251} 251}
252 252
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index d9ec9c8c14..446ef319f8 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_v3.c,v 1.13 2016/03/21 04:05:33 mmcc Exp $ */ 1/* $OpenBSD: x509_v3.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -156,7 +156,7 @@ X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc)
156 STACK_OF(X509_EXTENSION) *sk = NULL; 156 STACK_OF(X509_EXTENSION) *sk = NULL;
157 157
158 if (x == NULL) { 158 if (x == NULL) {
159 X509err(X509_F_X509V3_ADD_EXT, ERR_R_PASSED_NULL_PARAMETER); 159 X509error(ERR_R_PASSED_NULL_PARAMETER);
160 goto err2; 160 goto err2;
161 } 161 }
162 162
@@ -181,7 +181,7 @@ X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc)
181 return (sk); 181 return (sk);
182 182
183err: 183err:
184 X509err(X509_F_X509V3_ADD_EXT, ERR_R_MALLOC_FAILURE); 184 X509error(ERR_R_MALLOC_FAILURE);
185err2: 185err2:
186 if (new_ex != NULL) 186 if (new_ex != NULL)
187 X509_EXTENSION_free(new_ex); 187 X509_EXTENSION_free(new_ex);
@@ -199,8 +199,7 @@ X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, int crit,
199 199
200 obj = OBJ_nid2obj(nid); 200 obj = OBJ_nid2obj(nid);
201 if (obj == NULL) { 201 if (obj == NULL) {
202 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID, 202 X509error(X509_R_UNKNOWN_NID);
203 X509_R_UNKNOWN_NID);
204 return (NULL); 203 return (NULL);
205 } 204 }
206 ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data); 205 ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data);
@@ -217,8 +216,7 @@ X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, ASN1_OBJECT *obj, int crit,
217 216
218 if ((ex == NULL) || (*ex == NULL)) { 217 if ((ex == NULL) || (*ex == NULL)) {
219 if ((ret = X509_EXTENSION_new()) == NULL) { 218 if ((ret = X509_EXTENSION_new()) == NULL) {
220 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ, 219 X509error(ERR_R_MALLOC_FAILURE);
221 ERR_R_MALLOC_FAILURE);
222 return (NULL); 220 return (NULL);
223 } 221 }
224 } else 222 } else
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
index 9dba97bbf8..b81387a237 100644
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_vfy.c,v 1.59 2017/01/21 01:09:54 beck Exp $ */ 1/* $OpenBSD: x509_vfy.c,v 1.60 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -228,8 +228,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
228 STACK_OF(X509) *sktmp = NULL; 228 STACK_OF(X509) *sktmp = NULL;
229 229
230 if (ctx->cert == NULL) { 230 if (ctx->cert == NULL) {
231 X509err(X509_F_X509_VERIFY_CERT, 231 X509error(X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
232 X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
233 ctx->error = X509_V_ERR_INVALID_CALL; 232 ctx->error = X509_V_ERR_INVALID_CALL;
234 return -1; 233 return -1;
235 } 234 }
@@ -238,8 +237,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
238 * This X509_STORE_CTX has already been used to verify 237 * This X509_STORE_CTX has already been used to verify
239 * a cert. We cannot do another one. 238 * a cert. We cannot do another one.
240 */ 239 */
241 X509err(X509_F_X509_VERIFY_CERT, 240 X509error(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
242 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
243 ctx->error = X509_V_ERR_INVALID_CALL; 241 ctx->error = X509_V_ERR_INVALID_CALL;
244 return -1; 242 return -1;
245 } 243 }
@@ -247,8 +245,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
247 /* 245 /*
248 * This X509_STORE_CTX has not been properly initialized. 246 * This X509_STORE_CTX has not been properly initialized.
249 */ 247 */
250 X509err(X509_F_X509_VERIFY_CERT, 248 X509error(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
251 ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
252 ctx->error = X509_V_ERR_INVALID_CALL; 249 ctx->error = X509_V_ERR_INVALID_CALL;
253 return -1; 250 return -1;
254 } 251 }
@@ -262,7 +259,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
262 */ 259 */
263 ctx->chain = sk_X509_new_null(); 260 ctx->chain = sk_X509_new_null();
264 if (ctx->chain == NULL || !sk_X509_push(ctx->chain, ctx->cert)) { 261 if (ctx->chain == NULL || !sk_X509_push(ctx->chain, ctx->cert)) {
265 X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); 262 X509error(ERR_R_MALLOC_FAILURE);
266 ctx->error = X509_V_ERR_OUT_OF_MEM; 263 ctx->error = X509_V_ERR_OUT_OF_MEM;
267 goto end; 264 goto end;
268 } 265 }
@@ -272,7 +269,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
272 /* We use a temporary STACK so we can chop and hack at it */ 269 /* We use a temporary STACK so we can chop and hack at it */
273 if (ctx->untrusted != NULL && 270 if (ctx->untrusted != NULL &&
274 (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) { 271 (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) {
275 X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); 272 X509error(ERR_R_MALLOC_FAILURE);
276 ctx->error = X509_V_ERR_OUT_OF_MEM; 273 ctx->error = X509_V_ERR_OUT_OF_MEM;
277 goto end; 274 goto end;
278 } 275 }
@@ -316,8 +313,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
316 xtmp = find_issuer(ctx, sktmp, x); 313 xtmp = find_issuer(ctx, sktmp, x);
317 if (xtmp != NULL) { 314 if (xtmp != NULL) {
318 if (!sk_X509_push(ctx->chain, xtmp)) { 315 if (!sk_X509_push(ctx->chain, xtmp)) {
319 X509err(X509_F_X509_VERIFY_CERT, 316 X509error(ERR_R_MALLOC_FAILURE);
320 ERR_R_MALLOC_FAILURE);
321 ctx->error = X509_V_ERR_OUT_OF_MEM; 317 ctx->error = X509_V_ERR_OUT_OF_MEM;
322 ok = 0; 318 ok = 0;
323 goto end; 319 goto end;
@@ -415,8 +411,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
415 x = xtmp; 411 x = xtmp;
416 if (!sk_X509_push(ctx->chain, x)) { 412 if (!sk_X509_push(ctx->chain, x)) {
417 X509_free(xtmp); 413 X509_free(xtmp);
418 X509err(X509_F_X509_VERIFY_CERT, 414 X509error(ERR_R_MALLOC_FAILURE);
419 ERR_R_MALLOC_FAILURE);
420 ctx->error = X509_V_ERR_OUT_OF_MEM; 415 ctx->error = X509_V_ERR_OUT_OF_MEM;
421 ok = 0; 416 ok = 0;
422 goto end; 417 goto end;
@@ -488,7 +483,7 @@ X509_verify_cert(X509_STORE_CTX *ctx)
488 } else { 483 } else {
489 if (!sk_X509_push(ctx->chain, chain_ss)) { 484 if (!sk_X509_push(ctx->chain, chain_ss)) {
490 X509_free(chain_ss); 485 X509_free(chain_ss);
491 X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); 486 X509error(ERR_R_MALLOC_FAILURE);
492 return 0; 487 return 0;
493 } 488 }
494 num++; 489 num++;
@@ -1669,7 +1664,7 @@ check_policy(X509_STORE_CTX *ctx)
1669 ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain, 1664 ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain,
1670 ctx->param->policies, ctx->param->flags); 1665 ctx->param->policies, ctx->param->flags);
1671 if (ret == 0) { 1666 if (ret == 0) {
1672 X509err(X509_F_CHECK_POLICY, ERR_R_MALLOC_FAILURE); 1667 X509error(ERR_R_MALLOC_FAILURE);
1673 return 0; 1668 return 0;
1674 } 1669 }
1675 /* Invalid or inconsistent extensions */ 1670 /* Invalid or inconsistent extensions */
@@ -1941,8 +1936,7 @@ X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
1941 for (i = 0; i < sk_X509_num(chain); i++) { 1936 for (i = 0; i < sk_X509_num(chain); i++) {
1942 ktmp = X509_get_pubkey(sk_X509_value(chain, i)); 1937 ktmp = X509_get_pubkey(sk_X509_value(chain, i));
1943 if (ktmp == NULL) { 1938 if (ktmp == NULL) {
1944 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS, 1939 X509error(X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
1945 X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
1946 return 0; 1940 return 0;
1947 } 1941 }
1948 if (!EVP_PKEY_missing_parameters(ktmp)) 1942 if (!EVP_PKEY_missing_parameters(ktmp))
@@ -1953,8 +1947,7 @@ X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
1953 } 1947 }
1954 } 1948 }
1955 if (ktmp == NULL) { 1949 if (ktmp == NULL) {
1956 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS, 1950 X509error(X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
1957 X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);
1958 return 0; 1951 return 0;
1959 } 1952 }
1960 1953
@@ -2109,16 +2102,14 @@ X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2109 X509_PURPOSE *ptmp; 2102 X509_PURPOSE *ptmp;
2110 idx = X509_PURPOSE_get_by_id(purpose); 2103 idx = X509_PURPOSE_get_by_id(purpose);
2111 if (idx == -1) { 2104 if (idx == -1) {
2112 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, 2105 X509error(X509_R_UNKNOWN_PURPOSE_ID);
2113 X509_R_UNKNOWN_PURPOSE_ID);
2114 return 0; 2106 return 0;
2115 } 2107 }
2116 ptmp = X509_PURPOSE_get0(idx); 2108 ptmp = X509_PURPOSE_get0(idx);
2117 if (ptmp->trust == X509_TRUST_DEFAULT) { 2109 if (ptmp->trust == X509_TRUST_DEFAULT) {
2118 idx = X509_PURPOSE_get_by_id(def_purpose); 2110 idx = X509_PURPOSE_get_by_id(def_purpose);
2119 if (idx == -1) { 2111 if (idx == -1) {
2120 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, 2112 X509error(X509_R_UNKNOWN_PURPOSE_ID);
2121 X509_R_UNKNOWN_PURPOSE_ID);
2122 return 0; 2113 return 0;
2123 } 2114 }
2124 ptmp = X509_PURPOSE_get0(idx); 2115 ptmp = X509_PURPOSE_get0(idx);
@@ -2130,8 +2121,7 @@ X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2130 if (trust) { 2121 if (trust) {
2131 idx = X509_TRUST_get_by_id(trust); 2122 idx = X509_TRUST_get_by_id(trust);
2132 if (idx == -1) { 2123 if (idx == -1) {
2133 X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, 2124 X509error(X509_R_UNKNOWN_TRUST_ID);
2134 X509_R_UNKNOWN_TRUST_ID);
2135 return 0; 2125 return 0;
2136 } 2126 }
2137 } 2127 }
@@ -2150,7 +2140,7 @@ X509_STORE_CTX_new(void)
2150 2140
2151 ctx = calloc(1, sizeof(X509_STORE_CTX)); 2141 ctx = calloc(1, sizeof(X509_STORE_CTX));
2152 if (!ctx) { 2142 if (!ctx) {
2153 X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE); 2143 X509error(ERR_R_MALLOC_FAILURE);
2154 return NULL; 2144 return NULL;
2155 } 2145 }
2156 return ctx; 2146 return ctx;
@@ -2258,7 +2248,7 @@ X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2258 2248
2259 ctx->param = X509_VERIFY_PARAM_new(); 2249 ctx->param = X509_VERIFY_PARAM_new();
2260 if (!ctx->param) { 2250 if (!ctx->param) {
2261 X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); 2251 X509error(ERR_R_MALLOC_FAILURE);
2262 return 0; 2252 return 0;
2263 } 2253 }
2264 2254
@@ -2275,13 +2265,13 @@ X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2275 X509_VERIFY_PARAM_lookup("default")); 2265 X509_VERIFY_PARAM_lookup("default"));
2276 2266
2277 if (param_ret == 0) { 2267 if (param_ret == 0) {
2278 X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); 2268 X509error(ERR_R_MALLOC_FAILURE);
2279 return 0; 2269 return 0;
2280 } 2270 }
2281 2271
2282 if (CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, 2272 if (CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx,
2283 &(ctx->ex_data)) == 0) { 2273 &(ctx->ex_data)) == 0) {
2284 X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); 2274 X509error(ERR_R_MALLOC_FAILURE);
2285 return 0; 2275 return 0;
2286 } 2276 }
2287 return 1; 2277 return 1;
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c
index 14634013cf..ef242ce0a5 100644
--- a/src/lib/libcrypto/x509/x509name.c
+++ b/src/lib/libcrypto/x509/x509name.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509name.c,v 1.13 2014/09/29 04:17:24 miod Exp $ */ 1/* $OpenBSD: x509name.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -275,7 +275,7 @@ X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, int set)
275 goto err; 275 goto err;
276 new_name->set = set; 276 new_name->set = set;
277 if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) { 277 if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) {
278 X509err(X509_F_X509_NAME_ADD_ENTRY, ERR_R_MALLOC_FAILURE); 278 X509error(ERR_R_MALLOC_FAILURE);
279 goto err; 279 goto err;
280 } 280 }
281 if (inc) { 281 if (inc) {
@@ -300,8 +300,7 @@ X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne,
300 300
301 obj = OBJ_txt2obj(field, 0); 301 obj = OBJ_txt2obj(field, 0);
302 if (obj == NULL) { 302 if (obj == NULL) {
303 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, 303 X509error(X509_R_INVALID_FIELD_NAME);
304 X509_R_INVALID_FIELD_NAME);
305 ERR_asprintf_error_data("name=%s", field); 304 ERR_asprintf_error_data("name=%s", field);
306 return (NULL); 305 return (NULL);
307 } 306 }
@@ -319,8 +318,7 @@ X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,
319 318
320 obj = OBJ_nid2obj(nid); 319 obj = OBJ_nid2obj(nid);
321 if (obj == NULL) { 320 if (obj == NULL) {
322 X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID, 321 X509error(X509_R_UNKNOWN_NID);
323 X509_R_UNKNOWN_NID);
324 return (NULL); 322 return (NULL);
325 } 323 }
326 nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); 324 nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len);
@@ -359,8 +357,7 @@ int
359X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) 357X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
360{ 358{
361 if ((ne == NULL) || (obj == NULL)) { 359 if ((ne == NULL) || (obj == NULL)) {
362 X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT, 360 X509error(ERR_R_PASSED_NULL_PARAMETER);
363 ERR_R_PASSED_NULL_PARAMETER);
364 return (0); 361 return (0);
365 } 362 }
366 ASN1_OBJECT_free(ne->object); 363 ASN1_OBJECT_free(ne->object);
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
index cd29a8138a..3a1c37cd86 100644
--- a/src/lib/libcrypto/x509/x509spki.c
+++ b/src/lib/libcrypto/x509/x509spki.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509spki.c,v 1.12 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: x509spki.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -91,13 +91,12 @@ NETSCAPE_SPKI_b64_decode(const char *str, int len)
91 if (len <= 0) 91 if (len <= 0)
92 len = strlen(str); 92 len = strlen(str);
93 if (!(spki_der = malloc(len + 1))) { 93 if (!(spki_der = malloc(len + 1))) {
94 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); 94 X509error(ERR_R_MALLOC_FAILURE);
95 return NULL; 95 return NULL;
96 } 96 }
97 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); 97 spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len);
98 if (spki_len < 0) { 98 if (spki_len < 0) {
99 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, 99 X509error(X509_R_BASE64_DECODE_ERROR);
100 X509_R_BASE64_DECODE_ERROR);
101 free(spki_der); 100 free(spki_der);
102 return NULL; 101 return NULL;
103 } 102 }
@@ -119,7 +118,7 @@ NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
119 der_spki = malloc(der_len); 118 der_spki = malloc(der_len);
120 b64_str = reallocarray(NULL, der_len, 2); 119 b64_str = reallocarray(NULL, der_len, 2);
121 if (!der_spki || !b64_str) { 120 if (!der_spki || !b64_str) {
122 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); 121 X509error(ERR_R_MALLOC_FAILURE);
123 free(der_spki); 122 free(der_spki);
124 free(b64_str); 123 free(b64_str);
125 return NULL; 124 return NULL;
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
index 028c709d28..e2e5730c7d 100644
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ b/src/lib/libcrypto/x509v3/v3_akey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_akey.c,v 1.18 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_akey.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -145,8 +145,7 @@ v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
145 if (cnf->value && !strcmp(cnf->value, "always")) 145 if (cnf->value && !strcmp(cnf->value, "always"))
146 issuer = 2; 146 issuer = 2;
147 } else { 147 } else {
148 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, 148 X509V3error(X509V3_R_UNKNOWN_OPTION);
149 X509V3_R_UNKNOWN_OPTION);
150 ERR_asprintf_error_data("name=%s", cnf->name); 149 ERR_asprintf_error_data("name=%s", cnf->name);
151 return NULL; 150 return NULL;
152 } 151 }
@@ -155,8 +154,7 @@ v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
155 if (!ctx || !ctx->issuer_cert) { 154 if (!ctx || !ctx->issuer_cert) {
156 if (ctx && (ctx->flags == CTX_TEST)) 155 if (ctx && (ctx->flags == CTX_TEST))
157 return AUTHORITY_KEYID_new(); 156 return AUTHORITY_KEYID_new();
158 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, 157 X509V3error(X509V3_R_NO_ISSUER_CERTIFICATE);
159 X509V3_R_NO_ISSUER_CERTIFICATE);
160 return NULL; 158 return NULL;
161 } 159 }
162 160
@@ -167,8 +165,7 @@ v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
167 if ((i >= 0) && (ext = X509_get_ext(cert, i))) 165 if ((i >= 0) && (ext = X509_get_ext(cert, i)))
168 ikeyid = X509V3_EXT_d2i(ext); 166 ikeyid = X509V3_EXT_d2i(ext);
169 if (keyid == 2 && !ikeyid) { 167 if (keyid == 2 && !ikeyid) {
170 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, 168 X509V3error(X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
171 X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
172 return NULL; 169 return NULL;
173 } 170 }
174 } 171 }
@@ -177,8 +174,7 @@ v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
177 isname = X509_NAME_dup(X509_get_issuer_name(cert)); 174 isname = X509_NAME_dup(X509_get_issuer_name(cert));
178 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert)); 175 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert));
179 if (!isname || !serial) { 176 if (!isname || !serial) {
180 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, 177 X509V3error(X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
181 X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
182 goto err; 178 goto err;
183 } 179 }
184 } 180 }
@@ -190,8 +186,7 @@ v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
190 if (!(gens = sk_GENERAL_NAME_new_null()) || 186 if (!(gens = sk_GENERAL_NAME_new_null()) ||
191 !(gen = GENERAL_NAME_new()) || 187 !(gen = GENERAL_NAME_new()) ||
192 !sk_GENERAL_NAME_push(gens, gen)) { 188 !sk_GENERAL_NAME_push(gens, gen)) {
193 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, 189 X509V3error(ERR_R_MALLOC_FAILURE);
194 ERR_R_MALLOC_FAILURE);
195 goto err; 190 goto err;
196 } 191 }
197 gen->type = GEN_DIRNAME; 192 gen->type = GEN_DIRNAME;
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
index 23867ea449..746339bebd 100644
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_alt.c,v 1.26 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_alt.c,v 1.27 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -279,7 +279,7 @@ v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
279 int i; 279 int i;
280 280
281 if ((gens = sk_GENERAL_NAME_new_null()) == NULL) { 281 if ((gens = sk_GENERAL_NAME_new_null()) == NULL) {
282 X509V3err(X509V3_F_V2I_ISSUER_ALT, ERR_R_MALLOC_FAILURE); 282 X509V3error(ERR_R_MALLOC_FAILURE);
283 return NULL; 283 return NULL;
284 } 284 }
285 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { 285 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -318,7 +318,7 @@ copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
318 if (ctx && (ctx->flags == CTX_TEST)) 318 if (ctx && (ctx->flags == CTX_TEST))
319 return 1; 319 return 1;
320 if (!ctx || !ctx->issuer_cert) { 320 if (!ctx || !ctx->issuer_cert) {
321 X509V3err(X509V3_F_COPY_ISSUER, X509V3_R_NO_ISSUER_DETAILS); 321 X509V3error(X509V3_R_NO_ISSUER_DETAILS);
322 goto err; 322 goto err;
323 } 323 }
324 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1); 324 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
@@ -326,14 +326,14 @@ copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens)
326 return 1; 326 return 1;
327 if (!(ext = X509_get_ext(ctx->issuer_cert, i)) || 327 if (!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
328 !(ialt = X509V3_EXT_d2i(ext))) { 328 !(ialt = X509V3_EXT_d2i(ext))) {
329 X509V3err(X509V3_F_COPY_ISSUER, X509V3_R_ISSUER_DECODE_ERROR); 329 X509V3error(X509V3_R_ISSUER_DECODE_ERROR);
330 goto err; 330 goto err;
331 } 331 }
332 332
333 for (i = 0; i < sk_GENERAL_NAME_num(ialt); i++) { 333 for (i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
334 gen = sk_GENERAL_NAME_value(ialt, i); 334 gen = sk_GENERAL_NAME_value(ialt, i);
335 if (!sk_GENERAL_NAME_push(gens, gen)) { 335 if (!sk_GENERAL_NAME_push(gens, gen)) {
336 X509V3err(X509V3_F_COPY_ISSUER, ERR_R_MALLOC_FAILURE); 336 X509V3error(ERR_R_MALLOC_FAILURE);
337 goto err; 337 goto err;
338 } 338 }
339 } 339 }
@@ -355,7 +355,7 @@ v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
355 int i; 355 int i;
356 356
357 if (!(gens = sk_GENERAL_NAME_new_null())) { 357 if (!(gens = sk_GENERAL_NAME_new_null())) {
358 X509V3err(X509V3_F_V2I_SUBJECT_ALT, ERR_R_MALLOC_FAILURE); 358 X509V3error(ERR_R_MALLOC_FAILURE);
359 return NULL; 359 return NULL;
360 } 360 }
361 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { 361 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -401,7 +401,7 @@ copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
401 if (ctx != NULL && ctx->flags == CTX_TEST) 401 if (ctx != NULL && ctx->flags == CTX_TEST)
402 return 1; 402 return 1;
403 if (!ctx || (!ctx->subject_cert && !ctx->subject_req)) { 403 if (!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
404 X509V3err(X509V3_F_COPY_EMAIL, X509V3_R_NO_SUBJECT_DETAILS); 404 X509V3error(X509V3_R_NO_SUBJECT_DETAILS);
405 goto err; 405 goto err;
406 } 406 }
407 /* Find the subject name */ 407 /* Find the subject name */
@@ -422,14 +422,14 @@ copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
422 i--; 422 i--;
423 } 423 }
424 if (!email || !(gen = GENERAL_NAME_new())) { 424 if (!email || !(gen = GENERAL_NAME_new())) {
425 X509V3err(X509V3_F_COPY_EMAIL, ERR_R_MALLOC_FAILURE); 425 X509V3error(ERR_R_MALLOC_FAILURE);
426 goto err; 426 goto err;
427 } 427 }
428 gen->d.ia5 = email; 428 gen->d.ia5 = email;
429 email = NULL; 429 email = NULL;
430 gen->type = GEN_EMAIL; 430 gen->type = GEN_EMAIL;
431 if (!sk_GENERAL_NAME_push(gens, gen)) { 431 if (!sk_GENERAL_NAME_push(gens, gen)) {
432 X509V3err(X509V3_F_COPY_EMAIL, ERR_R_MALLOC_FAILURE); 432 X509V3error(ERR_R_MALLOC_FAILURE);
433 goto err; 433 goto err;
434 } 434 }
435 gen = NULL; 435 gen = NULL;
@@ -453,7 +453,7 @@ v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
453 int i; 453 int i;
454 454
455 if (!(gens = sk_GENERAL_NAME_new_null())) { 455 if (!(gens = sk_GENERAL_NAME_new_null())) {
456 X509V3err(X509V3_F_V2I_GENERAL_NAMES, ERR_R_MALLOC_FAILURE); 456 X509V3error(ERR_R_MALLOC_FAILURE);
457 return NULL; 457 return NULL;
458 } 458 }
459 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { 459 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -487,7 +487,7 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
487 GENERAL_NAME *gen = NULL; 487 GENERAL_NAME *gen = NULL;
488 488
489 if (!value) { 489 if (!value) {
490 X509V3err(X509V3_F_A2I_GENERAL_NAME, X509V3_R_MISSING_VALUE); 490 X509V3error(X509V3_R_MISSING_VALUE);
491 return NULL; 491 return NULL;
492 } 492 }
493 493
@@ -496,8 +496,7 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
496 else { 496 else {
497 gen = GENERAL_NAME_new(); 497 gen = GENERAL_NAME_new();
498 if (gen == NULL) { 498 if (gen == NULL) {
499 X509V3err(X509V3_F_A2I_GENERAL_NAME, 499 X509V3error(ERR_R_MALLOC_FAILURE);
500 ERR_R_MALLOC_FAILURE);
501 return NULL; 500 return NULL;
502 } 501 }
503 } 502 }
@@ -513,8 +512,7 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
513 { 512 {
514 ASN1_OBJECT *obj; 513 ASN1_OBJECT *obj;
515 if (!(obj = OBJ_txt2obj(value, 0))) { 514 if (!(obj = OBJ_txt2obj(value, 0))) {
516 X509V3err(X509V3_F_A2I_GENERAL_NAME, 515 X509V3error(X509V3_R_BAD_OBJECT);
517 X509V3_R_BAD_OBJECT);
518 ERR_asprintf_error_data("value=%s", value); 516 ERR_asprintf_error_data("value=%s", value);
519 goto err; 517 goto err;
520 } 518 }
@@ -528,8 +526,7 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
528 else 526 else
529 gen->d.ip = a2i_IPADDRESS(value); 527 gen->d.ip = a2i_IPADDRESS(value);
530 if (gen->d.ip == NULL) { 528 if (gen->d.ip == NULL) {
531 X509V3err(X509V3_F_A2I_GENERAL_NAME, 529 X509V3error(X509V3_R_BAD_IP_ADDRESS);
532 X509V3_R_BAD_IP_ADDRESS);
533 ERR_asprintf_error_data("value=%s", value); 530 ERR_asprintf_error_data("value=%s", value);
534 goto err; 531 goto err;
535 } 532 }
@@ -537,22 +534,20 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
537 534
538 case GEN_DIRNAME: 535 case GEN_DIRNAME:
539 if (!do_dirname(gen, value, ctx)) { 536 if (!do_dirname(gen, value, ctx)) {
540 X509V3err(X509V3_F_A2I_GENERAL_NAME, 537 X509V3error(X509V3_R_DIRNAME_ERROR);
541 X509V3_R_DIRNAME_ERROR);
542 goto err; 538 goto err;
543 } 539 }
544 break; 540 break;
545 541
546 case GEN_OTHERNAME: 542 case GEN_OTHERNAME:
547 if (!do_othername(gen, value, ctx)) { 543 if (!do_othername(gen, value, ctx)) {
548 X509V3err(X509V3_F_A2I_GENERAL_NAME, 544 X509V3error(X509V3_R_OTHERNAME_ERROR);
549 X509V3_R_OTHERNAME_ERROR);
550 goto err; 545 goto err;
551 } 546 }
552 break; 547 break;
553 548
554 default: 549 default:
555 X509V3err(X509V3_F_A2I_GENERAL_NAME, X509V3_R_UNSUPPORTED_TYPE); 550 X509V3error(X509V3_R_UNSUPPORTED_TYPE);
556 goto err; 551 goto err;
557 } 552 }
558 553
@@ -560,8 +555,7 @@ a2i_GENERAL_NAME(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
560 if (!(gen->d.ia5 = ASN1_IA5STRING_new()) || 555 if (!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
561 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value, 556 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
562 strlen(value))) { 557 strlen(value))) {
563 X509V3err(X509V3_F_A2I_GENERAL_NAME, 558 X509V3error(ERR_R_MALLOC_FAILURE);
564 ERR_R_MALLOC_FAILURE);
565 goto err; 559 goto err;
566 } 560 }
567 } 561 }
@@ -587,7 +581,7 @@ v2i_GENERAL_NAME_ex(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
587 value = cnf->value; 581 value = cnf->value;
588 582
589 if (!value) { 583 if (!value) {
590 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX, X509V3_R_MISSING_VALUE); 584 X509V3error(X509V3_R_MISSING_VALUE);
591 return NULL; 585 return NULL;
592 } 586 }
593 587
@@ -606,8 +600,7 @@ v2i_GENERAL_NAME_ex(GENERAL_NAME *out, const X509V3_EXT_METHOD *method,
606 else if (!name_cmp(name, "otherName")) 600 else if (!name_cmp(name, "otherName"))
607 type = GEN_OTHERNAME; 601 type = GEN_OTHERNAME;
608 else { 602 else {
609 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX, 603 X509V3error(X509V3_R_UNSUPPORTED_OPTION);
610 X509V3_R_UNSUPPORTED_OPTION);
611 ERR_asprintf_error_data("name=%s", name); 604 ERR_asprintf_error_data("name=%s", name);
612 return NULL; 605 return NULL;
613 } 606 }
@@ -655,7 +648,7 @@ do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
655 return 0; 648 return 0;
656 sk = X509V3_get_section(ctx, value); 649 sk = X509V3_get_section(ctx, value);
657 if (!sk) { 650 if (!sk) {
658 X509V3err(X509V3_F_DO_DIRNAME, X509V3_R_SECTION_NOT_FOUND); 651 X509V3error(X509V3_R_SECTION_NOT_FOUND);
659 ERR_asprintf_error_data("section=%s", value); 652 ERR_asprintf_error_data("section=%s", value);
660 X509_NAME_free(nm); 653 X509_NAME_free(nm);
661 return 0; 654 return 0;
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
index 96b42e2e20..6c5823c44e 100644
--- a/src/lib/libcrypto/x509v3/v3_bcons.c
+++ b/src/lib/libcrypto/x509v3/v3_bcons.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_bcons.c,v 1.14 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_bcons.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -159,7 +159,7 @@ v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
159 int i; 159 int i;
160 160
161 if (!(bcons = BASIC_CONSTRAINTS_new())) { 161 if (!(bcons = BASIC_CONSTRAINTS_new())) {
162 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); 162 X509V3error(ERR_R_MALLOC_FAILURE);
163 return NULL; 163 return NULL;
164 } 164 }
165 for (i = 0; i < sk_CONF_VALUE_num(values); i++) { 165 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
@@ -171,8 +171,7 @@ v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
171 if (!X509V3_get_value_int(val, &bcons->pathlen)) 171 if (!X509V3_get_value_int(val, &bcons->pathlen))
172 goto err; 172 goto err;
173 } else { 173 } else {
174 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, 174 X509V3error(X509V3_R_INVALID_NAME);
175 X509V3_R_INVALID_NAME);
176 X509V3_conf_err(val); 175 X509V3_conf_err(val);
177 goto err; 176 goto err;
178 } 177 }
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
index e846fc2ffe..039faf2fd6 100644
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ b/src/lib/libcrypto/x509v3/v3_bitst.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_bitst.c,v 1.13 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_bitst.c,v 1.14 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -145,7 +145,7 @@ v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
145 BIT_STRING_BITNAME *bnam; 145 BIT_STRING_BITNAME *bnam;
146 146
147 if (!(bs = ASN1_BIT_STRING_new())) { 147 if (!(bs = ASN1_BIT_STRING_new())) {
148 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, ERR_R_MALLOC_FAILURE); 148 X509V3error(ERR_R_MALLOC_FAILURE);
149 return NULL; 149 return NULL;
150 } 150 }
151 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { 151 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -155,8 +155,7 @@ v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
155 !strcmp(bnam->lname, val->name) ) { 155 !strcmp(bnam->lname, val->name) ) {
156 if (!ASN1_BIT_STRING_set_bit(bs, 156 if (!ASN1_BIT_STRING_set_bit(bs,
157 bnam->bitnum, 1)) { 157 bnam->bitnum, 1)) {
158 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 158 X509V3error(ERR_R_MALLOC_FAILURE);
159 ERR_R_MALLOC_FAILURE);
160 ASN1_BIT_STRING_free(bs); 159 ASN1_BIT_STRING_free(bs);
161 return NULL; 160 return NULL;
162 } 161 }
@@ -164,8 +163,7 @@ v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
164 } 163 }
165 } 164 }
166 if (!bnam->lname) { 165 if (!bnam->lname) {
167 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 166 X509V3error(X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
168 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
169 X509V3_conf_err(val); 167 X509V3_conf_err(val);
170 ASN1_BIT_STRING_free(bs); 168 ASN1_BIT_STRING_free(bs);
171 return NULL; 169 return NULL;
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
index 6847985913..27e1bc9f57 100644
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_conf.c,v 1.20 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_conf.c,v 1.21 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -93,8 +93,7 @@ X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name, char *value)
93 return v3_generic_extension(name, value, crit, ext_type, ctx); 93 return v3_generic_extension(name, value, crit, ext_type, ctx);
94 ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value); 94 ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
95 if (!ret) { 95 if (!ret) {
96 X509V3err(X509V3_F_X509V3_EXT_NCONF, 96 X509V3error(X509V3_R_ERROR_IN_EXTENSION);
97 X509V3_R_ERROR_IN_EXTENSION);
98 ERR_asprintf_error_data("name=%s, value=%s", name, value); 97 ERR_asprintf_error_data("name=%s, value=%s", name, value);
99 } 98 }
100 return ret; 99 return ret;
@@ -125,12 +124,11 @@ do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value)
125 void *ext_struc; 124 void *ext_struc;
126 125
127 if (ext_nid == NID_undef) { 126 if (ext_nid == NID_undef) {
128 X509V3err(X509V3_F_DO_EXT_NCONF, 127 X509V3error(X509V3_R_UNKNOWN_EXTENSION_NAME);
129 X509V3_R_UNKNOWN_EXTENSION_NAME);
130 return NULL; 128 return NULL;
131 } 129 }
132 if (!(method = X509V3_EXT_get_nid(ext_nid))) { 130 if (!(method = X509V3_EXT_get_nid(ext_nid))) {
133 X509V3err(X509V3_F_DO_EXT_NCONF, X509V3_R_UNKNOWN_EXTENSION); 131 X509V3error(X509V3_R_UNKNOWN_EXTENSION);
134 return NULL; 132 return NULL;
135 } 133 }
136 /* Now get internal extension representation based on type */ 134 /* Now get internal extension representation based on type */
@@ -142,8 +140,7 @@ do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value)
142 else 140 else
143 nval = X509V3_parse_list(value); 141 nval = X509V3_parse_list(value);
144 if (sk_CONF_VALUE_num(nval) <= 0) { 142 if (sk_CONF_VALUE_num(nval) <= 0) {
145 X509V3err(X509V3_F_DO_EXT_NCONF, 143 X509V3error(X509V3_R_INVALID_EXTENSION_STRING);
146 X509V3_R_INVALID_EXTENSION_STRING);
147 ERR_asprintf_error_data("name=%s,section=%s", 144 ERR_asprintf_error_data("name=%s,section=%s",
148 OBJ_nid2sn(ext_nid), value); 145 OBJ_nid2sn(ext_nid), value);
149 if (*value != '@') 146 if (*value != '@')
@@ -157,14 +154,12 @@ do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value)
157 ext_struc = method->s2i(method, ctx, value); 154 ext_struc = method->s2i(method, ctx, value);
158 } else if (method->r2i) { 155 } else if (method->r2i) {
159 if (!ctx->db || !ctx->db_meth) { 156 if (!ctx->db || !ctx->db_meth) {
160 X509V3err(X509V3_F_DO_EXT_NCONF, 157 X509V3error(X509V3_R_NO_CONFIG_DATABASE);
161 X509V3_R_NO_CONFIG_DATABASE);
162 return NULL; 158 return NULL;
163 } 159 }
164 ext_struc = method->r2i(method, ctx, value); 160 ext_struc = method->r2i(method, ctx, value);
165 } else { 161 } else {
166 X509V3err(X509V3_F_DO_EXT_NCONF, 162 X509V3error(X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
167 X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
168 ERR_asprintf_error_data("name=%s", OBJ_nid2sn(ext_nid)); 163 ERR_asprintf_error_data("name=%s", OBJ_nid2sn(ext_nid));
169 return NULL; 164 return NULL;
170 } 165 }
@@ -217,7 +212,7 @@ do_ext_i2d(const X509V3_EXT_METHOD *method, int ext_nid, int crit,
217 212
218merr: 213merr:
219 ASN1_OCTET_STRING_free(ext_oct); 214 ASN1_OCTET_STRING_free(ext_oct);
220 X509V3err(X509V3_F_DO_EXT_I2D, ERR_R_MALLOC_FAILURE); 215 X509V3error(ERR_R_MALLOC_FAILURE);
221 return NULL; 216 return NULL;
222 217
223} 218}
@@ -230,7 +225,7 @@ X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
230 const X509V3_EXT_METHOD *method; 225 const X509V3_EXT_METHOD *method;
231 226
232 if (!(method = X509V3_EXT_get_nid(ext_nid))) { 227 if (!(method = X509V3_EXT_get_nid(ext_nid))) {
233 X509V3err(X509V3_F_X509V3_EXT_I2D, X509V3_R_UNKNOWN_EXTENSION); 228 X509V3error(X509V3_R_UNKNOWN_EXTENSION);
234 return NULL; 229 return NULL;
235 } 230 }
236 return do_ext_i2d(method, ext_nid, crit, ext_struc); 231 return do_ext_i2d(method, ext_nid, crit, ext_struc);
@@ -284,8 +279,7 @@ v3_generic_extension(const char *ext, char *value, int crit, int gen_type,
284 X509_EXTENSION *extension = NULL; 279 X509_EXTENSION *extension = NULL;
285 280
286 if (!(obj = OBJ_txt2obj(ext, 0))) { 281 if (!(obj = OBJ_txt2obj(ext, 0))) {
287 X509V3err(X509V3_F_V3_GENERIC_EXTENSION, 282 X509V3error(X509V3_R_EXTENSION_NAME_ERROR);
288 X509V3_R_EXTENSION_NAME_ERROR);
289 ERR_asprintf_error_data("name=%s", ext); 283 ERR_asprintf_error_data("name=%s", ext);
290 goto err; 284 goto err;
291 } 285 }
@@ -300,14 +294,13 @@ v3_generic_extension(const char *ext, char *value, int crit, int gen_type,
300 } 294 }
301 295
302 if (ext_der == NULL) { 296 if (ext_der == NULL) {
303 X509V3err(X509V3_F_V3_GENERIC_EXTENSION, 297 X509V3error(X509V3_R_EXTENSION_VALUE_ERROR);
304 X509V3_R_EXTENSION_VALUE_ERROR);
305 ERR_asprintf_error_data("value=%s", value); 298 ERR_asprintf_error_data("value=%s", value);
306 goto err; 299 goto err;
307 } 300 }
308 301
309 if (!(oct = ASN1_OCTET_STRING_new())) { 302 if (!(oct = ASN1_OCTET_STRING_new())) {
310 X509V3err(X509V3_F_V3_GENERIC_EXTENSION, ERR_R_MALLOC_FAILURE); 303 X509V3error(ERR_R_MALLOC_FAILURE);
311 goto err; 304 goto err;
312 } 305 }
313 306
@@ -414,8 +407,7 @@ char *
414X509V3_get_string(X509V3_CTX *ctx, char *name, char *section) 407X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
415{ 408{
416 if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string) { 409 if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string) {
417 X509V3err(X509V3_F_X509V3_GET_STRING, 410 X509V3error(X509V3_R_OPERATION_NOT_DEFINED);
418 X509V3_R_OPERATION_NOT_DEFINED);
419 return NULL; 411 return NULL;
420 } 412 }
421 if (ctx->db_meth->get_string) 413 if (ctx->db_meth->get_string)
@@ -427,8 +419,7 @@ STACK_OF(CONF_VALUE) *
427X509V3_get_section(X509V3_CTX *ctx, char *section) 419X509V3_get_section(X509V3_CTX *ctx, char *section)
428{ 420{
429 if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section) { 421 if (!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section) {
430 X509V3err(X509V3_F_X509V3_GET_SECTION, 422 X509V3error(X509V3_R_OPERATION_NOT_DEFINED);
431 X509V3_R_OPERATION_NOT_DEFINED);
432 return NULL; 423 return NULL;
433 } 424 }
434 if (ctx->db_meth->get_section) 425 if (ctx->db_meth->get_section)
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
index 216e91c040..34d3381d76 100644
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_cpols.c,v 1.24 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_cpols.c,v 1.25 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -412,20 +412,19 @@ STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
412 412
413 pols = sk_POLICYINFO_new_null(); 413 pols = sk_POLICYINFO_new_null();
414 if (pols == NULL) { 414 if (pols == NULL) {
415 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE); 415 X509V3error(ERR_R_MALLOC_FAILURE);
416 return NULL; 416 return NULL;
417 } 417 }
418 vals = X509V3_parse_list(value); 418 vals = X509V3_parse_list(value);
419 if (vals == NULL) { 419 if (vals == NULL) {
420 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_X509V3_LIB); 420 X509V3error(ERR_R_X509V3_LIB);
421 goto err; 421 goto err;
422 } 422 }
423 ia5org = 0; 423 ia5org = 0;
424 for (i = 0; i < sk_CONF_VALUE_num(vals); i++) { 424 for (i = 0; i < sk_CONF_VALUE_num(vals); i++) {
425 cnf = sk_CONF_VALUE_value(vals, i); 425 cnf = sk_CONF_VALUE_value(vals, i);
426 if (cnf->value || !cnf->name) { 426 if (cnf->value || !cnf->name) {
427 X509V3err(X509V3_F_R2I_CERTPOL, 427 X509V3error(X509V3_R_INVALID_POLICY_IDENTIFIER);
428 X509V3_R_INVALID_POLICY_IDENTIFIER);
429 X509V3_conf_err(cnf); 428 X509V3_conf_err(cnf);
430 goto err; 429 goto err;
431 } 430 }
@@ -437,8 +436,7 @@ STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
437 STACK_OF(CONF_VALUE) *polsect; 436 STACK_OF(CONF_VALUE) *polsect;
438 polsect = X509V3_get_section(ctx, pstr + 1); 437 polsect = X509V3_get_section(ctx, pstr + 1);
439 if (!polsect) { 438 if (!polsect) {
440 X509V3err(X509V3_F_R2I_CERTPOL, 439 X509V3error(X509V3_R_INVALID_SECTION);
441 X509V3_R_INVALID_SECTION);
442 X509V3_conf_err(cnf); 440 X509V3_conf_err(cnf);
443 goto err; 441 goto err;
444 } 442 }
@@ -448,8 +446,7 @@ STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
448 goto err; 446 goto err;
449 } else { 447 } else {
450 if (!(pobj = OBJ_txt2obj(cnf->name, 0))) { 448 if (!(pobj = OBJ_txt2obj(cnf->name, 0))) {
451 X509V3err(X509V3_F_R2I_CERTPOL, 449 X509V3error(X509V3_R_INVALID_OBJECT_IDENTIFIER);
452 X509V3_R_INVALID_OBJECT_IDENTIFIER);
453 X509V3_conf_err(cnf); 450 X509V3_conf_err(cnf);
454 goto err; 451 goto err;
455 } 452 }
@@ -458,7 +455,7 @@ STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
458 } 455 }
459 if (!sk_POLICYINFO_push(pols, pol)){ 456 if (!sk_POLICYINFO_push(pols, pol)){
460 POLICYINFO_free(pol); 457 POLICYINFO_free(pol);
461 X509V3err(X509V3_F_R2I_CERTPOL, ERR_R_MALLOC_FAILURE); 458 X509V3error(ERR_R_MALLOC_FAILURE);
462 goto err; 459 goto err;
463 } 460 }
464 } 461 }
@@ -487,8 +484,7 @@ policy_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *polstrs, int ia5org)
487 ASN1_OBJECT *pobj; 484 ASN1_OBJECT *pobj;
488 485
489 if ((pobj = OBJ_txt2obj(cnf->value, 0)) == NULL) { 486 if ((pobj = OBJ_txt2obj(cnf->value, 0)) == NULL) {
490 X509V3err(X509V3_F_POLICY_SECTION, 487 X509V3error(X509V3_R_INVALID_OBJECT_IDENTIFIER);
491 X509V3_R_INVALID_OBJECT_IDENTIFIER);
492 X509V3_conf_err(cnf); 488 X509V3_conf_err(cnf);
493 goto err; 489 goto err;
494 } 490 }
@@ -517,15 +513,13 @@ policy_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *polstrs, int ia5org)
517 POLICYQUALINFO *qual; 513 POLICYQUALINFO *qual;
518 514
519 if (*cnf->value != '@') { 515 if (*cnf->value != '@') {
520 X509V3err(X509V3_F_POLICY_SECTION, 516 X509V3error(X509V3_R_EXPECTED_A_SECTION_NAME);
521 X509V3_R_EXPECTED_A_SECTION_NAME);
522 X509V3_conf_err(cnf); 517 X509V3_conf_err(cnf);
523 goto err; 518 goto err;
524 } 519 }
525 unot = X509V3_get_section(ctx, cnf->value + 1); 520 unot = X509V3_get_section(ctx, cnf->value + 1);
526 if (unot == NULL) { 521 if (unot == NULL) {
527 X509V3err(X509V3_F_POLICY_SECTION, 522 X509V3error(X509V3_R_INVALID_SECTION);
528 X509V3_R_INVALID_SECTION);
529 X509V3_conf_err(cnf); 523 X509V3_conf_err(cnf);
530 goto err; 524 goto err;
531 } 525 }
@@ -542,22 +536,20 @@ policy_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *polstrs, int ia5org)
542 if (sk_POLICYQUALINFO_push(pol->qualifiers, qual) == 0) 536 if (sk_POLICYQUALINFO_push(pol->qualifiers, qual) == 0)
543 goto merr; 537 goto merr;
544 } else { 538 } else {
545 X509V3err(X509V3_F_POLICY_SECTION, 539 X509V3error(X509V3_R_INVALID_OPTION);
546 X509V3_R_INVALID_OPTION);
547 X509V3_conf_err(cnf); 540 X509V3_conf_err(cnf);
548 goto err; 541 goto err;
549 } 542 }
550 } 543 }
551 if (pol->policyid == NULL) { 544 if (pol->policyid == NULL) {
552 X509V3err(X509V3_F_POLICY_SECTION, 545 X509V3error(X509V3_R_NO_POLICY_IDENTIFIER);
553 X509V3_R_NO_POLICY_IDENTIFIER);
554 goto err; 546 goto err;
555 } 547 }
556 548
557 return pol; 549 return pol;
558 550
559merr: 551merr:
560 X509V3err(X509V3_F_POLICY_SECTION, ERR_R_MALLOC_FAILURE); 552 X509V3error(ERR_R_MALLOC_FAILURE);
561 553
562err: 554err:
563 POLICYQUALINFO_free(nqual); 555 POLICYQUALINFO_free(nqual);
@@ -616,8 +608,7 @@ notice_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *unot, int ia5org)
616 nref = not->noticeref; 608 nref = not->noticeref;
617 nos = X509V3_parse_list(cnf->value); 609 nos = X509V3_parse_list(cnf->value);
618 if (!nos || !sk_CONF_VALUE_num(nos)) { 610 if (!nos || !sk_CONF_VALUE_num(nos)) {
619 X509V3err(X509V3_F_NOTICE_SECTION, 611 X509V3error(X509V3_R_INVALID_NUMBERS);
620 X509V3_R_INVALID_NUMBERS);
621 X509V3_conf_err(cnf); 612 X509V3_conf_err(cnf);
622 if (nos != NULL) 613 if (nos != NULL)
623 sk_CONF_VALUE_pop_free(nos, 614 sk_CONF_VALUE_pop_free(nos,
@@ -629,8 +620,7 @@ notice_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *unot, int ia5org)
629 if (!ret) 620 if (!ret)
630 goto err; 621 goto err;
631 } else { 622 } else {
632 X509V3err(X509V3_F_NOTICE_SECTION, 623 X509V3error(X509V3_R_INVALID_OPTION);
633 X509V3_R_INVALID_OPTION);
634 X509V3_conf_err(cnf); 624 X509V3_conf_err(cnf);
635 goto err; 625 goto err;
636 } 626 }
@@ -638,15 +628,14 @@ notice_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *unot, int ia5org)
638 628
639 if (not->noticeref && 629 if (not->noticeref &&
640 (!not->noticeref->noticenos || !not->noticeref->organization)) { 630 (!not->noticeref->noticenos || !not->noticeref->organization)) {
641 X509V3err(X509V3_F_NOTICE_SECTION, 631 X509V3error(X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
642 X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
643 goto err; 632 goto err;
644 } 633 }
645 634
646 return qual; 635 return qual;
647 636
648merr: 637merr:
649 X509V3err(X509V3_F_NOTICE_SECTION, ERR_R_MALLOC_FAILURE); 638 X509V3error(ERR_R_MALLOC_FAILURE);
650 639
651err: 640err:
652 POLICYQUALINFO_free(qual); 641 POLICYQUALINFO_free(qual);
@@ -663,7 +652,7 @@ nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
663 for (i = 0; i < sk_CONF_VALUE_num(nos); i++) { 652 for (i = 0; i < sk_CONF_VALUE_num(nos); i++) {
664 cnf = sk_CONF_VALUE_value(nos, i); 653 cnf = sk_CONF_VALUE_value(nos, i);
665 if (!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) { 654 if (!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
666 X509V3err(X509V3_F_NREF_NOS, X509V3_R_INVALID_NUMBER); 655 X509V3error(X509V3_R_INVALID_NUMBER);
667 goto err; 656 goto err;
668 } 657 }
669 if (!sk_ASN1_INTEGER_push(nnums, aint)) 658 if (!sk_ASN1_INTEGER_push(nnums, aint))
@@ -672,7 +661,7 @@ nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
672 return 1; 661 return 1;
673 662
674merr: 663merr:
675 X509V3err(X509V3_F_NREF_NOS, ERR_R_MALLOC_FAILURE); 664 X509V3error(ERR_R_MALLOC_FAILURE);
676 665
677err: 666err:
678 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free); 667 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
index b13bbc3501..f9f69fee14 100644
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ b/src/lib/libcrypto/x509v3/v3_crld.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_crld.c,v 1.20 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_crld.c,v 1.21 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -115,8 +115,7 @@ STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, char *sect)
115 else 115 else
116 gnsect = X509V3_parse_list(sect); 116 gnsect = X509V3_parse_list(sect);
117 if (!gnsect) { 117 if (!gnsect) {
118 X509V3err(X509V3_F_GNAMES_FROM_SECTNAME, 118 X509V3error(X509V3_R_SECTION_NOT_FOUND);
119 X509V3_R_SECTION_NOT_FOUND);
120 return NULL; 119 return NULL;
121 } 120 }
122 gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect); 121 gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect);
@@ -146,8 +145,7 @@ set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, CONF_VALUE *cnf)
146 return -1; 145 return -1;
147 dnsect = X509V3_get_section(ctx, cnf->value); 146 dnsect = X509V3_get_section(ctx, cnf->value);
148 if (!dnsect) { 147 if (!dnsect) {
149 X509V3err(X509V3_F_SET_DIST_POINT_NAME, 148 X509V3error(X509V3_R_SECTION_NOT_FOUND);
150 X509V3_R_SECTION_NOT_FOUND);
151 X509_NAME_free(nm); 149 X509_NAME_free(nm);
152 return -1; 150 return -1;
153 } 151 }
@@ -163,16 +161,14 @@ set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, CONF_VALUE *cnf)
163 */ 161 */
164 if (sk_X509_NAME_ENTRY_value(rnm, 162 if (sk_X509_NAME_ENTRY_value(rnm,
165 sk_X509_NAME_ENTRY_num(rnm) - 1)->set) { 163 sk_X509_NAME_ENTRY_num(rnm) - 1)->set) {
166 X509V3err(X509V3_F_SET_DIST_POINT_NAME, 164 X509V3error(X509V3_R_INVALID_MULTIPLE_RDNS);
167 X509V3_R_INVALID_MULTIPLE_RDNS);
168 goto err; 165 goto err;
169 } 166 }
170 } else 167 } else
171 return 0; 168 return 0;
172 169
173 if (*pdp) { 170 if (*pdp) {
174 X509V3err(X509V3_F_SET_DIST_POINT_NAME, 171 X509V3error(X509V3_R_DISTPOINT_ALREADY_SET);
175 X509V3_R_DISTPOINT_ALREADY_SET);
176 goto err; 172 goto err;
177 } 173 }
178 174
@@ -361,7 +357,7 @@ v2i_crld(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
361 return crld; 357 return crld;
362 358
363merr: 359merr:
364 X509V3err(X509V3_F_V2I_CRLD, ERR_R_MALLOC_FAILURE); 360 X509V3error(ERR_R_MALLOC_FAILURE);
365err: 361err:
366 GENERAL_NAME_free(gen); 362 GENERAL_NAME_free(gen);
367 GENERAL_NAMES_free(gens); 363 GENERAL_NAMES_free(gens);
@@ -692,7 +688,7 @@ v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
692 if (!set_reasons(&idp->onlysomereasons, val)) 688 if (!set_reasons(&idp->onlysomereasons, val))
693 goto err; 689 goto err;
694 } else { 690 } else {
695 X509V3err(X509V3_F_V2I_IDP, X509V3_R_INVALID_NAME); 691 X509V3error(X509V3_R_INVALID_NAME);
696 X509V3_conf_err(cnf); 692 X509V3_conf_err(cnf);
697 goto err; 693 goto err;
698 } 694 }
@@ -700,7 +696,7 @@ v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
700 return idp; 696 return idp;
701 697
702merr: 698merr:
703 X509V3err(X509V3_F_V2I_IDP, ERR_R_MALLOC_FAILURE); 699 X509V3error(ERR_R_MALLOC_FAILURE);
704err: 700err:
705 ISSUING_DIST_POINT_free(idp); 701 ISSUING_DIST_POINT_free(idp);
706 return NULL; 702 return NULL;
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
index 88682f6818..527e80b28e 100644
--- a/src/lib/libcrypto/x509v3/v3_extku.c
+++ b/src/lib/libcrypto/x509v3/v3_extku.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_extku.c,v 1.14 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_extku.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -175,8 +175,7 @@ v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
175 int i; 175 int i;
176 176
177 if (!(extku = sk_ASN1_OBJECT_new_null())) { 177 if (!(extku = sk_ASN1_OBJECT_new_null())) {
178 X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, 178 X509V3error(ERR_R_MALLOC_FAILURE);
179 ERR_R_MALLOC_FAILURE);
180 return NULL; 179 return NULL;
181 } 180 }
182 181
@@ -188,16 +187,14 @@ v2i_EXTENDED_KEY_USAGE(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
188 extval = val->name; 187 extval = val->name;
189 if (!(objtmp = OBJ_txt2obj(extval, 0))) { 188 if (!(objtmp = OBJ_txt2obj(extval, 0))) {
190 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); 189 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
191 X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, 190 X509V3error(X509V3_R_INVALID_OBJECT_IDENTIFIER);
192 X509V3_R_INVALID_OBJECT_IDENTIFIER);
193 X509V3_conf_err(val); 191 X509V3_conf_err(val);
194 return NULL; 192 return NULL;
195 } 193 }
196 if (sk_ASN1_OBJECT_push(extku, objtmp) == 0) { 194 if (sk_ASN1_OBJECT_push(extku, objtmp) == 0) {
197 ASN1_OBJECT_free(objtmp); 195 ASN1_OBJECT_free(objtmp);
198 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); 196 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
199 X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE, 197 X509V3error(ERR_R_MALLOC_FAILURE);
200 ERR_R_MALLOC_FAILURE);
201 return NULL; 198 return NULL;
202 } 199 }
203 } 200 }
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
index 74b6439346..a92041e691 100644
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_ia5.c,v 1.16 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_ia5.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -207,7 +207,7 @@ i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5)
207 if (!ia5 || !ia5->length) 207 if (!ia5 || !ia5->length)
208 return NULL; 208 return NULL;
209 if (!(tmp = malloc(ia5->length + 1))) { 209 if (!(tmp = malloc(ia5->length + 1))) {
210 X509V3err(X509V3_F_I2S_ASN1_IA5STRING, ERR_R_MALLOC_FAILURE); 210 X509V3error(ERR_R_MALLOC_FAILURE);
211 return NULL; 211 return NULL;
212 } 212 }
213 memcpy(tmp, ia5->data, ia5->length); 213 memcpy(tmp, ia5->data, ia5->length);
@@ -220,8 +220,7 @@ s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
220{ 220{
221 ASN1_IA5STRING *ia5; 221 ASN1_IA5STRING *ia5;
222 if (!str) { 222 if (!str) {
223 X509V3err(X509V3_F_S2I_ASN1_IA5STRING, 223 X509V3error(X509V3_R_INVALID_NULL_ARGUMENT);
224 X509V3_R_INVALID_NULL_ARGUMENT);
225 return NULL; 224 return NULL;
226 } 225 }
227 if (!(ia5 = ASN1_IA5STRING_new())) 226 if (!(ia5 = ASN1_IA5STRING_new()))
@@ -234,6 +233,6 @@ s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
234 return ia5; 233 return ia5;
235 234
236err: 235err:
237 X509V3err(X509V3_F_S2I_ASN1_IA5STRING, ERR_R_MALLOC_FAILURE); 236 X509V3error(ERR_R_MALLOC_FAILURE);
238 return NULL; 237 return NULL;
239} 238}
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
index 34ffb1c539..27b5415b2a 100644
--- a/src/lib/libcrypto/x509v3/v3_info.c
+++ b/src/lib/libcrypto/x509v3/v3_info.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_info.c,v 1.24 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_info.c,v 1.25 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -221,8 +221,7 @@ i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
221 nlen = strlen(objtmp) + strlen(vtmp->name) + 5; 221 nlen = strlen(objtmp) + strlen(vtmp->name) + 5;
222 ntmp = malloc(nlen); 222 ntmp = malloc(nlen);
223 if (!ntmp) { 223 if (!ntmp) {
224 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS, 224 X509V3error(ERR_R_MALLOC_FAILURE);
225 ERR_R_MALLOC_FAILURE);
226 return NULL; 225 return NULL;
227 } 226 }
228 strlcpy(ntmp, objtmp, nlen); 227 strlcpy(ntmp, objtmp, nlen);
@@ -248,27 +247,23 @@ v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
248 char *objtmp, *ptmp; 247 char *objtmp, *ptmp;
249 248
250 if (!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) { 249 if (!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) {
251 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 250 X509V3error(ERR_R_MALLOC_FAILURE);
252 ERR_R_MALLOC_FAILURE);
253 return NULL; 251 return NULL;
254 } 252 }
255 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { 253 for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
256 cnf = sk_CONF_VALUE_value(nval, i); 254 cnf = sk_CONF_VALUE_value(nval, i);
257 if ((acc = ACCESS_DESCRIPTION_new()) == NULL) { 255 if ((acc = ACCESS_DESCRIPTION_new()) == NULL) {
258 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 256 X509V3error(ERR_R_MALLOC_FAILURE);
259 ERR_R_MALLOC_FAILURE);
260 goto err; 257 goto err;
261 } 258 }
262 if (sk_ACCESS_DESCRIPTION_push(ainfo, acc) == 0) { 259 if (sk_ACCESS_DESCRIPTION_push(ainfo, acc) == 0) {
263 ACCESS_DESCRIPTION_free(acc); 260 ACCESS_DESCRIPTION_free(acc);
264 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 261 X509V3error(ERR_R_MALLOC_FAILURE);
265 ERR_R_MALLOC_FAILURE);
266 goto err; 262 goto err;
267 } 263 }
268 ptmp = strchr(cnf->name, ';'); 264 ptmp = strchr(cnf->name, ';');
269 if (!ptmp) { 265 if (!ptmp) {
270 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 266 X509V3error(X509V3_R_INVALID_SYNTAX);
271 X509V3_R_INVALID_SYNTAX);
272 goto err; 267 goto err;
273 } 268 }
274 objlen = ptmp - cnf->name; 269 objlen = ptmp - cnf->name;
@@ -277,15 +272,13 @@ v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
277 if (!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0)) 272 if (!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0))
278 goto err; 273 goto err;
279 if (!(objtmp = malloc(objlen + 1))) { 274 if (!(objtmp = malloc(objlen + 1))) {
280 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 275 X509V3error(ERR_R_MALLOC_FAILURE);
281 ERR_R_MALLOC_FAILURE);
282 goto err; 276 goto err;
283 } 277 }
284 strlcpy(objtmp, cnf->name, objlen + 1); 278 strlcpy(objtmp, cnf->name, objlen + 1);
285 acc->method = OBJ_txt2obj(objtmp, 0); 279 acc->method = OBJ_txt2obj(objtmp, 0);
286 if (!acc->method) { 280 if (!acc->method) {
287 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS, 281 X509V3error(X509V3_R_BAD_OBJECT);
288 X509V3_R_BAD_OBJECT);
289 ERR_asprintf_error_data("value=%s", objtmp); 282 ERR_asprintf_error_data("value=%s", objtmp);
290 free(objtmp); 283 free(objtmp);
291 goto err; 284 goto err;
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
index 946ef1d54e..f0cc93bda6 100644
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ b/src/lib/libcrypto/x509v3/v3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_lib.c,v 1.16 2017/01/21 04:42:16 jsing Exp $ */ 1/* $OpenBSD: v3_lib.c,v 1.17 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -75,11 +75,11 @@ int
75X509V3_EXT_add(X509V3_EXT_METHOD *ext) 75X509V3_EXT_add(X509V3_EXT_METHOD *ext)
76{ 76{
77 if (!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) { 77 if (!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_cmp))) {
78 X509V3err(X509V3_F_X509V3_EXT_ADD, ERR_R_MALLOC_FAILURE); 78 X509V3error(ERR_R_MALLOC_FAILURE);
79 return 0; 79 return 0;
80 } 80 }
81 if (!sk_X509V3_EXT_METHOD_push(ext_list, ext)) { 81 if (!sk_X509V3_EXT_METHOD_push(ext_list, ext)) {
82 X509V3err(X509V3_F_X509V3_EXT_ADD, ERR_R_MALLOC_FAILURE); 82 X509V3error(ERR_R_MALLOC_FAILURE);
83 return 0; 83 return 0;
84 } 84 }
85 return 1; 85 return 1;
@@ -157,12 +157,11 @@ X509V3_EXT_add_alias(int nid_to, int nid_from)
157 X509V3_EXT_METHOD *tmpext; 157 X509V3_EXT_METHOD *tmpext;
158 158
159 if (!(ext = X509V3_EXT_get_nid(nid_from))) { 159 if (!(ext = X509V3_EXT_get_nid(nid_from))) {
160 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, 160 X509V3error(X509V3_R_EXTENSION_NOT_FOUND);
161 X509V3_R_EXTENSION_NOT_FOUND);
162 return 0; 161 return 0;
163 } 162 }
164 if (!(tmpext = malloc(sizeof(X509V3_EXT_METHOD)))) { 163 if (!(tmpext = malloc(sizeof(X509V3_EXT_METHOD)))) {
165 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, ERR_R_MALLOC_FAILURE); 164 X509V3error(ERR_R_MALLOC_FAILURE);
166 return 0; 165 return 0;
167 } 166 }
168 *tmpext = *ext; 167 *tmpext = *ext;
@@ -331,8 +330,7 @@ X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
331 ext = X509V3_EXT_i2d(nid, crit, value); 330 ext = X509V3_EXT_i2d(nid, crit, value);
332 331
333 if (!ext) { 332 if (!ext) {
334 X509V3err(X509V3_F_X509V3_ADD1_I2D, 333 X509V3error(X509V3_R_ERROR_CREATING_EXTENSION);
335 X509V3_R_ERROR_CREATING_EXTENSION);
336 return 0; 334 return 0;
337 } 335 }
338 336
@@ -354,6 +352,6 @@ X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
354 352
355err: 353err:
356 if (!(flags & X509V3_ADD_SILENT)) 354 if (!(flags & X509V3_ADD_SILENT))
357 X509V3err(X509V3_F_X509V3_ADD1_I2D, errcode); 355 X509V3error(errcode);
358 return 0; 356 return 0;
359} 357}
diff --git a/src/lib/libcrypto/x509v3/v3_ncons.c b/src/lib/libcrypto/x509v3/v3_ncons.c
index e96d426de6..88643981ca 100644
--- a/src/lib/libcrypto/x509v3/v3_ncons.c
+++ b/src/lib/libcrypto/x509v3/v3_ncons.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_ncons.c,v 1.10 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_ncons.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -204,8 +204,7 @@ v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
204 ptree = &ncons->excludedSubtrees; 204 ptree = &ncons->excludedSubtrees;
205 tval.name = val->name + 9; 205 tval.name = val->name + 9;
206 } else { 206 } else {
207 X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, 207 X509V3error(X509V3_R_INVALID_SYNTAX);
208 X509V3_R_INVALID_SYNTAX);
209 goto err; 208 goto err;
210 } 209 }
211 tval.value = val->value; 210 tval.value = val->value;
@@ -222,7 +221,7 @@ v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
222 return ncons; 221 return ncons;
223 222
224memerr: 223memerr:
225 X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, ERR_R_MALLOC_FAILURE); 224 X509V3error(ERR_R_MALLOC_FAILURE);
226err: 225err:
227 if (ncons) 226 if (ncons)
228 NAME_CONSTRAINTS_free(ncons); 227 NAME_CONSTRAINTS_free(ncons);
diff --git a/src/lib/libcrypto/x509v3/v3_ocsp.c b/src/lib/libcrypto/x509v3/v3_ocsp.c
index 0c8094dcb8..8ebda2e770 100644
--- a/src/lib/libcrypto/x509v3/v3_ocsp.c
+++ b/src/lib/libcrypto/x509v3/v3_ocsp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_ocsp.c,v 1.14 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_ocsp.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -313,7 +313,7 @@ d2i_ocsp_nonce(void *a, const unsigned char **pp, long length)
313err: 313err:
314 if (pos == NULL || *pos != os) 314 if (pos == NULL || *pos != os)
315 ASN1_OCTET_STRING_free(os); 315 ASN1_OCTET_STRING_free(os);
316 OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE); 316 OCSPerror(ERR_R_MALLOC_FAILURE);
317 return NULL; 317 return NULL;
318} 318}
319 319
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c
index d0a1af96ea..dd015452d0 100644
--- a/src/lib/libcrypto/x509v3/v3_pci.c
+++ b/src/lib/libcrypto/x509v3/v3_pci.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_pci.c,v 1.11 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_pci.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */
2/* Contributed to the OpenSSL Project 2004 2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org) 3 * by Richard Levitte (richard@levitte.org)
4 */ 4 */
@@ -90,28 +90,24 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
90 90
91 if (strcmp(val->name, "language") == 0) { 91 if (strcmp(val->name, "language") == 0) {
92 if (*language) { 92 if (*language) {
93 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 93 X509V3error(X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED);
94 X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED);
95 X509V3_conf_err(val); 94 X509V3_conf_err(val);
96 return 0; 95 return 0;
97 } 96 }
98 if (!(*language = OBJ_txt2obj(val->value, 0))) { 97 if (!(*language = OBJ_txt2obj(val->value, 0))) {
99 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 98 X509V3error(X509V3_R_INVALID_OBJECT_IDENTIFIER);
100 X509V3_R_INVALID_OBJECT_IDENTIFIER);
101 X509V3_conf_err(val); 99 X509V3_conf_err(val);
102 return 0; 100 return 0;
103 } 101 }
104 } 102 }
105 else if (strcmp(val->name, "pathlen") == 0) { 103 else if (strcmp(val->name, "pathlen") == 0) {
106 if (*pathlen) { 104 if (*pathlen) {
107 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 105 X509V3error(X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED);
108 X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED);
109 X509V3_conf_err(val); 106 X509V3_conf_err(val);
110 return 0; 107 return 0;
111 } 108 }
112 if (!X509V3_get_value_int(val, pathlen)) { 109 if (!X509V3_get_value_int(val, pathlen)) {
113 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 110 X509V3error(X509V3_R_POLICY_PATH_LENGTH);
114 X509V3_R_POLICY_PATH_LENGTH);
115 X509V3_conf_err(val); 111 X509V3_conf_err(val);
116 return 0; 112 return 0;
117 } 113 }
@@ -122,8 +118,7 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
122 if (!*policy) { 118 if (!*policy) {
123 *policy = ASN1_OCTET_STRING_new(); 119 *policy = ASN1_OCTET_STRING_new();
124 if (!*policy) { 120 if (!*policy) {
125 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 121 X509V3error(ERR_R_MALLOC_FAILURE);
126 ERR_R_MALLOC_FAILURE);
127 X509V3_conf_err(val); 122 X509V3_conf_err(val);
128 return 0; 123 return 0;
129 } 124 }
@@ -134,8 +129,7 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
134 string_to_hex(val->value + 4, &val_len); 129 string_to_hex(val->value + 4, &val_len);
135 130
136 if (!tmp_data2) { 131 if (!tmp_data2) {
137 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 132 X509V3error(X509V3_R_ILLEGAL_HEX_DIGIT);
138 X509V3_R_ILLEGAL_HEX_DIGIT);
139 X509V3_conf_err(val); 133 X509V3_conf_err(val);
140 goto err; 134 goto err;
141 } 135 }
@@ -153,8 +147,7 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
153 free((*policy)->data); 147 free((*policy)->data);
154 (*policy)->data = NULL; 148 (*policy)->data = NULL;
155 (*policy)->length = 0; 149 (*policy)->length = 0;
156 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 150 X509V3error(ERR_R_MALLOC_FAILURE);
157 ERR_R_MALLOC_FAILURE);
158 X509V3_conf_err(val); 151 X509V3_conf_err(val);
159 goto err; 152 goto err;
160 } 153 }
@@ -165,8 +158,7 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
165 int n; 158 int n;
166 BIO *b = BIO_new_file(val->value + 5, "r"); 159 BIO *b = BIO_new_file(val->value + 5, "r");
167 if (!b) { 160 if (!b) {
168 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 161 X509V3error(ERR_R_BIO_LIB);
169 ERR_R_BIO_LIB);
170 X509V3_conf_err(val); 162 X509V3_conf_err(val);
171 goto err; 163 goto err;
172 } 164 }
@@ -190,8 +182,7 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
190 BIO_free_all(b); 182 BIO_free_all(b);
191 183
192 if (n < 0) { 184 if (n < 0) {
193 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 185 X509V3error(ERR_R_BIO_LIB);
194 ERR_R_BIO_LIB);
195 X509V3_conf_err(val); 186 X509V3_conf_err(val);
196 goto err; 187 goto err;
197 } 188 }
@@ -210,20 +201,17 @@ process_pci_value(CONF_VALUE *val, ASN1_OBJECT **language,
210 free((*policy)->data); 201 free((*policy)->data);
211 (*policy)->data = NULL; 202 (*policy)->data = NULL;
212 (*policy)->length = 0; 203 (*policy)->length = 0;
213 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 204 X509V3error(ERR_R_MALLOC_FAILURE);
214 ERR_R_MALLOC_FAILURE);
215 X509V3_conf_err(val); 205 X509V3_conf_err(val);
216 goto err; 206 goto err;
217 } 207 }
218 } else { 208 } else {
219 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 209 X509V3error(X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);
220 X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);
221 X509V3_conf_err(val); 210 X509V3_conf_err(val);
222 goto err; 211 goto err;
223 } 212 }
224 if (!tmp_data) { 213 if (!tmp_data) {
225 X509V3err(X509V3_F_PROCESS_PCI_VALUE, 214 X509V3error(ERR_R_MALLOC_FAILURE);
226 ERR_R_MALLOC_FAILURE);
227 X509V3_conf_err(val); 215 X509V3_conf_err(val);
228 goto err; 216 goto err;
229 } 217 }
@@ -252,8 +240,7 @@ r2i_pci(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value)
252 for (i = 0; i < sk_CONF_VALUE_num(vals); i++) { 240 for (i = 0; i < sk_CONF_VALUE_num(vals); i++) {
253 CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i); 241 CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i);
254 if (!cnf->name || (*cnf->name != '@' && !cnf->value)) { 242 if (!cnf->name || (*cnf->name != '@' && !cnf->value)) {
255 X509V3err(X509V3_F_R2I_PCI, 243 X509V3error(X509V3_R_INVALID_PROXY_POLICY_SETTING);
256 X509V3_R_INVALID_PROXY_POLICY_SETTING);
257 X509V3_conf_err(cnf); 244 X509V3_conf_err(cnf);
258 goto err; 245 goto err;
259 } 246 }
@@ -263,8 +250,7 @@ r2i_pci(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value)
263 250
264 sect = X509V3_get_section(ctx, cnf->name + 1); 251 sect = X509V3_get_section(ctx, cnf->name + 1);
265 if (!sect) { 252 if (!sect) {
266 X509V3err(X509V3_F_R2I_PCI, 253 X509V3error(X509V3_R_INVALID_SECTION);
267 X509V3_R_INVALID_SECTION);
268 X509V3_conf_err(cnf); 254 X509V3_conf_err(cnf);
269 goto err; 255 goto err;
270 } 256 }
@@ -288,20 +274,18 @@ r2i_pci(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value)
288 274
289 /* Language is mandatory */ 275 /* Language is mandatory */
290 if (!language) { 276 if (!language) {
291 X509V3err(X509V3_F_R2I_PCI, 277 X509V3error(X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED);
292 X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED);
293 goto err; 278 goto err;
294 } 279 }
295 i = OBJ_obj2nid(language); 280 i = OBJ_obj2nid(language);
296 if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy) { 281 if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy) {
297 X509V3err(X509V3_F_R2I_PCI, 282 X509V3error(X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY);
298 X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY);
299 goto err; 283 goto err;
300 } 284 }
301 285
302 pci = PROXY_CERT_INFO_EXTENSION_new(); 286 pci = PROXY_CERT_INFO_EXTENSION_new();
303 if (!pci) { 287 if (!pci) {
304 X509V3err(X509V3_F_R2I_PCI, ERR_R_MALLOC_FAILURE); 288 X509V3error(ERR_R_MALLOC_FAILURE);
305 goto err; 289 goto err;
306 } 290 }
307 291
diff --git a/src/lib/libcrypto/x509v3/v3_pcons.c b/src/lib/libcrypto/x509v3/v3_pcons.c
index 144ba88e8d..30487a4d18 100644
--- a/src/lib/libcrypto/x509v3/v3_pcons.c
+++ b/src/lib/libcrypto/x509v3/v3_pcons.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_pcons.c,v 1.10 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_pcons.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -150,8 +150,7 @@ v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
150 int i; 150 int i;
151 151
152 if (!(pcons = POLICY_CONSTRAINTS_new())) { 152 if (!(pcons = POLICY_CONSTRAINTS_new())) {
153 X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, 153 X509V3error(ERR_R_MALLOC_FAILURE);
154 ERR_R_MALLOC_FAILURE);
155 return NULL; 154 return NULL;
156 } 155 }
157 for (i = 0; i < sk_CONF_VALUE_num(values); i++) { 156 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
@@ -163,15 +162,13 @@ v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
163 if (!X509V3_get_value_int(val, 162 if (!X509V3_get_value_int(val,
164 &pcons->inhibitPolicyMapping)) goto err; 163 &pcons->inhibitPolicyMapping)) goto err;
165 } else { 164 } else {
166 X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, 165 X509V3error(X509V3_R_INVALID_NAME);
167 X509V3_R_INVALID_NAME);
168 X509V3_conf_err(val); 166 X509V3_conf_err(val);
169 goto err; 167 goto err;
170 } 168 }
171 } 169 }
172 if (!pcons->inhibitPolicyMapping && !pcons->requireExplicitPolicy) { 170 if (!pcons->inhibitPolicyMapping && !pcons->requireExplicitPolicy) {
173 X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, 171 X509V3error(X509V3_R_ILLEGAL_EMPTY_EXTENSION);
174 X509V3_R_ILLEGAL_EMPTY_EXTENSION);
175 goto err; 172 goto err;
176 } 173 }
177 174
diff --git a/src/lib/libcrypto/x509v3/v3_pmaps.c b/src/lib/libcrypto/x509v3/v3_pmaps.c
index 8c92098006..32ef6be866 100644
--- a/src/lib/libcrypto/x509v3/v3_pmaps.c
+++ b/src/lib/libcrypto/x509v3/v3_pmaps.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_pmaps.c,v 1.10 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_pmaps.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -174,7 +174,7 @@ v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
174 int i, rc; 174 int i, rc;
175 175
176 if (!(pmaps = sk_POLICY_MAPPING_new_null())) { 176 if (!(pmaps = sk_POLICY_MAPPING_new_null())) {
177 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, ERR_R_MALLOC_FAILURE); 177 X509V3error(ERR_R_MALLOC_FAILURE);
178 return NULL; 178 return NULL;
179 } 179 }
180 180
@@ -208,7 +208,7 @@ v2i_POLICY_MAPPINGS(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
208 208
209err: 209err:
210 sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free); 210 sk_POLICY_MAPPING_pop_free(pmaps, POLICY_MAPPING_free);
211 X509V3err(X509V3_F_V2I_POLICY_MAPPINGS, rc); 211 X509V3error(rc);
212 if (rc == X509V3_R_INVALID_OBJECT_IDENTIFIER) 212 if (rc == X509V3_R_INVALID_OBJECT_IDENTIFIER)
213 X509V3_conf_err(val); 213 X509V3_conf_err(val);
214 ASN1_OBJECT_free(obj1); 214 ASN1_OBJECT_free(obj1);
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
index d8ab679304..bdcdf95d12 100644
--- a/src/lib/libcrypto/x509v3/v3_purp.c
+++ b/src/lib/libcrypto/x509v3/v3_purp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_purp.c,v 1.28 2017/01/21 04:42:16 jsing Exp $ */ 1/* $OpenBSD: v3_purp.c,v 1.29 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -138,7 +138,7 @@ int
138X509_PURPOSE_set(int *p, int purpose) 138X509_PURPOSE_set(int *p, int purpose)
139{ 139{
140 if (X509_PURPOSE_get_by_id(purpose) == -1) { 140 if (X509_PURPOSE_get_by_id(purpose) == -1) {
141 X509V3err(X509V3_F_X509_PURPOSE_SET, X509V3_R_INVALID_PURPOSE); 141 X509V3error(X509V3_R_INVALID_PURPOSE);
142 return 0; 142 return 0;
143 } 143 }
144 *p = purpose; 144 *p = purpose;
@@ -206,8 +206,7 @@ X509_PURPOSE_add(int id, int trust, int flags,
206 name_dup = sname_dup = NULL; 206 name_dup = sname_dup = NULL;
207 207
208 if (name == NULL || sname == NULL) { 208 if (name == NULL || sname == NULL) {
209 X509V3err(X509V3_F_X509_PURPOSE_ADD, 209 X509V3error(X509V3_R_INVALID_NULL_ARGUMENT);
210 X509V3_R_INVALID_NULL_ARGUMENT);
211 return 0; 210 return 0;
212 } 211 }
213 212
@@ -220,8 +219,7 @@ X509_PURPOSE_add(int id, int trust, int flags,
220 /* Need a new entry */ 219 /* Need a new entry */
221 if (idx == -1) { 220 if (idx == -1) {
222 if ((ptmp = malloc(sizeof(X509_PURPOSE))) == NULL) { 221 if ((ptmp = malloc(sizeof(X509_PURPOSE))) == NULL) {
223 X509V3err(X509V3_F_X509_PURPOSE_ADD, 222 X509V3error(ERR_R_MALLOC_FAILURE);
224 ERR_R_MALLOC_FAILURE);
225 return 0; 223 return 0;
226 } 224 }
227 ptmp->flags = X509_PURPOSE_DYNAMIC; 225 ptmp->flags = X509_PURPOSE_DYNAMIC;
@@ -266,7 +264,7 @@ err:
266 free(sname_dup); 264 free(sname_dup);
267 if (idx == -1) 265 if (idx == -1)
268 free(ptmp); 266 free(ptmp);
269 X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); 267 X509V3error(ERR_R_MALLOC_FAILURE);
270 return 0; 268 return 0;
271} 269}
272 270
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
index fbd66bb721..9dc1741788 100644
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ b/src/lib/libcrypto/x509v3/v3_skey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_skey.c,v 1.14 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_skey.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -95,7 +95,7 @@ s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
95 long length; 95 long length;
96 96
97 if (!(oct = ASN1_OCTET_STRING_new())) { 97 if (!(oct = ASN1_OCTET_STRING_new())) {
98 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE); 98 X509V3error(ERR_R_MALLOC_FAILURE);
99 return NULL; 99 return NULL;
100 } 100 }
101 101
@@ -121,7 +121,7 @@ s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
121 return s2i_ASN1_OCTET_STRING(method, ctx, str); 121 return s2i_ASN1_OCTET_STRING(method, ctx, str);
122 122
123 if (!(oct = ASN1_OCTET_STRING_new())) { 123 if (!(oct = ASN1_OCTET_STRING_new())) {
124 X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE); 124 X509V3error(ERR_R_MALLOC_FAILURE);
125 return NULL; 125 return NULL;
126 } 126 }
127 127
@@ -129,7 +129,7 @@ s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
129 return oct; 129 return oct;
130 130
131 if (!ctx || (!ctx->subject_req && !ctx->subject_cert)) { 131 if (!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
132 X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY); 132 X509V3error(X509V3_R_NO_PUBLIC_KEY);
133 goto err; 133 goto err;
134 } 134 }
135 135
@@ -139,7 +139,7 @@ s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
139 pk = ctx->subject_cert->cert_info->key->public_key; 139 pk = ctx->subject_cert->cert_info->key->public_key;
140 140
141 if (!pk) { 141 if (!pk) {
142 X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY); 142 X509V3error(X509V3_R_NO_PUBLIC_KEY);
143 goto err; 143 goto err;
144 } 144 }
145 145
@@ -148,7 +148,7 @@ s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
148 goto err; 148 goto err;
149 149
150 if (!ASN1_STRING_set(oct, pkey_dig, diglen)) { 150 if (!ASN1_STRING_set(oct, pkey_dig, diglen)) {
151 X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE); 151 X509V3error(ERR_R_MALLOC_FAILURE);
152 goto err; 152 goto err;
153 } 153 }
154 154
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
index bb88da4b49..14c6e5c0a4 100644
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_sxnet.c,v 1.18 2016/12/30 15:54:49 jsing Exp $ */ 1/* $OpenBSD: v3_sxnet.c,v 1.19 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -258,8 +258,7 @@ SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen)
258 ASN1_INTEGER *izone = NULL; 258 ASN1_INTEGER *izone = NULL;
259 259
260 if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { 260 if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
261 X509V3err(X509V3_F_SXNET_ADD_ID_ASC, 261 X509V3error(X509V3_R_ERROR_CONVERTING_ZONE);
262 X509V3_R_ERROR_CONVERTING_ZONE);
263 return 0; 262 return 0;
264 } 263 }
265 return SXNET_add_id_INTEGER(psx, izone, user, userlen); 264 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
@@ -274,7 +273,7 @@ SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen)
274 273
275 if (!(izone = ASN1_INTEGER_new()) || 274 if (!(izone = ASN1_INTEGER_new()) ||
276 !ASN1_INTEGER_set(izone, lzone)) { 275 !ASN1_INTEGER_set(izone, lzone)) {
277 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE); 276 X509V3error(ERR_R_MALLOC_FAILURE);
278 ASN1_INTEGER_free(izone); 277 ASN1_INTEGER_free(izone);
279 return 0; 278 return 0;
280 } 279 }
@@ -293,15 +292,13 @@ SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, int userlen)
293 SXNETID *id = NULL; 292 SXNETID *id = NULL;
294 293
295 if (!psx || !zone || !user) { 294 if (!psx || !zone || !user) {
296 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, 295 X509V3error(X509V3_R_INVALID_NULL_ARGUMENT);
297 X509V3_R_INVALID_NULL_ARGUMENT);
298 return 0; 296 return 0;
299 } 297 }
300 if (userlen == -1) 298 if (userlen == -1)
301 userlen = strlen(user); 299 userlen = strlen(user);
302 if (userlen > 64) { 300 if (userlen > 64) {
303 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, 301 X509V3error(X509V3_R_USER_TOO_LONG);
304 X509V3_R_USER_TOO_LONG);
305 return 0; 302 return 0;
306 } 303 }
307 if (!*psx) { 304 if (!*psx) {
@@ -313,8 +310,7 @@ SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, int userlen)
313 } else 310 } else
314 sx = *psx; 311 sx = *psx;
315 if (SXNET_get_id_INTEGER(sx, zone)) { 312 if (SXNET_get_id_INTEGER(sx, zone)) {
316 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, 313 X509V3error(X509V3_R_DUPLICATE_ZONE_ID);
317 X509V3_R_DUPLICATE_ZONE_ID);
318 return 0; 314 return 0;
319 } 315 }
320 316
@@ -331,7 +327,7 @@ SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, int userlen)
331 return 1; 327 return 1;
332 328
333err: 329err:
334 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, ERR_R_MALLOC_FAILURE); 330 X509V3error(ERR_R_MALLOC_FAILURE);
335 SXNETID_free(id); 331 SXNETID_free(id);
336 SXNET_free(sx); 332 SXNET_free(sx);
337 *psx = NULL; 333 *psx = NULL;
@@ -345,8 +341,7 @@ SXNET_get_id_asc(SXNET *sx, char *zone)
345 ASN1_OCTET_STRING *oct; 341 ASN1_OCTET_STRING *oct;
346 342
347 if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { 343 if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
348 X509V3err(X509V3_F_SXNET_GET_ID_ASC, 344 X509V3error(X509V3_R_ERROR_CONVERTING_ZONE);
349 X509V3_R_ERROR_CONVERTING_ZONE);
350 return NULL; 345 return NULL;
351 } 346 }
352 oct = SXNET_get_id_INTEGER(sx, izone); 347 oct = SXNET_get_id_INTEGER(sx, izone);
@@ -362,7 +357,7 @@ SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
362 357
363 if (!(izone = ASN1_INTEGER_new()) || 358 if (!(izone = ASN1_INTEGER_new()) ||
364 !ASN1_INTEGER_set(izone, lzone)) { 359 !ASN1_INTEGER_set(izone, lzone)) {
365 X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE); 360 X509V3error(ERR_R_MALLOC_FAILURE);
366 ASN1_INTEGER_free(izone); 361 ASN1_INTEGER_free(izone);
367 return NULL; 362 return NULL;
368 } 363 }
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index 7516cd3c20..04c789922b 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: v3_utl.c,v 1.25 2016/09/03 11:56:33 beck Exp $ */ 1/* $OpenBSD: v3_utl.c,v 1.26 2017/01/29 17:49:23 beck Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -103,7 +103,7 @@ X509V3_add_value(const char *name, const char *value,
103 return 1; 103 return 1;
104 104
105err: 105err:
106 X509V3err(X509V3_F_X509V3_ADD_VALUE, ERR_R_MALLOC_FAILURE); 106 X509V3error(ERR_R_MALLOC_FAILURE);
107 free(vtmp); 107 free(vtmp);
108 free(tname); 108 free(tname);
109 free(tvalue); 109 free(tvalue);
@@ -159,7 +159,7 @@ i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
159 return NULL; 159 return NULL;
160 if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) || 160 if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
161 !(strtmp = BN_bn2dec(bntmp))) 161 !(strtmp = BN_bn2dec(bntmp)))
162 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); 162 X509V3error(ERR_R_MALLOC_FAILURE);
163 BN_free(bntmp); 163 BN_free(bntmp);
164 return strtmp; 164 return strtmp;
165} 165}
@@ -174,7 +174,7 @@ i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
174 return NULL; 174 return NULL;
175 if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) || 175 if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
176 !(strtmp = BN_bn2dec(bntmp))) 176 !(strtmp = BN_bn2dec(bntmp)))
177 X509V3err(X509V3_F_I2S_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); 177 X509V3error(ERR_R_MALLOC_FAILURE);
178 BN_free(bntmp); 178 BN_free(bntmp);
179 return strtmp; 179 return strtmp;
180} 180}
@@ -188,8 +188,7 @@ s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
188 int ret; 188 int ret;
189 189
190 if (!value) { 190 if (!value) {
191 X509V3err(X509V3_F_S2I_ASN1_INTEGER, 191 X509V3error(X509V3_R_INVALID_NULL_VALUE);
192 X509V3_R_INVALID_NULL_VALUE);
193 return 0; 192 return 0;
194 } 193 }
195 bn = BN_new(); 194 bn = BN_new();
@@ -212,7 +211,7 @@ s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
212 211
213 if (!ret || value[ret]) { 212 if (!ret || value[ret]) {
214 BN_free(bn); 213 BN_free(bn);
215 X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_BN_DEC2BN_ERROR); 214 X509V3error(X509V3_R_BN_DEC2BN_ERROR);
216 return 0; 215 return 0;
217 } 216 }
218 217
@@ -222,8 +221,7 @@ s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
222 aint = BN_to_ASN1_INTEGER(bn, NULL); 221 aint = BN_to_ASN1_INTEGER(bn, NULL);
223 BN_free(bn); 222 BN_free(bn);
224 if (!aint) { 223 if (!aint) {
225 X509V3err(X509V3_F_S2I_ASN1_INTEGER, 224 X509V3error(X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
226 X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
227 return 0; 225 return 0;
228 } 226 }
229 if (isneg) 227 if (isneg)
@@ -267,8 +265,7 @@ X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
267 } 265 }
268 266
269err: 267err:
270 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL, 268 X509V3error(X509V3_R_INVALID_BOOLEAN_STRING);
271 X509V3_R_INVALID_BOOLEAN_STRING);
272 X509V3_conf_err(value); 269 X509V3_conf_err(value);
273 return 0; 270 return 0;
274} 271}
@@ -302,7 +299,7 @@ X509V3_parse_list(const char *line)
302 299
303 /* We are going to modify the line so copy it first */ 300 /* We are going to modify the line so copy it first */
304 if ((linebuf = strdup(line)) == NULL) { 301 if ((linebuf = strdup(line)) == NULL) {
305 X509V3err(X509V3_F_X509V3_PARSE_LIST, ERR_R_MALLOC_FAILURE); 302 X509V3error(ERR_R_MALLOC_FAILURE);
306 goto err; 303 goto err;
307 } 304 }
308 state = HDR_NAME; 305 state = HDR_NAME;
@@ -319,8 +316,7 @@ X509V3_parse_list(const char *line)
319 *p = 0; 316 *p = 0;
320 ntmp = strip_spaces(q); 317 ntmp = strip_spaces(q);
321 if (!ntmp) { 318 if (!ntmp) {
322 X509V3err(X509V3_F_X509V3_PARSE_LIST, 319 X509V3error(X509V3_R_INVALID_NULL_NAME);
323 X509V3_R_INVALID_NULL_NAME);
324 goto err; 320 goto err;
325 } 321 }
326 q = p + 1; 322 q = p + 1;
@@ -329,8 +325,7 @@ X509V3_parse_list(const char *line)
329 ntmp = strip_spaces(q); 325 ntmp = strip_spaces(q);
330 q = p + 1; 326 q = p + 1;
331 if (!ntmp) { 327 if (!ntmp) {
332 X509V3err(X509V3_F_X509V3_PARSE_LIST, 328 X509V3error(X509V3_R_INVALID_NULL_NAME);
333 X509V3_R_INVALID_NULL_NAME);
334 goto err; 329 goto err;
335 } 330 }
336 X509V3_add_value(ntmp, NULL, &values); 331 X509V3_add_value(ntmp, NULL, &values);
@@ -343,8 +338,7 @@ X509V3_parse_list(const char *line)
343 *p = 0; 338 *p = 0;
344 vtmp = strip_spaces(q); 339 vtmp = strip_spaces(q);
345 if (!vtmp) { 340 if (!vtmp) {
346 X509V3err(X509V3_F_X509V3_PARSE_LIST, 341 X509V3error(X509V3_R_INVALID_NULL_VALUE);
347 X509V3_R_INVALID_NULL_VALUE);
348 goto err; 342 goto err;
349 } 343 }
350 X509V3_add_value(ntmp, vtmp, &values); 344 X509V3_add_value(ntmp, vtmp, &values);
@@ -358,16 +352,14 @@ X509V3_parse_list(const char *line)
358 if (state == HDR_VALUE) { 352 if (state == HDR_VALUE) {
359 vtmp = strip_spaces(q); 353 vtmp = strip_spaces(q);
360 if (!vtmp) { 354 if (!vtmp) {
361 X509V3err(X509V3_F_X509V3_PARSE_LIST, 355 X509V3error(X509V3_R_INVALID_NULL_VALUE);
362 X509V3_R_INVALID_NULL_VALUE);
363 goto err; 356 goto err;
364 } 357 }
365 X509V3_add_value(ntmp, vtmp, &values); 358 X509V3_add_value(ntmp, vtmp, &values);
366 } else { 359 } else {
367 ntmp = strip_spaces(q); 360 ntmp = strip_spaces(q);
368 if (!ntmp) { 361 if (!ntmp) {
369 X509V3err(X509V3_F_X509V3_PARSE_LIST, 362 X509V3error(X509V3_R_INVALID_NULL_NAME);
370 X509V3_R_INVALID_NULL_NAME);
371 goto err; 363 goto err;
372 } 364 }
373 X509V3_add_value(ntmp, NULL, &values); 365 X509V3_add_value(ntmp, NULL, &values);
@@ -420,7 +412,7 @@ hex_to_string(const unsigned char *buffer, long len)
420 if (!buffer || !len) 412 if (!buffer || !len)
421 return NULL; 413 return NULL;
422 if (!(tmp = malloc(len * 3 + 1))) { 414 if (!(tmp = malloc(len * 3 + 1))) {
423 X509V3err(X509V3_F_HEX_TO_STRING, ERR_R_MALLOC_FAILURE); 415 X509V3error(ERR_R_MALLOC_FAILURE);
424 return NULL; 416 return NULL;
425 } 417 }
426 q = tmp; 418 q = tmp;
@@ -443,8 +435,7 @@ string_to_hex(const char *str, long *len)
443 unsigned char *hexbuf, *q; 435 unsigned char *hexbuf, *q;
444 unsigned char ch, cl, *p; 436 unsigned char ch, cl, *p;
445 if (!str) { 437 if (!str) {
446 X509V3err(X509V3_F_STRING_TO_HEX, 438 X509V3error(X509V3_R_INVALID_NULL_ARGUMENT);
447 X509V3_R_INVALID_NULL_ARGUMENT);
448 return NULL; 439 return NULL;
449 } 440 }
450 if (!(hexbuf = malloc(strlen(str) >> 1))) 441 if (!(hexbuf = malloc(strlen(str) >> 1)))
@@ -455,8 +446,7 @@ string_to_hex(const char *str, long *len)
455 continue; 446 continue;
456 cl = *p++; 447 cl = *p++;
457 if (!cl) { 448 if (!cl) {
458 X509V3err(X509V3_F_STRING_TO_HEX, 449 X509V3error(X509V3_R_ODD_NUMBER_OF_DIGITS);
459 X509V3_R_ODD_NUMBER_OF_DIGITS);
460 free(hexbuf); 450 free(hexbuf);
461 return NULL; 451 return NULL;
462 } 452 }
@@ -487,12 +477,12 @@ string_to_hex(const char *str, long *len)
487 477
488err: 478err:
489 free(hexbuf); 479 free(hexbuf);
490 X509V3err(X509V3_F_STRING_TO_HEX, ERR_R_MALLOC_FAILURE); 480 X509V3error(ERR_R_MALLOC_FAILURE);
491 return NULL; 481 return NULL;
492 482
493badhex: 483badhex:
494 free(hexbuf); 484 free(hexbuf);
495 X509V3err(X509V3_F_STRING_TO_HEX, X509V3_R_ILLEGAL_HEX_DIGIT); 485 X509V3error(X509V3_R_ILLEGAL_HEX_DIGIT);
496 return NULL; 486 return NULL;
497} 487}
498 488
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c
index 46c08a1798..ababa8cf17 100644
--- a/src/lib/libssl/bio_ssl.c
+++ b/src/lib/libssl/bio_ssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_ssl.c,v 1.25 2017/01/26 12:44:52 beck Exp $ */ 1/* $OpenBSD: bio_ssl.c,v 1.26 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -110,7 +110,7 @@ ssl_new(BIO *bi)
110 110
111 bs = calloc(1, sizeof(BIO_SSL)); 111 bs = calloc(1, sizeof(BIO_SSL));
112 if (bs == NULL) { 112 if (bs == NULL) {
113 BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE); 113 SSLerror(ERR_R_MALLOC_FAILURE);
114 return (0); 114 return (0);
115 } 115 }
116 bi->init = 0; 116 bi->init = 0;
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
index e608bcfea4..73683d4099 100644
--- a/src/lib/libssl/ssl_cert.c
+++ b/src/lib/libssl/ssl_cert.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_cert.c,v 1.62 2017/01/26 12:16:13 beck Exp $ */ 1/* $OpenBSD: ssl_cert.c,v 1.63 2017/01/29 17:49:23 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -709,7 +709,7 @@ SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *dir)
709 (void) closedir(dirp); 709 (void) closedir(dirp);
710 } 710 }
711 if (!ret) { 711 if (!ret) {
712 SYSerr(SYS_F_OPENDIR, errno); 712 SYSerror(errno);
713 ERR_asprintf_error_data("opendir ('%s')", dir); 713 ERR_asprintf_error_data("opendir ('%s')", dir);
714 SSLerror(ERR_R_SYS_LIB); 714 SSLerror(ERR_R_SYS_LIB);
715 } 715 }