]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost28147/mac.go
Simplify keys and IVs arguments passing: use slices instead of arrays
[gogost.git] / src / cypherpunks.ru / gogost / gost28147 / mac.go
index 2849f15b950392420a5354d04eac4e43b3f6f206..05e8a323dfb2aa8a31ca0400637b6194991f5782 100644 (file)
@@ -41,12 +41,15 @@ type MAC struct {
 // Size is in bytes and must be between 1 and 8. To be RFC conformant,
 // iv must be the first block of the authenticated data, second and
 // following ones are fed to Write function.
-func (c *Cipher) NewMAC(size int, iv [BlockSize]byte) (*MAC, error) {
+func (c *Cipher) NewMAC(size int, iv []byte) (*MAC, error) {
        if size == 0 || size > 8 {
                return nil, errors.New("Invalid tag size")
        }
-       m := MAC{c: c, size: size, iv: iv[:]}
-       n2, n1 := block2nvs(iv[:])
+       if len(iv) != BlockSize {
+               return nil, errors.New("iv length is not equal to blocksize")
+       }
+       m := MAC{c: c, size: size, iv: iv}
+       n2, n1 := block2nvs(iv)
        m.iv = make([]byte, BlockSize)
        nvs2block(n1, n2, m.iv)
        m.prev = make([]byte, BlockSize)