Codebase list openssl / c1a1ee9
New upstream version 3.0.2 Sebastian Andrzej Siewior 2 years ago
269 changed file(s) with 5495 addition(s) and 1201 deletion(s). Raw diff Collapse all Expand all
2626 breaking changes, and mappings for the large list of deprecated functions.
2727
2828 [Migration guide]: https://github.com/openssl/openssl/tree/master/doc/man7/migration_guide.pod
29
30 ### Changes between 3.0.1 and 3.0.2 [15 Mar 2022]
31
32 * Fixed a bug in the BN_mod_sqrt() function that can cause it to loop forever
33 for non-prime moduli.
34
35 Internally this function is used when parsing certificates that contain
36 elliptic curve public keys in compressed form or explicit elliptic curve
37 parameters with a base point encoded in compressed form.
38
39 It is possible to trigger the infinite loop by crafting a certificate that
40 has invalid explicit curve parameters.
41
42 Since certificate parsing happens prior to verification of the certificate
43 signature, any process that parses an externally supplied certificate may thus
44 be subject to a denial of service attack. The infinite loop can also be
45 reached when parsing crafted private keys as they can contain explicit
46 elliptic curve parameters.
47
48 Thus vulnerable situations include:
49
50 - TLS clients consuming server certificates
51 - TLS servers consuming client certificates
52 - Hosting providers taking certificates or private keys from customers
53 - Certificate authorities parsing certification requests from subscribers
54 - Anything else which parses ASN.1 elliptic curve parameters
55
56 Also any other applications that use the BN_mod_sqrt() where the attacker
57 can control the parameter values are vulnerable to this DoS issue.
58 ([CVE-2022-0778])
59
60 *Tomáš Mráz*
61
62 * Add ciphersuites based on DHE_PSK (RFC 4279) and ECDHE_PSK (RFC 5489)
63 to the list of ciphersuites providing Perfect Forward Secrecy as
64 required by SECLEVEL >= 3.
65
66 *Dmitry Belyavskiy, Nicola Tuveri*
67
68 * Made the AES constant time code for no-asm configurations
69 optional due to the resulting 95% performance degradation.
70 The AES constant time code can be enabled, for no assembly
71 builds, with: ./config no-asm -DOPENSSL_AES_CONST_TIME
72
73 *Paul Dale*
74
75 * Fixed PEM_write_bio_PKCS8PrivateKey() to make it possible to use empty
76 passphrase strings.
77
78 *Darshan Sen*
79
80 * The negative return value handling of the certificate verification callback
81 was reverted. The replacement is to set the verification retry state with
82 the SSL_set_retry_verify() function.
83
84 *Tomáš Mráz*
2985
3086 ### Changes between 3.0.0 and 3.0.1 [14 Dec 2021]
3187
10591059 bn_ops => "SIXTY_FOUR_BIT_LONG",
10601060 asm_arch => 'x86_64',
10611061 perlasm_scheme => "elf",
1062 },
1063
1064 # riscv64 below refers to contemporary RISCV Architecture
1065 # specifications,
1066 "BSD-riscv64" => {
1067 inherit_from => [ "BSD-generic64"],
1068 perlasm_scheme => "linux64",
10621069 },
10631070
10641071 "bsdi-elf-gcc" => {
260260 bn_ops => add("RC4_INT"),
261261 asm_arch => 'x86',
262262 perlasm_scheme => "android",
263 ex_libs => add(threads("-latomic")),
263264 },
264265 "android-x86_64" => {
265266 inherit_from => [ "android" ],
552552 - DELETE descrip.mms;*
553553
554554 depend : descrip.mms
555 descrip.mms : FORCE
556555 @ ! {- output_off() if $disabled{makedepend}; "" -}
557556 @ $(PERL) {- sourcefile("util", "add-depends.pl") -} "{- $config{makedep_scheme} -}"
558557 @ ! {- output_on() if $disabled{makedepend}; "" -}
754753
755754 # Building targets ###################################################
756755
757 configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
756 descrip.mms : configdata.pm {- join(" ", @{$config{build_file_templates}}) -}
757 perl configdata.pm
758 @ WRITE SYS$OUTPUT "*************************************************"
759 @ WRITE SYS$OUTPUT "*** ***"
760 @ WRITE SYS$OUTPUT "*** Please run the same mms command again ***"
761 @ WRITE SYS$OUTPUT "*** ***"
762 @ WRITE SYS$OUTPUT "*************************************************"
763 @ PIPE ( EXIT %X10000000 )
764
765 configdata.pm : $(SRCDIR)Configure $(SRCDIR)config.com {- join(" ", @{$config{build_infos}}, @{$config{conf_files}}) -}
758766 perl configdata.pm -r
759767 @ WRITE SYS$OUTPUT "*************************************************"
760768 @ WRITE SYS$OUTPUT "*** ***"
870878 return ($filename, $scripture);
871879 }
872880
881 # On VMS, (some) header file directories include the files
882 # __DECC_INCLUDE_EPILOGUE.H and __DECC_INCLUDE_PROLOGUE.H.
883 # When header files are generated, and the build directory
884 # isn't the same as the source directory, these files must
885 # be copied alongside the generated header file, or their
886 # effect will be lost.
887 # We use the same include file cache as make_includefile
888 # to check if the scripture to copy these files has already
889 # been generated.
890 sub make_decc_include_files {
891 my $outd = shift;
892 my $ind = shift;
893
894 # If the build directory and the source directory are the
895 # same, there's no need to copy the prologue and epilogue
896 # files.
897 return ('') if $outd eq $ind;
898
899 my $outprologue = catfile($outd, '__DECC_INCLUDE_PROLOGUE.H');
900 my $outepilogue = catfile($outd, '__DECC_INCLUDE_EPILOGUE.H');
901 my $inprologue = catfile($ind, '__DECC_INCLUDE_PROLOGUE.H');
902 my $inepilogue = catfile($ind, '__DECC_INCLUDE_EPILOGUE.H');
903 my @filenames = ();
904 my $scripture = '';
905
906 if ($includefile_cache{$outprologue}) {
907 push @filenames, $outprologue;
908 } elsif (-f $inprologue) {
909 my $local_scripture .= <<"EOF";
910 $outprologue : $inprologue
911 COPY $inprologue $outprologue
912 EOF
913 $includefile_cache{$outprologue} = $local_scripture;
914
915 push @filenames, $outprologue;
916 $scripture .= $local_scripture;
917 }
918 if ($includefile_cache{$outepilogue}) {
919 push @filenames, $outepilogue;
920 } elsif (-f $inepilogue) {
921 my $local_scripture .= <<"EOF";
922 $outepilogue : $inepilogue
923 COPY $inepilogue $outepilogue
924 EOF
925 $includefile_cache{$outepilogue} = $local_scripture;
926
927 push @filenames, $outepilogue;
928 $scripture .= $local_scripture;
929 }
930
931 return (@filenames, $scripture);
932 }
933
873934 sub generatetarget {
874935 my %args = @_;
875936 my $deps = join(" ", compute_platform_depends(@{$args{deps}}));
9831044 my @perlmodules = ( 'configdata.pm',
9841045 grep { $_ =~ m|\.pm$| } @{$args{deps}} );
9851046 my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules;
986 $deps = join(' ', $deps, compute_platform_depends(@perlmodules));
1047 my @decc_include_data
1048 = make_decc_include_files(dirname($args{src}), dirname($gen0));
1049 my $decc_include_scripture = pop @decc_include_data;
1050 $deps = join(' ', $deps, @decc_include_data,
1051 compute_platform_depends(@perlmodules));
9871052 @perlmodules = map { '"-M'.basename($_, '.pm').'"' } @perlmodules;
9881053 my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules);
1054
9891055 return <<"EOF";
9901056 $args{src} : $gen0 $deps
9911057 \$(PERL)$perlmodules $dofile "-o$target{build_file}" $gen0$gen_args > \$\@
1058 $decc_include_scripture
9921059 EOF
9931060 } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) {
9941061 #
581581 $(RM) $(MANDOCS3)
582582 $(RM) $(MANDOCS5)
583583 $(RM) $(MANDOCS7)
584 $(RM) $(PROGRAMS) $(TESTPROGS) $(MODULES) $(SCRIPTS)
584 $(RM) $(PROGRAMS) $(TESTPROGS) $(MODULES) $(FIPSMODULE) $(SCRIPTS)
585585 $(RM) $(GENERATED_MANDATORY) $(GENERATED)
586586 -find . -name '*{- platform->depext() -}' \! -name '.*' \! -type d -exec $(RM) {} \;
587587 -find . -name '*{- platform->objext() -}' \! -name '.*' \! -type d -exec $(RM) {} \;
598598
599599 # We check if any depfile is newer than Makefile and decide to
600600 # concatenate only if that is true.
601 depend:
601 depend: Makefile
602602 @: {- output_off() if $disabled{makedepend}; "" -}
603603 @$(PERL) $(SRCDIR)/util/add-depends.pl "{- $makedep_scheme -}"
604604 @: {- output_on() if $disabled{makedepend}; "" -}
11521152 crypto/objects/obj_mac.num \
11531153 crypto/objects/obj_xref.txt \
11541154 > crypto/objects/obj_xref.h )
1155 ( cd $(SRCDIR); cat crypto/objects/obj_compat.h >> include/openssl/obj_mac.h )
1155 ( cd $(SRCDIR); sed -e '1,8d' crypto/objects/obj_compat.h >> include/openssl/obj_mac.h )
11561156
11571157 generate_crypto_conf:
11581158 ( cd $(SRCDIR); $(PERL) crypto/conf/keysets.pl \
13701370
13711371 link-utils: $(BLDDIR)/util/opensslwrap.sh $(BLDDIR)/apps/openssl.cnf
13721372
1373 $(BLDDIR)/util/opensslwrap.sh: configdata.pm
1373 $(BLDDIR)/util/opensslwrap.sh: Makefile
13741374 @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
13751375 mkdir -p "$(BLDDIR)/util"; \
13761376 ln -sf "../$(SRCDIR)/util/`basename "$@"`" "$(BLDDIR)/util"; \
13771377 fi
13781378
1379 $(BLDDIR)/apps/openssl.cnf: configdata.pm
1379 $(BLDDIR)/apps/openssl.cnf: Makefile
13801380 @if [ "$(SRCDIR)" != "$(BLDDIR)" ]; then \
13811381 mkdir -p "$(BLDDIR)/apps"; \
13821382 ln -sf "../$(SRCDIR)/apps/`basename "$@"`" "$(BLDDIR)/apps"; \
13861386
13871387 # Building targets ###################################################
13881388
1389 libcrypto.pc libssl.pc openssl.pc: configdata.pm $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // platform->sharedlib_import($_) // platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
1389 libcrypto.pc libssl.pc openssl.pc: Makefile $(LIBS) {- join(" ",map { platform->sharedlib_simple($_) // platform->sharedlib_import($_) // platform->sharedlib($_) // () } @{$unified_info{libraries}}) -}
1390
13901391 libcrypto.pc:
13911392 @ ( echo 'prefix=$(INSTALLTOP)'; \
13921393 echo 'exec_prefix=$${prefix}'; \
14371438 echo 'Version: '$(VERSION); \
14381439 echo 'Requires: libssl libcrypto' ) > openssl.pc
14391440
1441 Makefile: configdata.pm \
1442 {- join(" \\\n" . ' ' x 10,
1443 fill_lines(" ", $COLUMNS - 10,
1444 @{$config{build_file_templates}})) -}
1445 @echo "Detected changed: $?"
1446 $(PERL) configdata.pm
1447 @echo "**************************************************"
1448 @echo "*** ***"
1449 @echo "*** Please run the same make command again ***"
1450 @echo "*** ***"
1451 @echo "**************************************************"
1452 @false
1453
14401454 configdata.pm: $(SRCDIR)/Configure $(SRCDIR)/config \
14411455 {- join(" \\\n" . ' ' x 15,
14421456 fill_lines(" ", $COLUMNS - 15,
1443 @{$config{build_file_templates}},
14441457 @{$config{build_infos}},
14451458 @{$config{conf_files}})) -}
14461459 @echo "Detected changed: $?"
480480 -del /Q /F configdata.pm
481481 -del /Q /F makefile
482482
483 depend:
483 depend: makefile
484484 @ {- output_off() if $disabled{makedepend}; "\@rem" -}
485485 @ "$(PERL)" "$(SRCDIR)\util\add-depends.pl" "{- $target{makedep_scheme} -}"
486486 @ {- output_on() if $disabled{makedepend}; "\@rem" -}
642642
643643 copy-utils: $(BLDDIR)\apps\openssl.cnf
644644
645 $(BLDDIR)\apps\openssl.cnf: configdata.pm
645 $(BLDDIR)\apps\openssl.cnf: makefile
646646 @if NOT EXIST "$(BLDDIR)\apps" mkdir "$(BLDDIR)\apps"
647647 @if NOT "$(SRCDIR)"=="$(BLDDIR)" copy "$(SRCDIR)\apps\$(@F)" "$(BLDDIR)\apps"
648648
649649 # Building targets ###################################################
650650
651 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}, @{$config{build_infos}}, @{$config{conf_files}}) -}
651 makefile: configdata.pm {- join(" ", map { '"'.$_.'"' } @{$config{build_file_templates}}) -}
652 @$(ECHO) "Detected changed: $?"
653 "$(PERL)" configdata.pm
654 @$(ECHO) "**************************************************"
655 @$(ECHO) "*** ***"
656 @$(ECHO) "*** Please run the same make command again ***"
657 @$(ECHO) "*** ***"
658 @$(ECHO) "**************************************************"
659 @exit 1
660
661 configdata.pm: "$(SRCDIR)\Configure" {- join(" ", map { '"'.$_.'"' } @{$config{build_infos}}, @{$config{conf_files}}) -}
652662 @$(ECHO) "Detected changed: $?"
653663 "$(PERL)" configdata.pm -r
654664 @$(ECHO) "**************************************************"
31683168 }
31693169 }
31703170
3171 foreach (sort keys %all_keys) {
3172 my $previous = $combined_inheritance{$_};
3171 foreach my $key (sort keys %all_keys) {
3172 my $previous = $combined_inheritance{$key};
31733173
31743174 # Current target doesn't have a value for the current key?
31753175 # Assign it the default combiner, the rest of this loop body
31763176 # will handle it just like any other coderef.
3177 if (!exists $table{$target}->{$_}) {
3178 $table{$target}->{$_} = $default_combiner;
3179 }
3180
3181 $table{$target}->{$_} = process_values($table{$target}->{$_},
3182 $combined_inheritance{$_},
3183 $target, $_);
3184 unless(defined($table{$target}->{$_})) {
3185 delete $table{$target}->{$_};
3177 if (!exists $table{$target}->{$key}) {
3178 $table{$target}->{$key} = $default_combiner;
3179 }
3180
3181 $table{$target}->{$key} = process_values($table{$target}->{$key},
3182 $combined_inheritance{$key},
3183 $target, $key);
3184 unless(defined($table{$target}->{$key})) {
3185 delete $table{$target}->{$key};
31863186 }
31873187 # if ($extra_checks &&
3188 # $previous && !($add_called || $previous ~~ $table{$target}->{$_})) {
3189 # warn "$_ got replaced in $target\n";
3188 # $previous && !($add_called || $previous ~~ $table{$target}->{$key})) {
3189 # warn "$key got replaced in $target\n";
31903190 # }
31913191 }
31923192
1616
1717 OpenSSL 3.0
1818 -----------
19
20 ### Major changes between OpenSSL 3.0.1 and OpenSSL 3.0.2 [15 Mar 2022]
21
22 * Fixed a bug in the BN_mod_sqrt() function that can cause it to loop forever
23 for non-prime moduli ([CVE-2022-0778])
1924
2025 ### Major changes between OpenSSL 3.0.0 and OpenSSL 3.0.1 [14 Dec 2021]
2126
6363 Documentation about using the FIPS module is available on the [fips_module(7)]
6464 manual page.
6565
66 [fips_module(7)]: https://www.openssl.org/docs/manmaster/man7/fips_module.html
66 [fips_module(7)]: https://www.openssl.org/docs/man3.0/man7/fips_module.html
1919 Documentation about writing providers is available on the [provider(7)]
2020 manual page.
2121
22 [provider(7)]: https://www.openssl.org/docs/manmaster/man7/provider.html
22 [provider(7)]: https://www.openssl.org/docs/man3.0/man7/provider.html
2323
2424 The Default Provider
2525 --------------------
8787 See the [config(5)] manual page for information about how to configure
8888 providers via the config file, and how to automatically activate them.
8989
90 [config(5)]: https://www.openssl.org/docs/manmaster/man5/config.html
90 [config(5)]: https://www.openssl.org/docs/man3.0/man5/config.html
9191
9292 The following is a minimal config file example to load and activate both
9393 the legacy and the default provider in the default library context.
112112 * [Notes on Perl](NOTES-PERL.md)
113113 * [Notes on Valgrind](NOTES-VALGRIND.md)
114114
115 Specific notes on upgrading to OpenSSL 3.0 from previous versions, as well as
116 known issues are available on the [OpenSSL 3.0 Wiki] page.
115 Specific notes on upgrading to OpenSSL 3.0 from previous versions can be found
116 in the [migration_guide(7ossl)] manual page.
117117
118118 Documentation
119119 =============
125125 available online.
126126
127127 - [OpenSSL master](https://www.openssl.org/docs/manmaster)
128 - [OpenSSL 3.0](https://www.openssl.org/docs/man3.0)
128129 - [OpenSSL 1.1.1](https://www.openssl.org/docs/man1.1.1)
129130
130131 Wiki
164165 Copyright
165166 =========
166167
167 Copyright (c) 1998-2021 The OpenSSL Project
168 Copyright (c) 1998-2022 The OpenSSL Project
168169
169170 Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
170171
192193 <https://wiki.openssl.org>
193194 "OpenSSL Wiki"
194195
195 [OpenSSL 3.0 Wiki]:
196 <https://wiki.openssl.org/index.php/OpenSSL_3.0>
197 "OpenSSL 3.0 Wiki"
196 [migration_guide(7ossl)]:
197 <https://www.openssl.org/docs/man3.0/man7/migration_guide.html>
198 "OpenSSL Migration Guide"
198199
199200 [RFC 8446]:
200201 <https://tools.ietf.org/html/rfc8446>
00 MAJOR=3
11 MINOR=0
2 PATCH=1
2 PATCH=2
33 PRE_RELEASE_TAG=
44 BUILD_METADATA=
5 RELEASE_DATE="14 Dec 2021"
5 RELEASE_DATE="15 Mar 2022"
66 SHLIB_VERSION=3
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
186186 goto end;
187187 }
188188
189 ctx = SSL_CTX_new(meth);
189 ctx = SSL_CTX_new_ex(app_get0_libctx(), app_get0_propq(), meth);
190190 if (ctx == NULL)
191191 goto err;
192192 if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)
00 /*
1 * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright Nokia 2007-2019
33 * Copyright Siemens AG 2015-2019
44 *
160160 static char *opt_rspout = NULL;
161161 static int opt_use_mock_srv = 0;
162162
163 /* server-side debugging */
163 /* mock server */
164164 #ifndef OPENSSL_NO_SOCK
165165 static char *opt_port = NULL;
166166 static int opt_max_msgs = 0;
286286 {"subject", OPT_SUBJECT, 's',
287287 "Distinguished Name (DN) of subject to use in the requested cert template"},
288288 {OPT_MORE_STR, 0, 0,
289 "For kur, default is subject of -csr arg or else of reference cert (see -oldcert)"},
289 "For kur, default is subject of -csr arg or reference cert (see -oldcert)"},
290290 {OPT_MORE_STR, 0, 0,
291291 "this default is used for ir and cr only if no Subject Alt Names are set"},
292292 {"issuer", OPT_ISSUER, 's',
335335 {OPT_MORE_STR, 0, 0,
336336 "also used as reference (defaulting to -cert) for subject DN and SANs."},
337337 {OPT_MORE_STR, 0, 0,
338 "Its issuer is used as recipient unless -recipient, -srvcert, or -issuer given"},
338 "Issuer is used as recipient unless -recipient, -srvcert, or -issuer given"},
339339 {"revreason", OPT_REVREASON, 'n',
340340 "Reason code to include in revocation request (rr); possible values:"},
341341 {OPT_MORE_STR, 0, 0,
469469 "Process sequence of CMP responses provided in file(s), skipping server"},
470470 {"rspout", OPT_RSPOUT, 's', "Save sequence of CMP responses to file(s)"},
471471
472 {"use_mock_srv", OPT_USE_MOCK_SRV, '-', "Use mock server at API level, bypassing HTTP"},
472 {"use_mock_srv", OPT_USE_MOCK_SRV, '-',
473 "Use internal mock server at API level, bypassing socket-based HTTP"},
473474
474475 OPT_SECTION("Mock server"),
475476 #ifdef OPENSSL_NO_SOCK
476477 {OPT_MORE_STR, 0, 0,
477478 "NOTE: -port and -max_msgs not supported due to no-sock build"},
478479 #else
479 {"port", OPT_PORT, 's', "Act as HTTP mock server listening on given port"},
480 {"port", OPT_PORT, 's',
481 "Act as HTTP-based mock server listening on given port"},
480482 {"max_msgs", OPT_MAX_MSGS, 'N',
481483 "max number of messages handled by HTTP mock server. Default: 0 = unlimited"},
482484 #endif
9991001 if (opt_srv_ref == NULL) {
10001002 if (opt_srv_cert == NULL) {
10011003 /* opt_srv_cert should determine the sender */
1002 CMP_err("must give -srv_ref for server if no -srv_cert given");
1004 CMP_err("must give -srv_ref for mock server if no -srv_cert given");
10031005 goto err;
10041006 }
10051007 } else {
10101012
10111013 if (opt_srv_secret != NULL) {
10121014 int res;
1013 char *pass_str = get_passwd(opt_srv_secret, "PBMAC secret of server");
1015 char *pass_str = get_passwd(opt_srv_secret, "PBMAC secret of mock server");
10141016
10151017 if (pass_str != NULL) {
10161018 cleanse(opt_srv_secret);
10211023 goto err;
10221024 }
10231025 } else if (opt_srv_cert == NULL) {
1024 CMP_err("server credentials must be given if -use_mock_srv or -port is used");
1026 CMP_err("mock server credentials must be given if -use_mock_srv or -port is used");
10251027 goto err;
10261028 } else {
1027 CMP_warn("server will not be able to handle PBM-protected requests since -srv_secret is not given");
1029 CMP_warn("mock server will not be able to handle PBM-protected requests since -srv_secret is not given");
10281030 }
10291031
10301032 if (opt_srv_secret == NULL
10341036 }
10351037 if (opt_srv_cert != NULL) {
10361038 X509 *srv_cert = load_cert_pwd(opt_srv_cert, opt_srv_keypass,
1037 "certificate of the server");
1039 "certificate of the mock server");
10381040
10391041 if (srv_cert == NULL || !OSSL_CMP_CTX_set1_cert(ctx, srv_cert)) {
10401042 X509_free(srv_cert);
10451047 if (opt_srv_key != NULL) {
10461048 EVP_PKEY *pkey = load_key_pwd(opt_srv_key, opt_keyform,
10471049 opt_srv_keypass,
1048 engine, "private key for server cert");
1050 engine, "private key for mock server cert");
10491051
10501052 if (pkey == NULL || !OSSL_CMP_CTX_set1_pkey(ctx, pkey)) {
10511053 EVP_PKEY_free(pkey);
10571059
10581060 if (opt_srv_trusted != NULL) {
10591061 X509_STORE *ts =
1060 load_trusted(opt_srv_trusted, 0, "certs trusted by server");
1062 load_trusted(opt_srv_trusted, 0, "certs trusted by mock server");
10611063
10621064 if (ts == NULL || !OSSL_CMP_CTX_set0_trustedStore(ctx, ts)) {
10631065 X509_STORE_free(ts);
10641066 goto err;
10651067 }
10661068 } else {
1067 CMP_warn("server will not be able to handle signature-protected requests since -srv_trusted is not given");
1069 CMP_warn("mock server will not be able to handle signature-protected requests since -srv_trusted is not given");
10681070 }
10691071 if (!setup_certs(opt_srv_untrusted,
10701072 "untrusted certificates for mock server", ctx,
10721074 goto err;
10731075
10741076 if (opt_rsp_cert == NULL) {
1075 CMP_err("must give -rsp_cert for mock server");
1076 goto err;
1077 CMP_warn("no -rsp_cert given for mock server");
10771078 } else {
10781079 X509 *cert = load_cert_pwd(opt_rsp_cert, opt_keypass,
10791080 "cert to be returned by the mock server");
18041805 static char server_port[32] = { '\0' };
18051806 const char *proxy_host = NULL;
18061807 #endif
1807 char server_buf[200] = { '\0' };
1808 char proxy_buf[200] = { '\0' };
1809
1808 char server_buf[200] = "mock server";
1809 char proxy_buf[200] = "";
1810
1811 if (!opt_use_mock_srv && opt_rspin == NULL) { /* note: -port is not given */
1812 #ifndef OPENSSL_NO_SOCK
1813 if (opt_server == NULL) {
1814 CMP_err("missing -server or -use_mock_srv or -rspin option");
1815 goto err;
1816 }
1817 #else
1818 CMP_err("missing -use_mock_srv or -rspin option; -server option is not supported due to no-sock build");
1819 goto err;
1820 #endif
1821 }
18101822 #ifndef OPENSSL_NO_SOCK
18111823 if (opt_server == NULL) {
1812 CMP_err("missing -server option");
1813 goto err;
1824 if (opt_proxy != NULL)
1825 CMP_warn("ignoring -proxy option since -server is not given");
1826 if (opt_no_proxy != NULL)
1827 CMP_warn("ignoring -no_proxy option since -server is not given");
1828 if (opt_tls_used) {
1829 CMP_warn("ignoring -tls_used option since -server is not given");
1830 opt_tls_used = 0;
1831 }
1832 goto set_path;
18141833 }
18151834 if (!OSSL_HTTP_parse_url(opt_server, &ssl, NULL /* user */, &host, &port,
18161835 &portnum, &path, NULL /* q */, NULL /* frag */)) {
18401859 if (proxy_host != NULL)
18411860 (void)BIO_snprintf(proxy_buf, sizeof(proxy_buf), " via %s", proxy_host);
18421861
1862 set_path:
18431863 #endif
18441864
18451865 if (!OSSL_CMP_CTX_set1_serverPath(ctx, used_path))
18851905 (void)OSSL_CMP_CTX_set_transfer_cb(ctx, read_write_req_resp);
18861906
18871907 #ifndef OPENSSL_NO_SOCK
1888 if ((opt_tls_cert != NULL || opt_tls_key != NULL
1889 || opt_tls_keypass != NULL || opt_tls_extra != NULL
1890 || opt_tls_trusted != NULL || opt_tls_host != NULL)
1891 && !opt_tls_used)
1892 CMP_warn("TLS options(s) given but not -tls_used");
18931908 if (opt_tls_used) {
18941909 APP_HTTP_TLS_INFO *info;
18951910
19031918 goto err;
19041919 }
19051920 }
1906 if (opt_use_mock_srv) {
1907 CMP_err("cannot use TLS options together with -use_mock_srv");
1908 goto err;
1909 }
1921
19101922 if ((info = OPENSSL_zalloc(sizeof(*info))) == NULL)
19111923 goto err;
19121924 (void)OSSL_CMP_CTX_set_http_cb_arg(ctx, info);
19131925 /* info will be freed along with CMP ctx */
19141926 info->server = opt_server;
19151927 info->port = server_port;
1916 info->use_proxy = opt_proxy != NULL;
1928 /* workaround for callback design flaw, see #17088: */
1929 info->use_proxy = proxy_host != NULL;
19171930 info->timeout = OSSL_CMP_CTX_get_option(ctx, OSSL_CMP_OPT_MSG_TIMEOUT);
19181931 info->ssl_ctx = setup_ssl_ctx(ctx, host, engine);
1932
19191933 if (info->ssl_ctx == NULL)
19201934 goto err;
19211935 (void)OSSL_CMP_CTX_set_http_cb(ctx, app_http_tls_cb);
19371951 goto err;
19381952
19391953 /* not printing earlier, to minimize confusion in case setup fails before */
1940 CMP_info2("will contact %s%s", server_buf, proxy_buf);
1954 if (opt_rspin != NULL)
1955 CMP_info("will not contact any server since -rspin is given");
1956 else
1957 CMP_info2("will contact %s%s", server_buf, proxy_buf);
19411958
19421959 ret = 1;
19431960
26912708 int i;
26922709 X509 *newcert = NULL;
26932710 ENGINE *engine = NULL;
2694 #ifndef OPENSSL_NO_SOCK
2695 char mock_server[] = "mock server:1";
2696 #endif
26972711 OSSL_CMP_CTX *srv_cmp_ctx = NULL;
26982712 int ret = 0; /* default: failure */
26992713
27842798 }
27852799 }
27862800
2787 #ifndef OPENSSL_NO_SOCK
2788 if (opt_port != NULL) {
2789 if (opt_use_mock_srv) {
2790 CMP_err("cannot use both -port and -use_mock_srv options");
2791 goto err;
2792 }
2793 if (opt_server != NULL) {
2794 CMP_err("cannot use both -port and -server options");
2795 goto err;
2796 }
2797 }
2798 #endif
2799
28002801 cmp_ctx = OSSL_CMP_CTX_new(app_get0_libctx(), app_get0_propq());
28012802 if (cmp_ctx == NULL)
28022803 goto err;
28052806 CMP_err1("cannot set up error reporting and logging for %s", prog);
28062807 goto err;
28072808 }
2809
2810 #ifndef OPENSSL_NO_SOCK
2811 if ((opt_tls_cert != NULL || opt_tls_key != NULL
2812 || opt_tls_keypass != NULL || opt_tls_extra != NULL
2813 || opt_tls_trusted != NULL || opt_tls_host != NULL)
2814 && !opt_tls_used)
2815 CMP_warn("Ingnoring TLS options(s) since -tls_used is not given");
2816 if (opt_port != NULL) {
2817 if (opt_tls_used) {
2818 CMP_err("-tls_used option not supported with -port option");
2819 goto err;
2820 }
2821 if (opt_use_mock_srv || opt_server != NULL || opt_rspin != NULL) {
2822 CMP_err("cannot use -port with -use_mock_srv, -server, or -rspin options");
2823 goto err;
2824 }
2825 }
2826 if (opt_server != NULL && opt_use_mock_srv) {
2827 CMP_err("cannot use both -server and -use_mock_srv options");
2828 goto err;
2829 }
2830 #endif
2831 if (opt_rspin != NULL && opt_use_mock_srv) {
2832 CMP_err("cannot use both -rspin and -use_mock_srv options");
2833 goto err;
2834 }
2835
28082836 if (opt_use_mock_srv
28092837 #ifndef OPENSSL_NO_SOCK
28102838 || opt_port != NULL
28232851 OSSL_CMP_CTX_set_log_verbosity(srv_cmp_ctx, opt_verbosity);
28242852 }
28252853
2826
28272854 #ifndef OPENSSL_NO_SOCK
2855 if (opt_tls_used && (opt_use_mock_srv || opt_rspin != NULL)) {
2856 CMP_warn("ignoring -tls_used option since -use_mock_srv or -rspin is given");
2857 opt_tls_used = 0;
2858 }
2859
28282860 if (opt_port != NULL) { /* act as very basic CMP HTTP server */
28292861 ret = cmp_server(srv_cmp_ctx);
28302862 goto err;
28312863 }
2832 #endif
2833 /* else act as CMP client */
2834
2835 if (opt_use_mock_srv) {
2836 #ifndef OPENSSL_NO_SOCK
2837 if (opt_server != NULL) {
2838 CMP_err("cannot use both -use_mock_srv and -server options");
2839 goto err;
2840 }
2841 if (opt_proxy != NULL) {
2842 CMP_err("cannot use both -use_mock_srv and -proxy options");
2843 goto err;
2844 }
2845 opt_server = mock_server;
2846 opt_proxy = "API";
2847 #endif
2848 }
2864
2865 /* act as CMP client, possibly using internal mock server */
2866
2867 if (opt_server != NULL) {
2868 if (opt_rspin != NULL) {
2869 CMP_warn("ignoring -server option since -rspin is given");
2870 opt_server = NULL;
2871 }
2872 }
2873 #endif
28492874
28502875 if (!setup_client_ctx(cmp_ctx, engine)) {
28512876 CMP_err("cannot set up CMP context");
00 /*
1 * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
3 * Licensed under the OpenSSL license (the "License"). You may not use
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
55 * in the file LICENSE in the source distribution or at
66 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
290290 i = atoi(arg + 3);
291291 if (i >= 0)
292292 pwdbio = BIO_new_fd(i, BIO_NOCLOSE);
293 if ((i < 0) || !pwdbio) {
293 if ((i < 0) || pwdbio == NULL) {
294294 BIO_printf(bio_err, "Can't access file descriptor %s\n", arg + 3);
295295 return NULL;
296296 }
298298 * Can't do BIO_gets on an fd BIO so add a buffering BIO
299299 */
300300 btmp = BIO_new(BIO_f_buffer());
301 if (btmp == NULL) {
302 BIO_free_all(pwdbio);
303 pwdbio = NULL;
304 BIO_printf(bio_err, "Out of memory\n");
305 return NULL;
306 }
301307 pwdbio = BIO_push(btmp, pwdbio);
302308 #endif
303309 } else if (strcmp(arg, "stdin") == 0) {
695701 if (ret) {
696702 if (pcert != NULL)
697703 warn_cert(uri, *pcert, 0, vpm);
698 warn_certs(uri, *pcerts, 1, vpm);
704 if (pcerts != NULL)
705 warn_certs(uri, *pcerts, 1, vpm);
699706 } else {
700 sk_X509_pop_free(*pcerts, X509_free);
701 *pcerts = NULL;
707 if (pcerts != NULL) {
708 sk_X509_pop_free(*pcerts, X509_free);
709 *pcerts = NULL;
710 }
702711 }
703712 return ret;
704713 }
24412450 }
24422451
24432452 /* HTTP callback function that supports TLS connection also via HTTPS proxy */
2444 BIO *app_http_tls_cb(BIO *hbio, void *arg, int connect, int detail)
2445 {
2453 BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail)
2454 {
2455 APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg;
2456 SSL_CTX *ssl_ctx = info->ssl_ctx;
2457
24462458 if (connect && detail) { /* connecting with TLS */
2447 APP_HTTP_TLS_INFO *info = (APP_HTTP_TLS_INFO *)arg;
2448 SSL_CTX *ssl_ctx = info->ssl_ctx;
24492459 SSL *ssl;
24502460 BIO *sbio = NULL;
24512461
2462 /* adapt after fixing callback design flaw, see #17088 */
24522463 if ((info->use_proxy
2453 && !OSSL_HTTP_proxy_connect(hbio, info->server, info->port,
2464 && !OSSL_HTTP_proxy_connect(bio, info->server, info->port,
24542465 NULL, NULL, /* no proxy credentials */
24552466 info->timeout, bio_err, opt_getprog()))
24562467 || (sbio = BIO_new(BIO_f_ssl())) == NULL) {
24612472 return NULL;
24622473 }
24632474
2464 SSL_set_tlsext_host_name(ssl, info->server);
2475 /* adapt after fixing callback design flaw, see #17088 */
2476 SSL_set_tlsext_host_name(ssl, info->server); /* not critical to do */
24652477
24662478 SSL_set_connect_state(ssl);
24672479 BIO_set_ssl(sbio, ssl, BIO_CLOSE);
24682480
2469 hbio = BIO_push(sbio, hbio);
2470 } else if (!connect && !detail) { /* disconnecting after error */
2471 const char *hint = tls_error_hint();
2472
2473 if (hint != NULL)
2474 ERR_add_error_data(2, " : ", hint);
2475 /*
2476 * If we pop sbio and BIO_free() it this may lead to libssl double free.
2477 * Rely on BIO_free_all() done by OSSL_HTTP_transfer() in http_client.c
2478 */
2479 }
2480 return hbio;
2481 bio = BIO_push(sbio, bio);
2482 }
2483 if (!connect) {
2484 const char *hint;
2485 BIO *cbio;
2486
2487 if (!detail) { /* disconnecting after error */
2488 hint = tls_error_hint();
2489 if (hint != NULL)
2490 ERR_add_error_data(2, " : ", hint);
2491 }
2492 if (ssl_ctx != NULL) {
2493 (void)ERR_set_mark();
2494 BIO_ssl_shutdown(bio);
2495 cbio = BIO_pop(bio); /* connect+HTTP BIO */
2496 BIO_free(bio); /* SSL BIO */
2497 (void)ERR_pop_to_mark(); /* hide SSL_R_READ_BIO_NOT_SET etc. */
2498 bio = cbio;
2499 }
2500 }
2501 return bio;
24812502 }
24822503
24832504 void APP_HTTP_TLS_INFO_free(APP_HTTP_TLS_INFO *info)
25172538
25182539 info.server = server;
25192540 info.port = port;
2520 info.use_proxy = proxy != NULL;
2541 info.use_proxy = /* workaround for callback design flaw, see #17088 */
2542 OSSL_HTTP_adapt_proxy(proxy, no_proxy, server, use_ssl) != NULL;
25212543 info.timeout = timeout;
25222544 info.ssl_ctx = ssl_ctx;
25232545 mem = OSSL_HTTP_get(url, proxy, no_proxy, NULL /* bio */, NULL /* rbio */,
25432565 const char *expected_content_type,
25442566 long timeout, const ASN1_ITEM *rsp_it)
25452567 {
2568 int use_ssl = ssl_ctx != NULL;
25462569 APP_HTTP_TLS_INFO info;
25472570 BIO *rsp, *req_mem = ASN1_item_i2d_mem_bio(req_it, req);
25482571 ASN1_VALUE *res;
25492572
25502573 if (req_mem == NULL)
25512574 return NULL;
2575
25522576 info.server = host;
25532577 info.port = port;
2554 info.use_proxy = proxy != NULL;
2578 info.use_proxy = /* workaround for callback design flaw, see #17088 */
2579 OSSL_HTTP_adapt_proxy(proxy, no_proxy, host, use_ssl) != NULL;
25552580 info.timeout = timeout;
25562581 info.ssl_ctx = ssl_ctx;
2557 rsp = OSSL_HTTP_transfer(NULL, host, port, path, ssl_ctx != NULL,
2582 rsp = OSSL_HTTP_transfer(NULL, host, port, path, use_ssl,
25582583 proxy, no_proxy, NULL /* bio */, NULL /* rbio */,
25592584 app_http_tls_cb, &info,
25602585 0 /* buf_size */, headers, content_type, req_mem,
00 /*
1 * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
3 * Licensed under the OpenSSL license (the "License"). You may not use
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
55 * in the file LICENSE in the source distribution or at
66 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
161161 #endif
162162
163163 if (!BIO_connect(*sock, BIO_ADDRINFO_address(ai),
164 protocol == IPPROTO_TCP ? BIO_SOCK_NODELAY : 0)) {
164 BIO_ADDRINFO_protocol(ai) == IPPROTO_TCP ? BIO_SOCK_NODELAY : 0)) {
165165 BIO_closesocket(*sock);
166166 *sock = INVALID_SOCKET;
167167 continue;
00 /*
1 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
11751175 bn = ASN1_INTEGER_to_BN(ser, NULL);
11761176 OPENSSL_assert(bn); /* FIXME: should report an error at this
11771177 * point and abort */
1178 if (BN_is_zero(bn))
1178 if (BN_is_zero(bn)) {
11791179 itmp = OPENSSL_strdup("00");
1180 else
1180 OPENSSL_assert(itmp);
1181 } else {
11811182 itmp = BN_bn2hex(bn);
1183 }
11821184 row[DB_serial] = itmp;
11831185 BN_free(bn);
11841186 rrow = TXT_DB_get_by_index(db->db, DB_serial, row);
00 /*
1 * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
409409 n >>= 1;
410410 }
411411 if (!EVP_DigestFinal_ex(md, buf, NULL))
412 return NULL;
412 goto err;
413413
414414 for (i = 0; i < 1000; i++) {
415415 if (!EVP_DigestInit_ex(md2, EVP_md5(), NULL))
635635 n >>= 1;
636636 }
637637 if (!EVP_DigestFinal_ex(md, buf, NULL))
638 return NULL;
638 goto err;
639639
640640 /* P sequence */
641641 if (!EVP_DigestInit_ex(md2, sha, NULL))
646646 goto err;
647647
648648 if (!EVP_DigestFinal_ex(md2, temp_buf, NULL))
649 return NULL;
649 goto err;
650650
651651 if ((p_bytes = OPENSSL_zalloc(passwd_len)) == NULL)
652652 goto err;
663663 goto err;
664664
665665 if (!EVP_DigestFinal_ex(md2, temp_buf, NULL))
666 return NULL;
666 goto err;
667667
668668 if ((s_bytes = OPENSSL_zalloc(salt_len)) == NULL)
669669 goto err;
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
463463 }
464464 goto end;
465465 }
466 if (kdflen != 0) {
467 buf_outlen = kdflen;
468 rv = 1;
466 if (rawin) {
467 /* rawin allocates the buffer in do_raw_keyop() */
468 rv = do_raw_keyop(pkey_op, mctx, pkey, in, filesize, NULL, 0,
469 &buf_out, (size_t *)&buf_outlen);
469470 } else {
470 if (rawin) {
471 /* rawin allocates the buffer in do_raw_keyop() */
472 rv = do_raw_keyop(pkey_op, mctx, pkey, in, filesize, NULL, 0,
473 &buf_out, (size_t *)&buf_outlen);
471 if (kdflen != 0) {
472 buf_outlen = kdflen;
473 rv = 1;
474474 } else {
475475 rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
476476 buf_in, (size_t)buf_inlen);
477 if (rv > 0 && buf_outlen != 0) {
478 buf_out = app_malloc(buf_outlen, "buffer output");
479 rv = do_keyop(ctx, pkey_op,
480 buf_out, (size_t *)&buf_outlen,
481 buf_in, (size_t)buf_inlen);
482 }
477 }
478 if (rv > 0 && buf_outlen != 0) {
479 buf_out = app_malloc(buf_outlen, "buffer output");
480 rv = do_keyop(ctx, pkey_op,
481 buf_out, (size_t *)&buf_outlen,
482 buf_in, (size_t)buf_inlen);
483483 }
484484 }
485485 if (rv <= 0) {
00 #! /usr/bin/env perl
1 # Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
2020 my %commands = ();
2121 my $cmdre = qr/^\s*int\s+([a-z_][a-z0-9_]*)_main\(\s*int\s+argc\s*,/;
2222 my $apps_openssl = shift @ARGV;
23 my $YEAR = [localtime()]->[5] + 1900;
23 my $YEAR = [gmtime($ENV{SOURCE_DATE_EPOCH} || time())]->[5] + 1900;
2424
2525 # because the program apps/openssl has object files as sources, and
2626 # they then have the corresponding C files as source, we need to chain
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2013-2014 Timo Teräs <timo.teras@gmail.com>
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
167167 *ep = nilhentry;
168168 ep->old_id = ~0;
169169 ep->filename = OPENSSL_strdup(filename);
170 if (ep->filename == NULL) {
171 OPENSSL_free(ep);
172 ep = NULL;
173 BIO_printf(bio_err, "out of memory\n");
174 return 1;
175 }
170176 if (bp->last_entry)
171177 bp->last_entry->next = ep;
172178 if (bp->first_entry == NULL)
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
774774 }
775775 }
776776 if (newreq || gen_x509) {
777 if (pkey == NULL /* can happen only if !newreq */) {
778 BIO_printf(bio_err, "Must provide a signature key using -key\n");
777 if (CAcert == NULL && pkey == NULL) {
778 BIO_printf(bio_err, "Must provide a signature key using -key or"
779 " provide -CA / -CAkey\n");
779780 goto end;
780781 }
781782
15931594 *pkeytype = OPENSSL_strndup(keytype, keytypelen);
15941595 else
15951596 *pkeytype = OPENSSL_strdup(keytype);
1597
1598 if (*pkeytype == NULL) {
1599 BIO_printf(bio_err, "Out of memory\n");
1600 EVP_PKEY_free(param);
1601 return NULL;
1602 }
1603
15961604 if (keylen >= 0)
15971605 *pkeylen = keylen;
15981606
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2005 Nokia. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
804804 char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
805805 char *chCApath = NULL, *chCAfile = NULL, *chCAstore = NULL, *host = NULL;
806806 char *thost = NULL, *tport = NULL;
807 char *port = OPENSSL_strdup(PORT);
807 char *port = NULL;
808808 char *bindhost = NULL, *bindport = NULL;
809809 char *passarg = NULL, *pass = NULL;
810810 char *vfyCApath = NULL, *vfyCAfile = NULL, *vfyCAstore = NULL;
842842 struct timeval tv;
843843 #endif
844844 const char *servername = NULL;
845 char *sname_alloc = NULL;
845846 int noservername = 0;
846847 const char *alpn_in = NULL;
847848 tlsextctx tlsextcbp = { NULL, 0 };
902903 c_debug = 0;
903904 c_showcerts = 0;
904905 c_nbio = 0;
906 port = OPENSSL_strdup(PORT);
905907 vpm = X509_VERIFY_PARAM_new();
906908 cctx = SSL_CONF_CTX_new();
907909
908 if (vpm == NULL || cctx == NULL) {
910 if (port == NULL || vpm == NULL || cctx == NULL) {
909911 BIO_printf(bio_err, "%s: out of memory\n", opt_getprog());
910912 goto end;
911913 }
11301132 break;
11311133 case OPT_MSGFILE:
11321134 bio_c_msg = BIO_new_file(opt_arg(), "w");
1135 if (bio_c_msg == NULL) {
1136 BIO_printf(bio_err, "Error writing file %s\n", opt_arg());
1137 goto end;
1138 }
11331139 break;
11341140 case OPT_TRACE:
11351141 #ifndef OPENSSL_NO_SSL_TRACE
15291535 goto opthelp;
15301536 }
15311537
1538 if (servername == NULL && !noservername) {
1539 servername = sname_alloc = OPENSSL_strdup(host);
1540 if (sname_alloc == NULL) {
1541 BIO_printf(bio_err, "%s: out of memory\n", prog);
1542 goto end;
1543 }
1544 }
1545
15321546 /* Retain the original target host:port for use in the HTTP proxy connect string */
15331547 thost = OPENSSL_strdup(host);
15341548 tport = OPENSSL_strdup(port);
16501664 if (bio_c_out == NULL) {
16511665 if (c_quiet && !c_debug) {
16521666 bio_c_out = BIO_new(BIO_s_null());
1653 if (c_msg && bio_c_msg == NULL)
1667 if (c_msg && bio_c_msg == NULL) {
16541668 bio_c_msg = dup_bio_out(FORMAT_TEXT);
1655 } else if (bio_c_out == NULL)
1669 if (bio_c_msg == NULL) {
1670 BIO_printf(bio_err, "Out of memory\n");
1671 goto end;
1672 }
1673 }
1674 } else {
16561675 bio_c_out = dup_bio_out(FORMAT_TEXT);
1676 }
1677
1678 if (bio_c_out == NULL) {
1679 BIO_printf(bio_err, "Unable to create BIO\n");
1680 goto end;
1681 }
16571682 }
16581683 #ifndef OPENSSL_NO_SRP
16591684 if (!app_passwd(srppass, NULL, &srp_arg.srppassin, NULL)) {
20162041 #endif
20172042 sbio = BIO_new_dgram(sock, BIO_NOCLOSE);
20182043
2019 if ((peer_info.addr = BIO_ADDR_new()) == NULL) {
2044 if (sbio == NULL || (peer_info.addr = BIO_ADDR_new()) == NULL) {
20202045 BIO_printf(bio_err, "memory allocation failure\n");
2046 BIO_free(sbio);
20212047 BIO_closesocket(sock);
20222048 goto end;
20232049 }
20242050 if (!BIO_sock_info(sock, BIO_SOCK_INFO_ADDRESS, &peer_info)) {
20252051 BIO_printf(bio_err, "getsockname:errno=%d\n",
20262052 get_last_socket_error());
2053 BIO_free(sbio);
20272054 BIO_ADDR_free(peer_info.addr);
20282055 BIO_closesocket(sock);
20292056 goto end;
20642091 #endif /* OPENSSL_NO_DTLS */
20652092 sbio = BIO_new_socket(sock, BIO_NOCLOSE);
20662093
2094 if (sbio == NULL) {
2095 BIO_printf(bio_err, "Unable to create BIO\n");
2096 ERR_print_errors(bio_err);
2097 BIO_closesocket(sock);
2098 goto end;
2099 }
2100
20672101 if (nbio_test) {
20682102 BIO *test;
20692103
20702104 test = BIO_new(BIO_f_nbio_test());
2105 if (test == NULL) {
2106 BIO_printf(bio_err, "Unable to create BIO\n");
2107 BIO_free(sbio);
2108 goto shut;
2109 }
20712110 sbio = BIO_push(test, sbio);
20722111 }
20732112
21342173 int foundit = 0;
21352174 BIO *fbio = BIO_new(BIO_f_buffer());
21362175
2176 if (fbio == NULL) {
2177 BIO_printf(bio_err, "Unable to create BIO\n");
2178 goto shut;
2179 }
21372180 BIO_push(fbio, sbio);
21382181 /* Wait for multi-line response to end from LMTP or SMTP */
21392182 do {
21822225 int foundit = 0;
21832226 BIO *fbio = BIO_new(BIO_f_buffer());
21842227
2228 if (fbio == NULL) {
2229 BIO_printf(bio_err, "Unable to create BIO\n");
2230 goto shut;
2231 }
21852232 BIO_push(fbio, sbio);
21862233 BIO_gets(fbio, mbuf, BUFSIZZ);
21872234 /* STARTTLS command requires CAPABILITY... */
22092256 {
22102257 BIO *fbio = BIO_new(BIO_f_buffer());
22112258
2259 if (fbio == NULL) {
2260 BIO_printf(bio_err, "Unable to create BIO\n");
2261 goto shut;
2262 }
22122263 BIO_push(fbio, sbio);
22132264 /* wait for multi-line response to end from FTP */
22142265 do {
23032354 int numeric;
23042355 BIO *fbio = BIO_new(BIO_f_buffer());
23052356
2357 if (fbio == NULL) {
2358 BIO_printf(bio_err, "Unable to create BIO\n");
2359 goto end;
2360 }
23062361 BIO_push(fbio, sbio);
23072362 BIO_printf(fbio, "STARTTLS\r\n");
23082363 (void)BIO_flush(fbio);
24632518 int foundit = 0;
24642519 BIO *fbio = BIO_new(BIO_f_buffer());
24652520
2521 if (fbio == NULL) {
2522 BIO_printf(bio_err, "Unable to create BIO\n");
2523 goto end;
2524 }
24662525 BIO_push(fbio, sbio);
24672526 BIO_gets(fbio, mbuf, BUFSIZZ);
24682527 /* STARTTLS command requires CAPABILITIES... */
25032562 int foundit = 0;
25042563 BIO *fbio = BIO_new(BIO_f_buffer());
25052564
2565 if (fbio == NULL) {
2566 BIO_printf(bio_err, "Unable to create BIO\n");
2567 goto end;
2568 }
25062569 BIO_push(fbio, sbio);
25072570 /* wait for multi-line response to end from Sieve */
25082571 do {
25622625 BIO *ldapbio = BIO_new(BIO_s_mem());
25632626 CONF *cnf = NCONF_new(NULL);
25642627
2565 if (cnf == NULL) {
2628 if (ldapbio == NULL || cnf == NULL) {
25662629 BIO_free(ldapbio);
2630 NCONF_free(cnf);
25672631 goto end;
25682632 }
25692633 BIO_puts(ldapbio, ldap_tls_genconf);
30373101 #ifndef OPENSSL_NO_SRP
30383102 OPENSSL_free(srp_arg.srppassin);
30393103 #endif
3104 OPENSSL_free(sname_alloc);
30403105 OPENSSL_free(connectstr);
30413106 OPENSSL_free(bindstr);
30423107 OPENSSL_free(bindhost);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
10051005 int socket_family = AF_UNSPEC, socket_type = SOCK_STREAM, protocol = 0;
10061006 int state = 0, crl_format = FORMAT_UNDEF, crl_download = 0;
10071007 char *host = NULL;
1008 char *port = OPENSSL_strdup(PORT);
1008 char *port = NULL;
10091009 unsigned char *context = NULL;
10101010 OPTION_CHOICE o;
10111011 EVP_PKEY *s_key2 = NULL;
10681068 async = 0;
10691069 use_sendfile = 0;
10701070
1071 port = OPENSSL_strdup(PORT);
10711072 cctx = SSL_CONF_CTX_new();
10721073 vpm = X509_VERIFY_PARAM_new();
1073 if (cctx == NULL || vpm == NULL)
1074 if (port == NULL || cctx == NULL || vpm == NULL)
10741075 goto end;
10751076 SSL_CONF_CTX_set_flags(cctx,
10761077 SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CMDLINE);
13881389 break;
13891390 case OPT_MSGFILE:
13901391 bio_s_msg = BIO_new_file(opt_arg(), "w");
1392 if (bio_s_msg == NULL) {
1393 BIO_printf(bio_err, "Error writing file %s\n", opt_arg());
1394 goto end;
1395 }
13911396 break;
13921397 case OPT_TRACE:
13931398 #ifndef OPENSSL_NO_SSL_TRACE
17991804 if (bio_s_out == NULL) {
18001805 if (s_quiet && !s_debug) {
18011806 bio_s_out = BIO_new(BIO_s_null());
1802 if (s_msg && bio_s_msg == NULL)
1807 if (s_msg && bio_s_msg == NULL) {
18031808 bio_s_msg = dup_bio_out(FORMAT_TEXT);
1809 if (bio_s_msg == NULL) {
1810 BIO_printf(bio_err, "Out of memory\n");
1811 goto end;
1812 }
1813 }
18041814 } else {
1805 if (bio_s_out == NULL)
1806 bio_s_out = dup_bio_out(FORMAT_TEXT);
1807 }
1808 }
1815 bio_s_out = dup_bio_out(FORMAT_TEXT);
1816 }
1817 }
1818
1819 if (bio_s_out == NULL)
1820 goto end;
1821
18091822 if (nocert) {
18101823 s_cert_file = NULL;
18111824 s_key_file = NULL;
23432356 else
23442357 # endif
23452358 sbio = BIO_new_dgram(s, BIO_NOCLOSE);
2359 if (sbio == NULL) {
2360 BIO_printf(bio_err, "Unable to create BIO\n");
2361 ERR_print_errors(bio_err);
2362 goto err;
2363 }
23462364
23472365 if (enable_timeouts) {
23482366 timeout.tv_sec = 0;
23922410 BIO *test;
23932411
23942412 test = BIO_new(BIO_f_nbio_test());
2413 if (test == NULL) {
2414 BIO_printf(bio_err, "Unable to create BIO\n");
2415 ret = -1;
2416 BIO_free(sbio);
2417 goto err;
2418 }
2419
23952420 sbio = BIO_push(test, sbio);
23962421 }
23972422
29753000 int total_bytes = 0;
29763001 #endif
29773002 int width;
3003 #ifndef OPENSSL_NO_KTLS
3004 int use_sendfile_for_req = use_sendfile;
3005 #endif
29783006 fd_set readfds;
29793007 const char *opmode;
3008 #ifdef CHARSET_EBCDIC
3009 BIO *filter;
3010 #endif
29803011
29813012 /* Set width for a select call if needed */
29823013 width = s + 1;
29833014
2984 buf = app_malloc(bufsize, "server www buffer");
3015 /* as we use BIO_gets(), and it always null terminates data, we need
3016 * to allocate 1 byte longer buffer to fit the full 2^14 byte record */
3017 buf = app_malloc(bufsize + 1, "server www buffer");
29853018 io = BIO_new(BIO_f_buffer());
29863019 ssl_bio = BIO_new(BIO_f_ssl());
29873020 if ((io == NULL) || (ssl_bio == NULL))
30143047 }
30153048
30163049 sbio = BIO_new_socket(s, BIO_NOCLOSE);
3050 if (sbio == NULL) {
3051 SSL_free(con);
3052 goto err;
3053 }
3054
30173055 if (s_nbio_test) {
30183056 BIO *test;
30193057
30203058 test = BIO_new(BIO_f_nbio_test());
3059 if (test == NULL) {
3060 SSL_free(con);
3061 BIO_free(sbio);
3062 goto err;
3063 }
3064
30213065 sbio = BIO_push(test, sbio);
30223066 }
30233067 SSL_set_bio(con, sbio, sbio);
30283072 BIO_push(io, ssl_bio);
30293073 ssl_bio = NULL;
30303074 #ifdef CHARSET_EBCDIC
3031 io = BIO_push(BIO_new(BIO_f_ebcdic_filter()), io);
3075 filter = BIO_new(BIO_f_ebcdic_filter());
3076 if (filter == NULL)
3077 goto err;
3078
3079 io = BIO_push(filter, io);
30323080 #endif
30333081
30343082 if (s_debug) {
30463094 }
30473095
30483096 for (;;) {
3049 i = BIO_gets(io, buf, bufsize - 1);
3097 i = BIO_gets(io, buf, bufsize + 1);
30503098 if (i < 0) { /* error */
30513099 if (!BIO_should_retry(io) && !SSL_waiting_for_async(con)) {
30523100 if (!s_quiet)
31113159 * we're expecting to come from the client. If they haven't
31123160 * sent one there's not much we can do.
31133161 */
3114 BIO_gets(io, buf, bufsize - 1);
3162 BIO_gets(io, buf, bufsize + 1);
31153163 }
31163164
31173165 BIO_puts(io,
32923340 }
32933341 /* send the file */
32943342 #ifndef OPENSSL_NO_KTLS
3295 if (use_sendfile) {
3343 if (use_sendfile_for_req && !BIO_get_ktls_send(SSL_get_wbio(con))) {
3344 BIO_printf(bio_err, "Warning: sendfile requested but KTLS is not available\n");
3345 use_sendfile_for_req = 0;
3346 }
3347 if (use_sendfile_for_req) {
32963348 FILE *fp = NULL;
32973349 int fd;
32983350 struct stat st;
33993451 int ret = 1;
34003452 SSL *con;
34013453 BIO *io, *ssl_bio, *sbio;
3402
3403 buf = app_malloc(bufsize, "server rev buffer");
3454 #ifdef CHARSET_EBCDIC
3455 BIO *filter;
3456 #endif
3457
3458 /* as we use BIO_gets(), and it always null terminates data, we need
3459 * to allocate 1 byte longer buffer to fit the full 2^14 byte record */
3460 buf = app_malloc(bufsize + 1, "server rev buffer");
34043461 io = BIO_new(BIO_f_buffer());
34053462 ssl_bio = BIO_new(BIO_f_ssl());
34063463 if ((io == NULL) || (ssl_bio == NULL))
34263483 }
34273484
34283485 sbio = BIO_new_socket(s, BIO_NOCLOSE);
3486 if (sbio == NULL) {
3487 SSL_free(con);
3488 ERR_print_errors(bio_err);
3489 goto err;
3490 }
3491
34293492 SSL_set_bio(con, sbio, sbio);
34303493 SSL_set_accept_state(con);
34313494
34343497 BIO_push(io, ssl_bio);
34353498 ssl_bio = NULL;
34363499 #ifdef CHARSET_EBCDIC
3437 io = BIO_push(BIO_new(BIO_f_ebcdic_filter()), io);
3500 filter = BIO_new(BIO_f_ebcdic_filter());
3501 if (filter == NULL)
3502 goto err;
3503
3504 io = BIO_push(filter, io);
34383505 #endif
34393506
34403507 if (s_debug) {
34753542 print_ssl_summary(con);
34763543
34773544 for (;;) {
3478 i = BIO_gets(io, buf, bufsize - 1);
3545 i = BIO_gets(io, buf, bufsize + 1);
34793546 if (i < 0) { /* error */
34803547 if (!BIO_should_retry(io)) {
34813548 if (!s_quiet)
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
2828 #include <math.h>
2929 #include "apps.h"
3030 #include "progs.h"
31 #include "internal/numbers.h"
3132 #include <openssl/crypto.h>
3233 #include <openssl/rand.h>
3334 #include <openssl/err.h>
450451 static double sm2_results[SM2_NUM][2]; /* 2 ops: sign then verify */
451452 #endif /* OPENSSL_NO_SM2 */
452453
453 #define COND(unused_cond) (run && count < 0x7fffffff)
454 #define COND(unused_cond) (run && count < INT_MAX)
454455 #define COUNT(d) (count)
455456
456457 typedef struct loopargs_st {
17731774 buflen = lengths[size_num - 1];
17741775 if (buflen < 36) /* size of random vector in RSA benchmark */
17751776 buflen = 36;
1777 if (INT_MAX - (MAX_MISALIGNMENT + 1) < buflen) {
1778 BIO_printf(bio_err, "Error: buffer size too large\n");
1779 goto end;
1780 }
17761781 buflen += MAX_MISALIGNMENT + 1;
17771782 loopargs[i].buf_malloc = app_malloc(buflen, "input buffer");
17781783 loopargs[i].buf2_malloc = app_malloc(buflen, "input buffer");
36163621 for (j = 0; j < num; j++) {
36173622 print_message(alg_name, 0, mblengths[j], seconds->sym);
36183623 Time_F(START);
3619 for (count = 0; run && count < 0x7fffffff; count++) {
3624 for (count = 0; run && count < INT_MAX; count++) {
36203625 unsigned char aad[EVP_AEAD_TLS1_AAD_LEN];
36213626 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
36223627 size_t len = mblengths[j];
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
262262 if (x509_ctrl_string(x, opt) <= 0) {
263263 BIO_printf(bio_err, "parameter error \"%s\"\n", opt);
264264 ERR_print_errors(bio_err);
265 X509_free(x);
265266 return 0;
266267 }
267268 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
705705 : "Certificate request self-signature did not match the contents\n");
706706 goto end;
707707 }
708 BIO_printf(out, "Certificate request self-signature ok\n");
709
710 print_name(out, "subject=", X509_REQ_get_subject_name(req));
708 BIO_printf(bio_err, "Certificate request self-signature ok\n");
709
710 print_name(bio_err, "subject=", X509_REQ_get_subject_name(req));
711711 } else if (!x509toreq && ext_copy != EXT_COPY_UNSET) {
712712 BIO_printf(bio_err, "Warning: ignoring -copy_extensions since neither -x509toreq nor -req is given\n");
713713 }
00 /*
1 * Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4949 #include <openssl/aes.h>
5050 #include "aes_local.h"
5151
52 #if !defined(OPENSSL_NO_AES_CONST_TIME) && !defined(AES_ASM)
52 #if defined(OPENSSL_AES_CONST_TIME) && !defined(AES_ASM)
5353
5454 # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
5555 # define U64(C) C##UI64
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
5353 goto err;
5454 }
5555
56 switch (EVP_PKEY_get_id(ret)) {
56 switch (EVP_PKEY_get_base_id(ret)) {
5757 case EVP_PKEY_RSA:
5858 if ((ret->pkey.rsa = d2i_RSAPublicKey(NULL, pp, length)) == NULL) {
5959 ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
130130
131131 return i2d_provided(a, EVP_PKEY_PUBLIC_KEY, output_info, pp);
132132 }
133 switch (EVP_PKEY_get_id(a)) {
133 switch (EVP_PKEY_get_base_id(a)) {
134134 case EVP_PKEY_RSA:
135135 return i2d_RSAPublicKey(EVP_PKEY_get0_RSA(a), pp);
136136 #ifndef OPENSSL_NO_DSA
00 /*
1 * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2424 # define ASYNC_POSIX
2525 # define ASYNC_ARCH
2626
27 # ifdef __CET__
27 # if defined(__CET__) || defined(__ia64__)
2828 /*
2929 * When Intel CET is enabled, makecontext will create a different
3030 * shadow stack for each context. async_fibre_swapcontext cannot
3131 * use _longjmp. It must call swapcontext to swap shadow stack as
3232 * well as normal stack.
33 * On IA64 the register stack engine is not saved across setjmp/longjmp. Here
34 * swapcontext() performs correctly.
35 */
36 # define USE_SWAPCONTEXT
37 # endif
38 # if defined(__aarch64__) && defined(__clang__) \
39 && defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
40 /*
41 * setjmp/longjmp don't currently work with BTI on all libc implementations
42 * when compiled by clang. This is because clang doesn't put a BTI after the
43 * call to setjmp where it returns the second time. This then fails on libc
44 * implementations - notably glibc - which use an indirect jump to there.
45 * So use the swapcontext implementation, which does work.
46 * See https://github.com/llvm/llvm-project/issues/48888.
3347 */
3448 # define USE_SWAPCONTEXT
3549 # endif
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
751751 # pragma pointer_size 32
752752 #endif
753753 /* Windows doesn't seem to have in_addr_t */
754 #ifdef OPENSSL_SYS_WINDOWS
754 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
755755 static uint32_t he_fallback_address;
756756 static const char *he_fallback_addresses[] =
757757 { (char *)&he_fallback_address, NULL };
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1212 #include "crypto/ctype.h"
1313 #include "internal/numbers.h"
1414 #include <openssl/bio.h>
15 #include <openssl/configuration.h>
1516
1617 /*
1718 * Copyright Patrick Powell 1995
3031 const char *, int, int, int);
3132 static int fmtint(char **, char **, size_t *, size_t *,
3233 int64_t, int, int, int, int);
34 #ifndef OPENSSL_SYS_UEFI
3335 static int fmtfp(char **, char **, size_t *, size_t *,
3436 LDOUBLE, int, int, int, int);
37 #endif
3538 static int doapr_outch(char **, char **, size_t *, size_t *, int);
3639 static int _dopr(char **sbuffer, char **buffer,
3740 size_t *maxlen, size_t *retlen, int *truncated,
8790 {
8891 char ch;
8992 int64_t value;
93 #ifndef OPENSSL_SYS_UEFI
9094 LDOUBLE fvalue;
95 #endif
9196 char *strvalue;
9297 int min;
9398 int max;
258263 min, max, flags))
259264 return 0;
260265 break;
266 #ifndef OPENSSL_SYS_UEFI
261267 case 'f':
262268 if (cflags == DP_C_LDOUBLE)
263269 fvalue = va_arg(args, LDOUBLE);
291297 flags, G_FORMAT))
292298 return 0;
293299 break;
300 #else
301 case 'f':
302 case 'E':
303 case 'e':
304 case 'G':
305 case 'g':
306 /* not implemented for UEFI */
307 ERR_raise(ERR_LIB_BIO, ERR_R_UNSUPPORTED);
308 return 0;
309 #endif
294310 case 'c':
295311 if (!doapr_outch(sbuffer, buffer, &currlen, maxlen,
296312 va_arg(args, int)))
510526 }
511527 return 1;
512528 }
529
530 #ifndef OPENSSL_SYS_UEFI
513531
514532 static LDOUBLE abs_val(LDOUBLE value)
515533 {
806824 return 1;
807825 }
808826
827 #endif /* OPENSSL_SYS_UEFI */
828
809829 #define BUFFER_INC 1024
810830
811831 static int
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4747 {
4848 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
4949
50 if (bcgbl->c_bio_read_ex == NULL)
50 if (bcgbl == NULL || bcgbl->c_bio_read_ex == NULL)
5151 return 0;
5252 return bcgbl->c_bio_read_ex(BIO_get_data(bio), data, data_len, bytes_read);
5353 }
5757 {
5858 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
5959
60 if (bcgbl->c_bio_write_ex == NULL)
60 if (bcgbl == NULL || bcgbl->c_bio_write_ex == NULL)
6161 return 0;
6262 return bcgbl->c_bio_write_ex(BIO_get_data(bio), data, data_len, written);
6363 }
6666 {
6767 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
6868
69 if (bcgbl->c_bio_ctrl == NULL)
69 if (bcgbl == NULL || bcgbl->c_bio_ctrl == NULL)
7070 return -1;
7171 return bcgbl->c_bio_ctrl(BIO_get_data(bio), cmd, num, ptr);
7272 }
7575 {
7676 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
7777
78 if (bcgbl->c_bio_gets == NULL)
78 if (bcgbl == NULL || bcgbl->c_bio_gets == NULL)
7979 return -1;
8080 return bcgbl->c_bio_gets(BIO_get_data(bio), buf, size);
8181 }
8484 {
8585 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
8686
87 if (bcgbl->c_bio_puts == NULL)
87 if (bcgbl == NULL || bcgbl->c_bio_puts == NULL)
8888 return -1;
8989 return bcgbl->c_bio_puts(BIO_get_data(bio), str);
9090 }
9999 static int bio_core_free(BIO *bio)
100100 {
101101 BIO_CORE_GLOBALS *bcgbl = get_globals(bio->libctx);
102
103 if (bcgbl == NULL)
104 return 0;
102105
103106 BIO_set_init(bio, 0);
104107 bcgbl->c_bio_free(BIO_get_data(bio));
132135 BIO_CORE_GLOBALS *bcgbl = get_globals(libctx);
133136
134137 /* Check the library context has been initialised with the callbacks */
135 if (bcgbl->c_bio_write_ex == NULL && bcgbl->c_bio_read_ex == NULL)
138 if (bcgbl == NULL || (bcgbl->c_bio_write_ex == NULL && bcgbl->c_bio_read_ex == NULL))
136139 return NULL;
137140
138141 if ((outbio = BIO_new_ex(libctx, BIO_s_core())) == NULL)
149152 int ossl_bio_init_core(OSSL_LIB_CTX *libctx, const OSSL_DISPATCH *fns)
150153 {
151154 BIO_CORE_GLOBALS *bcgbl = get_globals(libctx);
155
156 if (bcgbl == NULL)
157 return 0;
152158
153159 for (; fns->function_id != 0; fns++) {
154160 switch (fns->function_id) {
141141 continue;
142142
143143 if (i == 0 || i > INT_MAX / 4)
144 goto err;
144 return 0;
145145
146146 num = i + neg;
147147 if (bn == NULL)
153153 return 0;
154154 } else {
155155 ret = *bn;
156 if (BN_get_flags(ret, BN_FLG_STATIC_DATA)) {
157 ERR_raise(ERR_LIB_BN, ERR_R_PASSED_INVALID_ARGUMENT);
158 return 0;
159 }
156160 BN_zero(ret);
157161 }
158162
00 /*
1 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3131 bn_check_top(p2);
3232 bn_check_top(m);
3333
34 if (!(m->d[0] & 1)) {
34 if (!BN_is_odd(m)) {
3535 ERR_raise(ERR_LIB_BN, BN_R_CALLED_WITH_EVEN_MODULUS);
3636 return 0;
3737 }
00 /*
1 * Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3939 * no opportunity to figure it out...
4040 */
4141
42 #if defined(_ARCH_PPC64)
42 #if defined(_ARCH_PPC64) && !defined(__ILP32__)
4343 if (num == 6) {
4444 if (OPENSSL_ppccap_P & PPC_MADD300)
4545 return bn_mul_mont_300_fixed_n6(rp, ap, bp, np, n0, num);
00 /*
1 * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1313 /*
1414 * Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
1515 * algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
16 * Theory", algorithm 1.5.1). 'p' must be prime!
16 * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
17 * an incorrect "result" will be returned.
1718 */
1819 {
1920 BIGNUM *ret = in;
302303 goto vrfy;
303304 }
304305
305 /* find smallest i such that b^(2^i) = 1 */
306 i = 1;
307 if (!BN_mod_sqr(t, b, p, ctx))
308 goto end;
309 while (!BN_is_one(t)) {
310 i++;
311 if (i == e) {
312 ERR_raise(ERR_LIB_BN, BN_R_NOT_A_SQUARE);
313 goto end;
306 /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
307 for (i = 1; i < e; i++) {
308 if (i == 1) {
309 if (!BN_mod_sqr(t, b, p, ctx))
310 goto end;
311
312 } else {
313 if (!BN_mod_mul(t, t, t, p, ctx))
314 goto end;
314315 }
315 if (!BN_mod_mul(t, t, t, p, ctx))
316 goto end;
316 if (BN_is_one(t))
317 break;
318 }
319 /* If not found, a is not a square or p is not prime. */
320 if (i >= e) {
321 ERR_raise(ERR_LIB_BN, BN_R_NOT_A_SQUARE);
322 goto end;
317323 }
318324
319325 /* t := y^2^(e - i - 1) */
317317 int exp_chunk_no = exp_bit_no / 64;
318318 int exp_chunk_shift = exp_bit_no % 64;
319319
320 BN_ULONG red_table_idx_0, red_table_idx_1;
321
320322 /*
321323 * If rem == 0, then
322324 * exp_bit_no = modulus_bitsize - exp_win_size
328330 OPENSSL_assert(rem != 0);
329331
330332 /* Process 1-st exp window - just init result */
331 BN_ULONG red_table_idx_0 = expz[0][exp_chunk_no];
332 BN_ULONG red_table_idx_1 = expz[1][exp_chunk_no];
333 red_table_idx_0 = expz[0][exp_chunk_no];
334 red_table_idx_1 = expz[1][exp_chunk_no];
333335 /*
334336 * The function operates with fixed moduli sizes divisible by 64,
335337 * thus table index here is always in supported range [0, EXP_WIN_SIZE).
00 /*
1 * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright Nokia 2007-2019
33 * Copyright Siemens AG 2015-2019
44 *
259259 if (ctx->subjectName != NULL)
260260 return IS_NULL_DN(ctx->subjectName) ? NULL : ctx->subjectName;
261261
262 if (ref_subj != NULL && (for_KUR || !HAS_SAN(ctx)))
262 if (ref_subj != NULL && (ctx->p10CSR != NULL || for_KUR || !HAS_SAN(ctx)))
263263 /*
264264 * For KUR, copy subject from the reference.
265265 * For IR or CR, do the same only if there is no subjectAltName.
288288
289289 if (rkey == NULL && ctx->p10CSR != NULL)
290290 rkey = X509_REQ_get0_pubkey(ctx->p10CSR);
291 if (rkey == NULL && refcert != NULL)
292 rkey = X509_get0_pubkey(refcert);
291293 if (rkey == NULL)
292294 rkey = ctx->pkey; /* default is independent of ctx->oldCert */
293295 if (rkey == NULL) {
326328 }
327329
328330 /* extensions */
329 if (refcert != NULL && !ctx->SubjectAltName_nodefault)
330 default_sans = X509V3_get_d2i(X509_get0_extensions(refcert),
331 NID_subject_alt_name, NULL, NULL);
332331 if (ctx->p10CSR != NULL
333332 && (exts = X509_REQ_get_extensions(ctx->p10CSR)) == NULL)
333 goto err;
334 if (!ctx->SubjectAltName_nodefault && !HAS_SAN(ctx) && refcert != NULL
335 && (default_sans = X509V3_get_d2i(X509_get0_extensions(refcert),
336 NID_subject_alt_name, NULL, NULL))
337 != NULL
338 && !add1_extension(&exts, NID_subject_alt_name, crit, default_sans))
334339 goto err;
335340 if (ctx->reqExtensions != NULL /* augment/override existing ones */
336341 && !add_extensions(&exts, ctx->reqExtensions))
338343 if (sk_GENERAL_NAME_num(ctx->subjectAltNames) > 0
339344 && !add1_extension(&exts, NID_subject_alt_name,
340345 crit, ctx->subjectAltNames))
341 goto err;
342 if (!HAS_SAN(ctx) && default_sans != NULL
343 && !add1_extension(&exts, NID_subject_alt_name, crit, default_sans))
344346 goto err;
345347 if (ctx->policies != NULL
346348 && !add1_extension(&exts, NID_certificate_policies,
565567 if (!sk_OSSL_CMP_REVDETAILS_push(msg->body->value.rr, rd))
566568 goto err;
567569 rd = NULL;
570 /* Revocation Passphrase according to section 5.3.19.9 could be set here */
568571
569572 if (!ossl_cmp_msg_protect(ctx, msg))
570573 goto err;
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
9292 exdata_done = 1;
9393
9494 if (!ossl_crypto_new_ex_data_ex(ctx, CRYPTO_EX_INDEX_OSSL_LIB_CTX, NULL,
95 &ctx->data)) {
96 ossl_crypto_cleanup_all_ex_data_int(ctx);
95 &ctx->data))
9796 goto err;
98 }
9997
10098 /* Everything depends on properties, so we also pre-initialise that */
10199 if (!ossl_property_parse_init(ctx))
105103 err:
106104 if (exdata_done)
107105 ossl_crypto_cleanup_all_ex_data_int(ctx);
106 for (i = 0; i < OSSL_LIB_CTX_MAX_INDEXES; i++)
107 CRYPTO_THREAD_lock_free(ctx->index_locks[i]);
108108 CRYPTO_THREAD_lock_free(ctx->oncelock);
109109 CRYPTO_THREAD_lock_free(ctx->lock);
110 ctx->lock = NULL;
110 memset(ctx, '\0', sizeof(*ctx));
111111 return 0;
112112 }
113113
155155 void ossl_lib_ctx_default_deinit(void)
156156 {
157157 context_deinit(&default_context_int);
158 CRYPTO_THREAD_cleanup_local(&default_context_thread_local);
158159 }
159160
160161 static OSSL_LIB_CTX *get_thread_default_context(void)
188189 OSSL_LIB_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
189190
190191 if (ctx != NULL && !context_init(ctx)) {
191 OSSL_LIB_CTX_free(ctx);
192 OPENSSL_free(ctx);
192193 ctx = NULL;
193194 }
194195 return ctx;
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3636 CRYPTO_RWLOCK *lock;
3737 LHASH_OF(NAMENUM_ENTRY) *namenum; /* Name->number mapping */
3838
39 #ifdef tsan_ld_acq
40 TSAN_QUALIFIER int max_number; /* Current max number TSAN version */
41 #else
42 int max_number; /* Current max number plain version */
43 #endif
39 TSAN_QUALIFIER int max_number; /* Current max number */
4440 };
4541
4642 /* LHASH callbacks */
9894
9995 int ossl_namemap_empty(OSSL_NAMEMAP *namemap)
10096 {
101 #ifdef tsan_ld_acq
102 /* Have TSAN support */
103 return namemap == NULL || tsan_load(&namemap->max_number) == 0;
104 #else
97 #ifdef TSAN_REQUIRES_LOCKING
10598 /* No TSAN support */
10699 int rv;
107100
113106 rv = namemap->max_number == 0;
114107 CRYPTO_THREAD_unlock(namemap->lock);
115108 return rv;
109 #else
110 /* Have TSAN support */
111 return namemap == NULL || tsan_load(&namemap->max_number) == 0;
116112 #endif
117113 }
118114
259255 || (namenum->name = OPENSSL_strndup(name, name_len)) == NULL)
260256 goto err;
261257
258 /* The tsan_counter use here is safe since we're under lock */
262259 namenum->number =
263260 number != 0 ? number : 1 + tsan_counter(&namemap->max_number);
264261 (void)lh_NAMENUM_ENTRY_insert(namemap->namenum, namenum);
408405 {
409406 const EVP_CIPHER *cipher = (void *)OBJ_NAME_get(on->name, on->type);
410407
411 get_legacy_evp_names(NID_undef, EVP_CIPHER_get_type(cipher), NULL, arg);
408 if (cipher != NULL)
409 get_legacy_evp_names(NID_undef, EVP_CIPHER_get_type(cipher), NULL, arg);
412410 }
413411
414412 static void get_legacy_md_names(const OBJ_NAME *on, void *arg)
415413 {
416414 const EVP_MD *md = (void *)OBJ_NAME_get(on->name, on->type);
417415
418 get_legacy_evp_names(0, EVP_MD_get_type(md), NULL, arg);
416 if (md != NULL)
417 get_legacy_evp_names(0, EVP_MD_get_type(md), NULL, arg);
419418 }
420419
421420 static void get_legacy_pkey_meth_names(const EVP_PKEY_ASN1_METHOD *ameth,
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
510510 DH_set_flags(dh, type == EVP_PKEY_DH ? DH_FLAG_TYPE_DH : DH_FLAG_TYPE_DHX);
511511
512512 if (!ossl_dh_params_fromdata(dh, params)
513 || !ossl_dh_key_fromdata(dh, params)
513 || !ossl_dh_key_fromdata(dh, params, 1)
514514 || !EVP_PKEY_assign(pkey, type, dh)) {
515515 DH_free(dh);
516516 return 0;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
6262 return 1;
6363 }
6464
65 int ossl_dh_key_fromdata(DH *dh, const OSSL_PARAM params[])
65 int ossl_dh_key_fromdata(DH *dh, const OSSL_PARAM params[], int include_private)
6666 {
6767 const OSSL_PARAM *param_priv_key, *param_pub_key;
6868 BIGNUM *priv_key = NULL, *pub_key = NULL;
7373 param_priv_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
7474 param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
7575
76 if ((param_priv_key != NULL
77 && !OSSL_PARAM_get_BN(param_priv_key, &priv_key))
78 || (param_pub_key != NULL
79 && !OSSL_PARAM_get_BN(param_pub_key, &pub_key)))
76 if (include_private
77 && param_priv_key != NULL
78 && !OSSL_PARAM_get_BN(param_priv_key, &priv_key))
79 goto err;
80
81 if (param_pub_key != NULL
82 && !OSSL_PARAM_get_BN(param_pub_key, &pub_key))
8083 goto err;
8184
8285 if (!DH_set0_key(dh, pub_key, priv_key))
102105 return 1;
103106 }
104107
105 int ossl_dh_key_todata(DH *dh, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
108 int ossl_dh_key_todata(DH *dh, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
109 int include_private)
106110 {
107111 const BIGNUM *priv = NULL, *pub = NULL;
108112
111115
112116 DH_get0_key(dh, &pub, &priv);
113117 if (priv != NULL
118 && include_private
114119 && !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_PRIV_KEY, priv))
115120 return 0;
116121 if (pub != NULL
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
374374 int err_reason = DH_R_BN_ERROR;
375375 BIGNUM *pubkey = NULL;
376376 const BIGNUM *p;
377 size_t p_size;
377 int ret;
378378
379379 if ((pubkey = BN_bin2bn(buf, len, NULL)) == NULL)
380380 goto err;
381381 DH_get0_pqg(dh, &p, NULL, NULL);
382 if (p == NULL || (p_size = BN_num_bytes(p)) == 0) {
382 if (p == NULL || BN_num_bytes(p) == 0) {
383383 err_reason = DH_R_NO_PARAMETERS_SET;
384384 goto err;
385385 }
386 /*
387 * As per Section 4.2.8.1 of RFC 8446 fail if DHE's
388 * public key is of size not equal to size of p
389 */
390 if (BN_is_zero(pubkey) || p_size != len) {
386 /* Prevent small subgroup attacks per RFC 8446 Section 4.2.8.1 */
387 if (!ossl_dh_check_pub_key_partial(dh, pubkey, &ret)) {
391388 err_reason = DH_R_INVALID_PUBKEY;
392389 goto err;
393390 }
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
484484 }
485485
486486 if (!ossl_dsa_ffc_params_fromdata(dsa, params)
487 || !ossl_dsa_key_fromdata(dsa, params)
487 || !ossl_dsa_key_fromdata(dsa, params, 1)
488488 || !EVP_PKEY_assign_DSA(pkey, dsa)) {
489489 DSA_free(dsa);
490490 return 0;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2626 * implementations alike.
2727 */
2828
29 int ossl_dsa_key_fromdata(DSA *dsa, const OSSL_PARAM params[])
29 int ossl_dsa_key_fromdata(DSA *dsa, const OSSL_PARAM params[],
30 int include_private)
3031 {
31 const OSSL_PARAM *param_priv_key, *param_pub_key;
32 const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
3233 BIGNUM *priv_key = NULL, *pub_key = NULL;
3334
3435 if (dsa == NULL)
3536 return 0;
3637
37 param_priv_key =
38 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
38 if (include_private) {
39 param_priv_key =
40 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
41 }
3942 param_pub_key =
4043 OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
4144
00 #! /usr/bin/env perl
1 # Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
3 # Licensed under the OpenSSL license (the "License"). You may not use
3 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
55 # in the file LICENSE in the source distribution or at
66 # https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2016 Cryptography Research, Inc.
33 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
55 * this file except in compliance with the License. You can obtain a copy
66 * in the file LICENSE in the source distribution or at
77 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2014-2016 Cryptography Research, Inc.
33 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
55 * this file except in compliance with the License. You can obtain a copy
66 * in the file LICENSE in the source distribution or at
77 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2014 Cryptography Research, Inc.
33 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
55 * this file except in compliance with the License. You can obtain a copy
66 * in the file LICENSE in the source distribution or at
77 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
17091709 ptmp = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_EC_ENCODING);
17101710 if (ptmp != NULL
17111711 && !ossl_ec_encoding_param2id(ptmp, &encoding_flag)) {
1712 ECerr(0, EC_R_INVALID_ENCODING);
1713 return 0;
1712 ERR_raise(ERR_LIB_EC, EC_R_INVALID_ENCODING);
1713 goto err;
17141714 }
17151715 if (encoding_flag == OPENSSL_EC_NAMED_CURVE) {
17161716 ERR_raise(ERR_LIB_EC, EC_R_INVALID_ENCODING);
6767 len = strlen(hex) / 2;
6868 oct_buf = OPENSSL_malloc(len);
6969 if (oct_buf == NULL)
70 return NULL;
70 goto err;
7171
7272 if (!OPENSSL_hexstr2buf_ex(oct_buf, len, &oct_buf_len, hex, '\0')
7373 || !EC_POINT_oct2point(group, pt, oct_buf, oct_buf_len, ctx))
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
115115 /* Otherwise use default. */
116116 if (rc == -1)
117117 rc = ossl_ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
118 OPENSSL_cleanse(param + S390X_OFF_SCALAR(len), len);
118 OPENSSL_cleanse(param, sizeof(param));
119119 BN_CTX_end(ctx);
120120 BN_CTX_free(new_ctx);
121121 return rc;
211211
212212 ok = 1;
213213 ret:
214 OPENSSL_cleanse(param + S390X_OFF_K(len), 2 * len);
214 OPENSSL_cleanse(param, sizeof(param));
215215 if (ok != 1) {
216216 ECDSA_SIG_free(sig);
217217 sig = NULL;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
338338 {
339339 OSSL_METHOD_STORE *store = get_decoder_store(methdata->libctx);
340340 OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
341 const char *const propq = properties != NULL ? properties : "";
341342 void *method = NULL;
342343 int unsupported = 0;
343344
366367 unsupported = 1;
367368
368369 if (id == 0
369 || !ossl_method_store_cache_get(store, NULL, id, properties, &method)) {
370 || !ossl_method_store_cache_get(store, NULL, id, propq, &method)) {
370371 OSSL_METHOD_CONSTRUCT_METHOD mcm = {
371372 get_tmp_decoder_store,
372373 get_decoder_from_store,
374375 construct_decoder,
375376 destruct_decoder
376377 };
378 OSSL_PROVIDER *prov = NULL;
377379
378380 methdata->id = id;
379381 methdata->names = name;
380 methdata->propquery = properties;
382 methdata->propquery = propq;
381383 methdata->flag_construct_error_occurred = 0;
382384 if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_DECODER,
383 NULL, 0 /* !force_cache */,
385 &prov, 0 /* !force_cache */,
384386 &mcm, methdata)) != NULL) {
385387 /*
386388 * If construction did create a method for us, we know that
391393 if (id == 0 && name != NULL)
392394 id = ossl_namemap_name2num(namemap, name);
393395 if (id != 0)
394 ossl_method_store_cache_set(store, NULL, id, properties, method,
396 ossl_method_store_cache_set(store, prov, id, propq, method,
395397 up_ref_decoder, free_decoder);
396398 }
397399
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
348348 {
349349 OSSL_METHOD_STORE *store = get_encoder_store(methdata->libctx);
350350 OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
351 const char *const propq = properties != NULL ? properties : "";
351352 void *method = NULL;
352353 int unsupported = 0;
353354
376377 unsupported = 1;
377378
378379 if (id == 0
379 || !ossl_method_store_cache_get(store, NULL, id, properties, &method)) {
380 || !ossl_method_store_cache_get(store, NULL, id, propq, &method)) {
380381 OSSL_METHOD_CONSTRUCT_METHOD mcm = {
381382 get_tmp_encoder_store,
382383 get_encoder_from_store,
384385 construct_encoder,
385386 destruct_encoder
386387 };
388 OSSL_PROVIDER *prov = NULL;
387389
388390 methdata->id = id;
389391 methdata->names = name;
390 methdata->propquery = properties;
392 methdata->propquery = propq;
391393 methdata->flag_construct_error_occurred = 0;
392394 if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_ENCODER,
393 NULL, 0 /* !force_cache */,
395 &prov, 0 /* !force_cache */,
394396 &mcm, methdata)) != NULL) {
395397 /*
396398 * If construction did create a method for us, we know that
400402 */
401403 if (id == 0)
402404 id = ossl_namemap_name2num(namemap, name);
403 ossl_method_store_cache_set(store, NULL, id, properties, method,
405 ossl_method_store_cache_set(store, prov, id, propq, method,
404406 up_ref_encoder, free_encoder);
405407 }
406408
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
253253 * First, collect the keymgmt names, then the encoders that match.
254254 */
255255 keymgmt_data.names = sk_OPENSSL_CSTRING_new_null();
256 if (keymgmt_data.names == NULL) {
257 ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_MALLOC_FAILURE);
258 goto err;
259 }
260
256261 keymgmt_data.error_occurred = 0;
257262 EVP_KEYMGMT_names_do_all(pkey->keymgmt, collect_name, &keymgmt_data);
258263 if (keymgmt_data.error_occurred) {
00 /*
1 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
450450 * We fail if the version checker veto'd the load *or* if it is
451451 * deferring to us (by returning its version) and we think it is too
452452 * old.
453 * Unfortunately the version checker does not distinguish between
454 * engines built for openssl 1.1.x and openssl 3.x, but loading
455 * an engine that is built for openssl 1.1.x will cause a fatal
456 * error. Detect such engines, since EVP_PKEY_base_id is exported
457 * as a function in openssl 1.1.x, while it is a macro in openssl 3.x,
458 * and therefore only the symbol EVP_PKEY_get_base_id is available
459 * in openssl 3.x.
453460 */
454 if (vcheck_res < OSSL_DYNAMIC_OLDEST) {
461 if (vcheck_res < OSSL_DYNAMIC_OLDEST
462 || DSO_bind_func(ctx->dynamic_dso,
463 "EVP_PKEY_base_id") != NULL) {
455464 /* Fail */
456465 ctx->bind_engine = NULL;
457466 ctx->v_check = NULL;
00 /*
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
10031003 return 0;
10041004
10051005 if (state == PRE_CTRL_TO_PARAMS) {
1006 ctx->p2 = (char *)ossl_ffc_named_group_get_name
1007 (ossl_ffc_uid_to_dh_named_group(ctx->p1));
1006 if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
1007 (ossl_ffc_uid_to_dh_named_group(ctx->p1))) == NULL) {
1008 ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
1009 return 0;
1010 }
10081011 ctx->p1 = 0;
10091012 }
10101013
10271030
10281031 switch (state) {
10291032 case PRE_CTRL_TO_PARAMS:
1030 ctx->p2 = (char *)ossl_ffc_named_group_get_name
1031 (ossl_ffc_uid_to_dh_named_group(ctx->p1));
1033 if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
1034 (ossl_ffc_uid_to_dh_named_group(ctx->p1))) == NULL) {
1035 ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
1036 return 0;
1037 }
1038
10321039 ctx->p1 = 0;
10331040 break;
10341041
10351042 case PRE_CTRL_STR_TO_PARAMS:
10361043 if (ctx->p2 == NULL)
10371044 return 0;
1038 ctx->p2 = (char *)ossl_ffc_named_group_get_name
1039 (ossl_ffc_uid_to_dh_named_group(atoi(ctx->p2)));
1045 if ((ctx->p2 = (char *)ossl_ffc_named_group_get_name
1046 (ossl_ffc_uid_to_dh_named_group(atoi(ctx->p2)))) == NULL) {
1047 ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
1048 return 0;
1049 }
1050
10401051 ctx->p1 = 0;
10411052 break;
10421053
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2424 #include "crypto/evp.h"
2525 #include "evp_local.h"
2626
27
28 void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force)
27 static void cleanup_old_md_data(EVP_MD_CTX *ctx, int force)
28 {
29 if (ctx->digest != NULL) {
30 if (ctx->digest->cleanup != NULL
31 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))
32 ctx->digest->cleanup(ctx);
33 if (ctx->md_data != NULL && ctx->digest->ctx_size > 0
34 && (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)
35 || force)) {
36 OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
37 ctx->md_data = NULL;
38 }
39 }
40 }
41
42 void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force, int keep_fetched)
2943 {
3044 if (ctx->algctx != NULL) {
3145 if (ctx->digest != NULL && ctx->digest->freectx != NULL)
4054 * Don't assume ctx->md_data was cleaned in EVP_Digest_Final, because
4155 * sometimes only copies of the context are ever finalised.
4256 */
43 if (ctx->digest && ctx->digest->cleanup
44 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))
45 ctx->digest->cleanup(ctx);
46 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
47 && (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE) || force))
48 OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
57 cleanup_old_md_data(ctx, force);
4958 if (force)
5059 ctx->digest = NULL;
5160
5564 #endif
5665
5766 /* Non legacy code, this has to be later than the ctx->digest cleaning */
58 EVP_MD_free(ctx->fetched_digest);
59 ctx->fetched_digest = NULL;
60 ctx->reqdigest = NULL;
61 }
62
63 /* This call frees resources associated with the context */
64 int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
67 if (!keep_fetched) {
68 EVP_MD_free(ctx->fetched_digest);
69 ctx->fetched_digest = NULL;
70 ctx->reqdigest = NULL;
71 }
72 }
73
74 static int evp_md_ctx_reset_ex(EVP_MD_CTX *ctx, int keep_fetched)
6575 {
6676 if (ctx == NULL)
6777 return 1;
7787 }
7888 #endif
7989
80 evp_md_ctx_clear_digest(ctx, 0);
81 OPENSSL_cleanse(ctx, sizeof(*ctx));
90 evp_md_ctx_clear_digest(ctx, 0, keep_fetched);
91 if (!keep_fetched)
92 OPENSSL_cleanse(ctx, sizeof(*ctx));
8293
8394 return 1;
95 }
96
97 /* This call frees resources associated with the context */
98 int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
99 {
100 return evp_md_ctx_reset_ex(ctx, 0);
84101 }
85102
86103 #ifndef FIPS_MODULE
206223 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
207224 || tmpimpl != NULL
208225 #endif
209 || (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0) {
226 || (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0
227 || type->origin == EVP_ORIG_METH) {
210228 if (ctx->digest == ctx->fetched_digest)
211229 ctx->digest = NULL;
212230 EVP_MD_free(ctx->fetched_digest);
214232 goto legacy;
215233 }
216234
217 if (ctx->digest != NULL && ctx->digest->ctx_size > 0) {
218 OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
219 ctx->md_data = NULL;
220 }
235 cleanup_old_md_data(ctx, 1);
221236
222237 /* Start of non-legacy code below */
223238
306321 }
307322 #endif
308323 if (ctx->digest != type) {
309 if (ctx->digest && ctx->digest->ctx_size) {
310 OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
311 ctx->md_data = NULL;
312 }
324 cleanup_old_md_data(ctx, 1);
325
313326 ctx->digest = type;
314327 if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {
315328 ctx->update = type->update;
506519
507520 int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
508521 {
522 int digest_change = 0;
509523 unsigned char *tmp_buf;
510524
511525 if (in == NULL) {
519533 if (out->fetched_digest != NULL)
520534 EVP_MD_free(out->fetched_digest);
521535 *out = *in;
522 return 1;
536 goto clone_pkey;
523537 }
524538
525539 if (in->digest->prov == NULL
531545 return 0;
532546 }
533547
534 EVP_MD_CTX_reset(out);
535 if (out->fetched_digest != NULL)
548 evp_md_ctx_reset_ex(out, 1);
549 digest_change = (out->fetched_digest != in->fetched_digest);
550 if (digest_change && out->fetched_digest != NULL)
536551 EVP_MD_free(out->fetched_digest);
537552 *out = *in;
538553 /* NULL out pointers in case of error */
539554 out->pctx = NULL;
540555 out->algctx = NULL;
541556
542 if (in->fetched_digest != NULL)
557 if (digest_change && in->fetched_digest != NULL)
543558 EVP_MD_up_ref(in->fetched_digest);
544559
545560 if (in->algctx != NULL) {
550565 }
551566 }
552567
568 clone_pkey:
553569 /* copied EVP_MD_CTX should free the copied EVP_PKEY_CTX */
554570 EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
555571 #ifndef FIPS_MODULE
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
594594 const unsigned char *in, int inl)
595595 {
596596 int ret;
597 size_t soutl;
597 size_t soutl, inl_ = (size_t)inl;
598598 int blocksize;
599599
600600 if (outl != NULL) {
624624 ERR_raise(ERR_LIB_EVP, EVP_R_UPDATE_ERROR);
625625 return 0;
626626 }
627
627628 ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl,
628 inl + (blocksize == 1 ? 0 : blocksize), in,
629 (size_t)inl);
629 inl_ + (size_t)(blocksize == 1 ? 0 : blocksize),
630 in, inl_);
630631
631632 if (ret) {
632633 if (soutl > INT_MAX) {
742743 {
743744 int fix_len, cmpl = inl, ret;
744745 unsigned int b;
745 size_t soutl;
746 size_t soutl, inl_ = (size_t)inl;
746747 int blocksize;
747748
748749 if (outl != NULL) {
772773 return 0;
773774 }
774775 ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl,
775 inl + (blocksize == 1 ? 0 : blocksize), in,
776 (size_t)inl);
776 inl_ + (size_t)(blocksize == 1 ? 0 : blocksize),
777 in, inl_);
777778
778779 if (ret) {
779780 if (soutl > INT_MAX) {
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
246246 {
247247 OSSL_METHOD_STORE *store = get_evp_method_store(methdata->libctx);
248248 OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
249 const char *const propq = properties != NULL ? properties : "";
249250 uint32_t meth_id = 0;
250251 void *method = NULL;
251252 int unsupported = 0;
298299 unsupported = 1;
299300
300301 if (meth_id == 0
301 || !ossl_method_store_cache_get(store, prov, meth_id, properties,
302 &method)) {
302 || !ossl_method_store_cache_get(store, prov, meth_id, propq, &method)) {
303303 OSSL_METHOD_CONSTRUCT_METHOD mcm = {
304304 get_tmp_evp_method_store,
305305 get_evp_method_from_store,
311311 methdata->operation_id = operation_id;
312312 methdata->name_id = name_id;
313313 methdata->names = name;
314 methdata->propquery = properties;
314 methdata->propquery = propq;
315315 methdata->method_from_algorithm = new_method;
316316 methdata->refcnt_up_method = up_ref_method;
317317 methdata->destruct_method = free_method;
329329 name_id = ossl_namemap_name2num(namemap, name);
330330 meth_id = evp_method_id(name_id, operation_id);
331331 if (name_id != 0)
332 ossl_method_store_cache_set(store, prov, meth_id, properties,
332 ossl_method_store_cache_set(store, prov, meth_id, propq,
333333 method, up_ref_method, free_method);
334334 }
335335
348348 ERR_raise_data(ERR_LIB_EVP, code,
349349 "%s, Algorithm (%s : %d), Properties (%s)",
350350 ossl_lib_ctx_get_descriptor(methdata->libctx),
351 name = NULL ? "<null>" : name, name_id,
351 name == NULL ? "<null>" : name, name_id,
352352 properties == NULL ? "<null>" : properties);
353353 }
354354
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
305305 /*
306306 * Ensure that the key is provided, either natively, or as a cached
307307 * export. We start by fetching the keymgmt with the same name as
308 * |ctx->pkey|, but from the provider of the exchange method, using
308 * |ctx->keymgmt|, but from the provider of the exchange method, using
309309 * the same property query as when fetching the exchange method.
310310 * With the keymgmt we found (if we did), we try to export |ctx->pkey|
311311 * to it (evp_pkey_export_to_provider() is smart enough to only actually
379379 int ret = 0, check;
380380 void *provkey = NULL;
381381 EVP_PKEY_CTX *check_ctx = NULL;
382 EVP_KEYMGMT *tmp_keymgmt = NULL, *tmp_keymgmt_tofree = NULL;
382383
383384 if (ctx == NULL) {
384385 ERR_raise(ERR_LIB_EVP, ERR_R_PASSED_NULL_PARAMETER);
403404 return -1;
404405 }
405406
406 provkey = evp_pkey_export_to_provider(peer, ctx->libctx, &ctx->keymgmt,
407 ctx->propquery);
407 /*
408 * Ensure that the |peer| is provided, either natively, or as a cached
409 * export. We start by fetching the keymgmt with the same name as
410 * |ctx->keymgmt|, but from the provider of the exchange method, using
411 * the same property query as when fetching the exchange method.
412 * With the keymgmt we found (if we did), we try to export |peer|
413 * to it (evp_pkey_export_to_provider() is smart enough to only actually
414 * export it if |tmp_keymgmt| is different from |peer|'s keymgmt)
415 */
416 tmp_keymgmt_tofree = tmp_keymgmt =
417 evp_keymgmt_fetch_from_prov((OSSL_PROVIDER *)
418 EVP_KEYEXCH_get0_provider(ctx->op.kex.exchange),
419 EVP_KEYMGMT_get0_name(ctx->keymgmt),
420 ctx->propquery);
421 if (tmp_keymgmt != NULL)
422 provkey = evp_pkey_export_to_provider(peer, ctx->libctx,
423 &tmp_keymgmt, ctx->propquery);
424 EVP_KEYMGMT_free(tmp_keymgmt_tofree);
425
408426 /*
409427 * If making the key provided wasn't possible, legacy may be able to pick
410428 * it up
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
369369 * but also to determine if we should attempt a cross export
370370 * the other way. There's no point doing it both ways.
371371 */
372 int ok = 1;
372 int ok = 0;
373373
374374 /* Complex case, where the keymgmt differ */
375375 if (keymgmt1 != NULL
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
230230 * We're about to get a new digest so clear anything associated with
231231 * an old digest.
232232 */
233 evp_md_ctx_clear_digest(ctx, 1);
233 evp_md_ctx_clear_digest(ctx, 1, 0);
234234
235235 /* legacy code support for engines */
236236 ERR_set_mark();
479479 if (sigret == NULL || (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) != 0)
480480 return pctx->op.sig.signature->digest_sign_final(pctx->op.sig.algctx,
481481 sigret, siglen,
482 (siglen == NULL) ? 0 : *siglen);
482 sigret == NULL ? 0 : *siglen);
483483 dctx = EVP_PKEY_CTX_dup(pctx);
484484 if (dctx == NULL)
485485 return 0;
486486
487487 r = dctx->op.sig.signature->digest_sign_final(dctx->op.sig.algctx,
488488 sigret, siglen,
489 (siglen == NULL) ? 0 : *siglen);
489 *siglen);
490490 EVP_PKEY_CTX_free(dctx);
491491 return r;
492492
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
09 #include <openssl/evp.h>
110 #include <openssl/err.h>
211 #include <openssl/core.h>
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
127127 int EVP_PKEY_generate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
128128 {
129129 int ret = 0;
130 OSSL_CALLBACK cb;
131130 EVP_PKEY *allocated_pkey = NULL;
132131 /* Legacy compatible keygen callback info, only used with provider impls */
133132 int gentmp[2];
364363 OSSL_PARAM params[])
365364 {
366365 void *keydata = NULL;
366 EVP_PKEY *allocated_pkey = NULL;
367367
368368 if (ctx == NULL || (ctx->operation & EVP_PKEY_OP_FROMDATA) == 0) {
369369 ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
374374 return -1;
375375
376376 if (*ppkey == NULL)
377 *ppkey = EVP_PKEY_new();
377 allocated_pkey = *ppkey = EVP_PKEY_new();
378378
379379 if (*ppkey == NULL) {
380380 ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
382382 }
383383
384384 keydata = evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, selection, params);
385 if (keydata == NULL)
386 return 0;
385 if (keydata == NULL) {
386 if (allocated_pkey != NULL) {
387 *ppkey = NULL;
388 EVP_PKEY_free(allocated_pkey);
389 }
390 return 0;
391 }
387392 /* keydata is cached in *ppkey, so we need not bother with it further */
388393 return 1;
389394 }
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3636 const DH_NAMED_GROUP *group = NULL;
3737
3838 if (prm->data_type != OSSL_PARAM_UTF8_STRING
39 || prm->data == NULL
3940 || (group = ossl_ffc_name_to_dh_named_group(prm->data)) == NULL
4041 || !ossl_ffc_named_group_set_pqg(ffc, group))
4142 #endif
00 /*
1 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright Siemens AG 2018-2020
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
946946 }
947947 /* now overall_timeout is guaranteed to be >= 0 */
948948
949 /* adapt in order to fix callback design flaw, see #17088 */
949950 /* callback can be used to wrap or prepend TLS session */
950951 if (bio_update_fn != NULL) {
951952 BIO *orig_bio = cbio;
11961197
11971198 int OSSL_HTTP_close(OSSL_HTTP_REQ_CTX *rctx, int ok)
11981199 {
1200 BIO *wbio;
11991201 int ret = 1;
12001202
1201 /* callback can be used to clean up TLS session on disconnect */
1202 if (rctx != NULL && rctx->upd_fn != NULL)
1203 ret = (*rctx->upd_fn)(rctx->wbio, rctx->upd_arg, 0, ok) != NULL;
1203 /* callback can be used to finish TLS session and free its BIO */
1204 if (rctx != NULL && rctx->upd_fn != NULL) {
1205 wbio = (*rctx->upd_fn)(rctx->wbio, rctx->upd_arg,
1206 0 /* disconnect */, ok);
1207 ret = wbio != NULL;
1208 if (ret)
1209 rctx->wbio = wbio;
1210 }
12041211 OSSL_HTTP_REQ_CTX_free(rctx);
12051212 return ret;
12061213 }
00 /*
1 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
6060
6161 void OPENSSL_LH_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
6262 {
63 int omit_tsan = 0;
64
65 #ifdef TSAN_REQUIRES_LOCKING
66 if (!CRYPTO_THREAD_read_lock(lh->tsan_lock)) {
67 BIO_printf(out, "unable to lock table, omitting TSAN counters\n");
68 omit_tsan = 1;
69 }
70 #endif
6371 BIO_printf(out, "num_items = %lu\n", lh->num_items);
6472 BIO_printf(out, "num_nodes = %u\n", lh->num_nodes);
6573 BIO_printf(out, "num_alloc_nodes = %u\n", lh->num_alloc_nodes);
6775 BIO_printf(out, "num_expand_reallocs = %lu\n", lh->num_expand_reallocs);
6876 BIO_printf(out, "num_contracts = %lu\n", lh->num_contracts);
6977 BIO_printf(out, "num_contract_reallocs = %lu\n", lh->num_contract_reallocs);
70 BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls);
71 BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls);
78 if (!omit_tsan) {
79 BIO_printf(out, "num_hash_calls = %lu\n", lh->num_hash_calls);
80 BIO_printf(out, "num_comp_calls = %lu\n", lh->num_comp_calls);
81 }
7282 BIO_printf(out, "num_insert = %lu\n", lh->num_insert);
7383 BIO_printf(out, "num_replace = %lu\n", lh->num_replace);
7484 BIO_printf(out, "num_delete = %lu\n", lh->num_delete);
7585 BIO_printf(out, "num_no_delete = %lu\n", lh->num_no_delete);
76 BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve);
77 BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss);
78 BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps);
86 if (!omit_tsan) {
87 BIO_printf(out, "num_retrieve = %lu\n", lh->num_retrieve);
88 BIO_printf(out, "num_retrieve_miss = %lu\n", lh->num_retrieve_miss);
89 BIO_printf(out, "num_hash_comps = %lu\n", lh->num_hash_comps);
90 #ifdef TSAN_REQUIRES_LOCKING
91 CRYPTO_THREAD_unlock(lh->tsan_lock);
92 #endif
93 }
7994 }
8095
8196 void OPENSSL_LH_node_stats_bio(const OPENSSL_LHASH *lh, BIO *out)
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4343 static void contract(OPENSSL_LHASH *lh);
4444 static OPENSSL_LH_NODE **getrn(OPENSSL_LHASH *lh, const void *data, unsigned long *rhash);
4545
46 static ossl_inline int tsan_lock(const OPENSSL_LHASH *lh)
47 {
48 #ifdef TSAN_REQUIRES_LOCKING
49 if (!CRYPTO_THREAD_write_lock(lh->tsan_lock))
50 return 0;
51 #endif
52 return 1;
53 }
54
55 static ossl_inline void tsan_unlock(const OPENSSL_LHASH *lh)
56 {
57 #ifdef TSAN_REQUIRES_LOCKING
58 CRYPTO_THREAD_unlock(lh->tsan_lock);
59 #endif
60 }
61
4662 OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)
4763 {
4864 OPENSSL_LHASH *ret;
5773 }
5874 if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)
5975 goto err;
76 #ifdef TSAN_REQUIRES_LOCKING
77 if ((ret->tsan_lock = CRYPTO_THREAD_lock_new()) == NULL)
78 goto err;
79 #endif
6080 ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);
6181 ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
6282 ret->num_nodes = MIN_NODES / 2;
7898 return;
7999
80100 OPENSSL_LH_flush(lh);
101 #ifdef TSAN_REQUIRES_LOCKING
102 CRYPTO_THREAD_lock_free(lh->tsan_lock);
103 #endif
81104 OPENSSL_free(lh->b);
82105 OPENSSL_free(lh);
83106 }
165188 {
166189 unsigned long hash;
167190 OPENSSL_LH_NODE **rn;
168 void *ret;
169
191
192 /*-
193 * This should be atomic without tsan.
194 * It's not clear why it was done this way and not elsewhere.
195 */
170196 tsan_store((TSAN_QUALIFIER int *)&lh->error, 0);
171197
172198 rn = getrn(lh, data, &hash);
173199
174 if (*rn == NULL) {
175 tsan_counter(&lh->num_retrieve_miss);
176 return NULL;
177 } else {
178 ret = (*rn)->data;
179 tsan_counter(&lh->num_retrieve);
180 }
181
182 return ret;
200 if (tsan_lock(lh)) {
201 tsan_counter(*rn == NULL ? &lh->num_retrieve_miss : &lh->num_retrieve);
202 tsan_unlock(lh);
203 }
204 return *rn == NULL ? NULL : (*rn)->data;
183205 }
184206
185207 static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
306328 OPENSSL_LH_NODE **ret, *n1;
307329 unsigned long hash, nn;
308330 OPENSSL_LH_COMPFUNC cf;
309
331 int do_tsan = 1;
332
333 #ifdef TSAN_REQUIRES_LOCKING
334 do_tsan = tsan_lock(lh);
335 #endif
310336 hash = (*(lh->hash)) (data);
311 tsan_counter(&lh->num_hash_calls);
337 if (do_tsan)
338 tsan_counter(&lh->num_hash_calls);
312339 *rhash = hash;
313340
314341 nn = hash % lh->pmax;
318345 cf = lh->comp;
319346 ret = &(lh->b[(int)nn]);
320347 for (n1 = *ret; n1 != NULL; n1 = n1->next) {
321 tsan_counter(&lh->num_hash_comps);
348 if (do_tsan)
349 tsan_counter(&lh->num_hash_comps);
322350 if (n1->hash != hash) {
323351 ret = &(n1->next);
324352 continue;
325353 }
326 tsan_counter(&lh->num_comp_calls);
354 if (do_tsan)
355 tsan_counter(&lh->num_comp_calls);
327356 if (cf(n1->data, data) == 0)
328357 break;
329358 ret = &(n1->next);
330359 }
360 if (do_tsan)
361 tsan_unlock(lh);
331362 return ret;
332363 }
333364
351382 v = n | (*c);
352383 n += 0x100;
353384 r = (int)((v >> 2) ^ v) & 0x0f;
354 ret = (ret << r) | (ret >> (32 - r));
385 /* cast to uint64_t to avoid 32 bit shift of 32 bit value */
386 ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r));
355387 ret &= 0xFFFFFFFFL;
356388 ret ^= v * v;
357389 c++;
372404 for (n = 0x100; *c != '\0'; n += 0x100) {
373405 v = n | ossl_tolower(*c);
374406 r = (int)((v >> 2) ^ v) & 0x0f;
375 ret = (ret << r) | (ret >> (32 - r));
407 /* cast to uint64_t to avoid 32 bit shift of 32 bit value */
408 ret = (ret << r) | (unsigned long)((uint64_t)ret >> (32 - r));
376409 ret &= 0xFFFFFFFFL;
377410 ret ^= v * v;
378411 c++;
00 /*
1 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4040 TSAN_QUALIFIER unsigned long num_retrieve_miss;
4141 TSAN_QUALIFIER unsigned long num_hash_comps;
4242 int error;
43 #ifdef TSAN_REQUIRES_LOCKING
44 CRYPTO_RWLOCK *tsan_lock;
45 #endif
4346 };
00 /*
1 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2525 #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODULE)
2626 # include "internal/tsan_assist.h"
2727
28 # ifdef TSAN_REQUIRES_LOCKING
29 # define INCREMENT(x) /* empty */
30 # define LOAD(x) 0
31 # else /* TSAN_REQUIRES_LOCKING */
2832 static TSAN_QUALIFIER int malloc_count;
2933 static TSAN_QUALIFIER int realloc_count;
3034 static TSAN_QUALIFIER int free_count;
3135
32 # define INCREMENT(x) tsan_counter(&(x))
36 # define INCREMENT(x) tsan_counter(&(x))
37 # define LOAD(x) tsan_load(&x)
38 # endif /* TSAN_REQUIRES_LOCKING */
3339
3440 static char *md_failstring;
3541 static long md_count;
7884 void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount)
7985 {
8086 if (mcount != NULL)
81 *mcount = tsan_load(&malloc_count);
87 *mcount = LOAD(malloc_count);
8288 if (rcount != NULL)
83 *rcount = tsan_load(&realloc_count);
89 *rcount = LOAD(realloc_count);
8490 if (fcount != NULL)
85 *fcount = tsan_load(&free_count);
91 *fcount = LOAD(free_count);
8692 }
8793
8894 /*
00 /*
1 * Copyright 2003-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2003-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
214214 return ossl_hexstr2buf_sep(str, buflen, DEFAULT_SEPARATOR);
215215 }
216216
217 static int buf2hexstr_sep(char *str, size_t str_n, size_t *strlen,
217 static int buf2hexstr_sep(char *str, size_t str_n, size_t *strlength,
218218 const unsigned char *buf, size_t buflen,
219219 const char sep)
220220 {
225225 int has_sep = (sep != CH_ZERO);
226226 size_t len = has_sep ? buflen * 3 : 1 + buflen * 2;
227227
228 if (strlen != NULL)
229 *strlen = len;
228 if (strlength != NULL)
229 *strlength = len;
230230 if (str == NULL)
231231 return 1;
232232
252252 return 1;
253253 }
254254
255 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
255 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength,
256256 const unsigned char *buf, size_t buflen,
257257 const char sep)
258258 {
259 return buf2hexstr_sep(str, str_n, strlen, buf, buflen, sep);
259 return buf2hexstr_sep(str, str_n, strlength, buf, buflen, sep);
260260 }
261261
262262 char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep)
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
08
19 #ifndef OPENSSL_NO_DEPRECATED_3_0
210
11 * WARNING: do not edit!
22 * Generated by crypto/objects/obj_dat.pl
33 *
4 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
4 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
55 * Licensed under the Apache License 2.0 (the "License"). You may not use
66 * this file except in compliance with the License. You can obtain a copy
77 * in the file LICENSE in the source distribution or at
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4040 ossl_pw_clear_passphrase_data(data);
4141 data->type = is_expl_passphrase;
4242 data->_.expl_passphrase.passphrase_copy =
43 OPENSSL_memdup(passphrase, passphrase_len);
43 passphrase_len != 0 ? OPENSSL_memdup(passphrase, passphrase_len)
44 : OPENSSL_malloc(1);
4445 if (data->_.expl_passphrase.passphrase_copy == NULL) {
4546 ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
4647 return 0;
108109 * UI_METHOD processor. It differs from UI_UTIL_read_pw() like this:
109110 *
110111 * 1. It constructs a prompt on its own, based on |prompt_info|.
111 * 2. It allocates a buffer for verification on its own.
112 * 2. It allocates a buffer for password and verification on its own
113 * to compensate for NUL terminator in UI password strings.
112114 * 3. It raises errors.
113115 * 4. It reports back the length of the prompted pass phrase.
114116 */
116118 const char *prompt_info, int verify,
117119 const UI_METHOD *ui_method, void *ui_data)
118120 {
119 char *prompt = NULL, *vpass = NULL;
120 int prompt_idx = -1, verify_idx = -1;
121 char *prompt = NULL, *ipass = NULL, *vpass = NULL;
122 int prompt_idx = -1, verify_idx = -1, res;
121123 UI *ui = NULL;
122124 int ret = 0;
123125
144146 goto end;
145147 }
146148
149 /* Get a buffer for verification prompt */
150 ipass = OPENSSL_zalloc(pass_size + 1);
151 if (ipass == NULL) {
152 ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
153 goto end;
154 }
155
147156 prompt_idx = UI_add_input_string(ui, prompt,
148157 UI_INPUT_FLAG_DEFAULT_PWD,
149 pass, 0, pass_size - 1) - 1;
158 ipass, 0, pass_size) - 1;
150159 if (prompt_idx < 0) {
151160 ERR_raise(ERR_LIB_CRYPTO, ERR_R_UI_LIB);
152161 goto end;
154163
155164 if (verify) {
156165 /* Get a buffer for verification prompt */
157 vpass = OPENSSL_zalloc(pass_size);
166 vpass = OPENSSL_zalloc(pass_size + 1);
158167 if (vpass == NULL) {
159168 ERR_raise(ERR_LIB_CRYPTO, ERR_R_MALLOC_FAILURE);
160169 goto end;
161170 }
162171 verify_idx = UI_add_verify_string(ui, prompt,
163172 UI_INPUT_FLAG_DEFAULT_PWD,
164 vpass, 0, pass_size - 1,
165 pass) - 1;
173 vpass, 0, pass_size,
174 ipass) - 1;
166175 if (verify_idx < 0) {
167176 ERR_raise(ERR_LIB_CRYPTO, ERR_R_UI_LIB);
168177 goto end;
177186 ERR_raise(ERR_LIB_CRYPTO, ERR_R_UI_LIB);
178187 break;
179188 default:
180 *pass_len = (size_t)UI_get_result_length(ui, prompt_idx);
189 res = UI_get_result_length(ui, prompt_idx);
190 if (res < 0) {
191 ERR_raise(ERR_LIB_CRYPTO, ERR_R_UI_LIB);
192 break;
193 }
194 *pass_len = (size_t)res;
195 memcpy(pass, ipass, *pass_len);
181196 ret = 1;
182197 break;
183198 }
184199
185200 end:
186 OPENSSL_free(vpass);
201 OPENSSL_clear_free(vpass, pass_size + 1);
202 OPENSSL_clear_free(ipass, pass_size + 1);
187203 OPENSSL_free(prompt);
188204 UI_free(ui);
189205 return ret;
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
973973 headerlen = BIO_get_mem_data(headerB, NULL);
974974 *header = pem_malloc(headerlen + 1, flags);
975975 *data = pem_malloc(len, flags);
976 if (*header == NULL || *data == NULL) {
977 pem_free(*header, flags, 0);
978 pem_free(*data, flags, 0);
979 goto end;
980 }
981 BIO_read(headerB, *header, headerlen);
976 if (*header == NULL || *data == NULL)
977 goto out_free;
978 if (headerlen != 0 && BIO_read(headerB, *header, headerlen) != headerlen)
979 goto out_free;
982980 (*header)[headerlen] = '\0';
983 BIO_read(dataB, *data, len);
981 if (BIO_read(dataB, *data, len) != len)
982 goto out_free;
984983 *len_out = len;
985984 *name_out = name;
986985 name = NULL;
987986 ret = 1;
988
987 goto end;
988
989 out_free:
990 pem_free(*header, flags, 0);
991 pem_free(*data, flags, 0);
989992 end:
990993 EVP_ENCODE_CTX_free(ctx);
991994 pem_free(name, flags, 0);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
135135 if (enc || (nid != -1)) {
136136 if (kstr == NULL) {
137137 klen = cb(buf, PEM_BUFSIZE, 1, u);
138 if (klen <= 0) {
138 if (klen < 0) {
139139 ERR_raise(ERR_LIB_PEM, PEM_R_READ_KEY);
140140 goto legacy_end;
141141 }
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
595595 QUERY elem, *r;
596596 int res = 0;
597597
598 if (nid <= 0 || store == NULL)
598 if (nid <= 0 || store == NULL || prop_query == NULL)
599599 return 0;
600600
601601 if (!ossl_property_read_lock(store))
604604 if (alg == NULL)
605605 goto err;
606606
607 elem.query = prop_query != NULL ? prop_query : "";
607 elem.query = prop_query;
608608 elem.provider = prov;
609609 r = lh_QUERY_retrieve(alg->cache, &elem);
610610 if (r == NULL)
628628 size_t len;
629629 int res = 1;
630630
631 if (nid <= 0 || store == NULL)
632 return 0;
633 if (prop_query == NULL)
634 return 1;
631 if (nid <= 0 || store == NULL || prop_query == NULL)
632 return 0;
635633
636634 if (!ossl_assert(prov != NULL))
637635 return 0;
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
602602 OSSL_PROVIDER tmpl = { 0, };
603603 OSSL_PROVIDER *actualtmp = NULL;
604604
605 if (actualprov != NULL)
606 *actualprov = NULL;
607
605608 if ((store = get_provider_store(prov->libctx)) == NULL)
606609 return 0;
607610
658661 err:
659662 CRYPTO_THREAD_unlock(store->lock);
660663 if (actualprov != NULL)
661 ossl_provider_free(actualtmp);
664 ossl_provider_free(*actualprov);
662665 return 0;
663666 }
664667
19441947 const char *pkey_name)
19451948 {
19461949 int sign_nid = OBJ_txt2nid(sign_name);
1947 int digest_nid = OBJ_txt2nid(digest_name);
1950 int digest_nid = NID_undef;
19481951 int pkey_nid = OBJ_txt2nid(pkey_name);
1952
1953 if (digest_name != NULL && digest_name[0] != '\0'
1954 && (digest_nid = OBJ_txt2nid(digest_name)) == NID_undef)
1955 return 0;
19491956
19501957 if (sign_nid == NID_undef)
19511958 return 0;
19571964 if (OBJ_find_sigid_algs(sign_nid, NULL, NULL))
19581965 return 1;
19591966
1960 if (digest_nid == NID_undef
1961 || pkey_nid == NID_undef)
1967 if (pkey_nid == NID_undef)
19621968 return 0;
19631969
19641970 return OBJ_add_sigid(sign_nid, digest_nid, pkey_nid);
7979 # define AF_UNIX_PORTABILITY "$ZAFN2"
8080 # define AF_UNIX_COMPATIBILITY "$ZPLS"
8181
82 if (!_arg_present(transport) || transport != NULL || transport[0] == '\0')
82 if (!_arg_present(transport) || transport == NULL || transport[0] == '\0')
8383 return socket(family, type, protocol);
8484
8585 socket_transport_name_get(AF_UNIX, current_transport, 20);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
528528 EVP_RAND_CTX *ctx;
529529 char *name;
530530
531 if (dgbl == NULL)
532 return NULL;
531533 name = dgbl->seed_name != NULL ? dgbl->seed_name : "SEED-SRC";
532534 rand = EVP_RAND_fetch(libctx, name, dgbl->seed_propq);
533535 if (rand == NULL) {
559561 OSSL_PARAM params[7], *p = params;
560562 char *name, *cipher;
561563
564 if (dgbl == NULL)
565 return NULL;
562566 name = dgbl->rng_name != NULL ? dgbl->rng_name : "CTR-DRBG";
563567 rand = EVP_RAND_fetch(libctx, name, dgbl->rng_propq);
564568 if (rand == NULL) {
757761 ERR_raise(ERR_LIB_CRYPTO, CRYPTO_R_RANDOM_SECTION_ERROR);
758762 return 0;
759763 }
764
765 if (dgbl == NULL)
766 return 0;
760767
761768 for (i = 0; i < sk_CONF_VALUE_num(elist); i++) {
762769 cval = sk_CONF_VALUE_value(elist, i);
00 /*
1 * Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
741741 if (RSA_get0_n(rsa) == NULL || RSA_get0_e(rsa) == NULL)
742742 goto err;
743743
744 if (!ossl_rsa_todata(rsa, tmpl, NULL))
744 if (!ossl_rsa_todata(rsa, tmpl, NULL, 1))
745745 goto err;
746746
747747 selection |= OSSL_KEYMGMT_SELECT_PUBLIC_KEY;
834834 goto err;
835835 }
836836
837 if (!ossl_rsa_fromdata(rsa, params))
837 if (!ossl_rsa_fromdata(rsa, params, 1))
838838 goto err;
839839
840840 switch (rsa_type) {
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
5959 return 1;
6060 }
6161
62 int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[])
63 {
64 const OSSL_PARAM *param_n, *param_e, *param_d;
62 int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private)
63 {
64 const OSSL_PARAM *param_n, *param_e, *param_d = NULL;
6565 BIGNUM *n = NULL, *e = NULL, *d = NULL;
6666 STACK_OF(BIGNUM) *factors = NULL, *exps = NULL, *coeffs = NULL;
6767 int is_private = 0;
7171
7272 param_n = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_N);
7373 param_e = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_E);
74 param_d = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
74 if (include_private)
75 param_d = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_RSA_D);
7576
7677 if ((param_n != NULL && !OSSL_PARAM_get_BN(param_n, &n))
7778 || (param_e != NULL && !OSSL_PARAM_get_BN(param_e, &e))
117118
118119 DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM)
119120
120 int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
121 int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
122 int include_private)
121123 {
122124 int ret = 0;
123125 const BIGNUM *rsa_d = NULL, *rsa_n = NULL, *rsa_e = NULL;
136138 goto err;
137139
138140 /* Check private key data integrity */
139 if (rsa_d != NULL) {
141 if (include_private && rsa_d != NULL) {
140142 int numprimes = sk_BIGNUM_const_num(factors);
141143 int numexps = sk_BIGNUM_const_num(exps);
142144 int numcoeffs = sk_BIGNUM_const_num(coeffs);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
212212 */
213213 int ret;
214214
215 BN_BLINDING_lock(b);
215 if (!BN_BLINDING_lock(b))
216 return 0;
217
216218 ret = BN_BLINDING_convert_ex(f, unblind, b, ctx);
217219 BN_BLINDING_unlock(b);
218220
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
279279 {
280280 OSSL_METHOD_STORE *store = get_loader_store(methdata->libctx);
281281 OSSL_NAMEMAP *namemap = ossl_namemap_stored(methdata->libctx);
282 const char *const propq = properties != NULL ? properties : "";
282283 void *method = NULL;
283284 int unsupported = 0;
284285
308309 unsupported = 1;
309310
310311 if (id == 0
311 || !ossl_method_store_cache_get(store, NULL, id, properties, &method)) {
312 || !ossl_method_store_cache_get(store, NULL, id, propq, &method)) {
312313 OSSL_METHOD_CONSTRUCT_METHOD mcm = {
313314 get_tmp_loader_store,
314315 get_loader_from_store,
316317 construct_loader,
317318 destruct_loader
318319 };
320 OSSL_PROVIDER *prov = NULL;
319321
320322 methdata->scheme_id = id;
321323 methdata->scheme = scheme;
322 methdata->propquery = properties;
324 methdata->propquery = propq;
323325 methdata->flag_construct_error_occurred = 0;
324326 if ((method = ossl_method_construct(methdata->libctx, OSSL_OP_STORE,
325 NULL, 0 /* !force_cache */,
327 &prov, 0 /* !force_cache */,
326328 &mcm, methdata)) != NULL) {
327329 /*
328330 * If construction did create a method for us, we know that there
331333 */
332334 if (id == 0)
333335 id = ossl_namemap_name2num(namemap, scheme);
334 ossl_method_store_cache_set(store, NULL, id, properties, method,
336 ossl_method_store_cache_set(store, prov, id, propq, method,
335337 up_ref_loader, free_loader);
336338 }
337339
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
524524
525525 if (p12 != NULL) {
526526 char *pass = NULL;
527 char tpass[PEM_BUFSIZE];
527 char tpass[PEM_BUFSIZE + 1];
528528 size_t tpass_len;
529529 EVP_PKEY *pkey = NULL;
530530 X509 *cert = NULL;
546546 OSSL_PARAM_END
547547 };
548548
549 if (!ossl_pw_get_passphrase(tpass, sizeof(tpass), &tpass_len,
549 if (!ossl_pw_get_passphrase(tpass, sizeof(tpass) - 1,
550 &tpass_len,
550551 pw_params, 0, &ctx->pwdata)) {
551552 ERR_raise(ERR_LIB_OSSL_STORE,
552553 OSSL_STORE_R_PASSPHRASE_CALLBACK_ERROR);
553554 goto p12_end;
554555 }
555556 pass = tpass;
556 if (!PKCS12_verify_mac(p12, pass, strlen(pass))) {
557 /*
558 * ossl_pw_get_passphrase() does not NUL terminate but
559 * we must do it for PKCS12_parse()
560 */
561 pass[tpass_len] = '\0';
562 if (!PKCS12_verify_mac(p12, pass, tpass_len)) {
557563 ERR_raise_data(ERR_LIB_OSSL_STORE,
558564 OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC,
559 strlen(pass) == 0 ? "empty password" :
565 tpass_len == 0 ? "empty password" :
560566 "maybe wrong password");
561567 goto p12_end;
562568 }
612618 }
613619 ctx->cached_info = infos;
614620 }
615 }
616 p12_end:
617 PKCS12_free(p12);
621 p12_end:
622 OPENSSL_cleanse(tpass, sizeof(tpass));
623 PKCS12_free(p12);
624 }
618625 *v = sk_OSSL_STORE_INFO_shift(ctx->cached_info);
619626 }
620627
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
260260 return 1;
261261 }
262262 # ifndef FIPS_MODULE
263 # ifdef OPENSSL_SYS_UNIX
264
265 static pthread_once_t fork_once_control = PTHREAD_ONCE_INIT;
266
267 static void fork_once_func(void)
268 {
269 # ifndef OPENSSL_NO_DEPRECATED_3_0
270 pthread_atfork(OPENSSL_fork_prepare,
271 OPENSSL_fork_parent, OPENSSL_fork_child);
272 # endif
273 }
274 # endif
275
276263 int openssl_init_fork_handlers(void)
277264 {
278 # ifdef OPENSSL_SYS_UNIX
279 if (pthread_once(&fork_once_control, fork_once_func) == 0)
280 return 1;
281 # endif
282 return 0;
265 return 1;
283266 }
284267 # endif /* FIPS_MODULE */
285268
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
135135 TRACE_CATEGORY_(PKCS12_DECRYPT),
136136 TRACE_CATEGORY_(X509V3_POLICY),
137137 TRACE_CATEGORY_(BN_CTX),
138 TRACE_CATEGORY_(CMP),
138139 TRACE_CATEGORY_(STORE),
139140 TRACE_CATEGORY_(DECODER),
140141 TRACE_CATEGORY_(ENCODER),
495496 char *suffix = NULL;
496497
497498 category = ossl_trace_get_category(category);
499 if (category < 0)
500 return;
498501 suffix = trace_channels[category].suffix;
499502 if (channel != NULL
500503 && ossl_assert(channel == current_channel)) {
00 /*
1 * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
550550
551551 static int close_console(UI *ui)
552552 {
553 int ret = 1;
554
553555 if (tty_in != stdin)
554556 fclose(tty_in);
555557 if (tty_out != stderr)
559561 if (status != SS$_NORMAL) {
560562 ERR_raise_data(ERR_LIB_UI, UI_R_SYSDASSGN_ERROR,
561563 "status=%%X%08X", status);
562 return 0;
564 ret = 0;
563565 }
564566 # endif
565567 CRYPTO_THREAD_unlock(ui->lock);
566568
567 return 1;
569 return ret;
568570 }
569571
570572 # if !defined(OPENSSL_SYS_WINCE)
00 /*
1 * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
7272 static int ui_dup_method_data(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from,
7373 void **pptr, int idx, long argl, void *argp)
7474 {
75 if (*pptr != NULL)
75 if (*pptr != NULL) {
7676 *pptr = OPENSSL_memdup(*pptr, sizeof(struct pem_password_cb_data));
77 return 1;
77 if (*pptr != NULL)
78 return 1;
79 }
80 return 0;
7881 }
7982
8083 static void ui_free_method_data(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
113116
114117 if (len >= 0)
115118 result[len] = '\0';
116 if (len <= 0)
119 if (len < 0)
117120 return len;
118121 if (UI_set_result_ex(ui, uis, result, len) >= 0)
119122 return 1;
00 /*
1 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
8282 return -1;
8383 dnsect = X509V3_get_section(ctx, cnf->value);
8484 if (!dnsect) {
85 X509_NAME_free(nm);
8586 ERR_raise(ERR_LIB_X509V3, X509V3_R_SECTION_NOT_FOUND);
8687 return -1;
8788 }
00 /*
1 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
166166 goto err;
167167 if (!ASN1_INTEGER_set(sx->version, 0))
168168 goto err;
169 *psx = sx;
170169 } else
171170 sx = *psx;
172171 if (SXNET_get_id_INTEGER(sx, zone)) {
173172 ERR_raise(ERR_LIB_X509V3, X509V3_R_DUPLICATE_ZONE_ID);
173 if (*psx == NULL)
174 SXNET_free(sx);
174175 return 0;
175176 }
176177
184185 if (!sk_SXNETID_push(sx->ids, id))
185186 goto err;
186187 id->zone = zone;
188 *psx = sx;
187189 return 1;
188190
189191 err:
190192 ERR_raise(ERR_LIB_X509V3, ERR_R_MALLOC_FAILURE);
191193 SXNETID_free(id);
192 SXNET_free(sx);
193 *psx = NULL;
194 if (*psx == NULL)
195 SXNET_free(sx);
194196 return 0;
195197 }
196198
00 /*
1 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
538538 return 0;
539539
540540 emtmp = OPENSSL_strndup((char *)email->data, email->length);
541 if (emtmp == NULL)
542 return 0;
541 if (emtmp == NULL) {
542 X509_email_free(*sk);
543 *sk = NULL;
544 return 0;
545 }
543546
544547 /* Don't add duplicates */
545548 if (sk_OPENSSL_STRING_find(*sk, emtmp) != -1) {
832835 rv = equal(a->data, a->length, (unsigned char *)b, blen, flags);
833836 else if (a->length == (int)blen && !memcmp(a->data, b, blen))
834837 rv = 1;
835 if (rv > 0 && peername)
838 if (rv > 0 && peername != NULL) {
836839 *peername = OPENSSL_strndup((char *)a->data, a->length);
840 if (*peername == NULL)
841 return -1;
842 }
837843 } else {
838844 int astrlen;
839845 unsigned char *astr;
846852 return -1;
847853 }
848854 rv = equal(astr, astrlen, (unsigned char *)b, blen, flags);
849 if (rv > 0 && peername)
855 if (rv > 0 && peername != NULL) {
850856 *peername = OPENSSL_strndup((char *)astr, astrlen);
857 if (*peername == NULL) {
858 OPENSSL_free(astr);
859 return -1;
860 }
861 }
851862 OPENSSL_free(astr);
852863 }
853864 return rv;
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
320320 stmp.type = X509_LU_NONE;
321321 stmp.data.ptr = NULL;
322322
323 X509_STORE_lock(store);
323 if (!X509_STORE_lock(store))
324 return 0;
325
324326 tmp = X509_OBJECT_retrieve_by_subject(store->objs, type, name);
325327 X509_STORE_unlock(store);
326328
370372 return 0;
371373 }
372374
373 X509_STORE_lock(store);
375 if (!X509_STORE_lock(store)) {
376 obj->type = X509_LU_NONE;
377 X509_OBJECT_free(obj);
378 return 0;
379 }
380
374381 if (X509_OBJECT_retrieve_match(store->objs, obj)) {
375382 ret = 1;
376383 } else {
552559 }
553560 if ((sk = sk_X509_new_null()) == NULL)
554561 return NULL;
555 X509_STORE_lock(store);
562 if (!X509_STORE_lock(store))
563 goto out_free;
564
556565 objs = X509_STORE_get0_objects(store);
557566 for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
558567 X509 *cert = X509_OBJECT_get0_X509(sk_X509_OBJECT_value(objs, i));
566575
567576 err:
568577 X509_STORE_unlock(store);
578 out_free:
569579 sk_X509_pop_free(sk, X509_free);
570580 return NULL;
571581 }
582592 if (store == NULL)
583593 return NULL;
584594
585 X509_STORE_lock(store);
595 if (!X509_STORE_lock(store))
596 return NULL;
597
586598 idx = x509_object_idx_cnt(store->objs, X509_LU_X509, nm, &cnt);
587599 if (idx < 0) {
588600 /*
600612 return NULL;
601613 }
602614 X509_OBJECT_free(xobj);
603 X509_STORE_lock(store);
615 if (!X509_STORE_lock(store))
616 return NULL;
604617 idx = x509_object_idx_cnt(store->objs, X509_LU_X509, nm, &cnt);
605618 if (idx < 0) {
606619 X509_STORE_unlock(store);
641654 return NULL;
642655 }
643656 X509_OBJECT_free(xobj);
644 X509_STORE_lock(store);
657 if (!X509_STORE_lock(store)) {
658 sk_X509_CRL_free(sk);
659 return NULL;
660 }
645661 idx = x509_object_idx_cnt(store->objs, X509_LU_CRL, nm, &cnt);
646662 if (idx < 0) {
647663 X509_STORE_unlock(store);
743759
744760 /* Find index of first currently valid cert accepted by 'check_issued' */
745761 ret = 0;
746 X509_STORE_lock(store);
762 if (!X509_STORE_lock(store))
763 return 0;
764
747765 idx = x509_object_idx_cnt(store->objs, X509_LU_X509, xn, &nmatch);
748766 if (idx != -1) { /* should be true as we've had at least one match */
749767 /* Look through all matching certs for suitable issuer */
00 /*
1 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
7171 return obj_trust(NID_anyExtendedKeyUsage, x,
7272 flags | X509_TRUST_DO_SS_COMPAT);
7373 idx = X509_TRUST_get_by_id(id);
74 if (idx == -1)
74 if (idx < 0)
7575 return default_trust(id, x, flags);
7676 pt = X509_TRUST_get0(idx);
7777 return pt->check_trust(pt, x, flags);
111111
112112 int X509_TRUST_set(int *t, int trust)
113113 {
114 if (X509_TRUST_get_by_id(trust) == -1) {
114 if (X509_TRUST_get_by_id(trust) < 0) {
115115 ERR_raise(ERR_LIB_X509, X509_R_INVALID_TRUST);
116116 return 0;
117117 }
133133 /* Get existing entry if any */
134134 idx = X509_TRUST_get_by_id(id);
135135 /* Need a new entry */
136 if (idx == -1) {
136 if (idx < 0) {
137137 if ((trtmp = OPENSSL_malloc(sizeof(*trtmp))) == NULL) {
138138 ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
139139 return 0;
161161 trtmp->arg2 = arg2;
162162
163163 /* If its a new entry manage the dynamic table */
164 if (idx == -1) {
164 if (idx < 0) {
165165 if (trtable == NULL
166166 && (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) {
167167 ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
174174 }
175175 return 1;
176176 err:
177 if (idx == -1) {
177 if (idx < 0) {
178178 OPENSSL_free(trtmp->name);
179179 OPENSSL_free(trtmp);
180180 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
22292229 /* If purpose not set use default */
22302230 if (purpose == 0)
22312231 purpose = def_purpose;
2232 /*
2233 * If purpose is set but we don't have a default then set the default to
2234 * the current purpose
2235 */
2236 else if (def_purpose == 0)
2237 def_purpose = purpose;
22322238 /* If we have a purpose then check it is valid */
22332239 if (purpose != 0) {
22342240 X509_PURPOSE *ptmp;
22412247 ptmp = X509_PURPOSE_get0(idx);
22422248 if (ptmp->trust == X509_TRUST_DEFAULT) {
22432249 idx = X509_PURPOSE_get_by_id(def_purpose);
2244 /*
2245 * XXX: In the two callers above def_purpose is always 0, which is
2246 * not a known value, so idx will always be -1. How is the
2247 * X509_TRUST_DEFAULT case actually supposed to be handled?
2248 */
22492250 if (idx == -1) {
22502251 ERR_raise(ERR_LIB_X509, X509_R_UNKNOWN_PURPOSE_ID);
22512252 return 0;
99 cipher:
1010 aesgcm.c Demonstration of symmetric cipher GCM mode encrypt/decrypt
1111 aesccm.c Demonstration of symmetric cipher CCM mode encrypt/decrypt
12 ariacbc.c Demonstration of symmetric cipher CBC mode encrypt/decrypt
1213
1314 cms:
1415
1516 digest:
1617 EVP_MD_demo.c Compute a digest from multiple buffers
1718 EVP_MD_stdin.c Compute a digest with data read from stdin
19 EVP_MD_xof.c Compute a digest using the SHAKE256 XOF
1820 EVP_f_md.c Compute a digest using BIO and EVP_f_md
1921
2022 kdf:
2426
2527 mac:
2628 gmac.c Demonstration of GMAC message authentication
29 poly1305.c Demonstration of Poly1305-AES message authentication
30 siphash.c Demonstration of SIPHASH message authentication
2731
2832 pkey:
2933 EVP_PKEY_EC_keygen.c Generate an EC key.
34 EVP_PKEY_RSA_keygen.c Generate an RSA key.
3035
3136 smime:
3237
3641
3742 signature:
3843 EVP_Signature_demo.c Compute and verify a signature from multiple buffers
44 rsa_pss_direct.c Compute and verify an RSA-PSS signature from a hash
45 rsa_pss_hash.c Compute and verify an RSA-PSS signature over a buffer
1010 CFLAGS = $(OPENSSL_INCS_LOCATION)
1111 LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto
1212
13 all: aesccm aesgcm
13 all: aesccm aesgcm ariacbc
1414
1515 aesccm: aesccm.o
1616 aesgcm: aesgcm.o
17 ariacbc: ariacbc.o
1718
18 aesccm aesgcm:
19 aesccm aesgcm ariacbc:
1920 $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
2021
2122 clean:
22 $(RM) aesccm aesgcm *.o
23 $(RM) aesccm aesgcm ariacbc *.o
0 /*
1 * Copyright 2012-2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 /*
10 * Simple ARIA CBC encryption demonstration program.
11 */
12
13 #include <stdio.h>
14 #include <openssl/err.h>
15 #include <openssl/bio.h>
16 #include <openssl/evp.h>
17 #include <openssl/crypto.h>
18 #include <openssl/core_names.h>
19
20 /* ARIA key */
21 static const unsigned char cbc_key[] = {
22 0xee, 0xbc, 0x1f, 0x57, 0x48, 0x7f, 0x51, 0x92, 0x1c, 0x04, 0x65, 0x66,
23 0x5f, 0x8a, 0xe6, 0xd1, 0x65, 0x8b, 0xb2, 0x6d, 0xe6, 0xf8, 0xa0, 0x69,
24 0xa3, 0x52, 0x02, 0x93, 0xa5, 0x72, 0x07, 0x8f
25 };
26
27 /* Unique initialisation vector */
28 static const unsigned char cbc_iv[] = {
29 0x99, 0xaa, 0x3e, 0x68, 0xed, 0x81, 0x73, 0xa0, 0xee, 0xd0, 0x66, 0x84,
30 0x99, 0xaa, 0x3e, 0x68,
31 };
32
33 /* Example plaintext to encrypt */
34 static const unsigned char cbc_pt[] = {
35 0xf5, 0x6e, 0x87, 0x05, 0x5b, 0xc3, 0x2d, 0x0e, 0xeb, 0x31, 0xb2, 0xea,
36 0xcc, 0x2b, 0xf2, 0xa5
37 };
38
39 /* Expected ciphertext value */
40 static const unsigned char cbc_ct[] = {
41 0x9a, 0x44, 0xe6, 0x85, 0x94, 0x26, 0xff, 0x30, 0x03, 0xd3, 0x7e, 0xc6,
42 0xb5, 0x4a, 0x09, 0x66, 0x39, 0x28, 0xf3, 0x67, 0x14, 0xbc, 0xe8, 0xe2,
43 0xcf, 0x31, 0xb8, 0x60, 0x42, 0x72, 0x6d, 0xc8
44 };
45
46 /*
47 * A library context and property query can be used to select & filter
48 * algorithm implementations. If they are NULL then the default library
49 * context and properties are used.
50 */
51 OSSL_LIB_CTX *libctx = NULL;
52 const char *propq = NULL;
53
54 int aria_cbc_encrypt(void)
55 {
56 int ret = 0;
57 EVP_CIPHER_CTX *ctx;
58 EVP_CIPHER *cipher = NULL;
59 int outlen, tmplen;
60 size_t cbc_ivlen = sizeof(cbc_iv);
61 unsigned char outbuf[1024];
62 unsigned char outtag[16];
63
64 printf("ARIA CBC Encrypt:\n");
65 printf("Plaintext:\n");
66 BIO_dump_fp(stdout, cbc_pt, sizeof(cbc_pt));
67
68 /* Create a context for the encrypt operation */
69 if ((ctx = EVP_CIPHER_CTX_new()) == NULL)
70 goto err;
71
72 /* Fetch the cipher implementation */
73 if ((cipher = EVP_CIPHER_fetch(libctx, "ARIA-256-CBC", propq)) == NULL)
74 goto err;
75
76 /*
77 * Initialise an encrypt operation with the cipher/mode, key and IV.
78 * We are not setting any custom params so let params be just NULL.
79 */
80 if (!EVP_EncryptInit_ex2(ctx, cipher, cbc_key, cbc_iv, /* params */ NULL))
81 goto err;
82
83 /* Encrypt plaintext */
84 if (!EVP_EncryptUpdate(ctx, outbuf, &outlen, cbc_pt, sizeof(cbc_pt)))
85 goto err;
86
87 /* Finalise: there can be some additional output from padding */
88 if (!EVP_EncryptFinal_ex(ctx, outbuf + outlen, &tmplen))
89 goto err;
90 outlen += tmplen;
91
92 /* Output encrypted block */
93 printf("Ciphertext (outlen:%d):\n", outlen);
94 BIO_dump_fp(stdout, outbuf, outlen);
95
96 if (sizeof(cbc_ct) == outlen && !CRYPTO_memcmp(outbuf, cbc_ct, outlen))
97 printf("Final ciphertext matches expected ciphertext\n");
98 else
99 printf("Final ciphertext differs from expected ciphertext\n");
100
101 ret = 1;
102 err:
103 if (!ret)
104 ERR_print_errors_fp(stderr);
105
106 EVP_CIPHER_free(cipher);
107 EVP_CIPHER_CTX_free(ctx);
108
109 return ret;
110 }
111
112 int aria_cbc_decrypt(void)
113 {
114 int ret = 0;
115 EVP_CIPHER_CTX *ctx;
116 EVP_CIPHER *cipher = NULL;
117 int outlen, tmplen, rv;
118 size_t cbc_ivlen = sizeof(cbc_iv);
119 unsigned char outbuf[1024];
120
121 printf("ARIA CBC Decrypt:\n");
122 printf("Ciphertext:\n");
123 BIO_dump_fp(stdout, cbc_ct, sizeof(cbc_ct));
124
125 if ((ctx = EVP_CIPHER_CTX_new()) == NULL)
126 goto err;
127
128 /* Fetch the cipher implementation */
129 if ((cipher = EVP_CIPHER_fetch(libctx, "ARIA-256-CBC", propq)) == NULL)
130 goto err;
131
132 /*
133 * Initialise an encrypt operation with the cipher/mode, key and IV.
134 * We are not setting any custom params so let params be just NULL.
135 */
136 if (!EVP_DecryptInit_ex2(ctx, cipher, cbc_key, cbc_iv, /* params */ NULL))
137 goto err;
138
139 /* Decrypt plaintext */
140 if (!EVP_DecryptUpdate(ctx, outbuf, &outlen, cbc_ct, sizeof(cbc_ct)))
141 goto err;
142
143 /* Finalise: there can be some additional output from padding */
144 if (!EVP_DecryptFinal_ex(ctx, outbuf + outlen, &tmplen))
145 goto err;
146 outlen += tmplen;
147
148 /* Output decrypted block */
149 printf("Plaintext (outlen:%d):\n", outlen);
150 BIO_dump_fp(stdout, outbuf, outlen);
151
152 if (sizeof(cbc_pt) == outlen && !CRYPTO_memcmp(outbuf, cbc_pt, outlen))
153 printf("Final plaintext matches original plaintext\n");
154 else
155 printf("Final plaintext differs from original plaintext\n");
156
157 ret = 1;
158 err:
159 if (!ret)
160 ERR_print_errors_fp(stderr);
161
162 EVP_CIPHER_free(cipher);
163 EVP_CIPHER_CTX_free(ctx);
164
165 return ret;
166 }
167
168 int main(int argc, char **argv)
169 {
170 if (!aria_cbc_encrypt())
171 return 1;
172
173 if (!aria_cbc_decrypt())
174 return 1;
175
176 return 0;
177 }
2626 /* Set up trusted CA certificate store */
2727
2828 st = X509_STORE_new();
29 if (st == NULL)
30 goto err;
2931
3032 /* Read in CA certificate */
3133 tbio = BIO_new_file("cacert.pem", "r");
3234
33 if (!tbio)
35 if (tbio == NULL)
3436 goto err;
3537
3638 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
3739
38 if (!cacert)
40 if (cacert == NULL)
3941 goto err;
4042
4143 if (!X509_STORE_add_cert(st, cacert))
4547
4648 in = BIO_new_file("smout.txt", "r");
4749
48 if (!in)
50 if (in == NULL)
4951 goto err;
5052
5153 /* parse message */
5254 cms = SMIME_read_CMS(in, &cont);
5355
54 if (!cms)
56 if (cms == NULL)
5557 goto err;
5658
5759 /* File to output verified content to */
5860 out = BIO_new_file("smver.txt", "w");
59 if (!out)
61 if (out == NULL)
6062 goto err;
6163
6264 if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
7577 ERR_print_errors_fp(stderr);
7678 }
7779
80 X509_STORE_free(st);
7881 CMS_ContentInfo_free(cms);
7982 X509_free(cacert);
8083 BIO_free(in);
0 /*-
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <openssl/err.h>
12 #include <openssl/evp.h>
13 #include <openssl/core_names.h>
14
15 /*
16 * Example of using an extendable-output hash function (XOF). A XOF is a hash
17 * function with configurable output length and which can generate an
18 * arbitrarily large output.
19 *
20 * This example uses SHAKE256, an extendable output variant of SHA3 (Keccak).
21 *
22 * To generate different output lengths, you can pass a single integer argument
23 * on the command line, which is the output size in bytes. By default, a 20-byte
24 * output is generated and (for this length only) a known answer test is
25 * performed.
26 */
27
28 /* Our input to the XOF hash function. */
29 const char message[] = "This is a test message.";
30
31 /* Expected output when an output length of 20 bytes is used. */
32 static const char known_answer[] = {
33 0x52, 0x97, 0x93, 0x78, 0x27, 0x58, 0x7d, 0x62,
34 0x8b, 0x00, 0x25, 0xb5, 0xec, 0x39, 0x5e, 0x2d,
35 0x7f, 0x3e, 0xd4, 0x19
36 };
37
38 /*
39 * A property query used for selecting the SHAKE256 implementation.
40 */
41 static const char *propq = NULL;
42
43 int main(int argc, char **argv)
44 {
45 int rv = 1;
46 OSSL_LIB_CTX *libctx = NULL;
47 EVP_MD *md = NULL;
48 EVP_MD_CTX *ctx = NULL;
49 unsigned int digest_len = 20;
50 int digest_len_i;
51 unsigned char *digest = NULL;
52
53 /* Allow digest length to be changed for demonstration purposes. */
54 if (argc > 1) {
55 digest_len_i = atoi(argv[1]);
56 if (digest_len_i <= 0) {
57 fprintf(stderr, "Specify a non-negative digest length\n");
58 goto end;
59 }
60
61 digest_len = (unsigned int)digest_len_i;
62 }
63
64 /*
65 * Retrieve desired algorithm. This must be a hash algorithm which supports
66 * XOF.
67 */
68 md = EVP_MD_fetch(libctx, "SHAKE256", propq);
69 if (md == NULL) {
70 fprintf(stderr, "Failed to retrieve SHAKE256 algorithm\n");
71 goto end;
72 }
73
74 /* Create context. */
75 ctx = EVP_MD_CTX_new();
76 if (ctx == NULL) {
77 fprintf(stderr, "Failed to create digest context\n");
78 goto end;
79 }
80
81 /* Initialize digest context. */
82 if (EVP_DigestInit(ctx, md) == 0) {
83 fprintf(stderr, "Failed to initialize digest\n");
84 goto end;
85 }
86
87 /*
88 * Feed our message into the digest function.
89 * This may be called multiple times.
90 */
91 if (EVP_DigestUpdate(ctx, message, sizeof(message)) == 0) {
92 fprintf(stderr, "Failed to hash input message\n");
93 goto end;
94 }
95
96 /* Allocate enough memory for our digest length. */
97 digest = OPENSSL_malloc(digest_len);
98 if (digest == NULL) {
99 fprintf(stderr, "Failed to allocate memory for digest\n");
100 goto end;
101 }
102
103 /* Get computed digest. The digest will be of whatever length we specify. */
104 if (EVP_DigestFinalXOF(ctx, digest, digest_len) == 0) {
105 fprintf(stderr, "Failed to finalize hash\n");
106 goto end;
107 }
108
109 printf("Output digest:\n");
110 BIO_dump_indent_fp(stdout, digest, digest_len, 2);
111
112 /* If digest length is 20 bytes, check it matches our known answer. */
113 if (digest_len == 20) {
114 /*
115 * Always use a constant-time function such as CRYPTO_memcmp
116 * when comparing cryptographic values. Do not use memcmp(3).
117 */
118 if (CRYPTO_memcmp(digest, known_answer, sizeof(known_answer)) != 0) {
119 fprintf(stderr, "Output does not match expected result\n");
120 goto end;
121 }
122 }
123
124 rv = 0;
125 end:
126 OPENSSL_free(digest);
127 EVP_MD_CTX_free(ctx);
128 EVP_MD_free(md);
129 OSSL_LIB_CTX_free(libctx);
130 return rv;
131 }
22 #
33 # LD_LIBRARY_PATH=../.. ./EVP_MD_demo
44
5 CFLAGS = -I../../include -g
5 CFLAGS = -I../../include -g -Wall
66 LDFLAGS = -L../..
77 LDLIBS = -lcrypto
88
9 all: EVP_MD_demo EVP_MD_stdin BIO_f_md
9 all: EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md
1010
1111 %.o: %.c
1212 $(CC) $(CFLAGS) -c $<
1313
1414 EVP_MD_demo: EVP_MD_demo.o
1515 EVP_MD_stdin: EVP_MD_stdin.o
16 EVP_MD_xof: EVP_MD_xof.o
1617 BIO_f_md: BIO_f_md.o
1718
1819 test: ;
1920
2021 clean:
21 $(RM) *.o EVP_MD_demo EVP_MD_stdin BIO_f_md
22 $(RM) *.o EVP_MD_demo EVP_MD_stdin EVP_MD_xof BIO_f_md
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <openssl/core_names.h>
12 #include <openssl/evp.h>
13
14 /*
15 * This is a demonstration of key exchange using X25519.
16 *
17 * The variables beginning `peer1_` / `peer2_` are data which would normally be
18 * accessible to that peer.
19 *
20 * Ordinarily you would use random keys, which are demonstrated
21 * below when use_kat=0. A known answer test is demonstrated
22 * when use_kat=1.
23 */
24
25 /* A property query used for selecting the X25519 implementation. */
26 static const char *propq = NULL;
27
28 static const unsigned char peer1_privk_data[32] = {
29 0x80, 0x5b, 0x30, 0x20, 0x25, 0x4a, 0x70, 0x2c,
30 0xad, 0xa9, 0x8d, 0x7d, 0x47, 0xf8, 0x1b, 0x20,
31 0x89, 0xd2, 0xf9, 0x14, 0xac, 0x92, 0x27, 0xf2,
32 0x10, 0x7e, 0xdb, 0x21, 0xbd, 0x73, 0x73, 0x5d
33 };
34
35 static const unsigned char peer2_privk_data[32] = {
36 0xf8, 0x84, 0x19, 0x69, 0x79, 0x13, 0x0d, 0xbd,
37 0xb1, 0x76, 0xd7, 0x0e, 0x7e, 0x0f, 0xb6, 0xf4,
38 0x8c, 0x4a, 0x8c, 0x5f, 0xd8, 0x15, 0x09, 0x0a,
39 0x71, 0x78, 0x74, 0x92, 0x0f, 0x85, 0xc8, 0x43
40 };
41
42 static const unsigned char expected_result[32] = {
43 0x19, 0x71, 0x26, 0x12, 0x74, 0xb5, 0xb1, 0xce,
44 0x77, 0xd0, 0x79, 0x24, 0xb6, 0x0a, 0x5c, 0x72,
45 0x0c, 0xa6, 0x56, 0xc0, 0x11, 0xeb, 0x43, 0x11,
46 0x94, 0x3b, 0x01, 0x45, 0xca, 0x19, 0xfe, 0x09
47 };
48
49 typedef struct peer_data_st {
50 const char *name; /* name of peer */
51 EVP_PKEY *privk; /* privk generated for peer */
52 unsigned char pubk_data[32]; /* generated pubk to send to other peer */
53
54 unsigned char *secret; /* allocated shared secret buffer */
55 size_t secret_len;
56 } PEER_DATA;
57
58 /*
59 * Prepare for X25519 key exchange. The public key to be sent to the remote peer
60 * is put in pubk_data, which should be a 32-byte buffer. Returns 1 on success.
61 */
62 static int keyexch_x25519_before(
63 OSSL_LIB_CTX *libctx,
64 const unsigned char *kat_privk_data,
65 PEER_DATA *local_peer)
66 {
67 int rv = 0;
68 size_t pubk_data_len = 0;
69
70 /* Generate or load X25519 key for the peer */
71 if (kat_privk_data != NULL)
72 local_peer->privk =
73 EVP_PKEY_new_raw_private_key_ex(libctx, "X25519", propq,
74 kat_privk_data,
75 sizeof(peer1_privk_data));
76 else
77 local_peer->privk = EVP_PKEY_Q_keygen(libctx, propq, "X25519");
78
79 if (local_peer->privk == NULL) {
80 fprintf(stderr, "Could not load or generate private key\n");
81 goto end;
82 }
83
84 /* Get public key corresponding to the private key */
85 if (EVP_PKEY_get_octet_string_param(local_peer->privk,
86 OSSL_PKEY_PARAM_PUB_KEY,
87 local_peer->pubk_data,
88 sizeof(local_peer->pubk_data),
89 &pubk_data_len) == 0) {
90 fprintf(stderr, "EVP_PKEY_get_octet_string_param() failed\n");
91 goto end;
92 }
93
94 /* X25519 public keys are always 32 bytes */
95 if (pubk_data_len != 32) {
96 fprintf(stderr, "EVP_PKEY_get_octet_string_param() "
97 "yielded wrong length\n");
98 goto end;
99 }
100
101 rv = 1;
102 end:
103 if (rv == 0) {
104 EVP_PKEY_free(local_peer->privk);
105 local_peer->privk = NULL;
106 }
107
108 return rv;
109 }
110
111 /*
112 * Complete X25519 key exchange. remote_peer_pubk_data should be the 32 byte
113 * public key value received from the remote peer. On success, returns 1 and the
114 * secret is pointed to by *secret. The caller must free it.
115 */
116 static int keyexch_x25519_after(
117 OSSL_LIB_CTX *libctx,
118 int use_kat,
119 PEER_DATA *local_peer,
120 const unsigned char *remote_peer_pubk_data)
121 {
122 int rv = 0;
123 EVP_PKEY *remote_peer_pubk = NULL;
124 EVP_PKEY_CTX *ctx = NULL;
125
126 local_peer->secret = NULL;
127
128 /* Load public key for remote peer. */
129 remote_peer_pubk =
130 EVP_PKEY_new_raw_public_key_ex(libctx, "X25519", propq,
131 remote_peer_pubk_data, 32);
132 if (remote_peer_pubk == NULL) {
133 fprintf(stderr, "EVP_PKEY_new_raw_public_key_ex() failed\n");
134 goto end;
135 }
136
137 /* Create key exchange context. */
138 ctx = EVP_PKEY_CTX_new_from_pkey(libctx, local_peer->privk, propq);
139 if (ctx == NULL) {
140 fprintf(stderr, "EVP_PKEY_CTX_new_from_pkey() failed\n");
141 goto end;
142 }
143
144 /* Initialize derivation process. */
145 if (EVP_PKEY_derive_init(ctx) == 0) {
146 fprintf(stderr, "EVP_PKEY_derive_init() failed\n");
147 goto end;
148 }
149
150 /* Configure each peer with the other peer's public key. */
151 if (EVP_PKEY_derive_set_peer(ctx, remote_peer_pubk) == 0) {
152 fprintf(stderr, "EVP_PKEY_derive_set_peer() failed\n");
153 goto end;
154 }
155
156 /* Determine the secret length. */
157 if (EVP_PKEY_derive(ctx, NULL, &local_peer->secret_len) == 0) {
158 fprintf(stderr, "EVP_PKEY_derive() failed\n");
159 goto end;
160 }
161
162 /*
163 * We are using X25519, so the secret generated will always be 32 bytes.
164 * However for exposition, the code below demonstrates a generic
165 * implementation for arbitrary lengths.
166 */
167 if (local_peer->secret_len != 32) { /* unreachable */
168 fprintf(stderr, "Secret is always 32 bytes for X25519\n");
169 goto end;
170 }
171
172 /* Allocate memory for shared secrets. */
173 local_peer->secret = OPENSSL_malloc(local_peer->secret_len);
174 if (local_peer->secret == NULL) {
175 fprintf(stderr, "Could not allocate memory for secret\n");
176 goto end;
177 }
178
179 /* Derive the shared secret. */
180 if (EVP_PKEY_derive(ctx, local_peer->secret,
181 &local_peer->secret_len) == 0) {
182 fprintf(stderr, "EVP_PKEY_derive() failed\n");
183 goto end;
184 }
185
186 printf("Shared secret (%s):\n", local_peer->name);
187 BIO_dump_indent_fp(stdout, local_peer->secret, local_peer->secret_len, 2);
188 putchar('\n');
189
190 rv = 1;
191 end:
192 EVP_PKEY_CTX_free(ctx);
193 EVP_PKEY_free(remote_peer_pubk);
194 if (rv == 0) {
195 OPENSSL_clear_free(local_peer->secret, local_peer->secret_len);
196 local_peer->secret = NULL;
197 }
198
199 return rv;
200 }
201
202 static int keyexch_x25519(int use_kat)
203 {
204 int rv = 0;
205 OSSL_LIB_CTX *libctx = NULL;
206 PEER_DATA peer1 = {"peer 1"}, peer2 = {"peer 2"};
207
208 /*
209 * Each peer generates its private key and sends its public key
210 * to the other peer. The private key is stored locally for
211 * later use.
212 */
213 if (keyexch_x25519_before(libctx, use_kat ? peer1_privk_data : NULL,
214 &peer1) == 0)
215 return 0;
216
217 if (keyexch_x25519_before(libctx, use_kat ? peer2_privk_data : NULL,
218 &peer2) == 0)
219 return 0;
220
221 /*
222 * Each peer uses the other peer's public key to perform key exchange.
223 * After this succeeds, each peer has the same secret in its
224 * PEER_DATA.
225 */
226 if (keyexch_x25519_after(libctx, use_kat, &peer1, peer2.pubk_data) == 0)
227 return 0;
228
229 if (keyexch_x25519_after(libctx, use_kat, &peer2, peer1.pubk_data) == 0)
230 return 0;
231
232 /*
233 * Here we demonstrate the secrets are equal for exposition purposes.
234 *
235 * Although in practice you will generally not need to compare secrets
236 * produced through key exchange, if you do compare cryptographic secrets,
237 * always do so using a constant-time function such as CRYPTO_memcmp, never
238 * using memcmp(3).
239 */
240 if (CRYPTO_memcmp(peer1.secret, peer2.secret, peer1.secret_len) != 0) {
241 fprintf(stderr, "Negotiated secrets do not match\n");
242 goto end;
243 }
244
245 /* If we are doing the KAT, the secret should equal our reference result. */
246 if (use_kat && CRYPTO_memcmp(peer1.secret, expected_result,
247 peer1.secret_len) != 0) {
248 fprintf(stderr, "Did not get expected result\n");
249 goto end;
250 }
251
252 rv = 1;
253 end:
254 /* The secrets are sensitive, so ensure they are erased before freeing. */
255 OPENSSL_clear_free(peer1.secret, peer1.secret_len);
256 OPENSSL_clear_free(peer2.secret, peer2.secret_len);
257
258 EVP_PKEY_free(peer1.privk);
259 EVP_PKEY_free(peer2.privk);
260 OSSL_LIB_CTX_free(libctx);
261 return rv;
262 }
263
264 int main(int argc, char **argv)
265 {
266 /* Test X25519 key exchange with known result. */
267 printf("Key exchange using known answer (deterministic):\n");
268 if (keyexch_x25519(1) == 0)
269 return 1;
270
271 /* Test X25519 key exchange with random keys. */
272 printf("Key exchange using random keys:\n");
273 if (keyexch_x25519(0) == 0)
274 return 1;
275
276 return 0;
277 }
0 # Quick instruction:
1 # To build against an OpenSSL built in the source tree, do this:
2 #
3 # make OPENSSL_INCS_LOCATION=-I../../include OPENSSL_LIBS_LOCATION=-L../..
4 #
5 # To run the demos when linked with a shared library (default):
6 #
7 # LD_LIBRARY_PATH=../.. ./gmac
8 # LD_LIBRARY_PATH=../.. ./poly1305
9
10 CFLAGS = $(OPENSSL_INCS_LOCATION) -Wall
11 LDFLAGS = $(OPENSSL_LIBS_LOCATION) -lssl -lcrypto
12
13 all: gmac poly1305
14
15 gmac: gmac.o
16 poly1305: poly1305.o
17
18 gmac poly1305:
19 $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
20
21 clean:
22 $(RM) gmac poly1305 *.o
0 /*
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <openssl/core_names.h>
13 #include <openssl/evp.h>
14 #include <openssl/params.h>
15 #include <openssl/err.h>
16
17 /*
18 * This is a demonstration of how to compute Poly1305-AES using the OpenSSL
19 * Poly1305 and AES providers and the EVP API.
20 *
21 * Please note that:
22 *
23 * - Poly1305 must never be used alone and must be used in conjunction with
24 * another primitive which processes the input nonce to be secure;
25 *
26 * - you must never pass a nonce to the Poly1305 primitive directly;
27 *
28 * - Poly1305 exhibits catastrophic failure (that is, can be broken) if a
29 * nonce is ever reused for a given key.
30 *
31 * If you are looking for a general purpose MAC, you should consider using a
32 * different MAC and looking at one of the other examples, unless you have a
33 * good familiarity with the details and caveats of Poly1305.
34 *
35 * This example uses AES, as described in the original paper, "The Poly1305-AES
36 * message authentication code":
37 * https://cr.yp.to/mac/poly1305-20050329.pdf
38 *
39 * The test vectors below are from that paper.
40 */
41
42 /*
43 * Hard coding the key into an application is very bad.
44 * It is done here solely for educational purposes.
45 * These are the "r" and "k" inputs to Poly1305-AES.
46 */
47 static const unsigned char test_r[] = {
48 0x85, 0x1f, 0xc4, 0x0c, 0x34, 0x67, 0xac, 0x0b,
49 0xe0, 0x5c, 0xc2, 0x04, 0x04, 0xf3, 0xf7, 0x00
50 };
51
52 static const unsigned char test_k[] = {
53 0xec, 0x07, 0x4c, 0x83, 0x55, 0x80, 0x74, 0x17,
54 0x01, 0x42, 0x5b, 0x62, 0x32, 0x35, 0xad, 0xd6
55 };
56
57 /*
58 * Hard coding a nonce must not be done under any circumstances and is done here
59 * purely for demonstration purposes. Please note that Poly1305 exhibits
60 * catastrophic failure (that is, can be broken) if a nonce is ever reused for a
61 * given key.
62 */
63 static const unsigned char test_n[] = {
64 0xfb, 0x44, 0x73, 0x50, 0xc4, 0xe8, 0x68, 0xc5,
65 0x2a, 0xc3, 0x27, 0x5c, 0xf9, 0xd4, 0x32, 0x7e
66 };
67
68 /* Input message. */
69 static const unsigned char test_m[] = {
70 0xf3, 0xf6
71 };
72
73 static const unsigned char expected_output[] = {
74 0xf4, 0xc6, 0x33, 0xc3, 0x04, 0x4f, 0xc1, 0x45,
75 0xf8, 0x4f, 0x33, 0x5c, 0xb8, 0x19, 0x53, 0xde
76 };
77
78 /*
79 * A property query used for selecting the POLY1305 implementation.
80 */
81 static char *propq = NULL;
82
83 int main(int argc, char **argv)
84 {
85 int rv = EXIT_FAILURE;
86 EVP_CIPHER *aes = NULL;
87 EVP_CIPHER_CTX *aesctx = NULL;
88 EVP_MAC *mac = NULL;
89 EVP_MAC_CTX *mctx = NULL;
90 unsigned char composite_key[32];
91 unsigned char out[16];
92 OSSL_LIB_CTX *library_context = NULL;
93 size_t out_len = 0;
94 int aes_len = 0;
95
96 library_context = OSSL_LIB_CTX_new();
97 if (library_context == NULL) {
98 fprintf(stderr, "OSSL_LIB_CTX_new() returned NULL\n");
99 goto end;
100 }
101
102 /* Fetch the Poly1305 implementation */
103 mac = EVP_MAC_fetch(library_context, "POLY1305", propq);
104 if (mac == NULL) {
105 fprintf(stderr, "EVP_MAC_fetch() returned NULL\n");
106 goto end;
107 }
108
109 /* Create a context for the Poly1305 operation */
110 mctx = EVP_MAC_CTX_new(mac);
111 if (mctx == NULL) {
112 fprintf(stderr, "EVP_MAC_CTX_new() returned NULL\n");
113 goto end;
114 }
115
116 /* Fetch the AES implementation */
117 aes = EVP_CIPHER_fetch(library_context, "AES-128-ECB", propq);
118 if (aes == NULL) {
119 fprintf(stderr, "EVP_CIPHER_fetch() returned NULL\n");
120 goto end;
121 }
122
123 /* Create a context for AES */
124 aesctx = EVP_CIPHER_CTX_new();
125 if (aesctx == NULL) {
126 fprintf(stderr, "EVP_CIPHER_CTX_new() returned NULL\n");
127 goto end;
128 }
129
130 /* Initialize the AES cipher with the 128-bit key k */
131 if (!EVP_EncryptInit_ex(aesctx, aes, NULL, test_k, NULL)) {
132 fprintf(stderr, "EVP_EncryptInit_ex() failed\n");
133 goto end;
134 }
135
136 /*
137 * Disable padding for the AES cipher. We do not strictly need to do this as
138 * we are encrypting a single block and thus there are no alignment or
139 * padding concerns, but this ensures that the operation below fails if
140 * padding would be required for some reason, which in this circumstance
141 * would indicate an implementation bug.
142 */
143 if (!EVP_CIPHER_CTX_set_padding(aesctx, 0)) {
144 fprintf(stderr, "EVP_CIPHER_CTX_set_padding() failed\n");
145 goto end;
146 }
147
148 /*
149 * Computes the value AES_k(n) which we need for our Poly1305-AES
150 * computation below.
151 */
152 if (!EVP_EncryptUpdate(aesctx, composite_key + 16, &aes_len,
153 test_n, sizeof(test_n))) {
154 fprintf(stderr, "EVP_EncryptUpdate() failed\n");
155 goto end;
156 }
157
158 /*
159 * The Poly1305 provider expects the key r to be passed as the first 16
160 * bytes of the "key" and the processed nonce (that is, AES_k(n)) to be
161 * passed as the second 16 bytes of the "key". We already put the processed
162 * nonce in the correct place above, so copy r into place.
163 */
164 memcpy(composite_key, test_r, 16);
165
166 /* Initialise the Poly1305 operation */
167 if (!EVP_MAC_init(mctx, composite_key, sizeof(composite_key), NULL)) {
168 fprintf(stderr, "EVP_MAC_init() failed\n");
169 goto end;
170 }
171
172 /* Make one or more calls to process the data to be authenticated */
173 if (!EVP_MAC_update(mctx, test_m, sizeof(test_m))) {
174 fprintf(stderr, "EVP_MAC_update() failed\n");
175 goto end;
176 }
177
178 /* Make one call to the final to get the MAC */
179 if (!EVP_MAC_final(mctx, out, &out_len, sizeof(out))) {
180 fprintf(stderr, "EVP_MAC_final() failed\n");
181 goto end;
182 }
183
184 printf("Generated MAC:\n");
185 BIO_dump_indent_fp(stdout, out, out_len, 2);
186 putchar('\n');
187
188 if (out_len != sizeof(expected_output)) {
189 fprintf(stderr, "Generated MAC has an unexpected length\n");
190 goto end;
191 }
192
193 if (CRYPTO_memcmp(expected_output, out, sizeof(expected_output)) != 0) {
194 fprintf(stderr, "Generated MAC does not match expected value\n");
195 goto end;
196 }
197
198 rv = EXIT_SUCCESS;
199 end:
200 EVP_CIPHER_CTX_free(aesctx);
201 EVP_CIPHER_free(aes);
202 EVP_MAC_CTX_free(mctx);
203 EVP_MAC_free(mac);
204 OSSL_LIB_CTX_free(library_context);
205 if (rv != EXIT_SUCCESS)
206 ERR_print_errors_fp(stderr);
207 return rv;
208 }
0 /*
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <openssl/core_names.h>
12 #include <openssl/evp.h>
13 #include <openssl/params.h>
14 #include <openssl/err.h>
15
16 /*
17 * Taken from the test vector from the paper "SipHash: a fast short-input PRF".
18 * https://www.aumasson.jp/siphash/siphash.pdf
19 */
20
21 /*
22 * Hard coding the key into an application is very bad.
23 * It is done here solely for educational purposes.
24 */
25 static unsigned char key[] = {
26 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
27 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
28 };
29
30 static unsigned char data[] = {
31 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
32 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e
33 };
34
35 static const unsigned char expected_output[] = {
36 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1
37 };
38
39 /*
40 * A property query used for selecting the SIPHASH implementation.
41 */
42 static char *propq = NULL;
43
44 int main(int argc, char **argv)
45 {
46 int rv = EXIT_FAILURE;
47 EVP_MAC *mac = NULL;
48 EVP_MAC_CTX *mctx = NULL;
49 unsigned char out[8];
50 OSSL_PARAM params[4], *p = params;
51 OSSL_LIB_CTX *library_context = NULL;
52 unsigned int digest_len = 8, c_rounds = 2, d_rounds = 4;
53 size_t out_len = 0;
54
55 library_context = OSSL_LIB_CTX_new();
56 if (library_context == NULL) {
57 fprintf(stderr, "OSSL_LIB_CTX_new() returned NULL\n");
58 goto end;
59 }
60
61 /* Fetch the SipHash implementation */
62 mac = EVP_MAC_fetch(library_context, "SIPHASH", propq);
63 if (mac == NULL) {
64 fprintf(stderr, "EVP_MAC_fetch() returned NULL\n");
65 goto end;
66 }
67
68 /* Create a context for the SipHash operation */
69 mctx = EVP_MAC_CTX_new(mac);
70 if (mctx == NULL) {
71 fprintf(stderr, "EVP_MAC_CTX_new() returned NULL\n");
72 goto end;
73 }
74
75 /* SipHash can support either 8 or 16-byte digests. */
76 *p++ = OSSL_PARAM_construct_uint(OSSL_MAC_PARAM_SIZE, &digest_len);
77
78 /*
79 * The number of C-rounds and D-rounds is configurable. Standard SipHash
80 * uses values of 2 and 4 respectively. The following lines are unnecessary
81 * as they set the default, but demonstrate how to change these values.
82 */
83 *p++ = OSSL_PARAM_construct_uint(OSSL_MAC_PARAM_C_ROUNDS, &c_rounds);
84 *p++ = OSSL_PARAM_construct_uint(OSSL_MAC_PARAM_D_ROUNDS, &d_rounds);
85
86 *p = OSSL_PARAM_construct_end();
87
88 /* Initialise the SIPHASH operation */
89 if (!EVP_MAC_init(mctx, key, sizeof(key), params)) {
90 fprintf(stderr, "EVP_MAC_init() failed\n");
91 goto end;
92 }
93
94 /* Make one or more calls to process the data to be authenticated */
95 if (!EVP_MAC_update(mctx, data, sizeof(data))) {
96 fprintf(stderr, "EVP_MAC_update() failed\n");
97 goto end;
98 }
99
100 /* Make one call to the final to get the MAC */
101 if (!EVP_MAC_final(mctx, out, &out_len, sizeof(out))) {
102 fprintf(stderr, "EVP_MAC_final() failed\n");
103 goto end;
104 }
105
106 printf("Generated MAC:\n");
107 BIO_dump_indent_fp(stdout, out, out_len, 2);
108 putchar('\n');
109
110 if (out_len != sizeof(expected_output)) {
111 fprintf(stderr, "Generated MAC has an unexpected length\n");
112 goto end;
113 }
114
115 if (CRYPTO_memcmp(expected_output, out, sizeof(expected_output)) != 0) {
116 fprintf(stderr, "Generated MAC does not match expected value\n");
117 goto end;
118 }
119
120 rv = EXIT_SUCCESS;
121 end:
122 EVP_MAC_CTX_free(mctx);
123 EVP_MAC_free(mac);
124 OSSL_LIB_CTX_free(library_context);
125 if (rv != EXIT_SUCCESS)
126 ERR_print_errors_fp(stderr);
127 return rv;
128 }
00 /*-
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
8888 unsigned char out_pubkey[80];
8989 unsigned char out_privkey[80];
9090 BIGNUM *out_priv = NULL;
91 size_t i, out_pubkey_len, out_privkey_len = 0;
91 size_t out_pubkey_len, out_privkey_len = 0;
9292
9393 if (!EVP_PKEY_get_utf8_string_param(pkey, OSSL_PKEY_PARAM_GROUP_NAME,
9494 out_curvename, sizeof(out_curvename),
0 /*-
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 /*
10 * Example showing how to generate an RSA key pair.
11 *
12 * When generating an RSA key, you must specify the number of bits in the key. A
13 * reasonable value would be 4096. Avoid using values below 2048. These values
14 * are reasonable as of 2022.
15 */
16
17 #include <string.h>
18 #include <stdio.h>
19 #include <openssl/err.h>
20 #include <openssl/evp.h>
21 #include <openssl/rsa.h>
22 #include <openssl/core_names.h>
23 #include <openssl/pem.h>
24
25 /* A property query used for selecting algorithm implementations. */
26 static const char *propq = NULL;
27
28 /*
29 * Generates an RSA public-private key pair and returns it.
30 * The number of bits is specified by the bits argument.
31 *
32 * This uses the long way of generating an RSA key.
33 */
34 static EVP_PKEY *generate_rsa_key_long(OSSL_LIB_CTX *libctx, unsigned int bits)
35 {
36 EVP_PKEY_CTX *genctx = NULL;
37 EVP_PKEY *pkey = NULL;
38 unsigned int primes = 2;
39
40 /* Create context using RSA algorithm. "RSA-PSS" could also be used here. */
41 genctx = EVP_PKEY_CTX_new_from_name(libctx, "RSA", propq);
42 if (genctx == NULL) {
43 fprintf(stderr, "EVP_PKEY_CTX_new_from_name() failed\n");
44 goto cleanup;
45 }
46
47 /* Initialize context for key generation purposes. */
48 if (EVP_PKEY_keygen_init(genctx) <= 0) {
49 fprintf(stderr, "EVP_PKEY_keygen_init() failed\n");
50 goto cleanup;
51 }
52
53 /*
54 * Here we set the number of bits to use in the RSA key.
55 * See comment at top of file for information on appropriate values.
56 */
57 if (EVP_PKEY_CTX_set_rsa_keygen_bits(genctx, bits) <= 0) {
58 fprintf(stderr, "EVP_PKEY_CTX_set_rsa_keygen_bits() failed\n");
59 goto cleanup;
60 }
61
62 /*
63 * It is possible to create an RSA key using more than two primes.
64 * Do not do this unless you know why you need this.
65 * You ordinarily do not need to specify this, as the default is two.
66 *
67 * Both of these parameters can also be set via EVP_PKEY_CTX_set_params, but
68 * these functions provide a more concise way to do so.
69 */
70 if (EVP_PKEY_CTX_set_rsa_keygen_primes(genctx, primes) <= 0) {
71 fprintf(stderr, "EVP_PKEY_CTX_set_rsa_keygen_primes() failed\n");
72 goto cleanup;
73 }
74
75 /*
76 * Generating an RSA key with a number of bits large enough to be secure for
77 * modern applications can take a fairly substantial amount of time (e.g.
78 * one second). If you require fast key generation, consider using an EC key
79 * instead.
80 *
81 * If you require progress information during the key generation process,
82 * you can set a progress callback using EVP_PKEY_set_cb; see the example in
83 * EVP_PKEY_generate(3).
84 */
85 fprintf(stderr, "Generating RSA key, this may take some time...\n");
86 if (EVP_PKEY_generate(genctx, &pkey) <= 0) {
87 fprintf(stderr, "EVP_PKEY_generate() failed\n");
88 goto cleanup;
89 }
90
91 /* pkey is now set to an object representing the generated key pair. */
92
93 cleanup:
94 EVP_PKEY_CTX_free(genctx);
95 return pkey;
96 }
97
98 /*
99 * Generates an RSA public-private key pair and returns it.
100 * The number of bits is specified by the bits argument.
101 *
102 * This uses a more concise way of generating an RSA key, which is suitable for
103 * simple cases. It is used if -s is passed on the command line, otherwise the
104 * long method above is used. The ability to choose between these two methods is
105 * shown here only for demonstration; the results are equivalent.
106 */
107 static EVP_PKEY *generate_rsa_key_short(OSSL_LIB_CTX *libctx, unsigned int bits)
108 {
109 EVP_PKEY *pkey = NULL;
110
111 fprintf(stderr, "Generating RSA key, this may take some time...\n");
112 pkey = EVP_PKEY_Q_keygen(libctx, propq, "RSA", (size_t)bits);
113
114 if (pkey == NULL)
115 fprintf(stderr, "EVP_PKEY_Q_keygen() failed\n");
116
117 return pkey;
118 }
119
120 /*
121 * Prints information on an EVP_PKEY object representing an RSA key pair.
122 */
123 static int dump_key(const EVP_PKEY *pkey)
124 {
125 int rv = 0;
126 int bits = 0;
127 BIGNUM *n = NULL, *e = NULL, *d = NULL, *p = NULL, *q = NULL;
128
129 /*
130 * Retrieve value of n. This value is not secret and forms part of the
131 * public key.
132 *
133 * Calling EVP_PKEY_get_bn_param with a NULL BIGNUM pointer causes
134 * a new BIGNUM to be allocated, so these must be freed subsequently.
135 */
136 if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_N, &n) == 0) {
137 fprintf(stderr, "Failed to retrieve n\n");
138 goto cleanup;
139 }
140
141 /*
142 * Retrieve value of e. This value is not secret and forms part of the
143 * public key. It is typically 65537 and need not be changed.
144 */
145 if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_E, &e) == 0) {
146 fprintf(stderr, "Failed to retrieve e\n");
147 goto cleanup;
148 }
149
150 /*
151 * Retrieve value of d. This value is secret and forms part of the private
152 * key. It must not be published.
153 */
154 if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_D, &d) == 0) {
155 fprintf(stderr, "Failed to retrieve d\n");
156 goto cleanup;
157 }
158
159 /*
160 * Retrieve value of the first prime factor, commonly known as p. This value
161 * is secret and forms part of the private key. It must not be published.
162 */
163 if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1, &p) == 0) {
164 fprintf(stderr, "Failed to retrieve p\n");
165 goto cleanup;
166 }
167
168 /*
169 * Retrieve value of the second prime factor, commonly known as q. This value
170 * is secret and forms part of the private key. It must not be published.
171 *
172 * If you are creating an RSA key with more than two primes for special
173 * applications, you can retrieve these primes with
174 * OSSL_PKEY_PARAM_RSA_FACTOR3, etc.
175 */
176 if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &q) == 0) {
177 fprintf(stderr, "Failed to retrieve q\n");
178 goto cleanup;
179 }
180
181 /*
182 * We can also retrieve the key size in bits for informational purposes.
183 */
184 if (EVP_PKEY_get_int_param(pkey, OSSL_PKEY_PARAM_BITS, &bits) == 0) {
185 fprintf(stderr, "Failed to retrieve bits\n");
186 goto cleanup;
187 }
188
189 /* Output hexadecimal representations of the BIGNUM objects. */
190 fprintf(stdout, "\nNumber of bits: %d\n\n", bits);
191 fprintf(stderr, "Public values:\n");
192 fprintf(stdout, " n = 0x");
193 BN_print_fp(stdout, n);
194 fprintf(stdout, "\n");
195
196 fprintf(stdout, " e = 0x");
197 BN_print_fp(stdout, e);
198 fprintf(stdout, "\n\n");
199
200 fprintf(stdout, "Private values:\n");
201 fprintf(stdout, " d = 0x");
202 BN_print_fp(stdout, d);
203 fprintf(stdout, "\n");
204
205 fprintf(stdout, " p = 0x");
206 BN_print_fp(stdout, p);
207 fprintf(stdout, "\n");
208
209 fprintf(stdout, " q = 0x");
210 BN_print_fp(stdout, q);
211 fprintf(stdout, "\n\n");
212
213 /* Output a PEM encoding of the public key. */
214 if (PEM_write_PUBKEY(stdout, pkey) == 0) {
215 fprintf(stderr, "Failed to output PEM-encoded public key\n");
216 goto cleanup;
217 }
218
219 /*
220 * Output a PEM encoding of the private key. Please note that this output is
221 * not encrypted. You may wish to use the arguments to specify encryption of
222 * the key if you are storing it on disk. See PEM_write_PrivateKey(3).
223 */
224 if (PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL) == 0) {
225 fprintf(stderr, "Failed to output PEM-encoded private key\n");
226 goto cleanup;
227 }
228
229 rv = 1;
230 cleanup:
231 BN_free(n); /* not secret */
232 BN_free(e); /* not secret */
233 BN_clear_free(d); /* secret - scrub before freeing */
234 BN_clear_free(p); /* secret - scrub before freeing */
235 BN_clear_free(q); /* secret - scrub before freeing */
236 return rv;
237 }
238
239 int main(int argc, char **argv)
240 {
241 int rv = 1;
242 OSSL_LIB_CTX *libctx = NULL;
243 EVP_PKEY *pkey = NULL;
244 unsigned int bits = 4096;
245 int bits_i, use_short = 0;
246
247 /* usage: [-s] [<bits>] */
248 if (argc > 1 && strcmp(argv[1], "-s") == 0) {
249 --argc;
250 ++argv;
251 use_short = 1;
252 }
253
254 if (argc > 1) {
255 bits_i = atoi(argv[1]);
256 if (bits < 512) {
257 fprintf(stderr, "Invalid RSA key size\n");
258 return 1;
259 }
260
261 bits = (unsigned int)bits_i;
262 }
263
264 /* Avoid using key sizes less than 2048 bits; see comment at top of file. */
265 if (bits < 2048)
266 fprintf(stderr, "Warning: very weak key size\n\n");
267
268 /* Generate RSA key. */
269 if (use_short)
270 pkey = generate_rsa_key_short(libctx, bits);
271 else
272 pkey = generate_rsa_key_long(libctx, bits);
273
274 if (pkey == NULL)
275 goto cleanup;
276
277 /* Dump the integers comprising the key. */
278 if (dump_key(pkey) == 0) {
279 fprintf(stderr, "Failed to dump key\n");
280 goto cleanup;
281 }
282
283 rv = 0;
284 cleanup:
285 EVP_PKEY_free(pkey);
286 OSSL_LIB_CTX_free(libctx);
287 return rv;
288 }
11 # To run the demos when linked with a shared library (default):
22 #
33 # LD_LIBRARY_PATH=../.. ./EVP_PKEY_EC_keygen
4 # LD_LIBRARY_PATH=../.. ./EVP_PKEY_RSA_keygen
45
5 CFLAGS = -I../../include -g
6 CFLAGS = -I../../include -g -Wall
67 LDFLAGS = -L../..
78 LDLIBS = -lcrypto
89
9 all: EVP_PKEY_EC_keygen
10 all: EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen
1011
1112 %.o: %.c
1213 $(CC) $(CFLAGS) -c $<
1314
1415 EVP_PKEY_EC_keygen: EVP_PKEY_EC_keygen.o
1516
17 EVP_PKEY_RSA_keygen: EVP_PKEY_RSA_keygen.o
18
1619 test: ;
1720
1821 clean:
19 $(RM) *.o EVP_PKEY_EC_keygen
22 $(RM) *.o EVP_PKEY_EC_keygen EVP_PKEY_RSA_keygen
22 #
33 # LD_LIBRARY_PATH=../.. ./EVP_Signature_demo
44
5 CFLAGS = -I../../include -g
5 CFLAGS = -I../../include -g -Wall
66 LDFLAGS = -L../..
77 LDLIBS = -lcrypto
88
9 all: EVP_Signature_demo
9 all: EVP_Signature_demo rsa_pss_direct rsa_pss_hash
1010
1111 %.o: %.c
1212 $(CC) $(CFLAGS) -c $<
1313
1414 EVP_Signature_demo: EVP_Signature_demo.o
15 rsa_pss_direct: rsa_pss_direct.o
16 rsa_pss_hash: rsa_pss_hash.o
1517
1618 test: ;
1719
1820 clean:
19 $(RM) *.o EVP_Signature_demo
21 $(RM) *.o EVP_Signature_demo rsa_pss_direct rsa_pss_hash
0 /*-
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 /* 4096-bit RSA private key, DER. */
10 static const unsigned char rsa_priv_key[] = {
11 0x30, 0x82, 0x09, 0x28, 0x02, 0x01, 0x00, 0x02, 0x82, 0x02, 0x01, 0x00,
12 0xa3, 0x14, 0xe4, 0xb8, 0xd8, 0x58, 0x0d, 0xab, 0xd7, 0x87, 0xa4, 0xf6,
13 0x84, 0x51, 0x74, 0x60, 0x4c, 0xe3, 0x60, 0x28, 0x89, 0x49, 0x65, 0x18,
14 0x5c, 0x8f, 0x1a, 0x1b, 0xe9, 0xdb, 0xc1, 0xc1, 0xf7, 0x08, 0x27, 0x44,
15 0xe5, 0x9d, 0x9a, 0x33, 0xc3, 0xac, 0x5a, 0xca, 0xba, 0x20, 0x5a, 0x9e,
16 0x3a, 0x18, 0xb5, 0x3d, 0xe3, 0x9d, 0x94, 0x58, 0xa7, 0xa9, 0x5a, 0x0b,
17 0x4f, 0xb8, 0xe5, 0xa3, 0x7b, 0x01, 0x11, 0x0f, 0x16, 0x11, 0xb8, 0x65,
18 0x2f, 0xa8, 0x95, 0xf7, 0x58, 0x2c, 0xec, 0x1d, 0x41, 0xad, 0xd1, 0x12,
19 0xca, 0x4a, 0x80, 0x35, 0x35, 0x43, 0x7e, 0xe0, 0x97, 0xfc, 0x86, 0x8f,
20 0xcf, 0x4b, 0xdc, 0xbc, 0x15, 0x2c, 0x8e, 0x90, 0x84, 0x26, 0x83, 0xc1,
21 0x96, 0x97, 0xf4, 0xd7, 0x90, 0xce, 0xfe, 0xd4, 0xf3, 0x70, 0x22, 0xa8,
22 0xb0, 0x1f, 0xed, 0x08, 0xd7, 0xc5, 0xc0, 0xd6, 0x41, 0x6b, 0x24, 0x68,
23 0x5c, 0x07, 0x1f, 0x44, 0x97, 0xd8, 0x6e, 0x18, 0x93, 0x67, 0xc3, 0xba,
24 0x3a, 0xaf, 0xfd, 0xc2, 0x65, 0x00, 0x21, 0x63, 0xdf, 0xb7, 0x28, 0x68,
25 0xd6, 0xc0, 0x20, 0x86, 0x92, 0xed, 0x68, 0x6a, 0x27, 0x3a, 0x07, 0xec,
26 0x66, 0x00, 0xfe, 0x51, 0x51, 0x86, 0x41, 0x6f, 0x83, 0x69, 0xd2, 0xf0,
27 0xe6, 0xf7, 0x61, 0xda, 0x12, 0x45, 0x53, 0x09, 0xdf, 0xf8, 0x42, 0xc7,
28 0x30, 0x6a, 0xe5, 0xd8, 0x2b, 0xa2, 0x49, 0x7a, 0x05, 0x10, 0xee, 0xb2,
29 0x59, 0x0a, 0xe5, 0xbe, 0xf8, 0x4d, 0x0f, 0xa8, 0x9e, 0x63, 0x81, 0x39,
30 0x32, 0xaa, 0xfd, 0xa8, 0x03, 0xf6, 0xd8, 0xc6, 0xaa, 0x02, 0x93, 0x03,
31 0xeb, 0x15, 0xd3, 0x38, 0xc8, 0x1a, 0x78, 0xcf, 0xf3, 0xa7, 0x9f, 0x98,
32 0x4b, 0x91, 0x5b, 0x79, 0xf8, 0x4e, 0x53, 0xaf, 0x0c, 0x65, 0xe9, 0xb0,
33 0x93, 0xc2, 0xcb, 0x5d, 0x3c, 0x5f, 0x6e, 0x39, 0xd2, 0x58, 0x23, 0x50,
34 0xe5, 0x2e, 0xef, 0x12, 0x00, 0xa4, 0x59, 0x13, 0x2b, 0x2f, 0x2c, 0x0a,
35 0x7b, 0x36, 0x89, 0xc5, 0xe5, 0x8f, 0x95, 0x5e, 0x14, 0x0f, 0x0f, 0x94,
36 0x5a, 0xe9, 0xdc, 0x0b, 0x49, 0x14, 0xbe, 0x0a, 0x70, 0x45, 0xc1, 0x7c,
37 0xbf, 0x83, 0x70, 0xfd, 0x3d, 0x99, 0xe6, 0x8a, 0xf5, 0x9c, 0x09, 0x71,
38 0x84, 0x9a, 0x18, 0xa0, 0xe0, 0x6c, 0x43, 0x5c, 0x7e, 0x48, 0x33, 0xc8,
39 0xbe, 0x5d, 0xdd, 0xd8, 0x77, 0xe3, 0xe7, 0x6b, 0x34, 0x4b, 0xa2, 0xb7,
40 0x54, 0x07, 0x72, 0x2e, 0xab, 0xa9, 0x91, 0x1e, 0x4b, 0xe3, 0xb5, 0xd8,
41 0xfa, 0x35, 0x64, 0x8a, 0xe9, 0x03, 0xa1, 0xa8, 0x26, 0xbd, 0x72, 0x58,
42 0x10, 0x6a, 0xec, 0x1a, 0xf6, 0x1e, 0xb8, 0xc0, 0x46, 0x19, 0x31, 0x2c,
43 0xca, 0xf9, 0x6a, 0xd7, 0x2e, 0xd0, 0xa7, 0x2c, 0x60, 0x58, 0xc4, 0x8f,
44 0x46, 0x63, 0x61, 0x8d, 0x29, 0x6f, 0xe2, 0x5f, 0xe2, 0x43, 0x90, 0x9c,
45 0xe6, 0xfc, 0x08, 0x41, 0xc8, 0xb5, 0x23, 0x56, 0x24, 0x3e, 0x3a, 0x2c,
46 0x41, 0x22, 0x43, 0xda, 0x22, 0x15, 0x2b, 0xad, 0xd0, 0xfa, 0xc8, 0x47,
47 0x44, 0xe6, 0x2a, 0xf9, 0x38, 0x90, 0x13, 0x62, 0x22, 0xea, 0x06, 0x8c,
48 0x44, 0x9c, 0xd6, 0xca, 0x50, 0x93, 0xe9, 0xd4, 0x03, 0xd8, 0x3e, 0x71,
49 0x36, 0x4b, 0xaa, 0xab, 0xbb, 0xe2, 0x48, 0x66, 0x26, 0x53, 0xb1, 0x6d,
50 0x3b, 0x82, 0x2c, 0x8c, 0x25, 0x05, 0xf0, 0xf8, 0xcf, 0x55, 0xbf, 0x8e,
51 0x29, 0xf7, 0x54, 0x5b, 0x6f, 0x30, 0x54, 0xa6, 0xad, 0x46, 0xff, 0x22,
52 0x95, 0xb1, 0x87, 0x98, 0x00, 0x51, 0x69, 0x15, 0x07, 0xbd, 0x3d, 0x9c,
53 0x6e, 0xaa, 0xaa, 0x3b, 0x0b, 0x74, 0x65, 0x4c, 0x04, 0xe0, 0x80, 0x3e,
54 0xaf, 0x5e, 0x10, 0xd6, 0x9b, 0x28, 0x37, 0x6f, 0x02, 0x03, 0x01, 0x00,
55 0x01, 0x02, 0x82, 0x02, 0x00, 0x09, 0x6e, 0xf8, 0xf8, 0x14, 0x53, 0xab,
56 0x9e, 0xc8, 0x1d, 0xe9, 0x95, 0xf4, 0xfb, 0x7d, 0x3e, 0xe0, 0xd3, 0xba,
57 0x49, 0x3d, 0xff, 0xc7, 0xe0, 0x4b, 0xe2, 0x5f, 0x41, 0x44, 0x1a, 0xd9,
58 0x2f, 0x6e, 0x29, 0xc3, 0x93, 0xc1, 0xb0, 0x87, 0x2d, 0xfd, 0x60, 0xa7,
59 0xf3, 0xd8, 0x26, 0x6c, 0xf7, 0x80, 0x26, 0xd3, 0xbd, 0x1b, 0xc0, 0x8e,
60 0xc7, 0x3e, 0x13, 0x96, 0xc8, 0xd6, 0xb8, 0xbc, 0x57, 0xe3, 0x92, 0xa1,
61 0x38, 0xfd, 0x2e, 0xd3, 0x3a, 0xcf, 0x31, 0xf2, 0x52, 0xd7, 0x7f, 0xe9,
62 0xbc, 0x9b, 0x83, 0x01, 0x78, 0x13, 0xc9, 0x91, 0x77, 0x02, 0x78, 0xc0,
63 0x0b, 0x1f, 0xdf, 0x94, 0xad, 0x16, 0xf1, 0xad, 0x78, 0x17, 0xc5, 0x77,
64 0x0d, 0xb7, 0x07, 0x3f, 0x51, 0xe0, 0x73, 0x33, 0xcf, 0x90, 0x69, 0xd8,
65 0xe5, 0xda, 0x9b, 0x1e, 0xf6, 0x21, 0x12, 0x07, 0xb5, 0x1e, 0x3e, 0x2b,
66 0x34, 0x79, 0x9e, 0x48, 0x01, 0xdd, 0x68, 0xf0, 0x0f, 0x18, 0xb5, 0x85,
67 0x50, 0xd8, 0x9e, 0x04, 0xfd, 0x6d, 0xcd, 0xa6, 0x61, 0x2b, 0x54, 0x81,
68 0x99, 0xf4, 0x63, 0xf4, 0xeb, 0x73, 0x98, 0xb3, 0x88, 0xf5, 0x50, 0xd4,
69 0x5c, 0x67, 0x9e, 0x7c, 0xbc, 0xd8, 0xfd, 0xaf, 0xb8, 0x66, 0x7d, 0xdc,
70 0xa5, 0x25, 0xb5, 0xe6, 0x64, 0xd7, 0x07, 0x72, 0x5a, 0x99, 0xf9, 0xf6,
71 0x9e, 0xb8, 0x9c, 0xf4, 0xc7, 0xee, 0xee, 0x10, 0x13, 0x9c, 0x1a, 0x8c,
72 0x23, 0x89, 0xcd, 0x7b, 0xf1, 0x47, 0x23, 0x51, 0x3c, 0xe5, 0xc2, 0x17,
73 0x68, 0xca, 0x98, 0xb8, 0xed, 0xe5, 0x17, 0x6d, 0x0a, 0xde, 0x07, 0xd6,
74 0x6c, 0x4f, 0x83, 0x4c, 0x9b, 0xca, 0x6a, 0x7d, 0xc8, 0x68, 0x12, 0xd7,
75 0xf0, 0x37, 0x88, 0xf7, 0xbb, 0x68, 0x8b, 0xa4, 0xfd, 0xfe, 0x36, 0x11,
76 0xb3, 0x2b, 0x85, 0x6d, 0xaa, 0x30, 0x31, 0xf1, 0x6f, 0x80, 0x72, 0x42,
77 0x23, 0xfe, 0x93, 0x88, 0xcc, 0x1e, 0x4b, 0x53, 0x4f, 0x8e, 0x24, 0x67,
78 0x4a, 0x72, 0xb6, 0x3c, 0x13, 0x00, 0x11, 0x4f, 0xe1, 0x30, 0xd6, 0xe7,
79 0x45, 0x8f, 0xaf, 0xdd, 0xe5, 0xaa, 0xb7, 0x02, 0x17, 0x04, 0xf8, 0xd2,
80 0xc1, 0x7b, 0x6c, 0x92, 0xec, 0x76, 0x94, 0x1b, 0xb0, 0xe4, 0xc3, 0x0c,
81 0x9e, 0xee, 0xb5, 0xdc, 0x97, 0xca, 0x10, 0x1d, 0x17, 0x96, 0x45, 0xd4,
82 0x04, 0x0c, 0xea, 0xca, 0x45, 0xfc, 0x52, 0x54, 0x82, 0x9b, 0xdf, 0x64,
83 0xd6, 0x59, 0x6c, 0x12, 0x70, 0xf0, 0x19, 0xd8, 0x46, 0xbb, 0x08, 0x43,
84 0x81, 0xa1, 0x73, 0xa8, 0x00, 0xc9, 0x4e, 0xb9, 0xd5, 0xfd, 0x42, 0x5f,
85 0xcf, 0x94, 0x14, 0x18, 0xab, 0x9d, 0x11, 0xd0, 0xbd, 0x44, 0x88, 0x2c,
86 0xd8, 0x29, 0xec, 0x94, 0x70, 0xf9, 0x42, 0x14, 0xf4, 0xb0, 0x3f, 0xfe,
87 0x27, 0x16, 0x43, 0x59, 0x90, 0x14, 0x48, 0x61, 0x8c, 0x91, 0xd9, 0x37,
88 0x41, 0xef, 0xf1, 0xe9, 0x15, 0x4a, 0x4f, 0x5e, 0x1f, 0x50, 0x25, 0x20,
89 0x2d, 0xa6, 0xf8, 0x79, 0x0d, 0x92, 0xb0, 0x00, 0x0b, 0xa2, 0xfb, 0xc3,
90 0x7b, 0x0f, 0xa6, 0xff, 0x75, 0x5d, 0x70, 0xaa, 0xcf, 0x0a, 0xdf, 0xe1,
91 0xfc, 0x32, 0x53, 0x1e, 0xf6, 0xe6, 0x69, 0x9f, 0x09, 0xd0, 0xc8, 0xab,
92 0xaf, 0xec, 0xb0, 0x04, 0xfa, 0x83, 0xe2, 0x29, 0x23, 0x54, 0x37, 0x87,
93 0x63, 0x47, 0x75, 0x9b, 0xdb, 0x1f, 0x4f, 0x1b, 0x6b, 0xa6, 0xe2, 0x67,
94 0x1c, 0xb4, 0x74, 0x9e, 0x48, 0x77, 0x61, 0xc2, 0x9a, 0x3e, 0x6b, 0x89,
95 0xa9, 0x68, 0x74, 0x27, 0x01, 0x29, 0xd6, 0x46, 0xe8, 0x0f, 0xd0, 0x33,
96 0x22, 0x00, 0x45, 0x6c, 0xde, 0x32, 0x28, 0x42, 0x57, 0xaf, 0x70, 0x28,
97 0xa0, 0xd5, 0x99, 0xbb, 0x1f, 0xd7, 0x3c, 0x84, 0x20, 0x70, 0x1f, 0xe3,
98 0xa9, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe6, 0x68, 0xfe, 0x5f, 0x75, 0x71,
99 0x2a, 0xd8, 0xcf, 0x0d, 0x1d, 0xf4, 0xa1, 0x06, 0x8b, 0xa5, 0x70, 0x6f,
100 0x29, 0x03, 0xf3, 0x50, 0xd3, 0x83, 0x39, 0xf9, 0xf6, 0xe5, 0x79, 0x7a,
101 0x29, 0x75, 0xde, 0xda, 0x6a, 0x98, 0x7c, 0x33, 0xf8, 0x64, 0xca, 0x86,
102 0x5a, 0xda, 0x55, 0x5b, 0x4d, 0x7b, 0x1a, 0xe5, 0x5d, 0x19, 0x7d, 0xf3,
103 0x57, 0x49, 0x3d, 0x7a, 0xe8, 0x3f, 0x5a, 0x40, 0x8c, 0x15, 0xc7, 0xb0,
104 0x53, 0xf8, 0x63, 0x42, 0x17, 0x7c, 0x20, 0xb9, 0xfc, 0xff, 0x27, 0xd0,
105 0xc2, 0x0c, 0x45, 0x52, 0x1b, 0x75, 0x1f, 0x89, 0x87, 0xc4, 0xa8, 0x07,
106 0x3b, 0x73, 0x16, 0xc7, 0xd7, 0x77, 0x2e, 0x47, 0xa2, 0x7d, 0x12, 0xb4,
107 0x25, 0x24, 0x5e, 0xa5, 0xb2, 0x12, 0x76, 0x65, 0xd1, 0xcd, 0xa4, 0x66,
108 0x33, 0x2d, 0xed, 0xb2, 0x85, 0xb0, 0xb3, 0x33, 0x56, 0x18, 0x5a, 0xb3,
109 0x75, 0x43, 0x4d, 0x40, 0x14, 0x22, 0x55, 0xf6, 0x5a, 0x0c, 0x6a, 0xb3,
110 0xc3, 0x8a, 0x9b, 0x76, 0x1e, 0x23, 0x8d, 0x4a, 0x8f, 0x38, 0x21, 0x25,
111 0x43, 0x45, 0xf6, 0x25, 0x46, 0xdb, 0xae, 0x42, 0x43, 0x74, 0x69, 0x15,
112 0x46, 0xf0, 0x3a, 0x41, 0x4f, 0x9f, 0xfe, 0xda, 0x07, 0x0b, 0x38, 0xbe,
113 0x6b, 0xad, 0xc2, 0xef, 0x5b, 0x97, 0x18, 0x42, 0x13, 0xac, 0x13, 0x15,
114 0x70, 0x7b, 0xe2, 0x00, 0xbb, 0x41, 0x22, 0x99, 0xe5, 0xd3, 0x67, 0xfe,
115 0xfd, 0xbd, 0x8e, 0xc3, 0xca, 0x60, 0x59, 0x3d, 0x8f, 0x85, 0x76, 0x41,
116 0xf0, 0xb8, 0x09, 0x1a, 0x48, 0x50, 0xe4, 0x9c, 0x4a, 0x56, 0x02, 0x60,
117 0x76, 0xff, 0xde, 0xd4, 0x8e, 0x76, 0xa3, 0x9c, 0x30, 0xb4, 0xa4, 0x73,
118 0xe6, 0xb0, 0x70, 0xac, 0x67, 0x5f, 0x25, 0xd2, 0x94, 0xc5, 0x25, 0xb6,
119 0xbf, 0xf6, 0x0b, 0xd8, 0x9f, 0x35, 0x8c, 0x20, 0xb6, 0xdd, 0x02, 0x82,
120 0x01, 0x01, 0x00, 0xb5, 0x31, 0x9e, 0xa2, 0x10, 0x38, 0xca, 0x2b, 0x07,
121 0xc9, 0x3f, 0x0f, 0x18, 0x2c, 0x98, 0x7f, 0x15, 0x87, 0x92, 0x93, 0x2e,
122 0xce, 0x6b, 0x11, 0x42, 0x2a, 0x94, 0x3e, 0x31, 0xd0, 0xf5, 0xae, 0x9d,
123 0xc7, 0x67, 0x51, 0x3c, 0x0a, 0x52, 0x04, 0x94, 0x86, 0x2e, 0x50, 0x32,
124 0xe1, 0x48, 0x83, 0x85, 0xe8, 0x82, 0x04, 0x2f, 0x25, 0xbc, 0xea, 0xfc,
125 0x3d, 0x4b, 0xd1, 0x53, 0x90, 0x61, 0x97, 0x47, 0x73, 0xcd, 0x1f, 0xa9,
126 0x5a, 0x3f, 0xfb, 0xbf, 0xc3, 0xd5, 0x19, 0xb6, 0xd3, 0x59, 0x57, 0x37,
127 0xd9, 0x09, 0x29, 0xd3, 0x80, 0xc4, 0xae, 0x52, 0xce, 0xce, 0x82, 0x29,
128 0x6b, 0x95, 0x44, 0x69, 0x33, 0xfd, 0x6a, 0x6d, 0x65, 0xf7, 0xa9, 0xc0,
129 0x65, 0x25, 0x91, 0x05, 0xdf, 0x07, 0xbe, 0x61, 0x5c, 0xaa, 0x8f, 0x87,
130 0xc8, 0x43, 0xd7, 0x30, 0xd0, 0x8b, 0x25, 0xaf, 0xb8, 0x5d, 0x50, 0x4e,
131 0x31, 0x4a, 0xc9, 0x79, 0x56, 0xbf, 0x8d, 0xcc, 0x40, 0xa7, 0xea, 0xd4,
132 0xf7, 0x66, 0x86, 0xe2, 0x0b, 0xf3, 0x13, 0xbc, 0xdc, 0x0d, 0x62, 0x28,
133 0x4e, 0xb7, 0x31, 0xb4, 0x5a, 0x9b, 0x97, 0x65, 0x76, 0x24, 0xbb, 0xef,
134 0x90, 0x1b, 0xdb, 0x93, 0x98, 0xae, 0xce, 0xb0, 0x69, 0x82, 0x49, 0x94,
135 0xc0, 0xc3, 0x8f, 0x9c, 0x5d, 0x26, 0x45, 0xa0, 0xad, 0x15, 0x3b, 0x6e,
136 0xda, 0x6e, 0x78, 0xc1, 0x78, 0xc3, 0x15, 0x8e, 0x64, 0xaf, 0x50, 0xa6,
137 0xb7, 0xd9, 0xfb, 0x8f, 0x68, 0xa0, 0x2d, 0x59, 0xa9, 0xce, 0x5b, 0xa7,
138 0x91, 0x36, 0xb8, 0x05, 0x28, 0x31, 0x25, 0xc7, 0x7e, 0xa4, 0x68, 0x9d,
139 0xea, 0x5c, 0x71, 0x10, 0x84, 0xab, 0xc4, 0xd7, 0xbe, 0x7d, 0xe9, 0x4a,
140 0x11, 0x22, 0xa6, 0xd5, 0xa3, 0x6e, 0x46, 0x07, 0x70, 0x78, 0xcc, 0xd5,
141 0xbc, 0xfe, 0xc4, 0x39, 0x58, 0xf4, 0xbb, 0x02, 0x82, 0x01, 0x01, 0x00,
142 0xaa, 0x0c, 0x73, 0x30, 0x20, 0x8d, 0x15, 0x02, 0x4e, 0x4d, 0x6f, 0xfe,
143 0x4b, 0x99, 0x79, 0x16, 0xf0, 0x94, 0x19, 0xc1, 0x40, 0xa2, 0x36, 0x78,
144 0x73, 0x21, 0x78, 0x86, 0x83, 0xd1, 0x15, 0x28, 0x59, 0x00, 0xfa, 0x0a,
145 0xf0, 0x1f, 0xab, 0x03, 0x38, 0x35, 0x50, 0x78, 0x32, 0xe6, 0xdf, 0x98,
146 0x2b, 0x91, 0x7b, 0xd4, 0x84, 0x90, 0x43, 0xab, 0x5a, 0x24, 0x8b, 0xa3,
147 0xb6, 0x08, 0x4d, 0x5b, 0x05, 0xb5, 0xad, 0x43, 0x74, 0x7e, 0x22, 0xb7,
148 0x09, 0xb0, 0x3a, 0x78, 0x55, 0xfa, 0x4c, 0x3c, 0xa2, 0x2c, 0xa6, 0xf7,
149 0x19, 0xff, 0x76, 0xa4, 0x3d, 0x1e, 0x99, 0x51, 0xa7, 0x4e, 0x76, 0x47,
150 0x0f, 0x70, 0xef, 0x0b, 0x3f, 0xf2, 0x94, 0x36, 0xf3, 0x63, 0x76, 0xb9,
151 0x09, 0x88, 0xbb, 0xfe, 0xf9, 0x86, 0x33, 0xdf, 0x81, 0xbe, 0x6f, 0xcc,
152 0xa9, 0x75, 0x09, 0xe5, 0x8f, 0x8b, 0x42, 0xd0, 0x19, 0x03, 0x61, 0xd8,
153 0xb5, 0x78, 0xcb, 0x9c, 0xbe, 0x63, 0x4d, 0xbd, 0xce, 0x5e, 0xae, 0x7f,
154 0xae, 0x97, 0x88, 0x7b, 0xf4, 0x7a, 0x7b, 0xdb, 0xf6, 0x7e, 0x2c, 0x7d,
155 0x95, 0x6e, 0x72, 0x3a, 0x48, 0x13, 0xdb, 0xf7, 0x10, 0x07, 0x83, 0xac,
156 0xa1, 0x7a, 0x68, 0x18, 0x70, 0x18, 0x99, 0x7f, 0xf4, 0x8e, 0x93, 0x1a,
157 0x40, 0x5d, 0x04, 0x07, 0xcb, 0x4d, 0xd7, 0x66, 0x96, 0xb5, 0xd3, 0x7d,
158 0x8e, 0xfb, 0xe6, 0x12, 0xd0, 0x7d, 0xf0, 0xe7, 0x25, 0xa6, 0x7a, 0x86,
159 0x01, 0x56, 0xdd, 0xc5, 0xb2, 0x31, 0x98, 0x67, 0x3a, 0xd0, 0x9a, 0xee,
160 0x98, 0xca, 0x80, 0x52, 0x5a, 0x0e, 0xb7, 0xc4, 0xbf, 0xc0, 0x40, 0x24,
161 0x6f, 0x3b, 0xa6, 0xf6, 0xab, 0x28, 0x9e, 0xe9, 0x39, 0x3f, 0x04, 0x4b,
162 0xc4, 0xae, 0x55, 0xfd, 0xea, 0x87, 0xa5, 0xc5, 0x01, 0x99, 0x2e, 0x67,
163 0x66, 0xb3, 0xfe, 0x41, 0x02, 0x82, 0x01, 0x00, 0x05, 0x26, 0x96, 0xf2,
164 0xd6, 0x71, 0x36, 0xd6, 0x08, 0x4f, 0xa1, 0x3a, 0x45, 0x9e, 0xa6, 0xeb,
165 0x1d, 0xea, 0x8f, 0xb1, 0x1d, 0x68, 0x82, 0xc4, 0xa7, 0xd3, 0xdc, 0x08,
166 0xf4, 0x93, 0x93, 0x18, 0x56, 0xa5, 0xdf, 0x7b, 0x00, 0xb0, 0xee, 0x69,
167 0xf0, 0xea, 0xeb, 0x90, 0x1e, 0x12, 0x27, 0x64, 0x8d, 0xbe, 0xf1, 0x4b,
168 0x3b, 0x27, 0xe0, 0x79, 0xf1, 0x97, 0xb0, 0x7b, 0x0f, 0xdc, 0x0f, 0xda,
169 0x24, 0x0e, 0xd7, 0xaa, 0xe9, 0xbe, 0x86, 0x09, 0x1b, 0x07, 0x6f, 0x1c,
170 0x5f, 0x05, 0x1d, 0x0a, 0x0c, 0xad, 0x5f, 0xc4, 0x4f, 0x9d, 0xde, 0x79,
171 0x72, 0x23, 0x2c, 0xdd, 0xa8, 0x5d, 0xc5, 0x8d, 0x7f, 0x4c, 0x1a, 0x0d,
172 0x17, 0x75, 0x09, 0x98, 0x4a, 0xbe, 0xd5, 0x55, 0x8d, 0x0c, 0x2d, 0x05,
173 0x2d, 0x71, 0x5b, 0xeb, 0xde, 0x99, 0x43, 0xcc, 0x6f, 0x37, 0xce, 0x6c,
174 0xd0, 0xd4, 0xf5, 0xda, 0x1d, 0x8e, 0xeb, 0x28, 0x55, 0x09, 0xb1, 0x42,
175 0x4f, 0xa7, 0x1a, 0xde, 0xe3, 0x14, 0xf1, 0x56, 0x2e, 0x40, 0xd6, 0xb5,
176 0x1d, 0xee, 0x47, 0x77, 0x1d, 0xdc, 0x36, 0xfa, 0xf3, 0xbc, 0x8b, 0xa5,
177 0xbf, 0x1d, 0x9f, 0xa7, 0xb4, 0x04, 0xad, 0xb6, 0x0d, 0x39, 0x0e, 0xe7,
178 0x13, 0x3e, 0xbc, 0x94, 0x68, 0xe5, 0x1d, 0xea, 0x0c, 0x30, 0xdd, 0xb0,
179 0xa7, 0x03, 0xa4, 0x91, 0xde, 0xf1, 0xd8, 0xa8, 0x18, 0x1f, 0xdd, 0xb3,
180 0xd4, 0x2b, 0x6a, 0x8c, 0x69, 0x60, 0xda, 0x92, 0x7b, 0x1e, 0x27, 0x47,
181 0x82, 0xbf, 0xff, 0xfc, 0xbd, 0x03, 0xb4, 0xc1, 0x80, 0x6c, 0x07, 0x11,
182 0xa2, 0xdd, 0x27, 0xc1, 0x4d, 0x93, 0xe6, 0xf2, 0xd3, 0xdc, 0x61, 0xa1,
183 0xa3, 0xdc, 0x67, 0x69, 0xe5, 0x50, 0x1d, 0x63, 0x0e, 0xb9, 0xa9, 0x9d,
184 0xd6, 0x02, 0x4d, 0x7c, 0xcd, 0x2a, 0xa5, 0x37, 0x60, 0xc5, 0xf5, 0x97,
185 0x02, 0x82, 0x01, 0x00, 0x14, 0x8b, 0x04, 0xdb, 0x4e, 0x41, 0x4a, 0xcd,
186 0x86, 0x2e, 0x5f, 0x13, 0xb3, 0x48, 0x1e, 0x00, 0xdf, 0x8d, 0x0b, 0x35,
187 0x51, 0x51, 0x1b, 0x16, 0x3d, 0x49, 0x4e, 0xe1, 0xee, 0x4d, 0xc7, 0x03,
188 0xc0, 0xf6, 0x5c, 0x6c, 0x36, 0xe8, 0x22, 0xa5, 0x79, 0xb4, 0x4c, 0xce,
189 0xa8, 0x45, 0x12, 0x2c, 0xf3, 0x6a, 0xcd, 0x33, 0xbd, 0xd0, 0x84, 0x4d,
190 0xf7, 0x8f, 0xb5, 0x80, 0x1f, 0x18, 0x52, 0xad, 0xad, 0xce, 0xcd, 0x94,
191 0xc9, 0xc6, 0xb4, 0xd2, 0x14, 0x29, 0xe4, 0xc7, 0x40, 0xf1, 0x0b, 0x85,
192 0x43, 0xaf, 0x11, 0xd3, 0x46, 0x0a, 0xb1, 0x15, 0x87, 0x1f, 0x4e, 0x2e,
193 0xc1, 0x11, 0xe9, 0x24, 0x70, 0x40, 0xba, 0x0b, 0x0e, 0x4a, 0xac, 0x45,
194 0x21, 0xcc, 0x6d, 0xa4, 0x1d, 0x55, 0x33, 0x89, 0x4c, 0x65, 0x21, 0x23,
195 0xab, 0x61, 0x31, 0xcb, 0x11, 0x65, 0xb3, 0x80, 0xa4, 0x5a, 0x2b, 0xf1,
196 0x65, 0xdb, 0x4c, 0x58, 0x5a, 0xbe, 0xf3, 0x15, 0xcd, 0x94, 0xa1, 0xe4,
197 0xcb, 0x30, 0xfa, 0xe1, 0x28, 0x51, 0x52, 0xd2, 0xb8, 0xb4, 0x8c, 0xfc,
198 0x3a, 0xcc, 0xd1, 0x19, 0xa2, 0x27, 0x36, 0xfa, 0xc4, 0x23, 0x96, 0xb9,
199 0xc7, 0x74, 0xca, 0xf1, 0x45, 0x1f, 0x4b, 0xc2, 0x77, 0x4d, 0x32, 0x3f,
200 0xab, 0x7a, 0xd9, 0x2b, 0x22, 0x1d, 0xcb, 0x24, 0x58, 0x29, 0xa3, 0xb8,
201 0x92, 0xdb, 0x1c, 0xda, 0x84, 0x01, 0xca, 0x6d, 0x4a, 0x50, 0xd4, 0x2b,
202 0x79, 0xfa, 0xc5, 0x4c, 0x9d, 0x79, 0x49, 0xf1, 0xde, 0xbd, 0x3f, 0x50,
203 0xa7, 0xa6, 0xc6, 0xc7, 0x99, 0x61, 0x9b, 0xda, 0x38, 0xdc, 0xbe, 0x85,
204 0x75, 0x81, 0xb9, 0x0f, 0x33, 0xd0, 0xd4, 0xd0, 0xaa, 0xbd, 0x32, 0xc9,
205 0x62, 0xe8, 0x21, 0x24, 0xeb, 0x03, 0x73, 0x46, 0xb3, 0x84, 0x65, 0xf2,
206 0x40, 0x7d, 0x1b, 0x1b, 0x8f, 0x86, 0x7c, 0xe7
207 };
208
209 /* The corresponding public key, DER. */
210 static const unsigned char rsa_pub_key[] = {
211 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xa3, 0x14, 0xe4,
212 0xb8, 0xd8, 0x58, 0x0d, 0xab, 0xd7, 0x87, 0xa4, 0xf6, 0x84, 0x51, 0x74,
213 0x60, 0x4c, 0xe3, 0x60, 0x28, 0x89, 0x49, 0x65, 0x18, 0x5c, 0x8f, 0x1a,
214 0x1b, 0xe9, 0xdb, 0xc1, 0xc1, 0xf7, 0x08, 0x27, 0x44, 0xe5, 0x9d, 0x9a,
215 0x33, 0xc3, 0xac, 0x5a, 0xca, 0xba, 0x20, 0x5a, 0x9e, 0x3a, 0x18, 0xb5,
216 0x3d, 0xe3, 0x9d, 0x94, 0x58, 0xa7, 0xa9, 0x5a, 0x0b, 0x4f, 0xb8, 0xe5,
217 0xa3, 0x7b, 0x01, 0x11, 0x0f, 0x16, 0x11, 0xb8, 0x65, 0x2f, 0xa8, 0x95,
218 0xf7, 0x58, 0x2c, 0xec, 0x1d, 0x41, 0xad, 0xd1, 0x12, 0xca, 0x4a, 0x80,
219 0x35, 0x35, 0x43, 0x7e, 0xe0, 0x97, 0xfc, 0x86, 0x8f, 0xcf, 0x4b, 0xdc,
220 0xbc, 0x15, 0x2c, 0x8e, 0x90, 0x84, 0x26, 0x83, 0xc1, 0x96, 0x97, 0xf4,
221 0xd7, 0x90, 0xce, 0xfe, 0xd4, 0xf3, 0x70, 0x22, 0xa8, 0xb0, 0x1f, 0xed,
222 0x08, 0xd7, 0xc5, 0xc0, 0xd6, 0x41, 0x6b, 0x24, 0x68, 0x5c, 0x07, 0x1f,
223 0x44, 0x97, 0xd8, 0x6e, 0x18, 0x93, 0x67, 0xc3, 0xba, 0x3a, 0xaf, 0xfd,
224 0xc2, 0x65, 0x00, 0x21, 0x63, 0xdf, 0xb7, 0x28, 0x68, 0xd6, 0xc0, 0x20,
225 0x86, 0x92, 0xed, 0x68, 0x6a, 0x27, 0x3a, 0x07, 0xec, 0x66, 0x00, 0xfe,
226 0x51, 0x51, 0x86, 0x41, 0x6f, 0x83, 0x69, 0xd2, 0xf0, 0xe6, 0xf7, 0x61,
227 0xda, 0x12, 0x45, 0x53, 0x09, 0xdf, 0xf8, 0x42, 0xc7, 0x30, 0x6a, 0xe5,
228 0xd8, 0x2b, 0xa2, 0x49, 0x7a, 0x05, 0x10, 0xee, 0xb2, 0x59, 0x0a, 0xe5,
229 0xbe, 0xf8, 0x4d, 0x0f, 0xa8, 0x9e, 0x63, 0x81, 0x39, 0x32, 0xaa, 0xfd,
230 0xa8, 0x03, 0xf6, 0xd8, 0xc6, 0xaa, 0x02, 0x93, 0x03, 0xeb, 0x15, 0xd3,
231 0x38, 0xc8, 0x1a, 0x78, 0xcf, 0xf3, 0xa7, 0x9f, 0x98, 0x4b, 0x91, 0x5b,
232 0x79, 0xf8, 0x4e, 0x53, 0xaf, 0x0c, 0x65, 0xe9, 0xb0, 0x93, 0xc2, 0xcb,
233 0x5d, 0x3c, 0x5f, 0x6e, 0x39, 0xd2, 0x58, 0x23, 0x50, 0xe5, 0x2e, 0xef,
234 0x12, 0x00, 0xa4, 0x59, 0x13, 0x2b, 0x2f, 0x2c, 0x0a, 0x7b, 0x36, 0x89,
235 0xc5, 0xe5, 0x8f, 0x95, 0x5e, 0x14, 0x0f, 0x0f, 0x94, 0x5a, 0xe9, 0xdc,
236 0x0b, 0x49, 0x14, 0xbe, 0x0a, 0x70, 0x45, 0xc1, 0x7c, 0xbf, 0x83, 0x70,
237 0xfd, 0x3d, 0x99, 0xe6, 0x8a, 0xf5, 0x9c, 0x09, 0x71, 0x84, 0x9a, 0x18,
238 0xa0, 0xe0, 0x6c, 0x43, 0x5c, 0x7e, 0x48, 0x33, 0xc8, 0xbe, 0x5d, 0xdd,
239 0xd8, 0x77, 0xe3, 0xe7, 0x6b, 0x34, 0x4b, 0xa2, 0xb7, 0x54, 0x07, 0x72,
240 0x2e, 0xab, 0xa9, 0x91, 0x1e, 0x4b, 0xe3, 0xb5, 0xd8, 0xfa, 0x35, 0x64,
241 0x8a, 0xe9, 0x03, 0xa1, 0xa8, 0x26, 0xbd, 0x72, 0x58, 0x10, 0x6a, 0xec,
242 0x1a, 0xf6, 0x1e, 0xb8, 0xc0, 0x46, 0x19, 0x31, 0x2c, 0xca, 0xf9, 0x6a,
243 0xd7, 0x2e, 0xd0, 0xa7, 0x2c, 0x60, 0x58, 0xc4, 0x8f, 0x46, 0x63, 0x61,
244 0x8d, 0x29, 0x6f, 0xe2, 0x5f, 0xe2, 0x43, 0x90, 0x9c, 0xe6, 0xfc, 0x08,
245 0x41, 0xc8, 0xb5, 0x23, 0x56, 0x24, 0x3e, 0x3a, 0x2c, 0x41, 0x22, 0x43,
246 0xda, 0x22, 0x15, 0x2b, 0xad, 0xd0, 0xfa, 0xc8, 0x47, 0x44, 0xe6, 0x2a,
247 0xf9, 0x38, 0x90, 0x13, 0x62, 0x22, 0xea, 0x06, 0x8c, 0x44, 0x9c, 0xd6,
248 0xca, 0x50, 0x93, 0xe9, 0xd4, 0x03, 0xd8, 0x3e, 0x71, 0x36, 0x4b, 0xaa,
249 0xab, 0xbb, 0xe2, 0x48, 0x66, 0x26, 0x53, 0xb1, 0x6d, 0x3b, 0x82, 0x2c,
250 0x8c, 0x25, 0x05, 0xf0, 0xf8, 0xcf, 0x55, 0xbf, 0x8e, 0x29, 0xf7, 0x54,
251 0x5b, 0x6f, 0x30, 0x54, 0xa6, 0xad, 0x46, 0xff, 0x22, 0x95, 0xb1, 0x87,
252 0x98, 0x00, 0x51, 0x69, 0x15, 0x07, 0xbd, 0x3d, 0x9c, 0x6e, 0xaa, 0xaa,
253 0x3b, 0x0b, 0x74, 0x65, 0x4c, 0x04, 0xe0, 0x80, 0x3e, 0xaf, 0x5e, 0x10,
254 0xd6, 0x9b, 0x28, 0x37, 0x6f, 0x02, 0x03, 0x01, 0x00, 0x01
255 };
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <openssl/core_names.h>
12 #include <openssl/evp.h>
13 #include <openssl/rsa.h>
14 #include <openssl/params.h>
15 #include <openssl/err.h>
16 #include <openssl/bio.h>
17 #include "rsa_pss.h"
18
19 /*
20 * The digest to be signed. This should be the output of a hash function.
21 * Here we sign an all-zeroes digest for demonstration purposes.
22 */
23 static const unsigned char test_digest[32] = {0};
24
25 /* A property query used for selecting algorithm implementations. */
26 static const char *propq = NULL;
27
28 /*
29 * This function demonstrates RSA signing of a SHA-256 digest using the PSS
30 * padding scheme. You must already have hashed the data you want to sign.
31 * For a higher-level demonstration which does the hashing for you, see
32 * rsa_pss_hash.c.
33 *
34 * For more information, see RFC 8017 section 9.1. The digest passed in
35 * (test_digest above) corresponds to the 'mHash' value.
36 */
37 static int sign(OSSL_LIB_CTX *libctx, unsigned char **sig, size_t *sig_len)
38 {
39 int rv = 0;
40 EVP_PKEY *pkey = NULL;
41 EVP_PKEY_CTX *ctx = NULL;
42 EVP_MD *md = NULL;
43 const unsigned char *ppriv_key = NULL;
44
45 *sig = NULL;
46
47 /* Load DER-encoded RSA private key. */
48 ppriv_key = rsa_priv_key;
49 pkey = d2i_PrivateKey_ex(EVP_PKEY_RSA, NULL, &ppriv_key,
50 sizeof(rsa_priv_key), libctx, propq);
51 if (pkey == NULL) {
52 fprintf(stderr, "Failed to load private key\n");
53 goto end;
54 }
55
56 /* Fetch hash algorithm we want to use. */
57 md = EVP_MD_fetch(libctx, "SHA256", propq);
58 if (md == NULL) {
59 fprintf(stderr, "Failed to fetch hash algorithm\n");
60 goto end;
61 }
62
63 /* Create signing context. */
64 ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propq);
65 if (ctx == NULL) {
66 fprintf(stderr, "Failed to create signing context\n");
67 goto end;
68 }
69
70 /* Initialize context for signing and set options. */
71 if (EVP_PKEY_sign_init(ctx) == 0) {
72 fprintf(stderr, "Failed to initialize signing context\n");
73 goto end;
74 }
75
76 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) == 0) {
77 fprintf(stderr, "Failed to configure padding\n");
78 goto end;
79 }
80
81 if (EVP_PKEY_CTX_set_signature_md(ctx, md) == 0) {
82 fprintf(stderr, "Failed to configure digest type\n");
83 goto end;
84 }
85
86 /* Determine length of signature. */
87 if (EVP_PKEY_sign(ctx, NULL, sig_len,
88 test_digest, sizeof(test_digest)) == 0) {
89 fprintf(stderr, "Failed to get signature length\n");
90 goto end;
91 }
92
93 /* Allocate memory for signature. */
94 *sig = OPENSSL_malloc(*sig_len);
95 if (*sig == NULL) {
96 fprintf(stderr, "Failed to allocate memory for signature\n");
97 goto end;
98 }
99
100 /* Generate signature. */
101 if (EVP_PKEY_sign(ctx, *sig, sig_len,
102 test_digest, sizeof(test_digest)) != 1) {
103 fprintf(stderr, "Failed to sign\n");
104 goto end;
105 }
106
107 rv = 1;
108 end:
109 EVP_PKEY_CTX_free(ctx);
110 EVP_PKEY_free(pkey);
111 EVP_MD_free(md);
112
113 if (rv == 0)
114 OPENSSL_free(*sig);
115
116 return rv;
117 }
118
119 /*
120 * This function demonstrates verification of an RSA signature over a SHA-256
121 * digest using the PSS signature scheme.
122 */
123 static int verify(OSSL_LIB_CTX *libctx, const unsigned char *sig, size_t sig_len)
124 {
125 int rv = 0;
126 const unsigned char *ppub_key = NULL;
127 EVP_PKEY *pkey = NULL;
128 EVP_PKEY_CTX *ctx = NULL;
129 EVP_MD *md = NULL;
130
131 /* Load DER-encoded RSA public key. */
132 ppub_key = rsa_pub_key;
133 pkey = d2i_PublicKey(EVP_PKEY_RSA, NULL, &ppub_key, sizeof(rsa_pub_key));
134 if (pkey == NULL) {
135 fprintf(stderr, "Failed to load public key\n");
136 goto end;
137 }
138
139 /* Fetch hash algorithm we want to use. */
140 md = EVP_MD_fetch(libctx, "SHA256", propq);
141 if (md == NULL) {
142 fprintf(stderr, "Failed to fetch hash algorithm\n");
143 goto end;
144 }
145
146 /* Create verification context. */
147 ctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propq);
148 if (ctx == NULL) {
149 fprintf(stderr, "Failed to create verification context\n");
150 goto end;
151 }
152
153 /* Initialize context for verification and set options. */
154 if (EVP_PKEY_verify_init(ctx) == 0) {
155 fprintf(stderr, "Failed to initialize verification context\n");
156 goto end;
157 }
158
159 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PSS_PADDING) == 0) {
160 fprintf(stderr, "Failed to configure padding\n");
161 goto end;
162 }
163
164 if (EVP_PKEY_CTX_set_signature_md(ctx, md) == 0) {
165 fprintf(stderr, "Failed to configure digest type\n");
166 goto end;
167 }
168
169 /* Verify signature. */
170 if (EVP_PKEY_verify(ctx, sig, sig_len,
171 test_digest, sizeof(test_digest)) == 0) {
172 fprintf(stderr, "Failed to verify signature; "
173 "signature may be invalid\n");
174 goto end;
175 }
176
177 rv = 1;
178 end:
179 EVP_PKEY_CTX_free(ctx);
180 EVP_PKEY_free(pkey);
181 EVP_MD_free(md);
182 return rv;
183 }
184
185 int main(int argc, char **argv)
186 {
187 int rv = 1;
188 OSSL_LIB_CTX *libctx = NULL;
189 unsigned char *sig = NULL;
190 size_t sig_len = 0;
191
192 if (sign(libctx, &sig, &sig_len) == 0)
193 goto end;
194
195 if (verify(libctx, sig, sig_len) == 0)
196 goto end;
197
198 rv = 0;
199 end:
200 OPENSSL_free(sig);
201 OSSL_LIB_CTX_free(libctx);
202 return rv;
203 }
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <openssl/core_names.h>
12 #include <openssl/evp.h>
13 #include <openssl/rsa.h>
14 #include <openssl/params.h>
15 #include <openssl/err.h>
16 #include <openssl/bio.h>
17 #include "rsa_pss.h"
18
19 /* The data to be signed. This will be hashed. */
20 static const char test_message[] =
21 "This is an example message to be signed.";
22
23 /* A property query used for selecting algorithm implementations. */
24 static const char *propq = NULL;
25
26 /*
27 * This function demonstrates RSA signing of an arbitrary-length message.
28 * Hashing is performed automatically. In this example, SHA-256 is used. If you
29 * have already hashed your message and simply want to sign the hash directly,
30 * see rsa_pss_direct.c.
31 */
32 static int sign(OSSL_LIB_CTX *libctx, unsigned char **sig, size_t *sig_len)
33 {
34 int rv = 0;
35 EVP_PKEY *pkey = NULL;
36 EVP_MD_CTX *mctx = NULL;
37 OSSL_PARAM params[2], *p = params;
38 const unsigned char *ppriv_key = NULL;
39
40 *sig = NULL;
41
42 /* Load DER-encoded RSA private key. */
43 ppriv_key = rsa_priv_key;
44 pkey = d2i_PrivateKey_ex(EVP_PKEY_RSA, NULL, &ppriv_key,
45 sizeof(rsa_priv_key), libctx, propq);
46 if (pkey == NULL) {
47 fprintf(stderr, "Failed to load private key\n");
48 goto end;
49 }
50
51 /* Create MD context used for signing. */
52 mctx = EVP_MD_CTX_new();
53 if (mctx == NULL) {
54 fprintf(stderr, "Failed to create MD context\n");
55 goto end;
56 }
57
58 /* Initialize MD context for signing. */
59 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,
60 OSSL_PKEY_RSA_PAD_MODE_PSS, 0);
61 *p = OSSL_PARAM_construct_end();
62
63 if (EVP_DigestSignInit_ex(mctx, NULL, "SHA256", libctx, propq,
64 pkey, params) == 0) {
65 fprintf(stderr, "Failed to initialize signing context\n");
66 goto end;
67 }
68
69 /*
70 * Feed data to be signed into the algorithm. This may
71 * be called multiple times.
72 */
73 if (EVP_DigestSignUpdate(mctx, test_message, sizeof(test_message)) == 0) {
74 fprintf(stderr, "Failed to hash message into signing context\n");
75 goto end;
76 }
77
78 /* Determine signature length. */
79 if (EVP_DigestSignFinal(mctx, NULL, sig_len) == 0) {
80 fprintf(stderr, "Failed to get signature length\n");
81 goto end;
82 }
83
84 /* Allocate memory for signature. */
85 *sig = OPENSSL_malloc(*sig_len);
86 if (*sig == NULL) {
87 fprintf(stderr, "Failed to allocate memory for signature\n");
88 goto end;
89 }
90
91 /* Generate signature. */
92 if (EVP_DigestSignFinal(mctx, *sig, sig_len) == 0) {
93 fprintf(stderr, "Failed to sign\n");
94 goto end;
95 }
96
97 rv = 1;
98 end:
99 EVP_MD_CTX_free(mctx);
100 EVP_PKEY_free(pkey);
101
102 if (rv == 0)
103 OPENSSL_free(*sig);
104
105 return rv;
106 }
107
108 /*
109 * This function demonstrates verification of an RSA signature over an
110 * arbitrary-length message using the PSS signature scheme. Hashing is performed
111 * automatically.
112 */
113 static int verify(OSSL_LIB_CTX *libctx, const unsigned char *sig, size_t sig_len)
114 {
115 int rv = 0;
116 EVP_PKEY *pkey = NULL;
117 EVP_MD_CTX *mctx = NULL;
118 OSSL_PARAM params[2], *p = params;
119 const unsigned char *ppub_key = NULL;
120
121 /* Load DER-encoded RSA public key. */
122 ppub_key = rsa_pub_key;
123 pkey = d2i_PublicKey(EVP_PKEY_RSA, NULL, &ppub_key, sizeof(rsa_pub_key));
124 if (pkey == NULL) {
125 fprintf(stderr, "Failed to load public key\n");
126 goto end;
127 }
128
129 /* Create MD context used for verification. */
130 mctx = EVP_MD_CTX_new();
131 if (mctx == NULL) {
132 fprintf(stderr, "Failed to create MD context\n");
133 goto end;
134 }
135
136 /* Initialize MD context for verification. */
137 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_PAD_MODE,
138 OSSL_PKEY_RSA_PAD_MODE_PSS, 0);
139 *p = OSSL_PARAM_construct_end();
140
141 if (EVP_DigestVerifyInit_ex(mctx, NULL, "SHA256", libctx, propq,
142 pkey, params) == 0) {
143 fprintf(stderr, "Failed to initialize signing context\n");
144 goto end;
145 }
146
147 /*
148 * Feed data to be signed into the algorithm. This may
149 * be called multiple times.
150 */
151 if (EVP_DigestVerifyUpdate(mctx, test_message, sizeof(test_message)) == 0) {
152 fprintf(stderr, "Failed to hash message into signing context\n");
153 goto end;
154 }
155
156 /* Verify signature. */
157 if (EVP_DigestVerifyFinal(mctx, sig, sig_len) == 0) {
158 fprintf(stderr, "Failed to verify signature; "
159 "signature may be invalid\n");
160 goto end;
161 }
162
163 rv = 1;
164 end:
165 EVP_MD_CTX_free(mctx);
166 EVP_PKEY_free(pkey);
167 return rv;
168 }
169
170 int main(int argc, char **argv)
171 {
172 int rv = 1;
173 OSSL_LIB_CTX *libctx = NULL;
174 unsigned char *sig = NULL;
175 size_t sig_len = 0;
176
177 if (sign(libctx, &sig, &sig_len) == 0)
178 goto end;
179
180 if (verify(libctx, sig, sig_len) == 0)
181 goto end;
182
183 rv = 0;
184 end:
185 OPENSSL_free(sig);
186 OSSL_LIB_CTX_free(libctx);
187 return rv;
188 }
2626 /* Set up trusted CA certificate store */
2727
2828 st = X509_STORE_new();
29 if (st == NULL)
30 goto err;
2931
3032 /* Read in signer certificate and private key */
3133 tbio = BIO_new_file("cacert.pem", "r");
3234
33 if (!tbio)
35 if (tbio == NULL)
3436 goto err;
3537
3638 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
3739
38 if (!cacert)
40 if (cacert == NULL)
3941 goto err;
4042
4143 if (!X509_STORE_add_cert(st, cacert))
4547
4648 in = BIO_new_file("smout.txt", "r");
4749
48 if (!in)
50 if (in == NULL)
4951 goto err;
5052
5153 /* Sign content */
5254 p7 = SMIME_read_PKCS7(in, &cont);
5355
54 if (!p7)
56 if (p7 == NULL)
5557 goto err;
5658
5759 /* File to output verified content to */
5860 out = BIO_new_file("smver.txt", "w");
59 if (!out)
61 if (out == NULL)
6062 goto err;
6163
6264 if (!PKCS7_verify(p7, NULL, st, cont, out, 0)) {
7375 fprintf(stderr, "Error Verifying Data\n");
7476 ERR_print_errors_fp(stderr);
7577 }
78
79 X509_STORE_free(st);
7680 PKCS7_free(p7);
7781 X509_free(cacert);
7882 BIO_free(in);
24142414 GENERATE[html/man3/SSL_get_all_async_fds.html]=man3/SSL_get_all_async_fds.pod
24152415 DEPEND[man/man3/SSL_get_all_async_fds.3]=man3/SSL_get_all_async_fds.pod
24162416 GENERATE[man/man3/SSL_get_all_async_fds.3]=man3/SSL_get_all_async_fds.pod
2417 DEPEND[html/man3/SSL_get_certificate.html]=man3/SSL_get_certificate.pod
2418 GENERATE[html/man3/SSL_get_certificate.html]=man3/SSL_get_certificate.pod
2419 DEPEND[man/man3/SSL_get_certificate.3]=man3/SSL_get_certificate.pod
2420 GENERATE[man/man3/SSL_get_certificate.3]=man3/SSL_get_certificate.pod
24172421 DEPEND[html/man3/SSL_get_ciphers.html]=man3/SSL_get_ciphers.pod
24182422 GENERATE[html/man3/SSL_get_ciphers.html]=man3/SSL_get_ciphers.pod
24192423 DEPEND[man/man3/SSL_get_ciphers.3]=man3/SSL_get_ciphers.pod
25462550 GENERATE[html/man3/SSL_set_fd.html]=man3/SSL_set_fd.pod
25472551 DEPEND[man/man3/SSL_set_fd.3]=man3/SSL_set_fd.pod
25482552 GENERATE[man/man3/SSL_set_fd.3]=man3/SSL_set_fd.pod
2553 DEPEND[html/man3/SSL_set_retry_verify.html]=man3/SSL_set_retry_verify.pod
2554 GENERATE[html/man3/SSL_set_retry_verify.html]=man3/SSL_set_retry_verify.pod
2555 DEPEND[man/man3/SSL_set_retry_verify.3]=man3/SSL_set_retry_verify.pod
2556 GENERATE[man/man3/SSL_set_retry_verify.3]=man3/SSL_set_retry_verify.pod
25492557 DEPEND[html/man3/SSL_set_session.html]=man3/SSL_set_session.pod
25502558 GENERATE[html/man3/SSL_set_session.html]=man3/SSL_set_session.pod
25512559 DEPEND[man/man3/SSL_set_session.3]=man3/SSL_set_session.pod
33223330 html/man3/SSL_get0_peer_scts.html \
33233331 html/man3/SSL_get_SSL_CTX.html \
33243332 html/man3/SSL_get_all_async_fds.html \
3333 html/man3/SSL_get_certificate.html \
33253334 html/man3/SSL_get_ciphers.html \
33263335 html/man3/SSL_get_client_random.html \
33273336 html/man3/SSL_get_current_cipher.html \
33553364 html/man3/SSL_set_bio.html \
33563365 html/man3/SSL_set_connect_state.html \
33573366 html/man3/SSL_set_fd.html \
3367 html/man3/SSL_set_retry_verify.html \
33583368 html/man3/SSL_set_session.html \
33593369 html/man3/SSL_set_shutdown.html \
33603370 html/man3/SSL_set_verify_result.html \
39143924 man/man3/SSL_get0_peer_scts.3 \
39153925 man/man3/SSL_get_SSL_CTX.3 \
39163926 man/man3/SSL_get_all_async_fds.3 \
3927 man/man3/SSL_get_certificate.3 \
39173928 man/man3/SSL_get_ciphers.3 \
39183929 man/man3/SSL_get_client_random.3 \
39193930 man/man3/SSL_get_current_cipher.3 \
39473958 man/man3/SSL_set_bio.3 \
39483959 man/man3/SSL_set_connect_state.3 \
39493960 man/man3/SSL_set_fd.3 \
3961 man/man3/SSL_set_retry_verify.3 \
39503962 man/man3/SSL_set_session.3 \
39513963 man/man3/SSL_set_shutdown.3 \
39523964 man/man3/SSL_set_verify_result.3 \
101101 reference count of the method and the I<method_destruct> function is called
102102 to decrement it.
103103
104 =head1 NOTES
105
106 The I<prop_query> argument to ossl_method_store_cache_get() and
107 ossl_method_store_cache_set() is not allowed to be NULL. Use "" for an
108 empty property definition or query.
109
104110 =head1 RETURN VALUES
105111
106112 ossl_method_store_new() returns a new method store object or NULL on failure.
118124
119125 =head1 COPYRIGHT
120126
121 Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
127 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
122128 Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
123129
124130 Licensed under the Apache License 2.0 (the "License"). You may not use this
250250 The source of the private or public key for the certificate requested
251251 in Initialization Request (IR), Certification Request(CR), or
252252 Key Update Request (KUR).
253 Default is the public key in the PKCS#10 CSR given with the B<-csr> option,
254 if any, or else the current client key, if given.
253 Defaults to the public key in the PKCS#10 CSR given with the B<-csr> option,
254 the public key of the reference certificate, or the current client key.
255255
256256 =item B<-newkeypass> I<arg>
257257
439439
440440 =item B<-server> I<[http[s]://][userinfo@]host[:port][/path][?query][#fragment]>
441441
442 The IP address or DNS hostname and optionally port
443 of the CMP server to connect to using HTTP(S) transport.
442 The DNS hostname or IP address and optionally port
443 of the CMP server to connect to using HTTP(S).
444 This excludes I<-port> and I<-use_mock_srv> and is ignored with I<-rspin>.
445
444446 The scheme C<https> may be given only if the B<-tls_used> option is used.
445447 In this case the default port is 443, else 80.
446448 The optional userinfo and fragment components are ignored.
457459 components.
458460 Defaults to the environment variable C<http_proxy> if set, else C<HTTP_PROXY>
459461 in case no TLS is used, otherwise C<https_proxy> if set, else C<HTTPS_PROXY>.
462 This option is ignored if I<-server> is not given.
460463
461464 =item B<-no_proxy> I<addresses>
462465
464467 not to use an HTTP(S) proxy for, separated by commas and/or whitespace
465468 (where in the latter case the whole argument must be enclosed in "...").
466469 Default is from the environment variable C<no_proxy> if set, else C<NO_PROXY>.
470 This option is ignored if I<-server> is not given.
467471
468472 =item B<-recipient> I<name>
469473
794798 =item B<-tls_used>
795799
796800 Enable using TLS (even when other TLS_related options are not set)
797 when connecting to CMP server.
801 when connecting to CMP server via HTTP.
802 This option is not supported with the I<-port> option
803 and is ignored with the I<-use_mock_srv> and I<-rspin> options
804 or if the I<-server> option is not given.
798805
799806 =item B<-tls_cert> I<filename>|I<uri>
800807
879886 =item B<-rspin> I<filenames>
880887
881888 Process sequence of CMP responses provided in file(s), skipping server.
889 This excludes I<-server>, I<-port>, and I<-use_mock_srv>.
882890
883891 Multiple filenames may be given, separated by commas and/or whitespace.
884892 As many files are read as needed for the complete transaction.
892900
893901 =item B<-use_mock_srv>
894902
895 Use the internal mock server for testing the client.
896 This works at API level, bypassing HTTP transport.
903 Test the client using the internal CMP server mock-up at API level,
904 bypassing socket-based transfer via HTTP.
905 This excludes I<-server>, I<-port>, and I<-rspin>.
897906
898907 =back
899908
903912
904913 =item B<-port> I<number>
905914
906 Act as CMP HTTP server mock-up listening on the given port.
915 Act as HTTP-based CMP server mock-up listening on the given port.
916 This excludes I<-server>, I<-rspin>, and I<-use_mock_srv>.
907917
908918 =item B<-max_msgs> I<number>
909919
12201230
12211231 =head1 COPYRIGHT
12221232
1223 Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
1224
1225 Licensed under the OpenSSL license (the "License"). You may not use
1233 Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
1234
1235 Licensed under the Apache License 2.0 (the "License"). You may not use
12261236 this file except in compliance with the License. You can obtain a copy
12271237 in the file LICENSE in the source distribution or at
12281238 L<https://www.openssl.org/source/license.html>.
88
99 B<openssl> B<dgst>|I<digest>
1010 [B<-I<digest>>]
11 [B<-list>]
1112 [B<-help>]
1213 [B<-c>]
1314 [B<-d>]
1415 [B<-debug>]
15 [B<-list>]
1616 [B<-hex>]
1717 [B<-binary>]
1818 [B<-xoflen> I<length>]
4646 algorithm to be used.
4747 The default digest is B<sha256>.
4848 A supported I<digest> name may also be used as the sub-command name.
49 To see the list of supported algorithms, use C<openssl list -digest-commands>
49 To see the list of supported algorithms, use C<openssl list -digest-algorithms>
5050
5151 =head1 OPTIONS
5252
5858
5959 =item B<-I<digest>>
6060
61 Specifies name of a supported digest to be used. To see the list of
62 supported digests, use the command C<list --digest-commands>.
61 Specifies name of a supported digest to be used. See option B<-list> below :
62
63 =item B<-list>
64
65 Prints out a list of supported message digests.
6366
6467 =item B<-c>
6568
6972 =item B<-d>, B<-debug>
7073
7174 Print out BIO debugging information.
72
73 =item B<-list>
74
75 Prints out a list of supported message digests.
7675
7776 =item B<-hex>
7877
205204 =head1 EXAMPLES
206205
207206 To create a hex-encoded message digest of a file:
207
208208 openssl dgst -md5 -hex file.txt
209 or
210 openssl md5 file.txt
209211
210212 To sign a file using SHA-256 with binary file output:
213
211214 openssl dgst -sha256 -sign privatekey.pem -out signature.sign file.txt
215 or
216 openssl sha256 -sign privatekey.pem -out signature.sign file.txt
212217
213218 To verify a signature:
219
214220 openssl dgst -sha256 -verify publickey.pem \
215221 -signature signature.sign \
216222 file.txt
220226
221227 The digest mechanisms that are available will depend on the options
222228 used when building OpenSSL.
223 The C<openssl list -digest-commands> command can be used to list them.
229 The C<openssl list -digest-algorithms> command can be used to list them.
224230
225231 New or agile applications should use probably use SHA-256. Other digests,
226232 particularly SHA-1 and MD5, are still widely used for interoperating
258264
259265 =head1 COPYRIGHT
260266
261 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
267 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
262268
263269 Licensed under the Apache License 2.0 (the "License"). You may not use
264270 this file except in compliance with the License. You can obtain a copy
165165 Use scrypt to create a hex-encoded derived key from a password and salt:
166166
167167 openssl kdf -keylen 64 -kdfopt pass:password -kdfopt salt:NaCl \
168 -kdfopt N:1024 -kdfopt r:8 -kdfopt p:16 \
168 -kdfopt n:1024 -kdfopt r:8 -kdfopt p:16 \
169169 -kdfopt maxmem_bytes:10485760 SCRYPT
170170
171171 =head1 NOTES
194194
195195 =head1 COPYRIGHT
196196
197 Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
197 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
198198
199199 Licensed under the Apache License 2.0 (the "License"). You may not use
200200 this file except in compliance with the License. You can obtain a copy
100100 =item B<-bytes> I<num>
101101
102102 Run benchmarks on I<num>-byte buffers. Affects ciphers, digests and the CSPRNG.
103 The limit on the size of the buffer is INT_MAX - 64 bytes, which for a 32-bit
104 int would be 2147483583 bytes.
103105
104106 =item B<-mr>
105107
133135
134136 =head1 COPYRIGHT
135137
136 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
138 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
137139
138140 Licensed under the Apache License 2.0 (the "License"). You may not use
139141 this file except in compliance with the License. You can obtain a copy
1616
1717 long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
1818 long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb);
19 char *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
19 void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
2020 long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
2121
2222 int BIO_reset(BIO *b);
145145
146146 =head1 COPYRIGHT
147147
148 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
148 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
149149
150150 Licensed under the Apache License 2.0 (the "License"). You may not use
151151 this file except in compliance with the License. You can obtain a copy
2020
2121 Base64 BIOs do not support BIO_gets() or BIO_puts().
2222
23 For writing, output is by default divided to lines of length 64
24 characters and there is always a newline at the end of output.
25
26 For reading, first line should be at most 1024
27 characters long. If it is longer then it is ignored completely.
28 Other input lines can be of any length. There must be a newline
29 at the end of input.
30
31 This behavior can be changed with BIO_FLAGS_BASE64_NO_NL flag.
32
2333 BIO_flush() on a base64 BIO that is being written through is
2434 used to signal that no more data is to be encoded: this is used
2535 to flush the final block through the BIO.
2636
27 The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags()
28 to encode the data all on one line or expect the data to be all
29 on one line.
37 The flag BIO_FLAGS_BASE64_NO_NL can be set with BIO_set_flags().
38 For writing, it causes all data to be written on one line without
39 newline at the end.
40 For reading, it forces the decoder to process the data regardless
41 of newlines. All newlines are ignored and the input does not need
42 to contain any newline at all.
3043
3144 =head1 NOTES
3245
8093
8194 =head1 COPYRIGHT
8295
83 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
96 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
8497
8598 Licensed under the Apache License 2.0 (the "License"). You may not use
8699 this file except in compliance with the License. You can obtain a copy
22 =head1 NAME
33
44 BN_add, BN_sub, BN_mul, BN_sqr, BN_div, BN_mod, BN_nnmod, BN_mod_add,
5 BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_exp, BN_mod_exp, BN_gcd -
5 BN_mod_sub, BN_mod_mul, BN_mod_sqr, BN_mod_sqrt, BN_exp, BN_mod_exp, BN_gcd -
66 arithmetic operations on BIGNUMs
77
88 =head1 SYNOPSIS
3434 BN_CTX *ctx);
3535
3636 int BN_mod_sqr(BIGNUM *r, BIGNUM *a, const BIGNUM *m, BN_CTX *ctx);
37
38 BIGNUM *BN_mod_sqrt(BIGNUM *in, BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
3739
3840 int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx);
3941
8688 BN_mod_sqr() takes the square of I<a> modulo B<m> and places the
8789 result in I<r>.
8890
91 BN_mod_sqrt() returns the modular square root of I<a> such that
92 C<in^2 = a (mod p)>. The modulus I<p> must be a
93 prime, otherwise an error or an incorrect "result" will be returned.
94 The result is stored into I<in> which can be NULL. The result will be
95 newly allocated in that case.
96
8997 BN_exp() raises I<a> to the I<p>-th power and places the result in I<r>
9098 (C<r=a^p>). This function is faster than repeated applications of
9199 BN_mul().
107115
108116 =head1 RETURN VALUES
109117
110 For all functions, 1 is returned for success, 0 on error. The return
118 The BN_mod_sqrt() returns the result (possibly incorrect if I<p> is
119 not a prime), or NULL.
120
121 For all remaining functions, 1 is returned for success, 0 on error. The return
111122 value should always be checked (e.g., C<if (!BN_add(r,a,b)) goto err;>).
112123 The error codes can be obtained by L<ERR_get_error(3)>.
113124
118129
119130 =head1 COPYRIGHT
120131
121 Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
132 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
122133
123134 Licensed under the Apache License 2.0 (the "License"). You may not use
124135 this file except in compliance with the License. You can obtain a copy
265265
266266 B<sk_I<TYPE>_insert>(), B<sk_I<TYPE>_push>() and B<sk_I<TYPE>_unshift>() return
267267 the total number of elements in the stack and 0 if an error occurred.
268 B<sk_I<TYPE>_push>() further returns -1 if I<sk> is NULL.
268269
269270 B<sk_I<TYPE>_set>() returns a pointer to the replacement element or NULL on
270271 error.
3030 const char **func,
3131 const char **data, int *flags);
3232 unsigned long ERR_peek_error_all(const char **file, int *line,
33 const char *func,
33 const char **func,
3434 const char **data, int *flags);
3535 unsigned long ERR_peek_last_error_all(const char **file, int *line,
3636 const char *func,
131131
132132 =head1 COPYRIGHT
133133
134 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
134 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
135135
136136 Licensed under the Apache License 2.0 (the "License"). You may not use
137137 this file except in compliance with the License. You can obtain a copy
3636 the names and types of key parameters that can be retrieved.
3737 See L<OSSL_PARAM(3)> for information about parameters.
3838
39 An B<OSSL_PARAM> of type B<OSSL_PARAM_INTEGER> or
40 B<OSSL_PARAM_UNSIGNED_INTEGER> is of arbitrary length. Such a parameter can be
41 obtained using any of the functions EVP_PKEY_get_int_param(),
42 EVP_PKEY_get_size_t_param() or EVP_PKEY_get_bn_param(). Attempting to
43 obtain an integer value that does not fit into a native C B<int> type will cause
44 EVP_PKEY_get_int_param() to fail. Similarly attempting to obtain an integer
45 value that is negative or does not fit into a native C B<size_t> type using
46 EVP_PKEY_get_size_t_param() will also fail.
47
3948 EVP_PKEY_get_int_param() retrieves a key I<pkey> integer value I<*out>
40 associated with a name of I<key_name>.
49 associated with a name of I<key_name> if it fits into C<int> type. For
50 parameters that do not fit into C<int> use EVP_PKEY_get_bn_param().
4151
4252 EVP_PKEY_get_size_t_param() retrieves a key I<pkey> size_t value I<*out>
43 associated with a name of I<key_name>.
53 associated with a name of I<key_name> if it fits into C<size_t> type. For
54 parameters that do not fit into C<size_t> use EVP_PKEY_get_bn_param().
4455
4556 EVP_PKEY_get_bn_param() retrieves a key I<pkey> BIGNUM value I<**bn>
4657 associated with a name of I<key_name>. If I<*bn> is NULL then the BIGNUM
114125
115126 =head1 COPYRIGHT
116127
117 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
128 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
118129
119130 Licensed under the Apache License 2.0 (the "License"). You may not use
120131 this file except in compliance with the License. You can obtain a copy
100100 algorithm and the other representing a digest algorithm to be used in
101101 conjunction with it. I<signid> represents the NID for the composite "Signature
102102 Algorithm", I<dig_id> is the NID for the digest algorithm and I<pkey_id> is the
103 NID for the underlying signature algorithm.
103 NID for the underlying signature algorithm. As there are signature algorithms
104 that do not require a digest, NID_undef is a valid I<dig_id>.
104105
105106 OBJ_cleanup() releases any resources allocated by creating new objects.
106107
1414 int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, long *buflen,
1515 const char *str, const char sep);
1616 unsigned char *OPENSSL_hexstr2buf(const char *str, long *len);
17 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
18 const unsigned char *buf, long buflen, const char sep);
17 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength,
18 const unsigned char *buf, long buflen,
19 const char sep);
1920 char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen);
2021
2122 =head1 DESCRIPTION
4647 The character I<sep> is the separator between the bytes, setting this to '\0'
4748 means that there is no separator.
4849 I<str_n> gives the size of the of the string buffer.
49 If I<strlen> is not NULL, it is filled in with the result length.
50 If I<strlength> is not NULL, it is filled in with the result length.
5051 To find out how large the result will be, call this function with NULL
5152 for I<str>.
5253
6970
7071 =head1 COPYRIGHT
7172
72 Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
73 Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
7374
7475 Licensed under the Apache License 2.0 (the "License"). You may not use
7576 this file except in compliance with the License. You can obtain a copy
537537 alternate names on the certificate template request. This cannot be used if
538538 any Subject Alternative Name extension is set via
539539 OSSL_CMP_CTX_set0_reqExtensions().
540 By default, unless OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT has been set,
540 By default, unless B<OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT> has been set,
541541 the Subject Alternative Names are copied from the reference certificate,
542542 see OSSL_CMP_CTX_set1_oldCert().
543543 If set and the subject DN is not set with OSSL_CMP_CTX_set1_subjectName() then
558558 OSSL_CMP_CTX_set1_oldCert() sets the old certificate to be updated in
559559 Key Update Requests (KUR) or to be revoked in Revocation Requests (RR).
560560 It must be given for RR, else it defaults to the CMP signer certificate.
561 The reference certificate determined in this way, if any, is also used for
562 deriving default subject DN and Subject Alternative Names and the
561 The I<reference certificate> determined in this way, if any, is also used for
562 deriving default subject DN, public key, Subject Alternative Names, and the
563563 default issuer entry in the requested certificate template of IR/CR/KUR.
564564 The subject of the reference certificate is used as the sender field value
565565 in CMP message headers.
566566 Its issuer is used as default recipient in CMP message headers.
567567
568 OSSL_CMP_CTX_set1_p10CSR() sets the PKCS#10 CSR to be used in P10CR.
568 OSSL_CMP_CTX_set1_p10CSR() sets the PKCS#10 CSR to use in P10CR messages.
569 If such a CSR is provided, its subject, public key, and extension fields are
570 also used as fallback values for the certificate template of IR/CR/KUR messages.
569571
570572 OSSL_CMP_CTX_push0_genm_ITAV() adds I<itav> to the stack in the I<ctx> which
571573 will be the body of a General Message sent with this context.
755757
756758 =head1 COPYRIGHT
757759
758 Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
760 Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
759761
760762 Licensed under the Apache License 2.0 (the "License"). You may not use
761763 this file except in compliance with the License. You can obtain a copy
3535 This requires re-protecting the message (if it was protected).
3636
3737 OSSL_CMP_CTX_setup_CRM() creates a CRMF certificate request message
38 from various information provided in the CMP context argument I<ctx>
3839 for inclusion in a CMP request message based on details contained in I<ctx>.
39 If the CMP context does not include a subject name set via
40 L<OSSL_CMP_CTX_set1_subjectName(3)> but includes a reference certificate
41 then it copies the subject DN from there
42 if I<for_KUR> is set or the I<ctx> does not include a subjectAltName.
43 The I<rid> defines the request identifier to use, which typically is 0.
40 The I<rid> argument defines the request identifier to use, which typically is 0.
41
42 The subject DN to include in the certificate template is determined as follows.
43 If I<ctx> includes a subject name set via L<OSSL_CMP_CTX_set1_subjectName(3)>,
44 this name is used.
45 Otherwise, if a PKCS#10 CSR is given in I<ctx>, its subject is used.
46 Otherwise, if a reference certificate is given in I<ctx>
47 (see L<OSSL_CMP_CTX_set1_oldCert(3)>), its subject is used if I<for_KUR>
48 is nonzero or the I<ctx> does not include a Subject Alternative Name.
49
50 The public key to include is taken from any value set via
51 L<OSSL_CMP_CTX_set0_newPkey(3)>,
52 otherwise the public key of any PKCS#10 CSR is given in I<ctx>,
53 otherwise the public key of any reference certificate given in I<ctx>,
54 otherwise it is derived from the client private key if given in I<ctx>.
55
56 The set of X.509 extensions to include is computed as follows.
57 If a PKCS#10 CSR is present in I<ctx>, default extensions are taken from there,
58 otherwise the empty set is taken as the initial value.
59 If there is a reference certificate in I<ctx> and contains Subject Alternative
60 Names (SANs) and B<OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT> is not set,
61 these override any SANs from the PKCS#10 CSR.
62 The extensions are further augmented or overridden by any extensions with the
63 same OIDs included in the I<ctx> via L<OSSL_CMP_CTX_set0_reqExtensions(3)>.
64 The SANs are further overridden by any SANs included in I<ctx> via
65 L<OSSL_CMP_CTX_push1_subjectAltName(3)>.
66 Finally, policies are overridden by any policies included in I<ctx> via
67 L<OSSL_CMP_CTX_push0_policy(3)>.
68
69 OSSL_CMP_CTX_setup_CRM() also sets the sets the regToken control B<oldCertID>
70 for KUR messages using the issuer name and serial number of the reference
71 certificate, if present.
4472
4573 OSSL_CMP_MSG_read() loads a DER-encoded OSSL_CMP_MSG from I<file>.
4674
82110
83111 =head1 COPYRIGHT
84112
85 Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
113 Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
86114
87115 Licensed under the Apache License 2.0 (the "License"). You may not use
88116 this file except in compliance with the License. You can obtain a copy
8888 OSSL_CRMF_MSG_set1_regCtrl_protocolEncrKey() sets the protocolEncrKey control in
8989 the given I<msg> copying the given I<pubkey> as value. See RFC 4211 section 6.6.
9090
91 OSSL_CRMF_MSG_set1_regCtrl_oldCertID() sets the oldCertID control in the given
92 I<msg> copying the given I<cid> as value. See RFC 4211, section 6.5.
91 OSSL_CRMF_MSG_set1_regCtrl_oldCertID() sets the B<oldCertID> regToken control in
92 the given I<msg> copying the given I<cid> as value. See RFC 4211, section 6.5.
9393
9494 OSSL_CRMF_CERTID_gen produces an OSSL_CRMF_CERTID_gen structure copying the
9595 given I<issuer> name and I<serial> number.
120120
121121 =head1 COPYRIGHT
122122
123 Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
123 Copyright 2007-2022 The OpenSSL Project Authors. All Rights Reserved.
124124
125125 Licensed under the Apache License 2.0 (the "License"). You may not use
126126 this file except in compliance with the License. You can obtain a copy
112112
113113 Here is a simple example that supports TLS connections (but not via a proxy):
114114
115 BIO *http_tls_cb(BIO *hbio, void *arg, int connect, int detail)
115 BIO *http_tls_cb(BIO *bio, void *arg, int connect, int detail)
116116 {
117117 if (connect && detail) { /* connecting with TLS */
118118 SSL_CTX *ctx = (SSL_CTX *)arg;
119119 BIO *sbio = BIO_new_ssl(ctx, 1);
120120
121 hbio = sbio != NULL ? BIO_push(sbio, hbio) : NULL;
122 } else if (!connect && !detail) { /* disconnecting after error */
123 /* optionally add diagnostics here */
121 bio = sbio != NULL ? BIO_push(sbio, bio) : NULL;
122 } else if (!connect) { /* disconnecting */
123 BIO *hbio;
124
125 if (!detail) { /* an error has occurred */
126 /* optionally add diagnostics here */
127 }
128 BIO_ssl_shutdown(bio);
129 hbio = BIO_pop(bio);
130 BIO_free(bio); /* SSL BIO */
131 bio = hbio;
124132 }
125 return hbio;
133 return bio;
126134 }
127135
128136 After disconnect the modified BIO will be deallocated using BIO_free_all().
3737
3838 const char *OPENSSL_info(int t);
3939
40 Deprecated:
41
4240 /* from openssl/opensslv.h */
4341 #define OPENSSL_VERSION_NUMBER 0xnnnnnnnnL
4442
7977 (B<maj>) and minor (B<min>) number or not. It will evaluate to true if the
8078 header version number (B<OPENSSL_VERSION_MAJOR>.B<OPENSSL_VERSION_MINOR>) is
8179 greater than or equal to B<maj>.B<min>.
80
81 B<OPENSSL_VERSION_NUMBER> is a combination of the major, minor and
82 patch version into a single integer 0xMNN00PP0L, where:
83
84 =over 4
85
86 =item M
87
88 is the number from B<OPENSSL_VERSION_MAJOR>, in hexadecimal notation
89
90 =item NN
91
92 is the number from B<OPENSSL_VERSION_MINOR>, in hexadecimal notation
93
94 =item PP
95
96 is the number from B<OPENSSL_VERSION_PATCH>, in hexadecimal notation
97
98 =back
8299
83100 =head2 Functions
84101
197214
198215 For an unknown I<t>, NULL is returned.
199216
200 =head1 BACKWARD COMPATIBILITY
201
202 For compatibility, some older macros and functions are retained or
203 synthesised.
204 They are all considered deprecated.
205
206 =head2 Macros
207
208 B<OPENSSL_VERSION_NUMBER> is a combination of the major, minor and
209 patch version into a single integer 0xMNN00PP0L, where:
210
211 =over 4
212
213 =item M
214
215 is the number from B<OPENSSL_VERSION_MAJOR>, in hexadecimal notation
216
217 =item NN
218
219 is the number from B<OPENSSL_VERSION_MINOR>, in hexadecimal notation
220
221 =item PP
222
223 is the number from B<OPENSSL_VERSION_PATCH>, in hexadecimal notation
224
225 =back
226
227 =head2 Functions
228
229217 OpenSSL_version_num() returns the value of B<OPENSSL_VERSION_NUMBER>.
230218
231219 =head1 RETURN VALUES
247235 =head1 HISTORY
248236
249237 The macros and functions described here were added in OpenSSL 3.0,
250 with the exception of the L</BACKWARD COMPATIBILITY> ones.
238 except for OPENSSL_VERSION_NUMBER and OpenSSL_version_num().
251239
252240 =head1 COPYRIGHT
253241
254 Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
242 Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
255243
256244 Licensed under the Apache License 2.0 (the "License"). You may not use
257245 this file except in compliance with the License. You can obtain a copy
334334 ignored.
335335
336336 If the I<cb> parameters is set to NULL and the I<u> parameter is not
337 NULL then the I<u> parameter is interpreted as a null terminated string
337 NULL then the I<u> parameter is interpreted as a NUL terminated string
338338 to use as the passphrase. If both I<cb> and I<u> are NULL then the
339339 default callback routine is used which will typically prompt for the
340340 passphrase on the current terminal with echoing turned off.
354354 arbitrary data to be passed to the callback by the application
355355 (for example a window handle in a GUI application). The callback
356356 I<must> return the number of characters in the passphrase or -1 if
357 an error occurred.
357 an error occurred. The passphrase can be arbitrary data; in the case where it
358 is a string, it is not NUL terminated. See the L</EXAMPLES> section below.
358359
359360 Some implementations may need to use cryptographic algorithms during their
360361 operation. If this is the case and I<libctx> and I<propq> parameters have been
572573
573574 =head1 COPYRIGHT
574575
575 Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
576 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
576577
577578 Licensed under the Apache License 2.0 (the "License"). You may not use
578579 this file except in compliance with the License. You can obtain a copy
459459 B<SSL_OP_NO_TICKET>: that is B<-SessionTicket> is the same as setting
460460 B<SSL_OP_NO_TICKET>.
461461
462 B<Compression>: SSL/TLS compression support, enabled by default. Inverse
462 B<Compression>: SSL/TLS compression support, disabled by default. Inverse
463463 of B<SSL_OP_NO_COMPRESSION>.
464464
465465 B<EmptyFragments>: use empty fragments as a countermeasure against a
495495
496496 B<UnsafeLegacyServerConnect>: permits the use of unsafe legacy renegotiation
497497 for OpenSSL clients only. Equivalent to B<SSL_OP_LEGACY_SERVER_CONNECT>.
498 Set by default.
499498
500499 B<EncryptThenMac>: use encrypt-then-mac extension, enabled by
501500 default. Inverse of B<SSL_OP_NO_ENCRYPT_THEN_MAC>: that is,
730729
731730 B<AllowNoDHEKEX> and B<PrioritizeChaCha> were added in OpenSSL 1.1.1.
732731
732 The B<UnsafeLegacyServerConnect> option is no longer set by default from
733 OpenSSL 3.0.
734
733735 =head1 COPYRIGHT
734736
735 Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved.
737 Copyright 2012-2022 The OpenSSL Project Authors. All Rights Reserved.
736738
737739 Licensed under the Apache License 2.0 (the "License"). You may not use
738740 this file except in compliance with the License. You can obtain a copy
3535 In client mode, the behaviour is as follows.
3636 All values, including 0, are ignored
3737 if the verification mode is B<SSL_VERIFY_NONE>.
38 Otherwise, when the return value is 0, the handshake will fail.
38 Otherwise, when the return value is less than or equal to 0, the handshake will
39 fail.
3940
40 In client mode I<callback> may also return -1,
41 typically on failure verifying the server certificate.
42 This makes the handshake suspend and return control to the calling application
43 with B<SSL_ERROR_WANT_RETRY_VERIFY>.
44 The app can for instance fetch further certificates or cert status information
45 needed for the verification.
46 Calling L<SSL_connect(3)> again resumes the connection attempt
47 by retrying the server certificate verification step.
41 In client mode I<callback> may also call the L<SSL_set_retry_verify(3)>
42 function on the B<SSL> object set in the I<x509_store_ctx> ex data (see
43 L<SSL_get_ex_data_X509_STORE_CTX_idx(3)>) and return 1. This would be
44 typically done in case the certificate verification was not yet able
45 to succeed. This makes the handshake suspend and return control to the
46 calling application with B<SSL_ERROR_WANT_RETRY_VERIFY>. The app can for
47 instance fetch further certificates or cert status information needed for
48 the verification. Calling L<SSL_connect(3)> again resumes the connection
49 attempt by retrying the server certificate verification step.
4850 This process may even be repeated if need be.
4951
5052 In any case a viable verification result value must be reflected
8890 L<ssl(7)>, L<SSL_CTX_set_verify(3)>,
8991 L<X509_STORE_CTX_set_error(3)>,
9092 L<SSL_get_verify_result(3)>,
93 L<SSL_set_retry_verify(3)>,
9194 L<SSL_CTX_load_verify_locations(3)>
9295
9396 =head1 COPYRIGHT
9497
95 Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
98 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
9699
97100 Licensed under the Apache License 2.0 (the "License"). You may not use
98101 this file except in compliance with the License. You can obtain a copy
1010
1111 #include <openssl/ssl.h>
1212
13 long SSL_CTX_set_dh_auto(SSL *s, int onoff);
13 long SSL_CTX_set_dh_auto(SSL_CTX *ctx, int onoff);
1414 long SSL_set_dh_auto(SSL *s, int onoff);
1515 int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey);
1616 int SSL_set0_tmp_dh_pkey(SSL *s, EVP_PKEY *dhpkey);
111111
112112 =head1 COPYRIGHT
113113
114 Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
114 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
115115
116116 Licensed under the Apache License 2.0 (the "License"). You may not use
117117 this file except in compliance with the License. You can obtain a copy
4242 L<SSL_new(3)>. Within the callback function,
4343 B<SSL_get_ex_data_X509_STORE_CTX_idx> can be called to get the data index
4444 of the current SSL object that is doing the verification.
45
46 In client mode B<verify_callback> may also call the L<SSL_set_retry_verify(3)>
47 function on the B<SSL> object set in the I<x509_store_ctx> ex data (see
48 L<SSL_get_ex_data_X509_STORE_CTX_idx(3)>) and return 1.
49 This would be typically done in case the certificate verification was not yet
50 able to succeed.
51 This makes the handshake suspend and return control to the calling application
52 with B<SSL_ERROR_WANT_RETRY_VERIFY>.
53 The application can for instance fetch further certificates or cert status
54 information needed for the verification.
55 Note that the handshake may still be aborted if a subsequent invocation of the
56 callback (e.g. at a lower depth, or for a separate error condition) returns 0.
57 Calling L<SSL_connect(3)> again resumes the connection attempt by retrying the
58 server certificate verification step.
59 This process may even be repeated if need be.
4560
4661 SSL_CTX_set_verify_depth() sets the maximum B<depth> for the certificate chain
4762 verification that shall be allowed for B<ctx>.
347362
348363 =head1 COPYRIGHT
349364
350 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
365 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
351366
352367 Licensed under the Apache License 2.0 (the "License"). You may not use
353368 this file except in compliance with the License. You can obtain a copy
0 =pod
1
2 =head1 NAME
3
4 SSL_get_certificate, SSL_get_privatekey - retrieve TLS/SSL certificate and
5 private key
6
7 =head1 SYNOPSIS
8
9 #include <openssl/ssl.h>
10
11 X509 *SSL_get_certificate(const SSL *s);
12 EVP_PKEY *SSL_get_privatekey(const SSL *s);
13
14 =head1 DESCRIPTION
15
16 SSL_get_certificate() returns a pointer to an B<X509> object representing a
17 certificate used as the local peer's identity.
18
19 Multiple certificates can be configured; for example, a server might have both
20 RSA and ECDSA certificates. The certificate which is returned by
21 SSL_get_certificate() is determined as follows:
22
23 =over 4
24
25 =item
26
27 If it is called before certificate selection has occurred, it returns the most
28 recently added certificate, or NULL if no certificate has been added.
29
30 =item
31
32 After certificate selection has occurred, it returns the certificate which was
33 selected during the handshake, or NULL if no certificate was selected (for
34 example, on a client where no client certificate is in use).
35
36 =back
37
38 Certificate selection occurs during the handshake; therefore, the value returned
39 by SSL_get_certificate() during any callback made during the handshake process
40 will depend on whether that callback is made before or after certificate
41 selection occurs.
42
43 A specific use for SSL_get_certificate() is inside a callback set via a call to
44 L<SSL_CTX_set_tlsext_status_cb(3)>. This callback occurs after certificate
45 selection, where it can be used to examine a server's chosen certificate, for
46 example for the purpose of identifying a certificate's OCSP responder URL so
47 that an OCSP response can be obtained.
48
49 SSL_get_privatekey() returns a pointer to the B<EVP_PKEY> object corresponding
50 to the certificate returned by SSL_get_certificate(), if any.
51
52 =head1 RETURN VALUES
53
54 These functions return pointers to their respective objects, or NULL if no such
55 object is available. Returned objects are owned by the SSL object and should not
56 be freed by users of these functions.
57
58 =head1 SEE ALSO
59
60 L<ssl(7)>, L<SSL_CTX_set_tlsext_status_cb(3)>
61
62 =head1 COPYRIGHT
63
64 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
65
66 Licensed under the Apache License 2.0 (the "License"). You may not use
67 this file except in compliance with the License. You can obtain a copy
68 in the file LICENSE in the source distribution or at
69 L<https://www.openssl.org/source/license.html>.
70
71 =cut
72
0 =pod
1
2 =head1 NAME
3
4 SSL_set_retry_verify - indicate that certificate verification should be retried
5
6 =head1 SYNOPSIS
7
8 #include <openssl/ssl.h>
9
10 int SSL_set_retry_verify(SSL *ssl);
11
12 =head1 DESCRIPTION
13
14 SSL_set_retry_verify() should be called from the certificate verification
15 callback on a client when the application wants to indicate that the handshake
16 should be suspended and the control should be returned to the application.
17 L<SSL_want_retry_verify(3)> will return 1 as a consequence until the handshake
18 is resumed again by the application, retrying the verification step.
19
20 Please refer to L<SSL_CTX_set_cert_verify_callback(3)> for further details.
21
22 =head1 NOTES
23
24 The effect of calling SSL_set_retry_verify() outside of the certificate
25 verification callback on the client side is undefined.
26
27 =head1 RETURN VALUES
28
29 SSL_set_retry verify() returns 1 on success, 0 otherwise.
30
31 =head1 EXAMPLES
32
33 The following code snippet shows how to obtain the B<SSL> object associated
34 with the B<X509_STORE_CTX> to call the SSL_set_retry_verify() function:
35
36 int idx = SSL_get_ex_data_X509_STORE_CTX_idx();
37 SSL *ssl;
38
39 /* this should not happen but check anyway */
40 if (idx < 0
41 || (ssl = X509_STORE_CTX_get_ex_data(ctx, idx)) == NULL)
42 return 0;
43
44 if (/* we need to retry verification callback */)
45 return SSL_set_retry_verify(ssl);
46
47 /* do normal processing of the verification callback */
48
49 =head1 SEE ALSO
50
51 L<ssl(7)>, L<SSL_connect(3)>, L<SSL_CTX_set_cert_verify_callback(3)>,
52 L<SSL_want_retry_verify(3)>
53
54 =head1 HISTORY
55
56 SSL_set_retry_verify() was added in OpenSSL 3.0.2 to replace backwards
57 incompatible handling of a negative return value from the verification
58 callback.
59
60 =head1 COPYRIGHT
61
62 Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
63
64 Licensed under the Apache License 2.0 (the "License"). You may not use
65 this file except in compliance with the License. You can obtain a copy
66 in the file LICENSE in the source distribution or at
67 L<https://www.openssl.org/source/license.html>.
68
69 =cut
6969
7070 =item SSL_RETRY_VERIFY
7171
72 The operation did not complete because an application callback set by
73 SSL_CTX_set_cert_verify_callback() has asked to be called again.
72 The operation did not complete because a certificate verification callback
73 has asked to be called again via L<SSL_set_retry_verify(3)>.
7474 A call to L<SSL_get_error(3)> should return B<SSL_ERROR_WANT_RETRY_VERIFY>.
7575
7676 =item SSL_ASYNC_PAUSED
109109
110110 =head1 COPYRIGHT
111111
112 Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
112 Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
113113
114114 Licensed under the Apache License 2.0 (the "License"). You may not use
115115 this file except in compliance with the License. You can obtain a copy
11
22 =head1 NAME
33
4 X509_get0_extensions, X509_CRL_get0_extensions, X509_REVOKED_get0_extensions,
54 X509V3_get_d2i, X509V3_add1_i2d, X509V3_EXT_d2i, X509V3_EXT_i2d,
6 X509_get_ext_d2i, X509_add1_ext_i2d, X509_CRL_get_ext_d2i,
7 X509_CRL_add1_ext_i2d, X509_REVOKED_get_ext_d2i,
8 X509_REVOKED_add1_ext_i2d - X509 extension decode and encode functions
5 X509_get_ext_d2i, X509_add1_ext_i2d,
6 X509_CRL_get_ext_d2i, X509_CRL_add1_ext_i2d,
7 X509_REVOKED_get_ext_d2i, X509_REVOKED_add1_ext_i2d,
8 X509_get0_extensions, X509_CRL_get0_extensions,
9 X509_REVOKED_get0_extensions - X509 extension decode and encode functions
910
1011 =head1 SYNOPSIS
1112
3738
3839 =head1 DESCRIPTION
3940
40 X509V3_get_ext_d2i() looks for an extension with OID B<nid> in the extensions
41 B<x> and, if found, decodes it. If B<idx> is B<NULL> then only one
41 X509V3_get_d2i() looks for an extension with OID I<nid> in the extensions
42 I<x> and, if found, decodes it. If I<idx> is NULL then only one
4243 occurrence of an extension is permissible otherwise the first extension after
43 index B<*idx> is returned and B<*idx> updated to the location of the extension.
44 If B<crit> is not B<NULL> then B<*crit> is set to a status value: -2 if the
45 extension occurs multiple times (this is only returned if B<idx> is B<NULL>),
44 index I<*idx> is returned and I<*idx> updated to the location of the extension.
45 If I<crit> is not NULL then I<*crit> is set to a status value: -2 if the
46 extension occurs multiple times (this is only returned if I<idx> is NULL),
4647 -1 if the extension could not be found, 0 if the extension is found and is
4748 not critical and 1 if critical. A pointer to an extension specific structure
48 or B<NULL> is returned.
49
50 X509V3_add1_i2d() adds extension B<value> to STACK B<*x> (allocating a new
51 STACK if necessary) using OID B<nid> and criticality B<crit> according
52 to B<flags>.
49 or NULL is returned.
50
51 X509V3_add1_i2d() adds extension I<value> to STACK I<*x> (allocating a new
52 STACK if necessary) using OID I<nid> and criticality I<crit> according
53 to I<flags>.
5354
5455 X509V3_EXT_d2i() attempts to decode the ASN.1 data contained in extension
55 B<ext> and returns a pointer to an extension specific structure or B<NULL>
56 I<ext> and returns a pointer to an extension specific structure or NULL
5657 if the extension could not be decoded (invalid syntax or not supported).
5758
58 X509V3_EXT_i2d() encodes the extension specific structure B<ext>
59 with OID B<ext_nid> and criticality B<crit>.
59 X509V3_EXT_i2d() encodes the extension specific structure I<ext>
60 with OID I<ext_nid> and criticality I<crit>.
6061
6162 X509_get_ext_d2i() and X509_add1_ext_i2d() operate on the extensions of
62 certificate B<x>, they are otherwise identical to X509V3_get_d2i() and
63 certificate I<x>, they are otherwise identical to X509V3_get_d2i() and
6364 X509V3_add_i2d().
6465
6566 X509_CRL_get_ext_d2i() and X509_CRL_add1_ext_i2d() operate on the extensions
66 of CRL B<crl>, they are otherwise identical to X509V3_get_d2i() and
67 of CRL I<crl>, they are otherwise identical to X509V3_get_d2i() and
6768 X509V3_add_i2d().
6869
6970 X509_REVOKED_get_ext_d2i() and X509_REVOKED_add1_ext_i2d() operate on the
70 extensions of B<X509_REVOKED> structure B<r> (i.e for CRL entry extensions),
71 extensions of B<X509_REVOKED> structure I<r> (i.e for CRL entry extensions),
7172 they are otherwise identical to X509V3_get_d2i() and X509V3_add_i2d().
7273
7374 X509_get0_extensions(), X509_CRL_get0_extensions() and
7778 =head1 NOTES
7879
7980 In almost all cases an extension can occur at most once and multiple
80 occurrences is an error. Therefore, the B<idx> parameter is usually B<NULL>.
81
82 The B<flags> parameter may be one of the following values.
81 occurrences is an error. Therefore, the I<idx> parameter is usually NULL.
82
83 The I<flags> parameter may be one of the following values.
8384
8485 B<X509V3_ADD_DEFAULT> appends a new extension only if the extension does
8586 not already exist. An error is returned if the extension does already
9899 not already exist. An error B<is not> returned if the extension does already
99100 exist.
100101
101 B<X509V3_ADD_DELETE> extension B<nid> is deleted: no new extension is added.
102
103 If B<X509V3_ADD_SILENT> is ored with B<flags>: any error returned will not
102 B<X509V3_ADD_DELETE> extension I<nid> is deleted: no new extension is added.
103
104 If B<X509V3_ADD_SILENT> is ored with I<flags>: any error returned will not
104105 be added to the error queue.
105106
106 The function X509V3_get_d2i() will return B<NULL> if the extension is not
107 The function X509V3_get_d2i() and its variants
108 will return NULL if the extension is not
107109 found, occurs multiple times or cannot be decoded. It is possible to
108 determine the precise reason by checking the value of B<*crit>.
110 determine the precise reason by checking the value of I<*crit>.
109111
110112 =head1 SUPPORTED EXTENSIONS
111113
194196
195197 =head1 RETURN VALUES
196198
197 X509V3_EXT_d2i() and *X509V3_get_d2i() return a pointer to an extension
198 specific structure or B<NULL> if an error occurs.
199
200 X509V3_EXT_i2d() returns a pointer to an B<X509_EXTENSION> structure
201 or B<NULL> if an error occurs.
202
203 X509V3_add1_i2d() returns 1 if the operation is successful and 0 if it
204 fails due to a non-fatal error (extension not found, already exists,
199 X509V3_get_d2i(), its variants, and X509V3_EXT_d2i() return
200 a pointer to an extension specific structure or NULL if an error occurs.
201
202 X509V3_add1_i2d() and its variants return 1 if the operation is successful
203 and 0 if it fails due to a non-fatal error (extension not found, already exists,
205204 cannot be encoded) or -1 due to a fatal error such as a memory allocation
206205 failure.
206
207 X509V3_EXT_i2d() returns a pointer to an B<X509_EXTENSION> structure
208 or NULL if an error occurs.
207209
208210 X509_get0_extensions(), X509_CRL_get0_extensions() and
209211 X509_REVOKED_get0_extensions() return a stack of extensions. They return
230232
231233 =head1 COPYRIGHT
232234
233 Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
235 Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
234236
235237 Licensed under the Apache License 2.0 (the "License"). You may not use
236238 this file except in compliance with the License. You can obtain a copy
1010 X509_STORE_CTX_get0_chain, X509_STORE_CTX_set0_verified_chain,
1111 X509_STORE_CTX_set_default,
1212 X509_STORE_CTX_set_verify,
13 X509_STORE_CTX_verify_fn
13 X509_STORE_CTX_verify_fn,
14 X509_STORE_CTX_set_purpose,
15 X509_STORE_CTX_set_trust,
16 X509_STORE_CTX_purpose_inherit
1417 - X509_STORE_CTX initialisation
1518
1619 =head1 SYNOPSIS
4346 int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
4447 typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *);
4548 void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, X509_STORE_CTX_verify_fn verify);
49
50 int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
51 int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
52 int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
53 int purpose, int trust);
4654
4755 =head1 DESCRIPTION
4856
154162 This function should receive the current X509_STORE_CTX as a parameter and
155163 return 1 on success or 0 on failure.
156164
165 X509 certificates may contain information about what purposes keys contained
166 within them can be used for. For example "TLS WWW Server Authentication" or
167 "Email Protection". This "key usage" information is held internally to the
168 certificate itself. In addition the trust store containing trusted certificates
169 can declare what purposes we trust different certificates for. This "trust"
170 information is not held within the certificate itself but is "meta" information
171 held alongside it. This "meta" information is associated with the certificate
172 after it is issued and could be determined by a system administrator. For
173 example a certificate might declare that it is suitable for use for both
174 "TLS WWW Server Authentication" and "TLS Client Authentication", but a system
175 administrator might only trust it for the former. An X.509 certificate extension
176 exists that can record extended key usage information to supplement the purpose
177 information described above. This extended mechanism is arbitrarily extensible
178 and not well suited for a generic library API; applications that need to
179 validate extended key usage information in certifiates will need to define a
180 custom "purpose" (see below) or supply a nondefault verification callback
181 (L<X509_STORE_set_verify_cb_func(3)>).
182
183 X509_STORE_CTX_set_purpose() sets the purpose for the target certificate being
184 verified in the I<ctx>. Built-in available values for the I<purpose> argument
185 are B<X509_PURPOSE_SSL_CLIENT>, B<X509_PURPOSE_SSL_SERVER>,
186 B<X509_PURPOSE_NS_SSL_SERVER>, B<X509_PURPOSE_SMIME_SIGN>,
187 B<X509_PURPOSE_SMIME_ENCRYPT>, B<X509_PURPOSE_CRL_SIGN>, B<X509_PURPOSE_ANY>,
188 B<X509_PURPOSE_OCSP_HELPER> and B<X509_PURPOSE_TIMESTAMP_SIGN>. It is also
189 possible to create a custom purpose value. Setting a purpose will ensure that
190 the key usage declared within certificates in the chain being verified is
191 consistent with that purpose as well as, potentially, other checks. Every
192 purpose also has an associated default trust value which will also be set at the
193 same time. During verification this trust setting will be verified to check it
194 is consistent with the trust set by the system administrator for certificates in
195 the chain.
196
197 X509_STORE_CTX_set_trust() sets the trust value for the target certificate
198 being verified in the I<ctx>. Built-in available values for the I<trust>
199 argument are B<X509_TRUST_COMPAT>, B<X509_TRUST_SSL_CLIENT>,
200 B<X509_TRUST_SSL_SERVER>, B<X509_TRUST_EMAIL>, B<X509_TRUST_OBJECT_SIGN>,
201 B<X509_TRUST_OCSP_SIGN>, B<X509_TRUST_OCSP_REQUEST> and B<X509_TRUST_TSA>. It is
202 also possible to create a custom trust value. Since X509_STORE_CTX_set_purpose()
203 also sets the trust value it is normally sufficient to only call that function.
204 If both are called then X509_STORE_CTX_set_trust() should be called after
205 X509_STORE_CTX_set_purpose() since the trust setting of the last call will be
206 used.
207
208 It should not normally be necessary for end user applications to call
209 X509_STORE_CTX_purpose_inherit() directly. Typically applications should call
210 X509_STORE_CTX_set_purpose() or X509_STORE_CTX_set_trust() instead. Using this
211 function it is possible to set the purpose and trust values for the I<ctx> at
212 the same time. The I<def_purpose> and I<purpose> arguments can have the same
213 purpose values as described for X509_STORE_CTX_set_purpose() above. The I<trust>
214 argument can have the same trust values as described in
215 X509_STORE_CTX_set_trust() above. Any of the I<def_purpose>, I<purpose> or
216 I<trust> values may also have the value 0 to indicate that the supplied
217 parameter should be ignored. After calling this function the purpose to be used
218 for verification is set from the I<purpose> argument, and the trust is set from
219 the I<trust> argument. If I<trust> is 0 then the trust value will be set from
220 the default trust value for I<purpose>. If the default trust value for the
221 purpose is I<X509_TRUST_DEFAULT> and I<trust> is 0 then the default trust value
222 associated with the I<def_purpose> value is used for the trust setting instead.
223
157224 =head1 NOTES
158225
159226 The certificates and CRLs in a store are used internally and should B<not>
201268
202269 =head1 COPYRIGHT
203270
204 Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
271 Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
205272
206273 Licensed under the Apache License 2.0 (the "License"). You may not use
207274 this file except in compliance with the License. You can obtain a copy
248248 B<X509_V_FLAG_CRL_CHECK_ALL> enables CRL checking for the entire certificate
249249 chain.
250250
251 B<X509_V_FLAG_IGNORE_CRITICAL> disabled critical extension checking. By default
252 any unhandled critical extensions in certificates or (if checked) CRLs results
251 B<X509_V_FLAG_IGNORE_CRITICAL> disables critical extension checking. By default
252 any unhandled critical extensions in certificates or (if checked) CRLs result
253253 in a fatal error. If this flag is set unhandled critical extensions are
254254 ignored. B<WARNING> setting this option for anything other than debugging
255255 purposes can be a security risk. Finer control over which extensions are
400400
401401 =head1 COPYRIGHT
402402
403 Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
403 Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
404404
405405 Licensed under the Apache License 2.0 (the "License"). You may not use
406406 this file except in compliance with the License. You can obtain a copy
6161 IPv6 address. The B<address> array is in binary format, in network
6262 byte order. The length is either 4 (IPv4) or 16 (IPv6). Only
6363 explicitly marked addresses in the certificates are considered; IP
64 addresses stored in DNS names and Common Names are ignored.
64 addresses stored in DNS names and Common Names are ignored. There are
65 currently no B<flags> that would affect the behavior of this call.
6566
6667 X509_check_ip_asc() is similar, except that the NUL-terminated
6768 string B<address> is first converted to the internal representation.
152153
153154 =head1 COPYRIGHT
154155
155 Copyright 2012-2021 The OpenSSL Project Authors. All Rights Reserved.
156 Copyright 2012-2022 The OpenSSL Project Authors. All Rights Reserved.
156157
157158 Licensed under the Apache License 2.0 (the "License"). You may not use
158159 this file except in compliance with the License. You can obtain a copy
5151 incorrectly, such as with no certificate set in I<ctx>, or when it is called
5252 twice in succession without reinitialising I<ctx> for the second call.
5353 A negative return value can also happen due to internal resource problems
54 or because an internal inconsistency has been detected
55 or if a retry operation is requested during internal lookups
56 (which never happens with standard lookup methods).
54 or because an internal inconsistency has been detected.
5755 Applications must interpret any return value <= 0 as an error.
5856
5957 The X509_STORE_CTX_verify() behaves like X509_verify_cert() except that its
9088
9189 =head1 COPYRIGHT
9290
93 Copyright 2009-2021 The OpenSSL Project Authors. All Rights Reserved.
91 Copyright 2009-2022 The OpenSSL Project Authors. All Rights Reserved.
9492
9593 Licensed under the Apache License 2.0 (the "License"). You may not use
9694 this file except in compliance with the License. You can obtain a copy
1414
1515 =item "pad" (B<OSSL_EXCHANGE_PARAM_PAD>) <unsigned integer>
1616
17 Sets the padding mode for the associated key exchange ctx.
18 Setting a value of 1 will turn padding on.
19 Setting a value of 0 will turn padding off.
20 If padding is off then the derived shared secret may be smaller than the
21 largest possible secret size.
22 If padding is on then the derived shared secret will have its first bytes
23 filled with zeros where necessary to make the shared secret the same size as
24 the largest possible secret size.
25 The padding mode parameter is ignored (and padding implicitly enabled) when
26 the KDF type is set to "X942KDF-ASN1" (B<OSSL_KDF_NAME_X942KDF_ASN1>).
27
28 =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <UTF8 string>
29
30 See L<provider-keyexch(7)/Common Key Exchange parameters>.
31
32 =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <UTF8 string>
33
34 See L<provider-keyexch(7)/Common Key Exchange parameters>.
35
36 =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <UTF8 string>
37
38 See L<provider-keyexch(7)/Common Key Exchange parameters>.
39
40 =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <unsigned integer>
41
1742 See L<provider-keyexch(7)/Common Key Exchange parameters>.
1843
1944 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string>
2045
21 Sets the User Key Material to be used as part of the selected Key Derivation
22 Function associated with the given key exchange ctx.
46 See L<provider-keyexch(7)/Common Key Exchange parameters>.
2347
24 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string ptr>
48 =item "cekalg" (B<OSSL_KDF_PARAM_CEK_ALG>) <octet string ptr>
2549
26 Gets a pointer to the User Key Material to be used as part of the selected
27 Key Derivation Function associated with the given key exchange ctx. Providers
28 usually do not need to support this gettable parameter as its sole purpose
29 is to support functionality of the deprecated EVP_PKEY_CTX_get0_dh_kdf_ukm()
30 function.
50 See L<provider-kdf(7)/KDF Parameters>.
3151
3252 =back
3353
5777
5878 To derive a shared secret on the host using the host's key and the peer's public
5979 key:
80
6081 /* It is assumed that the host_key and peer_pub_key are set up */
6182 void derive_secret(EVP_KEY *host_key, EVP_PKEY *peer_pub_key)
6283 {
100121
101122 =head1 COPYRIGHT
102123
103 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
124 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
104125
105126 Licensed under the Apache License 2.0 (the "License"). You may not use
106127 this file except in compliance with the License. You can obtain a copy
3232
3333 =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <UTF8 string>
3434
35 Sets or gets the Key Derivation Function type to apply within the associated key
36 exchange ctx.
35 See L<provider-keyexch(7)/Common Key Exchange parameters>.
3736
3837 =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <UTF8 string>
3938
40 Sets or gets the Digest algorithm to be used as part of the Key Derivation Function
41 associated with the given key exchange ctx.
39 See L<provider-keyexch(7)/Common Key Exchange parameters>.
4240
4341 =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <UTF8 string>
4442
45 Sets properties to be used upon look up of the implementation for the selected
46 Digest algorithm for the Key Derivation Function associated with the given key
47 exchange ctx.
43 See L<provider-keyexch(7)/Common Key Exchange parameters>.
4844
4945 =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <unsigned integer>
5046
51 Sets or gets the desired size for the output of the chosen Key Derivation Function
52 associated with the given key exchange ctx.
53 The length of the "kdf-outlen" parameter should not exceed that of a B<size_t>.
47 See L<provider-keyexch(7)/Common Key Exchange parameters>.
5448
5549 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string>
5650
57 Sets the User Key Material to be used as part of the selected Key Derivation
58 Function associated with the given key exchange ctx.
59
60 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string ptr>
61
62 Gets a pointer to the User Key Material to be used as part of the selected
63 Key Derivation Function associated with the given key exchange ctx. Providers
64 usually do not need to support this gettable parameter as its sole purpose
65 is to support functionality of the deprecated EVP_PKEY_CTX_get0_ecdh_kdf_ukm()
66 function.
51 See L<provider-keyexch(7)/Common Key Exchange parameters>.
6752
6853 =back
6954
8772 size_t secret_len = out_len;
8873 unsigned int pad = 1;
8974 OSSL_PARAM params[6];
90 EVP_PKET_CTX *dctx = EVP_PKEY_CTX_new_from_pkey(NULL, host_key, NULL);
75 EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_new_from_pkey(NULL, host_key, NULL);
9176
9277 EVP_PKEY_derive_init(dctx);
9378
121106
122107 =head1 COPYRIGHT
123108
124 Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
109 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
125110
126111 Licensed under the Apache License 2.0 (the "License"). You may not use
127112 this file except in compliance with the License. You can obtain a copy
55
66 =head1 DESCRIPTION
77
8 Support for computing SHA2 digests through the B<EVP_MD> API.
8 Support for computing BLAKE2 digests through the B<EVP_MD> API.
99
1010 =head2 Identities
1111
3535
3636 =head1 COPYRIGHT
3737
38 Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
38 Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
3939
4040 Licensed under the Apache License 2.0 (the "License"). You may not use
4141 this file except in compliance with the License. You can obtain a copy
379379 #include <stdio.h>
380380 #include <openssl/evp.h>
381381 #include <openssl/bio.h>
382 #include <openssl/err.h>
382383
383384 int main(void)
384385 {
389390 };
390391 unsigned int len = 0;
391392 unsigned char *outdigest = NULL;
393 int ret = 1;
392394
393395 /* Create a context for the digest operation */
394396 ctx = EVP_MD_CTX_new();
429431 /* Print out the digest result */
430432 BIO_dump_fp(stdout, outdigest, len);
431433
434 ret = 0;
435
432436 err:
433437 /* Clean up all the resources we allocated */
434438 OPENSSL_free(outdigest);
435439 EVP_MD_free(sha256);
436440 EVP_MD_CTX_free(ctx);
441 if (ret != 0)
442 ERR_print_errors_fp(stderr);
443 return ret;
437444 }
438445
439446 =head1 CONFIGURATION
496503
497504 =head1 COPYRIGHT
498505
499 Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
506 Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
500507
501508 Licensed under the Apache License 2.0 (the "License"). You may not use
502509 this file except in compliance with the License. You can obtain a copy
276276 rather than a numeric NID. Any name (OID, short name or long name) can be used
277277 to identify the object. It will treat as success the case where the composite
278278 signature algorithm already exists (even if registered against a different
279 underlying signature or digest algorithm). It returns 1 on success or 0 on
280 failure.
279 underlying signature or digest algorithm). For I<digest_name>, NULL or an
280 empty string is permissible for signature algorithms that do not need a digest
281 to operate correctly. The function returns 1 on success or 0 on failure.
281282 This function is not thread safe.
282283
283284 CRYPTO_malloc(), CRYPTO_zalloc(), CRYPTO_free(), CRYPTO_clear_free(),
169169
170170 =over 4
171171
172 =item "pad" (B<OSSL_EXCHANGE_PARAM_PAD>) <unsigned integer>
173
174 Sets the padding mode for the associated key exchange ctx.
175 Setting a value of 1 will turn padding on.
176 Setting a value of 0 will turn padding off.
177 If padding is off then the derived shared secret may be smaller than the largest
178 possible secret size.
179 If padding is on then the derived shared secret will have its first bytes filled
180 with 0s where necessary to make the shared secret the same size as the largest
181 possible secret size.
172 =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <UTF8 string>
173
174 Sets or gets the Key Derivation Function type to apply within the associated key
175 exchange ctx.
176
177 =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <UTF8 string>
178
179 Sets or gets the Digest algorithm to be used as part of the Key Derivation Function
180 associated with the given key exchange ctx.
181
182 =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <UTF8 string>
183
184 Sets properties to be used upon look up of the implementation for the selected
185 Digest algorithm for the Key Derivation Function associated with the given key
186 exchange ctx.
187
188 =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <unsigned integer>
189
190 Sets or gets the desired size for the output of the chosen Key Derivation Function
191 associated with the given key exchange ctx.
192 The length of the "kdf-outlen" parameter should not exceed that of a B<size_t>.
193
194 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string>
195
196 Sets the User Key Material to be used as part of the selected Key Derivation
197 Function associated with the given key exchange ctx.
198
199 =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string ptr>
200
201 Gets a pointer to the User Key Material to be used as part of the selected
202 Key Derivation Function associated with the given key exchange ctx. Providers
203 usually do not need to support this gettable parameter as its sole purpose
204 is to support functionality of the deprecated EVP_PKEY_CTX_get0_ecdh_kdf_ukm()
205 and EVP_PKEY_CTX_get0_dh_kdf_ukm() functions.
182206
183207 =back
184208
204228
205229 =head1 COPYRIGHT
206230
207 Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
231 Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
208232
209233 Licensed under the Apache License 2.0 (the "License"). You may not use
210234 this file except in compliance with the License. You can obtain a copy
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License");
44 * you may not use this file except in compliance with the License.
217217 int len2; \
218218 BIO *bio = BIO_new(BIO_s_null()); \
219219 \
220 PRINT(bio, type); \
221 BIO_free(bio); \
220 if (bio != NULL) { \
221 PRINT(bio, type); \
222 BIO_free(bio); \
223 } \
222224 len2 = I2D(type, &der); \
223225 if (len2 != 0) {} \
224226 OPENSSL_free(der); \
234236 if (type != NULL) { \
235237 BIO *bio = BIO_new(BIO_s_null()); \
236238 \
237 PRINT(bio, type, 0); \
238 BIO_free(bio); \
239 if (bio != NULL) { \
240 PRINT(bio, type, 0); \
241 BIO_free(bio); \
242 } \
239243 I2D(type, &der); \
240244 OPENSSL_free(der); \
241245 TYPE ## _free(type); \
250254 if (type != NULL) { \
251255 BIO *bio = BIO_new(BIO_s_null()); \
252256 \
253 PRINT(bio, type, 0, pctx); \
254 BIO_free(bio); \
257 if (bio != NULL) { \
258 PRINT(bio, type, 0, pctx); \
259 BIO_free(bio); \
260 } \
255261 I2D(type, &der); \
256262 OPENSSL_free(der); \
257263 TYPE ## _free(type); \
306312
307313 if (o != NULL) {
308314 BIO *bio = BIO_new(BIO_s_null());
309
310 ASN1_item_print(bio, o, 4, i, pctx);
311 BIO_free(bio);
315 if (bio != NULL) {
316 ASN1_item_print(bio, o, 4, i, pctx);
317 BIO_free(bio);
318 }
312319 ASN1_item_i2d(o, &der, i);
313320 OPENSSL_free(der);
314321 ASN1_item_free(o, i);
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License");
44 * you may not use this file except in compliance with the License.
145145 const OSSL_DISPATCH **out, void **provctx)
146146 {
147147 *provctx = OSSL_LIB_CTX_new();
148 if (*provctx == NULL)
149 return 0;
148150 *out = fuzz_rand_method;
149151 return 1;
150152 }
00 # WARNING: do not edit!
11 # Generated by fuzz/mkfuzzoids.pl
22 #
3 # Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3 # Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
44 #
55 # Licensed under the Apache License 2.0 (the "License"). You may not use
66 # this file except in compliance with the License. You can obtain a copy
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3131 FFC_PARAMS *ossl_dh_get0_params(DH *dh);
3232 int ossl_dh_get0_nid(const DH *dh);
3333 int ossl_dh_params_fromdata(DH *dh, const OSSL_PARAM params[]);
34 int ossl_dh_key_fromdata(DH *dh, const OSSL_PARAM params[]);
34 int ossl_dh_key_fromdata(DH *dh, const OSSL_PARAM params[], int include_private);
3535 int ossl_dh_params_todata(DH *dh, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
36 int ossl_dh_key_todata(DH *dh, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
36 int ossl_dh_key_todata(DH *dh, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
37 int include_private);
3738 DH *ossl_dh_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
3839 OSSL_LIB_CTX *libctx, const char *propq);
3940 int ossl_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
66 * https://www.openssl.org/source/license.html
77 */
88
9 #ifndef OSSL_CRYPTO_DSAERR_H
10 # define OSSL_CRYPTO_DSAERR_H
9 #ifndef OSSL_CRYPTO_DSA_H
10 # define OSSL_CRYPTO_DSA_H
1111 # pragma once
1212
1313 # include <openssl/core.h>
2929
3030 FFC_PARAMS *ossl_dsa_get0_params(DSA *dsa);
3131 int ossl_dsa_ffc_params_fromdata(DSA *dsa, const OSSL_PARAM params[]);
32 int ossl_dsa_key_fromdata(DSA *dsa, const OSSL_PARAM params[]);
32 int ossl_dsa_key_fromdata(DSA *dsa, const OSSL_PARAM params[],
33 int include_private);
3334 DSA *ossl_dsa_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
3435 OSSL_LIB_CTX *libctx, const char *propq);
3536
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
899899 int loadconfig, int mirrored);
900900 char *evp_get_global_properties_str(OSSL_LIB_CTX *libctx, int loadconfig);
901901
902 void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force);
902 void evp_md_ctx_clear_digest(EVP_MD_CTX *ctx, int force, int keep_digest);
903903
904904 /* Three possible states: */
905905 # define EVP_PKEY_STATE_UNKNOWN 0
00 /*
1 * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
3 * Licensed under the OpenSSL license (the "License"). You may not use
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
55 * in the file LICENSE in the source distribution or at
66 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
6464 int ossl_rsa_is_foreign(const RSA *rsa);
6565 RSA *ossl_rsa_dup(const RSA *rsa, int selection);
6666
67 int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
68 int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[]);
67 int ossl_rsa_todata(RSA *rsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
68 int include_private);
69 int ossl_rsa_fromdata(RSA *rsa, const OSSL_PARAM params[], int include_private);
6970 int ossl_rsa_pss_params_30_todata(const RSA_PSS_PARAMS_30 *pss,
7071 OSSL_PARAM_BLD *bld, OSSL_PARAM params[]);
7172 int ossl_rsa_pss_params_30_fromdata(RSA_PSS_PARAMS_30 *pss_params,
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4747 * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next.
4848 * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving.
4949 */
50 # define BIO_FLAGS_KTLS_TX 0x800
5150 # define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000
5251 # define BIO_FLAGS_KTLS_RX 0x2000
52 # define BIO_FLAGS_KTLS_TX 0x4000
5353
5454 /* KTLS related controls and flags */
5555 # define BIO_set_ktls_flag(b, is_tx) \
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3131 # include <sys/un.h>
3232 # include <tcp.h>
3333 # include <netdb.h>
34 # include <arpa/inet.h>
35 # include <netinet/tcp.h>
3436 # elif defined(_WIN32_WCE) && _WIN32_WCE<410
3537 # define getservbyname _masked_declaration_getservbyname
3638 # endif
00 /*
1 * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
129129
130130 #ifndef TSAN_QUALIFIER
131131
132 # define TSAN_QUALIFIER volatile
132 # ifdef OPENSSL_THREADS
133 # define TSAN_QUALIFIER volatile
134 # define TSAN_REQUIRES_LOCKING
135 # else /* OPENSSL_THREADS */
136 # define TSAN_QUALIFIER
137 # endif /* OPENSSL_THREADS */
138
133139 # define tsan_load(ptr) (*(ptr))
134140 # define tsan_store(ptr, val) (*(ptr) = (val))
135141 # define tsan_counter(ptr) ((*(ptr))++)
00 /*
11 * {- join("\n * ", @autowarntext) -}
22 *
3 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
44 *
55 * Licensed under the Apache License 2.0 (the "License"). You may not use
66 * this file except in compliance with the License. You can obtain a copy
207207 # define BIO_FLAGS_MEM_RDONLY 0x200
208208 # define BIO_FLAGS_NONCLEAR_RST 0x400
209209 # define BIO_FLAGS_IN_EOF 0x800
210
211 /* the BIO FLAGS values 0x1000 to 0x4000 are reserved for internal KTLS flags */
210212
211213 typedef union bio_addr_st BIO_ADDR;
212214 typedef struct bio_addrinfo_st BIO_ADDRINFO;
00 /*
11 * {- join("\n * ", @autowarntext) -}
22 *
3 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
44 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
55 *
66 * Licensed under the Apache License 2.0 (the "License"). You may not use
124124 size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz);
125125 size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz);
126126 size_t OPENSSL_strnlen(const char *str, size_t maxlen);
127 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlen,
127 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength,
128128 const unsigned char *buf, size_t buflen,
129129 const char sep);
130130 char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen);
00 /*
1 * Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
1818
1919 # include <openssl/opensslconf.h>
2020 # include <openssl/types.h>
21
22 # include <string.h>
2123
2224 # ifdef __cplusplus
2325 extern "C" {
15471549
15481550 # define EVP_EC_gen(curve) \
15491551 EVP_PKEY_Q_keygen(NULL, NULL, "EC", (char *)(strstr(curve, "")))
1552 /* strstr is used to enable type checking for the variadic string arg */
15501553 # define ECParameters_dup(x) ASN1_dup_of(EC_KEY, i2d_ECParameters, \
15511554 d2i_ECParameters, x)
15521555
00 /*
1 * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
800800 CRYPTO_set_mem_functions(fns->mem_fns.malloc_fn, \
801801 fns->mem_fns.realloc_fn, \
802802 fns->mem_fns.free_fn); \
803 OPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, NULL); \
803804 skip_cbs: \
804805 if (!fn(e, id)) return 0; \
805806 return 1; }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
204204 * don't accidentally reuse the values for other purposes.
205205 */
206206
207 # define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008/* Allow use of non FIPS
208 * digest in FIPS mode */
207 /* This flag has no effect from openssl-3.0 onwards */
208 # define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008
209209
210210 /*
211211 * The following PAD options are also currently ignored in 1.0.0, digest
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
7272 # define OSSL_SELF_TEST_DESC_KDF_TLS13_EXPAND "TLS13_KDF_EXPAND"
7373 # define OSSL_SELF_TEST_DESC_RNG "RNG"
7474
75 # ifdef __cplusplus
76 }
77 # endif
78
7975 void OSSL_SELF_TEST_set_callback(OSSL_LIB_CTX *libctx, OSSL_CALLBACK *cb,
8076 void *cbarg);
8177 void OSSL_SELF_TEST_get_callback(OSSL_LIB_CTX *libctx, OSSL_CALLBACK **cb,
8985 int OSSL_SELF_TEST_oncorrupt_byte(OSSL_SELF_TEST *st, unsigned char *bytes);
9086 void OSSL_SELF_TEST_onend(OSSL_SELF_TEST *st, int ret);
9187
88 # ifdef __cplusplus
89 }
90 # endif
9291 #endif /* OPENSSL_SELF_TEST_H */
00 /*
11 * {- join("\n * ", @autowarntext) -}
22 *
3 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
44 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
55 * Copyright 2005 Nokia. All rights reserved.
66 *
13071307 # define SSL_CTRL_GET_SIGNATURE_NID 132
13081308 # define SSL_CTRL_GET_TMP_KEY 133
13091309 # define SSL_CTRL_GET_NEGOTIATED_GROUP 134
1310 # define SSL_CTRL_SET_RETRY_VERIFY 136
13101311 # define SSL_CERT_SET_FIRST 1
13111312 # define SSL_CERT_SET_NEXT 2
13121313 # define SSL_CERT_SET_SERVER 3
21292130 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
21302131 # define SSL_set_max_pipelines(ssl,m) \
21312132 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_PIPELINES,m,NULL)
2133 # define SSL_set_retry_verify(ssl) \
2134 (SSL_ctrl(ssl,SSL_CTRL_SET_RETRY_VERIFY,0,NULL) > 0)
21322135
21332136 void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len);
21342137 void SSL_set_default_read_buffer_len(SSL *s, size_t len);
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
09 #include <sys/select.h>
110 #include <sys/time.h>
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- From https://tools.ietf.org/html/rfc4055#section-2.1
29
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- Taken from RFC 3279, 3 ASN.1 Module
29 -- (https://www.rfc-editor.org/rfc/rfc3279.html#section-3)
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- Taken from RFC 3279, 3 ASN.1 Module
29 -- (https://www.rfc-editor.org/rfc/rfc3279.html#section-3)
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
06
17 -- -------------------------------------------------------------------
28 -- Taken from RFC 8410, 9 ASN.1 Module
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- Taken from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
29
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- Taken from RFC 8017, Appendix C
29 -- (https://www.rfc-editor.org/rfc/rfc8017.html#appendix-C)
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 oscca OBJECT IDENTIFIER ::= { iso(1) member-body(2) cn(156) 10197 }
18
29 sm-scheme OBJECT IDENTIFIER ::= { oscca 1 }
0 -- Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
1 --
2 -- Licensed under the Apache License 2.0 (the "License"). You may not use
3 -- this file except in compliance with the License. You can obtain a copy
4 -- in the file LICENSE in the source distribution or at
5 -- https://www.openssl.org/source/license.html
6
07 -- -------------------------------------------------------------------
18 -- Taken from RFC 3370, Section 4.3.1 Triple-DES Key Wrap
29 -- (https://tools.ietf.org/html/rfc3370)
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1717 { name, OSSL_PARAM_OCTET_STRING, ITM(data) }
1818 #define ST_KAT_PARAM_UTF8STRING(name, data) \
1919 { name, OSSL_PARAM_UTF8_STRING, ITM_STR(data) }
20 #define ST_KAT_PARAM_UTF8CHAR(name, data) \
20 #define ST_KAT_PARAM_UTF8CHAR(name, data) \
2121 { name, OSSL_PARAM_UTF8_STRING, ITM(data) }
2222 #define ST_KAT_PARAM_INT(name, i) \
2323 { name, OSSL_PARAM_INTEGER, ITM(i) }
12901290 ST_KAT_PARAM_END()
12911291 };
12921292
1293 /*-
1294 * Using OSSL_PKEY_RSA_PAD_MODE_NONE directly in the expansion of the
1295 * ST_KAT_PARAM_UTF8STRING macro below causes a failure on ancient
1296 * HP/UX PA-RISC compilers.
1297 */
1298 static const char pad_mode_none[] = OSSL_PKEY_RSA_PAD_MODE_NONE;
1299
12931300 static const ST_KAT_PARAM rsa_enc_params[] = {
1294 ST_KAT_PARAM_UTF8STRING(OSSL_ASYM_CIPHER_PARAM_PAD_MODE,
1295 OSSL_PKEY_RSA_PAD_MODE_NONE),
1301 ST_KAT_PARAM_UTF8STRING(OSSL_ASYM_CIPHER_PARAM_PAD_MODE, pad_mode_none),
12961302 ST_KAT_PARAM_END()
12971303 };
12981304
00 0e22ea0cf34ef3871e30df0bc302dc29352d38001d1622ddb78a27a374b6aee8 crypto/aes/aes_cbc.c
1 cfd71afe1588c2c362b77fa7f6cddf77a517c49856df086b01391bbae3f779c4 crypto/aes/aes_core.c
1 c049a936d74100fcced225f575d46662792a6a0039777d2d4df0cf61eff90a68 crypto/aes/aes_core.c
22 3fac41ce96acb9189eac2d5571425c3ff33a34c884ae7e275e1fd3068b5fc662 crypto/aes/aes_ecb.c
33 c1e674d08683a25bc053f6233f73a0d0b3a90aafe591ff57b702c7da1582e4a5 crypto/aes/aes_local.h
44 a2466f18da5847c7d9fbced17524633c10ce024671a72f53f9c9c55b9b9923dd crypto/aes/aes_misc.c
6868 3962dfaa0142e67115ab84f7809d46d59bd122758be09a081b08b2e0d4743b2e crypto/bn/bn_asm.c
6969 3e86e6e5777499703420afade11dd23a7c6912f8eccd08da47308c7aadd7459d crypto/bn/bn_blind.c
7070 7b761d541e3b7f6a3f2b14a09b2b3836a079a845cf67a54db4853e3fd38277c6 crypto/bn/bn_const.c
71 69b864ae1f230c6c1cbc8f512031a107fcc43651aeceafcb6647b2b222a6f7f8 crypto/bn/bn_conv.c
71 58b587e20404efa408b31a88ba9c357059ced709bea78c07deb91df7b687db81 crypto/bn/bn_conv.c
7272 2893b6d03d4850d09c15959941b0759bbb50d8c20e873bed088e7cde4e15a65a crypto/bn/bn_ctx.c
7373 d94295953ab91469fe2b9da2a542b8ea11ac38551ecde8f8202b7f645c2dea16 crypto/bn/bn_dh.c
7474 a837ba52750ab30a57b6dd2fd4cf901e18a891a189b089f83add2f5dc8138eb7 crypto/bn/bn_div.c
7575 160ea2c916774d6a7f8130e0a05cad7c0a954b4726c15017b3df67e3285231f3 crypto/bn/bn_exp.c
76 617d0fd580faf72aa144f9489d6d102e2a1c4953713ac31a2b1feea4fabb2f6c crypto/bn/bn_exp2.c
76 ec2b6e3af6df473a23e7f1a8522f2554cb0eb5d34e3282458c4a66d242278434 crypto/bn/bn_exp2.c
7777 b32d83cee8c00d837a7e4fb8af3f5cf17cb8d2419302e8f5fbcf62119092e874 crypto/bn/bn_gcd.c
7878 4d6cc7ed36978247a191df1eea0120f8ee97b639ba228793dabe5a8355a1a609 crypto/bn/bn_gf2m.c
7979 081e8a6abc23599307dab3b1a92113a65e0bf8717cbc40c970c7469350bc4581 crypto/bn/bn_intern.c
9292 9d8c10645db51c3baedf57d5f0f32b67fc7eba223c192bc1ae7d87af40307e59 crypto/bn/bn_rsa_fips186_4.c
9393 704b0b4723e5c9e9bae5f3e35f9ae8ae8dca3383929e954de9e5169845abfdb2 crypto/bn/bn_shift.c
9494 622e90766b29e0d25f46474429aebda8eba2246835b9e85dc26da7cdbd49334f crypto/bn/bn_sqr.c
95 8e397a44eefa00ecb85fafc11fe8c883b3bb1572d6ac136373946d472fbe2490 crypto/bn/bn_sqrt.c
95 42c8ce944c889abcfcf089d0ad2744b7587696d8d7785efa91b3f7ec53dc062a crypto/bn/bn_sqrt.c
9696 24e62baa56e02f2db6454e10168b7c7fa7638db9221b9acda1803d43f38f36e0 crypto/bn/bn_word.c
9797 3a85d20f80c4d96b3704e58b173fc876ec81f19eac805ae2b125c138c91c86c4 crypto/bn/rsaz_exp.c
9898 affabb87861653b216e746d6c2fce5c2ac395b0ca570d439508e9f5e102ee340 crypto/bn/rsaz_exp.h
99 e18b943bfc1623597d6233421c358f3453bb0f026f28ae11cfd3b3c484c0bc4b crypto/bn/rsaz_exp_x2.c
99 46e6c75a334558586ab3610bbea0e5565273888bf60d891ae7b24251c6688aef crypto/bn/rsaz_exp_x2.c
100100 834db8ff36006e5cb53e09ca6c44290124bd23692f4341ea6563b66fcade4cea crypto/bsearch.c
101101 c39334b70e1394e43f378ae8d31b6e6dc125e4d9181e6536d38e649c4eaadb75 crypto/buffer/buffer.c
102102 23d46ae37a8d9452c0c88418d2cb8350153f8c2c6060234130a2e429da2370e0 crypto/cmac/cmac.c
103 b352903e60908dc7287051983e2068508715b4d9f3f46575540295010908bfa0 crypto/context.c
103 7f24e4937e0af857e233afbb6a7f25b09b1e5674185242a5cc8f579a45bbf1da crypto/context.c
104104 83b8912fb01bacfe0b5269c7afa69db7e1718530cce1ed27870abef1407951d6 crypto/core_algorithm.c
105105 60321d1af7bf9697d969438f6b319fbcb4fdc1a47a0b056d02b971973a8550ca crypto/core_fetch.c
106 4982395fa843f62c83b95f81e1f5622d799a2fe17108bde44cdab935b77e8ae1 crypto/core_namemap.c
106 7d090f71175f28fdc400455fdbc68340a545556d16cb1f6251ac92ebb63a38c1 crypto/core_namemap.c
107107 469e2f53b5f76cd487a60d3d4c44c8fc3a6c4d08405597ba664661ba485508d3 crypto/cpuid.c
108108 71f0fff881eb4c5505fb17662f0ea4bbff24c6858c045a013ad8f786b07da5c4 crypto/cryptlib.c
109109 a3d146afa1d66cc3bbfdc7c106f262b679bb5aecce54e8dee732ae9b3e3333db crypto/ctype.c
115115 499513b3ad386fe694c4e04b3c8a9fd4c4e18fc44bb6c4f94d6bf2d9362a3a5a crypto/des/ncbc_enc.c
116116 61926e30dd940616e80936d1c94c5f522daf0d475fb3a40a9e589e78f322901e crypto/des/set_key.c
117117 8344811b14d151f6cd40a7bc45c8f4a1106252b119c1d5e6a589a023f39b107d crypto/des/spr.h
118 0209b1ff430e2c237bf96e2e283c24df4b6708014c5a7005b295c28733d2a8ce crypto/dh/dh_backend.c
118 816472a54c273906d0a2b58650e0b9d28cc2c8023d120f0d77160f1fe34c4ca3 crypto/dh/dh_backend.c
119119 832e5a1caf9cb0dacfd937fc59252aaac7c5c1bf0ae1a9ebf3c3af6e59dcf4c0 crypto/dh/dh_check.c
120120 7838e9a35870b0fbcba0aff2f52a2439f64d026e9922bce6e5978c2f22c51120 crypto/dh/dh_gen.c
121121 70f4cf3485a38cd7d22aa3e965bfe950905f8efec1622e832592a6728498fd78 crypto/dh/dh_group_params.c
122122 7809cbfd5570db17dcb4bd8f0cf9c5f94337096d39da453d0624c08f071e809f crypto/dh/dh_kdf.c
123 c71b8691416a61c306ea0973ca22570a56d3e9e93618a3eb2fd7b9d9a789ca44 crypto/dh/dh_key.c
123 0afa7dd237f9b21b0cfb0de10505facd57eb07ded905d888d43a1de2356d4002 crypto/dh/dh_key.c
124124 b0046b2c4e1d74ff4e93f2486a00f63728909b8a75cbdd29b9100e607f97995c crypto/dh/dh_lib.c
125125 8300775d88db0a1aa26a77eb49d6c4f7252e7fee69e1440de4c40edadc9da044 crypto/dh/dh_local.h
126 27d0ea795bb7f571ba37b7460eee63608b9089a95337491c0980b91135563e15 crypto/dsa/dsa_backend.c
126 bbcf4fc3067ac462a27d7277973180b7dc140df9262a686c7fbe4318ca01f7b8 crypto/dsa/dsa_backend.c
127127 b9c5992089203123c3fae46e39bb4d05e19854087bca7a30ad1f82a3505deec7 crypto/dsa/dsa_check.c
128128 ae727bf6319eb57e682de35d75ea357921987953b3688365c710e7fba51c7c58 crypto/dsa/dsa_gen.c
129129 b1de1624e590dbf76f76953802ff162cc8de7c5e2eaba897313c866424d6902b crypto/dsa/dsa_key.c
166166 8cfd0dcfb5acbf6105691a2d5e2826dba1ff3906707bc9dd6ff9bffcc306468f crypto/ec/ec_cvt.c
167167 28726bc957ea821639b1023e5bff0e77ced61bae31f96c165e33aadfe0bc5c9a crypto/ec/ec_key.c
168168 7e40fc646863e0675bbb90f075b809f61bdf0600d8095c8366858d9533ab7700 crypto/ec/ec_kmeth.c
169 2db28a620fa62889c816dca25bb1153c99af2e8604beb3b1655495da96f2c965 crypto/ec/ec_lib.c
169 074a5345ea71ff3fdfb8e0be360391a7640719f1a8a4eae8580c8f02e57af880 crypto/ec/ec_lib.c
170170 a8a4690e42b4af60aad822aa8b16196df337906af53ea4db926707f7b596ff27 crypto/ec/ec_local.h
171171 fa901b996eb0e460359cd470843bdb03af7a77a2f1136c5e1d30daef70f3e4d2 crypto/ec/ec_mult.c
172172 129c6b42417bfcf582f4a959cfd65433e6f85b158274f4fa38f9c62615ac9166 crypto/ec/ec_oct.c
185185 22c44f561ab42d1bd7fd3a3c538ebaba375a704f98056b035e7949d73963c580 crypto/ec/ecx_key.c
186186 28abc295dad8888b5482eb61d31cd78dd80545ecb67dc6f9446a36deb8c40a5e crypto/evp/asymcipher.c
187187 0e75a058dcbbb62cfe39fec6c4a85385dc1a8fce794e4278ce6cebb29763b82b crypto/evp/dh_support.c
188 e696c10cc2ed2fc5552e659b343af751b9edc3b4dbce1a2108d21e8b10424657 crypto/evp/digest.c
188 7fca5ec7c5723b799a7d84d5803071b8f495511e1baf89d430e6800a5228cdad crypto/evp/digest.c
189189 5e2c5d865029ae86855f15e162360d091f28ca0d4c67260700c90aa25faf308b crypto/evp/ec_support.c
190 37b5e0bdb30a24c925a26f818828fd3b4ab4c1725f84797260556c0f47f2b76d crypto/evp/evp_enc.c
191 d8162b57e041e83da55efe6f073d156a00b8d7a3b2fb7782b05295f2c0ea3c14 crypto/evp/evp_fetch.c
190 2724dc804304135bc874bd305e14b811169a9e4a62176220a0d5e83f152c2546 crypto/evp/evp_enc.c
191 0cd2765bf33d998f96d6e8193b2bf27293bcc6a37b7bef7dfd6ec54952ad3c8f crypto/evp/evp_fetch.c
192192 029df8bb80a2fb45c22765234b9041ffce82735108e0b11580fd3fbd805362dd crypto/evp/evp_lib.c
193193 9ac3d97d756ec008db16dd1952115b551f32b2d0590d9a85e1c87d1c78620257 crypto/evp/evp_local.h
194194 e822c16fc4dc30f2c86e8598c721a9ddfe46d318ce78f4e8e883cdcf8b936221 crypto/evp/evp_rand.c
195195 2a128617ec0178e9eeacbe41d75a5530755f41ea524cd124607543cf73456a0c crypto/evp/evp_utils.c
196 5496cf34a1643923ff434e4ae16ee203a626b36685e98201dec30547857847d8 crypto/evp/exchange.c
196 06442eff7fd25971d247fa3a769c6df56f5eb8cdedbd764cd2daa7e0c7ab3f2f crypto/evp/exchange.c
197197 a3164e3247e2a38f4f9a20db463779b5260e4e6639ac8eec6e960b265fc8cce5 crypto/evp/kdf_lib.c
198198 1d72f5506984df1df8606e8c7045f041cf517223e2e1b50c4da8ba8bf1c6c186 crypto/evp/kdf_meth.c
199199 38715a14f202e7d24602e5cc19d2f78abbd9f5fa3dde8d7b2bfded907690e18f crypto/evp/kem.c
200 787105780e2aa625bfedfbfd7167be16f743883d02a897969695ad8e637298af crypto/evp/keymgmt_lib.c
200 724d2ac784d6f22cb0a382abc23ac0f2d76f2f6831fcd09e101f6f27d0c3e4ed crypto/evp/keymgmt_lib.c
201201 3d0a2c5fea0d9bb01a09e1eabc041e3bc76ba4ee90bc0af54ef414e7ca3a531f crypto/evp/keymgmt_meth.c
202202 e1a052839b8b70dca20dbac1282d61abd1c415bf4fb6afb56b811e8770d8a2e1 crypto/evp/m_sigver.c
203203 5b8b0bcd4b720b66ce6bc54090ec333891126bb7f6cce4502daf2333668c3db9 crypto/evp/mac_lib.c
204204 e7e8eb5683cd3fbd409df888020dc353b65ac291361829cc4131d5bc86c9fcb3 crypto/evp/mac_meth.c
205205 b976077a1f880768f2f0a1c996a53dfdd363605e4977c56fb37e9c1f84f35aa6 crypto/evp/p_lib.c
206206 3b4228b92eebd04616ecc3ee58684095313dd5ffd1b43cf698a7d6c202cb4622 crypto/evp/pmeth_check.c
207 bbce11755bcc5ba2ee8e9c1eb95905447136f614fdc2b0f74cf785fe81ead6a5 crypto/evp/pmeth_gn.c
207 1f0e9e94e9b0ad322956521b438b78d44cfcd8eb974e8921d05f9e21ba1c05cf crypto/evp/pmeth_gn.c
208208 76511fba789089a50ef87774817a5482c33633a76a94ecf7b6e8eb915585575d crypto/evp/pmeth_lib.c
209209 f3a5cbbccb1078cf1fafd74c4caa9f30827081832fbe6dfa5579b17ef809776c crypto/evp/signature.c
210210 b06cb8fd4bd95aae1f66e1e145269c82169257f1a60ef0f78f80a3d4c5131fac crypto/ex_data.c
211 00ca3b72cd56308aabb2826b6a400c675526afa7efca052d39c74b2ac6d137d8 crypto/ffc/ffc_backend.c
211 324feb067d0f8deb4334f3e6518f570114cb388c85b24f9232bd931a64ff0a9e crypto/ffc/ffc_backend.c
212212 ead786b4f5689ab69d6cca5d49e513e0f90cb558b67e6c5898255f2671f1393d crypto/ffc/ffc_dh.c
213213 82abf1f9645336b7dff5e3fa153899280ecaa27b3dad50e6a9ba94d871961888 crypto/ffc/ffc_key_generate.c
214214 084ae8e68a9df5785376bb961a998036336ed13092ffd1c4258b56e6a7e0478b crypto/ffc/ffc_key_validate.c
218218 0a4fc92e408b0562cf95c480df93a9907a318a2c92356642903a5d50ed04fd88 crypto/hmac/hmac.c
219219 0395c1b0834f2f4a0ca1756385f4dc1a4ef6fb925b2db3743df7f57256c5166f crypto/hmac/hmac_local.h
220220 f897493b50f4e9dd4cacb2a7accda6683c10ece602641874cdff1dac7128a751 crypto/initthread.c
221 e82f2213ac9438af20a2b19743c6c790d841acf89429868c9d1770f3f06a597a crypto/lhash/lhash.c
222 95ceca6a32b1d8a2e3a172121e7b3379267867a8c1d2b5cf2c1fbb16d1f8424c crypto/lhash/lhash_local.h
221 f0782ee92b6ebf5a0e66b970ecfbd9c9c6fc4a35ccd055967fbb402577c234ab crypto/lhash/lhash.c
222 73d63f91fbaba47649231636c5afdf76d049a46436fde9fbb2e107cf16bb879e crypto/lhash/lhash_local.h
223223 f866aafae928db1b439ac950dc90744a2397dfe222672fe68b3798396190c8b0 crypto/mem_clr.c
224224 183bdca6f855182d7d2c78a5c961b34283f85ea69ac828b700605ee82546397d crypto/modes/asm/aes-gcm-armv8_64.pl
225225 1d686af304f94743038f916125effcb51790c025f3165d8d37b526bbeee781f0 crypto/modes/asm/aesni-gcm-x86_64.pl
242242 bdf25257b15eca206be4d950d2dd807ca5f058f91f54edbd7a0d312ed83eef8e crypto/modes/ofb128.c
243243 e55a816c356b2d526bc6e40c8b81afa02576e4d44c7d7b6bbe444fb8b01aad41 crypto/modes/wrap128.c
244244 608a04f387be2a509b4d4ad414b7015ab833e56b85020e692e193160f36883a2 crypto/modes/xts128.c
245 ca8f63ee71797f51c2bf5629190897306b3308882feb3d64c982239f18e8b738 crypto/o_str.c
245 ecb4a6f28a0acdb00cb654612e26cd4c825d9f83b15d42cefc1ccd47b00f8eb0 crypto/o_str.c
246246 7b8d9f5dfe00460df5fbcfd4a5f2f36128020ebd2ced85ff5071b91f98740b2e crypto/packet.c
247247 cc4483ec9ba7a30908e3a433a6817e2f211d4c1f69c206e6bae24bbd39a68281 crypto/param_build.c
248248 c2fe815fb3fd5efe9a6544cae55f9469063a0f6fb728361737b927f6182ae0bb crypto/param_build_set.c
250250 4f2a8c9acf5898fdc1e4bf98813049947221cd9a1db04faaa490250591f54cb4 crypto/params_dup.c
251251 a0097ff2da8955fe15ba204cb54f3fd48a06f846e2b9826f507b26acf65715c3 crypto/params_from_text.c
252252 2140778d5f35e503e22b173736e18ff84406f6657463e8ff9e7b91a78aa686d3 crypto/property/defn_cache.c
253 b09bfc2cdde7ab703b54630a67cc8d01ca92af402be246e5a9f82d176abd9442 crypto/property/property.c
253 9153343b26e5c2c4f6009d37a12d6af85681ed0c7d3f58de2ace44dfd789a59b crypto/property/property.c
254254 a2c69527b60692a8b07cfdfe7e75f654daa092411d5de5e02b446a4ef3752855 crypto/property/property_local.h
255255 c3217b73871d93d81ab9f15e9f1fc37ea609bbe4bbc0c1b84ec62a99c91f6756 crypto/property/property_parse.c
256256 a7cefda6a117550e2c76e0f307565ce1e11640b11ba10c80e469a837fd1212a3 crypto/property/property_query.c
257257 065698c8d88a5facc0cbc02a3bd0c642c94687a8c5dd79901c942138b406067d crypto/property/property_string.c
258 c56fb722699e1148dc392bad8069292e6521e7498c8aa9572661af118ff59e16 crypto/provider_core.c
258 01d2e5be52d94efdff4329281b3609c7fa57162ab6143492c380c96952df1396 crypto/provider_core.c
259259 d0af10d4091b2032aac1b7db80f8c2e14fa7176592716b25b9437ab6b53c0a89 crypto/provider_local.h
260260 5ba2e1c74ddcd0453d02e32612299d1eef18eff8493a7606c15d0dc3738ad1d9 crypto/provider_predefined.c
261 5d16318d3a36b06145af74afa3523109768990a33457c81895c7ab8a830654f8 crypto/rand/rand_lib.c
261 4e6b7d1d8278067c18bcb5e3ac9b7fe7e9b1d0d03bc5a276275483f541d1a12c crypto/rand/rand_lib.c
262262 fd03b9bb2c23470fa40880ed3bf9847bb17d50592101a78c0ad7a0f121209788 crypto/rand/rand_local.h
263263 f0c8792a99132e0b9c027cfa7370f45594a115934cdc9e8f23bdd64abecaf7fd crypto/rsa/rsa_acvp_test_params.c
264 8b93871f1f0392704d29028b8c93281be62cf02d0f79f9831bdabcd7a378df5b crypto/rsa/rsa_backend.c
264 054f8e32eabb218d219a5fa8cb40f6e76bc5a395d03e4f83c5f2b703a5a476b9 crypto/rsa/rsa_backend.c
265265 38a102cd1da1f6ca5a46e6a22f018237964336274385f5c70cbedcaa6997647e crypto/rsa/rsa_chk.c
266266 e32cfa04221a2a3ea33f7bcb93ee51b84cbeba97e94c1fbf6e420b24f97fc9ce crypto/rsa/rsa_crpt.c
267267 21794dcb6bfebcf9a14d4f8aa7fab8f745b595433b388b55f46ba6e615d90f98 crypto/rsa/rsa_gen.c
270270 cf0b75cd54b61b9b9a290ef18d0ddce9fb26a029a54eb3f720d9b25188440f00 crypto/rsa/rsa_mp_names.c
271271 5c60f6e05db82e13178d805deb1947b8eee4a905e6e77523d3b288da70a46bb5 crypto/rsa/rsa_none.c
272272 33de2accc3af530fd0a4758eb83d5e1d994bf49bac4512b01387dbae656e1a7d crypto/rsa/rsa_oaep.c
273 a2fd2e4e31ec53d01a575ccaf03bad5a270412ff66804cf0b5fa40492b89181d crypto/rsa/rsa_ossl.c
273 1b58825809bb9c5fc9e876d71e5b787b08f034eaee3c30eb20d30a1d889bdbd5 crypto/rsa/rsa_ossl.c
274274 be3f39c1fcb777d6c0122061f9ef735d10a6bee95d67fcc1ca6ae2a664022d2b crypto/rsa/rsa_pk1.c
275275 174a42e156be48927fe6d6bf0d95575619b8e643a99761275bff933bc3449722 crypto/rsa/rsa_pss.c
276276 bf6d300b7e7e9e512a47c5bd1f8713806ae3033a140d83dfae4a16ad58d11170 crypto/rsa/rsa_schemes.c
343343 e69b2b20fb415e24b970941c84a62b752b5d0175bc68126e467f7cc970495504 include/crypto/cryptlib.h
344344 5ee1ea30382bef9869f29b6610665ca304f3b9cf3653746a2d02c64b1a24f103 include/crypto/ctype.h
345345 89693e0a7528a9574e1d2f80644b29e3b895d3684111dd07c18cc5bed28b45b7 include/crypto/des_platform.h
346 830da1513661794e979f7cca2bba1792224e3b3d20d4f10f6f5c6566d9b7e723 include/crypto/dh.h
347 7ddd70f02371c7bd190414369d2bbe7c9c6d2de085dfe1e3eab0c4082f803ca1 include/crypto/dsa.h
346 daf508bb7ed5783f1c8c622f0c230e179244dd3f584e1223a19ab95930fbcb4f include/crypto/dh.h
347 20d99c9a740e4d7d67e23fa4ae4c6a39d114e486c66ad41b65d91a8244cd1dea include/crypto/dsa.h
348348 2ea47c059e84ce9d14cc31f4faf45f64d631de9e2937aa1d7a83de5571c63574 include/crypto/ec.h
349349 edbfae8720502a4708983b60eac72aa04f031059f197ada31627cb5e72812858 include/crypto/ecx.h
350 782ea27154525789cd49afd36a8056457dfab4ea662481b502363cc0a55ed34e include/crypto/evp.h
350 cca363846ac7ef1f6196e5ac858d03bf78545af2de4f83a0150575c037813e4b include/crypto/evp.h
351351 bbe5e52d84e65449a13e42cd2d6adce59b8ed6e73d6950917aa77dc1f3f5dff6 include/crypto/lhash.h
352352 162812058c69f65a824906193057cd3edeabc22f51a4220aea7cb9064379a9b6 include/crypto/md32_common.h
353353 f12bfc145290444bcc7bf408874bded348e742443c145b8b5bc70ae558d96c31 include/crypto/modes.h
354354 0e4472433ca4008aa4fc9234761be70f323a22a4519bb9d62728dc001d606f04 include/crypto/rand.h
355355 90930fc8788d6e04e57829346e0405293ac7a678c3cef23d0692c742e9586d09 include/crypto/rand_pool.h
356 bd5ce686c97a8a3a0e3d7ca1e4f16706fd51df5da9673169303a4428d62da233 include/crypto/rsa.h
356 306abf9d327a9e63fff2cdef730275abc4d2781254a032b1f370f3428eb5a2ef include/crypto/rsa.h
357357 32f0149ab1d82fddbdfbbc44e3078b4a4cc6936d35187e0f8d02cc0bc19f2401 include/crypto/security_bits.h
358358 0f743762f646656b5480648c05632575fe8acc7506460c63e0fcdf42cf20c08a include/crypto/sha.h
359359 7676b02824b2d68df6bddeb251e9b8a8fa2e35a95dad9a7ebeca53f9ab8d2dad include/crypto/sparse_array.h
360360 5bfeea62d21b7cb43d9a819c5cd2800f02ea019687a8331abf313d615889ad37 include/crypto/types.h
361 a1778b610a244f49317a09e1e6c78b5fb68bc6d003ffdea0f6eefe5733ee5b5f include/internal/bio.h
361 782a83d4e489fd865e2768a20bfa31e78c2071fd0ceeb9eb077276ae2bcc6590 include/internal/bio.h
362362 92aacb3e49288f91b44f97e41933e88fe455706e1dd21a365683c2ab545db131 include/internal/constant_time.h
363363 71ddae419297069056065ab71f32fe88b09ddbe4db2200a759fedd8ad4349628 include/internal/core.h
364364 d7ddeab97434a21cb2cad1935a3cb130f6cd0b3c75322463d431c5eab3ab1ae1 include/internal/cryptlib.h
382382 24f41a1985fa305833c3f58030c494d2563d15fc922cdf3eeb6a7ea8c135a880 include/internal/symhacks.h
383383 640cc6a2aae208073a7f495c08b4c5006a69e8ac1c2d9aaaafd56b0e74d5f859 include/internal/thread_once.h
384384 415b725d7f949a6191ab7bb30b48931bafc01c7aa93607e529fabbc853a4ddc5 include/internal/tlsgroups.h
385 b24938409313384024524cbde837690d83119bcb70fb289b38cb7efa8e082852 include/internal/tsan_assist.h
385 fc0f9199487ef278b9fd317d1572db3e3fb95e182055f0e49c4d8faf78ed7dd2 include/internal/tsan_assist.h
386386 2b38fb6e65d549aca3b2c76907daf67124f395251c0261dec26faa54da8d6d73 include/openssl/aes.h
387387 98aa2fc5eae9ef2a36d3d0053212696d58893baa083fa1fcf720660fb4bc0a9f include/openssl/asn1.h.in
388388 d4733dcd490b3a2554eaf859d1ea964fe76f7d24f78e42be1094bdad6dee7429 include/openssl/asn1err.h
401401 df5e60af861665675e4a00d40d15e36884f940e3379c7b45c9f717eaf1942697 include/openssl/core.h
402402 00110e80b9b4f621c604ea99f05e7a75d3db4721fc2779224e6fa7e52f06e345 include/openssl/core_dispatch.h
403403 cbd9d7855ca3ba4240207fc025c22bbfef7411116446ff63511e336a0559bed0 include/openssl/core_names.h
404 d165f5c61bfe17ba366a3ba94afb30d3c8ce6b21e9cff59a15f3622f2654ae49 include/openssl/crypto.h.in
404 8880892256a4d2dd7a9be91f23518f71e5037dbd377cd41bdb4c1f3cb3c7ee2d include/openssl/crypto.h.in
405405 1d1697bd3e35920ff9eaec23c29472d727a7fc4d108150957f41f6f5ecf80f1a include/openssl/cryptoerr.h
406406 bbc82260cbcadd406091f39b9e3b5ea63146d9a4822623ead16fa12c43ab9fc6 include/openssl/cryptoerr_legacy.h
407407 fa3e6b6c2e6222424b9cd7005e3c5499a2334c831cd5d6a29256ce945be8cb1d include/openssl/des.h
411411 335eb40a33cd1e95e7783bda2d031ec2bcf02cff8aa804ba3484d1354452b7ea include/openssl/dsaerr.h
412412 41bf49e64e1c341a8c17778147ddeba35e88dfd7ff131db6210e801ef25a8fd5 include/openssl/e_os2.h
413413 bc9ec2be442a4f49980ba2c63c8f0da701de1f6e23d7db35d781658f833dd7b9 include/openssl/ebcdic.h
414 0ad64e592528898c84f2a16e2a03749774b908b3a9944a7f9aa54b1f95094dfb include/openssl/ec.h
414 33b6321d1c6b7b1621198346946401bb81472054aa236b03c6f22f247248d2ad include/openssl/ec.h
415415 cbbf74efc7fdb020f06840c856ad7fe97553944f4cc3c197fbb004de38158048 include/openssl/ecerr.h
416416 61c76ee3f12ed0e42503a56421ca00f1cb9a0f4caa5f9c4421c374bcd45917d7 include/openssl/encoder.h
417417 69dd983f45b8ccd551f084796519446552963a18c52b70470d978b597c81b2dc include/openssl/encodererr.h
440440 c1015b77c444a3816d2ea7ad770f1c3b79a1e54887930af6dd662895701f3323 include/openssl/rsa.h
441441 2f339ba2f22b8faa406692289a6e51fdbbb04b03f85cf3ca849835e58211ad23 include/openssl/rsaerr.h
442442 6586f2187991731835353de0ffad0b6b57609b495e53d0f32644491ece629eb2 include/openssl/safestack.h.in
443 2702c0c5b8df31f764aa97d44c8a2b00b4b91c3482fd8ca5e1c5c91dfc61dc58 include/openssl/self_test.h
443 af5cc56fb31161ccd87cf925f3d3f22119dfbca78bc39a2e2d65d78bfcf0f0c6 include/openssl/self_test.h
444444 2964274ab32b1ba8578a06b06663db2eda4317ae806369271d889176bb5a7d04 include/openssl/sha.h
445445 c169a015d7be52b7b99dd41c418a48d97e52ad21687c39c512a83a7c3f3ddb70 include/openssl/stack.h
446446 22d7584ad609e30e818b54dca1dfae8dea38913fffedd25cd540c550372fb9a6 include/openssl/symhacks.h
484484 a4dc9bf2d77e34175737b7b8d28fbe90815ac0e2904e3ac2d9e2a271f345ef20 providers/fips/fipsprov.c
485485 fdbaf748044ce54f13e673b92db876e32436e4d5644f443cc43d063112a89676 providers/fips/self_test.c
486486 f822a03138e8b83ccaa910b89d72f31691da6778bf6638181f993ec7ae1167e3 providers/fips/self_test.h
487 7a23cc81ca7542325634891d1982c70e68a27914b088a51ca60249d54031bfc2 providers/fips/self_test_data.inc
487 5b3379a3d382c4dad37841dbd58b77ed5ff712b0a37c485771b828fa9b39c351 providers/fips/self_test_data.inc
488488 2f4f23ebc2c7ed5ef71c98ca71f06b639112a1dea04784c46af58083482c150f providers/fips/self_test_kats.c
489489 f054b24ea53ad5db41dd7f37f20f42166ed68b832121a94858cb0173b1aaeb1d providers/implementations/asymciphers/rsa_enc.c
490490 4db1826ecce8b60cb641bcd7a61430ec8cef73d2fe3cbc06aa33526afe1c954a providers/implementations/ciphers/cipher_aes.c
514514 f358c4121a8a223e2c6cf009fd28b8a195520279016462890214e8858880f632 providers/implementations/ciphers/cipher_aes_xts_hw.c
515515 f2e7404005e0602c4cc90b49b7af7453aa5b8644720ca1028d93e78bc28a7c09 providers/implementations/ciphers/cipher_cts.c
516516 74640ce402acc704af72e055fb7f27e6aa8efd417babc56f710478e571d8631c providers/implementations/ciphers/cipher_cts.h
517 06d8f86ec724075e7f72dabfb675b5c85a93c01997e4142fbaa8482e617f4ae5 providers/implementations/ciphers/cipher_tdes.c
517 fcc3bb0637864252402aaa9d543209909df9a39611127f777b168bc888498dc0 providers/implementations/ciphers/cipher_tdes.c
518518 77709f7fc3f7c08986cd4f0ebf2ef6e44bacb975c1483ef444b3cf5e5071f9d6 providers/implementations/ciphers/cipher_tdes.h
519519 9e07260067083c76d26eb0dd8a8bb4a8dac678812644ff88951a0661be70d9fd providers/implementations/ciphers/cipher_tdes_common.c
520520 50645122f08ef4891cd96cace833bd550be7f5278ab785515fd61fe8993c8c25 providers/implementations/ciphers/cipher_tdes_hw.c
529529 39b47b6ef9d71852964c26e07ef0e9b23f04c7493b1b16ba7c3dba7074b6b70d providers/implementations/digests/digestcommon.c
530530 80551b53302d95faea257df3edbdbd02d48427ce42da2c4335f998456400d057 providers/implementations/digests/sha2_prov.c
531531 de342d04be6af69037922d5c97bdc40c0c27f6740636e72786a765d0d8ad9173 providers/implementations/digests/sha3_prov.c
532 007d431b3cdb53374c5f5aaef2fcb557e213c23f26e55ebdd32b53527f3f4826 providers/implementations/exchange/dh_exch.c
532 b5f94d597df72ca58486c59b2a70b4057d13f09528f861ed41a84b7125b54a82 providers/implementations/exchange/dh_exch.c
533533 9c46dc0d859875fcc0bc3d61a7b610cd3520b1bf63718775c1124f54a1fe5f24 providers/implementations/exchange/ecdh_exch.c
534534 9bf87b8429398a6465c7e9f749a33b84974303a458736b56f3359b30726d3969 providers/implementations/exchange/ecx_exch.c
535535 06ba83a8a8235bcdbda56f82b017cb19361469fe47c23cc6218a7e9b88ae6513 providers/implementations/exchange/kdf_exch.c
553553 3c46ec0e14be09a133d709c3a1c3d5ab05a4f1ed5385c3e7a1afb2f0ee47ef7a providers/implementations/kdfs/tls1_prf.c
554554 27bb6ee5e2d00c545635c0c29402b10e74a1831adbc9800c159cbe04f2bfa2f7 providers/implementations/kdfs/x942kdf.c
555555 f419a9f6b17cfba1543a3690326188ac8335db66807c58de211a3d69e18f7d4d providers/implementations/kem/rsa_kem.c
556 6878218c16d5c9c308a414af67790e11912ced638ba9e64668912ec98ca20d9d providers/implementations/keymgmt/dh_kmgmt.c
557 4f9e8263d529f619766be73a11223b8a3dfaf46b506c17b44d8a1cd9d2eaee54 providers/implementations/keymgmt/dsa_kmgmt.c
556 7628cfd7c88f37faa557c671a78ff56266691d64075104a514a28cb6fb9a6816 providers/implementations/keymgmt/dh_kmgmt.c
557 68d5cad49334ad0ee6948329b3784bb43eede84c3bc59ff22cbbe7aed9292672 providers/implementations/keymgmt/dsa_kmgmt.c
558558 3e2798d299d6571c973fc75468e2ac025b7c893ae2f15f14e057430325622a69 providers/implementations/keymgmt/ec_kmgmt.c
559559 258ae17bb2dd87ed1511a8eb3fe99eed9b77f5c2f757215ff6b3d0e8791fc251 providers/implementations/keymgmt/ec_kmgmt_imexport.inc
560 085e1cf54941fa1c1e423b4a75b820945a1c05d1c347d4910d9a772b8c9d9f3a providers/implementations/keymgmt/ecx_kmgmt.c
560 8871260c1b05832efa8363e5546210004da1683fee74da6c749ebba802b40f2b providers/implementations/keymgmt/ecx_kmgmt.c
561561 053a2be39a87f50b877ebdbbf799cf5faf8b2de33b04311d819d212ee1ea329b providers/implementations/keymgmt/kdf_legacy_kmgmt.c
562562 260c560930c5aca61225a40ed49dfbb905f2b1fa50728d1388e946358f9d5e18 providers/implementations/keymgmt/mac_legacy_kmgmt.c
563 9c16e76419aeb422d189ff7c5bf9a07f37abb54043dd47e48d450d68329de933 providers/implementations/keymgmt/rsa_kmgmt.c
563 d469be20a6d1a3744c1a2d5c26cb3b8ff6339a2242d4ef6e5ed9531551f717c1 providers/implementations/keymgmt/rsa_kmgmt.c
564564 79da66d4b696388d7eab6b2126bccc88908915813d79c4305b8b4d545a500469 providers/implementations/macs/cmac_prov.c
565565 41464d1e640434bb3ff9998f093829d5e2c1963d68033dca7d31e5ab75365fb1 providers/implementations/macs/gmac_prov.c
566566 282c1065f18c87073529ed1bdc2c0b3a1967701728084de6632ddc72c671d209 providers/implementations/macs/hmac_prov.c
567567 aa7ba1d39ea4e3347294eb50b4dfcb895ef1a22bd6117d3b076a74e9ff11c242 providers/implementations/macs/kmac_prov.c
568568 bf30274dd6b528ae913984775bd8f29c6c48c0ef06d464d0f738217727b7aa5c providers/implementations/rands/crngt.c
569 f8d24c882fda71c117a00bf4e6c7ffb6b88946c16a816249a5a7499dbdff712d providers/implementations/rands/drbg.c
569 c7236e6e2e8adce14f8206da0ceef63c7974d4ba1a7dd71b94fa100cac6b46ba providers/implementations/rands/drbg.c
570570 b1e7a0b2610aaab5800af7ede0df13a184f4a321a4084652cdb509357c55783b providers/implementations/rands/drbg_ctr.c
571571 a05adc3f6d9d6f948e5ead75f0522ed3164cb5b2d301169242f3cb97c4a7fac3 providers/implementations/rands/drbg_hash.c
572572 0876dfae991028c569631938946e458e6829cacf4cfb673d2b144ae50a3160bb providers/implementations/rands/drbg_hmac.c
0 a59d74b7f6b55bd9d58d55876562fdd00d28dbb3c942ae80ccea859da4624f1d providers/fips-sources.checksums
0 0223646a9f0ba5ca3bd4dc320fe5a647c8b4d48cc1e273b09acceeabc035c19e providers/fips-sources.checksums
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1818 #include "cipher_tdes.h"
1919 #include "prov/implementations.h"
2020
21 /*
22 * NOTE: ECB mode does not use an IV - but existing test code is setting
23 * an IV. Fixing this could potentially make applications break.
24 */
2521 /* ossl_tdes_ede3_ecb_functions */
26 IMPLEMENT_tdes_cipher(ede3, EDE3, ecb, ECB, TDES_FLAGS, 64*3, 64, 64, block);
22 IMPLEMENT_tdes_cipher(ede3, EDE3, ecb, ECB, TDES_FLAGS, 64*3, 64, 0, block);
2723 /* ossl_tdes_ede3_cbc_functions */
2824 IMPLEMENT_tdes_cipher(ede3, EDE3, cbc, CBC, TDES_FLAGS, 64*3, 64, 64, block);
00 /*
1 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2525 IMPLEMENT_tdes_cipher(ede3, EDE3, cfb8, CFB, TDES_FLAGS, 64*3, 8, 64, stream);
2626
2727 /* ossl_tdes_ede2_ecb_functions */
28 IMPLEMENT_tdes_cipher(ede2, EDE2, ecb, ECB, TDES_FLAGS, 64*2, 64, 64, block);
28 IMPLEMENT_tdes_cipher(ede2, EDE2, ecb, ECB, TDES_FLAGS, 64*2, 64, 0, block);
2929 /* ossl_tdes_ede2_cbc_functions */
3030 IMPLEMENT_tdes_cipher(ede2, EDE2, cbc, CBC, TDES_FLAGS, 64*2, 64, 64, block);
3131 /* ossl_tdes_ede2_ofb_functions */
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
203203 if (!ok)
204204 goto next;
205205
206 ok = 0; /* Assume that we fail */
207
206 ok = 0; /* Assume that we fail */
207
208 ERR_set_mark();
208209 if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
209210 derp = der;
210211 if (ctx->desc->d2i_PKCS8 != NULL) {
211212 key = ctx->desc->d2i_PKCS8(NULL, &derp, der_len, ctx);
212 if (ctx->flag_fatal)
213 if (ctx->flag_fatal) {
214 ERR_clear_last_mark();
213215 goto end;
216 }
214217 } else if (ctx->desc->d2i_private_key != NULL) {
215218 key = ctx->desc->d2i_private_key(NULL, &derp, der_len);
216219 }
217 if (key == NULL && ctx->selection != 0)
220 if (key == NULL && ctx->selection != 0) {
221 ERR_clear_last_mark();
218222 goto next;
223 }
219224 }
220225 if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
221226 derp = der;
223228 key = ctx->desc->d2i_PUBKEY(NULL, &derp, der_len);
224229 else
225230 key = ctx->desc->d2i_public_key(NULL, &derp, der_len);
226 if (key == NULL && ctx->selection != 0)
231 if (key == NULL && ctx->selection != 0) {
232 ERR_clear_last_mark();
227233 goto next;
234 }
228235 }
229236 if (key == NULL && (selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) {
230237 derp = der;
231238 if (ctx->desc->d2i_key_params != NULL)
232239 key = ctx->desc->d2i_key_params(NULL, &derp, der_len);
233 if (key == NULL && ctx->selection != 0)
240 if (key == NULL && ctx->selection != 0) {
241 ERR_clear_last_mark();
234242 goto next;
235 }
243 }
244 }
245 if (key == NULL)
246 ERR_clear_last_mark();
247 else
248 ERR_pop_to_mark();
236249
237250 /*
238251 * Last minute check to see if this was the correct type of key. This
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
6767 PKCS8_PRIV_KEY_INFO *p8inf = NULL;
6868 const X509_ALGOR *alg = NULL;
6969 BIO *in = ossl_bio_new_from_core_bio(ctx->provctx, cin);
70 int ok = (asn1_d2i_read_bio(in, &mem) >= 0);
70 int ok = 0;
7171
72 if (in == NULL)
73 return 0;
74
75 ok = (asn1_d2i_read_bio(in, &mem) >= 0);
7276 BIO_free(in);
7377
7478 /* We return "empty handed". This is not an error. */
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
9191 int ispub = -1;
9292 void *key = NULL;
9393 int ok = 0;
94
95 if (in == NULL)
96 return 0;
9497
9598 if (BIO_read(in, hdr_buf, 16) != 16) {
9699 ERR_raise(ERR_LIB_PEM, PEM_R_KEYBLOB_TOO_SHORT);
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3232 unsigned char **data, long *len)
3333 {
3434 BIO *in = ossl_bio_new_from_core_bio(provctx, cin);
35 int ok = (PEM_read_bio(in, pem_name, pem_header, data, len) > 0);
35 int ok;
36
37 if (in == NULL)
38 return 0;
39 ok = (PEM_read_bio(in, pem_name, pem_header, data, len) > 0);
3640
3741 BIO_free(in);
3842 return ok;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
8686 BIO *in = ossl_bio_new_from_core_bio(ctx->provctx, cin);
8787 void *key = NULL;
8888 int ok = 0;
89
90 if (in == NULL)
91 return 0;
8992
9093 ctx->selection = selection;
9194
00 /*
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2929 void *data, int len)
3030 {
3131 BIO *out = ossl_bio_new_from_core_bio(provctx, cout);
32 int ret = BIO_write(out, data, len);
32 int ret;
33
34 if (out == NULL)
35 return 0;
36 ret = BIO_write(out, data, len);
3337
3438 BIO_free(out);
3539 return ret;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3838 EVP_PKEY *pkey, int ispub)
3939 {
4040 BIO *out = ossl_bio_new_from_core_bio(ctx->provctx, cout);
41 int ret =
42 ispub ? i2b_PublicKey_bio(out, pkey) : i2b_PrivateKey_bio(out, pkey);
41 int ret;
42
43 if (out == NULL)
44 return 0;
45 ret = ispub ? i2b_PublicKey_bio(out, pkey) : i2b_PrivateKey_bio(out, pkey);
4346
4447 BIO_free(out);
4548 return ret;
4952 EVP_PKEY *pkey)
5053 {
5154 BIO *out = NULL;
52 int ret = 0;
55 int ret;
5356 OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
5457
5558 out = ossl_bio_new_from_core_bio(ctx->provctx, cout);
59 if (out == NULL)
60 return 0;
5661 ret = i2b_PVK_bio_ex(out, pkey, ctx->pvk_encr_level,
5762 ossl_pw_pvk_password, &ctx->pwdata, libctx, NULL);
5863 BIO_free(out);
59
6064 return ret;
6165 }
6266
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
7979 }
8080
8181 hex_str = BN_bn2hex(bn);
82 if (hex_str == NULL)
83 return 0;
84
8285 p = hex_str;
8386 if (*p == '-') {
8487 ++p;
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
8888 {
8989 BUF_MEM *mem = NULL;
9090 BIO *in = ossl_bio_new_from_core_bio(provctx, cin);
91 int ok = (asn1_d2i_read_bio(in, &mem) >= 0);
91 int ok;
9292
93 if (in == NULL)
94 return 0;
95 ok = (asn1_d2i_read_bio(in, &mem) >= 0);
9396 if (ok) {
9497 *data = (unsigned char *)mem->data;
9598 *len = (long)mem->length;
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
140140
141141 static int dh_plain_derive(void *vpdhctx,
142142 unsigned char *secret, size_t *secretlen,
143 size_t outlen)
143 size_t outlen, unsigned int pad)
144144 {
145145 PROV_DH_CTX *pdhctx = (PROV_DH_CTX *)vpdhctx;
146146 int ret;
163163 }
164164
165165 DH_get0_key(pdhctx->dhpeer, &pub_key, NULL);
166 if (pdhctx->pad)
166 if (pad)
167167 ret = DH_compute_key_padded(secret, pub_key, pdhctx->dh);
168168 else
169169 ret = DH_compute_key(secret, pub_key, pdhctx->dh);
191191 ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
192192 return 0;
193193 }
194 if (!dh_plain_derive(pdhctx, NULL, &stmplen, 0))
194 if (!dh_plain_derive(pdhctx, NULL, &stmplen, 0, 1))
195195 return 0;
196196 if ((stmp = OPENSSL_secure_malloc(stmplen)) == NULL) {
197197 ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
198198 return 0;
199199 }
200 if (!dh_plain_derive(pdhctx, stmp, &stmplen, stmplen))
200 if (!dh_plain_derive(pdhctx, stmp, &stmplen, stmplen, 1))
201201 goto err;
202202
203203 /* Do KDF stuff */
228228
229229 switch (pdhctx->kdf_type) {
230230 case PROV_DH_KDF_NONE:
231 return dh_plain_derive(pdhctx, secret, psecretlen, outlen);
231 return dh_plain_derive(pdhctx, secret, psecretlen, outlen,
232 pdhctx->pad);
232233 case PROV_DH_KDF_X9_42_ASN1:
233234 return dh_X9_42_kdf_derive(pdhctx, secret, psecretlen, outlen);
234235 default:
291292 if (dstctx->kdf_ukm == NULL)
292293 goto err;
293294 }
294 dstctx->kdf_cekalg = OPENSSL_strdup(srcctx->kdf_cekalg);
295
296 if (srcctx->kdf_cekalg != NULL) {
297 dstctx->kdf_cekalg = OPENSSL_strdup(srcctx->kdf_cekalg);
298 if (dstctx->kdf_cekalg == NULL)
299 goto err;
300 }
295301
296302 return dstctx;
297303 err:
388394 p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_CEK_ALG);
389395 if (p != NULL) {
390396 str = name;
391 if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(name)))
392 return 0;
393 pdhctx->kdf_cekalg = OPENSSL_strdup(name);
397
398 OPENSSL_free(pdhctx->kdf_cekalg);
399 pdhctx->kdf_cekalg = NULL;
400 if (p->data != NULL && p->data_size != 0) {
401 if (!OSSL_PARAM_get_utf8_string(p, &str, sizeof(name)))
402 return 0;
403 pdhctx->kdf_cekalg = OPENSSL_strdup(name);
404 if (pdhctx->kdf_cekalg == NULL)
405 return 0;
406 }
394407 }
395408 return 1;
396409 }
413426 }
414427
415428 static const OSSL_PARAM known_gettable_ctx_params[] = {
416 OSSL_PARAM_int(OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE, NULL),
417429 OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE, NULL, 0),
418430 OSSL_PARAM_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST, NULL, 0),
419431 OSSL_PARAM_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN, NULL),
420432 OSSL_PARAM_DEFN(OSSL_EXCHANGE_PARAM_KDF_UKM, OSSL_PARAM_OCTET_PTR,
421433 NULL, 0),
434 OSSL_PARAM_utf8_string(OSSL_KDF_PARAM_CEK_ALG, NULL, 0),
422435 OSSL_PARAM_END
423436 };
424437
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
200200 if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
201201 ok = ok && ossl_dh_params_fromdata(dh, params);
202202
203 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
204 ok = ok && ossl_dh_key_fromdata(dh, params);
203 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
204 int include_private =
205 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
206
207 ok = ok && ossl_dh_key_fromdata(dh, params, include_private);
208 }
205209
206210 return ok;
207211 }
223227
224228 if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
225229 ok = ok && ossl_dh_params_todata(dh, tmpl, NULL);
226 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
227 ok = ok && ossl_dh_key_todata(dh, tmpl, NULL);
230
231 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
232 int include_private =
233 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
234
235 ok = ok && ossl_dh_key_todata(dh, tmpl, NULL, include_private);
236 }
228237
229238 if (!ok
230239 || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) {
322331 }
323332
324333 return ossl_dh_params_todata(dh, NULL, params)
325 && ossl_dh_key_todata(dh, NULL, params);
334 && ossl_dh_key_todata(dh, NULL, params, 1);
326335 }
327336
328337 static const OSSL_PARAM dh_params[] = {
531540 const DH_NAMED_GROUP *group = NULL;
532541
533542 if (p->data_type != OSSL_PARAM_UTF8_STRING
543 || p->data == NULL
534544 || (group = ossl_ffc_name_to_dh_named_group(p->data)) == NULL
535545 || ((gctx->group_nid =
536546 ossl_ffc_named_group_get_uid(group)) == NID_undef)) {
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
9595 return -1;
9696 }
9797
98 static int dsa_key_todata(DSA *dsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[])
98 static int dsa_key_todata(DSA *dsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[],
99 int include_private)
99100 {
100101 const BIGNUM *priv = NULL, *pub = NULL;
101102
103104 return 0;
104105
105106 DSA_get0_key(dsa, &pub, &priv);
106 if (priv != NULL
107 if (include_private
108 && priv != NULL
107109 && !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_PRIV_KEY, priv))
108110 return 0;
109111 if (pub != NULL
199201
200202 if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
201203 ok = ok && ossl_dsa_ffc_params_fromdata(dsa, params);
202 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
203 ok = ok && ossl_dsa_key_fromdata(dsa, params);
204 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
205 int include_private =
206 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
207
208 ok = ok && ossl_dsa_key_fromdata(dsa, params, include_private);
209 }
204210
205211 return ok;
206212 }
209215 void *cbarg)
210216 {
211217 DSA *dsa = keydata;
212 OSSL_PARAM_BLD *tmpl = OSSL_PARAM_BLD_new();
218 OSSL_PARAM_BLD *tmpl;
213219 OSSL_PARAM *params = NULL;
214220 int ok = 1;
215221
216222 if (!ossl_prov_is_running() || dsa == NULL)
217 goto err;
223 return 0;
224
225 tmpl = OSSL_PARAM_BLD_new();
226 if (tmpl == NULL)
227 return 0;
218228
219229 if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0)
220230 ok = ok && ossl_ffc_params_todata(ossl_dsa_get0_params(dsa), tmpl, NULL);
221 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
222 ok = ok && dsa_key_todata(dsa, tmpl, NULL);
231 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
232 int include_private =
233 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
234
235 ok = ok && dsa_key_todata(dsa, tmpl, NULL, include_private);
236 }
223237
224238 if (!ok
225239 || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
308322 && !OSSL_PARAM_set_utf8_string(p, DSA_DEFAULT_MD))
309323 return 0;
310324 return ossl_ffc_params_todata(ossl_dsa_get0_params(dsa), NULL, params)
311 && dsa_key_todata(dsa, NULL, params);
325 && dsa_key_todata(dsa, NULL, params, 1);
312326 }
313327
314328 static const OSSL_PARAM dsa_params[] = {
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
09 /*
110 * This file is meant to be included from ec_kmgmt.c
211 */
00 /*
1 * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
193193 {
194194 ECX_KEY *key = keydata;
195195 int ok = 1;
196 int include_private = 0;
196 int include_private;
197197
198198 if (!ossl_prov_is_running() || key == NULL)
199199 return 0;
201201 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0)
202202 return 0;
203203
204 include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
204 include_private = selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
205205 ok = ok && ossl_ecx_key_fromdata(key, params, include_private);
206206
207207 return ok;
208208 }
209209
210210 static int key_to_params(ECX_KEY *key, OSSL_PARAM_BLD *tmpl,
211 OSSL_PARAM params[])
211 OSSL_PARAM params[], int include_private)
212212 {
213213 if (key == NULL)
214214 return 0;
218218 key->pubkey, key->keylen))
219219 return 0;
220220
221 if (key->privkey != NULL
221 if (include_private
222 && key->privkey != NULL
222223 && !ossl_param_build_set_octet_string(tmpl, params,
223224 OSSL_PKEY_PARAM_PRIV_KEY,
224225 key->privkey, key->keylen))
242243 if (tmpl == NULL)
243244 return 0;
244245
245 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0
246 && !key_to_params(key, tmpl, NULL))
247 goto err;
246 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
247 int include_private = ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0);
248
249 if (!key_to_params(key, tmpl, NULL, include_private))
250 goto err;
251 }
248252
249253 params = OSSL_PARAM_BLD_to_param(tmpl);
250254 if (params == NULL)
294298 return 0;
295299 }
296300
297 return key_to_params(ecx, NULL, params);
301 return key_to_params(ecx, NULL, params, 1);
298302 }
299303
300304 static int ed_get_params(void *key, OSSL_PARAM params[])
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
189189 &pss_defaults_set,
190190 params, rsa_type,
191191 ossl_rsa_get0_libctx(rsa));
192 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
193 ok = ok && ossl_rsa_fromdata(rsa, params);
192 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
193 int include_private =
194 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
195
196 ok = ok && ossl_rsa_fromdata(rsa, params, include_private);
197 }
194198
195199 return ok;
196200 }
217221 if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0)
218222 ok = ok && (ossl_rsa_pss_params_30_is_unrestricted(pss_params)
219223 || ossl_rsa_pss_params_30_todata(pss_params, tmpl, NULL));
220 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0)
221 ok = ok && ossl_rsa_todata(rsa, tmpl, NULL);
224 if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) {
225 int include_private =
226 selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY ? 1 : 0;
227
228 ok = ok && ossl_rsa_todata(rsa, tmpl, NULL, include_private);
229 }
222230
223231 if (!ok
224232 || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL)
362370 }
363371 return (rsa_type != RSA_FLAG_TYPE_RSASSAPSS
364372 || ossl_rsa_pss_params_30_todata(pss_params, NULL, params))
365 && ossl_rsa_todata(rsa, NULL, params);
373 && ossl_rsa_todata(rsa, NULL, params, 1);
366374 }
367375
368376 static const OSSL_PARAM rsa_params[] = {
453461 gctx->libctx = libctx;
454462 if ((gctx->pub_exp = BN_new()) == NULL
455463 || !BN_set_word(gctx->pub_exp, RSA_F4)) {
456 BN_free(gctx->pub_exp);
457 OPENSSL_free(gctx);
458 return NULL;
464 goto err;
459465 }
460466 gctx->nbits = 2048;
461467 gctx->primes = RSA_DEFAULT_PRIME_NUM;
462468 gctx->rsa_type = rsa_type;
463 }
464 if (!rsa_gen_set_params(gctx, params)) {
465 OPENSSL_free(gctx);
466 return NULL;
467 }
469 } else {
470 goto err;
471 }
472
473 if (!rsa_gen_set_params(gctx, params))
474 goto err;
468475 return gctx;
476
477 err:
478 if (gctx != NULL)
479 BN_free(gctx->pub_exp);
480 OPENSSL_free(gctx);
481 return NULL;
469482 }
470483
471484 static void *rsa_gen_init(void *provctx, int selection,
00 /*
1 * Copyright 2011-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2011-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
836836 goto err;
837837 }
838838 }
839 #ifdef TSAN_REQUIRES_LOCKING
840 if (!ossl_drbg_enable_locking(drbg))
841 goto err;
842 #endif
839843 return drbg;
840844
841845 err:
174174
175175 if ((ctx = new_file_ctx(IS_DIR, uri, provctx)) == NULL) {
176176 ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
177 goto err;
177 return NULL;
178178 }
179179
180180 ctx->_.dir.last_entry = OPENSSL_DIR_read(&ctx->_.dir.ctx, path);
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
190190
191191 rr = RECORD_LAYER_get_rrec(&s->rlayer);
192192 rbuf = RECORD_LAYER_get_rbuf(&s->rlayer);
193 is_ktls_left = (rbuf->left > 0);
193 is_ktls_left = (SSL3_BUFFER_get_left(rbuf) > 0);
194194 max_recs = s->max_pipelines;
195195 if (max_recs == 0)
196196 max_recs = 1;
407407 len -= SSL3_RT_MAX_COMPRESSED_OVERHEAD;
408408 #endif
409409
410 if (thisrr->length > len && !BIO_get_ktls_recv(s->rbio)) {
410 /* KTLS may use all of the buffer */
411 if (BIO_get_ktls_recv(s->rbio) && !is_ktls_left)
412 len = SSL3_BUFFER_get_left(rbuf);
413
414 if (thisrr->length > len) {
411415 SSLfatal(s, SSL_AD_RECORD_OVERFLOW,
412416 SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
413417 return -1;
710714 goto end;
711715 }
712716
717 /*
718 * Usually thisrr->length is the length of a single record, but when
719 * KTLS handles the decryption, thisrr->length may be larger than
720 * SSL3_RT_MAX_PLAIN_LENGTH because the kernel may have coalesced
721 * multiple records.
722 * Therefore we have to rely on KTLS to check the plaintext length
723 * limit in the kernel.
724 */
713725 if (thisrr->length > SSL3_RT_MAX_PLAIN_LENGTH
714 && !BIO_get_ktls_recv(s->rbio)) {
726 && (!BIO_get_ktls_recv(s->rbio) || is_ktls_left)) {
715727 SSLfatal(s, SSL_AD_RECORD_OVERFLOW, SSL_R_DATA_LENGTH_TOO_LONG);
716728 goto end;
717729 }
718730
719 /* If received packet overflows current Max Fragment Length setting */
731 /*
732 * Check if the received packet overflows the current
733 * Max Fragment Length setting.
734 * Note: USE_MAX_FRAGMENT_LENGTH_EXT and KTLS are mutually exclusive.
735 */
720736 if (s->session != NULL && USE_MAX_FRAGMENT_LENGTH_EXT(s->session)
721 && thisrr->length > GET_MAX_FRAGMENT_LENGTH(s->session)
722 && !BIO_get_ktls_recv(s->rbio)) {
737 && thisrr->length > GET_MAX_FRAGMENT_LENGTH(s->session)) {
723738 SSLfatal(s, SSL_AD_RECORD_OVERFLOW, SSL_R_DATA_LENGTH_TOO_LONG);
724739 goto end;
725740 }
13911406 int tlstree_mac = sending ? (ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_TLSTREE)
13921407 : (ssl->mac_flags & SSL_MAC_FLAG_READ_MAC_TLSTREE);
13931408 int t;
1409 int ret = 0;
13941410
13951411 if (sending) {
13961412 seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
14111427 } else {
14121428 hmac = EVP_MD_CTX_new();
14131429 if (hmac == NULL || !EVP_MD_CTX_copy(hmac, hash)) {
1414 EVP_MD_CTX_free(hmac);
1415 return 0;
1430 goto end;
14161431 }
14171432 mac_ctx = hmac;
14181433 }
14191434
14201435 if (!SSL_IS_DTLS(ssl) && tlstree_mac && EVP_MD_CTX_ctrl(mac_ctx, EVP_MD_CTRL_TLSTREE, 0, seq) <= 0) {
1421 EVP_MD_CTX_free(hmac);
1422 return 0;
1436 goto end;
14231437 }
14241438
14251439 if (SSL_IS_DTLS(ssl)) {
14491463 *p++ = OSSL_PARAM_construct_end();
14501464
14511465 if (!EVP_PKEY_CTX_set_params(EVP_MD_CTX_get_pkey_ctx(mac_ctx),
1452 tls_hmac_params))
1453 return 0;
1466 tls_hmac_params)) {
1467 goto end;
1468 }
14541469 }
14551470
14561471 if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0
14571472 || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0
14581473 || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {
1459 EVP_MD_CTX_free(hmac);
1460 return 0;
1461 }
1462
1463 EVP_MD_CTX_free(hmac);
1474 goto end;
1475 }
14641476
14651477 OSSL_TRACE_BEGIN(TLS) {
14661478 BIO_printf(trc_out, "seq:\n");
14801492 BIO_printf(trc_out, "md:\n");
14811493 BIO_dump_indent(trc_out, md, md_size, 4);
14821494 } OSSL_TRACE_END(TLS);
1483 return 1;
1495 ret = 1;
1496 end:
1497 EVP_MD_CTX_free(hmac);
1498 return ret;
14841499 }
14851500
14861501 int dtls1_process_record(SSL *s, DTLS1_BITMAP *bitmap)
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
21672167 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256,
21682168 TLS1_RFC_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256,
21692169 TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256,
2170 SSL_kEDH,
2170 SSL_kDHE,
21712171 SSL_aDSS,
21722172 SSL_CAMELLIA128,
21732173 SSL_SHA256,
21832183 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
21842184 TLS1_RFC_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
21852185 TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
2186 SSL_kEDH,
2186 SSL_kDHE,
21872187 SSL_aRSA,
21882188 SSL_CAMELLIA128,
21892189 SSL_SHA256,
21992199 TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA256,
22002200 TLS1_RFC_ADH_WITH_CAMELLIA_128_CBC_SHA256,
22012201 TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA256,
2202 SSL_kEDH,
2202 SSL_kDHE,
22032203 SSL_aNULL,
22042204 SSL_CAMELLIA128,
22052205 SSL_SHA256,
22312231 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256,
22322232 TLS1_RFC_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256,
22332233 TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256,
2234 SSL_kEDH,
2234 SSL_kDHE,
22352235 SSL_aDSS,
22362236 SSL_CAMELLIA256,
22372237 SSL_SHA256,
22472247 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256,
22482248 TLS1_RFC_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256,
22492249 TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256,
2250 SSL_kEDH,
2250 SSL_kDHE,
22512251 SSL_aRSA,
22522252 SSL_CAMELLIA256,
22532253 SSL_SHA256,
22632263 TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA256,
22642264 TLS1_RFC_ADH_WITH_CAMELLIA_256_CBC_SHA256,
22652265 TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA256,
2266 SSL_kEDH,
2266 SSL_kDHE,
22672267 SSL_aNULL,
22682268 SSL_CAMELLIA256,
22692269 SSL_SHA256,
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
10001000 int op, int bits, int nid, void *other,
10011001 void *ex)
10021002 {
1003 int level, minbits;
1003 int level, minbits, pfs_mask;
10041004
10051005 minbits = ssl_get_security_level_bits(s, ctx, &level);
10061006
10351035 if (level >= 2 && c->algorithm_enc == SSL_RC4)
10361036 return 0;
10371037 /* Level 3: forward secure ciphersuites only */
1038 pfs_mask = SSL_kDHE | SSL_kECDHE | SSL_kDHEPSK | SSL_kECDHEPSK;
10381039 if (level >= 3 && c->min_tls != TLS1_3_VERSION &&
1039 !(c->algorithm_mkey & (SSL_kEDH | SSL_kEECDH)))
1040 !(c->algorithm_mkey & pfs_mask))
10401041 return 0;
10411042 break;
10421043 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
23922392 return 1;
23932393 case SSL_CTRL_GET_RI_SUPPORT:
23942394 return s->s3.send_connection_binding;
2395 case SSL_CTRL_SET_RETRY_VERIFY:
2396 s->rwstate = SSL_RETRY_VERIFY;
2397 return 1;
23952398 case SSL_CTRL_CERT_FLAGS:
23962399 return (s->cert->cert_flags |= larg);
23972400 case SSL_CTRL_CLEAR_CERT_FLAGS:
24502453 return ctx->sessions;
24512454 }
24522455
2456 static int ssl_tsan_load(SSL_CTX *ctx, TSAN_QUALIFIER int *stat)
2457 {
2458 int res = 0;
2459
2460 if (ssl_tsan_lock(ctx)) {
2461 res = tsan_load(stat);
2462 ssl_tsan_unlock(ctx);
2463 }
2464 return res;
2465 }
2466
24532467 long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
24542468 {
24552469 long l;
25052519 case SSL_CTRL_SESS_NUMBER:
25062520 return lh_SSL_SESSION_num_items(ctx->sessions);
25072521 case SSL_CTRL_SESS_CONNECT:
2508 return tsan_load(&ctx->stats.sess_connect);
2522 return ssl_tsan_load(ctx, &ctx->stats.sess_connect);
25092523 case SSL_CTRL_SESS_CONNECT_GOOD:
2510 return tsan_load(&ctx->stats.sess_connect_good);
2524 return ssl_tsan_load(ctx, &ctx->stats.sess_connect_good);
25112525 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
2512 return tsan_load(&ctx->stats.sess_connect_renegotiate);
2526 return ssl_tsan_load(ctx, &ctx->stats.sess_connect_renegotiate);
25132527 case SSL_CTRL_SESS_ACCEPT:
2514 return tsan_load(&ctx->stats.sess_accept);
2528 return ssl_tsan_load(ctx, &ctx->stats.sess_accept);
25152529 case SSL_CTRL_SESS_ACCEPT_GOOD:
2516 return tsan_load(&ctx->stats.sess_accept_good);
2530 return ssl_tsan_load(ctx, &ctx->stats.sess_accept_good);
25172531 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
2518 return tsan_load(&ctx->stats.sess_accept_renegotiate);
2532 return ssl_tsan_load(ctx, &ctx->stats.sess_accept_renegotiate);
25192533 case SSL_CTRL_SESS_HIT:
2520 return tsan_load(&ctx->stats.sess_hit);
2534 return ssl_tsan_load(ctx, &ctx->stats.sess_hit);
25212535 case SSL_CTRL_SESS_CB_HIT:
2522 return tsan_load(&ctx->stats.sess_cb_hit);
2536 return ssl_tsan_load(ctx, &ctx->stats.sess_cb_hit);
25232537 case SSL_CTRL_SESS_MISSES:
2524 return tsan_load(&ctx->stats.sess_miss);
2538 return ssl_tsan_load(ctx, &ctx->stats.sess_miss);
25252539 case SSL_CTRL_SESS_TIMEOUTS:
2526 return tsan_load(&ctx->stats.sess_timeout);
2540 return ssl_tsan_load(ctx, &ctx->stats.sess_timeout);
25272541 case SSL_CTRL_SESS_CACHE_FULL:
2528 return tsan_load(&ctx->stats.sess_cache_full);
2542 return ssl_tsan_load(ctx, &ctx->stats.sess_cache_full);
25292543 case SSL_CTRL_MODE:
25302544 return (ctx->mode |= larg);
25312545 case SSL_CTRL_CLEAR_MODE:
31983212 return NULL;
31993213 }
32003214
3215 #ifdef TSAN_REQUIRES_LOCKING
3216 ret->tsan_lock = CRYPTO_THREAD_lock_new();
3217 if (ret->tsan_lock == NULL) {
3218 ERR_raise(ERR_LIB_SSL, ERR_R_MALLOC_FAILURE);
3219 goto err;
3220 }
3221 #endif
3222
32013223 ret->libctx = libctx;
32023224 if (propq != NULL) {
32033225 ret->propq = OPENSSL_strdup(propq);
34643486 OPENSSL_free(a->sigalg_lookup_cache);
34653487
34663488 CRYPTO_THREAD_lock_free(a->lock);
3489 #ifdef TSAN_REQUIRES_LOCKING
3490 CRYPTO_THREAD_lock_free(a->tsan_lock);
3491 #endif
34673492
34683493 OPENSSL_free(a->propq);
34693494
37323757 /* auto flush every 255 connections */
37333758 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) && ((i & mode) == mode)) {
37343759 TSAN_QUALIFIER int *stat;
3760
37353761 if (mode & SSL_SESS_CACHE_CLIENT)
37363762 stat = &s->session_ctx->stats.sess_connect_good;
37373763 else
37383764 stat = &s->session_ctx->stats.sess_accept_good;
3739 if ((tsan_load(stat) & 0xff) == 0xff)
3765 if ((ssl_tsan_load(s->session_ctx, stat) & 0xff) == 0xff)
37403766 SSL_CTX_flush_sessions(s->session_ctx, (unsigned long)time(NULL));
37413767 }
37423768 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
810810 size_t ssl_hmac_size(const SSL_HMAC *ctx);
811811
812812 int ssl_get_EC_curve_nid(const EVP_PKEY *pkey);
813 __owur int tls13_set_encoded_pub_key(EVP_PKEY *pkey,
814 const unsigned char *enckey,
815 size_t enckeylen);
813816
814817 typedef struct tls_group_info_st {
815818 char *tlsname; /* Curve Name as in TLS specs */
897900 * other processes - spooky
898901 * :-) */
899902 } stats;
903 #ifdef TSAN_REQUIRES_LOCKING
904 CRYPTO_RWLOCK *tsan_lock;
905 #endif
900906
901907 CRYPTO_REF_COUNT references;
902908
28462852 # define ssl3_setup_buffers SSL_test_functions()->p_ssl3_setup_buffers
28472853
28482854 # endif
2855
2856 /* Some helper routines to support TSAN operations safely */
2857 static ossl_unused ossl_inline int ssl_tsan_lock(const SSL_CTX *ctx)
2858 {
2859 #ifdef TSAN_REQUIRES_LOCKING
2860 if (!CRYPTO_THREAD_write_lock(ctx->tsan_lock))
2861 return 0;
28492862 #endif
2863 return 1;
2864 }
2865
2866 static ossl_unused ossl_inline void ssl_tsan_unlock(const SSL_CTX *ctx)
2867 {
2868 #ifdef TSAN_REQUIRES_LOCKING
2869 CRYPTO_THREAD_unlock(ctx->tsan_lock);
2870 #endif
2871 }
2872
2873 static ossl_unused ossl_inline void ssl_tsan_counter(const SSL_CTX *ctx,
2874 TSAN_QUALIFIER int *stat)
2875 {
2876 if (ssl_tsan_lock(ctx)) {
2877 tsan_counter(stat);
2878 ssl_tsan_unlock(ctx);
2879 }
2880 }
2881
2882 #endif
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2005 Nokia. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
501501 }
502502 CRYPTO_THREAD_unlock(s->session_ctx->lock);
503503 if (ret == NULL)
504 tsan_counter(&s->session_ctx->stats.sess_miss);
504 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_miss);
505505 }
506506
507507 if (ret == NULL && s->session_ctx->get_session_cb != NULL) {
510510 ret = s->session_ctx->get_session_cb(s, sess_id, sess_id_len, &copy);
511511
512512 if (ret != NULL) {
513 tsan_counter(&s->session_ctx->stats.sess_cb_hit);
513 ssl_tsan_counter(s->session_ctx,
514 &s->session_ctx->stats.sess_cb_hit);
514515
515516 /*
516517 * Increment reference count now if the session callback asks us
641642 }
642643
643644 if (sess_timedout(time(NULL), ret)) {
644 tsan_counter(&s->session_ctx->stats.sess_timeout);
645 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_timeout);
645646 if (try_session_cache) {
646647 /* session was from the cache, so remove it */
647648 SSL_CTX_remove_session(s->session_ctx, ret);
668669 s->session = ret;
669670 }
670671
671 tsan_counter(&s->session_ctx->stats.sess_hit);
672 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_hit);
672673 s->verify_result = s->session->verify_result;
673674 return 1;
674675
768769 if (!remove_session_lock(ctx, ctx->session_cache_tail, 0))
769770 break;
770771 else
771 tsan_counter(&ctx->stats.sess_cache_full);
772 ssl_tsan_counter(ctx, &ctx->stats.sess_cache_full);
772773 }
773774 }
774775 }
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
896896 return 1;
897897 }
898898
899 static ossl_inline void ssl_tsan_decr(const SSL_CTX *ctx,
900 TSAN_QUALIFIER int *stat)
901 {
902 if (ssl_tsan_lock(ctx)) {
903 tsan_decr(stat);
904 ssl_tsan_unlock(ctx);
905 }
906 }
907
899908 static int init_server_name(SSL *s, unsigned int context)
900909 {
901910 if (s->server) {
953962 */
954963 if (SSL_IS_FIRST_HANDSHAKE(s) && s->ctx != s->session_ctx
955964 && s->hello_retry_request == SSL_HRR_NONE) {
956 tsan_counter(&s->ctx->stats.sess_accept);
957 tsan_decr(&s->session_ctx->stats.sess_accept);
965 ssl_tsan_counter(s->ctx, &s->ctx->stats.sess_accept);
966 ssl_tsan_decr(s->session_ctx, &s->session_ctx->stats.sess_accept);
958967 }
959968
960969 /*
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
18371837 return 0;
18381838 }
18391839
1840 if (EVP_PKEY_set1_encoded_public_key(skey, PACKET_data(&encoded_pt),
1841 PACKET_remaining(&encoded_pt)) <= 0) {
1840 if (tls13_set_encoded_pub_key(skey, PACKET_data(&encoded_pt),
1841 PACKET_remaining(&encoded_pt)) <= 0) {
18421842 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_ECPOINT);
18431843 EVP_PKEY_free(skey);
18441844 return 0;
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
662662 /* Cache the selected group ID in the SSL_SESSION */
663663 s->session->kex_group = group_id;
664664
665 if (EVP_PKEY_set1_encoded_public_key(s->s3.peer_tmp,
666 PACKET_data(&encoded_pt),
667 PACKET_remaining(&encoded_pt)) <= 0) {
665 if (tls13_set_encoded_pub_key(s->s3.peer_tmp,
666 PACKET_data(&encoded_pt),
667 PACKET_remaining(&encoded_pt)) <= 0) {
668668 SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_R_BAD_ECPOINT);
669669 return 0;
670670 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
15681568 * overwritten if the server refuses resumption.
15691569 */
15701570 if (s->session->session_id_length > 0) {
1571 tsan_counter(&s->session_ctx->stats.sess_miss);
1571 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_miss);
15721572 if (!ssl_get_new_session(s, 0)) {
15731573 /* SSLfatal() already called */
15741574 goto err;
18581858 size_t certidx;
18591859 int i;
18601860
1861 if (s->rwstate == SSL_RETRY_VERIFY)
1862 s->rwstate = SSL_NOTHING;
18611863 i = ssl_verify_cert_chain(s, s->session->peer_chain);
1862 if (i == -1) {
1863 s->rwstate = SSL_RETRY_VERIFY;
1864 if (i > 0 && s->rwstate == SSL_RETRY_VERIFY) {
18641865 return WORK_MORE_A;
18651866 }
18661867 /*
18771878 * (less clean) historic behaviour of performing validation if any flag is
18781879 * set. The *documented* interface remains the same.
18791880 */
1880 if (s->verify_mode != SSL_VERIFY_NONE && i == 0) {
1881 if (s->verify_mode != SSL_VERIFY_NONE && i <= 0) {
18811882 SSLfatal(s, ssl_x509err2alert(s->verify_result),
18821883 SSL_R_CERTIFICATE_VERIFY_FAILED);
18831884 return WORK_ERROR;
29252926 encoded_pub_len = EVP_PKEY_get1_encoded_public_key(ckey, &encoded_pub);
29262927 if (encoded_pub_len == 0) {
29272928 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
2928 EVP_PKEY_free(skey);
2929 EVP_PKEY_free(ckey);
29292930 return EXT_RETURN_FAIL;
29302931 }
29312932
30733074 EVP_MD_CTX_free(ukm_hash);
30743075 ukm_hash = NULL;
30753076 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_ENCRYPT,
3076 EVP_PKEY_CTRL_SET_IV, 8, shared_ukm) < 0) {
3077 EVP_PKEY_CTRL_SET_IV, 8, shared_ukm) <= 0) {
30773078 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_LIBRARY_BUG);
30783079 goto err;
30793080 }
31863187 if (peer_cert == NULL) {
31873188 SSLfatal(s, SSL_AD_HANDSHAKE_FAILURE,
31883189 SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER);
3189 return 0;
3190 goto err;
31903191 }
31913192
31923193 pkey_ctx = EVP_PKEY_CTX_new_from_pkey(s->ctx->libctx,
31943195 s->ctx->propq);
31953196 if (pkey_ctx == NULL) {
31963197 SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_MALLOC_FAILURE);
3197 return 0;
3198 goto err;
31983199 }
31993200
32003201 if (EVP_PKEY_encrypt_init(pkey_ctx) <= 0 ) {
32043205
32053206 /* Reuse EVP_PKEY_CTRL_SET_IV, make choice in engine code */
32063207 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_ENCRYPT,
3207 EVP_PKEY_CTRL_SET_IV, 32, rnd_dgst) < 0) {
3208 EVP_PKEY_CTRL_SET_IV, 32, rnd_dgst) <= 0) {
32083209 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_LIBRARY_BUG);
32093210 goto err;
32103211 }
32113212
32123213 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_ENCRYPT,
3213 EVP_PKEY_CTRL_CIPHER, cipher_nid, NULL) < 0) {
3214 EVP_PKEY_CTRL_CIPHER, cipher_nid, NULL) <= 0) {
32143215 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_LIBRARY_BUG);
32153216 goto err;
32163217 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
174174 }
175175 if (SSL_IS_FIRST_HANDSHAKE(s)) {
176176 /* N.B. s->session_ctx == s->ctx here */
177 tsan_counter(&s->session_ctx->stats.sess_accept);
177 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_accept);
178178 } else {
179179 /* N.B. s->ctx may not equal s->session_ctx */
180 tsan_counter(&s->ctx->stats.sess_accept_renegotiate);
180 ssl_tsan_counter(s->ctx, &s->ctx->stats.sess_accept_renegotiate);
181181
182182 s->s3.tmp.cert_request = 0;
183183 }
184184 } else {
185185 if (SSL_IS_FIRST_HANDSHAKE(s))
186 tsan_counter(&s->session_ctx->stats.sess_connect);
186 ssl_tsan_counter(s->session_ctx, &s->session_ctx->stats.sess_connect);
187187 else
188 tsan_counter(&s->session_ctx->stats.sess_connect_renegotiate);
188 ssl_tsan_counter(s->session_ctx,
189 &s->session_ctx->stats.sess_connect_renegotiate);
189190
190191 /* mark client_random uninitialized */
191192 memset(s->s3.client_random, 0, sizeof(s->s3.client_random));
10951096 ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
10961097
10971098 /* N.B. s->ctx may not equal s->session_ctx */
1098 tsan_counter(&s->ctx->stats.sess_accept_good);
1099 ssl_tsan_counter(s->ctx, &s->ctx->stats.sess_accept_good);
10991100 s->handshake_func = ossl_statem_accept;
11001101 } else {
11011102 if (SSL_IS_TLS13(s)) {
11141115 ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
11151116 }
11161117 if (s->hit)
1117 tsan_counter(&s->session_ctx->stats.sess_hit);
1118 ssl_tsan_counter(s->session_ctx,
1119 &s->session_ctx->stats.sess_hit);
11181120
11191121 s->handshake_func = ossl_statem_connect;
1120 tsan_counter(&s->session_ctx->stats.sess_connect_good);
1122 ssl_tsan_counter(s->session_ctx,
1123 &s->session_ctx->stats.sess_connect_good);
11211124 }
11221125
11231126 if (SSL_IS_DTLS(s)) {
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
32433243
32443244 /* Reuse EVP_PKEY_CTRL_SET_IV, make choice in engine code depending on size */
32453245 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_DECRYPT,
3246 EVP_PKEY_CTRL_SET_IV, 32, rnd_dgst) < 0) {
3246 EVP_PKEY_CTRL_SET_IV, 32, rnd_dgst) <= 0) {
32473247 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_LIBRARY_BUG);
32483248 goto err;
32493249 }
32503250
32513251 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, EVP_PKEY_OP_DECRYPT,
3252 EVP_PKEY_CTRL_CIPHER, cipher_nid, NULL) < 0) {
3252 EVP_PKEY_CTRL_CIPHER, cipher_nid, NULL) <= 0) {
32533253 SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_R_LIBRARY_BUG);
32543254 goto err;
32553255 }
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2005 Nokia. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
121121 return -1;
122122
123123 /* Read until next record */
124 if (PACKET_get_length_prefixed_2(&pkt, &subpkt))
124 if (!PACKET_get_length_prefixed_2(&pkt, &subpkt))
125125 return -1;
126126
127127 count += 1;
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
34763476
34773477 return NID_undef;
34783478 }
3479
3480 __owur int tls13_set_encoded_pub_key(EVP_PKEY *pkey,
3481 const unsigned char *enckey,
3482 size_t enckeylen)
3483 {
3484 if (EVP_PKEY_is_a(pkey, "DH")) {
3485 int bits = EVP_PKEY_get_bits(pkey);
3486
3487 if (bits <= 0 || enckeylen != (size_t)bits / 8)
3488 /* the encoded key must be padded to the length of the p */
3489 return 0;
3490 } else if (EVP_PKEY_is_a(pkey, "EC")) {
3491 if (enckeylen < 3 /* point format and at least 1 byte for x and y */
3492 || enckey[0] != 0x04)
3493 return 0;
3494 }
3495
3496 return EVP_PKEY_set1_encoded_public_key(pkey, enckey, enckeylen);
3497 }
217217 r1 = ECDSA_SIG_get0_r(sign);
218218 s1 = ECDSA_SIG_get0_s(sign);
219219 if (r1 == NULL || s1 == NULL)
220 return 0;
220 goto err;
221221
222222 r1_len = BN_num_bytes(r1);
223223 s1_len = BN_num_bytes(s1);
559559 return 0;
560560 DSA_SIG_get0(sign, &r1, &s1);
561561 if (r1 == NULL || s1 == NULL)
562 return 0;
562 goto err;
563563
564564 r1_len = BN_num_bytes(r1);
565565 s1_len = BN_num_bytes(s1);
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3737 static int do_bio_cipher(const EVP_CIPHER* cipher, const unsigned char* key,
3838 const unsigned char* iv)
3939 {
40 BIO *b;
40 BIO *b, *mem;
4141 static unsigned char inp[BUF_SIZE] = { 0 };
4242 unsigned char out[BUF_SIZE], ref[BUF_SIZE];
4343 int i, lref, len;
5353 if (!TEST_ptr(b))
5454 return 0;
5555 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, ENCRYPT)))
56 return 0;
57 BIO_push(b, BIO_new_mem_buf(inp, DATA_SIZE));
56 goto err;
57 mem = BIO_new_mem_buf(inp, DATA_SIZE);
58 if (!TEST_ptr(mem))
59 goto err;
60 BIO_push(b, mem);
5861 lref = BIO_read(b, ref, sizeof(ref));
5962 BIO_free_all(b);
6063
6568 return 0;
6669 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, ENCRYPT))) {
6770 TEST_info("Split encrypt failed @ operation %d", i);
68 return 0;
69 }
70 BIO_push(b, BIO_new_mem_buf(inp, DATA_SIZE));
71 goto err;
72 }
73 mem = BIO_new_mem_buf(inp, DATA_SIZE);
74 if (!TEST_ptr(mem))
75 goto err;
76 BIO_push(b, mem);
7177 memset(out, 0, sizeof(out));
7278 out[i] = ~ref[i];
7379 len = BIO_read(b, out, i);
7480 /* check for overstep */
7581 if (!TEST_uchar_eq(out[i], (unsigned char)~ref[i])) {
7682 TEST_info("Encrypt overstep check failed @ operation %d", i);
77 return 0;
83 goto err;
7884 }
7985 len += BIO_read(b, out + len, sizeof(out) - len);
8086 BIO_free_all(b);
94100 return 0;
95101 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, ENCRYPT))) {
96102 TEST_info("Small chunk encrypt failed @ operation %d", i);
97 return 0;
98 }
99 BIO_push(b, BIO_new_mem_buf(inp, DATA_SIZE));
103 goto err;
104 }
105 mem = BIO_new_mem_buf(inp, DATA_SIZE);
106 if (!TEST_ptr(mem))
107 goto err;
108 BIO_push(b, mem);
100109 memset(out, 0, sizeof(out));
101110 for (len = 0; (delta = BIO_read(b, out + len, i)); ) {
102111 len += delta;
116125 if (!TEST_ptr(b))
117126 return 0;
118127 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, DECRYPT)))
119 return 0;
128 goto err;
120129 /* Use original reference output as input */
121 BIO_push(b, BIO_new_mem_buf(ref, lref));
130 mem = BIO_new_mem_buf(ref, lref);
131 if (!TEST_ptr(mem))
132 goto err;
133 BIO_push(b, mem);
122134 (void)BIO_flush(b);
123135 memset(out, 0, sizeof(out));
124136 len = BIO_read(b, out, sizeof(out));
134146 return 0;
135147 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, DECRYPT))) {
136148 TEST_info("Split decrypt failed @ operation %d", i);
137 return 0;
138 }
139 BIO_push(b, BIO_new_mem_buf(ref, lref));
149 goto err;
150 }
151 mem = BIO_new_mem_buf(ref, lref);
152 if (!TEST_ptr(mem))
153 goto err;
154 BIO_push(b, mem);
140155 memset(out, 0, sizeof(out));
141156 out[i] = ~ref[i];
142157 len = BIO_read(b, out, i);
143158 /* check for overstep */
144159 if (!TEST_uchar_eq(out[i], (unsigned char)~ref[i])) {
145160 TEST_info("Decrypt overstep check failed @ operation %d", i);
146 return 0;
161 goto err;
147162 }
148163 len += BIO_read(b, out + len, sizeof(out) - len);
149164 BIO_free_all(b);
163178 return 0;
164179 if (!TEST_true(BIO_set_cipher(b, cipher, key, iv, DECRYPT))) {
165180 TEST_info("Small chunk decrypt failed @ operation %d", i);
166 return 0;
167 }
168 BIO_push(b, BIO_new_mem_buf(ref, lref));
181 goto err;
182 }
183 mem = BIO_new_mem_buf(ref, lref);
184 if (!TEST_ptr(mem))
185 goto err;
186 BIO_push(b, mem);
169187 memset(out, 0, sizeof(out));
170188 for (len = 0; (delta = BIO_read(b, out + len, i)); ) {
171189 len += delta;
179197 }
180198
181199 return 1;
200
201 err:
202 BIO_free_all(b);
203 return 0;
182204 }
183205
184206 static int do_test_bio_cipher(const EVP_CIPHER* cipher, int idx)
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
17311731 || !TEST_ptr(ret2 = BN_new()))
17321732 goto err;
17331733
1734 if (BN_is_negative(mod_sqrt)) {
1735 /* A negative testcase */
1736 if (!TEST_ptr_null(BN_mod_sqrt(ret, a, p, ctx)))
1737 goto err;
1738
1739 st = 1;
1740 goto err;
1741 }
1742
17341743 /* There are two possible answers. */
1735 if (!TEST_true(BN_mod_sqrt(ret, a, p, ctx))
1744 if (!TEST_ptr(BN_mod_sqrt(ret, a, p, ctx))
17361745 || !TEST_true(BN_sub(ret2, p, ret)))
17371746 goto err;
17381747
28802889 return res;
28812890 }
28822891
2892 /*
2893 * Regression test to ensure BN_mod_exp2_mont fails safely if argument m is
2894 * zero.
2895 */
2896 static int test_mod_exp2_mont(void)
2897 {
2898 int res = 0;
2899 BIGNUM *exp_result = NULL;
2900 BIGNUM *exp_a1 = NULL, *exp_p1 = NULL, *exp_a2 = NULL, *exp_p2 = NULL,
2901 *exp_m = NULL;
2902
2903 if (!TEST_ptr(exp_result = BN_new())
2904 || !TEST_ptr(exp_a1 = BN_new())
2905 || !TEST_ptr(exp_p1 = BN_new())
2906 || !TEST_ptr(exp_a2 = BN_new())
2907 || !TEST_ptr(exp_p2 = BN_new())
2908 || !TEST_ptr(exp_m = BN_new()))
2909 goto err;
2910
2911 if (!TEST_true(BN_one(exp_a1))
2912 || !TEST_true(BN_one(exp_p1))
2913 || !TEST_true(BN_one(exp_a2))
2914 || !TEST_true(BN_one(exp_p2)))
2915 goto err;
2916
2917 BN_zero(exp_m);
2918
2919 /* input of 0 is even, so must fail */
2920 if (!TEST_int_eq(BN_mod_exp2_mont(exp_result, exp_a1, exp_p1, exp_a2,
2921 exp_p2, exp_m, ctx, NULL), 0))
2922 goto err;
2923
2924 res = 1;
2925
2926 err:
2927 BN_free(exp_result);
2928 BN_free(exp_a1);
2929 BN_free(exp_p1);
2930 BN_free(exp_a2);
2931 BN_free(exp_p2);
2932 BN_free(exp_m);
2933 return res;
2934 }
2935
28832936 static int file_test_run(STANZA *s)
28842937 {
28852938 static const FILETEST filetests[] = {
30213074 ADD_TEST(test_gcd_prime);
30223075 ADD_ALL_TESTS(test_mod_exp, (int)OSSL_NELEM(ModExpTests));
30233076 ADD_ALL_TESTS(test_mod_exp_consttime, (int)OSSL_NELEM(ModExpTests));
3077 ADD_TEST(test_mod_exp2_mont);
30243078 if (stochastic)
30253079 ADD_TEST(test_rand_range);
30263080 } else {
0 -----BEGIN ENCRYPTED PRIVATE KEY-----
1 MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIEBBNanZFjs8CAggA
2 MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAECBBDr8bhquxPf762O3jk0LAtJBIIE
3 0FQB7c06dpoHn1KBn8jTzsLIdVR0SeKUvq4edZfUPbB/6go97j48BwSzAaXY7BNL
4 90GRMrNNjKZDLeNf0wwf1+67YX7neGnb+LdxpQdqEjOTGQdwTx9SG6XIqT8x4R67
5 rI2DQqI937FSor9292koXQNM9Asoenn6kOCITaa8chsPdKCtFjfVmqZRMaewr5PW
6 W1rooFuCVAIfgBOOaEeN7OMTJRdAGtWWOJqyLB29gXxwaI1+PnXmkHPgRGXZYz7W
7 N5lTp1xvFPY+Rp/cK0DfeR5MrMYSVvrXbi6usjteJ2h0Rzcy8SY6Jnvuaoowi+rj
8 lDUP0K/51tTQBd6bpsvcmc2cBx+7pg4BAkf9SnuKQpYCWPjiwrCiDJIP/o5GYIn2
9 m/3K2pLahjOeGZAmhGUi0fZPZhaq37IQKwuzLDuYw1CkR7LhaJcJ9V1vXMPePgCY
10 +BvjFG5z0mLDwUNvzCHQokav3Z/QT6CfOgTL10qKuBgylT1d5Cw7bfv8Lnc6C/YK
11 aVXosCaKTJO8r4t7NgJX4PYQP/DZIl5CJIoUzJkrAkShLwcGtXMHVNSWx4LS60QY
12 lfjz80cWWE6Tx/XjBkae0AQJW8S9nDB8/X80ox8jJ/sdd5XNZqUQhDxBP5/4GiAS
13 pZlgp/IwssoG5HUnwn/4AUgD7Gdo5QRqFlkXeCFlHgjBrEHBkevHECRHAdWwrK7X
14 5td662K1B9hm6EfA1R51jiOKBuM0bwYtI+tpmpT5zeDGeaOWuPUYPUFjfo9xt1Lx
15 cmX3ouBt34uT/cQesPxP8gJwRdo0KqPK+KLjtQazXmHFu+FStZ29gUvhqAw9kcxq
16 ps9neGAl3DJgYbB1QqqefGqFWBhJzt4toqxcgm6Z0PJSYQlxJEC3yWWs5w5wfLJJ
17 KGfnpsY1IGYsbw9Caa84XqnzHosGWx724GJeb3YSwwMj311oMi9s8J/d/NpJZHOu
18 uk/mQWezCfdEFSnkOtIDJWTQUtRtRfIZQp243c25E3/rJySuSoMfn4eolAGurse8
19 6r7SEJ6MUjCTd3ZcA+XZAtFxPQnNBYm691hvGE6uclxYy9L6bmws9dosNlpCyvIQ
20 +OYdB9Mvx9hs0KwAWZ6bnIxa3tc6Ob9mxV7ycMS43d4ShEqzy44DZD02Z0iQIRym
21 1AoGwgLbc2d9NouUiw2ur5n6ByYCTHwmMSAstVovuBoS2XDF23BzLL7KuCnkHH0y
22 +M6CRaXW0ceTP4DfEvBphxfj4NNEZpjm8j6ERvnnQvC5tRAaMglhg1WOvUVUtPg5
23 cJPIiSn+yVuoFDnLKJ53N9NzDtUKSBQgwNGyVVPTzpfxLmjg00bNQ7eyoRr6uK0l
24 ezmHemo52JpCaBGV01tnvVKzGouFN/KxP9GxvPQY8UQxVkE+E/p0UjGOpNLIDmzl
25 /qVKxky9lMBoHc+neeCbOrtgwkyYgpPkKlmTTsi/yUxpbUmobFZJTUbOWrpeRbw3
26 Pt9u8NeVmD4Ys/NenHIJwksOqmWxSy7IjJpzQsee1CZXV7McAYsg24tP4Bdj9aGT
27 hsMyiaiNB+rjkNxhUCm39nJsaN1AoTZ3Br1UYfHrfocif12yNGOEBy2swfjQIGNH
28 fjGk3px34MZZv3S0bM/ZPi9ankzAZnf8qkHoDVtsP+Gk
29 -----END ENCRYPTED PRIVATE KEY-----
5050
5151 static CMP_VFY_TEST_FIXTURE *set_up(const char *const test_case_name)
5252 {
53 X509_STORE *ts = X509_STORE_new();
53 X509_STORE *ts;
5454 CMP_VFY_TEST_FIXTURE *fixture;
5555
5656 if (!TEST_ptr(fixture = OPENSSL_zalloc(sizeof(*fixture))))
5757 return NULL;
58
59 ts = X509_STORE_new();
5860 fixture->test_case_name = test_case_name;
5961 if (ts == NULL
6062 || !TEST_ptr(fixture->cmp_ctx = OSSL_CMP_CTX_new(libctx, NULL))
00 /*
1 * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
199199 */
200200 static X509_CRL *CRL_from_strings(const char **pem)
201201 {
202 X509_CRL *crl;
202203 char *p;
203204 BIO *b = glue2bio(pem, &p);
204 X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);
205
206 if (b == NULL) {
207 OPENSSL_free(p);
208 return NULL;
209 }
210
211 crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);
205212
206213 OPENSSL_free(p);
207214 BIO_free(b);
213220 */
214221 static X509 *X509_from_strings(const char **pem)
215222 {
223 X509 *x;
216224 char *p;
217225 BIO *b = glue2bio(pem, &p);
218 X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL);
226
227 if (b == NULL) {
228 OPENSSL_free(p);
229 return NULL;
230 }
231
232 x = PEM_read_bio_X509(b, NULL, NULL, NULL);
219233
220234 OPENSSL_free(p);
221235 BIO_free(b);
362376 char *p;
363377 BIO *b = glue2bio(kRevokedCRL, &p);
364378
379 if (b == NULL) {
380 OPENSSL_free(p);
381 X509_CRL_free(reused_crl);
382 return 0;
383 }
384
365385 reused_crl = PEM_read_bio_X509_CRL(b, &reused_crl, NULL, NULL);
366386
367387 OPENSSL_free(p);
00 /*
1 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
448448 SETUP_CT_TEST_FIXTURE();
449449
450450 fixture->sct_list = sk_SCT_new_null();
451 if (fixture->sct_list == NULL)
452 return 0;
453
451454 if (!TEST_ptr(sct = SCT_new_from_base64(SCT_VERSION_V1, log_id,
452455 CT_LOG_ENTRY_TYPE_X509, timestamp,
453456 extensions, signature)))
0 # Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
0 # Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
11 #
2 # Licensed under the OpenSSL license (the "License"). You may not use
2 # Licensed under the Apache License 2.0 (the "License"). You may not use
33 # this file except in compliance with the License. You can obtain a copy
44 # in the file LICENSE in the source distribution or at
55 # https://www.openssl.org/source/license.html
0 /*
1 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
2 *
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
4 * this file except in compliance with the License. You can obtain a copy
5 * in the file LICENSE in the source distribution or at
6 * https://www.openssl.org/source/license.html
7 */
8
09 #include <string.h>
110 #include <openssl/evp.h>
211 #include <openssl/provider.h>
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
742742 goto err;
743743 /* Tested function is called here */
744744 if (!TEST_int_eq(EVP_PKEY_CTX_set_dhx_rfc5114(paramgen_ctx, 3), 1))
745 goto err;
746 /* Negative test */
747 if (!TEST_int_eq(EVP_PKEY_CTX_set_dhx_rfc5114(paramgen_ctx, 99), 0))
748 goto err;
749 /* If we're still running then the test passed. */
750 ok = 1;
751 err:
752 EVP_PKEY_CTX_free(paramgen_ctx);
753 return ok;
754 }
755
756 static int dh_set_dh_nid_test(void)
757 {
758 int ok = 0;
759 EVP_PKEY_CTX *paramgen_ctx;
760
761 /* Run the test. Success is any time the test does not cause a SIGSEGV interrupt */
762 paramgen_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DH, 0);
763 if (!TEST_ptr(paramgen_ctx))
764 goto err;
765 if (!TEST_int_eq(EVP_PKEY_paramgen_init(paramgen_ctx), 1))
766 goto err;
767 /* Tested function is called here */
768 if (!TEST_int_eq(EVP_PKEY_CTX_set_dh_nid(paramgen_ctx, NID_ffdhe2048), 1))
769 goto err;
770 /* Negative test */
771 if (!TEST_int_eq(EVP_PKEY_CTX_set_dh_nid(paramgen_ctx, NID_secp521r1), 0))
745772 goto err;
746773 /* If we're still running then the test passed. */
747774 ok = 1;
897924 ADD_TEST(dh_get_nid);
898925 ADD_TEST(dh_load_pkcs3_namedgroup_privlen_test);
899926 ADD_TEST(dh_rfc5114_fix_nid_test);
927 ADD_TEST(dh_set_dh_nid_test);
900928 #endif
901929 return 1;
902930 }
00 /*
1 * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2323 # include <openssl/rsa.h>
2424 # include <openssl/err.h>
2525 # include <openssl/x509.h>
26 # include <openssl/pem.h>
2627
2728 static void display_engine_list(void)
2829 {
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
41784178 return testresult;
41794179 }
41804180
4181 typedef struct {
4182 int data;
4183 } custom_dgst_ctx;
4184
4185 static int custom_md_init_called = 0;
4186 static int custom_md_cleanup_called = 0;
4187
4188 static int custom_md_init(EVP_MD_CTX *ctx)
4189 {
4190 custom_dgst_ctx *p = EVP_MD_CTX_md_data(ctx);
4191
4192 if (p == NULL)
4193 return 0;
4194
4195 custom_md_init_called++;
4196 return 1;
4197 }
4198
4199 static int custom_md_cleanup(EVP_MD_CTX *ctx)
4200 {
4201 custom_dgst_ctx *p = EVP_MD_CTX_md_data(ctx);
4202
4203 if (p == NULL)
4204 /* Nothing to do */
4205 return 1;
4206
4207 custom_md_cleanup_called++;
4208 return 1;
4209 }
4210
4211 static int test_custom_md_meth(void)
4212 {
4213 EVP_MD_CTX *mdctx = NULL;
4214 EVP_MD *tmp = NULL;
4215 char mess[] = "Test Message\n";
4216 unsigned char md_value[EVP_MAX_MD_SIZE];
4217 unsigned int md_len;
4218 int testresult = 0;
4219 int nid;
4220
4221 /*
4222 * We are testing deprecated functions. We don't support a non-default
4223 * library context in this test.
4224 */
4225 if (testctx != NULL)
4226 return 1;
4227
4228 custom_md_init_called = custom_md_cleanup_called = 0;
4229
4230 nid = OBJ_create("1.3.6.1.4.1.16604.998866.1", "custom-md", "custom-md");
4231 if (!TEST_int_ne(nid, NID_undef))
4232 goto err;
4233 tmp = EVP_MD_meth_new(nid, NID_undef);
4234 if (!TEST_ptr(tmp))
4235 goto err;
4236
4237 if (!TEST_true(EVP_MD_meth_set_init(tmp, custom_md_init))
4238 || !TEST_true(EVP_MD_meth_set_cleanup(tmp, custom_md_cleanup))
4239 || !TEST_true(EVP_MD_meth_set_app_datasize(tmp,
4240 sizeof(custom_dgst_ctx))))
4241 goto err;
4242
4243 mdctx = EVP_MD_CTX_new();
4244 if (!TEST_ptr(mdctx)
4245 /*
4246 * Initing our custom md and then initing another md should
4247 * result in the init and cleanup functions of the custom md
4248 * from being called.
4249 */
4250 || !TEST_true(EVP_DigestInit_ex(mdctx, tmp, NULL))
4251 || !TEST_true(EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL))
4252 || !TEST_true(EVP_DigestUpdate(mdctx, mess, strlen(mess)))
4253 || !TEST_true(EVP_DigestFinal_ex(mdctx, md_value, &md_len))
4254 || !TEST_int_eq(custom_md_init_called, 1)
4255 || !TEST_int_eq(custom_md_cleanup_called, 1))
4256 goto err;
4257
4258 testresult = 1;
4259 err:
4260 EVP_MD_CTX_free(mdctx);
4261 EVP_MD_meth_free(tmp);
4262 return testresult;
4263 }
4264
41814265 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
41824266 /* Test we can create a signature keys with an associated ENGINE */
41834267 static int test_signatures_with_engine(int tst)
44724556 #ifndef OPENSSL_NO_DEPRECATED_3_0
44734557 ADD_ALL_TESTS(test_custom_pmeth, 12);
44744558 ADD_TEST(test_evp_md_cipher_meth);
4559 ADD_TEST(test_custom_md_meth);
44754560
44764561 # ifndef OPENSSL_NO_DYNAMIC_ENGINE
44774562 /* Tests only support the default libctx */
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
253253 {kExampleDHPrivateKeyDER, sizeof(kExampleDHPrivateKeyDER), EVP_PKEY_DH},
254254 #endif
255255 };
256
257 static int pkey_has_private(EVP_PKEY *key, const char *privtag,
258 int use_octstring)
259 {
260 int ret = 0;
261
262 if (use_octstring) {
263 unsigned char buf[64];
264
265 ret = EVP_PKEY_get_octet_string_param(key, privtag, buf, sizeof(buf),
266 NULL);
267 } else {
268 BIGNUM *bn = NULL;
269
270 ret = EVP_PKEY_get_bn_param(key, privtag, &bn);
271 BN_free(bn);
272 }
273 return ret;
274 }
275
276 static int do_pkey_tofrom_data_select(EVP_PKEY *key, const char *keytype)
277 {
278 int ret = 0;
279 OSSL_PARAM *pub_params = NULL, *keypair_params = NULL;
280 EVP_PKEY *fromkey = NULL, *fromkeypair = NULL;
281 EVP_PKEY_CTX *fromctx = NULL;
282 const char *privtag = strcmp(keytype, "RSA") == 0 ? "d" : "priv";
283 const int use_octstring = strcmp(keytype, "X25519") == 0;
284
285 /*
286 * Select only the public key component when using EVP_PKEY_todata() and
287 * check that the resulting param array does not contain a private key.
288 */
289 if (!TEST_int_eq(EVP_PKEY_todata(key, EVP_PKEY_PUBLIC_KEY, &pub_params), 1)
290 || !TEST_ptr_null(OSSL_PARAM_locate(pub_params, privtag)))
291 goto end;
292 /*
293 * Select the keypair when using EVP_PKEY_todata() and check that
294 * the param array contains a private key.
295 */
296 if (!TEST_int_eq(EVP_PKEY_todata(key, EVP_PKEY_KEYPAIR, &keypair_params), 1)
297 || !TEST_ptr(OSSL_PARAM_locate(keypair_params, privtag)))
298 goto end;
299
300 /*
301 * Select only the public key when using EVP_PKEY_fromdata() and check that
302 * the resulting key does not contain a private key.
303 */
304 if (!TEST_ptr(fromctx = EVP_PKEY_CTX_new_from_name(mainctx, keytype, NULL))
305 || !TEST_int_eq(EVP_PKEY_fromdata_init(fromctx), 1)
306 || !TEST_int_eq(EVP_PKEY_fromdata(fromctx, &fromkey, EVP_PKEY_PUBLIC_KEY,
307 keypair_params), 1)
308 || !TEST_false(pkey_has_private(fromkey, privtag, use_octstring)))
309 goto end;
310 /*
311 * Select the keypair when using EVP_PKEY_fromdata() and check that
312 * the resulting key contains a private key.
313 */
314 if (!TEST_int_eq(EVP_PKEY_fromdata(fromctx, &fromkeypair,
315 EVP_PKEY_KEYPAIR, keypair_params), 1)
316 || !TEST_true(pkey_has_private(fromkeypair, privtag, use_octstring)))
317 goto end;
318 ret = 1;
319 end:
320 EVP_PKEY_free(fromkeypair);
321 EVP_PKEY_free(fromkey);
322 EVP_PKEY_CTX_free(fromctx);
323 OSSL_PARAM_free(keypair_params);
324 OSSL_PARAM_free(pub_params);
325 return ret;
326 }
327
328 #ifndef OPENSSL_NO_DH
329 static int test_dh_tofrom_data_select(void)
330 {
331 int ret;
332 OSSL_PARAM params[2];
333 EVP_PKEY *key = NULL;
334 EVP_PKEY_CTX *gctx = NULL;
335
336 params[0] = OSSL_PARAM_construct_utf8_string("group", "ffdhe2048", 0);
337 params[1] = OSSL_PARAM_construct_end();
338 ret = TEST_ptr(gctx = EVP_PKEY_CTX_new_from_name(mainctx, "DHX", NULL))
339 && TEST_int_gt(EVP_PKEY_keygen_init(gctx), 0)
340 && TEST_true(EVP_PKEY_CTX_set_params(gctx, params))
341 && TEST_int_gt(EVP_PKEY_generate(gctx, &key), 0)
342 && TEST_true(do_pkey_tofrom_data_select(key, "DHX"));
343 EVP_PKEY_free(key);
344 EVP_PKEY_CTX_free(gctx);
345 return ret;
346 }
347 #endif
348
349 #ifndef OPENSSL_NO_EC
350 static int test_ec_tofrom_data_select(void)
351 {
352 int ret;
353 EVP_PKEY *key = NULL;
354
355 ret = TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "EC", "P-256"))
356 && TEST_true(do_pkey_tofrom_data_select(key, "EC"));
357 EVP_PKEY_free(key);
358 return ret;
359 }
360
361 static int test_ecx_tofrom_data_select(void)
362 {
363 int ret;
364 EVP_PKEY *key = NULL;
365
366 ret = TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "X25519"))
367 && TEST_true(do_pkey_tofrom_data_select(key, "X25519"));
368 EVP_PKEY_free(key);
369 return ret;
370 }
371 #endif
372
373 static int test_rsa_tofrom_data_select(void)
374 {
375 int ret;
376 EVP_PKEY *key = NULL;
377 const unsigned char *pdata = kExampleRSAKeyDER;
378 int pdata_len = sizeof(kExampleRSAKeyDER);
379
380 ret = TEST_ptr(key = d2i_AutoPrivateKey_ex(NULL, &pdata, pdata_len,
381 mainctx, NULL))
382 && TEST_true(do_pkey_tofrom_data_select(key, "RSA"));
383 EVP_PKEY_free(key);
384 return ret;
385 }
256386
257387 /* This is the equivalent of test_d2i_AutoPrivateKey in evp_extra_test */
258388 static int test_d2i_AutoPrivateKey_ex(int i)
660790 && TEST_int_eq(val, expected);
661791 }
662792
793 static int test_dsa_tofrom_data_select(void)
794 {
795 int ret;
796 EVP_PKEY *key = NULL;
797 const unsigned char *pkeydata = dsa_key;
798
799 ret = TEST_ptr(key = d2i_AutoPrivateKey_ex(NULL, &pkeydata, sizeof(dsa_key),
800 mainctx, NULL))
801 && TEST_true(do_pkey_tofrom_data_select(key, "DSA"));
802
803 EVP_PKEY_free(key);
804 return ret;
805 }
806
663807 static int test_dsa_todata(void)
664808 {
665809 EVP_PKEY *pkey = NULL;
8801024 ADD_ALL_TESTS(test_d2i_AutoPrivateKey_ex, OSSL_NELEM(keydata));
8811025 #ifndef OPENSSL_NO_EC
8821026 ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 2);
1027 ADD_TEST(test_ec_tofrom_data_select);
1028 ADD_TEST(test_ecx_tofrom_data_select);
8831029 #else
8841030 ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 1);
8851031 #endif
8861032 #ifndef OPENSSL_NO_DSA
8871033 ADD_TEST(test_dsa_todata);
1034 ADD_TEST(test_dsa_tofrom_data_select);
8881035 #endif
1036 #ifndef OPENSSL_NO_DH
1037 ADD_TEST(test_dh_tofrom_data_select);
1038 #endif
1039 ADD_TEST(test_rsa_tofrom_data_select);
1040
8891041 ADD_TEST(test_pkey_todata_null);
8901042 ADD_TEST(test_pkey_export_null);
8911043 ADD_TEST(test_pkey_export);
00 /*
1 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
2525 #endif
2626
2727 #ifndef OPENSSL_NO_KEYPARAMS
28
29 struct pubkey {
30 int bad;
31 const unsigned char *key_bin;
32 size_t key_bin_len;
33 };
34
2835 # ifndef OPENSSL_NO_DH
2936 static const unsigned char dhparam_bin[] = {
3037 0x30,0x82,0x01,0x08,0x02,0x82,0x01,0x01,0x00,0xc0,0xd1,0x2e,0x14,0x18,0xbd,0x03,
4451 0xa7,0x8f,0x50,0x31,0xda,0xd0,0x0d,0xd3,0x0b,0xdb,0xad,0xed,0x94,0x92,0xff,0x83,
4552 0x06,0x7f,0x7f,0xd7,0x7b,0x42,0x5b,0xba,0x93,0x7a,0xeb,0x43,0x5f,0xce,0x59,0x26,
4653 0xe8,0x76,0xdc,0xee,0xe2,0xbe,0x36,0x7a,0x83,0x02,0x01,0x02
54 };
55 static const unsigned char dhkey_1[] = {
56 0x7a, 0x49, 0xcb, 0xc3, 0x25, 0x67, 0x7a, 0x61,
57 0xd0, 0x60, 0x81, 0x0f, 0xf6, 0xbd, 0x38, 0x82,
58 0xe7, 0x38, 0x8c, 0xe9, 0xd1, 0x04, 0x33, 0xbf,
59 0x8a, 0x03, 0x63, 0xb3, 0x05, 0x04, 0xb5, 0x1f,
60 0xba, 0x9f, 0x1a, 0x5f, 0x31, 0x3e, 0x96, 0x79,
61 0x88, 0x7d, 0x3f, 0x59, 0x6d, 0x3b, 0xf3, 0x2f,
62 0xf2, 0xa6, 0x43, 0x48, 0x64, 0x5a, 0x6a, 0x32,
63 0x1f, 0x24, 0x37, 0x62, 0x54, 0x3a, 0x7d, 0xab,
64 0x26, 0x77, 0x7c, 0xec, 0x57, 0x3c, 0xa4, 0xbd,
65 0x96, 0x9d, 0xaa, 0x3b, 0x0e, 0x9a, 0x55, 0x7e,
66 0x1d, 0xb4, 0x47, 0x5b, 0xea, 0x20, 0x3c, 0x6d,
67 0xbe, 0xd6, 0x70, 0x7d, 0xa8, 0x9e, 0x84, 0xb4,
68 0x03, 0x52, 0xf2, 0x08, 0x4c, 0x98, 0xd3, 0x4f,
69 0x58, 0xb3, 0xdf, 0xb4, 0xe6, 0xdc, 0x2c, 0x43,
70 0x55, 0xd1, 0xce, 0x2a, 0xb3, 0xfc, 0xe0, 0x29,
71 0x97, 0xd8, 0xd8, 0x62, 0xc6, 0x87, 0x0a, 0x1b,
72 0xfd, 0x72, 0x74, 0xe0, 0xa9, 0xfb, 0xfa, 0x91,
73 0xf2, 0xc1, 0x09, 0x93, 0xea, 0x63, 0xf6, 0x9a,
74 0x4b, 0xdf, 0x4e, 0xdf, 0x6b, 0xf9, 0xeb, 0xf6,
75 0x66, 0x3c, 0xfd, 0x6f, 0x68, 0xcb, 0xdb, 0x6e,
76 0x40, 0x65, 0xf7, 0xf2, 0x46, 0xe5, 0x0d, 0x9a,
77 0xd9, 0x6f, 0xcf, 0x28, 0x22, 0x8f, 0xca, 0x0b,
78 0x30, 0xa0, 0x9e, 0xa5, 0x13, 0xba, 0x72, 0x7f,
79 0x85, 0x3d, 0x02, 0x9c, 0x97, 0x8e, 0x6f, 0xea,
80 0x6d, 0x35, 0x4e, 0xd1, 0x78, 0x7d, 0x73, 0x60,
81 0x92, 0xa9, 0x12, 0xf4, 0x2a, 0xac, 0x17, 0x97,
82 0xf3, 0x7b, 0x79, 0x08, 0x69, 0xd1, 0x9e, 0xb5,
83 0xf8, 0x2a, 0x0a, 0x2b, 0x00, 0x7b, 0x16, 0x8d,
84 0x41, 0x82, 0x3a, 0x72, 0x58, 0x57, 0x80, 0x65,
85 0xae, 0x17, 0xbc, 0x3a, 0x5b, 0x7e, 0x5c, 0x2d,
86 0xae, 0xb2, 0xc2, 0x26, 0x20, 0x9a, 0xaa, 0x57,
87 0x4b, 0x7d, 0x43, 0x41, 0x96, 0x3f, 0xf0, 0x0d
88 };
89 /* smaller but still valid key */
90 static const unsigned char dhkey_2[] = {
91 0x73, 0xb2, 0x22, 0x91, 0x27, 0xb9, 0x45, 0xb0,
92 0xfd, 0x17, 0x66, 0x79, 0x9b, 0x32, 0x71, 0x92,
93 0x97, 0x1d, 0x70, 0x02, 0x37, 0x70, 0x79, 0x63,
94 0xed, 0x11, 0x22, 0xe9, 0xe6, 0xf8, 0xeb, 0xd7,
95 0x90, 0x00, 0xe6, 0x5c, 0x47, 0x02, 0xfb, 0x13,
96 0xca, 0x29, 0x14, 0x1e, 0xf4, 0x61, 0x58, 0xf6,
97 0xaa, 0xbb, 0xcf, 0xa7, 0x82, 0x9a, 0x9e, 0x7c,
98 0x4a, 0x05, 0x42, 0xed, 0x55, 0xd8, 0x08, 0x37,
99 0x06, 0x49, 0x9b, 0xda, 0xb3, 0xb9, 0xc9, 0xc0,
100 0x56, 0x26, 0xda, 0x60, 0x1d, 0xbc, 0x06, 0x0b,
101 0xb0, 0x94, 0x4b, 0x4e, 0x95, 0xf9, 0xb4, 0x2f,
102 0x4e, 0xad, 0xf8, 0xab, 0x2d, 0x19, 0xa2, 0xe6,
103 0x6d, 0x11, 0xfd, 0x9b, 0x5a, 0x2a, 0xb0, 0x81,
104 0x42, 0x4d, 0x86, 0x76, 0xd5, 0x9e, 0xaf, 0xf9,
105 0x6f, 0x79, 0xab, 0x1d, 0xfe, 0xd8, 0xc8, 0xba,
106 0xb6, 0xce, 0x03, 0x61, 0x48, 0x53, 0xd8, 0x0b,
107 0x83, 0xf0, 0xb0, 0x46, 0xa0, 0xea, 0x46, 0x60,
108 0x7a, 0x39, 0x4e, 0x46, 0x6a, 0xbb, 0x07, 0x6c,
109 0x8c, 0x7d, 0xb7, 0x7d, 0x5b, 0xe5, 0x24, 0xa5,
110 0xab, 0x41, 0x8a, 0xc4, 0x63, 0xf9, 0xce, 0x20,
111 0x6f, 0x58, 0x4f, 0x0e, 0x42, 0x82, 0x9e, 0x17,
112 0x53, 0xa6, 0xd6, 0x42, 0x3e, 0x80, 0x66, 0x6f,
113 0x2a, 0x1c, 0x30, 0x08, 0x01, 0x99, 0x5a, 0x4f,
114 0x72, 0x16, 0xed, 0xb0, 0xd6, 0x8c, 0xf0, 0x7a,
115 0x33, 0x15, 0xc4, 0x95, 0x65, 0xba, 0x11, 0x37,
116 0xa0, 0xcc, 0xe7, 0x45, 0x65, 0x4f, 0x17, 0x0a,
117 0x2c, 0x62, 0xc0, 0x65, 0x3b, 0x65, 0x2a, 0x56,
118 0xf7, 0x29, 0x8a, 0x9b, 0x1b, 0xbb, 0x0c, 0x40,
119 0xcd, 0x66, 0x4b, 0x4f, 0x2f, 0xba, 0xdb, 0x59,
120 0x93, 0x6d, 0x34, 0xf3, 0x8d, 0xde, 0x68, 0x99,
121 0x78, 0xfc, 0xac, 0x95, 0xd9, 0xa3, 0x74, 0xe6,
122 0x24, 0x96, 0x98, 0x6f, 0x64, 0x71, 0x76
123 };
124 /* 1 is not a valid key */
125 static const unsigned char dhkey_3[] = {
126 0x01
47127 };
48128 # endif
49129
91171 static const unsigned char ecparam_bin[] = {
92172 0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,0x01,0x07
93173 };
94 # endif
174 static const unsigned char eckey_1[] = {
175 0x04, 0xc8, 0x65, 0x45, 0x63, 0x73, 0xe5, 0x0a,
176 0x61, 0x1d, 0xcf, 0x60, 0x76, 0x2c, 0xe7, 0x36,
177 0x0b, 0x76, 0xc2, 0x92, 0xfc, 0xa4, 0x56, 0xee,
178 0xc2, 0x62, 0x05, 0x00, 0x80, 0xe4, 0x4f, 0x07,
179 0x3b, 0xf4, 0x59, 0xb8, 0xc3, 0xb3, 0x1f, 0x77,
180 0x36, 0x16, 0x4c, 0x72, 0x2a, 0xc0, 0x89, 0x89,
181 0xd6, 0x16, 0x14, 0xee, 0x2f, 0x5a, 0xde, 0x9e,
182 0x83, 0xc5, 0x78, 0xd0, 0x0b, 0x69, 0xb4, 0xb9,
183 0xf1
184 };
185 /* a modified key */
186 static const unsigned char eckey_2[] = {
187 0x04, 0xc8, 0x65, 0x45, 0x63, 0x73, 0xe5, 0x0a,
188 0x61, 0x1d, 0xcf, 0x60, 0x76, 0x2c, 0xe7, 0x36,
189 0x0b, 0x77, 0xc2, 0x92, 0xfc, 0xa4, 0x56, 0xee,
190 0xc2, 0x62, 0x05, 0x00, 0x80, 0xe4, 0x4f, 0x07,
191 0x3b, 0xf4, 0x59, 0xb8, 0xc3, 0xb3, 0x1f, 0x77,
192 0x36, 0x16, 0x4c, 0x72, 0x2a, 0xc0, 0x89, 0x89,
193 0xd6, 0x16, 0x14, 0xee, 0x2f, 0x5a, 0xde, 0x9e,
194 0x83, 0xc5, 0x78, 0xd0, 0x0b, 0x69, 0xb4, 0xb9,
195 0xf1
196 };
197 /* an added byte */
198 static const unsigned char eckey_3[] = {
199 0x04, 0xc8, 0x65, 0x45, 0x63, 0x73, 0xe5, 0x0a,
200 0x61, 0x1d, 0xcf, 0x60, 0x76, 0x2c, 0xe7, 0x36,
201 0x0b, 0x76, 0xc2, 0x92, 0xfc, 0xa4, 0x56, 0xee,
202 0xc2, 0x62, 0x05, 0x00, 0x80, 0xe4, 0x4f, 0x07,
203 0x3b, 0xf4, 0x59, 0xb8, 0xc3, 0xb3, 0x1f, 0x77,
204 0x36, 0x16, 0x4c, 0x72, 0x2a, 0xc0, 0x89, 0x89,
205 0xd6, 0x16, 0x14, 0xee, 0x2f, 0x5a, 0xde, 0x9e,
206 0x83, 0xc5, 0x78, 0xd0, 0x0b, 0x69, 0xb4, 0xb9,
207 0xf1, 0xaa
208 };
209 # endif
210
211 #define NUM_KEYS 10
95212
96213 static const struct {
97214 int type;
98215 const unsigned char *param_bin;
99216 size_t param_bin_len;
217 struct pubkey keys[NUM_KEYS];
100218 } pkey_params [] = {
101219 # ifndef OPENSSL_NO_DH
102 { EVP_PKEY_DH, dhparam_bin, sizeof(dhparam_bin) },
220 { EVP_PKEY_DH, dhparam_bin, sizeof(dhparam_bin),
221 { { 0, dhkey_1, sizeof(dhkey_1) },
222 { 0, dhkey_2, sizeof(dhkey_2) },
223 { 1, dhkey_3, sizeof(dhkey_3) },
224 { 1, dhkey_1, 0 },
225 { 1, dhparam_bin, sizeof(dhparam_bin) }
226 }
227 },
103228 # endif
104229 # ifndef OPENSSL_NO_DSA
105230 { EVP_PKEY_DSA, dsaparam_bin, sizeof(dsaparam_bin) },
106231 # endif
107232 # ifndef OPENSSL_NO_EC
108 { EVP_PKEY_EC, ecparam_bin, sizeof(ecparam_bin) }
233 { EVP_PKEY_EC, ecparam_bin, sizeof(ecparam_bin),
234 { { 0, eckey_1, sizeof(eckey_1) },
235 { 1, eckey_2, sizeof(eckey_2) },
236 { 1, eckey_3, sizeof(eckey_3) },
237 { 1, eckey_1, 0 },
238 { 1, eckey_1, sizeof(eckey_1) - 1 }
239 }
240 }
109241 # endif
110242 };
111243
113245 {
114246 int ret, out_len;
115247 BIO *in = NULL, *out = NULL;
116 EVP_PKEY_CTX *ctx = NULL;
117248 EVP_PKEY *in_key = NULL, *out_key = NULL;
118249 unsigned char *out_bin;
119250 int type = pkey_params[id].type;
120251
121 ret = TEST_ptr(ctx = EVP_PKEY_CTX_new_id(type, NULL))
122 && TEST_ptr(in = BIO_new_mem_buf(pkey_params[id].param_bin,
252 ret = TEST_ptr(in = BIO_new_mem_buf(pkey_params[id].param_bin,
123253 (int)pkey_params[id].param_bin_len))
124254 /* Load in pkey params from binary */
125255 && TEST_ptr(d2i_KeyParams_bio(type, &in_key, in))
136266 BIO_free(out);
137267 EVP_PKEY_free(in_key);
138268 EVP_PKEY_free(out_key);
139 EVP_PKEY_CTX_free(ctx);
269 return ret;
270 }
271
272 static int set_enc_pubkey_test(int id)
273 {
274 int ret, i;
275 BIO *in = NULL;
276 EVP_PKEY *in_key = NULL;
277 int type = pkey_params[id].type;
278 const struct pubkey *keys = pkey_params[id].keys;
279
280 if (keys[0].key_bin == NULL)
281 return TEST_skip("Not applicable test");
282
283 ret = TEST_ptr(in = BIO_new_mem_buf(pkey_params[id].param_bin,
284 (int)pkey_params[id].param_bin_len))
285 /* Load in pkey params from binary */
286 && TEST_ptr(d2i_KeyParams_bio(type, &in_key, in));
287
288 for (i = 0; ret && i < NUM_KEYS && keys[i].key_bin != NULL; i++) {
289 if (keys[i].bad) {
290 ERR_set_mark();
291 ret = ret
292 && TEST_int_le(EVP_PKEY_set1_encoded_public_key(in_key,
293 keys[i].key_bin,
294 keys[i].key_bin_len),
295 0);
296 ERR_pop_to_mark();
297 } else {
298 ret = ret
299 && TEST_int_gt(EVP_PKEY_set1_encoded_public_key(in_key,
300 keys[i].key_bin,
301 keys[i].key_bin_len),
302 0);
303 }
304 if (!ret)
305 TEST_info("Test key index #%d", i);
306 }
307
308 BIO_free(in);
309 EVP_PKEY_free(in_key);
140310 return ret;
141311 }
142312 #endif
147317 TEST_note("No DH/DSA/EC support");
148318 #else
149319 ADD_ALL_TESTS(params_bio_test, OSSL_NELEM(pkey_params));
320 ADD_ALL_TESTS(set_enc_pubkey_test, OSSL_NELEM(pkey_params));
150321 #endif
151322 return 1;
152323 }
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
127127 return ret;
128128 }
129129
130 static int pass_cb(char *buf, int size, int rwflag, void *u)
131 {
132 return 0;
133 }
134
135 static int pass_cb_error(char *buf, int size, int rwflag, void *u)
136 {
137 return -1;
138 }
139
130140 static int test_print_key_using_pem(const char *alg, const EVP_PKEY *pk)
131141 {
132142 BIO *membio = BIO_new(BIO_s_mem());
139149 !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk, EVP_aes_256_cbc(),
140150 (unsigned char *)"pass", 4,
141151 NULL, NULL))
152 /* Output zero-length passphrase encrypted private key in PEM form */
153 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
154 EVP_aes_256_cbc(),
155 (const char *)~0, 0,
156 NULL, NULL))
157 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
158 EVP_aes_256_cbc(),
159 NULL, 0, NULL, ""))
160 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
161 EVP_aes_256_cbc(),
162 NULL, 0, pass_cb, NULL))
163 || !TEST_false(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
164 EVP_aes_256_cbc(),
165 NULL, 0, pass_cb_error,
166 NULL))
167 #ifndef OPENSSL_NO_DES
168 || !TEST_true(PEM_write_bio_PKCS8PrivateKey_nid(
169 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
170 (const char *)~0, 0, NULL, NULL))
171 || !TEST_true(PEM_write_bio_PKCS8PrivateKey_nid(
172 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
173 NULL, ""))
174 || !TEST_true(PEM_write_bio_PKCS8PrivateKey_nid(
175 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
176 pass_cb, NULL))
177 || !TEST_false(PEM_write_bio_PKCS8PrivateKey_nid(
178 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
179 pass_cb_error, NULL))
180 #endif
142181 /* Private key in text form */
143182 || !TEST_int_gt(EVP_PKEY_print_private(membio, pk, 0, NULL), 0)
144183 || !TEST_true(compare_with_file(alg, PRIV_TEXT, membio))
11121151 return ret;
11131152 }
11141153
1115 #define CURVE_NAME 2
1116
11171154 static int test_fromdata_ec(void)
11181155 {
11191156 int ret = 0;
11251162 OSSL_PARAM *fromdata_params = NULL;
11261163 const char *alg = "EC";
11271164 const char *curve = "prime256v1";
1165 const char bad_curve[] = "nonexistent-curve";
1166 OSSL_PARAM nokey_params[2] = {
1167 OSSL_PARAM_END,
1168 OSSL_PARAM_END
1169 };
11281170 /* UNCOMPRESSED FORMAT */
11291171 static const unsigned char ec_pub_keydata[] = {
11301172 POINT_CONVERSION_UNCOMPRESSED,
11761218 goto err;
11771219 ctx = EVP_PKEY_CTX_new_from_name(NULL, alg, NULL);
11781220 if (!TEST_ptr(ctx))
1221 goto err;
1222
1223 /* try importing parameters with bad curve first */
1224 nokey_params[0] =
1225 OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME,
1226 (char *)bad_curve, sizeof(bad_curve));
1227 if (!TEST_int_eq(EVP_PKEY_fromdata_init(ctx), 1)
1228 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEY_PARAMETERS,
1229 nokey_params), 0)
1230 || !TEST_ptr_null(pk))
11791231 goto err;
11801232
11811233 if (!TEST_int_eq(EVP_PKEY_fromdata_init(ctx), 1)
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
573573 }
574574 ERR_clear_last_mark();
575575
576 cdat = OPENSSL_zalloc(sizeof(*cdat));
576 if (!TEST_ptr(cdat = OPENSSL_zalloc(sizeof(*cdat))))
577 return 0;
578
577579 cdat->cipher = cipher;
578580 cdat->fetched_cipher = fetched_cipher;
579581 cdat->enc = -1;
11741176 return 0;
11751177 }
11761178
1177 mdat = OPENSSL_zalloc(sizeof(*mdat));
1179 if (!TEST_ptr(mdat = OPENSSL_zalloc(sizeof(*mdat))))
1180 return 0;
1181
11781182 mdat->type = type;
1179 mdat->mac_name = OPENSSL_strdup(alg);
1183 if (!TEST_ptr(mdat->mac_name = OPENSSL_strdup(alg))) {
1184 OPENSSL_free(mdat);
1185 return 0;
1186 }
1187
11801188 mdat->mac = mac;
1181 mdat->controls = sk_OPENSSL_STRING_new_null();
1189 if (!TEST_ptr(mdat->controls = sk_OPENSSL_STRING_new_null())) {
1190 OPENSSL_free(mdat->mac_name);
1191 OPENSSL_free(mdat);
1192 return 0;
1193 }
1194
11821195 mdat->output_size = mdat->block_size = -1;
11831196 t->data = mdat;
11841197 return 1;
18421855 return parse_bin(value, &kdata->output, &kdata->output_len);
18431856 if (strcmp(keyword, "Ctrl") == 0)
18441857 return pkey_test_ctrl(t, kdata->ctx, value);
1858 if (strcmp(keyword, "KDFType") == 0) {
1859 OSSL_PARAM params[2];
1860
1861 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_TYPE,
1862 (char *)value, 0);
1863 params[1] = OSSL_PARAM_construct_end();
1864 if (EVP_PKEY_CTX_set_params(kdata->ctx, params) == 0)
1865 return -1;
1866 return 1;
1867 }
1868 if (strcmp(keyword, "KDFDigest") == 0) {
1869 OSSL_PARAM params[2];
1870
1871 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_EXCHANGE_PARAM_KDF_DIGEST,
1872 (char *)value, 0);
1873 params[1] = OSSL_PARAM_construct_end();
1874 if (EVP_PKEY_CTX_set_params(kdata->ctx, params) == 0)
1875 return -1;
1876 return 1;
1877 }
1878 if (strcmp(keyword, "CEKAlg") == 0) {
1879 OSSL_PARAM params[2];
1880
1881 params[0] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG,
1882 (char *)value, 0);
1883 params[1] = OSSL_PARAM_construct_end();
1884 if (EVP_PKEY_CTX_set_params(kdata->ctx, params) == 0)
1885 return -1;
1886 return 1;
1887 }
1888 if (strcmp(keyword, "KDFOutlen") == 0) {
1889 OSSL_PARAM params[2];
1890 char *endptr;
1891 size_t outlen = (size_t)strtoul(value, &endptr, 0);
1892
1893 if (endptr[0] != '\0')
1894 return -1;
1895
1896 params[0] = OSSL_PARAM_construct_size_t(OSSL_EXCHANGE_PARAM_KDF_OUTLEN,
1897 &outlen);
1898 params[1] = OSSL_PARAM_construct_end();
1899 if (EVP_PKEY_CTX_set_params(kdata->ctx, params) == 0)
1900 return -1;
1901 return 1;
1902 }
18451903 return 0;
18461904 }
18471905
18571915 goto err;
18581916 }
18591917
1860 if (EVP_PKEY_derive(dctx, NULL, &got_len) <= 0) {
1918 if (EVP_PKEY_derive(dctx, NULL, &got_len) <= 0
1919 || !TEST_size_t_ne(got_len, 0)) {
18611920 t->err = "DERIVE_ERROR";
18621921 goto err;
18631922 }
25152574 item->pr_entropyB_len);
25162575 params[1] = OSSL_PARAM_construct_end();
25172576 if (!TEST_true(EVP_RAND_CTX_set_params(expected->parent, params)))
2518 return 0;
2577 goto err;
25192578 }
25202579 if (!TEST_true(EVP_RAND_generate
25212580 (expected->ctx, got, got_len,
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
304304
305305 static int n_retries = 0;
306306 static int verify_retry_cb(X509_STORE_CTX *ctx, void *arg) {
307 int idx = SSL_get_ex_data_X509_STORE_CTX_idx();
308 SSL *ssl;
309
310 /* this should not happen but check anyway */
311 if (idx < 0
312 || (ssl = X509_STORE_CTX_get_ex_data(ctx, idx)) == NULL)
313 return 0;
314
307315 if (--n_retries < 0)
308316 return 1;
309 X509_STORE_CTX_set_error(ctx, X509_V_ERR_APPLICATION_VERIFICATION);
310 return -1;
317
318 return SSL_set_retry_verify(ssl);
311319 }
312320
313321 static int verify_accept_cb(X509_STORE_CTX *ctx, void *arg) {
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
4848 SSL_CTX_set_srp_username_callback(server_ctx, server_srp_cb);
4949 server_ctx_data->srp_user = OPENSSL_strdup(extra->server.srp_user);
5050 server_ctx_data->srp_password = OPENSSL_strdup(extra->server.srp_password);
51 if (server_ctx_data->srp_user == NULL || server_ctx_data->srp_password == NULL) {
52 OPENSSL_free(server_ctx_data->srp_user);
53 OPENSSL_free(server_ctx_data->srp_password);
54 server_ctx_data->srp_user = NULL;
55 server_ctx_data->srp_password = NULL;
56 return 0;
57 }
5158 SSL_CTX_set_srp_cb_arg(server_ctx, server_ctx_data);
5259 }
5360 if (extra->server2.srp_user != NULL) {
5663 SSL_CTX_set_srp_username_callback(server2_ctx, server_srp_cb);
5764 server2_ctx_data->srp_user = OPENSSL_strdup(extra->server2.srp_user);
5865 server2_ctx_data->srp_password = OPENSSL_strdup(extra->server2.srp_password);
66 if (server2_ctx_data->srp_user == NULL || server2_ctx_data->srp_password == NULL) {
67 OPENSSL_free(server2_ctx_data->srp_user);
68 OPENSSL_free(server2_ctx_data->srp_password);
69 server2_ctx_data->srp_user = NULL;
70 server2_ctx_data->srp_password = NULL;
71 return 0;
72 }
5973 SSL_CTX_set_srp_cb_arg(server2_ctx, server2_ctx_data);
6074 }
6175 if (extra->client.srp_user != NULL) {
6478 return 0;
6579 SSL_CTX_set_srp_client_pwd_callback(client_ctx, client_srp_cb);
6680 client_ctx_data->srp_password = OPENSSL_strdup(extra->client.srp_password);
81 if (client_ctx_data->srp_password == NULL)
82 return 0;
6783 SSL_CTX_set_srp_cb_arg(client_ctx, client_ctx_data);
6884 }
6985 return 1;
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
169169 return dhpkey;
170170 }
171171
172 EVP_PKEY *get_dh4096(OSSL_LIB_CTX *libctx)
173 {
174 BIGNUM *p = NULL, *g = NULL;
175 EVP_PKEY *dhpkey = NULL;
176
177 g = BN_new();
178 if (g == NULL || !BN_set_word(g, 2))
179 goto err;
180
181 p = BN_get_rfc3526_prime_4096(NULL);
182 if (p == NULL)
183 goto err;
184
185 dhpkey = get_dh_from_pg_bn(libctx, "DH", p, g, NULL);
186
187 err:
188 BN_free(p);
189 BN_free(g);
190 return dhpkey;
191 }
192
172193 #endif
00 /*
1 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1313 EVP_PKEY *get_dhx512(OSSL_LIB_CTX *libctx);
1414 EVP_PKEY *get_dh1024dsa(OSSL_LIB_CTX *libct);
1515 EVP_PKEY *get_dh2048(OSSL_LIB_CTX *libctx);
16 EVP_PKEY *get_dh4096(OSSL_LIB_CTX *libctx);
1617 #endif
244244 return ret;
245245 }
246246
247 static int test_hmac_copy_uninited(void)
248 {
249 const unsigned char key[24] = {0};
250 const unsigned char ct[166] = {0};
251 EVP_PKEY *pkey = NULL;
252 EVP_MD_CTX *ctx = NULL;
253 EVP_MD_CTX *ctx_tmp = NULL;
254 int res = 0;
255
256 if (!TEST_ptr(ctx = EVP_MD_CTX_new())
257 || !TEST_ptr(pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
258 key, sizeof(key)))
259 || !TEST_true(EVP_DigestSignInit(ctx, NULL, EVP_sha1(), NULL, pkey))
260 || !TEST_ptr(ctx_tmp = EVP_MD_CTX_new())
261 || !TEST_true(EVP_MD_CTX_copy(ctx_tmp, ctx)))
262 goto err;
263 EVP_MD_CTX_free(ctx);
264 ctx = ctx_tmp;
265 ctx_tmp = NULL;
266
267 if (!TEST_true(EVP_DigestSignUpdate(ctx, ct, sizeof(ct))))
268 goto err;
269 res = 1;
270 err:
271 EVP_MD_CTX_free(ctx);
272 EVP_MD_CTX_free(ctx_tmp);
273 EVP_PKEY_free(pkey);
274 return res;
275 }
276
247277 # ifndef OPENSSL_NO_MD5
248278 static char *pt(unsigned char *md, unsigned int len)
249279 {
265295 ADD_TEST(test_hmac_bad);
266296 ADD_TEST(test_hmac_run);
267297 ADD_TEST(test_hmac_copy);
298 ADD_TEST(test_hmac_copy_uninited);
268299 return 1;
269300 }
270301
00 /*
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
3 * Licensed under the OpenSSL license (the "License"). You may not use
3 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
55 * in the file LICENSE in the source distribution or at
66 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
33 *
44 * Licensed under the Apache License 2.0 (the "License"). You may not use
00 /*
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
224224 * Test 1: Encoder
225225 * Test 2: Store loader
226226 * Test 3: EVP_RAND
227 * Test 4-7: As above, but additionally with a query string
227228 */
228229 static int fetch_test(int tst)
229230 {
235236 OSSL_STORE_LOADER *loader = NULL;
236237 int testresult = 0;
237238 unsigned char buf[32];
239 int query = tst > 3;
238240
239241 if (!TEST_ptr(libctx))
240242 goto err;
245247 || !TEST_ptr(dummyprov = OSSL_PROVIDER_load(libctx, "dummy-prov")))
246248 goto err;
247249
248 switch(tst) {
250 switch (tst % 4) {
249251 case 0:
250 decoder = OSSL_DECODER_fetch(libctx, "DUMMY", NULL);
252 decoder = OSSL_DECODER_fetch(libctx, "DUMMY",
253 query ? "provider=dummy" : NULL);
251254 if (!TEST_ptr(decoder))
252255 goto err;
253256 break;
254257 case 1:
255 encoder = OSSL_ENCODER_fetch(libctx, "DUMMY", NULL);
258 encoder = OSSL_ENCODER_fetch(libctx, "DUMMY",
259 query ? "provider=dummy" : NULL);
256260 if (!TEST_ptr(encoder))
257261 goto err;
258262 break;
259263 case 2:
260 loader = OSSL_STORE_LOADER_fetch(libctx, "DUMMY", NULL);
264 loader = OSSL_STORE_LOADER_fetch(libctx, "DUMMY",
265 query ? "provider=dummy" : NULL);
261266 if (!TEST_ptr(loader))
262267 goto err;
263268 break;
264269 case 3:
265 if (!TEST_true(RAND_set_DRBG_type(libctx, "DUMMY", NULL, NULL, NULL))
270 if (!TEST_true(RAND_set_DRBG_type(libctx, "DUMMY",
271 query ? "provider=dummy" : NULL,
272 NULL, NULL))
266273 || !TEST_int_ge(RAND_bytes_ex(libctx, buf, sizeof(buf), 0), 1))
267274 goto err;
268275 break;
283290
284291 int setup_tests(void)
285292 {
286 ADD_ALL_TESTS(fetch_test, 4);
287
288 return 1;
289 }
293 ADD_ALL_TESTS(fetch_test, 8);
294
295 return 1;
296 }
7575 # Drop the first space and everything following it
7676 s| .*||;
7777 # Drop OpenSSL dynamic version information if there is any
78 s|\@\@OPENSSL_[0-9._]+[a-z]?$||;
78 s|\@\@.+$||;
7979 # Return the result
8080 $_
8181 }
00 #! /usr/bin/env perl
1 # Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 # Copyright 2021 [UnionTech](https://www.uniontech.com). All Rights Reserved.
33 #
4 # Licensed under the OpenSSL license (the "License"). You may not use
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
55 # this file except in compliance with the License. You can obtain a copy
66 # in the file LICENSE in the source distribution or at
77 # https://www.openssl.org/source/license.html
0 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
0 # Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
11 #
22 # Licensed under the Apache License 2.0 (the "License"). You may not use
33 # this file except in compliance with the License. You can obtain a copy
27982798 ModSqrt = a1d52989f12f204d3d2167d9b1e6c8a6174c0c786a979a5952383b7b8bd186
27992799 A = 2eee37cf06228a387788188e650bc6d8a2ff402931443f69156a29155eca07dcb45f3aac238d92943c0c25c896098716baa433f25bd696a142f5a69d5d937e81
28002800 P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
2801
2802 # Negative testcases for BN_mod_sqrt()
2803
2804 # This one triggers an infinite loop with unfixed implementation
2805 # It should just fail.
2806 ModSqrt = -1
2807 A = 20a7ee
2808 P = 460201
2809
2810 ModSqrt = -1
2811 A = 65bebdb00a96fc814ec44b81f98b59fba3c30203928fa5214c51e0a97091645280c947b005847f239758482b9bfc45b066fde340d1fe32fc9c1bf02e1b2d0ed
2812 P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
00 #! /usr/bin/env perl
1 # Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
117117 # expect => [ 'BEGIN DH PARAMETERS', 'G: 5' ],
118118 # message => 'DH safe prime generator using an alias',
119119 # },
120 {
120 {
121121 algorithm => 'DHX',
122122 pkeyopts => [ 'type:generator', 'safeprime-generator:5'],
123123 expect => [ 'ERROR' ],
124124 message => 'safe prime generator should fail for DHX',
125 },
125 }
126126 );
127127
128128 plan skip_all => "DH isn't supported in this build" if disabled("dh");
139139 push(@pkeyopts, '-pkeyopt');
140140 push(@pkeyopts, $_);
141141 }
142 my @lines = run(app(['openssl', 'genpkey', '-genparam',
142 my @lines;
143 if ($expected[0] eq 'ERROR') {
144 @lines = run(app(['openssl', 'genpkey', '-genparam',
145 '-algorithm', $alg, '-text', @pkeyopts],
146 stderr => undef),
147 capture => 1);
148 } else {
149 @lines = run(app(['openssl', 'genpkey', '-genparam',
143150 '-algorithm', $alg, '-text', @pkeyopts]),
144 capture => 1);
151 capture => 1);
152 }
145153 ok(compareline(\@lines, \@expected), $msg);
146154 }
147155
156164 }
157165 print "-----------------\n";
158166 foreach (@lines) {
159 print $_;
167 print "# ".$_;
160168 }
161169 print "-----------------\n";
162170 foreach my $ex (@expected) {
00 #! /usr/bin/env perl
1 # Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
2424
2525 plan tests =>
2626 ($no_fips ? 0 : 3) # Extra FIPS related tests
27 + 13;
27 + 15;
2828
2929 # We want to know that an absurdly small number of bits isn't support
3030 is(run(app([ 'openssl', 'genpkey', '-out', 'genrsatest.pem',
102102 "genrsa -f4 $good");
103103 ok(run(app([ 'openssl', 'rsa', '-check', '-in', 'genrsatest.pem', '-noout' ])),
104104 "rsa -check");
105 ok(run(app([ 'openssl', 'rsa', '-in', 'genrsatest.pem', '-out', 'genrsatest-enc.pem',
106 '-aes256', '-passout', 'pass:x' ])),
107 "rsa encrypt");
108 ok(run(app([ 'openssl', 'rsa', '-in', 'genrsatest-enc.pem', '-passin', 'pass:x' ])),
109 "rsa decrypt");
105110
106111 unless ($no_fips) {
107112 my $provconf = srctop_file("test", "fips-and-base.cnf");
00 #! /usr/bin/env perl
1 # Copyright 2017-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2017-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
1111
1212 use File::Spec;
1313 use File::Basename;
14 use OpenSSL::Test qw/:DEFAULT with srctop_file bldtop_file/;
14 use OpenSSL::Test qw/:DEFAULT with srctop_file bldtop_dir/;
1515 use OpenSSL::Test::Utils;
1616
1717 setup("test_dgst");
112112 my $testdata = srctop_file('test', 'data.bin');
113113 # intentionally using -engine twice, please do not remove the duplicate line
114114 my @macdata = run(app(['openssl', 'dgst', '-sha1',
115 '-engine', $^O eq 'linux' ? bldtop_file("engines", "ossltest.so") : "ossltest",
116 '-engine', $^O eq 'linux' ? bldtop_file("engines", "ossltest.so") : "ossltest",
115 '-engine', "ossltest",
116 '-engine', "ossltest",
117117 $testdata]), capture => 1);
118118 chomp(@macdata);
119119 my $expected = qr/SHA1\(\Q$testdata\E\)= 000102030405060708090a0b0c0d0e0f10111213/;
00 #! /usr/bin/env perl
1 # Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
1414
1515 setup("test_req");
1616
17 plan tests => 43;
17 plan tests => 44;
1818
1919 require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
2020
4848 ok(!run(app([@addext_args, "-addext", $val, "-addext", $val3])));
4949 ok(!run(app([@addext_args, "-addext", $val2, "-addext", $val3])));
5050
51 # If a CSR is provided with neither of -key or -CA/-CAkey, this should fail.
52 ok(!run(app(["openssl", "req", "-x509",
53 "-in", srctop_file(@certs, "x509-check.csr"),
54 "-out", "testreq.pem"])));
55
5156 subtest "generating alt certificate requests with RSA" => sub {
5257 plan tests => 3;
5358
382387 my $ca_key = srctop_file(@certs, "ca-key.pem");
383388 my $key = $is_ca ? $ca_key : srctop_file(@certs, "ee-key.pem");
384389 my @cmd = ("openssl", "req", "-config", "", "-x509",
385 "-key", $key, "-subj", "/CN=$cn", @_, "-out", $cert);
390 "-subj", "/CN=$cn", @_, "-out", $cert);
391 push(@cmd, ("-key", $key)) if $ss;
386392 push(@cmd, ("-CA", $ca_cert, "-CAkey", $ca_key)) unless $ss;
387393 ok(run(app([@cmd])), "generate $cert");
388394 }
441447 #TODO strict_verify($cert, 1); # should be accepted because RFC 5280 does not apply
442448
443449 $cert = "v3_EE_default_KIDs.pem";
444 generate_cert($cert, "-addext", "keyUsage = dataEncipherment");
450 generate_cert($cert, "-addext", "keyUsage = dataEncipherment",
451 "-key", srctop_file(@certs, "ee-key.pem"));
445452 cert_ext_has_n_different_lines($cert, 4, $SKID_AKID); # SKID != AKID
446453 strict_verify($cert, 1, $ca_cert);
447454
448455 $cert = "v3_EE_no_AKID.pem";
449 generate_cert($cert, "-addext", "authorityKeyIdentifier = none");
456 generate_cert($cert, "-addext", "authorityKeyIdentifier = none",
457 "-key", srctop_file(@certs, "ee-key.pem"));
450458 has_SKID($cert, 1);
451459 has_AKID($cert, 0);
452460 strict_verify($cert, 0, $ca_cert);
00 #
1 # Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
1010 # PrivPubKeyPair Sign Verify VerifyRecover
1111 # and continue until a blank line. Lines starting with a pound sign are ignored.
1212
13 Title = DES3 Test
13 Title = DES3 Tests
1414
1515 # DES EDE3 CBC tests (from destest)
1616 Cipher = DES-EDE3-CBC
1919 Plaintext = 37363534333231204E6F77206973207468652074696D6520666F722000000000
2020 Ciphertext = 3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
2121 NextIV = 1c673812cfde9675
22
23 # DES EDE3 ECB test
24 Cipher = DES-EDE3-ECB
25 Key = 0123456789abcdeff1e0d3c2b5a49786fedcba9876543210
26 Plaintext = 37363534333231204E6F77206973207468652074696D6520666F722000000000
27 Ciphertext = 62c10cc9efbf15aaa5ae2e487b690e56d8b1dfb8f5c5b293855e77dd9024b1b1
28
29 # DES EDE ECB test
30 Availablein = default
31 Cipher = DES-EDE-ECB
32 Key = 0123456789abcdeffedcba9876543210
33 Plaintext = 37363534333231204E6F77206973207468652074696D6520666F722000000000
34 Ciphertext = 4d1332e49f380e23d80a0d8b2bae5e4e6a0094171abcfc27df2bfd40da9f4e4d
00 #
1 # Copyright 2001-2020 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
9191 PeerKey=ffdhe2048-2-pub
9292 Ctrl = dh_pad:1
9393 SharedSecret=00006620DD85B56EE8540C8040CAC46B7385344A164E4DBDF521F7D99F88FA68EDD295A45E36E0BBD5FF5DE84598824E2CA52ED82ACA918CAECC6B22846D0FC6F0203E8B6963964D11E9E704F83AF1D60E9B1931139E9E9967C4665A831A75D99359A8BA80DD5921E74379AF4CA8DB453EDBC5E669AB17A5254CA6C96794CD5196BE90AF37742C8F6812515FFCC45B08F4158EFF9559F1AEF3665B3D91519DCBC6DF22CD6DA521B86613558602E73D2CA4666972F7D2CB6B46299B1DF2DA29A2A2D99D105E10CB553D6738A9B1DB2A0314C3CF30642D5C44695623D8B95C4426BEA830FB51816B4F086945E9B12A445F42DD68610E3F378A6E69A383D13D85BF
94
95 # The following two testcases check that the padding is implicitly enabled
96 # with X942KDF-ASN1 KDF.
97 # The plain shared secret for these keys needs padding as seen above.
98 Derive=ffdhe2048-1
99 PeerKey=ffdhe2048-2-pub
100 KDFType=X942KDF-ASN1
101 KDFOutlen=32
102 KDFDigest=SHA-256
103 CEKAlg=id-aes128-wrap
104 Ctrl = dh_pad:1
105 SharedSecret=89A249DF4EE9033B89C2B4E52072A736D94F51143A1ED5C8F1E91FCBEBE09654
106
107 Derive=ffdhe2048-2
108 PeerKey=ffdhe2048-1-pub
109 KDFType=X942KDF-ASN1
110 KDFOutlen=32
111 KDFDigest=SHA-256
112 CEKAlg=id-aes128-wrap
113 Ctrl = dh_pad:0
114 SharedSecret=89A249DF4EE9033B89C2B4E52072A736D94F51143A1ED5C8F1E91FCBEBE09654
94115
95116 PrivateKey=ffdhe3072-1
96117 -----BEGIN PRIVATE KEY-----
00 #! /usr/bin/env perl
1 # Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
66 # https://www.openssl.org/source/license.html
77
88
9 use OpenSSL::Test qw/:DEFAULT srctop_file/;
9 use OpenSSL::Test qw/:DEFAULT srctop_dir/;
1010
1111 setup("test_verify_extra");
1212
1313 plan tests => 1;
1414
1515 ok(run(test(["verify_extra_test",
16 srctop_file("test", "certs", "rootCA.pem"),
17 srctop_file("test", "certs", "roots.pem"),
18 srctop_file("test", "certs", "untrusted.pem"),
19 srctop_file("test", "certs", "bad.pem"),
20 srctop_file("test", "certs", "sm2-csr.pem")])));
16 srctop_dir("test", "certs")])));
00 #! /usr/bin/env perl
1 # Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
345345 }
346346
347347
348 # plan tests => 11;
349
350348 subtest 'standard SSL tests' => sub {
351349 ######################################################################
352 plan tests => 13;
350 plan tests => 19;
353351
354352 SKIP: {
355353 skip "SSLv3 is not supported by this OpenSSL build", 4
377375 }
378376
379377 SKIP: {
380 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 8
378 skip "Neither SSLv3 nor any TLS version are supported by this OpenSSL build", 14
381379 if $no_anytls;
382380
383381 SKIP: {
405403 'test sslv2/sslv3 with both client and server authentication via BIO pair and app verify');
406404
407405 SKIP: {
408 skip "No IPv4 available on this machine", 1
406 skip "No IPv4 available on this machine", 4
409407 unless !disabled("sock") && have_IPv4();
410408 ok(run(test([@ssltest, "-ipv4"])),
411409 'test TLS via IPv4');
412 }
413
414 SKIP: {
415 skip "No IPv6 available on this machine", 1
410 ok(run(test([@ssltest, "-ipv4", "-client_ktls"])),
411 'test TLS via IPv4 + ktls(client)');
412 ok(run(test([@ssltest, "-ipv4", "-server_ktls"])),
413 'test TLS via IPv4 + ktls(server)');
414 ok(run(test([@ssltest, "-ipv4", "-client_ktls", "-server_ktls"])),
415 'test TLS via IPv4 + ktls');
416 }
417
418 SKIP: {
419 skip "No IPv6 available on this machine", 4
416420 unless !disabled("sock") && have_IPv6();
417421 ok(run(test([@ssltest, "-ipv6"])),
418422 'test TLS via IPv6');
423 ok(run(test([@ssltest, "-ipv6", "-client_ktls"])),
424 'test TLS via IPv6 + ktls(client)');
425 ok(run(test([@ssltest, "-ipv6", "-server_ktls"])),
426 'test TLS via IPv6 + ktls(client)');
427 ok(run(test([@ssltest, "-ipv6", "-client_ktls", "-server_ktls"])),
428 'test TLS via IPv6 + ktls');
419429 }
420430 }
421431 };
519529 subtest 'RSA/(EC)DHE/PSK tests' => sub {
520530 ######################################################################
521531
522 plan tests => 6;
532 plan tests => 10;
523533
524534 SKIP: {
525535 skip "TLSv1.0 is not supported by this OpenSSL build", 6
556566
557567 ok(run(test([@ssltest, "-bio_pair", "-tls1", "-cipher", "PSK", "-psk", "abc123"])),
558568 'test tls1 with PSK via BIO pair');
559 }
569 }
560570
561571 SKIP: {
562572 skip "skipping auto DH PSK tests", 1
564574
565575 ok(run(test(['ssl_old_test', '-psk', '0102030405', '-cipher', '@SECLEVEL=2:DHE-PSK-AES128-CCM'])),
566576 'test auto DH meets security strength');
577 }
578 }
579
580 SKIP: {
581 skip "TLSv1.1 is not supported by this OpenSSL build", 4
582 if $no_tls1_1;
583
584 SKIP: {
585 skip "skipping auto DHE PSK test at SECLEVEL 3", 1
586 if ($no_dh || $no_psk);
587
588 ok(run(test(['ssl_old_test', '-tls1_1', '-dhe4096', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:DHE-PSK-AES256-CBC-SHA384'])),
589 'test auto DHE PSK meets security strength');
590 }
591
592 SKIP: {
593 skip "skipping auto ECDHE PSK test at SECLEVEL 3", 1
594 if ($no_ec || $no_psk);
595
596 ok(run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:ECDHE-PSK-AES256-CBC-SHA384'])),
597 'test auto ECDHE PSK meets security strength');
598 }
599
600 SKIP: {
601 skip "skipping no RSA PSK at SECLEVEL 3 test", 1
602 if ($no_rsa || $no_psk);
603
604 ok(!run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:RSA-PSK-AES256-CBC-SHA384'])),
605 'test auto RSA PSK does not meet security level 3 requirements (PFS)');
606 }
607
608 SKIP: {
609 skip "skipping no PSK at SECLEVEL 3 test", 1
610 if ($no_psk);
611
612 ok(!run(test(['ssl_old_test', '-tls1_1', '-no_dhe', '-psk', '0102030405', '-cipher', '@SECLEVEL=3:PSK-AES256-CBC-SHA384'])),
613 'test auto PSK does not meet security level 3 requirements (PFS)');
567614 }
568615 }
569616
00 #! /usr/bin/env perl
1 # Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
308308 my $ret =
309309 $harness->runtests(map { [ abs2rel($_, rel2abs(curdir())), basename($_) ] }
310310 @preps);
311 die if $ret->has_errors;
312 $ret =
313 $harness->runtests(map { [ abs2rel($_, rel2abs(curdir())), basename($_) ] }
314 sort { reorder($a) cmp reorder($b) } keys %tests);
311
312 if (ref($ret) ne "TAP::Parser::Aggregator" || !$ret->has_errors) {
313 $ret =
314 $harness->runtests(map { [ abs2rel($_, rel2abs(curdir())), basename($_) ] }
315 sort { reorder($a) cmp reorder($b) } keys %tests);
316 }
315317
316318 # If this is a TAP::Parser::Aggregator, $ret->has_errors is the count of
317319 # tests that failed. We don't bother with that exact number, just exit
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
113113 TEST_error("int must not be wider than size_t");
114114 return 0;
115115 }
116
117 /* SIZE_MAX is always greater than 2*INT_MAX */
118 if (SIZE_MAX - INT_MAX <= INT_MAX) {
119 TEST_error("SIZE_MAX must exceed 2*INT_MAX");
120 return 0;
121 }
122
116123 return 1;
117124 }
118125
00 /*
1 * Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright 2021 UnionTech. All Rights Reserved.
33 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
55 * this file except in compliance with the License. You can obtain a copy
66 * in the file LICENSE in the source distribution or at
77 * https://www.openssl.org/source/license.html
00 /*
1 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
22 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
33 * Copyright 2005 Nokia. All rights reserved.
44 *
629629 fprintf(stderr,
630630 " -dhe512 - use 512 bit key for DHE (to test failure)\n");
631631 fprintf(stderr,
632 " -dhe1024 - use 1024 bit key (safe prime) for DHE (default, no-op)\n");
632 " -dhe1024dsa - use 1024 bit key (with 160-bit subprime) for DHE\n");
633633 fprintf(stderr,
634 " -dhe1024dsa - use 1024 bit key (with 160-bit subprime) for DHE\n");
634 " -dhe2048 - use 2048 bit key (safe prime) for DHE (default, no-op)\n");
635 fprintf(stderr,
636 " -dhe4096 - use 4096 bit key (safe prime) for DHE\n");
635637 #endif
636638 fprintf(stderr, " -no_dhe - disable DHE\n");
637639 #ifndef OPENSSL_NO_EC
645647 #endif
646648 #ifndef OPENSSL_NO_TLS1
647649 fprintf(stderr, " -tls1 - use TLSv1\n");
650 #endif
651 #ifndef OPENSSL_NO_TLS1_1
652 fprintf(stderr, " -tls1_1 - use TLSv1.1\n");
653 #endif
654 #ifndef OPENSSL_NO_TLS1_2
655 fprintf(stderr, " -tls1_2 - use TLSv1.2\n");
648656 #endif
649657 #ifndef OPENSSL_NO_DTLS
650658 fprintf(stderr, " -dtls - use DTLS\n");
710718 fprintf(stderr, " -client_sess_in <file> - Read the client session from a file\n");
711719 fprintf(stderr, " -should_reuse <number> - The expected state of reusing the session\n");
712720 fprintf(stderr, " -no_ticket - do not issue TLS session ticket\n");
721 fprintf(stderr, " -client_ktls - try to enable client KTLS\n");
722 fprintf(stderr, " -server_ktls - try to enable server KTLS\n");
713723 fprintf(stderr, " -provider <name> - Load the given provider into the library context\n");
714724 fprintf(stderr, " -config <cnf> - Load the given config file into the library context\n");
715725 }
870880 int badop = 0;
871881 enum { BIO_MEM, BIO_PAIR, BIO_IPV4, BIO_IPV6 } bio_type = BIO_MEM;
872882 int force = 0;
873 int dtls1 = 0, dtls12 = 0, dtls = 0, tls1 = 0, tls1_2 = 0, ssl3 = 0;
883 int dtls1 = 0, dtls12 = 0, dtls = 0, tls1 = 0, tls1_1 = 0, tls1_2 = 0, ssl3 = 0;
874884 int ret = EXIT_FAILURE;
875885 int client_auth = 0;
876886 int server_auth = 0, i;
882892 int number = 1, reuse = 0;
883893 int should_reuse = -1;
884894 int no_ticket = 0;
895 int client_ktls = 0, server_ktls = 0;
885896 long bytes = 256L;
886897 #ifndef OPENSSL_NO_DH
887898 EVP_PKEY *dhpkey;
888 int dhe512 = 0, dhe1024dsa = 0;
899 int dhe512 = 0, dhe1024dsa = 0, dhe4096 = 0;
889900 int no_dhe = 0;
890901 #endif
891902 int no_psk = 0;
980991 dhe512 = 1;
981992 else if (strcmp(*argv, "-dhe1024dsa") == 0)
982993 dhe1024dsa = 1;
994 else if (strcmp(*argv, "-dhe4096") == 0)
995 dhe4096 = 1;
983996 #endif
984997 else if (strcmp(*argv, "-no_ecdhe") == 0)
985998 /* obsolete */;
9981011 }
9991012 else if (strcmp(*argv, "-tls1_2") == 0) {
10001013 tls1_2 = 1;
1014 } else if (strcmp(*argv, "-tls1_1") == 0) {
1015 tls1_1 = 1;
10011016 } else if (strcmp(*argv, "-tls1") == 0) {
10021017 tls1 = 1;
10031018 } else if (strcmp(*argv, "-ssl3") == 0) {
11661181 should_reuse = !!atoi(*(++argv));
11671182 } else if (strcmp(*argv, "-no_ticket") == 0) {
11681183 no_ticket = 1;
1184 } else if (strcmp(*argv, "-client_ktls") == 0) {
1185 client_ktls = 1;
1186 } else if (strcmp(*argv, "-server_ktls") == 0) {
1187 server_ktls = 1;
11691188 } else if (strcmp(*argv, "-provider") == 0) {
11701189 if (--argc < 1)
11711190 goto bad;
12161235 goto end;
12171236 }
12181237
1219 if (ssl3 + tls1 + tls1_2 + dtls + dtls1 + dtls12 > 1) {
1220 fprintf(stderr, "At most one of -ssl3, -tls1, -tls1_2, -dtls, -dtls1 or -dtls12 should "
1238 if (ssl3 + tls1 + tls1_1 + tls1_2 + dtls + dtls1 + dtls12 > 1) {
1239 fprintf(stderr, "At most one of -ssl3, -tls1, -tls1_1, -tls1_2, -dtls, -dtls1 or -dtls12 should "
12211240 "be requested.\n");
12221241 EXIT(1);
12231242 }
12291248 #endif
12301249 #ifdef OPENSSL_NO_TLS1
12311250 if (tls1)
1251 no_protocol = 1;
1252 else
1253 #endif
1254 #ifdef OPENSSL_NO_TLS1_1
1255 if (tls1_1)
12321256 no_protocol = 1;
12331257 else
12341258 #endif
12611285 goto end;
12621286 }
12631287
1264 if (!ssl3 && !tls1 && !tls1_2 && !dtls && !dtls1 && !dtls12 && number > 1
1288 if (!ssl3 && !tls1 && !tls1_1 && !tls1_2 && !dtls && !dtls1 && !dtls12 && number > 1
12651289 && !reuse && !force) {
12661290 fprintf(stderr, "This case cannot work. Use -f to perform "
12671291 "the test anyway (and\n-d to see what happens), "
1268 "or add one of -ssl3, -tls1, -tls1_2, -dtls, -dtls1, -dtls12, -reuse\n"
1292 "or add one of -ssl3, -tls1, -tls1_1, -tls1_2, -dtls, -dtls1, -dtls12, -reuse\n"
12691293 "to avoid protocol mismatch.\n");
12701294 EXIT(1);
12711295 }
13171341 } else if (tls1) {
13181342 min_version = TLS1_VERSION;
13191343 max_version = TLS1_VERSION;
1344 } else if (tls1_1) {
1345 min_version = TLS1_1_VERSION;
1346 max_version = TLS1_1_VERSION;
13201347 } else if (tls1_2) {
13211348 min_version = TLS1_2_VERSION;
13221349 max_version = TLS1_2_VERSION;
14811508 dhpkey = get_dh1024dsa(libctx);
14821509 else if (dhe512)
14831510 dhpkey = get_dh512(libctx);
1511 else if (dhe4096)
1512 dhpkey = get_dh4096(libctx);
14841513 else
14851514 dhpkey = get_dh2048(libctx);
14861515
17231752
17241753 if (sn_client)
17251754 SSL_set_tlsext_host_name(c_ssl, sn_client);
1755 if (client_ktls)
1756 SSL_set_options(c_ssl, SSL_OP_ENABLE_KTLS);
1757 if (server_ktls)
1758 SSL_set_options(s_ssl, SSL_OP_ENABLE_KTLS);
17261759
17271760 if (!set_protocol_version(server_min_proto, s_ssl, SSL_CTRL_SET_MIN_PROTO_VERSION))
17281761 goto end;
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
556556 static int verify_retry_cb(X509_STORE_CTX *ctx, void *arg)
557557 {
558558 int res = X509_verify_cert(ctx);
559 int idx = SSL_get_ex_data_X509_STORE_CTX_idx();
560 SSL *ssl;
561
562 /* this should not happen but check anyway */
563 if (idx < 0
564 || (ssl = X509_STORE_CTX_get_ex_data(ctx, idx)) == NULL)
565 return 0;
559566
560567 if (res == 0 && X509_STORE_CTX_get_error(ctx) ==
561568 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)
562 return -1; /* indicate SSL_ERROR_WANT_RETRY_VERIFY */
569 /* indicate SSL_ERROR_WANT_RETRY_VERIFY */
570 return SSL_set_retry_verify(ssl);
571
563572 return res;
564573 }
565574
671680 return ret;
672681 }
673682
683 static int get_password_cb(char *buf, int size, int rw_flag, void *userdata)
684 {
685 static const char pass[] = "testpass";
686
687 if (!TEST_int_eq(size, PEM_BUFSIZE))
688 return -1;
689
690 memcpy(buf, pass, sizeof(pass) - 1);
691 return sizeof(pass) - 1;
692 }
693
674694 static int test_ssl_ctx_build_cert_chain(void)
675695 {
676696 int ret = 0;
677697 SSL_CTX *ctx = NULL;
678 char *skey = test_mk_file_path(certsdir, "leaf.key");
698 char *skey = test_mk_file_path(certsdir, "leaf-encrypted.key");
679699 char *leaf_chain = test_mk_file_path(certsdir, "leaf-chain.pem");
680700
681701 if (!TEST_ptr(ctx = SSL_CTX_new_ex(libctx, NULL, TLS_server_method())))
682702 goto end;
703 SSL_CTX_set_default_passwd_cb(ctx, get_password_cb);
683704 /* leaf_chain contains leaf + subinterCA + interCA + rootCA */
684705 if (!TEST_int_eq(SSL_CTX_use_certificate_chain_file(ctx, leaf_chain), 1)
685706 || !TEST_int_eq(SSL_CTX_use_PrivateKey_file(ctx, skey,
80618082 else
80628083 cert_cb_cnt = 0;
80638084
8064 if (tst == 2)
8065 snictx = SSL_CTX_new(TLS_server_method());
8085 if (tst == 2) {
8086 snictx = SSL_CTX_new_ex(libctx, NULL, TLS_server_method());
8087 if (!TEST_ptr(snictx))
8088 goto end;
8089 }
8090
80668091 SSL_CTX_set_cert_cb(sctx, cert_cb, snictx);
80678092
80688093 if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
00 /*
1 * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
3232 int res;
3333
3434 res = TEST_true(CRYPTO_THREAD_read_lock(lock))
35 && TEST_true(CRYPTO_THREAD_unlock(lock))
36 && TEST_true(CRYPTO_THREAD_write_lock(lock))
3537 && TEST_true(CRYPTO_THREAD_unlock(lock));
3638
3739 CRYPTO_THREAD_lock_free(lock);
00 /*
1 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
839839 {
840840 OSSL_LIB_CTX *libctx = OSSL_LIB_CTX_new();
841841
842 if (libctx == NULL)
843 return 0;
844
842845 *provctx = libctx;
843846
844847 /*
6767 if (!c_obj_add_sigid(handle, SIGALG_OID, DIGEST_SN, SIG_LN))
6868 return 0;
6969
70 /* additional tests checking empty digest algs are accepted, too */
71 if (!c_obj_add_sigid(handle, SIGALG_OID, "", SIG_LN))
72 return 0;
73 if (!c_obj_add_sigid(handle, SIGALG_OID, NULL, SIG_LN))
74 return 0;
75 /* checking wrong digest alg name is rejected: */
76 if (c_obj_add_sigid(handle, SIGALG_OID, "NonsenseAlg", SIG_LN))
77 return 0;
78
7079 return 1;
7180 }
7281
00 /*
1 * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
1 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
22 *
33 * Licensed under the Apache License 2.0 (the "License"). You may not use
44 * this file except in compliance with the License. You can obtain a copy
1111 #include <openssl/crypto.h>
1212 #include <openssl/bio.h>
1313 #include <openssl/x509.h>
14 #include <openssl/x509v3.h>
1415 #include <openssl/pem.h>
1516 #include <openssl/err.h>
1617 #include "testutil.h"
1718
18 static const char *root_f;
19 static const char *roots_f;
20 static const char *untrusted_f;
21 static const char *bad_f;
22 static const char *req_f;
19 static const char *certs_dir;
20 static char *root_f = NULL;
21 static char *roots_f = NULL;
22 static char *untrusted_f = NULL;
23 static char *bad_f = NULL;
24 static char *req_f = NULL;
25 static char *sroot_cert = NULL;
26 static char *ca_cert = NULL;
27 static char *ee_cert = NULL;
2328
2429 #define load_cert_from_file(file) load_cert_pem(file, NULL)
2530
98103 return ret;
99104 }
100105
101 OPT_TEST_DECLARE_USAGE("roots.pem untrusted.pem bad.pem\n")
102
103106 static int test_distinguishing_id(void)
104107 {
105108 X509 *x = NULL;
218221 return test_self_signed(bad_f, 0, 0);
219222 }
220223
224 static int do_test_purpose(int purpose, int expected)
225 {
226 X509 *eecert = load_cert_from_file(ee_cert); /* may result in NULL */
227 X509 *untrcert = load_cert_from_file(ca_cert);
228 X509 *trcert = load_cert_from_file(sroot_cert);
229 STACK_OF(X509) *trusted = sk_X509_new_null();
230 STACK_OF(X509) *untrusted = sk_X509_new_null();
231 X509_STORE_CTX *ctx = X509_STORE_CTX_new();
232 int testresult = 0;
233
234 if (!TEST_ptr(eecert)
235 || !TEST_ptr(untrcert)
236 || !TEST_ptr(trcert)
237 || !TEST_ptr(trusted)
238 || !TEST_ptr(untrusted)
239 || !TEST_ptr(ctx))
240 goto err;
241
242
243 if (!TEST_true(sk_X509_push(trusted, trcert)))
244 goto err;
245 trcert = NULL;
246 if (!TEST_true(sk_X509_push(untrusted, untrcert)))
247 goto err;
248 untrcert = NULL;
249
250 if (!TEST_true(X509_STORE_CTX_init(ctx, NULL, eecert, untrusted)))
251 goto err;
252
253 if (!TEST_true(X509_STORE_CTX_set_purpose(ctx, purpose)))
254 goto err;
255
256 /*
257 * X509_STORE_CTX_set0_trusted_stack() is bady named. Despite the set0 name
258 * we are still responsible for freeing trusted after we have finished with
259 * it.
260 */
261 X509_STORE_CTX_set0_trusted_stack(ctx, trusted);
262
263 if (!TEST_int_eq(X509_verify_cert(ctx), expected))
264 goto err;
265
266 testresult = 1;
267 err:
268 sk_X509_pop_free(trusted, X509_free);
269 sk_X509_pop_free(untrusted, X509_free);
270 X509_STORE_CTX_free(ctx);
271 X509_free(eecert);
272 X509_free(untrcert);
273 X509_free(trcert);
274 return testresult;
275 }
276
277 static int test_purpose_ssl_client(void)
278 {
279 return do_test_purpose(X509_PURPOSE_SSL_CLIENT, 0);
280 }
281
282 static int test_purpose_ssl_server(void)
283 {
284 return do_test_purpose(X509_PURPOSE_SSL_SERVER, 1);
285 }
286
287 static int test_purpose_any(void)
288 {
289 return do_test_purpose(X509_PURPOSE_ANY, 1);
290 }
291
292 OPT_TEST_DECLARE_USAGE("certs-dir\n")
293
221294 int setup_tests(void)
222295 {
223296 if (!test_skip_common_options()) {
225298 return 0;
226299 }
227300
228 if (!TEST_ptr(root_f = test_get_argument(0))
229 || !TEST_ptr(roots_f = test_get_argument(1))
230 || !TEST_ptr(untrusted_f = test_get_argument(2))
231 || !TEST_ptr(bad_f = test_get_argument(3))
232 || !TEST_ptr(req_f = test_get_argument(4)))
301 if (!TEST_ptr(certs_dir = test_get_argument(0)))
233302 return 0;
303
304 if (!TEST_ptr(root_f = test_mk_file_path(certs_dir, "rootCA.pem"))
305 || !TEST_ptr(roots_f = test_mk_file_path(certs_dir, "roots.pem"))
306 || !TEST_ptr(untrusted_f = test_mk_file_path(certs_dir, "untrusted.pem"))
307 || !TEST_ptr(bad_f = test_mk_file_path(certs_dir, "bad.pem"))
308 || !TEST_ptr(req_f = test_mk_file_path(certs_dir, "sm2-csr.pem"))
309 || !TEST_ptr(sroot_cert = test_mk_file_path(certs_dir, "sroot-cert.pem"))
310 || !TEST_ptr(ca_cert = test_mk_file_path(certs_dir, "ca-cert.pem"))
311 || !TEST_ptr(ee_cert = test_mk_file_path(certs_dir, "ee-cert.pem")))
312 goto err;
234313
235314 ADD_TEST(test_alt_chains_cert_forgery);
236315 ADD_TEST(test_store_ctx);
239318 ADD_TEST(test_self_signed_good);
240319 ADD_TEST(test_self_signed_bad);
241320 ADD_TEST(test_self_signed_error);
321 ADD_TEST(test_purpose_ssl_client);
322 ADD_TEST(test_purpose_ssl_server);
323 ADD_TEST(test_purpose_any);
242324 return 1;
243 }
325 err:
326 cleanup_tests();
327 return 0;
328 }
329
330 void cleanup_tests(void)
331 {
332 OPENSSL_free(root_f);
333 OPENSSL_free(roots_f);
334 OPENSSL_free(untrusted_f);
335 OPENSSL_free(bad_f);
336 OPENSSL_free(req_f);
337 OPENSSL_free(sroot_cert);
338 OPENSSL_free(ca_cert);
339 OPENSSL_free(ee_cert);
340 }
263263 BN_mod_lshift1(3)
264264 BN_mod_lshift1_quick(3)
265265 BN_mod_lshift_quick(3)
266 BN_mod_sqrt(3)
267266 BN_mod_sub_quick(3)
268267 BN_nist_mod_192(3)
269268 BN_nist_mod_224(3)
12761275 X509_STORE_CTX_get_by_subject(3)
12771276 X509_STORE_CTX_get_explicit_policy(3)
12781277 X509_STORE_CTX_get_obj_by_subject(3)
1279 X509_STORE_CTX_purpose_inherit(3)
12801278 X509_STORE_CTX_set0_dane(3)
12811279 X509_STORE_CTX_set_depth(3)
12821280 X509_STORE_CTX_set_flags(3)
1283 X509_STORE_CTX_set_purpose(3)
12841281 X509_STORE_CTX_set_time(3)
1285 X509_STORE_CTX_set_trust(3)
12861282 X509_STORE_get_verify(3)
12871283 X509_TRUST_add(3)
12881284 X509_TRUST_cleanup(3)
2121 SSL_copy_session_id(3)
2222 SSL_dup_CA_list(3)
2323 SSL_get0_dane(3)
24 SSL_get_certificate(3)
2524 SSL_get_current_compression(3)
2625 SSL_get_current_expansion(3)
2726 SSL_get_finished(3)
2827 SSL_get_peer_finished(3)
29 SSL_get_privatekey(3)
3028 SSL_set_SSL_CTX(3)
3129 SSL_set_debug(3)
3230 SSL_set_not_resumable_session_callback(3)
361361 OPENSSL_MSTR_HELPER define
362362 OPENSSL_VERSION_MAJOR define
363363 OPENSSL_VERSION_MINOR define
364 OPENSSL_VERSION_NUMBER define deprecated 3.0.0
364 OPENSSL_VERSION_NUMBER define
365365 OPENSSL_VERSION_PATCH define
366366 OPENSSL_VERSION_PRE_RELEASE define
367367 OPENSSL_VERSION_PREREQ define
667667 EVP_PKEY_size define
668668 EVP_PKEY_id define
669669 EVP_PKEY_base_id define
670 SSL_set_retry_verify define
00 #! /usr/bin/env perl
1 # Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 1998-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
484484 [ 'x86_64-apple-darwin.*',
485485 sub {
486486 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
487 # macOS >= 10.15 is 64-bit only
488 my $SW_VERS = `sw_vers -productVersion 2>/dev/null`;
489 if ($SW_VERS =~ /^(\d+)\.(\d+)\.(\d+)$/) {
490 if ($1 > 10 || ($1 == 10 && $2 >= 15)) {
491 die "32-bit applications not supported on macOS 10.15 or later\n" if $KERNEL_BITS eq '32';
492 return { target => "darwin64-x86_64" };
493 }
494 }
487495 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
488496
489497 print <<EOF;
740748 defines => [ 'L_ENDIAN' ] } ],
741749 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
742750 defines => [ 'B_ENDIAN' ] } ],
751 [ 'riscv64-.*-.*bsd.*', { target => "BSD-riscv64" } ],
743752 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
744753 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
745754 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
00 #! /usr/bin/env perl
1 # Copyright 2021 The OpenSSL Project Authors. All Rights Reserved.
1 # Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
22 #
33 # Licensed under the Apache License 2.0 (the "License"). You may not use
44 # this file except in compliance with the License. You can obtain a copy
2222
2323 # See if git's available
2424 open my $FH,
25 "git log -1 --date=format:%Y --format=format:%ad $file 2>/dev/null|"
25 "git log -1 --date=short --format=format:%cd $file 2>/dev/null|"
2626 or return $YEAR;
2727 my $LINE = <$FH>;
2828 close $FH;
29 chomp($LINE);
29 $LINE =~ s/^([0-9]*)-.*/$1/;
3030 $YEAR = $LINE if $LINE;
3131 return $YEAR;
3232 }