mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-07 20:50:39 +00:00
Merge branch 'feature/streamable-hash-to-scalar' into develop
This commit is contained in:
commit
7cbb8dd94e
1 changed files with 12 additions and 0 deletions
|
|
@ -207,6 +207,8 @@ impl Scalar {
|
||||||
/// Takes a type parameter `D`, which is any `Digest` producing 64
|
/// Takes a type parameter `D`, which is any `Digest` producing 64
|
||||||
/// bytes (512 bits) of output.
|
/// bytes (512 bits) of output.
|
||||||
///
|
///
|
||||||
|
/// Convenience wrapper around `from_hash`.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
|
@ -227,6 +229,16 @@ impl Scalar {
|
||||||
where D: Digest<OutputSize=U64> + Default {
|
where D: Digest<OutputSize=U64> + Default {
|
||||||
let mut hash = D::default();
|
let mut hash = D::default();
|
||||||
hash.input(input);
|
hash.input(input);
|
||||||
|
Scalar::from_hash(hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Construct a scalar from an existing `Digest` instance.
|
||||||
|
///
|
||||||
|
/// Use this instead of `hash_from_bytes` if it is more convenient
|
||||||
|
/// to stream data into the `Digest` than to pass a single byte
|
||||||
|
/// slice.
|
||||||
|
pub fn from_hash<D>(hash: D) -> Scalar
|
||||||
|
where D: Digest<OutputSize=U64> + Default {
|
||||||
// XXX this seems clumsy
|
// XXX this seems clumsy
|
||||||
let mut output = [0u8;64];
|
let mut output = [0u8;64];
|
||||||
output.copy_from_slice(hash.result().as_slice());
|
output.copy_from_slice(hash.result().as_slice());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue