ecdh_omr/
lib.rs

1// SPDX-FileCopyrightText: 2024 eaon <eaon@posteo.net>
2// SPDX-License-Identifier: EUPL-1.2
3
4#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5#![allow(clippy::needless_doctest_main)]
6#![doc = include_str!("../README.md")]
7#![warn(missing_docs)]
8
9use aead::{Aead, KeyInit};
10use rand_core::CryptoRngCore;
11
12pub mod curves;
13
14mod blinding;
15pub use blinding::*;
16
17mod hint;
18pub use hint::*;
19
20mod hints;
21pub use hints::*;
22
23mod take_the;
24pub use take_the::*;
25
26mod error;
27pub use error::*;
28
29/// Generate legitimate looking instances of data structures without user input.
30pub trait Decoy {
31    /// Create a decoy instance from provided RNG.
32    fn random_decoy(csprng: &mut impl CryptoRngCore) -> Self;
33}
34
35// Turn a shared secret supplied in the form of bytes into a key usable by `aead` implementations
36pub(crate) fn cipher_from_shared_secret<A: Aead + KeyInit>(shared_secret: impl AsRef<[u8]>) -> A {
37    let mut key = aead::Key::<A>::default();
38    key.copy_from_slice(&shared_secret.as_ref()[..A::key_size()]);
39
40    A::new(&key)
41}