Skip to main content

kopis/
lib.rs

1#![no_std]
2#![forbid(unsafe_code)]
3#![warn(
4    clippy::unwrap_used,
5    missing_docs,
6    rust_2018_idioms,
7    unused_lifetimes,
8    unused_qualifications
9)]
10#![doc = include_str!("../README.md")]
11
12mod arithmetic;
13mod consts;
14mod impls;
15mod kem;
16mod pke;
17mod sample;
18mod ser;
19
20pub use impls::*;
21
22use turboshake::{
23    CTurboShake256,
24    digest::{ExtendableOutput, Update, XofReader},
25};
26
27/// Helper function that computes the 32-bytes digest of the concatenation of the given inputs
28/// using TurboSHAKE256 with the given domain separator `DS` Pass an empty slice for `input1` to
29/// hash a single input.
30// Note: we cannot take a `&[&[u8]]` because that's a nested borrow, which aeneas doesn't support
31// yet.
32pub(crate) fn turboshake256_hash<const DS: u8>(input0: &[u8], input1: &[u8]) -> [u8; 32] {
33    let mut hasher = CTurboShake256::<DS>::default();
34    hasher.update(input0);
35    hasher.update(input1);
36
37    let mut out = [0u8; 32];
38    let mut reader = hasher.finalize_xof();
39    reader.read(&mut out);
40
41    out
42}