]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost28147/cfb_test.go
Forbid any later GNU GPL versions autousage
[gogost.git] / src / cypherpunks.ru / gogost / gost28147 / cfb_test.go
index 3b60a6f874274e97a9115361a5c172f3a80279e6..5647663f812c2c366129c61fabbbc221b772561a 100644 (file)
@@ -3,8 +3,7 @@
 //
 // This program is free software: you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// the Free Software Foundation, version 3 of the License.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,19 +18,18 @@ package gost28147
 import (
        "bytes"
        "crypto/cipher"
-       "crypto/rand"
        "testing"
        "testing/quick"
 )
 
 func TestCFBCryptomanager(t *testing.T) {
-       key := [KeySize]byte{
+       key := []byte{
                0x75, 0x71, 0x31, 0x34, 0xB6, 0x0F, 0xEC, 0x45,
                0xA6, 0x07, 0xBB, 0x83, 0xAA, 0x37, 0x46, 0xAF,
                0x4F, 0xF9, 0x9D, 0xA6, 0xD1, 0xB5, 0x3B, 0x5B,
                0x1B, 0x40, 0x2A, 0x1B, 0xAA, 0x03, 0x0D, 0x1B,
        }
-       sbox := &GostR3411_94_TestParamSet
+       sbox := &SboxIdGostR341194TestParamSet
        pt := []byte{
                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
                0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0x80, 0x00, 0x00,
@@ -41,34 +39,30 @@ func TestCFBCryptomanager(t *testing.T) {
                0xAD, 0x36, 0x16, 0x94, 0x0E, 0x16, 0x42, 0x42,
        }
        c := NewCipher(key, sbox)
-       iv := [8]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
+       iv := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
        tmp := make([]byte, 16)
        fe := c.NewCFBEncrypter(iv)
        fe.XORKeyStream(tmp, pt)
        if bytes.Compare(tmp, ct) != 0 {
-               t.Fail()
+               t.Fatal("encryption failed")
        }
        fd := c.NewCFBDecrypter(iv)
        fd.XORKeyStream(tmp, ct)
        if bytes.Compare(tmp, pt) != 0 {
-               t.Fail()
+               t.Fatal("decryption failed")
        }
 }
 
 func TestCFBRandom(t *testing.T) {
-       var key [KeySize]byte
-       rand.Read(key[:])
-       c := NewCipher(key, SboxDefault)
-       f := func(ivRaw []byte, pt []byte) bool {
-               if len(pt) == 0 || len(ivRaw) < 8 {
+       f := func(key [KeySize]byte, iv [BlockSize]byte, pt []byte) bool {
+               if len(pt) == 0 {
                        return true
                }
-               var iv [8]byte
-               copy(iv[:], ivRaw[:8])
+               c := NewCipher(key[:], SboxDefault)
                ct := make([]byte, len(pt))
-               fe := c.NewCFBEncrypter(iv)
+               fe := c.NewCFBEncrypter(iv[:])
                fe.XORKeyStream(ct, pt)
-               fd := c.NewCFBDecrypter(iv)
+               fd := c.NewCFBDecrypter(iv[:])
                pt2 := make([]byte, len(ct))
                fd.XORKeyStream(pt2, ct)
                return bytes.Compare(pt2, pt) == 0
@@ -81,7 +75,7 @@ func TestCFBRandom(t *testing.T) {
 func TestCFBInterface(t *testing.T) {
        var key [32]byte
        var iv [8]byte
-       c := NewCipher(key, SboxDefault)
-       var _ cipher.Stream = c.NewCFBEncrypter(iv)
-       var _ cipher.Stream = c.NewCFBDecrypter(iv)
+       c := NewCipher(key[:], SboxDefault)
+       var _ cipher.Stream = c.NewCFBEncrypter(iv[:])
+       var _ cipher.Stream = c.NewCFBDecrypter(iv[:])
 }