crypto::math+x86_64 +linux

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 ccopyu32(ctl: u32, dest: []u32, src: const []u32) void;
fn cmpu32(x: u32, y: u32) i32;
fn divu32(hi: u32, lo: u32, y: u32) (u32, u32);
fn eq0u32(x: u32) u32;
fn eqslice(x: []u8, y: []u8) int;
fn equ32(x: u32, y: u32) u32;
fn equ8(x: u8, y: u8) int;
fn geu32(x: u32, y: u32) u32;
fn gtu32(x: u32, y: u32) u32;
fn leu32(x: u32, y: u32) u32;
fn ltu32(x: u32, y: u32) u32;
fn mulu32(x: u32, y: u32) u64;
fn muxu32(ctl: u32, x: u32, y: u32) u32;
fn nequ32(x: u32, y: u32) u32;
fn notu32(x: u32) u32;
fn rotl32(x: u32, k: int) u32;
fn rotl64(x: u64, k: int) u64;
fn rotr32(x: u32, k: int) u32;
fn rotr64(x: u64, k: int) u64;
fn xor(dest: []u8, a: []u8, b: []u8) void;

Functions

fn ccopyu32[link]

fn ccopyu32(ctl: u32, dest: []u32, src: const []u32) void;

Copies 'src' to 'dest' if 'ctl' == 1

fn cmpu32[link]

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[link]

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[link]

fn eq0u32(x: u32) u32;

Returns 1 if 'x' is zero or 0 if not.

fn eqslice[link]

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[link]

fn equ32(x: u32, y: u32) u32;

Compares 'x' and 'y'. Returns 1 if they are equal or 0 otherwise.

fn equ8[link]

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[link]

fn geu32(x: u32, y: u32) u32;

Returns 1 if x >= y and 0 otherwise.

fn gtu32[link]

fn gtu32(x: u32, y: u32) u32;

Returns 1 if x > y and 0 otherwise.

fn leu32[link]

fn leu32(x: u32, y: u32) u32;

Returns 1 if x <= y and 0 otherwise.

fn ltu32[link]

fn ltu32(x: u32, y: u32) u32;

Returns 1 if x < y and 0 otherwise.

fn mulu32[link]

fn mulu32(x: u32, y: u32) u64;

Multiplies two u32 and returns result as u64.

fn muxu32[link]

fn muxu32(ctl: u32, x: u32, y: u32) u32;

Returns x if ctl == 1 and y if ctl == 0.

fn nequ32[link]

fn nequ32(x: u32, y: u32) u32;

Returns 1 if x != y and 0 otherwise.

fn notu32[link]

fn notu32(x: u32) u32;

Negates first bit.

fn rotl32[link]

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[link]

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[link]

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[link]

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[link]

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'.