From 4c4004fa5061f2821e4e129b8802bf8fe343f321 Mon Sep 17 00:00:00 2001 From: Hakase Date: Sun, 24 Jun 2018 20:52:36 +0900 Subject: [PATCH] Update 1.1.1-pre8 --- CHANGES | 22 ++++++++ Configurations/10-main.conf | 13 +++-- Configurations/unix-Makefile.tmpl | 44 ++++++++++++---- Configure | 18 ++++--- apps/ca.c | 6 +-- crypto/bn/bn_lcl.h | 8 --- crypto/bn/bn_prime.c | 28 +++++----- crypto/cms/cms_lcl.h | 7 --- crypto/ct/ct_log.c | 2 +- crypto/ec/curve25519.c | 2 +- crypto/ec/ec_lcl.h | 8 +-- crypto/ec/ec_lib.c | 60 ++++++++++++++++++++-- crypto/ec/ecdsa_ossl.c | 44 ++++------------ crypto/ec/ecp_nistp224.c | 2 +- crypto/ec/ecp_nistp256.c | 2 +- crypto/ec/ecp_nistp521.c | 2 +- crypto/ec/ecp_nistz256.c | 2 +- crypto/engine/eng_int.h | 8 --- crypto/hmac/hmac_lcl.h | 11 ---- crypto/include/internal/aria.h | 8 --- crypto/include/internal/bn_int.h | 8 --- crypto/include/internal/chacha.h | 7 --- crypto/include/internal/sm2.h | 8 --- crypto/include/internal/sm2err.h | 3 -- crypto/include/internal/store_int.h | 7 --- crypto/seed/seed_locl.h | 8 --- crypto/sha/asm/sha256-armv4.pl | 2 +- crypto/sha/asm/sha512-armv4.pl | 4 +- crypto/x509v3/v3_admis.h | 7 --- doc/man3/ASN1_INTEGER_get_int64.pod | 4 +- doc/man3/OCSP_resp_find_status.pod | 30 ++++++++++- doc/openssl-c-indent.el | 1 + e_os.h | 8 --- engines/e_afalg.c | 74 +++++++++++++++------------ engines/e_padlock.c | 4 +- include/internal/conf.h | 9 ---- include/internal/constant_time_locl.h | 8 --- include/internal/cryptlib.h | 8 --- include/internal/dso.h | 7 --- include/internal/dsoerr.h | 3 -- include/internal/o_dir.h | 8 --- ssl/packet_locl.h | 8 --- test/bntest.c | 50 +++++++++++++----- test/ectest.c | 2 +- test/recipes/90-test_shlibload.t | 1 + test/sm2_internal_test.c | 2 +- test/testutil/driver.c | 4 +- util/shlib_wrap.sh.in | 4 +- 48 files changed, 288 insertions(+), 298 deletions(-) diff --git a/CHANGES b/CHANGES index 4dc06592..4cdcf52f 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,28 @@ release branch. Changes between 1.1.0h and 1.1.1 [xx XXX xxxx] + + *) Numerous side-channel attack mitigations have been applied. This may have + performance impacts for some algorithms for the benefit of improved + security. Specific changes are noted in this change log by their respective + authors. + [Matt Caswell] + + *) AIX shared library support overhaul. Switch to AIX "natural" way of + handling shared libraries, which means collecting shared objects of + different versions and bitnesses in one common archive. This allows to + mitigate conflict between 1.0 and 1.1 side-by-side installations. It + doesn't affect the way 3rd party applications are linked, only how + multi-version installation is managed. + [Andy Polyakov] + + *) Make ec_group_do_inverse_ord() more robust and available to other + EC cryptosystems, so that irrespective of BN_FLG_CONSTTIME, SCA + mitigations are applied to the fallback BN_mod_inverse(). + When using this function rather than BN_mod_inverse() directly, new + EC cryptosystem implementations are then safer-by-default. + [Billy Bob Brumley] + *) Add coordinate blinding for EC_POINT and implement projective coordinate blinding for generic prime curves as a countermeasure to chosen point SCA attacks. diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index a62abe29..62b4c9d1 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -1110,14 +1110,17 @@ my %targets = ( template => 1, sys_id => "AIX", lib_cppflags => "-DB_ENDIAN", + lflags => "-Wl,-bsvr4", thread_scheme => "pthreads", dso_scheme => "dlfcn", shared_target => "self", - shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)", - bin_lflags => shared("-Wl,-bsvr4"), - module_ldflags => "-Wl,-G,-bsymbolic,-bexpall,-bnolibpath", - shared_ldflag => "-Wl,-G,-bsymbolic,-bnolibpath", + module_ldflags => "-Wl,-G,-bsymbolic,-bexpall", + shared_ldflag => "-Wl,-G,-bsymbolic", shared_defflag => "-Wl,-bE:", + shared_extension => ".so.\$(SHLIB_VERSION_NUMBER)", + dso_extension => ".so", + lib_extension => shared("_a.a"), + shared_extension_simple => shared(".a"), }, "aix-gcc" => { inherit_from => [ "aix-common", asm("ppc32_asm") ], @@ -1142,6 +1145,7 @@ my %targets = ( bn_ops => "SIXTY_FOUR_BIT_LONG RC4_CHAR", perlasm_scheme => "aix64", shared_ldflag => add_before("-shared -static-libgcc"), + shared_extension => "64.so.\$(SHLIB_VERSION_NUMBER)", AR => add("-X64"), RANLIB => add("-X64"), }, @@ -1173,6 +1177,7 @@ my %targets = ( perlasm_scheme => "aix64", dso_scheme => "dlfcn", shared_cflag => "-qpic", + shared_extension => "64.so.\$(SHLIB_VERSION_NUMBER)", AR => add("-X64"), RANLIB => add("-X64"), }, diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 42da98dd..8d33e843 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -16,6 +16,10 @@ sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ } + # Shared AIX support is special. We put libcrypto[64].so.ver into + # libcrypto.a and use libcrypto_a.a as static one. + sub sharedaix { !$disabled{shared} && $config{target} =~ /^aix/ } + our $sover_dirname = $config{shlib_version_number}; $sover_dirname =~ s|\.|_|g if $config{target} =~ /^mingw/; @@ -506,7 +510,7 @@ install_dev: s2=`echo "$$s" | cut -f2 -d";"`; \ fn1=`basename $$s1`; \ fn2=`basename $$s2`; \ - : {- output_off() if windowsdll(); "" -}; \ + : {- output_off(); output_on() unless windowsdll() or sharedaix(); "" -}; \ $(ECHO) "install $$s1 -> $(DESTDIR)$(libdir)/$$fn1"; \ cp $$s1 $(DESTDIR)$(libdir)/$$fn1.new; \ chmod 755 $(DESTDIR)$(libdir)/$$fn1.new; \ @@ -516,13 +520,28 @@ install_dev: $(ECHO) "link $(DESTDIR)$(libdir)/$$fn2 -> $(DESTDIR)$(libdir)/$$fn1"; \ ln -sf $$fn1 $(DESTDIR)$(libdir)/$$fn2; \ fi; \ - : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \ + : {- output_off() unless windowsdll() or sharedaix(); output_on() if windowsdll(); "" -}; \ $(ECHO) "install $$s2 -> $(DESTDIR)$(libdir)/$$fn2"; \ cp $$s2 $(DESTDIR)$(libdir)/$$fn2.new; \ chmod 755 $(DESTDIR)$(libdir)/$$fn2.new; \ mv -f $(DESTDIR)$(libdir)/$$fn2.new \ $(DESTDIR)$(libdir)/$$fn2; \ - : {- output_on() unless windowsdll(); "" -}; \ + : {- output_off() if windowsdll(); output_on() if sharedaix(); "" -}; \ + a=$(DESTDIR)$(libdir)/$$fn2; \ + $(ECHO) "install $$s1 -> $$a"; \ + if [ -f $$a ]; then ( trap "rm -rf /tmp/ar.$$$$" INT 0; \ + mkdir /tmp/ar.$$$$; ( cd /tmp/ar.$$$$; \ + cp -f $$a $$a.new; \ + for so in `$(AR) t $$a`; do \ + $(AR) x $$a $$so; \ + chmod u+w $$so; \ + strip -X32_64 -e $$so; \ + $(AR) r $$a.new $$so; \ + done; \ + )); fi; \ + $(AR) r $$a.new $$s1; \ + mv -f $$a.new $$a; \ + : {- output_off() if sharedaix(); output_on(); "" -}; \ done @ : {- output_on() if $disabled{shared}; "" -} @$(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(libdir)/pkgconfig @@ -562,11 +581,11 @@ uninstall_dev: fn1=`basename $$s1`; \ fn2=`basename $$s2`; \ : {- output_off() if windowsdll(); "" -}; \ - $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn1"; \ - $(RM) $(DESTDIR)$(libdir)/$$fn1; \ - if [ "$$fn1" != "$$fn2" ]; then \ - $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \ - $(RM) $(DESTDIR)$(libdir)/$$fn2; \ + $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \ + $(RM) $(DESTDIR)$(libdir)/$$fn2; \ + if [ "$$fn1" != "$$fn2" -a -f "$(DESTDIR)$(libdir)/$$fn1" ]; then \ + $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn1"; \ + $(RM) $(DESTDIR)$(libdir)/$$fn1; \ fi; \ : {- output_on() if windowsdll(); "" -}{- output_off() unless windowsdll(); "" -}; \ $(ECHO) "$(RM) $(DESTDIR)$(libdir)/$$fn2"; \ @@ -1104,6 +1123,11 @@ EOF cp -p $shlib'\$(SHLIB_EXT)' apps/ cp -p $shlib'\$(SHLIB_EXT)' test/ cp -p $shlib'\$(SHLIB_EXT)' fuzz/ +EOF + } elsif (sharedaix()) { + $recipe .= <<"EOF"; + rm -f $target && \\ + \$(AR) r $target $target_full EOF } else { $recipe .= <<"EOF"; @@ -1168,8 +1192,8 @@ EOF push @linkdirs, $d unless grep { $d eq $_ } @linkdirs; } my $linkflags = join("", map { "-L$_ " } @linkdirs); - my $linklibs = join("", map { if ($_ =~ /\.a$/) { - " $_"; + my $linklibs = join("", map { if ($_ =~ s/\.a$//) { + " $_$libext"; } else { my $f = basename($_); (my $l = $f) =~ s/^lib//; diff --git a/Configure b/Configure index bcf2c041..05b798bc 100755 --- a/Configure +++ b/Configure @@ -125,6 +125,7 @@ my $gcc_devteam_warn = "-DDEBUG_UNUSED" . " -Wswitch" . " -Wsign-compare" . " -Wmissing-prototypes" + . " -Wstrict-prototypes" . " -Wshadow" . " -Wformat" . " -Wtype-limits" @@ -822,11 +823,7 @@ while (@argvcopy) { read_config $1; } - elsif (/^-L(.*)$/) - { - push @{$useradd{LDFLAGS}}, $_; - } - elsif (/^-l(.*)$/ or /^-Wl,/) + elsif (/^-l(.*)$/) { push @{$useradd{LDLIBS}}, $_; } @@ -834,6 +831,10 @@ while (@argvcopy) { push @{$useradd{LDLIBS}}, $_, shift(@argvcopy); } + elsif (/^-L(.*)$/ or /^-Wl,/) + { + push @{$useradd{LDFLAGS}}, $_; + } elsif (/^-rpath$/ or /^-R$/) # -rpath is the OSF1 rpath flag # -R is the old Solaris rpath flag @@ -953,7 +954,7 @@ foreach (keys %user) { } } -if (grep { $_ =~ /(^|\s)-Wl,-rpath,/ } ($user{LDLIBS} ? @{$user{LDLIBS}} : ()) +if (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ()) && !$disabled{shared} && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) { die "***** Cannot simultaneously use -rpath, shared libraries, and\n", @@ -1110,8 +1111,9 @@ $target{exe_extension}=".exe" if ($config{target} eq "DJGPP" $target{exe_extension}=".pm" if ($config{target} =~ /vos/); ($target{shared_extension_simple}=$target{shared_extension}) - =~ s|\.\$\(SHLIB_VERSION_NUMBER\)||; -$target{dso_extension}=$target{shared_extension_simple}; + =~ s|\.\$\(SHLIB_VERSION_NUMBER\)|| + unless defined($target{shared_extension_simple}); +$target{dso_extension}//=$target{shared_extension_simple}; ($target{shared_import_extension}=$target{shared_extension_simple}.".a") if ($config{target} =~ /^(?:Cygwin|mingw)/); diff --git a/apps/ca.c b/apps/ca.c index 4a8396ee..558809ee 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -1706,11 +1706,11 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, BIO_printf(bio_err, "Memory allocation failure\n"); goto end; } + i = -1; while ((i = X509_NAME_get_index_by_NID(dn_subject, NID_pkcs9_emailAddress, - -1)) >= 0) { - tmpne = X509_NAME_get_entry(dn_subject, i); - X509_NAME_delete_entry(dn_subject, i); + i)) >= 0) { + tmpne = X509_NAME_delete_entry(dn_subject, i--); X509_NAME_ENTRY_free(tmpne); } diff --git a/crypto/bn/bn_lcl.h b/crypto/bn/bn_lcl.h index bab2c9d7..f57c87d9 100644 --- a/crypto/bn/bn_lcl.h +++ b/crypto/bn/bn_lcl.h @@ -23,10 +23,6 @@ # include "internal/bn_int.h" -#ifdef __cplusplus -extern "C" { -#endif - /* * These preprocessor symbols control various aspects of the bignum headers * and library code. They're not defined by any "normal" configuration, as @@ -659,8 +655,4 @@ static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits) return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2); } -#ifdef __cplusplus -} -#endif - #endif diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index 03ccde95..b91b31b1 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -154,19 +154,21 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, int i, j, ret = -1; int k; BN_CTX *ctx = NULL; - BIGNUM *A1, *A1_odd, *check; /* taken from ctx */ + BIGNUM *A1, *A1_odd, *A3, *check; /* taken from ctx */ BN_MONT_CTX *mont = NULL; - if (BN_cmp(a, BN_value_one()) <= 0) + /* Take care of the really small primes 2 & 3 */ + if (BN_is_word(a, 2) || BN_is_word(a, 3)) + return 1; + + /* Check odd and bigger than 1 */ + if (!BN_is_odd(a) || BN_cmp(a, BN_value_one()) <= 0) return 0; if (checks == BN_prime_checks) checks = BN_prime_checks_for_size(BN_num_bits(a)); /* first look for small factors */ - if (!BN_is_odd(a)) - /* a is even => a is prime if and only if a == 2 */ - return BN_is_word(a, 2); if (do_trial_division) { for (i = 1; i < NUMPRIMES; i++) { BN_ULONG mod = BN_mod_word(a, primes[i]); @@ -186,20 +188,18 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_CTX_start(ctx); A1 = BN_CTX_get(ctx); + A3 = BN_CTX_get(ctx); A1_odd = BN_CTX_get(ctx); check = BN_CTX_get(ctx); if (check == NULL) goto err; /* compute A1 := a - 1 */ - if (!BN_copy(A1, a)) + if (!BN_copy(A1, a) || !BN_sub_word(A1, 1)) goto err; - if (!BN_sub_word(A1, 1)) + /* compute A3 := a - 3 */ + if (!BN_copy(A3, a) || !BN_sub_word(A3, 3)) goto err; - if (BN_is_zero(A1)) { - ret = 0; - goto err; - } /* write A1 as A1_odd * 2^k */ k = 1; @@ -216,11 +216,9 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, goto err; for (i = 0; i < checks; i++) { - if (!BN_priv_rand_range(check, A1)) + /* 1 < check < a-1 */ + if (!BN_priv_rand_range(check, A3) || !BN_add_word(check, 2)) goto err; - if (!BN_add_word(check, 1)) - goto err; - /* now 1 <= check < a */ j = witness(check, a, A1, A1_odd, k, ctx, mont); if (j == -1) diff --git a/crypto/cms/cms_lcl.h b/crypto/cms/cms_lcl.h index c277f713..dd5a5852 100644 --- a/crypto/cms/cms_lcl.h +++ b/crypto/cms/cms_lcl.h @@ -10,10 +10,6 @@ #ifndef HEADER_CMS_LCL_H # define HEADER_CMS_LCL_H -#ifdef __cplusplus -extern "C" { -#endif - # include /* @@ -438,7 +434,4 @@ DECLARE_ASN1_ITEM(CMS_RevocationInfoChoice) DECLARE_ASN1_ITEM(CMS_SignedData) DECLARE_ASN1_ITEM(CMS_CompressedData) -#ifdef __cplusplus -} -#endif #endif diff --git a/crypto/ct/ct_log.c b/crypto/ct/ct_log.c index 3c9f9797..be6681dc 100644 --- a/crypto/ct/ct_log.c +++ b/crypto/ct/ct_log.c @@ -46,7 +46,7 @@ typedef struct ctlog_store_load_ctx_st { * Creates an empty context for loading a CT log store. * It should be populated before use. */ -static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(); +static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void); /* * Deletes a CT log store load context. diff --git a/crypto/ec/curve25519.c b/crypto/ec/curve25519.c index 0f18ff7c..9666de12 100644 --- a/crypto/ec/curve25519.c +++ b/crypto/ec/curve25519.c @@ -150,7 +150,7 @@ void x25519_fe51_mul121666(fe51 h, fe51 f); typedef uint64_t fe64[4]; -int x25519_fe64_eligible(); +int x25519_fe64_eligible(void); /* * There are no reference C implementations for this radix. diff --git a/crypto/ec/ec_lcl.h b/crypto/ec/ec_lcl.h index 006e3b6e..cf29c7c7 100644 --- a/crypto/ec/ec_lcl.h +++ b/crypto/ec/ec_lcl.h @@ -174,8 +174,8 @@ struct ec_method_st { int (*ecdh_compute_key)(unsigned char **pout, size_t *poutlen, const EC_POINT *pub_key, const EC_KEY *ecdh); /* Inverse modulo order */ - int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, BIGNUM *x, - BN_CTX *ctx); + int (*field_inverse_mod_ord)(const EC_GROUP *, BIGNUM *r, + const BIGNUM *x, BN_CTX *); int (*blind_coordinates)(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); }; @@ -636,7 +636,7 @@ int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32], void X25519_public_from_private(uint8_t out_public_value[32], const uint8_t private_key[32]); -int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, - BIGNUM *x, BN_CTX *ctx); +int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, + const BIGNUM *x, BN_CTX *ctx); int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index d0393e8b..6a2d1b58 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -1017,13 +1017,67 @@ int ec_group_simple_order_bits(const EC_GROUP *group) return BN_num_bits(group->order); } -int EC_GROUP_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, - BIGNUM *x, BN_CTX *ctx) +static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, + const BIGNUM *x, BN_CTX *ctx) +{ + BIGNUM *e = NULL; + BN_CTX *new_ctx = NULL; + int ret = 0; + + if (group->mont_data == NULL) + return 0; + + if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL) + return 0; + + BN_CTX_start(ctx); + if ((e = BN_CTX_get(ctx)) == NULL) + goto err; + + /*- + * We want inverse in constant time, therefore we utilize the fact + * order must be prime and use Fermats Little Theorem instead. + */ + if (!BN_set_word(e, 2)) + goto err; + if (!BN_sub(e, group->order, e)) + goto err; + /*- + * Exponent e is public. + * No need for scatter-gather or BN_FLG_CONSTTIME. + */ + if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data)) + goto err; + + ret = 1; + + err: + if (ctx != NULL) + BN_CTX_end(ctx); + BN_CTX_free(new_ctx); + return ret; +} + +/*- + * Default behavior, if group->meth->field_inverse_mod_ord is NULL: + * - When group->order is even, this function returns an error. + * - When group->order is otherwise composite, the correctness + * of the output is not guaranteed. + * - When x is outside the range [1, group->order), the correctness + * of the output is not guaranteed. + * - Otherwise, this function returns the multiplicative inverse in the + * range [1, group->order). + * + * EC_METHODs must implement their own field_inverse_mod_ord for + * other functionality. + */ +int ec_group_do_inverse_ord(const EC_GROUP *group, BIGNUM *res, + const BIGNUM *x, BN_CTX *ctx) { if (group->meth->field_inverse_mod_ord != NULL) return group->meth->field_inverse_mod_ord(group, res, x, ctx); else - return 0; + return ec_field_inverse_mod_ord(group, res, x, ctx); } /*- diff --git a/crypto/ec/ecdsa_ossl.c b/crypto/ec/ecdsa_ossl.c index cdd0cf02..dfb0d192 100644 --- a/crypto/ec/ecdsa_ossl.c +++ b/crypto/ec/ecdsa_ossl.c @@ -136,34 +136,10 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, } while (BN_is_zero(r)); - /* Check if optimized inverse is implemented */ - if (EC_GROUP_do_inverse_ord(group, k, k, ctx) == 0) { - /* compute the inverse of k */ - if (group->mont_data != NULL) { - /* - * We want inverse in constant time, therefore we utilize the fact - * order must be prime and use Fermats Little Theorem instead. - */ - if (!BN_set_word(X, 2)) { - ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); - goto err; - } - if (!BN_mod_sub(X, order, X, order, ctx)) { - ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); - goto err; - } - BN_set_flags(X, BN_FLG_CONSTTIME); - if (!BN_mod_exp_mont_consttime(k, k, X, order, ctx, - group->mont_data)) { - ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); - goto err; - } - } else { - if (!BN_mod_inverse(k, k, order, ctx)) { - ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); - goto err; - } - } + /* compute the inverse of k */ + if (!ec_group_do_inverse_ord(group, k, k, ctx)) { + ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB); + goto err; } /* clear old values if necessary */ @@ -360,7 +336,8 @@ ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len, ECDSA_SIG_free(ret); ret = NULL; } - BN_CTX_end(ctx); + if (ctx != NULL) + BN_CTX_end(ctx); BN_CTX_free(ctx); BN_clear_free(kinv); return ret; @@ -449,12 +426,9 @@ int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, goto err; } /* calculate tmp1 = inv(S) mod order */ - /* Check if optimized inverse is implemented */ - if (EC_GROUP_do_inverse_ord(group, u2, sig->s, ctx) == 0) { - if (!BN_mod_inverse(u2, sig->s, order, ctx)) { - ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB); - goto err; - } + if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)) { + ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB); + goto err; } /* digest -> m */ i = BN_num_bits(order); diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c index 6e7c687c..6155b546 100644 --- a/crypto/ec/ecp_nistp224.c +++ b/crypto/ec/ecp_nistp224.c @@ -1212,7 +1212,7 @@ static void batch_mul(felem x_out, felem y_out, felem z_out, * FUNCTIONS TO MANAGE PRECOMPUTATION */ -static NISTP224_PRE_COMP *nistp224_pre_comp_new() +static NISTP224_PRE_COMP *nistp224_pre_comp_new(void) { NISTP224_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret)); diff --git a/crypto/ec/ecp_nistp256.c b/crypto/ec/ecp_nistp256.c index 19caa031..00fcfd5b 100644 --- a/crypto/ec/ecp_nistp256.c +++ b/crypto/ec/ecp_nistp256.c @@ -1832,7 +1832,7 @@ const EC_METHOD *EC_GFp_nistp256_method(void) * FUNCTIONS TO MANAGE PRECOMPUTATION */ -static NISTP256_PRE_COMP *nistp256_pre_comp_new() +static NISTP256_PRE_COMP *nistp256_pre_comp_new(void) { NISTP256_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret)); diff --git a/crypto/ec/ecp_nistp521.c b/crypto/ec/ecp_nistp521.c index 43f3e2d9..4e6c0f98 100644 --- a/crypto/ec/ecp_nistp521.c +++ b/crypto/ec/ecp_nistp521.c @@ -1671,7 +1671,7 @@ const EC_METHOD *EC_GFp_nistp521_method(void) * FUNCTIONS TO MANAGE PRECOMPUTATION */ -static NISTP521_PRE_COMP *nistp521_pre_comp_new() +static NISTP521_PRE_COMP *nistp521_pre_comp_new(void) { NISTP521_PRE_COMP *ret = OPENSSL_zalloc(sizeof(*ret)); diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c index 02925616..045c2e71 100644 --- a/crypto/ec/ecp_nistz256.c +++ b/crypto/ec/ecp_nistz256.c @@ -1512,7 +1512,7 @@ void ecp_nistz256_ord_sqr_mont(BN_ULONG res[P256_LIMBS], int rep); static int ecp_nistz256_inv_mod_ord(const EC_GROUP *group, BIGNUM *r, - BIGNUM *x, BN_CTX *ctx) + const BIGNUM *x, BN_CTX *ctx) { /* RR = 2^512 mod ord(p256) */ static const BN_ULONG RR[P256_LIMBS] = { diff --git a/crypto/engine/eng_int.h b/crypto/engine/eng_int.h index 60fdf820..7c41da2f 100644 --- a/crypto/engine/eng_int.h +++ b/crypto/engine/eng_int.h @@ -16,10 +16,6 @@ # include "internal/thread_once.h" # include "internal/refcount.h" -#ifdef __cplusplus -extern "C" { -#endif - extern CRYPTO_RWLOCK *global_engine_lock; /* @@ -172,8 +168,4 @@ typedef struct st_engine_pile ENGINE_PILE; DEFINE_LHASH_OF(ENGINE_PILE); -#ifdef __cplusplus -} -#endif - #endif /* HEADER_ENGINE_INT_H */ diff --git a/crypto/hmac/hmac_lcl.h b/crypto/hmac/hmac_lcl.h index 4c156dc1..7ba0aac4 100644 --- a/crypto/hmac/hmac_lcl.h +++ b/crypto/hmac/hmac_lcl.h @@ -10,13 +10,6 @@ #ifndef HEADER_HMAC_LCL_H # define HEADER_HMAC_LCL_H -#ifdef __cplusplus -extern "C" { -#endif -#if 0 /* emacs indentation fix */ -} -#endif - struct hmac_ctx_st { const EVP_MD *md; EVP_MD_CTX *md_ctx; @@ -26,8 +19,4 @@ struct hmac_ctx_st { unsigned char key[HMAC_MAX_MD_CBLOCK]; }; -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif diff --git a/crypto/include/internal/aria.h b/crypto/include/internal/aria.h index 07382718..e402b8ee 100644 --- a/crypto/include/internal/aria.h +++ b/crypto/include/internal/aria.h @@ -25,10 +25,6 @@ # define ARIA_BLOCK_SIZE 16 /* Size of each encryption/decryption block */ # define ARIA_MAX_KEYS 17 /* Number of keys needed in the worst case */ -# ifdef __cplusplus -extern "C" { -# endif - typedef union { unsigned char c[ARIA_BLOCK_SIZE]; unsigned int u[ARIA_BLOCK_SIZE / sizeof(unsigned int)]; @@ -51,8 +47,4 @@ int aria_set_decrypt_key(const unsigned char *userKey, const int bits, void aria_encrypt(const unsigned char *in, unsigned char *out, const ARIA_KEY *key); -# ifdef __cplusplus -} -# endif - #endif diff --git a/crypto/include/internal/bn_int.h b/crypto/include/internal/bn_int.h index ac49d1ea..9379951d 100644 --- a/crypto/include/internal/bn_int.h +++ b/crypto/include/internal/bn_int.h @@ -13,10 +13,6 @@ # include # include -#ifdef __cplusplus -extern "C" { -#endif - BIGNUM *bn_wexpand(BIGNUM *a, int words); BIGNUM *bn_expand2(BIGNUM *a, int words); @@ -64,8 +60,4 @@ void bn_set_static_words(BIGNUM *a, BN_ULONG *words, int size); */ int bn_set_words(BIGNUM *a, BN_ULONG *words, int num_words); -#ifdef __cplusplus -} -#endif - #endif diff --git a/crypto/include/internal/chacha.h b/crypto/include/internal/chacha.h index 7d4366ea..119361d4 100644 --- a/crypto/include/internal/chacha.h +++ b/crypto/include/internal/chacha.h @@ -12,10 +12,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - /* * ChaCha20_ctr32 encrypts |len| bytes from |inp| with the given key and * nonce and writes the result to |out|, which may be equal to |inp|. @@ -43,7 +39,4 @@ void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp, #define CHACHA_CTR_SIZE 16 #define CHACHA_BLK_SIZE 64 -#ifdef __cplusplus -} -#endif #endif diff --git a/crypto/include/internal/sm2.h b/crypto/include/internal/sm2.h index 613fa340..23e38952 100644 --- a/crypto/include/internal/sm2.h +++ b/crypto/include/internal/sm2.h @@ -15,10 +15,6 @@ # ifndef OPENSSL_NO_SM2 -# ifdef __cplusplus -extern "C" { -# endif - # include /* The default user id as specified in GM/T 0009-2012 */ @@ -74,9 +70,5 @@ int sm2_decrypt(const EC_KEY *key, const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len); -# ifdef __cplusplus -} -# endif - # endif /* OPENSSL_NO_SM2 */ #endif diff --git a/crypto/include/internal/sm2err.h b/crypto/include/internal/sm2err.h index 9a7e2b62..f32d26c0 100644 --- a/crypto/include/internal/sm2err.h +++ b/crypto/include/internal/sm2err.h @@ -15,9 +15,6 @@ # ifndef OPENSSL_NO_SM2 -# ifdef __cplusplus -extern "C" -# endif int ERR_load_SM2_strings(void); /* diff --git a/crypto/include/internal/store_int.h b/crypto/include/internal/store_int.h index 9966aefa..0125aae0 100644 --- a/crypto/include/internal/store_int.h +++ b/crypto/include/internal/store_int.h @@ -14,10 +14,6 @@ # include # include -# ifdef __cplusplus -extern "C" { -# endif - /* * Two functions to read PEM data off an already opened BIO. To be used * instead of OSSLSTORE_open() and OSSLSTORE_close(). Everything is done @@ -27,7 +23,4 @@ OSSL_STORE_CTX *ossl_store_attach_pem_bio(BIO *bp, const UI_METHOD *ui_method, void *ui_data); int ossl_store_detach_pem_bio(OSSL_STORE_CTX *ctx); -# ifdef __cplusplus -} -# endif #endif diff --git a/crypto/seed/seed_locl.h b/crypto/seed/seed_locl.h index d4a03fc4..97c43ef6 100644 --- a/crypto/seed/seed_locl.h +++ b/crypto/seed/seed_locl.h @@ -45,10 +45,6 @@ typedef unsigned int seed_word; # endif -#ifdef __cplusplus -extern "C" { -#endif - # define char2word(c, i) \ (i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3])) @@ -113,8 +109,4 @@ extern "C" { (X1) ^= (T0); \ (X2) ^= (T1) -#ifdef __cplusplus -} -#endif - #endif /* HEADER_SEED_LOCL_H */ diff --git a/crypto/sha/asm/sha256-armv4.pl b/crypto/sha/asm/sha256-armv4.pl index 55d30cba..509aa2c5 100644 --- a/crypto/sha/asm/sha256-armv4.pl +++ b/crypto/sha/asm/sha256-armv4.pl @@ -254,7 +254,7 @@ for($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); } $code.=".Lrounds_16_xx:\n"; for (;$i<32;$i++) { &BODY_16_XX($i,@V); unshift(@V,pop(@V)); } $code.=<<___; -#if __ARM_ARCH__>=7 +#ifdef __thumb2__ ite eq @ Thumb2 thing, sanity check in ARM #endif ldreq $t3,[sp,#16*4] @ pull ctx diff --git a/crypto/sha/asm/sha512-armv4.pl b/crypto/sha/asm/sha512-armv4.pl index 22b5a9d0..872c27fb 100644 --- a/crypto/sha/asm/sha512-armv4.pl +++ b/crypto/sha/asm/sha512-armv4.pl @@ -157,7 +157,7 @@ $code.=<<___; teq $t0,#$magic ldr $t3,[sp,#$Coff+0] @ c.lo -#if __ARM_ARCH__>=7 +#ifdef __thumb2__ it eq @ Thumb2 thing, sanity check in ARM #endif orreq $Ktbl,$Ktbl,#1 @@ -411,7 +411,7 @@ $code.=<<___; ___ &BODY_00_15(0x17); $code.=<<___; -#if __ARM_ARCH__>=7 +#ifdef __thumb2__ ittt eq @ Thumb2 thing, sanity check in ARM #endif ldreq $t0,[sp,#`$Xoff+8*(16-1)`+0] diff --git a/crypto/x509v3/v3_admis.h b/crypto/x509v3/v3_admis.h index 2f1e76d7..fa23fc76 100644 --- a/crypto/x509v3/v3_admis.h +++ b/crypto/x509v3/v3_admis.h @@ -10,10 +10,6 @@ #ifndef HEADER_V3_ADMISSION_H # define HEADER_V3_ADMISSION_H -#ifdef __cplusplus -extern "C" { -#endif - struct NamingAuthority_st { ASN1_OBJECT* namingAuthorityId; ASN1_IA5STRING* namingAuthorityUrl; @@ -39,7 +35,4 @@ struct AdmissionSyntax_st { STACK_OF(ADMISSIONS)* contentsOfAdmissions; }; -#ifdef __cplusplus -} -#endif #endif diff --git a/doc/man3/ASN1_INTEGER_get_int64.pod b/doc/man3/ASN1_INTEGER_get_int64.pod index f61268d6..7ed1cca8 100644 --- a/doc/man3/ASN1_INTEGER_get_int64.pod +++ b/doc/man3/ASN1_INTEGER_get_int64.pod @@ -11,10 +11,10 @@ ASN1_INTEGER_get_int64, ASN1_INTEGER_get, ASN1_INTEGER_set_int64, ASN1_INTEGER_s #include int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a); - int ASN1_INTEGER_get(const ASN1_INTEGER *a, long v); + long ASN1_INTEGER_get(const ASN1_INTEGER *a); int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r); - long ASN1_INTEGER_set(const ASN1_INTEGER *a); + int ASN1_INTEGER_set(const ASN1_INTEGER *a, long v); int ASN1_INTEGER_get_uint64(uint64_t *pr, const ASN1_INTEGER *a); int ASN1_INTEGER_set_uint64(ASN1_INTEGER *a, uint64_t r); diff --git a/doc/man3/OCSP_resp_find_status.pod b/doc/man3/OCSP_resp_find_status.pod index af7fb1de..1bbc4e32 100644 --- a/doc/man3/OCSP_resp_find_status.pod +++ b/doc/man3/OCSP_resp_find_status.pod @@ -8,7 +8,8 @@ OCSP_resp_get0_id, OCSP_resp_get1_id, OCSP_resp_get0_produced_at, OCSP_resp_find_status, OCSP_resp_count, OCSP_resp_get0, OCSP_resp_find, -OCSP_single_get0_status, OCSP_check_validity +OCSP_single_get0_status, OCSP_check_validity, +OCSP_basic_verify - OCSP response utility functions =head1 SYNOPSIS @@ -48,6 +49,9 @@ OCSP_single_get0_status, OCSP_check_validity ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec); + int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, + X509_STORE *st, unsigned long flags); + =head1 DESCRIPTION OCSP_resp_find_status() searches B for an OCSP response for B. If it is @@ -100,6 +104,27 @@ OCSP_single_get0_status(). If B is non-zero it indicates how many seconds leeway should be allowed in the check. If B is positive it indicates the maximum age of B in seconds. +OCSP_basic_verify() checks that the basic response message B is correctly +signed and that the signer certificate can be validated. It takes B as +the trusted store and B as a set of untrusted intermediate certificates. +The function first tries to find the signer certificate of the response +in . It also searches the certificates the responder may have included +in B unless the B contain B. +It fails if the signer certificate cannot be found. +Next, the function checks the signature of B and fails on error +unless the B contain B. Then the function already returns +success if the B contain B or if the signer certificate +was found in B and the B contain B. +Otherwise the function continues by validating the signer certificate. +To this end, all certificates in B and in B are considered as +untrusted certificates for the construction of the validation path for the +signer certificate unless the B flag is set. After successful path +validation the function returns success if the B flag is set. +Otherwise it verifies that the signer certificate meets the OCSP issuer +criteria including potential delegation. If this does not succeed and the +B do not contain B the function checks for explicit +trust for OCSP signing in the root CA certificate. + =head1 RETURN VALUES OCSP_resp_find_status() returns 1 if B is found in B and 0 otherwise. @@ -119,6 +144,9 @@ occurred. OCSP_resp_get0_signer() returns 1 if the signing certificate was located, or 0 on error. +OCSP_basic_verify() returns 1 on success, 0 on error, or -1 on fatal error such +as malloc failure. + =head1 NOTES Applications will typically call OCSP_resp_find_status() using the certificate diff --git a/doc/openssl-c-indent.el b/doc/openssl-c-indent.el index 38e7a4f3..59dec445 100644 --- a/doc/openssl-c-indent.el +++ b/doc/openssl-c-indent.el @@ -54,6 +54,7 @@ (arglist-close . c-lineup-arglist) ; From "gnu" style (inline-open . 0) ; From "gnu" style (brace-list-open . +) ; From "gnu" style + (inextern-lang . 0) ; Don't indent inside extern block (topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont) ; From "gnu" style ) diff --git a/e_os.h b/e_os.h index 5071af62..5769029b 100644 --- a/e_os.h +++ b/e_os.h @@ -22,10 +22,6 @@ * outside; this file e_os.h is not part of the exported interface. */ -#ifdef __cplusplus -extern "C" { -#endif - # ifndef DEVRANDOM /* * set this to a comma-separated list of 'random' device files to try out. By @@ -325,8 +321,4 @@ struct servent *getservbyname(const char *name, const char *proto); # define CRYPTO_memcmp memcmp #endif -#ifdef __cplusplus -} -#endif - #endif diff --git a/engines/e_afalg.c b/engines/e_afalg.c index 54cecdd6..f09c396e 100644 --- a/engines/e_afalg.c +++ b/engines/e_afalg.c @@ -148,7 +148,7 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) /* Async mode */ waitctx = ASYNC_get_wait_ctx(job); if (waitctx == NULL) { - ALG_WARN("%s: ASYNC_get_wait_ctx error", __func__); + ALG_WARN("%s(%d): ASYNC_get_wait_ctx error", __FILE__, __LINE__); return 0; } /* Get waitfd from ASYNC_WAIT_CTX if it is already set */ @@ -161,7 +161,8 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) */ aio->efd = eventfd(0); if (aio->efd == -1) { - ALG_PERR("%s: Failed to get eventfd : ", __func__); + ALG_PERR("%s(%d): Failed to get eventfd : ", __FILE__, + __LINE__); AFALGerr(AFALG_F_AFALG_SETUP_ASYNC_EVENT_NOTIFICATION, AFALG_R_EVENTFD_FAILED); return 0; @@ -170,14 +171,14 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) aio->efd, custom, afalg_waitfd_cleanup); if (ret == 0) { - ALG_WARN("%s: Failed to set wait fd", __func__); + ALG_WARN("%s(%d): Failed to set wait fd", __FILE__, __LINE__); close(aio->efd); return 0; } /* make fd non-blocking in async mode */ if (fcntl(aio->efd, F_SETFL, O_NONBLOCK) != 0) { - ALG_WARN("%s: Failed to set event fd as NONBLOCKING", - __func__); + ALG_WARN("%s(%d): Failed to set event fd as NONBLOCKING", + __FILE__, __LINE__); } } aio->mode = MODE_ASYNC; @@ -185,7 +186,7 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) /* Sync mode */ aio->efd = eventfd(0); if (aio->efd == -1) { - ALG_PERR("%s: Failed to get eventfd : ", __func__); + ALG_PERR("%s(%d): Failed to get eventfd : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_SETUP_ASYNC_EVENT_NOTIFICATION, AFALG_R_EVENTFD_FAILED); return 0; @@ -203,7 +204,7 @@ static int afalg_init_aio(afalg_aio *aio) aio->aio_ctx = 0; r = io_setup(MAX_INFLIGHTS, &aio->aio_ctx); if (r < 0) { - ALG_PERR("%s: io_setup error : ", __func__); + ALG_PERR("%s(%d): io_setup error : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_INIT_AIO, AFALG_R_IO_SETUP_FAILED); return 0; } @@ -257,7 +258,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, */ r = io_read(aio->aio_ctx, 1, &cb); if (r < 0) { - ALG_PWARN("%s: io_read failed : ", __func__); + ALG_PWARN("%s(%d): io_read failed : ", __FILE__, __LINE__); return 0; } @@ -270,11 +271,11 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, if (r < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) continue; - ALG_PERR("%s: read failed for event fd : ", __func__); + ALG_PERR("%s(%d): read failed for event fd : ", __FILE__, __LINE__); return 0; } else if (r == 0 || eval <= 0) { - ALG_WARN("%s: eventfd read %d bytes, eval = %lu\n", __func__, r, - eval); + ALG_WARN("%s(%d): eventfd read %d bytes, eval = %lu\n", __FILE__, + __LINE__, r, eval); } if (eval > 0) { @@ -294,8 +295,8 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, if (events[0].res == -EBUSY && retry++ < 3) { r = io_read(aio->aio_ctx, 1, &cb); if (r < 0) { - ALG_PERR("%s: retry %d for io_read failed : ", - __func__, retry); + ALG_PERR("%s(%d): retry %d for io_read failed : ", + __FILE__, __LINE__, retry); return 0; } continue; @@ -305,18 +306,19 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, * condition for this instance of operation. */ ALG_WARN - ("%s: Crypto Operation failed with code %lld\n", - __func__, events[0].res); + ("%s(%d): Crypto Operation failed with code %lld\n", + __FILE__, __LINE__, events[0].res); return 0; } } /* Operation successful. */ done = 1; } else if (r < 0) { - ALG_PERR("%s: io_getevents failed : ", __func__); + ALG_PERR("%s(%d): io_getevents failed : ", __FILE__, __LINE__); return 0; } else { - ALG_WARN("%s: io_geteventd read 0 bytes\n", __func__); + ALG_WARN("%s(%d): io_geteventd read 0 bytes\n", __FILE__, + __LINE__); } } } while (!done); @@ -352,7 +354,7 @@ static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key, int ret; ret = setsockopt(actx->bfd, SOL_ALG, ALG_SET_KEY, key, klen); if (ret < 0) { - ALG_PERR("%s: Failed to set socket option : ", __func__); + ALG_PERR("%s(%d): Failed to set socket option : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_SET_KEY, AFALG_R_SOCKET_SET_KEY_FAILED); return 0; } @@ -376,21 +378,21 @@ static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, actx->bfd = socket(AF_ALG, SOCK_SEQPACKET, 0); if (actx->bfd == -1) { - ALG_PERR("%s: Failed to open socket : ", __func__); + ALG_PERR("%s(%d): Failed to open socket : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_CREATE_SK, AFALG_R_SOCKET_CREATE_FAILED); goto err; } r = bind(actx->bfd, (struct sockaddr *)&sa, sizeof(sa)); if (r < 0) { - ALG_PERR("%s: Failed to bind socket : ", __func__); + ALG_PERR("%s(%d): Failed to bind socket : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_CREATE_SK, AFALG_R_SOCKET_BIND_FAILED); goto err; } actx->sfd = accept(actx->bfd, NULL, 0); if (actx->sfd < 0) { - ALG_PERR("%s: Socket Accept Failed : ", __func__); + ALG_PERR("%s(%d): Socket Accept Failed : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_CREATE_SK, AFALG_R_SOCKET_ACCEPT_FAILED); goto err; } @@ -452,8 +454,8 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, /* Sendmsg() sends iv and cipher direction to the kernel */ sbytes = sendmsg(actx->sfd, &msg, 0); if (sbytes < 0) { - ALG_PERR("%s: sendmsg failed for zero copy cipher operation : ", - __func__); + ALG_PERR("%s(%d): sendmsg failed for zero copy cipher operation : ", + __FILE__, __LINE__); return 0; } @@ -463,13 +465,13 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, */ ret = vmsplice(actx->zc_pipe[1], &iov, 1, SPLICE_F_GIFT); if (ret < 0) { - ALG_PERR("%s: vmsplice failed : ", __func__); + ALG_PERR("%s(%d): vmsplice failed : ", __FILE__, __LINE__); return 0; } ret = splice(actx->zc_pipe[0], NULL, actx->sfd, NULL, inl, 0); if (ret < 0) { - ALG_PERR("%s: splice failed : ", __func__); + ALG_PERR("%s(%d): splice failed : ", __FILE__, __LINE__); return 0; } # else @@ -479,7 +481,8 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, /* Sendmsg() sends iv, cipher direction and input data to the kernel */ sbytes = sendmsg(actx->sfd, &msg, 0); if (sbytes < 0) { - ALG_PERR("%s: sendmsg failed for cipher operation : ", __func__); + ALG_PERR("%s(%d): sendmsg failed for cipher operation : ", __FILE__, + __LINE__); return 0; } @@ -502,18 +505,18 @@ static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, char ciphername[ALG_MAX_SALG_NAME]; if (ctx == NULL || key == NULL) { - ALG_WARN("%s: Null Parameter\n", __func__); + ALG_WARN("%s(%d): Null Parameter\n", __FILE__, __LINE__); return 0; } if (EVP_CIPHER_CTX_cipher(ctx) == NULL) { - ALG_WARN("%s: Cipher object NULL\n", __func__); + ALG_WARN("%s(%d): Cipher object NULL\n", __FILE__, __LINE__); return 0; } actx = EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL) { - ALG_WARN("%s: Cipher data NULL\n", __func__); + ALG_WARN("%s(%d): Cipher data NULL\n", __FILE__, __LINE__); return 0; } @@ -525,14 +528,15 @@ static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, strncpy(ciphername, "cbc(aes)", ALG_MAX_SALG_NAME); break; default: - ALG_WARN("%s: Unsupported Cipher type %d\n", __func__, ciphertype); + ALG_WARN("%s(%d): Unsupported Cipher type %d\n", __FILE__, __LINE__, + ciphertype); return 0; } ciphername[ALG_MAX_SALG_NAME-1]='\0'; if (ALG_AES_IV_LEN != EVP_CIPHER_CTX_iv_length(ctx)) { - ALG_WARN("%s: Unsupported IV length :%d\n", __func__, - EVP_CIPHER_CTX_iv_length(ctx)); + ALG_WARN("%s(%d): Unsupported IV length :%d\n", __FILE__, __LINE__, + EVP_CIPHER_CTX_iv_length(ctx)); return 0; } @@ -572,7 +576,8 @@ static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, char nxtiv[ALG_AES_IV_LEN] = { 0 }; if (ctx == NULL || out == NULL || in == NULL) { - ALG_WARN("NULL parameter passed to function %s\n", __func__); + ALG_WARN("NULL parameter passed to function %s(%d)\n", __FILE__, + __LINE__); return 0; } @@ -619,7 +624,8 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx) afalg_ctx *actx; if (ctx == NULL) { - ALG_WARN("NULL parameter passed to function %s\n", __func__); + ALG_WARN("NULL parameter passed to function %s(%d)\n", __FILE__, + __LINE__); return 0; } diff --git a/engines/e_padlock.c b/engines/e_padlock.c index b86f1655..43944abc 100644 --- a/engines/e_padlock.c +++ b/engines/e_padlock.c @@ -199,10 +199,10 @@ struct padlock_cipher_data { }; /* Interface to assembler module */ -unsigned int padlock_capability(); +unsigned int padlock_capability(void); void padlock_key_bswap(AES_KEY *key); void padlock_verify_context(struct padlock_cipher_data *ctx); -void padlock_reload_key(); +void padlock_reload_key(void); void padlock_aes_block(void *out, const void *inp, struct padlock_cipher_data *ctx); int padlock_ecb_encrypt(void *out, const void *inp, diff --git a/include/internal/conf.h b/include/internal/conf.h index ada3f92b..23a9c3b4 100644 --- a/include/internal/conf.h +++ b/include/internal/conf.h @@ -12,11 +12,6 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - - struct ossl_init_settings_st { char *appname; }; @@ -25,8 +20,4 @@ void openssl_config_int(const char *appname); void openssl_no_config_int(void); void conf_modules_free_int(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/include/internal/constant_time_locl.h b/include/internal/constant_time_locl.h index d23f515c..82ff7465 100644 --- a/include/internal/constant_time_locl.h +++ b/include/internal/constant_time_locl.h @@ -14,10 +14,6 @@ # include # include /* For 'ossl_inline' */ -#ifdef __cplusplus -extern "C" { -#endif - /*- * The boolean methods return a bitmask of all ones (0xff...f) for true * and 0 for false. This is useful for choosing a value based on the result @@ -328,8 +324,4 @@ static ossl_inline void constant_time_lookup(void *out, } } -#ifdef __cplusplus -} -#endif - #endif /* HEADER_CONSTANT_TIME_LOCL_H */ diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h index 8a96de98..2808fe7e 100644 --- a/include/internal/cryptlib.h +++ b/include/internal/cryptlib.h @@ -25,10 +25,6 @@ # include # include "internal/nelem.h" -#ifdef __cplusplus -extern "C" { -#endif - #ifdef NDEBUG # define ossl_assert(x) ((x) != 0) #else @@ -96,8 +92,4 @@ void *openssl_fopen(const char *filename, const char *mode); uint32_t OPENSSL_rdtsc(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/include/internal/dso.h b/include/internal/dso.h index 402a76f6..3e67d505 100644 --- a/include/internal/dso.h +++ b/include/internal/dso.h @@ -13,10 +13,6 @@ # include # include "internal/dsoerr.h" -#ifdef __cplusplus -extern "C" { -#endif - /* These values are used as commands to DSO_ctrl() */ # define DSO_CTRL_GET_FLAGS 1 # define DSO_CTRL_SET_FLAGS 2 @@ -166,7 +162,4 @@ void *DSO_global_lookup(const char *name); int ERR_load_DSO_strings(void); -# ifdef __cplusplus -} -# endif #endif diff --git a/include/internal/dsoerr.h b/include/internal/dsoerr.h index a54a1854..ac6bdcd0 100644 --- a/include/internal/dsoerr.h +++ b/include/internal/dsoerr.h @@ -15,9 +15,6 @@ # ifndef OPENSSL_NO_DSO -# ifdef __cplusplus -extern "C" -# endif int ERR_load_DSO_strings(void); /* diff --git a/include/internal/o_dir.h b/include/internal/o_dir.h index f18fc670..f8926877 100644 --- a/include/internal/o_dir.h +++ b/include/internal/o_dir.h @@ -39,10 +39,6 @@ #ifndef O_DIR_H # define O_DIR_H -#ifdef __cplusplus -extern "C" { -#endif - typedef struct OPENSSL_dir_context_st OPENSSL_DIR_CTX; /* @@ -53,8 +49,4 @@ const char *OPENSSL_DIR_read(OPENSSL_DIR_CTX **ctx, const char *directory); /* returns 1 on success, 0 on error */ int OPENSSL_DIR_end(OPENSSL_DIR_CTX **ctx); -#ifdef __cplusplus -} -#endif - #endif /* LPDIR_H */ diff --git a/ssl/packet_locl.h b/ssl/packet_locl.h index 8e553e62..fd32a640 100644 --- a/ssl/packet_locl.h +++ b/ssl/packet_locl.h @@ -18,10 +18,6 @@ # include "internal/numbers.h" -# ifdef __cplusplus -extern "C" { -# endif - typedef struct { /* Pointer to where we are currently reading from */ const unsigned char *curr; @@ -875,8 +871,4 @@ unsigned char *WPACKET_get_curr(WPACKET *pkt); /* Release resources in a WPACKET if a failure has occurred. */ void WPACKET_cleanup(WPACKET *pkt); -# ifdef __cplusplus -} -# endif - #endif /* HEADER_PACKET_LOCL_H */ diff --git a/test/bntest.c b/test/bntest.c index 35587780..0502497f 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -2128,25 +2128,48 @@ err: return st; } -static int test_3_is_prime(void) +static int primes[] = { 2, 3, 5, 7, 17863 }; + +static int test_is_prime(int i) { int ret = 0; BIGNUM *r = NULL; + int trial; - /* - * For a long time, small primes were not considered prime when - * do_trial_division was set. - */ - if (!TEST_ptr(r = BN_new()) - || !TEST_true(BN_set_word(r, 3)) - || !TEST_int_eq(BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, - 0 /* do_trial_division */, NULL), 1) - || !TEST_int_eq(BN_is_prime_fasttest_ex(r, 3 /* nchecks */, ctx, - 1 /* do_trial_division */, NULL), 1)) + if (!TEST_ptr(r = BN_new())) goto err; - ret = 1; + for (trial = 0; trial <= 1; ++trial) { + if (!TEST_true(BN_set_word(r, primes[i])) + || !TEST_int_eq(BN_is_prime_fasttest_ex(r, 1, ctx, trial, NULL), + 1)) + goto err; + } + ret = 1; +err: + BN_free(r); + return ret; +} + +static int not_primes[] = { -1, 0, 1, 4 }; + +static int test_not_prime(int i) +{ + int ret = 0; + BIGNUM *r = NULL; + int trial; + + if (!TEST_ptr(r = BN_new())) + goto err; + + for (trial = 0; trial <= 1; ++trial) { + if (!TEST_true(BN_set_word(r, not_primes[i])) + || !TEST_false(BN_is_prime_fasttest_ex(r, 1, ctx, trial, NULL))) + goto err; + } + + ret = 1; err: BN_free(r); return ret; @@ -2250,7 +2273,8 @@ int setup_tests(void) ADD_TEST(test_gf2m_modsqrt); ADD_TEST(test_gf2m_modsolvequad); #endif - ADD_TEST(test_3_is_prime); + ADD_ALL_TESTS(test_is_prime, (int)OSSL_NELEM(primes)); + ADD_ALL_TESTS(test_not_prime, (int)OSSL_NELEM(not_primes)); } else { ADD_ALL_TESTS(run_file_tests, n); } diff --git a/test/ectest.c b/test/ectest.c index 73e8aa87..ead23d72 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -1167,7 +1167,7 @@ static int internal_curve_test_method(int n) * implementations of several NIST curves with characteristic > 3. */ struct nistp_test_params { - const EC_METHOD *(*meth) (); + const EC_METHOD *(*meth) (void); int degree; /* * Qx, Qy and D are taken from diff --git a/test/recipes/90-test_shlibload.t b/test/recipes/90-test_shlibload.t index 04d52658..368dea31 100644 --- a/test/recipes/90-test_shlibload.t +++ b/test/recipes/90-test_shlibload.t @@ -19,6 +19,7 @@ use lib bldtop_dir('.'); use configdata; plan skip_all => "Test only supported in a shared build" if disabled("shared"); +plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|; plan tests => 4; diff --git a/test/sm2_internal_test.c b/test/sm2_internal_test.c index d4ec01e9..ea8ac7df 100644 --- a/test/sm2_internal_test.c +++ b/test/sm2_internal_test.c @@ -209,7 +209,7 @@ static int test_sm2_crypt(const EC_GROUP *group, static int sm2_crypt_test(void) { - int testresult = 1; + int testresult = 0; EC_GROUP *test_group = create_EC_group ("8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", diff --git a/test/testutil/driver.c b/test/testutil/driver.c index 9cdce7a4..09907347 100644 --- a/test/testutil/driver.c +++ b/test/testutil/driver.c @@ -26,7 +26,7 @@ */ typedef struct test_info { const char *test_case_name; - int (*test_fn) (); + int (*test_fn) (void); int (*param_test_fn)(int idx); int num; @@ -74,7 +74,7 @@ int subtest_level(void) } #ifndef OPENSSL_NO_CRYPTO_MDEBUG -static int should_report_leaks() +static int should_report_leaks(void) { /* * When compiled with enable-crypto-mdebug, OPENSSL_DEBUG_MEMORY=0 diff --git a/util/shlib_wrap.sh.in b/util/shlib_wrap.sh.in index b9e3ddf8..9199d12f 100755 --- a/util/shlib_wrap.sh.in +++ b/util/shlib_wrap.sh.in @@ -101,7 +101,7 @@ SunOS|IRIX*) ;; esac -{- output_off() if $config{ex_libs} !~ /,-rpath,/; ""; -} +{- output_off() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -} if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then # Following three lines are major excuse for isolating them into # this wrapper script. Original reason for setting LD_PRELOAD @@ -117,7 +117,7 @@ if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES fi -{- output_on() if $config{ex_libs} !~ /,-rpath,/; ""; -} +{- output_on() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -} cmd="$1"; [ -x "$cmd" ] || cmd="$cmd${EXE_EXT}" shift