crypto::math
crypto::math provides constant-time mathematical operations useful for
cryptographic algorithms.
This is a low-level module which implements cryptographic primitives. Direct use
of cryptographic primitives is not recommended for non-experts, as incorrect use
of these primitives can easily lead to the introduction of security
vulnerabilities. Non-experts are advised to use the high-level operations
available in the top-level crypto module.
Be advised that Hare's cryptography implementations have not been audited.
Index
Functions
fn cmpu32(u32, u32) i32;
fn divu32(u32, u32, u32) (u32, u32);
fn eq0u32(i32) u32;
fn eqslice([]u8, []u8) int;
fn equ32(u32, u32) u32;
fn equ8(u8, u8) int;
fn geu32(u32, u32) u32;
fn gtu32(u32, u32) u32;
fn leu32(u32, u32) u32;
fn ltu32(u32, u32) u32;
fn muxu32(u32, u32, u32) u32;
fn nequ32(u32, u32) u32;
fn notu32(u32) u32;
fn rotl32(u32, int) u32;
fn rotl64(u64, int) u64;
fn rotr32(u32, int) u32;
fn rotr64(u64, int) u64;
fn xor([]u8, []u8, []u8) void;
Functions
fn cmpu32
fn cmpu32(x: u32, y: u32) i32;
Compares 'x' with 'y'. Returns -1 if x < y, 0 if x == y and 1 if x > x.
fn divu32
fn divu32(hi: u32, lo: u32, y: u32) (u32, u32);
Returns the quotient and remainder of (hi, lo) divided by y:
quo = (hi, lo) / y, rem = (hi, lo) % y with the dividend bits' upper
half in parameter hi and the lower half in parameter lo.
Panics for y == 0 (division by zero) or y <= hi (quotient overflow).
fn eq0u32
fn eq0u32(x: i32) u32;
Returns 1 if 'x' is zero or 0 if not.
fn eqslice
fn eqslice(x: []u8, y: []u8) int;
Compare two byte slices in constant time.
Returns 1 if the two slices have the same contents, 0 otherwise.
fn equ32
fn equ32(x: u32, y: u32) u32;
Compares 'x' and 'y'. Returns 1 if they are equal or 0 otherwise.
fn equ8
fn equ8(x: u8, y: u8) int;
Compare two bytes in constant time. Returns 1 if the bytes are the same
value, 0 otherwise.
fn geu32
fn geu32(x: u32, y: u32) u32;
Returns 1 if x >= y and 0 otherwise.
fn gtu32
fn gtu32(x: u32, y: u32) u32;
Returns 1 if x > y and 0 otherwise.
fn leu32
fn leu32(x: u32, y: u32) u32;
Returns 1 if x <= y and 0 otherwise.
fn ltu32
fn ltu32(x: u32, y: u32) u32;
Returns 1 if x < y and 0 otherwise.
fn muxu32
fn muxu32(ctl: u32, x: u32, y: u32) u32;
Returns x if ctl == 1 and y if ctl == 0.
fn nequ32
fn nequ32(x: u32, y: u32) u32;
Returns 1 if x != y and 0 otherwise.
fn notu32
fn notu32(x: u32) u32;
Negates first bit.
fn rotl32
fn rotl32(x: u32, k: int) u32;
Rotates a 32-bit unsigned integer left by k bits. k may be negative to rotate
right instead, or see rotr32.
fn rotl64
fn rotl64(x: u64, k: int) u64;
Rotates a 64-bit unsigned integer left by k bits. k may be negative to rotate
right instead, or see rotr64.
fn rotr32
fn rotr32(x: u32, k: int) u32;
Rotates a 32-bit unsigned integer right by k bits. k may be negative to
rotate left instead, or see rotl32.
fn rotr64
fn rotr64(x: u64, k: int) u64;
Rotates a 64-bit unsigned integer right by k bits. k may be negative to rotate
left instead, or see rotl64.
fn xor
fn xor(dest: []u8, a: []u8, b: []u8) void;
Stores the xor of 'a' and 'b' into 'dest'. All parameters must have the same
length. 'dest' may be the same slice as 'a' and/or 'b'.