| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_KECCAK_INTERNAL_H |
| 16 | #define OPENSSL_HEADER_CRYPTO_FIPSMODULE_KECCAK_INTERNAL_H |
| 17 |
| 18 | #include <openssl/base.h> |
| 19 |
| 20 | #if defined(__cplusplus) |
| 21 | extern "C" { |
| 22 | #endif |
| 23 |
| 24 |
| 25 | enum boringssl_keccak_config_t { |
| 26 | boringssl_sha3_256, |
| 27 | boringssl_sha3_512, |
| 28 | boringssl_shake128, |
| 29 | boringssl_shake256, |
| 30 | }; |
| 31 |
| 32 | enum boringssl_keccak_phase_t { |
| 33 | boringssl_keccak_phase_absorb, |
| 34 | boringssl_keccak_phase_squeeze, |
| 35 | }; |
| 36 |
| 37 | struct BORINGSSL_keccak_st { |
| 38 | enum boringssl_keccak_config_t config; |
| 39 | enum boringssl_keccak_phase_t phase; |
| 40 | uint64_t state[25]; |
| 41 | size_t rate_bytes; |
| 42 | size_t absorb_offset; |
| 43 | size_t squeeze_offset; |
| 44 | }; |
| 45 |
| 46 | // BORINGSSL_keccak hashes |in_len| bytes from |in| and writes |out_len| bytes |
| 47 | // of output to |out|. If the |config| specifies a fixed-output function, like |
| 48 | // SHA3-256, then |out_len| must be the correct length for that function. |
| 49 | OPENSSL_EXPORT void BORINGSSL_keccak(uint8_t *out, size_t out_len, |
| 50 | const uint8_t *in, size_t in_len, |
| 51 | enum boringssl_keccak_config_t config); |
| 52 |
| 53 | // BORINGSSL_keccak_init prepares |ctx| for absorbing. The |config| must specify |
| 54 | // a SHAKE variant, otherwise callers should use |BORINGSSL_keccak|. |
| 55 | OPENSSL_EXPORT void BORINGSSL_keccak_init( |
| 56 | struct BORINGSSL_keccak_st *ctx, enum boringssl_keccak_config_t config); |
| 57 |
| 58 | // BORINGSSL_keccak_absorb absorbs |in_len| bytes from |in|. |
| 59 | OPENSSL_EXPORT void BORINGSSL_keccak_absorb(struct BORINGSSL_keccak_st *ctx, |
| 60 | const uint8_t *in, size_t in_len); |
| 61 |
| 62 | // BORINGSSL_keccak_squeeze writes |out_len| bytes to |out| from |ctx|. |
| 63 | OPENSSL_EXPORT void BORINGSSL_keccak_squeeze(struct BORINGSSL_keccak_st *ctx, |
| 64 | uint8_t *out, size_t out_len); |
| 65 |
| 66 | #if defined(__cplusplus) |
| 67 | } |
| 68 | #endif |
| 69 |
| 70 | #endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_KECCAK_INTERNAL_H |
| 71 |