Content deleted Content added
Add category |
m Reverted edits by 73.167.116.198 (talk) (HG) (3.4.12) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 69:
hLen = hash_func().digest_size
# https://www.ietf.org/rfc/rfc2437.txt
# 1. If l > 2^32(hLen), output "mask too long" and stop.
if length > (hLen << 32):
raise ValueError("mask too long")
# 2. Let T
T = b""
# 3. For counter from 0 to \lceil{l / hLen}\rceil-1, do the following:
# Note: \lceil{l / hLen}\rceil-1 is the number of iterations needed,
# but it's easier to check if we have reached the desired length.
counter = 0
while len(T) < length:
# a. Convert counter to an octet string C of length 4 with the primitive I2OSP: C = I2OSP (counter, 4)
C = int.to_bytes(counter, 4,
# b. Concatenate the hash of the seed Z and C to the octet string T: T = T || Hash (Z || C)
T += hash_func(seed + C).digest()
counter += 1
# 4. Output the leading l octets of T as the octet string mask.
return T[:length]
</syntaxhighlight>
|