File: block.ha

package info (click to toggle)
hare 0.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,352 kB
  • sloc: asm: 1,374; makefile: 123; sh: 117; lisp: 101
file content (49 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

use bytes;
use crypto::cipher;

// The block size used by the AES algorithm.
export def BLOCKSZ: size = 16;

// Size of the buffer used for [[crypto::cipher::cbc_encryptor]] and
// [[crypto::cipher::cbc_decryptor]].
export def CBC_BUFSZ: size = BLOCKSZ * 2;

// Size of the buffer used for [[crypto::cipher::ctr]].
export def CTR_BUFSZ: size = BLOCKSZ * (MAXNPARALLEL + 1);

export type block = struct {
	vtable: cipher::block,
	rounds: u32,
	expkey: [MAXEXPKEYSZ]u8,
};

// Returns an AES [[crypto::cipher::block]] cipher implementation that has
// hardware support if possible. Check [[hwsupport]] to see if it is available.
//
// The caller must call [[init]] to add a key to the cipher before using
// the cipher, and must call [[crypto::cipher::finish]] when they are finished
// using the cipher to securely erase any secret data stored in the cipher
// state.
export fn aes() block = block {
	vtable = rtvtable,
	...
};


let hwsup: bool = false;

// Checks whether hardware AES support is available.
export fn hwsupport() bool = hwsup;

type initfunc = fn(b: *block, key: []u8) void;

// Initializes the AES block with an encryption key.
export fn init(b: *block, key: []u8) void = initfuncptr(b, key);

fn block_finish(b: *cipher::block) void = {
	let b = b: *block;
	bytes::zero(b.expkey);
};