| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //! Basepoint derivation is keyed by group type, so two groups can coexist.
- use cmz::{cmz_basepoints, cmz_generator_a, cmz_group_init};
- use curve25519_dalek::ristretto::RistrettoPoint;
- use group::{Group, GroupEncoding};
- const RISTRETTO_A_ENCODING: &[u8] = &[
- 0x8e, 0x65, 0xa3, 0x1d, 0xc2, 0x60, 0x08, 0xdf, 0xbc, 0xd9, 0xf6, 0xef, 0xbd, 0x57, 0xf7, 0xcb,
- 0xb2, 0xb3, 0x98, 0x72, 0xf6, 0xfd, 0x32, 0x73, 0x6a, 0x00, 0x7a, 0x08, 0xc2, 0x1e, 0x47, 0x18,
- ];
- const P256_A_ENCODING: &[u8] = &[
- 0x02, 0x73, 0xe5, 0x71, 0x95, 0x24, 0x34, 0xf0, 0xd5, 0xac, 0xaa, 0xe0, 0xfc, 0xe7, 0x35, 0x7c,
- 0x45, 0xb2, 0x73, 0xbd, 0x8e, 0x30, 0x4e, 0xe1, 0xac, 0xd9, 0xf2, 0x43, 0xf3, 0x0b, 0x96, 0x18,
- 0x9e,
- ];
- #[test]
- fn two_groups_coexist() {
- let ristretto_a = cmz_generator_a::<RistrettoPoint>();
- let p256_a = cmz_generator_a::<p256::ProjectivePoint>();
- assert_eq!(&ristretto_a.to_bytes()[..], RISTRETTO_A_ENCODING);
- assert_eq!(&p256_a.to_bytes()[..], P256_A_ENCODING);
- // Each group is initialized automatically and reads back its own
- // basepoints, not the other's.
- assert_eq!(cmz_basepoints::<RistrettoPoint>().A(), ristretto_a);
- assert_eq!(
- cmz_basepoints::<RistrettoPoint>().B(),
- RistrettoPoint::generator()
- );
- assert_eq!(cmz_basepoints::<p256::ProjectivePoint>().A(), p256_a);
- assert_eq!(
- cmz_basepoints::<p256::ProjectivePoint>().B(),
- p256::ProjectivePoint::generator()
- );
- // Re-initializing keeps the first value, per cmz_group_init's contract.
- cmz_group_init::<RistrettoPoint>(RistrettoPoint::generator());
- assert_eq!(cmz_basepoints::<RistrettoPoint>().A(), ristretto_a);
- }
|