mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 06:23:08 -08:00
doc(ciphers + rosenpass): improve the documentation
This commit is contained in:
committed by
Jan Winkelmann (keks)
parent
62d408eade
commit
ebf6403ea7
@@ -14,7 +14,6 @@ impl<const KEY_LEN: usize, const HASH_LEN: usize> KeyedHash<KEY_LEN, HASH_LEN>
|
|||||||
{
|
{
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
/// TODO: Check comment
|
|
||||||
/// Provides a keyed hash function based on SHAKE256. To work for the protocol, the output length
|
/// Provides a keyed hash function based on SHAKE256. To work for the protocol, the output length
|
||||||
/// and key length are fixed to 32 bytes (also see [KEY_LEN] and [HASH_LEN]).
|
/// and key length are fixed to 32 bytes (also see [KEY_LEN] and [HASH_LEN]).
|
||||||
///
|
///
|
||||||
@@ -74,7 +73,12 @@ impl<const KEY_LEN: usize, const HASH_LEN: usize> Default for SHAKE256Core<KEY_L
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO use inferred hash somehow here
|
/// This type provides the same functionality as [SHAKE256Core], but bound to an instance.
|
||||||
|
/// In contrast to [SHAKE256Core], this allows for type interference and thus allows the user of the
|
||||||
|
/// type to omit explicit type parameters when instantiating the type or using it.
|
||||||
|
///
|
||||||
|
/// The instantiation is based on the [InferKeyedHash] trait.
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use rosenpass_ciphers::subtle::rust_crypto::keyed_shake256::{SHAKE256};
|
/// # use rosenpass_ciphers::subtle::rust_crypto::keyed_shake256::{SHAKE256};
|
||||||
/// use rosenpass_cipher_traits::primitives::KeyedHashInstance;
|
/// use rosenpass_cipher_traits::primitives::KeyedHashInstance;
|
||||||
@@ -84,7 +88,6 @@ impl<const KEY_LEN: usize, const HASH_LEN: usize> Default for SHAKE256Core<KEY_L
|
|||||||
/// let data: [u8; 32] = [255; 32]; // arbitrary data, could also be longer
|
/// let data: [u8; 32] = [255; 32]; // arbitrary data, could also be longer
|
||||||
/// // buffer for the hash output
|
/// // buffer for the hash output
|
||||||
/// let mut hash_data: [u8; 32] = [0u8; HASH_LEN];
|
/// let mut hash_data: [u8; 32] = [0u8; HASH_LEN];
|
||||||
/// // TODO: Note that we are using inferred hash here
|
|
||||||
/// assert!(SHAKE256::new().keyed_hash(&key, &data, &mut hash_data).is_ok(), "Hashing has to return OK result");
|
/// assert!(SHAKE256::new().keyed_hash(&key, &data, &mut hash_data).is_ok(), "Hashing has to return OK result");
|
||||||
/// # let expected_hash: &[u8] = &[174, 4, 47, 188, 1, 228, 179, 246, 67, 43, 255, 94, 155, 11, 187,
|
/// # let expected_hash: &[u8] = &[174, 4, 47, 188, 1, 228, 179, 246, 67, 43, 255, 94, 155, 11, 187,
|
||||||
/// 161, 38, 110, 217, 23, 4, 62, 172, 30, 218, 187, 249, 80, 171, 21, 145, 238];
|
/// 161, 38, 110, 217, 23, 4, 62, 172, 30, 218, 187, 249, 80, 171, 21, 145, 238];
|
||||||
@@ -93,7 +96,9 @@ impl<const KEY_LEN: usize, const HASH_LEN: usize> Default for SHAKE256Core<KEY_L
|
|||||||
pub type SHAKE256<const KEY_LEN: usize, const HASH_LEN: usize> =
|
pub type SHAKE256<const KEY_LEN: usize, const HASH_LEN: usize> =
|
||||||
InferKeyedHash<SHAKE256Core<KEY_LEN, HASH_LEN>, KEY_LEN, HASH_LEN>;
|
InferKeyedHash<SHAKE256Core<KEY_LEN, HASH_LEN>, KEY_LEN, HASH_LEN>;
|
||||||
|
|
||||||
/// TODO: Documentation and more interesting test
|
/// The SHAKE256_32 type is a specific instance of the [SHAKE256] type with the key length and hash
|
||||||
|
/// length fixed to 32 bytes.
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use rosenpass_ciphers::subtle::keyed_shake256::{SHAKE256_32};
|
/// # use rosenpass_ciphers::subtle::keyed_shake256::{SHAKE256_32};
|
||||||
/// use rosenpass_cipher_traits::primitives::KeyedHashInstance;
|
/// use rosenpass_cipher_traits::primitives::KeyedHashInstance;
|
||||||
|
|||||||
@@ -1433,9 +1433,8 @@ impl CryptoServer {
|
|||||||
(0..l).map(move |i| PeerPtr((i + n) % l))
|
(0..l).map(move |i| PeerPtr((i + n) % l))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a peer with an optional pre shared key (`psk`) and its public key (`pk`)
|
/// Add a peer with an optional pre shared key (`psk`), its public key (`pk`) and the peer's
|
||||||
///
|
/// protocol version (`protocol_version`).
|
||||||
/// TODO: Adapt documentation
|
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::ops::DerefMut;
|
/// use std::ops::DerefMut;
|
||||||
@@ -1453,7 +1452,7 @@ impl CryptoServer {
|
|||||||
/// StaticKem.keygen(sskt.secret_mut(), spkt.deref_mut())?;
|
/// StaticKem.keygen(sskt.secret_mut(), spkt.deref_mut())?;
|
||||||
///
|
///
|
||||||
/// let psk = SymKey::random();
|
/// let psk = SymKey::random();
|
||||||
///
|
/// // We use the latest protocol version for the example.
|
||||||
/// let peer = srv.add_peer(Some(psk), spkt.clone(), ProtocolVersion::V03)?;
|
/// let peer = srv.add_peer(Some(psk), spkt.clone(), ProtocolVersion::V03)?;
|
||||||
///
|
///
|
||||||
/// assert_eq!(peer.get(&srv).spkt, spkt);
|
/// assert_eq!(peer.get(&srv).spkt, spkt);
|
||||||
|
|||||||
Reference in New Issue
Block a user