Class: Cyphera::FF31
- Inherits:
-
Object
- Object
- Cyphera::FF31
- Defined in:
- lib/cyphera/ff3.rb
Overview
FF3-1 Format-Preserving Encryption (NIST SP 800-38G Revision 1).
FF3-1 is FF3 with a 56-bit (7-byte) tweak. The tweak is expanded into the 64-bit form the FF3 round function consumes; the algorithm is identical FF3.
Class Method Summary collapse
-
.expand_tweak(t) ⇒ Object
Expand the 56-bit FF3-1 tweak into the 64-bit tweak the FF3 round function consumes (NIST SP 800-38G Rev 1): bytes = T_L, [4,8] = T_R.
Instance Method Summary collapse
- #decrypt(ciphertext) ⇒ Object
- #encrypt(plaintext) ⇒ Object
-
#initialize(key, tweak, alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') ⇒ FF31
constructor
A new instance of FF31.
Constructor Details
#initialize(key, tweak, alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') ⇒ FF31
Returns a new instance of FF31.
178 179 180 181 182 183 |
# File 'lib/cyphera/ff3.rb', line 178 def initialize(key, tweak, alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') unless tweak.bytesize == 7 raise ArgumentError, "invalid tweak length: #{tweak.bytesize} (expected 7)" end @inner = FF3.new(key, FF31.(tweak), alphabet) end |
Class Method Details
.expand_tweak(t) ⇒ Object
Expand the 56-bit FF3-1 tweak into the 64-bit tweak the FF3 round function consumes (NIST SP 800-38G Rev 1): bytes = T_L, [4,8] = T_R.
195 196 197 198 |
# File 'lib/cyphera/ff3.rb', line 195 def self.(t) b = t.bytes [b[0], b[1], b[2], b[3] & 0xF0, b[4], b[5], b[6], (b[3] & 0x0F) << 4].pack('C*') end |
Instance Method Details
#decrypt(ciphertext) ⇒ Object
189 190 191 |
# File 'lib/cyphera/ff3.rb', line 189 def decrypt(ciphertext) @inner.decrypt(ciphertext) end |
#encrypt(plaintext) ⇒ Object
185 186 187 |
# File 'lib/cyphera/ff3.rb', line 185 def encrypt(plaintext) @inner.encrypt(plaintext) end |