Skip to content

Commit

Permalink
Fetch endianess from the codec
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 9, 2024
1 parent 3ea27aa commit 642a0a1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub trait Suite: Copy + Clone {
///
/// By default uses "try and increment" method described by RFC 9381.
fn data_to_point(data: &[u8]) -> Option<AffinePoint<Self>> {
utils::hash_to_curve_tai_rfc_9381::<Self>(data, false)
utils::hash_to_curve_tai_rfc_9381::<Self>(data)
}

/// Map the point to a hash value using `Self::Hasher`.
Expand Down
2 changes: 1 addition & 1 deletion src/suites/secp256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Suite for P256Sha256Tai {
}

fn data_to_point(data: &[u8]) -> Option<AffinePoint> {
utils::hash_to_curve_tai_rfc_9381::<Self>(data, true)
utils::hash_to_curve_tai_rfc_9381::<Self>(data)
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ pub fn hash_to_curve_tai_rfc_9381<S: Suite>(data: &[u8]) -> Option<AffinePoint<S
let ctr_pos = buf.len() - 2;

for ctr in 0..=255 {
// Modify the `ctr` value
buf[ctr_pos] = ctr;
let mut hash = hash::<S::Hasher>(&buf).to_vec();
if point_be_encoding {
if S::Codec::BIG_ENDIAN {
hash.reverse();
}
hash.push(0x00);
Expand Down Expand Up @@ -354,7 +353,7 @@ mod tests {

#[test]
fn hash_to_curve_tai_works() {
let pt = hash_to_curve_tai_rfc_9381::<TestSuite>(b"hello world", false).unwrap();
let pt = hash_to_curve_tai_rfc_9381::<TestSuite>(b"hello world").unwrap();
// Check that `pt` is in the prime subgroup
assert!(pt.is_on_curve());
assert!(pt.is_in_correct_subgroup_assuming_on_curve())
Expand Down

0 comments on commit 642a0a1

Please sign in to comment.