Skip to content

Commit

Permalink
Merge branch 'main' into openvpn
Browse files Browse the repository at this point in the history
  • Loading branch information
smittals2 authored Jun 14, 2024
2 parents 7291d4b + b765d4a commit 70d2bd5
Show file tree
Hide file tree
Showing 127 changed files with 1,907 additions and 979 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
python-main:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
name: Python main
steps:
- name: Install OS Dependencies
run: |
Expand All @@ -112,7 +113,17 @@ jobs:
./tests/ci/integration/run_python_integration.sh main
python-releases:
if: github.repository_owner == 'aws'
strategy:
fail-fast: false
matrix:
openssl_in_crt:
- "0"
- "1"
fips:
- "0"
- "1"
runs-on: ubuntu-latest
name: Python releases (FIPS=${{ matrix.fips}} OPENSSL_IN_CRT=${{ matrix.openssl_in_crt }})
steps:
- name: Install OS Dependencies
run: |
Expand All @@ -121,7 +132,10 @@ jobs:
- uses: actions/checkout@v3
- name: Build AWS-LC, build python, run tests
run: |
./tests/ci/integration/run_python_integration.sh 3.10 3.11 3.12
./tests/ci/integration/run_python_integration.sh 3.10 3.11 3.12 3.13
env:
FIPS: ${{ matrix.fips }}
AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO: ${{ matrix.openssl_in_crt }}
bind9:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-alt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
uses: KyleMayes/install-llvm-action@v2
id: clang
with:
version: 16
version: 17
env: true
- name: Setup CMake
uses: threeal/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ if(NOT OPENSSL_NO_ASM)
set(PERLASM_STYLE win32n)
set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
endif()
find_program(NASM_EXECUTABLE nasm)
set(CMAKE_ASM_NASM_COMPILER ${NASM_EXECUTABLE})
set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")

# On Windows, we use the NASM output.
Expand Down
43 changes: 8 additions & 35 deletions crypto/chacha/asm/chacha-armv4.pl
Original file line number Diff line number Diff line change
Expand Up @@ -199,39 +199,14 @@ sub ROUND {
.long 0x61707865,0x3320646e,0x79622d32,0x6b206574 @ endian-neutral
.Lone:
.long 1,0,0,0
#if __ARM_MAX_ARCH__>=7
.LOPENSSL_armcap:
.word OPENSSL_armcap_P-.Lsigma
#else
.word -1
#endif
.globl ChaCha20_ctr32
.type ChaCha20_ctr32,%function
.globl ChaCha20_ctr32_nohw
.type ChaCha20_ctr32_nohw,%function
.align 5
ChaCha20_ctr32:
.LChaCha20_ctr32:
ChaCha20_ctr32_nohw:
ldr r12,[sp,#0] @ pull pointer to counter and nonce
stmdb sp!,{r0-r2,r4-r11,lr}
adr r14,.Lsigma
cmp r2,#0 @ len==0?
#ifdef __thumb2__
itt eq
#endif
addeq sp,sp,#4*3
beq .Lno_data
#if __ARM_MAX_ARCH__>=7
cmp r2,#192 @ test len
bls .Lshort
ldr r4,[r14,#32]
ldr r4,[r14,r4]
# ifdef __APPLE__
ldr r4,[r4]
# endif
tst r4,#ARMV7_NEON
bne .LChaCha20_neon
.Lshort:
#endif
ldmia r12,{r4-r7} @ load counter and nonce
sub sp,sp,#4*(16) @ off-load area
stmdb sp!,{r4-r7} @ copy counter and nonce
Expand Down Expand Up @@ -624,9 +599,8 @@ sub ROUND {
.Ldone:
add sp,sp,#4*(32+3)
.Lno_data:
ldmia sp!,{r4-r11,pc}
.size ChaCha20_ctr32,.-ChaCha20_ctr32
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
___

{{{
Expand Down Expand Up @@ -668,12 +642,12 @@ sub NEONROUND {
.arch armv7-a
.fpu neon
.type ChaCha20_neon,%function
.globl ChaCha20_ctr32_neon
.type ChaCha20_ctr32_neon,%function
.align 5
ChaCha20_neon:
ChaCha20_ctr32_neon:
ldr r12,[sp,#0] @ pull pointer to counter and nonce
stmdb sp!,{r0-r2,r4-r11,lr}
.LChaCha20_neon:
adr r14,.Lsigma
vstmdb sp!,{d8-d15} @ ABI spec says so
stmdb sp!,{r0-r3}
Expand Down Expand Up @@ -1148,8 +1122,7 @@ sub NEONROUND {
vldmia sp,{d8-d15}
add sp,sp,#4*(16+3)
ldmia sp!,{r4-r11,pc}
.size ChaCha20_neon,.-ChaCha20_neon
.comm OPENSSL_armcap_P,4,4
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
#endif
___
}}}
Expand Down
33 changes: 8 additions & 25 deletions crypto/chacha/asm/chacha-armv8.pl
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ sub ROUND {
$code.=<<___;
#include <openssl/arm_arch.h>
.extern OPENSSL_armcap_P
.hidden OPENSSL_armcap_P
.section .rodata
.align 5
Expand All @@ -140,24 +137,10 @@ sub ROUND {
.text
.globl ChaCha20_ctr32
.type ChaCha20_ctr32,%function
.globl ChaCha20_ctr32_nohw
.type ChaCha20_ctr32_nohw,%function
.align 5
ChaCha20_ctr32:
AARCH64_VALID_CALL_TARGET
cbz $len,.Labort
#if defined(OPENSSL_HWASAN) && __clang_major__ >= 10
adrp @x[0],:pg_hi21_nc:OPENSSL_armcap_P
#else
adrp @x[0],:pg_hi21:OPENSSL_armcap_P
#endif
cmp $len,#192
b.lo .Lshort
ldr w17,[@x[0],:lo12:OPENSSL_armcap_P]
tst w17,#ARMV7_NEON
b.ne ChaCha20_neon
.Lshort:
ChaCha20_ctr32_nohw:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
Expand Down Expand Up @@ -280,7 +263,6 @@ sub ROUND {
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
.Labort:
ret
.align 4
Expand Down Expand Up @@ -338,7 +320,7 @@ sub ROUND {
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_ctr32,.-ChaCha20_ctr32
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
___

{{{
Expand Down Expand Up @@ -379,9 +361,10 @@ sub NEONROUND {

$code.=<<___;
.type ChaCha20_neon,%function
.globl ChaCha20_ctr32_neon
.type ChaCha20_ctr32_neon,%function
.align 5
ChaCha20_neon:
ChaCha20_ctr32_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
Expand Down Expand Up @@ -694,7 +677,7 @@ sub NEONROUND {
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_neon,.-ChaCha20_neon
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
___
{
my ($T0,$T1,$T2,$T3,$T4,$T5)=@K;
Expand Down
1 change: 1 addition & 0 deletions crypto/chacha/asm/chacha-x86_64.pl
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ sub ROUND { # critical path is 24 cycles per round
.align 64
ChaCha20_ctr32:
.cfi_startproc
_CET_ENDBR
cmp \$0,$len
je .Lno_data
mov OPENSSL_ia32cap_P+4(%rip),%r10
Expand Down
17 changes: 16 additions & 1 deletion crypto/chacha/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,22 @@ void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
#endif
}

#if defined(CHACHA20_ASM)
#if defined(CHACHA20_ASM_NOHW)
static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]) {
#if defined(CHACHA20_ASM_NEON)
if (ChaCha20_ctr32_neon_capable(in_len)) {
ChaCha20_ctr32_neon(out, in, in_len, key, counter);
return;
}
#endif
if (in_len > 0) {
ChaCha20_ctr32_nohw(out, in, in_len, key, counter);
}
}
#endif

#if defined(CHACHA20_ASM) || defined(CHACHA20_ASM_NOHW)

void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
const uint8_t key[32], const uint8_t nonce[12],
Expand Down
29 changes: 24 additions & 5 deletions crypto/chacha/chacha_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,25 @@ TEST(ChaChaTest, CounterOverflow) {
}
}

#if defined(CHACHA20_ASM) && defined(SUPPORTS_ABI_TEST)
#if defined(SUPPORTS_ABI_TEST)

static void check_abi(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]) {
#if defined(CHACHA20_ASM)
CHECK_ABI(ChaCha20_ctr32, out, in, in_len, key, counter);
#endif
#if defined(CHACHA20_ASM_NEON)
if (ChaCha20_ctr32_neon_capable(in_len)) {
CHECK_ABI(ChaCha20_ctr32_neon, out, in, in_len, key, counter);
}
#endif
#if defined(CHACHA20_ASM_NOHW)
if (in_len > 0) {
CHECK_ABI(ChaCha20_ctr32_nohw, out, in, in_len, key, counter);
}
#endif
}

TEST(ChaChaTest, ABI) {
uint32_t key[8];
OPENSSL_memcpy(key, kKey, sizeof(key));
Expand All @@ -357,14 +375,15 @@ TEST(ChaChaTest, ABI) {
std::unique_ptr<uint8_t[]> buf(new uint8_t[sizeof(kInput)]);
for (size_t len = 0; len <= 32; len++) {
SCOPED_TRACE(len);
CHECK_ABI(ChaCha20_ctr32, buf.get(), kInput, len, key, kCounterNonce);
check_abi(buf.get(), kInput, len, key, kCounterNonce);
}

for (size_t len : {32 * 2, 32 * 4, 32 * 8, 32 * 16, 32 * 24}) {
SCOPED_TRACE(len);
CHECK_ABI(ChaCha20_ctr32, buf.get(), kInput, len, key, kCounterNonce);
check_abi(buf.get(), kInput, len, key, kCounterNonce);
// Cover the partial block paths.
CHECK_ABI(ChaCha20_ctr32, buf.get(), kInput, len + 15, key, kCounterNonce);
check_abi(buf.get(), kInput, len + 15, key, kCounterNonce);
}
}
#endif // CHACHA20_ASM && SUPPORTS_ABI_TEST

#endif // SUPPORTS_ABI_TEST
29 changes: 26 additions & 3 deletions crypto/chacha/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <openssl/base.h>

#include "../fipsmodule/cpucap/internal.h"
#include "../internal.h"

#if defined(__cplusplus)
extern "C" {
#endif
Expand All @@ -27,11 +30,25 @@ extern "C" {
void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
const uint8_t nonce[16]);

#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64))

#define CHACHA20_ASM

#elif !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))

#define CHACHA20_ASM_NOHW

#define CHACHA20_ASM_NEON
OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) {
return (len >= 192) && CRYPTO_is_NEON_capable();
}
void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif

#if defined(CHACHA20_ASM)
// ChaCha20_ctr32 encrypts |in_len| bytes from |in| and writes the result to
// |out|. If |in| and |out| alias, they must be equal.
//
Expand All @@ -44,6 +61,12 @@ void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif

#if defined(CHACHA20_ASM_NOHW)
// ChaCha20_ctr32_nohw is like |ChaCha20_ctr32| except |in_len| must be nonzero.
void ChaCha20_ctr32_nohw(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif


#if defined(__cplusplus)
} // extern C
Expand Down
Loading

0 comments on commit 70d2bd5

Please sign in to comment.