lib/rmega/crypto/aes_ctr.rb in rmega-0.0.6 vs lib/rmega/crypto/aes_ctr.rb in rmega-0.1.0
- old
+ new
@@ -1,11 +1,14 @@
+require 'rmega/utils'
+require 'rmega/crypto/aes'
+
module Rmega
module Crypto
module AesCtr
extend self
- def decrypt key, nonce, data
+ def decrypt(key, nonce, data)
raise "invalid nonce" if nonce.size != 4 or !nonce.respond_to?(:pack)
raise "invalid key" if key.size != 4 or !key.respond_to?(:pack)
mac = [nonce[0], nonce[1], nonce[0], nonce[1]]
enc = nil
@@ -45,10 +48,10 @@
decrypted_data = Utils.a32_to_str(a32, data.size)
{data: decrypted_data, mac: mac}
end
- def encrypt key, nonce, data
+ def encrypt(key, nonce, data)
raise "invalid nonce" if nonce.size != 4 or !nonce.respond_to?(:pack)
raise "invalid key" if key.size != 4 or !key.respond_to?(:pack)
ctr = nonce.dup
mac = [ctr[0], ctr[1], ctr[0], ctr[1]]