Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed May 13, 2024
1 parent f555ad2 commit 5676ebd
Show file tree
Hide file tree
Showing 27 changed files with 5,939 additions and 5,911 deletions.
22 changes: 12 additions & 10 deletions blake256/blake256.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ func NewWithSalt(salt []byte) hash.Hash {
return d
}

// Sum returns the BLAKE-256 checksum of the data.
func Sum(data []byte) (out [Size]byte) {
d := New()
d.Write(data)
sum := d.Sum(nil)

copy(out[:], sum)
return
}

// =======

// New224 returns a new hash.Hash computing the BLAKE-224 checksum.
func New224() hash.Hash {
return newDigest(224, iv224)
Expand All @@ -26,16 +38,6 @@ func New224WithSalt(salt []byte) hash.Hash {
return d
}

// Sum returns the BLAKE-256 checksum of the data.
func Sum(data []byte) (out [Size]byte) {
d := New()
d.Write(data)
sum := d.Sum(nil)

copy(out[:], sum)
return
}

// Sum224 returns the BLAKE-224 checksum of the data.
func Sum224(data []byte) (out [Size224]byte) {
d := New224()
Expand Down
22 changes: 12 additions & 10 deletions blake512/blake512.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ func NewWithSalt(salt []byte) hash.Hash {
return d
}

// Sum returns the BLAKE-512 checksum of the data.
func Sum(data []byte) (out [Size]byte) {
d := New()
d.Write(data)
sum := d.Sum(nil)

copy(out[:], sum)
return
}

// ==========

// New384 returns a new hash.Hash computing the BLAKE-384 checksum.
func New384() hash.Hash {
return newDigest(48, iv384)
Expand All @@ -26,16 +38,6 @@ func New384WithSalt(salt []byte) hash.Hash {
return d
}

// Sum returns the BLAKE-512 checksum of the data.
func Sum(data []byte) (out [Size]byte) {
d := New()
d.Write(data)
sum := d.Sum(nil)

copy(out[:], sum)
return
}

// Sum384 returns the BLAKE-384 checksum of the data.
func Sum384(data []byte) (out [Size384]byte) {
d := New384()
Expand Down
66 changes: 33 additions & 33 deletions blake512/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (d *digest) checkSum() (out []byte) {

if ptr < 112 {
for i := ptr + 1; i < 112; i++ {
tmpBuf[i] = 0x00;
tmpBuf[i] = 0x00
}

if d.hs == 64 {
Expand Down Expand Up @@ -190,84 +190,84 @@ func (d *digest) compress(data []uint8) {
}

for r := 0; r < 16; r++ {
var o0 = SIGMA[(r << 4) + 0x0]
var o1 = SIGMA[(r << 4) + 0x1]
var o0 = sigma[(r << 4) + 0x0]
var o1 = sigma[(r << 4) + 0x1]

v0 += v4 + (m[o0] ^ CB[o1])
v0 += v4 + (m[o0] ^ cb[o1])
vC = circularRight(vC ^ v0, 32)
v8 += vC
v4 = circularRight(v4 ^ v8, 25)
v0 += v4 + (m[o1] ^ CB[o0])
v0 += v4 + (m[o1] ^ cb[o0])
vC = circularRight(vC ^ v0, 16)
v8 += vC
v4 = circularRight(v4 ^ v8, 11)
o0 = SIGMA[(r << 4) + 0x2]
o1 = SIGMA[(r << 4) + 0x3]
v1 += v5 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0x2]
o1 = sigma[(r << 4) + 0x3]
v1 += v5 + (m[o0] ^ cb[o1])
vD = circularRight(vD ^ v1, 32)
v9 += vD
v5 = circularRight(v5 ^ v9, 25)
v1 += v5 + (m[o1] ^ CB[o0])
v1 += v5 + (m[o1] ^ cb[o0])
vD = circularRight(vD ^ v1, 16)
v9 += vD
v5 = circularRight(v5 ^ v9, 11)
o0 = SIGMA[(r << 4) + 0x4]
o1 = SIGMA[(r << 4) + 0x5]
v2 += v6 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0x4]
o1 = sigma[(r << 4) + 0x5]
v2 += v6 + (m[o0] ^ cb[o1])
vE = circularRight(vE ^ v2, 32)
vA += vE
v6 = circularRight(v6 ^ vA, 25)
v2 += v6 + (m[o1] ^ CB[o0])
v2 += v6 + (m[o1] ^ cb[o0])
vE = circularRight(vE ^ v2, 16)
vA += vE
v6 = circularRight(v6 ^ vA, 11)
o0 = SIGMA[(r << 4) + 0x6]
o1 = SIGMA[(r << 4) + 0x7]
v3 += v7 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0x6]
o1 = sigma[(r << 4) + 0x7]
v3 += v7 + (m[o0] ^ cb[o1])
vF = circularRight(vF ^ v3, 32)
vB += vF
v7 = circularRight(v7 ^ vB, 25)
v3 += v7 + (m[o1] ^ CB[o0])
v3 += v7 + (m[o1] ^ cb[o0])
vF = circularRight(vF ^ v3, 16)
vB += vF
v7 = circularRight(v7 ^ vB, 11)
o0 = SIGMA[(r << 4) + 0x8]
o1 = SIGMA[(r << 4) + 0x9]
v0 += v5 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0x8]
o1 = sigma[(r << 4) + 0x9]
v0 += v5 + (m[o0] ^ cb[o1])
vF = circularRight(vF ^ v0, 32)
vA += vF
v5 = circularRight(v5 ^ vA, 25)
v0 += v5 + (m[o1] ^ CB[o0])
v0 += v5 + (m[o1] ^ cb[o0])
vF = circularRight(vF ^ v0, 16)
vA += vF
v5 = circularRight(v5 ^ vA, 11)
o0 = SIGMA[(r << 4) + 0xA]
o1 = SIGMA[(r << 4) + 0xB]
v1 += v6 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0xA]
o1 = sigma[(r << 4) + 0xB]
v1 += v6 + (m[o0] ^ cb[o1])
vC = circularRight(vC ^ v1, 32)
vB += vC
v6 = circularRight(v6 ^ vB, 25)
v1 += v6 + (m[o1] ^ CB[o0])
v1 += v6 + (m[o1] ^ cb[o0])
vC = circularRight(vC ^ v1, 16)
vB += vC
v6 = circularRight(v6 ^ vB, 11)
o0 = SIGMA[(r << 4) + 0xC]
o1 = SIGMA[(r << 4) + 0xD]
v2 += v7 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0xC]
o1 = sigma[(r << 4) + 0xD]
v2 += v7 + (m[o0] ^ cb[o1])
vD = circularRight(vD ^ v2, 32)
v8 += vD
v7 = circularRight(v7 ^ v8, 25)
v2 += v7 + (m[o1] ^ CB[o0])
v2 += v7 + (m[o1] ^ cb[o0])
vD = circularRight(vD ^ v2, 16)
v8 += vD
v7 = circularRight(v7 ^ v8, 11)
o0 = SIGMA[(r << 4) + 0xE]
o1 = SIGMA[(r << 4) + 0xF]
v3 += v4 + (m[o0] ^ CB[o1])
o0 = sigma[(r << 4) + 0xE]
o1 = sigma[(r << 4) + 0xF]
v3 += v4 + (m[o0] ^ cb[o1])
vE = circularRight(vE ^ v3, 32)
v9 += vE
v4 = circularRight(v4 ^ v9, 25)
v3 += v4 + (m[o1] ^ CB[o0])
v3 += v4 + (m[o1] ^ cb[o0])
vE = circularRight(vE ^ v3, 16)
v9 += vE
v4 = circularRight(v4 ^ v9, 11)
Expand Down
4 changes: 2 additions & 2 deletions blake512/sbox.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package blake512

var SIGMA = []uint8{
var sigma = []uint8{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
Expand All @@ -19,7 +19,7 @@ var SIGMA = []uint8{
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
}

var CB = []uint64{
var cb = []uint64{
0x243F6A8885A308D3, 0x13198A2E03707344,
0xA4093822299F31D0, 0x082EFA98EC4E6C89,
0x452821E638D01377, 0xBE5466CF34E90C6C,
Expand Down
24 changes: 13 additions & 11 deletions cubehash/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"errors"
)

// The size of an cubehash checksum in bytes.
const Size512 = 64
const Size384 = 48
const Size256 = 32
const Size224 = 28
const Size192 = 24
const Size160 = 20
const Size128 = 16
const (
// The size of an cubehash checksum in bytes.
Size512 = 64
Size384 = 48
Size256 = 32
Size224 = 28
Size192 = 24
Size160 = 20
Size128 = 16
)

// The blocksize of cubehash in bytes.
const BlockSize = 32
Expand Down Expand Up @@ -131,7 +133,7 @@ func (this *digest) initRound(r int) {

func (this *digest) ingest(x *[32]uint32, p []byte) {
for n := 0; n < this.bs/4; n++ {
x[n] ^= GETU32(p[n*4:])
x[n] ^= getu32(p[n*4:])
}

// the number of rounds per message block
Expand All @@ -144,7 +146,7 @@ func (this *digest) MarshalBinary() ([]byte, error) {
x := &this.s
buf := make([]byte, 128+1, 128+1+this.nx)
for n := 0; n < 32; n++ {
PUTU32(buf[n*4:], x[n])
putu32(buf[n*4:], x[n])
}

buf[128] = byte(this.nx)
Expand All @@ -164,7 +166,7 @@ func (this *digest) UnmarshalBinary(data []byte) error {
this.nx = n

for n := 0; n < 32; n++ {
x[n] = GETU32(data[n*4:])
x[n] = getu32(data[n*4:])
}

this.len = 0
Expand Down
4 changes: 2 additions & 2 deletions cubehash/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
// Endianness option
const littleEndian bool = true

func GETU32(ptr []byte) uint32 {
func getu32(ptr []byte) uint32 {
if littleEndian {
return binary.LittleEndian.Uint32(ptr)
} else {
return binary.BigEndian.Uint32(ptr)
}
}

func PUTU32(ptr []byte, a uint32) {
func putu32(ptr []byte, a uint32) {
if littleEndian {
binary.LittleEndian.PutUint32(ptr, a)
} else {
Expand Down

0 comments on commit 5676ebd

Please sign in to comment.