miracl / core

MIRACL Core
Apache License 2.0
199 stars 68 forks source link

Rust xmd_expand: support long DSTs. #57

Closed blynn closed 2 years ago

blynn commented 2 years ago

I tested the change on a test case from the spec: https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-12.html:

    let dst = b"QUUX-V01-CS02-with-expander-SHA256-128-long-DST-1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
    let msg = b"";
    let mut okm: [u8;512]=[0;512];
    hmac::xmd_expand(hmac::MC_SHA2,32,&mut okm,32,dst,msg);
    println!("{:?}", &okm);

but I didn't include this code in the commit because I'm not sure where it goes.

mcarrickscott commented 2 years ago

Yes, I see the need for this. But small technical issue - the rust library avoids any use of the heap, so suggest

let mut w = vec![0;hlen];

changed to

let mut w: [u8; 64]=[0;64];

and in line 347 &w changed to &w[0..hlen]

mcarrickscott commented 2 years ago

I have implemented support for long DSTs across all languages. Thanks for pointing out this omission.