Class: Miscreant::Internals::AES::CTR
- Inherits:
-
Object
- Object
- Miscreant::Internals::AES::CTR
- Defined in:
- lib/miscreant/internals/aes/ctr.rb
Overview
The AES-CTR unauthenticated stream cipher
Instance Method Summary collapse
-
#encrypt(iv, message) ⇒ Object
Encrypt the given message using the given counter (i.e. IV).
-
#initialize(key) ⇒ CTR
constructor
Create a new AES-CTR instance.
-
#inspect ⇒ String
Inspect this AES-CTR instance.
Constructor Details
#initialize(key) ⇒ CTR
Create a new AES-CTR instance
12 13 14 15 16 17 |
# File 'lib/miscreant/internals/aes/ctr.rb', line 12 def initialize(key) Util.validate_bytestring("key", key, length: [16, 32]) @cipher = OpenSSL::Cipher::AES.new(key.bytesize * 8, :CTR) @cipher.encrypt @cipher.key = key end |
Instance Method Details
#encrypt(iv, message) ⇒ Object
Encrypt the given message using the given counter (i.e. IV)
30 31 32 33 34 35 36 |
# File 'lib/miscreant/internals/aes/ctr.rb', line 30 def encrypt(iv, ) Util.validate_bytestring("IV", iv, length: Block::SIZE) return "".b if .empty? @cipher.iv = iv @cipher.update() + @cipher.final end |
#inspect ⇒ String
Inspect this AES-CTR instance
22 23 24 |
# File 'lib/miscreant/internals/aes/ctr.rb', line 22 def inspect to_s end |