mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
core/crypto/sm3: odinfmt (NFC)
This commit is contained in:
@@ -10,8 +10,8 @@ package sm3
|
|||||||
Implementation of the SM3 hashing algorithm, as defined in <https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02>
|
Implementation of the SM3 hashing algorithm, as defined in <https://datatracker.ietf.org/doc/html/draft-sca-cfrg-sm3-02>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "core:os"
|
|
||||||
import "core:io"
|
import "core:io"
|
||||||
|
import "core:os"
|
||||||
|
|
||||||
import "../util"
|
import "../util"
|
||||||
|
|
||||||
@@ -189,12 +189,18 @@ block :: proc "contextless" (ctx: ^Sm3_Context, buf: []byte) {
|
|||||||
for len(buf) >= 64 {
|
for len(buf) >= 64 {
|
||||||
for i := 0; i < 16; i += 1 {
|
for i := 0; i < 16; i += 1 {
|
||||||
j := i * 4
|
j := i * 4
|
||||||
w[i] = u32(buf[j]) << 24 | u32(buf[j + 1]) << 16 | u32(buf[j + 2]) << 8 | u32(buf[j + 3])
|
w[i] =
|
||||||
|
u32(buf[j]) << 24 | u32(buf[j + 1]) << 16 | u32(buf[j + 2]) << 8 | u32(buf[j + 3])
|
||||||
}
|
}
|
||||||
for i := 16; i < 68; i += 1 {
|
for i := 16; i < 68; i += 1 {
|
||||||
p1v := w[i - 16] ~ w[i - 9] ~ util.ROTL32(w[i - 3], 15)
|
p1v := w[i - 16] ~ w[i - 9] ~ util.ROTL32(w[i - 3], 15)
|
||||||
// @note(zh): inlined P1
|
// @note(zh): inlined P1
|
||||||
w[i] = p1v ~ util.ROTL32(p1v, 15) ~ util.ROTL32(p1v, 23) ~ util.ROTL32(w[i - 13], 7) ~ w[i - 6]
|
w[i] =
|
||||||
|
p1v ~
|
||||||
|
util.ROTL32(p1v, 15) ~
|
||||||
|
util.ROTL32(p1v, 23) ~
|
||||||
|
util.ROTL32(w[i - 13], 7) ~
|
||||||
|
w[i - 6]
|
||||||
}
|
}
|
||||||
for i := 0; i < 64; i += 1 {
|
for i := 0; i < 64; i += 1 {
|
||||||
wp[i] = w[i] ~ w[i + 4]
|
wp[i] = w[i] ~ w[i + 4]
|
||||||
@@ -215,7 +221,8 @@ block :: proc "contextless" (ctx: ^Sm3_Context, buf: []byte) {
|
|||||||
|
|
||||||
a, b, c, d = tt1, a, util.ROTL32(u32(b), 9), c
|
a, b, c, d = tt1, a, util.ROTL32(u32(b), 9), c
|
||||||
// @note(zh): inlined P0
|
// @note(zh): inlined P0
|
||||||
e, f, g, h = (tt2 ~ util.ROTL32(tt2, 9) ~ util.ROTL32(tt2, 17)), e, util.ROTL32(u32(f), 19), g
|
e, f, g, h =
|
||||||
|
(tt2 ~ util.ROTL32(tt2, 9) ~ util.ROTL32(tt2, 17)), e, util.ROTL32(u32(f), 19), g
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 16; i < 64; i += 1 {
|
for i := 16; i < 64; i += 1 {
|
||||||
@@ -230,7 +237,8 @@ block :: proc "contextless" (ctx: ^Sm3_Context, buf: []byte) {
|
|||||||
|
|
||||||
a, b, c, d = tt1, a, util.ROTL32(u32(b), 9), c
|
a, b, c, d = tt1, a, util.ROTL32(u32(b), 9), c
|
||||||
// @note(zh): inlined P0
|
// @note(zh): inlined P0
|
||||||
e, f, g, h = (tt2 ~ util.ROTL32(tt2, 9) ~ util.ROTL32(tt2, 17)), e, util.ROTL32(u32(f), 19), g
|
e, f, g, h =
|
||||||
|
(tt2 ~ util.ROTL32(tt2, 9) ~ util.ROTL32(tt2, 17)), e, util.ROTL32(u32(f), 19), g
|
||||||
}
|
}
|
||||||
|
|
||||||
state0 ~= a
|
state0 ~= a
|
||||||
|
|||||||
Reference in New Issue
Block a user