pub struct MontgomeryPoint(pub [u8; 32]);Expand description
Holds the \(u\)-coordinate of a point on the Montgomery form of Curve25519 or its twist.
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl MontgomeryPoint
impl MontgomeryPoint
Sourcepub fn mul_base(scalar: &Scalar) -> Self
pub fn mul_base(scalar: &Scalar) -> Self
Fixed-base scalar multiplication (i.e. multiplication by the base point).
theorem mul_base_spec (scalar : scalar.Scalar)
(h_s_canonical : U8x32_as_Nat scalar.bytes < 2 ^ 255) :
mul_base scalar ⦃ (result : MontgomeryPoint) =>
let ep := (U8x32_as_Nat scalar.bytes) • _root_.Edwards.basepoint
if ep.y = 1 then
MontgomeryPoint.mkPoint result = T_point
else
MontgomeryPoint.mkPoint result = abs_montgomery
((U8x32_as_Nat scalar.bytes) • (fromEdwards _root_.Edwards.basepoint)) ⦄
Sourcepub fn mul_clamped(self, bytes: [u8; 32]) -> Self
pub fn mul_clamped(self, bytes: [u8; 32]) -> Self
Multiply this point by clamp_integer(bytes). For a description of clamping, see
clamp_integer.
theorem mul_clamped_spec (P : MontgomeryPoint) (bytes : Array U8 32#usize)
(hP_bound : U8x32_as_Nat P < 2 ^ 255) :
mul_clamped P bytes ⦃ (result : MontgomeryPoint) =>
(∃ clamped_scalar,
h ∣ U8x32_as_Nat clamped_scalar ∧
U8x32_as_Nat clamped_scalar < 2 ^ 255 ∧
2 ^ 254 ≤ U8x32_as_Nat clamped_scalar ∧
let m := (U8x32_as_Nat clamped_scalar)
MontgomeryPoint.mkPoint result = m • (MontgomeryPoint.mkPoint P)) ⦄
Sourcepub fn mul_base_clamped(bytes: [u8; 32]) -> Self
pub fn mul_base_clamped(bytes: [u8; 32]) -> Self
Multiply the basepoint by clamp_integer(bytes). For a description of clamping, see
clamp_integer.
theorem mul_base_clamped_spec (bytes : Array U8 32#usize) :
mul_base_clamped bytes ⦃ (result : MontgomeryPoint) =>
(∃ clamped_scalar_nat,
h ∣ clamped_scalar_nat ∧
clamped_scalar_nat < 2 ^ 255 ∧
2 ^ 254 ≤ clamped_scalar_nat ∧
(if (clamped_scalar_nat • Edwards.basepoint).y = 1 then
MontgomeryPoint.mkPoint result = T_point
else MontgomeryPoint.mkPoint result =
abs_montgomery (clamped_scalar_nat • fromEdwards _root_.Edwards.basepoint))) ⦄
Sourcepub fn mul_bits_be(&self, bits: impl Iterator<Item = bool>) -> MontgomeryPoint
Available on non-verify only.
pub fn mul_bits_be(&self, bits: impl Iterator<Item = bool>) -> MontgomeryPoint
verify only.Given self \( = u_0(P) \), and a big-endian bit representation of an integer
\(n\), return \( u_0([n]P) \). This is constant time in the length of bits.
NOTE: You probably do not want to use this function. Almost every protocol built on
Curve25519 uses clamped multiplication, explained
here.
When in doubt, use Self::mul_clamped.
Sourcepub const fn as_bytes(&self) -> &[u8; 32]
pub const fn as_bytes(&self) -> &[u8; 32]
View this MontgomeryPoint as an array of bytes.
theorem as_bytes_spec (self : MontgomeryPoint) :
as_bytes self ⦃ (result : MontgomeryPoint) =>
result = self ⦄
Sourcepub const fn to_bytes(&self) -> [u8; 32]
pub const fn to_bytes(&self) -> [u8; 32]
Convert this MontgomeryPoint to an array of bytes.
theorem to_bytes_spec (self : MontgomeryPoint) :
to_bytes self ⦃ (result : MontgomeryPoint) =>
result = self ⦄
Sourcepub fn to_edwards(&self, sign: u8) -> Option<EdwardsPoint>
pub fn to_edwards(&self, sign: u8) -> Option<EdwardsPoint>
Attempt to convert to an EdwardsPoint, using the supplied
choice of sign for the EdwardsPoint.
§Inputs
sign: au8donating the desired sign of the resultingEdwardsPoint.0denotes positive and1negative.
§Return
-
Some(EdwardsPoint)ifselfis the \(u\)-coordinate of a point on (the Montgomery form of) Curve25519; -
Noneifselfis the \(u\)-coordinate of a point on the twist of (the Montgomery form of) Curve25519;
theorem to_edwards_spec (mp : MontgomeryPoint) (sign : U8) :
to_edwards mp sign ⦃ (result : Option edwards.EdwardsPoint) =>
(∀ ep, result = some ep →
∃ Z_inv,
field.FieldElement51.invert ep.Z = ok Z_inv ∧
let u := U8x32_as_Nat mp % 2^255
let y := Field51_as_Nat ep.Y * Field51_as_Nat Z_inv % p
(y * ((u + 1) % p)) % p = ((u + p - 1) % p) % p ∧
ep.IsValid ) ⦄
Trait Implementations§
Source§impl Clone for MontgomeryPoint
impl Clone for MontgomeryPoint
Source§fn clone(&self) -> MontgomeryPoint
fn clone(&self) -> MontgomeryPoint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConditionallySelectable for MontgomeryPoint
impl ConditionallySelectable for MontgomeryPoint
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
theorem conditional_select_spec (a b : MontgomeryPoint) (choice : subtle.Choice) :
conditional_select a b choice ⦃ (result : MontgomeryPoint) =>
∀ i < 32,
result[i]! = (if choice.val = 1#u8 then b[i]! else a[i]!) ⦄
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self and other if choice == 1; otherwise,
reassign both unto themselves. Read moreSource§impl ConstantTimeEq for MontgomeryPoint
Equality of MontgomeryPoints is defined mod p.
impl ConstantTimeEq for MontgomeryPoint
Equality of MontgomeryPoints is defined mod p.
Source§fn ct_eq(&self, other: &MontgomeryPoint) -> Choice
fn ct_eq(&self, other: &MontgomeryPoint) -> Choice
theorem ct_eq_spec (self other : MontgomeryPoint) :
ct_eq self other ⦃ (c : subtle.Choice) =>
(c = Choice.one ↔
(U8x32_as_Nat self % 2 ^ 255) ≡ (U8x32_as_Nat other % 2 ^ 255) [MOD p]) ⦄
Source§impl Debug for MontgomeryPoint
impl Debug for MontgomeryPoint
Source§impl Default for MontgomeryPoint
impl Default for MontgomeryPoint
Source§fn default() -> MontgomeryPoint
fn default() -> MontgomeryPoint
Source§impl Hash for MontgomeryPoint
impl Hash for MontgomeryPoint
Source§impl Identity for MontgomeryPoint
impl Identity for MontgomeryPoint
Source§fn identity() -> MontgomeryPoint
fn identity() -> MontgomeryPoint
Return the group identity element, which has order 4.
theorem identity_spec :
identity ⦃ (result : MontgomeryPoint) =>
(∀ i : Fin 32, result[i]! = 0#u8) ∧
U8x32_as_Nat result = 0 ⦄
Source§impl Mul<&MontgomeryPoint> for &Scalar
impl Mul<&MontgomeryPoint> for &Scalar
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§fn mul(self, point: &MontgomeryPoint) -> MontgomeryPoint
fn mul(self, point: &MontgomeryPoint) -> MontgomeryPoint
* operation. Read moreSource§impl<'b> Mul<&'b MontgomeryPoint> for Scalar
impl<'b> Mul<&'b MontgomeryPoint> for Scalar
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§fn mul(self, rhs: &'b MontgomeryPoint) -> MontgomeryPoint
fn mul(self, rhs: &'b MontgomeryPoint) -> MontgomeryPoint
* operation. Read moreSource§impl Mul<&Scalar> for &MontgomeryPoint
Multiply this MontgomeryPoint by a Scalar.
impl Mul<&Scalar> for &MontgomeryPoint
Multiply this MontgomeryPoint by a Scalar.
NOTE: This implementation avoids using Scalar::bits_le() and iterator adapters (.rev(), .skip()) because Charon/Aeneas cannot extract the Iterator trait machinery. Instead, we inline the bit iteration using a while loop.
Source§fn mul(self, scalar: &Scalar) -> MontgomeryPoint
fn mul(self, scalar: &Scalar) -> MontgomeryPoint
Given self \( = u_0(P) \), and a Scalar \(n\), return \( u_0([n]P) \)
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§impl<'b> Mul<&'b Scalar> for MontgomeryPoint
impl<'b> Mul<&'b Scalar> for MontgomeryPoint
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§fn mul(self, rhs: &'b Scalar) -> MontgomeryPoint
fn mul(self, rhs: &'b Scalar) -> MontgomeryPoint
* operation. Read moretheorem mul_loop_spec
(affine_u : backend.serial.u64.field.FieldElement51)
(x0 x1 : montgomery.ProjectivePoint)
(scalar_bytes : Array U8 32#usize)
(prev_bit : Bool)
(i : Isize)
(idx0W : Field51_as_Nat x0.W = 0)
(idx1W : Field51_as_Nat x1.W = 1)
(idx0U : Field51_as_Nat x0.U = 1) :
mul_loop affine_u x0 x1 scalar_bytes prev_bit i
⦃ (result : montgomery.ProjectivePoint × montgomery.ProjectivePoint × Bool) =>
(result.2.2 = true →
let q := (i.val / 8).toNat
let r := (i.val % 8).toNat
let m := ∑ i ∈ Finset.range q, 2^(8 * i) * (scalar_bytes[i]!).val
+ 2^(8 * q) * ((scalar_bytes[q]!).val % 2^(r+1))
+ 2^(8 * q + r) * prev_bit.toNat
let u := x1.U.toField
let u_out := result.2.1.U.toField
let w_out := result.2.1.W.toField
let u_ord := u_out/w_out
result.2.1.U.IsValid ∧
result.2.1.W.IsValid ∧
result.1.U.IsValid ∧
result.1.W.IsValid ∧
w_out ≠ 0 ∧
MontgomeryPoint.u_affine_toPoint u_ord = m • (MontgomeryPoint.u_affine_toPoint u)) ∧
(result.2.2 = false →
let q := (i.val / 8).toNat
let r := (i.val % 8).toNat
let m := ∑ i ∈ Finset.range q, 2^(8 * i) * (scalar_bytes[i]!).val
+ 2^(8 * q) * ((scalar_bytes[q]!).val % 2^(r+1))
+ 2^(8 * q + r) * prev_bit.toNat
let u := x1.U.toField
let u_out := result.1.U.toField
let w_out := result.1.W.toField
let u_ord := u_out/w_out
result.2.1.U.IsValid ∧
result.2.1.W.IsValid ∧
result.1.U.IsValid ∧
result.1.W.IsValid ∧
w_out ≠ 0 ∧
MontgomeryPoint.u_affine_toPoint u_ord = m • (MontgomeryPoint.u_affine_toPoint u)) ⦄
Source§impl<'a> Mul<MontgomeryPoint> for &'a Scalar
impl<'a> Mul<MontgomeryPoint> for &'a Scalar
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§fn mul(self, rhs: MontgomeryPoint) -> MontgomeryPoint
fn mul(self, rhs: MontgomeryPoint) -> MontgomeryPoint
* operation. Read moreSource§impl Mul<MontgomeryPoint> for Scalar
impl Mul<MontgomeryPoint> for Scalar
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§fn mul(self, rhs: MontgomeryPoint) -> MontgomeryPoint
fn mul(self, rhs: MontgomeryPoint) -> MontgomeryPoint
* operation. Read moreSource§impl<'a> Mul<Scalar> for &'a MontgomeryPoint
impl<'a> Mul<Scalar> for &'a MontgomeryPoint
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§impl Mul<Scalar> for MontgomeryPoint
impl Mul<Scalar> for MontgomeryPoint
Source§type Output = MontgomeryPoint
type Output = MontgomeryPoint
* operator.Source§impl MulAssign<&Scalar> for MontgomeryPoint
impl MulAssign<&Scalar> for MontgomeryPoint
Source§fn mul_assign(&mut self, scalar: &Scalar)
fn mul_assign(&mut self, scalar: &Scalar)
*= operation. Read moreSource§impl MulAssign<Scalar> for MontgomeryPoint
impl MulAssign<Scalar> for MontgomeryPoint
Source§fn mul_assign(&mut self, rhs: Scalar)
fn mul_assign(&mut self, rhs: Scalar)
*= operation. Read moretheorem mul_assign_spec (self : MontgomeryPoint) (scalar : scalar.Scalar)
(hself_bound : U8x32_as_Nat self < 2 ^ 255) :
mul_assign self scalar ⦃ (result : MontgomeryPoint) =>
let m := (U8x32_as_Nat scalar.bytes) % 2^255
MontgomeryPoint.mkPoint result = m • (MontgomeryPoint.mkPoint self) ⦄
Source§impl PartialEq for MontgomeryPoint
impl PartialEq for MontgomeryPoint
Source§fn eq(&self, other: &MontgomeryPoint) -> bool
fn eq(&self, other: &MontgomeryPoint) -> bool
self and other values to be equal, and is used by ==.theorem eq_spec (self other : MontgomeryPoint) :
eq self other ⦃ (b : Bool) =>
(b = true ↔
(U8x32_as_Nat self % 2 ^ 255) ≡ (U8x32_as_Nat other % 2 ^ 255) [MOD p]) ⦄
Source§impl Zeroize for MontgomeryPoint
Available on crate feature zeroize only.
impl Zeroize for MontgomeryPoint
zeroize only.