-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
salsa20/salsa: fix keystream loop in amd64 assembly when overflowing …
…32-bit counter Fixes golang/go#30965 Change-Id: I83a804d555c048e0124c35f95c9e611b2c5bdb01 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/436856 Reviewed-by: Adam Langley <agl@google.com> Reviewed-on: https://go-review.googlesource.com/c/crypto/+/168406 Reviewed-by: Filippo Valsorda <filippo@golang.org> Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
- Loading branch information
1 parent
a1f597e
commit b7391e9
Showing
5 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2019 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build amd64,!appengine,!gccgo | ||
|
||
package salsa | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestCounterOverflow(t *testing.T) { | ||
in := make([]byte, 4096) | ||
key := &[32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, | ||
6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2} | ||
for n, counter := range []*[16]byte{ | ||
&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0}, // zero counter | ||
&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff}, // counter about to overflow 32 bits | ||
&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 0xff, 0xff, 0xff, 0xff}, // counter above 32 bits | ||
} { | ||
out := make([]byte, 4096) | ||
XORKeyStream(out, in, counter, key) | ||
outGeneric := make([]byte, 4096) | ||
genericXORKeyStream(outGeneric, in, counter, key) | ||
if !bytes.Equal(out, outGeneric) { | ||
t.Errorf("%d: assembly and go implementations disagree", n) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2019 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build !amd64 appengine gccgo | ||
|
||
package salsa | ||
|
||
// XORKeyStream crypts bytes from in to out using the given key and counters. | ||
// In and out must overlap entirely or not at all. Counter | ||
// contains the raw salsa20 counter bytes (both nonce and block counter). | ||
func XORKeyStream(out, in []byte, counter *[16]byte, key *[32]byte) { | ||
genericXORKeyStream(out, in, counter, key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters