Skip to content

Commit 75b147d

Browse files
committed
Add KangarooTwelve as XOF
1 parent caa4d7b commit 75b147d

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ go get -u github.com/cloudflare/circl
7474
#### XOF: eXtendable Output Functions
7575
- [FIPS 202](https://doi.org/10.6028/NIST.FIPS.202): SHAKE128 and SHAKE256
7676
- [BLAKE2X](https://www.blake2.net/blake2x.pdf): BLAKE2XB and BLAKE2XS
77+
- [KangarooTwelve](https://keccak.team/kangarootwelve.html): KangarooTwelve
7778

7879
#### Zero-knowledge Proofs
7980
- [Schnorr](./zk/dl): Prove knowledge of the Discrete Logarithm.

xof/k12/k12.go

+23
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ func (s *State) Reset() {
7979
s.chunk = 0
8080
}
8181

82+
func (s *State) Clone() State {
83+
stalk := s.stalk.Clone().(*sha3.State)
84+
ret := State{
85+
initialTodo: s.initialTodo,
86+
stalk: *stalk,
87+
context: s.context,
88+
offset: s.offset,
89+
chunk: s.chunk,
90+
lanes: s.lanes,
91+
}
92+
93+
if s.leaf != nil {
94+
ret.leaf = s.leaf.Clone().(*sha3.State)
95+
}
96+
97+
if s.buf != nil {
98+
ret.buf = make([]byte, len(s.buf))
99+
copy(ret.buf, s.buf)
100+
}
101+
102+
return ret
103+
}
104+
82105
func Draft10Sum(hash []byte, msg []byte, c []byte) {
83106
// TODO Tweak number of lanes depending on the length of the message
84107
s := NewDraft10(c)

xof/xof.go

+13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"io"
1111

1212
"github.com/cloudflare/circl/internal/sha3"
13+
"github.com/cloudflare/circl/xof/k12"
14+
1315
"golang.org/x/crypto/blake2b"
1416
"golang.org/x/crypto/blake2s"
1517
)
@@ -38,6 +40,7 @@ const (
3840
SHAKE256
3941
BLAKE2XB
4042
BLAKE2XS
43+
K12D10
4144
)
4245

4346
func (x ID) New() XOF {
@@ -54,6 +57,9 @@ func (x ID) New() XOF {
5457
case BLAKE2XS:
5558
x, _ := blake2s.NewXOF(blake2s.OutputLengthUnknown, nil)
5659
return blake2xs{x}
60+
case K12D10:
61+
x := k12.NewDraft10([]byte{})
62+
return k12d10{&x}
5763
default:
5864
panic("crypto: requested unavailable XOF function")
5965
}
@@ -70,3 +76,10 @@ func (s blake2xb) Clone() XOF { return blake2xb{s.XOF.Clone()} }
7076
type blake2xs struct{ blake2s.XOF }
7177

7278
func (s blake2xs) Clone() XOF { return blake2xs{s.XOF.Clone()} }
79+
80+
type k12d10 struct{ *k12.State }
81+
82+
func (s k12d10) Clone() XOF {
83+
x := s.State.Clone()
84+
return k12d10{&x}
85+
}

xof/xof_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ var allVectors = []vector{
5353
out: "0650cde4df888a06eada0f0fecb3c17594304b4a03fdd678182f27db1238b174",
5454
outLen: 32,
5555
},
56+
{
57+
id: xof.K12D10,
58+
in: "The quick brown fox jumps over the lazy dog",
59+
out: "b4f249b4f77c58df170aa4d1723db1127d82f1d98d25ddda561ada459cd11a48",
60+
outLen: 32,
61+
},
5662
}
5763

5864
func TestXof(t *testing.T) {

0 commit comments

Comments
 (0)