]> Cypherpunks.ru repositories - gogost.git/blobdiff - src/cypherpunks.ru/gogost/gost28147/mac.go
Forbid any later GNU GPL versions autousage
[gogost.git] / src / cypherpunks.ru / gogost / gost28147 / mac.go
index 304e62274edf2d1525783a21b6e7e0bcc93befb2..bcfd52c5ed5044d5eee3f08524e5d5bd588e498b 100644 (file)
@@ -1,10 +1,9 @@
 // GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2016 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
@@ -41,12 +40,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)