Skip to content

Commit d5ba953

Browse files
authored
Merge branch 'main' into small-fixes
2 parents 0522382 + 863ed59 commit d5ba953

27 files changed

Lines changed: 589 additions & 102 deletions

.github/workflows/aws-lc-rs.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,111 @@ jobs:
251251
cargo test -p aws-lc-sys --target x86_64-pc-windows-msvc
252252
cargo test -p aws-lc-rs --target x86_64-pc-windows-msvc
253253
254+
# Cross-compile to Windows from Linux using cargo-xwin (clang-cl + lld-link)
255+
aws-lc-rs-windows-cross:
256+
if: github.repository_owner == 'aws'
257+
runs-on: ubuntu-24.04
258+
name: aws-lc-rs-windows-cross (${{ matrix.name }})
259+
strategy:
260+
fail-fast: false
261+
matrix:
262+
include:
263+
- name: x86_64
264+
target: x86_64-pc-windows-msvc
265+
- name: x86_64-fips
266+
target: x86_64-pc-windows-msvc
267+
fips: true
268+
steps:
269+
- uses: actions/checkout@v4
270+
with:
271+
repository: aws/aws-lc-rs
272+
path: ./aws-lc-rs
273+
submodules: 'recursive'
274+
- name: Remove aws-lc submodule from crate directories
275+
shell: bash
276+
run: |
277+
rm -rf ./aws-lc-rs/aws-lc-sys/aws-lc
278+
rm -rf ./aws-lc-rs/aws-lc-fips-sys/aws-lc
279+
- uses: actions/checkout@v4
280+
with:
281+
path: ./aws-lc-rs/aws-lc-sys/aws-lc
282+
- uses: actions/checkout@v4
283+
with:
284+
path: ./aws-lc-rs/aws-lc-fips-sys/aws-lc
285+
- uses: dtolnay/rust-toolchain@stable
286+
with:
287+
targets: ${{ matrix.target }}
288+
- uses: actions/setup-go@v4
289+
with:
290+
go-version: '>=1.20'
291+
- name: Install dependencies
292+
run: |
293+
set -ex
294+
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
295+
sudo apt-get install --assume-yes --no-install-recommends \
296+
cmake ninja-build nasm \
297+
wget lsb-release software-properties-common gnupg
298+
# Install Clang 19 from LLVM apt repository
299+
# (xwin's MSVC STL headers require Clang 19+; Ubuntu 24.04 ships Clang 18)
300+
wget -qO- https://apt.llvm.org/llvm.sh | sudo bash -s -- 19
301+
sudo ln -sf /usr/bin/clang-19 /usr/local/bin/clang-cl
302+
sudo ln -sf /usr/bin/lld-19 /usr/local/bin/lld-link
303+
sudo ln -sf /usr/bin/llvm-ar-19 /usr/local/bin/llvm-lib
304+
cargo install cargo-xwin --locked
305+
- name: Setup Wine binfmt
306+
if: matrix.fips
307+
env:
308+
WINEDEBUG: "-all"
309+
DISPLAY: ""
310+
run: |
311+
set -ex
312+
# Wine binfmt allows the kernel to transparently run .exe files through
313+
# Wine. This is needed for the FIPS build, which runs fips_empty_main.exe
314+
# at build time to capture the integrity hash.
315+
#
316+
# Ubuntu 24.04's wine64 (9.0) does not properly execute .CRT$XCU
317+
# initializers in cross-compiled DLLs, which prevents the FIPS
318+
# power-on self-test from running. WineHQ stable (11.0+) handles
319+
# this correctly.
320+
sudo dpkg --add-architecture i386
321+
sudo mkdir -pm755 /etc/apt/keyrings
322+
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
323+
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/noble/winehq-noble.sources
324+
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
325+
sudo apt-get install --assume-yes --install-recommends winehq-stable binfmt-support
326+
# Register Wine as the interpreter for Windows PE executables
327+
if [ ! -f /proc/sys/fs/binfmt_misc/wine ]; then
328+
echo ':wine:M::MZ::/usr/bin/wine:' | sudo tee /proc/sys/fs/binfmt_misc/register
329+
fi
330+
wineboot --init
331+
- name: Build
332+
working-directory: ./aws-lc-rs
333+
env:
334+
WINEDEBUG: "-all"
335+
DISPLAY: ""
336+
run: cargo xwin build -p aws-lc-rs --target ${{ matrix.target }} ${{ matrix.fips && '--features fips' || '' }}
337+
- name: FIPS sanity test (via Wine)
338+
if: matrix.fips
339+
working-directory: ./aws-lc-rs
340+
env:
341+
WINEDEBUG: "-all"
342+
DISPLAY: ""
343+
run: |
344+
# The FIPS crypto DLL has a version prefix (e.g.,
345+
# aws_lc_fips_0_13_13_crypto.dll) and lives in the cargo build
346+
# artifacts directory — not next to the test binary. Set WINEPATH
347+
# so Wine can find it at runtime.
348+
CRYPTO_DLL=$(find target -name '*crypto.dll' -path '*/aws-lc-fips-sys*' | head -1)
349+
if [ -z "${CRYPTO_DLL}" ]; then
350+
echo "ERROR: Could not find FIPS crypto DLL"
351+
exit 1
352+
fi
353+
echo "Found FIPS DLL: ${CRYPTO_DLL}"
354+
export WINEPATH="$(winepath -w "$(dirname "${CRYPTO_DLL}")")"
355+
# Any test that loads the FIPS crypto library triggers the power-on
356+
# self-test; if the integrity hash is wrong the process aborts.
357+
cargo xwin test -p aws-lc-rs --target ${{ matrix.target }} --features fips
358+
254359
# CMake Rust bindings generation tests
255360
cmake-rust-bindings:
256361
if: github.repository_owner == 'aws'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: OCSP integration tests
2+
on:
3+
pull_request:
4+
branches: ["*"]
5+
workflow_dispatch:
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.ref_name }}
8+
cancel-in-progress: true
9+
env:
10+
GOPROXY: https://proxy.golang.org,direct
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
ocsp-external:
16+
if: github.repository_owner == 'aws'
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Git clone the repository
20+
uses: actions/checkout@v3
21+
- name: Install OS Dependencies
22+
run: |
23+
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
24+
sudo apt-get -y --no-install-recommends install cmake ninja-build golang
25+
- name: Build integration_test
26+
run: |
27+
cmake -GNinja -Btest_build_dir
28+
ninja -C test_build_dir ssl/integration_test
29+
- name: Run OCSP integration tests
30+
run: ./test_build_dir/ssl/integration_test

.github/workflows/windows-alt.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ jobs:
166166
- if: ${{ matrix.target == 'x64' }}
167167
name: Run tests
168168
run: cmake --build ./build --target run_tests
169+
- if: ${{ matrix.target == 'x64' }}
170+
name: Setup Go (for FIPS)
171+
uses: actions/setup-go@v4
172+
with:
173+
go-version: '>=1.20'
174+
- if: ${{ matrix.target == 'x64' }}
175+
name: Build and test with FIPS
176+
run: |
177+
cmake -GNinja -B ./build-fips -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=Release -DFIPS=1 -DBUILD_SHARED_LIBS=1
178+
cmake --build ./build-fips
179+
$buildFips = (Resolve-Path ./build-fips).Path
180+
$env:PATH = "$buildFips;$buildFips\crypto;$buildFips\ssl;$env:PATH"
181+
cmake --build ./build-fips --target run_tests
169182
cross-mingw:
170183
if: github.repository_owner == 'aws'
171184
runs-on: ubuntu-22.04

crypto/CMakeLists.txt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -629,30 +629,34 @@ if(FIPS_SHARED)
629629
# Rewrite libcrypto.so, libcrypto.dylib, or crypto.dll to inject the correct module
630630
# hash value. For now we support the FIPS build only on Linux, macOS, iOS, and Windows.
631631
if(MSVC)
632-
# On Windows we use capture_hash.go to capture the computed integrity value that bcm.o prints to generate the
633-
# correct value in generated_fips_shared_support.c. See FIPS.md for a full explanation of the process
634-
build_libcrypto(NAME precrypto MODULE_SOURCE $<TARGET_OBJECTS:fipsmodule>)
632+
# On Windows we use capture_hash.go: build crypto.dll with a placeholder
633+
# hash, then run fips_empty_main.exe (which triggers the integrity check
634+
# and prints the correct hash), then patch the placeholder in crypto.dll.
635+
#
636+
# The fips_integrity target (marked ALL) ensures the hash injection runs
637+
# before 'install' copies crypto.dll. Without this, Cargo builds (which
638+
# run 'cmake --build --target install') would skip the hash injection
639+
# because fips_empty_main is not in crypto's dependency chain.
640+
build_libcrypto(NAME crypto MODULE_SOURCE $<TARGET_OBJECTS:fipsmodule> SET_OUTPUT_NAME)
641+
635642
add_executable(fips_empty_main fipsmodule/fips_empty_main.c)
636-
target_link_libraries(fips_empty_main PUBLIC precrypto)
643+
target_link_libraries(fips_empty_main PUBLIC crypto)
637644
target_add_awslc_include_paths(TARGET fips_empty_main SCOPE PRIVATE)
638-
add_custom_command(OUTPUT generated_fips_shared_support.c
639-
COMMAND ${GO_EXECUTABLE} run
640-
${AWSLC_SOURCE_DIR}/util/fipstools/capture_hash/capture_hash.go
641-
-in-executable $<TARGET_FILE:fips_empty_main> > generated_fips_shared_support.c
642-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
643-
DEPENDS fips_empty_main ${AWSLC_SOURCE_DIR}/util/fipstools/capture_hash/capture_hash.go
644-
)
645-
add_library(
646-
generated_fipsmodule
647-
648-
OBJECT
649-
650-
generated_fips_shared_support.c
651-
${AWSLC_SOURCE_DIR}/crypto/fipsmodule/cpucap/cpucap.c
652-
)
653-
target_add_awslc_include_paths(TARGET generated_fipsmodule SCOPE PRIVATE)
654645

655-
build_libcrypto(NAME crypto MODULE_SOURCE $<TARGET_OBJECTS:generated_fipsmodule> SET_OUTPUT_NAME)
646+
add_custom_command(
647+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fips_hash_injected.stamp
648+
COMMAND ${GO_EXECUTABLE} run
649+
${AWSLC_SOURCE_DIR}/util/fipstools/capture_hash/capture_hash.go
650+
-in-executable $<TARGET_FILE:fips_empty_main>
651+
-patch-dll $<TARGET_FILE:crypto>
652+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/fips_hash_injected.stamp
653+
DEPENDS fips_empty_main crypto
654+
${AWSLC_SOURCE_DIR}/util/fipstools/capture_hash/capture_hash.go
655+
WORKING_DIRECTORY ${AWSLC_SOURCE_DIR}
656+
)
657+
add_custom_target(fips_integrity ALL
658+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/fips_hash_injected.stamp
659+
)
656660
else()
657661
# On Apple and Linux platforms inject_hash.go can parse libcrypto and inject
658662
# the hash directly into the final library.

crypto/fipsmodule/CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,20 @@ elseif(FIPS_SHARED)
611611
# contain pragmas that instruct the compiler to put the code in specific FIPS sections. These sections have a
612612
# specific suffix $a through $c that controls the order of the FIPS sections when it is linked together into a
613613
# Grouped Section.
614+
#
615+
# These custom commands invoke the compiler directly (outside CMake's normal
616+
# target compilation), so we must forward CMAKE_C_FLAGS manually. This is
617+
# necessary for cross-compilation where the flags contain --target and
618+
# system include paths (e.g. clang-cl + xwin on Linux).
619+
separate_arguments(FIPS_MARKER_C_FLAGS NATIVE_COMMAND "${CMAKE_C_FLAGS}")
614620
add_custom_command(
615621
OUTPUT fips_msvc_start.obj
616-
COMMAND ${CMAKE_C_COMPILER} /nologo /c /DAWSLC_FIPS_SHARED_START /Fo:fips_msvc_start.obj ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
622+
COMMAND ${CMAKE_C_COMPILER} ${FIPS_MARKER_C_FLAGS} -w /nologo /c /DAWSLC_FIPS_SHARED_START /Fo:fips_msvc_start.obj ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
617623
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
618624
)
619625
add_custom_command(
620626
OUTPUT fips_msvc_end.obj
621-
COMMAND ${CMAKE_C_COMPILER} /nologo /c /DAWSLC_FIPS_SHARED_END /Fo:fips_msvc_end.obj ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
627+
COMMAND ${CMAKE_C_COMPILER} ${FIPS_MARKER_C_FLAGS} -w /nologo /c /DAWSLC_FIPS_SHARED_END /Fo:fips_msvc_end.obj ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
622628
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/fips_shared_library_marker.c
623629
)
624630
@@ -631,11 +637,9 @@ elseif(FIPS_SHARED)
631637
632638
add_custom_command(
633639
OUTPUT ${BCM_NAME}
634-
# This takes bcm_library which is static library and possibly a collection of assembly files in a CMake list.
635-
# The archiver does not handle the CMake list which uses semicolons between items, this generator expression
636-
# converts it to a list of quoted strings, it also needs to be itself string escaped
637-
COMMAND ${MSVC_LIB} /nologo fips_msvc_start.obj "\"$<JOIN:$<TARGET_OBJECTS:bcm_library>,\" \">\"" fips_msvc_end.obj /OUT:${BCM_NAME}
638-
DEPENDS fips_msvc_start.obj fips_msvc_end.obj bcm_library
640+
COMMAND ${MSVC_LIB} /nologo fips_msvc_start.obj $<TARGET_OBJECTS:bcm_library> fips_msvc_end.obj /OUT:${BCM_NAME}
641+
COMMAND_EXPAND_LISTS
642+
DEPENDS fips_msvc_start.obj fips_msvc_end.obj bcm_library
639643
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
640644
)
641645
else()

crypto/fipsmodule/FIPS.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,20 @@ The Shared Windows FIPS integrity test differs in two key ways:
163163
2. How the correct integrity hash is calculated
164164
165165
Microsoft Visual C compiler (MSVC) does not support linker scripts that add symbols to mark the start and end of the text and rodata sections, as is done on Linux. Instead, `fips_shared_library_marker.c` is compiled twice to generate two object files that contain start/end functions and variables. MSVC `pragma` segment definitions are used to place the markers in specific sections (e.g. `.fipstx$a`). This particular name format uses [Portable Executable Grouped Sections](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#grouped-sections-object-only) to control what section the code is placed in and the order within the section. With the start and end markers placed at `$a` and `$z` respectively, BCM puts everything in the `$b` section. When the final crypto.dll is built, all the code is in the `.fipstx` section, all data is in `.fipsda`, all constants are in `.fipsco`, all uninitialized items in `.fipsbs`, and everything is in the correct order.
166-
The process to generate the expected integrity fingerprint is also different from Linux:
166+
The process to generate the expected integrity fingerprint is also different from Linux. We use a single-DLL capture-and-patch approach: build `crypto.dll` once with a placeholder hash, run it to compute the real hash, then binary-patch the placeholder directly in the DLL. This avoids building two separate DLLs whose linker output may differ (e.g. mandatory ASLR on ARM64 causes different ADRP immediates, and `lld-link` used by clang-cl is not guaranteed to produce byte-identical output across two independent link operations).
167167
168-
1. Build the required object files once: `bcm.obj` from `bcm.c` and the start/end object files
168+
1. Build the required object files once: `bcm.obj` from `bcm.c` and the start/end object files
169169
1. `bcm.obj` places the power-on self tests in the `.CRT$XCU` section which is run automatically by the Windows Common Runtime library (CRT) startup code
170-
2. Use MSVC's `lib.exe` to combine the start/end object files with `bcm.obj` to create the static library `bcm.lib`.
170+
2. Use MSVC's `lib.exe` (or `llvm-lib` for clang-cl) to combine the start/end object files with `bcm.obj` to create the static library `bcm.lib`.
171171
1. MSVC does not support combining multiple object files into another object file like the Apple build.
172172
3. Build `fipsmodule` which contains the placeholder integrity hash
173-
4. Build `precrypto.dll` with `bcm.obj` and `fipsmodule`
174-
5. Build the small application `fips_empty_main.exe` and link it with `precrypto.dll`
175-
6. `capture-hash.go` runs `fips_empty_main.exe`
173+
4. Build `crypto.dll` with `bcm.lib` and `fipsmodule`
174+
5. Build the small application `fips_empty_main.exe` and link it with `crypto.dll`
175+
6. `capture_hash.go` runs `fips_empty_main.exe`
176176
1. The CRT runs all functions in the `.CRT$XC*` sections in order starting with `.CRT$XCA`
177177
2. The BCM power-on tests are in `.CRT$XCU` and are run after all other Windows initialization is complete
178178
3. BCM calculates the correct integrity value which will not match the placeholder value. Before aborting the process the correct value is printed
179-
4. `capture-hash.go` reads the correct integrity value and writes it to `generated_fips_shared_support.c`
180-
7. `generated_fipsmodule` is built with `generated_fips_shared_support.c`
181-
8. `crypto.dll` is built with the same original `bcm.lib` and `generated_fipsmodule`
179+
4. `capture_hash.go` reads the correct integrity value and binary-patches the 32-byte placeholder directly in `crypto.dll`
182180
183181
### Linux Static build
184182

crypto/fipsmodule/bcm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#pragma data_seg(".fipsda$b")
2222
#pragma const_seg(".fipsco$b")
2323
#pragma bss_seg(".fipsbs$b")
24+
// Explicitly declare the FIPS rodata section with correct attributes. This
25+
// ensures the section is known to the compiler/linker even if #pragma const_seg
26+
// is not fully supported (e.g. clang-cl on ARM64).
27+
#pragma section(".fipsco$b", read)
2428
#endif
2529

2630
#include <openssl/chacha.h>

crypto/fipsmodule/cipher/e_aes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
565565
//
566566
// key_len is two AES keys
567567

568-
if (OPENSSL_memcmp(key, key + ctx->key_len / 2, ctx->key_len / 2) == 0) {
568+
if (CRYPTO_memcmp(key, key + ctx->key_len / 2, ctx->key_len / 2) == 0) {
569569
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_XTS_DUPLICATED_KEYS);
570570
return 0;
571571
}

crypto/fipsmodule/evp/p_kem.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ static int pkey_kem_encapsulate(EVP_PKEY_CTX *ctx,
194194
size_t *ciphertext_len,
195195
uint8_t *shared_secret,
196196
size_t *shared_secret_len) {
197+
GUARD_PTR(ctx);
197198
KEM_PKEY_CTX *dctx = ctx->data;
199+
GUARD_PTR(dctx);
198200
const KEM *kem = dctx->kem;
199201
if (kem == NULL) {
200202
if (ctx->pkey == NULL) {
@@ -204,6 +206,12 @@ static int pkey_kem_encapsulate(EVP_PKEY_CTX *ctx,
204206
kem = KEM_KEY_get0_kem(ctx->pkey->pkey.kem_key);
205207
}
206208

209+
// Check that length pointers can be written to.
210+
if (ciphertext_len == NULL || shared_secret_len == NULL) {
211+
OPENSSL_PUT_ERROR(EVP, ERR_R_PASSED_NULL_PARAMETER);
212+
return 0;
213+
}
214+
207215
// Caller is getting parameter values.
208216
if (ciphertext == NULL && shared_secret == NULL) {
209217
*ciphertext_len = kem->ciphertext_len;
@@ -257,7 +265,9 @@ static int pkey_kem_decapsulate(EVP_PKEY_CTX *ctx,
257265
size_t *shared_secret_len,
258266
const uint8_t *ciphertext,
259267
size_t ciphertext_len) {
268+
GUARD_PTR(ctx);
260269
KEM_PKEY_CTX *dctx = ctx->data;
270+
GUARD_PTR(dctx);
261271
const KEM *kem = dctx->kem;
262272
if (kem == NULL) {
263273
if (ctx->pkey == NULL) {
@@ -267,12 +277,24 @@ static int pkey_kem_decapsulate(EVP_PKEY_CTX *ctx,
267277
kem = KEM_KEY_get0_kem(ctx->pkey->pkey.kem_key);
268278
}
269279

280+
// Check that the length pointer can be written to.
281+
if (shared_secret_len == NULL) {
282+
OPENSSL_PUT_ERROR(EVP, ERR_R_PASSED_NULL_PARAMETER);
283+
return 0;
284+
}
285+
270286
// Caller is getting parameter values.
271287
if (shared_secret == NULL) {
272288
*shared_secret_len = kem->shared_secret_len;
273289
return 1;
274290
}
275291

292+
// The ciphertext buffer must be non-NULL for actual decapsulation.
293+
if (ciphertext == NULL) {
294+
OPENSSL_PUT_ERROR(EVP, ERR_R_PASSED_NULL_PARAMETER);
295+
return 0;
296+
}
297+
276298
// The input and output buffers need to be large enough.
277299
if (ciphertext_len != kem->ciphertext_len ||
278300
*shared_secret_len < kem->shared_secret_len) {

crypto/fipsmodule/evp/p_pqdsa.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int pkey_pqdsa_sign_generic(EVP_PKEY_CTX *ctx, uint8_t *sig,
7878
return 1;
7979
}
8080

81-
if (*sig_len != pqdsa->signature_len) {
81+
if (*sig_len < pqdsa->signature_len) {
8282
OPENSSL_PUT_ERROR(EVP, EVP_R_BUFFER_TOO_SMALL);
8383
return 0;
8484
}
@@ -115,6 +115,10 @@ static int pkey_pqdsa_sign_generic(EVP_PKEY_CTX *ctx, uint8_t *sig,
115115
}
116116
// DIGEST sign mode
117117
else {
118+
if (message_len != pqdsa->digest_len) {
119+
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE);
120+
return 0;
121+
}
118122
if (!pqdsa->method->pqdsa_sign(key->private_key, sig, sig_len, message, message_len)) {
119123
OPENSSL_PUT_ERROR(EVP, ERR_R_INTERNAL_ERROR);
120124
return 0;
@@ -190,6 +194,10 @@ static int pkey_pqdsa_verify_generic(EVP_PKEY_CTX *ctx, const uint8_t *sig,
190194
}
191195
// DIGEST verify mode
192196
else {
197+
if (message_len != pqdsa->digest_len) {
198+
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_BUFFER_SIZE);
199+
return 0;
200+
}
193201
if (sig_len != pqdsa->signature_len ||
194202
!pqdsa->method->pqdsa_verify(key->public_key, sig, sig_len, message, message_len)) {
195203
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_SIGNATURE);

0 commit comments

Comments
 (0)