Class: CryptoToolchain::BlackBoxes::MD4Mac

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/black_boxes/md4_mac.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Random.new.bytes(16)) ⇒ MD4Mac

Returns a new instance of MD4Mac.



6
7
8
# File 'lib/crypto_toolchain/black_boxes/md4_mac.rb', line 6

def initialize(key: Random.new.bytes(16))
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/crypto_toolchain/black_boxes/md4_mac.rb', line 4

def key
  @key
end

Instance Method Details

#mac(str) ⇒ Object



10
11
12
13
# File 'lib/crypto_toolchain/black_boxes/md4_mac.rb', line 10

def mac(str)
  concat = key + str
  CryptoToolchain::Utilities::MD4.hexdigest(concat)
end

#valid?(message:, mac:) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/crypto_toolchain/black_boxes/md4_mac.rb', line 15

def valid?(message: , mac: )
  self.mac(message) == mac
end