X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Fmgm.py;h=49c478dc2619b5a00bc40de3e5c3dc5f4294453f;hb=9af4461c6af50f9cf83030867e7054d1f6311b32;hp=0321628bb16f37138f6d6b00b01d6766c9334140;hpb=6ee520badcc5298237f6a8a65e8cb0f749a980e1;p=pygost.git diff --git a/pygost/mgm.py b/pygost/mgm.py index 0321628..49c478d 100644 --- a/pygost/mgm.py +++ b/pygost/mgm.py @@ -1,6 +1,6 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2020 Sergey Matveev +# Copyright (C) 2015-2021 Sergey Matveev # # 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 @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" Multilinear Galois Mode (MGM) block cipher mode. +"""Multilinear Galois Mode (MGM) block cipher mode. """ from hmac import compare_digest @@ -57,10 +57,10 @@ class MGM(object): (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 @@ -74,7 +74,7 @@ class MGM(object): 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") @@ -164,5 +164,5 @@ class MGM(object): ) 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)