]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost341264/cipher.go
Forbid any later GNU GPL versions autousage
[gogost.git] / src / cypherpunks.ru / gogost / gost341264 / cipher.go
index 68a43b8d38dba13a3c7571a7c82ed3b4976d1456..53a27920b8009a602b5be3a4dfd0fd3b5107128d 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
@@ -31,8 +30,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 +42,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),
        }
 }