Skip to content

Commit 68bea24

Browse files
committed
Move constants, add sources
1 parent f7814dd commit 68bea24

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

packages/crypto/src/bls12_318/constants.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
pub const BLS12_381_G1_POINT_LEN: usize = 48;
2+
pub const BLS12_381_G2_POINT_LEN: usize = 96;
3+
4+
pub const BLS12_381_G1_GENERATOR_COMPRESSED: [u8; BLS12_381_G1_POINT_LEN] = [
5+
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79,
6+
151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251,
7+
58, 240, 10, 219, 34, 198, 187,
8+
];
9+
pub const BLS12_381_G2_GENERATOR_COMPRESSED: [u8; BLS12_381_G2_POINT_LEN] = [
10+
147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208,
11+
153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229,
12+
172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81,
13+
198, 228, 122, 212, 250, 64, 59, 2, 180, 81, 11, 100, 122, 227, 209, 119, 11, 172, 3, 38, 168,
14+
5, 187, 239, 212, 128, 86, 200, 193, 33, 189, 184,
15+
];
16+
117
#[cfg(test)]
218
mod test {
319
use ark_bls12_381::{G1Affine, G2Affine};
420
use ark_ec::AffineRepr;
521
use ark_serialize::CanonicalSerialize;
622
use hex_literal::hex;
723

8-
use crate::{
9-
bls12_318::{BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_GENERATOR_COMPRESSED},
10-
BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN,
11-
};
24+
use super::{BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_GENERATOR_COMPRESSED};
25+
26+
use crate::{BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
1227

1328
fn bls12_381_g1_generator() -> [u8; BLS12_381_G1_POINT_LEN] {
1429
let mut point = [0_u8; BLS12_381_G1_POINT_LEN];
@@ -30,6 +45,9 @@ mod test {
3045

3146
#[test]
3247
fn g1_generator_correct() {
48+
// Source: <https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-02#section-4.3.2>
49+
//
50+
// See the `x` coordinate
3351
let mut generator = hex!("17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb");
3452
generator[0] |= 0b1000_0000;
3553
assert_eq!(generator, bls12_381_g1_generator());
@@ -38,6 +56,11 @@ mod test {
3856

3957
#[test]
4058
fn g2_generator_correct() {
59+
// Source: <https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-02#section-4.3.2>
60+
//
61+
// $$
62+
// G2_{raw} = x'_1 || x'_0
63+
// $$
4164
let mut generator = hex!("13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8");
4265
generator[0] |= 0b1000_0000;
4366
assert_eq!(generator, bls12_381_g2_generator());

packages/crypto/src/bls12_318/mod.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
mod constants;
2+
3+
pub use self::constants::{
4+
BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR_COMPRESSED,
5+
BLS12_381_G2_POINT_LEN,
6+
};
7+
18
cfg_if::cfg_if! {
29
if #[cfg(feature = "std")] {
310
mod aggregate;
4-
mod constants;
511
mod hash;
612
mod pairing;
713
mod points;
@@ -12,19 +18,3 @@ cfg_if::cfg_if! {
1218
pub use self::points::{bls12_381_g1_is_identity, bls12_381_g2_is_identity};
1319
}
1420
}
15-
16-
pub const BLS12_381_G1_POINT_LEN: usize = 48;
17-
pub const BLS12_381_G2_POINT_LEN: usize = 96;
18-
19-
pub const BLS12_381_G1_GENERATOR_COMPRESSED: [u8; BLS12_381_G1_POINT_LEN] = [
20-
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79,
21-
151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251,
22-
58, 240, 10, 219, 34, 198, 187,
23-
];
24-
pub const BLS12_381_G2_GENERATOR_COMPRESSED: [u8; BLS12_381_G2_POINT_LEN] = [
25-
147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208,
26-
153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229,
27-
172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81,
28-
198, 228, 122, 212, 250, 64, 59, 2, 180, 81, 11, 100, 122, 227, 209, 119, 11, 172, 3, 38, 168,
29-
5, 187, 239, 212, 128, 86, 200, 193, 33, 189, 184,
30-
];

0 commit comments

Comments
 (0)