Skip to content

Commit

Permalink
openssl, refactor: update to v3.3.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jul 5, 2024
1 parent 88dbc18 commit 70d3548
Show file tree
Hide file tree
Showing 56 changed files with 1,353 additions and 594 deletions.
2 changes: 1 addition & 1 deletion openssl/cmake/linux_riscv64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ set(src_list
${PROJECT_SOURCE_DIR}/src/crypto/cast/c_skey.c
${PROJECT_SOURCE_DIR}/src/crypto/chacha/chacha_enc.c
${PROJECT_SOURCE_DIR}/src/crypto/chacha/chacha_riscv.c
${PROJECT_SOURCE_DIR}/src/crypto/chacha/gen/linux_riscv64/chacha-riscv64-zvkb.s
${PROJECT_SOURCE_DIR}/src/crypto/chacha/gen/linux_riscv64/chacha-riscv64-zbb-zvkb.s
${PROJECT_SOURCE_DIR}/src/crypto/cmac/cmac.c
${PROJECT_SOURCE_DIR}/src/crypto/cmp/cmp_asn.c
${PROJECT_SOURCE_DIR}/src/crypto/cmp/cmp_client.c
Expand Down
8 changes: 8 additions & 0 deletions openssl/include/crypto/bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ 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);
int ossl_bn_mask_bits_fixed_top(BIGNUM *a, int n);
int ossl_bn_is_word_fixed_top(const BIGNUM *a, BN_ULONG w);
int ossl_bn_priv_rand_range_fixed_top(BIGNUM *r, const BIGNUM *range,
unsigned int strength, BN_CTX *ctx);
int ossl_bn_gen_dsa_nonce_fixed_top(BIGNUM *out, const BIGNUM *range,
const BIGNUM *priv,
const unsigned char *message,
size_t message_len, BN_CTX *ctx);

#define BN_PRIMETEST_COMPOSITE 0
#define BN_PRIMETEST_COMPOSITE_WITH_FACTOR 1
Expand Down
25 changes: 24 additions & 1 deletion openssl/include/internal/constant_time.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2014-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -140,6 +140,29 @@ static ossl_inline uint64_t constant_time_lt_64(uint64_t a, uint64_t b)
return constant_time_msb_64(a ^ ((a ^ b) | ((a - b) ^ b)));
}

#ifdef BN_ULONG
static ossl_inline BN_ULONG constant_time_msb_bn(BN_ULONG a)
{
return 0 - (a >> (sizeof(a) * 8 - 1));
}

static ossl_inline BN_ULONG constant_time_lt_bn(BN_ULONG a, BN_ULONG b)
{
return constant_time_msb_bn(a ^ ((a ^ b) | ((a - b) ^ b)));
}

static ossl_inline BN_ULONG constant_time_is_zero_bn(BN_ULONG a)
{
return constant_time_msb_bn(~a & (a - 1));
}

static ossl_inline BN_ULONG constant_time_eq_bn(BN_ULONG a,
BN_ULONG b)
{
return constant_time_is_zero_bn(a ^ b);
}
#endif

static ossl_inline unsigned int constant_time_ge(unsigned int a,
unsigned int b)
{
Expand Down
35 changes: 35 additions & 0 deletions openssl/include/internal/quic_stream_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,41 @@ static ossl_inline ossl_unused int ossl_quic_stream_recv_get_final_size(const QU
}
}

/*
* Determines the number of bytes available still to be read, and (if
* include_fin is 1) whether a FIN or reset has yet to be read.
*/
static ossl_inline ossl_unused int ossl_quic_stream_recv_pending(const QUIC_STREAM *s,
int include_fin)
{
size_t avail;
int fin = 0;

switch (s->recv_state) {
default:
case QUIC_RSTREAM_STATE_NONE:
return 0;

case QUIC_RSTREAM_STATE_RECV:
case QUIC_RSTREAM_STATE_SIZE_KNOWN:
case QUIC_RSTREAM_STATE_DATA_RECVD:
if (!ossl_quic_rstream_available(s->rstream, &avail, &fin))
avail = 0;

if (avail == 0 && include_fin && fin)
avail = 1;

return avail;

case QUIC_RSTREAM_STATE_RESET_RECVD:
return include_fin;

case QUIC_RSTREAM_STATE_DATA_READ:
case QUIC_RSTREAM_STATE_RESET_READ:
return 0;
}
}

/*
* QUIC Stream Map
* ===============
Expand Down
12 changes: 3 additions & 9 deletions openssl/include/internal/sockets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -190,14 +190,8 @@ typedef size_t socklen_t; /* Currently appears to be missing on VMS */
# define readsocket(s,b,n) read((s),(b),(n))
# define writesocket(s,b,n) write((s),(char *)(b),(n))
# elif defined(OPENSSL_SYS_TANDEM)
# if defined(OPENSSL_TANDEM_FLOSS)
# include <floss.h(floss_read, floss_write)>
# define readsocket(s,b,n) floss_read((s),(b),(n))
# define writesocket(s,b,n) floss_write((s),(b),(n))
# else
# define readsocket(s,b,n) read((s),(b),(n))
# define writesocket(s,b,n) write((s),(b),(n))
# endif
# define readsocket(s,b,n) read((s),(b),(n))
# define writesocket(s,b,n) write((s),(b),(n))
# define ioctlsocket(a,b,c) ioctl(a,b,c)
# define closesocket(s) close(s)
# else
Expand Down
3 changes: 2 additions & 1 deletion openssl/include/openssl/e_os2.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand Down Expand Up @@ -228,6 +228,7 @@ typedef INT32 int32_t;
typedef UINT32 uint32_t;
typedef INT64 int64_t;
typedef UINT64 uint64_t;
typedef UINTN uintptr_t;
# elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(__osf__) || defined(__sgi) || defined(__hpux) || \
defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
Expand Down
10 changes: 5 additions & 5 deletions openssl/include/openssl/opensslv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
*/
# define OPENSSL_VERSION_MAJOR 3
# define OPENSSL_VERSION_MINOR 3
# define OPENSSL_VERSION_PATCH 0
# define OPENSSL_VERSION_PATCH 1

/*
* Additional version information
Expand Down Expand Up @@ -74,21 +74,21 @@ extern "C" {
* longer variant with OPENSSL_VERSION_PRE_RELEASE_STR and
* OPENSSL_VERSION_BUILD_METADATA_STR appended.
*/
# define OPENSSL_VERSION_STR "3.3.0"
# define OPENSSL_FULL_VERSION_STR "3.3.0"
# define OPENSSL_VERSION_STR "3.3.1"
# define OPENSSL_FULL_VERSION_STR "3.3.1"

/*
* SECTION 3: ADDITIONAL METADATA
*
* These strings are defined separately to allow them to be parsable.
*/
# define OPENSSL_RELEASE_DATE "9 Apr 2024"
# define OPENSSL_RELEASE_DATE "4 Jun 2024"

/*
* SECTION 4: BACKWARD COMPATIBILITY
*/

# define OPENSSL_VERSION_TEXT "OpenSSL 3.3.0 9 Apr 2024"
# define OPENSSL_VERSION_TEXT "OpenSSL 3.3.1 4 Jun 2024"

/* Synthesize OPENSSL_VERSION_NUMBER with the layout 0xMNN00PPSL */
# ifdef OPENSSL_VERSION_PRE_RELEASE
Expand Down
2 changes: 2 additions & 0 deletions openssl/include/openssl/sslerr.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@
# define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086
# define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
# define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
# define SSL_R_TLSV1_ALERT_NO_APPLICATION_PROTOCOL 1120
# define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
# define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
# define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
# define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
# define SSL_R_TLSV1_ALERT_UNKNOWN_PSK_IDENTITY 1115
# define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
# define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE 1114
# define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE 1113
Expand Down
7 changes: 5 additions & 2 deletions openssl/src/crypto/aes/gen/darwin_arm64/bsaes-armv8.S
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
// Copyright 2021-2024 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
Expand Down Expand Up @@ -984,6 +984,7 @@ Lkey_loop:
// Initialisation vector overwritten with last quadword of ciphertext
// No output registers, usual AAPCS64 register preservation
_ossl_bsaes_cbc_encrypt:
AARCH64_VALID_CALL_TARGET
cmp x2, #128
bhs Lcbc_do_bsaes
b _AES_cbc_encrypt
Expand Down Expand Up @@ -1236,7 +1237,7 @@ Lcbc_dec_bzero: // wipe key schedule [if any]
// Output text filled in
// No output registers, usual AAPCS64 register preservation
_ossl_bsaes_ctr32_encrypt_blocks:

AARCH64_VALID_CALL_TARGET
cmp x2, #8 // use plain AES for
blo Lctr_enc_short // small sizes

Expand Down Expand Up @@ -1442,6 +1443,7 @@ Lctr_enc_short_loop:
// Output ciphertext filled in
// No output registers, usual AAPCS64 register preservation
_ossl_bsaes_xts_encrypt:
AARCH64_VALID_CALL_TARGET
// Stack layout:
// sp ->
// nrounds*128-96 bytes: key schedule
Expand Down Expand Up @@ -1887,6 +1889,7 @@ Lxts_magic:
// Output plaintext filled in
// No output registers, usual AAPCS64 register preservation
_ossl_bsaes_xts_decrypt:
AARCH64_VALID_CALL_TARGET
// Stack layout:
// sp ->
// nrounds*128-96 bytes: key schedule
Expand Down
7 changes: 5 additions & 2 deletions openssl/src/crypto/aes/gen/linux_arm64/bsaes-armv8.S
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
// Copyright 2021-2024 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
Expand Down Expand Up @@ -984,6 +984,7 @@ _bsaes_key_convert:
// Initialisation vector overwritten with last quadword of ciphertext
// No output registers, usual AAPCS64 register preservation
ossl_bsaes_cbc_encrypt:
AARCH64_VALID_CALL_TARGET
cmp x2, #128
bhs .Lcbc_do_bsaes
b AES_cbc_encrypt
Expand Down Expand Up @@ -1236,7 +1237,7 @@ ossl_bsaes_cbc_encrypt:
// Output text filled in
// No output registers, usual AAPCS64 register preservation
ossl_bsaes_ctr32_encrypt_blocks:

AARCH64_VALID_CALL_TARGET
cmp x2, #8 // use plain AES for
blo .Lctr_enc_short // small sizes

Expand Down Expand Up @@ -1442,6 +1443,7 @@ ossl_bsaes_ctr32_encrypt_blocks:
// Output ciphertext filled in
// No output registers, usual AAPCS64 register preservation
ossl_bsaes_xts_encrypt:
AARCH64_VALID_CALL_TARGET
// Stack layout:
// sp ->
// nrounds*128-96 bytes: key schedule
Expand Down Expand Up @@ -1887,6 +1889,7 @@ ossl_bsaes_xts_encrypt:
// Output plaintext filled in
// No output registers, usual AAPCS64 register preservation
ossl_bsaes_xts_decrypt:
AARCH64_VALID_CALL_TARGET
// Stack layout:
// sp ->
// nrounds*128-96 bytes: key schedule
Expand Down
2 changes: 0 additions & 2 deletions openssl/src/crypto/asn1/a_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* generalTime GeneralizedTime }
*/

#define _XOPEN_SOURCE /* To get a definition of timezone */

#include <stdio.h>
#include <time.h>
#include "crypto/asn1.h"
Expand Down
8 changes: 6 additions & 2 deletions openssl/src/crypto/bio/bio_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,12 @@ static int bio_wait(BIO *bio, time_t max_time, unsigned int nap_milliseconds)
return 1;

#ifndef OPENSSL_NO_SOCK
if (BIO_get_fd(bio, &fd) > 0 && fd < FD_SETSIZE)
return BIO_socket_wait(fd, BIO_should_read(bio), max_time);
if (BIO_get_fd(bio, &fd) > 0) {
int ret = BIO_socket_wait(fd, BIO_should_read(bio), max_time);

if (ret != -1)
return ret;
}
#endif
/* fall back to polling since no sockets are available */

Expand Down
9 changes: 5 additions & 4 deletions openssl/src/crypto/bio/bio_sock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand All @@ -26,9 +26,6 @@ static int wsa_init_done = 0;
# if defined __TANDEM
# include <unistd.h>
# include <sys/time.h> /* select */
# if defined(OPENSSL_TANDEM_FLOSS)
# include <floss.h(floss_select)>
# endif
# elif defined _WIN32
# include <winsock.h> /* for type fd_set */
# else
Expand Down Expand Up @@ -435,7 +432,11 @@ int BIO_socket_wait(int fd, int for_read, time_t max_time)
struct timeval tv;
time_t now;

#ifdef _WIN32
if ((SOCKET)fd == INVALID_SOCKET)
#else
if (fd < 0 || fd >= FD_SETSIZE)
#endif
return -1;
if (max_time == 0)
return 1;
Expand Down
28 changes: 21 additions & 7 deletions openssl/src/crypto/bio/bss_dgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
socklen_t addr_len;
BIO_ADDR addr;
# endif
struct sockaddr_storage ss;
socklen_t ss_len = sizeof(ss);

data = (bio_dgram_data *)b->ptr;

Expand All @@ -577,6 +579,10 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
b->shutdown = (int)num;
b->init = 1;
dgram_update_local_addr(b);
if (getpeername(b->num, (struct sockaddr *)&ss, &ss_len) == 0) {
BIO_ADDR_make(&data->peer, BIO_ADDR_sockaddr((BIO_ADDR *)&ss));
data->connected = 1;
}
# if defined(SUPPORT_LOCAL_ADDR)
if (data->local_addr_enabled) {
if (enable_local_addr(b, 1) < 1)
Expand Down Expand Up @@ -1067,19 +1073,27 @@ static void translate_msg_win(BIO *b, WSAMSG *mh, WSABUF *iov,
static void translate_msg(BIO *b, struct msghdr *mh, struct iovec *iov,
unsigned char *control, BIO_MSG *msg)
{
bio_dgram_data *data;

iov->iov_base = msg->data;
iov->iov_len = msg->data_len;

/* macOS requires msg_namelen be 0 if msg_name is NULL */
mh->msg_name = msg->peer != NULL ? &msg->peer->sa : NULL;
if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET)
mh->msg_namelen = sizeof(struct sockaddr_in);
data = (bio_dgram_data *)b->ptr;
if (data->connected == 0) {
/* macOS requires msg_namelen be 0 if msg_name is NULL */
mh->msg_name = msg->peer != NULL ? &msg->peer->sa : NULL;
if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET)
mh->msg_namelen = sizeof(struct sockaddr_in);
# if OPENSSL_USE_IPV6
else if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET6)
mh->msg_namelen = sizeof(struct sockaddr_in6);
else if (msg->peer != NULL && dgram_get_sock_family(b) == AF_INET6)
mh->msg_namelen = sizeof(struct sockaddr_in6);
# endif
else
else
mh->msg_namelen = 0;
} else {
mh->msg_name = NULL;
mh->msg_namelen = 0;
}

mh->msg_iov = iov;
mh->msg_iovlen = 1;
Expand Down
Loading

0 comments on commit 70d3548

Please sign in to comment.