Class: CryptoToolchain::Tools::SHA1LengthExtensionAttack

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/tools/sha1_length_extension_attack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, add:, mac:, key_length:) ⇒ SHA1LengthExtensionAttack

Returns a new instance of SHA1LengthExtensionAttack.



5
6
7
8
9
10
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 5

def initialize(message: , add: , mac: , key_length: )
  @message = message
  @mac = mac
  @add = add
  @key_length = key_length
end

Instance Attribute Details

#addObject (readonly)

Returns the value of attribute add.



25
26
27
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 25

def add
  @add
end

#key_lengthObject (readonly)

Returns the value of attribute key_length.



25
26
27
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 25

def key_length
  @key_length
end

#macObject (readonly)

Returns the value of attribute mac.



25
26
27
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 25

def mac
  @mac
end

#messageObject (readonly)

Returns the value of attribute message.



25
26
27
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 25

def message
  @message
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/crypto_toolchain/tools/sha1_length_extension_attack.rb', line 13

def execute
  dummy_key = "A" * key_length
  padding = CryptoToolchain::Utilities::SHA1.padding(dummy_key + message)
  [
    message + padding + add,
    CryptoToolchain::Utilities::SHA1.hexdigest(add,
                                               state: mac,
                                               append_length: (padding + message + dummy_key).length
                                              )
  ]
end