...

Source file src/golang.org/x/crypto/salsa20/salsa/salsa20_amd64_test.go

Documentation: golang.org/x/crypto/salsa20/salsa

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build amd64 && !purego && gc
     6  
     7  package salsa
     8  
     9  import (
    10  	"bytes"
    11  	"testing"
    12  )
    13  
    14  func TestCounterOverflow(t *testing.T) {
    15  	in := make([]byte, 4096)
    16  	key := &[32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5,
    17  		6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2}
    18  	for n, counter := range []*[16]byte{
    19  		&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0},             // zero counter
    20  		&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff}, // counter about to overflow 32 bits
    21  		&[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 0xff, 0xff, 0xff, 0xff}, // counter above 32 bits
    22  	} {
    23  		out := make([]byte, 4096)
    24  		XORKeyStream(out, in, counter, key)
    25  		outGeneric := make([]byte, 4096)
    26  		genericXORKeyStream(outGeneric, in, counter, key)
    27  		if !bytes.Equal(out, outGeneric) {
    28  			t.Errorf("%d: assembly and go implementations disagree", n)
    29  		}
    30  	}
    31  }
    32  

View as plain text