mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-22 03:57:19 +08:00
Update to FreeBSD stable/12 2019-03-11
Git mirror commit 735fe7a0a5f9c265040e2e6654a01b081d6354f1.
This commit is contained in:
parent
d542c19668
commit
eb1d30ad35
@ -1 +1 @@
|
||||
Subproject commit 606b591dae1023a71ff020faf99789059eb6591f
|
||||
Subproject commit 735fe7a0a5f9c265040e2e6654a01b081d6354f1
|
@ -25,18 +25,22 @@
|
||||
int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data,
|
||||
unsigned char *md, unsigned int *len)
|
||||
{
|
||||
int i;
|
||||
int inl;
|
||||
unsigned char *str, *p;
|
||||
|
||||
i = i2d(data, NULL);
|
||||
if ((str = OPENSSL_malloc(i)) == NULL) {
|
||||
inl = i2d(data, NULL);
|
||||
if (inl <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
if ((str = OPENSSL_malloc(inl)) == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_DIGEST, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
p = str;
|
||||
i2d(data, &p);
|
||||
|
||||
if (!EVP_Digest(str, i, md, len, type, NULL)) {
|
||||
if (!EVP_Digest(str, inl, md, len, type, NULL)) {
|
||||
OPENSSL_free(str);
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
{
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
unsigned char *p, *buf_in = NULL, *buf_out = NULL;
|
||||
int i, inl = 0, outl = 0, outll = 0;
|
||||
int i, inl = 0, outl = 0;
|
||||
size_t inll = 0, outll = 0;
|
||||
X509_ALGOR *a;
|
||||
|
||||
if (ctx == NULL) {
|
||||
@ -72,10 +73,15 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
}
|
||||
}
|
||||
inl = i2d(data, NULL);
|
||||
buf_in = OPENSSL_malloc((unsigned int)inl);
|
||||
if (inl <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
inll = (size_t)inl;
|
||||
buf_in = OPENSSL_malloc(inll);
|
||||
outll = outl = EVP_PKEY_size(pkey);
|
||||
buf_out = OPENSSL_malloc((unsigned int)outl);
|
||||
if ((buf_in == NULL) || (buf_out == NULL)) {
|
||||
buf_out = OPENSSL_malloc(outll);
|
||||
if (buf_in == NULL || buf_out == NULL) {
|
||||
outl = 0;
|
||||
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
@ -103,7 +109,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
|
||||
signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
|
||||
err:
|
||||
EVP_MD_CTX_free(ctx);
|
||||
OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
|
||||
OPENSSL_clear_free((char *)buf_in, inll);
|
||||
OPENSSL_clear_free((char *)buf_out, outll);
|
||||
return outl;
|
||||
}
|
||||
@ -140,7 +146,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
EVP_PKEY *pkey;
|
||||
unsigned char *buf_in = NULL, *buf_out = NULL;
|
||||
size_t inl = 0, outl = 0, outll = 0;
|
||||
int signid, paramtype;
|
||||
int signid, paramtype, buf_len = 0;
|
||||
int rv;
|
||||
|
||||
type = EVP_MD_CTX_md(ctx);
|
||||
@ -200,10 +206,16 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
|
||||
}
|
||||
|
||||
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||
buf_len = ASN1_item_i2d(asn, &buf_in, it);
|
||||
if (buf_len <= 0) {
|
||||
outl = 0;
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
inl = buf_len;
|
||||
outll = outl = EVP_PKEY_size(pkey);
|
||||
buf_out = OPENSSL_malloc((unsigned int)outl);
|
||||
if ((buf_in == NULL) || (buf_out == NULL)) {
|
||||
buf_out = OPENSSL_malloc(outll);
|
||||
if (buf_in == NULL || buf_out == NULL) {
|
||||
outl = 0;
|
||||
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
@ -225,7 +237,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
|
||||
signature->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
|
||||
signature->flags |= ASN1_STRING_FLAG_BITS_LEFT;
|
||||
err:
|
||||
OPENSSL_clear_free((char *)buf_in, (unsigned int)inl);
|
||||
OPENSSL_clear_free((char *)buf_in, inl);
|
||||
OPENSSL_clear_free((char *)buf_out, outll);
|
||||
return outl;
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
|
||||
}
|
||||
|
||||
inl = i2d(data, NULL);
|
||||
if (inl <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
buf_in = OPENSSL_malloc((unsigned int)inl);
|
||||
if (buf_in == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_VERIFY, ERR_R_MALLOC_FAILURE);
|
||||
@ -89,8 +93,8 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
EVP_MD_CTX *ctx = NULL;
|
||||
unsigned char *buf_in = NULL;
|
||||
int ret = -1, inl = 0;
|
||||
|
||||
int mdnid, pknid;
|
||||
size_t inll = 0;
|
||||
|
||||
if (!pkey) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
|
||||
@ -129,8 +133,8 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
goto err;
|
||||
ret = -1;
|
||||
} else {
|
||||
const EVP_MD *type;
|
||||
type = EVP_get_digestbynid(mdnid);
|
||||
const EVP_MD *type = EVP_get_digestbynid(mdnid);
|
||||
|
||||
if (type == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY,
|
||||
ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
|
||||
@ -152,11 +156,15 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
}
|
||||
|
||||
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||
|
||||
if (inl <= 0) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (buf_in == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
inll = inl;
|
||||
|
||||
ret = EVP_DigestVerify(ctx, signature->data, (size_t)signature->length,
|
||||
buf_in, inl);
|
||||
@ -166,7 +174,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
OPENSSL_clear_free(buf_in, (unsigned int)inl);
|
||||
OPENSSL_clear_free(buf_in, inll);
|
||||
EVP_MD_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
@ -142,6 +142,22 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD tmp = { 0, };
|
||||
|
||||
/*
|
||||
* One of the following must be true:
|
||||
*
|
||||
* pem_str == NULL AND ASN1_PKEY_ALIAS is set
|
||||
* pem_str != NULL AND ASN1_PKEY_ALIAS is clear
|
||||
*
|
||||
* Anything else is an error and may lead to a corrupt ASN1 method table
|
||||
*/
|
||||
if (!((ameth->pem_str == NULL
|
||||
&& (ameth->pkey_flags & ASN1_PKEY_ALIAS) != 0)
|
||||
|| (ameth->pem_str != NULL
|
||||
&& (ameth->pkey_flags & ASN1_PKEY_ALIAS) == 0))) {
|
||||
EVPerr(EVP_F_EVP_PKEY_ASN1_ADD0, ERR_R_PASSED_INVALID_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (app_methods == NULL) {
|
||||
app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);
|
||||
if (app_methods == NULL)
|
||||
@ -218,18 +234,6 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
|
||||
goto err;
|
||||
}
|
||||
|
||||
/*
|
||||
* One of the following must be true:
|
||||
*
|
||||
* pem_str == NULL AND ASN1_PKEY_ALIAS is set
|
||||
* pem_str != NULL AND ASN1_PKEY_ALIAS is clear
|
||||
*
|
||||
* Anything else is an error and may lead to a corrupt ASN1 method table
|
||||
*/
|
||||
if (!((pem_str == NULL && (flags & ASN1_PKEY_ALIAS) != 0)
|
||||
|| (pem_str != NULL && (flags & ASN1_PKEY_ALIAS) == 0)))
|
||||
goto err;
|
||||
|
||||
if (pem_str) {
|
||||
ameth->pem_str = OPENSSL_strdup(pem_str);
|
||||
if (!ameth->pem_str)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/asn1/charmap.pl
|
||||
*
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -34,7 +34,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
} else
|
||||
ret = *a;
|
||||
|
||||
if (!EVP_PKEY_set_type(ret, type)) {
|
||||
if (type != EVP_PKEY_id(ret) && !EVP_PKEY_set_type(ret, type)) {
|
||||
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -784,7 +784,12 @@ int BIO_lookup_ex(const char *host, const char *service, int lookup_type,
|
||||
* anyway [above getaddrinfo/gai_strerror is]. We just let
|
||||
* system administrator figure this out...
|
||||
*/
|
||||
# if defined(OPENSSL_SYS_VXWORKS)
|
||||
/* h_errno doesn't exist on VxWorks */
|
||||
SYSerr(SYS_F_GETHOSTBYNAME, 1000 );
|
||||
# else
|
||||
SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno);
|
||||
# endif
|
||||
#else
|
||||
SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError());
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -255,9 +255,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
}
|
||||
# elif defined(OPENSSL_SYS_WIN32_CYGWIN)
|
||||
int fd = fileno((FILE *)ptr);
|
||||
if (num & BIO_FP_TEXT)
|
||||
setmode(fd, O_TEXT);
|
||||
else
|
||||
if (!(num & BIO_FP_TEXT))
|
||||
setmode(fd, O_BINARY);
|
||||
# endif
|
||||
}
|
||||
@ -281,11 +279,14 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32_CYGWIN)
|
||||
# if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS)
|
||||
if (!(num & BIO_FP_TEXT))
|
||||
OPENSSL_strlcat(p, "b", sizeof(p));
|
||||
else
|
||||
OPENSSL_strlcat(p, "t", sizeof(p));
|
||||
# elif defined(OPENSSL_SYS_WIN32_CYGWIN)
|
||||
if (!(num & BIO_FP_TEXT))
|
||||
OPENSSL_strlcat(p, "b", sizeof(p));
|
||||
# endif
|
||||
fp = openssl_fopen(ptr, p);
|
||||
if (fp == NULL) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -22,7 +22,7 @@ static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
|
||||
static int mem_new(BIO *h);
|
||||
static int secmem_new(BIO *h);
|
||||
static int mem_free(BIO *data);
|
||||
static int mem_buf_free(BIO *data, int free_all);
|
||||
static int mem_buf_free(BIO *data);
|
||||
static int mem_buf_sync(BIO *h);
|
||||
|
||||
static const BIO_METHOD mem_method = {
|
||||
@ -142,10 +142,20 @@ static int secmem_new(BIO *bi)
|
||||
|
||||
static int mem_free(BIO *a)
|
||||
{
|
||||
return mem_buf_free(a, 1);
|
||||
BIO_BUF_MEM *bb;
|
||||
|
||||
if (a == NULL)
|
||||
return 0;
|
||||
|
||||
bb = (BIO_BUF_MEM *)a->ptr;
|
||||
if (!mem_buf_free(a))
|
||||
return 0;
|
||||
OPENSSL_free(bb->readp);
|
||||
OPENSSL_free(bb);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mem_buf_free(BIO *a, int free_all)
|
||||
static int mem_buf_free(BIO *a)
|
||||
{
|
||||
if (a == NULL)
|
||||
return 0;
|
||||
@ -157,11 +167,6 @@ static int mem_buf_free(BIO *a, int free_all)
|
||||
if (a->flags & BIO_FLAGS_MEM_RDONLY)
|
||||
b->data = NULL;
|
||||
BUF_MEM_free(b);
|
||||
if (free_all) {
|
||||
OPENSSL_free(bb->readp);
|
||||
OPENSSL_free(bb);
|
||||
}
|
||||
a->ptr = NULL;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -268,11 +273,10 @@ static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_BUF_MEM:
|
||||
mem_buf_free(b, 0);
|
||||
mem_buf_free(b);
|
||||
b->shutdown = (int)num;
|
||||
bbm->buf = ptr;
|
||||
*bbm->readp = *bbm->buf;
|
||||
b->ptr = bbm;
|
||||
break;
|
||||
case BIO_C_GET_BUF_MEM_PTR:
|
||||
if (ptr != NULL) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -229,6 +229,8 @@ BIGNUM *BN_CTX_get(BN_CTX *ctx)
|
||||
}
|
||||
/* OK, make sure the returned bignum is "zero" */
|
||||
BN_zero(ret);
|
||||
/* clear BN_FLG_CONSTTIME if leaked from previous frames */
|
||||
ret->flags &= (~BN_FLG_CONSTTIME);
|
||||
ctx->used++;
|
||||
CTXDBG_RET(ctx, ret);
|
||||
return ret;
|
||||
@ -258,7 +260,7 @@ static int BN_STACK_push(BN_STACK *st, unsigned int idx)
|
||||
unsigned int newsize =
|
||||
st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
|
||||
unsigned int *newitems;
|
||||
|
||||
|
||||
if ((newitems = OPENSSL_malloc(sizeof(*newitems) * newsize)) == NULL) {
|
||||
BNerr(BN_F_BN_STACK_PUSH, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
@ -312,7 +314,7 @@ static BIGNUM *BN_POOL_get(BN_POOL *p, int flag)
|
||||
/* Full; allocate a new pool item and link it in. */
|
||||
if (p->used == p->size) {
|
||||
BN_POOL_ITEM *item;
|
||||
|
||||
|
||||
if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) {
|
||||
BNerr(BN_F_BN_POOL_GET, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -42,7 +42,7 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
|
||||
goto err;
|
||||
|
||||
/* we have a prime :-) */
|
||||
return ret;
|
||||
return rnd;
|
||||
err:
|
||||
BN_free(rnd);
|
||||
return NULL;
|
||||
|
@ -9,6 +9,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "bn_lcl.h"
|
||||
@ -88,6 +89,77 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
|
||||
|
||||
#else
|
||||
|
||||
# if defined(BN_DIV3W)
|
||||
BN_ULONG bn_div_3_words(const BN_ULONG *m, BN_ULONG d1, BN_ULONG d0);
|
||||
# elif 0
|
||||
/*
|
||||
* This is #if-ed away, because it's a reference for assembly implementations,
|
||||
* where it can and should be made constant-time. But if you want to test it,
|
||||
* just replace 0 with 1.
|
||||
*/
|
||||
# if BN_BITS2 == 64 && defined(__SIZEOF_INT128__) && __SIZEOF_INT128__==16
|
||||
# undef BN_ULLONG
|
||||
# define BN_ULLONG __uint128_t
|
||||
# define BN_LLONG
|
||||
# endif
|
||||
|
||||
# ifdef BN_LLONG
|
||||
# define BN_DIV3W
|
||||
/*
|
||||
* Interface is somewhat quirky, |m| is pointer to most significant limb,
|
||||
* and less significant limb is referred at |m[-1]|. This means that caller
|
||||
* is responsible for ensuring that |m[-1]| is valid. Second condition that
|
||||
* has to be met is that |d0|'s most significant bit has to be set. Or in
|
||||
* other words divisor has to be "bit-aligned to the left." bn_div_fixed_top
|
||||
* does all this. The subroutine considers four limbs, two of which are
|
||||
* "overlapping," hence the name...
|
||||
*/
|
||||
static BN_ULONG bn_div_3_words(const BN_ULONG *m, BN_ULONG d1, BN_ULONG d0)
|
||||
{
|
||||
BN_ULLONG R = ((BN_ULLONG)m[0] << BN_BITS2) | m[-1];
|
||||
BN_ULLONG D = ((BN_ULLONG)d0 << BN_BITS2) | d1;
|
||||
BN_ULONG Q = 0, mask;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < BN_BITS2; i++) {
|
||||
Q <<= 1;
|
||||
if (R >= D) {
|
||||
Q |= 1;
|
||||
R -= D;
|
||||
}
|
||||
D >>= 1;
|
||||
}
|
||||
|
||||
mask = 0 - (Q >> (BN_BITS2 - 1)); /* does it overflow? */
|
||||
|
||||
Q <<= 1;
|
||||
Q |= (R >= D);
|
||||
|
||||
return (Q | mask) & BN_MASK2;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
static int bn_left_align(BIGNUM *num)
|
||||
{
|
||||
BN_ULONG *d = num->d, n, m, rmask;
|
||||
int top = num->top;
|
||||
int rshift = BN_num_bits_word(d[top - 1]), lshift, i;
|
||||
|
||||
lshift = BN_BITS2 - rshift;
|
||||
rshift %= BN_BITS2; /* say no to undefined behaviour */
|
||||
rmask = (BN_ULONG)0 - rshift; /* rmask = 0 - (rshift != 0) */
|
||||
rmask |= rmask >> 8;
|
||||
|
||||
for (i = 0, m = 0; i < top; i++) {
|
||||
n = d[i];
|
||||
d[i] = ((n << lshift) | m) & BN_MASK2;
|
||||
m = (n >> rshift) & rmask;
|
||||
}
|
||||
|
||||
return lshift;
|
||||
}
|
||||
|
||||
# if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \
|
||||
&& !defined(PEDANTIC) && !defined(BN_DIV3W)
|
||||
# if defined(__GNUC__) && __GNUC__>=2
|
||||
@ -139,56 +211,74 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
|
||||
int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
int norm_shift, i, loop;
|
||||
BIGNUM *tmp, wnum, *snum, *sdiv, *res;
|
||||
BN_ULONG *resp, *wnump;
|
||||
BN_ULONG d0, d1;
|
||||
int num_n, div_n;
|
||||
int no_branch = 0;
|
||||
|
||||
/*
|
||||
* Invalid zero-padding would have particularly bad consequences so don't
|
||||
* just rely on bn_check_top() here (bn_check_top() works only for
|
||||
* BN_DEBUG builds)
|
||||
*/
|
||||
if ((num->top > 0 && num->d[num->top - 1] == 0) ||
|
||||
(divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {
|
||||
BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bn_check_top(num);
|
||||
bn_check_top(divisor);
|
||||
|
||||
if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)
|
||||
|| (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {
|
||||
no_branch = 1;
|
||||
}
|
||||
|
||||
bn_check_top(dv);
|
||||
bn_check_top(rm);
|
||||
/*- bn_check_top(num); *//*
|
||||
* 'num' has been checked already
|
||||
*/
|
||||
/*- bn_check_top(divisor); *//*
|
||||
* 'divisor' has been checked already
|
||||
*/
|
||||
int ret;
|
||||
|
||||
if (BN_is_zero(divisor)) {
|
||||
BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!no_branch && BN_ucmp(num, divisor) < 0) {
|
||||
if (rm != NULL) {
|
||||
if (BN_copy(rm, num) == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (dv != NULL)
|
||||
BN_zero(dv);
|
||||
return 1;
|
||||
/*
|
||||
* Invalid zero-padding would have particularly bad consequences so don't
|
||||
* just rely on bn_check_top() here (bn_check_top() works only for
|
||||
* BN_DEBUG builds)
|
||||
*/
|
||||
if (divisor->d[divisor->top - 1] == 0) {
|
||||
BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);
|
||||
|
||||
if (ret) {
|
||||
if (dv != NULL)
|
||||
bn_correct_top(dv);
|
||||
if (rm != NULL)
|
||||
bn_correct_top(rm);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* It's argued that *length* of *significant* part of divisor is public.
|
||||
* Even if it's private modulus that is. Again, *length* is assumed
|
||||
* public, but not *value*. Former is likely to be pre-defined by
|
||||
* algorithm with bit granularity, though below subroutine is invariant
|
||||
* of limb length. Thanks to this assumption we can require that |divisor|
|
||||
* may not be zero-padded, yet claim this subroutine "constant-time"(*).
|
||||
* This is because zero-padded dividend, |num|, is tolerated, so that
|
||||
* caller can pass dividend of public length(*), but with smaller amount
|
||||
* of significant limbs. This naturally means that quotient, |dv|, would
|
||||
* contain correspongly less significant limbs as well, and will be zero-
|
||||
* padded accordingly. Returned remainder, |rm|, will have same bit length
|
||||
* as divisor, also zero-padded if needed. These actually leave sign bits
|
||||
* in ambiguous state. In sense that we try to avoid negative zeros, while
|
||||
* zero-padded zeros would retain sign.
|
||||
*
|
||||
* (*) "Constant-time-ness" has two pre-conditions:
|
||||
*
|
||||
* - 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
|
||||
* divisor's length is considered public;
|
||||
*/
|
||||
int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
|
||||
const BIGNUM *divisor, BN_CTX *ctx)
|
||||
{
|
||||
int norm_shift, i, j, loop;
|
||||
BIGNUM *tmp, *snum, *sdiv, *res;
|
||||
BN_ULONG *resp, *wnum, *wnumtop;
|
||||
BN_ULONG d0, d1;
|
||||
int num_n, div_n;
|
||||
|
||||
assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);
|
||||
|
||||
bn_check_top(num);
|
||||
bn_check_top(divisor);
|
||||
bn_check_top(dv);
|
||||
bn_check_top(rm);
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
res = (dv == NULL) ? BN_CTX_get(ctx) : dv;
|
||||
tmp = BN_CTX_get(ctx);
|
||||
@ -198,113 +288,72 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
goto err;
|
||||
|
||||
/* First we normalise the numbers */
|
||||
norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
|
||||
if (!(BN_lshift(sdiv, divisor, norm_shift)))
|
||||
if (!BN_copy(sdiv, divisor))
|
||||
goto err;
|
||||
norm_shift = bn_left_align(sdiv);
|
||||
sdiv->neg = 0;
|
||||
norm_shift += BN_BITS2;
|
||||
if (!(BN_lshift(snum, num, norm_shift)))
|
||||
/*
|
||||
* Note that bn_lshift_fixed_top's output is always one limb longer
|
||||
* than input, even when norm_shift is zero. This means that amount of
|
||||
* inner loop iterations is invariant of dividend value, and that one
|
||||
* doesn't need to compare dividend and divisor if they were originally
|
||||
* of the same bit length.
|
||||
*/
|
||||
if (!(bn_lshift_fixed_top(snum, num, norm_shift)))
|
||||
goto err;
|
||||
snum->neg = 0;
|
||||
|
||||
if (no_branch) {
|
||||
/*
|
||||
* Since we don't know whether snum is larger than sdiv, we pad snum
|
||||
* with enough zeroes without changing its value.
|
||||
*/
|
||||
if (snum->top <= sdiv->top + 1) {
|
||||
if (bn_wexpand(snum, sdiv->top + 2) == NULL)
|
||||
goto err;
|
||||
for (i = snum->top; i < sdiv->top + 2; i++)
|
||||
snum->d[i] = 0;
|
||||
snum->top = sdiv->top + 2;
|
||||
} else {
|
||||
if (bn_wexpand(snum, snum->top + 1) == NULL)
|
||||
goto err;
|
||||
snum->d[snum->top] = 0;
|
||||
snum->top++;
|
||||
}
|
||||
}
|
||||
|
||||
div_n = sdiv->top;
|
||||
num_n = snum->top;
|
||||
|
||||
if (num_n <= div_n) {
|
||||
/* caller didn't pad dividend -> no constant-time guarantee... */
|
||||
if (bn_wexpand(snum, div_n + 1) == NULL)
|
||||
goto err;
|
||||
memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));
|
||||
snum->top = num_n = div_n + 1;
|
||||
}
|
||||
|
||||
loop = num_n - div_n;
|
||||
/*
|
||||
* Lets setup a 'window' into snum This is the part that corresponds to
|
||||
* the current 'area' being divided
|
||||
*/
|
||||
wnum.neg = 0;
|
||||
wnum.d = &(snum->d[loop]);
|
||||
wnum.top = div_n;
|
||||
wnum.flags = BN_FLG_STATIC_DATA;
|
||||
/*
|
||||
* only needed when BN_ucmp messes up the values between top and max
|
||||
*/
|
||||
wnum.dmax = snum->dmax - loop; /* so we don't step out of bounds */
|
||||
wnum = &(snum->d[loop]);
|
||||
wnumtop = &(snum->d[num_n - 1]);
|
||||
|
||||
/* Get the top 2 words of sdiv */
|
||||
/* div_n=sdiv->top; */
|
||||
d0 = sdiv->d[div_n - 1];
|
||||
d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];
|
||||
|
||||
/* pointer to the 'top' of snum */
|
||||
wnump = &(snum->d[num_n - 1]);
|
||||
|
||||
/* Setup to 'res' */
|
||||
if (!bn_wexpand(res, (loop + 1)))
|
||||
/* Setup quotient */
|
||||
if (!bn_wexpand(res, loop))
|
||||
goto err;
|
||||
res->neg = (num->neg ^ divisor->neg);
|
||||
res->top = loop - no_branch;
|
||||
resp = &(res->d[loop - 1]);
|
||||
res->top = loop;
|
||||
res->flags |= BN_FLG_FIXED_TOP;
|
||||
resp = &(res->d[loop]);
|
||||
|
||||
/* space for temp */
|
||||
if (!bn_wexpand(tmp, (div_n + 1)))
|
||||
goto err;
|
||||
|
||||
if (!no_branch) {
|
||||
if (BN_ucmp(&wnum, sdiv) >= 0) {
|
||||
/*
|
||||
* If BN_DEBUG_RAND is defined BN_ucmp changes (via bn_pollute)
|
||||
* the const bignum arguments => clean the values between top and
|
||||
* max again
|
||||
*/
|
||||
bn_clear_top2max(&wnum);
|
||||
bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);
|
||||
*resp = 1;
|
||||
} else
|
||||
res->top--;
|
||||
}
|
||||
|
||||
/* Increase the resp pointer so that we never create an invalid pointer. */
|
||||
resp++;
|
||||
|
||||
/*
|
||||
* if res->top == 0 then clear the neg value otherwise decrease the resp
|
||||
* pointer
|
||||
*/
|
||||
if (res->top == 0)
|
||||
res->neg = 0;
|
||||
else
|
||||
resp--;
|
||||
|
||||
for (i = 0; i < loop - 1; i++, wnump--) {
|
||||
for (i = 0; i < loop; i++, wnumtop--) {
|
||||
BN_ULONG q, l0;
|
||||
/*
|
||||
* the first part of the loop uses the top two words of snum and sdiv
|
||||
* to calculate a BN_ULONG q such that | wnum - sdiv * q | < sdiv
|
||||
*/
|
||||
# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
|
||||
BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);
|
||||
q = bn_div_3_words(wnump, d1, d0);
|
||||
# if defined(BN_DIV3W)
|
||||
q = bn_div_3_words(wnumtop, d1, d0);
|
||||
# else
|
||||
BN_ULONG n0, n1, rem = 0;
|
||||
|
||||
n0 = wnump[0];
|
||||
n1 = wnump[-1];
|
||||
n0 = wnumtop[0];
|
||||
n1 = wnumtop[-1];
|
||||
if (n0 == d0)
|
||||
q = BN_MASK2;
|
||||
else { /* n0 < d0 */
|
||||
|
||||
BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];
|
||||
# ifdef BN_LLONG
|
||||
BN_ULLONG t2;
|
||||
|
||||
@ -324,7 +373,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
t2 = (BN_ULLONG) d1 *q;
|
||||
|
||||
for (;;) {
|
||||
if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))
|
||||
if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))
|
||||
break;
|
||||
q--;
|
||||
rem += d0;
|
||||
@ -357,7 +406,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
# endif
|
||||
|
||||
for (;;) {
|
||||
if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))
|
||||
if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))
|
||||
break;
|
||||
q--;
|
||||
rem += d0;
|
||||
@ -373,43 +422,33 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
|
||||
|
||||
l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);
|
||||
tmp->d[div_n] = l0;
|
||||
wnum.d--;
|
||||
wnum--;
|
||||
/*
|
||||
* ingore top values of the bignums just sub the two BN_ULONG arrays
|
||||
* ignore top values of the bignums just sub the two BN_ULONG arrays
|
||||
* with bn_sub_words
|
||||
*/
|
||||
if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {
|
||||
/*
|
||||
* Note: As we have considered only the leading two BN_ULONGs in
|
||||
* the calculation of q, sdiv * q might be greater than wnum (but
|
||||
* then (q-1) * sdiv is less or equal than wnum)
|
||||
*/
|
||||
q--;
|
||||
if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))
|
||||
/*
|
||||
* we can't have an overflow here (assuming that q != 0, but
|
||||
* if q == 0 then tmp is zero anyway)
|
||||
*/
|
||||
(*wnump)++;
|
||||
}
|
||||
/* store part of the result */
|
||||
resp--;
|
||||
*resp = q;
|
||||
}
|
||||
bn_correct_top(snum);
|
||||
if (rm != NULL) {
|
||||
l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);
|
||||
q -= l0;
|
||||
/*
|
||||
* Keep a copy of the neg flag in num because if rm==num BN_rshift()
|
||||
* will overwrite it.
|
||||
* Note: As we have considered only the leading two BN_ULONGs in
|
||||
* the calculation of q, sdiv * q might be greater than wnum (but
|
||||
* then (q-1) * sdiv is less or equal than wnum)
|
||||
*/
|
||||
int neg = num->neg;
|
||||
BN_rshift(rm, snum, norm_shift);
|
||||
if (!BN_is_zero(rm))
|
||||
rm->neg = neg;
|
||||
bn_check_top(rm);
|
||||
for (l0 = 0 - l0, j = 0; j < div_n; j++)
|
||||
tmp->d[j] = sdiv->d[j] & l0;
|
||||
l0 = bn_add_words(wnum, wnum, tmp->d, div_n);
|
||||
(*wnumtop) += l0;
|
||||
assert((*wnumtop) == 0);
|
||||
|
||||
/* store part of the result */
|
||||
*--resp = q;
|
||||
}
|
||||
if (no_branch)
|
||||
bn_correct_top(res);
|
||||
/* snum holds remainder, it's as wide as divisor */
|
||||
snum->neg = num->neg;
|
||||
snum->top = div_n;
|
||||
snum->flags |= BN_FLG_FIXED_TOP;
|
||||
if (rm != NULL)
|
||||
bn_rshift_fixed_top(rm, snum, norm_shift);
|
||||
BN_CTX_end(ctx);
|
||||
return 1;
|
||||
err:
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -650,34 +650,41 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifdef RSAZ_ENABLED
|
||||
if (!a->neg) {
|
||||
/*
|
||||
* If the size of the operands allow it, perform the optimized
|
||||
* RSAZ exponentiation. For further information see
|
||||
* crypto/bn/rsaz_exp.c and accompanying assembly modules.
|
||||
*/
|
||||
if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)
|
||||
&& rsaz_avx2_eligible()) {
|
||||
if (NULL == bn_wexpand(rr, 16))
|
||||
goto err;
|
||||
RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,
|
||||
mont->n0[0]);
|
||||
rr->top = 16;
|
||||
rr->neg = 0;
|
||||
bn_correct_top(rr);
|
||||
ret = 1;
|
||||
goto err;
|
||||
} else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {
|
||||
if (NULL == bn_wexpand(rr, 8))
|
||||
goto err;
|
||||
RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);
|
||||
rr->top = 8;
|
||||
rr->neg = 0;
|
||||
bn_correct_top(rr);
|
||||
ret = 1;
|
||||
if (a->neg || BN_ucmp(a, m) >= 0) {
|
||||
BIGNUM *reduced = BN_CTX_get(ctx);
|
||||
if (reduced == NULL
|
||||
|| !BN_nnmod(reduced, a, m, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
a = reduced;
|
||||
}
|
||||
|
||||
#ifdef RSAZ_ENABLED
|
||||
/*
|
||||
* If the size of the operands allow it, perform the optimized
|
||||
* RSAZ exponentiation. For further information see
|
||||
* crypto/bn/rsaz_exp.c and accompanying assembly modules.
|
||||
*/
|
||||
if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)
|
||||
&& rsaz_avx2_eligible()) {
|
||||
if (NULL == bn_wexpand(rr, 16))
|
||||
goto err;
|
||||
RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,
|
||||
mont->n0[0]);
|
||||
rr->top = 16;
|
||||
rr->neg = 0;
|
||||
bn_correct_top(rr);
|
||||
ret = 1;
|
||||
goto err;
|
||||
} else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {
|
||||
if (NULL == bn_wexpand(rr, 8))
|
||||
goto err;
|
||||
RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);
|
||||
rr->top = 8;
|
||||
rr->neg = 0;
|
||||
bn_correct_top(rr);
|
||||
ret = 1;
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -749,12 +756,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
goto err;
|
||||
|
||||
/* prepare a^1 in Montgomery domain */
|
||||
if (a->neg || BN_ucmp(a, m) >= 0) {
|
||||
if (!BN_nnmod(&am, a, m, ctx))
|
||||
goto err;
|
||||
if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))
|
||||
goto err;
|
||||
} else if (!bn_to_mont_fixed_top(&am, a, mont, ctx))
|
||||
if (!bn_to_mont_fixed_top(&am, a, mont, ctx))
|
||||
goto err;
|
||||
|
||||
#if defined(SPARC_T4_MONT)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -697,6 +697,9 @@ int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
|
||||
int i;
|
||||
BN_ULONG aa, bb;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
aa = a[n - 1];
|
||||
bb = b[n - 1];
|
||||
if (aa != bb)
|
||||
@ -739,26 +742,25 @@ int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)
|
||||
return bn_cmp_words(a, b, cl);
|
||||
}
|
||||
|
||||
/*
|
||||
/*-
|
||||
* Constant-time conditional swap of a and b.
|
||||
* a and b are swapped if condition is not 0. The code assumes that at most one bit of condition is set.
|
||||
* nwords is the number of words to swap. The code assumes that at least nwords are allocated in both a and b,
|
||||
* and that no more than nwords are used by either a or b.
|
||||
* a and b cannot be the same number
|
||||
* a and b are swapped if condition is not 0.
|
||||
* nwords is the number of words to swap.
|
||||
* Assumes that at least nwords are allocated in both a and b.
|
||||
* Assumes that no more than nwords are used by either a or b.
|
||||
*/
|
||||
void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
|
||||
{
|
||||
BN_ULONG t;
|
||||
int i;
|
||||
|
||||
if (a == b)
|
||||
return;
|
||||
|
||||
bn_wcheck_size(a, nwords);
|
||||
bn_wcheck_size(b, nwords);
|
||||
|
||||
assert(a != b);
|
||||
assert((condition & (condition - 1)) == 0);
|
||||
assert(sizeof(BN_ULONG) >= sizeof(int));
|
||||
|
||||
condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;
|
||||
condition = ((~condition & ((condition - 1))) >> (BN_BITS2 - 1)) - 1;
|
||||
|
||||
t = (a->top ^ b->top) & condition;
|
||||
a->top ^= t;
|
||||
@ -796,42 +798,16 @@ void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
|
||||
a->flags ^= t;
|
||||
b->flags ^= t;
|
||||
|
||||
#define BN_CONSTTIME_SWAP(ind) \
|
||||
do { \
|
||||
t = (a->d[ind] ^ b->d[ind]) & condition; \
|
||||
a->d[ind] ^= t; \
|
||||
b->d[ind] ^= t; \
|
||||
} while (0)
|
||||
|
||||
switch (nwords) {
|
||||
default:
|
||||
for (i = 10; i < nwords; i++)
|
||||
BN_CONSTTIME_SWAP(i);
|
||||
/* Fallthrough */
|
||||
case 10:
|
||||
BN_CONSTTIME_SWAP(9); /* Fallthrough */
|
||||
case 9:
|
||||
BN_CONSTTIME_SWAP(8); /* Fallthrough */
|
||||
case 8:
|
||||
BN_CONSTTIME_SWAP(7); /* Fallthrough */
|
||||
case 7:
|
||||
BN_CONSTTIME_SWAP(6); /* Fallthrough */
|
||||
case 6:
|
||||
BN_CONSTTIME_SWAP(5); /* Fallthrough */
|
||||
case 5:
|
||||
BN_CONSTTIME_SWAP(4); /* Fallthrough */
|
||||
case 4:
|
||||
BN_CONSTTIME_SWAP(3); /* Fallthrough */
|
||||
case 3:
|
||||
BN_CONSTTIME_SWAP(2); /* Fallthrough */
|
||||
case 2:
|
||||
BN_CONSTTIME_SWAP(1); /* Fallthrough */
|
||||
case 1:
|
||||
BN_CONSTTIME_SWAP(0);
|
||||
/* conditionally swap the data */
|
||||
for (i = 0; i < nwords; i++) {
|
||||
t = (a->d[i] ^ b->d[i]) & condition;
|
||||
a->d[i] ^= t;
|
||||
b->d[i] ^= t;
|
||||
}
|
||||
#undef BN_CONSTTIME_SWAP
|
||||
}
|
||||
|
||||
#undef BN_CONSTTIME_SWAP_FLAGS
|
||||
|
||||
/* Bits of security, see SP800-57 */
|
||||
|
||||
int BN_security_bits(int L, int N)
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/bn/bn_prime.pl
|
||||
*
|
||||
* Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -9,6 +9,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "internal/cryptlib.h"
|
||||
#include "bn_lcl.h"
|
||||
|
||||
@ -84,40 +85,70 @@ int BN_rshift1(BIGNUM *r, const BIGNUM *a)
|
||||
|
||||
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
|
||||
{
|
||||
int i, nw, lb, rb;
|
||||
BN_ULONG *t, *f;
|
||||
BN_ULONG l;
|
||||
|
||||
bn_check_top(r);
|
||||
bn_check_top(a);
|
||||
int ret;
|
||||
|
||||
if (n < 0) {
|
||||
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = bn_lshift_fixed_top(r, a, n);
|
||||
|
||||
bn_correct_top(r);
|
||||
bn_check_top(r);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* In respect to shift factor the execution time is invariant of
|
||||
* |n % BN_BITS2|, but not |n / BN_BITS2|. Or in other words pre-condition
|
||||
* for constant-time-ness is |n < BN_BITS2| or |n / BN_BITS2| being
|
||||
* non-secret.
|
||||
*/
|
||||
int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n)
|
||||
{
|
||||
int i, nw;
|
||||
unsigned int lb, rb;
|
||||
BN_ULONG *t, *f;
|
||||
BN_ULONG l, m, rmask = 0;
|
||||
|
||||
assert(n >= 0);
|
||||
|
||||
bn_check_top(r);
|
||||
bn_check_top(a);
|
||||
|
||||
nw = n / BN_BITS2;
|
||||
if (bn_wexpand(r, a->top + nw + 1) == NULL)
|
||||
return 0;
|
||||
r->neg = a->neg;
|
||||
lb = n % BN_BITS2;
|
||||
rb = BN_BITS2 - lb;
|
||||
f = a->d;
|
||||
t = r->d;
|
||||
t[a->top + nw] = 0;
|
||||
if (lb == 0)
|
||||
for (i = a->top - 1; i >= 0; i--)
|
||||
t[nw + i] = f[i];
|
||||
else
|
||||
for (i = a->top - 1; i >= 0; i--) {
|
||||
l = f[i];
|
||||
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
|
||||
t[nw + i] = (l << lb) & BN_MASK2;
|
||||
|
||||
if (a->top != 0) {
|
||||
lb = (unsigned int)n % BN_BITS2;
|
||||
rb = BN_BITS2 - lb;
|
||||
rb %= BN_BITS2; /* say no to undefined behaviour */
|
||||
rmask = (BN_ULONG)0 - rb; /* rmask = 0 - (rb != 0) */
|
||||
rmask |= rmask >> 8;
|
||||
f = &(a->d[0]);
|
||||
t = &(r->d[nw]);
|
||||
l = f[a->top - 1];
|
||||
t[a->top] = (l >> rb) & rmask;
|
||||
for (i = a->top - 1; i > 0; i--) {
|
||||
m = l << lb;
|
||||
l = f[i - 1];
|
||||
t[i] = (m | ((l >> rb) & rmask)) & BN_MASK2;
|
||||
}
|
||||
memset(t, 0, sizeof(*t) * nw);
|
||||
t[0] = (l << lb) & BN_MASK2;
|
||||
} else {
|
||||
/* shouldn't happen, but formally required */
|
||||
r->d[nw] = 0;
|
||||
}
|
||||
if (nw != 0)
|
||||
memset(r->d, 0, sizeof(*t) * nw);
|
||||
|
||||
r->neg = a->neg;
|
||||
r->top = a->top + nw + 1;
|
||||
bn_correct_top(r);
|
||||
bn_check_top(r);
|
||||
r->flags |= BN_FLG_FIXED_TOP;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -175,3 +206,54 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
|
||||
bn_check_top(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* In respect to shift factor the execution time is invariant of
|
||||
* |n % BN_BITS2|, but not |n / BN_BITS2|. Or in other words pre-condition
|
||||
* for constant-time-ness for sufficiently[!] zero-padded inputs is
|
||||
* |n < BN_BITS2| or |n / BN_BITS2| being non-secret.
|
||||
*/
|
||||
int bn_rshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n)
|
||||
{
|
||||
int i, top, nw;
|
||||
unsigned int lb, rb;
|
||||
BN_ULONG *t, *f;
|
||||
BN_ULONG l, m, mask;
|
||||
|
||||
bn_check_top(r);
|
||||
bn_check_top(a);
|
||||
|
||||
assert(n >= 0);
|
||||
|
||||
nw = n / BN_BITS2;
|
||||
if (nw >= a->top) {
|
||||
/* shouldn't happen, but formally required */
|
||||
BN_zero(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rb = (unsigned int)n % BN_BITS2;
|
||||
lb = BN_BITS2 - rb;
|
||||
lb %= BN_BITS2; /* say no to undefined behaviour */
|
||||
mask = (BN_ULONG)0 - lb; /* mask = 0 - (lb != 0) */
|
||||
mask |= mask >> 8;
|
||||
top = a->top - nw;
|
||||
if (r != a && bn_wexpand(r, top) == NULL)
|
||||
return 0;
|
||||
|
||||
t = &(r->d[0]);
|
||||
f = &(a->d[nw]);
|
||||
l = f[0];
|
||||
for (i = 0; i < top - 1; i++) {
|
||||
m = f[i + 1];
|
||||
t[i] = (l >> rb) | ((m << lb) & mask);
|
||||
l = m;
|
||||
}
|
||||
t[i] = l >> rb;
|
||||
|
||||
r->neg = a->neg;
|
||||
r->top = top;
|
||||
r->flags |= BN_FLG_FIXED_TOP;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2013-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -284,7 +284,7 @@ static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari,
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Initialise a ktri based on passed certificate and key */
|
||||
/* Initialise a kari based on passed certificate and key */
|
||||
|
||||
int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
EVP_PKEY *pk, unsigned int flags)
|
||||
@ -301,6 +301,9 @@ int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
kari->version = 3;
|
||||
|
||||
rek = M_ASN1_new_of(CMS_RecipientEncryptedKey);
|
||||
if (rek == NULL)
|
||||
return 0;
|
||||
|
||||
if (!sk_CMS_RecipientEncryptedKey_push(kari->recipientEncryptedKeys, rek)) {
|
||||
M_ASN1_free_of(rek, CMS_RecipientEncryptedKey);
|
||||
return 0;
|
||||
|
@ -375,6 +375,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
|
||||
goto err;
|
||||
}
|
||||
|
||||
OPENSSL_clear_free(ec->key, ec->keylen);
|
||||
ec->key = key;
|
||||
ec->keylen = keylen;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -350,10 +350,15 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
|
||||
psection = section;
|
||||
}
|
||||
p = eat_ws(conf, end);
|
||||
if (strncmp(pname, ".include", 8) == 0 && p != pname + 8) {
|
||||
if (strncmp(pname, ".include", 8) == 0
|
||||
&& (p != pname + 8 || *p == '=')) {
|
||||
char *include = NULL;
|
||||
BIO *next;
|
||||
|
||||
if (*p == '=') {
|
||||
p++;
|
||||
p = eat_ws(conf, p);
|
||||
}
|
||||
trim_ws(conf, p);
|
||||
if (!str_copy(conf, psection, &include, p))
|
||||
goto err;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/conf/keysets.pl
|
||||
*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the OpenSSL license (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
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -360,11 +360,36 @@ OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void)
|
||||
|
||||
if (ret != NULL)
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
ret->flags = DEFAULT_CONF_MFLAGS;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_STDIO
|
||||
int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings,
|
||||
const char *filename)
|
||||
{
|
||||
char *newfilename = NULL;
|
||||
|
||||
if (filename != NULL) {
|
||||
newfilename = strdup(filename);
|
||||
if (newfilename == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
free(settings->filename);
|
||||
settings->filename = newfilename;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *settings,
|
||||
unsigned long flags)
|
||||
{
|
||||
settings->flags = flags;
|
||||
}
|
||||
|
||||
int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings,
|
||||
const char *appname)
|
||||
{
|
||||
@ -385,6 +410,7 @@ int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings,
|
||||
|
||||
void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings)
|
||||
{
|
||||
free(settings->filename);
|
||||
free(settings->appname);
|
||||
free(settings);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -148,6 +148,9 @@ int CONF_modules_load_file(const char *filename, const char *appname,
|
||||
OPENSSL_free(file);
|
||||
NCONF_free(conf);
|
||||
|
||||
if (flags & CONF_MFLAGS_IGNORE_RETURN_CODES)
|
||||
return 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -41,10 +41,24 @@ void OPENSSL_config(const char *appname)
|
||||
}
|
||||
#endif
|
||||
|
||||
void openssl_config_int(const char *appname)
|
||||
int openssl_config_int(const OPENSSL_INIT_SETTINGS *settings)
|
||||
{
|
||||
int ret;
|
||||
const char *filename;
|
||||
const char *appname;
|
||||
unsigned long flags;
|
||||
|
||||
if (openssl_configured)
|
||||
return;
|
||||
return 1;
|
||||
|
||||
filename = settings ? settings->filename : NULL;
|
||||
appname = settings ? settings->appname : NULL;
|
||||
flags = settings ? settings->flags : DEFAULT_CONF_MFLAGS;
|
||||
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr, "OPENSSL_INIT: openssl_config_int(%s, %s, %lu)\n",
|
||||
filename, appname, flags);
|
||||
#endif
|
||||
|
||||
OPENSSL_load_builtin_modules();
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
@ -53,11 +67,10 @@ void openssl_config_int(const char *appname)
|
||||
#endif
|
||||
ERR_clear_error();
|
||||
#ifndef OPENSSL_SYS_UEFI
|
||||
CONF_modules_load_file(NULL, appname,
|
||||
CONF_MFLAGS_DEFAULT_SECTION |
|
||||
CONF_MFLAGS_IGNORE_MISSING_FILE);
|
||||
ret = CONF_modules_load_file(filename, appname, flags);
|
||||
#endif
|
||||
openssl_configured = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void openssl_no_config_int(void)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -80,6 +80,8 @@ static int ssl_module_init(CONF_IMODULE *md, const CONF *cnf)
|
||||
cnt = sk_CONF_VALUE_num(cmd_lists);
|
||||
ssl_module_free(md);
|
||||
ssl_names = OPENSSL_zalloc(sizeof(*ssl_names) * cnt);
|
||||
if (ssl_names == NULL)
|
||||
goto err;
|
||||
ssl_names_count = cnt;
|
||||
for (i = 0; i < ssl_names_count; i++) {
|
||||
struct ssl_conf_name_st *ssl_name = ssl_names + i;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -354,9 +354,9 @@ void OPENSSL_showfatal(const char *fmta, ...)
|
||||
|
||||
/*
|
||||
* TODO: (For non GUI and no std error cases)
|
||||
* Add event logging feature here.
|
||||
* Add event logging feature here.
|
||||
*/
|
||||
|
||||
|
||||
# if !defined(NDEBUG)
|
||||
/*
|
||||
* We are in a situation where we tried to report a critical
|
||||
@ -395,7 +395,7 @@ void OPENSSL_showfatal(const char *fmta, ...)
|
||||
# endif
|
||||
# else
|
||||
MessageBox(NULL, buf, _T("OpenSSL: FATAL"), MB_OK | MB_ICONERROR);
|
||||
# endif
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
void OPENSSL_showfatal(const char *fmta, ...)
|
||||
@ -462,4 +462,14 @@ uint32_t OPENSSL_rdtsc(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t OPENSSL_instrument_bus(unsigned int *out, size_t cnt)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t OPENSSL_instrument_bus2(unsigned int *out, size_t cnt, size_t max)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -248,10 +248,36 @@ c448_error_t c448_ed448_verify(
|
||||
uint8_t context_len)
|
||||
{
|
||||
curve448_point_t pk_point, r_point;
|
||||
c448_error_t error =
|
||||
curve448_point_decode_like_eddsa_and_mul_by_ratio(pk_point, pubkey);
|
||||
c448_error_t error;
|
||||
curve448_scalar_t challenge_scalar;
|
||||
curve448_scalar_t response_scalar;
|
||||
/* Order in little endian format */
|
||||
static const uint8_t order[] = {
|
||||
0xF3, 0x44, 0x58, 0xAB, 0x92, 0xC2, 0x78, 0x23, 0x55, 0x8F, 0xC5, 0x8D,
|
||||
0x72, 0xC2, 0x6C, 0x21, 0x90, 0x36, 0xD6, 0xAE, 0x49, 0xDB, 0x4E, 0xC4,
|
||||
0xE9, 0x23, 0xCA, 0x7C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00
|
||||
};
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Check that s (second 57 bytes of the sig) is less than the order. Both
|
||||
* s and the order are in little-endian format. This can be done in
|
||||
* variable time, since if this is not the case the signature if publicly
|
||||
* invalid.
|
||||
*/
|
||||
for (i = EDDSA_448_PUBLIC_BYTES - 1; i >= 0; i--) {
|
||||
if (signature[i + EDDSA_448_PUBLIC_BYTES] > order[i])
|
||||
return C448_FAILURE;
|
||||
if (signature[i + EDDSA_448_PUBLIC_BYTES] < order[i])
|
||||
break;
|
||||
}
|
||||
if (i < 0)
|
||||
return C448_FAILURE;
|
||||
|
||||
error =
|
||||
curve448_point_decode_like_eddsa_and_mul_by_ratio(pk_point, pubkey);
|
||||
|
||||
if (C448_SUCCESS != error)
|
||||
return error;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2016 Cryptography Research, Inc.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -116,7 +116,7 @@ void curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES],
|
||||
|
||||
/*
|
||||
* Add two scalars. |a|, |b| and |out| may alias each other.
|
||||
*
|
||||
*
|
||||
* a (in): One scalar.
|
||||
* b (in): Another scalar.
|
||||
* out (out): a+b.
|
||||
@ -135,7 +135,7 @@ void curve448_scalar_sub(curve448_scalar_t out,
|
||||
|
||||
/*
|
||||
* Multiply two scalars. |a|, |b| and |out| may alias each other.
|
||||
*
|
||||
*
|
||||
* a (in): One scalar.
|
||||
* b (in): Another scalar.
|
||||
* out (out): a*b.
|
||||
@ -145,7 +145,7 @@ void curve448_scalar_mul(curve448_scalar_t out,
|
||||
|
||||
/*
|
||||
* Halve a scalar. |a| and |out| may alias each other.
|
||||
*
|
||||
*
|
||||
* a (in): A scalar.
|
||||
* out (out): a/2.
|
||||
*/
|
||||
@ -154,7 +154,7 @@ void curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a);
|
||||
/*
|
||||
* Copy a scalar. The scalars may alias each other, in which case this
|
||||
* function does nothing.
|
||||
*
|
||||
*
|
||||
* a (in): A scalar.
|
||||
* out (out): Will become a copy of a.
|
||||
*/
|
||||
@ -183,7 +183,7 @@ static ossl_inline void curve448_point_copy(curve448_point_t a,
|
||||
*
|
||||
* a (in): A point.
|
||||
* b (in): Another point.
|
||||
*
|
||||
*
|
||||
* Returns:
|
||||
* C448_TRUE: The points are equal.
|
||||
* C448_FALSE: The points are not equal.
|
||||
@ -243,7 +243,7 @@ void curve448_point_mul_by_ratio_and_encode_like_x448(
|
||||
/*
|
||||
* RFC 7748 Diffie-Hellman base point scalarmul. This function uses a different
|
||||
* (non-Decaf) encoding.
|
||||
*
|
||||
*
|
||||
* out (out): The scaled point base*scalar
|
||||
* scalar (in): The scalar to multiply by.
|
||||
*/
|
||||
@ -273,7 +273,7 @@ void curve448_precomputed_scalarmul(curve448_point_t scaled,
|
||||
* base2 (in): A second point to be scaled.
|
||||
* scalar2 (in) A second scalar to multiply by.
|
||||
*
|
||||
* Warning: This function takes variable time, and may leak the scalars used.
|
||||
* Warning: This function takes variable time, and may leak the scalars used.
|
||||
* It is designed for signature verification.
|
||||
*/
|
||||
void curve448_base_double_scalarmul_non_secret(curve448_point_t combo,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* 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 OpenSSL license (the "License"). You may not use
|
||||
@ -812,7 +812,7 @@ int ec_GF2m_simple_ladder_post(const EC_GROUP *group,
|
||||
|| !group->meth->field_mul(group, t2, t2, t0, ctx)
|
||||
|| !BN_GF2m_add(t1, t2, t1)
|
||||
|| !group->meth->field_mul(group, t2, p->X, t0, ctx)
|
||||
|| !BN_GF2m_mod_inv(t2, t2, group->field, ctx)
|
||||
|| !group->meth->field_inv(group, t2, t2, ctx)
|
||||
|| !group->meth->field_mul(group, t1, t1, t2, ctx)
|
||||
|| !group->meth->field_mul(group, r->X, r->Z, t2, ctx)
|
||||
|| !BN_GF2m_add(t2, p->X, r->X)
|
||||
@ -891,6 +891,21 @@ int ec_GF2m_simple_points_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*-
|
||||
* Computes the multiplicative inverse of a in GF(2^m), storing the result in r.
|
||||
* If a is zero (or equivalent), you'll get a EC_R_CANNOT_INVERT error.
|
||||
* SCA hardening is with blinding: BN_GF2m_mod_inv does that.
|
||||
*/
|
||||
static int ec_GF2m_simple_field_inv(const EC_GROUP *group, BIGNUM *r,
|
||||
const BIGNUM *a, BN_CTX *ctx)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!(ret = BN_GF2m_mod_inv(r, a, group->field, ctx)))
|
||||
ECerr(EC_F_EC_GF2M_SIMPLE_FIELD_INV, EC_R_CANNOT_INVERT);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const EC_METHOD *EC_GF2m_simple_method(void)
|
||||
{
|
||||
static const EC_METHOD ret = {
|
||||
@ -931,6 +946,7 @@ const EC_METHOD *EC_GF2m_simple_method(void)
|
||||
ec_GF2m_simple_field_mul,
|
||||
ec_GF2m_simple_field_sqr,
|
||||
ec_GF2m_simple_field_div,
|
||||
ec_GF2m_simple_field_inv,
|
||||
0, /* field_encode */
|
||||
0, /* field_decode */
|
||||
0, /* field_set_to_one */
|
||||
|
@ -507,7 +507,7 @@ static int ec_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;
|
||||
|
||||
case ASN1_PKEY_CTRL_SET1_TLS_ENCPT:
|
||||
return EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(pkey), arg2, arg1, NULL);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* 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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -68,6 +68,8 @@ static const ERR_STRING_DATA EC_str_functs[] = {
|
||||
"ec_asn1_group2fieldid"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, 0),
|
||||
"ec_GF2m_montgomery_point_multiply"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GF2M_SIMPLE_FIELD_INV, 0),
|
||||
"ec_GF2m_simple_field_inv"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT, 0),
|
||||
"ec_GF2m_simple_group_check_discriminant"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE, 0),
|
||||
@ -92,6 +94,8 @@ static const ERR_STRING_DATA EC_str_functs[] = {
|
||||
"ec_GFp_mont_field_decode"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_MONT_FIELD_ENCODE, 0),
|
||||
"ec_GFp_mont_field_encode"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_MONT_FIELD_INV, 0),
|
||||
"ec_GFp_mont_field_inv"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_MONT_FIELD_MUL, 0),
|
||||
"ec_GFp_mont_field_mul"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE, 0),
|
||||
@ -126,6 +130,8 @@ static const ERR_STRING_DATA EC_str_functs[] = {
|
||||
"ec_GFp_nist_group_set_curve"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_SIMPLE_BLIND_COORDINATES, 0),
|
||||
"ec_GFp_simple_blind_coordinates"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_SIMPLE_FIELD_INV, 0),
|
||||
"ec_GFp_simple_field_inv"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT, 0),
|
||||
"ec_GFp_simple_group_check_discriminant"},
|
||||
{ERR_PACK(ERR_LIB_EC, EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, 0),
|
||||
@ -289,6 +295,7 @@ static const ERR_STRING_DATA EC_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_BAD_SIGNATURE), "bad signature"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_BIGNUM_OUT_OF_RANGE), "bignum out of range"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_CANNOT_INVERT), "cannot invert"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_COORDINATES_OUT_OF_RANGE),
|
||||
"coordinates out of range"},
|
||||
{ERR_PACK(ERR_LIB_EC, 0, EC_R_CURVE_DOES_NOT_SUPPORT_ECDH),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -15,7 +15,6 @@
|
||||
#include <openssl/bn.h>
|
||||
#include "internal/refcount.h"
|
||||
#include "internal/ec_int.h"
|
||||
#include "curve448/curve448_lcl.h"
|
||||
|
||||
#if defined(__SUNPRO_C)
|
||||
# if __SUNPRO_C >= 0x520
|
||||
@ -154,6 +153,13 @@ struct ec_method_st {
|
||||
int (*field_sqr) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
|
||||
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,
|
||||
* storing the result in r.
|
||||
*
|
||||
* If 'a' is zero (or equivalent), you'll get an EC_R_CANNOT_INVERT error.
|
||||
*/
|
||||
int (*field_inv) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
|
||||
/* e.g. to Montgomery */
|
||||
int (*field_encode) (const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
@ -390,6 +396,8 @@ int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *b, BN_CTX *);
|
||||
int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
int ec_GFp_simple_field_inv(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
int ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p,
|
||||
BN_CTX *ctx);
|
||||
int ec_GFp_simple_ladder_pre(const EC_GROUP *group,
|
||||
@ -413,6 +421,8 @@ int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *b, BN_CTX *);
|
||||
int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
int ec_GFp_mont_field_inv(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *);
|
||||
int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -52,6 +52,7 @@ const EC_METHOD *EC_GFp_mont_method(void)
|
||||
ec_GFp_mont_field_mul,
|
||||
ec_GFp_mont_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_mont_field_inv,
|
||||
ec_GFp_mont_field_encode,
|
||||
ec_GFp_mont_field_decode,
|
||||
ec_GFp_mont_field_set_to_one,
|
||||
@ -208,6 +209,54 @@ int ec_GFp_mont_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
|
||||
return BN_mod_mul_montgomery(r, a, a, group->field_data1, ctx);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Computes the multiplicative inverse of a in GF(p), storing the result in r.
|
||||
* If a is zero (or equivalent), you'll get a EC_R_CANNOT_INVERT error.
|
||||
* We have a Mont structure, so SCA hardening is FLT inversion.
|
||||
*/
|
||||
int ec_GFp_mont_field_inv(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
BIGNUM *e = NULL;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (group->field_data1 == NULL)
|
||||
return 0;
|
||||
|
||||
if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)
|
||||
return 0;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
if ((e = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
|
||||
/* Inverse in constant time with Fermats Little Theorem */
|
||||
if (!BN_set_word(e, 2))
|
||||
goto err;
|
||||
if (!BN_sub(e, group->field, e))
|
||||
goto err;
|
||||
/*-
|
||||
* Exponent e is public.
|
||||
* No need for scatter-gather or BN_FLG_CONSTTIME.
|
||||
*/
|
||||
if (!BN_mod_exp_mont(r, a, e, group->field, ctx, group->field_data1))
|
||||
goto err;
|
||||
|
||||
/* throw an error on zero */
|
||||
if (BN_is_zero(r)) {
|
||||
ECerr(EC_F_EC_GFP_MONT_FIELD_INV, EC_R_CANNOT_INVERT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ec_GFp_mont_field_encode(const EC_GROUP *group, BIGNUM *r,
|
||||
const BIGNUM *a, BN_CTX *ctx)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -54,6 +54,7 @@ const EC_METHOD *EC_GFp_nist_method(void)
|
||||
ec_GFp_nist_field_mul,
|
||||
ec_GFp_nist_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_simple_field_inv,
|
||||
0 /* field_encode */ ,
|
||||
0 /* field_decode */ ,
|
||||
0, /* field_set_to_one */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2010-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2010-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -281,6 +281,7 @@ const EC_METHOD *EC_GFp_nistp224_method(void)
|
||||
ec_GFp_nist_field_mul,
|
||||
ec_GFp_nist_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_simple_field_inv,
|
||||
0 /* field_encode */ ,
|
||||
0 /* field_decode */ ,
|
||||
0, /* field_set_to_one */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -1812,6 +1812,7 @@ const EC_METHOD *EC_GFp_nistp256_method(void)
|
||||
ec_GFp_nist_field_mul,
|
||||
ec_GFp_nist_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_simple_field_inv,
|
||||
0 /* field_encode */ ,
|
||||
0 /* field_decode */ ,
|
||||
0, /* field_set_to_one */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2011-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2011-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -1649,6 +1649,7 @@ const EC_METHOD *EC_GFp_nistp521_method(void)
|
||||
ec_GFp_nist_field_mul,
|
||||
ec_GFp_nist_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_simple_field_inv,
|
||||
0 /* field_encode */ ,
|
||||
0 /* field_decode */ ,
|
||||
0, /* field_set_to_one */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2014-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2014-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2014, Intel Corporation. All Rights Reserved.
|
||||
* Copyright (c) 2015, CloudFlare, Inc.
|
||||
*
|
||||
@ -1679,6 +1679,7 @@ const EC_METHOD *EC_GFp_nistz256_method(void)
|
||||
ec_GFp_mont_field_mul,
|
||||
ec_GFp_mont_field_sqr,
|
||||
0, /* field_div */
|
||||
ec_GFp_mont_field_inv,
|
||||
ec_GFp_mont_field_encode,
|
||||
ec_GFp_mont_field_decode,
|
||||
ec_GFp_mont_field_set_to_one,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -53,6 +53,7 @@ const EC_METHOD *EC_GFp_simple_method(void)
|
||||
ec_GFp_simple_field_mul,
|
||||
ec_GFp_simple_field_sqr,
|
||||
0 /* field_div */ ,
|
||||
ec_GFp_simple_field_inv,
|
||||
0 /* field_encode */ ,
|
||||
0 /* field_decode */ ,
|
||||
0, /* field_set_to_one */
|
||||
@ -555,7 +556,7 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!BN_mod_inverse(Z_1, Z_, group->field, ctx)) {
|
||||
if (!group->meth->field_inv(group, Z_1, Z_, ctx)) {
|
||||
ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,
|
||||
ERR_R_BN_LIB);
|
||||
goto err;
|
||||
@ -1268,7 +1269,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,
|
||||
* points[i]->Z by its inverse.
|
||||
*/
|
||||
|
||||
if (!BN_mod_inverse(tmp, prod_Z[num - 1], group->field, ctx)) {
|
||||
if (!group->meth->field_inv(group, tmp, prod_Z[num - 1], ctx)) {
|
||||
ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
@ -1371,6 +1372,50 @@ int ec_GFp_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
|
||||
return BN_mod_sqr(r, a, group->field, ctx);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Computes the multiplicative inverse of a in GF(p), storing the result in r.
|
||||
* If a is zero (or equivalent), you'll get a EC_R_CANNOT_INVERT error.
|
||||
* Since we don't have a Mont structure here, SCA hardening is with blinding.
|
||||
*/
|
||||
int ec_GFp_simple_field_inv(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
|
||||
BN_CTX *ctx)
|
||||
{
|
||||
BIGNUM *e = NULL;
|
||||
BN_CTX *new_ctx = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)
|
||||
return 0;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
if ((e = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
|
||||
do {
|
||||
if (!BN_priv_rand_range(e, group->field))
|
||||
goto err;
|
||||
} while (BN_is_zero(e));
|
||||
|
||||
/* r := a * e */
|
||||
if (!group->meth->field_mul(group, r, a, e, ctx))
|
||||
goto err;
|
||||
/* r := 1/(a * e) */
|
||||
if (!BN_mod_inverse(r, r, group->field, ctx)) {
|
||||
ECerr(EC_F_EC_GFP_SIMPLE_FIELD_INV, EC_R_CANNOT_INVERT);
|
||||
goto err;
|
||||
}
|
||||
/* r := e/(a * e) = 1/a */
|
||||
if (!group->meth->field_mul(group, r, r, e, ctx))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(new_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*-
|
||||
* Apply randomization of EC point projective coordinates:
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -17,6 +17,7 @@
|
||||
#include "internal/asn1_int.h"
|
||||
#include "internal/evp_int.h"
|
||||
#include "ec_lcl.h"
|
||||
#include "curve448/curve448_lcl.h"
|
||||
|
||||
#define X25519_BITS 253
|
||||
#define X25519_SECURITY_BITS 128
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -37,6 +37,15 @@
|
||||
*/
|
||||
static int cfd;
|
||||
|
||||
static int clean_devcrypto_session(struct session_op *sess) {
|
||||
if (ioctl(cfd, CIOCFSESSION, &sess->ses) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
}
|
||||
memset(sess, 0, sizeof(struct session_op));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Ciphers
|
||||
@ -49,10 +58,12 @@ static int cfd;
|
||||
|
||||
struct cipher_ctx {
|
||||
struct session_op sess;
|
||||
|
||||
/* to pass from init to do_cipher */
|
||||
const unsigned char *iv;
|
||||
int op; /* COP_ENCRYPT or COP_DECRYPT */
|
||||
unsigned long mode; /* EVP_CIPH_*_MODE */
|
||||
|
||||
/* to handle ctr mode being a stream cipher */
|
||||
unsigned char partial[EVP_MAX_BLOCK_LENGTH];
|
||||
unsigned int blocksize, num;
|
||||
};
|
||||
|
||||
static const struct cipher_data_st {
|
||||
@ -89,9 +100,9 @@ static const struct cipher_data_st {
|
||||
{ NID_aes_256_xts, 16, 256 / 8 * 2, 16, EVP_CIPH_XTS_MODE, CRYPTO_AES_XTS },
|
||||
#endif
|
||||
#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_AES_ECB)
|
||||
{ NID_aes_128_ecb, 16, 128 / 8, 16, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
{ NID_aes_192_ecb, 16, 192 / 8, 16, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
{ NID_aes_256_ecb, 16, 256 / 8, 16, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
{ NID_aes_128_ecb, 16, 128 / 8, 0, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
{ NID_aes_192_ecb, 16, 192 / 8, 0, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
{ NID_aes_256_ecb, 16, 256 / 8, 0, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB },
|
||||
#endif
|
||||
#if 0 /* Not yet supported */
|
||||
{ NID_aes_128_gcm, 16, 128 / 8, 16, EVP_CIPH_GCM_MODE, CRYPTO_AES_GCM },
|
||||
@ -143,11 +154,17 @@ static int cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const struct cipher_data_st *cipher_d =
|
||||
get_cipher_data(EVP_CIPHER_CTX_nid(ctx));
|
||||
|
||||
memset(&cipher_ctx->sess, 0, sizeof(cipher_ctx->sess));
|
||||
/* cleanup a previous session */
|
||||
if (cipher_ctx->sess.ses != 0 &&
|
||||
clean_devcrypto_session(&cipher_ctx->sess) == 0)
|
||||
return 0;
|
||||
|
||||
cipher_ctx->sess.cipher = cipher_d->devcryptoid;
|
||||
cipher_ctx->sess.keylen = cipher_d->keylen;
|
||||
cipher_ctx->sess.key = (void *)key;
|
||||
cipher_ctx->op = enc ? COP_ENCRYPT : COP_DECRYPT;
|
||||
cipher_ctx->mode = cipher_d->flags & EVP_CIPH_MODE;
|
||||
cipher_ctx->blocksize = cipher_d->blocksize;
|
||||
if (ioctl(cfd, CIOCGSESSION, &cipher_ctx->sess) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
@ -162,8 +179,11 @@ static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
struct cipher_ctx *cipher_ctx =
|
||||
(struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
||||
struct crypt_op cryp;
|
||||
unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx);
|
||||
#if !defined(COP_FLAG_WRITE_IV)
|
||||
unsigned char saved_iv[EVP_MAX_IV_LENGTH];
|
||||
const unsigned char *ivptr;
|
||||
size_t nblocks, ivlen;
|
||||
#endif
|
||||
|
||||
memset(&cryp, 0, sizeof(cryp));
|
||||
@ -171,19 +191,28 @@ static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
cryp.len = inl;
|
||||
cryp.src = (void *)in;
|
||||
cryp.dst = (void *)out;
|
||||
cryp.iv = (void *)EVP_CIPHER_CTX_iv_noconst(ctx);
|
||||
cryp.iv = (void *)iv;
|
||||
cryp.op = cipher_ctx->op;
|
||||
#if !defined(COP_FLAG_WRITE_IV)
|
||||
cryp.flags = 0;
|
||||
|
||||
if (EVP_CIPHER_CTX_iv_length(ctx) > 0) {
|
||||
assert(inl >= EVP_CIPHER_CTX_iv_length(ctx));
|
||||
if (!EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
unsigned char *ivptr = in + inl - EVP_CIPHER_CTX_iv_length(ctx);
|
||||
ivlen = EVP_CIPHER_CTX_iv_length(ctx);
|
||||
if (ivlen > 0)
|
||||
switch (cipher_ctx->mode) {
|
||||
case EVP_CIPH_CBC_MODE:
|
||||
assert(inl >= ivlen);
|
||||
if (!EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
ivptr = in + inl - ivlen;
|
||||
memcpy(saved_iv, ivptr, ivlen);
|
||||
}
|
||||
break;
|
||||
|
||||
memcpy(saved_iv, ivptr, EVP_CIPHER_CTX_iv_length(ctx));
|
||||
case EVP_CIPH_CTR_MODE:
|
||||
break;
|
||||
|
||||
default: /* should not happen */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
cryp.flags = COP_FLAG_WRITE_IV;
|
||||
#endif
|
||||
@ -194,32 +223,113 @@ static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
}
|
||||
|
||||
#if !defined(COP_FLAG_WRITE_IV)
|
||||
if (EVP_CIPHER_CTX_iv_length(ctx) > 0) {
|
||||
unsigned char *ivptr = saved_iv;
|
||||
if (ivlen > 0)
|
||||
switch (cipher_ctx->mode) {
|
||||
case EVP_CIPH_CBC_MODE:
|
||||
assert(inl >= ivlen);
|
||||
if (EVP_CIPHER_CTX_encrypting(ctx))
|
||||
ivptr = out + inl - ivlen;
|
||||
else
|
||||
ivptr = saved_iv;
|
||||
|
||||
assert(inl >= EVP_CIPHER_CTX_iv_length(ctx));
|
||||
if (!EVP_CIPHER_CTX_encrypting(ctx))
|
||||
ivptr = out + inl - EVP_CIPHER_CTX_iv_length(ctx);
|
||||
memcpy(iv, ivptr, ivlen);
|
||||
break;
|
||||
|
||||
memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), ivptr,
|
||||
EVP_CIPHER_CTX_iv_length(ctx));
|
||||
}
|
||||
case EVP_CIPH_CTR_MODE:
|
||||
nblocks = (inl + cipher_ctx->blocksize - 1)
|
||||
/ cipher_ctx->blocksize;
|
||||
do {
|
||||
ivlen--;
|
||||
nblocks += iv[ivlen];
|
||||
iv[ivlen] = (uint8_t) nblocks;
|
||||
nblocks >>= 8;
|
||||
} while (ivlen);
|
||||
break;
|
||||
|
||||
default: /* should not happen */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
||||
const unsigned char *in, size_t inl)
|
||||
{
|
||||
struct cipher_ctx *cipher_ctx =
|
||||
(struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
||||
size_t nblocks, len;
|
||||
|
||||
/* initial partial block */
|
||||
while (cipher_ctx->num && inl) {
|
||||
(*out++) = *(in++) ^ cipher_ctx->partial[cipher_ctx->num];
|
||||
--inl;
|
||||
cipher_ctx->num = (cipher_ctx->num + 1) % cipher_ctx->blocksize;
|
||||
}
|
||||
|
||||
/* full blocks */
|
||||
if (inl > (unsigned int) cipher_ctx->blocksize) {
|
||||
nblocks = inl/cipher_ctx->blocksize;
|
||||
len = nblocks * cipher_ctx->blocksize;
|
||||
if (cipher_do_cipher(ctx, out, in, len) < 1)
|
||||
return 0;
|
||||
inl -= len;
|
||||
out += len;
|
||||
in += len;
|
||||
}
|
||||
|
||||
/* final partial block */
|
||||
if (inl) {
|
||||
memset(cipher_ctx->partial, 0, cipher_ctx->blocksize);
|
||||
if (cipher_do_cipher(ctx, cipher_ctx->partial, cipher_ctx->partial,
|
||||
cipher_ctx->blocksize) < 1)
|
||||
return 0;
|
||||
while (inl--) {
|
||||
out[cipher_ctx->num] = in[cipher_ctx->num]
|
||||
^ cipher_ctx->partial[cipher_ctx->num];
|
||||
cipher_ctx->num++;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void* p2)
|
||||
{
|
||||
struct cipher_ctx *cipher_ctx =
|
||||
(struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
||||
EVP_CIPHER_CTX *to_ctx = (EVP_CIPHER_CTX *)p2;
|
||||
struct cipher_ctx *to_cipher_ctx;
|
||||
|
||||
switch (type) {
|
||||
case EVP_CTRL_COPY:
|
||||
if (cipher_ctx == NULL)
|
||||
return 1;
|
||||
/* when copying the context, a new session needs to be initialized */
|
||||
to_cipher_ctx =
|
||||
(struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(to_ctx);
|
||||
memset(&to_cipher_ctx->sess, 0, sizeof(to_cipher_ctx->sess));
|
||||
return cipher_init(to_ctx, cipher_ctx->sess.key, EVP_CIPHER_CTX_iv(ctx),
|
||||
(cipher_ctx->op == COP_ENCRYPT));
|
||||
|
||||
case EVP_CTRL_INIT:
|
||||
memset(&cipher_ctx->sess, 0, sizeof(cipher_ctx->sess));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int cipher_cleanup(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
struct cipher_ctx *cipher_ctx =
|
||||
(struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
||||
|
||||
if (ioctl(cfd, CIOCFSESSION, &cipher_ctx->sess.ses) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return clean_devcrypto_session(&cipher_ctx->sess);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -235,6 +345,7 @@ static void prepare_cipher_methods(void)
|
||||
{
|
||||
size_t i;
|
||||
struct session_op sess;
|
||||
unsigned long cipher_mode;
|
||||
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
sess.key = (void *)"01234567890123456789012345678901234567890123456789";
|
||||
@ -252,18 +363,26 @@ static void prepare_cipher_methods(void)
|
||||
|| ioctl(cfd, CIOCFSESSION, &sess.ses) < 0)
|
||||
continue;
|
||||
|
||||
cipher_mode = cipher_data[i].flags & EVP_CIPH_MODE;
|
||||
|
||||
if ((known_cipher_methods[i] =
|
||||
EVP_CIPHER_meth_new(cipher_data[i].nid,
|
||||
cipher_data[i].blocksize,
|
||||
cipher_mode == EVP_CIPH_CTR_MODE ? 1 :
|
||||
cipher_data[i].blocksize,
|
||||
cipher_data[i].keylen)) == NULL
|
||||
|| !EVP_CIPHER_meth_set_iv_length(known_cipher_methods[i],
|
||||
cipher_data[i].ivlen)
|
||||
|| !EVP_CIPHER_meth_set_flags(known_cipher_methods[i],
|
||||
cipher_data[i].flags
|
||||
| EVP_CIPH_CUSTOM_COPY
|
||||
| EVP_CIPH_CTRL_INIT
|
||||
| EVP_CIPH_FLAG_DEFAULT_ASN1)
|
||||
|| !EVP_CIPHER_meth_set_init(known_cipher_methods[i], cipher_init)
|
||||
|| !EVP_CIPHER_meth_set_do_cipher(known_cipher_methods[i],
|
||||
cipher_mode == EVP_CIPH_CTR_MODE ?
|
||||
ctr_do_cipher :
|
||||
cipher_do_cipher)
|
||||
|| !EVP_CIPHER_meth_set_ctrl(known_cipher_methods[i], cipher_ctrl)
|
||||
|| !EVP_CIPHER_meth_set_cleanup(known_cipher_methods[i],
|
||||
cipher_cleanup)
|
||||
|| !EVP_CIPHER_meth_set_impl_ctx_size(known_cipher_methods[i],
|
||||
@ -340,34 +459,36 @@ static int devcrypto_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
|
||||
|
||||
struct digest_ctx {
|
||||
struct session_op sess;
|
||||
int init;
|
||||
/* This signals that the init function was called, not that it succeeded. */
|
||||
int init_called;
|
||||
};
|
||||
|
||||
static const struct digest_data_st {
|
||||
int nid;
|
||||
int blocksize;
|
||||
int digestlen;
|
||||
int devcryptoid;
|
||||
} digest_data[] = {
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
{ NID_md5, 16, CRYPTO_MD5 },
|
||||
{ NID_md5, /* MD5_CBLOCK */ 64, 16, CRYPTO_MD5 },
|
||||
#endif
|
||||
{ NID_sha1, 20, CRYPTO_SHA1 },
|
||||
{ NID_sha1, SHA_CBLOCK, 20, CRYPTO_SHA1 },
|
||||
#ifndef OPENSSL_NO_RMD160
|
||||
# if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_RIPEMD160)
|
||||
{ NID_ripemd160, 20, CRYPTO_RIPEMD160 },
|
||||
{ NID_ripemd160, /* RIPEMD160_CBLOCK */ 64, 20, CRYPTO_RIPEMD160 },
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_SHA2_224)
|
||||
{ NID_sha224, 224 / 8, CRYPTO_SHA2_224 },
|
||||
{ NID_sha224, SHA256_CBLOCK, 224 / 8, CRYPTO_SHA2_224 },
|
||||
#endif
|
||||
#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_SHA2_256)
|
||||
{ NID_sha256, 256 / 8, CRYPTO_SHA2_256 },
|
||||
{ NID_sha256, SHA256_CBLOCK, 256 / 8, CRYPTO_SHA2_256 },
|
||||
#endif
|
||||
#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_SHA2_384)
|
||||
{ NID_sha384, 384 / 8, CRYPTO_SHA2_384 },
|
||||
{ NID_sha384, SHA512_CBLOCK, 384 / 8, CRYPTO_SHA2_384 },
|
||||
#endif
|
||||
#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_SHA2_512)
|
||||
{ NID_sha512, 512 / 8, CRYPTO_SHA2_512 },
|
||||
{ NID_sha512, SHA512_CBLOCK, 512 / 8, CRYPTO_SHA2_512 },
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -405,7 +526,7 @@ static int digest_init(EVP_MD_CTX *ctx)
|
||||
const struct digest_data_st *digest_d =
|
||||
get_digest_data(EVP_MD_CTX_type(ctx));
|
||||
|
||||
digest_ctx->init = 1;
|
||||
digest_ctx->init_called = 1;
|
||||
|
||||
memset(&digest_ctx->sess, 0, sizeof(digest_ctx->sess));
|
||||
digest_ctx->sess.mac = digest_d->devcryptoid;
|
||||
@ -440,6 +561,9 @@ static int digest_update(EVP_MD_CTX *ctx, const void *data, size_t count)
|
||||
if (count == 0)
|
||||
return 1;
|
||||
|
||||
if (digest_ctx == NULL)
|
||||
return 0;
|
||||
|
||||
if (digest_op(digest_ctx, data, count, NULL, COP_FLAG_UPDATE) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
@ -453,11 +577,9 @@ static int digest_final(EVP_MD_CTX *ctx, unsigned char *md)
|
||||
struct digest_ctx *digest_ctx =
|
||||
(struct digest_ctx *)EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
if (md == NULL || digest_ctx == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (ioctl(cfd, CIOCFSESSION, &digest_ctx->sess.ses) < 0) {
|
||||
if (digest_op(digest_ctx, NULL, 0, md, COP_FLAG_FINAL) < 0) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
}
|
||||
@ -473,14 +595,9 @@ static int digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
|
||||
(struct digest_ctx *)EVP_MD_CTX_md_data(to);
|
||||
struct cphash_op cphash;
|
||||
|
||||
if (digest_from == NULL)
|
||||
if (digest_from == NULL || digest_from->init_called != 1)
|
||||
return 1;
|
||||
|
||||
if (digest_from->init != 1) {
|
||||
SYSerr(SYS_F_IOCTL, EINVAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!digest_init(to)) {
|
||||
SYSerr(SYS_F_IOCTL, errno);
|
||||
return 0;
|
||||
@ -497,7 +614,37 @@ static int digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from)
|
||||
|
||||
static int digest_cleanup(EVP_MD_CTX *ctx)
|
||||
{
|
||||
return 1;
|
||||
struct digest_ctx *digest_ctx =
|
||||
(struct digest_ctx *)EVP_MD_CTX_md_data(ctx);
|
||||
|
||||
if (digest_ctx == NULL)
|
||||
return 1;
|
||||
|
||||
return clean_devcrypto_session(&digest_ctx->sess);
|
||||
}
|
||||
|
||||
static int devcrypto_test_digest(size_t digest_data_index)
|
||||
{
|
||||
struct session_op sess1, sess2;
|
||||
struct cphash_op cphash;
|
||||
int ret=0;
|
||||
|
||||
memset(&sess1, 0, sizeof(sess1));
|
||||
memset(&sess2, 0, sizeof(sess2));
|
||||
sess1.mac = digest_data[digest_data_index].devcryptoid;
|
||||
if (ioctl(cfd, CIOCGSESSION, &sess1) < 0)
|
||||
return 0;
|
||||
/* Make sure the driver is capable of hash state copy */
|
||||
sess2.mac = sess1.mac;
|
||||
if (ioctl(cfd, CIOCGSESSION, &sess2) >= 0) {
|
||||
cphash.src_ses = sess1.ses;
|
||||
cphash.dst_ses = sess2.ses;
|
||||
if (ioctl(cfd, CIOCCPHASH, &cphash) >= 0)
|
||||
ret = 1;
|
||||
ioctl(cfd, CIOCFSESSION, &sess2.ses);
|
||||
}
|
||||
ioctl(cfd, CIOCFSESSION, &sess1.ses);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -512,24 +659,20 @@ static EVP_MD *known_digest_methods[OSSL_NELEM(digest_data)] = { NULL, };
|
||||
static void prepare_digest_methods(void)
|
||||
{
|
||||
size_t i;
|
||||
struct session_op sess;
|
||||
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
|
||||
for (i = 0, known_digest_nids_amount = 0; i < OSSL_NELEM(digest_data);
|
||||
i++) {
|
||||
|
||||
/*
|
||||
* Check that the algo is really availably by trying to open and close
|
||||
* a session.
|
||||
* Check that the algo is usable
|
||||
*/
|
||||
sess.mac = digest_data[i].devcryptoid;
|
||||
if (ioctl(cfd, CIOCGSESSION, &sess) < 0
|
||||
|| ioctl(cfd, CIOCFSESSION, &sess.ses) < 0)
|
||||
if (!devcrypto_test_digest(i))
|
||||
continue;
|
||||
|
||||
if ((known_digest_methods[i] = EVP_MD_meth_new(digest_data[i].nid,
|
||||
NID_undef)) == NULL
|
||||
|| !EVP_MD_meth_set_input_blocksize(known_digest_methods[i],
|
||||
digest_data[i].blocksize)
|
||||
|| !EVP_MD_meth_set_result_size(known_digest_methods[i],
|
||||
digest_data[i].digestlen)
|
||||
|| !EVP_MD_meth_set_init(known_digest_methods[i], digest_init)
|
||||
@ -617,15 +760,10 @@ void engine_load_devcrypto_int()
|
||||
ENGINE *e = NULL;
|
||||
|
||||
if ((cfd = open("/dev/crypto", O_RDWR, 0)) < 0) {
|
||||
fprintf(stderr, "Could not open /dev/crypto: %s\n", strerror(errno));
|
||||
fprintf(stderr, "Could not open /dev/crypto: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
prepare_cipher_methods();
|
||||
#ifdef IMPLEMENT_DIGEST
|
||||
prepare_digest_methods();
|
||||
#endif
|
||||
|
||||
if ((e = ENGINE_new()) == NULL
|
||||
|| !ENGINE_set_destroy_function(e, devcrypto_unload)) {
|
||||
ENGINE_free(e);
|
||||
@ -638,6 +776,11 @@ void engine_load_devcrypto_int()
|
||||
return;
|
||||
}
|
||||
|
||||
prepare_cipher_methods();
|
||||
#ifdef IMPLEMENT_DIGEST
|
||||
prepare_digest_methods();
|
||||
#endif
|
||||
|
||||
if (!ENGINE_set_id(e, "devcrypto")
|
||||
|| !ENGINE_set_name(e, "/dev/crypto engine")
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -126,7 +126,7 @@ static int int_cleanup_check(int create)
|
||||
static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
|
||||
{
|
||||
ENGINE_CLEANUP_ITEM *item;
|
||||
|
||||
|
||||
if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) {
|
||||
ENGINEerr(ENGINE_F_INT_CLEANUP_ITEM, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -21,6 +21,9 @@
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
#include "internal/thread_once.h"
|
||||
#include "internal/ctype.h"
|
||||
#include "internal/constant_time_locl.h"
|
||||
#include "e_os.h"
|
||||
|
||||
static int err_load_strings(const ERR_STRING_DATA *str);
|
||||
|
||||
@ -183,8 +186,9 @@ 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
|
||||
# define NUM_SYS_STR_REASONS 127
|
||||
# define LEN_SYS_STR_REASON 32
|
||||
|
||||
static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
|
||||
/*
|
||||
@ -200,9 +204,12 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
|
||||
static void build_SYS_str_reasons(void)
|
||||
{
|
||||
/* OPENSSL_malloc cannot be used here, use static storage instead */
|
||||
static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
|
||||
static char strerror_pool[SPACE_SYS_STR_REASONS];
|
||||
char *cur = strerror_pool;
|
||||
size_t cnt = 0;
|
||||
static int init = 1;
|
||||
int i;
|
||||
int saveerrno = get_last_sys_error();
|
||||
|
||||
CRYPTO_THREAD_write_lock(err_string_lock);
|
||||
if (!init) {
|
||||
@ -215,9 +222,26 @@ static void build_SYS_str_reasons(void)
|
||||
|
||||
str->error = ERR_PACK(ERR_LIB_SYS, 0, i);
|
||||
if (str->string == NULL) {
|
||||
char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
|
||||
if (openssl_strerror_r(i, *dest, sizeof(*dest)))
|
||||
str->string = *dest;
|
||||
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.
|
||||
*/
|
||||
while (ossl_isspace(cur[-1])) {
|
||||
cur--;
|
||||
cnt--;
|
||||
}
|
||||
*cur++ = '\0';
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
if (str->string == NULL)
|
||||
str->string = "unknown";
|
||||
@ -231,6 +255,8 @@ static void build_SYS_str_reasons(void)
|
||||
init = 0;
|
||||
|
||||
CRYPTO_THREAD_unlock(err_string_lock);
|
||||
/* openssl_strerror_r could change errno, but we want to preserve it */
|
||||
set_sys_error(saveerrno);
|
||||
err_load_strings(SYS_str_reasons);
|
||||
}
|
||||
#endif
|
||||
@ -673,6 +699,7 @@ DEFINE_RUN_ONCE_STATIC(err_do_init)
|
||||
ERR_STATE *ERR_get_state(void)
|
||||
{
|
||||
ERR_STATE *state;
|
||||
int saveerrno = get_last_sys_error();
|
||||
|
||||
if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
|
||||
return NULL;
|
||||
@ -704,6 +731,7 @@ ERR_STATE *ERR_get_state(void)
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
|
||||
}
|
||||
|
||||
set_sys_error(saveerrno);
|
||||
return state;
|
||||
}
|
||||
|
||||
@ -713,6 +741,20 @@ ERR_STATE *ERR_get_state(void)
|
||||
*/
|
||||
int err_shelve_state(void **state)
|
||||
{
|
||||
int saveerrno = get_last_sys_error();
|
||||
|
||||
/*
|
||||
* Note, at present our only caller is OPENSSL_init_crypto(), indirectly
|
||||
* via ossl_init_load_crypto_nodelete(), by which point the requested
|
||||
* "base" initialization has already been performed, so the below call is a
|
||||
* NOOP, that re-enters OPENSSL_init_crypto() only to quickly return.
|
||||
*
|
||||
* If are no other valid callers of this function, the call below can be
|
||||
* removed, avoiding the re-entry into OPENSSL_init_crypto(). If there are
|
||||
* potential uses that are not from inside OPENSSL_init_crypto(), then this
|
||||
* call is needed, but some care is required to make sure that the re-entry
|
||||
* remains a NOOP.
|
||||
*/
|
||||
if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
|
||||
return 0;
|
||||
|
||||
@ -723,6 +765,7 @@ int err_shelve_state(void **state)
|
||||
if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
|
||||
return 0;
|
||||
|
||||
set_sys_error(saveerrno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -749,20 +792,31 @@ int ERR_get_next_error_library(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ERR_set_error_data(char *data, int flags)
|
||||
static int err_set_error_data_int(char *data, int flags)
|
||||
{
|
||||
ERR_STATE *es;
|
||||
int i;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
i = es->top;
|
||||
|
||||
err_clear_data(es, i);
|
||||
es->err_data[i] = data;
|
||||
es->err_data_flags[i] = flags;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ERR_set_error_data(char *data, int flags)
|
||||
{
|
||||
/*
|
||||
* This function is void so we cannot propagate the error return. Since it
|
||||
* is also in the public API we can't change the return type.
|
||||
*/
|
||||
err_set_error_data_int(data, flags);
|
||||
}
|
||||
|
||||
void ERR_add_error_data(int num, ...)
|
||||
@ -802,7 +856,8 @@ void ERR_add_error_vdata(int num, va_list args)
|
||||
}
|
||||
OPENSSL_strlcat(str, a, (size_t)s + 1);
|
||||
}
|
||||
ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING);
|
||||
if (!err_set_error_data_int(str, ERR_TXT_MALLOCED | ERR_TXT_STRING))
|
||||
OPENSSL_free(str);
|
||||
}
|
||||
|
||||
int ERR_set_mark(void)
|
||||
@ -859,3 +914,42 @@ int ERR_clear_last_mark(void)
|
||||
es->err_flags[top] &= ~ERR_FLAG_MARK;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef UINTPTR_T
|
||||
# undef UINTPTR_T
|
||||
#endif
|
||||
/*
|
||||
* uintptr_t is the answer, but unfortunately C89, current "least common
|
||||
* denominator" doesn't define it. Most legacy platforms typedef it anyway,
|
||||
* so that attempt to fill the gaps means that one would have to identify
|
||||
* that track these gaps, which would be undesirable. Macro it is...
|
||||
*/
|
||||
#if defined(__VMS) && __INITIAL_POINTER_SIZE==64
|
||||
/*
|
||||
* But we can't use size_t on VMS, because it adheres to sizeof(size_t)==4
|
||||
* even in 64-bit builds, which means that it won't work as mask.
|
||||
*/
|
||||
# define UINTPTR_T unsigned long long
|
||||
#else
|
||||
# define UINTPTR_T size_t
|
||||
#endif
|
||||
|
||||
void err_clear_last_constant_time(int clear)
|
||||
{
|
||||
ERR_STATE *es;
|
||||
int top;
|
||||
|
||||
es = ERR_get_state();
|
||||
if (es == NULL)
|
||||
return;
|
||||
|
||||
top = es->top;
|
||||
|
||||
es->err_flags[top] &= ~(0 - clear);
|
||||
es->err_buffer[top] &= ~(0UL - clear);
|
||||
es->err_file[top] = (const char *)((UINTPTR_T)es->err_file[top] &
|
||||
~((UINTPTR_T)0 - clear));
|
||||
es->err_line[top] |= 0 - clear;
|
||||
|
||||
es->top = (top + ERR_NUM_ERRORS - clear) % ERR_NUM_ERRORS;
|
||||
}
|
||||
|
@ -296,8 +296,9 @@ int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)
|
||||
return overlapped;
|
||||
}
|
||||
|
||||
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
const unsigned char *in, int inl)
|
||||
static int evp_EncryptDecryptUpdate(EVP_CIPHER_CTX *ctx,
|
||||
unsigned char *out, int *outl,
|
||||
const unsigned char *in, int inl)
|
||||
{
|
||||
int i, j, bl, cmpl = inl;
|
||||
|
||||
@ -309,7 +310,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
|
||||
/* If block size > 1 then the cipher will have to do this check */
|
||||
if (bl == 1 && is_partially_overlapping(out, in, cmpl)) {
|
||||
EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
|
||||
EVPerr(EVP_F_EVP_ENCRYPTDECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -326,7 +327,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
return inl == 0;
|
||||
}
|
||||
if (is_partially_overlapping(out + ctx->buf_len, in, cmpl)) {
|
||||
EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
|
||||
EVPerr(EVP_F_EVP_ENCRYPTDECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -373,6 +374,19 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
const unsigned char *in, int inl)
|
||||
{
|
||||
/* Prevent accidental use of decryption context when encrypting */
|
||||
if (!ctx->encrypt) {
|
||||
EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);
|
||||
}
|
||||
|
||||
int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
{
|
||||
int ret;
|
||||
@ -385,6 +399,12 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
int n, ret;
|
||||
unsigned int i, b, bl;
|
||||
|
||||
/* Prevent accidental use of decryption context when encrypting */
|
||||
if (!ctx->encrypt) {
|
||||
EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX, EVP_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
|
||||
ret = ctx->cipher->do_cipher(ctx, out, NULL, 0);
|
||||
if (ret < 0)
|
||||
@ -428,6 +448,12 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
int fix_len, cmpl = inl;
|
||||
unsigned int b;
|
||||
|
||||
/* Prevent accidental use of encryption context when decrypting */
|
||||
if (ctx->encrypt) {
|
||||
EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
b = ctx->cipher->block_size;
|
||||
|
||||
if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))
|
||||
@ -454,7 +480,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
}
|
||||
|
||||
if (ctx->flags & EVP_CIPH_NO_PADDING)
|
||||
return EVP_EncryptUpdate(ctx, out, outl, in, inl);
|
||||
return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);
|
||||
|
||||
OPENSSL_assert(b <= sizeof(ctx->final));
|
||||
|
||||
@ -471,7 +497,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
|
||||
} else
|
||||
fix_len = 0;
|
||||
|
||||
if (!EVP_EncryptUpdate(ctx, out, outl, in, inl))
|
||||
if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
@ -502,6 +528,13 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
|
||||
{
|
||||
int i, n;
|
||||
unsigned int b;
|
||||
|
||||
/* Prevent accidental use of encryption context when decrypting */
|
||||
if (ctx->encrypt) {
|
||||
EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_INVALID_OPERATION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*outl = 0;
|
||||
|
||||
if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
|
||||
|
@ -52,6 +52,8 @@ static const ERR_STRING_DATA EVP_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTUPDATE, 0), "EVP_DecryptUpdate"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTFINALXOF, 0), "EVP_DigestFinalXOF"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTINIT_EX, 0), "EVP_DigestInit_ex"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_ENCRYPTDECRYPTUPDATE, 0),
|
||||
"evp_EncryptDecryptUpdate"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_ENCRYPTFINAL_EX, 0),
|
||||
"EVP_EncryptFinal_ex"},
|
||||
{ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_ENCRYPTUPDATE, 0), "EVP_EncryptUpdate"},
|
||||
|
@ -44,7 +44,7 @@ int EVP_PKEY_security_bits(const EVP_PKEY *pkey)
|
||||
return pkey->ameth->pkey_security_bits(pkey);
|
||||
}
|
||||
|
||||
int EVP_PKEY_size(EVP_PKEY *pkey)
|
||||
int EVP_PKEY_size(const EVP_PKEY *pkey)
|
||||
{
|
||||
if (pkey && pkey->ameth && pkey->ameth->pkey_size)
|
||||
return pkey->ameth->pkey_size(pkey);
|
||||
|
@ -65,7 +65,10 @@ int bn_set_words(BIGNUM *a, const BN_ULONG *words, int num_words);
|
||||
* is customarily arranged by bn_correct_top. Output from below functions
|
||||
* is not processed with bn_correct_top, and for this reason it may not be
|
||||
* returned out of public API. It may only be passed internally into other
|
||||
* functions known to support non-minimal or zero-padded BIGNUMs.
|
||||
* functions known to support non-minimal or zero-padded BIGNUMs. Even
|
||||
* though the goal is to facilitate constant-time-ness, not each subroutine
|
||||
* is constant-time by itself. They all have pre-conditions, consult source
|
||||
* code...
|
||||
*/
|
||||
int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
BN_MONT_CTX *mont, BN_CTX *ctx);
|
||||
@ -79,5 +82,9 @@ int bn_mod_sub_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
|
||||
const BIGNUM *m);
|
||||
int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
|
||||
int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
|
||||
int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int bn_rshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
|
||||
const BIGNUM *d, BN_CTX *ctx);
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -104,12 +104,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_base)
|
||||
return 0;
|
||||
if ((init_lock = CRYPTO_THREAD_lock_new()) == NULL)
|
||||
goto err;
|
||||
#ifndef OPENSSL_SYS_UEFI
|
||||
#ifndef __rtems__
|
||||
if (atexit(OPENSSL_cleanup) != 0)
|
||||
goto err;
|
||||
#endif /* __rtems__ */
|
||||
#endif
|
||||
OPENSSL_cpuid_setup();
|
||||
|
||||
destructor_key.value = key;
|
||||
@ -127,13 +121,55 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
static CRYPTO_ONCE register_atexit = CRYPTO_ONCE_STATIC_INIT;
|
||||
#if !defined(OPENSSL_SYS_UEFI) && defined(_WIN32)
|
||||
static int win32atexit(void)
|
||||
{
|
||||
OPENSSL_cleanup();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_register_atexit)
|
||||
{
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr, "OPENSSL_INIT: ossl_init_register_atexit()\n");
|
||||
#endif
|
||||
#ifndef OPENSSL_SYS_UEFI
|
||||
# ifdef _WIN32
|
||||
/* We use _onexit() in preference because it gets called on DLL unload */
|
||||
if (_onexit(win32atexit) == NULL)
|
||||
return 0;
|
||||
# else
|
||||
if (atexit(OPENSSL_cleanup) != 0)
|
||||
return 0;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_register_atexit,
|
||||
ossl_init_register_atexit)
|
||||
{
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr, "OPENSSL_INIT: ossl_init_no_register_atexit ok!\n");
|
||||
#endif
|
||||
/* Do nothing in this case */
|
||||
return 1;
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
static CRYPTO_ONCE load_crypto_nodelete = CRYPTO_ONCE_STATIC_INIT;
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_nodelete)
|
||||
{
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr, "OPENSSL_INIT: ossl_init_load_crypto_nodelete()\n");
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_DSO) && !defined(OPENSSL_USE_NODELETE)
|
||||
#if !defined(OPENSSL_NO_DSO) \
|
||||
&& !defined(OPENSSL_USE_NODELETE) \
|
||||
&& !defined(OPENSSL_NO_PINSHARED)
|
||||
# ifdef DSO_WIN32
|
||||
{
|
||||
HMODULE handle = NULL;
|
||||
@ -183,12 +219,6 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_nodelete)
|
||||
|
||||
static CRYPTO_ONCE load_crypto_strings = CRYPTO_ONCE_STATIC_INIT;
|
||||
static int load_crypto_strings_inited = 0;
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_crypto_strings)
|
||||
{
|
||||
/* Do nothing in this case */
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
|
||||
{
|
||||
int ret = 1;
|
||||
@ -207,6 +237,13 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_strings)
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_load_crypto_strings,
|
||||
ossl_init_load_crypto_strings)
|
||||
{
|
||||
/* Do nothing in this case */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static CRYPTO_ONCE add_all_ciphers = CRYPTO_ONCE_STATIC_INIT;
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
|
||||
{
|
||||
@ -224,6 +261,13 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_ciphers)
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_add_all_ciphers,
|
||||
ossl_init_add_all_ciphers)
|
||||
{
|
||||
/* Do nothing */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static CRYPTO_ONCE add_all_digests = CRYPTO_ONCE_STATIC_INIT;
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
|
||||
{
|
||||
@ -241,7 +285,8 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_add_all_digests)
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_add_all_digests,
|
||||
ossl_init_add_all_digests)
|
||||
{
|
||||
/* Do nothing */
|
||||
return 1;
|
||||
@ -249,19 +294,14 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_no_add_algs)
|
||||
|
||||
static CRYPTO_ONCE config = CRYPTO_ONCE_STATIC_INIT;
|
||||
static int config_inited = 0;
|
||||
static const char *appname;
|
||||
static const OPENSSL_INIT_SETTINGS *conf_settings = NULL;
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_config)
|
||||
{
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr,
|
||||
"OPENSSL_INIT: ossl_init_config: openssl_config(%s)\n",
|
||||
appname == NULL ? "NULL" : appname);
|
||||
#endif
|
||||
openssl_config_int(appname);
|
||||
int ret = openssl_config_int(conf_settings);
|
||||
config_inited = 1;
|
||||
return 1;
|
||||
return ret;
|
||||
}
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_no_config)
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_config, ossl_init_config)
|
||||
{
|
||||
#ifdef OPENSSL_INIT_DEBUG
|
||||
fprintf(stderr,
|
||||
@ -596,17 +636,45 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* When the caller specifies OPENSSL_INIT_BASE_ONLY, that should be the
|
||||
* *only* option specified. With that option we return immediately after
|
||||
* doing the requested limited initialization. Note that
|
||||
* err_shelve_state() called by us via ossl_init_load_crypto_nodelete()
|
||||
* re-enters OPENSSL_init_crypto() with OPENSSL_INIT_BASE_ONLY, but with
|
||||
* base already initialized this is a harmless NOOP.
|
||||
*
|
||||
* If we remain the only caller of err_shelve_state() the recursion should
|
||||
* perhaps be removed, but if in doubt, it can be left in place.
|
||||
*/
|
||||
if (!RUN_ONCE(&base, ossl_init_base))
|
||||
return 0;
|
||||
if (opts & OPENSSL_INIT_BASE_ONLY)
|
||||
return 1;
|
||||
|
||||
if (!(opts & OPENSSL_INIT_BASE_ONLY)
|
||||
&& !RUN_ONCE(&load_crypto_nodelete,
|
||||
ossl_init_load_crypto_nodelete))
|
||||
#ifndef __rtems__
|
||||
/*
|
||||
* Now we don't always set up exit handlers, the INIT_BASE_ONLY calls
|
||||
* should not have the side-effect of setting up exit handlers, and
|
||||
* therefore, this code block is below the INIT_BASE_ONLY-conditioned early
|
||||
* return above.
|
||||
*/
|
||||
if ((opts & OPENSSL_INIT_NO_ATEXIT) != 0) {
|
||||
if (!RUN_ONCE_ALT(®ister_atexit, ossl_init_no_register_atexit,
|
||||
ossl_init_register_atexit))
|
||||
return 0;
|
||||
} else if (!RUN_ONCE(®ister_atexit, ossl_init_register_atexit)) {
|
||||
return 0;
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
if (!RUN_ONCE(&load_crypto_nodelete, ossl_init_load_crypto_nodelete))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
|
||||
&& !RUN_ONCE(&load_crypto_strings,
|
||||
ossl_init_no_load_crypto_strings))
|
||||
&& !RUN_ONCE_ALT(&load_crypto_strings,
|
||||
ossl_init_no_load_crypto_strings,
|
||||
ossl_init_load_crypto_strings))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
|
||||
@ -614,7 +682,8 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
|
||||
&& !RUN_ONCE(&add_all_ciphers, ossl_init_no_add_algs))
|
||||
&& !RUN_ONCE_ALT(&add_all_ciphers, ossl_init_no_add_all_ciphers,
|
||||
ossl_init_add_all_ciphers))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
|
||||
@ -622,7 +691,8 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
|
||||
&& !RUN_ONCE(&add_all_digests, ossl_init_no_add_algs))
|
||||
&& !RUN_ONCE_ALT(&add_all_digests, ossl_init_no_add_all_digests,
|
||||
ossl_init_add_all_digests))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
|
||||
@ -634,14 +704,15 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG)
|
||||
&& !RUN_ONCE(&config, ossl_init_no_config))
|
||||
&& !RUN_ONCE_ALT(&config, ossl_init_no_config, ossl_init_config))
|
||||
return 0;
|
||||
|
||||
if (opts & OPENSSL_INIT_LOAD_CONFIG) {
|
||||
int ret;
|
||||
CRYPTO_THREAD_write_lock(init_lock);
|
||||
appname = (settings == NULL) ? NULL : settings->appname;
|
||||
conf_settings = settings;
|
||||
ret = RUN_ONCE(&config, ossl_init_config);
|
||||
conf_settings = NULL;
|
||||
CRYPTO_THREAD_unlock(init_lock);
|
||||
if (!ret)
|
||||
return 0;
|
||||
@ -708,7 +779,9 @@ int OPENSSL_atexit(void (*handler)(void))
|
||||
{
|
||||
OPENSSL_INIT_STOP *newhand;
|
||||
|
||||
#if !defined(OPENSSL_NO_DSO) && !defined(OPENSSL_USE_NODELETE)
|
||||
#if !defined(OPENSSL_NO_DSO) \
|
||||
&& !defined(OPENSSL_USE_NODELETE)\
|
||||
&& !defined(OPENSSL_NO_PINSHARED)
|
||||
{
|
||||
union {
|
||||
void *sym;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/objects/obj_dat.pl
|
||||
*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the OpenSSL license (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
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by objxref.pl
|
||||
*
|
||||
* Copyright 1998-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1998-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -299,7 +299,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Create the right magic header stuff */
|
||||
/* Create the right magic header stuff */
|
||||
buf[0] = '\0';
|
||||
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);
|
||||
PEM_dek_info(buf, objstr, EVP_CIPHER_iv_length(enc),
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2014-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -22,5 +22,7 @@ extern unsigned int OPENSSL_ppccap_P;
|
||||
# define PPC_CRYPTO207 (1<<2)
|
||||
# define PPC_FPU (1<<3)
|
||||
# define PPC_MADD300 (1<<4)
|
||||
# define PPC_MFTB (1<<5)
|
||||
# define PPC_MFSPR268 (1<<6)
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -95,6 +95,27 @@ static uint64_t get_timer_bits(void);
|
||||
# error "UEFI and VXWorks only support seeding NONE"
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_SYS_VXWORKS)
|
||||
/* empty implementation */
|
||||
int rand_pool_init(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void rand_pool_cleanup(void)
|
||||
{
|
||||
}
|
||||
|
||||
void rand_pool_keep_random_devices_open(int keep)
|
||||
{
|
||||
}
|
||||
|
||||
size_t rand_pool_acquire_entropy(RAND_POOL *pool)
|
||||
{
|
||||
return rand_pool_entropy_available(pool);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) \
|
||||
|| defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VXWORKS) \
|
||||
|| defined(OPENSSL_SYS_UEFI))
|
||||
|
@ -36,7 +36,7 @@ static int rsa_param_encode(const EVP_PKEY *pkey,
|
||||
|
||||
*pstr = NULL;
|
||||
/* If RSA it's just NULL type */
|
||||
if (pkey->ameth->pkey_id == EVP_PKEY_RSA) {
|
||||
if (pkey->ameth->pkey_id != EVP_PKEY_RSA_PSS) {
|
||||
*pstrtype = V_ASN1_NULL;
|
||||
return 1;
|
||||
}
|
||||
@ -60,7 +60,7 @@ static int rsa_param_decode(RSA *rsa, const X509_ALGOR *alg)
|
||||
int algptype;
|
||||
|
||||
X509_ALGOR_get0(&algoid, &algptype, &algp, alg);
|
||||
if (OBJ_obj2nid(algoid) == EVP_PKEY_RSA)
|
||||
if (OBJ_obj2nid(algoid) != EVP_PKEY_RSA_PSS)
|
||||
return 1;
|
||||
if (algptype == V_ASN1_UNDEF)
|
||||
return 1;
|
||||
@ -111,7 +111,10 @@ static int rsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
RSA_free(rsa);
|
||||
return 0;
|
||||
}
|
||||
EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa);
|
||||
if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, rsa)) {
|
||||
RSA_free(rsa);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
|
||||
const EVP_MD *mgf1md)
|
||||
{
|
||||
int i, dblen = 0, mlen = -1, one_index = 0, msg_index;
|
||||
unsigned int good, found_one_byte;
|
||||
unsigned int good = 0, found_one_byte, mask;
|
||||
const unsigned char *maskedseed, *maskeddb;
|
||||
/*
|
||||
* |em| is the encoded message, zero-padded to exactly |num| bytes: em =
|
||||
@ -149,8 +149,11 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
|
||||
* the ciphertext, see PKCS #1 v2.2, section 7.1.2.
|
||||
* This does not leak any side-channel information.
|
||||
*/
|
||||
if (num < flen || num < 2 * mdlen + 2)
|
||||
goto decoding_err;
|
||||
if (num < flen || num < 2 * mdlen + 2) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,
|
||||
RSA_R_OAEP_DECODING_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dblen = num - mdlen - 1;
|
||||
db = OPENSSL_malloc(dblen);
|
||||
@ -159,26 +162,27 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (flen != num) {
|
||||
em = OPENSSL_zalloc(num);
|
||||
if (em == NULL) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Caller is encouraged to pass zero-padded message created with
|
||||
* BN_bn2binpad, but if it doesn't, we do this zero-padding copy
|
||||
* to avoid leaking that information. The copy still leaks some
|
||||
* side-channel information, but it's impossible to have a fixed
|
||||
* memory access pattern since we can't read out of the bounds of
|
||||
* |from|.
|
||||
*/
|
||||
memcpy(em + num - flen, from, flen);
|
||||
from = em;
|
||||
em = OPENSSL_malloc(num);
|
||||
if (em == NULL) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,
|
||||
ERR_R_MALLOC_FAILURE);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Caller is encouraged to pass zero-padded message created with
|
||||
* BN_bn2binpad. Trouble is that since we can't read out of |from|'s
|
||||
* bounds, it's impossible to have an invariant memory access pattern
|
||||
* in case |from| was not zero-padded in advance.
|
||||
*/
|
||||
for (from += flen, em += num, i = 0; i < num; i++) {
|
||||
mask = ~constant_time_is_zero(flen);
|
||||
flen -= 1 & mask;
|
||||
from -= 1 & mask;
|
||||
*--em = *from & mask;
|
||||
}
|
||||
from = em;
|
||||
|
||||
/*
|
||||
* The first byte must be zero, however we must not leak if this is
|
||||
* true. See James H. Manger, "A Chosen Ciphertext Attack on RSA
|
||||
@ -224,32 +228,48 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
|
||||
* so plaintext-awareness ensures timing side-channels are no longer a
|
||||
* concern.
|
||||
*/
|
||||
if (!good)
|
||||
goto decoding_err;
|
||||
|
||||
msg_index = one_index + 1;
|
||||
mlen = dblen - msg_index;
|
||||
|
||||
if (tlen < mlen) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1, RSA_R_DATA_TOO_LARGE);
|
||||
mlen = -1;
|
||||
} else {
|
||||
memcpy(to, db + msg_index, mlen);
|
||||
goto cleanup;
|
||||
/*
|
||||
* For good measure, do this check in constant tine as well.
|
||||
*/
|
||||
good &= constant_time_ge(tlen, mlen);
|
||||
|
||||
/*
|
||||
* Even though we can't fake result's length, we can pretend copying
|
||||
* |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |dblen|
|
||||
* bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
|
||||
* where |mlen'| is "saturated" |mlen| value. Deducing information
|
||||
* about failure or |mlen| would take attacker's ability to observe
|
||||
* memory access pattern with byte granularity *as it occurs*. It
|
||||
* should be noted that failure is indistinguishable from normal
|
||||
* operation if |tlen| is fixed by protocol.
|
||||
*/
|
||||
tlen = constant_time_select_int(constant_time_lt(dblen, tlen), dblen, tlen);
|
||||
msg_index = constant_time_select_int(good, msg_index, dblen - tlen);
|
||||
mlen = dblen - msg_index;
|
||||
for (from = db + msg_index, mask = good, i = 0; i < tlen; i++) {
|
||||
unsigned int equals = constant_time_eq(i, mlen);
|
||||
|
||||
from -= dblen & equals; /* if (i == dblen) rewind */
|
||||
mask &= mask ^ equals; /* if (i == dblen) mask = 0 */
|
||||
to[i] = constant_time_select_8(mask, from[i], to[i]);
|
||||
}
|
||||
|
||||
decoding_err:
|
||||
/*
|
||||
* To avoid chosen ciphertext attacks, the error message should not
|
||||
* reveal which kind of decoding error happened.
|
||||
*/
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,
|
||||
RSA_R_OAEP_DECODING_ERROR);
|
||||
err_clear_last_constant_time(1 & good);
|
||||
cleanup:
|
||||
OPENSSL_cleanse(seed, sizeof(seed));
|
||||
OPENSSL_clear_free(db, dblen);
|
||||
OPENSSL_clear_free(em, num);
|
||||
return mlen;
|
||||
|
||||
return constant_time_select_int(good, mlen, -1);
|
||||
}
|
||||
|
||||
int PKCS1_MGF1(unsigned char *mask, long len,
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "internal/cryptlib.h"
|
||||
#include "internal/bn_int.h"
|
||||
#include "rsa_locl.h"
|
||||
#include "internal/constant_time_locl.h"
|
||||
|
||||
static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,
|
||||
unsigned char *to, RSA *rsa, int padding);
|
||||
@ -288,6 +289,11 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
|
||||
if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
|
||||
rsa->n, ctx))
|
||||
goto err;
|
||||
|
||||
if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {
|
||||
blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
|
||||
if (blinding == NULL) {
|
||||
@ -320,13 +326,6 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,
|
||||
}
|
||||
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
|
||||
|
||||
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
|
||||
if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
|
||||
rsa->n, ctx)) {
|
||||
BN_free(d);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
|
||||
rsa->_method_mod_n)) {
|
||||
BN_free(d);
|
||||
@ -483,8 +482,8 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);
|
||||
goto err;
|
||||
}
|
||||
if (r < 0)
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
|
||||
RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
|
||||
err_clear_last_constant_time(r >= 0);
|
||||
|
||||
err:
|
||||
if (ctx != NULL)
|
||||
|
@ -160,10 +160,10 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
|
||||
int i;
|
||||
/* |em| is the encoded message, zero-padded to exactly |num| bytes */
|
||||
unsigned char *em = NULL;
|
||||
unsigned int good, found_zero_byte;
|
||||
unsigned int good, found_zero_byte, mask;
|
||||
int zero_index = 0, msg_index, mlen = -1;
|
||||
|
||||
if (tlen < 0 || flen < 0)
|
||||
if (tlen <= 0 || flen <= 0)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
@ -171,39 +171,41 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
|
||||
* section 7.2.2.
|
||||
*/
|
||||
|
||||
if (flen > num)
|
||||
goto err;
|
||||
|
||||
if (num < 11)
|
||||
goto err;
|
||||
|
||||
if (flen != num) {
|
||||
em = OPENSSL_zalloc(num);
|
||||
if (em == NULL) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Caller is encouraged to pass zero-padded message created with
|
||||
* BN_bn2binpad, but if it doesn't, we do this zero-padding copy
|
||||
* to avoid leaking that information. The copy still leaks some
|
||||
* side-channel information, but it's impossible to have a fixed
|
||||
* memory access pattern since we can't read out of the bounds of
|
||||
* |from|.
|
||||
*/
|
||||
memcpy(em + num - flen, from, flen);
|
||||
from = em;
|
||||
if (flen > num || num < 11) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,
|
||||
RSA_R_PKCS_DECODING_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
em = OPENSSL_malloc(num);
|
||||
if (em == NULL) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Caller is encouraged to pass zero-padded message created with
|
||||
* BN_bn2binpad. Trouble is that since we can't read out of |from|'s
|
||||
* bounds, it's impossible to have an invariant memory access pattern
|
||||
* in case |from| was not zero-padded in advance.
|
||||
*/
|
||||
for (from += flen, em += num, i = 0; i < num; i++) {
|
||||
mask = ~constant_time_is_zero(flen);
|
||||
flen -= 1 & mask;
|
||||
from -= 1 & mask;
|
||||
*--em = *from & mask;
|
||||
}
|
||||
from = em;
|
||||
|
||||
good = constant_time_is_zero(from[0]);
|
||||
good &= constant_time_eq(from[1], 2);
|
||||
|
||||
/* scan over padding data */
|
||||
found_zero_byte = 0;
|
||||
for (i = 2; i < num; i++) {
|
||||
unsigned int equals0 = constant_time_is_zero(from[i]);
|
||||
zero_index =
|
||||
constant_time_select_int(~found_zero_byte & equals0, i,
|
||||
zero_index);
|
||||
|
||||
zero_index = constant_time_select_int(~found_zero_byte & equals0,
|
||||
i, zero_index);
|
||||
found_zero_byte |= equals0;
|
||||
}
|
||||
|
||||
@ -212,7 +214,7 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
|
||||
* If we never found a 0-byte, then |zero_index| is 0 and the check
|
||||
* also fails.
|
||||
*/
|
||||
good &= constant_time_ge((unsigned int)(zero_index), 2 + 8);
|
||||
good &= constant_time_ge(zero_index, 2 + 8);
|
||||
|
||||
/*
|
||||
* Skip the zero byte. This is incorrect if we never found a zero-byte
|
||||
@ -222,27 +224,34 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
|
||||
mlen = num - msg_index;
|
||||
|
||||
/*
|
||||
* For good measure, do this check in constant time as well; it could
|
||||
* leak something if |tlen| was assuming valid padding.
|
||||
* For good measure, do this check in constant time as well.
|
||||
*/
|
||||
good &= constant_time_ge((unsigned int)(tlen), (unsigned int)(mlen));
|
||||
good &= constant_time_ge(tlen, mlen);
|
||||
|
||||
/*
|
||||
* We can't continue in constant-time because we need to copy the result
|
||||
* and we cannot fake its length. This unavoidably leaks timing
|
||||
* information at the API boundary.
|
||||
* Even though we can't fake result's length, we can pretend copying
|
||||
* |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num|
|
||||
* bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
|
||||
* where |mlen'| is "saturated" |mlen| value. Deducing information
|
||||
* about failure or |mlen| would take attacker's ability to observe
|
||||
* memory access pattern with byte granularity *as it occurs*. It
|
||||
* should be noted that failure is indistinguishable from normal
|
||||
* operation if |tlen| is fixed by protocol.
|
||||
*/
|
||||
if (!good) {
|
||||
mlen = -1;
|
||||
goto err;
|
||||
tlen = constant_time_select_int(constant_time_lt(num, tlen), num, tlen);
|
||||
msg_index = constant_time_select_int(good, msg_index, num - tlen);
|
||||
mlen = num - msg_index;
|
||||
for (from += msg_index, mask = good, i = 0; i < tlen; i++) {
|
||||
unsigned int equals = constant_time_eq(i, mlen);
|
||||
|
||||
from -= tlen & equals; /* if (i == mlen) rewind */
|
||||
mask &= mask ^ equals; /* if (i == mlen) mask = 0 */
|
||||
to[i] = constant_time_select_8(mask, from[i], to[i]);
|
||||
}
|
||||
|
||||
memcpy(to, from + msg_index, mlen);
|
||||
|
||||
err:
|
||||
OPENSSL_clear_free(em, num);
|
||||
if (mlen == -1)
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,
|
||||
RSA_R_PKCS_DECODING_ERROR);
|
||||
return mlen;
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, RSA_R_PKCS_DECODING_ERROR);
|
||||
err_clear_last_constant_time(1 & good);
|
||||
|
||||
return constant_time_select_int(good, mlen, -1);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/rand.h>
|
||||
#include "internal/constant_time_locl.h"
|
||||
|
||||
int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
|
||||
const unsigned char *from, int flen)
|
||||
@ -54,57 +55,115 @@ int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy of RSA_padding_check_PKCS1_type_2 with a twist that rejects padding
|
||||
* if nul delimiter is preceded by 8 consecutive 0x03 bytes. It also
|
||||
* preserves error code reporting for backward compatibility.
|
||||
*/
|
||||
int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
|
||||
const unsigned char *from, int flen, int num)
|
||||
{
|
||||
int i, j, k;
|
||||
const unsigned char *p;
|
||||
int i;
|
||||
/* |em| is the encoded message, zero-padded to exactly |num| bytes */
|
||||
unsigned char *em = NULL;
|
||||
unsigned int good, found_zero_byte, mask, threes_in_row;
|
||||
int zero_index = 0, msg_index, mlen = -1, err;
|
||||
|
||||
p = from;
|
||||
if (flen < 10) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_SMALL);
|
||||
return -1;
|
||||
}
|
||||
/* Accept even zero-padded input */
|
||||
if (flen == num) {
|
||||
if (*(p++) != 0) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_BLOCK_TYPE_IS_NOT_02);
|
||||
return -1;
|
||||
}
|
||||
flen--;
|
||||
}
|
||||
if ((num != (flen + 1)) || (*(p++) != 02)) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_BLOCK_TYPE_IS_NOT_02);
|
||||
|
||||
em = OPENSSL_malloc(num);
|
||||
if (em == NULL) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, ERR_R_MALLOC_FAILURE);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Caller is encouraged to pass zero-padded message created with
|
||||
* BN_bn2binpad. Trouble is that since we can't read out of |from|'s
|
||||
* bounds, it's impossible to have an invariant memory access pattern
|
||||
* in case |from| was not zero-padded in advance.
|
||||
*/
|
||||
for (from += flen, em += num, i = 0; i < num; i++) {
|
||||
mask = ~constant_time_is_zero(flen);
|
||||
flen -= 1 & mask;
|
||||
from -= 1 & mask;
|
||||
*--em = *from & mask;
|
||||
}
|
||||
from = em;
|
||||
|
||||
good = constant_time_is_zero(from[0]);
|
||||
good &= constant_time_eq(from[1], 2);
|
||||
err = constant_time_select_int(good, 0, RSA_R_BLOCK_TYPE_IS_NOT_02);
|
||||
mask = ~good;
|
||||
|
||||
/* scan over padding data */
|
||||
j = flen - 1; /* one for type */
|
||||
for (i = 0; i < j; i++)
|
||||
if (*(p++) == 0)
|
||||
break;
|
||||
found_zero_byte = 0;
|
||||
threes_in_row = 0;
|
||||
for (i = 2; i < num; i++) {
|
||||
unsigned int equals0 = constant_time_is_zero(from[i]);
|
||||
|
||||
if ((i == j) || (i < 8)) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,
|
||||
RSA_R_NULL_BEFORE_BLOCK_MISSING);
|
||||
return -1;
|
||||
}
|
||||
for (k = -9; k < -1; k++) {
|
||||
if (p[k] != 0x03)
|
||||
break;
|
||||
}
|
||||
if (k == -1) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_SSLV3_ROLLBACK_ATTACK);
|
||||
return -1;
|
||||
zero_index = constant_time_select_int(~found_zero_byte & equals0,
|
||||
i, zero_index);
|
||||
found_zero_byte |= equals0;
|
||||
|
||||
threes_in_row += 1 & ~found_zero_byte;
|
||||
threes_in_row &= found_zero_byte | constant_time_eq(from[i], 3);
|
||||
}
|
||||
|
||||
i++; /* Skip over the '\0' */
|
||||
j -= i;
|
||||
if (j > tlen) {
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, RSA_R_DATA_TOO_LARGE);
|
||||
return -1;
|
||||
}
|
||||
memcpy(to, p, (unsigned int)j);
|
||||
/*
|
||||
* PS must be at least 8 bytes long, and it starts two bytes into |from|.
|
||||
* If we never found a 0-byte, then |zero_index| is 0 and the check
|
||||
* also fails.
|
||||
*/
|
||||
good &= constant_time_ge(zero_index, 2 + 8);
|
||||
err = constant_time_select_int(mask | good, err,
|
||||
RSA_R_NULL_BEFORE_BLOCK_MISSING);
|
||||
mask = ~good;
|
||||
|
||||
return j;
|
||||
good &= constant_time_lt(threes_in_row, 8);
|
||||
err = constant_time_select_int(mask | good, err,
|
||||
RSA_R_SSLV3_ROLLBACK_ATTACK);
|
||||
mask = ~good;
|
||||
|
||||
/*
|
||||
* Skip the zero byte. This is incorrect if we never found a zero-byte
|
||||
* but in this case we also do not copy the message out.
|
||||
*/
|
||||
msg_index = zero_index + 1;
|
||||
mlen = num - msg_index;
|
||||
|
||||
/*
|
||||
* For good measure, do this check in constant time as well.
|
||||
*/
|
||||
good &= constant_time_ge(tlen, mlen);
|
||||
err = constant_time_select_int(mask | good, err, RSA_R_DATA_TOO_LARGE);
|
||||
|
||||
/*
|
||||
* Even though we can't fake result's length, we can pretend copying
|
||||
* |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num|
|
||||
* bytes are viewed as circular buffer with start at |tlen|-|mlen'|,
|
||||
* where |mlen'| is "saturated" |mlen| value. Deducing information
|
||||
* about failure or |mlen| would take attacker's ability to observe
|
||||
* memory access pattern with byte granularity *as it occurs*. It
|
||||
* should be noted that failure is indistinguishable from normal
|
||||
* operation if |tlen| is fixed by protocol.
|
||||
*/
|
||||
tlen = constant_time_select_int(constant_time_lt(num, tlen), num, tlen);
|
||||
msg_index = constant_time_select_int(good, msg_index, num - tlen);
|
||||
mlen = num - msg_index;
|
||||
for (from += msg_index, mask = good, i = 0; i < tlen; i++) {
|
||||
unsigned int equals = constant_time_eq(i, mlen);
|
||||
|
||||
from -= tlen & equals; /* if (i == mlen) rewind */
|
||||
mask &= mask ^ equals; /* if (i == mlen) mask = 0 */
|
||||
to[i] = constant_time_select_8(mask, from[i], to[i]);
|
||||
}
|
||||
|
||||
OPENSSL_clear_free(em, num);
|
||||
RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23, err);
|
||||
err_clear_last_constant_time(1 & good);
|
||||
|
||||
return constant_time_select_int(good, mlen, -1);
|
||||
}
|
||||
|
@ -130,6 +130,8 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
|
||||
|
||||
/* calculate inverse of q mod p */
|
||||
rsa->iqmp = BN_mod_inverse(NULL, rsa->q, rsa->p, ctx2);
|
||||
if (rsa->iqmp == NULL)
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2004, EdelKey Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -28,6 +28,7 @@ static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)
|
||||
unsigned char *tmp = NULL;
|
||||
int numN = BN_num_bytes(N);
|
||||
BIGNUM *res = NULL;
|
||||
|
||||
if (x != N && BN_ucmp(x, N) >= 0)
|
||||
return NULL;
|
||||
if (y != N && BN_ucmp(y, N) >= 0)
|
||||
@ -141,7 +142,8 @@ BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)
|
||||
|| !EVP_DigestFinal_ex(ctxt, dig, NULL)
|
||||
|| !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL))
|
||||
goto err;
|
||||
BN_bn2bin(s, cs);
|
||||
if (BN_bn2bin(s, cs) < 0)
|
||||
goto err;
|
||||
if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))
|
||||
goto err;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2004, EdelKey Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -189,7 +189,7 @@ void SRP_user_pwd_free(SRP_user_pwd *user_pwd)
|
||||
static SRP_user_pwd *SRP_user_pwd_new(void)
|
||||
{
|
||||
SRP_user_pwd *ret;
|
||||
|
||||
|
||||
if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) {
|
||||
/* SRPerr(SRP_F_SRP_USER_PWD_NEW, ERR_R_MALLOC_FAILURE); */ /*ckerr_ignore*/
|
||||
return NULL;
|
||||
@ -600,10 +600,14 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt,
|
||||
if ((len = t_fromb64(tmp, sizeof(tmp), N)) <= 0)
|
||||
goto err;
|
||||
N_bn_alloc = BN_bin2bn(tmp, len, NULL);
|
||||
if (N_bn_alloc == NULL)
|
||||
goto err;
|
||||
N_bn = N_bn_alloc;
|
||||
if ((len = t_fromb64(tmp, sizeof(tmp) ,g)) <= 0)
|
||||
goto err;
|
||||
g_bn_alloc = BN_bin2bn(tmp, len, NULL);
|
||||
if (g_bn_alloc == NULL)
|
||||
goto err;
|
||||
g_bn = g_bn_alloc;
|
||||
defgNid = "*";
|
||||
} else {
|
||||
@ -625,15 +629,19 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt,
|
||||
goto err;
|
||||
s = BN_bin2bn(tmp2, len, NULL);
|
||||
}
|
||||
if (s == NULL)
|
||||
goto err;
|
||||
|
||||
if (!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn))
|
||||
goto err;
|
||||
|
||||
BN_bn2bin(v, tmp);
|
||||
if (BN_bn2bin(v, tmp) < 0)
|
||||
goto err;
|
||||
vfsize = BN_num_bytes(v) * 2;
|
||||
if (((vf = OPENSSL_malloc(vfsize)) == NULL))
|
||||
goto err;
|
||||
t_tob64(vf, tmp, BN_num_bytes(v));
|
||||
if (!t_tob64(vf, tmp, BN_num_bytes(v)))
|
||||
goto err;
|
||||
|
||||
if (*salt == NULL) {
|
||||
char *tmp_salt;
|
||||
@ -641,7 +649,10 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt,
|
||||
if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) {
|
||||
goto err;
|
||||
}
|
||||
t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN);
|
||||
if (!t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN)) {
|
||||
OPENSSL_free(tmp_salt);
|
||||
goto err;
|
||||
}
|
||||
*salt = tmp_salt;
|
||||
}
|
||||
|
||||
@ -688,11 +699,15 @@ int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
|
||||
goto err;
|
||||
|
||||
salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);
|
||||
if (salttmp == NULL)
|
||||
goto err;
|
||||
} else {
|
||||
salttmp = *salt;
|
||||
}
|
||||
|
||||
x = SRP_Calc_x(salttmp, user, pass);
|
||||
if (x == NULL)
|
||||
goto err;
|
||||
|
||||
*verifier = BN_new();
|
||||
if (*verifier == NULL)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -103,6 +103,12 @@
|
||||
|
||||
# endif
|
||||
|
||||
# if defined(OPENSSL_SYS_VXWORKS)
|
||||
# undef TERMIOS
|
||||
# undef TERMIO
|
||||
# undef SGTTY
|
||||
# endif
|
||||
|
||||
# ifdef TERMIOS
|
||||
# include <termios.h>
|
||||
# define TTY_STRUCT struct termios
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -36,12 +36,13 @@ int OPENSSL_issetugid(void)
|
||||
# if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
|
||||
# if __GLIBC_PREREQ(2, 16)
|
||||
# include <sys/auxv.h>
|
||||
# define OSSL_IMPLEMENT_GETAUXVAL
|
||||
# endif
|
||||
# endif
|
||||
|
||||
int OPENSSL_issetugid(void)
|
||||
{
|
||||
# ifdef AT_SECURE
|
||||
# ifdef OSSL_IMPLEMENT_GETAUXVAL
|
||||
return getauxval(AT_SECURE) != 0;
|
||||
# else
|
||||
return getuid() != geteuid() || getgid() != getegid();
|
||||
|
@ -3234,12 +3234,19 @@ static int check_key_level(X509_STORE_CTX *ctx, X509 *cert)
|
||||
EVP_PKEY *pkey = X509_get0_pubkey(cert);
|
||||
int level = ctx->param->auth_level;
|
||||
|
||||
/*
|
||||
* At security level zero, return without checking for a supported public
|
||||
* key type. Some engines support key types not understood outside the
|
||||
* engine, and we only need to understand the key when enforcing a security
|
||||
* floor.
|
||||
*/
|
||||
if (level <= 0)
|
||||
return 1;
|
||||
|
||||
/* Unsupported or malformed keys are not secure */
|
||||
if (pkey == NULL)
|
||||
return 0;
|
||||
|
||||
if (level <= 0)
|
||||
return 1;
|
||||
if (level > NUM_AUTH_LEVELS)
|
||||
level = NUM_AUTH_LEVELS;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -160,6 +160,18 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
int idx;
|
||||
|
||||
switch (operation) {
|
||||
case ASN1_OP_D2I_PRE:
|
||||
if (crl->meth->crl_free) {
|
||||
if (!crl->meth->crl_free(crl))
|
||||
return 0;
|
||||
}
|
||||
AUTHORITY_KEYID_free(crl->akid);
|
||||
ISSUING_DIST_POINT_free(crl->idp);
|
||||
ASN1_INTEGER_free(crl->crl_number);
|
||||
ASN1_INTEGER_free(crl->base_crl_number);
|
||||
sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free);
|
||||
/* fall thru */
|
||||
|
||||
case ASN1_OP_NEW_POST:
|
||||
crl->idp = NULL;
|
||||
crl->akid = NULL;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -38,6 +38,7 @@ static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
/* Attempt to decode public key and cache in pubkey structure. */
|
||||
X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
|
||||
EVP_PKEY_free(pubkey->pkey);
|
||||
pubkey->pkey = NULL;
|
||||
/*
|
||||
* Opportunistically decode the key but remove any non fatal errors
|
||||
* from the queue. Subsequent explicit attempts to decode/use the key
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -42,12 +42,35 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
|
||||
switch (operation) {
|
||||
|
||||
case ASN1_OP_D2I_PRE:
|
||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
|
||||
X509_CERT_AUX_free(ret->aux);
|
||||
ASN1_OCTET_STRING_free(ret->skid);
|
||||
AUTHORITY_KEYID_free(ret->akid);
|
||||
CRL_DIST_POINTS_free(ret->crldp);
|
||||
policy_cache_free(ret->policy_cache);
|
||||
GENERAL_NAMES_free(ret->altname);
|
||||
NAME_CONSTRAINTS_free(ret->nc);
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
|
||||
ASIdentifiers_free(ret->rfc3779_asid);
|
||||
#endif
|
||||
|
||||
/* fall thru */
|
||||
|
||||
case ASN1_OP_NEW_POST:
|
||||
ret->ex_cached = 0;
|
||||
ret->ex_kusage = 0;
|
||||
ret->ex_xkusage = 0;
|
||||
ret->ex_nscert = 0;
|
||||
ret->ex_flags = 0;
|
||||
ret->ex_pathlen = -1;
|
||||
ret->ex_pcpathlen = -1;
|
||||
ret->skid = NULL;
|
||||
ret->akid = NULL;
|
||||
ret->policy_cache = NULL;
|
||||
ret->altname = NULL;
|
||||
ret->nc = NULL;
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
ret->rfc3779_addr = NULL;
|
||||
ret->rfc3779_asid = NULL;
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
# define get_last_sys_error() errno
|
||||
# define clear_sys_error() errno=0
|
||||
# define set_sys_error(e) errno=(e)
|
||||
|
||||
/********************************************************************
|
||||
The Microsoft section
|
||||
@ -66,8 +67,10 @@
|
||||
# ifdef WIN32
|
||||
# undef get_last_sys_error
|
||||
# undef clear_sys_error
|
||||
# undef set_sys_error
|
||||
# define get_last_sys_error() GetLastError()
|
||||
# define clear_sys_error() SetLastError(0)
|
||||
# define set_sys_error(e) SetLastError(e)
|
||||
# if !defined(WINNT)
|
||||
# define WIN_CONSOLE_BUG
|
||||
# endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -140,7 +140,6 @@ struct dasync_pipeline_ctx {
|
||||
unsigned char **inbufs;
|
||||
unsigned char **outbufs;
|
||||
size_t *lens;
|
||||
int enc;
|
||||
unsigned char tlsaad[SSL_MAX_PIPELINES][EVP_AEAD_TLS1_AAD_LEN];
|
||||
unsigned int aadctr;
|
||||
};
|
||||
@ -158,6 +157,14 @@ static const EVP_CIPHER *dasync_aes_128_cbc(void)
|
||||
/*
|
||||
* Holds the EVP_CIPHER object for aes_128_cbc_hmac_sha1 in this engine. Set up
|
||||
* once only during engine bind and can then be reused many times.
|
||||
*
|
||||
* This 'stitched' cipher depends on the EVP_aes_128_cbc_hmac_sha1() cipher,
|
||||
* which is implemented only if the AES-NI instruction set extension is available
|
||||
* (see OPENSSL_IA32CAP(3)). If that's not the case, then this cipher will not
|
||||
* be available either.
|
||||
*
|
||||
* Note: Since it is a legacy mac-then-encrypt cipher, modern TLS peers (which
|
||||
* negotiate the encrypt-then-mac extension) won't negotiate it anyway.
|
||||
*/
|
||||
static EVP_CIPHER *_hidden_aes_128_cbc_hmac_sha1 = NULL;
|
||||
static const EVP_CIPHER *dasync_aes_128_cbc_hmac_sha1(void)
|
||||
@ -605,7 +612,7 @@ static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg,
|
||||
|
||||
len = p[arg - 2] << 8 | p[arg - 1];
|
||||
|
||||
if (pipe_ctx->enc) {
|
||||
if (EVP_CIPHER_CTX_encrypting(ctx)) {
|
||||
if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) {
|
||||
if (len < AES_BLOCK_SIZE)
|
||||
return 0;
|
||||
@ -754,6 +761,10 @@ static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
|
||||
const unsigned char *iv,
|
||||
int enc)
|
||||
{
|
||||
/*
|
||||
* We can safely assume that EVP_aes_128_cbc_hmac_sha1() != NULL,
|
||||
* see comment before the definition of dasync_aes_128_cbc_hmac_sha1().
|
||||
*/
|
||||
return dasync_cipher_init_key_helper(ctx, key, iv, enc,
|
||||
EVP_aes_128_cbc_hmac_sha1());
|
||||
}
|
||||
@ -768,5 +779,9 @@ static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx,
|
||||
|
||||
static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx)
|
||||
{
|
||||
/*
|
||||
* We can safely assume that EVP_aes_128_cbc_hmac_sha1() != NULL,
|
||||
* see comment before the definition of dasync_aes_128_cbc_hmac_sha1().
|
||||
*/
|
||||
return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1());
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -12,11 +12,18 @@
|
||||
|
||||
#include <openssl/conf.h>
|
||||
|
||||
#define DEFAULT_CONF_MFLAGS \
|
||||
(CONF_MFLAGS_DEFAULT_SECTION | \
|
||||
CONF_MFLAGS_IGNORE_MISSING_FILE | \
|
||||
CONF_MFLAGS_IGNORE_RETURN_CODES)
|
||||
|
||||
struct ossl_init_settings_st {
|
||||
char *filename;
|
||||
char *appname;
|
||||
unsigned long flags;
|
||||
};
|
||||
|
||||
void openssl_config_int(const char *appname);
|
||||
int openssl_config_int(const OPENSSL_INIT_SETTINGS *);
|
||||
void openssl_no_config_int(void);
|
||||
void conf_modules_free_int(void);
|
||||
|
||||
|
@ -324,4 +324,10 @@ static ossl_inline void constant_time_lookup(void *out,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Expected usage pattern is to unconditionally set error and then
|
||||
* wipe it if there was no actual error. |clear| is 1 or 0.
|
||||
*/
|
||||
void err_clear_last_constant_time(int clear);
|
||||
|
||||
#endif /* HEADER_CONSTANT_TIME_LOCL_H */
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -92,5 +92,7 @@ void *openssl_fopen(const char *filename, const char *mode);
|
||||
# endif
|
||||
|
||||
uint32_t OPENSSL_rdtsc(void);
|
||||
size_t OPENSSL_instrument_bus(unsigned int *, size_t);
|
||||
size_t OPENSSL_instrument_bus2(unsigned int *, size_t, size_t);
|
||||
|
||||
#endif
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -72,11 +72,7 @@ struct servent *PASCAL getservbyname(const char *, const char *);
|
||||
# else
|
||||
# include <sys/socket.h>
|
||||
# ifndef NO_SYS_UN_H
|
||||
# ifdef OPENSSL_SYS_VXWORKS
|
||||
# include <streams/un.h>
|
||||
# else
|
||||
# include <sys/un.h>
|
||||
# endif
|
||||
# include <sys/un.h>
|
||||
# ifndef UNIX_PATH_MAX
|
||||
# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
|
||||
# endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -9,6 +9,20 @@
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
/*
|
||||
* DEFINE_RUN_ONCE: Define an initialiser function that should be run exactly
|
||||
* once. It takes no arguments and returns and int result (1 for success or
|
||||
* 0 for failure). Typical usage might be:
|
||||
*
|
||||
* DEFINE_RUN_ONCE(myinitfunc)
|
||||
* {
|
||||
* do_some_initialisation();
|
||||
* if (init_is_successful())
|
||||
* return 1;
|
||||
*
|
||||
* return 0;
|
||||
* }
|
||||
*/
|
||||
#define DEFINE_RUN_ONCE(init) \
|
||||
static int init(void); \
|
||||
int init##_ossl_ret_ = 0; \
|
||||
@ -17,10 +31,30 @@
|
||||
init##_ossl_ret_ = init(); \
|
||||
} \
|
||||
static int init(void)
|
||||
|
||||
/*
|
||||
* DECLARE_RUN_ONCE: Declare an initialiser function that should be run exactly
|
||||
* once that has been defined in another file via DEFINE_RUN_ONCE().
|
||||
*/
|
||||
#define DECLARE_RUN_ONCE(init) \
|
||||
extern int init##_ossl_ret_; \
|
||||
void init##_ossl_(void);
|
||||
|
||||
/*
|
||||
* DEFINE_RUN_ONCE_STATIC: Define an initialiser function that should be run
|
||||
* exactly once. This function will be declared as static within the file. It
|
||||
* takes no arguments and returns and int result (1 for success or 0 for
|
||||
* failure). Typical usage might be:
|
||||
*
|
||||
* DEFINE_RUN_ONCE_STATIC(myinitfunc)
|
||||
* {
|
||||
* do_some_initialisation();
|
||||
* if (init_is_successful())
|
||||
* return 1;
|
||||
*
|
||||
* return 0;
|
||||
* }
|
||||
*/
|
||||
#define DEFINE_RUN_ONCE_STATIC(init) \
|
||||
static int init(void); \
|
||||
static int init##_ossl_ret_ = 0; \
|
||||
@ -30,6 +64,46 @@
|
||||
} \
|
||||
static int init(void)
|
||||
|
||||
/*
|
||||
* DEFINE_RUN_ONCE_STATIC_ALT: Define an alternative initialiser function. This
|
||||
* function will be declared as static within the file. It takes no arguments
|
||||
* and returns an int result (1 for success or 0 for failure). An alternative
|
||||
* initialiser function is expected to be associated with a primary initialiser
|
||||
* function defined via DEFINE_ONCE_STATIC where both functions use the same
|
||||
* CRYPTO_ONCE object to synchronise. Where an alternative initialiser function
|
||||
* is used only one of the primary or the alternative initialiser function will
|
||||
* ever be called - and that function will be called exactly once. Definitition
|
||||
* of an alternative initialiser function MUST occur AFTER the definition of the
|
||||
* primary initialiser function.
|
||||
*
|
||||
* Typical usage might be:
|
||||
*
|
||||
* DEFINE_RUN_ONCE_STATIC(myinitfunc)
|
||||
* {
|
||||
* do_some_initialisation();
|
||||
* if (init_is_successful())
|
||||
* return 1;
|
||||
*
|
||||
* return 0;
|
||||
* }
|
||||
*
|
||||
* DEFINE_RUN_ONCE_STATIC_ALT(myaltinitfunc, myinitfunc)
|
||||
* {
|
||||
* do_some_alternative_initialisation();
|
||||
* if (init_is_successful())
|
||||
* return 1;
|
||||
*
|
||||
* return 0;
|
||||
* }
|
||||
*/
|
||||
#define DEFINE_RUN_ONCE_STATIC_ALT(initalt, init) \
|
||||
static int initalt(void); \
|
||||
static void initalt##_ossl_(void) \
|
||||
{ \
|
||||
init##_ossl_ret_ = initalt(); \
|
||||
} \
|
||||
static int initalt(void)
|
||||
|
||||
/*
|
||||
* RUN_ONCE - use CRYPTO_THREAD_run_once, and check if the init succeeded
|
||||
* @once: pointer to static object of type CRYPTO_ONCE
|
||||
@ -43,3 +117,21 @@
|
||||
*/
|
||||
#define RUN_ONCE(once, init) \
|
||||
(CRYPTO_THREAD_run_once(once, init##_ossl_) ? init##_ossl_ret_ : 0)
|
||||
|
||||
/*
|
||||
* RUN_ONCE_ALT - use CRYPTO_THREAD_run_once, to run an alternative initialiser
|
||||
* function and check if that initialisation succeeded
|
||||
* @once: pointer to static object of type CRYPTO_ONCE
|
||||
* @initalt: alternative initialiser function name that was previously given to
|
||||
* DEFINE_RUN_ONCE_STATIC_ALT. This function must return 1 for
|
||||
* success or 0 for failure.
|
||||
* @init: primary initialiser function name that was previously given to
|
||||
* DEFINE_RUN_ONCE_STATIC. This function must return 1 for success or
|
||||
* 0 for failure.
|
||||
*
|
||||
* The return value is 1 on success (*) or 0 in case of error.
|
||||
*
|
||||
* (*) by convention, since the init function must return 1 on success.
|
||||
*/
|
||||
#define RUN_ONCE_ALT(once, initalt, init) \
|
||||
(CRYPTO_THREAD_run_once(once, initalt##_ossl_) ? init##_ossl_ret_ : 0)
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2018-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (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
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Contemporary compilers implement lock-free atomic memory access
|
||||
* primitives that facilitate writing "thread-opportunistic" or even real
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -109,13 +109,8 @@ DEFINE_STACK_OF(void)
|
||||
# define CRYPTO_EX_INDEX_DRBG 15
|
||||
# define CRYPTO_EX_INDEX__COUNT 16
|
||||
|
||||
/*
|
||||
* This is the default callbacks, but we can have others as well: this is
|
||||
* needed in Win32 where the application malloc and the library malloc may
|
||||
* not be the same.
|
||||
*/
|
||||
#define OPENSSL_malloc_init() \
|
||||
CRYPTO_set_mem_functions(CRYPTO_malloc, CRYPTO_realloc, CRYPTO_free)
|
||||
/* No longer needed, so this is a no-op */
|
||||
#define OPENSSL_malloc_init() while(0) continue
|
||||
|
||||
int CRYPTO_mem_ctrl(int mode);
|
||||
|
||||
@ -377,6 +372,7 @@ int CRYPTO_memcmp(const void * in_a, const void * in_b, size_t len);
|
||||
/* OPENSSL_INIT_ZLIB 0x00010000L */
|
||||
# define OPENSSL_INIT_ATFORK 0x00020000L
|
||||
/* OPENSSL_INIT_BASE_ONLY 0x00040000L */
|
||||
# define OPENSSL_INIT_NO_ATEXIT 0x00080000L
|
||||
/* OPENSSL_INIT flag range 0xfff00000 reserved for OPENSSL_init_ssl() */
|
||||
/* Max OPENSSL_INIT flag value is 0x80000000 */
|
||||
|
||||
@ -396,8 +392,12 @@ void OPENSSL_thread_stop(void);
|
||||
/* Low-level control of initialization */
|
||||
OPENSSL_INIT_SETTINGS *OPENSSL_INIT_new(void);
|
||||
# ifndef OPENSSL_NO_STDIO
|
||||
int OPENSSL_INIT_set_config_filename(OPENSSL_INIT_SETTINGS *settings,
|
||||
const char *config_filename);
|
||||
void OPENSSL_INIT_set_config_file_flags(OPENSSL_INIT_SETTINGS *settings,
|
||||
unsigned long flags);
|
||||
int OPENSSL_INIT_set_config_appname(OPENSSL_INIT_SETTINGS *settings,
|
||||
const char *config_file);
|
||||
const char *config_appname);
|
||||
# endif
|
||||
void OPENSSL_INIT_free(OPENSSL_INIT_SETTINGS *settings);
|
||||
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -287,6 +287,13 @@ typedef unsigned __int64 uint64_t;
|
||||
# define ossl_noreturn
|
||||
# endif
|
||||
|
||||
/* ossl_unused: portable unused attribute for use in public headers */
|
||||
# if defined(__GNUC__)
|
||||
# define ossl_unused __attribute__((unused))
|
||||
# else
|
||||
# define ossl_unused
|
||||
# endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -62,6 +62,7 @@ int ERR_load_EC_strings(void);
|
||||
# define EC_F_EC_ASN1_GROUP2CURVE 153
|
||||
# define EC_F_EC_ASN1_GROUP2FIELDID 154
|
||||
# define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208
|
||||
# define EC_F_EC_GF2M_SIMPLE_FIELD_INV 296
|
||||
# define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159
|
||||
# define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195
|
||||
# define EC_F_EC_GF2M_SIMPLE_LADDER_POST 285
|
||||
@ -74,6 +75,7 @@ int ERR_load_EC_strings(void);
|
||||
# define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164
|
||||
# define EC_F_EC_GFP_MONT_FIELD_DECODE 133
|
||||
# define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
|
||||
# define EC_F_EC_GFP_MONT_FIELD_INV 297
|
||||
# define EC_F_EC_GFP_MONT_FIELD_MUL 131
|
||||
# define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209
|
||||
# define EC_F_EC_GFP_MONT_FIELD_SQR 132
|
||||
@ -91,6 +93,7 @@ int ERR_load_EC_strings(void);
|
||||
# define EC_F_EC_GFP_NIST_FIELD_SQR 201
|
||||
# define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202
|
||||
# define EC_F_EC_GFP_SIMPLE_BLIND_COORDINATES 287
|
||||
# define EC_F_EC_GFP_SIMPLE_FIELD_INV 298
|
||||
# define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165
|
||||
# define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166
|
||||
# define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
|
||||
@ -202,6 +205,7 @@ int ERR_load_EC_strings(void);
|
||||
# define EC_R_BAD_SIGNATURE 156
|
||||
# define EC_R_BIGNUM_OUT_OF_RANGE 144
|
||||
# define EC_R_BUFFER_TOO_SMALL 100
|
||||
# define EC_R_CANNOT_INVERT 165
|
||||
# define EC_R_COORDINATES_OUT_OF_RANGE 146
|
||||
# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH 160
|
||||
# define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING 159
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -945,14 +945,9 @@ const EVP_CIPHER *EVP_sm4_ctr(void);
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
|
||||
|
||||
# ifdef OPENSSL_LOAD_CONF
|
||||
# define OpenSSL_add_all_algorithms() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS \
|
||||
| OPENSSL_INIT_LOAD_CONFIG, NULL)
|
||||
# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_conf()
|
||||
# else
|
||||
# define OpenSSL_add_all_algorithms() \
|
||||
OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS, NULL)
|
||||
# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_noconf()
|
||||
# endif
|
||||
|
||||
# define OpenSSL_add_all_ciphers() \
|
||||
@ -994,7 +989,7 @@ int EVP_PKEY_id(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_base_id(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_bits(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_security_bits(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_size(EVP_PKEY *pkey);
|
||||
int EVP_PKEY_size(const EVP_PKEY *pkey);
|
||||
int EVP_PKEY_set_type(EVP_PKEY *pkey, int type);
|
||||
int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len);
|
||||
int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type);
|
||||
|
@ -47,6 +47,7 @@ int ERR_load_EVP_strings(void);
|
||||
# define EVP_F_EVP_DECRYPTUPDATE 166
|
||||
# define EVP_F_EVP_DIGESTFINALXOF 174
|
||||
# define EVP_F_EVP_DIGESTINIT_EX 128
|
||||
# define EVP_F_EVP_ENCRYPTDECRYPTUPDATE 219
|
||||
# define EVP_F_EVP_ENCRYPTFINAL_EX 127
|
||||
# define EVP_F_EVP_ENCRYPTUPDATE 167
|
||||
# define EVP_F_EVP_MD_CTX_COPY_EX 110
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -127,52 +127,52 @@ void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
|
||||
return (LHASH_OF(type) *) \
|
||||
OPENSSL_LH_new((OPENSSL_LH_HASHFUNC)hfn, (OPENSSL_LH_COMPFUNC)cfn); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \
|
||||
static ossl_unused ossl_inline void lh_##type##_free(LHASH_OF(type) *lh) \
|
||||
{ \
|
||||
OPENSSL_LH_free((OPENSSL_LHASH *)lh); \
|
||||
} \
|
||||
static ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
|
||||
static ossl_unused ossl_inline type *lh_##type##_insert(LHASH_OF(type) *lh, type *d) \
|
||||
{ \
|
||||
return (type *)OPENSSL_LH_insert((OPENSSL_LHASH *)lh, d); \
|
||||
} \
|
||||
static ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
|
||||
static ossl_unused ossl_inline type *lh_##type##_delete(LHASH_OF(type) *lh, const type *d) \
|
||||
{ \
|
||||
return (type *)OPENSSL_LH_delete((OPENSSL_LHASH *)lh, d); \
|
||||
} \
|
||||
static ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
|
||||
static ossl_unused ossl_inline type *lh_##type##_retrieve(LHASH_OF(type) *lh, const type *d) \
|
||||
{ \
|
||||
return (type *)OPENSSL_LH_retrieve((OPENSSL_LHASH *)lh, d); \
|
||||
} \
|
||||
static ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \
|
||||
static ossl_unused ossl_inline int lh_##type##_error(LHASH_OF(type) *lh) \
|
||||
{ \
|
||||
return OPENSSL_LH_error((OPENSSL_LHASH *)lh); \
|
||||
} \
|
||||
static ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \
|
||||
static ossl_unused ossl_inline unsigned long lh_##type##_num_items(LHASH_OF(type) *lh) \
|
||||
{ \
|
||||
return OPENSSL_LH_num_items((OPENSSL_LHASH *)lh); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
static ossl_unused ossl_inline void lh_##type##_node_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
{ \
|
||||
OPENSSL_LH_node_stats_bio((const OPENSSL_LHASH *)lh, out); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
static ossl_unused ossl_inline void lh_##type##_node_usage_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
{ \
|
||||
OPENSSL_LH_node_usage_stats_bio((const OPENSSL_LHASH *)lh, out); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
static ossl_unused ossl_inline void lh_##type##_stats_bio(const LHASH_OF(type) *lh, BIO *out) \
|
||||
{ \
|
||||
OPENSSL_LH_stats_bio((const OPENSSL_LHASH *)lh, out); \
|
||||
} \
|
||||
static ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \
|
||||
static ossl_unused ossl_inline unsigned long lh_##type##_get_down_load(LHASH_OF(type) *lh) \
|
||||
{ \
|
||||
return OPENSSL_LH_get_down_load((OPENSSL_LHASH *)lh); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
|
||||
static ossl_unused ossl_inline void lh_##type##_set_down_load(LHASH_OF(type) *lh, unsigned long dl) \
|
||||
{ \
|
||||
OPENSSL_LH_set_down_load((OPENSSL_LHASH *)lh, dl); \
|
||||
} \
|
||||
static ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \
|
||||
void (*doall)(type *)) \
|
||||
static ossl_unused ossl_inline void lh_##type##_doall(LHASH_OF(type) *lh, \
|
||||
void (*doall)(type *)) \
|
||||
{ \
|
||||
OPENSSL_LH_doall((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNC)doall); \
|
||||
} \
|
||||
@ -185,7 +185,7 @@ void OPENSSL_LH_node_usage_stats_bio(const OPENSSL_LHASH *lh, BIO *out);
|
||||
int_implement_lhash_doall(type, argtype, type)
|
||||
|
||||
#define int_implement_lhash_doall(type, argtype, cbargtype) \
|
||||
static ossl_inline void \
|
||||
static ossl_unused ossl_inline void \
|
||||
lh_##type##_doall_##argtype(LHASH_OF(type) *lh, \
|
||||
void (*fn)(cbargtype *, argtype *), \
|
||||
argtype *arg) \
|
||||
@ -210,6 +210,31 @@ DEFINE_LHASH_OF(OPENSSL_CSTRING);
|
||||
# pragma warning (pop)
|
||||
# endif
|
||||
|
||||
/*
|
||||
* If called without higher optimization (min. -xO3) the Oracle Developer
|
||||
* Studio compiler generates code for the defined (static inline) functions
|
||||
* above.
|
||||
* This would later lead to the linker complaining about missing symbols when
|
||||
* this header file is included but the resulting object is not linked against
|
||||
* the Crypto library (openssl#6912).
|
||||
*/
|
||||
# ifdef __SUNPRO_C
|
||||
# pragma weak OPENSSL_LH_new
|
||||
# pragma weak OPENSSL_LH_free
|
||||
# pragma weak OPENSSL_LH_insert
|
||||
# pragma weak OPENSSL_LH_delete
|
||||
# pragma weak OPENSSL_LH_retrieve
|
||||
# pragma weak OPENSSL_LH_error
|
||||
# pragma weak OPENSSL_LH_num_items
|
||||
# pragma weak OPENSSL_LH_node_stats_bio
|
||||
# pragma weak OPENSSL_LH_node_usage_stats_bio
|
||||
# pragma weak OPENSSL_LH_stats_bio
|
||||
# pragma weak OPENSSL_LH_get_down_load
|
||||
# pragma weak OPENSSL_LH_set_down_load
|
||||
# pragma weak OPENSSL_LH_doall
|
||||
# pragma weak OPENSSL_LH_doall_arg
|
||||
# endif /* __SUNPRO_C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/objects/objects.pl
|
||||
*
|
||||
* Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the OpenSSL license (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
|
||||
|
@ -39,8 +39,8 @@ extern "C" {
|
||||
* (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
|
||||
* major minor fix final patch/beta)
|
||||
*/
|
||||
# define OPENSSL_VERSION_NUMBER 0x1010101fL
|
||||
# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1a-freebsd 20 Nov 2018"
|
||||
# define OPENSSL_VERSION_NUMBER 0x1010102fL
|
||||
# define OPENSSL_VERSION_TEXT "OpenSSL 1.1.1b-freebsd 26 Feb 2019"
|
||||
|
||||
/*-
|
||||
* The macros below are to be used for shared library (.so, .dll, ...)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1999-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -24,96 +24,96 @@ extern "C" {
|
||||
typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
|
||||
typedef void (*sk_##t1##_freefunc)(t3 *a); \
|
||||
typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
|
||||
static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \
|
||||
} \
|
||||
static ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
|
||||
static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
|
||||
{ \
|
||||
return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \
|
||||
} \
|
||||
static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
|
||||
static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
|
||||
{ \
|
||||
return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \
|
||||
} \
|
||||
static ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \
|
||||
static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \
|
||||
{ \
|
||||
return (STACK_OF(t1) *)OPENSSL_sk_new_reserve((OPENSSL_sk_compfunc)compare, n); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_reserve(STACK_OF(t1) *sk, int n) \
|
||||
{ \
|
||||
return OPENSSL_sk_reserve((OPENSSL_STACK *)sk, n); \
|
||||
} \
|
||||
static ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
OPENSSL_sk_free((OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
OPENSSL_sk_zero((OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, \
|
||||
(const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
{ \
|
||||
return OPENSSL_sk_push((OPENSSL_STACK *)sk, (const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
{ \
|
||||
return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
|
||||
static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
|
||||
{ \
|
||||
OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
|
||||
{ \
|
||||
return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (const void *)ptr, idx); \
|
||||
} \
|
||||
static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
|
||||
static ossl_unused ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
|
||||
{ \
|
||||
return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
{ \
|
||||
return OPENSSL_sk_find((OPENSSL_STACK *)sk, (const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
|
||||
{ \
|
||||
return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (const void *)ptr); \
|
||||
} \
|
||||
static ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
OPENSSL_sk_sort((OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
|
||||
static ossl_unused ossl_inline STACK_OF(t1) * sk_##t1##_dup(const STACK_OF(t1) *sk) \
|
||||
{ \
|
||||
return (STACK_OF(t1) *)OPENSSL_sk_dup((const OPENSSL_STACK *)sk); \
|
||||
} \
|
||||
static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
|
||||
static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(const STACK_OF(t1) *sk, \
|
||||
sk_##t1##_copyfunc copyfunc, \
|
||||
sk_##t1##_freefunc freefunc) \
|
||||
{ \
|
||||
@ -121,7 +121,7 @@ extern "C" {
|
||||
(OPENSSL_sk_copyfunc)copyfunc, \
|
||||
(OPENSSL_sk_freefunc)freefunc); \
|
||||
} \
|
||||
static ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
|
||||
static ossl_unused ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
|
||||
{ \
|
||||
return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \
|
||||
}
|
||||
@ -166,6 +166,41 @@ DEFINE_SPECIAL_STACK_OF_CONST(OPENSSL_CSTRING, char)
|
||||
typedef void *OPENSSL_BLOCK;
|
||||
DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
|
||||
|
||||
/*
|
||||
* If called without higher optimization (min. -xO3) the Oracle Developer
|
||||
* Studio compiler generates code for the defined (static inline) functions
|
||||
* above.
|
||||
* This would later lead to the linker complaining about missing symbols when
|
||||
* this header file is included but the resulting object is not linked against
|
||||
* the Crypto library (openssl#6912).
|
||||
*/
|
||||
# ifdef __SUNPRO_C
|
||||
# pragma weak OPENSSL_sk_num
|
||||
# pragma weak OPENSSL_sk_value
|
||||
# pragma weak OPENSSL_sk_new
|
||||
# pragma weak OPENSSL_sk_new_null
|
||||
# pragma weak OPENSSL_sk_new_reserve
|
||||
# pragma weak OPENSSL_sk_reserve
|
||||
# pragma weak OPENSSL_sk_free
|
||||
# pragma weak OPENSSL_sk_zero
|
||||
# pragma weak OPENSSL_sk_delete
|
||||
# pragma weak OPENSSL_sk_delete_ptr
|
||||
# pragma weak OPENSSL_sk_push
|
||||
# pragma weak OPENSSL_sk_unshift
|
||||
# pragma weak OPENSSL_sk_pop
|
||||
# pragma weak OPENSSL_sk_shift
|
||||
# pragma weak OPENSSL_sk_pop_free
|
||||
# pragma weak OPENSSL_sk_insert
|
||||
# pragma weak OPENSSL_sk_set
|
||||
# pragma weak OPENSSL_sk_find
|
||||
# pragma weak OPENSSL_sk_find_ex
|
||||
# pragma weak OPENSSL_sk_sort
|
||||
# pragma weak OPENSSL_sk_is_sorted
|
||||
# pragma weak OPENSSL_sk_dup
|
||||
# pragma weak OPENSSL_sk_deep_copy
|
||||
# pragma weak OPENSSL_sk_set_cmp_func
|
||||
# endif /* __SUNPRO_C */
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
@ -494,6 +494,19 @@ typedef int (*SSL_verify_cb)(int preverify_ok, X509_STORE_CTX *x509_ctx);
|
||||
*/
|
||||
# define SSL_MODE_ASYNC 0x00000100U
|
||||
|
||||
/*
|
||||
* When using DTLS/SCTP, include the terminating zero in the label
|
||||
* used for computing the endpoint-pair shared secret. Required for
|
||||
* interoperability with implementations having this bug like these
|
||||
* older version of OpenSSL:
|
||||
* - OpenSSL 1.0.0 series
|
||||
* - OpenSSL 1.0.1 series
|
||||
* - OpenSSL 1.0.2 series
|
||||
* - OpenSSL 1.1.0 series
|
||||
* - OpenSSL 1.1.1 and 1.1.1a
|
||||
*/
|
||||
# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U
|
||||
|
||||
/* Cert related flags */
|
||||
/*
|
||||
* Many implementations ignore some aspects of the TLS standards such as
|
||||
@ -1904,17 +1917,17 @@ __owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);
|
||||
|
||||
__owur int SSL_do_handshake(SSL *s);
|
||||
int SSL_key_update(SSL *s, int updatetype);
|
||||
int SSL_get_key_update_type(SSL *s);
|
||||
int SSL_get_key_update_type(const SSL *s);
|
||||
int SSL_renegotiate(SSL *s);
|
||||
int SSL_renegotiate_abbreviated(SSL *s);
|
||||
__owur int SSL_renegotiate_pending(SSL *s);
|
||||
__owur int SSL_renegotiate_pending(const SSL *s);
|
||||
int SSL_shutdown(SSL *s);
|
||||
__owur int SSL_verify_client_post_handshake(SSL *s);
|
||||
void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
|
||||
void SSL_set_post_handshake_auth(SSL *s, int val);
|
||||
|
||||
__owur const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx);
|
||||
__owur const SSL_METHOD *SSL_get_ssl_method(SSL *s);
|
||||
__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
|
||||
__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s);
|
||||
__owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
|
||||
__owur const char *SSL_alert_type_string_long(int value);
|
||||
__owur const char *SSL_alert_type_string(int value);
|
||||
@ -2062,8 +2075,8 @@ void SSL_set_tmp_dh_callback(SSL *ssl,
|
||||
int keylength));
|
||||
# endif
|
||||
|
||||
__owur const COMP_METHOD *SSL_get_current_compression(SSL *s);
|
||||
__owur const COMP_METHOD *SSL_get_current_expansion(SSL *s);
|
||||
__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s);
|
||||
__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s);
|
||||
__owur const char *SSL_COMP_get_name(const COMP_METHOD *comp);
|
||||
__owur const char *SSL_COMP_get0_name(const SSL_COMP *comp);
|
||||
__owur int SSL_COMP_get_id(const SSL_COMP *comp);
|
||||
@ -2107,20 +2120,20 @@ void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx,
|
||||
size_t (*cb) (SSL *ssl, int type,
|
||||
size_t len, void *arg));
|
||||
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
|
||||
void *SSL_CTX_get_record_padding_callback_arg(SSL_CTX *ctx);
|
||||
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
|
||||
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);
|
||||
|
||||
void SSL_set_record_padding_callback(SSL *ssl,
|
||||
size_t (*cb) (SSL *ssl, int type,
|
||||
size_t len, void *arg));
|
||||
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
|
||||
void *SSL_get_record_padding_callback_arg(SSL *ssl);
|
||||
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
|
||||
int SSL_set_block_padding(SSL *ssl, size_t block_size);
|
||||
|
||||
int SSL_set_num_tickets(SSL *s, size_t num_tickets);
|
||||
size_t SSL_get_num_tickets(SSL *s);
|
||||
size_t SSL_get_num_tickets(const SSL *s);
|
||||
int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
|
||||
size_t SSL_CTX_get_num_tickets(SSL_CTX *ctx);
|
||||
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);
|
||||
|
||||
# if OPENSSL_API_COMPAT < 0x10100000L
|
||||
# define SSL_cache_hit(s) SSL_session_reused(s)
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -596,6 +596,7 @@ int ERR_load_SSL_strings(void);
|
||||
# define SSL_R_MISSING_SUPPORTED_GROUPS_EXTENSION 209
|
||||
# define SSL_R_MISSING_TMP_DH_KEY 171
|
||||
# define SSL_R_MISSING_TMP_ECDH_KEY 311
|
||||
# define SSL_R_MIXED_HANDSHAKE_AND_NON_HANDSHAKE_DATA 293
|
||||
# define SSL_R_NOT_ON_RECORD_BOUNDARY 182
|
||||
# define SSL_R_NOT_REPLACING_CERTIFICATE 289
|
||||
# define SSL_R_NOT_SERVER 284
|
||||
|
@ -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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -362,7 +362,11 @@ X509_STORE_CTX_cleanup_fn X509_STORE_CTX_get_cleanup(X509_STORE_CTX *ctx);
|
||||
# define X509_STORE_CTX_set_chain X509_STORE_CTX_set0_untrusted
|
||||
# define X509_STORE_CTX_trusted_stack X509_STORE_CTX_set0_trusted_stack
|
||||
# define X509_STORE_get_by_subject X509_STORE_CTX_get_by_subject
|
||||
# define X509_STORE_get1_certs X509_STORE_CTX_get1_certs
|
||||
# define X509_STORE_get1_crls X509_STORE_CTX_get1_crls
|
||||
/* the following macro is misspelled; use X509_STORE_get1_certs instead */
|
||||
# define X509_STORE_get1_cert X509_STORE_CTX_get1_certs
|
||||
/* the following macro is misspelled; use X509_STORE_get1_crls instead */
|
||||
# define X509_STORE_get1_crl X509_STORE_CTX_get1_crls
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2005-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2005-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -442,19 +442,6 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
|
||||
&& SSL3_RECORD_get_length(rr) != 0)
|
||||
s->rlayer.alert_count = 0;
|
||||
|
||||
if (SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE
|
||||
&& SSL3_RECORD_get_type(rr) != SSL3_RT_CHANGE_CIPHER_SPEC
|
||||
&& !SSL_in_init(s)
|
||||
&& (s->d1->next_timeout.tv_sec != 0
|
||||
|| s->d1->next_timeout.tv_usec != 0)) {
|
||||
/*
|
||||
* The timer is still running but we've received something that isn't
|
||||
* handshake data - so the peer must have finished processing our
|
||||
* last handshake flight. Stop the timer.
|
||||
*/
|
||||
dtls1_stop_timer(s);
|
||||
}
|
||||
|
||||
/* we now have a packet which can be read and processed */
|
||||
|
||||
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -1317,6 +1317,14 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
|
||||
} while (num_recs == 0);
|
||||
rr = &rr[curr_rec];
|
||||
|
||||
if (s->rlayer.handshake_fragment_len > 0
|
||||
&& SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE
|
||||
&& SSL_IS_TLS13(s)) {
|
||||
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_SSL3_READ_BYTES,
|
||||
SSL_R_MIXED_HANDSHAKE_AND_NON_HANDSHAKE_DATA);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reset the count of consecutive warning alerts if we've got a non-empty
|
||||
* record that isn't an alert.
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
@ -92,8 +92,6 @@ static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
|
||||
int ssl3_change_cipher_state(SSL *s, int which)
|
||||
{
|
||||
unsigned char *p, *mac_secret;
|
||||
unsigned char exp_key[EVP_MAX_KEY_LENGTH];
|
||||
unsigned char exp_iv[EVP_MAX_IV_LENGTH];
|
||||
unsigned char *ms, *key, *iv;
|
||||
EVP_CIPHER_CTX *dd;
|
||||
const EVP_CIPHER *c;
|
||||
@ -241,12 +239,8 @@ int ssl3_change_cipher_state(SSL *s, int which)
|
||||
}
|
||||
|
||||
s->statem.enc_write_state = ENC_WRITE_STATE_VALID;
|
||||
OPENSSL_cleanse(exp_key, sizeof(exp_key));
|
||||
OPENSSL_cleanse(exp_iv, sizeof(exp_iv));
|
||||
return 1;
|
||||
err:
|
||||
OPENSSL_cleanse(exp_key, sizeof(exp_key));
|
||||
OPENSSL_cleanse(exp_iv, sizeof(exp_iv));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3783,7 +3783,7 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
|
||||
EVP_PKEY_security_bits(pkdh), 0, pkdh)) {
|
||||
SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_DH_KEY_TOO_SMALL);
|
||||
EVP_PKEY_free(pkdh);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
EVP_PKEY_free(ctx->cert->dh_tmp);
|
||||
ctx->cert->dh_tmp = pkdh;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
@ -173,6 +173,8 @@ static int ssl_mac_pkey_id[SSL_MD_NUM_IDX] = {
|
||||
EVP_PKEY_HMAC, EVP_PKEY_HMAC, EVP_PKEY_HMAC, NID_undef,
|
||||
/* GOST2012_512 */
|
||||
EVP_PKEY_HMAC,
|
||||
/* MD5/SHA1, SHA224, SHA512 */
|
||||
NID_undef, NID_undef, NID_undef
|
||||
};
|
||||
|
||||
static size_t ssl_mac_secret_size[SSL_MD_NUM_IDX];
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* 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 OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -967,6 +967,8 @@ static const ERR_STRING_DATA SSL_str_reasons[] = {
|
||||
{ERR_PACK(ERR_LIB_SSL, 0, SSL_R_MISSING_TMP_DH_KEY), "missing tmp dh key"},
|
||||
{ERR_PACK(ERR_LIB_SSL, 0, SSL_R_MISSING_TMP_ECDH_KEY),
|
||||
"missing tmp ecdh key"},
|
||||
{ERR_PACK(ERR_LIB_SSL, 0, SSL_R_MIXED_HANDSHAKE_AND_NON_HANDSHAKE_DATA),
|
||||
"mixed handshake and non handshake data"},
|
||||
{ERR_PACK(ERR_LIB_SSL, 0, SSL_R_NOT_ON_RECORD_BOUNDARY),
|
||||
"not on record boundary"},
|
||||
{ERR_PACK(ERR_LIB_SSL, 0, SSL_R_NOT_REPLACING_CERTIFICATE),
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -140,7 +140,8 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_ssl_strings)
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_RUN_ONCE_STATIC(ossl_init_no_load_ssl_strings)
|
||||
DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_no_load_ssl_strings,
|
||||
ossl_init_load_ssl_strings)
|
||||
{
|
||||
/* Do nothing in this case */
|
||||
return 1;
|
||||
@ -202,20 +203,22 @@ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS * settings)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!OPENSSL_init_crypto(opts
|
||||
opts |= OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS;
|
||||
#ifndef OPENSSL_NO_AUTOLOAD_CONFIG
|
||||
| OPENSSL_INIT_LOAD_CONFIG
|
||||
if ((opts & OPENSSL_INIT_NO_LOAD_CONFIG) == 0)
|
||||
opts |= OPENSSL_INIT_LOAD_CONFIG;
|
||||
#endif
|
||||
| OPENSSL_INIT_ADD_ALL_CIPHERS
|
||||
| OPENSSL_INIT_ADD_ALL_DIGESTS,
|
||||
settings))
|
||||
|
||||
if (!OPENSSL_init_crypto(opts, settings))
|
||||
return 0;
|
||||
|
||||
if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
|
||||
&& !RUN_ONCE(&ssl_strings, ossl_init_no_load_ssl_strings))
|
||||
&& !RUN_ONCE_ALT(&ssl_strings, ossl_init_no_load_ssl_strings,
|
||||
ossl_init_load_ssl_strings))
|
||||
return 0;
|
||||
|
||||
if ((opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
@ -2109,7 +2109,7 @@ int SSL_key_update(SSL *s, int updatetype)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SSL_get_key_update_type(SSL *s)
|
||||
int SSL_get_key_update_type(const SSL *s)
|
||||
{
|
||||
return s->key_update;
|
||||
}
|
||||
@ -2150,7 +2150,7 @@ int SSL_renegotiate_abbreviated(SSL *s)
|
||||
return s->method->ssl_renegotiate(s);
|
||||
}
|
||||
|
||||
int SSL_renegotiate_pending(SSL *s)
|
||||
int SSL_renegotiate_pending(const SSL *s)
|
||||
{
|
||||
/*
|
||||
* becomes true when negotiation is requested; false again once a
|
||||
@ -2510,6 +2510,26 @@ STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Distinguish between ciphers controlled by set_ciphersuite() and
|
||||
* set_cipher_list() when counting.
|
||||
*/
|
||||
static int cipher_list_tls12_num(STACK_OF(SSL_CIPHER) *sk)
|
||||
{
|
||||
int i, num = 0;
|
||||
const SSL_CIPHER *c;
|
||||
|
||||
if (sk == NULL)
|
||||
return 0;
|
||||
for (i = 0; i < sk_SSL_CIPHER_num(sk); ++i) {
|
||||
c = sk_SSL_CIPHER_value(sk, i);
|
||||
if (c->min_tls >= TLS1_3_VERSION)
|
||||
continue;
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/** specify the ciphers to be used by default by the SSL_CTX */
|
||||
int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
|
||||
{
|
||||
@ -2527,7 +2547,7 @@ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
|
||||
*/
|
||||
if (sk == NULL)
|
||||
return 0;
|
||||
else if (sk_SSL_CIPHER_num(sk) == 0) {
|
||||
else if (cipher_list_tls12_num(sk) == 0) {
|
||||
SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
|
||||
return 0;
|
||||
}
|
||||
@ -2545,7 +2565,7 @@ int SSL_set_cipher_list(SSL *s, const char *str)
|
||||
/* see comment in SSL_CTX_set_cipher_list */
|
||||
if (sk == NULL)
|
||||
return 0;
|
||||
else if (sk_SSL_CIPHER_num(sk) == 0) {
|
||||
else if (cipher_list_tls12_num(sk) == 0) {
|
||||
SSLerr(SSL_F_SSL_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);
|
||||
return 0;
|
||||
}
|
||||
@ -3430,12 +3450,12 @@ void ssl_update_cache(SSL *s, int mode)
|
||||
}
|
||||
}
|
||||
|
||||
const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx)
|
||||
const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx)
|
||||
{
|
||||
return ctx->method;
|
||||
}
|
||||
|
||||
const SSL_METHOD *SSL_get_ssl_method(SSL *s)
|
||||
const SSL_METHOD *SSL_get_ssl_method(const SSL *s)
|
||||
{
|
||||
return s->method;
|
||||
}
|
||||
@ -3873,7 +3893,7 @@ const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s)
|
||||
return s->s3->tmp.new_cipher;
|
||||
}
|
||||
|
||||
const COMP_METHOD *SSL_get_current_compression(SSL *s)
|
||||
const COMP_METHOD *SSL_get_current_compression(const SSL *s)
|
||||
{
|
||||
#ifndef OPENSSL_NO_COMP
|
||||
return s->compress ? COMP_CTX_get_method(s->compress) : NULL;
|
||||
@ -3882,7 +3902,7 @@ const COMP_METHOD *SSL_get_current_compression(SSL *s)
|
||||
#endif
|
||||
}
|
||||
|
||||
const COMP_METHOD *SSL_get_current_expansion(SSL *s)
|
||||
const COMP_METHOD *SSL_get_current_expansion(const SSL *s)
|
||||
{
|
||||
#ifndef OPENSSL_NO_COMP
|
||||
return s->expand ? COMP_CTX_get_method(s->expand) : NULL;
|
||||
@ -4330,7 +4350,7 @@ void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg)
|
||||
ctx->record_padding_arg = arg;
|
||||
}
|
||||
|
||||
void *SSL_CTX_get_record_padding_callback_arg(SSL_CTX *ctx)
|
||||
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx)
|
||||
{
|
||||
return ctx->record_padding_arg;
|
||||
}
|
||||
@ -4359,7 +4379,7 @@ void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg)
|
||||
ssl->record_padding_arg = arg;
|
||||
}
|
||||
|
||||
void *SSL_get_record_padding_callback_arg(SSL *ssl)
|
||||
void *SSL_get_record_padding_callback_arg(const SSL *ssl)
|
||||
{
|
||||
return ssl->record_padding_arg;
|
||||
}
|
||||
@ -4383,7 +4403,7 @@ int SSL_set_num_tickets(SSL *s, size_t num_tickets)
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t SSL_get_num_tickets(SSL *s)
|
||||
size_t SSL_get_num_tickets(const SSL *s)
|
||||
{
|
||||
return s->num_tickets;
|
||||
}
|
||||
@ -4395,7 +4415,7 @@ int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets)
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t SSL_CTX_get_num_tickets(SSL_CTX *ctx)
|
||||
size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx)
|
||||
{
|
||||
return ctx->num_tickets;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
@ -1170,8 +1170,6 @@ struct ssl_st {
|
||||
EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
|
||||
unsigned char write_iv[EVP_MAX_IV_LENGTH]; /* TLSv1.3 static write IV */
|
||||
EVP_MD_CTX *write_hash; /* used for mac generation */
|
||||
/* Count of how many KeyUpdate messages we have received */
|
||||
unsigned int key_update_count;
|
||||
/* session info */
|
||||
/* client cert? */
|
||||
/* This is used to hold the server certificate used */
|
||||
@ -2461,7 +2459,7 @@ __owur int tls13_hkdf_expand(SSL *s, const EVP_MD *md,
|
||||
const unsigned char *secret,
|
||||
const unsigned char *label, size_t labellen,
|
||||
const unsigned char *data, size_t datalen,
|
||||
unsigned char *out, size_t outlen);
|
||||
unsigned char *out, size_t outlen, int fatal);
|
||||
__owur int tls13_derive_key(SSL *s, const EVP_MD *md,
|
||||
const unsigned char *secret, unsigned char *key,
|
||||
size_t keylen);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -350,10 +350,12 @@ static const EXTENSION_DEFINITION ext_defs[] = {
|
||||
{
|
||||
/*
|
||||
* Special unsolicited ServerHello extension only used when
|
||||
* SSL_OP_CRYPTOPRO_TLSEXT_BUG is set
|
||||
* SSL_OP_CRYPTOPRO_TLSEXT_BUG is set. We allow it in a ClientHello but
|
||||
* ignore it.
|
||||
*/
|
||||
TLSEXT_TYPE_cryptopro_bug,
|
||||
SSL_EXT_TLS1_2_SERVER_HELLO | SSL_EXT_TLS1_2_AND_BELOW_ONLY,
|
||||
SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_2_SERVER_HELLO
|
||||
| SSL_EXT_TLS1_2_AND_BELOW_ONLY,
|
||||
NULL, NULL, NULL, tls_construct_stoc_cryptopro_bug, NULL, NULL
|
||||
},
|
||||
{
|
||||
@ -625,7 +627,12 @@ int tls_collect_extensions(SSL *s, PACKET *packet, unsigned int context,
|
||||
&& type != TLSEXT_TYPE_cookie
|
||||
&& type != TLSEXT_TYPE_renegotiate
|
||||
&& type != TLSEXT_TYPE_signed_certificate_timestamp
|
||||
&& (s->ext.extflags[idx] & SSL_EXT_FLAG_SENT) == 0) {
|
||||
&& (s->ext.extflags[idx] & SSL_EXT_FLAG_SENT) == 0
|
||||
#ifndef OPENSSL_NO_GOST
|
||||
&& !((context & SSL_EXT_TLS1_2_SERVER_HELLO) != 0
|
||||
&& type == TLSEXT_TYPE_cryptopro_bug)
|
||||
#endif
|
||||
) {
|
||||
SSLfatal(s, SSL_AD_UNSUPPORTED_EXTENSION,
|
||||
SSL_F_TLS_COLLECT_EXTENSIONS, SSL_R_UNSOLICITED_EXTENSION);
|
||||
goto err;
|
||||
@ -1508,7 +1515,7 @@ int tls_psk_do_binder(SSL *s, const EVP_MD *md, const unsigned char *msgstart,
|
||||
|
||||
/* Generate the binder key */
|
||||
if (!tls13_hkdf_expand(s, md, early_secret, label, labelsize, hash,
|
||||
hashsize, binderkey, hashsize)) {
|
||||
hashsize, binderkey, hashsize, 1)) {
|
||||
/* SSLfatal() already called */
|
||||
goto err;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@ -344,8 +344,10 @@ static int state_machine(SSL *s, int server)
|
||||
}
|
||||
|
||||
s->server = server;
|
||||
if (cb != NULL)
|
||||
cb(s, SSL_CB_HANDSHAKE_START, 1);
|
||||
if (cb != NULL) {
|
||||
if (SSL_IS_FIRST_HANDSHAKE(s) || !SSL_IS_TLS13(s))
|
||||
cb(s, SSL_CB_HANDSHAKE_START, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fatal errors in this block don't send an alert because we have
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
/*
|
||||
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
* Copyright 2005 Nokia. All rights reserved.
|
||||
*
|
||||
@ -1114,13 +1114,6 @@ int tls_construct_client_hello(SSL *s, WPACKET *pkt)
|
||||
SSL_SESSION *sess = s->session;
|
||||
unsigned char *session_id;
|
||||
|
||||
if (!WPACKET_set_max_size(pkt, SSL3_RT_MAX_PLAIN_LENGTH)) {
|
||||
/* Should not happen */
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR,
|
||||
SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Work out what SSL/TLS/DTLS version to use */
|
||||
protverr = ssl_set_client_hello_version(s);
|
||||
if (protverr != 0) {
|
||||
@ -1716,6 +1709,7 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt)
|
||||
if (SSL_IS_DTLS(s) && s->hit) {
|
||||
unsigned char sctpauthkey[64];
|
||||
char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)];
|
||||
size_t labellen;
|
||||
|
||||
/*
|
||||
* Add new shared key for SCTP-Auth, will be ignored if
|
||||
@ -1724,10 +1718,15 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt)
|
||||
memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL,
|
||||
sizeof(DTLS1_SCTP_AUTH_LABEL));
|
||||
|
||||
/* Don't include the terminating zero. */
|
||||
labellen = sizeof(labelbuffer) - 1;
|
||||
if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG)
|
||||
labellen += 1;
|
||||
|
||||
if (SSL_export_keying_material(s, sctpauthkey,
|
||||
sizeof(sctpauthkey),
|
||||
labelbuffer,
|
||||
sizeof(labelbuffer), NULL, 0, 0) <= 0) {
|
||||
labellen, NULL, 0, 0) <= 0) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_SERVER_HELLO,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
goto err;
|
||||
@ -2355,7 +2354,8 @@ MSG_PROCESS_RETURN tls_process_key_exchange(SSL *s, PACKET *pkt)
|
||||
}
|
||||
#ifdef SSL_DEBUG
|
||||
if (SSL_USE_SIGALGS(s))
|
||||
fprintf(stderr, "USING TLSv1.2 HASH %s\n", EVP_MD_name(md));
|
||||
fprintf(stderr, "USING TLSv1.2 HASH %s\n",
|
||||
md == NULL ? "n/a" : EVP_MD_name(md));
|
||||
#endif
|
||||
|
||||
if (!PACKET_get_length_prefixed_2(pkt, &signature)
|
||||
@ -2741,7 +2741,7 @@ MSG_PROCESS_RETURN tls_process_new_session_ticket(SSL *s, PACKET *pkt)
|
||||
PACKET_data(&nonce),
|
||||
PACKET_remaining(&nonce),
|
||||
s->session->master_key,
|
||||
hashlen)) {
|
||||
hashlen, 1)) {
|
||||
/* SSLfatal() already called */
|
||||
goto err;
|
||||
}
|
||||
@ -3405,6 +3405,7 @@ int tls_client_key_exchange_post_work(SSL *s)
|
||||
if (SSL_IS_DTLS(s)) {
|
||||
unsigned char sctpauthkey[64];
|
||||
char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)];
|
||||
size_t labellen;
|
||||
|
||||
/*
|
||||
* Add new shared key for SCTP-Auth, will be ignored if no SCTP
|
||||
@ -3413,9 +3414,14 @@ int tls_client_key_exchange_post_work(SSL *s)
|
||||
memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL,
|
||||
sizeof(DTLS1_SCTP_AUTH_LABEL));
|
||||
|
||||
/* Don't include the terminating zero. */
|
||||
labellen = sizeof(labelbuffer) - 1;
|
||||
if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG)
|
||||
labellen += 1;
|
||||
|
||||
if (SSL_export_keying_material(s, sctpauthkey,
|
||||
sizeof(sctpauthkey), labelbuffer,
|
||||
sizeof(labelbuffer), NULL, 0, 0) <= 0) {
|
||||
labellen, NULL, 0, 0) <= 0) {
|
||||
SSLfatal(s, SSL_AD_INTERNAL_ERROR,
|
||||
SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK,
|
||||
ERR_R_INTERNAL_ERROR);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user