1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
//! Module for Public Trait implementations. /// Gives the Identity element for the /// type which it has been implemented on. /// /// This trait is implemented following the rules that /// mandate over the Type that is being implemented. pub trait Identity { #[must_use] /// Returns the identity element for the implemented /// type, following it's mathematical rules. fn identity() -> Self; } pub mod ops { use subtle::Choice; /// Trait that represents the `^2` operation for any /// kind of element on the library. /// /// This trait is implemented following the rules that /// mandate over the Type that is being implemented. pub trait Square { type Output; #[must_use] /// Returns the square of the input: `x^2`. fn square(self) -> Self::Output; } /// Trait that represents the Point doubling operation /// for any type of Point that is used on the lib. /// /// This trait is implemented following the rules that /// mandate over the Type that is being implemented. pub trait Double { type Output; #[must_use] /// Performs the point-doubling operation over the /// coordinates which this trait has been implemented /// for. fn double(self) -> Self::Output; } /// Trait that represents the `/2` operation for any /// kind of element on the library. /// /// This is a more performant way of performing the /// division by 2 that dividing by 2 with the `Div` /// trait implementation. /// /// This trait is implemented following the rules that /// mandate over the Type that is being implemented. pub trait Half { type Output; #[must_use] /// Returns the half of the input: `x/2`. fn half(self) -> Self::Output; } /// Trait that represents the modular exponentiation /// operation, ie.`a ^ b (mod l)`, for any /// kind of element on the library (except points). /// /// This trait is implemented following the rules that /// mandate over the Type that is being implemented. pub trait Pow<T> { type Output; #[must_use] /// Returns `a^b (mod l)`. fn pow(self, exp: T) -> Self::Output; } pub trait ModSqrt { type Output; #[must_use] /// Performs the modular Square Root operation over a finite /// field ie. `sqrt(x) (mod l)`. /// /// With the given `Choice`, the impl is able to provide the /// result that corresponds to the positive or negative sign choosen. /// /// # Returns /// /// `Some(symb_choosen_result)` if the input is a QR for the prime modulo. /// Otherways it returns `None` fn mod_sqrt(self, choice: Choice) -> Self::Output; } }