@@ -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.
441441OPENSSL_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.
459484OPENSSL_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.
465490int 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.
470496int 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);
510536int 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.
528554int 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.
534560int 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.
542568int 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);
548574int 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