Skip to main content

k256/
arithmetic.rs

1//! A pure-Rust implementation of group operations on secp256k1.
2
3pub(crate) mod affine;
4mod field;
5mod mul;
6pub(crate) mod projective;
7pub(crate) mod scalar;
8
9#[cfg(test)]
10mod dev;
11#[cfg(feature = "hash2curve")]
12mod hash2curve;
13#[cfg(feature = "precomputed-tables")]
14mod tables;
15
16pub use field::FieldElement;
17
18use self::{affine::AffinePoint, projective::ProjectivePoint, scalar::Scalar};
19use crate::Secp256k1;
20use elliptic_curve::{CurveArithmetic, hazmat::FieldArithmetic};
21
22impl CurveArithmetic for Secp256k1 {
23    type AffinePoint = AffinePoint;
24    type ProjectivePoint = ProjectivePoint;
25    type Scalar = Scalar;
26}
27
28impl FieldArithmetic for Secp256k1 {
29    type FieldElement = FieldElement;
30}
31
32const CURVE_EQUATION_B_SINGLE: u32 = 7u32;
33
34#[rustfmt::skip]
35#[allow(clippy::cast_possible_truncation)]
36pub(crate) const CURVE_EQUATION_B: FieldElement = FieldElement::from_bytes_unchecked(&[
37    0, 0, 0, 0, 0, 0, 0, 0,
38    0, 0, 0, 0, 0, 0, 0, 0,
39    0, 0, 0, 0, 0, 0, 0, 0,
40    0, 0, 0, 0, 0, 0, 0, CURVE_EQUATION_B_SINGLE as u8,
41]);
42
43#[cfg(test)]
44mod tests {
45    use super::CURVE_EQUATION_B;
46    use hex_literal::hex;
47
48    const CURVE_EQUATION_B_BYTES: [u8; 32] =
49        hex!("0000000000000000000000000000000000000000000000000000000000000007");
50
51    #[test]
52    fn verify_constants() {
53        assert_eq!(CURVE_EQUATION_B.to_bytes(), CURVE_EQUATION_B_BYTES);
54    }
55}