Skip to content

Commit 46bf040

Browse files
committed
Clarify how ChaCha20.seek() can be used to seek to blocks
1 parent fd3c7f2 commit 46bf040

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Crypto/Cipher/ChaCha20.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
unsigned long block_high,
5858
unsigned long block_low,
5959
unsigned offset);
60+
6061
int hchacha20( const uint8_t key[32],
6162
const uint8_t nonce16[16],
6263
uint8_t subkey[32]);
@@ -192,14 +193,17 @@ def decrypt(self, ciphertext, output=None):
192193
def seek(self, position):
193194
"""Seek to a certain position in the key stream.
194195
196+
If you want to seek to a certain block,
197+
use ``seek(block_number * 64)``.
198+
195199
Args:
196200
position (integer):
197201
The absolute position within the key stream, in bytes.
198202
"""
199203

200-
position, offset = divmod(position, 64)
201-
block_low = position & 0xFFFFFFFF
202-
block_high = position >> 32
204+
block_number, offset = divmod(position, 64)
205+
block_low = block_number & 0xFFFFFFFF
206+
block_high = block_number >> 32
203207

204208
result = _raw_chacha20_lib.chacha20_seek(
205209
self._state.get(),

0 commit comments

Comments
 (0)