core/crypto/blake2: odinfmt (NFC)

This commit is contained in:
Yawning Angel
2023-11-17 16:53:29 +09:00
parent 12b370ddc1
commit d6e0e5d3f6
3 changed files with 152 additions and 139 deletions
+20 -7
View File
@@ -50,7 +50,9 @@ Blake2_Config :: struct {
key: []byte, key: []byte,
salt: []byte, salt: []byte,
person: []byte, person: []byte,
tree: union{Blake2_Tree}, tree: union {
Blake2_Tree,
},
} }
Blake2_Tree :: struct { Blake2_Tree :: struct {
@@ -257,7 +259,8 @@ blocks :: proc "contextless" (ctx: ^$T, p: []byte) {
} }
blake2s_blocks :: #force_inline proc "contextless" (ctx: ^Blake2s_Context, p: []byte) { blake2s_blocks :: #force_inline proc "contextless" (ctx: ^Blake2s_Context, p: []byte) {
h0, h1, h2, h3, h4, h5, h6, h7 := ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] h0, h1, h2, h3, h4, h5, h6, h7 :=
ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7]
p := p p := p
for len(p) >= BLAKE2S_BLOCK_SIZE { for len(p) >= BLAKE2S_BLOCK_SIZE {
ctx.t[0] += BLAKE2S_BLOCK_SIZE ctx.t[0] += BLAKE2S_BLOCK_SIZE
@@ -1409,11 +1412,13 @@ blake2s_blocks :: #force_inline proc "contextless" (ctx: ^Blake2s_Context, p: []
h7 ~= v7 ~ v15 h7 ~= v7 ~ v15
p = p[BLAKE2S_BLOCK_SIZE:] p = p[BLAKE2S_BLOCK_SIZE:]
} }
ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] = h0, h1, h2, h3, h4, h5, h6, h7 ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] =
h0, h1, h2, h3, h4, h5, h6, h7
} }
blake2b_blocks :: #force_inline proc "contextless" (ctx: ^Blake2b_Context, p: []byte) { blake2b_blocks :: #force_inline proc "contextless" (ctx: ^Blake2b_Context, p: []byte) {
h0, h1, h2, h3, h4, h5, h6, h7 := ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] h0, h1, h2, h3, h4, h5, h6, h7 :=
ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7]
p := p p := p
for len(p) >= BLAKE2B_BLOCK_SIZE { for len(p) >= BLAKE2B_BLOCK_SIZE {
ctx.t[0] += BLAKE2B_BLOCK_SIZE ctx.t[0] += BLAKE2B_BLOCK_SIZE
@@ -1432,8 +1437,15 @@ blake2b_blocks :: #force_inline proc "contextless" (ctx: ^Blake2b_Context, p: []
m: [16]u64 = --- m: [16]u64 = ---
j := 0 j := 0
for i := 0; i < 16; i += 1 { for i := 0; i < 16; i += 1 {
m[i] = u64(p[j]) | u64(p[j + 1]) << 8 | u64(p[j + 2]) << 16 | u64(p[j + 3]) << 24 | m[i] =
u64(p[j + 4]) << 32 | u64(p[j + 5]) << 40 | u64(p[j + 6]) << 48 | u64(p[j + 7]) << 56 u64(p[j]) |
u64(p[j + 1]) << 8 |
u64(p[j + 2]) << 16 |
u64(p[j + 3]) << 24 |
u64(p[j + 4]) << 32 |
u64(p[j + 5]) << 40 |
u64(p[j + 6]) << 48 |
u64(p[j + 7]) << 56
j += 8 j += 8
} }
v0 += m[0] v0 += m[0]
@@ -2790,5 +2802,6 @@ blake2b_blocks :: #force_inline proc "contextless" (ctx: ^Blake2b_Context, p: []
h7 ~= v7 ~ v15 h7 ~= v7 ~ v15
p = p[BLAKE2B_BLOCK_SIZE:] p = p[BLAKE2B_BLOCK_SIZE:]
} }
ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] = h0, h1, h2, h3, h4, h5, h6, h7 ctx.h[0], ctx.h[1], ctx.h[2], ctx.h[3], ctx.h[4], ctx.h[5], ctx.h[6], ctx.h[7] =
h0, h1, h2, h3, h4, h5, h6, h7
} }
+3 -3
View File
@@ -7,12 +7,12 @@ package blake2b
List of contributors: List of contributors:
zhibog, dotbmp: Initial implementation. zhibog, dotbmp: Initial implementation.
Interface for the BLAKE2B hashing algorithm. Interface for the BLAKE2b hashing algorithm.
BLAKE2B and BLAKE2B share the implementation in the _blake2 package. BLAKE2b and BLAKE2s share the implementation in the _blake2 package.
*/ */
import "core:os"
import "core:io" import "core:io"
import "core:os"
import "../_blake2" import "../_blake2"
+3 -3
View File
@@ -7,12 +7,12 @@ package blake2s
List of contributors: List of contributors:
zhibog, dotbmp: Initial implementation. zhibog, dotbmp: Initial implementation.
Interface for the BLAKE2S hashing algorithm. Interface for the BLAKE2s hashing algorithm.
BLAKE2B and BLAKE2B share the implementation in the _blake2 package. BLAKE2s and BLAKE2b share the implementation in the _blake2 package.
*/ */
import "core:os"
import "core:io" import "core:io"
import "core:os"
import "../_blake2" import "../_blake2"