mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-04 20:03:40 +00:00
Remove decaf fuzzer and change scalar fuzzer.
* REMOVE fuzz/fuzz_targets/decaf.rs * RENAME fuzz/fuzz_targets/scalar_constructor_accepts_256bit_values.rs to fuzz/fuzz_targets/scalar_constructors_and_reduction.rs * CHANGE scalar_constructors_and_reduction fuzz target to test reduction after using the 255-bit constructor versus constructor mod order. * FIXES #91: https://github.com/isislovecruft/curve25519-dalek/issues/91
This commit is contained in:
parent
88200f9fc9
commit
313607f06a
3 changed files with 5 additions and 34 deletions
|
|
@ -23,10 +23,6 @@ git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
|
|||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "decaf"
|
||||
path = "fuzz_targets/decaf.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "scalar_constructor_accepts_256bit_values"
|
||||
path = "fuzz_targets/scalar_constructor_accepts_256bit_values.rs"
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
extern crate curve25519_dalek;
|
||||
|
||||
use curve25519_dalek::curve::ValidityCheck;
|
||||
use curve25519_dalek::decaf::DecafPoint;
|
||||
use curve25519_dalek::field::FieldElement;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() != 32 {
|
||||
return;
|
||||
}
|
||||
let mut field_bytes = [0u8; 32];
|
||||
for (by, data) in field_bytes.iter_mut().zip(data.iter()) {
|
||||
*by = *data;
|
||||
}
|
||||
let fe = FieldElement::from_bytes(&field_bytes);
|
||||
let p = DecafPoint::elligator_decaf_flavour(&fe);
|
||||
assert!(p.0.is_valid());
|
||||
p.compress();
|
||||
});
|
||||
|
|
@ -4,10 +4,10 @@ extern crate curve25519_dalek;
|
|||
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
|
||||
/// Check that the Scalar constructor accepts 256-bit input values and
|
||||
/// Check that the Scalar constructor accepts 255-bit input values and
|
||||
/// behaves correctly on them.
|
||||
///
|
||||
/// Specifically, we take 256-bit values `a` and `b` from the fuzzer
|
||||
/// Specifically, we take 255-bit values `a` and `b` from the fuzzer
|
||||
/// input data and check that `(a mod l) * (b mod l) == (a * b) mod l`.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() != 64 {
|
||||
|
|
@ -21,15 +21,11 @@ fuzz_target!(|data: &[u8]| {
|
|||
b_bytes.copy_from_slice(&data[32..64]);
|
||||
|
||||
// Compute c = a*b (mod l)
|
||||
let c1 = &Scalar(a_bytes) * &Scalar(b_bytes);
|
||||
let c1 = (&Scalar::from_bits(a_bytes) * &Scalar::from_bits(b_bytes)).reduce();
|
||||
|
||||
// Compute c = (a mod l) * (b mod l)
|
||||
let mut tmp = [0u8; 64];
|
||||
tmp[0..32].copy_from_slice(&a_bytes[..]);
|
||||
let a_mod_l = Scalar::reduce(&tmp);
|
||||
tmp[0..32].copy_from_slice(&b_bytes[..]);
|
||||
let b_mod_l = Scalar::reduce(&tmp);
|
||||
|
||||
let a_mod_l = Scalar::from_bytes_mod_order(a_bytes);
|
||||
let b_mod_l = Scalar::from_bytes_mod_order(b_bytes);
|
||||
let c2 = &a_mod_l * &b_mod_l;
|
||||
|
||||
assert_eq!(c1, c2);
|
||||
Loading…
Reference in a new issue