Skip to content

Commit 0ac7106

Browse files
committed
CRITICAL: Fix FF1 expandS — XOR with R not previous block (NIST SP 800-38G)
Same bug as Java, Rust, Node. Verified against independent fpe crate v0.6.1.
1 parent 7c1d57f commit 0ac7106

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

cyphera/ff1.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ def _prf(self, data: bytes) -> bytes:
5050
def _expand_s(self, r: bytes, d: int) -> bytes:
5151
blocks = (d + 15) // 16
5252
out = bytearray(r)
53-
prev = r
5453
for j in range(1, blocks):
5554
x = j.to_bytes(16, "big")
56-
x = bytes(a ^ b for a, b in zip(x, prev))
55+
# XOR with R (not previous block) per NIST SP 800-38G
56+
x = bytes(a ^ b for a, b in zip(x, r))
5757
enc = self._aes_ecb(x)
5858
out.extend(enc)
59-
prev = enc
6059
return bytes(out[:d])
6160

6261
def _num(self, digits: list[int]) -> int:

0 commit comments

Comments
 (0)