capitalone / fpe

A format-preserving encryption implementation in Go
Apache License 2.0
201 stars 40 forks source link

ff3: fix maxLen calculation #33

Open anitgandhi opened 3 years ago

anitgandhi commented 3 years ago

maxLen is incorrectly being calculated by moving the multiplication by 2 into the floor, whereas the spec calls for the multiplication to happen outside (after) the flooring.

This causes the bug referenced later in Encrypt, where the length of the input, n, is not allowed to be equal to maxLen, whereas it is allowed in the spec.

https://github.com/capitalone/fpe/blob/e6bfa0dae121111c2e93483777f0f2cde562f341/ff3/ff3.go#L87