ggm.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #![allow(non_snake_case)]
  2. use curve25519_dalek::ristretto::RistrettoPoint;
  3. use curve25519_dalek::scalar::Scalar;
  4. use cmz::ggm::*;
  5. #[test]
  6. fn create_issuer() {
  7. let i0 = Issuer::new(0);
  8. println!("i0 = {:?}", i0);
  9. let i1 = Issuer::new(1);
  10. println!("i1 = {:?}", i1);
  11. let i5 = Issuer::new(5);
  12. println!("i5 = {:?}", i5);
  13. }
  14. #[test]
  15. fn generator_test() {
  16. use hex_fmt::HexFmt;
  17. let A : &RistrettoPoint = &CMZ_A;
  18. let B : &RistrettoPoint = &CMZ_B;
  19. let two = Scalar::one() + Scalar::one();
  20. println!("A = {}", HexFmt(A.compress().to_bytes()));
  21. println!("B = {}", HexFmt(B.compress().to_bytes()));
  22. println!("2*A = {}", HexFmt((two*A).compress().to_bytes()));
  23. println!("2*A = {}", HexFmt((A+A).compress().to_bytes()));
  24. println!("2*B = {}", HexFmt((two*B).compress().to_bytes()));
  25. println!("2*B = {}", HexFmt((B+B).compress().to_bytes()));
  26. }
  27. #[test]
  28. fn nonblind_5_test() {
  29. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  30. let issuer = Issuer::new(5);
  31. let m1 = Scalar::random(&mut rng);
  32. let m2 = Scalar::random(&mut rng);
  33. let m3 = Scalar::random(&mut rng);
  34. let m4 = Scalar::random(&mut rng);
  35. let m5 = Scalar::random(&mut rng);
  36. let (req,state) = issue_nonblind_5::request(&m1, &m2, &m3, &m4, &m5);
  37. let resp = issuer.issue_nonblind_5(&req);
  38. let result = issue_nonblind_5::verify(state, resp, &issuer.pubkey);
  39. assert!(result.is_ok());
  40. }
  41. #[test]
  42. fn blind124_5_test() {
  43. let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
  44. let issuer = Issuer::new(5);
  45. let m1 = Scalar::random(&mut rng);
  46. let m2 = Scalar::random(&mut rng);
  47. let m3 = Scalar::random(&mut rng);
  48. let m4 = Scalar::random(&mut rng);
  49. let m5 = Scalar::random(&mut rng);
  50. let (req,state) = issue_blind124_5::request(&m1, &m2, &m3, &m4, &m5);
  51. let resp = issuer.issue_blind124_5(&req);
  52. assert!(resp.is_ok());
  53. let result = issue_blind124_5::verify(state, resp.unwrap(), &issuer.pubkey);
  54. assert!(result.is_ok());
  55. }