Latest update
This commit is contained in:
@@ -18,7 +18,7 @@ my %targets = (
|
||||
"debug-erbridge" => {
|
||||
inherit_from => [ 'BASE_unix', "x86_64_asm" ],
|
||||
cc => "gcc",
|
||||
cflags => combine(join(' ', @{$gcc_devteam_warn{CFLAGS}}),
|
||||
cflags => combine(join(' ', @gcc_devteam_warn),
|
||||
"-DBN_DEBUG -DCONF_DEBUG -m64 -DL_ENDIAN -DTERMIO -g",
|
||||
threads("-D_REENTRANT")),
|
||||
ex_libs => add(" ","-ldl"),
|
||||
@@ -81,7 +81,7 @@ my %targets = (
|
||||
"debug-test-64-clang" => {
|
||||
inherit_from => [ 'BASE_unix', "x86_64_asm" ],
|
||||
cc => "clang",
|
||||
cflags => combine(join(' ', @{$gcc_devteam_warn{CFLAGS}}),
|
||||
cflags => combine(join(' ', @gcc_devteam_warn),
|
||||
"-Wno-error=overlength-strings -Wno-error=extended-offsetof -Wno-error=language-extension-token -Wno-error=unused-const-variable -Wstrict-overflow -Qunused-arguments -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -g3 -O3 -pipe",
|
||||
threads("${BSDthreads}")),
|
||||
bn_ops => "SIXTY_FOUR_BIT_LONG",
|
||||
@@ -95,7 +95,7 @@ my %targets = (
|
||||
inherit_from => [ 'BASE_unix', "x86_64_asm" ],
|
||||
cc => "clang",
|
||||
cflags => combine("-arch x86_64 -DL_ENDIAN",
|
||||
join(' ', @{$gcc_devteam_warn{CFLAGS}}),
|
||||
join(' ', @gcc_devteam_warn),
|
||||
"-Wno-error=overlength-strings -Wno-error=extended-offsetof -Wno-error=language-extension-token -Wno-error=unused-const-variable -Wstrict-overflow -Qunused-arguments -DBN_DEBUG -DCONF_DEBUG -DDEBUG_SAFESTACK -DDEBUG_UNUSED -g3 -O3 -pipe",
|
||||
threads("${BSDthreads}")),
|
||||
sys_id => "MACOSX",
|
||||
|
||||
@@ -102,8 +102,9 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lx
|
||||
# SHA512_ASM sha512_block is implemented in assembler
|
||||
# AES_ASM AES_[en|de]crypt is implemented in assembler
|
||||
|
||||
# Minimum warning options... any contributions to OpenSSL should at least get
|
||||
# past these.
|
||||
# Minimum warning options... any contributions to OpenSSL should at least
|
||||
# get past these. Note that we only use these with C compilers, not with
|
||||
# C++ compilers.
|
||||
|
||||
# DEBUG_UNUSED enables __owur (warn unused result) checks.
|
||||
# -DPEDANTIC complements -pedantic and is meant to mask code that
|
||||
@@ -118,27 +119,23 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lx
|
||||
# code, so we just tell compiler to be pedantic about everything
|
||||
# but 'long long' type.
|
||||
|
||||
my %gcc_devteam_warn = ();
|
||||
{
|
||||
my @common = qw( -DDEBUG_UNUSED
|
||||
-DPEDANTIC -pedantic -Wno-long-long
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
-Wno-missing-field-initializers
|
||||
-Wswitch
|
||||
-Wsign-compare
|
||||
-Wshadow
|
||||
-Wformat
|
||||
-Wtype-limits
|
||||
-Wundef
|
||||
-Werror );
|
||||
%gcc_devteam_warn = (
|
||||
CFLAGS => [ @common, qw( -Wmissing-prototypes
|
||||
-Wstrict-prototypes ) ],
|
||||
CXXFLAGS => [ @common ]
|
||||
);
|
||||
}
|
||||
my @gcc_devteam_warn = qw(
|
||||
-DDEBUG_UNUSED
|
||||
-DPEDANTIC -pedantic -Wno-long-long
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
-Wno-missing-field-initializers
|
||||
-Wswitch
|
||||
-Wsign-compare
|
||||
-Wshadow
|
||||
-Wformat
|
||||
-Wtype-limits
|
||||
-Wundef
|
||||
-Werror
|
||||
-Wmissing-prototypes
|
||||
-Wstrict-prototypes
|
||||
);
|
||||
|
||||
# These are used in addition to $gcc_devteam_warn when the compiler is clang.
|
||||
# TODO(openssl-team): fix problems and investigate if (at least) the
|
||||
@@ -148,20 +145,16 @@ my %gcc_devteam_warn = ();
|
||||
# -Wlanguage-extension-token -- no, we use asm()
|
||||
# -Wunused-macros -- no, too tricky for BN and _XOPEN_SOURCE etc
|
||||
# -Wextended-offsetof -- no, needed in CMS ASN1 code
|
||||
my %clang_devteam_warn = ();
|
||||
{
|
||||
my @common = qw( -Wswitch-default
|
||||
-Wno-parentheses-equality
|
||||
-Wno-language-extension-token
|
||||
-Wno-extended-offsetof
|
||||
-Wconditional-uninitialized
|
||||
-Wincompatible-pointer-types-discards-qualifiers
|
||||
-Wno-unknown-warning-option );
|
||||
%clang_devteam_warn = (
|
||||
CFLAGS => [ @common, qw( -Wmissing-variable-declarations ) ],
|
||||
CXXFLAGS => [ @common ]
|
||||
);
|
||||
}
|
||||
my @clang_devteam_warn = qw(
|
||||
-Wswitch-default
|
||||
-Wno-parentheses-equality
|
||||
-Wno-language-extension-token
|
||||
-Wno-extended-offsetof
|
||||
-Wconditional-uninitialized
|
||||
-Wincompatible-pointer-types-discards-qualifiers
|
||||
-Wno-unknown-warning-option
|
||||
-Wmissing-variable-declarations
|
||||
);
|
||||
|
||||
# This adds backtrace information to the memory leak info. Is only used
|
||||
# when crypto-mdebug-backtrace is enabled.
|
||||
@@ -800,7 +793,6 @@ while (@argvcopy)
|
||||
# Pretend that our strict flags is a C flag, and replace it
|
||||
# with the proper flags later on
|
||||
push @{$useradd{CFLAGS}}, '--ossl-strict-warnings';
|
||||
push @{$useradd{CXXFLAGS}}, '--ossl-strict-warnings';
|
||||
$strict_warnings=1;
|
||||
}
|
||||
elsif (/^--debug$/)
|
||||
@@ -1363,20 +1355,16 @@ if ($disabled{"dynamic-engine"}) {
|
||||
|
||||
unless ($disabled{asan} || defined $detected_sanitizers{asan}) {
|
||||
push @{$config{cflags}}, "-fsanitize=address";
|
||||
push @{$config{cxxflags}}, "-fsanitize=address" if $config{CXX};
|
||||
}
|
||||
|
||||
unless ($disabled{ubsan} || defined $detected_sanitizers{ubsan}) {
|
||||
# -DPEDANTIC or -fnosanitize=alignment may also be required on some
|
||||
# platforms.
|
||||
push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all";
|
||||
push @{$config{cxxflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all"
|
||||
if $config{CXX};
|
||||
}
|
||||
|
||||
unless ($disabled{msan} || defined $detected_sanitizers{msan}) {
|
||||
push @{$config{cflags}}, "-fsanitize=memory";
|
||||
push @{$config{cxxflags}}, "-fsanitize=memory" if $config{CXX};
|
||||
}
|
||||
|
||||
unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"}
|
||||
@@ -1563,41 +1551,27 @@ $config{openssl_api_defines} = [
|
||||
"OPENSSL_MIN_API=".($apitable->{$config{api} // ""} // -1)
|
||||
];
|
||||
|
||||
my %strict_warnings_collection=( CFLAGS => [], CXXFLAGS => []);
|
||||
my @strict_warnings_collection=();
|
||||
if ($strict_warnings)
|
||||
{
|
||||
my $wopt;
|
||||
my $gccver = $predefined_C{__GNUC__} // -1;
|
||||
my $gxxver = $predefined_CXX{__GNUC__} // -1;
|
||||
|
||||
warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike"
|
||||
unless $gccver >= 4;
|
||||
warn "WARNING --strict-warnings requires g++[>=4] or g++-alike"
|
||||
unless $gxxver >= 4;
|
||||
foreach (qw(CFLAGS CXXFLAGS))
|
||||
{
|
||||
push @{$strict_warnings_collection{$_}},
|
||||
@{$gcc_devteam_warn{$_}};
|
||||
}
|
||||
push @{$strict_warnings_collection{CFLAGS}},
|
||||
@{$clang_devteam_warn{CFLAGS}}
|
||||
if (defined($predefined_C{__clang__}));
|
||||
push @{$strict_warnings_collection{CXXFLAGS}},
|
||||
@{$clang_devteam_warn{CXXFLAGS}}
|
||||
if (defined($predefined_CXX{__clang__}));
|
||||
push @strict_warnings_collection, @gcc_devteam_warn;
|
||||
push @strict_warnings_collection, @clang_devteam_warn
|
||||
if (defined($predefined_C{__clang__}));
|
||||
}
|
||||
|
||||
if (grep { $_ eq '-static' } @{$config{LDFLAGS}}) {
|
||||
disable('static', 'pic', 'threads');
|
||||
}
|
||||
|
||||
foreach my $idx (qw(CFLAGS CXXFLAGS))
|
||||
{
|
||||
$config{$idx} = [ map { $_ eq '--ossl-strict-warnings'
|
||||
? @{$strict_warnings_collection{$idx}}
|
||||
: ( $_ ) }
|
||||
@{$config{$idx}} ];
|
||||
}
|
||||
$config{CFLAGS} = [ map { $_ eq '--ossl-strict-warnings'
|
||||
? @strict_warnings_collection
|
||||
: ( $_ ) }
|
||||
@{$config{CFLAGS}} ];
|
||||
|
||||
unless ($disabled{"crypto-mdebug-backtrace"})
|
||||
{
|
||||
@@ -1605,9 +1579,6 @@ unless ($disabled{"crypto-mdebug-backtrace"})
|
||||
{
|
||||
push @{$config{cflags}}, $wopt
|
||||
unless grep { $_ eq $wopt } @{$config{cflags}};
|
||||
push @{$config{cxxflags}}, $wopt
|
||||
if ($config{CXX}
|
||||
&& !grep { $_ eq $wopt } @{$config{cxxflags}});
|
||||
}
|
||||
if ($target =~ /^BSD-/)
|
||||
{
|
||||
|
||||
+1
-1
@@ -247,7 +247,7 @@ int ciphers_main(int argc, char **argv)
|
||||
const char *nm = SSL_CIPHER_standard_name(c);
|
||||
if (nm == NULL)
|
||||
nm = "UNKNOWN";
|
||||
BIO_printf(bio_out, "%s - ", nm);
|
||||
BIO_printf(bio_out, "%-45s - ", nm);
|
||||
}
|
||||
BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
+16
-4
@@ -2717,16 +2717,28 @@ int speed_main(int argc, char **argv)
|
||||
|
||||
for (k = 0; k < loopargs_len; k++) {
|
||||
loopargs[k].ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL, NULL,
|
||||
iv, decrypt ? 0 : 1);
|
||||
if (loopargs[k].ctx == NULL) {
|
||||
BIO_printf(bio_err, "\nEVP_CIPHER_CTX_new failure\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!EVP_CipherInit_ex(loopargs[k].ctx, evp_cipher, NULL,
|
||||
NULL, iv, decrypt ? 0 : 1)) {
|
||||
BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
|
||||
ERR_print_errors(bio_err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_set_padding(loopargs[k].ctx, 0);
|
||||
|
||||
keylen = EVP_CIPHER_CTX_key_length(loopargs[k].ctx);
|
||||
loopargs[k].key = app_malloc(keylen, "evp_cipher key");
|
||||
EVP_CIPHER_CTX_rand_key(loopargs[k].ctx, loopargs[k].key);
|
||||
EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
|
||||
loopargs[k].key, NULL, -1);
|
||||
if (!EVP_CipherInit_ex(loopargs[k].ctx, NULL, NULL,
|
||||
loopargs[k].key, NULL, -1)) {
|
||||
BIO_printf(bio_err, "\nEVP_CipherInit_ex failure\n");
|
||||
ERR_print_errors(bio_err);
|
||||
exit(1);
|
||||
}
|
||||
OPENSSL_clear_free(loopargs[k].key, keylen);
|
||||
|
||||
/* SIV mode only allows for a single Update operation */
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
SUBDIRS=crypto ssl apps test util tools fuzz engines providers
|
||||
|
||||
LIBS=libcrypto libssl
|
||||
INCLUDE[libcrypto]=. crypto/include include providers/common/include
|
||||
INCLUDE[libcrypto]=. crypto/include include
|
||||
INCLUDE[libssl]=. include
|
||||
DEPEND[libssl]=libcrypto
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -107,6 +107,7 @@ static const ERR_STRING_DATA ASN1_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_ASN1_UINTEGER, 0), "d2i_ASN1_UINTEGER"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_AUTOPRIVATEKEY, 0),
|
||||
"d2i_AutoPrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_KEYPARAMS, 0), "d2i_KeyParams"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_PRIVATEKEY, 0), "d2i_PrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_D2I_PUBLICKEY, 0), "d2i_PublicKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_DO_BUF, 0), "do_buf"},
|
||||
@@ -119,6 +120,7 @@ static const ERR_STRING_DATA ASN1_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_ASN1_OBJECT, 0), "i2d_ASN1_OBJECT"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_DSA_PUBKEY, 0), "i2d_DSA_PUBKEY"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_EC_PUBKEY, 0), "i2d_EC_PUBKEY"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_KEYPARAMS, 0), "i2d_KeyParams"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_PRIVATEKEY, 0), "i2d_PrivateKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_PUBLICKEY, 0), "i2d_PublicKey"},
|
||||
{ERR_PACK(ERR_LIB_ASN1, ASN1_F_I2D_RSA_PUBKEY, 0), "i2d_RSA_PUBKEY"},
|
||||
|
||||
@@ -13,4 +13,5 @@ SOURCE[../../libcrypto]=\
|
||||
x_pkey.c bio_asn1.c bio_ndef.c asn_mime.c \
|
||||
asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c \
|
||||
evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p5_scrypt.c p8_pkey.c \
|
||||
asn_moid.c asn_mstbl.c asn1_item_list.c
|
||||
asn_moid.c asn_mstbl.c asn1_item_list.c \
|
||||
d2i_param.c i2d_param.c
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/asn1_int.h"
|
||||
|
||||
EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
long length)
|
||||
{
|
||||
EVP_PKEY *ret = NULL;
|
||||
const unsigned char *p = *pp;
|
||||
|
||||
if ((a == NULL) || (*a == NULL)) {
|
||||
if ((ret = EVP_PKEY_new()) == NULL)
|
||||
return NULL;
|
||||
} else
|
||||
ret = *a;
|
||||
|
||||
if (type != EVP_PKEY_id(ret) && !EVP_PKEY_set_type(ret, type))
|
||||
goto err;
|
||||
|
||||
if (ret->ameth == NULL || ret->ameth->param_decode == NULL) {
|
||||
ASN1err(ASN1_F_D2I_KEYPARAMS, ASN1_R_UNSUPPORTED_TYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!ret->ameth->param_decode(ret, &p, length))
|
||||
goto err;
|
||||
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
return ret;
|
||||
err:
|
||||
if (a == NULL || *a != ret)
|
||||
EVP_PKEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in)
|
||||
{
|
||||
BUF_MEM *b = NULL;
|
||||
const unsigned char *p;
|
||||
void *ret = NULL;
|
||||
int len;
|
||||
|
||||
len = asn1_d2i_read_bio(in, &b);
|
||||
if (len < 0)
|
||||
goto err;
|
||||
|
||||
p = (unsigned char *)b->data;
|
||||
ret = d2i_KeyParams(type, a, &p, len);
|
||||
err:
|
||||
BUF_MEM_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp)
|
||||
{
|
||||
if (a->ameth != NULL && a->ameth->param_encode != NULL)
|
||||
return a->ameth->param_encode(a, pp);
|
||||
ASN1err(ASN1_F_I2D_KEYPARAMS, ASN1_R_UNSUPPORTED_TYPE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey)
|
||||
{
|
||||
return ASN1_i2d_bio_of(EVP_PKEY, i2d_KeyParams, bp, pkey);
|
||||
}
|
||||
|
||||
+6
-1
@@ -12,6 +12,9 @@ LIBS=../libcrypto
|
||||
SOURCE[../libcrypto]=provider_core.c provider_predefined.c provider_conf.c \
|
||||
core_fetch.c core_namemap.c
|
||||
|
||||
SOURCE[../providers/fips]=provider_core.c provider_predefined.c \
|
||||
core_fetch.c core_namemap.c
|
||||
|
||||
# Central utilities
|
||||
SOURCE[../libcrypto]=\
|
||||
cryptlib.c mem.c mem_dbg.c cversion.c info.c ex_data.c cpt_err.c \
|
||||
@@ -23,7 +26,9 @@ SOURCE[../libcrypto]=\
|
||||
|
||||
# FIPS module
|
||||
SOURCE[../providers/fips]=\
|
||||
cryptlib.c mem.c mem_clr.c params.c bsearch.c
|
||||
cryptlib.c mem.c mem_clr.c params.c bsearch.c ex_data.c o_str.c \
|
||||
ctype.c threads_pthread.c threads_win.c threads_none.c context.c \
|
||||
sparse_array.c
|
||||
|
||||
|
||||
DEPEND[cversion.o]=buildinf.h
|
||||
|
||||
+1
-1
@@ -36,10 +36,10 @@ struct openssl_ctx_st {
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
static OPENSSL_CTX default_context_int;
|
||||
#endif
|
||||
|
||||
/* Always points at default_context_int if it has been initialised */
|
||||
static OPENSSL_CTX *default_context = NULL;
|
||||
#endif
|
||||
|
||||
static int context_init(OPENSSL_CTX *ctx)
|
||||
{
|
||||
|
||||
@@ -80,6 +80,7 @@ ASN1_F_COLLECT_DATA:140:collect_data
|
||||
ASN1_F_D2I_ASN1_OBJECT:147:d2i_ASN1_OBJECT
|
||||
ASN1_F_D2I_ASN1_UINTEGER:150:d2i_ASN1_UINTEGER
|
||||
ASN1_F_D2I_AUTOPRIVATEKEY:207:d2i_AutoPrivateKey
|
||||
ASN1_F_D2I_KEYPARAMS:144:d2i_KeyParams
|
||||
ASN1_F_D2I_PRIVATEKEY:154:d2i_PrivateKey
|
||||
ASN1_F_D2I_PUBLICKEY:155:d2i_PublicKey
|
||||
ASN1_F_DO_BUF:142:do_buf
|
||||
@@ -91,6 +92,7 @@ ASN1_F_I2D_ASN1_BIO_STREAM:211:i2d_ASN1_bio_stream
|
||||
ASN1_F_I2D_ASN1_OBJECT:143:i2d_ASN1_OBJECT
|
||||
ASN1_F_I2D_DSA_PUBKEY:161:i2d_DSA_PUBKEY
|
||||
ASN1_F_I2D_EC_PUBKEY:181:i2d_EC_PUBKEY
|
||||
ASN1_F_I2D_KEYPARAMS:145:i2d_KeyParams
|
||||
ASN1_F_I2D_PRIVATEKEY:163:i2d_PrivateKey
|
||||
ASN1_F_I2D_PUBLICKEY:164:i2d_PublicKey
|
||||
ASN1_F_I2D_RSA_PUBKEY:165:i2d_RSA_PUBKEY
|
||||
|
||||
@@ -20,6 +20,10 @@ SOURCE[../../libcrypto]=\
|
||||
SOURCE[../../libcrypto]=\
|
||||
evp_fetch.c
|
||||
|
||||
# FIPS Module
|
||||
SOURCE[../../providers/fips]=\
|
||||
digest.c evp_enc.c evp_lib.c evp_fetch.c cmeth_lib.c
|
||||
|
||||
INCLUDE[e_aes.o]=.. ../modes
|
||||
INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes
|
||||
INCLUDE[e_aes_cbc_hmac_sha256.o]=../modes
|
||||
|
||||
+31
-8
@@ -55,10 +55,14 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
||||
* pctx should be freed by the user of EVP_MD_CTX
|
||||
* if EVP_MD_CTX_FLAG_KEEP_PKEY_CTX is set
|
||||
*/
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
|
||||
EVP_PKEY_CTX_free(ctx->pctx);
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
ENGINE_finish(ctx->engine);
|
||||
# endif
|
||||
#endif
|
||||
OPENSSL_cleanse(ctx, sizeof(*ctx));
|
||||
|
||||
@@ -102,8 +106,9 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
|
||||
|
||||
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
{
|
||||
EVP_MD *provmd;
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
ENGINE *tmpimpl = NULL;
|
||||
#endif
|
||||
|
||||
EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
|
||||
|
||||
@@ -111,7 +116,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
ctx->reqdigest = type;
|
||||
|
||||
/* TODO(3.0): Legacy work around code below. Remove this */
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
/*
|
||||
* Whether it's nice or not, "Inits" can be used on "Final"'d contexts so
|
||||
* this context may already have an ENGINE! Try to avoid releasing the
|
||||
@@ -132,7 +137,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
*/
|
||||
if (ctx->engine != NULL
|
||||
|| impl != NULL
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
|| tmpimpl != NULL
|
||||
#endif
|
||||
|| ctx->pctx != NULL
|
||||
|| (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0) {
|
||||
if (ctx->digest == ctx->fetched_digest)
|
||||
@@ -160,7 +167,13 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
/* TODO(3.0): Start of non-legacy code below */
|
||||
|
||||
if (type->prov == NULL) {
|
||||
provmd = EVP_MD_fetch(NULL, OBJ_nid2sn(type->type), "");
|
||||
#ifdef FIPS_MODE
|
||||
/* We only do explict fetches inside the FIPS module */
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
#else
|
||||
EVP_MD *provmd = EVP_MD_fetch(NULL, OBJ_nid2sn(type->type), "");
|
||||
|
||||
if (provmd == NULL) {
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
@@ -168,6 +181,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
type = provmd;
|
||||
EVP_MD_meth_free(ctx->fetched_digest);
|
||||
ctx->fetched_digest = provmd;
|
||||
#endif
|
||||
}
|
||||
|
||||
ctx->digest = type;
|
||||
@@ -189,7 +203,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
if (type) {
|
||||
/*
|
||||
* Ensure an ENGINE left lying around from last time is cleared (the
|
||||
@@ -247,16 +261,19 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
skip_to_init:
|
||||
#endif
|
||||
if (ctx->pctx) {
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
if (ctx->pctx != NULL) {
|
||||
int r;
|
||||
r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
|
||||
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
|
||||
if (r <= 0 && (r != -2))
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)
|
||||
return 1;
|
||||
return ctx->digest->init(ctx);
|
||||
@@ -397,6 +414,8 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
|
||||
/* copied EVP_MD_CTX should free the copied EVP_PKEY_CTX */
|
||||
EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
if (in->pctx != NULL) {
|
||||
out->pctx = EVP_PKEY_CTX_dup(in->pctx);
|
||||
if (out->pctx == NULL) {
|
||||
@@ -405,12 +424,13 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
/* Make sure it's safe to copy a digest context using an ENGINE */
|
||||
if (in->engine && !ENGINE_init(in->engine)) {
|
||||
EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);
|
||||
@@ -451,6 +471,8 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
|
||||
out->update = in->update;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
/* TODO(3.0): Temporarily no support for EVP_DigestSign* in FIPS module */
|
||||
if (in->pctx) {
|
||||
out->pctx = EVP_PKEY_CTX_dup(in->pctx);
|
||||
if (!out->pctx) {
|
||||
@@ -458,6 +480,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (out->digest->copy)
|
||||
return out->digest->copy(out, in);
|
||||
|
||||
+35
-16
@@ -51,7 +51,7 @@ int EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
|
||||
OPENSSL_cleanse(ctx->cipher_data, ctx->cipher->ctx_size);
|
||||
}
|
||||
OPENSSL_free(ctx->cipher_data);
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
ENGINE_finish(ctx->engine);
|
||||
#endif
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
@@ -81,8 +81,9 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
ENGINE *impl, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
EVP_CIPHER *provciph = NULL;
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
ENGINE *tmpimpl = NULL;
|
||||
#endif
|
||||
const EVP_CIPHER *tmpcipher;
|
||||
|
||||
/*
|
||||
@@ -105,7 +106,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
|
||||
/* TODO(3.0): Legacy work around code below. Remove this */
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
/*
|
||||
* Whether it's nice or not, "Inits" can be used on "Final"'d contexts so
|
||||
* this context may already have an ENGINE! Try to avoid releasing the
|
||||
@@ -126,8 +127,10 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
* If there are engines involved then we should use legacy handling for now.
|
||||
*/
|
||||
if (ctx->engine != NULL
|
||||
|| impl != NULL
|
||||
|| tmpimpl != NULL) {
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
|| tmpimpl != NULL
|
||||
#endif
|
||||
|| impl != NULL) {
|
||||
if (ctx->cipher == ctx->fetched_cipher)
|
||||
ctx->cipher = NULL;
|
||||
EVP_CIPHER_meth_free(ctx->fetched_cipher);
|
||||
@@ -194,7 +197,14 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
cipher = ctx->cipher;
|
||||
|
||||
if (cipher->prov == NULL) {
|
||||
provciph = EVP_CIPHER_fetch(NULL, OBJ_nid2sn(cipher->nid), "");
|
||||
#ifdef FIPS_MODE
|
||||
/* We only do explict fetches inside the FIPS module */
|
||||
EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
#else
|
||||
EVP_CIPHER *provciph =
|
||||
EVP_CIPHER_fetch(NULL, OBJ_nid2sn(cipher->nid), "");
|
||||
|
||||
if (provciph == NULL) {
|
||||
EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
return 0;
|
||||
@@ -202,6 +212,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
cipher = provciph;
|
||||
EVP_CIPHER_meth_free(ctx->fetched_cipher);
|
||||
ctx->fetched_cipher = provciph;
|
||||
#endif
|
||||
}
|
||||
|
||||
ctx->cipher = cipher;
|
||||
@@ -279,7 +290,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
ctx->encrypt = enc;
|
||||
ctx->flags = flags;
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
if (impl != NULL) {
|
||||
if (!ENGINE_init(impl)) {
|
||||
EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
@@ -335,7 +346,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
skip_to_init:
|
||||
#endif
|
||||
if (ctx->cipher == NULL)
|
||||
@@ -576,7 +587,12 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher == NULL || ctx->cipher->prov == NULL)
|
||||
if (ctx->cipher == NULL) {
|
||||
EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_NO_CIPHER_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
blocksize = EVP_CIPHER_CTX_block_size(ctx);
|
||||
@@ -820,7 +836,12 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher == NULL || ctx->cipher->prov == NULL)
|
||||
if (ctx->cipher == NULL) {
|
||||
EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_NO_CIPHER_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
blocksize = EVP_CIPHER_CTX_block_size(ctx);
|
||||
@@ -847,11 +868,6 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
legacy:
|
||||
|
||||
*outl = 0;
|
||||
if (ctx->cipher == NULL) {
|
||||
EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_NO_CIPHER_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
|
||||
i = ctx->cipher->do_cipher(ctx, out, NULL, 0);
|
||||
if (i < 0)
|
||||
@@ -966,6 +982,8 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if !defined(FIPS_MODE)
|
||||
/* TODO(3.0): No support for RAND yet in the FIPS module */
|
||||
int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
|
||||
{
|
||||
int kl;
|
||||
@@ -976,6 +994,7 @@ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
||||
{
|
||||
@@ -1013,7 +1032,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
legacy:
|
||||
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
/* Make sure it's safe to copy a cipher context using an ENGINE */
|
||||
if (in->engine && !ENGINE_init(in->engine)) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_CTX_COPY, ERR_R_ENGINE_LIB);
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ui.h>
|
||||
|
||||
#ifndef BUFSIZ
|
||||
# define BUFSIZ 256
|
||||
#endif
|
||||
|
||||
/* should be init to zeros. */
|
||||
static char prompt_string[80];
|
||||
|
||||
|
||||
+18
-7
@@ -17,6 +17,7 @@
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
#if !defined(FIPS_MODE)
|
||||
int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
{
|
||||
int ret;
|
||||
@@ -146,12 +147,12 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
|
||||
}
|
||||
return i;
|
||||
}
|
||||
#endif /* !defined(FIPS_MODE) */
|
||||
|
||||
/* Convert the various cipher NIDs and dummies to a proper OID NID */
|
||||
int EVP_CIPHER_type(const EVP_CIPHER *ctx)
|
||||
{
|
||||
int nid;
|
||||
ASN1_OBJECT *otmp;
|
||||
nid = EVP_CIPHER_nid(ctx);
|
||||
|
||||
switch (nid) {
|
||||
@@ -198,12 +199,19 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx)
|
||||
return NID_des_cfb64;
|
||||
|
||||
default:
|
||||
/* Check it has an OID and it is valid */
|
||||
otmp = OBJ_nid2obj(nid);
|
||||
if (OBJ_get0_data(otmp) == NULL)
|
||||
nid = NID_undef;
|
||||
ASN1_OBJECT_free(otmp);
|
||||
return nid;
|
||||
#ifdef FIPS_MODE
|
||||
return NID_undef;
|
||||
#else
|
||||
{
|
||||
/* Check it has an OID and it is valid */
|
||||
ASN1_OBJECT *otmp = OBJ_nid2obj(nid);
|
||||
|
||||
if (OBJ_get0_data(otmp) == NULL)
|
||||
nid = NID_undef;
|
||||
ASN1_OBJECT_free(otmp);
|
||||
return nid;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,6 +604,8 @@ EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx)
|
||||
return ctx->pctx;
|
||||
}
|
||||
|
||||
#if !defined(FIPS_MODE)
|
||||
/* TODO(3.0): EVP_DigestSign* not yet supported in FIPS module */
|
||||
void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
|
||||
{
|
||||
/*
|
||||
@@ -614,6 +624,7 @@ void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
|
||||
EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
|
||||
}
|
||||
}
|
||||
#endif /* !defined(FIPS_MODE) */
|
||||
|
||||
void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx)
|
||||
{
|
||||
|
||||
+99
-6
@@ -28,7 +28,7 @@ static int HKDF(const EVP_MD *evp_md,
|
||||
unsigned char *okm, size_t okm_len);
|
||||
static int HKDF_Extract(const EVP_MD *evp_md,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *key, size_t key_len,
|
||||
const unsigned char *ikm, size_t ikm_len,
|
||||
unsigned char *prk, size_t prk_len);
|
||||
static int HKDF_Expand(const EVP_MD *evp_md,
|
||||
const unsigned char *prk, size_t prk_len,
|
||||
@@ -240,9 +240,34 @@ const EVP_KDF hkdf_kdf_meth = {
|
||||
kdf_hkdf_derive
|
||||
};
|
||||
|
||||
/*
|
||||
* Refer to "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)"
|
||||
* Section 2 (https://tools.ietf.org/html/rfc5869#section-2) and
|
||||
* "Cryptographic Extraction and Key Derivation: The HKDF Scheme"
|
||||
* Section 4.2 (https://eprint.iacr.org/2010/264.pdf).
|
||||
*
|
||||
* From the paper:
|
||||
* The scheme HKDF is specified as:
|
||||
* HKDF(XTS, SKM, CTXinfo, L) = K(1) | K(2) | ... | K(t)
|
||||
*
|
||||
* where:
|
||||
* SKM is source key material
|
||||
* XTS is extractor salt (which may be null or constant)
|
||||
* CTXinfo is context information (may be null)
|
||||
* L is the number of key bits to be produced by KDF
|
||||
* k is the output length in bits of the hash function used with HMAC
|
||||
* t = ceil(L/k)
|
||||
* the value K(t) is truncated to its first d = L mod k bits.
|
||||
*
|
||||
* From RFC 5869:
|
||||
* 2.2. Step 1: Extract
|
||||
* HKDF-Extract(salt, IKM) -> PRK
|
||||
* 2.3. Step 2: Expand
|
||||
* HKDF-Expand(PRK, info, L) -> OKM
|
||||
*/
|
||||
static int HKDF(const EVP_MD *evp_md,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *key, size_t key_len,
|
||||
const unsigned char *ikm, size_t ikm_len,
|
||||
const unsigned char *info, size_t info_len,
|
||||
unsigned char *okm, size_t okm_len)
|
||||
{
|
||||
@@ -255,18 +280,44 @@ static int HKDF(const EVP_MD *evp_md,
|
||||
return 0;
|
||||
prk_len = (size_t)sz;
|
||||
|
||||
if (!HKDF_Extract(evp_md, salt, salt_len, key, key_len, prk, prk_len))
|
||||
/* Step 1: HKDF-Extract(salt, IKM) -> PRK */
|
||||
if (!HKDF_Extract(evp_md, salt, salt_len, ikm, ikm_len, prk, prk_len))
|
||||
return 0;
|
||||
|
||||
/* Step 2: HKDF-Expand(PRK, info, L) -> OKM */
|
||||
ret = HKDF_Expand(evp_md, prk, prk_len, info, info_len, okm, okm_len);
|
||||
OPENSSL_cleanse(prk, sizeof(prk));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Refer to "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)"
|
||||
* Section 2.2 (https://tools.ietf.org/html/rfc5869#section-2.2).
|
||||
*
|
||||
* 2.2. Step 1: Extract
|
||||
*
|
||||
* HKDF-Extract(salt, IKM) -> PRK
|
||||
*
|
||||
* Options:
|
||||
* Hash a hash function; HashLen denotes the length of the
|
||||
* hash function output in octets
|
||||
*
|
||||
* Inputs:
|
||||
* salt optional salt value (a non-secret random value);
|
||||
* if not provided, it is set to a string of HashLen zeros.
|
||||
* IKM input keying material
|
||||
*
|
||||
* Output:
|
||||
* PRK a pseudorandom key (of HashLen octets)
|
||||
*
|
||||
* The output PRK is calculated as follows:
|
||||
*
|
||||
* PRK = HMAC-Hash(salt, IKM)
|
||||
*/
|
||||
static int HKDF_Extract(const EVP_MD *evp_md,
|
||||
const unsigned char *salt, size_t salt_len,
|
||||
const unsigned char *key, size_t key_len,
|
||||
const unsigned char *ikm, size_t ikm_len,
|
||||
unsigned char *prk, size_t prk_len)
|
||||
{
|
||||
int sz = EVP_MD_size(evp_md);
|
||||
@@ -277,9 +328,49 @@ static int HKDF_Extract(const EVP_MD *evp_md,
|
||||
KDFerr(KDF_F_HKDF_EXTRACT, KDF_R_WRONG_OUTPUT_BUFFER_SIZE);
|
||||
return 0;
|
||||
}
|
||||
return HMAC(evp_md, salt, salt_len, key, key_len, prk, NULL) != NULL;
|
||||
/* calc: PRK = HMAC-Hash(salt, IKM) */
|
||||
return HMAC(evp_md, salt, salt_len, ikm, ikm_len, prk, NULL) != NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Refer to "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)"
|
||||
* Section 2.3 (https://tools.ietf.org/html/rfc5869#section-2.3).
|
||||
*
|
||||
* 2.3. Step 2: Expand
|
||||
*
|
||||
* HKDF-Expand(PRK, info, L) -> OKM
|
||||
*
|
||||
* Options:
|
||||
* Hash a hash function; HashLen denotes the length of the
|
||||
* hash function output in octets
|
||||
*
|
||||
* Inputs:
|
||||
* PRK a pseudorandom key of at least HashLen octets
|
||||
* (usually, the output from the extract step)
|
||||
* info optional context and application specific information
|
||||
* (can be a zero-length string)
|
||||
* L length of output keying material in octets
|
||||
* (<= 255*HashLen)
|
||||
*
|
||||
* Output:
|
||||
* OKM output keying material (of L octets)
|
||||
*
|
||||
* The output OKM is calculated as follows:
|
||||
*
|
||||
* N = ceil(L/HashLen)
|
||||
* T = T(1) | T(2) | T(3) | ... | T(N)
|
||||
* OKM = first L octets of T
|
||||
*
|
||||
* where:
|
||||
* T(0) = empty string (zero length)
|
||||
* T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
|
||||
* T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
|
||||
* T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
|
||||
* ...
|
||||
*
|
||||
* (where the constant concatenated to the end of each T(n) is a
|
||||
* single octet.)
|
||||
*/
|
||||
static int HKDF_Expand(const EVP_MD *evp_md,
|
||||
const unsigned char *prk, size_t prk_len,
|
||||
const unsigned char *info, size_t info_len,
|
||||
@@ -295,8 +386,9 @@ static int HKDF_Expand(const EVP_MD *evp_md,
|
||||
if (sz <= 0)
|
||||
return 0;
|
||||
dig_len = (size_t)sz;
|
||||
n = okm_len / dig_len;
|
||||
|
||||
/* calc: N = ceil(L/HashLen) */
|
||||
n = okm_len / dig_len;
|
||||
if (okm_len % dig_len)
|
||||
n++;
|
||||
|
||||
@@ -313,6 +405,7 @@ static int HKDF_Expand(const EVP_MD *evp_md,
|
||||
size_t copy_len;
|
||||
const unsigned char ctr = i;
|
||||
|
||||
/* calc: T(i) = HMAC-Hash(PRK, T(i - 1) | info | i) */
|
||||
if (i > 1) {
|
||||
if (!HMAC_Init_ex(hmac, NULL, 0, NULL, NULL))
|
||||
goto err;
|
||||
|
||||
+117
-35
@@ -7,6 +7,44 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Refer to "The TLS Protocol Version 1.0" Section 5
|
||||
* (https://tools.ietf.org/html/rfc2246#section-5) and
|
||||
* "The Transport Layer Security (TLS) Protocol Version 1.2" Section 5
|
||||
* (https://tools.ietf.org/html/rfc5246#section-5).
|
||||
*
|
||||
* For TLS v1.0 and TLS v1.1 the TLS PRF algorithm is given by:
|
||||
*
|
||||
* PRF(secret, label, seed) = P_MD5(S1, label + seed) XOR
|
||||
* P_SHA-1(S2, label + seed)
|
||||
*
|
||||
* where P_MD5 and P_SHA-1 are defined by P_<hash>, below, and S1 and S2 are
|
||||
* two halves of the secret (with the possibility of one shared byte, in the
|
||||
* case where the length of the original secret is odd). S1 is taken from the
|
||||
* first half of the secret, S2 from the second half.
|
||||
*
|
||||
* For TLS v1.2 the TLS PRF algorithm is given by:
|
||||
*
|
||||
* PRF(secret, label, seed) = P_<hash>(secret, label + seed)
|
||||
*
|
||||
* where hash is SHA-256 for all cipher suites defined in RFC 5246 as well as
|
||||
* those published prior to TLS v1.2 while the TLS v1.2 protocol is in effect,
|
||||
* unless defined otherwise by the cipher suite.
|
||||
*
|
||||
* P_<hash> is an expansion function that uses a single hash function to expand
|
||||
* a secret and seed into an arbitrary quantity of output:
|
||||
*
|
||||
* P_<hash>(secret, seed) = HMAC_<hash>(secret, A(1) + seed) +
|
||||
* HMAC_<hash>(secret, A(2) + seed) +
|
||||
* HMAC_<hash>(secret, A(3) + seed) + ...
|
||||
*
|
||||
* where + indicates concatenation. P_<hash> can be iterated as many times as
|
||||
* is necessary to produce the required quantity of data.
|
||||
*
|
||||
* A(i) is defined as:
|
||||
* A(0) = seed
|
||||
* A(i) = HMAC_<hash>(secret, A(i-1))
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
@@ -82,7 +120,7 @@ static int kdf_tls1_prf_ctrl(EVP_KDF_IMPL *impl, int cmd, va_list args)
|
||||
if (impl->sec == NULL)
|
||||
return 0;
|
||||
|
||||
impl->seclen = len;
|
||||
impl->seclen = len;
|
||||
return 1;
|
||||
|
||||
case EVP_KDF_CTRL_RESET_TLS_SEED:
|
||||
@@ -168,25 +206,41 @@ const EVP_KDF tls1_prf_kdf_meth = {
|
||||
kdf_tls1_prf_derive
|
||||
};
|
||||
|
||||
/*
|
||||
* Refer to "The TLS Protocol Version 1.0" Section 5
|
||||
* (https://tools.ietf.org/html/rfc2246#section-5) and
|
||||
* "The Transport Layer Security (TLS) Protocol Version 1.2" Section 5
|
||||
* (https://tools.ietf.org/html/rfc5246#section-5).
|
||||
*
|
||||
* P_<hash> is an expansion function that uses a single hash function to expand
|
||||
* a secret and seed into an arbitrary quantity of output:
|
||||
*
|
||||
* P_<hash>(secret, seed) = HMAC_<hash>(secret, A(1) + seed) +
|
||||
* HMAC_<hash>(secret, A(2) + seed) +
|
||||
* HMAC_<hash>(secret, A(3) + seed) + ...
|
||||
*
|
||||
* where + indicates concatenation. P_<hash> can be iterated as many times as
|
||||
* is necessary to produce the required quantity of data.
|
||||
*
|
||||
* A(i) is defined as:
|
||||
* A(0) = seed
|
||||
* A(i) = HMAC_<hash>(secret, A(i-1))
|
||||
*/
|
||||
static int tls1_prf_P_hash(const EVP_MD *md,
|
||||
const unsigned char *sec, size_t sec_len,
|
||||
const unsigned char *seed, size_t seed_len,
|
||||
unsigned char *out, size_t olen)
|
||||
{
|
||||
int chunk;
|
||||
EVP_MAC_CTX *ctx = NULL, *ctx_tmp = NULL, *ctx_init = NULL;
|
||||
unsigned char A1[EVP_MAX_MD_SIZE];
|
||||
size_t A1_len;
|
||||
size_t chunk;
|
||||
EVP_MAC_CTX *ctx = NULL, *ctx_Ai = NULL, *ctx_init = NULL;
|
||||
unsigned char Ai[EVP_MAX_MD_SIZE];
|
||||
size_t Ai_len;
|
||||
int ret = 0;
|
||||
|
||||
chunk = EVP_MD_size(md);
|
||||
if (!ossl_assert(chunk > 0))
|
||||
goto err;
|
||||
|
||||
ctx = EVP_MAC_CTX_new_id(EVP_MAC_HMAC);
|
||||
ctx_tmp = EVP_MAC_CTX_new_id(EVP_MAC_HMAC);
|
||||
ctx_Ai = EVP_MAC_CTX_new_id(EVP_MAC_HMAC);
|
||||
ctx_init = EVP_MAC_CTX_new_id(EVP_MAC_HMAC);
|
||||
if (ctx == NULL || ctx_tmp == NULL || ctx_init == NULL)
|
||||
if (ctx == NULL || ctx_Ai == NULL || ctx_init == NULL)
|
||||
goto err;
|
||||
if (EVP_MAC_ctrl(ctx_init, EVP_MAC_CTRL_SET_FLAGS, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW) != 1)
|
||||
goto err;
|
||||
@@ -196,59 +250,85 @@ static int tls1_prf_P_hash(const EVP_MD *md,
|
||||
goto err;
|
||||
if (!EVP_MAC_init(ctx_init))
|
||||
goto err;
|
||||
if (!EVP_MAC_CTX_copy(ctx, ctx_init))
|
||||
chunk = EVP_MAC_size(ctx_init);
|
||||
if (chunk == 0)
|
||||
goto err;
|
||||
if (seed != NULL && !EVP_MAC_update(ctx, seed, seed_len))
|
||||
/* A(0) = seed */
|
||||
if (!EVP_MAC_CTX_copy(ctx_Ai, ctx_init))
|
||||
goto err;
|
||||
if (!EVP_MAC_final(ctx, A1, &A1_len))
|
||||
if (seed != NULL && !EVP_MAC_update(ctx_Ai, seed, seed_len))
|
||||
goto err;
|
||||
|
||||
for (;;) {
|
||||
/* Reinit mac contexts */
|
||||
/* calc: A(i) = HMAC_<hash>(secret, A(i-1)) */
|
||||
if (!EVP_MAC_final(ctx_Ai, Ai, &Ai_len))
|
||||
goto err;
|
||||
|
||||
/* calc next chunk: HMAC_<hash>(secret, A(i) + seed) */
|
||||
if (!EVP_MAC_CTX_copy(ctx, ctx_init))
|
||||
goto err;
|
||||
if (!EVP_MAC_update(ctx, A1, A1_len))
|
||||
if (!EVP_MAC_update(ctx, Ai, Ai_len))
|
||||
goto err;
|
||||
if (olen > (size_t)chunk && !EVP_MAC_CTX_copy(ctx_tmp, ctx))
|
||||
/* save state for calculating next A(i) value */
|
||||
if (olen > chunk && !EVP_MAC_CTX_copy(ctx_Ai, ctx))
|
||||
goto err;
|
||||
if (seed != NULL && !EVP_MAC_update(ctx, seed, seed_len))
|
||||
goto err;
|
||||
|
||||
if (olen > (size_t)chunk) {
|
||||
size_t mac_len;
|
||||
if (!EVP_MAC_final(ctx, out, &mac_len))
|
||||
if (olen <= chunk) {
|
||||
/* last chunk - use Ai as temp bounce buffer */
|
||||
if (!EVP_MAC_final(ctx, Ai, &Ai_len))
|
||||
goto err;
|
||||
out += mac_len;
|
||||
olen -= mac_len;
|
||||
/* calc the next A1 value */
|
||||
if (!EVP_MAC_final(ctx_tmp, A1, &A1_len))
|
||||
goto err;
|
||||
} else { /* last one */
|
||||
|
||||
if (!EVP_MAC_final(ctx, A1, &A1_len))
|
||||
goto err;
|
||||
memcpy(out, A1, olen);
|
||||
memcpy(out, Ai, olen);
|
||||
break;
|
||||
}
|
||||
if (!EVP_MAC_final(ctx, out, NULL))
|
||||
goto err;
|
||||
out += chunk;
|
||||
olen -= chunk;
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_MAC_CTX_free(ctx);
|
||||
EVP_MAC_CTX_free(ctx_tmp);
|
||||
EVP_MAC_CTX_free(ctx_Ai);
|
||||
EVP_MAC_CTX_free(ctx_init);
|
||||
OPENSSL_cleanse(A1, sizeof(A1));
|
||||
OPENSSL_cleanse(Ai, sizeof(Ai));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Refer to "The TLS Protocol Version 1.0" Section 5
|
||||
* (https://tools.ietf.org/html/rfc2246#section-5) and
|
||||
* "The Transport Layer Security (TLS) Protocol Version 1.2" Section 5
|
||||
* (https://tools.ietf.org/html/rfc5246#section-5).
|
||||
*
|
||||
* For TLS v1.0 and TLS v1.1:
|
||||
*
|
||||
* PRF(secret, label, seed) = P_MD5(S1, label + seed) XOR
|
||||
* P_SHA-1(S2, label + seed)
|
||||
*
|
||||
* S1 is taken from the first half of the secret, S2 from the second half.
|
||||
*
|
||||
* L_S = length in bytes of secret;
|
||||
* L_S1 = L_S2 = ceil(L_S / 2);
|
||||
*
|
||||
* For TLS v1.2:
|
||||
*
|
||||
* PRF(secret, label, seed) = P_<hash>(secret, label + seed)
|
||||
*/
|
||||
static int tls1_prf_alg(const EVP_MD *md,
|
||||
const unsigned char *sec, size_t slen,
|
||||
const unsigned char *seed, size_t seed_len,
|
||||
unsigned char *out, size_t olen)
|
||||
{
|
||||
if (EVP_MD_type(md) == NID_md5_sha1) {
|
||||
/* TLS v1.0 and TLS v1.1 */
|
||||
size_t i;
|
||||
unsigned char *tmp;
|
||||
if (!tls1_prf_P_hash(EVP_md5(), sec, slen/2 + (slen & 1),
|
||||
/* calc: L_S1 = L_S2 = ceil(L_S / 2) */
|
||||
size_t L_S1 = (slen + 1) / 2;
|
||||
size_t L_S2 = L_S1;
|
||||
|
||||
if (!tls1_prf_P_hash(EVP_md5(), sec, L_S1,
|
||||
seed, seed_len, out, olen))
|
||||
return 0;
|
||||
|
||||
@@ -256,7 +336,7 @@ static int tls1_prf_alg(const EVP_MD *md,
|
||||
KDFerr(KDF_F_TLS1_PRF_ALG, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
if (!tls1_prf_P_hash(EVP_sha1(), sec + slen/2, slen/2 + (slen & 1),
|
||||
if (!tls1_prf_P_hash(EVP_sha1(), sec + slen - L_S2, L_S2,
|
||||
seed, seed_len, tmp, olen)) {
|
||||
OPENSSL_clear_free(tmp, olen);
|
||||
return 0;
|
||||
@@ -266,6 +346,8 @@ static int tls1_prf_alg(const EVP_MD *md,
|
||||
OPENSSL_clear_free(tmp, olen);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TLS v1.2 */
|
||||
if (!tls1_prf_P_hash(md, sec, slen, seed, seed_len, out, olen))
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
lhash.c lh_stats.c
|
||||
SOURCE[../../providers/fips]=\
|
||||
lhash.c
|
||||
@@ -439,6 +439,7 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls)
|
||||
|
||||
if ((sloc = OCSP_SERVICELOC_new()) == NULL)
|
||||
goto err;
|
||||
X509_NAME_free(sloc->issuer);
|
||||
if ((sloc->issuer = X509_NAME_dup(issuer)) == NULL)
|
||||
goto err;
|
||||
if (urls && *urls
|
||||
@@ -449,12 +450,11 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls)
|
||||
goto err;
|
||||
if ((ad->method = OBJ_nid2obj(NID_ad_OCSP)) == NULL)
|
||||
goto err;
|
||||
if ((ad->location = GENERAL_NAME_new()) == NULL)
|
||||
goto err;
|
||||
if ((ia5 = ASN1_IA5STRING_new()) == NULL)
|
||||
goto err;
|
||||
if (!ASN1_STRING_set((ASN1_STRING *)ia5, *urls, -1))
|
||||
goto err;
|
||||
/* ad->location is allocated inside ACCESS_DESCRIPTION_new */
|
||||
ad->location->type = GEN_URI;
|
||||
ad->location->d.ia5 = ia5;
|
||||
ia5 = NULL;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=property_string.c property_parse.c property.c \
|
||||
property_err.c defn_cache.c
|
||||
SOURCE[../../providers/fips]=\
|
||||
property_string.c property_parse.c property.c defn_cache.c
|
||||
@@ -391,6 +391,8 @@ IMPLEMENT_LHASH_DOALL_ARG(QUERY, IMPL_CACHE_FLUSH);
|
||||
*/
|
||||
static void impl_cache_flush_cache(QUERY *c, IMPL_CACHE_FLUSH *state)
|
||||
{
|
||||
#if !defined(FIPS_MODE)
|
||||
/* TODO(3.0): No RAND_bytes yet in FIPS module. Add this back when available */
|
||||
OSSL_METHOD_STORE *store = state->store;
|
||||
unsigned int n;
|
||||
|
||||
@@ -404,6 +406,7 @@ static void impl_cache_flush_cache(QUERY *c, IMPL_CACHE_FLUSH *state)
|
||||
OPENSSL_free(lh_QUERY_delete(state->cache, c));
|
||||
else
|
||||
state->nelem++;
|
||||
#endif /* !defined(FIPS_MODE) */
|
||||
}
|
||||
|
||||
static void impl_cache_flush_one_alg(ossl_uintmax_t idx, ALGORITHM *alg,
|
||||
|
||||
+44
-4
@@ -275,7 +275,9 @@ void ossl_provider_free(OSSL_PROVIDER *prov)
|
||||
* the store. All we have to do here is clean it out.
|
||||
*/
|
||||
if (ref == 0) {
|
||||
#ifndef FIPS_MODE
|
||||
DSO_free(prov->module);
|
||||
#endif
|
||||
OPENSSL_free(prov->name);
|
||||
OPENSSL_free(prov->path);
|
||||
sk_INFOPAIR_pop_free(prov->parameters, free_infopair);
|
||||
@@ -338,9 +340,11 @@ static const OSSL_DISPATCH *core_dispatch; /* Define further down */
|
||||
/*
|
||||
* Internal version that doesn't affect the store flags, and thereby avoid
|
||||
* locking. Direct callers must remember to set the store flags when
|
||||
* appropriate
|
||||
* appropriate. The libctx parameter is only necessary when FIPS_MODE is set
|
||||
* (i.e. we are being called from inside the FIPS module) - it is ignored for
|
||||
* other uses.
|
||||
*/
|
||||
static int provider_activate(OSSL_PROVIDER *prov)
|
||||
static int provider_activate(OSSL_PROVIDER *prov, OPENSSL_CTX *libctx)
|
||||
{
|
||||
const OSSL_DISPATCH *provider_dispatch = NULL;
|
||||
|
||||
@@ -352,6 +356,9 @@ static int provider_activate(OSSL_PROVIDER *prov)
|
||||
* a loadable module.
|
||||
*/
|
||||
if (prov->init_function == NULL) {
|
||||
#ifdef FIPS_MODE
|
||||
return 0;
|
||||
#else
|
||||
if (prov->module == NULL) {
|
||||
char *allocated_path = NULL;
|
||||
const char *module_path = NULL;
|
||||
@@ -389,15 +396,38 @@ static int provider_activate(OSSL_PROVIDER *prov)
|
||||
if (prov->module != NULL)
|
||||
prov->init_function = (OSSL_provider_init_fn *)
|
||||
DSO_bind_func(prov->module, "OSSL_provider_init");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* We call the initialise function for the provider.
|
||||
*
|
||||
* If FIPS_MODE is defined then we are inside the FIPS module and are about
|
||||
* to recursively initialise ourselves. We need to do this so that we can
|
||||
* get all the provider callback functions set up in order for us to be able
|
||||
* to make EVP calls from within the FIPS module itself. Only algorithms
|
||||
* from the FIPS module itself are available via the FIPS module EVP
|
||||
* interface, i.e. we only ever have one provider available inside the FIPS
|
||||
* module - the FIPS provider itself.
|
||||
*
|
||||
* For modules in general we cannot know what value will be used for the
|
||||
* provctx - it is a "black box". But for the FIPS module we know that the
|
||||
* provctx is really a library context. We default the provctx value to the
|
||||
* same library context as was used for the EVP call that caused this call
|
||||
* to "provider_activate".
|
||||
*/
|
||||
#ifdef FIPS_MODE
|
||||
prov->provctx = libctx;
|
||||
#endif
|
||||
if (prov->init_function == NULL
|
||||
|| !prov->init_function(prov, core_dispatch, &provider_dispatch,
|
||||
&prov->provctx)) {
|
||||
CRYPTOerr(CRYPTO_F_PROVIDER_ACTIVATE, ERR_R_INIT_FAIL);
|
||||
ERR_add_error_data(2, "name=", prov->name);
|
||||
#ifndef FIPS_MODE
|
||||
DSO_free(prov->module);
|
||||
prov->module = NULL;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -430,7 +460,7 @@ static int provider_activate(OSSL_PROVIDER *prov)
|
||||
|
||||
int ossl_provider_activate(OSSL_PROVIDER *prov)
|
||||
{
|
||||
if (provider_activate(prov)) {
|
||||
if (provider_activate(prov, NULL)) {
|
||||
CRYPTO_THREAD_write_lock(prov->store->lock);
|
||||
prov->store->use_fallbacks = 0;
|
||||
CRYPTO_THREAD_unlock(prov->store->lock);
|
||||
@@ -507,7 +537,7 @@ int ossl_provider_forall_loaded(OPENSSL_CTX *ctx,
|
||||
*/
|
||||
if (prov->flag_fallback) {
|
||||
activated_fallback_count++;
|
||||
provider_activate(prov);
|
||||
provider_activate(prov, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,13 +587,21 @@ const DSO *ossl_provider_dso(OSSL_PROVIDER *prov)
|
||||
|
||||
const char *ossl_provider_module_name(OSSL_PROVIDER *prov)
|
||||
{
|
||||
#ifdef FIPS_MODE
|
||||
return NULL;
|
||||
#else
|
||||
return DSO_get_filename(prov->module);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *ossl_provider_module_path(OSSL_PROVIDER *prov)
|
||||
{
|
||||
#ifdef FIPS_MODE
|
||||
return NULL;
|
||||
#else
|
||||
/* FIXME: Ensure it's a full path */
|
||||
return DSO_get_filename(prov->module);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Wrappers around calls to the provider */
|
||||
@@ -643,6 +681,8 @@ static int core_get_params(const OSSL_PROVIDER *prov, const OSSL_PARAM params[])
|
||||
static const OSSL_DISPATCH core_dispatch_[] = {
|
||||
{ OSSL_FUNC_CORE_GET_PARAM_TYPES, (void (*)(void))core_get_param_types },
|
||||
{ OSSL_FUNC_CORE_GET_PARAMS, (void (*)(void))core_get_params },
|
||||
{ OSSL_FUNC_CORE_PUT_ERROR, (void (*)(void))ERR_put_error },
|
||||
{ OSSL_FUNC_CORE_ADD_ERROR_VDATA, (void (*)(void))ERR_add_error_vdata },
|
||||
{ 0, NULL }
|
||||
};
|
||||
static const OSSL_DISPATCH *core_dispatch = core_dispatch_;
|
||||
@@ -11,8 +11,13 @@
|
||||
#include "provider_local.h"
|
||||
|
||||
OSSL_provider_init_fn ossl_default_provider_init;
|
||||
OSSL_provider_init_fn fips_intern_provider_init;
|
||||
|
||||
const struct predefined_providers_st predefined_providers[] = {
|
||||
#ifdef FIPS_MODE
|
||||
{ "fips", fips_intern_provider_init, 1 },
|
||||
#else
|
||||
{ "default", ossl_default_provider_init, 1 },
|
||||
#endif
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
@@ -1,2 +1,3 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=stack.c
|
||||
SOURCE[../../providers/fips]=stack.c
|
||||
@@ -175,7 +175,10 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
|
||||
return 1;
|
||||
}
|
||||
|
||||
# ifdef OPENSSL_SYS_UNIX
|
||||
# ifndef FIPS_MODE
|
||||
/* TODO(3.0): No fork protection in FIPS module yet! */
|
||||
|
||||
# ifdef OPENSSL_SYS_UNIX
|
||||
static pthread_once_t fork_once_control = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void fork_once_func(void)
|
||||
@@ -183,14 +186,15 @@ static void fork_once_func(void)
|
||||
pthread_atfork(OPENSSL_fork_prepare,
|
||||
OPENSSL_fork_parent, OPENSSL_fork_child);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
int openssl_init_fork_handlers(void)
|
||||
{
|
||||
# ifdef OPENSSL_SYS_UNIX
|
||||
# ifdef OPENSSL_SYS_UNIX
|
||||
if (pthread_once(&fork_once_control, fork_once_func) == 0)
|
||||
return 1;
|
||||
# endif
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
# endif /* FIPS_MODE */
|
||||
#endif
|
||||
@@ -143,7 +143,7 @@ void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
|
||||
a->type = type;
|
||||
}
|
||||
|
||||
void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype)
|
||||
void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype)
|
||||
{
|
||||
if (ptype)
|
||||
*ptype = a->type;
|
||||
@@ -188,7 +188,7 @@ int GENERAL_NAME_set0_othername(GENERAL_NAME *gen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen,
|
||||
int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen,
|
||||
ASN1_OBJECT **poid, ASN1_TYPE **pvalue)
|
||||
{
|
||||
if (gen->type != GEN_OTHERNAME)
|
||||
|
||||
@@ -46,7 +46,7 @@ are used as untrusted CAs. If CRL checking is enabled in B<store> any internal
|
||||
CRLs are used in addition to attempting to look them up in B<store>. If any
|
||||
chain verify fails an error code is returned.
|
||||
|
||||
Finally the signed content is read (and written to B<out> is it is not NULL)
|
||||
Finally the signed content is read (and written to B<out> if it is not NULL)
|
||||
and the signature's checked.
|
||||
|
||||
If all signature's verify correctly then the function is successful.
|
||||
|
||||
@@ -150,10 +150,20 @@ the X509_LOOKUP context, the type of the X509_OBJECT being requested, parameters
|
||||
related to the lookup, and an X509_OBJECT that will receive the requested
|
||||
object.
|
||||
|
||||
Implementations should use either X509_OBJECT_set1_X509() or
|
||||
X509_OBJECT_set1_X509_CRL() to set the result. Any method data that was
|
||||
created as a result of the new_item function set by
|
||||
X509_LOOKUP_meth_set_new_item() can be accessed with
|
||||
Implementations must add objects they find to the B<X509_STORE> object
|
||||
using X509_STORE_add_cert() or X509_STORE_add_crl(). This increments
|
||||
its reference count. However, the X509_STORE_CTX_get_by_subject()
|
||||
function also increases the reference count which leads to one too
|
||||
many references being held. Therefore applications should
|
||||
additionally call X509_free() or X509_CRL_free() to decrement the
|
||||
reference count again.
|
||||
|
||||
Implementations should also use either X509_OBJECT_set1_X509() or
|
||||
X509_OBJECT_set1_X509_CRL() to set the result. Note that this also
|
||||
increments the result's reference count.
|
||||
|
||||
Any method data that was created as a result of the new_item function
|
||||
set by X509_LOOKUP_meth_set_new_item() can be accessed with
|
||||
X509_LOOKUP_get_method_data(). The B<X509_STORE> object that owns the
|
||||
X509_LOOKUP may be accessed with X509_LOOKUP_get_store(). Successful lookups
|
||||
should return 1, and unsuccessful lookups should return 0.
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
=head1 NAME
|
||||
|
||||
d2i_PrivateKey, d2i_PublicKey, d2i_AutoPrivateKey,
|
||||
i2d_PrivateKey, i2d_PublicKey,
|
||||
d2i_PrivateKey_bio, d2i_PrivateKey_fp
|
||||
d2i_PrivateKey, d2i_PublicKey, d2i_KeyParams, d2i_AutoPrivateKey,
|
||||
i2d_PrivateKey, i2d_PublicKey, i2d_KeyParams, i2d_KeyParams_bio,
|
||||
d2i_PrivateKey_bio, d2i_PrivateKey_fp, d2i_KeyParams_bio
|
||||
- decode and encode functions for reading and saving EVP_PKEY structures
|
||||
|
||||
=head1 SYNOPSIS
|
||||
@@ -15,13 +15,19 @@ d2i_PrivateKey_bio, d2i_PrivateKey_fp
|
||||
long length);
|
||||
EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
long length);
|
||||
EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
long length);
|
||||
EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
|
||||
long length);
|
||||
|
||||
int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
|
||||
int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp);
|
||||
int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
|
||||
int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
|
||||
|
||||
EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a);
|
||||
EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
|
||||
EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
@@ -30,6 +36,7 @@ use any key specific format or PKCS#8 unencrypted PrivateKeyInfo format. The
|
||||
B<type> parameter should be a public key algorithm constant such as
|
||||
B<EVP_PKEY_RSA>. An error occurs if the decoded key does not match B<type>.
|
||||
d2i_PublicKey() does the same for public keys.
|
||||
d2i_KeyParams() does the same for domain parameter keys.
|
||||
|
||||
d2i_AutoPrivateKey() is similar to d2i_PrivateKey() except it attempts to
|
||||
automatically detect the private key format.
|
||||
@@ -37,7 +44,7 @@ automatically detect the private key format.
|
||||
i2d_PrivateKey() encodes B<key>. It uses a key specific format or, if none is
|
||||
defined for that key type, PKCS#8 unencrypted PrivateKeyInfo format.
|
||||
i2d_PublicKey() does the same for public keys.
|
||||
|
||||
i2d_KeyParams() does the same for domain parameter keys.
|
||||
These functions are similar to the d2i_X509() functions; see L<d2i_X509(3)>.
|
||||
|
||||
=head1 NOTES
|
||||
@@ -57,12 +64,13 @@ EC_GROUP.
|
||||
=head1 RETURN VALUES
|
||||
|
||||
The d2i_PrivateKey(), d2i_AutoPrivateKey(), d2i_PrivateKey_bio(), d2i_PrivateKey_fp(),
|
||||
and d2i_PublicKey() functions return a valid B<EVP_KEY> structure or B<NULL> if an
|
||||
error occurs. The error code can be obtained by calling L<ERR_get_error(3)>.
|
||||
d2i_PublicKey(), d2i_KeyParams() and d2i_KeyParams_bio() functions return a valid
|
||||
B<EVP_KEY> structure or B<NULL> if an error occurs. The error code can be
|
||||
obtained by calling L<ERR_get_error(3)>.
|
||||
|
||||
i2d_PrivateKey() and i2d_PublicKey() return the number of bytes successfully
|
||||
encoded or a negative value if an error occurs. The error code can be obtained
|
||||
by calling L<ERR_get_error(3)>.
|
||||
i2d_PrivateKey(), i2d_PublicKey(), i2d_KeyParams() i2d_KeyParams_bio() return
|
||||
the number of bytes successfully encoded or a negative value if an error occurs.
|
||||
The error code can be obtained by calling L<ERR_get_error(3)>.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
|
||||
@@ -121,6 +121,10 @@ and seed value "seed":
|
||||
}
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
|
||||
=head1 CONFORMING TO
|
||||
|
||||
RFC 2246, RFC 5246 and NIST SP 800-135 r1
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<EVP_KDF_CTX>,
|
||||
|
||||
@@ -97,6 +97,7 @@ int ERR_load_ASN1_strings(void);
|
||||
# define ASN1_F_D2I_ASN1_OBJECT 147
|
||||
# define ASN1_F_D2I_ASN1_UINTEGER 150
|
||||
# define ASN1_F_D2I_AUTOPRIVATEKEY 207
|
||||
# define ASN1_F_D2I_KEYPARAMS 144
|
||||
# define ASN1_F_D2I_PRIVATEKEY 154
|
||||
# define ASN1_F_D2I_PUBLICKEY 155
|
||||
# define ASN1_F_DO_BUF 142
|
||||
@@ -108,6 +109,7 @@ int ERR_load_ASN1_strings(void);
|
||||
# define ASN1_F_I2D_ASN1_OBJECT 143
|
||||
# define ASN1_F_I2D_DSA_PUBKEY 161
|
||||
# define ASN1_F_I2D_EC_PUBKEY 181
|
||||
# define ASN1_F_I2D_KEYPARAMS 145
|
||||
# define ASN1_F_I2D_PRIVATEKEY 163
|
||||
# define ASN1_F_I2D_PUBLICKEY 164
|
||||
# define ASN1_F_I2D_RSA_PUBKEY 165
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#ifndef OSSL_CORE_NUMBERS_H
|
||||
# define OSSL_CORE_NUMBERS_H
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <openssl/core.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
@@ -57,6 +58,12 @@ OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,
|
||||
# define OSSL_FUNC_CORE_GET_PARAMS 2
|
||||
OSSL_CORE_MAKE_FUNC(int,core_get_params,(const OSSL_PROVIDER *prov,
|
||||
const OSSL_PARAM params[]))
|
||||
# define OSSL_FUNC_CORE_PUT_ERROR 3
|
||||
OSSL_CORE_MAKE_FUNC(void,core_put_error,(int lib, int func, int reason,
|
||||
const char *file, int line))
|
||||
# define OSSL_FUNC_CORE_ADD_ERROR_VDATA 4
|
||||
OSSL_CORE_MAKE_FUNC(void,core_add_error_vdata,(int num, va_list args))
|
||||
|
||||
|
||||
/* Functions provided by the provider to the Core, reserved numbers 1024-1535 */
|
||||
# define OSSL_FUNC_PROVIDER_TEARDOWN 1024
|
||||
|
||||
@@ -1116,6 +1116,12 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
|
||||
long length);
|
||||
int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp);
|
||||
|
||||
int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp);
|
||||
EVP_PKEY *d2i_KeyParams(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
long length);
|
||||
int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey);
|
||||
EVP_PKEY *d2i_KeyParams_bio(int type, EVP_PKEY **a, BIO *in);
|
||||
|
||||
int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from);
|
||||
int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode);
|
||||
|
||||
@@ -497,10 +497,10 @@ DECLARE_ASN1_FUNCTIONS(OTHERNAME)
|
||||
DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME)
|
||||
int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b);
|
||||
void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value);
|
||||
void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype);
|
||||
void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype);
|
||||
int GENERAL_NAME_set0_othername(GENERAL_NAME *gen,
|
||||
ASN1_OBJECT *oid, ASN1_TYPE *value);
|
||||
int GENERAL_NAME_get0_otherName(GENERAL_NAME *gen,
|
||||
int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen,
|
||||
ASN1_OBJECT **poid, ASN1_TYPE **pvalue);
|
||||
|
||||
char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
SUBDIRS=common default
|
||||
|
||||
INCLUDE[../libcrypto]=common/include
|
||||
|
||||
IF[{- !$disabled{fips} -}]
|
||||
SUBDIRS=fips
|
||||
MODULES=fips
|
||||
|
||||
@@ -13,10 +13,19 @@
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
/* TODO(3.0): Needed for dummy_evp_call(). To be removed */
|
||||
#include <openssl/sha.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/property.h"
|
||||
#include "internal/evp_int.h"
|
||||
|
||||
/* Functions provided by the core */
|
||||
static OSSL_core_get_param_types_fn *c_get_param_types = NULL;
|
||||
static OSSL_core_get_params_fn *c_get_params = NULL;
|
||||
static OSSL_core_put_error_fn *c_put_error = NULL;
|
||||
static OSSL_core_add_error_vdata_fn *c_add_error_vdata = NULL;
|
||||
|
||||
/* Parameters we provide to the core */
|
||||
static const OSSL_ITEM fips_param_types[] = {
|
||||
@@ -26,6 +35,40 @@ static const OSSL_ITEM fips_param_types[] = {
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* TODO(3.0): To be removed */
|
||||
static int dummy_evp_call(OPENSSL_CTX *libctx)
|
||||
{
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
EVP_MD *sha256 = EVP_MD_fetch(libctx, "SHA256", NULL);
|
||||
char msg[] = "Hello World!";
|
||||
const unsigned char exptd[] = {
|
||||
0x7f, 0x83, 0xb1, 0x65, 0x7f, 0xf1, 0xfc, 0x53, 0xb9, 0x2d, 0xc1, 0x81,
|
||||
0x48, 0xa1, 0xd6, 0x5d, 0xfc, 0x2d, 0x4b, 0x1f, 0xa3, 0xd6, 0x77, 0x28,
|
||||
0x4a, 0xdd, 0xd2, 0x00, 0x12, 0x6d, 0x90, 0x69
|
||||
};
|
||||
unsigned int dgstlen = 0;
|
||||
unsigned char dgst[SHA256_DIGEST_LENGTH];
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL || sha256 == NULL)
|
||||
goto err;
|
||||
|
||||
if (!EVP_DigestInit_ex(ctx, sha256, NULL))
|
||||
goto err;
|
||||
if (!EVP_DigestUpdate(ctx, msg, sizeof(msg) - 1))
|
||||
goto err;
|
||||
if (!EVP_DigestFinal(ctx, dgst, &dgstlen))
|
||||
goto err;
|
||||
if (dgstlen != sizeof(exptd) || memcmp(dgst, exptd, sizeof(exptd)) != 0)
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_MD_CTX_free(ctx);
|
||||
EVP_MD_meth_free(sha256);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const OSSL_ITEM *fips_get_param_types(const OSSL_PROVIDER *prov)
|
||||
{
|
||||
return fips_param_types;
|
||||
@@ -70,17 +113,31 @@ static const OSSL_ALGORITHM *fips_query(OSSL_PROVIDER *prov,
|
||||
|
||||
/* Functions we provide to the core */
|
||||
static const OSSL_DISPATCH fips_dispatch_table[] = {
|
||||
/*
|
||||
* To release our resources we just need to free the OPENSSL_CTX so we just
|
||||
* use OPENSSL_CTX_free directly as our teardown function
|
||||
*/
|
||||
{ OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))OPENSSL_CTX_free },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))fips_get_param_types },
|
||||
{ OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))fips_get_params },
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* Functions we provide to ourself */
|
||||
static const OSSL_DISPATCH intern_dispatch_table[] = {
|
||||
{ OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
OPENSSL_CTX *ctx;
|
||||
|
||||
for (; in->function_id != 0; in++) {
|
||||
switch (in->function_id) {
|
||||
case OSSL_FUNC_CORE_GET_PARAM_TYPES:
|
||||
@@ -89,12 +146,77 @@ int OSSL_provider_init(const OSSL_PROVIDER *provider,
|
||||
case OSSL_FUNC_CORE_GET_PARAMS:
|
||||
c_get_params = OSSL_get_core_get_params(in);
|
||||
break;
|
||||
case OSSL_FUNC_CORE_PUT_ERROR:
|
||||
c_put_error = OSSL_get_core_put_error(in);
|
||||
break;
|
||||
case OSSL_FUNC_CORE_ADD_ERROR_VDATA:
|
||||
c_add_error_vdata = OSSL_get_core_add_error_vdata(in);
|
||||
break;
|
||||
/* Just ignore anything we don't understand */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx = OPENSSL_CTX_new();
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* TODO(3.0): Remove me. This is just a dummy call to demonstrate making
|
||||
* EVP calls from within the FIPS module.
|
||||
*/
|
||||
if (!dummy_evp_call(ctx)) {
|
||||
OPENSSL_CTX_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out = fips_dispatch_table;
|
||||
*provctx = ctx;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The internal init function used when the FIPS module uses EVP to call
|
||||
* another algorithm also in the FIPS module. This is a recursive call that has
|
||||
* been made from within the FIPS module itself. Normally we are responsible for
|
||||
* providing our own provctx value, but in this recursive case it has been
|
||||
* pre-populated for us with the same library context that was used in the EVP
|
||||
* call that initiated this recursive call - so we don't need to do anything
|
||||
* further with that parameter. This only works because we *know* in the core
|
||||
* code that the FIPS module uses a library context for its provctx. This is
|
||||
* not generally true for all providers.
|
||||
*/
|
||||
OSSL_provider_init_fn fips_intern_provider_init;
|
||||
int fips_intern_provider_init(const OSSL_PROVIDER *provider,
|
||||
const OSSL_DISPATCH *in,
|
||||
const OSSL_DISPATCH **out,
|
||||
void **provctx)
|
||||
{
|
||||
*out = intern_dispatch_table;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ERR_put_error(int lib, int func, int reason, const char *file, int line)
|
||||
{
|
||||
/*
|
||||
* TODO(3.0): This works for the FIPS module because we're going to be
|
||||
* using lib/func/reason codes that libcrypto already knows about. This
|
||||
* won't work for third party providers that have their own error mechanisms,
|
||||
* so we'll need to come up with something else for them.
|
||||
*/
|
||||
c_put_error(lib, func, reason, file, line);
|
||||
}
|
||||
|
||||
void ERR_add_error_data(int num, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, num);
|
||||
ERR_add_error_vdata(num, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ERR_add_error_vdata(int num, va_list args)
|
||||
{
|
||||
c_add_error_vdata(num, args);
|
||||
}
|
||||
+1
-1
@@ -1727,7 +1727,7 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
|
||||
const char *ver;
|
||||
const char *kx, *au, *enc, *mac;
|
||||
uint32_t alg_mkey, alg_auth, alg_enc, alg_mac;
|
||||
static const char *format = "%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n";
|
||||
static const char *format = "%-30s %-7s Kx=%-8s Au=%-5s Enc=%-9s Mac=%-4s\n";
|
||||
|
||||
if (buf == NULL) {
|
||||
len = 128;
|
||||
|
||||
+18
-12
@@ -31,7 +31,7 @@ static int tls1_PRF(SSL *s,
|
||||
unsigned char *out, size_t olen, int fatal)
|
||||
{
|
||||
const EVP_MD *md = ssl_prf_md(s);
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
EVP_KDF_CTX *kctx = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (md == NULL) {
|
||||
@@ -43,16 +43,22 @@ static int tls1_PRF(SSL *s,
|
||||
SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
|
||||
if (pctx == NULL || EVP_PKEY_derive_init(pctx) <= 0
|
||||
|| EVP_PKEY_CTX_set_tls1_prf_md(pctx, md) <= 0
|
||||
|| EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, sec, (int)slen) <= 0
|
||||
|| EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed1, (int)seed1_len) <= 0
|
||||
|| EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed2, (int)seed2_len) <= 0
|
||||
|| EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed3, (int)seed3_len) <= 0
|
||||
|| EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed4, (int)seed4_len) <= 0
|
||||
|| EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed5, (int)seed5_len) <= 0
|
||||
|| EVP_PKEY_derive(pctx, out, &olen) <= 0) {
|
||||
kctx = EVP_KDF_CTX_new_id(EVP_PKEY_TLS1_PRF);
|
||||
if (kctx == NULL
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_TLS_SECRET,
|
||||
sec, (size_t)slen) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED,
|
||||
seed1, (size_t)seed1_len) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED,
|
||||
seed2, (size_t)seed2_len) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED,
|
||||
seed3, (size_t)seed3_len) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED,
|
||||
seed4, (size_t)seed4_len) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED,
|
||||
seed5, (size_t)seed5_len) <= 0
|
||||
|| EVP_KDF_derive(kctx, out, olen) <= 0) {
|
||||
if (fatal)
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS1_PRF,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
@@ -64,7 +70,7 @@ static int tls1_PRF(SSL *s,
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+24
-26
@@ -31,7 +31,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
unsigned char *out, size_t outlen, int fatal)
|
||||
{
|
||||
static const unsigned char label_prefix[] = "tls13 ";
|
||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_PKEY_HKDF);
|
||||
int ret;
|
||||
size_t hkdflabellen;
|
||||
size_t hashlen;
|
||||
@@ -45,7 +45,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
+ 1 + EVP_MAX_MD_SIZE];
|
||||
WPACKET pkt;
|
||||
|
||||
if (pctx == NULL)
|
||||
if (kctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (labellen > TLS13_MAX_LABEL_LEN) {
|
||||
@@ -59,7 +59,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
*/
|
||||
SSLerr(SSL_F_TLS13_HKDF_EXPAND, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
|
||||
}
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
|| !WPACKET_sub_memcpy_u8(&pkt, data, (data == NULL) ? 0 : datalen)
|
||||
|| !WPACKET_get_total_written(&pkt, &hkdflabellen)
|
||||
|| !WPACKET_finish(&pkt)) {
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
WPACKET_cleanup(&pkt);
|
||||
if (fatal)
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_HKDF_EXPAND,
|
||||
@@ -84,15 +84,15 @@ int tls13_hkdf_expand(SSL *s, const EVP_MD *md, const unsigned char *secret,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = EVP_PKEY_derive_init(pctx) <= 0
|
||||
|| EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY)
|
||||
<= 0
|
||||
|| EVP_PKEY_CTX_set_hkdf_md(pctx, md) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_key(pctx, secret, hashlen) <= 0
|
||||
|| EVP_PKEY_CTX_add1_hkdf_info(pctx, hkdflabel, hkdflabellen) <= 0
|
||||
|| EVP_PKEY_derive(pctx, out, &outlen) <= 0;
|
||||
ret = EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_HKDF_MODE,
|
||||
EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, secret, hashlen) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO,
|
||||
hkdflabel, hkdflabellen) <= 0
|
||||
|| EVP_KDF_derive(kctx, out, outlen) <= 0;
|
||||
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
|
||||
if (ret != 0) {
|
||||
if (fatal)
|
||||
@@ -155,11 +155,11 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
size_t mdlen, prevsecretlen;
|
||||
int mdleni;
|
||||
int ret;
|
||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL);
|
||||
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_PKEY_HKDF);
|
||||
static const char derived_secret_label[] = "derived";
|
||||
unsigned char preextractsec[EVP_MAX_MD_SIZE];
|
||||
|
||||
if (pctx == NULL) {
|
||||
if (kctx == NULL) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
@@ -192,7 +192,7 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
EVP_MD_CTX_free(mctx);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
EVP_MD_CTX_free(mctx);
|
||||
@@ -203,7 +203,7 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
sizeof(derived_secret_label) - 1, hash, mdlen,
|
||||
preextractsec, mdlen, 1)) {
|
||||
/* SSLfatal() already called */
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -211,21 +211,19 @@ int tls13_generate_secret(SSL *s, const EVP_MD *md,
|
||||
prevsecretlen = mdlen;
|
||||
}
|
||||
|
||||
ret = EVP_PKEY_derive_init(pctx) <= 0
|
||||
|| EVP_PKEY_CTX_hkdf_mode(pctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY)
|
||||
<= 0
|
||||
|| EVP_PKEY_CTX_set_hkdf_md(pctx, md) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_key(pctx, insecret, insecretlen) <= 0
|
||||
|| EVP_PKEY_CTX_set1_hkdf_salt(pctx, prevsecret, prevsecretlen)
|
||||
<= 0
|
||||
|| EVP_PKEY_derive(pctx, outsecret, &mdlen)
|
||||
<= 0;
|
||||
ret = EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_HKDF_MODE,
|
||||
EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, insecret, insecretlen) <= 0
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT,
|
||||
prevsecret, prevsecretlen) <= 0
|
||||
|| EVP_KDF_derive(kctx, outsecret, mdlen) <= 0;
|
||||
|
||||
if (ret != 0)
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS13_GENERATE_SECRET,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
if (prevsecret == preextractsec)
|
||||
OPENSSL_cleanse(preextractsec, mdlen);
|
||||
return ret == 0;
|
||||
|
||||
+5
-1
@@ -50,7 +50,7 @@ IF[{- !$disabled{tests} -}]
|
||||
time_offset_test pemtest ssl_cert_table_internal_test ciphername_test \
|
||||
servername_test ocspapitest rsa_mp_test fatalerrtest tls13ccstest \
|
||||
sysdefaulttest errtest gosttest \
|
||||
context_internal_test aesgcmtest params_test
|
||||
context_internal_test aesgcmtest params_test evp_pkey_dparams_test
|
||||
|
||||
SOURCE[versions]=versions.c
|
||||
INCLUDE[versions]=../include ../apps/include
|
||||
@@ -350,6 +350,10 @@ IF[{- !$disabled{tests} -}]
|
||||
INCLUDE[evp_kdf_test]=../include ../apps/include
|
||||
DEPEND[evp_kdf_test]=../libcrypto libtestutil.a
|
||||
|
||||
SOURCE[evp_pkey_dparams_test]=evp_pkey_dparams_test.c
|
||||
INCLUDE[evp_pkey_dparams_test]=../include ../apps/include
|
||||
DEPEND[evp_pkey_dparams_test]=../libcrypto libtestutil.a
|
||||
|
||||
SOURCE[x509_time_test]=x509_time_test.c
|
||||
INCLUDE[x509_time_test]=../include ../apps/include
|
||||
DEPEND[x509_time_test]=../libcrypto libtestutil.a
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "internal/nelem.h"
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ec.h>
|
||||
#include "testutil.h"
|
||||
|
||||
static int pkey_param_types[] = {
|
||||
#ifndef OPENSSL_NO_DH
|
||||
EVP_PKEY_DH,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
EVP_PKEY_DSA,
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
EVP_PKEY_EC
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
|
||||
|
||||
static int params_bio_test(int id)
|
||||
{
|
||||
int ret;
|
||||
BIO *mem_bio = NULL;
|
||||
EVP_PKEY_CTX *ctx = NULL;
|
||||
EVP_PKEY *params_key = NULL, *out_key = NULL;
|
||||
int type = pkey_param_types[id];
|
||||
|
||||
ret =
|
||||
TEST_ptr(mem_bio = BIO_new(BIO_s_mem()))
|
||||
&& TEST_ptr(ctx = EVP_PKEY_CTX_new_id(type, NULL))
|
||||
&& TEST_int_gt(EVP_PKEY_paramgen_init(ctx), 0)
|
||||
&& (type != EVP_PKEY_EC
|
||||
|| EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, NID_secp256k1) > 0)
|
||||
&& TEST_int_gt(EVP_PKEY_paramgen(ctx, ¶ms_key), 0)
|
||||
&& TEST_int_gt(i2d_KeyParams_bio(mem_bio, params_key), 0)
|
||||
&& TEST_ptr(d2i_KeyParams_bio(type, &out_key, mem_bio))
|
||||
&& TEST_int_gt(EVP_PKEY_cmp_parameters(out_key, params_key), 0);
|
||||
|
||||
BIO_free(mem_bio);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
EVP_PKEY_free(params_key);
|
||||
EVP_PKEY_free(out_key);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
#if defined(OPENSSL_NO_DH) && defined(OPENSSL_NO_DSA) && defined(OPENSSL_NO_EC)
|
||||
TEST_note("No DH/DSA/EC support");
|
||||
#else
|
||||
ADD_ALL_TESTS(params_bio_test, OSSL_NELEM(pkey_param_types));
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
+81
-1
@@ -47,6 +47,24 @@ static int get_cert_and_key(X509 **cert_out, EVP_PKEY **key_out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_cert(X509 **cert_out)
|
||||
{
|
||||
BIO *certbio;
|
||||
X509 *cert = NULL;
|
||||
|
||||
if (!TEST_ptr(certbio = BIO_new_file(certstr, "r")))
|
||||
return 0;
|
||||
cert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
|
||||
BIO_free(certbio);
|
||||
if (!TEST_ptr(cert))
|
||||
goto end;
|
||||
*cert_out = cert;
|
||||
return 1;
|
||||
end:
|
||||
X509_free(cert);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static OCSP_BASICRESP *make_dummy_resp(void)
|
||||
{
|
||||
const unsigned char namestr[] = "openssl.example.com";
|
||||
@@ -131,7 +149,67 @@ static int test_resp_signer(void)
|
||||
EVP_PKEY_free(key);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_access_description(int testcase)
|
||||
{
|
||||
ACCESS_DESCRIPTION *ad = ACCESS_DESCRIPTION_new();
|
||||
int ret = 0;
|
||||
|
||||
if (!TEST_ptr(ad))
|
||||
goto err;
|
||||
|
||||
switch (testcase) {
|
||||
case 0: /* no change */
|
||||
break;
|
||||
case 1: /* check and release current location */
|
||||
if (!TEST_ptr(ad->location))
|
||||
goto err;
|
||||
GENERAL_NAME_free(ad->location);
|
||||
ad->location = NULL;
|
||||
break;
|
||||
case 2: /* replace current location */
|
||||
GENERAL_NAME_free(ad->location);
|
||||
ad->location = GENERAL_NAME_new();
|
||||
if (!TEST_ptr(ad->location))
|
||||
goto err;
|
||||
break;
|
||||
}
|
||||
ACCESS_DESCRIPTION_free(ad);
|
||||
ret = 1;
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_ocsp_url_svcloc_new(void)
|
||||
{
|
||||
static const char * urls[] = {
|
||||
"www.openssl.org",
|
||||
"www.openssl.net",
|
||||
NULL
|
||||
};
|
||||
|
||||
X509 *issuer = NULL;
|
||||
X509_EXTENSION * ext = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (!TEST_true(get_cert(&issuer)))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Test calling this ocsp method to catch any memory leak
|
||||
*/
|
||||
ext = OCSP_url_svcloc_new(X509_get_issuer_name(issuer), urls);
|
||||
if (!TEST_ptr(ext))
|
||||
goto err;
|
||||
|
||||
X509_EXTENSION_free(ext);
|
||||
ret = 1;
|
||||
err:
|
||||
X509_free(issuer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* OPENSSL_NO_OCSP */
|
||||
|
||||
OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
|
||||
|
||||
@@ -142,6 +220,8 @@ int setup_tests(void)
|
||||
return 0;
|
||||
#ifndef OPENSSL_NO_OCSP
|
||||
ADD_TEST(test_resp_signer);
|
||||
ADD_ALL_TESTS(test_access_description, 3);
|
||||
ADD_TEST(test_ocsp_url_svcloc_new);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ setup("test_evp");
|
||||
|
||||
my @files = ( "evpciph.txt", "evpdigest.txt", "evpencod.txt", "evpkdf.txt",
|
||||
"evppkey_kdf.txt", "evpmac.txt", "evppbe.txt", "evppkey.txt",
|
||||
"evppkey_ecc.txt", "evpcase.txt", "evpaessiv.txt" );
|
||||
"evppkey_ecc.txt", "evpcase.txt", "evpaessiv.txt", "evpccmcavs.txt" );
|
||||
|
||||
plan tests => scalar(@files);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
use OpenSSL::Test::Simple;
|
||||
|
||||
simple_test("test_evp_pkey_dparam", "evp_pkey_dparams_test");
|
||||
@@ -0,0 +1,121 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
#Convert CCM CAVS test vectors to a format suitable for evp_test
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $alg;
|
||||
my $mode;
|
||||
my $keylen;
|
||||
my $key = "";
|
||||
my $iv = "";
|
||||
my $aad = "";
|
||||
my $ct = "";
|
||||
my $pt = "";
|
||||
my $tag = "";
|
||||
my $aadlen = 0;
|
||||
my $ptlen = 0;
|
||||
my $taglen = 0;
|
||||
my $res = "";
|
||||
my $intest = 0;
|
||||
my $fixediv = 0;
|
||||
|
||||
while (<STDIN>)
|
||||
{
|
||||
chomp;
|
||||
|
||||
# Pull out the cipher mode from the comment at the beginning of the file
|
||||
if(/^#\s*"([^-]+)-\w+" information/) {
|
||||
$mode = lc($1);
|
||||
# Pull out the key length from the comment at the beginning of the file
|
||||
} elsif(/^#\s*(\w+) Keylen: (\d+)/) {
|
||||
$alg = lc($1);
|
||||
$keylen = $2;
|
||||
# Some parameters common to many tests appear as a list in square brackets
|
||||
# so parse these
|
||||
} elsif(/\[(.*)\]/) {
|
||||
my @pairs = split(/, /, $1);
|
||||
foreach my $pair (@pairs) {
|
||||
$pair =~ /(\w+)\s*=\s*(\d+)/;
|
||||
# AAD Length
|
||||
if ($1 eq "Alen") {
|
||||
$aadlen = $2;
|
||||
# Plaintext length
|
||||
} elsif ($1 eq "Plen") {
|
||||
$ptlen = $2;
|
||||
# Tag length
|
||||
} elsif ($1 eq "Tlen") {
|
||||
$taglen = $2;
|
||||
}
|
||||
}
|
||||
# Key/Value pair
|
||||
} elsif (/^\s*(\w+)\s*=\s*(\S.*)\r/) {
|
||||
if ($1 eq "Key") {
|
||||
$key = $2;
|
||||
} elsif ($1 eq "Nonce") {
|
||||
$iv = $2;
|
||||
if ($intest == 0) {
|
||||
$fixediv = 1;
|
||||
} else {
|
||||
$fixediv = 0;
|
||||
}
|
||||
} elsif ($1 eq "Adata") {
|
||||
$aad = $2;
|
||||
} elsif ($1 eq "CT") {
|
||||
$ct = substr($2, 0, length($2) - ($taglen * 2));
|
||||
$tag = substr($2, $taglen * -2);
|
||||
} elsif ($1 eq "Payload") {
|
||||
$pt = $2;
|
||||
} elsif ($1 eq "Result") {
|
||||
if ($2 =~ /Fail/) {
|
||||
$res = "CIPHERUPDATE_ERROR";
|
||||
}
|
||||
} elsif ($1 eq "Count") {
|
||||
$intest = 1;
|
||||
} elsif ($1 eq "Plen") {
|
||||
$ptlen = $2;
|
||||
} elsif ($1 eq "Tlen") {
|
||||
$taglen = $2;
|
||||
} elsif ($1 eq "Alen") {
|
||||
$aadlen = $2;
|
||||
}
|
||||
# Something else - probably just a blank line
|
||||
} elsif ($intest) {
|
||||
print "Cipher = $alg-$keylen-$mode\n";
|
||||
print "Key = $key\n";
|
||||
print "IV = $iv\n";
|
||||
print "AAD =";
|
||||
if ($aadlen > 0) {
|
||||
print " $aad";
|
||||
}
|
||||
print "\nTag =";
|
||||
if ($taglen > 0) {
|
||||
print " $tag";
|
||||
}
|
||||
print "\nPlaintext =";
|
||||
if ($ptlen > 0) {
|
||||
print " $pt";
|
||||
}
|
||||
print "\nCiphertext = $ct\n";
|
||||
if ($res ne "") {
|
||||
print "Operation = DECRYPT\n";
|
||||
print "Result = $res\n";
|
||||
}
|
||||
print "\n";
|
||||
$res = "";
|
||||
if ($fixediv == 0) {
|
||||
$iv = "";
|
||||
}
|
||||
$aad = "";
|
||||
$tag = "";
|
||||
$pt = "";
|
||||
$intest = 0;
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -4804,4 +4804,8 @@ EVP_KDF_CTX_new 4751 3_0_0 EXIST::FUNCTION:
|
||||
EVP_KDF_CTX_kdf 4752 3_0_0 EXIST::FUNCTION:
|
||||
EVP_KDF_nid 4753 3_0_0 EXIST::FUNCTION:
|
||||
EVP_get_kdfbyname 4754 3_0_0 EXIST::FUNCTION:
|
||||
EVP_chacha20_poly1305_draft 4755 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305
|
||||
i2d_KeyParams 4755 3_0_0 EXIST::FUNCTION:
|
||||
d2i_KeyParams 4756 3_0_0 EXIST::FUNCTION:
|
||||
i2d_KeyParams_bio 4757 3_0_0 EXIST::FUNCTION:
|
||||
d2i_KeyParams_bio 4758 3_0_0 EXIST::FUNCTION:
|
||||
EVP_chacha20_poly1305_draft 4759 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305
|
||||
Reference in New Issue
Block a user