Skip to content

Commit 816690f

Browse files
authored
Merge branch 'main' into add-backport-tool-analysis
2 parents e009741 + 0a34e4b commit 816690f

21 files changed

Lines changed: 1636 additions & 43 deletions

File tree

.github/workflows/integrations.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ jobs:
8686
- name: Run socat integration test
8787
run: |
8888
./tests/ci/integration/run_socat_integration.sh
89+
memcached:
90+
if: github.repository_owner == 'aws'
91+
runs-on: ubuntu-latest
92+
steps:
93+
# libio-socket-ssl-perl is what lets the Perl test suite speak TLS to
94+
# memcached; t/ssl_ports.t needs its TLS 1.3 support and
95+
# t/ssl_session_resumption.t needs get_session_reused().
96+
- name: Install OS Dependencies
97+
run: |
98+
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
99+
sudo apt-get -y --no-install-recommends install \
100+
cmake gcc ninja-build golang make autoconf automake libtool pkg-config \
101+
libevent-dev libio-socket-ssl-perl
102+
- uses: actions/checkout@v7
103+
# Pinned to a memcached release for a stable required check. Omit the
104+
# argument to track the default branch instead.
105+
- name: Run memcached integration test
106+
run: |
107+
./tests/ci/integration/run_memcached_integration.sh '1.6.45'
89108
rust-openssl:
90109
if: github.repository_owner == 'aws'
91110
runs-on: ubuntu-latest

crypto/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ add_library(
429429
ex_data.c
430430
hpke/hpke.c
431431
hrss/hrss.c
432+
keccak/keccak.c
432433
lhash/lhash.c
433434
md4/md4.c
434435
mem.c
@@ -835,6 +836,7 @@ if(BUILD_TESTING)
835836
hmac_extra/hmac_test.cc
836837
hrss/hrss_test.cc
837838
impl_dispatch_test.cc
839+
keccak/keccak256_test.cc
838840
lhash/lhash_test.cc
839841
obj/obj_test.cc
840842
ocsp/ocsp_test.cc

crypto/digest_extra/digest_extra.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "../asn1/internal.h"
1616
#include "../internal.h"
1717
#include "../fipsmodule/digest/internal.h"
18+
#include "../fipsmodule/sha/internal.h"
19+
#include "../keccak/internal.h"
1820

1921

2022
struct nid_to_digest {
@@ -41,6 +43,11 @@ static const struct nid_to_digest nid_to_digest_mapping[] = {
4143
{NID_sha3_512, EVP_sha3_512, SN_sha3_512, LN_sha3_512},
4244
{NID_shake128, EVP_shake128, SN_shake128, LN_shake128},
4345
{NID_shake256, EVP_shake256, SN_shake256, LN_shake256},
46+
// Keccak-256 has no NID/OID (the Ethereum-style 0x01-padding variant is
47+
// not standardised), so its names are not in nid.h. Registered by name
48+
// only via string literals; "KECCAK-256" matches OpenSSL 3.2+'s provider
49+
// name for cross-library lookups, with a lowercase alias for convenience.
50+
{NID_undef, EVP_keccak256, "KECCAK-256", "keccak-256"},
4451
{NID_md5_sha1, EVP_md5_sha1, SN_md5_sha1, LN_md5_sha1},
4552
// As a remnant of signing |EVP_MD|s, OpenSSL returned the corresponding
4653
// hash function when given a signature OID. To avoid unintended lax parsing
@@ -262,6 +269,40 @@ static const EVP_MD evp_md_blake2b256 = {
262269

263270
const EVP_MD *EVP_blake2b256(void) { return &evp_md_blake2b256; }
264271

272+
// Keccak-256 (Ethereum-style, 0x01 padding). NOT FIPS-approved, no OID.
273+
static void keccak256_init(EVP_MD_CTX *ctx) {
274+
AWSLC_ASSERT(Keccak256_Init(ctx->md_data));
275+
}
276+
277+
static int keccak256_update(EVP_MD_CTX *ctx, const void *data, size_t len) {
278+
return Keccak256_Update(ctx->md_data, data, len);
279+
}
280+
281+
static void keccak256_final(EVP_MD_CTX *ctx, uint8_t *md) {
282+
AWSLC_ASSERT(Keccak256_Final(md, ctx->md_data));
283+
}
284+
285+
// |EVP_MD_FLAG_DIGALGID_ABSENT| matches OpenSSL 3.2+'s
286+
// |PROV_DIGEST_FLAG_ALGID_ABSENT| on KECCAK-{224,256,384,512}. With
287+
// |NID_undef| this is effectively unreachable in current AWS-LC code paths
288+
// (|EVP_marshal_digest_algorithm| rejects digests without a known OID before
289+
// inspecting flags), but we set it for parity with OpenSSL and to remain
290+
// correct if any downstream caller starts honouring the flag.
291+
static const EVP_MD evp_md_keccak256 = {
292+
NID_undef,
293+
KECCAK256_DIGEST_LENGTH,
294+
EVP_MD_FLAG_DIGALGID_ABSENT,
295+
keccak256_init,
296+
keccak256_update,
297+
keccak256_final,
298+
KECCAK256_CBLOCK,
299+
sizeof(KECCAK1600_CTX),
300+
/*finalXOF=*/ NULL,
301+
/*squeezeXOF=*/ NULL
302+
};
303+
304+
const EVP_MD *EVP_keccak256(void) { return &evp_md_keccak256; }
305+
265306
static void null_init(EVP_MD_CTX *ctx) {}
266307

267308
static int null_update(EVP_MD_CTX *ctx, const void *data, size_t count) { return 1;}

crypto/digest_extra/digest_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "../fipsmodule/md5/internal.h"
2828
#include "../fipsmodule/sha/internal.h"
29+
#include "../keccak/internal.h"
2930
#include "../internal.h"
3031
#include "../test/test_util.h"
3132

@@ -61,6 +62,7 @@ static const MD shake128 = { "shake128", &EVP_shake128, nullptr, &SHAKE128};
6162
static const MD shake256 = { "shake256", &EVP_shake256, nullptr, &SHAKE256};
6263
static const MD md5_sha1 = { "MD5-SHA1", &EVP_md5_sha1, nullptr, nullptr };
6364
static const MD blake2b256 = { "BLAKE2b-256", &EVP_blake2b256, nullptr, nullptr };
65+
static const MD keccak256 = { "KECCAK-256", &EVP_keccak256, &Keccak256, nullptr };
6466
static const MD md_null = { "NULL", &EVP_md_null, nullptr, nullptr };
6567

6668
struct DigestTestVector {
@@ -224,6 +226,16 @@ static const DigestTestVector kTestVectors[] = {
224226
{sha3_512, "\x0c\xe9\xf8\xc3\xa9\x90\xc2\x68\xf3\x4e\xfd\x9b\xef\xdb\x0f\x7c\x4e\xf8\x46\x6c\xfd\xb0\x11\x71\xf8\xde\x70\xdc\x5f\xef\xa9\x2a\xcb\xe9\x3d\x29\xe2\xac\x1a\x5c\x29\x79\x12\x9f\x1a\xb0\x8c\x0e\x77\xde\x79\x24\xdd\xf6\x8a\x20\x9c\xdf\xa0\xad\xc6\x2f\x85\xc1\x86\x37\xd9\xc6\xb3\x3f\x4f\xf8",
225227
1, "b018a20fcf831dde290e4fb18c56342efe138472cbe142da6b77eea4fce52588c04c808eb32912faa345245a850346faec46c3a16d39bd2e1ddb1816bc57d2da"},
226228

229+
// Keccak-256 tests (Ethereum-style, original 0x01 padding). Reproducible
230+
// by anyone using e.g. eth_utils.keccak() or pycryptodome with
231+
// digest_bits=256. NOT FIPS, no OID.
232+
{keccak256, "", 1,
233+
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"},
234+
{keccak256, "abc", 1,
235+
"4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45"},
236+
{keccak256, "The quick brown fox jumps over the lazy dog", 1,
237+
"4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15"},
238+
227239
// SHAKE128 XOF tests, from NIST.
228240
// http://csrc.nist.gov/groups/STM/cavp/secure-hashing.html
229241
// NOTE: the |repeat| field in this struct denotes output length for XOF digests.
@@ -392,6 +404,13 @@ TEST(DigestTest, Getters) {
392404
EXPECT_EQ(EVP_md4(), EVP_get_digestbyname("md4"));
393405
EXPECT_EQ(EVP_md4(), EVP_get_digestbyname("MD4"));
394406

407+
// Keccak-256 is registered by name only (no OID), matching OpenSSL 3.x's
408+
// "KECCAK-256" provider name. Lookup via either casing must work; lookup
409+
// by NID does not (the digest's type is NID_undef).
410+
EXPECT_EQ(EVP_keccak256(), EVP_get_digestbyname("KECCAK-256"));
411+
EXPECT_EQ(EVP_keccak256(), EVP_get_digestbyname("keccak-256"));
412+
EXPECT_EQ(NID_undef, EVP_MD_type(EVP_keccak256()));
413+
395414
EXPECT_EQ(EVP_sha512(), EVP_get_digestbynid(NID_sha512));
396415
EXPECT_EQ(nullptr, EVP_get_digestbynid(NID_sha512WithRSAEncryption));
397416
EXPECT_EQ(nullptr, EVP_get_digestbynid(NID_undef));

crypto/fipsmodule/sha/internal.h

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,33 @@ OPENSSL_EXPORT uint8_t *SHAKE128(const uint8_t *data, const size_t in_len,
440440
// to |out| and returns |out| on success and NULL on failure.
441441
OPENSSL_EXPORT uint8_t *SHAKE256(const uint8_t *data, const size_t in_len,
442442
uint8_t *out, size_t out_len);
443+
444+
// KeccakSponge APIs manage the internal input/output buffer on top of the
445+
// Keccak1600 API layer. They are the shared padding-and-buffering primitives
446+
// underneath the SHA3 and SHAKE APIs below. They are also reused, outside the
447+
// FIPS module, by the (non-FIPS) Keccak-256 implementation in
448+
// crypto/keccak/keccak.c, which sets up the context with the original Keccak
449+
// padding byte rather than a FIPS 202 one. |KeccakSponge_Init| deliberately
450+
// accepts only FIPS 202 padding characters and is therefore kept private to
451+
// this module.
452+
453+
// KeccakSponge_Reset zeroes the Keccak state and buffer of |ctx| and returns it
454+
// to the absorb phase.
455+
void KeccakSponge_Reset(KECCAK1600_CTX *ctx);
456+
457+
// KeccakSponge_Absorb absorbs |len| bytes from |data| into |ctx|, buffering any
458+
// trailing partial block. It returns 1 on success and 0 if |ctx| is no longer
459+
// in a phase that accepts input. |len| must be non-zero (checked by callers).
460+
int KeccakSponge_Absorb(KECCAK1600_CTX *ctx, const void *data, size_t len);
461+
462+
// KeccakSponge_AbsorbFinal applies the |ctx->pad| padding to the final block
463+
// and absorbs it. It must be called once to conclude the absorb phase, after
464+
// which the caller squeezes the digest via |Keccak1600_Squeeze|. It returns 1 on
465+
// success and 0 if |ctx| is no longer in a phase that accepts input.
466+
int KeccakSponge_AbsorbFinal(uint8_t *md, KECCAK1600_CTX *ctx);
467+
443468
/*
444-
* SHA3 APIs implement SHA3 functionalities on top of FIPS202 API layer
469+
* SHA3 APIs implement SHA3 functionalities on top of KeccakSponge API layer
445470
*
446471
* SHA3 context must go through the flow: (a) Init, (b) Update [multiple times],
447472
* (c) Final [one time].
@@ -452,19 +477,20 @@ OPENSSL_EXPORT uint8_t *SHAKE256(const uint8_t *data, const size_t in_len,
452477
* detailed above each SHA3_ function signature, is satisfied.
453478
*/
454479

455-
// SHA3_Init initialises |ctx| field through |FIPS202_Init| and
480+
// SHA3_Init initialises |ctx| field through |KeccakSponge_Init| and
456481
// returns 1 on success and 0 on failure. When call-discipline is
457482
// maintained and |bitlen| value corresponds to a SHA3 digest length
458483
// in bits, this function never fails.
459484
OPENSSL_EXPORT int SHA3_Init(KECCAK1600_CTX *ctx, size_t bitlen);
460485

461-
// SHA3_Update checks |ctx| pointer and |len| value, calls |FIPS202_Update|
486+
// SHA3_Update checks |ctx| pointer and |len| value, calls |KeccakSponge_Absorb|
462487
// and returns 1 on success and 0 on failure. When call-discipline is
463488
// maintained and |len| value corresponds to the input message length
464489
// (including zero), this function never fails.
465490
int SHA3_Update(KECCAK1600_CTX *ctx, const void *data, size_t len);
466491

467-
// SHA3_Final pads the last data block and absorbs it through |FIPS202_Finalize|.
492+
// SHA3_Final pads the last data block and absorbs it through
493+
// |KeccakSponge_AbsorbFinal|.
468494
// It then calls |Keccak1600_Squeeze| and returns 1 on success and 0 on failure.
469495
// When call-discipline is maintained, this function never fails.
470496
int SHA3_Final(uint8_t *md, KECCAK1600_CTX *ctx);
@@ -510,7 +536,7 @@ int SHA3_512_Update(KECCAK1600_CTX *sha, const void *data, size_t len);
510536
int SHA3_512_Final(uint8_t out[SHA3_512_DIGEST_LENGTH], KECCAK1600_CTX *sha);
511537

512538
/*
513-
* SHAKE APIs implement SHAKE functionalities on top of FIPS202 API layer
539+
* SHAKE APIs implement SHAKE functionalities on top of KeccakSponge API layer
514540
*
515541
* SHAKE context must go through the flow: (a) Init, (b) Absorb [multiple times],
516542
* (c) Final [one time] or Squeeze [multiple times]
@@ -521,24 +547,24 @@ int SHA3_512_Final(uint8_t out[SHA3_512_DIGEST_LENGTH], KECCAK1600_CTX *sha);
521547
* detailed above each SHAKE_ function signature, is satisfied.
522548
*/
523549

524-
// SHAKE_Init initialises |ctx| fields through |FIPS202_Init| and
550+
// SHAKE_Init initialises |ctx| fields through |KeccakSponge_Init| and
525551
// returns 1 on success and 0 on failure. When call-discipline is
526552
// maintained and |block_size| value corresponds to a SHAKE block size length
527553
// in bytes, this function never fails.
528554
int SHAKE_Init(KECCAK1600_CTX *ctx, size_t block_size);
529555

530556
// SHAKE_Absorb checks |ctx| pointer and |len| values. It updates and absorbs
531-
// input blocks via |FIPS202_Update|. When call-discipline is
557+
// input blocks via |KeccakSponge_Absorb|. When call-discipline is
532558
// maintained and |len| value corresponds to the input message length
533559
// (including zero), this function never fails.
534560
int SHAKE_Absorb(KECCAK1600_CTX *ctx, const void *data,
535561
size_t len);
536562

537563
// SHAKE_Squeeze pads the last data block and absorbs it through
538-
// |FIPS202_Finalize| on first call. It writes |len| bytes of incremental
539-
// XOF output to |md| and returns 1 on success and 0 on failure. It can be
540-
// called multiple times. When call-discipline is maintained, this function
541-
// never fails.
564+
// |KeccakSponge_AbsorbFinal| on first call. It writes |len| bytes of
565+
// incremental XOF output to |md| and returns 1 on success and 0 on failure. It
566+
// can be called multiple times. When call-discipline is maintained, this
567+
// function never fails.
542568
int SHAKE_Squeeze(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);
543569

544570
// SHAKE_Final writes |len| bytes of finalized extendible output to |md|, returns 1 on
@@ -548,7 +574,8 @@ int SHAKE_Squeeze(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);
548574
int SHAKE_Final(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);
549575

550576
/*
551-
* SHAKE128_x4_ batched APIs implement x4 SHAKE functionalities on top of FIPS202 API layer
577+
* SHAKE128_x4_ batched APIs implement x4 SHAKE functionalities on top of
578+
* KeccakSponge API layer
552579
*
553580
* SHAKE128_x4_ context must go through the flow: (a) Init_x4, (b) Absorb_once_x4 [one time;
554581
* maximum input length of |SHAKE128_BLOCKSIZE - 1|] (c) Squeezeblocks_x4 [multiple times]
@@ -581,7 +608,7 @@ OPENSSL_EXPORT int SHAKE128_Squeezeblocks_x4(uint8_t *md0, uint8_t *md1, uint8_t
581608
KECCAK1600_CTX_x4 *ctx, size_t blks);
582609
/*
583610
* SHAKE256_x4_ signle-shot batched API implements x4 SHAKE256 functionalities on top
584-
* of FIPS202 API layer
611+
* of KeccakSponge API layer
585612
*
586613
* SHAKE256_x4_ function never fails when the later call-discipline is adhered to:
587614
* (a) the pointers passed to the functions are valid.

0 commit comments

Comments
 (0)