...

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

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

     1  // Copyright 2012 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  package salsa
     6  
     7  import "testing"
     8  
     9  func TestCore208(t *testing.T) {
    10  	in := [64]byte{
    11  		0x7e, 0x87, 0x9a, 0x21, 0x4f, 0x3e, 0xc9, 0x86,
    12  		0x7c, 0xa9, 0x40, 0xe6, 0x41, 0x71, 0x8f, 0x26,
    13  		0xba, 0xee, 0x55, 0x5b, 0x8c, 0x61, 0xc1, 0xb5,
    14  		0x0d, 0xf8, 0x46, 0x11, 0x6d, 0xcd, 0x3b, 0x1d,
    15  		0xee, 0x24, 0xf3, 0x19, 0xdf, 0x9b, 0x3d, 0x85,
    16  		0x14, 0x12, 0x1e, 0x4b, 0x5a, 0xc5, 0xaa, 0x32,
    17  		0x76, 0x02, 0x1d, 0x29, 0x09, 0xc7, 0x48, 0x29,
    18  		0xed, 0xeb, 0xc6, 0x8d, 0xb8, 0xb8, 0xc2, 0x5e}
    19  
    20  	out := [64]byte{
    21  		0xa4, 0x1f, 0x85, 0x9c, 0x66, 0x08, 0xcc, 0x99,
    22  		0x3b, 0x81, 0xca, 0xcb, 0x02, 0x0c, 0xef, 0x05,
    23  		0x04, 0x4b, 0x21, 0x81, 0xa2, 0xfd, 0x33, 0x7d,
    24  		0xfd, 0x7b, 0x1c, 0x63, 0x96, 0x68, 0x2f, 0x29,
    25  		0xb4, 0x39, 0x31, 0x68, 0xe3, 0xc9, 0xe6, 0xbc,
    26  		0xfe, 0x6b, 0xc5, 0xb7, 0xa0, 0x6d, 0x96, 0xba,
    27  		0xe4, 0x24, 0xcc, 0x10, 0x2c, 0x91, 0x74, 0x5c,
    28  		0x24, 0xad, 0x67, 0x3d, 0xc7, 0x61, 0x8f, 0x81,
    29  	}
    30  
    31  	Core208(&in, &in)
    32  	if in != out {
    33  		t.Errorf("expected %x, got %x", out, in)
    34  	}
    35  }
    36  
    37  func TestOutOfBoundsWrite(t *testing.T) {
    38  	// encrypted "0123456789"
    39  	cipherText := []byte{170, 166, 196, 104, 175, 121, 68, 44, 174, 51}
    40  	var counter [16]byte
    41  	var key [32]byte
    42  	want := "abcdefghij"
    43  	plainText := []byte(want)
    44  	defer func() {
    45  		err := recover()
    46  		if err == nil {
    47  			t.Error("XORKeyStream expected to panic on len(dst) < len(src), but didn't")
    48  		}
    49  		if plainText[3] == '3' {
    50  			t.Errorf("XORKeyStream did out of bounds write, want %v, got %v", want, string(plainText))
    51  		}
    52  	}()
    53  	XORKeyStream(plainText[:3], cipherText, &counter, &key)
    54  }
    55  

View as plain text