commit 7bb816f3cadd4288b23a06ce306fdebcbce80d9d parent 7bc46f6099382a5ca3f2323d1611ffe8c9a90998 Author: Armin Preiml <apreiml@strohwolke.at> Date: Sat, 19 Aug 2023 20:36:47 +0200 crypto: use SZ as suffix for sizes To convert your projects you could use: find . -name "*.ha" -exec sed -i 's/SIZE/SZ/g' {} \; Signed-off-by: Armin Preiml <apreiml@strohwolke.at> Diffstat:
43 files changed, 283 insertions(+), 283 deletions(-)
diff --git a/crypto/aes/+test/gcm.ha b/crypto/aes/+test/gcm.ha @@ -612,7 +612,7 @@ const gcmtestcases: []gcmtestcase = [ defer io::close(&gstream)!; io::writeall(&gstream, t.plain)!; - let tag: [cipher::GCMTAGSIZE]u8 = [0...]; + let tag: [cipher::GCMTAGSZ]u8 = [0...]; cipher::gcm_seal(&gstream, tag); assert(bytes::equal(t.cipher, result)); @@ -676,7 +676,7 @@ const gcmtestcases: []gcmtestcase = [ io::writeall(&gstream, result)!; - let tag: [cipher::GCMTAGSIZE]u8 = [0...]; + let tag: [cipher::GCMTAGSZ]u8 = [0...]; cipher::gcm_seal(&gstream, tag); assert(bytes::equal(t.cipher, result)); assert(bytes::equal(t.tag, tag)); diff --git a/crypto/aes/+x86_64/ni.ha b/crypto/aes/+x86_64/ni.ha @@ -6,10 +6,10 @@ def EXPKEYLEN128: size = 176; def EXPKEYLEN192: size = 208; def EXPKEYLEN256: size = 240; -def X86NI_EXPKEYSIZE: size = 480; +def X86NI_EXPKEYSZ: size = 480; const x86ni_vtable: cipher::blockvtable = cipher::blockvtable { - blocksz = BLOCKSIZE, + blocksz = BLOCKSZ, nparallel = 1, encrypt = &x86ni_encrypt, decrypt = &x86ni_decrypt, @@ -46,7 +46,7 @@ fn x86ni_init(b: *block, key: []u8) void = { }; fn x86ni_encrypt(b: *cipher::block, dest: []u8, src: []u8) void = { - assert(len(dest) == len(src) && len(dest) % BLOCKSIZE == 0); + assert(len(dest) == len(src) && len(dest) % BLOCKSZ == 0); let b = b: *block; const expkeylen = (b.rounds + 1) << 4; let enc = b.expkey[..expkeylen]; @@ -54,13 +54,13 @@ fn x86ni_encrypt(b: *cipher::block, dest: []u8, src: []u8) void = { // XXX loop could be done in assembly for (len(src) > 0) { x86ni_asencrypt(enc, dest, src); - src = src[BLOCKSIZE..]; - dest = dest[BLOCKSIZE..]; + src = src[BLOCKSZ..]; + dest = dest[BLOCKSZ..]; }; }; fn x86ni_decrypt(b: *cipher::block, dest: []u8, src: []u8) void = { - assert(len(dest) == len(src) && len(dest) % BLOCKSIZE == 0); + assert(len(dest) == len(src) && len(dest) % BLOCKSZ == 0); let b = b: *block; const expkeylen = (b.rounds + 1) << 4; let dec = b.expkey[EXPKEYLEN256..]; @@ -68,8 +68,8 @@ fn x86ni_decrypt(b: *cipher::block, dest: []u8, src: []u8) void = { // XXX loop could be done in assembly for (len(src) > 0) { x86ni_asdecrypt(dec[..expkeylen], dest, src); - src = src[BLOCKSIZE..]; - dest = dest[BLOCKSIZE..]; + src = src[BLOCKSZ..]; + dest = dest[BLOCKSZ..]; }; }; diff --git a/crypto/aes/aes+x86_64.ha b/crypto/aes/aes+x86_64.ha @@ -2,7 +2,7 @@ // (c) 2022 Armin Preiml <apreiml@strohwolke.at> use crypto::cipher; -def MAXEXPKEYSIZE: size = CT64_EXPKEYSIZE; +def MAXEXPKEYSZ: size = CT64_EXPKEYSZ; def MAXNPARALLEL: size = CT64_NPARALLEL; let rtvtable: *cipher::blockvtable = &ct64_vtable; diff --git a/crypto/aes/aes.ha b/crypto/aes/aes.ha @@ -2,7 +2,7 @@ // (c) 2022 Armin Preiml <apreiml@strohwolke.at> use crypto::cipher; -def MAXEXPKEYSIZE: size = CT64_EXPKEYSIZE; +def MAXEXPKEYSZ: size = CT64_EXPKEYSZ; def MAXNPARALLEL: size = CT64_NPARALLEL; const rtvtable: *cipher::blockvtable = &ct64_vtable; diff --git a/crypto/aes/aes_ct64.ha b/crypto/aes/aes_ct64.ha @@ -32,7 +32,7 @@ use crypto::cipher::{blocksz,nparallel}; use crypto::math; use endian; -def CT64_EXPKEYSIZE: size = 960; +def CT64_EXPKEYSZ: size = 960; def CT64_NPARALLEL: size = 4; // Returns an AES [[crypto::cipher::block]] cipher implementation optimized for @@ -48,7 +48,7 @@ fn ct64() block = block { }; const ct64_vtable: cipher::blockvtable = cipher::blockvtable { - blocksz = BLOCKSIZE, + blocksz = BLOCKSZ, nparallel = CT64_NPARALLEL, encrypt = &aes_ct64_encrypt, decrypt = &aes_ct64_decrypt, diff --git a/crypto/aes/block.ha b/crypto/aes/block.ha @@ -4,19 +4,19 @@ use bytes; use crypto::cipher; // The block size used by the AES algorithm. -export def BLOCKSIZE: size = 16; +export def BLOCKSZ: size = 16; // Size of the buffer used for [[crypto::cipher::cbc_encryptor]] and // [[crypto::cipher::cbc_decryptor]]. -export def CBC_BUFSIZE: size = BLOCKSIZE * 2; +export def CBC_BUFSZ: size = BLOCKSZ * 2; // Size of the buffer used for [[crypto::cipher::ctr]]. -export def CTR_BUFSIZE: size = BLOCKSIZE * (MAXNPARALLEL + 1); +export def CTR_BUFSZ: size = BLOCKSZ * (MAXNPARALLEL + 1); export type block = struct { vtable: cipher::block, rounds: u32, - expkey: [MAXEXPKEYSIZE]u8, + expkey: [MAXEXPKEYSZ]u8, }; // Returns an AES [[crypto::cipher::block]] cipher implementation that has diff --git a/crypto/aes/cbc+test.ha b/crypto/aes/cbc+test.ha @@ -38,7 +38,7 @@ use bytes; ]; let result: [64]u8 = [0...]; - let buf: [CBC_BUFSIZE]u8 = [0...]; + let buf: [CBC_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); @@ -89,7 +89,7 @@ use bytes; ]; let result: [64]u8 = plain; - let buf: [CBC_BUFSIZE]u8 = [0...]; + let buf: [CBC_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); diff --git a/crypto/aes/ctr+test.ha b/crypto/aes/ctr+test.ha @@ -29,7 +29,7 @@ use memio; ]; let result: [16]u8 = [0...]; - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let resultbuf = memio::fixed(result); let b = ct64(); @@ -42,7 +42,7 @@ use memio; assert(bytes::equal(cipher, result)); io::close(&ctr)!; - const zero: [CTR_BUFSIZE]u8 = [0...]; + const zero: [CTR_BUFSZ]u8 = [0...]; const bsz = cipher::blocksz(&b); assert(bytes::equal(ctr.xorbuf, zero[bsz..])); @@ -83,7 +83,7 @@ use memio; let result: [18]u8 = [0...]; let resultbuf = memio::fixed(result); - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); @@ -134,7 +134,7 @@ use memio; let result: [80]u8 = [0...]; let resultbuf = memio::fixed(result); - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); @@ -195,7 +195,7 @@ use memio; let result: [80]u8 = [0...]; let resultbuf = memio::fixed(result); - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); @@ -244,7 +244,7 @@ use memio; ct64_init(&b, key); defer cipher::finish(&b); - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let resultbuf = memio::fixed(result); let ctr = cipher::ctr(&resultbuf, &b, iv[..], buf[..]); defer io::close(&ctr)!; @@ -399,7 +399,7 @@ fn errwriter(out: io::handle, limit: size, err: io::error) err_stream = { let result: [80]u8 = [0...]; let resultbuf = memio::fixed(result); let errw = errwriter(&resultbuf, 20, errors::again); - let buf: [CTR_BUFSIZE]u8 = [0...]; + let buf: [CTR_BUFSZ]u8 = [0...]; let b = ct64(); ct64_init(&b, key); diff --git a/crypto/aes/rt+test.ha b/crypto/aes/rt+test.ha @@ -10,7 +10,7 @@ use bytes; 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c, ]; - const zero: [CT64_EXPKEYSIZE]u8 = [0...]; + const zero: [CT64_EXPKEYSZ]u8 = [0...]; let block = aes(); init(&block, key); diff --git a/crypto/aes/xts/xts.ha b/crypto/aes/xts/xts.ha @@ -7,7 +7,7 @@ use crypto::cipher; export type block = struct { b1: aes::block, b2: aes::block, - x: [aes::BLOCKSIZE]u8, + x: [aes::BLOCKSZ]u8, }; // Creates a AES-XTS instance. Must be initialized with [[init]] and always be @@ -32,11 +32,11 @@ export fn init(b: *block, key: []u8) void = { def GF_128_FDBK: u8 = 0x87; // Encrypts a block given its 'sector' number. The block must be a multiple of -// [[crypto::aes::BLOCKSIZE]] (16 bytes) in length. +// [[crypto::aes::BLOCKSZ]] (16 bytes) in length. export fn encrypt(b: *block, dest: []u8, src: []u8, sector: u64) void = { - assert(len(src) == len(dest) && len(src) % aes::BLOCKSIZE == 0); + assert(len(src) == len(dest) && len(src) % aes::BLOCKSZ == 0); - let tweak: [aes::BLOCKSIZE]u8 = [0...]; + let tweak: [aes::BLOCKSZ]u8 = [0...]; let carryin: u8 = 0; let carryout: u8 = 0; @@ -48,20 +48,20 @@ export fn encrypt(b: *block, dest: []u8, src: []u8, sector: u64) void = { cipher::encrypt(&b.b2, tweak, tweak); let i = 0z; - for (i + aes::BLOCKSIZE <= len(src); i += aes::BLOCKSIZE) { - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (i + aes::BLOCKSZ <= len(src); i += aes::BLOCKSZ) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { b.x[j] = src[i + j] ^ tweak[j]; }; cipher::encrypt(&b.b1, b.x, b.x); - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { dest[i + j] = b.x[j] ^ tweak[j]; }; // multiply primitive carryin = 0; - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { carryout = (tweak[j] >> 7) & 1; tweak[j] = ((tweak[j] << 1) + carryin) & 0xff; carryin = carryout; @@ -75,9 +75,9 @@ export fn encrypt(b: *block, dest: []u8, src: []u8, sector: u64) void = { // Decrypts a block given its 'sector' number. export fn decrypt(b: *block, dest: []u8, src: []u8, sector: u64) void = { - assert(len(src) == len(dest) && len(src) % aes::BLOCKSIZE == 0); + assert(len(src) == len(dest) && len(src) % aes::BLOCKSZ == 0); - let tweak: [aes::BLOCKSIZE]u8 = [0...]; + let tweak: [aes::BLOCKSZ]u8 = [0...]; let carryin: u8 = 0; let carryout: u8 = 0; @@ -89,21 +89,21 @@ export fn decrypt(b: *block, dest: []u8, src: []u8, sector: u64) void = { cipher::encrypt(&b.b2, tweak, tweak); let i = 0z; - for (i + aes::BLOCKSIZE <= len(src); i += aes::BLOCKSIZE) { - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (i + aes::BLOCKSZ <= len(src); i += aes::BLOCKSZ) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { b.x[j] = src[i + j] ^ tweak[j]; }; cipher::decrypt(&b.b1, b.x, b.x); - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { dest[i + j] = b.x[j] ^ tweak[j]; }; // multiply primitive carryin = 0; - for (let j = 0z; j < aes::BLOCKSIZE; j += 1) { + for (let j = 0z; j < aes::BLOCKSZ; j += 1) { carryout = (tweak[j] >> 7) & 1; tweak[j] = ((tweak[j] << 1) + carryin) & 0xff; carryin = carryout; diff --git a/crypto/argon2/+test.ha b/crypto/argon2/+test.ha @@ -41,7 +41,7 @@ use strings; let data: [12]u8 = [4...]; let result: [32]u8 = [0...]; - let mem: []u64 = alloc([0...], 32z * BLOCKSIZE); + let mem: []u64 = alloc([0...], 32z * BLOCKSZ); defer free(mem); let expected: [_]u8 = [ @@ -74,7 +74,7 @@ use strings; let data: [12]u8 = [4...]; let result: [32]u8 = [0...]; - let mem: []u64 = alloc([0...], 32z * BLOCKSIZE); + let mem: []u64 = alloc([0...], 32z * BLOCKSZ); defer free(mem); let expected: [_]u8 = [ @@ -106,7 +106,7 @@ use strings; let data: [12]u8 = [4...]; let result: [32]u8 = [0...]; - let mem: []u64 = alloc([0...], 32z * BLOCKSIZE); + let mem: []u64 = alloc([0...], 32z * BLOCKSZ); defer free(mem); let expected: [_]u8 = [ diff --git a/crypto/argon2/argon2.ha b/crypto/argon2/argon2.ha @@ -15,11 +15,11 @@ use types; export def VERSION: u8 = 0x13; // Number of u64 elements of one block. -export def BLOCKSIZE: u32 = 128; +export def BLOCKSZ: u32 = 128; def SLICES: size = 4; -type block64 = [BLOCKSIZE]u64; +type block64 = [BLOCKSZ]u64; const zeroblock: block64 = [0...]; @@ -51,9 +51,9 @@ type mode = enum { // number of 1024-byte blocks the implementation shall allocate for you. If the // caller wants to manage the allocation itself, provide a []u8 instead. The // length of this slice must be at least 8 times the value of 'parallel' in -// blocks, and must be a multiple of [[BLOCKSIZE]]. To have the implementation +// blocks, and must be a multiple of [[BLOCKSZ]]. To have the implementation // allocate 64 KiB, set 'mem' to 64. To use the same amount of caller-provided -// memory, provide a slice of length 64 * [[BLOCKSIZE]]. +// memory, provide a slice of length 64 * [[BLOCKSZ]]. export type conf = struct { mem: (u32 | []u64), parallel: u32, @@ -165,14 +165,14 @@ fn argon2( let initmemsize = 0u32; let mem: []u64 = match (cfg.mem) { case let mem: []u64 => - assert(len(mem) >= 8 * cfg.parallel * BLOCKSIZE - && len(mem) % BLOCKSIZE == 0 - && len(mem) / BLOCKSIZE <= types::U32_MAX); - initmemsize = (len(mem) / BLOCKSIZE): u32; + assert(len(mem) >= 8 * cfg.parallel * BLOCKSZ + && len(mem) % BLOCKSZ == 0 + && len(mem) / BLOCKSZ <= types::U32_MAX); + initmemsize = (len(mem) / BLOCKSZ): u32; // round down memory to nearest multiple of 4 times parallel const memsize = len(mem) - len(mem) - % (4 * cfg.parallel * BLOCKSIZE); + % (4 * cfg.parallel * BLOCKSZ); yield mem[..memsize]; case let memsize: u32 => assert(memsize >= 8 * cfg.parallel @@ -180,13 +180,13 @@ fn argon2( initmemsize = memsize; const memsize = memsize - memsize % (4 * cfg.parallel); - yield alloc([0...], memsize * BLOCKSIZE): []u64; + yield alloc([0...], memsize * BLOCKSZ): []u64; }; let h0: [64]u8 = [0...]; inithash(&h0, len(dest): u32, password, salt, cfg, mode, initmemsize); - const memsize = (len(mem) / BLOCKSIZE): u32; + const memsize = (len(mem) / BLOCKSZ): u32; const cols = 4 * (memsize / (4 * cfg.parallel)); let ctx = context { rows = cfg.parallel, @@ -241,12 +241,12 @@ fn argon2( }; fn block(ctx: *context, i: size, j: size) []u64 = { - let index = (ctx.cols * i + j) * BLOCKSIZE; - return ctx.mem[index..index + BLOCKSIZE]; + let index = (ctx.cols * i + j) * BLOCKSZ; + return ctx.mem[index..index + BLOCKSZ]; }; fn blocku8(ctx: *context, i: size, j: size) []u8 = { - return (block(ctx, i, j): *[*]u8)[..BLOCKSIZE * size(u64)]; + return (block(ctx, i, j): *[*]u8)[..BLOCKSZ * size(u64)]; }; fn refblock(cfg: *conf, ctx: *context, seed: u64, i: size, j: size) []u64 = { @@ -397,7 +397,7 @@ fn segproc(cfg: *conf, ctx: *context, i: size, slice: size) void = { ctx.seedsinit[0] = ctx.pass; ctx.seedsinit[1] = i; ctx.seedsinit[2] = slice; - ctx.seedsinit[3] = len(ctx.mem) / BLOCKSIZE; + ctx.seedsinit[3] = len(ctx.mem) / BLOCKSZ; ctx.seedsinit[4] = cfg.passes; ctx.seedsinit[5] = ctx.mode: u64; ctx.seedsinit[6] = 0; @@ -432,14 +432,14 @@ fn segproc(cfg: *conf, ctx: *context, i: size, slice: size) void = { const seed: u64 = if (dmodeseed) { yield prev[0]; } else { - if (b % BLOCKSIZE == 0) { + if (b % BLOCKSZ == 0) { ctx.seedsinit[6] += 1; compress(ctx.seedblock, ctx.seedsinit, zeroblock, false); compress(ctx.seedblock, ctx.seedblock, zeroblock, false); }; - yield ctx.seedblock[b % BLOCKSIZE]; + yield ctx.seedblock[b % BLOCKSZ]; }; let ref = refblock(cfg, ctx, seed, i, j); diff --git a/crypto/bcrypt/bcrypt.ha b/crypto/bcrypt/bcrypt.ha @@ -46,16 +46,16 @@ export def DEFAULT_COST: uint = 10; def MAJOR: u8 = '2'; def MINOR: u8 = 'a'; -def MAX_SALT_SIZE: size = 16; -def MAX_CRYPTED_HASH_SIZE: size = 23; -def ENCODED_SALT_SIZE: size = 22; -def ENCODED_HASH_SIZE: size = 31; -def MIN_HASH_SIZE: size = 59; +def MAX_SALT_SZ: size = 16; +def MAX_CRYPTED_HASH_SZ: size = 23; +def ENCODED_SALT_SZ: size = 22; +def ENCODED_HASH_SZ: size = 31; +def MIN_HASH_SZ: size = 59; // Hashes a password using the bcrypt algorithm. The caller must free the return // value. export fn generate(password: []u8, cost: uint) []u8 = { - let salt: [MAX_SALT_SIZE]u8 = [0...]; + let salt: [MAX_SALT_SZ]u8 = [0...]; random::buffer(salt); const hash = hash_password(password, salt, cost)!; defer finish(&hash); @@ -107,7 +107,7 @@ fn hash_password( }; fn load(input: []u8) (hash | errors::invalid) = { - if (len(input) < MIN_HASH_SIZE || input[0] != '$') { + if (len(input) < MIN_HASH_SZ || input[0] != '$') { return errors::invalid; }; let hash = hash { ... }; @@ -138,8 +138,8 @@ fn load(input: []u8) (hash | errors::invalid) = { return errors::invalid; }; - hash.salt = alloc(data[..ENCODED_SALT_SIZE]...); - hash.hash = alloc(data[ENCODED_SALT_SIZE..]...); + hash.salt = alloc(data[..ENCODED_SALT_SZ]...); + hash.hash = alloc(data[ENCODED_SALT_SZ..]...); return hash; }; @@ -170,7 +170,7 @@ fn bcrypt(password: []u8, salt: []u8, cost: uint) ([]u8 | errors::invalid) = { }; // Bug compat: only encode 32 bytes - const enc = b64_encode(state[..MAX_CRYPTED_HASH_SIZE]); + const enc = b64_encode(state[..MAX_CRYPTED_HASH_SZ]); return enc; }; diff --git a/crypto/bigint/arithm.ha b/crypto/bigint/arithm.ha @@ -32,7 +32,7 @@ export fn add(a: []word, b: const []word, ctl: u32) u32 = { let carry: u32 = 0; for (let i = 1z; i <= l; i += 1) { const n: u32 = a[i] + b[i] + carry; - carry = n >> WORD_BITSIZE; + carry = n >> WORD_BITSZ; a[i] = muxu32(ctl, n & WORD_BITMASK, a[i]): word; }; return carry; @@ -49,7 +49,7 @@ export fn sub(a: []word, b: const []word, do: u32) u32 = { let carry: u32 = 0; for (let i = 1z; i <= l; i += 1) { let n: u32 = a[i] - b[i] - carry; - carry = n >> WORD_BITSIZE; + carry = n >> WORD_BITSZ; a[i] = muxu32(do, n & WORD_BITMASK, a[i]): word; }; return carry; @@ -62,9 +62,9 @@ export fn decrodd(x: []word) void = { }; // Right-shift an integer 'x' by 'count'. The shift amount must be less than -// [[WORD_BITSIZE]]. +// [[WORD_BITSZ]]. export fn rshift(x: []word, count: word) void = { - assert(ltu32(count, WORD_BITSIZE) == 1); + assert(ltu32(count, WORD_BITSZ) == 1); const l = ewordlen(x); if (l == 0) { @@ -74,13 +74,13 @@ export fn rshift(x: []word, count: word) void = { let r = x[1] >> count; for (let i = 2z; i <= l; i += 1) { const w = x[i]; - x[i - 1] = (w << (WORD_BITSIZE - count) | r) & WORD_BITMASK; + x[i - 1] = (w << (WORD_BITSZ - count) | r) & WORD_BITMASK; r = w >> count; }; x[l] = r; }; -// Multiply 'x' by 2^WORD_BITSIZE and then add integer 'z', modulo 'm'. This +// Multiply 'x' by 2^WORD_BITSZ and then add integer 'z', modulo 'm'. This // function assumes that 'x' and 'm' have the same announced bit length, and the // announced bit length of 'm' matches its true bit length. // @@ -100,15 +100,15 @@ fn muladd_small(x: []word, z: word, m: const []word) void = { return; }; - if (m_bitlen <= WORD_BITSIZE) { + if (m_bitlen <= WORD_BITSZ) { hi = x[1] >> 1; - const lo = (x[1] << WORD_BITSIZE) | z; + const lo = (x[1] << WORD_BITSZ) | z; x[1] = divu32(hi, lo, m[1]).1: word; return; }; let mlen = ewordlen(m); - let mblr = m_bitlen & WORD_BITSIZE: word; + let mblr = m_bitlen & WORD_BITSZ: word; // Principle: we estimate the quotient (x*2^31+z)/m by // doing a 64/32 division with the high words. @@ -144,13 +144,13 @@ fn muladd_small(x: []word, z: word, m: const []word) void = { a1 = x[mlen]; b0 = m[mlen]; } else { - a0 = ((x[mlen] << (WORD_BITSIZE: word - mblr)) + a0 = ((x[mlen] << (WORD_BITSZ: word - mblr)) | (x[mlen - 1] >> mblr)) & WORD_BITMASK; x[2..mlen+1] = x[1..mlen]; x[1] = z; - a1 = ((x[mlen] << (WORD_BITSIZE: word - mblr)) + a1 = ((x[mlen] << (WORD_BITSZ: word - mblr)) | (x[mlen - 1] >> mblr)) & WORD_BITMASK; - b0 = ((m[mlen] << (WORD_BITSIZE: word - mblr)) + b0 = ((m[mlen] << (WORD_BITSZ: word - mblr)) | (m[mlen - 1] >> mblr)) & WORD_BITMASK; }; @@ -182,11 +182,11 @@ fn muladd_small(x: []word, z: word, m: const []word) void = { for (let u = 1z; u <= mlen; u += 1) { const mw = m[u]; const zl = mul31(mw, q) + cc; - cc = (zl >> WORD_BITSIZE): word; + cc = (zl >> WORD_BITSZ): word; const zw = zl: word & WORD_BITMASK; const xw = x[u]; let nxw = xw - zw; - cc += nxw >> WORD_BITSIZE; + cc += nxw >> WORD_BITSZ; nxw &= WORD_BITMASK; x[u] = nxw; tb = muxu32(equ32(nxw, mw), tb, gtu32(nxw, mw)); @@ -212,7 +212,7 @@ fn muladd_small(x: []word, z: word, m: const []word) void = { fn mul31(x: u32, y: u32) u64 = x: u64 * y: u64; fn mul31_lo(x: u32, y: u32) u32 = (x: u32 * y: u32) & 0x7FFFFFFF; -// Calculate "m0i" which is equal to -(1/m0) mod 2^WORD_BITSIZE, where m0 is the +// Calculate "m0i" which is equal to -(1/m0) mod 2^WORD_BITSZ, where m0 is the // least significant value word of m: []word. fn ninv31(m0: u32) u32 = { let y: u32 = 2 - m0; @@ -223,7 +223,7 @@ fn ninv31(m0: u32) u32 = { return muxu32(m0 & 1, -y, 0) & 0x7FFFFFFF; }; -// Calculates "m0i" which is equal to -(1/'m0') mod 2^WORD_BITSIZE. 'm0' is the +// Calculates "m0i" which is equal to -(1/'m0') mod 2^WORD_BITSZ. 'm0' is the // the first significant word of a big integer, which is the word at index 1. export fn ninv(m0: word) word = ninv31(m0); @@ -245,10 +245,10 @@ export fn mulacc(d: []word, a: const []word, b: const []word) void = { // We want to add the two bit lengths, but these are encoded, // which requires some extra care. - const dl: u32 = (a[0] & WORD_BITSIZE) + (b[0] & WORD_BITSIZE); + const dl: u32 = (a[0] & WORD_BITSZ) + (b[0] & WORD_BITSZ); const dh: u32 = (a[0] >> WORD_SHIFT) + (b[0] >> WORD_SHIFT); d[0] = (dh << WORD_SHIFT) + dl - + (~(dl - WORD_BITSIZE): u32 >> 31); + + (~(dl - WORD_BITSZ): u32 >> 31); for (let u = 0z; u < blen; u += 1) { // Carry always fits on 31 bits; we want to keep it in a @@ -263,7 +263,7 @@ export fn mulacc(d: []word, a: const []word, b: const []word) void = { for (let v = 0z; v < alen; v += 1) { let z: u64 = d[1 + u + v]: u64 + mul31(f, a[1 + v]) + cc; - cc = z >> WORD_BITSIZE; + cc = z >> WORD_BITSZ; d[1 + u + v] = z: word & WORD_BITMASK; }; d[1 + u + alen] = cc: word; diff --git a/crypto/bigint/encoding.ha b/crypto/bigint/encoding.ha @@ -24,9 +24,9 @@ use crypto::math::*; // Minimal required words to encode 'x' into an []word. To statically allocate // resources, following expression may be used: // -// ((number_of_bits + WORD_BITSIZE - 1) / WORD_BITSIZE) + 1 +// ((number_of_bits + WORD_BITSZ - 1) / WORD_BITSZ) + 1 export fn encodelen(x: []u8) size = { - return (((len(x) * 8) + WORD_BITSIZE - 1) / WORD_BITSIZE) + 1; + return (((len(x) * 8) + WORD_BITSZ - 1) / WORD_BITSZ) + 1; }; // Encode 'src' from its big-endian unsigned encoding into the internal @@ -43,9 +43,9 @@ export fn encode(dest: []word, src: const []u8) void = { acc |= (src[i] << accbits); accbits += 8; - if (accbits >= WORD_BITSIZE) { + if (accbits >= WORD_BITSZ) { dest[didx] = (acc & WORD_BITMASK): word; - accbits -= WORD_BITSIZE; + accbits -= WORD_BITSZ; acc = src[i] >> (8 - accbits); didx += 1; }; @@ -106,7 +106,7 @@ fn ebitlen(x: const []word) u32 = { // words that are used to represent the actual value. Eg. the number 7 will have // an effective word length of 1, no matter of len(x). fn ewordlen(x: const []word) u32 = { - return (x[0] + WORD_BITSIZE) >> WORD_SHIFT; + return (x[0] + WORD_BITSZ) >> WORD_SHIFT; }; // Decode 'src' into a big-endian unsigned byte array. The caller must ensure @@ -122,7 +122,7 @@ export fn decode(dest: []u8, src: const []word) void = { acc |= ((src[sidx]: u64) << accbits: u64): u64; sidx += 1; }; - accbits += WORD_BITSIZE; + accbits += WORD_BITSZ; }; dest[i] = acc: u8; acc >>= 8; @@ -134,9 +134,9 @@ export fn decode(dest: []u8, src: const []word) void = { // // For static allocation following expression may be used: // -// ((len(src) - 1) * WORD_BITSIZE + 7) / 8 +// ((len(src) - 1) * WORD_BITSZ + 7) / 8 export fn decodelen(src: const []word) size = { - return ((len(src) - 1) * WORD_BITSIZE + 7) / 8; + return ((len(src) - 1) * WORD_BITSZ + 7) / 8; }; // Encodes an integer from its big-endian unsigned encoding. 'src' must be lower @@ -192,9 +192,9 @@ export fn encodemod(dest: []word, src: const []u8, m: const []word) u32 = { }; acc |= (b << acc_len); acc_len += 8; - if (acc_len >= WORD_BITSIZE) { + if (acc_len >= WORD_BITSZ) { const xw: u32 = acc & WORD_BITMASK; - acc_len -= WORD_BITSIZE; + acc_len -= WORD_BITSZ; acc = b >> (8 - acc_len); if (v <= mlen) { if (pass == 1) { @@ -249,7 +249,7 @@ export fn encodereduce(dest: []word, src: const []u8, m: const []word) void = { // First decode directly as many bytes as possible. This requires // computing the actual bit length. let m_rbitlen = m_ebitlen >> WORD_SHIFT; - m_rbitlen = (m_ebitlen & WORD_BITSIZE) + m_rbitlen = (m_ebitlen & WORD_BITSZ) + (m_rbitlen << WORD_SHIFT) - m_rbitlen; const mblen: size = (m_rbitlen + 7) >> 3; let k: size = mblen - 1; @@ -283,7 +283,7 @@ export fn encodereduce(dest: []word, src: const []u8, m: const []word) void = { // be able to inject these bits as a full 31-bit word. if (acc_len != 0) { acc = (acc | (dest[1] << acc_len)) & WORD_BITMASK; - rshift(dest, WORD_BITSIZE - acc_len); + rshift(dest, WORD_BITSZ - acc_len); muladd_small(dest, acc, m); }; }; diff --git a/crypto/bigint/types.ha b/crypto/bigint/types.ha @@ -5,7 +5,7 @@ export type word = u32; // Number of bits that are used for storing the value in a word. -export def WORD_BITSIZE: u32 = 31; +export def WORD_BITSZ: u32 = 31; // Bitmask for bits that are used for storing the value in a word. export def WORD_BITMASK: word = 0x7fffffff; diff --git a/crypto/blake2b/blake2b.ha b/crypto/blake2b/blake2b.ha @@ -13,7 +13,7 @@ def R2: int = 24; def R3: int = 16; def R4: int = 63; def r: u64 = 12; -def BSIZE: size = 128; +def BSZ: size = 128; const iv: [8]u64 = [ 0x6A09E667F3BCC908, 0xBB67AE8584CAA73B, @@ -42,7 +42,7 @@ export type digest = struct { h: [8]u64, tlow: u64, thigh: u64, - block: [BSIZE]u8, + block: [BSZ]u8, blocklen: size, }; @@ -64,7 +64,7 @@ export fn blake2b(key: []u8, sz: size) digest = { assert(len(key) <= 64); let h = iv; h[0] ^= 0x01010000 ^ (len(key) << 8) ^ sz; - let keyblock: [BSIZE]u8 = [0...]; + let keyblock: [BSZ]u8 = [0...]; keyblock[..len(key)] = key; return digest { stream = &blake2b_vtable, @@ -74,7 +74,7 @@ export fn blake2b(key: []u8, sz: size) digest = { tlow = 0, thigh = 0, block = keyblock, - blocklen = if (len(key) > 0) BSIZE else 0, + blocklen = if (len(key) > 0) BSZ else 0, ... }; }; @@ -85,12 +85,12 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { let length = len(buf); let buf = buf[..]; - for (h.blocklen + len(buf) > BSIZE) { - const n = BSIZE - h.blocklen; + for (h.blocklen + len(buf) > BSZ) { + const n = BSZ - h.blocklen; h.block[h.blocklen..h.blocklen + n] = buf[..n]; buf = buf[n..]; - h.tlow += BSIZE; + h.tlow += BSZ; if (h.tlow < n: u64) h.thigh += 1; compress(&h.h, &h.block, h.tlow, h.thigh, false); @@ -111,9 +111,9 @@ fn sum(h: *hash::hash, buf: []u8) void = { if (h.tlow < h.blocklen: u64) h.thigh += 1; // Padding - let tmp: [BSIZE]u8 = [0...]; - h.block[h.blocklen..BSIZE] = tmp[..BSIZE - h.blocklen]; - h.blocklen = BSIZE; + let tmp: [BSZ]u8 = [0...]; + h.block[h.blocklen..BSZ] = tmp[..BSZ - h.blocklen]; + h.blocklen = BSZ; compress(&h.h, &h.block, h.tlow, h.thigh, true); @@ -123,7 +123,7 @@ fn sum(h: *hash::hash, buf: []u8) void = { }; // Compression function F -fn compress(h: *[8]u64, b: *[BSIZE]u8, tlow: u64, thigh: u64, f: bool) void = { +fn compress(h: *[8]u64, b: *[BSZ]u8, tlow: u64, thigh: u64, f: bool) void = { let v: [16]u64 = [0...]; v[..8] = h[..]; v[8..] = iv; diff --git a/crypto/blowfish/blowfish.ha b/crypto/blowfish/blowfish.ha @@ -7,7 +7,7 @@ use crypto::cipher; use endian; // The block size of the Blowfish cipher in bytes. -export def BLOCKSIZE: size = 8; +export def BLOCKSZ: size = 8; export type state = struct { block: cipher::block, @@ -19,7 +19,7 @@ export type state = struct { }; const vtable: cipher::blockvtable = cipher::blockvtable { - blocksz = BLOCKSIZE, + blocksz = BLOCKSZ, nparallel = 1, encrypt = &block_encrypt, decrypt = &block_decrypt, diff --git a/crypto/chacha/chacha20.ha b/crypto/chacha/chacha20.ha @@ -7,16 +7,16 @@ use endian; use io; // Size of a Chacha key, in bytes. -export def KEYSIZE: size = 32; +export def KEYSZ: size = 32; // Size of the XChacha20 nonce, in bytes. -export def XNONCESIZE: size = 24; +export def XNONCESZ: size = 24; // Size of the Chacha20 nonce, in bytes. -export def NONCESIZE: size = 12; +export def NONCESZ: size = 12; // The block size of the Chacha cipher in bytes. -export def BLOCKSIZE: size = 64; +export def BLOCKSZ: size = 64; def ROUNDS: size = 20; const magic: [4]u32 = [0x61707865, 0x3320646e, 0x79622d32, 0x6b206574]; @@ -26,7 +26,7 @@ const magic: [4]u32 = [0x61707865, 0x3320646e, 0x79622d32, 0x6b206574]; export type stream = struct { cipher::xorstream, state: [16]u32, - xorbuf: [BLOCKSIZE]u8, + xorbuf: [BLOCKSZ]u8, xorused: size, rounds: size, }; @@ -41,7 +41,7 @@ export fn chacha20() stream = { keybuf = &keybuf, advance = &advance, finish = &finish, - xorused = BLOCKSIZE, + xorused = BLOCKSZ, rounds = ROUNDS, ... }; @@ -54,8 +54,8 @@ export fn chacha20_init( key: []u8, nonce: []u8 ) void = { - assert(len(key) == KEYSIZE); - assert(len(nonce) == NONCESIZE); + assert(len(key) == KEYSZ); + assert(len(nonce) == NONCESZ); s.h = h; @@ -83,13 +83,13 @@ export fn xchacha20_init( key: []u8, nonce: []u8 ) void = { - assert(len(key) == KEYSIZE); - assert(len(nonce) == XNONCESIZE); + assert(len(key) == KEYSZ); + assert(len(nonce) == XNONCESZ); let dkey: [32]u8 = [0...]; hchacha20(&dkey, key, nonce[..16]); - let dnonce: [NONCESIZE]u8 = [0...]; + let dnonce: [NONCESZ]u8 = [0...]; dnonce[4..] = nonce[16..]; chacha20_init(s, h, &dkey, dnonce); @@ -102,12 +102,12 @@ export fn xchacha20_init( // initialization. This function may only be used for specific purposes // such as X25519 key derivation. Do not use if in doubt. export fn hchacha20(out: []u8, key: []u8, nonce: []u8) void = { - assert(len(out) == KEYSIZE); - assert(len(key) == KEYSIZE); + assert(len(out) == KEYSZ); + assert(len(key) == KEYSZ); assert(len(nonce) == 16); let state: [16]u32 = [0...]; - defer bytes::zero((state: []u8: *[*]u8)[..BLOCKSIZE]); + defer bytes::zero((state: []u8: *[*]u8)[..BLOCKSZ]); state[0] = magic[0]; state[1] = magic[1]; @@ -139,18 +139,18 @@ export fn hchacha20(out: []u8, key: []u8, nonce: []u8) void = { }; // Advances the key stream to "seek" to a future state by 'counter' times -// [[BLOCKSIZE]]. +// [[BLOCKSZ]]. export fn setctr(s: *stream, counter: u32) void = { s.state[12] = counter; // enforce block generation - s.xorused = BLOCKSIZE; + s.xorused = BLOCKSZ; }; fn keybuf(s: *cipher::xorstream) []u8 = { let s = s: *stream; - if (s.xorused >= BLOCKSIZE) { + if (s.xorused >= BLOCKSZ) { block((s.xorbuf: []u8: *[*]u32)[..16], &s.state, s.rounds); // TODO on big endian systems s.xorbuf values need to @@ -215,6 +215,6 @@ fn qr(a: *u32, b: *u32, c: *u32, d: *u32) void = { fn finish(c: *cipher::xorstream) void = { let s = c: *stream; - bytes::zero((s.state[..]: *[*]u8)[..BLOCKSIZE]); + bytes::zero((s.state[..]: *[*]u8)[..BLOCKSZ]); bytes::zero(s.xorbuf); }; diff --git a/crypto/chachapoly/chachapoly.ha b/crypto/chachapoly/chachapoly.ha @@ -12,16 +12,16 @@ use memio; use types; // Nonce size as required by [[init]]. -export def NONCESZ: size = chacha::NONCESIZE; +export def NONCESZ: size = chacha::NONCESZ; // Nonce size as required by [[xinit]]. -export def XNONCESZ: size = chacha::XNONCESIZE; +export def XNONCESZ: size = chacha::XNONCESZ; // Key size -export def KEYSZ: size = chacha::KEYSIZE; +export def KEYSZ: size = chacha::KEYSZ; // Tag size -export def TAGSZ: size = poly1305::SIZE; +export def TAGSZ: size = poly1305::SZ; export type stream = struct { stream: io::stream, @@ -110,12 +110,12 @@ fn geninit( }; fn polypad(p: *poly1305::state, n: size) void = { - if (n % poly1305::BLOCKSIZE == 0) { + if (n % poly1305::BLOCKSZ == 0) { return; }; - const pad: [poly1305::BLOCKSIZE]u8 = [0...]; - const padlen = poly1305::BLOCKSIZE - (n % poly1305::BLOCKSIZE); + const pad: [poly1305::BLOCKSZ]u8 = [0...]; + const padlen = poly1305::BLOCKSZ - (n % poly1305::BLOCKSZ); mac::write(p, pad[..padlen]); }; diff --git a/crypto/cipher/gcm.ha b/crypto/cipher/gcm.ha @@ -7,19 +7,19 @@ use errors; use io; use types; -def GCMBLOCKSIZE: size = 16; +def GCMBLOCKSZ: size = 16; -export def GCMTAGSIZE: size = 16; +export def GCMTAGSZ: size = 16; export type gcmstream = struct { stream: io::stream, block: nullable *block, handle: io::handle, - tagbuf: [GCMBLOCKSIZE]u8, - xorbuf: [GCMBLOCKSIZE]u8, - cipherbuf: [GCMBLOCKSIZE]u8, - y0: [GCMBLOCKSIZE]u8, - h: [GCMBLOCKSIZE]u8, + tagbuf: [GCMBLOCKSZ]u8, + xorbuf: [GCMBLOCKSZ]u8, + cipherbuf: [GCMBLOCKSZ]u8, + y0: [GCMBLOCKSZ]u8, + h: [GCMBLOCKSZ]u8, y: u32, xorbufpos: size, adlen: u64, @@ -70,13 +70,13 @@ export fn gcm_init( iv: const []u8, ad: const []u8 ) void = { - assert(blocksz(b) == GCMBLOCKSIZE); + assert(blocksz(b) == GCMBLOCKSZ); assert(len(iv): u64 <= (types::U64_MAX >> 3)); s.handle = handle; s.block = b; s.adlen = len(ad); - s.xorbufpos = GCMBLOCKSIZE; // to force fill xorbuf at start + s.xorbufpos = GCMBLOCKSZ; // to force fill xorbuf at start encrypt(b, s.h, s.h); @@ -95,8 +95,8 @@ export fn gcm_init( let ad = ad[..]; for (len(ad) > 0) { - const max = if (len(ad) >= GCMBLOCKSIZE) { - yield GCMBLOCKSIZE; + const max = if (len(ad) >= GCMBLOCKSZ) { + yield GCMBLOCKSZ; } else { yield len(ad); }; @@ -112,7 +112,7 @@ fn gcm_writer(s: *io::stream, buf: const []u8) (size | io::error) = { return 0z; }; - if (s.xorbufpos == GCMBLOCKSIZE) { + if (s.xorbufpos == GCMBLOCKSZ) { // current key block is depleted, prepare the next one fillxorbuf(s); }; @@ -134,7 +134,7 @@ fn gcm_writer(s: *io::stream, buf: const []u8) (size | io::error) = { s.xorbufpos += n; s.clen += n; - if (s.xorbufpos == GCMBLOCKSIZE) { + if (s.xorbufpos == GCMBLOCKSZ) { ghash_ctmul64(s.tagbuf, s.h, s.cipherbuf); }; @@ -142,7 +142,7 @@ fn gcm_writer(s: *io::stream, buf: const []u8) (size | io::error) = { }; fn fillxorbuf(s: *gcmstream) void = { - let y: [GCMBLOCKSIZE]u8 = [0...]; + let y: [GCMBLOCKSZ]u8 = [0...]; s.xorbuf[..] = s.y0[..]; beputu32(s.xorbuf[12..], s.y); encrypt(s.block as *block, s.xorbuf, s.xorbuf); @@ -161,11 +161,11 @@ fn gcm_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { }; for (let i = n; i > 0) { - if (s.xorbufpos == GCMBLOCKSIZE) { + if (s.xorbufpos == GCMBLOCKSZ) { fillxorbuf(s); }; - const max = if (s.xorbufpos + i > GCMBLOCKSIZE) { + const max = if (s.xorbufpos + i > GCMBLOCKSZ) { yield len(s.cipherbuf) - s.xorbufpos; } else { yield i; @@ -194,8 +194,8 @@ fn gcm_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { // Finishes encryption and returns the authentication tag. After calling seal, // the user must not write any more data to the stream. export fn gcm_seal(s: *gcmstream, tag: []u8) void = { - assert(len(tag) == GCMTAGSIZE); - if (s.xorbufpos > 0 && s.xorbufpos < GCMBLOCKSIZE) { + assert(len(tag) == GCMTAGSZ); + if (s.xorbufpos > 0 && s.xorbufpos < GCMBLOCKSZ) { // last block was is not full, therefore the content was not // hashed yet. ghash_ctmul64(s.tagbuf, s.h, s.cipherbuf[..s.xorbufpos]); @@ -215,8 +215,8 @@ export fn gcm_seal(s: *gcmstream, tag: []u8) void = { // modified. If the data was modified, [[errors::invalid]] will be returned and // the data must not be trusted. export fn gcm_verify(s: *gcmstream, tag: []u8) (void | errors::invalid) = { - assert(len(tag) == GCMTAGSIZE); - if (s.xorbufpos > 0 && s.xorbufpos < GCMBLOCKSIZE) { + assert(len(tag) == GCMTAGSZ); + if (s.xorbufpos > 0 && s.xorbufpos < GCMBLOCKSZ) { ghash_ctmul64(s.tagbuf, s.h, s.cipherbuf[..s.xorbufpos]); }; diff --git a/crypto/ed25519/edwards25519.ha b/crypto/ed25519/edwards25519.ha @@ -314,7 +314,7 @@ fn point_encode(out: *scalar, p: *point) void = { out[31] ^= fe_parity(&tx) << 7; }; -// len(in) must be POINTSIZE +// len(in) must be POINTSZ fn point_decode(p: *point, in: []u8) bool = { let t: elem = [0...]; let chk: elem = [0...]; diff --git a/crypto/hkdf/+test.ha b/crypto/hkdf/+test.ha @@ -26,7 +26,7 @@ use crypto::sha256; 0x58, 0x65, ]; - let buf: [sha256::SIZE + sha256::BLOCKSIZE]u8 = [0...]; + let buf: [sha256::SZ + sha256::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, info, salt, buf); @@ -81,7 +81,7 @@ use crypto::sha256; 0x1d, 0x87, ]; - let buf: [sha256::SIZE + sha256::BLOCKSIZE]u8 = [0...]; + let buf: [sha256::SZ + sha256::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, info, salt, buf); @@ -103,7 +103,7 @@ use crypto::sha256; 0x96, 0xc8, ]; - let buf: [sha256::SIZE + sha256::BLOCKSIZE]u8 = [0...]; + let buf: [sha256::SZ + sha256::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, [], [], buf); @@ -133,7 +133,7 @@ use crypto::sha256; 0xf8, 0x96, ]; - let buf: [sha1::SIZE + sha1::BLOCKSIZE]u8 = [0...]; + let buf: [sha1::SZ + sha1::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, info, salt, buf); @@ -188,7 +188,7 @@ use crypto::sha256; 0xd3, 0xb4, ]; - let buf: [sha1::SIZE + sha1::BLOCKSIZE]u8 = [0...]; + let buf: [sha1::SZ + sha1::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, info, salt, buf); @@ -210,7 +210,7 @@ use crypto::sha256; 0xfc, 0x48, ]; - let buf: [sha1::SIZE + sha1::BLOCKSIZE]u8 = [0...]; + let buf: [sha1::SZ + sha1::BLOCKSZ]u8 = [0...]; hkdf(&h, dest[..], key, [], void, buf); diff --git a/crypto/hmac/+test.ha b/crypto/hmac/+test.ha @@ -12,7 +12,7 @@ use strings; fn assert_hmac_sha1(keystr: str, vectors: [](str, [20]u8)) void = { let key = strings::toutf8(keystr); let h = sha1::sha1(); - let buf: [sha1::BLOCKSIZE]u8 = [0...]; + let buf: [sha1::BLOCKSZ]u8 = [0...]; for (let i = 0z; i < len(vectors); i += 1) { hash::reset(&h); @@ -23,7 +23,7 @@ fn assert_hmac_sha1(keystr: str, vectors: [](str, [20]u8)) void = { mac::write(&hmac, strings::toutf8(vector.0)); - let sum: [sha1::SIZE]u8 = [0...]; + let sum: [sha1::SZ]u8 = [0...]; mac::sum(&hmac, sum); assert(bytes::equal(vector.1, sum)); @@ -141,7 +141,7 @@ fn assert_hmac_sha1(keystr: str, vectors: [](str, [20]u8)) void = { let hmac = sha256([]); defer mac::finish(&hmac); - let sum: [sha256::SIZE]u8 = [0...]; + let sum: [sha256::SZ]u8 = [0...]; mac::sum(&hmac, sum); assert(bytes::equal(expected, sum)); diff --git a/crypto/hmac/hmac.ha b/crypto/hmac/hmac.ha @@ -19,7 +19,7 @@ const hmac_vtable: io::vtable = io::vtable { // Creates a [[crypto::mac::mac]] that computes an HMAC using the provided hash // function 'h' with given 'key'. The caller must provide a 'buf' of -// [[hash::bsz]] bytes. Use the BLOCKSIZE constant of the given hash function to +// [[hash::bsz]] bytes. Use the BLOCKSZ constant of the given hash function to // allocate the memory statically. // // The caller must take extra care to call [[crypto::mac::finish]] when they are diff --git a/crypto/hmac/sha1.ha b/crypto/hmac/sha1.ha @@ -9,7 +9,7 @@ use io; export type sha1state = struct { mac::mac, h: sha1::state, - keypad: [sha1::BLOCKSIZE]u8, + keypad: [sha1::BLOCKSZ]u8, }; const sha1_vtable: io::vtable = io::vtable { @@ -28,8 +28,8 @@ export fn sha1(key: []u8) sha1state = { let s = sha1state { h = sha1::sha1(), stream = &sha1_vtable, - sz = sha1::SIZE, - bsz = sha1::BLOCKSIZE, + sz = sha1::SZ, + bsz = sha1::BLOCKSZ, sum = &sha1sum, finish = &sha1finish, ... diff --git a/crypto/hmac/sha256.ha b/crypto/hmac/sha256.ha @@ -9,7 +9,7 @@ use io; export type sha256state = struct { mac::mac, h: sha256::state, - keypad: [sha256::BLOCKSIZE]u8, + keypad: [sha256::BLOCKSZ]u8, }; const sha256_vtable: io::vtable = io::vtable { @@ -28,8 +28,8 @@ export fn sha256(key: []u8) sha256state = { let s = sha256state { stream = &sha256_vtable, h = sha256::sha256(), - sz = sha256::SIZE, - bsz = sha256::BLOCKSIZE, + sz = sha256::SZ, + bsz = sha256::BLOCKSZ, sum = &sha256sum, finish = &sha256finish, ... diff --git a/crypto/poly1305/poly1305.ha b/crypto/poly1305/poly1305.ha @@ -9,10 +9,10 @@ use endian; use io; // Internal block size in bytes. -export def BLOCKSIZE: size = 16; +export def BLOCKSZ: size = 16; // Length of the resulting MAC in bytes. -export def SIZE: size = 16; +export def SZ: size = 16; // Poly1305 key. export type key = [32]u8; @@ -39,8 +39,8 @@ export fn poly1305() state = { stream = &poly1305_vtable, sum = &sum, finish = &finish, - sz = SIZE, - bsz = BLOCKSIZE, + sz = SZ, + bsz = BLOCKSZ, ... }; }; @@ -70,17 +70,17 @@ fn write(st: *io::stream, bbuf: const []u8) (size | io::error) = { const written = len(buf); for (len(buf) > 0) { - const n = if (len(buf) <= BLOCKSIZE - p.cidx) { + const n = if (len(buf) <= BLOCKSZ - p.cidx) { yield len(buf); } else { - yield BLOCKSIZE - p.cidx; + yield BLOCKSZ - p.cidx; }; p.c[p.cidx..p.cidx + n] = buf[..n]; p.cidx += n; buf = buf[n..]; - if (p.cidx >= BLOCKSIZE) { + if (p.cidx >= BLOCKSZ) { block(p, p.c, 1); p.cidx = 0; }; diff --git a/crypto/rsa/+test/core_test.ha b/crypto/rsa/+test/core_test.ha @@ -3,10 +3,10 @@ use bytes; use crypto::bigint::*; -let pubbuf: [PUBEXP_BUFSIZE]u8 = [0...]; -let privbuf: [PRIVEXP_BUFSIZE]u8 = [0...]; -let pkcs1_verifybuf: [PKCS1_VERIFYBUFSIZE]u8 = [0...]; -let pkcs1_signbuf: [PKCS1_SIGNBUFSIZE]u8 = [0...]; +let pubbuf: [PUBEXP_BUFSZ]u8 = [0...]; +let privbuf: [PRIVEXP_BUFSZ]u8 = [0...]; +let pkcs1_verifybuf: [PKCS1_VERIFYBUFSZ]u8 = [0...]; +let pkcs1_signbuf: [PKCS1_SIGNBUFSZ]u8 = [0...]; @test fn tiny() void = { let pub = pubparams { diff --git a/crypto/rsa/+test/keys_test.ha b/crypto/rsa/+test/keys_test.ha @@ -472,7 +472,7 @@ let enc4096: keypair = keypair { ... }; - let priv: [PRIVKEYSIZE]u8 = [0...]; + let priv: [PRIVKEYSZ]u8 = [0...]; privkey_initd(priv, params, enc4096.d, enc4096.pub.n)!; const newparams = privkey_params(priv); diff --git a/crypto/rsa/+test/pkcs1_test.ha b/crypto/rsa/+test/pkcs1_test.ha @@ -230,10 +230,10 @@ const sig512_256: [_]u8 = [ @test fn pkcs1() void = { let pk = sign3072.priv; - let priv: [PRIVKEYSIZE]u8 = [0...]; + let priv: [PRIVKEYSZ]u8 = [0...]; privkey_init(priv, sign3072.priv)!; - let pub: [PUBKEYSIZE]u8 = [0...]; + let pub: [PUBKEYSZ]u8 = [0...]; pubkey_init(pub, sign3072.pub)!; assertpkcs1(priv, pub, msg, sig1, pkcs1_hashalgo::SHA1); diff --git a/crypto/rsa/core.ha b/crypto/rsa/core.ha @@ -27,22 +27,22 @@ use crypto::bigint::*; use errors; use types; -// Maximum factor size of a key of [[BITSIZE]]. -def MAXFACTOR: size = ((BITSIZE + 64) >> 1); +// Maximum factor size of a key of [[BITSZ]]. +def MAXFACTOR: size = ((BITSZ + 64) >> 1); // Required buf size for the [[pubexp]] operation. -def PUBEXP_BUFSIZE: size = size(word) * (1 + (4 * (2 - + ((BITSIZE + WORD_BITSIZE - 1) / WORD_BITSIZE)))); +def PUBEXP_BUFSZ: size = size(word) * (1 + (4 * (2 + + ((BITSZ + WORD_BITSZ - 1) / WORD_BITSZ)))); // Requried buf size for the [[privexp]] operation. -def PRIVEXP_BUFSIZE: size = size(word) * (1 + (8 * (2 - + ((MAXFACTOR + WORD_BITSIZE - 1) / WORD_BITSIZE)))); +def PRIVEXP_BUFSZ: size = size(word) * (1 + (8 * (2 + + ((MAXFACTOR + WORD_BITSZ - 1) / WORD_BITSZ)))); // Performs the modular exponentiation of 'x' with the public exponent of 'pub'. // 'x' is modified in place. 'x' must be the same length as the actual length // of 'pub.n'. // -// For the size of 'buf' see [[PUBEXP_BUFSIZE]]. If the buffer is not large +// For the size of 'buf' see [[PUBEXP_BUFSZ]]. If the buffer is not large // enough, [[errors::overflow]] will be returned. In case of 'x' being not of // required length or if 'x' is not modulo 'pub.n' [[errors::invalid]] is // returned and 'x' will be zeroed. @@ -53,8 +53,8 @@ fn pubexp(pub: *pubparams, x: []u8, buf: []u8) (void | error) = { let n = pub.n; // get the maximal allowed key size for given buffer. Reverse of the - // [[PUBEXP_BUFSIZE]] equation. - const maxkeybits = (((wbuflen - 1) / 4) - 2) * WORD_BITSIZE; + // [[PUBEXP_BUFSZ]] equation. + const maxkeybits = (((wbuflen - 1) / 4) - 2) * WORD_BITSZ; if (len(n) == 0 || len(n) > (maxkeybits >> 3)) { return errors::overflow; @@ -66,9 +66,9 @@ fn pubexp(pub: *pubparams, x: []u8, buf: []u8) (void | error) = { }; // add word size - 1 to ceil required words in the division that follows - const maxnbitlen = (len(n) << 3) + WORD_BITSIZE: size - 1; + const maxnbitlen = (len(n) << 3) + WORD_BITSZ: size - 1; assert(maxnbitlen <= types::U32_MAX); - let bwordlen = 1 + divu32(0, maxnbitlen: u32, WORD_BITSIZE).0; + let bwordlen = 1 + divu32(0, maxnbitlen: u32, WORD_BITSZ).0; // make it even bwordlen += bwordlen & 1; @@ -102,7 +102,7 @@ fn pubexp(pub: *pubparams, x: []u8, buf: []u8) (void | error) = { // 'x' is modified in place. 'x' must be the same length as the actual length // of the modulus n (see [[privkey_nsize]]). // -// For size of 'buf' see [[PRIVEXP_BUFSIZE]]. If the buffer is not large enough +// For size of 'buf' see [[PRIVEXP_BUFSZ]]. If the buffer is not large enough // [[errors::overflow]] will be returned. In case of an invalid size of 'x' or // an invalid key, [[errors::invalid]] will be returned and 'x' will be zeroed. fn privexp(priv: *privparams, x: []u8, buf: []u8) (void | error) = { @@ -116,9 +116,9 @@ fn privexp(priv: *privparams, x: []u8, buf: []u8) (void | error) = { const maxflen = if (len(p) > len(q)) len(p) else len(q); // add word size - 1 to ceil required words in the division that follows - const maxfbitlen = (maxflen << 3) + WORD_BITSIZE: size - 1; + const maxfbitlen = (maxflen << 3) + WORD_BITSZ: size - 1; assert(maxfbitlen <= types::U32_MAX); - let bwordlen = 1 + divu32(0, maxfbitlen: u32, WORD_BITSIZE).0; + let bwordlen = 1 + divu32(0, maxfbitlen: u32, WORD_BITSZ).0; // make it even bwordlen += bwordlen & 1; diff --git a/crypto/rsa/keys.ha b/crypto/rsa/keys.ha @@ -10,11 +10,11 @@ use memio; use types; // The default bit size of RSA keys is 4096-bit. Used as base for buffer sizes. -export def BITSIZE: size = 4096; +export def BITSZ: size = 4096; // The minimum bit size of RSA keys used only for validation during key init. // The default value is 1024-bit. -export def MINBITSIZE: size = 1024; +export def MINBITSZ: size = 1024; // RSA key parameters for initializing public keys with [[pubkey_init]]. export type pubparams = struct { @@ -51,12 +51,12 @@ export type privparams = struct { iq: []u8, }; -// Size required to store a public key of [[BITSIZE]] length. -export def PUBKEYSIZE: size = 5 + 2 * (BITSIZE >> 3); +// Size required to store a public key of [[BITSZ]] length. +export def PUBKEYSZ: size = 5 + 2 * (BITSZ >> 3); // Initializes a public key from given [[pubparams]] 'x'. The data format // of 'pubkey' is subject to change and must not be used to serialize the key. -// [[PUBKEYSIZE]] defines the required size to store a key of [[BITSIZE]]. +// [[PUBKEYSZ]] defines the required size to store a key of [[BITSZ]]. // // If given key does not fit into 'pubkey' or is too small, [[errors::overflow]] // is returned. Returns [[errors::invalid]], if given key parameters are @@ -74,7 +74,7 @@ export fn pubkey_init(pubkey: []u8, x: pubparams) (size | error) = { if ((len(e) == 1 && e[0] == 1) || len(e) > len(n)) { return errors::invalid; }; - if (bitlen(n) < MINBITSIZE) { + if (bitlen(n) < MINBITSZ) { return errors::invalid; }; @@ -159,8 +159,8 @@ fn nextslice(key: *[]u8) []u8 = { return s; }; -// Size required to store a private key of [[BITSIZE]] length. -export def PRIVKEYSIZE: size = 13 + (MAXFACTOR >> 3) * 5; +// Size required to store a private key of [[BITSZ]] length. +export def PRIVKEYSZ: size = 13 + (MAXFACTOR >> 3) * 5; fn privkey_len(x: *privparams) size = 13z + len(x.p) + len(x.q) + len(x.dp) + len(x.dq) + len(x.iq); @@ -229,7 +229,7 @@ fn privkey_writehead( if (nbitlen > types::U16_MAX) { return errors::overflow; }; - if (nbitlen < MINBITSIZE) { + if (nbitlen < MINBITSZ) { return errors::invalid; }; diff --git a/crypto/rsa/pkcs1.ha b/crypto/rsa/pkcs1.ha @@ -56,13 +56,13 @@ const OID_SHA512_256: [_]u8 = [ ]; // Required buffer size for [[pkcs1_verify]]. -export def PKCS1_VERIFYBUFSIZE: size = PUBEXP_BUFSIZE + (BITSIZE / 8); +export def PKCS1_VERIFYBUFSZ: size = PUBEXP_BUFSZ + (BITSZ / 8); // Verifies a PKCS#1 v1.5 signature given a public key 'pubkey', the message // hash 'msghash', the signature 'sig' and the hash algorithm 'algo'. 'algo' // must reflect the hash algorithm 'sig' was created with. // -// A temporary buffer 'buf' of size [[PKCS1_VERIFYBUFSIZE]] must be provided. +// A temporary buffer 'buf' of size [[PKCS1_VERIFYBUFSZ]] must be provided. export fn pkcs1_verify( pubkey: []u8, msghash: []u8, @@ -92,14 +92,14 @@ export fn pkcs1_verify( }; // Required buffer size for [[pkcs1_sign]]. -export def PKCS1_SIGNBUFSIZE: size = PRIVEXP_BUFSIZE; +export def PKCS1_SIGNBUFSZ: size = PRIVEXP_BUFSZ; // Signs a message hash 'msghash' using the PKCS#1 V1.5 signature scheme. The // signature will be written to 'sig' which must be in the the size of the // modulus n (see [[privkey_nsize]]). 'algo' defines the hash algorithm // 'msghash' was created with. // -// A temporary buffer 'buf' of size [[PKCS1_SIGNBUFSIZE]] must be provided. +// A temporary buffer 'buf' of size [[PKCS1_SIGNBUFSZ]] must be provided. export fn pkcs1_sign( priv: []u8, msghash: []u8, @@ -116,17 +116,17 @@ export fn pkcs1_sign( fn pkcs1_hashinfo(algo: pkcs1_hashalgo) (const []u8, size) = { switch (algo) { case pkcs1_hashalgo::SHA1 => - return (OID_SHA1, sha1::SIZE); + return (OID_SHA1, sha1::SZ); case pkcs1_hashalgo::SHA256 => - return (OID_SHA256, sha256::SIZE); + return (OID_SHA256, sha256::SZ); case pkcs1_hashalgo::SHA384 => - return (OID_SHA384, sha512::SIZE384); + return (OID_SHA384, sha512::SZ384); case pkcs1_hashalgo::SHA512 => - return (OID_SHA512, sha512::SIZE); + return (OID_SHA512, sha512::SZ); case pkcs1_hashalgo::SHA512_224 => - return (OID_SHA512_224, sha512::SIZE224); + return (OID_SHA512_224, sha512::SZ224); case pkcs1_hashalgo::SHA512_256 => - return (OID_SHA512_256, sha512::SIZE256); + return (OID_SHA512_256, sha512::SZ256); case => abort("unreachable"); }; diff --git a/crypto/salsa/+test.ha b/crypto/salsa/+test.ha @@ -16,13 +16,13 @@ use types; }; @test fn xsalsa20() void = { - let key: [KEYSIZE]u8 = [ + let key: [KEYSZ]u8 = [ 0x47, 0x85, 0x1a, 0xb8, 0xa0, 0xd4, 0x41, 0x20, 0xb7, 0x7b, 0xf6, 0x16, 0x0d, 0xcb, 0xbf, 0xa6, 0x9f, 0xa9, 0xc5, 0xdd, 0x2a, 0x0c, 0xb9, 0x8c, 0xeb, 0x72, 0xe7, 0x96, 0x57, 0x01, 0xb5, 0x5a, ]; - let nonce: [XNONCESIZE]u8 = [ + let nonce: [XNONCESZ]u8 = [ 0x1b, 0xcb, 0x13, 0xb8, 0xf5, 0x27, 0x53, 0x34, 0xa0, 0xb4, 0x8e, 0xd2, 0xeb, 0x5b, 0xbc, 0x15, 0x44, 0x5b, 0x05, 0x09, 0x56, 0xa8, 0x86, 0xa7, @@ -69,13 +69,13 @@ use types; }; @test fn xsalsa20_ctr_overflow_u32() void = { - let key: [KEYSIZE]u8 = [ + let key: [KEYSZ]u8 = [ 0x7f, 0xa3, 0x4d, 0x21, 0x7c, 0xc3, 0x91, 0x99, 0x47, 0xef, 0xa1, 0xde, 0x4b, 0xaa, 0x8d, 0xcb, 0x38, 0x4e, 0x7f, 0xf7, 0xbe, 0xd6, 0xaf, 0x4c, 0x11, 0x97, 0x68, 0x39, 0xf1, 0xd9, 0x0f, 0x92, ]; - let nonce: [XNONCESIZE]u8 = [ + let nonce: [XNONCESZ]u8 = [ 0x42, 0x4a, 0xff, 0xdb, 0x30, 0xde, 0x7f, 0xaf, 0xe9, 0xd4, 0xd5, 0xe5, 0x64, 0xfc, 0x3a, 0x87, 0xe1, 0x74, 0x9d, 0x3b, 0xd5, 0x5f, 0x01, 0xec, @@ -123,13 +123,13 @@ use types; }; @test fn xsalsa20_ctr_overflow_u64() void = { - let key: [KEYSIZE]u8 = [ + let key: [KEYSZ]u8 = [ 0xe3, 0xe0, 0xa8, 0x09, 0x09, 0xd2, 0x8c, 0xb4, 0x13, 0xa6, 0x8a, 0x33, 0xdf, 0x9c, 0xa2, 0x7f, 0x46, 0xd1, 0x9e, 0x32, 0x14, 0x53, 0x66, 0x23, 0x36, 0x45, 0x58, 0xff, 0x68, 0x36, 0x78, 0x69, ]; - let nonce: [XNONCESIZE]u8 = [ + let nonce: [XNONCESZ]u8 = [ 0x8d, 0xe8, 0x84, 0xa0, 0x91, 0x0a, 0x26, 0xa3, 0xb4, 0x8a, 0x05, 0x22, 0x41, 0x77, 0xd1, 0x14, 0xbd, 0x09, 0x35, 0x0e, 0xbd, 0x73, 0xe5, 0xae, diff --git a/crypto/salsa/salsa20.ha b/crypto/salsa/salsa20.ha @@ -7,25 +7,25 @@ use endian; use io; // Size of a Salsa key, in bytes. -export def KEYSIZE: size = 32; +export def KEYSZ: size = 32; // Size of the XSalsa20 nonce, in bytes. -export def XNONCESIZE: size = 24; +export def XNONCESZ: size = 24; // Size of the Salsa20 nonce, in bytes. -export def NONCESIZE: size = 8; +export def NONCESZ: size = 8; def ROUNDS: size = 20; // The block size of the Salsa cipher. -export def BLOCKSIZE: size = 64; +export def BLOCKSZ: size = 64; const magic: [4]u32 = [0x61707865, 0x3320646e, 0x79622d32, 0x6b206574]; export type stream = struct { cipher::xorstream, state: [16]u32, - xorbuf: [BLOCKSIZE]u8, + xorbuf: [BLOCKSZ]u8, xorused: size, rounds: size, }; @@ -40,7 +40,7 @@ export fn salsa20() stream = { keybuf = &keybuf, advance = &advance, finish = &finish, - xorused = BLOCKSIZE, + xorused = BLOCKSZ, rounds = ROUNDS, ... }; @@ -77,8 +77,8 @@ export fn salsa20_init( key: []u8, nonce: []u8, ) void = { - assert(len(key) == KEYSIZE); - assert(len(nonce) == NONCESIZE); + assert(len(key) == KEYSZ); + assert(len(nonce) == NONCESZ); let counter: [8]u8 = [0...]; init(&s.state, key, nonce, &counter); @@ -93,25 +93,25 @@ export fn xsalsa20_init( key: []u8, nonce: []u8 ) void = { - assert(len(key) == KEYSIZE); - assert(len(nonce) == XNONCESIZE); + assert(len(key) == KEYSZ); + assert(len(nonce) == XNONCESZ); let dkey: [32]u8 = [0...]; defer bytes::zero(dkey); hsalsa20(&dkey, key, nonce[..16]); - salsa20_init(s, h, &dkey, nonce[16..]: *[NONCESIZE]u8); + salsa20_init(s, h, &dkey, nonce[16..]: *[NONCESZ]u8); }; // Derives a new key from 'key' and 'nonce' as used during XSalsa20 // initialization. This function may only be used for specific purposes // such as X25519 key derivation. Do not use if in doubt. export fn hsalsa20(out: []u8, key: []u8, nonce: []u8) void = { - assert(len(out) == KEYSIZE); - assert(len(key) == KEYSIZE); + assert(len(out) == KEYSZ); + assert(len(key) == KEYSZ); assert(len(nonce) == 16); let state: [16]u32 = [0...]; - defer bytes::zero((state: []u8: *[*]u8)[..BLOCKSIZE]); + defer bytes::zero((state: []u8: *[*]u8)[..BLOCKSZ]); init(&state, key, nonce[0..8]: *[8]u8, nonce[8..16]: *[8]u8); hblock(state[..], &state, 20); @@ -127,16 +127,16 @@ export fn hsalsa20(out: []u8, key: []u8, nonce: []u8) void = { }; // Advances the key stream to "seek" to a future state by 'counter' times -// [[BLOCKSIZE]]. +// [[BLOCKSZ]]. export fn setctr(s: *stream, counter: u64) void = { s.state[8] = (counter & 0xFFFFFFFF): u32; s.state[9] = (counter >> 32): u32; - s.xorused = BLOCKSIZE; + s.xorused = BLOCKSZ; }; fn keybuf(s: *cipher::xorstream) []u8 = { let s = s: *stream; - if (s.xorused >= BLOCKSIZE) { + if (s.xorused >= BLOCKSZ) { block((s.xorbuf[..]: *[*]u32)[..16], &s.state, s.rounds); s.state[8] += 1; if (s.state[8] == 0) { diff --git a/crypto/sha1/+test.ha b/crypto/sha1/+test.ha @@ -30,7 +30,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE]u8 = [0...]; + let sum: [SZ]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); @@ -52,7 +52,7 @@ use encoding::hex; // for (let i = 0z; i < 16777216; i += 1) // hash::write(&sha, strings::toutf8(input)); // -// let sum: [SIZE]u8 = [0...]; +// let sum: [SZ]u8 = [0...]; // hash::sum(&sha, sum); // // let shahex = hex::encodestr(sum); diff --git a/crypto/sha1/sha1.ha b/crypto/sha1/sha1.ha @@ -10,9 +10,9 @@ use crypto::math; use endian; // The size, in bytes, of a SHA-1 digest. -export def SIZE: size = 20; +export def SZ: size = 20; -export def BLOCKSIZE: size = 64; +export def BLOCKSZ: size = 64; def chunk: size = 64; def init0: u32 = 0x67452301; @@ -46,8 +46,8 @@ export fn sha1() state = { stream = &sha1_vtable, sum = &sum, reset = &reset, - sz = SIZE, - bsz = BLOCKSIZE, + sz = SZ, + bsz = BLOCKSZ, ... }; hash::reset(&sha); diff --git a/crypto/sha256/+test.ha b/crypto/sha256/+test.ha @@ -27,7 +27,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE]u8 = [0...]; + let sum: [SZ]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); @@ -45,7 +45,7 @@ use encoding::hex; //for (let i = 0z; i < 16777216; i += 1) { // hash::write(&sha, strings::toutf8(input)); //}; - //let sum: [SIZE]u8 = [0...]; + //let sum: [SZ]u8 = [0...]; //hash::sum(&sha, sum); //let shahex = hex::encodestr(sum); diff --git a/crypto/sha256/sha256.ha b/crypto/sha256/sha256.ha @@ -9,10 +9,10 @@ use hash; use io; // The size, in bytes, of a SHA-256 digest. -export def SIZE: size = 32; +export def SZ: size = 32; // The internal block size. -export def BLOCKSIZE: size = 64; +export def BLOCKSZ: size = 64; // This is loosely based on the Go implementation def init0: u32 = 0x6A09E667; @@ -41,7 +41,7 @@ const k: [_]u32 = [ export type state = struct { hash::hash, h: [8]u32, - x: [BLOCKSIZE]u8, + x: [BLOCKSZ]u8, nx: size, ln: size, }; @@ -61,8 +61,8 @@ export fn sha256() state = { stream = &sha256_vtable, sum = &sum, reset = &reset, - sz = SIZE, - bsz = BLOCKSIZE, + sz = SZ, + bsz = BLOCKSZ, ... }; hash::reset(&sha); @@ -94,14 +94,14 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { } else len(b); h.x[h.nx..h.nx + n] = b[..n]; h.nx += n; - if (h.nx == BLOCKSIZE) { + if (h.nx == BLOCKSZ) { block(h, h.x[..]); h.nx = 0; }; b = b[n..]; }; - if (len(b) >= BLOCKSIZE) { - let n = len(b) & ~(BLOCKSIZE - 1); + if (len(b) >= BLOCKSZ) { + let n = len(b) & ~(BLOCKSZ - 1); block(h, b[..n]); b = b[n..]; }; @@ -148,7 +148,7 @@ fn block(h: *state, buf: []u8) void = { let w: [64]u32 = [0...]; let h0 = h.h[0], h1 = h.h[1], h2 = h.h[2], h3 = h.h[3], h4 = h.h[4], h5 = h.h[5], h6 = h.h[6], h7 = h.h[7]; - for (len(buf) >= BLOCKSIZE) { + for (len(buf) >= BLOCKSZ) { for (let i = 0; i < 16; i += 1) { let j = i * 4; w[i] = buf[j]: u32 << 24 @@ -200,7 +200,7 @@ fn block(h: *state, buf: []u8) void = { h6 += g; h7 += h; - buf = buf[BLOCKSIZE..]; + buf = buf[BLOCKSZ..]; }; h.h[0] = h0; diff --git a/crypto/sha512/+test.ha b/crypto/sha512/+test.ha @@ -26,7 +26,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE]u8 = [0...]; + let sum: [SZ]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); @@ -50,7 +50,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE224]u8 = [0...]; + let sum: [SZ224]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); @@ -74,7 +74,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE256]u8 = [0...]; + let sum: [SZ256]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); @@ -99,7 +99,7 @@ use encoding::hex; hash::reset(&sha); hash::write(&sha, strings::toutf8(vector.0)); - let sum: [SIZE384]u8 = [0...]; + let sum: [SZ384]u8 = [0...]; hash::sum(&sha, sum); let shahex = hex::encodestr(sum); diff --git a/crypto/sha512/sha512.ha b/crypto/sha512/sha512.ha @@ -18,16 +18,16 @@ export type variant = enum { }; // The size, in bytes, of a SHA-512 checksum. -export def SIZE: size = 64; +export def SZ: size = 64; // The size, in bytes, of a SHA-512/224 checksum. -export def SIZE224: size = 28; +export def SZ224: size = 28; // The size, in bytes, of a SHA-512/256 checksum. -export def SIZE256: size = 32; +export def SZ256: size = 32; // The size, in bytes, of a SHA-384 checksum. -export def SIZE384: size = 48; +export def SZ384: size = 48; def chunk: size = 128; def init0: u64 = 0x6a09e667f3bcc908; @@ -76,25 +76,25 @@ export type digest = struct { // used to hash sensitive information, the caller should call [[hash::close]] to // erase sensitive data from memory after use; if not, the use of // [[hash::close]] is optional. -export fn sha512() digest = init(variant::SHA512, SIZE); +export fn sha512() digest = init(variant::SHA512, SZ); // Creates a [[hash::hash]] which computes a SHA-512/224 hash. If this function // is used to hash sensitive information, the caller should call [[hash::close]] // to erase sensitive data from memory after use; if not, the use of // [[hash::close]] is optional. -export fn sha512_224() digest = init(variant::SHA512_224, SIZE224); +export fn sha512_224() digest = init(variant::SHA512_224, SZ224); // Creates a [[hash::hash]] which computes a SHA-512/256 hash. If this function // is used to hash sensitive information, the caller should call [[hash::close]] // to erase sensitive data from memory after use; if not, the use of // [[hash::close]] is optional. -export fn sha512_256() digest = init(variant::SHA512_256, SIZE256); +export fn sha512_256() digest = init(variant::SHA512_256, SZ256); // Creates a [[hash::hash]] which computes a SHA-384 hash. If this function is // used to hash sensitive information, the caller should call [[hash::close]] to // erase sensitive data from memory after use; if not, the use of // [[hash::close]] is optional. -export fn sha384() digest = init(variant::SHA384, SIZE384); +export fn sha384() digest = init(variant::SHA384, SZ384); const sha512_vtable: io::vtable = io::vtable { writer = &write, @@ -174,7 +174,7 @@ fn sum(h: *hash::hash, buf: []u8) void = { assert(d.nx == 0); - let dig: [SIZE]u8 = [0...]; + let dig: [SZ]u8 = [0...]; endian::beputu64(dig[0..], d.h[0]); endian::beputu64(dig[8..], d.h[1]); endian::beputu64(dig[16..], d.h[2]); diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -58,7 +58,7 @@ export fn scan(ctx: *context, path: str) (version | error) = { }; append(inputs, in); - let sumbuf: [sha256::SIZE]u8 = [0...]; + let sumbuf: [sha256::SZ]u8 = [0...]; hash::write(&sha, in.hash); hash::sum(&sha, sumbuf); @@ -89,7 +89,7 @@ export fn scan(ctx: *context, path: str) (version | error) = { return notfound; }; - let tmp: [sha256::SIZE]u8 = [0...]; + let tmp: [sha256::SZ]u8 = [0...]; hash::sum(&sha, tmp); ver.hash = alloc([], sha.sz); append(ver.hash, tmp...); @@ -392,7 +392,7 @@ fn scan_file( }; }; - let tmp: [sha256::SIZE]u8 = [0...]; + let tmp: [sha256::SZ]u8 = [0...]; hash::sum(&sha, tmp); let checksum: []u8 = alloc([], sha.sz);