1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-26 00:51:22 +00:00

adds sha2: wip

This commit is contained in:
Henry Case 2021-03-07 15:36:46 +00:00
parent 8474981cfc
commit 29c33a33a7
3 changed files with 953 additions and 0 deletions

245
hash/sha2/compress.go Normal file
View File

@ -0,0 +1,245 @@
package sha2
func rotl32(count uint32, val uint32) uint32 {
return (val << count) | (val >> (32 - count))
}
// compression
func p0(X uint32) uint32 {
return X ^ rotl32(9, X) ^ rotl32(17, X)
}
// expansion
func p1(X uint32) uint32 {
return X ^ rotl32(15, X) ^ rotl32(23, X)
}
func ff1(X uint32, Y uint32, Z uint32) uint32 {
return (X & Y) | ((X | Y) & Z)
}
func gg1(X uint32, Y uint32, Z uint32) uint32 {
return (X & Y) ^ ((^X) & Z) // Can be also (Z ^ (X & (Y ^ Z)))
}
func r1(
A uint32, B *uint32, C uint32, D *uint32, E uint32, F *uint32,
G uint32, H *uint32, TJ uint32, Wi uint32, Wj uint32) {
A12 := rotl32(12, A)
SS1 := rotl32(7, A12+E+TJ)
TT1 := (A ^ *B ^ C) + *D + (SS1 ^ A12) + Wj
TT2 := (E ^ *F ^ G) + *H + SS1 + Wi
*B = rotl32(9, *B)
*D = TT1
*F = rotl32(19, *F)
*H = p0(TT2)
}
func r2(
A uint32, B *uint32, C uint32, D *uint32, E uint32, F *uint32,
G uint32, H *uint32, TJ uint32, Wi uint32, Wj uint32) {
A12 := rotl32(12, A)
SS1 := rotl32(7, A12+E+TJ)
TT1 := ff1(A, *B, C) + *D + (SS1 ^ A12) + Wj
TT2 := gg1(E, *F, G) + *H + SS1 + Wi
*B = rotl32(9, *B)
*D = TT1
*F = rotl32(19, *F)
*H = p0(TT2)
}
func sm3e(W0 uint32, W7 uint32, W13 uint32, W3 uint32, W10 uint32) uint32 {
return p1(W0^W7^rotl32(15, W13)) ^ rotl32(7, W3) ^ W10
}
func loadBe32(x []byte) uint32 {
return uint32(x[3]) | (uint32(x[2]) << 8) | (uint32(x[1]) << 16) | (uint32(x[0]) << 24)
}
func store64Be(val []byte, x uint64) {
val[0] = byte(x >> 56)
val[1] = byte(x >> 48)
val[2] = byte(x >> 40)
val[3] = byte(x >> 32)
val[4] = byte(x >> 24)
val[5] = byte(x >> 16)
val[6] = byte(x >> 8)
val[7] = byte(x >> 0)
}
func store32Be(val []byte, x uint32) {
val[0] = byte(x >> 24)
val[1] = byte(x >> 16)
val[2] = byte(x >> 8)
val[3] = byte(x >> 0)
}
func (d *digest) compress(input []byte, blocks int) {
A := d.h[0]
B := d.h[1]
C := d.h[2]
D := d.h[3]
E := d.h[4]
F := d.h[5]
G := d.h[6]
H := d.h[7]
for i := 0; i < blocks; i++ {
next64Block := input[i*64:]
W00 := loadBe32(next64Block[0:])
W01 := loadBe32(next64Block[4:])
W02 := loadBe32(next64Block[8:])
W03 := loadBe32(next64Block[12:])
W04 := loadBe32(next64Block[16:])
W05 := loadBe32(next64Block[20:])
W06 := loadBe32(next64Block[24:])
W07 := loadBe32(next64Block[28:])
W08 := loadBe32(next64Block[32:])
W09 := loadBe32(next64Block[36:])
W10 := loadBe32(next64Block[40:])
W11 := loadBe32(next64Block[44:])
W12 := loadBe32(next64Block[48:])
W13 := loadBe32(next64Block[52:])
W14 := loadBe32(next64Block[56:])
W15 := loadBe32(next64Block[60:])
r1(A, &B, C, &D, E, &F, G, &H, 0x79CC4519, W00, W00^W04)
W00 = sm3e(W00, W07, W13, W03, W10)
r1(D, &A, B, &C, H, &E, F, &G, 0xF3988A32, W01, W01^W05)
W01 = sm3e(W01, W08, W14, W04, W11)
r1(C, &D, A, &B, G, &H, E, &F, 0xE7311465, W02, W02^W06)
W02 = sm3e(W02, W09, W15, W05, W12)
r1(B, &C, D, &A, F, &G, H, &E, 0xCE6228CB, W03, W03^W07)
W03 = sm3e(W03, W10, W00, W06, W13)
r1(A, &B, C, &D, E, &F, G, &H, 0x9CC45197, W04, W04^W08)
W04 = sm3e(W04, W11, W01, W07, W14)
r1(D, &A, B, &C, H, &E, F, &G, 0x3988A32F, W05, W05^W09)
W05 = sm3e(W05, W12, W02, W08, W15)
r1(C, &D, A, &B, G, &H, E, &F, 0x7311465E, W06, W06^W10)
W06 = sm3e(W06, W13, W03, W09, W00)
r1(B, &C, D, &A, F, &G, H, &E, 0xE6228CBC, W07, W07^W11)
W07 = sm3e(W07, W14, W04, W10, W01)
r1(A, &B, C, &D, E, &F, G, &H, 0xCC451979, W08, W08^W12)
W08 = sm3e(W08, W15, W05, W11, W02)
r1(D, &A, B, &C, H, &E, F, &G, 0x988A32F3, W09, W09^W13)
W09 = sm3e(W09, W00, W06, W12, W03)
r1(C, &D, A, &B, G, &H, E, &F, 0x311465E7, W10, W10^W14)
W10 = sm3e(W10, W01, W07, W13, W04)
r1(B, &C, D, &A, F, &G, H, &E, 0x6228CBCE, W11, W11^W15)
W11 = sm3e(W11, W02, W08, W14, W05)
r1(A, &B, C, &D, E, &F, G, &H, 0xC451979C, W12, W12^W00)
W12 = sm3e(W12, W03, W09, W15, W06)
r1(D, &A, B, &C, H, &E, F, &G, 0x88A32F39, W13, W13^W01)
W13 = sm3e(W13, W04, W10, W00, W07)
r1(C, &D, A, &B, G, &H, E, &F, 0x11465E73, W14, W14^W02)
W14 = sm3e(W14, W05, W11, W01, W08)
r1(B, &C, D, &A, F, &G, H, &E, 0x228CBCE6, W15, W15^W03)
W15 = sm3e(W15, W06, W12, W02, W09)
r2(A, &B, C, &D, E, &F, G, &H, 0x9D8A7A87, W00, W00^W04)
W00 = sm3e(W00, W07, W13, W03, W10)
r2(D, &A, B, &C, H, &E, F, &G, 0x3B14F50F, W01, W01^W05)
W01 = sm3e(W01, W08, W14, W04, W11)
r2(C, &D, A, &B, G, &H, E, &F, 0x7629EA1E, W02, W02^W06)
W02 = sm3e(W02, W09, W15, W05, W12)
r2(B, &C, D, &A, F, &G, H, &E, 0xEC53D43C, W03, W03^W07)
W03 = sm3e(W03, W10, W00, W06, W13)
r2(A, &B, C, &D, E, &F, G, &H, 0xD8A7A879, W04, W04^W08)
W04 = sm3e(W04, W11, W01, W07, W14)
r2(D, &A, B, &C, H, &E, F, &G, 0xB14F50F3, W05, W05^W09)
W05 = sm3e(W05, W12, W02, W08, W15)
r2(C, &D, A, &B, G, &H, E, &F, 0x629EA1E7, W06, W06^W10)
W06 = sm3e(W06, W13, W03, W09, W00)
r2(B, &C, D, &A, F, &G, H, &E, 0xC53D43CE, W07, W07^W11)
W07 = sm3e(W07, W14, W04, W10, W01)
r2(A, &B, C, &D, E, &F, G, &H, 0x8A7A879D, W08, W08^W12)
W08 = sm3e(W08, W15, W05, W11, W02)
r2(D, &A, B, &C, H, &E, F, &G, 0x14F50F3B, W09, W09^W13)
W09 = sm3e(W09, W00, W06, W12, W03)
r2(C, &D, A, &B, G, &H, E, &F, 0x29EA1E76, W10, W10^W14)
W10 = sm3e(W10, W01, W07, W13, W04)
r2(B, &C, D, &A, F, &G, H, &E, 0x53D43CEC, W11, W11^W15)
W11 = sm3e(W11, W02, W08, W14, W05)
r2(A, &B, C, &D, E, &F, G, &H, 0xA7A879D8, W12, W12^W00)
W12 = sm3e(W12, W03, W09, W15, W06)
r2(D, &A, B, &C, H, &E, F, &G, 0x4F50F3B1, W13, W13^W01)
W13 = sm3e(W13, W04, W10, W00, W07)
r2(C, &D, A, &B, G, &H, E, &F, 0x9EA1E762, W14, W14^W02)
W14 = sm3e(W14, W05, W11, W01, W08)
r2(B, &C, D, &A, F, &G, H, &E, 0x3D43CEC5, W15, W15^W03)
W15 = sm3e(W15, W06, W12, W02, W09)
r2(A, &B, C, &D, E, &F, G, &H, 0x7A879D8A, W00, W00^W04)
W00 = sm3e(W00, W07, W13, W03, W10)
r2(D, &A, B, &C, H, &E, F, &G, 0xF50F3B14, W01, W01^W05)
W01 = sm3e(W01, W08, W14, W04, W11)
r2(C, &D, A, &B, G, &H, E, &F, 0xEA1E7629, W02, W02^W06)
W02 = sm3e(W02, W09, W15, W05, W12)
r2(B, &C, D, &A, F, &G, H, &E, 0xD43CEC53, W03, W03^W07)
W03 = sm3e(W03, W10, W00, W06, W13)
r2(A, &B, C, &D, E, &F, G, &H, 0xA879D8A7, W04, W04^W08)
W04 = sm3e(W04, W11, W01, W07, W14)
r2(D, &A, B, &C, H, &E, F, &G, 0x50F3B14F, W05, W05^W09)
W05 = sm3e(W05, W12, W02, W08, W15)
r2(C, &D, A, &B, G, &H, E, &F, 0xA1E7629E, W06, W06^W10)
W06 = sm3e(W06, W13, W03, W09, W00)
r2(B, &C, D, &A, F, &G, H, &E, 0x43CEC53D, W07, W07^W11)
W07 = sm3e(W07, W14, W04, W10, W01)
r2(A, &B, C, &D, E, &F, G, &H, 0x879D8A7A, W08, W08^W12)
W08 = sm3e(W08, W15, W05, W11, W02)
r2(D, &A, B, &C, H, &E, F, &G, 0x0F3B14F5, W09, W09^W13)
W09 = sm3e(W09, W00, W06, W12, W03)
r2(C, &D, A, &B, G, &H, E, &F, 0x1E7629EA, W10, W10^W14)
W10 = sm3e(W10, W01, W07, W13, W04)
r2(B, &C, D, &A, F, &G, H, &E, 0x3CEC53D4, W11, W11^W15)
W11 = sm3e(W11, W02, W08, W14, W05)
r2(A, &B, C, &D, E, &F, G, &H, 0x79D8A7A8, W12, W12^W00)
W12 = sm3e(W12, W03, W09, W15, W06)
r2(D, &A, B, &C, H, &E, F, &G, 0xF3B14F50, W13, W13^W01)
W13 = sm3e(W13, W04, W10, W00, W07)
r2(C, &D, A, &B, G, &H, E, &F, 0xE7629EA1, W14, W14^W02)
W14 = sm3e(W14, W05, W11, W01, W08)
r2(B, &C, D, &A, F, &G, H, &E, 0xCEC53D43, W15, W15^W03)
W15 = sm3e(W15, W06, W12, W02, W09)
r2(A, &B, C, &D, E, &F, G, &H, 0x9D8A7A87, W00, W00^W04)
W00 = sm3e(W00, W07, W13, W03, W10)
r2(D, &A, B, &C, H, &E, F, &G, 0x3B14F50F, W01, W01^W05)
W01 = sm3e(W01, W08, W14, W04, W11)
r2(C, &D, A, &B, G, &H, E, &F, 0x7629EA1E, W02, W02^W06)
W02 = sm3e(W02, W09, W15, W05, W12)
r2(B, &C, D, &A, F, &G, H, &E, 0xEC53D43C, W03, W03^W07)
W03 = sm3e(W03, W10, W00, W06, W13)
r2(A, &B, C, &D, E, &F, G, &H, 0xD8A7A879, W04, W04^W08)
r2(D, &A, B, &C, H, &E, F, &G, 0xB14F50F3, W05, W05^W09)
r2(C, &D, A, &B, G, &H, E, &F, 0x629EA1E7, W06, W06^W10)
r2(B, &C, D, &A, F, &G, H, &E, 0xC53D43CE, W07, W07^W11)
r2(A, &B, C, &D, E, &F, G, &H, 0x8A7A879D, W08, W08^W12)
r2(D, &A, B, &C, H, &E, F, &G, 0x14F50F3B, W09, W09^W13)
r2(C, &D, A, &B, G, &H, E, &F, 0x29EA1E76, W10, W10^W14)
r2(B, &C, D, &A, F, &G, H, &E, 0x53D43CEC, W11, W11^W15)
r2(A, &B, C, &D, E, &F, G, &H, 0xA7A879D8, W12, W12^W00)
r2(D, &A, B, &C, H, &E, F, &G, 0x4F50F3B1, W13, W13^W01)
r2(C, &D, A, &B, G, &H, E, &F, 0x9EA1E762, W14, W14^W02)
r2(B, &C, D, &A, F, &G, H, &E, 0x3D43CEC5, W15, W15^W03)
d.h[0] ^= A
d.h[1] ^= B
d.h[2] ^= C
d.h[3] ^= D
d.h[4] ^= E
d.h[5] ^= F
d.h[6] ^= G
d.h[7] ^= H
A = d.h[0]
B = d.h[1]
C = d.h[2]
D = d.h[3]
E = d.h[4]
F = d.h[5]
G = d.h[6]
H = d.h[7]
}
}

110
hash/sha2/sha2.go Normal file
View File

@ -0,0 +1,110 @@
// Package sha2 implements the SM-3 hash algorithm as defined in "SM3 Hash
// function draft-shen-sha2-hash-01" draft
//
package sha2
import (
"hash"
)
const (
init0 = 0x6A09E667
init1 = 0xBB67AE85
init2 = 0x3C6EF372
init3 = 0xA54FF53A
init4 = 0x510E527F
init5 = 0x9B05688C
init6 = 0x1F83D9AB
init7 = 0x5BE0CD19
)
// The size of a SM-3 checksum in bytes.
const Size = 32
// The blocksize of SM-3 in bytes.
const BlockSize int = 64
// digest represents the partial evaluation of a checksum.
type digest struct {
h [8]uint32
len uint64
b [BlockSize]byte
}
func New() hash.Hash {
d := new(digest)
d.Reset()
return d
}
func (d *digest) BlockSize() int { return BlockSize }
func (d *digest) Size() int { return Size }
func (d *digest) Init() { d.Reset() }
func (d *digest) Reset() {
d.h[0] = init0
d.h[1] = init1
d.h[2] = init2
d.h[3] = init3
d.h[4] = init4
d.h[5] = init5
d.h[6] = init6
d.h[7] = init7
d.len = 0
}
func (d *digest) Write(input []byte) (nn int, err error) {
// current possition in the buffer
idx := int(d.len & uint64((d.BlockSize() - 1)))
d.len += uint64(len(input))
if len(input)+idx < d.BlockSize() {
copy(d.b[idx:], input)
return
}
c := d.BlockSize() - idx
copy(d.b[idx:], input[:c])
d.compress(d.b[:], 1)
input = input[c:]
nblocks := int(len(input) / d.BlockSize())
d.compress(input[:], nblocks)
// this eventually could be done in d.compress
copy(d.b[:], input[nblocks*d.BlockSize():])
return len(input), nil
}
func (d *digest) Sum(in []byte) []byte {
var output [32]byte
// Copy context so that caller can keep updating
dc := *d
dc.Write(in)
idx := int(dc.len & uint64(dc.BlockSize()-1))
for i := idx + 1; i < len(dc.b); i++ {
dc.b[i] = 0
}
dc.b[idx] = 0x80
if idx >= 56 {
dc.compress(dc.b[:], 1)
for i := range dc.b {
dc.b[i] = 0
}
}
// add total bits
store64Be(dc.b[56:], dc.len*8)
dc.compress(dc.b[:], 1)
for i := 0; i < Size/4; i++ {
store32Be(output[4*i:], dc.h[i])
}
return output[:]
}

598
hash/sha2/sha2_test.go Normal file
View File

@ -0,0 +1,598 @@
package sha2
import (
"encoding/hex"
"testing"
)
/* -------------------- Unit tests -----------------------*/
func do_hash(t *testing.T, idx int, input []byte, expected_output [32]byte) {
var d digest
var output [32]byte
d.Init()
d.Write(input[:])
copy(output[:], d.Sum(nil))
if output != expected_output {
exp := make([]byte, hex.EncodedLen(32))
hex.Encode(exp, expected_output[:])
got := make([]byte, hex.EncodedLen(len(output)))
hex.Encode(got, output[:])
t.Errorf("[%d]: %s != %s", idx, exp, got)
}
}
func TestSHA256OfficialVectors(t *testing.T) {
var vectors = []struct {
in []byte
out [32]byte
}{
{
[]byte(""),
[32]byte{
0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55},
},
/*
// draft-shen-sha2-hash-01: Example 2
{
[]byte{
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64},
[32]byte{
0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1, 0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d,
0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65, 0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32},
},
// B.1. GB/T 32918.2-2016 A.2 Example 1
{
[]byte{
0x00, 0x90, 0x41, 0x4C, 0x49, 0x43, 0x45, 0x31, 0x32, 0x33, 0x40, 0x59, 0x41, 0x48, 0x4F, 0x4F,
0x2E, 0x43, 0x4F, 0x4D, 0x78, 0x79, 0x68, 0xB4, 0xFA, 0x32, 0xC3, 0xFD, 0x24, 0x17, 0x84, 0x2E,
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0xF4, 0xA3, 0x84, 0x89, 0xE3, 0x2B, 0x45, 0xB6, 0xF8, 0x76, 0xE3, 0xAC, 0x21, 0x68, 0xCA, 0x39,
0x23, 0x62, 0xDC, 0x8F, 0x23, 0x45, 0x9C, 0x1D, 0x11, 0x46, 0xFC, 0x3D, 0xBF, 0xB7, 0xBC, 0x9A,
},
},
// B.2. GB/T 32918.2-2016 A.2 Example 2
{
[]byte{
0xF4, 0xA3, 0x84, 0x89, 0xE3, 0x2B, 0x45, 0xB6, 0xF8, 0x76, 0xE3, 0xAC, 0x21, 0x68, 0xCA, 0x39,
0x23, 0x62, 0xDC, 0x8F, 0x23, 0x45, 0x9C, 0x1D, 0x11, 0x46, 0xFC, 0x3D, 0xBF, 0xB7, 0xBC, 0x9A,
0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74,
},
[32]byte{
0xB5, 0x24, 0xF5, 0x52, 0xCD, 0x82, 0xB8, 0xB0, 0x28, 0x47, 0x6E, 0x00, 0x5C, 0x37, 0x7F, 0xB1,
0x9A, 0x87, 0xE6, 0xFC, 0x68, 0x2D, 0x48, 0xBB, 0x5D, 0x42, 0xE3, 0xD9, 0xB9, 0xEF, 0xFE, 0x76,
},
},
// B.3. GB/T 32918.2-2016 A.3 Example 1
{
[]byte{
0x00, 0x90, 0x41, 0x4C, 0x49, 0x43, 0x45, 0x31, 0x32, 0x33, 0x40, 0x59, 0x41, 0x48, 0x4F, 0x4F,
0x2E, 0x43, 0x4F, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE7, 0x8B, 0xCD, 0x09, 0x74, 0x6C, 0x20, 0x23, 0x78, 0xA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0x97, 0xA8, 0x1F, 0xD5,
},
},
// B.4. GB/T 32918.2-2016 A.3 Example 2
{
[]byte{
0x26, 0x35, 0x2A, 0xF8, 0x2E, 0xC1, 0x9F, 0x20, 0x7B, 0xBC, 0x6F, 0x94, 0x74, 0xE1, 0x1E, 0x90,
0xCE, 0x0F, 0x7D, 0xDA, 0xCE, 0x03, 0xB2, 0x7F, 0x80, 0x18, 0x17, 0xE8, 0x97, 0xA8, 0x1F, 0xD5,
0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74},
[32]byte{
0xAD, 0x67, 0x3C, 0xBD, 0xA3, 0x11, 0x41, 0x71, 0x29, 0xA9, 0xEA, 0xA5, 0xF9, 0xAB, 0x1A, 0xA1,
0x63, 0x3A, 0xD4, 0x77, 0x18, 0xA8, 0x4D, 0xFD, 0x46, 0xC1, 0x7C, 0x6F, 0xA0, 0xAA, 0x3B, 0x12,
},
},
// B.5. GB/T 32918.3-2016 A.2 Example 1
{
[]byte{
0x00, 0x90, 0x41, 0x4C, 0x49, 0x43, 0x45, 0x31, 0x32, 0x33, 0x40, 0x59, 0x41, 0x48, 0x4F, 0x4F,
0x2E, 0x43, 0x4F, 0x4D, 0x78, 0x79, 0x68, 0xB4, 0xFA, 0x32, 0xC3, 0xFD, 0x24, 0x17, 0x84, 0x2E,
0x73, 0xBB, 0xFE, 0xFF, 0x2F, 0x3C, 0x84, 0x8B, 0x68, 0x31, 0xD7, 0xE0, 0xEC, 0x65, 0x22, 0x8B,
0x39, 0x37, 0xE4, 0x98, 0x63, 0xE4, 0xC6, 0xD3, 0xB2, 0x3B, 0x0C, 0x84, 0x9C, 0xF8, 0x42, 0x41,
0x48, 0x4B, 0xFE, 0x48, 0xF6, 0x1D, 0x59, 0xA5, 0xB1, 0x6B, 0xA0, 0x6E, 0x6E, 0x12, 0xD1, 0xDA,
0x27, 0xC5, 0x24, 0x9A, 0x42, 0x1D, 0xEB, 0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70, 0x91,
0x10, 0x9F, 0x51, 0x39, 0x44, 0x42, 0x91, 0x6B, 0xD1, 0x54, 0xD1, 0xDE, 0x43, 0x79, 0xD9, 0x76,
0x47,
},
[32]byte{
0x28, 0x4C, 0x8F, 0x19, 0x8F, 0x14, 0x1B, 0x50, 0x2E, 0x81, 0x25, 0x0F, 0x15, 0x81, 0xC7, 0xE9,
0xEE, 0xB4, 0xCA, 0x69, 0x90, 0xF9, 0xE0, 0x2D, 0xF3, 0x88, 0xB4, 0x54, 0x71, 0xF5, 0xBC, 0x5C,
},
},
// B.9. GB/T 32918.3-2016 A.2 Example 5
{
[]byte{
0x03, 0x2A, 0xF8, 0x6E, 0xFE, 0x73, 0x2C, 0xF1, 0x2A, 0xD0, 0xE0, 0x9A, 0x1F, 0x25, 0x56, 0xCC,
0x65, 0x0D, 0x9C, 0xCC, 0xE3, 0xE2, 0x49, 0x86, 0x6B, 0xBB, 0x5C, 0x68, 0x46, 0xA4, 0xC4, 0xA2,
0x95, 0xFF, 0x49, 0xD9, 0x5B, 0xD4, 0x5F, 0xCE, 0x99, 0xED, 0x54, 0xA8, 0xAD, 0x7A, 0x70, 0x91,
0x10, 0x9F, 0x51, 0x39, 0x44, 0x42, 0x91, 0x6B, 0xD1, 0x54, 0xD1, 0xDE, 0x43, 0x79, 0xD9, 0x76,
0x47,
},
[32]byte{
0x23, 0x44, 0x4D, 0xAF, 0x8E, 0xD7, 0x53, 0x43, 0x66, 0xCB, 0x90, 0x1C, 0x84, 0xB3, 0xBD, 0xBB,
0x63, 0x50, 0x4F, 0x40, 0x65, 0xC1, 0x11, 0x6C, 0x91, 0xA4, 0xC0, 0x06, 0x97, 0xE6, 0xCF, 0x7A,
},
},
// B.11. GB/T 32918.3-2016 A.3 Example 2
{
[]byte{
0x00, 0x88, 0x42, 0x49, 0x4C, 0x4C, 0x34, 0x35, 0x36, 0x40, 0x59, 0x41, 0x48, 0x4F, 0x4F, 0x2E,
0x43, 0x4F, 0x4D, 0x00, 0x00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D, 0x86, 0x69,
0x43, 0x11, 0x56, 0x29, 0x14, 0xF4, 0xF6, 0xA3, 0x42, 0x41, 0x01, 0xD8, 0x85, 0xF8, 0x8B, 0x05,
0x36, 0x9C,
},
[32]byte{
0x4E, 0xB4, 0x7D, 0x28, 0xAD, 0x39, 0x06, 0xD6, 0x24, 0x4D, 0x01, 0xE0, 0xF6, 0xAE, 0xC7, 0x3B,
0x0B, 0x51, 0xDE, 0x15, 0x74, 0xC1, 0x37, 0x98, 0x18, 0x4E, 0x48, 0x33, 0xDB, 0xAE, 0x29, 0x5A,
},
},
// B.14. GB/T 32918.3-2016 A.3 Example 5
{
[]byte{
0x03, 0x01, 0xF0, 0x46, 0x4B, 0x1E, 0x81, 0x68, 0x4E, 0x5E, 0xD6, 0xEF, 0x28, 0x1B, 0x55, 0x62,
0x4E, 0xF4, 0x6C, 0xAA, 0x3B, 0x2D, 0x37, 0x48, 0x43, 0x72, 0xD9, 0x16, 0x10, 0xB6, 0x98, 0x25,
0x2C, 0xC9, 0xE0, 0x5F, 0xE2, 0x87, 0xB7, 0x3B, 0x0C, 0xE6, 0x63, 0x95, 0x24, 0xCD, 0x86, 0x69,
0x43, 0x11, 0x56, 0x29, 0x14, 0xF4, 0xF6, 0xA3, 0x42, 0x41, 0x01, 0xD8, 0x85, 0xF8, 0x8B, 0x05,
0x36, 0x9C,
},
[32]byte{
0x58, 0x8A, 0xA6, 0x70, 0x64, 0xF2, 0x4D, 0xC2, 0x7C, 0xCA, 0xA1, 0xFA, 0xB7, 0xE2, 0x7D, 0xFF,
0x81, 0x1D, 0x50, 0x0A, 0xD7, 0xEF, 0x2F, 0xB8, 0xF6, 0x9D, 0xDF, 0x48, 0xCC, 0x0F, 0xEC, 0xB7,
},
},
// B.15. GB/T 32918.4-2016 A.2 Example 1
{
[]byte{
0x57, 0xE7, 0xB6, 0x36, 0x23, 0xFA, 0xE5, 0xF0, 0x8C, 0xDA, 0x46, 0x8E, 0x87, 0x2A, 0x20, 0xAF,
0xA0, 0x3D, 0xED, 0x41, 0xBF, 0x14, 0x03, 0x77, 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69,
0x6F, 0x6E, 0x20, 0x73, 0x74, 0x61, 0x6E, 0x64, 0x61, 0x72, 0x64, 0x0E, 0x04, 0x0D, 0xC8, 0x3A,
0xF3, 0x1A, 0x67, 0x99, 0x1F, 0x2B, 0x01, 0xEB, 0xF9, 0xEF, 0xD8, 0x88, 0x1F, 0x0A, 0x04, 0x93,
0x00, 0x06, 0x03,
},
[32]byte{
0x6A, 0xFB, 0x3B, 0xCE, 0xBD, 0x76, 0xF8, 0x2B, 0x25, 0x2C, 0xE5, 0xEB, 0x25, 0xB5, 0x79, 0x96,
0x86, 0x90, 0x2B, 0x8C, 0xF2, 0xFD, 0x87, 0x53, 0x6E, 0x55, 0xEF, 0x76, 0x03, 0xB0, 0x9E, 0x7C,
},
},
// B.16. GB/T 32918.4-2016 A.2 Example 2
{
[]byte{
0x64, 0xD2, 0x0D, 0x27, 0xD0, 0x63, 0x29, 0x57, 0xF8, 0x02, 0x8C, 0x1E, 0x02, 0x4F, 0x6B, 0x02,
0xED, 0xF2, 0x31, 0x02, 0xA5, 0x66, 0xC9, 0x32, 0xAE, 0x8B, 0xD6, 0x13, 0xA8, 0xE8, 0x65, 0xFE,
0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x73, 0x74, 0x61, 0x6E, 0x64,
0x61, 0x72, 0x64, 0x58, 0xD2, 0x25, 0xEC, 0xA7, 0x84, 0xAE, 0x30, 0x0A, 0x81, 0xA2, 0xD4, 0x82,
0x81, 0xA8, 0x28, 0xE1, 0xCE, 0xDF, 0x11, 0xC4, 0x21, 0x90, 0x99, 0x84, 0x02, 0x65, 0x37, 0x50,
0x77, 0xBF, 0x78,
},
[32]byte{
0x9C, 0x3D, 0x73, 0x60, 0xC3, 0x01, 0x56, 0xFA, 0xB7, 0xC8, 0x0A, 0x02, 0x76, 0x71, 0x2D, 0xA9,
0xD8, 0x09, 0x4A, 0x63, 0x4B, 0x76, 0x6D, 0x3A, 0x28, 0x5E, 0x07, 0x48, 0x06, 0x53, 0x42, 0x6D,
},
},
// B.17. GB/T 32918.4-2016 A.3 Example 1
{
[]byte{
0x64, 0xD2, 0x0D, 0x27, 0xD0, 0x63, 0x29, 0x57, 0xF8, 0x02, 0x8C, 0x1E, 0x02, 0x4F, 0x6B, 0x02,
0xED, 0xF2, 0x31, 0x02, 0xA5, 0x66, 0xC9, 0x32, 0xAE, 0x8B, 0xD6, 0x13, 0xA8, 0xE8, 0x65, 0xFE,
0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x73, 0x74, 0x61, 0x6E, 0x64,
0x61, 0x72, 0x64, 0x58, 0xD2, 0x25, 0xEC, 0xA7, 0x84, 0xAE, 0x30, 0x0A, 0x81, 0xA2, 0xD4, 0x82,
0x81, 0xA8, 0x28, 0xE1, 0xCE, 0xDF, 0x11, 0xC4, 0x21, 0x90, 0x99, 0x84, 0x02, 0x65, 0x37, 0x50,
0x77, 0xBF, 0x78,
},
[32]byte{
0x9C, 0x3D, 0x73, 0x60, 0xC3, 0x01, 0x56, 0xFA, 0xB7, 0xC8, 0x0A, 0x02, 0x76, 0x71, 0x2D, 0xA9,
0xD8, 0x09, 0x4A, 0x63, 0x4B, 0x76, 0x6D, 0x3A, 0x28, 0x5E, 0x07, 0x48, 0x06, 0x53, 0x42, 0x6D,
},
},
// B.18. GB/T 32918.4-2016 A.3 Example 2
{
[]byte{
0x00, 0x83, 0xE6, 0x28, 0xCF, 0x70, 0x1E, 0xE3, 0x14, 0x1E, 0x88, 0x73, 0xFE, 0x55, 0x93, 0x6A,
0xDF, 0x24, 0x96, 0x3F, 0x5D, 0xC9, 0xC6, 0x48, 0x05, 0x66, 0xC8, 0x0F, 0x8A, 0x1D, 0x8C, 0xC5,
0x1B, 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x73, 0x74, 0x61, 0x6E,
0x64, 0x61, 0x72, 0x64, 0x01, 0x52, 0x4C, 0x64, 0x7F, 0x0C, 0x04, 0x12, 0xDE, 0xFD, 0x46, 0x8B,
0xDA, 0x3A, 0xE0, 0xE5, 0xA8, 0x0F, 0xCC, 0x8F, 0x5C, 0x99, 0x0F, 0xEE, 0x11, 0x60, 0x29, 0x29,
0x23, 0x2D, 0xCD, 0x9F, 0x36,
},
[32]byte{
0x73, 0xA4, 0x86, 0x25, 0xD3, 0x75, 0x8F, 0xA3, 0x7B, 0x3E, 0xAB, 0x80, 0xE9, 0xCF, 0xCA, 0xBA,
0x66, 0x5E, 0x31, 0x99, 0xEA, 0x15, 0xA1, 0xFA, 0x81, 0x89, 0xD9, 0x6F, 0x57, 0x91, 0x25, 0xE4,
},
},
*/
}
for i := range vectors {
do_hash(t, i, vectors[i].in[:], vectors[i].out)
}
}
func TestSM3Sizes(t *testing.T) {
/*
* Tests KATs for input of all zeros and length from 0 to 63
* DISCLAIMER:
* Those vectors come from "SM3 tiny" (https://github.com/odzhan/sha2.git)
* and they do depend on correctness of "SM3 tiny" implementation
*/
kat := [][32]byte{
{0x1a, 0xb2, 0x1d, 0x83, 0x55, 0xcf, 0xa1, 0x7f, 0x8e, 0x61, 0x19, 0x48, 0x31, 0xe8, 0x1a, 0x8f,
0x22, 0xbe, 0xc8, 0xc7, 0x28, 0xfe, 0xfb, 0x74, 0x7e, 0xd0, 0x35, 0xeb, 0x50, 0x82, 0xaa, 0x2b},
{0x2d, 0xae, 0xf6, 0x0e, 0x7a, 0x0b, 0x8f, 0x5e, 0x02, 0x4c, 0x81, 0xcd, 0x2a, 0xb3, 0x10, 0x9f,
0x2b, 0x4f, 0x15, 0x5c, 0xf8, 0x3a, 0xde, 0xb2, 0xae, 0x55, 0x32, 0xf7, 0x4a, 0x15, 0x7f, 0xdf},
{0xaf, 0x83, 0xa9, 0x66, 0x22, 0x20, 0x57, 0xac, 0x76, 0x12, 0x46, 0xa7, 0x54, 0x3c, 0x58, 0x0d,
0x91, 0x11, 0x01, 0x4f, 0x4e, 0x5e, 0x3c, 0xb1, 0x28, 0x1d, 0xb3, 0x31, 0x51, 0x16, 0x03, 0x35},
{0x18, 0x39, 0x20, 0xf0, 0x0e, 0x15, 0xa0, 0x43, 0x3e, 0xe3, 0xa8, 0xfc, 0x90, 0xdd, 0x9a, 0xc1,
0x64, 0xc4, 0x14, 0x2c, 0xcf, 0x63, 0xca, 0x18, 0x9a, 0x8f, 0x64, 0x5e, 0xc9, 0x6f, 0xf8, 0xde},
{0xaf, 0xcc, 0x87, 0x0f, 0xa2, 0x0c, 0x50, 0x79, 0x95, 0x49, 0x97, 0x94, 0x37, 0x1e, 0x8c, 0x25,
0xe3, 0xa7, 0x31, 0x0f, 0xa7, 0x22, 0x00, 0xc1, 0x09, 0x37, 0x99, 0x73, 0xae, 0x23, 0x68, 0x45},
{0x04, 0x71, 0x33, 0x17, 0xea, 0x89, 0x4e, 0x89, 0x0d, 0x27, 0xfb, 0x1c, 0xf0, 0x80, 0x0e, 0xad,
0x81, 0x83, 0xf6, 0x47, 0xfd, 0x2f, 0xd3, 0x11, 0x2d, 0x15, 0x1f, 0x8a, 0xc2, 0x69, 0x61, 0x7c},
{0x40, 0x7b, 0x8b, 0x70, 0x20, 0x99, 0x35, 0x66, 0xd8, 0x15, 0x36, 0x31, 0xa6, 0x7c, 0xe5, 0x83,
0x66, 0x47, 0xe6, 0xce, 0xce, 0x0d, 0x61, 0x8c, 0x7b, 0x86, 0x7d, 0x41, 0x6a, 0x52, 0x95, 0xc5},
{0xfa, 0x35, 0x64, 0xff, 0x6f, 0x77, 0x6a, 0x9c, 0xfc, 0x53, 0xa1, 0xf9, 0xb8, 0x6b, 0xd0, 0xdc,
0x74, 0x7a, 0x47, 0x31, 0xa4, 0x49, 0x11, 0x6e, 0x45, 0xc0, 0xad, 0x0d, 0x05, 0xf5, 0x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0x9b,
0xbe, 0x4e, 0x54, 0xc1, 0x5d, 0x5b, 0xfb, 0xde, 0x84, 0x38, 0x8a, 0x33, 0xe0, 0xc3, 0x54, 0x8e},
{0xc9, 0x42, 0xff, 0xfc, 0x60, 0x82, 0x68, 0xbb, 0xd8, 0xf7, 0xaf, 0xb2, 0x3d, 0x9a, 0x4f, 0xde,
0x41, 0x7d, 0xb6, 0xaa, 0x69, 0xd4, 0x75, 0x25, 0x0a, 0xf8, 0x9c, 0x87, 0xeb, 0x95, 0x58, 0x60},
{0x98, 0x58, 0xf7, 0x10, 0x59, 0xb2, 0xbc, 0xc1, 0x17, 0xdf, 0x33, 0x3d, 0x2b, 0x37, 0xac, 0x19,
0x4b, 0xee, 0x70, 0x73, 0x7d, 0x07, 0x58, 0x97, 0x30, 0x50, 0x32, 0xb3, 0x12, 0x85, 0x93, 0x13},
{0x0e, 0x03, 0xd5, 0xe8, 0xe9, 0x8b, 0x69, 0x15, 0x01, 0xb2, 0x5b, 0xd6, 0x2a, 0xdc, 0x7c, 0x47,
0x83, 0xd8, 0x14, 0xd1, 0x29, 0x70, 0xc3, 0xe3, 0xff, 0x8a, 0x8b, 0xeb, 0x11, 0x19, 0x59, 0xc2},
{0x52, 0x41, 0xdc, 0x10, 0xcb, 0x3c, 0x70, 0x0e, 0x46, 0x44, 0x69, 0x43, 0xd2, 0x7b, 0x97, 0x1f,
0xef, 0xa7, 0xe8, 0x81, 0x15, 0xf8, 0x66, 0xd6, 0xf8, 0x3d, 0x50, 0x2f, 0xf1, 0xbc, 0x06, 0xc2},
}
for i := range kat {
in := make([]byte, i)
do_hash(t, i, in[:], kat[i])
}
}
func TestReset(t *testing.T) {
var d digest
var out [32]byte
in := []byte("abc")
exp := [32]byte{
0x66, 0xC7, 0xF0, 0xF4, 0x62, 0xEE, 0xED, 0xD9, 0xD1, 0xF2, 0xD4, 0x6B, 0xDC, 0x10, 0xE4, 0xE2,
0x41, 0x67, 0xC4, 0x87, 0x5C, 0xF2, 0xF7, 0xA2, 0x29, 0x7D, 0xA0, 0x2B, 0x8F, 0x4B, 0xA8, 0xE0,
}
d.Init()
d.Write(in[:1])
d.Reset()
d.Write(in[:])
copy(out[:], d.Sum(nil))
if out != exp {
t.Error("Wrong result")
}
}
func TestSplit(t *testing.T) {
var d digest
var out [32]byte
in := []byte{
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
}
exp := [32]byte{
0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1, 0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d,
0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65, 0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32,
}
d.Init()
d.Write(in[:8])
d.Write(in[8:16])
copy(out[:], d.Sum(in[16:]))
if out != exp {
t.Error("Wrong result")
}
}
func TestCallSumMultipleTimes(t *testing.T) {
var out [32]byte
in := []byte{
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64,
}
exp := [32]byte{
0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1, 0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d,
0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65, 0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32,
}
d := New()
d.Write(in[:10])
d.Sum(nil) // That's done on purpose
copy(out[:], d.Sum(in[10:]))
if out != exp {
t.Error("Wrong result")
}
}
/* ------------------ Benchmarks ------------------- */
var bench = New()
var buf = make([]byte, 8192)
func benchmarkSize(b *testing.B, size int) {
b.SetBytes(int64(size))
for i := 0; i < b.N; i++ {
bench.Reset()
bench.Write(buf[:size])
bench.Sum(nil)
}
}
func BenchmarkHash8Bytes(b *testing.B) {
benchmarkSize(b, 8)
}
func BenchmarkHash1K(b *testing.B) {
benchmarkSize(b, 1024)
}
func BenchmarkHash8K(b *testing.B) {
benchmarkSize(b, 8192)
}