Latest update
This commit is contained in:
@@ -43,7 +43,7 @@ The tree height is dynamically increased as needed based on additions.
|
||||
An empty tree is represented by a NULL root pointer. Inserting a value at
|
||||
index 0 results in the allocation of a top level node full of null pointers
|
||||
except for the single pointer to the user's data (N = SA_BLOCK_MAX for
|
||||
breviety):
|
||||
brevity):
|
||||
|
||||
+----+
|
||||
|Root|
|
||||
|
||||
@@ -38,14 +38,14 @@
|
||||
# Implement AES_set_[en|de]crypt_key. Key schedule setup is avoided
|
||||
# for 128-bit keys, if hardware support is detected.
|
||||
|
||||
# Januray 2009.
|
||||
# January 2009.
|
||||
#
|
||||
# Add support for hardware AES192/256 and reschedule instructions to
|
||||
# minimize/avoid Address Generation Interlock hazard and to favour
|
||||
# dual-issue z10 pipeline. This gave ~25% improvement on z10 and
|
||||
# almost 50% on z9. The gain is smaller on z10, because being dual-
|
||||
# issue z10 makes it impossible to eliminate the interlock condition:
|
||||
# critial path is not long enough. Yet it spends ~24 cycles per byte
|
||||
# critical path is not long enough. Yet it spends ~24 cycles per byte
|
||||
# processed with 128-bit key.
|
||||
#
|
||||
# Unlike previous version hardware support detection takes place only
|
||||
|
||||
+65
-3
@@ -1,7 +1,69 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
aes_misc.c aes_ecb.c aes_cfb.c aes_ofb.c \
|
||||
aes_ige.c aes_wrap.c {- $target{aes_asm_src} -}
|
||||
|
||||
$AESASM=aes_core.c aes_cbc.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$AESASM_x86=aes-586.s
|
||||
$AESDEF_x86=AES_ASM
|
||||
$AESASM_x86_sse2=vpaes-x86.s aesni-x86.s
|
||||
$AESDEF_x86_sse2=VPAES_ASM
|
||||
|
||||
$AESASM_x86_64=\
|
||||
aes-x86_64.s vpaes-x86_64.s bsaes-x86_64.s aesni-x86_64.s \
|
||||
aesni-sha1-x86_64.s aesni-sha256-x86_64.s aesni-mb-x86_64.s
|
||||
$AESDEF_x86_64=AES_ASM VPAES_ASM BSAES_ASM
|
||||
|
||||
$AESASM_ia64=aes_core.c aes_cbc.c aes-ia64.s
|
||||
$AESDEF_ia64=AES_ASM
|
||||
|
||||
$AESASM_sparcv9=\
|
||||
aes_core.c aes_cbc.c aes-sparcv9.S aest4-sparcv9.S aesfx-sparcv9.S
|
||||
$AESDEF_sparcv9=AES_ASM
|
||||
|
||||
$AESASM_mips32=aes_cbc.c aes-mips.S
|
||||
$AESDEF_mips32=AES_ASM
|
||||
$AESASM_mips64=$AESASM_mips32
|
||||
$AESDEF_mips64=$AESDEF_mips32
|
||||
|
||||
$AESASM_s390x=aes-s390x.S
|
||||
# aes-390x.S implements AES_ctr32_encrypt and AES_xts_[en|de]crypt
|
||||
$AESDEF_s390x=AES_ASM AES_CTR_ASM AES_XTS_ASM
|
||||
|
||||
$AESASM_armv4=aes_cbc.c aes-armv4.S bsaes-armv7.S aesv8-armx.S
|
||||
$AESDEF_armv4=AES_ASM BSAES_ASM
|
||||
$AESASM_aarch64=aes_core.c aes_cbc.c aesv8-armx.S vpaes-armv8.S
|
||||
$AESDEF_aarch64=VPAES_ASM
|
||||
|
||||
$AESASM_parisc11=aes_core.c aes_cbc.c aes-parisc.s
|
||||
$AESDEF_parisc11=AES_ASM
|
||||
$AESASM_parisc20_64=$AESASM_parisc11
|
||||
$AESDEF_parisc20_64=$AESDEF_parisc11
|
||||
|
||||
$AESASM_ppc32=aes_core.c aes_cbc.c aes-ppc.s vpaes-ppc.s aesp8-ppc.s
|
||||
$AESDEF_ppc32=AES_ASM VPAES_ASM
|
||||
$AESASM_ppc64=$AESASM_ppc32
|
||||
$AESDEF_ppc64=$AESDEF_ppc32
|
||||
|
||||
$AESASM_c64xplus=aes-c64xplus.s aes_cbc.c
|
||||
# aes-c64xplus.s implements AES_ctr32_encrypt
|
||||
$AESDEF_c64xplus=AES_ASM AES_CTR_ASM
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one, and define the appropriate macros
|
||||
IF[$AESASM_{- $target{asm_arch} -}]
|
||||
$AESASM=$AESASM_{- $target{asm_arch} -}
|
||||
$AESDEF=$AESDEF_{- $target{asm_arch} -}
|
||||
IF[{- !$disabled{sse2} -}]
|
||||
$AESASM=$AESASM $AESASM_{- $target{asm_arch} -}_sse2
|
||||
$AESDEF=$AESDEF $AESDEF_{- $target{asm_arch} -}_sse2
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$COMMON=aes_misc.c aes_ecb.c $AESASM
|
||||
SOURCE[../../libcrypto]=$COMMON aes_cfb.c aes_ofb.c aes_ige.c aes_wrap.c
|
||||
DEFINE[../../libcrypto]=$AESDEF
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
DEFINE[../../providers/fips]=$AESDEF
|
||||
|
||||
GENERATE[aes-ia64.s]=asm/aes-ia64.S
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
unsigned char *buf_in = NULL, *buf_out = NULL;
|
||||
size_t inl = 0, outl = 0, outll = 0;
|
||||
int signid, paramtype, buf_len = 0;
|
||||
int rv;
|
||||
int rv, pkey_id;
|
||||
|
||||
type = EVP_MD_CTX_md(ctx);
|
||||
pkey = EVP_PKEY_CTX_get0_pkey(EVP_MD_CTX_pkey_ctx(ctx));
|
||||
@@ -184,9 +184,14 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ASN1_R_CONTEXT_NOT_INITIALISED);
|
||||
goto err;
|
||||
}
|
||||
if (!OBJ_find_sigid_by_algs(&signid,
|
||||
EVP_MD_nid(type),
|
||||
pkey->ameth->pkey_id)) {
|
||||
|
||||
pkey_id =
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
EVP_PKEY_id(pkey) == NID_sm2 ? NID_sm2 :
|
||||
#endif
|
||||
pkey->ameth->pkey_id;
|
||||
|
||||
if (!OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type), pkey_id)) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,
|
||||
ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED);
|
||||
goto err;
|
||||
|
||||
@@ -67,7 +67,7 @@ static void determine_days(struct tm *tm)
|
||||
}
|
||||
c = y / 100;
|
||||
y %= 100;
|
||||
/* Zeller's congruance */
|
||||
/* Zeller's congruence */
|
||||
tm->tm_wday = (d + (13 * m) / 5 + y + y / 4 + c / 4 + 5 * c + 6) % 7;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
|
||||
int ASN1_TYPE_get(const ASN1_TYPE *a)
|
||||
{
|
||||
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
|
||||
if (a->type == V_ASN1_BOOLEAN
|
||||
|| a->type == V_ASN1_NULL
|
||||
|| a->value.ptr != NULL)
|
||||
return a->type;
|
||||
else
|
||||
return 0;
|
||||
@@ -23,7 +25,9 @@ int ASN1_TYPE_get(const ASN1_TYPE *a)
|
||||
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
|
||||
{
|
||||
if (a->value.ptr != NULL) {
|
||||
if (a->type != V_ASN1_BOOLEAN
|
||||
&& a->type != V_ASN1_NULL
|
||||
&& a->value.ptr != NULL) {
|
||||
ASN1_TYPE **tmp_a = &a;
|
||||
asn1_primitive_free((ASN1_VALUE **)tmp_a, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
static CRYPTO_THREAD_LOCAL ctxkey;
|
||||
static CRYPTO_THREAD_LOCAL poolkey;
|
||||
|
||||
static void async_delete_thread_state(void *arg);
|
||||
|
||||
static async_ctx *async_ctx_new(void)
|
||||
{
|
||||
async_ctx *nctx;
|
||||
|
||||
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC))
|
||||
if (!ossl_init_thread_start(NULL, NULL, async_delete_thread_state))
|
||||
return NULL;
|
||||
|
||||
nctx = OPENSSL_malloc(sizeof(*nctx));
|
||||
@@ -326,7 +328,7 @@ int ASYNC_init_thread(size_t max_size, size_t init_size)
|
||||
if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
|
||||
return 0;
|
||||
|
||||
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC))
|
||||
if (!ossl_init_thread_start(NULL, NULL, async_delete_thread_state))
|
||||
return 0;
|
||||
|
||||
pool = OPENSSL_zalloc(sizeof(*pool));
|
||||
@@ -374,7 +376,8 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void async_delete_thread_state(void)
|
||||
/* TODO(3.0): arg ignored for now */
|
||||
static void async_delete_thread_state(void *arg)
|
||||
{
|
||||
async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey);
|
||||
|
||||
@@ -393,7 +396,7 @@ void ASYNC_cleanup_thread(void)
|
||||
if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
|
||||
return;
|
||||
|
||||
async_delete_thread_state();
|
||||
async_delete_thread_state(NULL);
|
||||
}
|
||||
|
||||
ASYNC_JOB *ASYNC_get_current_job(void)
|
||||
|
||||
+13
-2
@@ -1,6 +1,17 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c \
|
||||
{- $target{bf_asm_src} -}
|
||||
|
||||
$BFASM=bf_enc.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$BFASM_x86=bf-586.s
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one
|
||||
IF[$BFASM_{- $target{asm_arch} -}]
|
||||
$BFASM=$BFASM_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c $BFASM
|
||||
|
||||
GENERATE[bf-586.s]=asm/bf-586.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
|
||||
@@ -696,6 +696,7 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
|
||||
/* Note that |res| SHOULD be a 'struct addrinfo **' thanks to
|
||||
* macro magic in bio_lcl.h
|
||||
*/
|
||||
retry:
|
||||
switch ((gai_ret = getaddrinfo(host, service, &hints, res))) {
|
||||
# ifdef EAI_SYSTEM
|
||||
case EAI_SYSTEM:
|
||||
@@ -706,6 +707,19 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
|
||||
case 0:
|
||||
ret = 1; /* Success */
|
||||
break;
|
||||
# if (defined(EAI_FAMILY) || defined(EAI_ADDRFAMILY)) && defined(AI_ADDRCONFIG)
|
||||
# ifdef EAI_FAMILY
|
||||
case EAI_FAMILY:
|
||||
# endif
|
||||
# ifdef EAI_ADDRFAMILY
|
||||
case EAI_ADDRFAMILY:
|
||||
# endif
|
||||
if (hints.ai_flags & AI_ADDRCONFIG) {
|
||||
hints.ai_flags &= ~AI_ADDRCONFIG;
|
||||
goto retry;
|
||||
}
|
||||
# endif
|
||||
/* fall through */
|
||||
default:
|
||||
BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB);
|
||||
ERR_add_error_data(1, gai_strerror(gai_ret));
|
||||
|
||||
@@ -152,7 +152,7 @@ extern CRYPTO_RWLOCK *bio_type_lock;
|
||||
|
||||
void bio_sock_cleanup_int(void);
|
||||
|
||||
#if BIO_FLAGS_UPLINK==0
|
||||
#if BIO_FLAGS_UPLINK_INTERNAL==0
|
||||
/* Shortcut UPLINK calls on most platforms... */
|
||||
# define UP_stdin stdin
|
||||
# define UP_stdout stdout
|
||||
|
||||
@@ -784,7 +784,7 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
* reasons. When BIO_CTRL_DGRAM_SET_PEEK_MODE was first defined its value
|
||||
* was incorrectly clashing with BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE. The
|
||||
* value has been updated to a non-clashing value. However to preserve
|
||||
* binary compatiblity we now respond to both the old value and the new one
|
||||
* binary compatibility we now respond to both the old value and the new one
|
||||
*/
|
||||
case BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE:
|
||||
case BIO_CTRL_DGRAM_SET_PEEK_MODE:
|
||||
|
||||
+2
-2
@@ -94,7 +94,7 @@ static int fd_new(BIO *bi)
|
||||
bi->init = 0;
|
||||
bi->num = -1;
|
||||
bi->ptr = NULL;
|
||||
bi->flags = BIO_FLAGS_UPLINK; /* essentially redundant */
|
||||
bi->flags = BIO_FLAGS_UPLINK_INTERNAL; /* essentially redundant */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ static int fd_free(BIO *a)
|
||||
UP_close(a->num);
|
||||
}
|
||||
a->init = 0;
|
||||
a->flags = BIO_FLAGS_UPLINK;
|
||||
a->flags = BIO_FLAGS_UPLINK_INTERNAL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
+21
-21
@@ -86,8 +86,8 @@ BIO *BIO_new_file(const char *filename, const char *mode)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage
|
||||
* UPLINK */
|
||||
/* we did fopen -> we disengage UPLINK */
|
||||
BIO_clear_flags(ret, BIO_FLAGS_UPLINK_INTERNAL);
|
||||
BIO_set_fp(ret, file, fp_flags);
|
||||
return ret;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ BIO *BIO_new_fp(FILE *stream, int close_flag)
|
||||
return NULL;
|
||||
|
||||
/* redundant flag, left for documentation purposes */
|
||||
BIO_set_flags(ret, BIO_FLAGS_UPLINK);
|
||||
BIO_set_flags(ret, BIO_FLAGS_UPLINK_INTERNAL);
|
||||
BIO_set_fp(ret, stream, close_flag);
|
||||
return ret;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ static int file_new(BIO *bi)
|
||||
bi->init = 0;
|
||||
bi->num = 0;
|
||||
bi->ptr = NULL;
|
||||
bi->flags = BIO_FLAGS_UPLINK; /* default to UPLINK */
|
||||
bi->flags = BIO_FLAGS_UPLINK_INTERNAL; /* default to UPLINK */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -125,12 +125,12 @@ static int file_free(BIO *a)
|
||||
return 0;
|
||||
if (a->shutdown) {
|
||||
if ((a->init) && (a->ptr != NULL)) {
|
||||
if (a->flags & BIO_FLAGS_UPLINK)
|
||||
if (a->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
UP_fclose(a->ptr);
|
||||
else
|
||||
fclose(a->ptr);
|
||||
a->ptr = NULL;
|
||||
a->flags = BIO_FLAGS_UPLINK;
|
||||
a->flags = BIO_FLAGS_UPLINK_INTERNAL;
|
||||
}
|
||||
a->init = 0;
|
||||
}
|
||||
@@ -142,13 +142,13 @@ static int file_read(BIO *b, char *out, int outl)
|
||||
int ret = 0;
|
||||
|
||||
if (b->init && (out != NULL)) {
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
ret = UP_fread(out, 1, (int)outl, b->ptr);
|
||||
else
|
||||
ret = fread(out, 1, (int)outl, (FILE *)b->ptr);
|
||||
if (ret == 0
|
||||
&& (b->flags & BIO_FLAGS_UPLINK) ? UP_ferror((FILE *)b->ptr) :
|
||||
ferror((FILE *)b->ptr)) {
|
||||
&& (b->flags & BIO_FLAGS_UPLINK_INTERNAL
|
||||
? UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr))) {
|
||||
SYSerr(SYS_F_FREAD, get_last_sys_error());
|
||||
BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
|
||||
ret = -1;
|
||||
@@ -162,7 +162,7 @@ static int file_write(BIO *b, const char *in, int inl)
|
||||
int ret = 0;
|
||||
|
||||
if (b->init && (in != NULL)) {
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
ret = UP_fwrite(in, (int)inl, 1, b->ptr);
|
||||
else
|
||||
ret = fwrite(in, (int)inl, 1, (FILE *)b->ptr);
|
||||
@@ -189,20 +189,20 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
switch (cmd) {
|
||||
case BIO_C_FILE_SEEK:
|
||||
case BIO_CTRL_RESET:
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
ret = (long)UP_fseek(b->ptr, num, 0);
|
||||
else
|
||||
ret = (long)fseek(fp, num, 0);
|
||||
break;
|
||||
case BIO_CTRL_EOF:
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
ret = (long)UP_feof(fp);
|
||||
else
|
||||
ret = (long)feof(fp);
|
||||
break;
|
||||
case BIO_C_FILE_TELL:
|
||||
case BIO_CTRL_INFO:
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
ret = UP_ftell(b->ptr);
|
||||
else
|
||||
ret = ftell(fp);
|
||||
@@ -212,22 +212,22 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->ptr = ptr;
|
||||
b->init = 1;
|
||||
# if BIO_FLAGS_UPLINK!=0
|
||||
# if BIO_FLAGS_UPLINK_INTERNAL!=0
|
||||
# if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES)
|
||||
# define _IOB_ENTRIES 20
|
||||
# endif
|
||||
/* Safety net to catch purely internal BIO_set_fp calls */
|
||||
# if defined(_MSC_VER) && _MSC_VER>=1900
|
||||
if (ptr == stdin || ptr == stdout || ptr == stderr)
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK);
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK_INTERNAL);
|
||||
# elif defined(_IOB_ENTRIES)
|
||||
if ((size_t)ptr >= (size_t)stdin &&
|
||||
(size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK);
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK_INTERNAL);
|
||||
# endif
|
||||
# endif
|
||||
# ifdef UP_fsetmod
|
||||
if (b->flags & BIO_FLAGS_UPLINK)
|
||||
if (b->flags & BIO_FLAGS_UPLINK_INTERNAL)
|
||||
UP_fsetmod(b->ptr, (char)((num & BIO_FP_TEXT) ? 't' : 'b'));
|
||||
else
|
||||
# endif
|
||||
@@ -296,8 +296,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
}
|
||||
b->ptr = fp;
|
||||
b->init = 1;
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage
|
||||
* UPLINK */
|
||||
/* we did fopen -> we disengage UPLINK */
|
||||
BIO_clear_flags(b, BIO_FLAGS_UPLINK_INTERNAL);
|
||||
break;
|
||||
case BIO_C_GET_FILE_PTR:
|
||||
/* the ptr parameter is actually a FILE ** in this case. */
|
||||
@@ -313,7 +313,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
b->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
st = b->flags & BIO_FLAGS_UPLINK
|
||||
st = b->flags & BIO_FLAGS_UPLINK_INTERNAL
|
||||
? UP_fflush(b->ptr) : fflush((FILE *)b->ptr);
|
||||
if (st == EOF) {
|
||||
SYSerr(SYS_F_FFLUSH, get_last_sys_error());
|
||||
@@ -342,7 +342,7 @@ static int file_gets(BIO *bp, char *buf, int size)
|
||||
int ret = 0;
|
||||
|
||||
buf[0] = '\0';
|
||||
if (bp->flags & BIO_FLAGS_UPLINK) {
|
||||
if (bp->flags & BIO_FLAGS_UPLINK_INTERNAL) {
|
||||
if (!UP_fgets(buf, size, bp->ptr))
|
||||
goto err;
|
||||
} else {
|
||||
|
||||
@@ -259,9 +259,7 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
bm = bbm->buf;
|
||||
if (bm->data != NULL) {
|
||||
if (!(b->flags & BIO_FLAGS_MEM_RDONLY)) {
|
||||
if (b->flags & BIO_FLAGS_NONCLEAR_RST) {
|
||||
bm->length = bm->max;
|
||||
} else {
|
||||
if (!(b->flags & BIO_FLAGS_NONCLEAR_RST)) {
|
||||
memset(bm->data, 0, bm->max);
|
||||
bm->length = 0;
|
||||
}
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static ossl_inline uint32_t load32(const uint8_t *src)
|
||||
{
|
||||
const union {
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
|
||||
if (is_endian.little) {
|
||||
uint32_t w;
|
||||
memcpy(&w, src, sizeof(w));
|
||||
return w;
|
||||
} else {
|
||||
uint32_t w = ((uint32_t)src[0])
|
||||
| ((uint32_t)src[1] << 8)
|
||||
| ((uint32_t)src[2] << 16)
|
||||
| ((uint32_t)src[3] << 24);
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
static ossl_inline uint64_t load64(const uint8_t *src)
|
||||
{
|
||||
const union {
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
|
||||
if (is_endian.little) {
|
||||
uint64_t w;
|
||||
memcpy(&w, src, sizeof(w));
|
||||
return w;
|
||||
} else {
|
||||
uint64_t w = ((uint64_t)src[0])
|
||||
| ((uint64_t)src[1] << 8)
|
||||
| ((uint64_t)src[2] << 16)
|
||||
| ((uint64_t)src[3] << 24)
|
||||
| ((uint64_t)src[4] << 32)
|
||||
| ((uint64_t)src[5] << 40)
|
||||
| ((uint64_t)src[6] << 48)
|
||||
| ((uint64_t)src[7] << 56);
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
static ossl_inline void store32(uint8_t *dst, uint32_t w)
|
||||
{
|
||||
const union {
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
|
||||
if (is_endian.little) {
|
||||
memcpy(dst, &w, sizeof(w));
|
||||
} else {
|
||||
uint8_t *p = (uint8_t *)dst;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
p[i] = (uint8_t)(w >> (8 * i));
|
||||
}
|
||||
}
|
||||
|
||||
static ossl_inline void store64(uint8_t *dst, uint64_t w)
|
||||
{
|
||||
const union {
|
||||
long one;
|
||||
char little;
|
||||
} is_endian = { 1 };
|
||||
|
||||
if (is_endian.little) {
|
||||
memcpy(dst, &w, sizeof(w));
|
||||
} else {
|
||||
uint8_t *p = (uint8_t *)dst;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
p[i] = (uint8_t)(w >> (8 * i));
|
||||
}
|
||||
}
|
||||
|
||||
static ossl_inline uint64_t load48(const uint8_t *src)
|
||||
{
|
||||
uint64_t w = ((uint64_t)src[0])
|
||||
| ((uint64_t)src[1] << 8)
|
||||
| ((uint64_t)src[2] << 16)
|
||||
| ((uint64_t)src[3] << 24)
|
||||
| ((uint64_t)src[4] << 32)
|
||||
| ((uint64_t)src[5] << 40);
|
||||
return w;
|
||||
}
|
||||
|
||||
static ossl_inline void store48(uint8_t *dst, uint64_t w)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)dst;
|
||||
p[0] = (uint8_t)w;
|
||||
p[1] = (uint8_t)(w>>8);
|
||||
p[2] = (uint8_t)(w>>16);
|
||||
p[3] = (uint8_t)(w>>24);
|
||||
p[4] = (uint8_t)(w>>32);
|
||||
p[5] = (uint8_t)(w>>40);
|
||||
}
|
||||
|
||||
static ossl_inline uint32_t rotr32(const uint32_t w, const unsigned int c)
|
||||
{
|
||||
return (w >> c) | (w << (32 - c));
|
||||
}
|
||||
|
||||
static ossl_inline uint64_t rotr64(const uint64_t w, const unsigned int c)
|
||||
{
|
||||
return (w >> c) | (w << (64 - c));
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2018 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define BLAKE2S_BLOCKBYTES 64
|
||||
#define BLAKE2S_OUTBYTES 32
|
||||
#define BLAKE2S_KEYBYTES 32
|
||||
#define BLAKE2S_SALTBYTES 8
|
||||
#define BLAKE2S_PERSONALBYTES 8
|
||||
|
||||
#define BLAKE2B_BLOCKBYTES 128
|
||||
#define BLAKE2B_OUTBYTES 64
|
||||
#define BLAKE2B_KEYBYTES 64
|
||||
#define BLAKE2B_SALTBYTES 16
|
||||
#define BLAKE2B_PERSONALBYTES 16
|
||||
|
||||
struct blake2s_param_st {
|
||||
uint8_t digest_length; /* 1 */
|
||||
uint8_t key_length; /* 2 */
|
||||
uint8_t fanout; /* 3 */
|
||||
uint8_t depth; /* 4 */
|
||||
uint8_t leaf_length[4];/* 8 */
|
||||
uint8_t node_offset[6];/* 14 */
|
||||
uint8_t node_depth; /* 15 */
|
||||
uint8_t inner_length; /* 16 */
|
||||
uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
|
||||
uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
|
||||
};
|
||||
|
||||
typedef struct blake2s_param_st BLAKE2S_PARAM;
|
||||
|
||||
struct blake2s_ctx_st {
|
||||
uint32_t h[8];
|
||||
uint32_t t[2];
|
||||
uint32_t f[2];
|
||||
uint8_t buf[BLAKE2S_BLOCKBYTES];
|
||||
size_t buflen;
|
||||
size_t outlen;
|
||||
};
|
||||
|
||||
struct blake2b_param_st {
|
||||
uint8_t digest_length; /* 1 */
|
||||
uint8_t key_length; /* 2 */
|
||||
uint8_t fanout; /* 3 */
|
||||
uint8_t depth; /* 4 */
|
||||
uint8_t leaf_length[4];/* 8 */
|
||||
uint8_t node_offset[8];/* 16 */
|
||||
uint8_t node_depth; /* 17 */
|
||||
uint8_t inner_length; /* 18 */
|
||||
uint8_t reserved[14]; /* 32 */
|
||||
uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
|
||||
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
||||
};
|
||||
|
||||
typedef struct blake2b_param_st BLAKE2B_PARAM;
|
||||
|
||||
struct blake2b_ctx_st {
|
||||
uint64_t h[8];
|
||||
uint64_t t[2];
|
||||
uint64_t f[2];
|
||||
uint8_t buf[BLAKE2B_BLOCKBYTES];
|
||||
size_t buflen;
|
||||
size_t outlen;
|
||||
};
|
||||
|
||||
#define BLAKE2B_DIGEST_LENGTH 64
|
||||
#define BLAKE2S_DIGEST_LENGTH 32
|
||||
|
||||
typedef struct blake2s_ctx_st BLAKE2S_CTX;
|
||||
typedef struct blake2b_ctx_st BLAKE2B_CTX;
|
||||
|
||||
int BLAKE2b_Init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P);
|
||||
int BLAKE2b_Init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key);
|
||||
int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen);
|
||||
int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c);
|
||||
|
||||
/*
|
||||
* These setters are internal and do not check the validity of their parameters.
|
||||
* See blake2b_mac_ctrl for validation logic.
|
||||
*/
|
||||
|
||||
void blake2b_param_init(BLAKE2B_PARAM *P);
|
||||
void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen);
|
||||
void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen);
|
||||
void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t length);
|
||||
void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t length);
|
||||
|
||||
int BLAKE2s_Init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P);
|
||||
int BLAKE2s_Init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, const void *key);
|
||||
int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen);
|
||||
int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c);
|
||||
|
||||
void blake2s_param_init(BLAKE2S_PARAM *P);
|
||||
void blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen);
|
||||
void blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen);
|
||||
void blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, size_t length);
|
||||
void blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t length);
|
||||
@@ -1,329 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2018 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "blake2_locl.h"
|
||||
#include "blake2_impl.h"
|
||||
|
||||
static const uint64_t blake2b_IV[8] =
|
||||
{
|
||||
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
static const uint8_t blake2b_sigma[12][16] =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
|
||||
};
|
||||
|
||||
/* Set that it's the last block we'll compress */
|
||||
static ossl_inline void blake2b_set_lastblock(BLAKE2B_CTX *S)
|
||||
{
|
||||
S->f[0] = -1;
|
||||
}
|
||||
|
||||
/* Initialize the hashing state. */
|
||||
static ossl_inline void blake2b_init0(BLAKE2B_CTX *S)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(S, 0, sizeof(BLAKE2B_CTX));
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] = blake2b_IV[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* init xors IV with input parameter block and sets the output length */
|
||||
static void blake2b_init_param(BLAKE2B_CTX *S, const BLAKE2B_PARAM *P)
|
||||
{
|
||||
size_t i;
|
||||
const uint8_t *p = (const uint8_t *)(P);
|
||||
|
||||
blake2b_init0(S);
|
||||
S->outlen = P->digest_length;
|
||||
|
||||
/* The param struct is carefully hand packed, and should be 64 bytes on
|
||||
* every platform. */
|
||||
assert(sizeof(BLAKE2B_PARAM) == 64);
|
||||
/* IV XOR ParamBlock */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] ^= load64(p + sizeof(S->h[i]) * i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the parameter block with default values */
|
||||
void blake2b_param_init(BLAKE2B_PARAM *P)
|
||||
{
|
||||
P->digest_length = BLAKE2B_DIGEST_LENGTH;
|
||||
P->key_length = 0;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
store32(P->leaf_length, 0);
|
||||
store64(P->node_offset, 0);
|
||||
P->node_depth = 0;
|
||||
P->inner_length = 0;
|
||||
memset(P->reserved, 0, sizeof(P->reserved));
|
||||
memset(P->salt, 0, sizeof(P->salt));
|
||||
memset(P->personal, 0, sizeof(P->personal));
|
||||
}
|
||||
|
||||
void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen)
|
||||
{
|
||||
P->digest_length = outlen;
|
||||
}
|
||||
|
||||
void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen)
|
||||
{
|
||||
P->key_length = keylen;
|
||||
}
|
||||
|
||||
void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t len)
|
||||
{
|
||||
memcpy(P->personal, personal, len);
|
||||
memset(P->personal + len, 0, BLAKE2B_PERSONALBYTES - len);
|
||||
}
|
||||
|
||||
void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t len)
|
||||
{
|
||||
memcpy(P->salt, salt, len);
|
||||
memset(P->salt + len, 0, BLAKE2B_SALTBYTES - len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the hashing context with the given parameter block.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2b_Init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P)
|
||||
{
|
||||
blake2b_init_param(c, P);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the hashing context with the given parameter block and key.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2b_Init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key)
|
||||
{
|
||||
blake2b_init_param(c, P);
|
||||
|
||||
/* Pad the key to form first data block */
|
||||
{
|
||||
uint8_t block[BLAKE2B_BLOCKBYTES] = {0};
|
||||
|
||||
memcpy(block, key, P->key_length);
|
||||
BLAKE2b_Update(c, block, BLAKE2B_BLOCKBYTES);
|
||||
OPENSSL_cleanse(block, BLAKE2B_BLOCKBYTES);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Permute the state while xoring in the block of data. */
|
||||
static void blake2b_compress(BLAKE2B_CTX *S,
|
||||
const uint8_t *blocks,
|
||||
size_t len)
|
||||
{
|
||||
uint64_t m[16];
|
||||
uint64_t v[16];
|
||||
int i;
|
||||
size_t increment;
|
||||
|
||||
/*
|
||||
* There are two distinct usage vectors for this function:
|
||||
*
|
||||
* a) BLAKE2b_Update uses it to process complete blocks,
|
||||
* possibly more than one at a time;
|
||||
*
|
||||
* b) BLAK2b_Final uses it to process last block, always
|
||||
* single but possibly incomplete, in which case caller
|
||||
* pads input with zeros.
|
||||
*/
|
||||
assert(len < BLAKE2B_BLOCKBYTES || len % BLAKE2B_BLOCKBYTES == 0);
|
||||
|
||||
/*
|
||||
* Since last block is always processed with separate call,
|
||||
* |len| not being multiple of complete blocks can be observed
|
||||
* only with |len| being less than BLAKE2B_BLOCKBYTES ("less"
|
||||
* including even zero), which is why following assignment doesn't
|
||||
* have to reside inside the main loop below.
|
||||
*/
|
||||
increment = len < BLAKE2B_BLOCKBYTES ? len : BLAKE2B_BLOCKBYTES;
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
v[i] = S->h[i];
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 16; ++i) {
|
||||
m[i] = load64(blocks + i * sizeof(m[i]));
|
||||
}
|
||||
|
||||
/* blake2b_increment_counter */
|
||||
S->t[0] += increment;
|
||||
S->t[1] += (S->t[0] < increment);
|
||||
|
||||
v[8] = blake2b_IV[0];
|
||||
v[9] = blake2b_IV[1];
|
||||
v[10] = blake2b_IV[2];
|
||||
v[11] = blake2b_IV[3];
|
||||
v[12] = S->t[0] ^ blake2b_IV[4];
|
||||
v[13] = S->t[1] ^ blake2b_IV[5];
|
||||
v[14] = S->f[0] ^ blake2b_IV[6];
|
||||
v[15] = S->f[1] ^ blake2b_IV[7];
|
||||
#define G(r,i,a,b,c,d) \
|
||||
do { \
|
||||
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
|
||||
d = rotr64(d ^ a, 32); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 24); \
|
||||
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
|
||||
d = rotr64(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 63); \
|
||||
} while (0)
|
||||
#define ROUND(r) \
|
||||
do { \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
||||
} while (0)
|
||||
#if defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
/* 3x size reduction on x86_64, almost 7x on ARMv8, 9x on ARMv4 */
|
||||
for (i = 0; i < 12; i++) {
|
||||
ROUND(i);
|
||||
}
|
||||
#else
|
||||
ROUND(0);
|
||||
ROUND(1);
|
||||
ROUND(2);
|
||||
ROUND(3);
|
||||
ROUND(4);
|
||||
ROUND(5);
|
||||
ROUND(6);
|
||||
ROUND(7);
|
||||
ROUND(8);
|
||||
ROUND(9);
|
||||
ROUND(10);
|
||||
ROUND(11);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] = v[i] ^= v[i + 8] ^ S->h[i];
|
||||
}
|
||||
#undef G
|
||||
#undef ROUND
|
||||
blocks += increment;
|
||||
len -= increment;
|
||||
} while (len);
|
||||
}
|
||||
|
||||
/* Absorb the input data into the hash state. Always returns 1. */
|
||||
int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen)
|
||||
{
|
||||
const uint8_t *in = data;
|
||||
size_t fill;
|
||||
|
||||
/*
|
||||
* Intuitively one would expect intermediate buffer, c->buf, to
|
||||
* store incomplete blocks. But in this case we are interested to
|
||||
* temporarily stash even complete blocks, because last one in the
|
||||
* stream has to be treated in special way, and at this point we
|
||||
* don't know if last block in *this* call is last one "ever". This
|
||||
* is the reason for why |datalen| is compared as >, and not >=.
|
||||
*/
|
||||
fill = sizeof(c->buf) - c->buflen;
|
||||
if (datalen > fill) {
|
||||
if (c->buflen) {
|
||||
memcpy(c->buf + c->buflen, in, fill); /* Fill buffer */
|
||||
blake2b_compress(c, c->buf, BLAKE2B_BLOCKBYTES);
|
||||
c->buflen = 0;
|
||||
in += fill;
|
||||
datalen -= fill;
|
||||
}
|
||||
if (datalen > BLAKE2B_BLOCKBYTES) {
|
||||
size_t stashlen = datalen % BLAKE2B_BLOCKBYTES;
|
||||
/*
|
||||
* If |datalen| is a multiple of the blocksize, stash
|
||||
* last complete block, it can be final one...
|
||||
*/
|
||||
stashlen = stashlen ? stashlen : BLAKE2B_BLOCKBYTES;
|
||||
datalen -= stashlen;
|
||||
blake2b_compress(c, in, datalen);
|
||||
in += datalen;
|
||||
datalen = stashlen;
|
||||
}
|
||||
}
|
||||
|
||||
assert(datalen <= BLAKE2B_BLOCKBYTES);
|
||||
|
||||
memcpy(c->buf + c->buflen, in, datalen);
|
||||
c->buflen += datalen; /* Be lazy, do not compress */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the final hash and save it in md.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c)
|
||||
{
|
||||
uint8_t outbuffer[BLAKE2B_OUTBYTES] = {0};
|
||||
uint8_t *target = outbuffer;
|
||||
int iter = (c->outlen + 7) / 8;
|
||||
int i;
|
||||
|
||||
/* Avoid writing to the temporary buffer if possible */
|
||||
if ((c->outlen % sizeof(c->h[0])) == 0)
|
||||
target = md;
|
||||
|
||||
blake2b_set_lastblock(c);
|
||||
/* Padding */
|
||||
memset(c->buf + c->buflen, 0, sizeof(c->buf) - c->buflen);
|
||||
blake2b_compress(c, c->buf, c->buflen);
|
||||
|
||||
/* Output full hash to buffer */
|
||||
for (i = 0; i < iter; ++i)
|
||||
store64(target + sizeof(c->h[i]) * i, c->h[i]);
|
||||
|
||||
if (target != md)
|
||||
memcpy(md, target, c->outlen);
|
||||
|
||||
OPENSSL_cleanse(c, sizeof(BLAKE2B_CTX));
|
||||
return 1;
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include "blake2_locl.h"
|
||||
# include "internal/blake2.h"
|
||||
# include "internal/cryptlib.h"
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
@@ -26,7 +26,7 @@ static EVP_MAC_IMPL *blake2b_mac_new(void)
|
||||
EVP_MAC_IMPL *macctx = OPENSSL_zalloc(sizeof(*macctx));
|
||||
if (macctx != NULL) {
|
||||
blake2b_param_init(&macctx->params);
|
||||
/* ctx initialization is deferred to BLAKE2b_Init() */
|
||||
/* ctx initialization is deferred to blake2b_init() */
|
||||
}
|
||||
return macctx;
|
||||
}
|
||||
@@ -39,10 +39,16 @@ static void blake2b_mac_free(EVP_MAC_IMPL *macctx)
|
||||
}
|
||||
}
|
||||
|
||||
static int blake2b_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src)
|
||||
static EVP_MAC_IMPL *blake2b_mac_dup(const EVP_MAC_IMPL *src)
|
||||
{
|
||||
EVP_MAC_IMPL *dst;
|
||||
|
||||
dst = OPENSSL_zalloc(sizeof(*dst));
|
||||
if (dst == NULL)
|
||||
return NULL;
|
||||
|
||||
*dst = *src;
|
||||
return 1;
|
||||
return dst;
|
||||
}
|
||||
|
||||
static int blake2b_mac_init(EVP_MAC_IMPL *macctx)
|
||||
@@ -53,18 +59,18 @@ static int blake2b_mac_init(EVP_MAC_IMPL *macctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BLAKE2b_Init_key(&macctx->ctx, &macctx->params, macctx->key);
|
||||
return blake2b_init_key(&macctx->ctx, &macctx->params, macctx->key);
|
||||
}
|
||||
|
||||
static int blake2b_mac_update(EVP_MAC_IMPL *macctx, const unsigned char *data,
|
||||
size_t datalen)
|
||||
{
|
||||
return BLAKE2b_Update(&macctx->ctx, data, datalen);
|
||||
return blake2b_update(&macctx->ctx, data, datalen);
|
||||
}
|
||||
|
||||
static int blake2b_mac_final(EVP_MAC_IMPL *macctx, unsigned char *out)
|
||||
{
|
||||
return BLAKE2b_Final(out, &macctx->ctx);
|
||||
return blake2b_final(out, &macctx->ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -177,7 +183,7 @@ static size_t blake2b_mac_size(EVP_MAC_IMPL *macctx)
|
||||
const EVP_MAC blake2b_mac_meth = {
|
||||
EVP_MAC_BLAKE2B,
|
||||
blake2b_mac_new,
|
||||
blake2b_mac_copy,
|
||||
blake2b_mac_dup,
|
||||
blake2b_mac_free,
|
||||
blake2b_mac_size,
|
||||
blake2b_mac_init,
|
||||
|
||||
@@ -1,320 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2018 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "blake2_locl.h"
|
||||
#include "blake2_impl.h"
|
||||
|
||||
static const uint32_t blake2s_IV[8] =
|
||||
{
|
||||
0x6A09E667U, 0xBB67AE85U, 0x3C6EF372U, 0xA54FF53AU,
|
||||
0x510E527FU, 0x9B05688CU, 0x1F83D9ABU, 0x5BE0CD19U
|
||||
};
|
||||
|
||||
static const uint8_t blake2s_sigma[10][16] =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
||||
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
||||
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
||||
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
||||
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
||||
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
|
||||
};
|
||||
|
||||
/* Set that it's the last block we'll compress */
|
||||
static ossl_inline void blake2s_set_lastblock(BLAKE2S_CTX *S)
|
||||
{
|
||||
S->f[0] = -1;
|
||||
}
|
||||
|
||||
/* Initialize the hashing state. */
|
||||
static ossl_inline void blake2s_init0(BLAKE2S_CTX *S)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(S, 0, sizeof(BLAKE2S_CTX));
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] = blake2s_IV[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* init xors IV with input parameter block and sets the output length */
|
||||
static void blake2s_init_param(BLAKE2S_CTX *S, const BLAKE2S_PARAM *P)
|
||||
{
|
||||
size_t i;
|
||||
const uint8_t *p = (const uint8_t *)(P);
|
||||
|
||||
blake2s_init0(S);
|
||||
S->outlen = P->digest_length;
|
||||
|
||||
/* The param struct is carefully hand packed, and should be 32 bytes on
|
||||
* every platform. */
|
||||
assert(sizeof(BLAKE2S_PARAM) == 32);
|
||||
/* IV XOR ParamBlock */
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] ^= load32(&p[i*4]);
|
||||
}
|
||||
}
|
||||
|
||||
void blake2s_param_init(BLAKE2S_PARAM *P)
|
||||
{
|
||||
P->digest_length = BLAKE2S_DIGEST_LENGTH;
|
||||
P->key_length = 0;
|
||||
P->fanout = 1;
|
||||
P->depth = 1;
|
||||
store32(P->leaf_length, 0);
|
||||
store48(P->node_offset, 0);
|
||||
P->node_depth = 0;
|
||||
P->inner_length = 0;
|
||||
memset(P->salt, 0, sizeof(P->salt));
|
||||
memset(P->personal, 0, sizeof(P->personal));
|
||||
}
|
||||
|
||||
void blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen)
|
||||
{
|
||||
P->digest_length = outlen;
|
||||
}
|
||||
|
||||
void blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen)
|
||||
{
|
||||
P->key_length = keylen;
|
||||
}
|
||||
|
||||
void blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, size_t len)
|
||||
{
|
||||
memcpy(P->personal, personal, len);
|
||||
memset(P->personal + len, 0, BLAKE2S_PERSONALBYTES - len);
|
||||
}
|
||||
|
||||
void blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t len)
|
||||
{
|
||||
memcpy(P->salt, salt, len);
|
||||
memset(P->salt + len, 0, BLAKE2S_SALTBYTES - len);}
|
||||
|
||||
/*
|
||||
* Initialize the hashing context with the given parameter block.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2s_Init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P)
|
||||
{
|
||||
blake2s_init_param(c, P);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the hashing context with the given parameter block and key.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2s_Init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, const void *key)
|
||||
{
|
||||
blake2s_init_param(c, P);
|
||||
|
||||
/* Pad the key to form first data block */
|
||||
{
|
||||
uint8_t block[BLAKE2S_BLOCKBYTES] = {0};
|
||||
|
||||
memcpy(block, key, P->key_length);
|
||||
BLAKE2s_Update(c, block, BLAKE2S_BLOCKBYTES);
|
||||
OPENSSL_cleanse(block, BLAKE2S_BLOCKBYTES);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Permute the state while xoring in the block of data. */
|
||||
static void blake2s_compress(BLAKE2S_CTX *S,
|
||||
const uint8_t *blocks,
|
||||
size_t len)
|
||||
{
|
||||
uint32_t m[16];
|
||||
uint32_t v[16];
|
||||
size_t i;
|
||||
size_t increment;
|
||||
|
||||
/*
|
||||
* There are two distinct usage vectors for this function:
|
||||
*
|
||||
* a) BLAKE2s_Update uses it to process complete blocks,
|
||||
* possibly more than one at a time;
|
||||
*
|
||||
* b) BLAK2s_Final uses it to process last block, always
|
||||
* single but possibly incomplete, in which case caller
|
||||
* pads input with zeros.
|
||||
*/
|
||||
assert(len < BLAKE2S_BLOCKBYTES || len % BLAKE2S_BLOCKBYTES == 0);
|
||||
|
||||
/*
|
||||
* Since last block is always processed with separate call,
|
||||
* |len| not being multiple of complete blocks can be observed
|
||||
* only with |len| being less than BLAKE2S_BLOCKBYTES ("less"
|
||||
* including even zero), which is why following assignment doesn't
|
||||
* have to reside inside the main loop below.
|
||||
*/
|
||||
increment = len < BLAKE2S_BLOCKBYTES ? len : BLAKE2S_BLOCKBYTES;
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
v[i] = S->h[i];
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 16; ++i) {
|
||||
m[i] = load32(blocks + i * sizeof(m[i]));
|
||||
}
|
||||
|
||||
/* blake2s_increment_counter */
|
||||
S->t[0] += increment;
|
||||
S->t[1] += (S->t[0] < increment);
|
||||
|
||||
v[ 8] = blake2s_IV[0];
|
||||
v[ 9] = blake2s_IV[1];
|
||||
v[10] = blake2s_IV[2];
|
||||
v[11] = blake2s_IV[3];
|
||||
v[12] = S->t[0] ^ blake2s_IV[4];
|
||||
v[13] = S->t[1] ^ blake2s_IV[5];
|
||||
v[14] = S->f[0] ^ blake2s_IV[6];
|
||||
v[15] = S->f[1] ^ blake2s_IV[7];
|
||||
#define G(r,i,a,b,c,d) \
|
||||
do { \
|
||||
a = a + b + m[blake2s_sigma[r][2*i+0]]; \
|
||||
d = rotr32(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = rotr32(b ^ c, 12); \
|
||||
a = a + b + m[blake2s_sigma[r][2*i+1]]; \
|
||||
d = rotr32(d ^ a, 8); \
|
||||
c = c + d; \
|
||||
b = rotr32(b ^ c, 7); \
|
||||
} while (0)
|
||||
#define ROUND(r) \
|
||||
do { \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
||||
} while (0)
|
||||
#if defined(OPENSSL_SMALL_FOOTPRINT)
|
||||
/* almost 3x reduction on x86_64, 4.5x on ARMv8, 4x on ARMv4 */
|
||||
for (i = 0; i < 10; i++) {
|
||||
ROUND(i);
|
||||
}
|
||||
#else
|
||||
ROUND(0);
|
||||
ROUND(1);
|
||||
ROUND(2);
|
||||
ROUND(3);
|
||||
ROUND(4);
|
||||
ROUND(5);
|
||||
ROUND(6);
|
||||
ROUND(7);
|
||||
ROUND(8);
|
||||
ROUND(9);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
S->h[i] = v[i] ^= v[i + 8] ^ S->h[i];
|
||||
}
|
||||
#undef G
|
||||
#undef ROUND
|
||||
blocks += increment;
|
||||
len -= increment;
|
||||
} while (len);
|
||||
}
|
||||
|
||||
/* Absorb the input data into the hash state. Always returns 1. */
|
||||
int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen)
|
||||
{
|
||||
const uint8_t *in = data;
|
||||
size_t fill;
|
||||
|
||||
/*
|
||||
* Intuitively one would expect intermediate buffer, c->buf, to
|
||||
* store incomplete blocks. But in this case we are interested to
|
||||
* temporarily stash even complete blocks, because last one in the
|
||||
* stream has to be treated in special way, and at this point we
|
||||
* don't know if last block in *this* call is last one "ever". This
|
||||
* is the reason for why |datalen| is compared as >, and not >=.
|
||||
*/
|
||||
fill = sizeof(c->buf) - c->buflen;
|
||||
if (datalen > fill) {
|
||||
if (c->buflen) {
|
||||
memcpy(c->buf + c->buflen, in, fill); /* Fill buffer */
|
||||
blake2s_compress(c, c->buf, BLAKE2S_BLOCKBYTES);
|
||||
c->buflen = 0;
|
||||
in += fill;
|
||||
datalen -= fill;
|
||||
}
|
||||
if (datalen > BLAKE2S_BLOCKBYTES) {
|
||||
size_t stashlen = datalen % BLAKE2S_BLOCKBYTES;
|
||||
/*
|
||||
* If |datalen| is a multiple of the blocksize, stash
|
||||
* last complete block, it can be final one...
|
||||
*/
|
||||
stashlen = stashlen ? stashlen : BLAKE2S_BLOCKBYTES;
|
||||
datalen -= stashlen;
|
||||
blake2s_compress(c, in, datalen);
|
||||
in += datalen;
|
||||
datalen = stashlen;
|
||||
}
|
||||
}
|
||||
|
||||
assert(datalen <= BLAKE2S_BLOCKBYTES);
|
||||
|
||||
memcpy(c->buf + c->buflen, in, datalen);
|
||||
c->buflen += datalen; /* Be lazy, do not compress */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the final hash and save it in md.
|
||||
* Always returns 1.
|
||||
*/
|
||||
int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c)
|
||||
{
|
||||
uint8_t outbuffer[BLAKE2S_OUTBYTES] = {0};
|
||||
uint8_t *target = outbuffer;
|
||||
int iter = (c->outlen + 3) / 4;
|
||||
int i;
|
||||
|
||||
/* Avoid writing to the temporary buffer if possible */
|
||||
if ((c->outlen % sizeof(c->h[0])) == 0)
|
||||
target = md;
|
||||
|
||||
blake2s_set_lastblock(c);
|
||||
/* Padding */
|
||||
memset(c->buf + c->buflen, 0, sizeof(c->buf) - c->buflen);
|
||||
blake2s_compress(c, c->buf, c->buflen);
|
||||
|
||||
/* Output full hash to buffer */
|
||||
for (i = 0; i < iter; ++i)
|
||||
store32(target + sizeof(c->h[i]) * i, c->h[i]);
|
||||
|
||||
if (target != md)
|
||||
memcpy(md, target, c->outlen);
|
||||
|
||||
OPENSSL_cleanse(c, sizeof(BLAKE2S_CTX));
|
||||
return 1;
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include "blake2_locl.h"
|
||||
# include "internal/blake2.h"
|
||||
# include "internal/cryptlib.h"
|
||||
# include "internal/evp_int.h"
|
||||
|
||||
@@ -39,10 +39,16 @@ static void blake2s_mac_free(EVP_MAC_IMPL *macctx)
|
||||
}
|
||||
}
|
||||
|
||||
static int blake2s_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src)
|
||||
static EVP_MAC_IMPL *blake2s_mac_dup(const EVP_MAC_IMPL *src)
|
||||
{
|
||||
EVP_MAC_IMPL *dst;
|
||||
|
||||
dst = OPENSSL_malloc(sizeof(*dst));
|
||||
if (dst == NULL)
|
||||
return NULL;
|
||||
|
||||
*dst = *src;
|
||||
return 1;
|
||||
return dst;
|
||||
}
|
||||
|
||||
static int blake2s_mac_init(EVP_MAC_IMPL *macctx)
|
||||
@@ -53,18 +59,18 @@ static int blake2s_mac_init(EVP_MAC_IMPL *macctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return BLAKE2s_Init_key(&macctx->ctx, &macctx->params, macctx->key);
|
||||
return blake2s_init_key(&macctx->ctx, &macctx->params, macctx->key);
|
||||
}
|
||||
|
||||
static int blake2s_mac_update(EVP_MAC_IMPL *macctx, const unsigned char *data,
|
||||
size_t datalen)
|
||||
{
|
||||
return BLAKE2s_Update(&macctx->ctx, data, datalen);
|
||||
return blake2s_update(&macctx->ctx, data, datalen);
|
||||
}
|
||||
|
||||
static int blake2s_mac_final(EVP_MAC_IMPL *macctx, unsigned char *out)
|
||||
{
|
||||
return BLAKE2s_Final(out, &macctx->ctx);
|
||||
return blake2s_final(out, &macctx->ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -177,7 +183,7 @@ static size_t blake2s_mac_size(EVP_MAC_IMPL *macctx)
|
||||
const EVP_MAC blake2s_mac_meth = {
|
||||
EVP_MAC_BLAKE2S,
|
||||
blake2s_mac_new,
|
||||
blake2s_mac_copy,
|
||||
blake2s_mac_dup,
|
||||
blake2s_mac_free,
|
||||
blake2s_mac_size,
|
||||
blake2s_mac_init,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
blake2b.c blake2s.c blake2b_mac.c blake2s_mac.c m_blake2b.c m_blake2s.c
|
||||
blake2b_mac.c blake2s_mac.c m_blake2b.c m_blake2s.c
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* 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
|
||||
@@ -7,37 +7,26 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "blake2_locl.h"
|
||||
# include <stddef.h>
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "internal/blake2.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
BLAKE2B_PARAM P;
|
||||
blake2b_param_init(&P);
|
||||
return BLAKE2b_Init(EVP_MD_CTX_md_data(ctx), &P);
|
||||
return blake2b512_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return BLAKE2b_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
return blake2b_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return BLAKE2b_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
return blake2b_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD blake2b_md = {
|
||||
@@ -58,4 +47,4 @@ const EVP_MD *EVP_blake2b512(void)
|
||||
{
|
||||
return &blake2b_md;
|
||||
}
|
||||
#endif
|
||||
#endif /* OPENSSL_NO_BLAKE2 */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* 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
|
||||
@@ -7,37 +7,26 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Derived from the BLAKE2 reference implementation written by Samuel Neves.
|
||||
* Copyright 2012, Samuel Neves <sneves@dei.uc.pt>
|
||||
* More information about the BLAKE2 hash function and its implementations
|
||||
* can be found at https://blake2.net.
|
||||
*/
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
|
||||
#ifndef OPENSSL_NO_BLAKE2
|
||||
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include "blake2_locl.h"
|
||||
# include <stddef.h>
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include "internal/blake2.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
BLAKE2S_PARAM P;
|
||||
blake2s_param_init(&P);
|
||||
return BLAKE2s_Init(EVP_MD_CTX_md_data(ctx), &P);
|
||||
return blake2s256_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
return BLAKE2s_Update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
return blake2s_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return BLAKE2s_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
return blake2s_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static const EVP_MD blake2s_md = {
|
||||
@@ -58,4 +47,4 @@ const EVP_MD *EVP_blake2s256(void)
|
||||
{
|
||||
return &blake2s_md;
|
||||
}
|
||||
#endif
|
||||
#endif /* OPENSSL_NO_BLAKE2 */
|
||||
@@ -800,7 +800,7 @@ $code.=<<___;
|
||||
#if 0
|
||||
/*
|
||||
* The bn_div_3_words entry point is re-used for constant-time interface.
|
||||
* Implementation is retained as hystorical reference.
|
||||
* Implementation is retained as historical reference.
|
||||
*/
|
||||
.align 5
|
||||
.globl bn_div_3_words
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright 1995-2017 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 <openssl/err.h>
|
||||
#include "internal/ctype.h"
|
||||
#include "bn_lcl.h"
|
||||
|
||||
static const char Hex[] = "0123456789ABCDEF";
|
||||
|
||||
/* Must 'OPENSSL_free' the returned data */
|
||||
char *BN_bn2hex(const BIGNUM *a)
|
||||
{
|
||||
int i, j, v, z = 0;
|
||||
char *buf;
|
||||
char *p;
|
||||
|
||||
if (BN_is_zero(a))
|
||||
return OPENSSL_strdup("0");
|
||||
buf = OPENSSL_malloc(a->top * BN_BYTES * 2 + 2);
|
||||
if (buf == NULL) {
|
||||
BNerr(BN_F_BN_BN2HEX, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
p = buf;
|
||||
if (a->neg)
|
||||
*p++ = '-';
|
||||
for (i = a->top - 1; i >= 0; i--) {
|
||||
for (j = BN_BITS2 - 8; j >= 0; j -= 8) {
|
||||
/* strip leading zeros */
|
||||
v = (int)((a->d[i] >> j) & 0xff);
|
||||
if (z || v != 0) {
|
||||
*p++ = Hex[v >> 4];
|
||||
*p++ = Hex[v & 0x0f];
|
||||
z = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
err:
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
/* No BIO_snprintf in FIPS_MODE */
|
||||
/* Must 'OPENSSL_free' the returned data */
|
||||
char *BN_bn2dec(const BIGNUM *a)
|
||||
{
|
||||
int i = 0, num, ok = 0, n, tbytes;
|
||||
char *buf = NULL;
|
||||
char *p;
|
||||
BIGNUM *t = NULL;
|
||||
BN_ULONG *bn_data = NULL, *lp;
|
||||
int bn_data_num;
|
||||
|
||||
/*-
|
||||
* get an upper bound for the length of the decimal integer
|
||||
* num <= (BN_num_bits(a) + 1) * log(2)
|
||||
* <= 3 * BN_num_bits(a) * 0.101 + log(2) + 1 (rounding error)
|
||||
* <= 3 * BN_num_bits(a) / 10 + 3 * BN_num_bits / 1000 + 1 + 1
|
||||
*/
|
||||
i = BN_num_bits(a) * 3;
|
||||
num = (i / 10 + i / 1000 + 1) + 1;
|
||||
tbytes = num + 3; /* negative and terminator and one spare? */
|
||||
bn_data_num = num / BN_DEC_NUM + 1;
|
||||
bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG));
|
||||
buf = OPENSSL_malloc(tbytes);
|
||||
if (buf == NULL || bn_data == NULL) {
|
||||
BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if ((t = BN_dup(a)) == NULL)
|
||||
goto err;
|
||||
|
||||
p = buf;
|
||||
lp = bn_data;
|
||||
if (BN_is_zero(t)) {
|
||||
*p++ = '0';
|
||||
*p++ = '\0';
|
||||
} else {
|
||||
if (BN_is_negative(t))
|
||||
*p++ = '-';
|
||||
|
||||
while (!BN_is_zero(t)) {
|
||||
if (lp - bn_data >= bn_data_num)
|
||||
goto err;
|
||||
*lp = BN_div_word(t, BN_DEC_CONV);
|
||||
if (*lp == (BN_ULONG)-1)
|
||||
goto err;
|
||||
lp++;
|
||||
}
|
||||
lp--;
|
||||
/*
|
||||
* We now have a series of blocks, BN_DEC_NUM chars in length, where
|
||||
* the last one needs truncation. The blocks need to be reversed in
|
||||
* order.
|
||||
*/
|
||||
n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT1, *lp);
|
||||
if (n < 0)
|
||||
goto err;
|
||||
p += n;
|
||||
while (lp != bn_data) {
|
||||
lp--;
|
||||
n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT2, *lp);
|
||||
if (n < 0)
|
||||
goto err;
|
||||
p += n;
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
err:
|
||||
OPENSSL_free(bn_data);
|
||||
BN_free(t);
|
||||
if (ok)
|
||||
return buf;
|
||||
OPENSSL_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int BN_hex2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
BIGNUM *ret = NULL;
|
||||
BN_ULONG l = 0;
|
||||
int neg = 0, h, m, i, j, k, c;
|
||||
int num;
|
||||
|
||||
if (a == NULL || *a == '\0')
|
||||
return 0;
|
||||
|
||||
if (*a == '-') {
|
||||
neg = 1;
|
||||
a++;
|
||||
}
|
||||
|
||||
for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)
|
||||
continue;
|
||||
|
||||
if (i == 0 || i > INT_MAX / 4)
|
||||
goto err;
|
||||
|
||||
num = i + neg;
|
||||
if (bn == NULL)
|
||||
return num;
|
||||
|
||||
/* a is the start of the hex digits, and it is 'i' long */
|
||||
if (*bn == NULL) {
|
||||
if ((ret = BN_new()) == NULL)
|
||||
return 0;
|
||||
} else {
|
||||
ret = *bn;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
/* i is the number of hex digits */
|
||||
if (bn_expand(ret, i * 4) == NULL)
|
||||
goto err;
|
||||
|
||||
j = i; /* least significant 'hex' */
|
||||
m = 0;
|
||||
h = 0;
|
||||
while (j > 0) {
|
||||
m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;
|
||||
l = 0;
|
||||
for (;;) {
|
||||
c = a[j - m];
|
||||
k = OPENSSL_hexchar2int(c);
|
||||
if (k < 0)
|
||||
k = 0; /* paranoia */
|
||||
l = (l << 4) | k;
|
||||
|
||||
if (--m <= 0) {
|
||||
ret->d[h++] = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
j -= BN_BYTES * 2;
|
||||
}
|
||||
ret->top = h;
|
||||
bn_correct_top(ret);
|
||||
|
||||
*bn = ret;
|
||||
bn_check_top(ret);
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (ret->top != 0)
|
||||
ret->neg = neg;
|
||||
return num;
|
||||
err:
|
||||
if (*bn == NULL)
|
||||
BN_free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_dec2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
BIGNUM *ret = NULL;
|
||||
BN_ULONG l = 0;
|
||||
int neg = 0, i, j;
|
||||
int num;
|
||||
|
||||
if (a == NULL || *a == '\0')
|
||||
return 0;
|
||||
if (*a == '-') {
|
||||
neg = 1;
|
||||
a++;
|
||||
}
|
||||
|
||||
for (i = 0; i <= INT_MAX / 4 && ossl_isdigit(a[i]); i++)
|
||||
continue;
|
||||
|
||||
if (i == 0 || i > INT_MAX / 4)
|
||||
goto err;
|
||||
|
||||
num = i + neg;
|
||||
if (bn == NULL)
|
||||
return num;
|
||||
|
||||
/*
|
||||
* a is the start of the digits, and it is 'i' long. We chop it into
|
||||
* BN_DEC_NUM digits at a time
|
||||
*/
|
||||
if (*bn == NULL) {
|
||||
if ((ret = BN_new()) == NULL)
|
||||
return 0;
|
||||
} else {
|
||||
ret = *bn;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
/* i is the number of digits, a bit of an over expand */
|
||||
if (bn_expand(ret, i * 4) == NULL)
|
||||
goto err;
|
||||
|
||||
j = BN_DEC_NUM - i % BN_DEC_NUM;
|
||||
if (j == BN_DEC_NUM)
|
||||
j = 0;
|
||||
l = 0;
|
||||
while (--i >= 0) {
|
||||
l *= 10;
|
||||
l += *a - '0';
|
||||
a++;
|
||||
if (++j == BN_DEC_NUM) {
|
||||
if (!BN_mul_word(ret, BN_DEC_CONV)
|
||||
|| !BN_add_word(ret, l))
|
||||
goto err;
|
||||
l = 0;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bn_correct_top(ret);
|
||||
*bn = ret;
|
||||
bn_check_top(ret);
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (ret->top != 0)
|
||||
ret->neg = neg;
|
||||
return num;
|
||||
err:
|
||||
if (*bn == NULL)
|
||||
BN_free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_asc2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
const char *p = a;
|
||||
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {
|
||||
if (!BN_hex2bn(bn, p + 2))
|
||||
return 0;
|
||||
} else {
|
||||
if (!BN_dec2bn(bn, p))
|
||||
return 0;
|
||||
}
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (*a == '-' && (*bn)->top != 0)
|
||||
(*bn)->neg = 1;
|
||||
return 1;
|
||||
}
|
||||
+32
-6
@@ -86,8 +86,11 @@ struct bignum_ctx {
|
||||
int too_many;
|
||||
/* Flags. */
|
||||
int flags;
|
||||
/* The library context */
|
||||
OPENSSL_CTX *libctx;
|
||||
};
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
/* Debugging functionality */
|
||||
static void ctxdbg(BIO *channel, const char *text, BN_CTX *ctx)
|
||||
{
|
||||
@@ -116,39 +119,54 @@ static void ctxdbg(BIO *channel, const char *text, BN_CTX *ctx)
|
||||
BIO_printf(channel, "\n");
|
||||
}
|
||||
|
||||
#define CTXDBG(str, ctx) \
|
||||
# define CTXDBG(str, ctx) \
|
||||
OSSL_TRACE_BEGIN(BN_CTX) { \
|
||||
ctxdbg(trc_out, str, ctx); \
|
||||
} OSSL_TRACE_END(BN_CTX)
|
||||
#else
|
||||
/* TODO(3.0): Consider if we want to do this in FIPS mode */
|
||||
# define CTXDBG(str, ctx) do {} while(0)
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
|
||||
BN_CTX *BN_CTX_new(void)
|
||||
BN_CTX *BN_CTX_new_ex(OPENSSL_CTX *ctx)
|
||||
{
|
||||
BN_CTX *ret;
|
||||
|
||||
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
|
||||
BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);
|
||||
BNerr(BN_F_BN_CTX_NEW_EX, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
/* Initialise the structure */
|
||||
BN_POOL_init(&ret->pool);
|
||||
BN_STACK_init(&ret->stack);
|
||||
ret->libctx = ctx;
|
||||
return ret;
|
||||
}
|
||||
|
||||
BN_CTX *BN_CTX_secure_new(void)
|
||||
BN_CTX *BN_CTX_new(void)
|
||||
{
|
||||
BN_CTX *ret = BN_CTX_new();
|
||||
return BN_CTX_new_ex(NULL);
|
||||
}
|
||||
|
||||
BN_CTX *BN_CTX_secure_new_ex(OPENSSL_CTX *ctx)
|
||||
{
|
||||
BN_CTX *ret = BN_CTX_new_ex(ctx);
|
||||
|
||||
if (ret != NULL)
|
||||
ret->flags = BN_FLG_SECURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
BN_CTX *BN_CTX_secure_new(void)
|
||||
{
|
||||
return BN_CTX_secure_new_ex(NULL);
|
||||
}
|
||||
|
||||
void BN_CTX_free(BN_CTX *ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
return;
|
||||
#ifndef FIPS_MODE
|
||||
OSSL_TRACE_BEGIN(BN_CTX) {
|
||||
BN_POOL_ITEM *pool = ctx->pool.head;
|
||||
BIO_printf(trc_out,
|
||||
@@ -163,6 +181,7 @@ void BN_CTX_free(BN_CTX *ctx)
|
||||
}
|
||||
BIO_printf(trc_out, "\n");
|
||||
} OSSL_TRACE_END(BN_CTX);
|
||||
#endif
|
||||
BN_STACK_finish(&ctx->stack);
|
||||
BN_POOL_finish(&ctx->pool);
|
||||
OPENSSL_free(ctx);
|
||||
@@ -226,6 +245,13 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx)
|
||||
return ret;
|
||||
}
|
||||
|
||||
OPENSSL_CTX *bn_get_lib_ctx(BN_CTX *ctx)
|
||||
{
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
return ctx->libctx;
|
||||
}
|
||||
|
||||
/************/
|
||||
/* BN_STACK */
|
||||
/************/
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
*
|
||||
* - availability of constant-time bn_div_3_words;
|
||||
* - dividend is at least as "wide" as divisor, limb-wise, zero-padded
|
||||
* if so requied, which shouldn't be a privacy problem, because
|
||||
* if so required, which shouldn't be a privacy problem, because
|
||||
* divisor's length is considered public;
|
||||
*/
|
||||
int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
|
||||
|
||||
+3
-1
@@ -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
|
||||
@@ -29,6 +29,7 @@ static const ERR_STRING_DATA BN_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_COMPUTE_WNAF, 0), "bn_compute_wNAF"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_CTX_GET, 0), "BN_CTX_get"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_CTX_NEW, 0), "BN_CTX_new"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_CTX_NEW_EX, 0), "BN_CTX_new_ex"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_CTX_START, 0), "BN_CTX_start"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_DIV, 0), "BN_div"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_DIV_RECP, 0), "BN_div_recp"},
|
||||
@@ -95,6 +96,7 @@ static const ERR_STRING_DATA BN_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_NOT_INITIALIZED), "not initialized"},
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_NO_INVERSE), "no inverse"},
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_NO_SOLUTION), "no solution"},
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_NO_SUITABLE_DIGEST), "no suitable digest"},
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_PRIVATE_KEY_TOO_LARGE),
|
||||
"private key too large"},
|
||||
{ERR_PACK(ERR_LIB_BN, 0, BN_R_P_IS_NOT_PRIME), "p is not prime"},
|
||||
|
||||
+3
-1
@@ -295,7 +295,7 @@ struct bn_gencb_st {
|
||||
(b) > 23 ? 3 : 1)
|
||||
|
||||
/*
|
||||
* BN_mod_exp_mont_conttime is based on the assumption that the L1 data cache
|
||||
* BN_mod_exp_mont_consttime is based on the assumption that the L1 data cache
|
||||
* line width of the target processor is at least the following value.
|
||||
*/
|
||||
# define MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH ( 64 )
|
||||
@@ -668,4 +668,6 @@ static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
|
||||
return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);
|
||||
}
|
||||
|
||||
OPENSSL_CTX *bn_get_lib_ctx(BN_CTX *ctx);
|
||||
|
||||
#endif
|
||||
@@ -98,8 +98,12 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
|
||||
/* There are no prime numbers this small. */
|
||||
BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
|
||||
return 0;
|
||||
} else if (bits == 2 && safe) {
|
||||
/* The smallest safe prime (7) is three bits. */
|
||||
} else if (add == NULL && safe && bits < 6 && bits != 3) {
|
||||
/*
|
||||
* The smallest safe prime (7) is three bits.
|
||||
* But the following two safe primes with less than 6 bits (11, 23)
|
||||
* are unreachable for BN_rand with BN_RAND_TOP_TWO.
|
||||
*/
|
||||
BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+3
-276
@@ -8,285 +8,12 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/ctype.h"
|
||||
#include <limits.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/bio.h>
|
||||
#include "bn_lcl.h"
|
||||
|
||||
static const char Hex[] = "0123456789ABCDEF";
|
||||
|
||||
/* Must 'OPENSSL_free' the returned data */
|
||||
char *BN_bn2hex(const BIGNUM *a)
|
||||
{
|
||||
int i, j, v, z = 0;
|
||||
char *buf;
|
||||
char *p;
|
||||
|
||||
if (BN_is_zero(a))
|
||||
return OPENSSL_strdup("0");
|
||||
buf = OPENSSL_malloc(a->top * BN_BYTES * 2 + 2);
|
||||
if (buf == NULL) {
|
||||
BNerr(BN_F_BN_BN2HEX, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
p = buf;
|
||||
if (a->neg)
|
||||
*p++ = '-';
|
||||
for (i = a->top - 1; i >= 0; i--) {
|
||||
for (j = BN_BITS2 - 8; j >= 0; j -= 8) {
|
||||
/* strip leading zeros */
|
||||
v = (int)((a->d[i] >> j) & 0xff);
|
||||
if (z || v != 0) {
|
||||
*p++ = Hex[v >> 4];
|
||||
*p++ = Hex[v & 0x0f];
|
||||
z = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
err:
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Must 'OPENSSL_free' the returned data */
|
||||
char *BN_bn2dec(const BIGNUM *a)
|
||||
{
|
||||
int i = 0, num, ok = 0, n, tbytes;
|
||||
char *buf = NULL;
|
||||
char *p;
|
||||
BIGNUM *t = NULL;
|
||||
BN_ULONG *bn_data = NULL, *lp;
|
||||
int bn_data_num;
|
||||
|
||||
/*-
|
||||
* get an upper bound for the length of the decimal integer
|
||||
* num <= (BN_num_bits(a) + 1) * log(2)
|
||||
* <= 3 * BN_num_bits(a) * 0.101 + log(2) + 1 (rounding error)
|
||||
* <= 3 * BN_num_bits(a) / 10 + 3 * BN_num_bits / 1000 + 1 + 1
|
||||
*/
|
||||
i = BN_num_bits(a) * 3;
|
||||
num = (i / 10 + i / 1000 + 1) + 1;
|
||||
tbytes = num + 3; /* negative and terminator and one spare? */
|
||||
bn_data_num = num / BN_DEC_NUM + 1;
|
||||
bn_data = OPENSSL_malloc(bn_data_num * sizeof(BN_ULONG));
|
||||
buf = OPENSSL_malloc(tbytes);
|
||||
if (buf == NULL || bn_data == NULL) {
|
||||
BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if ((t = BN_dup(a)) == NULL)
|
||||
goto err;
|
||||
|
||||
p = buf;
|
||||
lp = bn_data;
|
||||
if (BN_is_zero(t)) {
|
||||
*p++ = '0';
|
||||
*p++ = '\0';
|
||||
} else {
|
||||
if (BN_is_negative(t))
|
||||
*p++ = '-';
|
||||
|
||||
while (!BN_is_zero(t)) {
|
||||
if (lp - bn_data >= bn_data_num)
|
||||
goto err;
|
||||
*lp = BN_div_word(t, BN_DEC_CONV);
|
||||
if (*lp == (BN_ULONG)-1)
|
||||
goto err;
|
||||
lp++;
|
||||
}
|
||||
lp--;
|
||||
/*
|
||||
* We now have a series of blocks, BN_DEC_NUM chars in length, where
|
||||
* the last one needs truncation. The blocks need to be reversed in
|
||||
* order.
|
||||
*/
|
||||
n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT1, *lp);
|
||||
if (n < 0)
|
||||
goto err;
|
||||
p += n;
|
||||
while (lp != bn_data) {
|
||||
lp--;
|
||||
n = BIO_snprintf(p, tbytes - (size_t)(p - buf), BN_DEC_FMT2, *lp);
|
||||
if (n < 0)
|
||||
goto err;
|
||||
p += n;
|
||||
}
|
||||
}
|
||||
ok = 1;
|
||||
err:
|
||||
OPENSSL_free(bn_data);
|
||||
BN_free(t);
|
||||
if (ok)
|
||||
return buf;
|
||||
OPENSSL_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int BN_hex2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
BIGNUM *ret = NULL;
|
||||
BN_ULONG l = 0;
|
||||
int neg = 0, h, m, i, j, k, c;
|
||||
int num;
|
||||
|
||||
if (a == NULL || *a == '\0')
|
||||
return 0;
|
||||
|
||||
if (*a == '-') {
|
||||
neg = 1;
|
||||
a++;
|
||||
}
|
||||
|
||||
for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)
|
||||
continue;
|
||||
|
||||
if (i == 0 || i > INT_MAX / 4)
|
||||
goto err;
|
||||
|
||||
num = i + neg;
|
||||
if (bn == NULL)
|
||||
return num;
|
||||
|
||||
/* a is the start of the hex digits, and it is 'i' long */
|
||||
if (*bn == NULL) {
|
||||
if ((ret = BN_new()) == NULL)
|
||||
return 0;
|
||||
} else {
|
||||
ret = *bn;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
/* i is the number of hex digits */
|
||||
if (bn_expand(ret, i * 4) == NULL)
|
||||
goto err;
|
||||
|
||||
j = i; /* least significant 'hex' */
|
||||
m = 0;
|
||||
h = 0;
|
||||
while (j > 0) {
|
||||
m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;
|
||||
l = 0;
|
||||
for (;;) {
|
||||
c = a[j - m];
|
||||
k = OPENSSL_hexchar2int(c);
|
||||
if (k < 0)
|
||||
k = 0; /* paranoia */
|
||||
l = (l << 4) | k;
|
||||
|
||||
if (--m <= 0) {
|
||||
ret->d[h++] = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
j -= BN_BYTES * 2;
|
||||
}
|
||||
ret->top = h;
|
||||
bn_correct_top(ret);
|
||||
|
||||
*bn = ret;
|
||||
bn_check_top(ret);
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (ret->top != 0)
|
||||
ret->neg = neg;
|
||||
return num;
|
||||
err:
|
||||
if (*bn == NULL)
|
||||
BN_free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_dec2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
BIGNUM *ret = NULL;
|
||||
BN_ULONG l = 0;
|
||||
int neg = 0, i, j;
|
||||
int num;
|
||||
|
||||
if (a == NULL || *a == '\0')
|
||||
return 0;
|
||||
if (*a == '-') {
|
||||
neg = 1;
|
||||
a++;
|
||||
}
|
||||
|
||||
for (i = 0; i <= INT_MAX / 4 && ossl_isdigit(a[i]); i++)
|
||||
continue;
|
||||
|
||||
if (i == 0 || i > INT_MAX / 4)
|
||||
goto err;
|
||||
|
||||
num = i + neg;
|
||||
if (bn == NULL)
|
||||
return num;
|
||||
|
||||
/*
|
||||
* a is the start of the digits, and it is 'i' long. We chop it into
|
||||
* BN_DEC_NUM digits at a time
|
||||
*/
|
||||
if (*bn == NULL) {
|
||||
if ((ret = BN_new()) == NULL)
|
||||
return 0;
|
||||
} else {
|
||||
ret = *bn;
|
||||
BN_zero(ret);
|
||||
}
|
||||
|
||||
/* i is the number of digits, a bit of an over expand */
|
||||
if (bn_expand(ret, i * 4) == NULL)
|
||||
goto err;
|
||||
|
||||
j = BN_DEC_NUM - i % BN_DEC_NUM;
|
||||
if (j == BN_DEC_NUM)
|
||||
j = 0;
|
||||
l = 0;
|
||||
while (--i >= 0) {
|
||||
l *= 10;
|
||||
l += *a - '0';
|
||||
a++;
|
||||
if (++j == BN_DEC_NUM) {
|
||||
if (!BN_mul_word(ret, BN_DEC_CONV)
|
||||
|| !BN_add_word(ret, l))
|
||||
goto err;
|
||||
l = 0;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bn_correct_top(ret);
|
||||
*bn = ret;
|
||||
bn_check_top(ret);
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (ret->top != 0)
|
||||
ret->neg = neg;
|
||||
return num;
|
||||
err:
|
||||
if (*bn == NULL)
|
||||
BN_free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_asc2bn(BIGNUM **bn, const char *a)
|
||||
{
|
||||
const char *p = a;
|
||||
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {
|
||||
if (!BN_hex2bn(bn, p + 2))
|
||||
return 0;
|
||||
} else {
|
||||
if (!BN_dec2bn(bn, p))
|
||||
return 0;
|
||||
}
|
||||
/* Don't set the negative flag if it's zero. */
|
||||
if (*a == '-' && (*bn)->top != 0)
|
||||
(*bn)->neg = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
int BN_print_fp(FILE *fp, const BIGNUM *a)
|
||||
{
|
||||
BIO *b;
|
||||
@@ -299,7 +26,7 @@ int BN_print_fp(FILE *fp, const BIGNUM *a)
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int BN_print(BIO *bp, const BIGNUM *a)
|
||||
{
|
||||
|
||||
+61
-20
@@ -10,18 +10,22 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/rand_int.h"
|
||||
#include "bn_lcl.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
typedef enum bnrand_flag_e {
|
||||
NORMAL, TESTING, PRIVATE
|
||||
} BNRAND_FLAG;
|
||||
|
||||
static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
|
||||
static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
unsigned char *buf = NULL;
|
||||
int b, ret = 0, bit, bytes, mask;
|
||||
OPENSSL_CTX *libctx = bn_get_lib_ctx(ctx);
|
||||
|
||||
if (bits == 0) {
|
||||
if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)
|
||||
@@ -43,7 +47,8 @@ static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
|
||||
}
|
||||
|
||||
/* make a random number and set the top and bottom bits */
|
||||
b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);
|
||||
b = flag == NORMAL ? rand_bytes_ex(libctx, buf, bytes)
|
||||
: rand_priv_bytes_ex(libctx, buf, bytes);
|
||||
if (b <= 0)
|
||||
goto err;
|
||||
|
||||
@@ -55,7 +60,7 @@ static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
|
||||
unsigned char c;
|
||||
|
||||
for (i = 0; i < bytes; i++) {
|
||||
if (RAND_bytes(&c, 1) <= 0)
|
||||
if (rand_bytes_ex(libctx, &c, 1) <= 0)
|
||||
goto err;
|
||||
if (c >= 128 && i > 0)
|
||||
buf[i] = buf[i - 1];
|
||||
@@ -94,23 +99,33 @@ toosmall:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BN_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx)
|
||||
{
|
||||
return bnrand(NORMAL, rnd, bits, top, bottom, ctx);
|
||||
}
|
||||
int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(NORMAL, rnd, bits, top, bottom);
|
||||
return bnrand(NORMAL, rnd, bits, top, bottom, NULL);
|
||||
}
|
||||
|
||||
int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(TESTING, rnd, bits, top, bottom);
|
||||
return bnrand(TESTING, rnd, bits, top, bottom, NULL);
|
||||
}
|
||||
|
||||
int BN_priv_rand_ex(BIGNUM *rnd, int bits, int top, int bottom, BN_CTX *ctx)
|
||||
{
|
||||
return bnrand(PRIVATE, rnd, bits, top, bottom, ctx);
|
||||
}
|
||||
|
||||
int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
{
|
||||
return bnrand(PRIVATE, rnd, bits, top, bottom);
|
||||
return bnrand(PRIVATE, rnd, bits, top, bottom, NULL);
|
||||
}
|
||||
|
||||
/* random number r: 0 <= r < range */
|
||||
static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range)
|
||||
static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
int n;
|
||||
int count = 100;
|
||||
@@ -132,7 +147,8 @@ static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range)
|
||||
* than range
|
||||
*/
|
||||
do {
|
||||
if (!bnrand(flag, r, n + 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))
|
||||
if (!bnrand(flag, r, n + 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY,
|
||||
ctx))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@@ -159,7 +175,7 @@ static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range)
|
||||
} else {
|
||||
do {
|
||||
/* range = 11..._2 or range = 101..._2 */
|
||||
if (!bnrand(flag, r, n, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))
|
||||
if (!bnrand(flag, r, n, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY, ctx))
|
||||
return 0;
|
||||
|
||||
if (!--count) {
|
||||
@@ -174,14 +190,24 @@ static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int BN_rand_range_ex(BIGNUM *r, const BIGNUM *range, BN_CTX *ctx)
|
||||
{
|
||||
return bnrand_range(NORMAL, r, range, ctx);
|
||||
}
|
||||
|
||||
int BN_rand_range(BIGNUM *r, const BIGNUM *range)
|
||||
{
|
||||
return bnrand_range(NORMAL, r, range);
|
||||
return bnrand_range(NORMAL, r, range, NULL);
|
||||
}
|
||||
|
||||
int BN_priv_rand_range_ex(BIGNUM *r, const BIGNUM *range, BN_CTX *ctx)
|
||||
{
|
||||
return bnrand_range(PRIVATE, r, range, ctx);
|
||||
}
|
||||
|
||||
int BN_priv_rand_range(BIGNUM *r, const BIGNUM *range)
|
||||
{
|
||||
return bnrand_range(PRIVATE, r, range);
|
||||
return bnrand_range(PRIVATE, r, range, NULL);
|
||||
}
|
||||
|
||||
int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
|
||||
@@ -206,7 +232,7 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
|
||||
const BIGNUM *priv, const unsigned char *message,
|
||||
size_t message_len, BN_CTX *ctx)
|
||||
{
|
||||
SHA512_CTX sha;
|
||||
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
|
||||
/*
|
||||
* We use 512 bits of random data per iteration to ensure that we have at
|
||||
* least |range| bits of randomness.
|
||||
@@ -217,8 +243,13 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
|
||||
/* We generate |range|+8 bytes of random output. */
|
||||
const unsigned num_k_bytes = BN_num_bytes(range) + 8;
|
||||
unsigned char private_bytes[96];
|
||||
unsigned char *k_bytes;
|
||||
unsigned char *k_bytes = NULL;
|
||||
int ret = 0;
|
||||
EVP_MD *md = NULL;
|
||||
OPENSSL_CTX *libctx = bn_get_lib_ctx(ctx);
|
||||
|
||||
if (mdctx == NULL)
|
||||
goto err;
|
||||
|
||||
k_bytes = OPENSSL_malloc(num_k_bytes);
|
||||
if (k_bytes == NULL)
|
||||
@@ -238,15 +269,23 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
|
||||
memcpy(private_bytes, priv->d, todo);
|
||||
memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);
|
||||
|
||||
md = EVP_MD_fetch(libctx, "SHA512", NULL);
|
||||
if (md == NULL) {
|
||||
BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_NO_SUITABLE_DIGEST);
|
||||
goto err;
|
||||
}
|
||||
for (done = 0; done < num_k_bytes;) {
|
||||
if (RAND_priv_bytes(random_bytes, sizeof(random_bytes)) != 1)
|
||||
if (!rand_priv_bytes_ex(libctx, random_bytes, sizeof(random_bytes)))
|
||||
goto err;
|
||||
|
||||
if (!EVP_DigestInit_ex(mdctx, md, NULL)
|
||||
|| !EVP_DigestUpdate(mdctx, &done, sizeof(done))
|
||||
|| !EVP_DigestUpdate(mdctx, private_bytes,
|
||||
sizeof(private_bytes))
|
||||
|| !EVP_DigestUpdate(mdctx, message, message_len)
|
||||
|| !EVP_DigestUpdate(mdctx, random_bytes, sizeof(random_bytes))
|
||||
|| !EVP_DigestFinal_ex(mdctx, digest, NULL))
|
||||
goto err;
|
||||
SHA512_Init(&sha);
|
||||
SHA512_Update(&sha, &done, sizeof(done));
|
||||
SHA512_Update(&sha, private_bytes, sizeof(private_bytes));
|
||||
SHA512_Update(&sha, message, message_len);
|
||||
SHA512_Update(&sha, random_bytes, sizeof(random_bytes));
|
||||
SHA512_Final(digest, &sha);
|
||||
|
||||
todo = num_k_bytes - done;
|
||||
if (todo > SHA512_DIGEST_LENGTH)
|
||||
@@ -262,6 +301,8 @@ int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_free(mdctx);
|
||||
EVP_MD_meth_free(md);
|
||||
OPENSSL_free(k_bytes);
|
||||
OPENSSL_cleanse(private_bytes, sizeof(private_bytes));
|
||||
return ret;
|
||||
|
||||
+2
-1
@@ -125,7 +125,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
* = a.
|
||||
*
|
||||
* (This is due to A.O.L. Atkin,
|
||||
* <URL: http://listserv.nodak.edu/scripts/wa.exe?A2=ind9211&L=nmbrthry&O=T&P=562>,
|
||||
* Subject: Square Roots and Cognate Matters modulo p=8n+5.
|
||||
* URL: https://listserv.nodak.edu/cgi-bin/wa.exe?A2=ind9211&L=NMBRTHRY&P=4026
|
||||
* November 1992.)
|
||||
*/
|
||||
|
||||
|
||||
+112
-7
@@ -1,12 +1,117 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
|
||||
bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
|
||||
bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c \
|
||||
{- $target{bn_asm_src} -} \
|
||||
|
||||
$BNASM=bn_asm.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
# Define source files and macros per asm architecture
|
||||
# Known macros are:
|
||||
#
|
||||
# OPENSSL_BN_ASM_PART_WORDS For any collection with /-586/ file names
|
||||
# OPENSSL_BN_ASM_MONT For any collection with /-mont/ file names
|
||||
# OPENSSL_BN_ASM_MONT5 For any collection with /-mont5/ file names
|
||||
# OPENSSL_BN_ASM_GF2m For any collection with /-gf2m/ file names
|
||||
# OPENSSL_IA32_SSE2 For any collection with /86/ file names
|
||||
# when sse2 is enabled
|
||||
# BN_DIV3W For any collection with /-div3w/ file names
|
||||
#
|
||||
# All variables are named in such a way that they can be "indexed" with
|
||||
# $target{asm_arch}
|
||||
|
||||
$BNASM_x86=bn-586.s co-586.s x86-mont.s x86-gf2m.s
|
||||
# bn-586 is the only one implementing bn_*_part_words
|
||||
# => OPENSSL_BN_ASM_PART_WORDS
|
||||
$BNDEF_x86=OPENSSL_BN_ASM_PART_WORDS OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_GF2m
|
||||
$BNDEF_x86_sse2=OPENSSL_IA32_SSE2
|
||||
|
||||
$BNASM_x86_64=\
|
||||
x86_64-mont.s x86_64-mont5.s x86_64-gf2m.s rsaz_exp.c rsaz-x86_64.s \
|
||||
rsaz-avx2.s
|
||||
IF[{- $config{target} !~ /^VC/ -}]
|
||||
$BNASM_x86_64=asm/x86_64-gcc.c $BNASM_x86_64
|
||||
ELSE
|
||||
$BNASM_x86_64=bn_asm.c $BNASM_x86_64
|
||||
ENDIF
|
||||
$BNDEF_x86_64=OPENSSL_BN_ASM_MONT OPENSSL_BN_ASM_MONT5 OPENSSL_BN_ASM_GF2m
|
||||
$BNDEF_x86_64_sse2=OPENSSL_IA32_SSE2
|
||||
|
||||
IF[{- $config{target} !~ /^VC/ -}]
|
||||
$BNASM_ia64=bn-ia64.s ia64-mont.s
|
||||
ELSE
|
||||
$BNASM_ia64=bn_asm.c ia64-mont.s
|
||||
ENDIF
|
||||
|
||||
$BNASM_sparcv9=asm/sparcv8plus.S sparcv9-mont.S sparcv9a-mont.S vis3-mont.S \
|
||||
sparct4-mont.S
|
||||
$BNDEF_sparcv9=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_sparcv9_ec2m=sparcv9-gf2m.S
|
||||
$BNDEF_sparcv9_ec2m=OPENSSL_BN_ASM_GF2m
|
||||
|
||||
$BNASM_sparcv8=asm/sparcv8.S
|
||||
|
||||
$BNASM_alpha=bn_asm.c alpha-mont.S
|
||||
$BNDEF_alpha=OPENSSL_BN_ASM_MONT
|
||||
|
||||
$BNASM_mips32=bn-mips.S mips-mont.S
|
||||
$BNDEF_mips32=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_mips64=$BNASM_mips32
|
||||
$BNDEF_mips64=$BNDEF_mips32
|
||||
|
||||
IF[{- ($target{perlasm_scheme} // '') eq '31' -}]
|
||||
$BNASM_s390x=bn_asm.c s390x-mont.S
|
||||
ELSE
|
||||
$BNASM_s390x=asm/s390x.S s390x-mont.S
|
||||
ENDIF
|
||||
$BNDEF_s390x=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_s390x_ec2m=s390x-gf2m.s
|
||||
$BNDEF_s390x_ec2m=OPENSSL_BN_ASM_GF2m
|
||||
|
||||
$BNASM_armv4=bn_asm.c armv4-mont.S
|
||||
$BNDEF_armv4=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_armv4_ec2m=armv4-gf2m.S
|
||||
$BNDEF_armv4_ec2m=OPENSSL_BN_ASM_GF2m
|
||||
|
||||
$BNASM_aarch64=bn_asm.c armv8-mont.S
|
||||
$BNDEF_aarch64=OPENSSL_BN_ASM_MONT
|
||||
|
||||
$BNASM_parisc11=bn_asm.c parisc-mont.s
|
||||
$BNDEF_parisc11=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_parisc20_64=$BNASM_parisc11
|
||||
$BNDEF_parisc20_64=$BNDEF_parisc11
|
||||
|
||||
$BNASM_ppc32=bn-ppc.s ppc-mont.s
|
||||
$BNDEF_ppc32=OPENSSL_BN_ASM_MONT
|
||||
$BNASM_ppc64=$BNASM_ppc32
|
||||
$BNDEF_ppc64=$BNDEF_ppc32
|
||||
|
||||
$BNASM_c64xplus=asm/bn-c64xplus.asm
|
||||
$BNASM_c64xplus_ec2m=c64xplus-gf2m.s
|
||||
$BNDEF_c64xplus_ec2m=OPENSSL_BN_ASM_GF2m
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate ones, and define the appropriate macros
|
||||
IF[$BNASM_{- $target{asm_arch} -}]
|
||||
$BNASM=$BNASM_{- $target{asm_arch} -}
|
||||
$BNDEF=$BNDEF_{- $target{asm_arch} -}
|
||||
IF[{- !$disabled{ec2m} -}]
|
||||
$BNASM=$BNASM $BNASM_{- $target{asm_arch} -}_ec2m
|
||||
$BNDEF=$BNDEF $BNDEF_{- $target{asm_arch} -}_ec2m
|
||||
ENDIF
|
||||
IF[{- !$disabled{sse2} -}]
|
||||
$BNDEF_sse2=$BNDEF $BNDEF_{- $target{asm_arch} -}_sse2
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$COMMON=bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c \
|
||||
bn_mod.c bn_conv.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
|
||||
bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_sqr.c \
|
||||
bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
|
||||
bn_depr.c bn_const.c bn_x931p.c bn_intern.c bn_dh.c bn_srp.c \
|
||||
bn_rsa_fips186_4.c
|
||||
bn_const.c bn_x931p.c bn_intern.c bn_dh.c \
|
||||
bn_rsa_fips186_4.c $BNASM
|
||||
SOURCE[../../libcrypto]=$COMMON bn_print.c bn_err.c bn_depr.c bn_srp.c
|
||||
DEFINE[../../libcrypto]=$BNDEF
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
DEFINE[../../providers/fips]=$BNDEF
|
||||
|
||||
INCLUDE[../../libcrypto]=../../crypto/include
|
||||
|
||||
INCLUDE[bn_exp.o]=..
|
||||
|
||||
+70
-19
@@ -1,34 +1,85 @@
|
||||
# Note that these directories are filtered in Configure. Look for %skipdir
|
||||
# there for further explanations.
|
||||
SUBDIRS=objects buffer bio stack lhash rand evp asn1 pem x509 x509v3 conf \
|
||||
SUBDIRS=objects buffer bio stack lhash rand evp asn1 pem x509 conf \
|
||||
txt_db pkcs7 pkcs12 ui kdf store property \
|
||||
md2 md4 md5 sha mdc2 gmac hmac ripemd whrlpool poly1305 blake2 \
|
||||
siphash sm3 des aes rc2 rc4 rc5 idea aria bf cast camellia \
|
||||
seed sm4 chacha modes bn ec rsa dsa dh sm2 dso engine \
|
||||
err comp ocsp cms ts srp cmac ct async kmac ess crmf
|
||||
err comp ocsp cms ts srp cmac ct async kmac ess crmf cmp
|
||||
|
||||
LIBS=../libcrypto
|
||||
# The Core
|
||||
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
|
||||
$UPLINKSRC=
|
||||
$UPLINKDEF=
|
||||
IF[{- !$disabled{uplink} -}]
|
||||
$UPLINKSRC_common=../ms/uplink.c
|
||||
$UPLINKSRC_x86=$UPLINKSRC_common uplink-x86.s
|
||||
$UPLINKSRC_x86_64=$UPLINKSRC_common uplink-x86_64.s
|
||||
$UPLINKSRC_ia64=$UPLINKSRC_common uplink-ia64.s
|
||||
|
||||
IF[$UPLINKSRC_{- $target{uplink_arch} -}]
|
||||
$UPLINKSRC=$UPLINKSRC_{- $target{uplink_arch} -}
|
||||
$UPLINKDEF=OPENSSL_USE_APPLINK
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
$CPUIDASM=mem_clr.c
|
||||
$CPUIDDEF=
|
||||
IF[{- !$disabled{asm} && $config{processor} ne '386' -}]
|
||||
$CPUIDASM_x86=x86cpuid.s
|
||||
|
||||
$CPUIDASM_x86_64=x86_64cpuid.s
|
||||
|
||||
$CPUIDASM_ia64=ia64cpuid.s
|
||||
|
||||
$CPUIDASM_sparcv9=sparcv9cap.c sparccpuid.S
|
||||
|
||||
$CPUIDASM_alpha=alphacpuid.s
|
||||
|
||||
$CPUIDASM_s390x=s390xcap.c s390xcpuid.S
|
||||
|
||||
$CPUIDASM_armv4=armcap.c armv4cpuid.S
|
||||
|
||||
$CPUIDASM_aarch64=armcap.c arm64cpuid.S
|
||||
|
||||
$CPUIDASM_parisc11=pariscid.s
|
||||
$CPUIDASM_parisc20_64=$CPUIDASM_parisc11
|
||||
|
||||
$CPUIDASM_ppc32=ppccpuid.s ppccap.c
|
||||
$CPUIDASM_ppc64=$CPUIDASM_ppc32
|
||||
|
||||
$CPUIDASM_c64xplus=c64xpluscpuid.s
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one, and define the appropriate macros
|
||||
IF[$CPUIDASM_{- $target{asm_arch} -}]
|
||||
$CPUIDASM=$CPUIDASM_{- $target{asm_arch} -}
|
||||
$CPUIDDEF=OPENSSL_CPUID_OBJ
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
# The Core
|
||||
$CORE_COMMON=provider_core.c provider_predefined.c core_fetch.c core_namemap.c
|
||||
|
||||
SOURCE[../libcrypto]=$CORE_COMMON provider_conf.c
|
||||
SOURCE[../providers/fips]=$CORE_COMMON
|
||||
|
||||
# Central utilities
|
||||
SOURCE[../libcrypto]=\
|
||||
cryptlib.c mem.c mem_dbg.c cversion.c info.c ex_data.c cpt_err.c \
|
||||
ebcdic.c uid.c o_time.c o_str.c o_dir.c o_fopen.c ctype.c \
|
||||
threads_pthread.c threads_win.c threads_none.c getenv.c \
|
||||
o_init.c o_fips.c mem_sec.c init.c context.c sparse_array.c \
|
||||
trace.c provider.c params.c bsearch.c \
|
||||
{- $target{cpuid_asm_src} -} {- $target{uplink_aux_src} -}
|
||||
$UTIL_COMMON=\
|
||||
cryptlib.c params.c bsearch.c ex_data.c o_str.c \
|
||||
ctype.c threads_pthread.c threads_win.c threads_none.c initthread.c \
|
||||
context.c sparse_array.c $CPUIDASM
|
||||
$UTIL_DEFINE=$CPUIDDEF
|
||||
|
||||
# FIPS module
|
||||
SOURCE[../providers/fips]=\
|
||||
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
|
||||
SOURCE[../libcrypto]=$UTIL_COMMON \
|
||||
mem.c mem_sec.c mem_str.c mem_dbg.c \
|
||||
cversion.c info.c cpt_err.c ebcdic.c uid.c o_time.c o_dir.c \
|
||||
o_fopen.c getenv.c o_init.c o_fips.c init.c trace.c provider.c \
|
||||
$UPLINKSRC
|
||||
DEFINE[../libcrypto]=$UTIL_DEFINE $UPLINKDEF
|
||||
SOURCE[../providers/fips]=$UTIL_COMMON
|
||||
DEFINE[../providers/fips]=$UTIL_DEFINE
|
||||
|
||||
|
||||
|
||||
DEPEND[cversion.o]=buildinf.h
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
cmll_ecb.c cmll_ofb.c cmll_cfb.c cmll_ctr.c \
|
||||
{- $target{cmll_asm_src} -}
|
||||
|
||||
$CMLLASM=camellia.c cmll_misc.c cmll_cbc.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$CMLLASM_x86=cmll-x86.s
|
||||
$CMLLASM_x86_64=cmll-x86_64.s cmll_misc.c
|
||||
$CMLLASM_sparcv9=camellia.c cmll_misc.c cmll_cbc.c cmllt4-sparcv9.S
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one
|
||||
IF[$CMLLASM_{- $target{asm_arch} -}]
|
||||
$CMLLASM=$CMLLASM_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=cmll_ecb.c cmll_ofb.c cmll_cfb.c cmll_ctr.c $CMLLASM
|
||||
|
||||
GENERATE[cmll-x86.s]=asm/cmll-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) \
|
||||
|
||||
+14
-2
@@ -1,6 +1,18 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
c_skey.c c_ecb.c {- $target{cast_asm_src} -} c_cfb64.c c_ofb64.c
|
||||
|
||||
$CASTASM=c_enc.c
|
||||
# CAST assembly source is not PIC
|
||||
IF[{- !$disabled{asm} && !$disabled{pic} -}]
|
||||
$CASTASM_x86=cast-586.s
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one
|
||||
IF[$CASTASM_{- $target{asm_arch} -}]
|
||||
$CASTASM=$CASTASM_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=c_skey.c c_ecb.c $CASTASM c_cfb64.c c_ofb64.c
|
||||
|
||||
GENERATE[cast-586.s]=asm/cast-586.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]={- $target{chacha_asm_src} -}
|
||||
|
||||
$CHACHAASM=chacha_enc.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$CHACHAASM_x86=chacha-x86.s
|
||||
$CHACHAASM_x86_64=chacha-x86_64.s
|
||||
|
||||
$CHACHAASM_ia64=chacha-ia64.S
|
||||
|
||||
$CHACHAASM_s390x=chacha-s390x.S
|
||||
|
||||
$CHACHAASM_armv4=chacha-armv4.S
|
||||
$CHACHAASM_aarch64=chacha-armv8.S
|
||||
|
||||
$CHACHAASM_ppc32=chacha-ppc.s
|
||||
$CHACHAASM_ppc64=$CHACHAASM_ppc32
|
||||
|
||||
$CHACHAASM_c64xplus=chacha-c64xplus.s
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one
|
||||
IF[$CHACHAASM_{- $target{asm_arch} -}]
|
||||
$CHACHAASM=$CHACHAASM_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
SOURCE[../../libcrypto]=$CHACHAASM
|
||||
|
||||
GENERATE[chacha-x86.s]=asm/chacha-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
|
||||
+13
-5
@@ -46,14 +46,22 @@ static void cmac_free(EVP_MAC_IMPL *cctx)
|
||||
}
|
||||
}
|
||||
|
||||
static int cmac_copy(EVP_MAC_IMPL *cdst, EVP_MAC_IMPL *csrc)
|
||||
static EVP_MAC_IMPL *cmac_dup(const EVP_MAC_IMPL *csrc)
|
||||
{
|
||||
if (!CMAC_CTX_copy(cdst->ctx, csrc->ctx))
|
||||
return 0;
|
||||
EVP_MAC_IMPL *cdst = cmac_new();
|
||||
|
||||
if (cdst == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!CMAC_CTX_copy(cdst->ctx, csrc->ctx)) {
|
||||
cmac_free(cdst);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cdst->tmpengine = csrc->tmpengine;
|
||||
cdst->tmpcipher = csrc->tmpcipher;
|
||||
return 1;
|
||||
|
||||
return cdst;
|
||||
}
|
||||
|
||||
static size_t cmac_size(EVP_MAC_IMPL *cctx)
|
||||
@@ -153,7 +161,7 @@ static int cmac_ctrl_str(EVP_MAC_IMPL *cctx, const char *type,
|
||||
const EVP_MAC cmac_meth = {
|
||||
EVP_MAC_CMAC,
|
||||
cmac_new,
|
||||
cmac_copy,
|
||||
cmac_dup,
|
||||
cmac_free,
|
||||
cmac_size,
|
||||
cmac_init,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]= cmp_asn.c cmp_err.c
|
||||
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* CMP implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
|
||||
*/
|
||||
|
||||
#include <openssl/asn1t.h>
|
||||
|
||||
#include "cmp_int.h"
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
#include <openssl/cmp.h>
|
||||
#include <openssl/crmf.h>
|
||||
|
||||
/* ASN.1 declarations from RFC4210 */
|
||||
ASN1_SEQUENCE(OSSL_CMP_REVANNCONTENT) = {
|
||||
/* OSSL_CMP_PKISTATUS is effectively ASN1_INTEGER so it is used directly */
|
||||
ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, status, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, certId, OSSL_CRMF_CERTID),
|
||||
ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, willBeRevokedAt, ASN1_GENERALIZEDTIME),
|
||||
ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, badSinceDate, ASN1_GENERALIZEDTIME),
|
||||
ASN1_OPT(OSSL_CMP_REVANNCONTENT, crlDetails, X509_EXTENSIONS)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_REVANNCONTENT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVANNCONTENT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CHALLENGE) = {
|
||||
ASN1_OPT(OSSL_CMP_CHALLENGE, owf, X509_ALGOR),
|
||||
ASN1_SIMPLE(OSSL_CMP_CHALLENGE, witness, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(OSSL_CMP_CHALLENGE, challenge, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CHALLENGE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CHALLENGE)
|
||||
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_POPODECKEYCHALLCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
|
||||
OSSL_CMP_POPODECKEYCHALLCONTENT, OSSL_CMP_CHALLENGE)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POPODECKEYCHALLCONTENT)
|
||||
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_POPODECKEYRESPCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
|
||||
OSSL_CMP_POPODECKEYRESPCONTENT, ASN1_INTEGER)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POPODECKEYRESPCONTENT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CAKEYUPDANNCONTENT) = {
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, oldWithNew, X509),
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, newWithOld, X509),
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, newWithNew, X509)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CAKEYUPDANNCONTENT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_ERRORMSGCONTENT) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_ERRORMSGCONTENT, pKIStatusInfo, OSSL_CMP_PKISI),
|
||||
ASN1_OPT(OSSL_CMP_ERRORMSGCONTENT, errorCode, ASN1_INTEGER),
|
||||
/*
|
||||
* OSSL_CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
|
||||
* so it is used directly
|
||||
*
|
||||
*/
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ERRORMSGCONTENT, errorDetails, ASN1_UTF8STRING)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_ERRORMSGCONTENT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT)
|
||||
|
||||
ASN1_ADB_TEMPLATE(infotypeandvalue_default) = ASN1_OPT(OSSL_CMP_ITAV,
|
||||
infoValue.other, ASN1_ANY);
|
||||
/* ITAV means InfoTypeAndValue */
|
||||
ASN1_ADB(OSSL_CMP_ITAV) = {
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ADB_ENTRY(NID_id_it_caProtEncCert, ASN1_OPT(OSSL_CMP_ITAV,
|
||||
infoValue.caProtEncCert, X509)),
|
||||
ADB_ENTRY(NID_id_it_signKeyPairTypes,
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
|
||||
infoValue.signKeyPairTypes, X509_ALGOR)),
|
||||
ADB_ENTRY(NID_id_it_encKeyPairTypes,
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
|
||||
infoValue.encKeyPairTypes, X509_ALGOR)),
|
||||
ADB_ENTRY(NID_id_it_preferredSymmAlg,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.preferredSymmAlg,
|
||||
X509_ALGOR)),
|
||||
ADB_ENTRY(NID_id_it_caKeyUpdateInfo,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.caKeyUpdateInfo,
|
||||
OSSL_CMP_CAKEYUPDANNCONTENT)),
|
||||
ADB_ENTRY(NID_id_it_currentCRL,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.currentCRL, X509_CRL)),
|
||||
ADB_ENTRY(NID_id_it_unsupportedOIDs,
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
|
||||
infoValue.unsupportedOIDs, ASN1_OBJECT)),
|
||||
ADB_ENTRY(NID_id_it_keyPairParamReq,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.keyPairParamReq,
|
||||
ASN1_OBJECT)),
|
||||
ADB_ENTRY(NID_id_it_keyPairParamRep,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.keyPairParamRep,
|
||||
X509_ALGOR)),
|
||||
ADB_ENTRY(NID_id_it_revPassphrase,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.revPassphrase,
|
||||
OSSL_CRMF_ENCRYPTEDVALUE)),
|
||||
ADB_ENTRY(NID_id_it_implicitConfirm,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.implicitConfirm,
|
||||
ASN1_NULL)),
|
||||
ADB_ENTRY(NID_id_it_confirmWaitTime,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.confirmWaitTime,
|
||||
ASN1_GENERALIZEDTIME)),
|
||||
ADB_ENTRY(NID_id_it_origPKIMessage,
|
||||
ASN1_OPT(OSSL_CMP_ITAV, infoValue.origPKIMessage,
|
||||
OSSL_CMP_MSGS)),
|
||||
ADB_ENTRY(NID_id_it_suppLangTags,
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV, infoValue.suppLangTagsValue,
|
||||
ASN1_UTF8STRING)),
|
||||
} ASN1_ADB_END(OSSL_CMP_ITAV, 0, infoType, 0,
|
||||
&infotypeandvalue_default_tt, NULL);
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_ITAV) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_ITAV, infoType, ASN1_OBJECT),
|
||||
ASN1_ADB_OBJECT(OSSL_CMP_ITAV)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_ITAV)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV)
|
||||
|
||||
OSSL_CMP_ITAV *OSSL_CMP_ITAV_create(ASN1_OBJECT *type, ASN1_TYPE *value)
|
||||
{
|
||||
OSSL_CMP_ITAV *itav;
|
||||
|
||||
if (type == NULL || (itav = OSSL_CMP_ITAV_new()) == NULL)
|
||||
return NULL;
|
||||
OSSL_CMP_ITAV_set0(itav, type, value);
|
||||
return itav;
|
||||
}
|
||||
|
||||
void OSSL_CMP_ITAV_set0(OSSL_CMP_ITAV *itav, ASN1_OBJECT *type,
|
||||
ASN1_TYPE *value)
|
||||
{
|
||||
itav->infoType = type;
|
||||
itav->infoValue.other = value;
|
||||
}
|
||||
|
||||
ASN1_OBJECT *OSSL_CMP_ITAV_get0_type(const OSSL_CMP_ITAV *itav)
|
||||
{
|
||||
if (itav == NULL)
|
||||
return NULL;
|
||||
return itav->infoType;
|
||||
}
|
||||
|
||||
ASN1_TYPE *OSSL_CMP_ITAV_get0_value(const OSSL_CMP_ITAV *itav)
|
||||
{
|
||||
if (itav == NULL)
|
||||
return NULL;
|
||||
return itav->infoValue.other;
|
||||
}
|
||||
|
||||
int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
|
||||
OSSL_CMP_ITAV *itav)
|
||||
{
|
||||
int created = 0;
|
||||
|
||||
if (itav_sk_p == NULL)
|
||||
goto err;
|
||||
|
||||
if (*itav_sk_p == NULL) {
|
||||
if ((*itav_sk_p = sk_OSSL_CMP_ITAV_new_null()) == NULL)
|
||||
goto err;
|
||||
created = 1;
|
||||
}
|
||||
if (itav != NULL) {
|
||||
if (!sk_OSSL_CMP_ITAV_push(*itav_sk_p, itav))
|
||||
goto err;
|
||||
}
|
||||
return 1;
|
||||
err:
|
||||
if (created != 0) {
|
||||
sk_OSSL_CMP_ITAV_free(*itav_sk_p);
|
||||
*itav_sk_p = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ASN1_CHOICE(OSSL_CMP_CERTORENCCERT) = {
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.certificate, X509, 0),
|
||||
ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.encryptedCert,
|
||||
OSSL_CRMF_ENCRYPTEDVALUE, 1),
|
||||
} ASN1_CHOICE_END(OSSL_CMP_CERTORENCCERT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CERTIFIEDKEYPAIR) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_CERTIFIEDKEYPAIR, certOrEncCert,
|
||||
OSSL_CMP_CERTORENCCERT),
|
||||
ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, privateKey,
|
||||
OSSL_CRMF_ENCRYPTEDVALUE, 0),
|
||||
ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, publicationInfo,
|
||||
OSSL_CRMF_PKIPUBLICATIONINFO, 1)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CERTIFIEDKEYPAIR)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_REVDETAILS) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_REVDETAILS, certDetails, OSSL_CRMF_CERTTEMPLATE),
|
||||
ASN1_OPT(OSSL_CMP_REVDETAILS, crlEntryDetails, X509_EXTENSIONS)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_REVDETAILS)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
|
||||
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_REVREQCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_REVREQCONTENT,
|
||||
OSSL_CMP_REVDETAILS)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_REVREQCONTENT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_REVREPCONTENT) = {
|
||||
ASN1_SEQUENCE_OF(OSSL_CMP_REVREPCONTENT, status, OSSL_CMP_PKISI),
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, revCerts, OSSL_CRMF_CERTID,
|
||||
0),
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, crls, X509_CRL, 1)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_REVREPCONTENT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
|
||||
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_KEYRECREPCONTENT) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_KEYRECREPCONTENT, status, OSSL_CMP_PKISI),
|
||||
ASN1_EXP_OPT(OSSL_CMP_KEYRECREPCONTENT, newSigCert, X509, 0),
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, caCerts, X509, 1),
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, keyPairHist,
|
||||
OSSL_CMP_CERTIFIEDKEYPAIR, 2)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_KEYRECREPCONTENT)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
|
||||
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_PKISTATUS) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_UNIVERSAL, 0, status, ASN1_INTEGER)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_PKISTATUS)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_PKISI) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_PKISI, status, OSSL_CMP_PKISTATUS),
|
||||
/*
|
||||
* CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
|
||||
* so it is used directly
|
||||
*/
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_PKISI, statusString, ASN1_UTF8STRING),
|
||||
/*
|
||||
* OSSL_CMP_PKIFAILUREINFO is effectively ASN1_BIT_STRING so used directly
|
||||
*/
|
||||
ASN1_OPT(OSSL_CMP_PKISI, failInfo, ASN1_BIT_STRING)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_PKISI)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CERTSTATUS) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certHash, ASN1_OCTET_STRING),
|
||||
ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certReqId, ASN1_INTEGER),
|
||||
ASN1_OPT(OSSL_CMP_CERTSTATUS, statusInfo, OSSL_CMP_PKISI)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CERTSTATUS)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_CERTCONFIRMCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_CERTCONFIRMCONTENT,
|
||||
OSSL_CMP_CERTSTATUS)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CERTCONFIRMCONTENT)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CERTRESPONSE) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, certReqId, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, status, OSSL_CMP_PKISI),
|
||||
ASN1_OPT(OSSL_CMP_CERTRESPONSE, certifiedKeyPair,
|
||||
OSSL_CMP_CERTIFIEDKEYPAIR),
|
||||
ASN1_OPT(OSSL_CMP_CERTRESPONSE, rspInfo, ASN1_OCTET_STRING)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CERTRESPONSE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_POLLREQ) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_POLLREQ, certReqId, ASN1_INTEGER)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_POLLREQ)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREQCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_POLLREQCONTENT,
|
||||
OSSL_CMP_POLLREQ)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREQCONTENT)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_POLLREP) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_POLLREP, certReqId, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(OSSL_CMP_POLLREP, checkAfter, ASN1_INTEGER),
|
||||
ASN1_SEQUENCE_OF_OPT(OSSL_CMP_POLLREP, reason, ASN1_UTF8STRING),
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_POLLREP)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREPCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
|
||||
OSSL_CMP_POLLREPCONTENT,
|
||||
OSSL_CMP_POLLREP)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREPCONTENT)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_CERTREPMESSAGE) = {
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_CERTREPMESSAGE, caPubs, X509, 1),
|
||||
ASN1_SEQUENCE_OF(OSSL_CMP_CERTREPMESSAGE, response, OSSL_CMP_CERTRESPONSE)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_CERTREPMESSAGE)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_GENMSGCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENMSGCONTENT,
|
||||
OSSL_CMP_ITAV)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENMSGCONTENT)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_GENREPCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENREPCONTENT,
|
||||
OSSL_CMP_ITAV)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENREPCONTENT)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_CRLANNCONTENT) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
|
||||
OSSL_CMP_CRLANNCONTENT, X509_CRL)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CRLANNCONTENT)
|
||||
|
||||
ASN1_CHOICE(OSSL_CMP_PKIBODY) = {
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.ir, OSSL_CRMF_MSGS, 0),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.ip, OSSL_CMP_CERTREPMESSAGE, 1),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.cr, OSSL_CRMF_MSGS, 2),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.cp, OSSL_CMP_CERTREPMESSAGE, 3),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.p10cr, X509_REQ, 4),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecc, OSSL_CMP_POPODECKEYCHALLCONTENT, 5),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecr, OSSL_CMP_POPODECKEYRESPCONTENT, 6),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.kur, OSSL_CRMF_MSGS, 7),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.kup, OSSL_CMP_CERTREPMESSAGE, 8),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.krr, OSSL_CRMF_MSGS, 9),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.krp, OSSL_CMP_KEYRECREPCONTENT, 10),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.rr, OSSL_CMP_REVREQCONTENT, 11),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.rp, OSSL_CMP_REVREPCONTENT, 12),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.ccr, OSSL_CRMF_MSGS, 13),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.ccp, OSSL_CMP_CERTREPMESSAGE, 14),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.ckuann, OSSL_CMP_CAKEYUPDANNCONTENT, 15),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.cann, X509, 16),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.rann, OSSL_CMP_REVANNCONTENT, 17),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.crlann, OSSL_CMP_CRLANNCONTENT, 18),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.pkiconf, ASN1_ANY, 19),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.nested, OSSL_CMP_MSGS, 20),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.genm, OSSL_CMP_GENMSGCONTENT, 21),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.genp, OSSL_CMP_GENREPCONTENT, 22),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.error, OSSL_CMP_ERRORMSGCONTENT, 23),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.certConf, OSSL_CMP_CERTCONFIRMCONTENT, 24),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.pollReq, OSSL_CMP_POLLREQCONTENT, 25),
|
||||
ASN1_EXP(OSSL_CMP_PKIBODY, value.pollRep, OSSL_CMP_POLLREPCONTENT, 26),
|
||||
} ASN1_CHOICE_END(OSSL_CMP_PKIBODY)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_PKIHEADER) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_PKIHEADER, pvno, ASN1_INTEGER),
|
||||
ASN1_SIMPLE(OSSL_CMP_PKIHEADER, sender, GENERAL_NAME),
|
||||
ASN1_SIMPLE(OSSL_CMP_PKIHEADER, recipient, GENERAL_NAME),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, messageTime, ASN1_GENERALIZEDTIME, 0),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, protectionAlg, X509_ALGOR, 1),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderKID, ASN1_OCTET_STRING, 2),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipKID, ASN1_OCTET_STRING, 3),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, transactionID, ASN1_OCTET_STRING, 4),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderNonce, ASN1_OCTET_STRING, 5),
|
||||
ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipNonce, ASN1_OCTET_STRING, 6),
|
||||
/*
|
||||
* OSSL_CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
|
||||
* so it is used directly
|
||||
*/
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, freeText, ASN1_UTF8STRING, 7),
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, generalInfo,
|
||||
OSSL_CMP_ITAV, 8)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_PKIHEADER)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIHEADER)
|
||||
|
||||
ASN1_SEQUENCE(CMP_PROTECTEDPART) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
|
||||
ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY)
|
||||
} ASN1_SEQUENCE_END(CMP_PROTECTEDPART)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(CMP_PROTECTEDPART)
|
||||
|
||||
ASN1_SEQUENCE(OSSL_CMP_MSG) = {
|
||||
ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
|
||||
ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY),
|
||||
ASN1_EXP_OPT(OSSL_CMP_MSG, protection, ASN1_BIT_STRING, 0),
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_MSG, extraCerts, X509, 1)
|
||||
} ASN1_SEQUENCE_END(OSSL_CMP_MSG)
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_MSG)
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_MSG)
|
||||
|
||||
ASN1_ITEM_TEMPLATE(OSSL_CMP_MSGS) =
|
||||
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_MSGS,
|
||||
OSSL_CMP_MSG)
|
||||
ASN1_ITEM_TEMPLATE_END(OSSL_CMP_MSGS)
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
* 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
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cmperr.h>
|
||||
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
static const ERR_STRING_DATA CMP_str_functs[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static const ERR_STRING_DATA CMP_str_reasons[] = {
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
int ERR_load_CMP_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
if (ERR_func_error_string(CMP_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings_const(CMP_str_functs);
|
||||
ERR_load_strings_const(CMP_str_reasons);
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* CMP implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
|
||||
*/
|
||||
|
||||
#ifndef OSSL_HEADER_CMP_INT_H
|
||||
# define OSSL_HEADER_CMP_INT_H
|
||||
|
||||
# include "internal/cryptlib.h"
|
||||
|
||||
# include <openssl/cmp.h>
|
||||
# include <openssl/err.h>
|
||||
|
||||
/* explicit #includes not strictly needed since implied by the above: */
|
||||
# include <openssl/crmf.h>
|
||||
# include <openssl/ossl_typ.h>
|
||||
# include <openssl/safestack.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/x509v3.h>
|
||||
|
||||
/*
|
||||
* ##########################################################################
|
||||
* ASN.1 DECLARATIONS
|
||||
* ##########################################################################
|
||||
*/
|
||||
|
||||
/*-
|
||||
* RevAnnContent ::= SEQUENCE {
|
||||
* status PKIStatus,
|
||||
* certId CertId,
|
||||
* willBeRevokedAt GeneralizedTime,
|
||||
* badSinceDate GeneralizedTime,
|
||||
* crlDetails Extensions OPTIONAL
|
||||
* -- extra CRL details (e.g., crl number, reason, location, etc.)
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_revanncontent_st {
|
||||
ASN1_INTEGER *status;
|
||||
OSSL_CRMF_CERTID *certId;
|
||||
ASN1_GENERALIZEDTIME *willBeRevokedAt;
|
||||
ASN1_GENERALIZEDTIME *badSinceDate;
|
||||
X509_EXTENSIONS *crlDetails;
|
||||
} OSSL_CMP_REVANNCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVANNCONTENT)
|
||||
|
||||
/*-
|
||||
* Challenge ::= SEQUENCE {
|
||||
* owf AlgorithmIdentifier OPTIONAL,
|
||||
*
|
||||
* -- MUST be present in the first Challenge; MAY be omitted in
|
||||
* -- any subsequent Challenge in POPODecKeyChallContent (if
|
||||
* -- omitted, then the owf used in the immediately preceding
|
||||
* -- Challenge is to be used).
|
||||
*
|
||||
* witness OCTET STRING,
|
||||
* -- the result of applying the one-way function (owf) to a
|
||||
* -- randomly-generated INTEGER, A. [Note that a different
|
||||
* -- INTEGER MUST be used for each Challenge.]
|
||||
* challenge OCTET STRING
|
||||
* -- the encryption (under the public key for which the cert.
|
||||
* -- request is being made) of Rand, where Rand is specified as
|
||||
* -- Rand ::= SEQUENCE {
|
||||
* -- int INTEGER,
|
||||
* -- - the randomly-generated INTEGER A (above)
|
||||
* -- sender GeneralName
|
||||
* -- - the sender's name (as included in PKIHeader)
|
||||
* -- }
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_challenge_st {
|
||||
X509_ALGOR *owf;
|
||||
ASN1_OCTET_STRING *witness;
|
||||
ASN1_OCTET_STRING *challenge;
|
||||
} OSSL_CMP_CHALLENGE;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CHALLENGE)
|
||||
|
||||
/*-
|
||||
* CAKeyUpdAnnContent ::= SEQUENCE {
|
||||
* oldWithNew Certificate,
|
||||
* newWithOld Certificate,
|
||||
* newWithNew Certificate
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_cakeyupdanncontent_st {
|
||||
X509 *oldWithNew;
|
||||
X509 *newWithOld;
|
||||
X509 *newWithNew;
|
||||
} OSSL_CMP_CAKEYUPDANNCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT)
|
||||
|
||||
/*-
|
||||
* declared already here as it will be used in OSSL_CMP_MSG (nested) and
|
||||
* infoType and infoValue
|
||||
*/
|
||||
typedef STACK_OF(OSSL_CMP_MSG) OSSL_CMP_MSGS;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_MSGS)
|
||||
|
||||
/*-
|
||||
* InfoTypeAndValue ::= SEQUENCE {
|
||||
* infoType OBJECT IDENTIFIER,
|
||||
* infoValue ANY DEFINED BY infoType OPTIONAL
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_itav_st {
|
||||
ASN1_OBJECT *infoType;
|
||||
union {
|
||||
char *ptr;
|
||||
/* NID_id_it_caProtEncCert - CA Protocol Encryption Certificate */
|
||||
X509 *caProtEncCert;
|
||||
/* NID_id_it_signKeyPairTypes - Signing Key Pair Types */
|
||||
STACK_OF(X509_ALGOR) *signKeyPairTypes;
|
||||
/* NID_id_it_encKeyPairTypes - Encryption/Key Agreement Key Pair Types */
|
||||
STACK_OF(X509_ALGOR) *encKeyPairTypes;
|
||||
/* NID_id_it_preferredSymmAlg - Preferred Symmetric Algorithm */
|
||||
X509_ALGOR *preferredSymmAlg;
|
||||
/* NID_id_it_caKeyUpdateInfo - Updated CA Key Pair */
|
||||
OSSL_CMP_CAKEYUPDANNCONTENT *caKeyUpdateInfo;
|
||||
/* NID_id_it_currentCRL - CRL */
|
||||
X509_CRL *currentCRL;
|
||||
/* NID_id_it_unsupportedOIDs - Unsupported Object Identifiers */
|
||||
STACK_OF(ASN1_OBJECT) *unsupportedOIDs;
|
||||
/* NID_id_it_keyPairParamReq - Key Pair Parameters Request */
|
||||
ASN1_OBJECT *keyPairParamReq;
|
||||
/* NID_id_it_keyPairParamRep - Key Pair Parameters Response */
|
||||
X509_ALGOR *keyPairParamRep;
|
||||
/* NID_id_it_revPassphrase - Revocation Passphrase */
|
||||
OSSL_CRMF_ENCRYPTEDVALUE *revPassphrase;
|
||||
/* NID_id_it_implicitConfirm - ImplicitConfirm */
|
||||
ASN1_NULL *implicitConfirm;
|
||||
/* NID_id_it_confirmWaitTime - ConfirmWaitTime */
|
||||
ASN1_GENERALIZEDTIME *confirmWaitTime;
|
||||
/* NID_id_it_origPKIMessage - origPKIMessage */
|
||||
OSSL_CMP_MSGS *origPKIMessage;
|
||||
/* NID_id_it_suppLangTags - Supported Language Tags */
|
||||
STACK_OF(ASN1_UTF8STRING) *suppLangTagsValue;
|
||||
/* this is to be used for so far undeclared objects */
|
||||
ASN1_TYPE *other;
|
||||
} infoValue;
|
||||
} /* OSSL_CMP_ITAV */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
|
||||
DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV)
|
||||
|
||||
|
||||
typedef struct OSSL_cmp_certorenccert_st {
|
||||
int type;
|
||||
union {
|
||||
X509 *certificate;
|
||||
OSSL_CRMF_ENCRYPTEDVALUE *encryptedCert;
|
||||
} value;
|
||||
} OSSL_CMP_CERTORENCCERT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
|
||||
|
||||
/*-
|
||||
* CertifiedKeyPair ::= SEQUENCE {
|
||||
* certOrEncCert CertOrEncCert,
|
||||
* privateKey [0] EncryptedValue OPTIONAL,
|
||||
* -- see [CRMF] for comment on encoding
|
||||
* publicationInfo [1] PKIPublicationInfo OPTIONAL
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_certifiedkeypair_st {
|
||||
OSSL_CMP_CERTORENCCERT *certOrEncCert;
|
||||
OSSL_CRMF_ENCRYPTEDVALUE *privateKey;
|
||||
OSSL_CRMF_PKIPUBLICATIONINFO *publicationInfo;
|
||||
} OSSL_CMP_CERTIFIEDKEYPAIR;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
|
||||
|
||||
/*-
|
||||
* PKIStatusInfo ::= SEQUENCE {
|
||||
* status PKIStatus,
|
||||
* statusString PKIFreeText OPTIONAL,
|
||||
* failInfo PKIFailureInfo OPTIONAL
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_pkisi_st {
|
||||
OSSL_CMP_PKISTATUS *status;
|
||||
OSSL_CMP_PKIFREETEXT *statusString;
|
||||
OSSL_CMP_PKIFAILUREINFO *failInfo;
|
||||
} /* OSSL_CMP_PKISI */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
|
||||
DECLARE_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
|
||||
|
||||
/*-
|
||||
* RevReqContent ::= SEQUENCE OF RevDetails
|
||||
*
|
||||
* RevDetails ::= SEQUENCE {
|
||||
* certDetails CertTemplate,
|
||||
* crlEntryDetails Extensions OPTIONAL
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_revdetails_st {
|
||||
OSSL_CRMF_CERTTEMPLATE *certDetails;
|
||||
X509_EXTENSIONS *crlEntryDetails;
|
||||
} OSSL_CMP_REVDETAILS;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
|
||||
DEFINE_STACK_OF(OSSL_CMP_REVDETAILS)
|
||||
|
||||
/*-
|
||||
* RevRepContent ::= SEQUENCE {
|
||||
* status SEQUENCE SIZE (1..MAX) OF PKIStatusInfo,
|
||||
* -- in same order as was sent in RevReqContent
|
||||
* revCerts [0] SEQUENCE SIZE (1..MAX) OF CertId
|
||||
* OPTIONAL,
|
||||
* -- IDs for which revocation was requested
|
||||
* -- (same order as status)
|
||||
* crls [1] SEQUENCE SIZE (1..MAX) OF CertificateList
|
||||
* OPTIONAL
|
||||
* -- the resulting CRLs (there may be more than one)
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_revrepcontent_st {
|
||||
STACK_OF(OSSL_CMP_PKISI) *status;
|
||||
STACK_OF(OSSL_CRMF_CERTID) *revCerts;
|
||||
STACK_OF(X509_CRL) *crls;
|
||||
} /* OSSL_CMP_REVREPCONTENT */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
|
||||
|
||||
/*-
|
||||
* KeyRecRepContent ::= SEQUENCE {
|
||||
* status PKIStatusInfo,
|
||||
* newSigCert [0] Certificate OPTIONAL,
|
||||
* caCerts [1] SEQUENCE SIZE (1..MAX) OF
|
||||
* Certificate OPTIONAL,
|
||||
* keyPairHist [2] SEQUENCE SIZE (1..MAX) OF
|
||||
* CertifiedKeyPair OPTIONAL
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_keyrecrepcontent_st {
|
||||
OSSL_CMP_PKISI *status;
|
||||
X509 *newSigCert;
|
||||
STACK_OF(X509) *caCerts;
|
||||
STACK_OF(OSSL_CMP_CERTIFIEDKEYPAIR) *keyPairHist;
|
||||
} OSSL_CMP_KEYRECREPCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
|
||||
|
||||
/*-
|
||||
* ErrorMsgContent ::= SEQUENCE {
|
||||
* pKIStatusInfo PKIStatusInfo,
|
||||
* errorCode INTEGER OPTIONAL,
|
||||
* -- implementation-specific error codes
|
||||
* errorDetails PKIFreeText OPTIONAL
|
||||
* -- implementation-specific error details
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_errormsgcontent_st {
|
||||
OSSL_CMP_PKISI *pKIStatusInfo;
|
||||
ASN1_INTEGER *errorCode;
|
||||
OSSL_CMP_PKIFREETEXT *errorDetails;
|
||||
} OSSL_CMP_ERRORMSGCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT)
|
||||
|
||||
/*-
|
||||
* CertConfirmContent ::= SEQUENCE OF CertStatus
|
||||
*
|
||||
* CertStatus ::= SEQUENCE {
|
||||
* certHash OCTET STRING,
|
||||
* -- the hash of the certificate, using the same hash algorithm
|
||||
* -- as is used to create and verify the certificate signature
|
||||
* certReqId INTEGER,
|
||||
* -- to match this confirmation with the corresponding req/rep
|
||||
* statusInfo PKIStatusInfo OPTIONAL
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_certstatus_st {
|
||||
ASN1_OCTET_STRING *certHash;
|
||||
ASN1_INTEGER *certReqId;
|
||||
OSSL_CMP_PKISI *statusInfo;
|
||||
} /* OSSL_CMP_CERTSTATUS */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
|
||||
|
||||
typedef STACK_OF(OSSL_CMP_CERTSTATUS) OSSL_CMP_CERTCONFIRMCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTCONFIRMCONTENT)
|
||||
|
||||
/*-
|
||||
* CertResponse ::= SEQUENCE {
|
||||
* certReqId INTEGER,
|
||||
* -- to match this response with corresponding request (a value
|
||||
* -- of -1 is to be used if certReqId is not specified in the
|
||||
* -- corresponding request)
|
||||
* status PKIStatusInfo,
|
||||
* certifiedKeyPair CertifiedKeyPair OPTIONAL,
|
||||
* rspInfo OCTET STRING OPTIONAL
|
||||
* -- analogous to the id-regInfo-utf8Pairs string defined
|
||||
* -- for regInfo in CertReqMsg [CRMF]
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_certresponse_st {
|
||||
ASN1_INTEGER *certReqId;
|
||||
OSSL_CMP_PKISI *status;
|
||||
OSSL_CMP_CERTIFIEDKEYPAIR *certifiedKeyPair;
|
||||
ASN1_OCTET_STRING *rspInfo;
|
||||
} /* OSSL_CMP_CERTRESPONSE */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
|
||||
|
||||
/*-
|
||||
* CertRepMessage ::= SEQUENCE {
|
||||
* caPubs [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
|
||||
* OPTIONAL,
|
||||
* response SEQUENCE OF CertResponse
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_certrepmessage_st {
|
||||
STACK_OF(X509) *caPubs;
|
||||
STACK_OF(OSSL_CMP_CERTRESPONSE) *response;
|
||||
} /* OSSL_CMP_CERTREPMESSAGE */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
|
||||
|
||||
/*-
|
||||
* PollReqContent ::= SEQUENCE OF SEQUENCE {
|
||||
* certReqId INTEGER
|
||||
* }
|
||||
*/
|
||||
typedef struct OSSL_cmp_pollreq_st {
|
||||
ASN1_INTEGER *certReqId;
|
||||
} OSSL_CMP_POLLREQ;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
|
||||
DEFINE_STACK_OF(OSSL_CMP_POLLREQ)
|
||||
typedef STACK_OF(OSSL_CMP_POLLREQ) OSSL_CMP_POLLREQCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREQCONTENT)
|
||||
|
||||
/*-
|
||||
* PollRepContent ::= SEQUENCE OF SEQUENCE {
|
||||
* certReqId INTEGER,
|
||||
* checkAfter INTEGER, -- time in seconds
|
||||
* reason PKIFreeText OPTIONAL
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_pollrep_st {
|
||||
ASN1_INTEGER *certReqId;
|
||||
ASN1_INTEGER *checkAfter;
|
||||
OSSL_CMP_PKIFREETEXT *reason;
|
||||
} /* OSSL_CMP_POLLREP */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
|
||||
DEFINE_STACK_OF(OSSL_CMP_POLLREP)
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POLLREPCONTENT)
|
||||
|
||||
/*-
|
||||
* PKIHeader ::= SEQUENCE {
|
||||
* pvno INTEGER { cmp1999(1), cmp2000(2) },
|
||||
* sender GeneralName,
|
||||
* -- identifies the sender
|
||||
* recipient GeneralName,
|
||||
* -- identifies the intended recipient
|
||||
* messageTime [0] GeneralizedTime OPTIONAL,
|
||||
* -- time of production of this message (used when sender
|
||||
* -- believes that the transport will be "suitable"; i.e.,
|
||||
* -- that the time will still be meaningful upon receipt)
|
||||
* protectionAlg [1] AlgorithmIdentifier OPTIONAL,
|
||||
* -- algorithm used for calculation of protection bits
|
||||
* senderKID [2] KeyIdentifier OPTIONAL,
|
||||
* recipKID [3] KeyIdentifier OPTIONAL,
|
||||
* -- to identify specific keys used for protection
|
||||
* transactionID [4] OCTET STRING OPTIONAL,
|
||||
* -- identifies the transaction; i.e., this will be the same in
|
||||
* -- corresponding request, response, certConf, and PKIConf
|
||||
* -- messages
|
||||
* senderNonce [5] OCTET STRING OPTIONAL,
|
||||
* recipNonce [6] OCTET STRING OPTIONAL,
|
||||
* -- nonces used to provide replay protection, senderNonce
|
||||
* -- is inserted by the creator of this message; recipNonce
|
||||
* -- is a nonce previously inserted in a related message by
|
||||
* -- the intended recipient of this message
|
||||
* freeText [7] PKIFreeText OPTIONAL,
|
||||
* -- this may be used to indicate context-specific instructions
|
||||
* -- (this field is intended for human consumption)
|
||||
* generalInfo [8] SEQUENCE SIZE (1..MAX) OF
|
||||
* InfoTypeAndValue OPTIONAL
|
||||
* -- this may be used to convey context-specific information
|
||||
* -- (this field not primarily intended for human consumption)
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_pkiheader_st {
|
||||
ASN1_INTEGER *pvno;
|
||||
GENERAL_NAME *sender;
|
||||
GENERAL_NAME *recipient;
|
||||
ASN1_GENERALIZEDTIME *messageTime; /* 0 */
|
||||
X509_ALGOR *protectionAlg; /* 1 */
|
||||
ASN1_OCTET_STRING *senderKID; /* 2 */
|
||||
ASN1_OCTET_STRING *recipKID; /* 3 */
|
||||
ASN1_OCTET_STRING *transactionID; /* 4 */
|
||||
ASN1_OCTET_STRING *senderNonce; /* 5 */
|
||||
ASN1_OCTET_STRING *recipNonce; /* 6 */
|
||||
OSSL_CMP_PKIFREETEXT *freeText; /* 7 */
|
||||
STACK_OF(OSSL_CMP_ITAV) *generalInfo; /* 8 */
|
||||
} /* OSSL_CMP_PKIHEADER */;
|
||||
|
||||
typedef STACK_OF(OSSL_CMP_CHALLENGE) OSSL_CMP_POPODECKEYCHALLCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYCHALLCONTENT)
|
||||
typedef STACK_OF(ASN1_INTEGER) OSSL_CMP_POPODECKEYRESPCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_POPODECKEYRESPCONTENT)
|
||||
typedef STACK_OF(OSSL_CMP_REVDETAILS) OSSL_CMP_REVREQCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_REVREQCONTENT)
|
||||
typedef STACK_OF(X509_CRL) OSSL_CMP_CRLANNCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_CRLANNCONTENT)
|
||||
typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENMSGCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENMSGCONTENT)
|
||||
typedef STACK_OF(OSSL_CMP_ITAV) OSSL_CMP_GENREPCONTENT;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_GENREPCONTENT)
|
||||
|
||||
/*-
|
||||
* PKIBody ::= CHOICE { -- message-specific body elements
|
||||
* ir [0] CertReqMessages, --Initialization Request
|
||||
* ip [1] CertRepMessage, --Initialization Response
|
||||
* cr [2] CertReqMessages, --Certification Request
|
||||
* cp [3] CertRepMessage, --Certification Response
|
||||
* p10cr [4] CertificationRequest, --imported from [PKCS10]
|
||||
* popdecc [5] POPODecKeyChallContent, --pop Challenge
|
||||
* popdecr [6] POPODecKeyRespContent, --pop Response
|
||||
* kur [7] CertReqMessages, --Key Update Request
|
||||
* kup [8] CertRepMessage, --Key Update Response
|
||||
* krr [9] CertReqMessages, --Key Recovery Request
|
||||
* krp [10] KeyRecRepContent, --Key Recovery Response
|
||||
* rr [11] RevReqContent, --Revocation Request
|
||||
* rp [12] RevRepContent, --Revocation Response
|
||||
* ccr [13] CertReqMessages, --Cross-Cert. Request
|
||||
* ccp [14] CertRepMessage, --Cross-Cert. Response
|
||||
* ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann.
|
||||
* cann [16] CertAnnContent, --Certificate Ann.
|
||||
* rann [17] RevAnnContent, --Revocation Ann.
|
||||
* crlann [18] CRLAnnContent, --CRL Announcement
|
||||
* pkiconf [19] PKIConfirmContent, --Confirmation
|
||||
* nested [20] NestedMessageContent, --Nested Message
|
||||
* genm [21] GenMsgContent, --General Message
|
||||
* genp [22] GenRepContent, --General Response
|
||||
* error [23] ErrorMsgContent, --Error Message
|
||||
* certConf [24] CertConfirmContent, --Certificate confirm
|
||||
* pollReq [25] PollReqContent, --Polling request
|
||||
* pollRep [26] PollRepContent --Polling response
|
||||
*/
|
||||
typedef struct OSSL_cmp_pkibody_st {
|
||||
int type;
|
||||
union {
|
||||
OSSL_CRMF_MSGS *ir; /* 0 */
|
||||
OSSL_CMP_CERTREPMESSAGE *ip; /* 1 */
|
||||
OSSL_CRMF_MSGS *cr; /* 2 */
|
||||
OSSL_CMP_CERTREPMESSAGE *cp; /* 3 */
|
||||
/* p10cr [4] CertificationRequest, --imported from [PKCS10] */
|
||||
/*
|
||||
* PKCS10_CERTIFICATIONREQUEST is effectively X509_REQ
|
||||
* so it is used directly
|
||||
*/
|
||||
X509_REQ *p10cr; /* 4 */
|
||||
/* popdecc [5] POPODecKeyChallContent, --pop Challenge */
|
||||
/* POPODecKeyChallContent ::= SEQUENCE OF Challenge */
|
||||
OSSL_CMP_POPODECKEYCHALLCONTENT *popdecc; /* 5 */
|
||||
/* popdecr [6] POPODecKeyRespContent, --pop Response */
|
||||
/* POPODecKeyRespContent ::= SEQUENCE OF INTEGER */
|
||||
OSSL_CMP_POPODECKEYRESPCONTENT *popdecr; /* 6 */
|
||||
OSSL_CRMF_MSGS *kur; /* 7 */
|
||||
OSSL_CMP_CERTREPMESSAGE *kup; /* 8 */
|
||||
OSSL_CRMF_MSGS *krr; /* 9 */
|
||||
|
||||
/* krp [10] KeyRecRepContent, --Key Recovery Response */
|
||||
OSSL_CMP_KEYRECREPCONTENT *krp; /* 10 */
|
||||
/* rr [11] RevReqContent, --Revocation Request */
|
||||
OSSL_CMP_REVREQCONTENT *rr; /* 11 */
|
||||
/* rp [12] RevRepContent, --Revocation Response */
|
||||
OSSL_CMP_REVREPCONTENT *rp; /* 12 */
|
||||
/* ccr [13] CertReqMessages, --Cross-Cert. Request */
|
||||
OSSL_CRMF_MSGS *ccr; /* 13 */
|
||||
/* ccp [14] CertRepMessage, --Cross-Cert. Response */
|
||||
OSSL_CMP_CERTREPMESSAGE *ccp; /* 14 */
|
||||
/* ckuann [15] CAKeyUpdAnnContent, --CA Key Update Ann. */
|
||||
OSSL_CMP_CAKEYUPDANNCONTENT *ckuann; /* 15 */
|
||||
/* cann [16] CertAnnContent, --Certificate Ann. */
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
X509 *cann; /* 16 */
|
||||
/* rann [17] RevAnnContent, --Revocation Ann. */
|
||||
OSSL_CMP_REVANNCONTENT *rann; /* 17 */
|
||||
/* crlann [18] CRLAnnContent, --CRL Announcement */
|
||||
/* CRLAnnContent ::= SEQUENCE OF CertificateList */
|
||||
OSSL_CMP_CRLANNCONTENT *crlann;
|
||||
/* PKIConfirmContent ::= NULL */
|
||||
/* pkiconf [19] PKIConfirmContent, --Confirmation */
|
||||
/* OSSL_CMP_PKICONFIRMCONTENT would be only a typedef of ASN1_NULL */
|
||||
/* OSSL_CMP_CONFIRMCONTENT *pkiconf; */
|
||||
/*
|
||||
* NOTE: this should ASN1_NULL according to the RFC
|
||||
* but there might be a struct in it when sent from faulty servers...
|
||||
*/
|
||||
ASN1_TYPE *pkiconf; /* 19 */
|
||||
/* nested [20] NestedMessageContent, --Nested Message */
|
||||
/* NestedMessageContent ::= PKIMessages */
|
||||
OSSL_CMP_MSGS *nested; /* 20 */
|
||||
/* genm [21] GenMsgContent, --General Message */
|
||||
/* GenMsgContent ::= SEQUENCE OF InfoTypeAndValue */
|
||||
OSSL_CMP_GENMSGCONTENT *genm; /* 21 */
|
||||
/* genp [22] GenRepContent, --General Response */
|
||||
/* GenRepContent ::= SEQUENCE OF InfoTypeAndValue */
|
||||
OSSL_CMP_GENREPCONTENT *genp; /* 22 */
|
||||
/* error [23] ErrorMsgContent, --Error Message */
|
||||
OSSL_CMP_ERRORMSGCONTENT *error; /* 23 */
|
||||
/* certConf [24] CertConfirmContent, --Certificate confirm */
|
||||
OSSL_CMP_CERTCONFIRMCONTENT *certConf; /* 24 */
|
||||
/* pollReq [25] PollReqContent, --Polling request */
|
||||
OSSL_CMP_POLLREQCONTENT *pollReq;
|
||||
/* pollRep [26] PollRepContent --Polling response */
|
||||
OSSL_CMP_POLLREPCONTENT *pollRep;
|
||||
} value;
|
||||
} OSSL_CMP_PKIBODY;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
|
||||
|
||||
/*-
|
||||
* PKIProtection ::= BIT STRING
|
||||
*
|
||||
* PKIMessages ::= SEQUENCE SIZE (1..MAX) OF PKIMessage
|
||||
*
|
||||
* PKIMessage ::= SEQUENCE {
|
||||
* header PKIHeader,
|
||||
* body PKIBody,
|
||||
* protection [0] PKIProtection OPTIONAL,
|
||||
* extraCerts [1] SEQUENCE SIZE (1..MAX) OF CMPCertificate
|
||||
* OPTIONAL
|
||||
* }
|
||||
*/
|
||||
struct OSSL_cmp_msg_st {
|
||||
OSSL_CMP_PKIHEADER *header;
|
||||
OSSL_CMP_PKIBODY *body;
|
||||
ASN1_BIT_STRING *protection; /* 0 */
|
||||
/* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
|
||||
STACK_OF(X509) *extraCerts; /* 1 */
|
||||
} /* OSSL_CMP_MSG */;
|
||||
DECLARE_ASN1_FUNCTIONS(OSSL_CMP_MSG)
|
||||
|
||||
/*-
|
||||
* ProtectedPart ::= SEQUENCE {
|
||||
* header PKIHeader,
|
||||
* body PKIBody
|
||||
* }
|
||||
*/
|
||||
typedef struct cmp_protectedpart_st {
|
||||
OSSL_CMP_PKIHEADER *header;
|
||||
OSSL_CMP_PKIBODY *body;
|
||||
} CMP_PROTECTEDPART;
|
||||
DECLARE_ASN1_FUNCTIONS(CMP_PROTECTEDPART)
|
||||
|
||||
/*-
|
||||
* this is not defined here as it is already in CRMF:
|
||||
* id-PasswordBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 13}
|
||||
* PBMParameter ::= SEQUENCE {
|
||||
* salt OCTET STRING,
|
||||
* -- note: implementations MAY wish to limit acceptable sizes
|
||||
* -- of this string to values appropriate for their environment
|
||||
* -- in order to reduce the risk of denial-of-service attacks
|
||||
* owf AlgorithmIdentifier,
|
||||
* -- AlgId for a One-Way Function (SHA-1 recommended)
|
||||
* iterationCount INTEGER,
|
||||
* -- number of times the OWF is applied
|
||||
* -- note: implementations MAY wish to limit acceptable sizes
|
||||
* -- of this integer to values appropriate for their environment
|
||||
* -- in order to reduce the risk of denial-of-service attacks
|
||||
* mac AlgorithmIdentifier
|
||||
* -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
|
||||
* } -- or HMAC [RFC2104, RFC2202])
|
||||
*/
|
||||
/*-
|
||||
* TODO: this is not yet defined here - but DH is anyway not used yet
|
||||
*
|
||||
* id-DHBasedMac OBJECT IDENTIFIER ::= {1 2 840 113533 7 66 30}
|
||||
* DHBMParameter ::= SEQUENCE {
|
||||
* owf AlgorithmIdentifier,
|
||||
* -- AlgId for a One-Way Function (SHA-1 recommended)
|
||||
* mac AlgorithmIdentifier
|
||||
* -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],
|
||||
* } -- or HMAC [RFC2104, RFC2202])
|
||||
*/
|
||||
/*-
|
||||
* The following is not cared for, because it is described in section 5.2.5
|
||||
* that this is beyond the scope of CMP
|
||||
* OOBCert ::= CMPCertificate
|
||||
*
|
||||
* OOBCertHash ::= SEQUENCE {
|
||||
* hashAlg [0] AlgorithmIdentifier OPTIONAL,
|
||||
* certId [1] CertId OPTIONAL,
|
||||
* hashVal BIT STRING
|
||||
* -- hashVal is calculated over the DER encoding of the
|
||||
* -- self-signed certificate with the identifier certID.
|
||||
* }
|
||||
*/
|
||||
|
||||
#endif /* !defined OSSL_HEADER_CMP_INT_H */
|
||||
+133
-1
@@ -13,6 +13,56 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/cms.h>
|
||||
#include "cms_lcl.h"
|
||||
#include "internal/nelem.h"
|
||||
|
||||
/*-
|
||||
* Attribute flags.
|
||||
* CMS attribute restrictions are discussed in
|
||||
* - RFC 5652 Section 11.
|
||||
* ESS attribute restrictions are discussed in
|
||||
* - RFC 2634 Section 1.3.4 AND
|
||||
* - RFC 5035 Section 5.4
|
||||
*/
|
||||
/* This is a signed attribute */
|
||||
#define CMS_ATTR_F_SIGNED 0x01
|
||||
/* This is an unsigned attribute */
|
||||
#define CMS_ATTR_F_UNSIGNED 0x02
|
||||
/* Must be present if there are any other attributes of the same type */
|
||||
#define CMS_ATTR_F_REQUIRED_COND 0x10
|
||||
/* There can only be one instance of this attribute */
|
||||
#define CMS_ATTR_F_ONLY_ONE 0x20
|
||||
/* The Attribute's value must have exactly one entry */
|
||||
#define CMS_ATTR_F_ONE_ATTR_VALUE 0x40
|
||||
|
||||
/* Attributes rules for different attributes */
|
||||
static const struct {
|
||||
int nid; /* The attribute id */
|
||||
int flags;
|
||||
} cms_attribute_properties[] = {
|
||||
/* See RFC Section 11 */
|
||||
{ NID_pkcs9_contentType, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE
|
||||
| CMS_ATTR_F_REQUIRED_COND },
|
||||
{ NID_pkcs9_messageDigest, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE
|
||||
| CMS_ATTR_F_REQUIRED_COND },
|
||||
{ NID_pkcs9_signingTime, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE },
|
||||
{ NID_pkcs9_countersignature, CMS_ATTR_F_UNSIGNED },
|
||||
/* ESS */
|
||||
{ NID_id_smime_aa_signingCertificate, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE },
|
||||
{ NID_id_smime_aa_signingCertificateV2, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE },
|
||||
{ NID_id_smime_aa_receiptRequest, CMS_ATTR_F_SIGNED
|
||||
| CMS_ATTR_F_ONLY_ONE
|
||||
| CMS_ATTR_F_ONE_ATTR_VALUE }
|
||||
};
|
||||
|
||||
/* CMS SignedData Attribute utilities */
|
||||
|
||||
@@ -149,4 +199,86 @@ void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
|
||||
return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
|
||||
}
|
||||
|
||||
/* Specific attribute cases */
|
||||
/*
|
||||
* Retrieve an attribute by nid from a stack of attributes starting at index
|
||||
* *lastpos + 1.
|
||||
* Returns the attribute or NULL if there is no attribute.
|
||||
* If an attribute was found *lastpos returns the index of the found attribute.
|
||||
*/
|
||||
static X509_ATTRIBUTE *cms_attrib_get(int nid,
|
||||
const STACK_OF(X509_ATTRIBUTE) *attrs,
|
||||
int *lastpos)
|
||||
{
|
||||
X509_ATTRIBUTE *at;
|
||||
int loc;
|
||||
|
||||
loc = X509at_get_attr_by_NID(attrs, nid, *lastpos);
|
||||
if (loc < 0)
|
||||
return NULL;
|
||||
|
||||
at = X509at_get_attr(attrs, loc);
|
||||
*lastpos = loc;
|
||||
return at;
|
||||
}
|
||||
|
||||
static int cms_check_attribute(int nid, int flags, int type,
|
||||
const STACK_OF(X509_ATTRIBUTE) *attrs,
|
||||
int have_attrs)
|
||||
{
|
||||
int lastpos = -1;
|
||||
X509_ATTRIBUTE *at = cms_attrib_get(nid, attrs, &lastpos);
|
||||
|
||||
if (at != NULL) {
|
||||
int count = X509_ATTRIBUTE_count(at);
|
||||
|
||||
/* Is this attribute allowed? */
|
||||
if (((flags & type) == 0)
|
||||
/* check if multiple attributes of the same type are allowed */
|
||||
|| (((flags & CMS_ATTR_F_ONLY_ONE) != 0)
|
||||
&& cms_attrib_get(nid, attrs, &lastpos) != NULL)
|
||||
/* Check if attribute should have exactly one value in its set */
|
||||
|| (((flags & CMS_ATTR_F_ONE_ATTR_VALUE) != 0)
|
||||
&& count != 1)
|
||||
/* There should be at least one value */
|
||||
|| count == 0)
|
||||
return 0;
|
||||
} else {
|
||||
/* fail if a required attribute is missing */
|
||||
if (have_attrs
|
||||
&& ((flags & CMS_ATTR_F_REQUIRED_COND) != 0)
|
||||
&& (flags & type) != 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the signerinfo attributes obey the attribute rules which includes
|
||||
* the following checks
|
||||
* - If any signed attributes exist then there must be a Content Type
|
||||
* and Message Digest attribute in the signed attributes.
|
||||
* - The countersignature attribute is an optional unsigned attribute only.
|
||||
* - Content Type, Message Digest, and Signing time attributes are signed
|
||||
* attributes. Only one instance of each is allowed, with each of these
|
||||
* attributes containing a single attribute value in its set.
|
||||
*/
|
||||
int CMS_si_check_attributes(const CMS_SignerInfo *si)
|
||||
{
|
||||
int i;
|
||||
int have_signed_attrs = (CMS_signed_get_attr_count(si) > 0);
|
||||
int have_unsigned_attrs = (CMS_unsigned_get_attr_count(si) > 0);
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(cms_attribute_properties); ++i) {
|
||||
int nid = cms_attribute_properties[i].nid;
|
||||
int flags = cms_attribute_properties[i].flags;
|
||||
|
||||
if (!cms_check_attribute(nid, flags, CMS_ATTR_F_SIGNED,
|
||||
si->signedAttrs, have_signed_attrs)
|
||||
|| !cms_check_attribute(nid, flags, CMS_ATTR_F_UNSIGNED,
|
||||
si->unsignedAttrs, have_unsigned_attrs)) {
|
||||
CMSerr(CMS_F_CMS_SI_CHECK_ATTRIBUTES, CMS_R_ATTRIBUTE_ERROR);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -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
|
||||
@@ -150,6 +150,8 @@ static const ERR_STRING_DATA CMS_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT, 0),
|
||||
"CMS_SignerInfo_verify_content"},
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_SIGN_RECEIPT, 0), "CMS_sign_receipt"},
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_SI_CHECK_ATTRIBUTES, 0),
|
||||
"CMS_si_check_attributes"},
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_STREAM, 0), "CMS_stream"},
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_UNCOMPRESS, 0), "CMS_uncompress"},
|
||||
{ERR_PACK(ERR_LIB_CMS, CMS_F_CMS_VERIFY, 0), "CMS_verify"},
|
||||
@@ -159,6 +161,7 @@ static const ERR_STRING_DATA CMS_str_functs[] = {
|
||||
|
||||
static const ERR_STRING_DATA CMS_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ADD_SIGNER_ERROR), "add signer error"},
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ATTRIBUTE_ERROR), "attribute error"},
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_ALREADY_PRESENT),
|
||||
"certificate already present"},
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_HAS_NO_KEYID),
|
||||
|
||||
@@ -416,6 +416,8 @@ int cms_RecipientInfo_kari_encrypt(const CMS_ContentInfo *cms,
|
||||
/* PWRI routines */
|
||||
int cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
|
||||
int en_de);
|
||||
/* SignerInfo routines */
|
||||
int CMS_si_check_attributes(const CMS_SignerInfo *si);
|
||||
|
||||
DECLARE_ASN1_ITEM(CMS_CertificateChoices)
|
||||
DECLARE_ASN1_ITEM(CMS_DigestedData)
|
||||
|
||||
+39
-14
@@ -109,6 +109,27 @@ static void cms_sd_set_version(CMS_SignedData *sd)
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* RFC 5652 Section 11.1 Content Type
|
||||
* The content-type attribute within signed-data MUST
|
||||
* 1) be present if there are signed attributes
|
||||
* 2) match the content type in the signed-data,
|
||||
* 3) be a signed attribute.
|
||||
* 4) not have more than one copy of the attribute.
|
||||
*
|
||||
* Note that since the CMS_SignerInfo_sign() always adds the "signing time"
|
||||
* attribute, the content type attribute MUST be added also.
|
||||
* Assumptions: This assumes that the attribute does not already exist.
|
||||
*/
|
||||
static int cms_set_si_contentType_attr(CMS_ContentInfo *cms, CMS_SignerInfo *si)
|
||||
{
|
||||
ASN1_OBJECT *ctype = cms->d.signedData->encapContentInfo->eContentType;
|
||||
|
||||
/* Add the contentType attribute */
|
||||
return CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType,
|
||||
V_ASN1_OBJECT, ctype, -1) > 0;
|
||||
}
|
||||
|
||||
/* Copy an existing messageDigest value */
|
||||
|
||||
static int cms_copy_messageDigest(CMS_ContentInfo *cms, CMS_SignerInfo *si)
|
||||
@@ -325,13 +346,6 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
||||
if (!i)
|
||||
goto merr;
|
||||
}
|
||||
if (flags & CMS_REUSE_DIGEST) {
|
||||
if (!cms_copy_messageDigest(cms, si))
|
||||
goto err;
|
||||
if (!(flags & (CMS_PARTIAL | CMS_KEY_PARAM)) &&
|
||||
!CMS_SignerInfo_sign(si))
|
||||
goto err;
|
||||
}
|
||||
if (flags & CMS_CADES) {
|
||||
ESS_SIGNING_CERT *sc = NULL;
|
||||
ESS_SIGNING_CERT_V2 *sc2 = NULL;
|
||||
@@ -353,6 +367,15 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
||||
if (!add_sc)
|
||||
goto err;
|
||||
}
|
||||
if (flags & CMS_REUSE_DIGEST) {
|
||||
if (!cms_copy_messageDigest(cms, si))
|
||||
goto err;
|
||||
if (!cms_set_si_contentType_attr(cms, si))
|
||||
goto err;
|
||||
if (!(flags & (CMS_PARTIAL | CMS_KEY_PARAM)) &&
|
||||
!CMS_SignerInfo_sign(si))
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & CMS_NOCERTS)) {
|
||||
@@ -370,8 +393,7 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
|
||||
goto err;
|
||||
if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0)
|
||||
goto err;
|
||||
} else if (EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, pk) <=
|
||||
0)
|
||||
} else if (EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, pk) <= 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -579,8 +601,6 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
|
||||
*/
|
||||
|
||||
if (CMS_signed_get_attr_count(si) >= 0) {
|
||||
ASN1_OBJECT *ctype =
|
||||
cms->d.signedData->encapContentInfo->eContentType;
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int mdlen;
|
||||
if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
|
||||
@@ -589,9 +609,9 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
|
||||
V_ASN1_OCTET_STRING, md, mdlen))
|
||||
goto err;
|
||||
/* Copy content type across */
|
||||
if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType,
|
||||
V_ASN1_OBJECT, ctype, -1) <= 0)
|
||||
if (!cms_set_si_contentType_attr(cms, si))
|
||||
goto err;
|
||||
|
||||
if (!CMS_SignerInfo_sign(si))
|
||||
goto err;
|
||||
} else if (si->pctx) {
|
||||
@@ -671,6 +691,9 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!CMS_si_check_attributes(si))
|
||||
goto err;
|
||||
|
||||
if (si->pctx)
|
||||
pctx = si->pctx;
|
||||
else {
|
||||
@@ -717,7 +740,6 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
|
||||
OPENSSL_free(abuf);
|
||||
EVP_MD_CTX_reset(mctx);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
|
||||
@@ -732,6 +754,9 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!CMS_si_check_attributes(si))
|
||||
return -1;
|
||||
|
||||
md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
|
||||
if (md == NULL)
|
||||
return -1;
|
||||
|
||||
@@ -42,7 +42,7 @@ void OPENSSL_config(const char *appname)
|
||||
|
||||
int openssl_config_int(const OPENSSL_INIT_SETTINGS *settings)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
const char *filename;
|
||||
const char *appname;
|
||||
unsigned long flags;
|
||||
|
||||
+19
-34
@@ -7,7 +7,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/cryptlib_int.h"
|
||||
#include "internal/thread_once.h"
|
||||
|
||||
struct openssl_ctx_onfree_list_st {
|
||||
@@ -80,6 +80,8 @@ static int context_deinit(OPENSSL_CTX *ctx)
|
||||
if (ctx == NULL)
|
||||
return 1;
|
||||
|
||||
ossl_ctx_thread_stop(ctx);
|
||||
|
||||
onfree = ctx->onfreelist;
|
||||
while (onfree != NULL) {
|
||||
onfree->fn(ctx);
|
||||
@@ -129,6 +131,18 @@ void OPENSSL_CTX_free(OPENSSL_CTX *ctx)
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)
|
||||
{
|
||||
#ifndef FIPS_MODE
|
||||
if (ctx == NULL) {
|
||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||
return 0;
|
||||
return default_context;
|
||||
}
|
||||
#endif
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,
|
||||
CRYPTO_EX_DATA *ad, int index,
|
||||
long argl_ign, void *argp)
|
||||
@@ -154,13 +168,7 @@ static int openssl_ctx_init_index(OPENSSL_CTX *ctx, int static_index,
|
||||
{
|
||||
int idx;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (ctx == NULL) {
|
||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||
return 0;
|
||||
ctx = default_context;
|
||||
}
|
||||
#endif
|
||||
ctx = openssl_ctx_get_concrete(ctx);
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
@@ -180,13 +188,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
|
||||
{
|
||||
void *data = NULL;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (ctx == NULL) {
|
||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||
return NULL;
|
||||
ctx = default_context;
|
||||
}
|
||||
#endif
|
||||
ctx = openssl_ctx_get_concrete(ctx);
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -210,18 +212,7 @@ void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
|
||||
|
||||
OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)
|
||||
{
|
||||
/*
|
||||
* The default context code is not needed in FIPS_MODE and ctx should never
|
||||
* be NULL in the FIPS provider. However we compile this code out to ensure
|
||||
* we fail immediately if ctx == NULL in FIPS_MODE
|
||||
*/
|
||||
#ifndef FIPS_MODE
|
||||
if (ctx == NULL) {
|
||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||
return NULL;
|
||||
ctx = default_context;
|
||||
}
|
||||
#endif
|
||||
ctx = openssl_ctx_get_concrete(ctx);
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
return &ctx->global;
|
||||
@@ -232,13 +223,7 @@ int openssl_ctx_run_once(OPENSSL_CTX *ctx, unsigned int idx,
|
||||
{
|
||||
int done = 0, ret = 0;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (ctx == NULL) {
|
||||
if (!RUN_ONCE(&default_context_init, do_default_context_init))
|
||||
return 0;
|
||||
ctx = default_context;
|
||||
}
|
||||
#endif
|
||||
ctx = openssl_ctx_get_concrete(ctx);
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
|
||||
+9
-4
@@ -31,6 +31,9 @@ static int ossl_method_construct_this(OSSL_PROVIDER *provider, void *cbdata)
|
||||
const OSSL_ALGORITHM *map =
|
||||
ossl_provider_query_operation(provider, data->operation_id, &no_store);
|
||||
|
||||
if (map == NULL)
|
||||
return 0;
|
||||
|
||||
while (map->algorithm_name != NULL) {
|
||||
const OSSL_ALGORITHM *thismap = map++;
|
||||
void *method = NULL;
|
||||
@@ -56,12 +59,12 @@ static int ossl_method_construct_this(OSSL_PROVIDER *provider, void *cbdata)
|
||||
* If we haven't been told not to store,
|
||||
* add to the global store
|
||||
*/
|
||||
data->mcm->put(data->libctx, NULL, method,
|
||||
data->mcm->put(data->libctx, NULL, method, data->operation_id,
|
||||
thismap->algorithm_name,
|
||||
thismap->property_definition, data->mcm_data);
|
||||
}
|
||||
|
||||
data->mcm->put(data->libctx, data->store, method,
|
||||
data->mcm->put(data->libctx, data->store, method, data->operation_id,
|
||||
thismap->algorithm_name, thismap->property_definition,
|
||||
data->mcm_data);
|
||||
|
||||
@@ -80,7 +83,8 @@ void *ossl_method_construct(OPENSSL_CTX *libctx, int operation_id,
|
||||
void *method = NULL;
|
||||
|
||||
if ((method =
|
||||
mcm->get(libctx, NULL, name, propquery, mcm_data)) == NULL) {
|
||||
mcm->get(libctx, NULL, operation_id, name, propquery, mcm_data))
|
||||
== NULL) {
|
||||
struct construct_data_st cbdata;
|
||||
|
||||
/*
|
||||
@@ -98,7 +102,8 @@ void *ossl_method_construct(OPENSSL_CTX *libctx, int operation_id,
|
||||
ossl_provider_forall_loaded(libctx, ossl_method_construct_this,
|
||||
&cbdata);
|
||||
|
||||
method = mcm->get(libctx, cbdata.store, name, propquery, mcm_data);
|
||||
method = mcm->get(libctx, cbdata.store, operation_id, name,
|
||||
propquery, mcm_data);
|
||||
mcm->dealloc_tmp_store(cbdata.store);
|
||||
}
|
||||
|
||||
|
||||
+99
-96
@@ -7,45 +7,52 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "e_os.h" /* strcasecmp */
|
||||
#include "internal/namemap.h"
|
||||
#include <openssl/lhash.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include "internal/lhash.h" /* openssl_lh_strcasehash */
|
||||
|
||||
/* The namemap entry */
|
||||
/*-
|
||||
* The namenum entry
|
||||
* =================
|
||||
*/
|
||||
typedef struct {
|
||||
char *name;
|
||||
int number;
|
||||
const char *name;
|
||||
char body[1]; /* Sized appropriately to contain the name */
|
||||
} NAMEMAP_ENTRY;
|
||||
} NAMENUM_ENTRY;
|
||||
|
||||
DEFINE_LHASH_OF(NAMEMAP_ENTRY);
|
||||
DEFINE_STACK_OF(NAMEMAP_ENTRY)
|
||||
DEFINE_LHASH_OF(NAMENUM_ENTRY);
|
||||
|
||||
/* The namemap, which provides for bidirectional indexing */
|
||||
/*-
|
||||
* The namemap itself
|
||||
* ==================
|
||||
*/
|
||||
|
||||
struct ossl_namemap_st {
|
||||
/* Flags */
|
||||
unsigned int stored:1; /* If 1, it's stored in a library context */
|
||||
|
||||
CRYPTO_RWLOCK *lock;
|
||||
LHASH_OF(NAMEMAP_ENTRY) *namenum; /* Name->number mapping */
|
||||
STACK_OF(NAMEMAP_ENTRY) *numname; /* Number->name mapping */
|
||||
LHASH_OF(NAMENUM_ENTRY) *namenum; /* Name->number mapping */
|
||||
int max_number; /* Current max number */
|
||||
};
|
||||
|
||||
/* LHASH callbacks */
|
||||
|
||||
static unsigned long namemap_hash(const NAMEMAP_ENTRY *n)
|
||||
static unsigned long namenum_hash(const NAMENUM_ENTRY *n)
|
||||
{
|
||||
return OPENSSL_LH_strhash(n->name);
|
||||
return openssl_lh_strcasehash(n->name);
|
||||
}
|
||||
|
||||
static int namemap_cmp(const NAMEMAP_ENTRY *a, const NAMEMAP_ENTRY *b)
|
||||
static int namenum_cmp(const NAMENUM_ENTRY *a, const NAMENUM_ENTRY *b)
|
||||
{
|
||||
return strcmp(a->name, b->name);
|
||||
return strcasecmp(a->name, b->name);
|
||||
}
|
||||
|
||||
static void namemap_free(NAMEMAP_ENTRY *n)
|
||||
static void namenum_free(NAMENUM_ENTRY *n)
|
||||
{
|
||||
if (n != NULL)
|
||||
OPENSSL_free(n->name);
|
||||
OPENSSL_free(n);
|
||||
}
|
||||
|
||||
@@ -75,7 +82,10 @@ static const OPENSSL_CTX_METHOD stored_namemap_method = {
|
||||
stored_namemap_free,
|
||||
};
|
||||
|
||||
/* API functions */
|
||||
/*-
|
||||
* API functions
|
||||
* =============
|
||||
*/
|
||||
|
||||
OSSL_NAMEMAP *ossl_namemap_stored(OPENSSL_CTX *libctx)
|
||||
{
|
||||
@@ -89,11 +99,9 @@ OSSL_NAMEMAP *ossl_namemap_new(void)
|
||||
|
||||
if ((namemap = OPENSSL_zalloc(sizeof(*namemap))) != NULL
|
||||
&& (namemap->lock = CRYPTO_THREAD_lock_new()) != NULL
|
||||
&& (namemap->numname = sk_NAMEMAP_ENTRY_new_null()) != NULL
|
||||
&& (namemap->namenum =
|
||||
lh_NAMEMAP_ENTRY_new(namemap_hash, namemap_cmp)) != NULL) {
|
||||
lh_NAMENUM_ENTRY_new(namenum_hash, namenum_cmp)) != NULL)
|
||||
return namemap;
|
||||
}
|
||||
|
||||
ossl_namemap_free(namemap);
|
||||
return NULL;
|
||||
@@ -104,69 +112,71 @@ void ossl_namemap_free(OSSL_NAMEMAP *namemap)
|
||||
if (namemap == NULL || namemap->stored)
|
||||
return;
|
||||
|
||||
/* The elements will be freed by sk_NAMEMAP_ENTRY_pop_free() */
|
||||
lh_NAMEMAP_ENTRY_free(namemap->namenum);
|
||||
|
||||
sk_NAMEMAP_ENTRY_pop_free(namemap->numname, namemap_free);
|
||||
lh_NAMENUM_ENTRY_doall(namemap->namenum, namenum_free);
|
||||
lh_NAMENUM_ENTRY_free(namemap->namenum);
|
||||
|
||||
CRYPTO_THREAD_lock_free(namemap->lock);
|
||||
OPENSSL_free(namemap);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO(3.0) It isn't currently possible to have a default namemap in the
|
||||
* FIPS module because if init and cleanup constraints, so we currently
|
||||
* disable the code that would allow it when FIPS_MODE is defined.
|
||||
*/
|
||||
|
||||
const char *ossl_namemap_name(const OSSL_NAMEMAP *namemap, int number)
|
||||
{
|
||||
NAMEMAP_ENTRY *entry;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (namemap == NULL)
|
||||
namemap = ossl_namemap_stored(NULL);
|
||||
#endif
|
||||
|
||||
if (namemap == NULL || number == 0)
|
||||
return NULL;
|
||||
|
||||
CRYPTO_THREAD_read_lock(namemap->lock);
|
||||
entry = sk_NAMEMAP_ENTRY_value(namemap->numname, number);
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
|
||||
if (entry != NULL)
|
||||
return entry->name;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ossl_namemap_number(const OSSL_NAMEMAP *namemap, const char *name)
|
||||
{
|
||||
NAMEMAP_ENTRY *entry, template;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (namemap == NULL)
|
||||
namemap = ossl_namemap_stored(NULL);
|
||||
#endif
|
||||
|
||||
if (namemap == NULL)
|
||||
return 0;
|
||||
|
||||
template.name = name;
|
||||
CRYPTO_THREAD_read_lock(namemap->lock);
|
||||
entry = lh_NAMEMAP_ENTRY_retrieve(namemap->namenum, &template);
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
|
||||
if (entry == NULL)
|
||||
return 0;
|
||||
|
||||
return entry->number;
|
||||
}
|
||||
|
||||
int ossl_namemap_add(OSSL_NAMEMAP *namemap, const char *name)
|
||||
{
|
||||
NAMEMAP_ENTRY *entry;
|
||||
typedef struct doall_names_data_st {
|
||||
int number;
|
||||
void (*fn)(const char *name, void *data);
|
||||
void *data;
|
||||
} DOALL_NAMES_DATA;
|
||||
|
||||
static void do_name(const NAMENUM_ENTRY *namenum, DOALL_NAMES_DATA *data)
|
||||
{
|
||||
if (namenum->number == data->number)
|
||||
data->fn(namenum->name, data->data);
|
||||
}
|
||||
|
||||
IMPLEMENT_LHASH_DOALL_ARG_CONST(NAMENUM_ENTRY, DOALL_NAMES_DATA);
|
||||
|
||||
void ossl_namemap_doall_names(const OSSL_NAMEMAP *namemap, int number,
|
||||
void (*fn)(const char *name, void *data),
|
||||
void *data)
|
||||
{
|
||||
DOALL_NAMES_DATA cbdata;
|
||||
|
||||
cbdata.number = number;
|
||||
cbdata.fn = fn;
|
||||
cbdata.data = data;
|
||||
CRYPTO_THREAD_read_lock(namemap->lock);
|
||||
lh_NAMENUM_ENTRY_doall_DOALL_NAMES_DATA(namemap->namenum, do_name,
|
||||
&cbdata);
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
}
|
||||
|
||||
int ossl_namemap_name2num(const OSSL_NAMEMAP *namemap, const char *name)
|
||||
{
|
||||
NAMENUM_ENTRY *namenum_entry, namenum_tmpl;
|
||||
int number = 0;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (namemap == NULL)
|
||||
namemap = ossl_namemap_stored(NULL);
|
||||
#endif
|
||||
|
||||
if (namemap == NULL)
|
||||
return 0;
|
||||
|
||||
namenum_tmpl.name = (char *)name;
|
||||
namenum_tmpl.number = 0;
|
||||
CRYPTO_THREAD_read_lock(namemap->lock);
|
||||
namenum_entry =
|
||||
lh_NAMENUM_ENTRY_retrieve(namemap->namenum, &namenum_tmpl);
|
||||
if (namenum_entry != NULL)
|
||||
number = namenum_entry->number;
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
|
||||
return number;
|
||||
}
|
||||
|
||||
int ossl_namemap_add(OSSL_NAMEMAP *namemap, int number, const char *name)
|
||||
{
|
||||
NAMENUM_ENTRY *namenum = NULL;
|
||||
int tmp_number;
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
if (namemap == NULL)
|
||||
@@ -176,36 +186,29 @@ int ossl_namemap_add(OSSL_NAMEMAP *namemap, const char *name)
|
||||
if (name == NULL || namemap == NULL)
|
||||
return 0;
|
||||
|
||||
if ((number = ossl_namemap_number(namemap, name)) != 0)
|
||||
return number; /* Pretend success */
|
||||
|
||||
if ((entry = OPENSSL_zalloc(sizeof(*entry) + strlen(name))) == NULL)
|
||||
goto err;
|
||||
|
||||
strcpy(entry->body, name);
|
||||
entry->name = entry->body;
|
||||
if ((tmp_number = ossl_namemap_name2num(namemap, name)) != 0)
|
||||
return tmp_number; /* Pretend success */
|
||||
|
||||
CRYPTO_THREAD_write_lock(namemap->lock);
|
||||
|
||||
entry->number = sk_NAMEMAP_ENTRY_push(namemap->numname, entry);
|
||||
|
||||
if (entry->number == 0)
|
||||
if ((namenum = OPENSSL_zalloc(sizeof(*namenum))) == NULL
|
||||
|| (namenum->name = OPENSSL_strdup(name)) == NULL)
|
||||
goto err;
|
||||
|
||||
(void)lh_NAMEMAP_ENTRY_insert(namemap->namenum, entry);
|
||||
if (lh_NAMEMAP_ENTRY_error(namemap->namenum))
|
||||
namenum->number = tmp_number =
|
||||
number != 0 ? number : ++namemap->max_number;
|
||||
(void)lh_NAMENUM_ENTRY_insert(namemap->namenum, namenum);
|
||||
|
||||
if (lh_NAMENUM_ENTRY_error(namemap->namenum))
|
||||
goto err;
|
||||
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
|
||||
return entry->number;
|
||||
return tmp_number;
|
||||
|
||||
err:
|
||||
if (entry != NULL) {
|
||||
if (entry->number != 0)
|
||||
(void)sk_NAMEMAP_ENTRY_pop(namemap->numname);
|
||||
lh_NAMEMAP_ENTRY_delete(namemap->namenum, entry);
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
}
|
||||
namenum_free(namenum);
|
||||
|
||||
CRYPTO_THREAD_unlock(namemap->lock);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2018
|
||||
* Copyright Siemens AG 2015-2018
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2018
|
||||
* Copyright Siemens AG 2015-2018
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2018
|
||||
* Copyright Siemens AG 2015-2018
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-
|
||||
* Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2018
|
||||
* Copyright Siemens AG 2015-2018
|
||||
* Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright Nokia 2007-2019
|
||||
* Copyright Siemens AG 2015-2019
|
||||
*
|
||||
* 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
|
||||
|
||||
+15
-1
@@ -1,10 +1,24 @@
|
||||
$DESASM=des_enc.c fcrypt_b.c
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$DESASM_x86=des-586.s crypt586.s
|
||||
$DESASM_ia64=ghash-ia64.s
|
||||
$DESASM_sparcv9=des_enc-sparc.S fcrypt_b.c dest4-sparcv9.S
|
||||
$DESASM_sparcv8=des_enc-sparc.S fcrypt_b.c
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one
|
||||
IF[$DESASM_{- $target{asm_arch} -}]
|
||||
$DESASM=$DESASM_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
set_key.c ecb_enc.c cbc_enc.c \
|
||||
ecb3_enc.c cfb64enc.c cfb64ede.c cfb_enc.c \
|
||||
ofb64ede.c ofb64enc.c ofb_enc.c \
|
||||
str2key.c pcbc_enc.c qud_cksm.c rand_key.c \
|
||||
{- $target{des_asm_src} -} \
|
||||
$DESASM \
|
||||
fcrypt.c xcbc_enc.c cbc_cksm.c
|
||||
|
||||
GENERATE[des_enc-sparc.S]=asm/des_enc.m4
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include "des_locl.h"
|
||||
|
||||
/* defaults to false */
|
||||
OPENSSL_IMPLEMENT_GLOBAL(int, DES_check_key, 0)
|
||||
|
||||
static const unsigned char odd_parity[256] = {
|
||||
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
|
||||
16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
|
||||
@@ -277,12 +274,7 @@ static const DES_LONG des_skb[8][64] = {
|
||||
|
||||
int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
|
||||
{
|
||||
if (DES_check_key) {
|
||||
return DES_set_key_checked(key, schedule);
|
||||
} else {
|
||||
DES_set_key_unchecked(key, schedule);
|
||||
return 0;
|
||||
}
|
||||
return DES_set_key_checked(key, schedule);
|
||||
}
|
||||
|
||||
/*-
|
||||
|
||||
+14
-2
@@ -488,6 +488,18 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri);
|
||||
#endif
|
||||
|
||||
static int dh_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
{
|
||||
switch (op) {
|
||||
case ASN1_PKEY_CTRL_SET1_TLS_ENCPT:
|
||||
return dh_buf2key(EVP_PKEY_get0_DH(pkey), arg2, arg1);
|
||||
case ASN1_PKEY_CTRL_GET1_TLS_ENCPT:
|
||||
return dh_key2buf(EVP_PKEY_get0_DH(pkey), arg2);
|
||||
default:
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
static int dhx_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
{
|
||||
switch (op) {
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
@@ -558,7 +570,7 @@ const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
|
||||
0,
|
||||
|
||||
int_dh_free,
|
||||
0,
|
||||
dh_pkey_ctrl,
|
||||
|
||||
0, 0, 0, 0, 0,
|
||||
|
||||
@@ -597,7 +609,7 @@ const EVP_PKEY_ASN1_METHOD dhx_asn1_meth = {
|
||||
0,
|
||||
|
||||
int_dh_free,
|
||||
dh_pkey_ctrl,
|
||||
dhx_pkey_ctrl,
|
||||
|
||||
0, 0, 0, 0, 0,
|
||||
|
||||
|
||||
+3
-1
@@ -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
|
||||
@@ -16,6 +16,7 @@
|
||||
static const ERR_STRING_DATA DH_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_COMPUTE_KEY, 0), "compute_key"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DHPARAMS_PRINT_FP, 0), "DHparams_print_fp"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_BUF2KEY, 0), "dh_buf2key"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, 0),
|
||||
"dh_builtin_genparams"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_EX, 0), "DH_check_ex"},
|
||||
@@ -25,6 +26,7 @@ static const ERR_STRING_DATA DH_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CMS_SET_PEERKEY, 0), "dh_cms_set_peerkey"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CMS_SET_SHARED_INFO, 0),
|
||||
"dh_cms_set_shared_info"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_KEY2BUF, 0), "dh_key2buf"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_METH_DUP, 0), "DH_meth_dup"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_METH_NEW, 0), "DH_meth_new"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_METH_SET1_NAME, 0), "DH_meth_set1_name"},
|
||||
|
||||
+31
-129
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2013-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
|
||||
@@ -10,141 +10,43 @@
|
||||
#include "e_os.h"
|
||||
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
#include <string.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/cms.h>
|
||||
|
||||
|
||||
/* Key derivation from X9.42/RFC2631 */
|
||||
/* Uses CMS functions, hence the #ifdef wrapper. */
|
||||
|
||||
#define DH_KDF_MAX (1L << 30)
|
||||
|
||||
/* Skip past an ASN1 structure: for OBJECT skip content octets too */
|
||||
|
||||
static int skip_asn1(unsigned char **pp, long *plen, int exptag)
|
||||
{
|
||||
const unsigned char *q = *pp;
|
||||
int i, tag, xclass;
|
||||
long tmplen;
|
||||
i = ASN1_get_object(&q, &tmplen, &tag, &xclass, *plen);
|
||||
if (i & 0x80)
|
||||
return 0;
|
||||
if (tag != exptag || xclass != V_ASN1_UNIVERSAL)
|
||||
return 0;
|
||||
if (tag == V_ASN1_OBJECT)
|
||||
q += tmplen;
|
||||
*plen -= q - *pp;
|
||||
*pp = (unsigned char *)q;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode the DH shared info structure, return an offset to the counter value
|
||||
* so we can update the structure without reencoding it.
|
||||
*/
|
||||
|
||||
static int dh_sharedinfo_encode(unsigned char **pder, unsigned char **pctr,
|
||||
ASN1_OBJECT *key_oid, size_t outlen,
|
||||
const unsigned char *ukm, size_t ukmlen)
|
||||
{
|
||||
unsigned char *p;
|
||||
int derlen;
|
||||
long tlen;
|
||||
/* "magic" value to check offset is sane */
|
||||
static unsigned char ctr[4] = { 0xF3, 0x17, 0x22, 0x53 };
|
||||
X509_ALGOR atmp;
|
||||
ASN1_OCTET_STRING ctr_oct, ukm_oct, *pukm_oct;
|
||||
ASN1_TYPE ctr_atype;
|
||||
if (ukmlen > DH_KDF_MAX || outlen > DH_KDF_MAX)
|
||||
return 0;
|
||||
ctr_oct.data = ctr;
|
||||
ctr_oct.length = 4;
|
||||
ctr_oct.flags = 0;
|
||||
ctr_oct.type = V_ASN1_OCTET_STRING;
|
||||
ctr_atype.type = V_ASN1_OCTET_STRING;
|
||||
ctr_atype.value.octet_string = &ctr_oct;
|
||||
atmp.algorithm = key_oid;
|
||||
atmp.parameter = &ctr_atype;
|
||||
if (ukm) {
|
||||
ukm_oct.type = V_ASN1_OCTET_STRING;
|
||||
ukm_oct.flags = 0;
|
||||
ukm_oct.data = (unsigned char *)ukm;
|
||||
ukm_oct.length = ukmlen;
|
||||
pukm_oct = &ukm_oct;
|
||||
} else
|
||||
pukm_oct = NULL;
|
||||
derlen = CMS_SharedInfo_encode(pder, &atmp, pukm_oct, outlen);
|
||||
if (derlen <= 0)
|
||||
return 0;
|
||||
p = *pder;
|
||||
tlen = derlen;
|
||||
if (!skip_asn1(&p, &tlen, V_ASN1_SEQUENCE))
|
||||
return 0;
|
||||
if (!skip_asn1(&p, &tlen, V_ASN1_SEQUENCE))
|
||||
return 0;
|
||||
if (!skip_asn1(&p, &tlen, V_ASN1_OBJECT))
|
||||
return 0;
|
||||
if (!skip_asn1(&p, &tlen, V_ASN1_OCTET_STRING))
|
||||
return 0;
|
||||
if (CRYPTO_memcmp(p, ctr, 4))
|
||||
return 0;
|
||||
*pctr = p;
|
||||
return derlen;
|
||||
}
|
||||
# include <string.h>
|
||||
# include <openssl/dh.h>
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/asn1.h>
|
||||
# include <openssl/kdf.h>
|
||||
|
||||
int DH_KDF_X9_42(unsigned char *out, size_t outlen,
|
||||
const unsigned char *Z, size_t Zlen,
|
||||
ASN1_OBJECT *key_oid,
|
||||
const unsigned char *ukm, size_t ukmlen, const EVP_MD *md)
|
||||
{
|
||||
EVP_MD_CTX *mctx = NULL;
|
||||
int rv = 0;
|
||||
unsigned int i;
|
||||
size_t mdlen;
|
||||
unsigned char *der = NULL, *ctr;
|
||||
int derlen;
|
||||
if (Zlen > DH_KDF_MAX)
|
||||
int ret = 0, nid;
|
||||
EVP_KDF_CTX *kctx = NULL;
|
||||
const EVP_KDF *kdf = NULL;
|
||||
const char *oid_sn;
|
||||
|
||||
nid = OBJ_obj2nid(key_oid);
|
||||
if (nid == NID_undef)
|
||||
return 0;
|
||||
mctx = EVP_MD_CTX_new();
|
||||
if (mctx == NULL)
|
||||
oid_sn = OBJ_nid2sn(nid);
|
||||
if (oid_sn == NULL)
|
||||
return 0;
|
||||
mdlen = EVP_MD_size(md);
|
||||
derlen = dh_sharedinfo_encode(&der, &ctr, key_oid, outlen, ukm, ukmlen);
|
||||
if (derlen == 0)
|
||||
|
||||
kdf = EVP_get_kdfbyname(SN_x942kdf);
|
||||
if (kdf == NULL)
|
||||
goto err;
|
||||
for (i = 1;; i++) {
|
||||
unsigned char mtmp[EVP_MAX_MD_SIZE];
|
||||
if (!EVP_DigestInit_ex(mctx, md, NULL)
|
||||
|| !EVP_DigestUpdate(mctx, Z, Zlen))
|
||||
goto err;
|
||||
ctr[3] = i & 0xFF;
|
||||
ctr[2] = (i >> 8) & 0xFF;
|
||||
ctr[1] = (i >> 16) & 0xFF;
|
||||
ctr[0] = (i >> 24) & 0xFF;
|
||||
if (!EVP_DigestUpdate(mctx, der, derlen))
|
||||
goto err;
|
||||
if (outlen >= mdlen) {
|
||||
if (!EVP_DigestFinal(mctx, out, NULL))
|
||||
goto err;
|
||||
outlen -= mdlen;
|
||||
if (outlen == 0)
|
||||
break;
|
||||
out += mdlen;
|
||||
} else {
|
||||
if (!EVP_DigestFinal(mctx, mtmp, NULL))
|
||||
goto err;
|
||||
memcpy(out, mtmp, outlen);
|
||||
OPENSSL_cleanse(mtmp, mdlen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rv = 1;
|
||||
err:
|
||||
OPENSSL_free(der);
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv;
|
||||
kctx = EVP_KDF_CTX_new(kdf);
|
||||
ret =
|
||||
kctx != NULL
|
||||
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, md) > 0
|
||||
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, Z, Zlen) > 0
|
||||
&& (ukm == NULL
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_UKM, ukm, ukmlen) > 0)
|
||||
&& EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_CEK_ALG, oid_sn) > 0
|
||||
&& EVP_KDF_derive(kctx, out, outlen) > 0;
|
||||
err:
|
||||
EVP_KDF_CTX_free(kctx);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif /* OPENSSL_NO_CMS */
|
||||
@@ -228,3 +228,66 @@ static int dh_finish(DH *dh)
|
||||
BN_MONT_CTX_free(dh->method_mont_p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dh_buf2key(DH *dh, const unsigned char *buf, size_t len)
|
||||
{
|
||||
int err_reason = DH_R_BN_ERROR;
|
||||
BIGNUM *pubkey = NULL;
|
||||
const BIGNUM *p;
|
||||
size_t p_size;
|
||||
|
||||
if ((pubkey = BN_bin2bn(buf, len, NULL)) == NULL)
|
||||
goto err;
|
||||
DH_get0_pqg(dh, &p, NULL, NULL);
|
||||
if (p == NULL || (p_size = BN_num_bytes(p)) == 0) {
|
||||
err_reason = DH_R_NO_PARAMETERS_SET;
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
* As per Section 4.2.8.1 of RFC 8446 fail if DHE's
|
||||
* public key is of size not equal to size of p
|
||||
*/
|
||||
if (BN_is_zero(pubkey) || p_size != len) {
|
||||
err_reason = DH_R_INVALID_PUBKEY;
|
||||
goto err;
|
||||
}
|
||||
if (DH_set0_key(dh, pubkey, NULL) != 1)
|
||||
goto err;
|
||||
return 1;
|
||||
err:
|
||||
DHerr(DH_F_DH_BUF2KEY, err_reason);
|
||||
BN_free(pubkey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t dh_key2buf(const DH *dh, unsigned char **pbuf_out)
|
||||
{
|
||||
const BIGNUM *pubkey;
|
||||
unsigned char *pbuf;
|
||||
const BIGNUM *p;
|
||||
int p_size;
|
||||
|
||||
DH_get0_pqg(dh, &p, NULL, NULL);
|
||||
DH_get0_key(dh, &pubkey, NULL);
|
||||
if (p == NULL || pubkey == NULL
|
||||
|| (p_size = BN_num_bytes(p)) == 0
|
||||
|| BN_num_bytes(pubkey) == 0) {
|
||||
DHerr(DH_F_DH_KEY2BUF, DH_R_INVALID_PUBKEY);
|
||||
return 0;
|
||||
}
|
||||
if ((pbuf = OPENSSL_malloc(p_size)) == NULL) {
|
||||
DHerr(DH_F_DH_KEY2BUF, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* As per Section 4.2.8.1 of RFC 8446 left pad public
|
||||
* key with zeros to the size of p
|
||||
*/
|
||||
if (BN_bn2binpad(pubkey, pbuf, p_size) < 0) {
|
||||
OPENSSL_free(pbuf);
|
||||
DHerr(DH_F_DH_KEY2BUF, DH_R_BN_ERROR);
|
||||
return 0;
|
||||
}
|
||||
*pbuf_out = pbuf;
|
||||
return p_size;
|
||||
}
|
||||
@@ -55,3 +55,6 @@ struct dh_method {
|
||||
int (*generate_params) (DH *dh, int prime_len, int generator,
|
||||
BN_GENCB *cb);
|
||||
};
|
||||
|
||||
int dh_buf2key(DH *key, const unsigned char *buf, size_t len);
|
||||
size_t dh_key2buf(const DH *dh, unsigned char **pbuf);
|
||||
@@ -505,7 +505,7 @@ static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
|
||||
|
||||
case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
|
||||
*(int *)arg2 = NID_sha256;
|
||||
return 2;
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return -2;
|
||||
|
||||
@@ -248,7 +248,7 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,
|
||||
* one bit longer than the modulus.
|
||||
*
|
||||
* There are some concerns about the efficacy of doing this. More
|
||||
* specificly refer to the discussion starting with:
|
||||
* specifically refer to the discussion starting with:
|
||||
* https://github.com/openssl/openssl/pull/7486#discussion_r228323705
|
||||
* The fix is to rework BN so these gymnastics aren't required.
|
||||
*/
|
||||
|
||||
@@ -1301,7 +1301,7 @@ ecp_nistz256_ord_mul_montx:
|
||||
|
||||
################################# reduction
|
||||
mulx 8*0+128(%r14), $t0, $t1
|
||||
adcx $t0, $acc3 # guranteed to be zero
|
||||
adcx $t0, $acc3 # guaranteed to be zero
|
||||
adox $t1, $acc4
|
||||
|
||||
mulx 8*1+128(%r14), $t0, $t1
|
||||
|
||||
@@ -451,7 +451,7 @@ x25519_fe64_tobytes:
|
||||
and $t0,$t0,$t1
|
||||
sldi $a3,$a3,1
|
||||
add $t0,$t0,$t1 # compare to modulus in the same go
|
||||
srdi $a3,$a3,1 # most signifcant bit cleared
|
||||
srdi $a3,$a3,1 # most significant bit cleared
|
||||
|
||||
addc $a0,$a0,$t0
|
||||
addze $a1,$a1
|
||||
@@ -462,7 +462,7 @@ x25519_fe64_tobytes:
|
||||
sradi $t0,$a3,63 # most significant bit -> mask
|
||||
sldi $a3,$a3,1
|
||||
andc $t0,$t1,$t0
|
||||
srdi $a3,$a3,1 # most signifcant bit cleared
|
||||
srdi $a3,$a3,1 # most significant bit cleared
|
||||
|
||||
subi $rp,$rp,1
|
||||
subfc $a0,$t0,$a0
|
||||
|
||||
+46
-1
@@ -1,3 +1,47 @@
|
||||
$ECASM=
|
||||
IF[{- !$disabled{asm} -}]
|
||||
$ECASM_x86=ecp_nistz256.c ecp_nistz256-x86.s
|
||||
$ECDEF_x86=ECP_NISTZ256_ASM
|
||||
|
||||
$ECASM_x86_64=ecp_nistz256.c ecp_nistz256-x86_64.s x25519-x86_64.s
|
||||
$ECDEF_x86_64=ECP_NISTZ256_ASM X25519_ASM
|
||||
|
||||
$ECASM_ia64=
|
||||
|
||||
$ECASM_sparcv9=ecp_nistz256.c ecp_nistz256-sparcv9.S
|
||||
$ECDEF_sparcv9=ECP_NISTZ256_ASM
|
||||
|
||||
$ECASM_sparcv8=
|
||||
|
||||
$ECASM_alpha=
|
||||
|
||||
$ECASM_mips32=
|
||||
$ECASM_mips64=
|
||||
|
||||
$ECASM_s390x=
|
||||
|
||||
$ECASM_armv4=ecp_nistz256.c ecp_nistz256-armv4.S
|
||||
$ECDEF_armv4=ECP_NISTZ256_ASM
|
||||
$ECASM_aarch64=ecp_nistz256.c ecp_nistz256-armv8.S
|
||||
$ECDEF_aarch64=ECP_NISTZ256_ASM
|
||||
|
||||
$ECASM_parisc11=
|
||||
$ECASM_parisc20_64=
|
||||
|
||||
$ECASM_ppc32=
|
||||
$ECASM_ppc64=ecp_nistz256.c ecp_nistz256-ppc64.s x25519-ppc64.s
|
||||
$ECDEF_ppc64=ECP_NISTZ256_ASM X25519_ASM
|
||||
|
||||
$ECASM_c64xplus=
|
||||
|
||||
# Now that we have defined all the arch specific variables, use the
|
||||
# appropriate one, and define the appropriate macros
|
||||
IF[$ECASM_{- $target{asm_arch} -}]
|
||||
$ECASM=$ECASM_{- $target{asm_arch} -}
|
||||
$ECDEF=$ECDEF_{- $target{asm_arch} -}
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c \
|
||||
@@ -8,7 +52,8 @@ SOURCE[../../libcrypto]=\
|
||||
ecdsa_ossl.c ecdsa_sign.c ecdsa_vrf.c curve25519.c ecx_meth.c \
|
||||
curve448/arch_32/f_impl.c curve448/f_generic.c curve448/scalar.c \
|
||||
curve448/curve448_tables.c curve448/eddsa.c curve448/curve448.c \
|
||||
{- $target{ec_asm_src} -}
|
||||
$ECASM
|
||||
DEFINE[../../libcrypto]=$ECDEF
|
||||
|
||||
GENERATE[ecp_nistz256-x86.s]=asm/ecp_nistz256-x86.pl \
|
||||
$(PERLASM_SCHEME) $(LIB_CFLAGS) $(LIB_CPPFLAGS) $(PROCESSOR)
|
||||
|
||||
@@ -22,6 +22,13 @@ int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only)
|
||||
|
||||
int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
|
||||
{
|
||||
#ifdef FIPS_MODE
|
||||
/*
|
||||
* ECC domain parameter validation.
|
||||
* See SP800-56A R3 5.5.2 "Assurances of Domain-Parameter Validity" Part 1b.
|
||||
*/
|
||||
return EC_GROUP_check_named_curve(group, 1) >= 0 ? 1 : 0;
|
||||
#else
|
||||
int ret = 0;
|
||||
const BIGNUM *order;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
@@ -84,4 +91,5 @@ int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
|
||||
BN_CTX_free(new_ctx);
|
||||
EC_POINT_free(point);
|
||||
return ret;
|
||||
#endif /* FIPS_MODE */
|
||||
}
|
||||
+96
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/o_str.h"
|
||||
|
||||
typedef struct {
|
||||
int field_type, /* either NID_X9_62_prime_field or
|
||||
@@ -2801,6 +2800,70 @@ typedef struct _ec_list_element_st {
|
||||
const char *comment;
|
||||
} ec_list_element;
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
static const ec_list_element curve_list[] = {
|
||||
/* prime field curves */
|
||||
/* secg curves */
|
||||
# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
{NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
|
||||
"NIST/SECG curve over a 224 bit prime field"},
|
||||
# else
|
||||
{NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,
|
||||
"NIST/SECG curve over a 224 bit prime field"},
|
||||
# endif
|
||||
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
||||
{NID_secp384r1, &_EC_NIST_PRIME_384.h, 0,
|
||||
"NIST/SECG curve over a 384 bit prime field"},
|
||||
|
||||
# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h, EC_GFp_nistp521_method,
|
||||
"NIST/SECG curve over a 521 bit prime field"},
|
||||
# else
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h, 0,
|
||||
"NIST/SECG curve over a 521 bit prime field"},
|
||||
# endif
|
||||
|
||||
/* X9.62 curves */
|
||||
{NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
|
||||
"NIST/X9.62/SECG curve over a 192 bit prime field"},
|
||||
{NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
||||
# if defined(ECP_NISTZ256_ASM)
|
||||
EC_GFp_nistz256_method,
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp256_method,
|
||||
# else
|
||||
0,
|
||||
# endif
|
||||
"X9.62/SECG curve over a 256 bit prime field"},
|
||||
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
/* characteristic two field curves */
|
||||
/* NIST/SECG curves */
|
||||
{NID_sect163k1, &_EC_NIST_CHAR2_163K.h, 0,
|
||||
"NIST/SECG/WTLS curve over a 163 bit binary field"},
|
||||
{NID_sect163r2, &_EC_NIST_CHAR2_163B.h, 0,
|
||||
"NIST/SECG curve over a 163 bit binary field"},
|
||||
{NID_sect233k1, &_EC_NIST_CHAR2_233K.h, 0,
|
||||
"NIST/SECG/WTLS curve over a 233 bit binary field"},
|
||||
{NID_sect233r1, &_EC_NIST_CHAR2_233B.h, 0,
|
||||
"NIST/SECG/WTLS curve over a 233 bit binary field"},
|
||||
{NID_sect283k1, &_EC_NIST_CHAR2_283K.h, 0,
|
||||
"NIST/SECG curve over a 283 bit binary field"},
|
||||
{NID_sect283r1, &_EC_NIST_CHAR2_283B.h, 0,
|
||||
"NIST/SECG curve over a 283 bit binary field"},
|
||||
{NID_sect409k1, &_EC_NIST_CHAR2_409K.h, 0,
|
||||
"NIST/SECG curve over a 409 bit binary field"},
|
||||
{NID_sect409r1, &_EC_NIST_CHAR2_409B.h, 0,
|
||||
"NIST/SECG curve over a 409 bit binary field"},
|
||||
{NID_sect571k1, &_EC_NIST_CHAR2_571K.h, 0,
|
||||
"NIST/SECG curve over a 571 bit binary field"},
|
||||
{NID_sect571r1, &_EC_NIST_CHAR2_571B.h, 0,
|
||||
"NIST/SECG curve over a 571 bit binary field"},
|
||||
# endif
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
static const ec_list_element curve_list[] = {
|
||||
/* prime field curves */
|
||||
/* secg curves */
|
||||
@@ -2823,25 +2886,25 @@ static const ec_list_element curve_list[] = {
|
||||
"SECG curve over a 192 bit prime field"},
|
||||
{NID_secp224k1, &_EC_SECG_PRIME_224K1.h, 0,
|
||||
"SECG curve over a 224 bit prime field"},
|
||||
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
{NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
|
||||
"NIST/SECG curve over a 224 bit prime field"},
|
||||
#else
|
||||
# else
|
||||
{NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,
|
||||
"NIST/SECG curve over a 224 bit prime field"},
|
||||
#endif
|
||||
# endif
|
||||
{NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,
|
||||
"SECG curve over a 256 bit prime field"},
|
||||
/* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
|
||||
{NID_secp384r1, &_EC_NIST_PRIME_384.h, 0,
|
||||
"NIST/SECG curve over a 384 bit prime field"},
|
||||
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
# ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h, EC_GFp_nistp521_method,
|
||||
"NIST/SECG curve over a 521 bit prime field"},
|
||||
#else
|
||||
# else
|
||||
{NID_secp521r1, &_EC_NIST_PRIME_521.h, 0,
|
||||
"NIST/SECG curve over a 521 bit prime field"},
|
||||
#endif
|
||||
# endif
|
||||
/* X9.62 curves */
|
||||
{NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
|
||||
"NIST/X9.62/SECG curve over a 192 bit prime field"},
|
||||
@@ -2856,15 +2919,15 @@ static const ec_list_element curve_list[] = {
|
||||
{NID_X9_62_prime239v3, &_EC_X9_62_PRIME_239V3.h, 0,
|
||||
"X9.62 curve over a 239 bit prime field"},
|
||||
{NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
|
||||
#if defined(ECP_NISTZ256_ASM)
|
||||
# if defined(ECP_NISTZ256_ASM)
|
||||
EC_GFp_nistz256_method,
|
||||
#elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
# elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
|
||||
EC_GFp_nistp256_method,
|
||||
#else
|
||||
# else
|
||||
0,
|
||||
#endif
|
||||
# endif
|
||||
"X9.62/SECG curve over a 256 bit prime field"},
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
/* characteristic two field curves */
|
||||
/* NIST/SECG curves */
|
||||
{NID_sect113r1, &_EC_SECG_CHAR2_113R1.h, 0,
|
||||
@@ -2948,7 +3011,7 @@ static const ec_list_element curve_list[] = {
|
||||
"SECG curve over a 113 bit binary field"},
|
||||
{NID_wap_wsg_idm_ecid_wtls5, &_EC_X9_62_CHAR2_163V1.h, 0,
|
||||
"X9.62 curve over a 163 bit binary field"},
|
||||
#endif
|
||||
# endif
|
||||
{NID_wap_wsg_idm_ecid_wtls6, &_EC_SECG_PRIME_112R1.h, 0,
|
||||
"SECG/WTLS curve over a 112 bit prime field"},
|
||||
{NID_wap_wsg_idm_ecid_wtls7, &_EC_SECG_PRIME_160R2.h, 0,
|
||||
@@ -2957,15 +3020,15 @@ static const ec_list_element curve_list[] = {
|
||||
"WTLS curve over a 112 bit prime field"},
|
||||
{NID_wap_wsg_idm_ecid_wtls9, &_EC_WTLS_9.h, 0,
|
||||
"WTLS curve over a 160 bit prime field"},
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
{NID_wap_wsg_idm_ecid_wtls10, &_EC_NIST_CHAR2_233K.h, 0,
|
||||
"NIST/SECG/WTLS curve over a 233 bit binary field"},
|
||||
{NID_wap_wsg_idm_ecid_wtls11, &_EC_NIST_CHAR2_233B.h, 0,
|
||||
"NIST/SECG/WTLS curve over a 233 bit binary field"},
|
||||
#endif
|
||||
# endif
|
||||
{NID_wap_wsg_idm_ecid_wtls12, &_EC_WTLS_12.h, 0,
|
||||
"WTLS curve over a 224 bit prime field"},
|
||||
#ifndef OPENSSL_NO_EC2M
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
/* IPSec curves */
|
||||
{NID_ipsec3, &_EC_IPSEC_155_ID3.h, 0,
|
||||
"\n\tIPSec/IKE/Oakley curve #3 over a 155 bit binary field.\n"
|
||||
@@ -2973,7 +3036,7 @@ static const ec_list_element curve_list[] = {
|
||||
{NID_ipsec4, &_EC_IPSEC_185_ID4.h, 0,
|
||||
"\n\tIPSec/IKE/Oakley curve #4 over a 185 bit binary field.\n"
|
||||
"\tNot suitable for ECDSA.\n\tQuestionable extension field!"},
|
||||
#endif
|
||||
# endif
|
||||
/* brainpool curves */
|
||||
{NID_brainpoolP160r1, &_EC_brainpoolP160r1.h, 0,
|
||||
"RFC 5639 curve over a 160 bit prime field"},
|
||||
@@ -3003,11 +3066,12 @@ static const ec_list_element curve_list[] = {
|
||||
"RFC 5639 curve over a 512 bit prime field"},
|
||||
{NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0,
|
||||
"RFC 5639 curve over a 512 bit prime field"},
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
# ifndef OPENSSL_NO_SM2
|
||||
{NID_sm2, &_EC_sm2p256v1.h, 0,
|
||||
"SM2 curve over a 256 bit prime field"},
|
||||
#endif
|
||||
# endif
|
||||
};
|
||||
#endif /* FIPS_MODE */
|
||||
|
||||
#define curve_list_length OSSL_NELEM(curve_list)
|
||||
|
||||
@@ -3126,6 +3190,15 @@ EC_GROUP *EC_GROUP_new_by_curve_name(int nid)
|
||||
if (nid <= 0)
|
||||
return NULL;
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
/*
|
||||
* Only use approved NIST curves in FIPS.
|
||||
* NOTE: "B-163", "K-163" & "P-192" can only be used for legacy use
|
||||
* (i.e- ECDSA signature verification).
|
||||
*/
|
||||
if (EC_curve_nid2nist(nid) == NULL)
|
||||
return NULL;
|
||||
#endif /* FIPS_MODE */
|
||||
for (i = 0; i < curve_list_length; i++)
|
||||
if (curve_list[i].nid == nid) {
|
||||
ret = ec_group_new_from_data(curve_list[i]);
|
||||
@@ -3302,10 +3375,10 @@ int ec_curve_nid_from_params(const EC_GROUP *group)
|
||||
/* Check the optional seed (ignore if its not set) */
|
||||
&& (data->seed_len == 0 || seed_len == 0
|
||||
|| ((size_t)data->seed_len == seed_len
|
||||
&& OPENSSL_memcmp(params_seed, seed, seed_len) == 0))
|
||||
&& memcmp(params_seed, seed, seed_len) == 0))
|
||||
/* Check that the groups params match the built-in curve params */
|
||||
&& OPENSSL_memcmp(param_bytes, params, param_len * NUM_BN_FIELDS)
|
||||
== 0) {
|
||||
&& memcmp(param_bytes, params, param_len * NUM_BN_FIELDS)
|
||||
== 0) {
|
||||
ret = curve.nid;
|
||||
goto end;
|
||||
}
|
||||
|
||||
+1
-1
@@ -303,7 +303,7 @@ int EC_KEY_check_key(const EC_KEY *eckey)
|
||||
* See SP800-56A R3 Section 5.6.2.3.3 (Part 2)
|
||||
* i.e.
|
||||
* - If q = odd prime p: Verify that xQ and yQ are integers in the
|
||||
* interval[0, p − 1], OR
|
||||
* interval[0, p - 1], OR
|
||||
* - If q = 2m: Verify that xQ and yQ are bit strings of length m bits.
|
||||
* Returns 1 if the public key has a valid range, otherwise it returns 0.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ struct ec_method_st {
|
||||
int (*field_div) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *b, BN_CTX *);
|
||||
/*-
|
||||
* 'field_inv' computes the multipicative inverse of a in the field,
|
||||
* 'field_inv' computes the multiplicative inverse of a in the field,
|
||||
* storing the result in r.
|
||||
*
|
||||
* If 'a' is zero (or equivalent), you'll get an EC_R_CANNOT_INVERT error.
|
||||
|
||||
@@ -327,7 +327,8 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sha3_224 &&
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sha3_256 &&
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sha3_384 &&
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sha3_512) {
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sha3_512 &&
|
||||
EVP_MD_type((const EVP_MD *)p2) != NID_sm3) {
|
||||
ECerr(EC_F_PKEY_EC_CTRL, EC_R_INVALID_DIGEST_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1269,7 +1269,7 @@ static void point_add(felem x3, felem y3, felem z3,
|
||||
* ffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb
|
||||
* 71e913863f7, in that case the penultimate intermediate is -9G and
|
||||
* the final digit is also -9G. Since this only happens for a single
|
||||
* scalar, the timing leak is irrelevent. (Any attacker who wanted to
|
||||
* scalar, the timing leak is irrelevant. (Any attacker who wanted to
|
||||
* check whether a secret scalar was that exact value, can already do
|
||||
* so.)
|
||||
*/
|
||||
|
||||
+12
-12
@@ -158,13 +158,13 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
|
||||
* of a nonnegative integer (b_k in {0, 1}), rewrite it in digits 0, 1, -1
|
||||
* by using bit-wise subtraction as follows:
|
||||
*
|
||||
* b_k b_(k-1) ... b_2 b_1 b_0
|
||||
* - b_k ... b_3 b_2 b_1 b_0
|
||||
* -------------------------------------
|
||||
* s_k b_(k-1) ... s_3 s_2 s_1 s_0
|
||||
* b_k b_(k-1) ... b_2 b_1 b_0
|
||||
* - b_k ... b_3 b_2 b_1 b_0
|
||||
* -----------------------------------------
|
||||
* s_(k+1) s_k ... s_3 s_2 s_1 s_0
|
||||
*
|
||||
* A left-shift followed by subtraction of the original value yields a new
|
||||
* representation of the same value, using signed bits s_i = b_(i+1) - b_i.
|
||||
* representation of the same value, using signed bits s_i = b_(i-1) - b_i.
|
||||
* This representation from Booth's paper has since appeared in the
|
||||
* literature under a variety of different names including "reversed binary
|
||||
* form", "alternating greedy expansion", "mutual opposite form", and
|
||||
@@ -188,7 +188,7 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
|
||||
* (1961), pp. 67-91), in a radix-2^5 setting. That is, we always combine five
|
||||
* signed bits into a signed digit:
|
||||
*
|
||||
* s_(4j + 4) s_(4j + 3) s_(4j + 2) s_(4j + 1) s_(4j)
|
||||
* s_(5j + 4) s_(5j + 3) s_(5j + 2) s_(5j + 1) s_(5j)
|
||||
*
|
||||
* The sign-alternating property implies that the resulting digit values are
|
||||
* integers from -16 to 16.
|
||||
@@ -196,14 +196,14 @@ void ec_GFp_nistp_points_make_affine_internal(size_t num, void *point_array,
|
||||
* Of course, we don't actually need to compute the signed digits s_i as an
|
||||
* intermediate step (that's just a nice way to see how this scheme relates
|
||||
* to the wNAF): a direct computation obtains the recoded digit from the
|
||||
* six bits b_(4j + 4) ... b_(4j - 1).
|
||||
* six bits b_(5j + 4) ... b_(5j - 1).
|
||||
*
|
||||
* This function takes those five bits as an integer (0 .. 63), writing the
|
||||
* This function takes those six bits as an integer (0 .. 63), writing the
|
||||
* recoded digit to *sign (0 for positive, 1 for negative) and *digit (absolute
|
||||
* value, in the range 0 .. 8). Note that this integer essentially provides the
|
||||
* input bits "shifted to the left" by one position: for example, the input to
|
||||
* compute the least significant recoded digit, given that there's no bit b_-1,
|
||||
* has to be b_4 b_3 b_2 b_1 b_0 0.
|
||||
* value, in the range 0 .. 16). Note that this integer essentially provides
|
||||
* the input bits "shifted to the left" by one position: for example, the input
|
||||
* to compute the least significant recoded digit, given that there's no bit
|
||||
* b_-1, has to be b_4 b_3 b_2 b_1 b_0 0.
|
||||
*
|
||||
*/
|
||||
void ec_GFp_nistp_recode_scalar_bits(unsigned char *sign,
|
||||
|
||||
@@ -532,7 +532,7 @@ static int ecd_item_sign25519(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
|
||||
X509_ALGOR_set0(alg1, OBJ_nid2obj(NID_ED25519), V_ASN1_UNDEF, NULL);
|
||||
if (alg2)
|
||||
X509_ALGOR_set0(alg2, OBJ_nid2obj(NID_ED25519), V_ASN1_UNDEF, NULL);
|
||||
/* Algorithm idetifiers set: carry on as normal */
|
||||
/* Algorithm identifiers set: carry on as normal */
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
+37
-24
@@ -59,6 +59,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = {
|
||||
{ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"},
|
||||
{ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"},
|
||||
{ERR_PACK(ERR_LIB_CRMF, 0, 0), "CRMF routines"},
|
||||
{ERR_PACK(ERR_LIB_CMP, 0, 0), "CMP routines"},
|
||||
{ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"},
|
||||
{ERR_PACK(ERR_LIB_CT, 0, 0), "CT routines"},
|
||||
{ERR_PACK(ERR_LIB_ASYNC, 0, 0), "ASYNC routines"},
|
||||
@@ -187,8 +188,8 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
/* A measurement on Linux 2018-11-21 showed about 3.5kib */
|
||||
# define SPACE_SYS_STR_REASONS 4 * 1024
|
||||
/* 2019-05-21: Russian and Ukrainian locales on Linux require more than 6,5 kB */
|
||||
# define SPACE_SYS_STR_REASONS 8 * 1024
|
||||
# define NUM_SYS_STR_REASONS 127
|
||||
|
||||
static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
|
||||
@@ -222,21 +223,23 @@ static void build_SYS_str_reasons(void)
|
||||
ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
|
||||
|
||||
str->error = ERR_PACK(ERR_LIB_SYS, 0, i);
|
||||
if (str->string == NULL) {
|
||||
/*
|
||||
* If we have used up all the space in strerror_pool,
|
||||
* there's no point in calling openssl_strerror_r()
|
||||
*/
|
||||
if (str->string == NULL && cnt < sizeof(strerror_pool)) {
|
||||
if (openssl_strerror_r(i, cur, sizeof(strerror_pool) - cnt)) {
|
||||
size_t l = strlen(cur);
|
||||
|
||||
str->string = cur;
|
||||
cnt += l;
|
||||
if (cnt > sizeof(strerror_pool))
|
||||
cnt = sizeof(strerror_pool);
|
||||
cur += l;
|
||||
|
||||
/*
|
||||
* VMS has an unusual quirk of adding spaces at the end of
|
||||
* some (most? all?) messages. Lets trim them off.
|
||||
* some (most? all?) messages. Lets trim them off.
|
||||
*/
|
||||
while (ossl_isspace(cur[-1])) {
|
||||
while (cur > strerror_pool && ossl_isspace(cur[-1])) {
|
||||
cur--;
|
||||
cnt--;
|
||||
}
|
||||
@@ -685,7 +688,8 @@ const char *ERR_reason_error_string(unsigned long e)
|
||||
return ((p == NULL) ? NULL : p->string);
|
||||
}
|
||||
|
||||
void err_delete_thread_state(void)
|
||||
/* TODO(3.0): arg ignored for now */
|
||||
static void err_delete_thread_state(void *arg)
|
||||
{
|
||||
ERR_STATE *state = CRYPTO_THREAD_get_local(&err_thread_local);
|
||||
if (state == NULL)
|
||||
@@ -737,7 +741,7 @@ ERR_STATE *ERR_get_state(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)
|
||||
if (!ossl_init_thread_start(NULL, NULL, err_delete_thread_state)
|
||||
|| !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
|
||||
ERR_STATE_free(state);
|
||||
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
|
||||
@@ -846,32 +850,41 @@ void ERR_add_error_data(int num, ...)
|
||||
|
||||
void ERR_add_error_vdata(int num, va_list args)
|
||||
{
|
||||
int i, n, s;
|
||||
char *str, *p, *a;
|
||||
int i, len, size;
|
||||
char *str, *p, *arg;
|
||||
ERR_STATE *es;
|
||||
|
||||
s = 80;
|
||||
if ((str = OPENSSL_malloc(s + 1)) == NULL) {
|
||||
/* Get the current error data; if an allocated string get it. */
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
i = es->top;
|
||||
p = es->err_data_flags[i] == (ERR_TXT_MALLOCED | ERR_TXT_STRING)
|
||||
? es->err_data[i] : "";
|
||||
|
||||
/* Start with initial (or empty) string and allocate a new buffer */
|
||||
size = 80 + strlen(p);
|
||||
if ((str = OPENSSL_malloc(size + 1)) == NULL) {
|
||||
/* ERRerr(ERR_F_ERR_ADD_ERROR_VDATA, ERR_R_MALLOC_FAILURE); */
|
||||
return;
|
||||
}
|
||||
str[0] = '\0';
|
||||
strcpy(str, p);
|
||||
|
||||
n = 0;
|
||||
for (i = 0; i < num; i++) {
|
||||
a = va_arg(args, char *);
|
||||
if (a == NULL)
|
||||
a = "<NULL>";
|
||||
n += strlen(a);
|
||||
if (n > s) {
|
||||
s = n + 20;
|
||||
p = OPENSSL_realloc(str, s + 1);
|
||||
for (len = 0; --num >= 0; ) {
|
||||
arg = va_arg(args, char *);
|
||||
if (arg == NULL)
|
||||
arg = "<NULL>";
|
||||
len += strlen(arg);
|
||||
if (len > size) {
|
||||
size = len + 20;
|
||||
p = OPENSSL_realloc(str, size + 1);
|
||||
if (p == NULL) {
|
||||
OPENSSL_free(str);
|
||||
return;
|
||||
}
|
||||
str = p;
|
||||
}
|
||||
OPENSSL_strlcat(str, a, (size_t)s + 1);
|
||||
OPENSSL_strlcat(str, arg, (size_t)size + 1);
|
||||
}
|
||||
if (!err_set_error_data_int(str, ERR_TXT_MALLOCED | ERR_TXT_STRING))
|
||||
OPENSSL_free(str);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <openssl/tserr.h>
|
||||
#include <openssl/cmserr.h>
|
||||
#include <openssl/crmferr.h>
|
||||
#include <openssl/cmperr.h>
|
||||
#include <openssl/cterr.h>
|
||||
#include <openssl/asyncerr.h>
|
||||
#include <openssl/kdferr.h>
|
||||
@@ -94,6 +95,7 @@ int err_load_crypto_strings_int(void)
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_CRMF
|
||||
ERR_load_CRMF_strings() == 0 ||
|
||||
ERR_load_CMP_strings() == 0 ||
|
||||
# endif
|
||||
# ifndef OPENSSL_NO_CT
|
||||
ERR_load_CT_strings() == 0 ||
|
||||
|
||||
+7
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2017 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
|
||||
@@ -16,27 +16,19 @@
|
||||
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
|
||||
void *u)
|
||||
{
|
||||
CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();
|
||||
unsigned long l;
|
||||
char buf[256];
|
||||
char buf2[4096];
|
||||
char buf2[4096], *hex;
|
||||
const char *file, *data;
|
||||
int line, flags;
|
||||
/*
|
||||
* We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
|
||||
* attempt to convert it into something we can print.
|
||||
*/
|
||||
union {
|
||||
CRYPTO_THREAD_ID tid;
|
||||
unsigned long ltid;
|
||||
} tid;
|
||||
|
||||
tid.ltid = 0;
|
||||
tid.tid = CRYPTO_THREAD_get_current_id();
|
||||
|
||||
while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
|
||||
ERR_error_string_n(l, buf, sizeof(buf));
|
||||
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
|
||||
file, line, (flags & ERR_TXT_STRING) ? data : "");
|
||||
hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
|
||||
BIO_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%d:%s\n", hex, buf, file,
|
||||
line, (flags & ERR_TXT_STRING) ? data : "");
|
||||
OPENSSL_free(hex);
|
||||
if (cb(buf2, strlen(buf2), u) <= 0)
|
||||
break; /* abort outputting the error report */
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ L EC include/openssl/ec.h crypto/ec/ec_err.c
|
||||
L SSL include/openssl/ssl.h ssl/ssl_err.c
|
||||
L BIO include/openssl/bio.h crypto/bio/bio_err.c
|
||||
L PKCS7 include/openssl/pkcs7.h crypto/pkcs7/pkcs7err.c
|
||||
L X509V3 include/openssl/x509v3.h crypto/x509v3/v3err.c
|
||||
L X509V3 include/openssl/x509v3.h crypto/x509/v3err.c
|
||||
L PKCS12 include/openssl/pkcs12.h crypto/pkcs12/pk12err.c
|
||||
L RAND include/openssl/rand.h crypto/rand/rand_err.c
|
||||
L DSO include/internal/dso.h crypto/dso/dso_err.c
|
||||
@@ -30,6 +30,7 @@ L COMP include/openssl/comp.h crypto/comp/comp_err.c
|
||||
L TS include/openssl/ts.h crypto/ts/ts_err.c
|
||||
L CMS include/openssl/cms.h crypto/cms/cms_err.c
|
||||
L CRMF include/openssl/crmf.h crypto/crmf/crmf_err.c
|
||||
L CMP include/openssl/cmp.h crypto/cmp/cmp_err.c
|
||||
L CT include/openssl/ct.h crypto/ct/ct_err.c
|
||||
L ASYNC include/openssl/async.h crypto/async/async_err.c
|
||||
L KDF include/openssl/kdf.h crypto/kdf/kdf_err.c
|
||||
|
||||
+31
-2
@@ -196,6 +196,7 @@ BN_F_BN_BN2HEX:105:BN_bn2hex
|
||||
BN_F_BN_COMPUTE_WNAF:142:bn_compute_wNAF
|
||||
BN_F_BN_CTX_GET:116:BN_CTX_get
|
||||
BN_F_BN_CTX_NEW:106:BN_CTX_new
|
||||
BN_F_BN_CTX_NEW_EX:151:BN_CTX_new_ex
|
||||
BN_F_BN_CTX_START:129:BN_CTX_start
|
||||
BN_F_BN_DIV:107:BN_div
|
||||
BN_F_BN_DIV_RECP:130:BN_div_recp
|
||||
@@ -318,6 +319,7 @@ CMS_F_CMS_SIGNERINFO_VERIFY:152:CMS_SignerInfo_verify
|
||||
CMS_F_CMS_SIGNERINFO_VERIFY_CERT:153:cms_signerinfo_verify_cert
|
||||
CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT:154:CMS_SignerInfo_verify_content
|
||||
CMS_F_CMS_SIGN_RECEIPT:163:CMS_sign_receipt
|
||||
CMS_F_CMS_SI_CHECK_ATTRIBUTES:183:CMS_si_check_attributes
|
||||
CMS_F_CMS_STREAM:155:CMS_stream
|
||||
CMS_F_CMS_UNCOMPRESS:156:CMS_uncompress
|
||||
CMS_F_CMS_VERIFY:157:CMS_verify
|
||||
@@ -437,6 +439,7 @@ CT_F_SCT_SET_SIGNATURE_NID:103:SCT_set_signature_nid
|
||||
CT_F_SCT_SET_VERSION:104:SCT_set_version
|
||||
DH_F_COMPUTE_KEY:102:compute_key
|
||||
DH_F_DHPARAMS_PRINT_FP:101:DHparams_print_fp
|
||||
DH_F_DH_BUF2KEY:126:dh_buf2key
|
||||
DH_F_DH_BUILTIN_GENPARAMS:106:dh_builtin_genparams
|
||||
DH_F_DH_CHECK_EX:121:DH_check_ex
|
||||
DH_F_DH_CHECK_PARAMS_EX:122:DH_check_params_ex
|
||||
@@ -444,6 +447,7 @@ DH_F_DH_CHECK_PUB_KEY_EX:123:DH_check_pub_key_ex
|
||||
DH_F_DH_CMS_DECRYPT:114:dh_cms_decrypt
|
||||
DH_F_DH_CMS_SET_PEERKEY:115:dh_cms_set_peerkey
|
||||
DH_F_DH_CMS_SET_SHARED_INFO:116:dh_cms_set_shared_info
|
||||
DH_F_DH_KEY2BUF:127:dh_key2buf
|
||||
DH_F_DH_METH_DUP:117:DH_meth_dup
|
||||
DH_F_DH_METH_NEW:118:DH_meth_new
|
||||
DH_F_DH_METH_SET1_NAME:119:DH_meth_set1_name
|
||||
@@ -808,7 +812,7 @@ EVP_F_EVP_KDF_CTX_NEW:240:EVP_KDF_CTX_new
|
||||
EVP_F_EVP_KDF_CTX_NEW_ID:226:EVP_KDF_CTX_new_id
|
||||
EVP_F_EVP_MAC_CTRL:209:EVP_MAC_ctrl
|
||||
EVP_F_EVP_MAC_CTRL_STR:210:EVP_MAC_ctrl_str
|
||||
EVP_F_EVP_MAC_CTX_COPY:211:EVP_MAC_CTX_copy
|
||||
EVP_F_EVP_MAC_CTX_DUP:211:EVP_MAC_CTX_dup
|
||||
EVP_F_EVP_MAC_CTX_NEW:213:EVP_MAC_CTX_new
|
||||
EVP_F_EVP_MAC_INIT:212:EVP_MAC_init
|
||||
EVP_F_EVP_MD_BLOCK_SIZE:232:EVP_MD_block_size
|
||||
@@ -879,11 +883,13 @@ EVP_F_PKCS5_V2_PBE_KEYIVGEN:118:PKCS5_v2_PBE_keyivgen
|
||||
EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN:164:PKCS5_v2_PBKDF2_keyivgen
|
||||
EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN:180:PKCS5_v2_scrypt_keyivgen
|
||||
EVP_F_PKEY_KDF_CTRL:227:pkey_kdf_ctrl
|
||||
EVP_F_PKEY_MAC_COPY:241:pkey_mac_copy
|
||||
EVP_F_PKEY_MAC_INIT:214:pkey_mac_init
|
||||
EVP_F_PKEY_SET_TYPE:158:pkey_set_type
|
||||
EVP_F_POLY1305_CTRL:216:poly1305_ctrl
|
||||
EVP_F_RC2_MAGIC_TO_METH:109:rc2_magic_to_meth
|
||||
EVP_F_RC5_CTRL:125:rc5_ctrl
|
||||
EVP_F_R_32_12_16_INIT_KEY:242:r_32_12_16_init_key
|
||||
EVP_F_S390X_AES_GCM_CTRL:201:s390x_aes_gcm_ctrl
|
||||
EVP_F_S390X_AES_GCM_TLS_CIPHER:208:s390x_aes_gcm_tls_cipher
|
||||
EVP_F_SCRYPT_ALG:228:scrypt_alg
|
||||
@@ -893,6 +899,7 @@ KDF_F_KDF_HKDF_DERIVE:113:kdf_hkdf_derive
|
||||
KDF_F_KDF_HKDF_NEW:114:kdf_hkdf_new
|
||||
KDF_F_KDF_HKDF_SIZE:115:kdf_hkdf_size
|
||||
KDF_F_KDF_MD2CTRL:116:kdf_md2ctrl
|
||||
KDF_F_KDF_PBKDF2_CTRL:140:kdf_pbkdf2_ctrl
|
||||
KDF_F_KDF_PBKDF2_CTRL_STR:117:kdf_pbkdf2_ctrl_str
|
||||
KDF_F_KDF_PBKDF2_DERIVE:118:kdf_pbkdf2_derive
|
||||
KDF_F_KDF_PBKDF2_NEW:119:kdf_pbkdf2_new
|
||||
@@ -908,6 +915,7 @@ KDF_F_KDF_SSHKDF_NEW:133:kdf_sshkdf_new
|
||||
KDF_F_KDF_TLS1_PRF_CTRL_STR:125:kdf_tls1_prf_ctrl_str
|
||||
KDF_F_KDF_TLS1_PRF_DERIVE:126:kdf_tls1_prf_derive
|
||||
KDF_F_KDF_TLS1_PRF_NEW:127:kdf_tls1_prf_new
|
||||
KDF_F_PBKDF2_DERIVE:141:pbkdf2_derive
|
||||
KDF_F_PBKDF2_SET_MEMBUF:128:pbkdf2_set_membuf
|
||||
KDF_F_PKEY_HKDF_CTRL_STR:103:pkey_hkdf_ctrl_str
|
||||
KDF_F_PKEY_HKDF_DERIVE:102:pkey_hkdf_derive
|
||||
@@ -927,6 +935,11 @@ KDF_F_SSKDF_MAC2CTRL:136:sskdf_mac2ctrl
|
||||
KDF_F_SSKDF_NEW:137:sskdf_new
|
||||
KDF_F_SSKDF_SIZE:138:sskdf_size
|
||||
KDF_F_TLS1_PRF_ALG:111:tls1_prf_alg
|
||||
KDF_F_X942KDF_CTRL:142:x942kdf_ctrl
|
||||
KDF_F_X942KDF_DERIVE:143:x942kdf_derive
|
||||
KDF_F_X942KDF_HASH_KDM:144:x942kdf_hash_kdm
|
||||
KDF_F_X942KDF_NEW:145:x942kdf_new
|
||||
KDF_F_X942KDF_SIZE:146:x942kdf_size
|
||||
KDF_F_X963KDF_DERIVE:139:x963kdf_derive
|
||||
OBJ_F_OBJ_ADD_OBJECT:105:OBJ_add_object
|
||||
OBJ_F_OBJ_ADD_SIGID:107:OBJ_add_sigid
|
||||
@@ -1132,6 +1145,7 @@ RAND_F_DRBG_GET_ENTROPY:105:drbg_get_entropy
|
||||
RAND_F_DRBG_SETUP:117:drbg_setup
|
||||
RAND_F_GET_ENTROPY:106:get_entropy
|
||||
RAND_F_RAND_BYTES:100:RAND_bytes
|
||||
RAND_F_RAND_BYTES_EX:126:rand_bytes_ex
|
||||
RAND_F_RAND_DRBG_ENABLE_LOCKING:119:rand_drbg_enable_locking
|
||||
RAND_F_RAND_DRBG_GENERATE:107:RAND_DRBG_generate
|
||||
RAND_F_RAND_DRBG_GET_ENTROPY:120:rand_drbg_get_entropy
|
||||
@@ -1825,6 +1839,7 @@ X509_F_BUILD_CHAIN:106:build_chain
|
||||
X509_F_BY_FILE_CTRL:101:by_file_ctrl
|
||||
X509_F_CHECK_NAME_CONSTRAINTS:149:check_name_constraints
|
||||
X509_F_CHECK_POLICY:145:check_policy
|
||||
X509_F_COMMON_VERIFY_SM2:165:common_verify_sm2
|
||||
X509_F_DANE_I2D:107:dane_i2d
|
||||
X509_F_DIR_CTRL:102:dir_ctrl
|
||||
X509_F_GET_CERT_BY_SUBJECT:103:get_cert_by_subject
|
||||
@@ -1868,6 +1883,8 @@ X509_F_X509_REQ_CHECK_PRIVATE_KEY:144:X509_REQ_check_private_key
|
||||
X509_F_X509_REQ_PRINT_EX:121:X509_REQ_print_ex
|
||||
X509_F_X509_REQ_PRINT_FP:122:X509_REQ_print_fp
|
||||
X509_F_X509_REQ_TO_X509:123:X509_REQ_to_X509
|
||||
X509_F_X509_REQ_VERIFY:163:X509_REQ_verify
|
||||
X509_F_X509_REQ_VERIFY_SM2:164:x509_req_verify_sm2
|
||||
X509_F_X509_STORE_ADD_CERT:124:X509_STORE_add_cert
|
||||
X509_F_X509_STORE_ADD_CRL:125:X509_STORE_add_crl
|
||||
X509_F_X509_STORE_ADD_LOOKUP:157:X509_STORE_add_lookup
|
||||
@@ -2056,11 +2073,13 @@ BN_R_NOT_A_SQUARE:111:not a square
|
||||
BN_R_NOT_INITIALIZED:107:not initialized
|
||||
BN_R_NO_INVERSE:108:no inverse
|
||||
BN_R_NO_SOLUTION:116:no solution
|
||||
BN_R_NO_SUITABLE_DIGEST:120:no suitable digest
|
||||
BN_R_PRIVATE_KEY_TOO_LARGE:117:private key too large
|
||||
BN_R_P_IS_NOT_PRIME:112:p is not prime
|
||||
BN_R_TOO_MANY_ITERATIONS:113:too many iterations
|
||||
BN_R_TOO_MANY_TEMPORARY_VARIABLES:109:too many temporary variables
|
||||
CMS_R_ADD_SIGNER_ERROR:99:add signer error
|
||||
CMS_R_ATTRIBUTE_ERROR:161:attribute error
|
||||
CMS_R_CERTIFICATE_ALREADY_PRESENT:175:certificate already present
|
||||
CMS_R_CERTIFICATE_HAS_NO_KEYID:160:certificate has no keyid
|
||||
CMS_R_CERTIFICATE_VERIFY_ERROR:100:certificate verify error
|
||||
@@ -2373,6 +2392,7 @@ ESS_R_ESS_SIGNING_CERT_V2_ADD_ERROR:101:ess signing cert v2 add error
|
||||
EVP_R_AES_KEY_SETUP_FAILED:143:aes key setup failed
|
||||
EVP_R_ARIA_KEY_SETUP_FAILED:176:aria key setup failed
|
||||
EVP_R_BAD_DECRYPT:100:bad decrypt
|
||||
EVP_R_BAD_KEY_LENGTH:195:bad key length
|
||||
EVP_R_BUFFER_TOO_SMALL:155:buffer too small
|
||||
EVP_R_CAMELLIA_KEY_SETUP_FAILED:157:camellia key setup failed
|
||||
EVP_R_CIPHER_NOT_GCM_MODE:184:cipher not gcm mode
|
||||
@@ -2425,7 +2445,7 @@ EVP_R_NO_OPERATION_SET:149:no operation set
|
||||
EVP_R_ONLY_ONESHOT_SUPPORTED:177:only oneshot supported
|
||||
EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE:150:\
|
||||
operation not supported for this keytype
|
||||
EVP_R_OPERATON_NOT_INITIALIZED:151:operaton not initialized
|
||||
EVP_R_OPERATON_NOT_INITIALIZED:151:operation not initialized
|
||||
EVP_R_PARAMETER_TOO_LARGE:187:parameter too large
|
||||
EVP_R_PARTIALLY_OVERLAPPING:162:partially overlapping buffers
|
||||
EVP_R_PBKDF2_ERROR:181:pbkdf2 error
|
||||
@@ -2454,8 +2474,15 @@ EVP_R_WRAP_MODE_NOT_ALLOWED:170:wrap mode not allowed
|
||||
EVP_R_WRONG_FINAL_BLOCK_LENGTH:109:wrong final block length
|
||||
EVP_R_XTS_DATA_UNIT_IS_TOO_LARGE:191:xts data unit is too large
|
||||
EVP_R_XTS_DUPLICATED_KEYS:192:xts duplicated keys
|
||||
KDF_R_BAD_ENCODING:122:bad encoding
|
||||
KDF_R_BAD_LENGTH:123:bad length
|
||||
KDF_R_INAVLID_UKM_LEN:124:inavlid ukm len
|
||||
KDF_R_INVALID_DIGEST:100:invalid digest
|
||||
KDF_R_INVALID_ITERATION_COUNT:119:invalid iteration count
|
||||
KDF_R_INVALID_KEY_LEN:120:invalid key len
|
||||
KDF_R_INVALID_MAC_TYPE:116:invalid mac type
|
||||
KDF_R_INVALID_SALT_LEN:121:invalid salt len
|
||||
KDF_R_MISSING_CEK_ALG:125:missing cek alg
|
||||
KDF_R_MISSING_ITERATION_COUNT:109:missing iteration count
|
||||
KDF_R_MISSING_KEY:104:missing key
|
||||
KDF_R_MISSING_MESSAGE_DIGEST:105:missing message digest
|
||||
@@ -2469,6 +2496,7 @@ KDF_R_MISSING_TYPE:114:missing type
|
||||
KDF_R_MISSING_XCGHASH:115:missing xcghash
|
||||
KDF_R_NOT_SUPPORTED:118:not supported
|
||||
KDF_R_UNKNOWN_PARAMETER_TYPE:103:unknown parameter type
|
||||
KDF_R_UNSUPPORTED_CEK_ALG:126:unsupported cek alg
|
||||
KDF_R_UNSUPPORTED_MAC_TYPE:117:unsupported mac type
|
||||
KDF_R_VALUE_ERROR:108:value error
|
||||
KDF_R_VALUE_MISSING:102:value missing
|
||||
@@ -3207,6 +3235,7 @@ X509_R_CERT_ALREADY_IN_HASH_TABLE:101:cert already in hash table
|
||||
X509_R_CRL_ALREADY_DELTA:127:crl already delta
|
||||
X509_R_CRL_VERIFY_FAILURE:131:crl verify failure
|
||||
X509_R_IDP_MISMATCH:128:idp mismatch
|
||||
X509_R_INVALID_ATTRIBUTES:138:invalid attributes
|
||||
X509_R_INVALID_DIRECTORY:113:invalid directory
|
||||
X509_R_INVALID_FIELD_NAME:119:invalid field name
|
||||
X509_R_INVALID_TRUST:123:invalid trust
|
||||
|
||||
+2
-2
@@ -38,9 +38,9 @@
|
||||
of memory.
|
||||
|
||||
BIO_f_reliable splits data stream into blocks. Each block is prefixed
|
||||
with it's length and suffixed with it's digest. So you need only
|
||||
with its length and suffixed with its digest. So you need only
|
||||
several Kbytes of memory to buffer single block before verifying
|
||||
it's digest.
|
||||
its digest.
|
||||
|
||||
BIO_f_reliable goes further and adds several important capabilities:
|
||||
|
||||
|
||||
+6
-12
@@ -1,6 +1,7 @@
|
||||
LIBS=../../libcrypto
|
||||
SOURCE[../../libcrypto]=\
|
||||
encode.c digest.c evp_enc.c evp_key.c evp_cnf.c \
|
||||
$COMMON=digest.c evp_enc.c evp_lib.c evp_fetch.c cmeth_lib.c evp_utils.c
|
||||
SOURCE[../../libcrypto]=$COMMON\
|
||||
encode.c evp_key.c evp_cnf.c \
|
||||
e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\
|
||||
e_rc4.c e_aes.c names.c e_seed.c e_aria.c e_sm4.c \
|
||||
e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
|
||||
@@ -8,21 +9,14 @@ SOURCE[../../libcrypto]=\
|
||||
m_md5_sha1.c m_mdc2.c m_ripemd.c m_sha3.c \
|
||||
p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
|
||||
bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
|
||||
c_allc.c c_alld.c evp_lib.c bio_ok.c \
|
||||
c_allc.c c_alld.c bio_ok.c \
|
||||
evp_pkey.c kdf_lib.c evp_pbe.c p5_crpt.c p5_crpt2.c pbe_scrypt.c \
|
||||
pkey_kdf.c c_allkdf.c \
|
||||
e_old.c pmeth_lib.c pmeth_fn.c pmeth_gn.c m_sigver.c \
|
||||
e_aes_cbc_hmac_sha1.c e_aes_cbc_hmac_sha256.c e_rc4_hmac_md5.c \
|
||||
e_chacha20_poly1305.c cmeth_lib.c \
|
||||
e_chacha20_poly1305.c \
|
||||
mac_lib.c c_allm.c pkey_mac.c
|
||||
|
||||
# New design
|
||||
SOURCE[../../libcrypto]=\
|
||||
evp_fetch.c
|
||||
|
||||
# FIPS Module
|
||||
SOURCE[../../providers/fips]=\
|
||||
digest.c evp_enc.c evp_lib.c evp_fetch.c cmeth_lib.c
|
||||
SOURCE[../../providers/fips]=$COMMON
|
||||
|
||||
INCLUDE[e_aes.o]=.. ../modes
|
||||
INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes
|
||||
|
||||
@@ -21,4 +21,7 @@ void openssl_add_all_kdfs_int(void)
|
||||
EVP_add_kdf(&sshkdf_kdf_meth);
|
||||
EVP_add_kdf(&ss_kdf_meth);
|
||||
EVP_add_kdf(&x963_kdf_meth);
|
||||
#ifndef OPENSSL_NO_CMS
|
||||
EVP_add_kdf(&x942_kdf_meth);
|
||||
#endif
|
||||
}
|
||||
@@ -60,7 +60,7 @@ void EVP_CIPHER_meth_free(EVP_CIPHER *cipher)
|
||||
}
|
||||
}
|
||||
|
||||
int EVP_CIPHER_upref(EVP_CIPHER *cipher)
|
||||
int EVP_CIPHER_up_ref(EVP_CIPHER *cipher)
|
||||
{
|
||||
int ref = 0;
|
||||
|
||||
|
||||
+125
-61
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -8,10 +8,12 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/engine.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/provider.h"
|
||||
#include "evp_locl.h"
|
||||
@@ -127,6 +129,16 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
(type == NULL || (type->type == ctx->digest->type)))
|
||||
goto skip_to_init;
|
||||
|
||||
if (type != NULL) {
|
||||
/*
|
||||
* Ensure an ENGINE left lying around from last time is cleared (the
|
||||
* previous check attempted to avoid this if the same ENGINE and
|
||||
* EVP_MD could be used).
|
||||
*/
|
||||
ENGINE_finish(ctx->engine);
|
||||
ctx->engine = NULL;
|
||||
}
|
||||
|
||||
if (type != NULL && impl == NULL)
|
||||
tmpimpl = ENGINE_get_digest_engine(type->type);
|
||||
#endif
|
||||
@@ -149,16 +161,6 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
goto legacy;
|
||||
}
|
||||
|
||||
if (type->prov == NULL) {
|
||||
switch(type->type) {
|
||||
case NID_sha256:
|
||||
case NID_md2:
|
||||
break;
|
||||
default:
|
||||
goto legacy;
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx->digest != NULL && ctx->digest->ctx_size > 0) {
|
||||
OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
|
||||
ctx->md_data = NULL;
|
||||
@@ -184,6 +186,11 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ctx->provctx != NULL && ctx->digest != NULL && ctx->digest != type) {
|
||||
if (ctx->digest->freectx != NULL)
|
||||
ctx->digest->freectx(ctx->provctx);
|
||||
ctx->provctx = NULL;
|
||||
}
|
||||
ctx->digest = type;
|
||||
if (ctx->provctx == NULL) {
|
||||
ctx->provctx = ctx->digest->newctx(ossl_provider_ctx(type->prov));
|
||||
@@ -205,12 +212,6 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
|
||||
|
||||
#if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODE)
|
||||
if (type) {
|
||||
/*
|
||||
* Ensure an ENGINE left lying around from last time is cleared (the
|
||||
* previous check attempted to avoid this if the same ENGINE and
|
||||
* EVP_MD could be used).
|
||||
*/
|
||||
ENGINE_finish(ctx->engine);
|
||||
if (impl != NULL) {
|
||||
if (!ENGINE_init(impl)) {
|
||||
EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);
|
||||
@@ -334,7 +335,6 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
|
||||
}
|
||||
|
||||
EVP_MD_CTX_reset(ctx);
|
||||
|
||||
return ret;
|
||||
|
||||
/* TODO(3.0): Remove legacy code below */
|
||||
@@ -354,12 +354,30 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize)
|
||||
int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t size)
|
||||
{
|
||||
int ret = 0;
|
||||
OSSL_PARAM params[2];
|
||||
size_t i = 0;
|
||||
|
||||
if (ctx->digest == NULL || ctx->digest->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
if (ctx->digest->dfinal == NULL) {
|
||||
EVPerr(EVP_F_EVP_DIGESTFINALXOF, EVP_R_FINAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
params[i++] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN, &size);
|
||||
params[i++] = OSSL_PARAM_construct_end();
|
||||
|
||||
if (EVP_MD_CTX_set_params(ctx, params) > 0)
|
||||
ret = ctx->digest->dfinal(ctx->provctx, md, &size, size);
|
||||
EVP_MD_CTX_reset(ctx);
|
||||
return ret;
|
||||
|
||||
legacy:
|
||||
if (ctx->digest->flags & EVP_MD_FLAG_XOF
|
||||
&& size <= INT_MAX
|
||||
&& ctx->digest->md_ctrl(ctx, EVP_MD_CTRL_XOF_LEN, (int)size, NULL)) {
|
||||
ret = ctx->digest->final(ctx, md);
|
||||
|
||||
if (ctx->digest->cleanup != NULL) {
|
||||
ctx->digest->cleanup(ctx);
|
||||
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
|
||||
@@ -404,7 +422,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
|
||||
out->provctx = NULL;
|
||||
|
||||
if (in->fetched_digest != NULL)
|
||||
EVP_MD_upref(in->fetched_digest);
|
||||
EVP_MD_up_ref(in->fetched_digest);
|
||||
|
||||
out->provctx = in->digest->dupctx(in->provctx);
|
||||
if (out->provctx == NULL) {
|
||||
@@ -506,13 +524,55 @@ int EVP_Digest(const void *data, size_t count,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[])
|
||||
{
|
||||
if (ctx->digest != NULL && ctx->digest->set_params != NULL)
|
||||
return ctx->digest->set_params(ctx->provctx, params);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[])
|
||||
{
|
||||
if (ctx->digest != NULL && ctx->digest->get_params != NULL)
|
||||
return ctx->digest->get_params(ctx->provctx, params);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO(3.0): Remove legacy code below - only used by engines & DigestSign */
|
||||
int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
{
|
||||
if (ctx->digest && ctx->digest->md_ctrl) {
|
||||
int ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2);
|
||||
if (ret <= 0)
|
||||
if (ctx->digest != NULL) {
|
||||
if (ctx->digest->prov != NULL) {
|
||||
OSSL_PARAM params[2];
|
||||
size_t i, n = 0;
|
||||
|
||||
switch (cmd) {
|
||||
case EVP_MD_CTRL_XOF_LEN:
|
||||
if (ctx->digest->set_params == NULL)
|
||||
break;
|
||||
i = (size_t)p1;
|
||||
params[n++] =
|
||||
OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN, &i);
|
||||
params[n++] = OSSL_PARAM_construct_end();
|
||||
return ctx->digest->set_params(ctx->provctx, params);
|
||||
case EVP_MD_CTRL_MICALG:
|
||||
if (ctx->digest->get_params == NULL)
|
||||
break;
|
||||
params[n++] =
|
||||
OSSL_PARAM_construct_utf8_string(OSSL_DIGEST_PARAM_MICALG,
|
||||
p2, p1 ? p1 : 9999);
|
||||
params[n++] = OSSL_PARAM_construct_end();
|
||||
return ctx->digest->get_params(ctx->provctx, params);
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
/* legacy code */
|
||||
if (ctx->digest->md_ctrl != NULL) {
|
||||
int ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2);
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -530,55 +590,59 @@ static void *evp_md_from_dispatch(const OSSL_DISPATCH *fns,
|
||||
for (; fns->function_id != 0; fns++) {
|
||||
switch (fns->function_id) {
|
||||
case OSSL_FUNC_DIGEST_NEWCTX:
|
||||
if (md->newctx != NULL)
|
||||
break;
|
||||
md->newctx = OSSL_get_OP_digest_newctx(fns);
|
||||
fncnt++;
|
||||
if (md->newctx == NULL) {
|
||||
md->newctx = OSSL_get_OP_digest_newctx(fns);
|
||||
fncnt++;
|
||||
}
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_INIT:
|
||||
if (md->dinit != NULL)
|
||||
break;
|
||||
md->dinit = OSSL_get_OP_digest_init(fns);
|
||||
fncnt++;
|
||||
if (md->dinit == NULL) {
|
||||
md->dinit = OSSL_get_OP_digest_init(fns);
|
||||
fncnt++;
|
||||
}
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_UPDATE:
|
||||
if (md->dupdate != NULL)
|
||||
break;
|
||||
md->dupdate = OSSL_get_OP_digest_update(fns);
|
||||
fncnt++;
|
||||
if (md->dupdate == NULL) {
|
||||
md->dupdate = OSSL_get_OP_digest_update(fns);
|
||||
fncnt++;
|
||||
}
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_FINAL:
|
||||
if (md->dfinal != NULL)
|
||||
break;
|
||||
md->dfinal = OSSL_get_OP_digest_final(fns);
|
||||
fncnt++;
|
||||
if (md->dfinal == NULL) {
|
||||
md->dfinal = OSSL_get_OP_digest_final(fns);
|
||||
fncnt++;
|
||||
}
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_DIGEST:
|
||||
if (md->digest != NULL)
|
||||
break;
|
||||
md->digest = OSSL_get_OP_digest_digest(fns);
|
||||
if (md->digest == NULL)
|
||||
md->digest = OSSL_get_OP_digest_digest(fns);
|
||||
/* We don't increment fnct for this as it is stand alone */
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_FREECTX:
|
||||
if (md->freectx != NULL)
|
||||
break;
|
||||
md->freectx = OSSL_get_OP_digest_freectx(fns);
|
||||
fncnt++;
|
||||
if (md->freectx == NULL) {
|
||||
md->freectx = OSSL_get_OP_digest_freectx(fns);
|
||||
fncnt++;
|
||||
}
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_DUPCTX:
|
||||
if (md->dupctx != NULL)
|
||||
break;
|
||||
md->dupctx = OSSL_get_OP_digest_dupctx(fns);
|
||||
if (md->dupctx == NULL)
|
||||
md->dupctx = OSSL_get_OP_digest_dupctx(fns);
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_SIZE:
|
||||
if (md->size != NULL)
|
||||
break;
|
||||
md->size = OSSL_get_OP_digest_size(fns);
|
||||
if (md->size == NULL)
|
||||
md->size = OSSL_get_OP_digest_size(fns);
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_BLOCK_SIZE:
|
||||
if (md->dblock_size != NULL)
|
||||
break;
|
||||
md->dblock_size = OSSL_get_OP_digest_block_size(fns);
|
||||
if (md->dblock_size == NULL)
|
||||
md->dblock_size = OSSL_get_OP_digest_block_size(fns);
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_SET_PARAMS:
|
||||
if (md->set_params == NULL)
|
||||
md->set_params = OSSL_get_OP_digest_set_params(fns);
|
||||
break;
|
||||
case OSSL_FUNC_DIGEST_GET_PARAMS:
|
||||
if (md->get_params == NULL)
|
||||
md->get_params = OSSL_get_OP_digest_get_params(fns);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -596,14 +660,14 @@ static void *evp_md_from_dispatch(const OSSL_DISPATCH *fns,
|
||||
}
|
||||
md->prov = prov;
|
||||
if (prov != NULL)
|
||||
ossl_provider_upref(prov);
|
||||
ossl_provider_up_ref(prov);
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
static int evp_md_upref(void *md)
|
||||
static int evp_md_up_ref(void *md)
|
||||
{
|
||||
return EVP_MD_upref(md);
|
||||
return EVP_MD_up_ref(md);
|
||||
}
|
||||
|
||||
static void evp_md_free(void *md)
|
||||
@@ -616,7 +680,7 @@ EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
||||
{
|
||||
EVP_MD *md =
|
||||
evp_generic_fetch(ctx, OSSL_OP_DIGEST, algorithm, properties,
|
||||
evp_md_from_dispatch, evp_md_upref,
|
||||
evp_md_from_dispatch, evp_md_up_ref,
|
||||
evp_md_free);
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
|
||||
+24
-9
@@ -7,18 +7,19 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <openssl/aes.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "modes_lcl.h"
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/cmac.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/modes_int.h"
|
||||
#include "modes_lcl.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
typedef struct {
|
||||
@@ -63,6 +64,12 @@ typedef struct {
|
||||
const unsigned char iv[16]);
|
||||
} EVP_AES_XTS_CTX;
|
||||
|
||||
#ifdef FIPS_MODE
|
||||
static const int allow_insecure_decrypt = 0;
|
||||
#else
|
||||
static const int allow_insecure_decrypt = 1;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
OSSL_UNION_ALIGN;
|
||||
@@ -387,6 +394,7 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
EVP_AES_XTS_CTX *xctx = EVP_C_DATA(EVP_AES_XTS_CTX,ctx);
|
||||
|
||||
if (!iv && !key)
|
||||
return 1;
|
||||
|
||||
@@ -401,7 +409,8 @@ static int aesni_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
* This addresses Rogaway's vulnerability.
|
||||
* See comment in aes_xts_init_key() below.
|
||||
*/
|
||||
if (memcmp(key, key + bytes, bytes) == 0) {
|
||||
if ((!allow_insecure_decrypt || enc)
|
||||
&& CRYPTO_memcmp(key, key + bytes, bytes) == 0) {
|
||||
EVPerr(EVP_F_AESNI_XTS_INIT_KEY, EVP_R_XTS_DUPLICATED_KEYS);
|
||||
return 0;
|
||||
}
|
||||
@@ -804,6 +813,7 @@ static int aes_t4_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
EVP_AES_XTS_CTX *xctx = EVP_C_DATA(EVP_AES_XTS_CTX,ctx);
|
||||
|
||||
if (!iv && !key)
|
||||
return 1;
|
||||
|
||||
@@ -818,7 +828,8 @@ static int aes_t4_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
* This addresses Rogaway's vulnerability.
|
||||
* See comment in aes_xts_init_key() below.
|
||||
*/
|
||||
if (memcmp(key, key + bytes, bytes) == 0) {
|
||||
if ((!allow_insecure_decrypt || enc)
|
||||
&& CRYPTO_memcmp(key, key + bytes, bytes) == 0) {
|
||||
EVPerr(EVP_F_AES_T4_XTS_INIT_KEY, EVP_R_XTS_DUPLICATED_KEYS);
|
||||
return 0;
|
||||
}
|
||||
@@ -3408,10 +3419,12 @@ BLOCK_CIPHER_custom(NID_aes, 128, 1, 12, gcm, GCM,
|
||||
|
||||
static int aes_xts_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
{
|
||||
EVP_AES_XTS_CTX *xctx = EVP_C_DATA(EVP_AES_XTS_CTX,c);
|
||||
EVP_AES_XTS_CTX *xctx = EVP_C_DATA(EVP_AES_XTS_CTX, c);
|
||||
|
||||
if (type == EVP_CTRL_COPY) {
|
||||
EVP_CIPHER_CTX *out = ptr;
|
||||
EVP_AES_XTS_CTX *xctx_out = EVP_C_DATA(EVP_AES_XTS_CTX,out);
|
||||
|
||||
if (xctx->xts.key1) {
|
||||
if (xctx->xts.key1 != &xctx->ks1)
|
||||
return 0;
|
||||
@@ -3435,6 +3448,7 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
EVP_AES_XTS_CTX *xctx = EVP_C_DATA(EVP_AES_XTS_CTX,ctx);
|
||||
|
||||
if (!iv && !key)
|
||||
return 1;
|
||||
|
||||
@@ -3460,7 +3474,8 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
* BEFORE using the keys in the XTS-AES algorithm to process
|
||||
* data with them."
|
||||
*/
|
||||
if (memcmp(key, key + bytes, bytes) == 0) {
|
||||
if ((!allow_insecure_decrypt || enc)
|
||||
&& CRYPTO_memcmp(key, key + bytes, bytes) == 0) {
|
||||
EVPerr(EVP_F_AES_XTS_INIT_KEY, EVP_R_XTS_DUPLICATED_KEYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-3
@@ -66,9 +66,12 @@ static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
|
||||
static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const unsigned char *iv, int enc)
|
||||
{
|
||||
RC5_32_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx),
|
||||
key, data(ctx)->rounds);
|
||||
return 1;
|
||||
if (EVP_CIPHER_CTX_key_length(ctx) > 255) {
|
||||
EVPerr(EVP_F_R_32_12_16_INIT_KEY, EVP_R_BAD_KEY_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
return RC5_32_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx),
|
||||
key, data(ctx)->rounds);
|
||||
}
|
||||
|
||||
#endif
|
||||
+44
-43
@@ -920,6 +920,14 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
|
||||
int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
|
||||
{
|
||||
int ok = evp_do_param(c->cipher, &keylen, sizeof(keylen),
|
||||
OSSL_CIPHER_PARAM_KEYLEN, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_setparams, c->provctx);
|
||||
|
||||
if (ok != -2)
|
||||
return ok;
|
||||
|
||||
/* TODO(3.0) legacy code follows */
|
||||
if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
|
||||
return EVP_CIPHER_CTX_ctrl(c, EVP_CTRL_SET_KEY_LENGTH, keylen, NULL);
|
||||
if (EVP_CIPHER_CTX_key_length(c) == keylen)
|
||||
@@ -934,40 +942,51 @@ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int keylen)
|
||||
|
||||
int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
|
||||
{
|
||||
int ok;
|
||||
|
||||
if (pad)
|
||||
ctx->flags &= ~EVP_CIPH_NO_PADDING;
|
||||
else
|
||||
ctx->flags |= EVP_CIPH_NO_PADDING;
|
||||
|
||||
if (ctx->cipher != NULL && ctx->cipher->prov != NULL) {
|
||||
OSSL_PARAM params[] = {
|
||||
OSSL_PARAM_int(OSSL_CIPHER_PARAM_PADDING, NULL),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
params[0].data = &pad;
|
||||
|
||||
if (ctx->cipher->ctx_set_params == NULL) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_CTX_SET_PADDING, EVP_R_CTRL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ctx->cipher->ctx_set_params(ctx->provctx, params))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
ok = evp_do_param(ctx->cipher, &pad, sizeof(pad),
|
||||
OSSL_CIPHER_PARAM_PADDING, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_setparams, ctx->provctx);
|
||||
return ok != 0;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
|
||||
{
|
||||
int ret;
|
||||
int ret = -2; /* Unsupported */
|
||||
|
||||
if (!ctx->cipher) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_NO_CIPHER_SET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher->prov == NULL)
|
||||
goto legacy;
|
||||
|
||||
switch (type) {
|
||||
case EVP_CTRL_SET_KEY_LENGTH:
|
||||
ret = evp_do_param(ctx->cipher, &arg, sizeof(arg),
|
||||
OSSL_CIPHER_PARAM_KEYLEN, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_setparams, ctx->provctx);
|
||||
break;
|
||||
case EVP_CTRL_GET_IV:
|
||||
ret = evp_do_param(ctx->cipher, ptr, arg,
|
||||
OSSL_CIPHER_PARAM_IV, OSSL_PARAM_OCTET_STRING,
|
||||
evp_do_ciph_ctx_getparams, ctx->provctx);
|
||||
break;
|
||||
case EVP_CTRL_RAND_KEY: /* Used by DES */
|
||||
case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: /* Used by DASYNC */
|
||||
case EVP_CTRL_INIT: /* TODO(3.0) Purely legacy, no provider counterpart */
|
||||
ret = -2; /* Unsupported */
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
|
||||
legacy:
|
||||
if (!ctx->cipher->ctrl) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_CTX_CTRL, EVP_R_CTRL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
@@ -1016,7 +1035,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
||||
*out = *in;
|
||||
out->provctx = NULL;
|
||||
|
||||
if (in->fetched_cipher != NULL && !EVP_CIPHER_upref(in->fetched_cipher)) {
|
||||
if (in->fetched_cipher != NULL && !EVP_CIPHER_up_ref(in->fetched_cipher)) {
|
||||
out->fetched_cipher = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -1123,21 +1142,6 @@ static void *evp_cipher_from_dispatch(const OSSL_DISPATCH *fns,
|
||||
break;
|
||||
cipher->dupctx = OSSL_get_OP_cipher_dupctx(fns);
|
||||
break;
|
||||
case OSSL_FUNC_CIPHER_KEY_LENGTH:
|
||||
if (cipher->key_length != NULL)
|
||||
break;
|
||||
cipher->key_length = OSSL_get_OP_cipher_key_length(fns);
|
||||
break;
|
||||
case OSSL_FUNC_CIPHER_IV_LENGTH:
|
||||
if (cipher->iv_length != NULL)
|
||||
break;
|
||||
cipher->iv_length = OSSL_get_OP_cipher_iv_length(fns);
|
||||
break;
|
||||
case OSSL_FUNC_CIPHER_BLOCK_SIZE:
|
||||
if (cipher->blocksize != NULL)
|
||||
break;
|
||||
cipher->blocksize = OSSL_get_OP_cipher_block_size(fns);
|
||||
break;
|
||||
case OSSL_FUNC_CIPHER_GET_PARAMS:
|
||||
if (cipher->get_params != NULL)
|
||||
break;
|
||||
@@ -1157,10 +1161,7 @@ static void *evp_cipher_from_dispatch(const OSSL_DISPATCH *fns,
|
||||
}
|
||||
if ((fnciphcnt != 0 && fnciphcnt != 3 && fnciphcnt != 4)
|
||||
|| (fnciphcnt == 0 && cipher->ccipher == NULL)
|
||||
|| fnctxcnt != 2
|
||||
|| cipher->blocksize == NULL
|
||||
|| cipher->iv_length == NULL
|
||||
|| cipher->key_length == NULL) {
|
||||
|| fnctxcnt != 2) {
|
||||
/*
|
||||
* In order to be a consistent set of functions we must have at least
|
||||
* a complete set of "encrypt" functions, or a complete set of "decrypt"
|
||||
@@ -1174,14 +1175,14 @@ static void *evp_cipher_from_dispatch(const OSSL_DISPATCH *fns,
|
||||
}
|
||||
cipher->prov = prov;
|
||||
if (prov != NULL)
|
||||
ossl_provider_upref(prov);
|
||||
ossl_provider_up_ref(prov);
|
||||
|
||||
return cipher;
|
||||
}
|
||||
|
||||
static int evp_cipher_upref(void *cipher)
|
||||
static int evp_cipher_up_ref(void *cipher)
|
||||
{
|
||||
return EVP_CIPHER_upref(cipher);
|
||||
return EVP_CIPHER_up_ref(cipher);
|
||||
}
|
||||
|
||||
static void evp_cipher_free(void *cipher)
|
||||
@@ -1194,7 +1195,7 @@ EVP_CIPHER *EVP_CIPHER_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
||||
{
|
||||
EVP_CIPHER *cipher =
|
||||
evp_generic_fetch(ctx, OSSL_OP_CIPHER, algorithm, properties,
|
||||
evp_cipher_from_dispatch, evp_cipher_upref,
|
||||
evp_cipher_from_dispatch, evp_cipher_up_ref,
|
||||
evp_cipher_free);
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
|
||||
@@ -78,7 +78,7 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_KDF_CTX_NEW_ID, 0), "EVP_KDF_CTX_new_id"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTRL, 0), "EVP_MAC_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTRL_STR, 0), "EVP_MAC_ctrl_str"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTX_COPY, 0), "EVP_MAC_CTX_copy"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTX_DUP, 0), "EVP_MAC_CTX_dup"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_CTX_NEW, 0), "EVP_MAC_CTX_new"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MAC_INIT, 0), "EVP_MAC_init"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_MD_BLOCK_SIZE, 0), "EVP_MD_block_size"},
|
||||
@@ -179,11 +179,14 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_PKCS5_V2_SCRYPT_KEYIVGEN, 0),
|
||||
"PKCS5_v2_scrypt_keyivgen"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_PKEY_KDF_CTRL, 0), "pkey_kdf_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_PKEY_MAC_COPY, 0), "pkey_mac_copy"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_PKEY_MAC_INIT, 0), "pkey_mac_init"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_PKEY_SET_TYPE, 0), "pkey_set_type"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_POLY1305_CTRL, 0), "poly1305_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_RC2_MAGIC_TO_METH, 0), "rc2_magic_to_meth"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_RC5_CTRL, 0), "rc5_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_R_32_12_16_INIT_KEY, 0),
|
||||
"r_32_12_16_init_key"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_S390X_AES_GCM_CTRL, 0), "s390x_aes_gcm_ctrl"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_S390X_AES_GCM_TLS_CIPHER, 0),
|
||||
"s390x_aes_gcm_tls_cipher"},
|
||||
@@ -198,6 +201,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_ARIA_KEY_SETUP_FAILED),
|
||||
"aria key setup failed"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BAD_DECRYPT), "bad decrypt"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BAD_KEY_LENGTH), "bad key length"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_CAMELLIA_KEY_SETUP_FAILED),
|
||||
"camellia key setup failed"},
|
||||
@@ -280,7 +284,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE),
|
||||
"operation not supported for this keytype"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_OPERATON_NOT_INITIALIZED),
|
||||
"operaton not initialized"},
|
||||
"operation not initialized"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PARAMETER_TOO_LARGE),
|
||||
"parameter too large"},
|
||||
{ERR_PACK(ERR_LIB_EVP, 0, EVP_R_PARTIALLY_OVERLAPPING),
|
||||
|
||||
+72
-21
@@ -39,7 +39,6 @@ static const OPENSSL_CTX_METHOD default_method_store_method = {
|
||||
struct method_data_st {
|
||||
OPENSSL_CTX *libctx;
|
||||
const char *name;
|
||||
int id;
|
||||
OSSL_METHOD_CONSTRUCT_METHOD *mcm;
|
||||
void *(*method_from_dispatch)(const OSSL_DISPATCH *, OSSL_PROVIDER *);
|
||||
int (*refcnt_up_method)(void *method);
|
||||
@@ -66,24 +65,45 @@ static OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx)
|
||||
&default_method_store_method);
|
||||
}
|
||||
|
||||
/*
|
||||
* To identity the method in the method store, we mix the name identity
|
||||
* with the operation identity, with the assumption that we don't have
|
||||
* more than 2^24 names or more than 2^8 operation types.
|
||||
*
|
||||
* The resulting identity is a 32-bit integer, composed like this:
|
||||
*
|
||||
* +---------24 bits--------+-8 bits-+
|
||||
* | name identity | op id |
|
||||
* +------------------------+--------+
|
||||
*/
|
||||
static uint32_t method_id(unsigned int operation_id, unsigned int name_id)
|
||||
{
|
||||
if (!ossl_assert(name_id < (1 << 24) || operation_id < (1 << 8))
|
||||
|| !ossl_assert(name_id > 0 && operation_id > 0))
|
||||
return 0;
|
||||
return ((name_id << 8) & 0xFFFFFF00) | (operation_id & 0x000000FF);
|
||||
}
|
||||
|
||||
static void *get_method_from_store(OPENSSL_CTX *libctx, void *store,
|
||||
const char *name, const char *propquery,
|
||||
void *data)
|
||||
int operation_id, const char *name,
|
||||
const char *propquery, void *data)
|
||||
{
|
||||
struct method_data_st *methdata = data;
|
||||
void *method = NULL;
|
||||
OSSL_NAMEMAP *namemap;
|
||||
int id;
|
||||
int nameid;
|
||||
uint32_t methid;
|
||||
|
||||
if (store == NULL
|
||||
&& (store = get_default_method_store(libctx)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((namemap = ossl_namemap_stored(libctx)) == NULL
|
||||
|| (id = ossl_namemap_add(namemap, name)) == 0)
|
||||
|| (nameid = ossl_namemap_name2num(namemap, name)) == 0
|
||||
|| (methid = method_id(operation_id, nameid)) == 0)
|
||||
return NULL;
|
||||
|
||||
(void)ossl_method_store_fetch(store, id, propquery, &method);
|
||||
(void)ossl_method_store_fetch(store, methid, propquery, &method);
|
||||
|
||||
if (method != NULL
|
||||
&& !methdata->refcnt_up_method(method)) {
|
||||
@@ -93,15 +113,18 @@ static void *get_method_from_store(OPENSSL_CTX *libctx, void *store,
|
||||
}
|
||||
|
||||
static int put_method_in_store(OPENSSL_CTX *libctx, void *store,
|
||||
void *method, const char *name,
|
||||
const char *propdef, void *data)
|
||||
void *method, int operation_id,
|
||||
const char *name, const char *propdef,
|
||||
void *data)
|
||||
{
|
||||
struct method_data_st *methdata = data;
|
||||
OSSL_NAMEMAP *namemap;
|
||||
int id;
|
||||
int nameid;
|
||||
uint32_t methid;
|
||||
|
||||
if ((namemap = ossl_namemap_stored(methdata->libctx)) == NULL
|
||||
|| (id = ossl_namemap_add(namemap, name)) == 0)
|
||||
|| (nameid = ossl_namemap_add(namemap, 0, name)) == 0
|
||||
|| (methid = method_id(operation_id, nameid)) == 0)
|
||||
return 0;
|
||||
|
||||
if (store == NULL
|
||||
@@ -109,7 +132,7 @@ static int put_method_in_store(OPENSSL_CTX *libctx, void *store,
|
||||
return 0;
|
||||
|
||||
if (methdata->refcnt_up_method(method)
|
||||
&& ossl_method_store_add(store, id, propdef, method,
|
||||
&& ossl_method_store_add(store, methid, propdef, method,
|
||||
methdata->destruct_method))
|
||||
return 1;
|
||||
return 0;
|
||||
@@ -134,19 +157,37 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id,
|
||||
const char *name, const char *properties,
|
||||
void *(*new_method)(const OSSL_DISPATCH *fns,
|
||||
OSSL_PROVIDER *prov),
|
||||
int (*upref_method)(void *),
|
||||
int (*up_ref_method)(void *),
|
||||
void (*free_method)(void *))
|
||||
{
|
||||
OSSL_METHOD_STORE *store = get_default_method_store(libctx);
|
||||
OSSL_NAMEMAP *namemap = ossl_namemap_stored(libctx);
|
||||
int id;
|
||||
int nameid = 0;
|
||||
uint32_t methid = 0;
|
||||
void *method = NULL;
|
||||
|
||||
if (store == NULL || namemap == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((id = ossl_namemap_number(namemap, name)) == 0
|
||||
|| !ossl_method_store_cache_get(store, id, properties, &method)) {
|
||||
/*
|
||||
* If there's ever an operation_id == 0 passed, we have an internal
|
||||
* programming error.
|
||||
*/
|
||||
if (!ossl_assert(operation_id > 0))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* method_id returns 0 if we have too many operations (more than
|
||||
* about 2^8) or too many names (more than about 2^24). In that
|
||||
* case, we can't create any new method.
|
||||
*/
|
||||
if ((nameid = ossl_namemap_name2num(namemap, name)) != 0
|
||||
&& (methid = method_id(operation_id, nameid)) == 0)
|
||||
return NULL;
|
||||
|
||||
if (nameid == 0
|
||||
|| !ossl_method_store_cache_get(store, methid, properties,
|
||||
&method)) {
|
||||
OSSL_METHOD_CONSTRUCT_METHOD mcm = {
|
||||
alloc_tmp_method_store,
|
||||
dealloc_tmp_method_store,
|
||||
@@ -159,16 +200,26 @@ void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id,
|
||||
|
||||
mcmdata.mcm = &mcm;
|
||||
mcmdata.libctx = libctx;
|
||||
mcmdata.name = name;
|
||||
mcmdata.method_from_dispatch = new_method;
|
||||
mcmdata.destruct_method = free_method;
|
||||
mcmdata.refcnt_up_method = upref_method;
|
||||
mcmdata.refcnt_up_method = up_ref_method;
|
||||
mcmdata.destruct_method = free_method;
|
||||
method = ossl_method_construct(libctx, operation_id, name,
|
||||
properties, 0 /* !force_cache */,
|
||||
&mcm, &mcmdata);
|
||||
ossl_method_store_cache_set(store, id, properties, method);
|
||||
if ((method = ossl_method_construct(libctx, operation_id, name,
|
||||
properties, 0 /* !force_cache */,
|
||||
&mcm, &mcmdata)) != NULL) {
|
||||
/*
|
||||
* If construction did create a method for us, we know that
|
||||
* there is a correct nameid and methodid, since those have
|
||||
* already been calculated in get_method_from_store() and
|
||||
* put_method_in_store() above.
|
||||
*/
|
||||
nameid = ossl_namemap_name2num(namemap, name);
|
||||
methid = method_id(operation_id, nameid);
|
||||
ossl_method_store_cache_set(store, methid, properties, method);
|
||||
}
|
||||
} else {
|
||||
upref_method(method);
|
||||
up_ref_method(method);
|
||||
}
|
||||
|
||||
return method;
|
||||
|
||||
+61
-53
@@ -217,13 +217,12 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx)
|
||||
|
||||
int EVP_CIPHER_block_size(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher->prov != NULL) {
|
||||
if (cipher->blocksize != NULL)
|
||||
return cipher->blocksize();
|
||||
/* We default to a block size of 1 */
|
||||
return 1;
|
||||
}
|
||||
return cipher->block_size;
|
||||
int v = cipher->block_size;
|
||||
int ok = evp_do_param(cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_getparams, NULL);
|
||||
|
||||
return ok != 0 ? v : -1;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
|
||||
@@ -266,7 +265,12 @@ int EVP_CIPHER_CTX_encrypting(const EVP_CIPHER_CTX *ctx)
|
||||
|
||||
unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher)
|
||||
{
|
||||
return cipher->flags;
|
||||
unsigned long v = cipher->flags;
|
||||
int ok = evp_do_param(cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_FLAGS, OSSL_PARAM_UNSIGNED_INTEGER,
|
||||
evp_do_ciph_getparams, NULL);
|
||||
|
||||
return ok != 0 ? v : 0;
|
||||
}
|
||||
|
||||
void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
|
||||
@@ -296,13 +300,12 @@ void *EVP_CIPHER_CTX_set_cipher_data(EVP_CIPHER_CTX *ctx, void *cipher_data)
|
||||
|
||||
int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher->prov != NULL) {
|
||||
if (cipher->iv_length != NULL)
|
||||
return (int)cipher->iv_length();
|
||||
return 0;
|
||||
}
|
||||
int v = cipher->iv_len;
|
||||
int ok = evp_do_param(cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_IVLEN, OSSL_PARAM_UNSIGNED_INTEGER,
|
||||
evp_do_ciph_getparams, NULL);
|
||||
|
||||
return cipher->iv_len;
|
||||
return ok != 0 ? v: -1;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
|
||||
@@ -315,14 +318,27 @@ const unsigned char *EVP_CIPHER_CTX_original_iv(const EVP_CIPHER_CTX *ctx)
|
||||
return ctx->oiv;
|
||||
}
|
||||
|
||||
/*
|
||||
* OSSL_PARAM_OCTET_PTR gets us the pointer to the running IV in the provider
|
||||
*/
|
||||
const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return ctx->iv;
|
||||
const unsigned char *v = ctx->iv;
|
||||
int ok = evp_do_param(ctx->cipher, &v, sizeof(ctx->iv),
|
||||
OSSL_CIPHER_PARAM_IV, OSSL_PARAM_OCTET_PTR,
|
||||
evp_do_ciph_ctx_getparams, ctx->provctx);
|
||||
|
||||
return ok != 0 ? v: NULL;
|
||||
}
|
||||
|
||||
unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return ctx->iv;
|
||||
unsigned char *v = ctx->iv;
|
||||
int ok = evp_do_param(ctx->cipher, &v, sizeof(ctx->iv),
|
||||
OSSL_CIPHER_PARAM_IV, OSSL_PARAM_OCTET_PTR,
|
||||
evp_do_ciph_ctx_getparams, ctx->provctx);
|
||||
|
||||
return ok != 0 ? v: NULL;
|
||||
}
|
||||
|
||||
unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
|
||||
@@ -332,34 +348,42 @@ unsigned char *EVP_CIPHER_CTX_buf_noconst(EVP_CIPHER_CTX *ctx)
|
||||
|
||||
int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
return ctx->num;
|
||||
int v = ctx->num;
|
||||
int ok = evp_do_param(ctx->cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_NUM, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_getparams, ctx->provctx);
|
||||
|
||||
return ok != 0 ? v: -1;
|
||||
}
|
||||
|
||||
void EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num)
|
||||
int EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num)
|
||||
{
|
||||
int ok = evp_do_param(ctx->cipher, &num, sizeof(num),
|
||||
OSSL_CIPHER_PARAM_NUM, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_setparams, ctx->provctx);
|
||||
|
||||
ctx->num = num;
|
||||
return ok != 0;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher->prov != NULL) {
|
||||
if (cipher->key_length != NULL)
|
||||
return (int)cipher->key_length();
|
||||
return -1;
|
||||
}
|
||||
int v = cipher->key_len;
|
||||
int ok = evp_do_param(cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_KEYLEN, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_getparams, NULL);
|
||||
|
||||
return cipher->key_len;
|
||||
return ok != 0 ? v: -1;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
/*
|
||||
* TODO(3.0): This may need to change if/when we introduce variable length
|
||||
* key ciphers into the providers.
|
||||
*/
|
||||
if (ctx->cipher != NULL && ctx->cipher->prov != NULL)
|
||||
return EVP_CIPHER_key_length(ctx->cipher);
|
||||
return ctx->key_len;
|
||||
int v = ctx->key_len;
|
||||
int ok = evp_do_param(ctx->cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_KEYLEN, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_ctx_getparams, ctx->provctx);
|
||||
|
||||
return ok != 0 ? v: -1;
|
||||
}
|
||||
|
||||
int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
|
||||
@@ -374,28 +398,12 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
|
||||
|
||||
int EVP_CIPHER_mode(const EVP_CIPHER *cipher)
|
||||
{
|
||||
if (cipher->prov != NULL) {
|
||||
int mode;
|
||||
int v = EVP_CIPHER_flags(cipher) & EVP_CIPH_MODE;
|
||||
int ok = evp_do_param(cipher, &v, sizeof(v),
|
||||
OSSL_CIPHER_PARAM_MODE, OSSL_PARAM_INTEGER,
|
||||
evp_do_ciph_getparams, NULL);
|
||||
|
||||
/* Cipher comes from a provider - so ask the provider for the mode */
|
||||
OSSL_PARAM params[] = {
|
||||
OSSL_PARAM_int(OSSL_CIPHER_PARAM_MODE, NULL),
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
|
||||
params[0].data = &mode;
|
||||
|
||||
if (cipher->get_params == NULL) {
|
||||
EVPerr(EVP_F_EVP_CIPHER_MODE, EVP_R_CTRL_NOT_IMPLEMENTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!cipher->get_params(params))
|
||||
return 0;
|
||||
|
||||
return mode;
|
||||
}
|
||||
return EVP_CIPHER_flags(cipher) & EVP_CIPH_MODE;
|
||||
return ok != 0 ? v: 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -469,7 +477,7 @@ EVP_MD *EVP_MD_meth_dup(const EVP_MD *md)
|
||||
return to;
|
||||
}
|
||||
|
||||
int EVP_MD_upref(EVP_MD *md)
|
||||
int EVP_MD_up_ref(EVP_MD *md)
|
||||
{
|
||||
int ref = 0;
|
||||
|
||||
|
||||
+38
-1
@@ -93,5 +93,42 @@ void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id,
|
||||
const char *algorithm, const char *properties,
|
||||
void *(*new_method)(const OSSL_DISPATCH *fns,
|
||||
OSSL_PROVIDER *prov),
|
||||
int (*upref_method)(void *),
|
||||
int (*up_ref_method)(void *),
|
||||
void (*free_method)(void *));
|
||||
|
||||
/* Helper functions to avoid duplicating code */
|
||||
|
||||
/*
|
||||
* The callbacks implement different ways to pass a params array to the
|
||||
* provider. They will return one of these values:
|
||||
*
|
||||
* -2 if the method doesn't come from a provider
|
||||
* (evp_do_param will return this to the called)
|
||||
* -1 if the provider doesn't offer the desired function
|
||||
* (evp_do_param will raise an error and return 0)
|
||||
* or the return value from the desired function
|
||||
* (evp_do_param will return it to the caller)
|
||||
*/
|
||||
int evp_do_ciph_getparams(const void *vciph, void *ignored,
|
||||
OSSL_PARAM params[]);
|
||||
int evp_do_ciph_ctx_getparams(const void *vciph, void *provctx,
|
||||
OSSL_PARAM params[]);
|
||||
int evp_do_ciph_ctx_setparams(const void *vciph, void *provctx,
|
||||
OSSL_PARAM params[]);
|
||||
|
||||
/*-
|
||||
* prepares a singular parameter, then calls the callback to execute.
|
||||
*
|
||||
* |method| points to the method used by the callback.
|
||||
* EVP_CIPHER, EVP_MD, ...
|
||||
* |ptr| points at the data to transfer.
|
||||
* |sz| is the size of the data to transfer.
|
||||
* |key| is the name of the parameter to pass.
|
||||
* |datatype| is the data type of the parameter to pass.
|
||||
* |cb| is the callback that actually performs the parameter passing
|
||||
* |cb_ctx| is the cipher context
|
||||
*/
|
||||
int evp_do_param(const void *method, void *ptr, size_t sz, const char *key,
|
||||
int datatype,
|
||||
int (*cb)(const void *method, void *ctx, OSSL_PARAM params[]),
|
||||
void *cb_ctx);
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* Internal EVP utility functions */
|
||||
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1.h> /* evp_locl.h needs it */
|
||||
#include <openssl/safestack.h> /* evp_locl.h needs it */
|
||||
#include "internal/evp_int.h" /* evp_locl.h needs it */
|
||||
#include "evp_locl.h"
|
||||
|
||||
int evp_do_ciph_getparams(const void *vciph, void *ignored,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
const EVP_CIPHER *ciph = vciph;
|
||||
|
||||
if (ciph->prov == NULL)
|
||||
return -2;
|
||||
if (ciph->get_params == NULL)
|
||||
return -1;
|
||||
return ciph->get_params(params);
|
||||
}
|
||||
|
||||
int evp_do_ciph_ctx_getparams(const void *vciph, void *provctx,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
const EVP_CIPHER *ciph = vciph;
|
||||
|
||||
if (ciph->prov == NULL)
|
||||
return -2;
|
||||
if (ciph->ctx_get_params == NULL)
|
||||
return -1;
|
||||
return ciph->ctx_get_params(provctx, params);
|
||||
}
|
||||
|
||||
int evp_do_ciph_ctx_setparams(const void *vciph, void *provctx,
|
||||
OSSL_PARAM params[])
|
||||
{
|
||||
const EVP_CIPHER *ciph = vciph;
|
||||
|
||||
if (ciph->prov == NULL)
|
||||
return -2;
|
||||
if (ciph->ctx_set_params == NULL)
|
||||
return -1;
|
||||
return ciph->ctx_set_params(provctx, params);
|
||||
}
|
||||
|
||||
int evp_do_param(const void *method, void *ptr, size_t sz, const char *key,
|
||||
int datatype,
|
||||
int (*cb)(const void *method, void *ctx, OSSL_PARAM params[]),
|
||||
void *cb_ctx)
|
||||
{
|
||||
OSSL_PARAM params[2] = {
|
||||
OSSL_PARAM_END,
|
||||
OSSL_PARAM_END
|
||||
};
|
||||
int ret;
|
||||
|
||||
params[0].key = key;
|
||||
params[0].data_type = datatype;
|
||||
params[0].data = ptr;
|
||||
params[0].data_size = sz;
|
||||
|
||||
ret = cb(method, cb_ctx, params);
|
||||
if (ret == -1) {
|
||||
EVPerr(0, EVP_R_CTRL_NOT_IMPLEMENTED);
|
||||
ret = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
+14
-98
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-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
|
||||
@@ -7,131 +7,46 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#if !defined(OPENSSL_NO_MD5)
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
|
||||
# include <string.h>
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/md5.h>
|
||||
# include <openssl/sha.h>
|
||||
# include "internal/cryptlib.h"
|
||||
# include <openssl/obj_mac.h>
|
||||
# include "internal/evp_int.h"
|
||||
# include <openssl/rsa.h>
|
||||
|
||||
struct md5_sha1_ctx {
|
||||
MD5_CTX md5;
|
||||
SHA_CTX sha1;
|
||||
};
|
||||
# include "internal/md5_sha1.h"
|
||||
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
struct md5_sha1_ctx *mctx = EVP_MD_CTX_md_data(ctx);
|
||||
if (!MD5_Init(&mctx->md5))
|
||||
return 0;
|
||||
return SHA1_Init(&mctx->sha1);
|
||||
return md5_sha1_init(EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
{
|
||||
struct md5_sha1_ctx *mctx = EVP_MD_CTX_md_data(ctx);
|
||||
if (!MD5_Update(&mctx->md5, data, count))
|
||||
return 0;
|
||||
return SHA1_Update(&mctx->sha1, data, count);
|
||||
return md5_sha1_update(EVP_MD_CTX_md_data(ctx), data, count);
|
||||
}
|
||||
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
struct md5_sha1_ctx *mctx = EVP_MD_CTX_md_data(ctx);
|
||||
if (!MD5_Final(md, &mctx->md5))
|
||||
return 0;
|
||||
return SHA1_Final(md + MD5_DIGEST_LENGTH, &mctx->sha1);
|
||||
return md5_sha1_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int ctrl(EVP_MD_CTX *ctx, int cmd, int mslen, void *ms)
|
||||
{
|
||||
unsigned char padtmp[48];
|
||||
unsigned char md5tmp[MD5_DIGEST_LENGTH];
|
||||
unsigned char sha1tmp[SHA_DIGEST_LENGTH];
|
||||
struct md5_sha1_ctx *mctx;
|
||||
|
||||
if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
|
||||
return -2;
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
mctx = EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
/* SSLv3 client auth handling: see RFC-6101 5.6.8 */
|
||||
if (mslen != 48)
|
||||
return 0;
|
||||
|
||||
/* At this point hash contains all handshake messages, update
|
||||
* with master secret and pad_1.
|
||||
*/
|
||||
|
||||
if (update(ctx, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_1 value */
|
||||
memset(padtmp, 0x36, sizeof(padtmp));
|
||||
|
||||
if (!MD5_Update(&mctx->md5, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!MD5_Final(md5tmp, &mctx->md5))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Update(&mctx->sha1, padtmp, 40))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Final(sha1tmp, &mctx->sha1))
|
||||
return 0;
|
||||
|
||||
/* Reinitialise context */
|
||||
|
||||
if (!init(ctx))
|
||||
return 0;
|
||||
|
||||
if (update(ctx, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_2 value */
|
||||
memset(padtmp, 0x5c, sizeof(padtmp));
|
||||
|
||||
if (!MD5_Update(&mctx->md5, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!MD5_Update(&mctx->md5, md5tmp, sizeof(md5tmp)))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Update(&mctx->sha1, padtmp, 40))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Update(&mctx->sha1, sha1tmp, sizeof(sha1tmp)))
|
||||
return 0;
|
||||
|
||||
/* Now when ctx is finalised it will return the SSL v3 hash value */
|
||||
|
||||
OPENSSL_cleanse(md5tmp, sizeof(md5tmp));
|
||||
OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
|
||||
|
||||
return 1;
|
||||
|
||||
return md5_sha1_ctrl(EVP_MD_CTX_md_data(ctx), cmd, mslen, ms);
|
||||
}
|
||||
|
||||
static const EVP_MD md5_sha1_md = {
|
||||
NID_md5_sha1,
|
||||
NID_md5_sha1,
|
||||
MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH,
|
||||
MD5_SHA1_DIGEST_LENGTH,
|
||||
0,
|
||||
init,
|
||||
update,
|
||||
final,
|
||||
NULL,
|
||||
NULL,
|
||||
MD5_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(struct md5_sha1_ctx),
|
||||
MD5_SHA1_CBLOCK,
|
||||
sizeof(EVP_MD *) + sizeof(MD5_SHA1_CTX),
|
||||
ctrl
|
||||
};
|
||||
|
||||
@@ -139,4 +54,5 @@ const EVP_MD *EVP_md5_sha1(void)
|
||||
{
|
||||
return &md5_sha1_md;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENSSL_NO_MD5 */
|
||||
+2
-56
@@ -32,63 +32,9 @@ static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
return SHA1_Final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int ctrl(EVP_MD_CTX *ctx, int cmd, int mslen, void *ms)
|
||||
static int ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2)
|
||||
{
|
||||
unsigned char padtmp[40];
|
||||
unsigned char sha1tmp[SHA_DIGEST_LENGTH];
|
||||
|
||||
SHA_CTX *sha1;
|
||||
|
||||
if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
|
||||
return -2;
|
||||
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
|
||||
sha1 = EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
/* SSLv3 client auth handling: see RFC-6101 5.6.8 */
|
||||
if (mslen != 48)
|
||||
return 0;
|
||||
|
||||
/* At this point hash contains all handshake messages, update
|
||||
* with master secret and pad_1.
|
||||
*/
|
||||
|
||||
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_1 value */
|
||||
memset(padtmp, 0x36, sizeof(padtmp));
|
||||
|
||||
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Final(sha1tmp, sha1))
|
||||
return 0;
|
||||
|
||||
/* Reinitialise context */
|
||||
|
||||
if (!SHA1_Init(sha1))
|
||||
return 0;
|
||||
|
||||
if (SHA1_Update(sha1, ms, mslen) <= 0)
|
||||
return 0;
|
||||
|
||||
/* Set padtmp to pad_2 value */
|
||||
memset(padtmp, 0x5c, sizeof(padtmp));
|
||||
|
||||
if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
|
||||
return 0;
|
||||
|
||||
if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
|
||||
return 0;
|
||||
|
||||
/* Now when ctx is finalised it will return the SSL v3 hash value */
|
||||
OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
|
||||
|
||||
return 1;
|
||||
|
||||
return sha1_ctrl(ctx != NULL ? EVP_MD_CTX_md_data(ctx) : NULL, cmd, p1, p2);
|
||||
}
|
||||
|
||||
static const EVP_MD sha1_md = {
|
||||
|
||||
+33
-120
@@ -13,120 +13,33 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "internal/sha3.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,
|
||||
size_t r);
|
||||
void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r);
|
||||
|
||||
#define KECCAK1600_WIDTH 1600
|
||||
|
||||
typedef struct {
|
||||
uint64_t A[5][5];
|
||||
size_t block_size; /* cached ctx->digest->block_size */
|
||||
size_t md_size; /* output length, variable in XOF */
|
||||
size_t num; /* used bytes in below buffer */
|
||||
unsigned char buf[KECCAK1600_WIDTH / 8 - 32];
|
||||
unsigned char pad;
|
||||
} KECCAK1600_CTX;
|
||||
|
||||
static int init(EVP_MD_CTX *evp_ctx, unsigned char pad)
|
||||
static int init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
size_t bsz = evp_ctx->digest->block_size;
|
||||
|
||||
if (bsz <= sizeof(ctx->buf)) {
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
|
||||
ctx->num = 0;
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = evp_ctx->digest->md_size;
|
||||
ctx->pad = pad;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return sha3_init(EVP_MD_CTX_md_data(ctx), '\x06', ctx->digest->md_size * 8);
|
||||
}
|
||||
|
||||
static int sha3_init(EVP_MD_CTX *evp_ctx)
|
||||
static int update(EVP_MD_CTX *ctx, const void *_inp, size_t len)
|
||||
{
|
||||
return init(evp_ctx, '\x06');
|
||||
return sha3_update(EVP_MD_CTX_md_data(ctx), _inp, len);
|
||||
}
|
||||
|
||||
static int shake_init(EVP_MD_CTX *evp_ctx)
|
||||
static int final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
{
|
||||
return init(evp_ctx, '\x1f');
|
||||
return sha3_final(md, EVP_MD_CTX_md_data(ctx));
|
||||
}
|
||||
|
||||
static int kmac_init(EVP_MD_CTX *evp_ctx)
|
||||
static int shake_init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return init(evp_ctx, '\x04');
|
||||
return sha3_init(EVP_MD_CTX_md_data(ctx), '\x1f', ctx->digest->md_size * 8);
|
||||
}
|
||||
|
||||
static int sha3_update(EVP_MD_CTX *evp_ctx, const void *_inp, size_t len)
|
||||
static int kmac_init(EVP_MD_CTX *ctx)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
const unsigned char *inp = _inp;
|
||||
size_t bsz = ctx->block_size;
|
||||
size_t num, rem;
|
||||
|
||||
if (len == 0)
|
||||
return 1;
|
||||
|
||||
if ((num = ctx->num) != 0) { /* process intermediate buffer? */
|
||||
rem = bsz - num;
|
||||
|
||||
if (len < rem) {
|
||||
memcpy(ctx->buf + num, inp, len);
|
||||
ctx->num += len;
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
* We have enough data to fill or overflow the intermediate
|
||||
* buffer. So we append |rem| bytes and process the block,
|
||||
* leaving the rest for later processing...
|
||||
*/
|
||||
memcpy(ctx->buf + num, inp, rem);
|
||||
inp += rem, len -= rem;
|
||||
(void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz);
|
||||
ctx->num = 0;
|
||||
/* ctx->buf is processed, ctx->num is guaranteed to be zero */
|
||||
}
|
||||
|
||||
if (len >= bsz)
|
||||
rem = SHA3_absorb(ctx->A, inp, len, bsz);
|
||||
else
|
||||
rem = len;
|
||||
|
||||
if (rem) {
|
||||
memcpy(ctx->buf, inp + len - rem, rem);
|
||||
ctx->num = rem;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int sha3_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
size_t bsz = ctx->block_size;
|
||||
size_t num = ctx->num;
|
||||
|
||||
/*
|
||||
* Pad the data with 10*1. Note that |num| can be |bsz - 1|
|
||||
* in which case both byte operations below are performed on
|
||||
* same byte...
|
||||
*/
|
||||
memset(ctx->buf + num, 0, bsz - num);
|
||||
ctx->buf[num] = ctx->pad;
|
||||
ctx->buf[bsz - 1] |= 0x80;
|
||||
|
||||
(void)SHA3_absorb(ctx->A, ctx->buf, bsz, bsz);
|
||||
|
||||
SHA3_squeeze(ctx->A, md, ctx->md_size, bsz);
|
||||
|
||||
return 1;
|
||||
return keccak_kmac_init(EVP_MD_CTX_md_data(ctx), '\x04',
|
||||
ctx->digest->md_size * 8 / 2);
|
||||
}
|
||||
|
||||
static int shake_ctrl(EVP_MD_CTX *evp_ctx, int cmd, int p1, void *p2)
|
||||
@@ -205,7 +118,7 @@ static int s390x_sha3_init(EVP_MD_CTX *evp_ctx)
|
||||
}
|
||||
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
ctx->num = 0;
|
||||
ctx->bufsz = 0;
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = evp_ctx->digest->md_size;
|
||||
return 1;
|
||||
@@ -232,7 +145,7 @@ static int s390x_shake_init(EVP_MD_CTX *evp_ctx)
|
||||
}
|
||||
|
||||
memset(ctx->A, 0, sizeof(ctx->A));
|
||||
ctx->num = 0;
|
||||
ctx->bufsz = 0;
|
||||
ctx->block_size = bsz;
|
||||
ctx->md_size = evp_ctx->digest->md_size;
|
||||
return 1;
|
||||
@@ -248,19 +161,19 @@ static int s390x_sha3_update(EVP_MD_CTX *evp_ctx, const void *_inp, size_t len)
|
||||
if (len == 0)
|
||||
return 1;
|
||||
|
||||
if ((num = ctx->num) != 0) {
|
||||
if ((num = ctx->bufsz) != 0) {
|
||||
rem = bsz - num;
|
||||
|
||||
if (len < rem) {
|
||||
memcpy(ctx->buf + num, inp, len);
|
||||
ctx->num += len;
|
||||
ctx->bufsz += len;
|
||||
return 1;
|
||||
}
|
||||
memcpy(ctx->buf + num, inp, rem);
|
||||
inp += rem;
|
||||
len -= rem;
|
||||
s390x_kimd(ctx->buf, bsz, ctx->pad, ctx->A);
|
||||
ctx->num = 0;
|
||||
ctx->bufsz = 0;
|
||||
}
|
||||
rem = len % bsz;
|
||||
|
||||
@@ -268,7 +181,7 @@ static int s390x_sha3_update(EVP_MD_CTX *evp_ctx, const void *_inp, size_t len)
|
||||
|
||||
if (rem) {
|
||||
memcpy(ctx->buf, inp + len - rem, rem);
|
||||
ctx->num = rem;
|
||||
ctx->bufsz = rem;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -277,7 +190,7 @@ static int s390x_sha3_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
|
||||
s390x_klmd(ctx->buf, ctx->num, NULL, 0, ctx->pad, ctx->A);
|
||||
s390x_klmd(ctx->buf, ctx->bufsz, NULL, 0, ctx->pad, ctx->A);
|
||||
memcpy(md, ctx->A, ctx->md_size);
|
||||
return 1;
|
||||
}
|
||||
@@ -286,7 +199,7 @@ static int s390x_shake_final(EVP_MD_CTX *evp_ctx, unsigned char *md)
|
||||
{
|
||||
KECCAK1600_CTX *ctx = evp_ctx->md_data;
|
||||
|
||||
s390x_klmd(ctx->buf, ctx->num, md, ctx->md_size, ctx->pad, ctx->A);
|
||||
s390x_klmd(ctx->buf, ctx->bufsz, md, ctx->md_size, ctx->pad, ctx->A);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -311,9 +224,9 @@ const EVP_MD *EVP_sha3_##bitlen(void) \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
sha3_init, \
|
||||
sha3_update, \
|
||||
sha3_final, \
|
||||
init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
@@ -347,8 +260,8 @@ const EVP_MD *EVP_shake##bitlen(void) \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
shake_init, \
|
||||
sha3_update, \
|
||||
sha3_final, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
@@ -370,9 +283,9 @@ const EVP_MD *EVP_sha3_##bitlen(void) \
|
||||
NID_RSA_SHA3_##bitlen, \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_DIGALGID_ABSENT, \
|
||||
sha3_init, \
|
||||
sha3_update, \
|
||||
sha3_final, \
|
||||
init, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
@@ -390,8 +303,8 @@ const EVP_MD *EVP_shake##bitlen(void) \
|
||||
bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
shake_init, \
|
||||
sha3_update, \
|
||||
sha3_final, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
@@ -416,13 +329,13 @@ EVP_MD_SHAKE(256)
|
||||
const EVP_MD *evp_keccak_kmac##bitlen(void) \
|
||||
{ \
|
||||
static const EVP_MD kmac_##bitlen##_md = { \
|
||||
-1, \
|
||||
NID_kmac##bitlen, \
|
||||
0, \
|
||||
2 * bitlen / 8, \
|
||||
EVP_MD_FLAG_XOF, \
|
||||
kmac_init, \
|
||||
sha3_update, \
|
||||
sha3_final, \
|
||||
update, \
|
||||
final, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
(KECCAK1600_WIDTH - bitlen * 2) / 8, \
|
||||
|
||||
+17
-7
@@ -48,18 +48,28 @@ void EVP_MAC_CTX_free(EVP_MAC_CTX *ctx)
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
int EVP_MAC_CTX_copy(EVP_MAC_CTX *dst, const EVP_MAC_CTX *src)
|
||||
EVP_MAC_CTX *EVP_MAC_CTX_dup(const EVP_MAC_CTX *src)
|
||||
{
|
||||
EVP_MAC_IMPL *macdata;
|
||||
EVP_MAC_CTX *dst;
|
||||
|
||||
if (src->data != NULL && !dst->meth->copy(dst->data, src->data))
|
||||
return 0;
|
||||
if (src->data == NULL)
|
||||
return NULL;
|
||||
|
||||
dst = OPENSSL_malloc(sizeof(*dst));
|
||||
if (dst == NULL) {
|
||||
EVPerr(EVP_F_EVP_MAC_CTX_DUP, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
macdata = dst->data;
|
||||
*dst = *src;
|
||||
dst->data = macdata;
|
||||
|
||||
return 1;
|
||||
dst->data = src->meth->dup(src->data);
|
||||
if (dst->data == NULL) {
|
||||
EVP_MAC_CTX_free(dst);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
const EVP_MAC *EVP_MAC_CTX_mac(EVP_MAC_CTX *ctx)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1999-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
|
||||
@@ -40,6 +40,7 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
|
||||
if (kctx == NULL)
|
||||
return 0;
|
||||
if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, pass, (size_t)passlen) != 1
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PBKDF2_PKCS5_MODE, 1) != 1
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT,
|
||||
salt, (size_t)saltlen) != 1
|
||||
|| EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_ITER, iter) != 1
|
||||
|
||||
+29
-17
@@ -10,6 +10,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include "internal/evp_int.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
/* MAC PKEY context structure */
|
||||
|
||||
@@ -75,15 +76,25 @@ static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
|
||||
{
|
||||
MAC_PKEY_CTX *sctx, *dctx;
|
||||
|
||||
if (!pkey_mac_init(dst))
|
||||
sctx = EVP_PKEY_CTX_get_data(src);
|
||||
if (sctx->ctx->data == NULL)
|
||||
return 0;
|
||||
|
||||
sctx = EVP_PKEY_CTX_get_data(src);
|
||||
dctx = EVP_PKEY_CTX_get_data(dst);
|
||||
dctx = OPENSSL_zalloc(sizeof(*dctx));
|
||||
if (dctx == NULL) {
|
||||
EVPerr(EVP_F_PKEY_MAC_COPY, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EVP_MAC_CTX_copy(dctx->ctx, sctx->ctx))
|
||||
EVP_PKEY_CTX_set_data(dst, dctx);
|
||||
dst->keygen_info_count = 0;
|
||||
|
||||
dctx->ctx = EVP_MAC_CTX_dup(sctx->ctx);
|
||||
if (dctx->ctx == NULL)
|
||||
goto err;
|
||||
|
||||
dctx->type = sctx->type;
|
||||
|
||||
switch (dctx->type) {
|
||||
case MAC_TYPE_RAW:
|
||||
dctx->raw_data.md = sctx->raw_data.md;
|
||||
@@ -100,7 +111,7 @@ static int pkey_mac_copy(EVP_PKEY_CTX *dst, const EVP_PKEY_CTX *src)
|
||||
}
|
||||
return 1;
|
||||
err:
|
||||
pkey_mac_cleanup (dst);
|
||||
pkey_mac_cleanup(dst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -141,14 +152,10 @@ static int pkey_mac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
|
||||
break;
|
||||
case MAC_TYPE_MAC:
|
||||
{
|
||||
EVP_MAC_CTX *cmkey = EVP_MAC_CTX_new_id(nid);
|
||||
EVP_MAC_CTX *cmkey = EVP_MAC_CTX_dup(hctx->ctx);
|
||||
|
||||
if (cmkey == NULL)
|
||||
return 0;
|
||||
if (!EVP_MAC_CTX_copy(cmkey, hctx->ctx)) {
|
||||
EVP_MAC_CTX_free(cmkey);
|
||||
return 0;
|
||||
}
|
||||
EVP_PKEY_assign(pkey, nid, cmkey);
|
||||
}
|
||||
break;
|
||||
@@ -249,13 +256,18 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
case MAC_TYPE_RAW:
|
||||
hctx->raw_data.md = p2;
|
||||
break;
|
||||
case MAC_TYPE_MAC:
|
||||
if (ctx->pkey != NULL
|
||||
&& !EVP_MAC_CTX_copy(hctx->ctx,
|
||||
(EVP_MAC_CTX *)ctx->pkey->pkey.ptr))
|
||||
return 0;
|
||||
if (!EVP_MAC_init(hctx->ctx))
|
||||
return 0;
|
||||
case MAC_TYPE_MAC: {
|
||||
EVP_MAC_CTX *new_mac_ctx;
|
||||
|
||||
if (ctx->pkey == NULL)
|
||||
return 0;
|
||||
new_mac_ctx = EVP_MAC_CTX_dup((EVP_MAC_CTX *)ctx->pkey
|
||||
->pkey.ptr);
|
||||
if (new_mac_ctx == NULL)
|
||||
return 0;
|
||||
EVP_MAC_CTX_free(hctx->ctx);
|
||||
hctx->ctx = new_mac_ctx;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* This should be dead code */
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ static EX_CALLBACKS *get_and_lock(OPENSSL_CTX *ctx, int class_index)
|
||||
}
|
||||
|
||||
global = openssl_ctx_get_ex_data_global(ctx);
|
||||
if (global->ex_data_lock == NULL) {
|
||||
if (global == NULL || global->ex_data_lock == NULL) {
|
||||
/*
|
||||
* This can happen in normal operation when using CRYPTO_mem_leaks().
|
||||
* The CRYPTO_mem_leaks() function calls OPENSSL_cleanup() which cleans
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user