]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost28147/cipher.go
Simplify keys and IVs arguments passing: use slices instead of arrays
[gogost.git] / src / cypherpunks.ru / gogost / gost28147 / cipher.go
index 68da82dea8927396847dde6def51893ead072693..d71781ba1f25807fdbf88aad2acaf9eb78ecee5b 100644 (file)
@@ -53,15 +53,17 @@ var (
 )
 
 type Cipher struct {
-       key  *[KeySize]byte
+       key  [KeySize]byte
        sbox *Sbox
        x    [8]nv
 }
 
-func NewCipher(key [KeySize]byte, sbox *Sbox) *Cipher {
-       c := Cipher{}
-       c.key = &key
-       c.sbox = sbox
+func NewCipher(key []byte, sbox *Sbox) *Cipher {
+       if len(key) != KeySize {
+               panic("invalid key size")
+       }
+       c := Cipher{sbox: sbox}
+       copy(c.key[:], key)
        c.x = [8]nv{
                nv(key[0]) | nv(key[1])<<8 | nv(key[2])<<16 | nv(key[3])<<24,
                nv(key[4]) | nv(key[5])<<8 | nv(key[6])<<16 | nv(key[7])<<24,