diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2026-02-12 18:26:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-12 18:26:39 +0100 |
| commit | c9f53fdfd70f9b90c9dfca9d01af482ce121d7c4 (patch) | |
| tree | b2a725d684c4da52757591c864828554a919db8d /core/crypto/_aes | |
| parent | 1159110e735ba84d651f4bbc4e9883fd83e9eddc (diff) | |
| parent | c0300a33039ab003cbf105c082fe43de4b17ab96 (diff) | |
Merge pull request #6264 from Kelimion/mem_to_runtime
Replace trivial `core:mem` imports with `base:runtime`.
Diffstat (limited to 'core/crypto/_aes')
| -rw-r--r-- | core/crypto/_aes/ct64/api.odin | 7 | ||||
| -rw-r--r-- | core/crypto/_aes/ct64/ct64_dec.odin | 2 | ||||
| -rw-r--r-- | core/crypto/_aes/ct64/ct64_keysched.odin | 8 | ||||
| -rw-r--r-- | core/crypto/_aes/hw_intel/hw_intel_keysched.odin | 26 |
4 files changed, 31 insertions, 12 deletions
diff --git a/core/crypto/_aes/ct64/api.odin b/core/crypto/_aes/ct64/api.odin index f57a630b1..08acd37ed 100644 --- a/core/crypto/_aes/ct64/api.odin +++ b/core/crypto/_aes/ct64/api.odin @@ -1,7 +1,6 @@ package aes_ct64 -import "base:intrinsics" -import "core:mem" +import "core:crypto" STRIDE :: 4 @@ -82,5 +81,5 @@ decrypt_blocks :: proc(ctx: ^Context, dst, src: [][]byte) { // reset sanitizes the Context. The Context must be re-initialized to // be used again. reset :: proc(ctx: ^Context) { - mem.zero_explicit(ctx, size_of(ctx)) -} + crypto.zero_explicit(ctx, size_of(ctx)) +}
\ No newline at end of file diff --git a/core/crypto/_aes/ct64/ct64_dec.odin b/core/crypto/_aes/ct64/ct64_dec.odin index 408ee6002..6fca7a5f2 100644 --- a/core/crypto/_aes/ct64/ct64_dec.odin +++ b/core/crypto/_aes/ct64/ct64_dec.odin @@ -22,8 +22,6 @@ package aes_ct64 -import "base:intrinsics" - inv_sub_bytes :: proc "contextless" (q: ^[8]u64) { // AES S-box is: // S(x) = A(I(x)) ^ 0x63 diff --git a/core/crypto/_aes/ct64/ct64_keysched.odin b/core/crypto/_aes/ct64/ct64_keysched.odin index 0f00bba57..d0004dd5a 100644 --- a/core/crypto/_aes/ct64/ct64_keysched.odin +++ b/core/crypto/_aes/ct64/ct64_keysched.odin @@ -22,9 +22,9 @@ package aes_ct64 +import "core:crypto" import "core:crypto/_aes" import "core:encoding/endian" -import "core:mem" @(private, require_results) sub_word :: proc "contextless" (x: u32) -> u32 { @@ -35,7 +35,7 @@ sub_word :: proc "contextless" (x: u32) -> u32 { orthogonalize(&q) ret := u32(q[0]) - mem.zero_explicit(&q[0], size_of(u64)) + crypto.zero_explicit(&q[0], size_of(u64)) return ret } @@ -97,8 +97,8 @@ keysched :: proc "contextless" (comp_skey: []u64, key: []byte) -> int { (q[7] & 0x8888888888888888) } - mem.zero_explicit(&skey, size_of(skey)) - mem.zero_explicit(&q, size_of(q)) + crypto.zero_explicit(&skey, size_of(skey)) + crypto.zero_explicit(&q, size_of(q)) return num_rounds } diff --git a/core/crypto/_aes/hw_intel/hw_intel_keysched.odin b/core/crypto/_aes/hw_intel/hw_intel_keysched.odin index bdf0d3066..96108442d 100644 --- a/core/crypto/_aes/hw_intel/hw_intel_keysched.odin +++ b/core/crypto/_aes/hw_intel/hw_intel_keysched.odin @@ -25,7 +25,6 @@ package aes_hw_intel import "base:intrinsics" import "core:crypto/_aes" -import "core:mem" import "core:simd/x86" // Intel AES-NI based implementation. Inspiration taken from BearSSL. @@ -174,5 +173,28 @@ keysched :: proc(ctx: ^Context, key: []byte) { ctx._num_rounds = num_rounds - mem.zero_explicit(&sks, size_of(sks)) + zero_explicit(&sks, size_of(sks)) } + +/* +Set each byte of a memory range to zero. + +This procedure copies the value `0` into the `len` bytes of a memory range, +starting at address `data`. + +This procedure returns the pointer to `data`. + +Unlike the `zero()` procedure, which can be optimized away or reordered by the +compiler under certain circumstances, `zero_explicit()` procedure can not be +optimized away or reordered with other memory access operations, and the +compiler assumes volatile semantics of the memory. +*/ +zero_explicit :: proc "contextless" (data: rawptr, len: int) -> rawptr { + // This routine tries to avoid the compiler optimizing away the call, + // so that it is always executed. It is intended to provide + // equivalent semantics to those provided by the C11 Annex K 3.7.4.1 + // memset_s call. + intrinsics.mem_zero_volatile(data, len) // Use the volatile mem_zero + intrinsics.atomic_thread_fence(.Seq_Cst) // Prevent reordering + return data +}
\ No newline at end of file |