# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
-# Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+# Copyright (C) 2015-2021 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
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-""" Multilinear Galois Mode (MGM) block cipher mode.
+"""Multilinear Galois Mode (MGM) block cipher mode.
"""
from hmac import compare_digest
(defaults to blocksize if not specified)
"""
if bs not in (8, 16):
- raise ValueError("only 64/128-bit blocksizes allowed")
+ raise ValueError("Only 64/128-bit blocksizes allowed")
self.tag_size = bs if tag_size is None else bs
if self.tag_size < 4 or self.tag_size > bs:
- raise ValueError("invalid tag_size")
+ raise ValueError("Invalid tag_size")
self.encrypter = encrypter
self.bs = bs
self.max_size = (1 << (bs * 8 // 2)) - 1
def _validate_sizes(self, plaintext, additional_data):
if len(plaintext) == 0 and len(additional_data) == 0:
- raise ValueError("at least one of plaintext or additional_data required")
+ raise ValueError("At least one of plaintext or additional_data required")
if len(plaintext) + len(additional_data) > self.max_size:
raise ValueError("plaintext+additional_data are too big")
)
tag = self._auth(icn, ciphertext, additional_data)
if not compare_digest(tag_expected, tag):
- raise ValueError("invalid authentication tag")
+ raise ValueError("Invalid authentication tag")
return self._crypt(icn, ciphertext)