This is the primitive of no_std
and parity-scale-codec
cryptography libraries.
The following Fp
support four basic operation.
```rust use zerocrypto::arithmetic::bits256::; use zero_crypto::common::; use zero_crypto::dress::field::*;
pub struct Fp(pub(crate) [u64; 4]);
const MODULUS: [u64; 4] = [ 0xd0970e5ed6f72cb7, 0xa6682093ccc81082, 0x06673b0101343b00, 0x0e7db4ea6533afa9, ];
const GENERATOR: [u64; 4] = [2, 0, 0, 0];
/// R = 2^256 mod r const R: [u64; 4] = [ 0x25f80bb3b99607d9, 0xf315d62f66b6e750, 0x932514eeeb8814f4, 0x09a6fc6f479155c6, ];
/// R^2 = 2^512 mod r const R2: [u64; 4] = [ 0x67719aa495e57731, 0x51b0cef09ce3fc26, 0x69dab7fac026e9a5, 0x04f6547b8d127688, ];
/// R^3 = 2^768 mod r const R3: [u64; 4] = [ 0xe0d6c6563d830544, 0x323e3883598d0f85, 0xf0fea3004c2e2ba8, 0x05874f84946737ec, ];
pub const INV: u64 = 0x1ba3a358ef788ef9;
const S: usize = 1;
const ROOTOFUNITY: Fp = Fp([ 0xaa9f02ab1d6124de, 0xb3524a6466112932, 0x7342261215ac260b, 0x4d6b87b1da259e2, ]);
fftfieldoperation!(Fp, MODULUS, GENERATOR, INV, ROOTOFUNITY, R, R2, R3, S); ```
The following JubjubProjective
supports point arithmetic.
```rust
use crate::fp::Fp;
use zerocrypto::arithmetic::bits256::;
use zero_crypto::common::;
use zero_crypto::dress::curve::*;
/// The projective form of coordinate
pub struct JubjubProjective { pub(crate) x: Fp, pub(crate) y: Fp, pub(crate) z: Fp, }
const IDENTITY: JubjubProjective = JubjubProjective { x: Fp::zero(), y: Fp::zero(), z: Fp::zero(), };
const GENERATOR: JubjubProjective = JubjubProjective { x: Fp::tomontform([ 0x7c24d812779a3316, 0x72e38f4ebd4070f3, 0x03b3fe93f505a6f2, 0xc4c71e5a4102960, ]), y: Fp::tomontform([ 0xd2047ef3463de4af, 0x01ca03640d236cbf, 0xd3033593ae386e92, 0xaa87a50921b80ec, ]), z: Fp::one(), };
const PARAM_A: Fp = Fp::zero();
const PARAMB: Fp = Fp::tomont_form([4, 0, 0, 0]);
/// The projective form of coordinate
pub struct JubjubAffine { x: Fp, y: Fp, is_infinity: bool, }
curveoperation!( Fp, Fp, PARAMA, PARAM_B, JubjubAffine, JubjubProjective, GENERATOR, IDENTITY ); ```