Skip to content

Commit

Permalink
bindings/rust/src/lib.rs: add scalar inversion test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Oct 16, 2023
1 parent 1514337 commit 47bc240
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bindings/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,3 +2026,35 @@ mod fp12_test {
);
}
}

#[cfg(test)]
mod sk_test {
use super::*;
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;

#[test]
fn inverse() {
let mut bytes = [0u8; 64];
ChaCha20Rng::from_entropy().fill_bytes(bytes.as_mut());

let mut sk = blst_scalar::default();
let mut p1 = blst_p1::default();
let mut p2 = blst_p2::default();

unsafe {
blst_scalar_from_be_bytes(&mut sk, bytes.as_ptr(), bytes.len());

blst_p1_mult(&mut p1, blst_p1_generator(), sk.b.as_ptr(), 255);
blst_sk_inverse(&mut sk, &sk);
blst_p1_mult(&mut p1, &p1, sk.b.as_ptr(), 255);

blst_p2_mult(&mut p2, blst_p2_generator(), sk.b.as_ptr(), 255);
blst_sk_inverse(&mut sk, &sk);
blst_p2_mult(&mut p2, &p2, sk.b.as_ptr(), 255);
}

assert_eq!(p1, unsafe { *blst_p1_generator() });
assert_eq!(p2, unsafe { *blst_p2_generator() });
}
}

0 comments on commit 47bc240

Please sign in to comment.