two_groups.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //! Basepoint derivation is keyed by group type, so two groups can coexist.
  2. use cmz::{cmz_basepoints, cmz_generator_a, cmz_group_init};
  3. use curve25519_dalek::ristretto::RistrettoPoint;
  4. use group::{Group, GroupEncoding};
  5. const RISTRETTO_A_ENCODING: &[u8] = &[
  6. 0x8e, 0x65, 0xa3, 0x1d, 0xc2, 0x60, 0x08, 0xdf, 0xbc, 0xd9, 0xf6, 0xef, 0xbd, 0x57, 0xf7, 0xcb,
  7. 0xb2, 0xb3, 0x98, 0x72, 0xf6, 0xfd, 0x32, 0x73, 0x6a, 0x00, 0x7a, 0x08, 0xc2, 0x1e, 0x47, 0x18,
  8. ];
  9. const P256_A_ENCODING: &[u8] = &[
  10. 0x02, 0x73, 0xe5, 0x71, 0x95, 0x24, 0x34, 0xf0, 0xd5, 0xac, 0xaa, 0xe0, 0xfc, 0xe7, 0x35, 0x7c,
  11. 0x45, 0xb2, 0x73, 0xbd, 0x8e, 0x30, 0x4e, 0xe1, 0xac, 0xd9, 0xf2, 0x43, 0xf3, 0x0b, 0x96, 0x18,
  12. 0x9e,
  13. ];
  14. #[test]
  15. fn two_groups_coexist() {
  16. let ristretto_a = cmz_generator_a::<RistrettoPoint>();
  17. let p256_a = cmz_generator_a::<p256::ProjectivePoint>();
  18. assert_eq!(&ristretto_a.to_bytes()[..], RISTRETTO_A_ENCODING);
  19. assert_eq!(&p256_a.to_bytes()[..], P256_A_ENCODING);
  20. // Each group is initialized automatically and reads back its own
  21. // basepoints, not the other's.
  22. assert_eq!(cmz_basepoints::<RistrettoPoint>().A(), ristretto_a);
  23. assert_eq!(
  24. cmz_basepoints::<RistrettoPoint>().B(),
  25. RistrettoPoint::generator()
  26. );
  27. assert_eq!(cmz_basepoints::<p256::ProjectivePoint>().A(), p256_a);
  28. assert_eq!(
  29. cmz_basepoints::<p256::ProjectivePoint>().B(),
  30. p256::ProjectivePoint::generator()
  31. );
  32. // Re-initializing keeps the first value, per cmz_group_init's contract.
  33. cmz_group_init::<RistrettoPoint>(RistrettoPoint::generator());
  34. assert_eq!(cmz_basepoints::<RistrettoPoint>().A(), ristretto_a);
  35. }