]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost341264/cipher.go
Simplify keys and IVs arguments passing: use slices instead of arrays
[gogost.git] / src / cypherpunks.ru / gogost / gost341264 / cipher.go
index 68a43b8d38dba13a3c7571a7c82ed3b4976d1456..813d79da15caeaba0e9d17a8e6285308bec1ef76 100644 (file)
@@ -31,8 +31,11 @@ type Cipher struct {
        blk *[BlockSize]byte
 }
 
-func NewCipher(key [KeySize]byte) *Cipher {
-       keyCompatible := new([KeySize]byte)
+func NewCipher(key []byte) *Cipher {
+       if len(key) != KeySize {
+               panic("invalid key size")
+       }
+       keyCompatible := make([]byte, KeySize)
        for i := 0; i < KeySize/4; i++ {
                keyCompatible[i*4+0] = key[i*4+3]
                keyCompatible[i*4+1] = key[i*4+2]
@@ -40,10 +43,7 @@ func NewCipher(key [KeySize]byte) *Cipher {
                keyCompatible[i*4+3] = key[i*4+0]
        }
        return &Cipher{
-               c: gost28147.NewCipher(
-                       *keyCompatible,
-                       &gost28147.SboxIdtc26gost28147paramZ,
-               ),
+               c:   gost28147.NewCipher(keyCompatible, &gost28147.SboxIdtc26gost28147paramZ),
                blk: new([BlockSize]byte),
        }
 }