|
1 | 1 | //! Pure Rust implementation of group operations on secp224r1.
|
2 | 2 | //!
|
3 |
| -//! Curve parameters can be found in [NIST SP 800-186] § G.1.1: Curve P-384. |
| 3 | +//! Curve parameters can be found in [NIST SP 800-186] § 3.2.1.2: P-224. |
4 | 4 | //!
|
5 | 5 | //! [NIST SP 800-186]: https://csrc.nist.gov/publications/detail/sp/800-186/final
|
6 | 6 |
|
7 |
| -pub mod field; |
8 |
| -pub mod scalar; |
| 7 | +pub(crate) mod field; |
| 8 | +pub(crate) mod scalar; |
| 9 | + |
| 10 | +pub use self::scalar::Scalar; |
| 11 | + |
| 12 | +use self::field::FieldElement; |
| 13 | +use crate::NistP224; |
| 14 | +use elliptic_curve::{CurveArithmetic, PrimeCurveArithmetic}; |
| 15 | +use primeorder::{point_arithmetic, PrimeCurveParams}; |
| 16 | + |
| 17 | +/// Elliptic curve point in affine coordinates. |
| 18 | +pub type AffinePoint = primeorder::AffinePoint<NistP224>; |
| 19 | + |
| 20 | +/// Elliptic curve point in projective coordinates. |
| 21 | +pub type ProjectivePoint = primeorder::ProjectivePoint<NistP224>; |
| 22 | + |
| 23 | +impl CurveArithmetic for NistP224 { |
| 24 | + type AffinePoint = AffinePoint; |
| 25 | + type ProjectivePoint = ProjectivePoint; |
| 26 | + type Scalar = Scalar; |
| 27 | +} |
| 28 | + |
| 29 | +impl PrimeCurveArithmetic for NistP224 { |
| 30 | + type CurveGroup = ProjectivePoint; |
| 31 | +} |
| 32 | + |
| 33 | +/// Adapted from [NIST SP 800-186] § 3.2.1.2: P-224. |
| 34 | +/// |
| 35 | +/// [NIST SP 800-186]: https://csrc.nist.gov/publications/detail/sp/800-186/final |
| 36 | +impl PrimeCurveParams for NistP224 { |
| 37 | + type FieldElement = FieldElement; |
| 38 | + type PointArithmetic = point_arithmetic::EquationAIsMinusThree; |
| 39 | + |
| 40 | + /// a = -3 (=0xffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe) |
| 41 | + const EQUATION_A: FieldElement = FieldElement::from_u64(3).neg(); |
| 42 | + |
| 43 | + /// b = 0xb4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4 |
| 44 | + #[cfg(target_pointer_width = "32")] |
| 45 | + const EQUATION_B: FieldElement = |
| 46 | + FieldElement::from_hex("b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4"); |
| 47 | + |
| 48 | + /// b = 0xb4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4 |
| 49 | + #[cfg(target_pointer_width = "64")] |
| 50 | + const EQUATION_B: FieldElement = |
| 51 | + FieldElement::from_hex("00000000b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4"); |
| 52 | + |
| 53 | + /// Base point of P-224. |
| 54 | + /// |
| 55 | + /// ```text |
| 56 | + /// Gₓ = 0xb70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21 |
| 57 | + /// Gᵧ = 0xbd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34 |
| 58 | + /// ``` |
| 59 | + #[cfg(target_pointer_width = "32")] |
| 60 | + const GENERATOR: (FieldElement, FieldElement) = ( |
| 61 | + FieldElement::from_hex("b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21"), |
| 62 | + FieldElement::from_hex("bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"), |
| 63 | + ); |
| 64 | + |
| 65 | + /// Base point of P-224. |
| 66 | + /// |
| 67 | + /// ```text |
| 68 | + /// Gₓ = 0xb70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21 |
| 69 | + /// Gᵧ = 0xbd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34 |
| 70 | + /// ``` |
| 71 | + #[cfg(target_pointer_width = "64")] |
| 72 | + const GENERATOR: (FieldElement, FieldElement) = ( |
| 73 | + FieldElement::from_hex("00000000b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21"), |
| 74 | + FieldElement::from_hex("00000000bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"), |
| 75 | + ); |
| 76 | +} |
0 commit comments