mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
core/crypto: Switch to using ensure
This commit is contained in:
@@ -23,9 +23,7 @@
|
||||
package aes_ct64
|
||||
|
||||
add_round_key :: proc "contextless" (q: ^[8]u64, sk: []u64) #no_bounds_check {
|
||||
if len(sk) < 8 {
|
||||
panic_contextless("aes/ct64: invalid round key size")
|
||||
}
|
||||
ensure_contextless(len(sk) >= 8, "aes/ct64: invalid round key size")
|
||||
|
||||
q[0] ~= sk[0]
|
||||
q[1] ~= sk[1]
|
||||
|
||||
@@ -41,7 +41,7 @@ sub_word :: proc "contextless" (x: u32) -> u32 {
|
||||
}
|
||||
|
||||
@(private, require_results)
|
||||
keysched :: proc(comp_skey: []u64, key: []byte) -> int {
|
||||
keysched :: proc "contextless" (comp_skey: []u64, key: []byte) -> int {
|
||||
num_rounds, key_len := 0, len(key)
|
||||
switch key_len {
|
||||
case _aes.KEY_SIZE_128:
|
||||
@@ -51,7 +51,7 @@ keysched :: proc(comp_skey: []u64, key: []byte) -> int {
|
||||
case _aes.KEY_SIZE_256:
|
||||
num_rounds = _aes.ROUNDS_256
|
||||
case:
|
||||
panic("crypto/aes: invalid AES key size")
|
||||
panic_contextless("crypto/aes: invalid AES key size")
|
||||
}
|
||||
|
||||
skey: [60]u32 = ---
|
||||
|
||||
@@ -63,9 +63,8 @@ rev64 :: proc "contextless" (x: u64) -> u64 {
|
||||
// Note: `dst` is both an input and an output, to support easy implementation
|
||||
// of GCM.
|
||||
ghash :: proc "contextless" (dst, key, data: []byte) {
|
||||
if len(dst) != _aes.GHASH_BLOCK_SIZE || len(key) != _aes.GHASH_BLOCK_SIZE {
|
||||
panic_contextless("aes/ghash: invalid dst or key size")
|
||||
}
|
||||
ensure_contextless(len(dst) == _aes.GHASH_BLOCK_SIZE)
|
||||
ensure_contextless(len(key) == _aes.GHASH_BLOCK_SIZE)
|
||||
|
||||
buf := data
|
||||
l := len(buf)
|
||||
|
||||
@@ -31,41 +31,31 @@ and_interleaved :: #force_inline proc "contextless" (a0, a1, b0, b1: u64) -> (u6
|
||||
}
|
||||
|
||||
load_blockx1 :: proc "contextless" (q: ^[8]u64, src: []byte) {
|
||||
if len(src) != _aes.BLOCK_SIZE {
|
||||
panic_contextless("aes/ct64: invalid block size")
|
||||
}
|
||||
ensure_contextless(len(src) == _aes.BLOCK_SIZE, "aes/ct64: invalid block size")
|
||||
|
||||
q[0], q[4] = #force_inline load_interleaved(src)
|
||||
orthogonalize(q)
|
||||
}
|
||||
|
||||
store_blockx1 :: proc "contextless" (dst: []byte, q: ^[8]u64) {
|
||||
if len(dst) != _aes.BLOCK_SIZE {
|
||||
panic_contextless("aes/ct64: invalid block size")
|
||||
}
|
||||
ensure_contextless(len(dst) == _aes.BLOCK_SIZE, "aes/ct64: invalid block size")
|
||||
|
||||
orthogonalize(q)
|
||||
#force_inline store_interleaved(dst, q[0], q[4])
|
||||
}
|
||||
|
||||
load_blocks :: proc "contextless" (q: ^[8]u64, src: [][]byte) {
|
||||
if n := len(src); n > STRIDE || n == 0 {
|
||||
panic_contextless("aes/ct64: invalid block(s) size")
|
||||
}
|
||||
ensure_contextless(len(src) == 0 || len(src) <= STRIDE, "aes/ct64: invalid block(s) size")
|
||||
|
||||
for s, i in src {
|
||||
if len(s) != _aes.BLOCK_SIZE {
|
||||
panic_contextless("aes/ct64: invalid block size")
|
||||
}
|
||||
ensure_contextless(len(s) == _aes.BLOCK_SIZE, "aes/ct64: invalid block size")
|
||||
q[i], q[i + 4] = #force_inline load_interleaved(s)
|
||||
}
|
||||
orthogonalize(q)
|
||||
}
|
||||
|
||||
store_blocks :: proc "contextless" (dst: [][]byte, q: ^[8]u64) {
|
||||
if n := len(dst); n > STRIDE || n == 0 {
|
||||
panic_contextless("aes/ct64: invalid block(s) size")
|
||||
}
|
||||
ensure_contextless(len(dst) == 0 || len(dst) <= STRIDE, "aes/ct64: invalid block(s) size")
|
||||
|
||||
orthogonalize(q)
|
||||
for d, i in dst {
|
||||
@@ -73,9 +63,7 @@ store_blocks :: proc "contextless" (dst: [][]byte, q: ^[8]u64) {
|
||||
if d == nil {
|
||||
break
|
||||
}
|
||||
if len(d) != _aes.BLOCK_SIZE {
|
||||
panic_contextless("aes/ct64: invalid block size")
|
||||
}
|
||||
ensure_contextless(len(d) == _aes.BLOCK_SIZE, "aes/ct64: invalid block size")
|
||||
#force_inline store_interleaved(d, q[i], q[i + 4])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user