Skip to content

Commit

Permalink
Add KangarooTwelve as XOF
Browse files Browse the repository at this point in the history
  • Loading branch information
bwesterb committed May 3, 2023
1 parent caa4d7b commit 75b147d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -74,6 +74,7 @@ go get -u github.com/cloudflare/circl
#### XOF: eXtendable Output Functions
- [FIPS 202](https://doi.org/10.6028/NIST.FIPS.202): SHAKE128 and SHAKE256
- [BLAKE2X](https://www.blake2.net/blake2x.pdf): BLAKE2XB and BLAKE2XS
- [KangarooTwelve](https://keccak.team/kangarootwelve.html): KangarooTwelve

#### Zero-knowledge Proofs
- [Schnorr](./zk/dl): Prove knowledge of the Discrete Logarithm.
Expand Down
23 changes: 23 additions & 0 deletions xof/k12/k12.go
Expand Up @@ -79,6 +79,29 @@ func (s *State) Reset() {
s.chunk = 0
}

func (s *State) Clone() State {
stalk := s.stalk.Clone().(*sha3.State)
ret := State{
initialTodo: s.initialTodo,
stalk: *stalk,
context: s.context,
offset: s.offset,
chunk: s.chunk,
lanes: s.lanes,
}

if s.leaf != nil {
ret.leaf = s.leaf.Clone().(*sha3.State)
}

if s.buf != nil {
ret.buf = make([]byte, len(s.buf))
copy(ret.buf, s.buf)
}

return ret
}

func Draft10Sum(hash []byte, msg []byte, c []byte) {
// TODO Tweak number of lanes depending on the length of the message
s := NewDraft10(c)
Expand Down
13 changes: 13 additions & 0 deletions xof/xof.go
Expand Up @@ -10,6 +10,8 @@ import (
"io"

"github.com/cloudflare/circl/internal/sha3"
"github.com/cloudflare/circl/xof/k12"

"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/blake2s"
)
Expand Down Expand Up @@ -38,6 +40,7 @@ const (
SHAKE256
BLAKE2XB
BLAKE2XS
K12D10
)

func (x ID) New() XOF {
Expand All @@ -54,6 +57,9 @@ func (x ID) New() XOF {
case BLAKE2XS:
x, _ := blake2s.NewXOF(blake2s.OutputLengthUnknown, nil)
return blake2xs{x}
case K12D10:
x := k12.NewDraft10([]byte{})
return k12d10{&x}
default:
panic("crypto: requested unavailable XOF function")
}
Expand All @@ -70,3 +76,10 @@ func (s blake2xb) Clone() XOF { return blake2xb{s.XOF.Clone()} }
type blake2xs struct{ blake2s.XOF }

func (s blake2xs) Clone() XOF { return blake2xs{s.XOF.Clone()} }

type k12d10 struct{ *k12.State }

func (s k12d10) Clone() XOF {
x := s.State.Clone()
return k12d10{&x}
}
6 changes: 6 additions & 0 deletions xof/xof_test.go
Expand Up @@ -53,6 +53,12 @@ var allVectors = []vector{
out: "0650cde4df888a06eada0f0fecb3c17594304b4a03fdd678182f27db1238b174",
outLen: 32,
},
{
id: xof.K12D10,
in: "The quick brown fox jumps over the lazy dog",
out: "b4f249b4f77c58df170aa4d1723db1127d82f1d98d25ddda561ada459cd11a48",
outLen: 32,
},
}

func TestXof(t *testing.T) {
Expand Down

0 comments on commit 75b147d

Please sign in to comment.