Fully document crypto/

This commit is contained in:
Luke Parker
2023-03-20 20:10:00 -04:00
parent e1bb2c191b
commit 8d4d630e0f
45 changed files with 335 additions and 208 deletions

View File

@@ -73,6 +73,7 @@ macro_rules! field {
}
impl $FieldName {
/// Perform an exponentation.
pub fn pow(&self, other: $FieldName) -> $FieldName {
let mut table = [Self(U512::ONE); 16];
table[1] = *self;

View File

@@ -4,11 +4,12 @@ use crypto_bigint::{U512, U1024};
use crate::field;
/// Ed448 field element.
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Zeroize)]
pub struct FieldElement(pub(crate) U512);
// 2**448 - 2**224 - 1
pub const MODULUS: FieldElement = FieldElement(U512::from_be_hex(concat!(
pub(crate) const MODULUS: FieldElement = FieldElement(U512::from_be_hex(concat!(
"00000000000000",
"00",
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffe",

View File

@@ -1,13 +1,14 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![no_std]
#![doc = include_str!("../README.md")]
mod backend;
pub mod scalar;
mod scalar;
pub use scalar::Scalar;
pub mod field;
mod field;
pub use field::FieldElement;
pub mod point;
mod point;
pub use point::Point;

View File

@@ -47,6 +47,7 @@ fn recover_x(y: FieldElement) -> CtOption<FieldElement> {
})
}
/// Ed448 point.
#[derive(Clone, Copy, Debug, Zeroize)]
pub struct Point {
x: FieldElement,
@@ -270,7 +271,7 @@ impl MulAssign<&Scalar> for Point {
}
impl Point {
pub fn is_torsion_free(&self) -> Choice {
fn is_torsion_free(&self) -> Choice {
(*self * SCALAR_MODULUS).is_identity()
}
}

View File

@@ -2,13 +2,14 @@ use zeroize::Zeroize;
use crypto_bigint::{U512, U1024};
pub use crate::field;
use crate::field;
/// Ed448 Scalar field element.
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug, Zeroize)]
pub struct Scalar(pub(crate) U512);
// 2**446 - 13818066809895115352007386748515426880336692474882178609894547503885
pub const MODULUS: Scalar = Scalar(U512::from_be_hex(concat!(
pub(crate) const MODULUS: Scalar = Scalar(U512::from_be_hex(concat!(
"00000000000000",
"00",
"3fffffffffffffffffffffffffffffffffffffffffffffffffffffff",
@@ -27,6 +28,7 @@ const WIDE_MODULUS: U1024 = U1024::from_be_hex(concat!(
field!(Scalar, MODULUS, WIDE_MODULUS, 446);
impl Scalar {
/// Perform a wide reduction to obtain a non-biased Scalar.
pub fn wide_reduce(bytes: [u8; 114]) -> Scalar {
Scalar(reduce(U1024::from_le_slice(&[bytes.as_ref(), &[0; 14]].concat())))
}