Crypto crates.io badge

This crate provides basic cryptographic implementation as in Field, Curve and Pairing, Fft, Kzg, and also supports fully no_std and parity-scale-codec.

Usage

Field

The following Fr support four basic operation.

```rust

[derive(Clone, Copy, Decode, Encode, Serialize, Deserialize)]

pub struct Fr(pub [u64; 4]);

const MODULUS: [u64; 4] = [ 0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48, ];

const GENERATOR: [u64; 4] = [ 0x0000000efffffff1, 0x17e363d300189c0f, 0xff9c57876f8457b0, 0x351332208fc5a8c4, ];

/// R = 2^256 mod r const R: [u64; 4] = [ 0x00000001fffffffe, 0x5884b7fa00034802, 0x998c4fefecbc4ff5, 0x1824b159acc5056f, ];

/// R^2 = 2^512 mod r const R2: [u64; 4] = [ 0xc999e990f3f29c6d, 0x2b6cedcb87925c23, 0x05d314967254398f, 0x0748d9d99f59ff11, ];

/// R^3 = 2^768 mod r const R3: [u64; 4] = [ 0xc62c1807439b73af, 0x1b3e0d188cf06990, 0x73d13c71c7b5f418, 0x6e2a5bb9c8db33e9, ];

pub const INV: u64 = 0xfffffffeffffffff;

const S: usize = 32;

pub const ROOTOFUNITY: Fr = Fr([ 0xb9b58d8c5f0e466a, 0x5b1b4c801819d7ec, 0x0af53ae352a31e64, 0x5bf3adda19e9b27b, ]);

fftfieldoperation!(Fr, MODULUS, GENERATOR, INV, ROOTOFUNITY, R, R2, R3, S);

[cfg(test)]

mod tests { use super::*; use paste::paste; use rand_core::OsRng;

field_test!(bls12_381_scalar, Fr, 1000);

} ```

Curve

The following G1Affine and G1Projective supports point arithmetic.

```rust use crate::fq::Fq; use crate::fr::Fr; use zerocrypto::arithmetic::bits384::; use zero_crypto::common::; use zero_crypto::dress::curve::*;

/// The projective form of coordinate

[derive(Debug, Clone, Copy, Decode, Encode)]

pub struct G1Projective { pub(crate) x: Fq, pub(crate) y: Fq, pub(crate) z: Fq, }

/// The projective form of coordinate

[derive(Debug, Clone, Copy, Decode, Encode)]

pub struct G1Affine { pub(crate) x: Fq, pub(crate) y: Fq, is_infinity: bool, }

curveoperation!( Fr, Fq, G1PARAMA, G1PARAMB, G1Affine, G1Projective, G1GENERATORX, G1GENERATOR_Y );

[cfg(test)]

mod tests { #[allow(unused_imports)] use super::*;

curve_test!(bls12_381, Fr, G1Affine, G1Projective, 100);

} ```