capitalone / fpe

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

Should tweak be input to Encrypt/Decrypt rather than NewCipher? #7

Closed anitgandhi closed 6 years ago

anitgandhi commented 7 years ago

Right now, the tweak parameter to NewCipher prevents re-use of the same cipher for different data inputs.

So, would it be better to instead pass in tweak to Encrypt and Decrypt?

This would likely cause a breaking change to the current API.

anitgandhi commented 6 years ago

If desired, the functions could be refactored to be follow a new pattern (vs current NewCipher --> Encrypt/Decrypt) like NewCipherWithoutTweak --> EncryptWithTweak/DecryptWithTweak.

All the rest of the code basically remains the same.

raj-jain commented 6 years ago

In practical applications of FPE, Tweak must be passed in every Encrypt/Decrypt operation. For instance, in protecting credit card PANs, the tweak may be dynamically extracted from the plaintext PAN as first 6 and last 4 digits of the PAN.