Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion expander/expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ func NewExpanderXOF(id xof.ID, kSecLevel uint, dst []byte) *expanderXOF {
return &expanderXOF{id, kSecLevel, dst}
}

// Expand panics if output's length is longer than 2^16 bytes.
// Expand panics if output's length exceeds 65535 bytes.
func (e *expanderXOF) Expand(in []byte, n uint) []byte {
if n >= 1<<16 {
panic(errorLongOutput)
}

bLen := []byte{0, 0}
binary.BigEndian.PutUint16(bLen, uint16(n))
pseudo := make([]byte, n)
Expand Down
14 changes: 14 additions & 0 deletions expander/expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ func TestExpander(t *testing.T) {
}
}

func TestXOFExpandLengthLimit(t *testing.T) {
exp := expander.NewExpanderXOF(xof.SHAKE128, 128, []byte("dst"))
if got := exp.Expand(nil, 1<<16-1); len(got) != 1<<16-1 {
t.Fatalf("unexpected output length: got %d, want %d", len(got), 1<<16-1)
}

defer func() {
if recover() == nil {
t.Fatal("Expand did not panic for an output length exceeding 65535 bytes")
}
}()
exp.Expand(nil, 1<<16)
}

func (vs *vectorExpanderSuite) testExpander(t *testing.T) {
var exp expander.Expander
switch vs.Hash {
Expand Down
Loading