Class: Miscreant::AES::CMAC
- Inherits:
-
Object
- Object
- Miscreant::AES::CMAC
- Defined in:
- lib/miscreant/aes/cmac.rb
Overview
The AES-CMAC message authentication code
Instance Method Summary collapse
-
#digest(message) ⇒ String
Compute the AES-CMAC of the given input message in a single shot, outputting the MAC tag.
-
#initialize(key) ⇒ CMAC
constructor
Create a new AES-CMAC instance.
-
#inspect ⇒ String
Inspect this AES-CMAC instance.
Constructor Details
#initialize(key) ⇒ CMAC
Create a new AES-CMAC instance
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/miscreant/aes/cmac.rb', line 12 def initialize(key) @cipher = Internals::AES::BlockCipher.new(key) @subkey1 = Internals::Block.new @subkey1.encrypt(@cipher) @subkey1.dbl @subkey2 = @subkey1.dup @subkey2.dbl end |
Instance Method Details
#digest(message) ⇒ String
Compute the AES-CMAC of the given input message in a single shot, outputting the MAC tag.
Unlike other AES-CMAC implementations, this one does not support incremental processing/IUF operation. (Though that would enable slightly more efficient decryption for AES-SIV)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/miscreant/aes/cmac.rb', line 40 def digest() Internals::Util.validate_bytestring("message", ) if .empty? || .length % Internals::Block::SIZE != 0 = Internals::Util.pad(, Internals::Block::SIZE) subkey = @subkey2 else subkey = @subkey1 end count = .length / Internals::Block::SIZE digest = Internals::Block.new count.times do |i| digest.xor_in_place([Internals::Block::SIZE * i, Internals::Block::SIZE]) digest.xor_in_place(subkey) if i == count - 1 digest.encrypt(@cipher) end digest.data end |
#inspect ⇒ String
Inspect this AES-CMAC instance
26 27 28 |
# File 'lib/miscreant/aes/cmac.rb', line 26 def inspect to_s end |