// GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2017 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
//
// 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
// 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)