crypto

// jda::crypto — Cryptographic primitives

Constants

SHA256_BLOCK  = 64    // bytes per block
SHA256_DIGEST = 32    // bytes in output
SHA1_DIGEST = 20
AES_BLOCK = 16

Structs

Sha256Ctx

struct Sha256Ctx {
    state:   u32[8]          // H0-H7
    count:   u64             // total bytes hashed
    buf:     u8[64]          // partial block
    buf_len: i64
}

Sha1Ctx

struct Sha1Ctx {
    state:   u32[5]
    count:   u64
    buf:     u8[64]
    buf_len: i64
}

AesCtx

struct AesCtx {
    round_keys: u8[240]    // enough for AES-256 (15×16 bytes)
    nr:         i32        // number of rounds: 10 for AES-128, 14 for AES-256
    nk:         i32        // key size in u32 words: 4 or 8
}

Poly1305Ctx

struct Poly1305Ctx {
    r:   u32[5]    // clamped key r (130-bit)
    h:   u32[5]    // accumulator
    pad: u32[4]    // s (pad key)
}

Functions

FunctionDescription
sha256_k
rotr32
sha256_transform
sha256_init
sha256_update
sha256_final
sha256
rotl32
sha1_transform
sha1_init
sha1_update
sha1_final
sha1
hmac_sha256
aes_sbox
xtime
gf_mul
aes_key_expand
aes_add_round_key
aes_sub_bytes
aes_shift_rows
aes_mix_columns
aes_encrypt_block
aes_ctr
aes128_ctr_init
aes256_ctr_init
chacha20_quarter_round
chacha20_block
chacha20_encrypt
poly1305_init
poly1305_mac
chacha20_poly1305_seal
chacha20_poly1305_open
ct_memcmp
hex_encode
base64_encode

Details

sha256_k

fn sha256_k(i: i64) -> u32

rotr32

fn rotr32(x: u32, n: u32) -> u32

sha256_transform

fn sha256_transform(ctx: &Sha256Ctx, blk: &u8)

sha256_init

fn sha256_init(ctx: &Sha256Ctx)

sha256_update

fn sha256_update(ctx: &Sha256Ctx, data: &u8, len: i64)

sha256_final

fn sha256_final(ctx: &Sha256Ctx, out: &u8)

sha256

fn sha256(data: &u8, len: i64, out: &u8)

rotl32

fn rotl32(x: u32, n: u32) -> u32

sha1_transform

fn sha1_transform(ctx: &Sha1Ctx, blk: &u8)

sha1_init

fn sha1_init(ctx: &Sha1Ctx)

sha1_update

fn sha1_update(ctx: &Sha1Ctx, data: &u8, len: i64)

sha1_final

fn sha1_final(ctx: &Sha1Ctx, out: &u8)

sha1

fn sha1(data: &u8, len: i64, out: &u8)

hmac_sha256

fn hmac_sha256(key: &u8, key_len: i64, msg: &u8, msg_len: i64, out: &u8)

aes_sbox

fn aes_sbox(x: u8) -> u8

xtime

fn xtime(x: u8) -> u8

gf_mul

fn gf_mul(a: u8, b: u8) -> u8

aes_key_expand

fn aes_key_expand(ctx: &AesCtx, key: &u8, key_len: i32)

aes_add_round_key

fn aes_add_round_key(state: &u8, rk: &u8)

aes_sub_bytes

fn aes_sub_bytes(state: &u8)

aes_shift_rows

fn aes_shift_rows(state: &u8)

aes_mix_columns

fn aes_mix_columns(state: &u8)

aes_encrypt_block

fn aes_encrypt_block(ctx: &AesCtx, inp: &u8, out: &u8)

aes_ctr

fn aes_ctr(ctx: &AesCtx, nonce: &u8, inp: &u8, len: i64, out: &u8)

aes128_ctr_init

fn aes128_ctr_init(ctx: &AesCtx, key: &u8)

aes256_ctr_init

fn aes256_ctr_init(ctx: &AesCtx, key: &u8)

chacha20_quarter_round

fn chacha20_quarter_round(a: &u32, b: &u32, c: &u32, d: &u32)

chacha20_block

fn chacha20_block(key: &u32, counter: u32, nonce: &u32, out: &u32)

chacha20_encrypt

fn chacha20_encrypt(key: &u8, nonce: &u8, counter: u32,

poly1305_init

fn poly1305_init(ctx: &Poly1305Ctx, key: &u8)

poly1305_mac

fn poly1305_mac(key: &u8, msg: &u8, msg_len: i64, out: &u8)

chacha20_poly1305_seal

fn chacha20_poly1305_seal(key: &u8, nonce: &u8,

chacha20_poly1305_open

fn chacha20_poly1305_open(key: &u8, nonce: &u8,

ct_memcmp

fn ct_memcmp(a: &u8, b: &u8, len: i64) -> i32

hex_encode

fn hex_encode(inp: &u8, len: i64, out: &i8)

base64_encode

fn base64_encode(inp: &u8, in_len: i64, out: &i8) -> i64