halo2curves/secq256k1/
curve.rs
1use core::{
2 cmp,
3 fmt::Debug,
4 iter::Sum,
5 ops::{Add, Mul, Neg, Sub},
6};
7
8use rand::RngCore;
9use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
10
11use crate::{
12 ff::{Field, PrimeField, WithSmallOrderMulGroup},
13 group::{prime::PrimeCurveAffine, Curve, Group, GroupEncoding},
14 impl_binops_additive, impl_binops_additive_specify_output, impl_binops_multiplicative,
15 impl_binops_multiplicative_mixed, new_curve_impl,
16 secp256k1::{Fp, Fq},
17 Coordinates, CurveAffine, CurveExt,
18};
19
20const SECQ_GENERATOR_X: Fq = Fq::from_raw([
21 0xA24288E37702EDA6,
22 0x3134E45A097781A6,
23 0xB6B06C87A2CE32E2,
24 0x76C39F5585CB160E,
25]);
26
27const SECQ_GENERATOR_Y: Fq = Fq::from_raw([
28 0xA4120DDAD952677F,
29 0xD18983D26E8DC055,
30 0xDC2D265A8E82A7F7,
31 0x3FFC646C7B2918B5,
32]);
33
34const SECQ_A: Fq = Fq::from_raw([0, 0, 0, 0]);
35const SECQ_B: Fq = Fq::from_raw([7, 0, 0, 0]);
36
37new_curve_impl!(
38 (pub),
39 Secq256k1,
40 Secq256k1Affine,
41 Fq,
42 Fp,
43 (SECQ_GENERATOR_X, SECQ_GENERATOR_Y),
44 SECQ_A,
45 SECQ_B,
46 "secq256k1",
47 |domain_prefix| crate::hash_to_curve::hash_to_curve(domain_prefix, Secq256k1::default_hash_to_curve_suite()),
48 crate::serde::CompressedFlagConfig::Extra,
49 standard_sign
50);
51
52impl group::cofactor::CofactorGroup for Secq256k1 {
53 type Subgroup = Secq256k1;
54
55 fn clear_cofactor(&self) -> Self {
56 *self
57 }
58
59 fn into_subgroup(self) -> CtOption<Self::Subgroup> {
60 CtOption::new(self, 1.into())
61 }
62
63 fn is_torsion_free(&self) -> Choice {
64 1.into()
65 }
66}
67
68impl Secq256k1 {
69 const SVDW_Z: Fq = Fq::ONE;
70
71 fn default_hash_to_curve_suite() -> crate::hash_to_curve::Suite<Self, sha2::Sha256, 48> {
72 crate::hash_to_curve::Suite::<Self, sha2::Sha256, 48>::new(
73 b"secq256k1_XMD:SHA-256_SVDW_RO_",
74 Self::SVDW_Z,
75 crate::hash_to_curve::Method::SVDW,
76 )
77 }
78}
79
80#[cfg(test)]
81mod test {
82 use group::UncompressedEncoding;
83 use rand_core::OsRng;
84
85 use super::*;
86 use crate::serde::SerdeObject;
87
88 crate::curve_testing_suite!(Secq256k1);
89 crate::curve_testing_suite!(Secq256k1, "endo_consistency");
90 crate::curve_testing_suite!(
91 Secq256k1,
92 "constants",
93 Fq::MODULUS,
94 SECQ_A,
95 SECQ_B,
96 SECQ_GENERATOR_X,
97 SECQ_GENERATOR_Y,
98 Fp::MODULUS
99 );
100}