aboutsummaryrefslogtreecommitdiff
path: root/frozen_deps/Cryptodome/Util/Counter.py
diff options
context:
space:
mode:
Diffstat (limited to 'frozen_deps/Cryptodome/Util/Counter.py')
-rw-r--r--frozen_deps/Cryptodome/Util/Counter.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/frozen_deps/Cryptodome/Util/Counter.py b/frozen_deps/Cryptodome/Util/Counter.py
index 423f91f..c67bc95 100644
--- a/frozen_deps/Cryptodome/Util/Counter.py
+++ b/frozen_deps/Cryptodome/Util/Counter.py
@@ -45,6 +45,7 @@ def new(nbits, prefix=b"", suffix=b"", initial_value=1, little_endian=False, all
used.
initial_value (integer):
The initial value of the counter. Default value is 1.
+ Its length in bits must not exceed the argument ``nbits``.
little_endian (boolean):
If ``True``, the counter number will be encoded in little endian format.
If ``False`` (default), in big endian format.
@@ -61,6 +62,12 @@ def new(nbits, prefix=b"", suffix=b"", initial_value=1, little_endian=False, all
if (nbits % 8) != 0:
raise ValueError("'nbits' must be a multiple of 8")
+ iv_bl = initial_value.bit_length()
+ if iv_bl > nbits:
+ raise ValueError("Initial value takes %d bits but it is longer than "
+ "the counter (%d bits)" %
+ (iv_bl, nbits))
+
# Ignore wraparound
return {"counter_len": nbits // 8,
"prefix": prefix,