Make oprf::generate_oprf1 generic in the Digest, as long as it matches the hash-to-curve intake of the group

We used to have three problems:
- overuse of the <Sha256 as Digest>::OutputSize, which is just, well, U32. Sometimes used as a parameter (as in generate_oprf1), sometimes as a constant (as in generate_oprf3).
- the `hash_to_curve` operation for `RistrettoPoint` which requires 64 bits of input entropy, is fed 64 bits of which the last 32 are zero,
- the `hash_to_curve` operation for `Curve25519Point` which requires 32 bits of input entropy, is fed 64 bits of which the last 32 are discarded,

This corrects all three and uses U32 where the size of the digest is not meant to be a constraint.

Addresses #15 partially.
This commit is contained in:
François Garillot
2020-07-03 18:28:34 -04:00
parent 45ea7b6e84
commit 41cd80ccb5
12 changed files with 99 additions and 63 deletions
+4 -11
View File
@@ -7,33 +7,26 @@
use crate::errors::InternalPakeError;
use generic_array::GenericArray;
use sha2::{Digest, Sha256};
use generic_array::{typenum::U32, GenericArray};
/// Used for the slow hashing function in OPAQUE
pub trait SlowHash {
/// Computes the slow hashing function
fn hash(
input: GenericArray<u8, <Sha256 as Digest>::OutputSize>,
) -> Result<Vec<u8>, InternalPakeError>;
fn hash(input: GenericArray<u8, U32>) -> Result<Vec<u8>, InternalPakeError>;
}
/// A no-op hash which simply returns its input
pub struct NoOpHash;
impl SlowHash for NoOpHash {
fn hash(
input: GenericArray<u8, <Sha256 as Digest>::OutputSize>,
) -> Result<Vec<u8>, InternalPakeError> {
fn hash(input: GenericArray<u8, U32>) -> Result<Vec<u8>, InternalPakeError> {
Ok(input.to_vec())
}
}
#[cfg(feature = "slow-hash")]
impl SlowHash for scrypt::ScryptParams {
fn hash(
input: GenericArray<u8, <Sha256 as Digest>::OutputSize>,
) -> Result<Vec<u8>, InternalPakeError> {
fn hash(input: GenericArray<u8, U32>) -> Result<Vec<u8>, InternalPakeError> {
let params = scrypt::ScryptParams::new(15, 8, 1).unwrap();
let mut output = [0u8; 32];
scrypt::scrypt(&input, &[], &params, &mut output)