Add some lightweight documentation.

This commit is contained in:
2018-10-27 15:01:38 -07:00
parent 0bec74b18c
commit 1cb77de521
13 changed files with 79 additions and 7 deletions

View File

@@ -7,26 +7,33 @@ macro_rules! signed_impls {
}
impl $sname {
/// Generate a new signed number from an unsigned number and a
/// boolean describing whether or not the new number is negative.
/// Note that if the value is zero, the value of the negative flag
/// will be ignored.
pub fn new(negative: bool, value: $name) -> $sname {
if value.is_zero() {
$sname{ negative: false, value: value }
} else {
$sname{ negative: negative, value: value }
$sname{ negative: negative, value: value }
}
}
}
/// Return a new number that is the negated version of this number.
pub fn negate(&self) -> $sname {
if self.value.is_zero() {
self.clone()
} else {
$sname{ negative: !self.negative, value: self.value.clone() }
$sname{ negative: !self.negative, value: self.value.clone() }
}
}
}
/// Return the absolute value of the number.
pub fn abs(&self) -> $sname {
$sname{ negative: false, value: self.value.clone() }
}
/// Return true iff the value is negative and not zero.
pub fn is_negative(&self) -> bool {
self.negative
}

View File

@@ -1,4 +1,8 @@
/// GCD computations, with extended information
pub trait EGCD<T> {
/// Compute the extended GCD for this value and the given value.
/// If the inputs to this function are x (self) and y (the argument),
/// and the results are (a, b, g), then (a * x) + (b * y) = g.
fn egcd(&self, rhs: &Self) -> (T, T, T);
}

View File

@@ -1,3 +1,14 @@
//! This module includes a large number of signed integer types for very
//! large integers, designed to try to match good performance with a high
//! assurance threshold.
//!
//! The types provided in this module, and the functions available for each
//! of those types, is derived from standard bit widths for RSA, DSA, and
//! Elliptic Curve encryption schemes. If this library does not include a
//! function you would like for another cryptographic scheme, please reach
//! out to the authors; in many cases, the relevant code can be automatically
//! generated.
//!
#[macro_use]
mod add;
#[macro_use]

View File

@@ -1,4 +1,8 @@
/// Computations of the modular inverse.
pub trait ModInv: Sized {
/// Compute the modular inverse of this number under the given
/// modulus, if it exists. If self is a, the modulus / argument
/// is phi, and the result is Some(m), then (a * m) % phi = 1.
fn modinv(&self, phi: &Self) -> Option<Self>;
}