Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHA3 and SHAKE - New API Design #2098

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c6ed451
Introduce SHA3/SHAKE layered API design; Only SHA3/SHAKE files updates
manastasova Dec 30, 2024
a05d255
Add changes to ML-KEM based on SHA3/SHAKE new API Design
manastasova Dec 30, 2024
50cf7fa
Add changes to ML-DSA based on SHA3/SHAKE new API Design
manastasova Dec 30, 2024
4b0b92e
Update build files in generated-src
manastasova Dec 30, 2024
eb992ea
Update service indicator in SHA3_Final
manastasova Dec 30, 2024
d40fbec
Initialize |ctx->padded| to 0 for SHAKE inside SHAKE_Init
manastasova Dec 31, 2024
adb910d
Update service indicator at the end of SHAKE_Finalize; The XOF functi…
manastasova Dec 31, 2024
02b8085
Fix conflicts with MLDSA parameters renaming
manastasova Dec 31, 2024
e61be0d
Merge branch 'main' into sha3_absorb_squeeze
manastasova Dec 31, 2024
3008821
Merge branch 'aws:main' into sha3_absorb_squeeze
manastasova Jan 3, 2025
2a1622f
Update SHAKE single-shot and streaming APIs
manastasova Jan 3, 2025
c5d0afd
Update incremental block-wise SHAKE squeezes in MLKEM
manastasova Jan 3, 2025
b6a5590
Update incremental block-wise SHAKE squeezes in MLDSA
manastasova Jan 3, 2025
7ccaeba
Replace |keccak_st->padded| flag with |keccak_st->state| flag
manastasova Jan 3, 2025
7edb6c7
Update MLKEM and MLDSA
manastasova Jan 3, 2025
7386c1b
Update Keccak state flag in SHA3 functions
manastasova Jan 3, 2025
e424771
Address code review comments
manastasova Jan 4, 2025
6597af1
Add export macro to functions in the tests
manastasova Jan 4, 2025
7766425
Merge branch 'aws:main' into sha3_absorb_squeeze
manastasova Jan 6, 2025
ff3cbd8
Rename Absorb and Squeeze functions to Keccak1600_ layer specific
manastasova Jan 6, 2025
680dd43
Update build files in generated-src
manastasova Jan 6, 2025
872d368
Apply suggestions from code review
manastasova Jan 7, 2025
5780ee5
Move all common |ctx->state| flag checks in the FIPS202 layer
manastasova Jan 7, 2025
3f43dde
Merge branch 'sha3_absorb_squeeze' of github.com:manastasova/aws-lc i…
manastasova Jan 7, 2025
07bac7c
Update MLKEM and MLDSA
manastasova Jan 7, 2025
2973e4a
Merge branch 'main' of github.com:aws/aws-lc into sha3_absorb_squeeze
manastasova Jan 7, 2025
86fa4b0
Remove SHAKE_Squeeze service indicator update
manastasova Jan 8, 2025
36ab448
Merge branch 'main' of github.com:aws/aws-lc into sha3_absorb_squeeze
manastasova Jan 8, 2025
b2228b6
Bring back exports
manastasova Jan 8, 2025
14da500
Merge branch 'main' of github.com:aws/aws-lc into sha3_only_rename
manastasova Jan 8, 2025
97b02c6
Only add shanges to Init functions
manastasova Jan 8, 2025
95c7e26
add new line at the end of file
manastasova Jan 8, 2025
077ef78
Merge branch 'main' into sha3_absorb_squeeze
manastasova Jan 8, 2025
b4ce7b2
Merge branch 'main' into sha3_only_rename
manastasova Jan 9, 2025
5b18483
Merge branch 'main' into sha3_only_rename
manastasova Jan 13, 2025
d3bba6b
Merge branch 'main' into sha3_only_rename
manastasova Jan 13, 2025
f48fb78
merge with aws-lc main and sha3/shake_only_Init PR changes
manastasova Jan 13, 2025
6ce3a3b
Allow TLS PSK without server certificate (#2083)
WillChilds-Klein Jan 14, 2025
72373f3
Align guard macros for OPENSSL_cpuid_setup (#2111)
justsmth Jan 14, 2025
820394a
Init variable to avoid "may be used uninitialized" warning (#2114)
manastasova Jan 15, 2025
26544da
SCRUTINICE fixes (#2103)
smittals2 Jan 15, 2025
0239af3
Remove jent_read_entropy_safe usage from AWS-LC (main) (#2110)
smittals2 Jan 15, 2025
2ddcd83
CDK: Add scrutinice permissions (#2118)
justsmth Jan 15, 2025
94bc599
Address Scrutinice findings (#2121)
justsmth Jan 15, 2025
6933d45
Finalize ML-DSA asn.1 module (#2117)
jakemas Jan 16, 2025
9462df8
Align BN_bn2hex behavior with OpenSSL (#2122)
samuel40791765 Jan 16, 2025
9d433cb
Start making asserts constant-time too
davidben Jan 16, 2024
705f36c
Fix EVP_PKEY_CTX_dup with EC generation
davidben Mar 17, 2024
a03e160
Remove unused flags argument from trust handlers
botovq Mar 21, 2024
507ff49
Document that null STACK_OF(T) can be used with several functions
davidben Mar 22, 2024
863387d
Upstream rebase
manastasova Jan 30, 2025
5a4dc9c
Add a PrivacyInfo plist file
Mar 26, 2024
ebfb590
Switch EVP_CIPHERs to C99 initializers
davidben Mar 29, 2024
b80f99e
Document that our Unicode APIs reject noncharacters
davidben Mar 29, 2024
3001ac9
Rewrite RAND_enable_fork_unsafe_buffering documentation
davidben Mar 29, 2024
8d6b7f5
Disable `-Wcast-function-type-strict` for `BORINGSSL_DEFINE_STACK_OF_…
brianpl Apr 2, 2024
64f25eb
Increase DTLS window size from 64 to 256
nharper Mar 28, 2024
80260d9
Avoid strdup in crypto/err/err.c
davidben Nov 20, 2023
2d90347
Add more debug logging to channelID test failures (#2130)
andrewhop Jan 21, 2025
55742fa
Compress crypto_test_data.cc (#2123)
justsmth Jan 21, 2025
c91bd6a
Prepare AWS-LC v1.43.0 (#2133)
justsmth Jan 22, 2025
a66a1a5
Minor symbols to work with Ruby's mainline (#2132)
samuel40791765 Jan 22, 2025
7fb93e8
ACVP test harness for ML-DSA (#2127)
jakemas Jan 24, 2025
95a9e8a
Remove remaining support for Trusty and Fuchsia operating systems (#2…
torben-hansen Jan 24, 2025
0b9ef21
Avoid mixing SSE and AVX in XTS-mode AVX512 implementation (#2140)
torben-hansen Jan 27, 2025
df51857
Support for ML-DSA public key generation from private key (#2142)
jakemas Jan 28, 2025
9d3b72b
Ed25519ph and Ed25519ctx Support (#2120)
skmcgrail Jan 28, 2025
3b18668
Check for MIPSEB in target.h (#2143)
justsmth Jan 28, 2025
3cdcaa3
Optimize x86/aarch64 MD5 implementation (#2137)
olivergillespie Jan 28, 2025
cb6f877
Support keypair calculation for PQDSA PKEY (#2145)
jakemas Jan 29, 2025
96f8169
Upstream merge
manastasova Jan 30, 2025
7848023
fix
manastasova Jan 30, 2025
1fdb30e
Update comments and exports
manastasova Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crypto/fipsmodule/digest/digests.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512_256) {


static void sha3_224_init(EVP_MD_CTX *ctx) {
CHECK(SHA3_Init(ctx->md_data, SHA3_PAD_CHAR, SHA3_224_DIGEST_BITLENGTH));
CHECK(SHA3_Init(ctx->md_data, SHA3_224_DIGEST_BITLENGTH));
}

static void sha3_224_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
Expand All @@ -351,7 +351,7 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha3_224) {


static void sha3_256_init(EVP_MD_CTX *ctx) {
CHECK(SHA3_Init(ctx->md_data, SHA3_PAD_CHAR, SHA3_256_DIGEST_BITLENGTH));
CHECK(SHA3_Init(ctx->md_data, SHA3_256_DIGEST_BITLENGTH));
}

static void sha3_256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
Expand All @@ -376,7 +376,7 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha3_256) {


static void sha3_384_init(EVP_MD_CTX *ctx) {
CHECK(SHA3_Init(ctx->md_data, SHA3_PAD_CHAR, SHA3_384_DIGEST_BITLENGTH));
CHECK(SHA3_Init(ctx->md_data, SHA3_384_DIGEST_BITLENGTH));
}

static void sha3_384_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
Expand All @@ -401,7 +401,7 @@ DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha3_384) {


static void sha3_512_init(EVP_MD_CTX *ctx) {
CHECK(SHA3_Init(ctx->md_data, SHA3_PAD_CHAR, SHA3_512_DIGEST_BITLENGTH));
CHECK(SHA3_Init(ctx->md_data, SHA3_512_DIGEST_BITLENGTH));
}

static void sha3_512_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
Expand Down Expand Up @@ -430,7 +430,7 @@ static void shake128_init(EVP_MD_CTX *ctx) {
}

static void shake128_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
CHECK(SHA3_Update(ctx->md_data, data, count));
CHECK(SHAKE_Absorb(ctx->md_data, data, count));
}

static void shake128_final(EVP_MD_CTX *ctx, uint8_t *md, size_t len) {
Expand All @@ -455,7 +455,7 @@ static void shake256_init(EVP_MD_CTX *ctx) {
}

static void shake256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
CHECK(SHA3_Update(ctx->md_data, data, count));
CHECK(SHAKE_Absorb(ctx->md_data, data, count));
}

static void shake256_finalXOF(EVP_MD_CTX *ctx, uint8_t *md, size_t len) {
Expand Down
28 changes: 14 additions & 14 deletions crypto/fipsmodule/ml_dsa/ml_dsa_ref/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ void ml_dsa_poly_uniform(ml_dsa_poly *a,
t[1] = nonce >> 8;

SHAKE_Init(&state, SHAKE128_BLOCKSIZE);
SHA3_Update(&state, seed, ML_DSA_SEEDBYTES);
SHA3_Update(&state, t, 2);
SHAKE_Final(buf, &state, POLY_UNIFORM_NBLOCKS * SHAKE128_BLOCKSIZE);
SHAKE_Absorb(&state, seed, ML_DSA_SEEDBYTES);
SHAKE_Absorb(&state, t, 2);
SHAKE_Squeeze(buf, &state, POLY_UNIFORM_NBLOCKS * SHAKE128_BLOCKSIZE);

ctr = ml_dsa_rej_uniform(a->coeffs, ML_DSA_N, buf, buflen);

Expand All @@ -327,7 +327,7 @@ void ml_dsa_poly_uniform(ml_dsa_poly *a,
for(i = 0; i < off; ++i)
buf[i] = buf[buflen - off + i];

SHAKE_Final(buf + off, &state, POLY_UNIFORM_NBLOCKS * SHAKE128_BLOCKSIZE);
SHAKE_Squeeze(buf + off, &state, POLY_UNIFORM_NBLOCKS * SHAKE128_BLOCKSIZE);
buflen = SHAKE128_BLOCKSIZE + off;
ctr += ml_dsa_rej_uniform(a->coeffs + ctr, ML_DSA_N - ctr, buf, buflen);
}
Expand Down Expand Up @@ -418,16 +418,17 @@ void ml_dsa_poly_uniform_eta(ml_dsa_params *params,
t[1] = nonce >> 8;

SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, seed, ML_DSA_CRHBYTES);
SHA3_Update(&state, t, 2);
SHAKE_Final(buf, &state, ML_DSA_POLY_UNIFORM_ETA_NBLOCKS_MAX * SHAKE256_BLOCKSIZE);
SHAKE_Absorb(&state, seed, ML_DSA_CRHBYTES);
SHAKE_Absorb(&state, t, 2);
SHAKE_Squeeze(buf, &state, ML_DSA_POLY_UNIFORM_ETA_NBLOCKS_MAX * SHAKE256_BLOCKSIZE);

ctr = rej_eta(params, a->coeffs, ML_DSA_N, buf, buflen);

while(ctr < ML_DSA_N) {
SHAKE_Final(buf, &state, SHAKE256_BLOCKSIZE);
SHAKE_Squeeze(buf, &state, SHAKE256_BLOCKSIZE);
ctr += rej_eta(params, a->coeffs + ctr, ML_DSA_N - ctr, buf, SHAKE256_BLOCKSIZE);
}

/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
OPENSSL_cleanse(buf, sizeof(buf));
OPENSSL_cleanse(&state, sizeof(state));
Expand Down Expand Up @@ -459,9 +460,8 @@ void ml_dsa_poly_uniform_gamma1(ml_dsa_params *params,
t[1] = nonce >> 8;

SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, seed, ML_DSA_CRHBYTES);
SHA3_Update(&state, t, 2);

SHAKE_Absorb(&state, seed, ML_DSA_CRHBYTES);
SHAKE_Absorb(&state, t, 2);
SHAKE_Final(buf, &state, POLY_UNIFORM_GAMMA1_NBLOCKS * SHAKE256_BLOCKSIZE);
ml_dsa_polyz_unpack(params, a, buf);
/* FIPS 204. Section 3.6.3 Destruction of intermediate values. */
Expand All @@ -487,8 +487,8 @@ void ml_dsa_poly_challenge(ml_dsa_params *params, ml_dsa_poly *c, const uint8_t
KECCAK1600_CTX state;

SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, seed, params->c_tilde_bytes);
SHAKE_Final(buf, &state, SHAKE256_BLOCKSIZE);
SHAKE_Absorb(&state, seed, params->c_tilde_bytes);
SHAKE_Squeeze(buf, &state, SHAKE256_BLOCKSIZE);

signs = 0;
for(i = 0; i < 8; ++i) {
Expand All @@ -502,7 +502,7 @@ void ml_dsa_poly_challenge(ml_dsa_params *params, ml_dsa_poly *c, const uint8_t
for(i = ML_DSA_N-params->tau; i < ML_DSA_N; ++i) {
do {
if(pos >= SHAKE256_BLOCKSIZE) {
SHAKE_Final(buf, &state, SHAKE256_BLOCKSIZE);
SHAKE_Squeeze(buf, &state, SHAKE256_BLOCKSIZE);
pos = 0;
}

Expand Down
27 changes: 14 additions & 13 deletions crypto/fipsmodule/ml_dsa/ml_dsa_ref/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ int ml_dsa_sign_internal(ml_dsa_params *params,
// processing of M' in the external function. However, as M' = (pre, msg),
// mu = CRH(tr, M') = CRH(tr, pre, msg).
SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, tr, ML_DSA_TRBYTES);
SHA3_Update(&state, pre, prelen);
SHA3_Update(&state, m, mlen);
SHAKE_Absorb(&state, tr, ML_DSA_TRBYTES);
SHAKE_Absorb(&state, pre, prelen);
SHAKE_Absorb(&state, m, mlen);
SHAKE_Final(mu, &state, ML_DSA_CRHBYTES);

/* FIPS 204: line 7 Compute rhoprime = CRH(key, rnd, mu) */
SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, key, ML_DSA_SEEDBYTES);
SHA3_Update(&state, rnd, ML_DSA_RNDBYTES);
SHA3_Update(&state, mu, ML_DSA_CRHBYTES);
SHAKE_Absorb(&state, key, ML_DSA_SEEDBYTES);
SHAKE_Absorb(&state, rnd, ML_DSA_RNDBYTES);
SHAKE_Absorb(&state, mu, ML_DSA_CRHBYTES);
SHAKE_Final(rhoprime, &state, ML_DSA_CRHBYTES);

/* FIPS 204: line 5 Expand matrix and transform vectors */
Expand All @@ -191,8 +191,8 @@ int ml_dsa_sign_internal(ml_dsa_params *params,
ml_dsa_polyveck_pack_w1(params, sig, &w1);

SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, mu, ML_DSA_CRHBYTES);
SHA3_Update(&state, sig, params->k * params->poly_w1_packed_bytes);
SHAKE_Absorb(&state, mu, ML_DSA_CRHBYTES);
SHAKE_Absorb(&state, sig, params->k * params->poly_w1_packed_bytes);
SHAKE_Final(sig, &state, params->c_tilde_bytes);
ml_dsa_poly_challenge(params, &cp, sig);
ml_dsa_poly_ntt(&cp);
Expand Down Expand Up @@ -395,9 +395,9 @@ int ml_dsa_verify_internal(ml_dsa_params *params,
// Like crypto_sign_signature_internal, the processing of M' is performed
// here, as opposed to within the external function.
SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, tr, ML_DSA_TRBYTES);
SHA3_Update(&state, pre, prelen);
SHA3_Update(&state, m, mlen);
SHAKE_Absorb(&state, tr, ML_DSA_TRBYTES);
SHAKE_Absorb(&state, pre, prelen);
SHAKE_Absorb(&state, m, mlen);
SHAKE_Final(mu, &state, ML_DSA_CRHBYTES);

/* FIPS 204: line 9 Matrix-vector multiplication; compute Az - c2^dt1 */
Expand All @@ -423,9 +423,10 @@ int ml_dsa_verify_internal(ml_dsa_params *params,

/* FIPS 204: line 12 Call random oracle and verify challenge */
SHAKE_Init(&state, SHAKE256_BLOCKSIZE);
SHA3_Update(&state, mu, ML_DSA_CRHBYTES);
SHA3_Update(&state, buf, params->k * params->poly_w1_packed_bytes);
SHAKE_Absorb(&state, mu, ML_DSA_CRHBYTES);
SHAKE_Absorb(&state, buf, params->k * params->poly_w1_packed_bytes);
SHAKE_Final(c2, &state, params->c_tilde_bytes);

for(i = 0; i < params->c_tilde_bytes; ++i) {
if(c[i] != c2[i]) {
return -1;
Expand Down
18 changes: 9 additions & 9 deletions crypto/fipsmodule/ml_kem/ml_kem_ref/symmetric-shake.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void kyber_shake128_absorb(KECCAK1600_CTX *ctx,
// SHAKE_Init always returns 1 when called with correct block size value
SHAKE_Init(ctx, SHAKE128_BLOCKSIZE);

// SHA3_Update always returns 1 on first call of sizeof(extseed) (34 bytes)
SHA3_Update(ctx, extseed, sizeof(extseed));
// SHAKE_Absorb always returns 1 on first call of sizeof(extseed) (34 bytes)
SHAKE_Absorb(ctx, extseed, sizeof(extseed));
}

/*************************************************
Expand All @@ -48,8 +48,8 @@ void kyber_shake128_absorb(KECCAK1600_CTX *ctx,
void kyber_shake128_squeeze(KECCAK1600_CTX *ctx, uint8_t *out, int nblocks)
{
// Return code checks can be omitted
// SHAKE_Final always returns 1
SHAKE_Final(out, ctx, nblocks * SHAKE128_BLOCKSIZE);
// SHAKE_Squeeze always returns 1 when |ctx->padded| flag is cleared
SHAKE_Squeeze(out, ctx, nblocks * SHAKE128_BLOCKSIZE);
}

/*************************************************
Expand Down Expand Up @@ -94,12 +94,12 @@ void kyber_shake256_rkprf(ml_kem_params *params, uint8_t out[KYBER_SSBYTES], con
// SHAKE_Init always returns 1 when called with correct block size value
SHAKE_Init(&ctx, SHAKE256_BLOCKSIZE);

// SHA3_Update always returns 1 on first call of KYBER_SYMBYTES (32 bytes)
SHA3_Update(&ctx, key, KYBER_SYMBYTES);
// SHAKE_Absorb always returns 1 on first call of KYBER_SYMBYTES (32 bytes)
SHAKE_Absorb(&ctx, key, KYBER_SYMBYTES);

// SHA3_Update always returns 1 processing all data blocks that don't need pad
SHA3_Update(&ctx, input, params->ciphertext_bytes);
// SHAKE_Absorb always returns 1 processing all data blocks that don't need pad
SHAKE_Absorb(&ctx, input, params->ciphertext_bytes);

// SHAKE_Final always returns 1
// SHAKE_Squeeze always returns 1 when |ctx->padded| flag is cleared (no previous calls to SHAKE_Squeeze)
SHAKE_Final(out, &ctx, KYBER_SSBYTES);
}
53 changes: 34 additions & 19 deletions crypto/fipsmodule/sha/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ extern "C" {
// SHAKE128 has the maximum block size among the SHA3/SHAKE algorithms.
#define SHA3_MAX_BLOCKSIZE SHAKE128_BLOCKSIZE

// Define state flag values for Keccak-based functions
#define KECCAK1600_STATE_ABSORB 0
#define KECCAK1600_STATE_SQUEEZE 1
// KECCAK1600_STATE_FINAL restricts the incremental calls to SHAKE_Final .
// KECCAK1600_STATE_FINAL can be called once. SHAKE_Squeeze cannot be called after SHAKE_Final.
// SHAKE_Squeeze should be called for streaming XOF output.
#define KECCAK1600_STATE_FINAL 2

typedef struct keccak_st KECCAK1600_CTX;

// The data buffer should have at least the maximum number of
Expand All @@ -82,7 +90,7 @@ struct keccak_st {
size_t buf_load; // used bytes in below buffer
uint8_t buf[SHA3_MAX_BLOCKSIZE]; // should have at least the max data block size bytes
uint8_t pad; // padding character
uint8_t padded; // denotes if padding has been performed
uint8_t state; // denotes the keccak phase (absorb, squeeze, final)
};

// Define SHA{n}[_{variant}]_ASM if sha{n}_block_data_order[_{variant}] is
Expand Down Expand Up @@ -396,32 +404,39 @@ OPENSSL_EXPORT uint8_t *SHAKE128(const uint8_t *data, const size_t in_len,
OPENSSL_EXPORT uint8_t *SHAKE256(const uint8_t *data, const size_t in_len,
uint8_t *out, size_t out_len);

// SHAKE_Init initializes |ctx| with specified |block_size|, returns 1 on
// success and 0 on failure. Calls SHA3_Init under the hood.
int SHAKE_Init(KECCAK1600_CTX *ctx, size_t block_size);
// SHA3_Init initialises |ctx| fields and returns 1 on success and 0 on failure.
OPENSSL_EXPORT int SHA3_Init(KECCAK1600_CTX *ctx, size_t bitlen);

// SHAKE_Final writes |len| bytes of finalized digest to |md|, returns 1 on
// success and 0 on failure. Calls SHA3_Final under the hood.
int SHAKE_Final(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);
// SHA3_Update check |ctx| pointer and |len| value and calls FIPS202_Update.
int SHA3_Update(KECCAK1600_CTX *ctx, const void *data,
size_t len);

// SHA3_Reset zeros the bitstate and the amount of processed input.
void SHA3_Reset(KECCAK1600_CTX *ctx);
// SHA3_Final pads the last data block and processes it through Keccak1600_Absorb.
// It writes |md_digest| bytes of finalized digest to |md|, returns 1 on
// success and 0 on failure.
OPENSSL_EXPORT int SHA3_Final(uint8_t *md, KECCAK1600_CTX *ctx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're removing a parameter from the public API. Will there be any impact for downstream users?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function is currently public. To verify, I checked our Rust bindings to see whether it was listed. I don't see it here: https://docs.rs/aws-lc-sys/latest/aws_lc_sys/#functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, only the functions defined in the include/openssl are consider external APIs.
These APIs should be internal, however, they are exported so that they can be used in our tests. However, I am not sure if there may be some customers that use these internal APIs as well.


// SHA3_Init initialises |ctx| fields and returns 1 on success and 0 on failure.
OPENSSL_EXPORT int SHA3_Init(KECCAK1600_CTX *ctx, uint8_t pad, size_t bitlen);
// SHAKE_Init initializes |ctx| with specified |block_size|, returns 1 on
// success and 0 on failure. Calls SHA3_Init under the hood.
OPENSSL_EXPORT int SHAKE_Init(KECCAK1600_CTX *ctx, size_t block_size);

// SHAKE_Absorb checks |ctx| pointer and |len| values and calls FIPS202_Update.
OPENSSL_EXPORT int SHAKE_Absorb(KECCAK1600_CTX *ctx, const void *data,
size_t len);

// SHA3_Update processes all data blocks that don't need pad through
// |Keccak1600_Absorb| and returns 1 and 0 on failure.
int SHA3_Update(KECCAK1600_CTX *ctx, const void *data, size_t len);
// SHAKE_Final writes |len| bytes of finalized extendible output to |md|, returns 1 on
// success and 0 on failure. It should be called once to finalize absorb and
// initiate squeeze phase. Incremental XOF output should be generated via SHAKE_Squeeze.
OPENSSL_EXPORT int SHAKE_Final(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);

// SHA3_Final pads the last data block and processes it through |Keccak1600_Absorb|.
// It processes the data through |Keccak1600_Squeeze| and returns 1 and 0 on failure.
int SHA3_Final(uint8_t *md, KECCAK1600_CTX *ctx);
// SHAKE_Squeeze writes |len| bytes of incremental XOF output to |md|, returns 1 on
// success and 0 on failure. It can be called multiple times.
OPENSSL_EXPORT int SHAKE_Squeeze(uint8_t *md, KECCAK1600_CTX *ctx, size_t len);

// Keccak1600_Absorb processes the largest multiple of |r| out of |len| bytes and
// returns the remaining number of bytes.
size_t Keccak1600_Absorb(uint64_t A[KECCAK1600_ROWS][KECCAK1600_ROWS],
const uint8_t *data, size_t len, size_t r);
OPENSSL_EXPORT size_t Keccak1600_Absorb(uint64_t A[KECCAK1600_ROWS][KECCAK1600_ROWS],
const uint8_t *data, size_t len, size_t r);

// Keccak1600_Squeeze generates |out| value of |len| bytes (per call). It can be called
// multiple times when used as eXtendable Output Function. |padded| indicates
Expand Down
Loading
Loading