From 73e172484c0ac982265c1d210723feaa3999eed6 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sun, 2 Apr 2017 23:12:18 +0200 Subject: [PATCH] Add tick marks around code items in docs --- src/constants.rs | 10 +++++----- src/curve.rs | 14 +++++++------- src/field.rs | 26 ++++++++++++++------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 9ff4d4d..c0e6cc2 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -70,7 +70,7 @@ pub const SQRT_M1: FieldElement = FieldElement([ pub const SQRT_M1: FieldElement = FieldElement([1718705420411056, 234908883556509, 2233514472574048, 2117202627021982, 765476049583133]); /// Precomputed value of the other square root of -1 (mod p), -/// i.e., MSQRT_M1 = -SQRT_M1. +/// i.e., `MSQRT_M1 = -SQRT_M1`. #[cfg(not(feature="radix_51"))] pub const MSQRT_M1: FieldElement = FieldElement([ 32595792, 7943725, -9377950, -3500415, -12389472, @@ -92,7 +92,7 @@ pub const A: FieldElement = FieldElement([ #[cfg(feature="radix_51")] pub const A: FieldElement = FieldElement([486662, 0, 0, 0, 0]); -/// SQRT_MINUS_A is sqrt(-486662) +/// `SQRT_MINUS_A` is sqrt(-486662) // XXX I think that this was used in Adam's code for his elligator // implementation, but that should maybe be using sqrt(-486664) // instead...? - hdevalence @@ -103,7 +103,7 @@ pub const SQRT_MINUS_A: FieldElement = FieldElement([ // sqrtMinusA #[cfg(feature="radix_51")] pub const SQRT_MINUS_A: FieldElement = FieldElement([557817479725543, 1643290402203250, 16226468853936, 1304118542701054, 1985241807451647]); -/// SQRT_MINUS_APLUS2 is sqrt(-486664) +/// `SQRT_MINUS_APLUS2` is sqrt(-486664) #[cfg(not(feature="radix_51"))] pub const SQRT_MINUS_APLUS2: FieldElement = FieldElement([ -12222970, -8312128, -11511410, 9067497, -15300785, @@ -111,7 +111,7 @@ pub const SQRT_MINUS_APLUS2: FieldElement = FieldElement([ #[cfg(feature="radix_51")] pub const SQRT_MINUS_APLUS2: FieldElement = FieldElement([1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600]); -/// SQRT_MINUS_HALF is sqrt(-1/2) +/// `SQRT_MINUS_HALF` is sqrt(-1/2) #[cfg(not(feature="radix_51"))] pub const SQRT_MINUS_HALF: FieldElement = FieldElement([ // sqrtMinusHalf -17256545, 3971863, 28865457, -1750208, 27359696, @@ -119,7 +119,7 @@ pub const SQRT_MINUS_HALF: FieldElement = FieldElement([ // sqrtMinusHalf #[cfg(feature="radix_51")] pub const SQRT_MINUS_HALF: FieldElement = FieldElement([266547196637087, 2134345371906993, 1135042577398223, 67298593331632, 743161882051057]); -/// HALF_Q_MINUS_1_BYTES is (2^255-20)/2 expressed in little endian form. +/// `HALF_Q_MINUS_1_BYTES` is (2^255-20)/2 expressed in little endian form. pub const HALF_Q_MINUS_1_BYTES: [u8; 32] = [ // halfQMinus1Bytes 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/src/curve.rs b/src/curve.rs index aefecac..7638da1 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -59,15 +59,15 @@ //! implementation for [Ed25519](https://ed25519.cr.yp.to/ed25519-20110926.pdf), //! we use several different models for curve points: //! -//! * CompletedPoint: points in ๐—ฃ^1 x ๐—ฃ^1; -//! * ExtendedPoint: points in ๐—ฃ^3; -//! * ProjectivePoint: points in ๐—ฃ^2. +//! * `CompletedPoint`: points in ๐—ฃ^1 x ๐—ฃ^1; +//! * `ExtendedPoint`: points in ๐—ฃ^3; +//! * `ProjectivePoint`: points in ๐—ฃ^2. //! //! Finally, to accelerate additions, we use two cached point formats, //! one for the affine model and one for the ๐—ฃ^3 model: //! -//! * AffineNielsPoint: `(y+x, y-x, 2dxy)` -//! * ProjectiveNielsPoint: `(Y+X, Y-X, Z, 2dXY)` +//! * `AffineNielsPoint`: `(y+x, y-x, 2dxy)` +//! * `ProjectiveNielsPoint`: `(Y+X, Y-X, Z, 2dXY)` //! //! [1]: https://moderncrypto.org/mail-archive/curves/2016/000807.html @@ -103,7 +103,7 @@ use std::boxed::Box; /// determined by the `y`-coordinate and the sign of `x`, marshalled /// into a 32-byte array. /// -/// The first 255 bits of a CompressedEdwardsY represent the +/// The first 255 bits of a `CompressedEdwardsY` represent the /// y-coordinate. The high bit of the 32nd byte gives the sign of `x`. #[derive(Copy, Clone, Eq, PartialEq)] pub struct CompressedEdwardsY(pub [u8; 32]); @@ -303,7 +303,7 @@ pub struct ProjectivePoint { Z: FieldElement, } -/// A CompletedPoint is a point ((X:Z), (Y:T)) in ๐—ฃยน(๐”ฝโ‚š)ร—๐—ฃยน(๐”ฝโ‚š). +/// A `CompletedPoint` is a point ((X:Z), (Y:T)) in ๐—ฃยน(๐”ฝโ‚š)ร—๐—ฃยน(๐”ฝโ‚š). /// A point (x,y) in the affine model corresponds to ((x:1),(y:1)). #[derive(Copy, Clone)] pub struct CompletedPoint { diff --git a/src/field.rs b/src/field.rs index 78dcc9b..8a6373c 100644 --- a/src/field.rs +++ b/src/field.rs @@ -41,25 +41,27 @@ use constants; #[cfg(feature="radix_51")] pub type Limb = u64; -/// FieldElement represents an element of the field GF(2^255 - 19). An element -/// t, entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77 -/// t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on -/// context. +/// A `FieldElement` represents an element of the field GF(2^255 - 19). +/// +/// With the `radix_51` feature, a `FieldElement` is represented in +/// radix 2^51 as five `u64`s; the coefficients are allowed to grow up +/// to 2^54 between reductions mod `p`. #[cfg(feature="radix_51")] #[derive(Copy, Clone)] pub struct FieldElement(pub [u64; 5]); -/// FieldElements are represented as an array of ten "Limbs", which are radix -/// 25.5, that is, each Limb of a FieldElement alternates between being -/// represented as a factor of 2^25 or 2^26 more than the last corresponding -/// integer. +/// Without the `radix51` feature enabled, `FieldElements` are represented +/// in radix 2^25.5 as ten `i32`s. #[cfg(not(feature="radix_51"))] pub type Limb = i32; -/// FieldElement represents an element of the field GF(2^255 - 19). An element -/// t, entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77 -/// t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on -/// context. +/// A `FieldElement` represents an element of the field GF(2^255 - 19). +/// +/// With the `radix_51` feature, a `FieldElement` is represented in +/// radix 2^25.5 as ten `i32`s, so that an element t, entries +/// t[0],...,t[9], represents the integer t[0]+2^26 t[1]+2^51 +/// t[2]+2^77 t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] +/// vary depending on context. #[cfg(not(feature="radix_51"))] #[derive(Copy, Clone)] pub struct FieldElement(pub [i32; 10]);