crypto-toolbox 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d44c3eb26aa94b3c7b941235ae67cfd42d1d7e4
4
- data.tar.gz: 9e9c64094502898955d362e5fe5ff30d7563c056
3
+ metadata.gz: 5728516f47174d06b0901a72afa8a499ee5f0662
4
+ data.tar.gz: 9d83b1da078d82ba3345fb4b8aca1f860aaf1eb5
5
5
  SHA512:
6
- metadata.gz: 6b72ad40abe63b30723d5bc392ab470cdca4e4bf9d24fa5fbf7ad2ecb1b280b5a1d66c8753a548a9922c9df61e834e7f61d77bfd888fd6dd5780baf5ce862883
7
- data.tar.gz: be527c12832e261bc5223262034ac8774b030383cb9ba1b28f751417ca68cb990e3f83e06f7951225c57a2d429ed4a3e12d9defc4a0acb3dd5c94de47b54aa1c
6
+ metadata.gz: 21c9a10d814988c289b578850e1b769c817e086cd47a369578a01bdd8f5058ea6e1ef0573d311ab4ee6b3ee54f038ddc043475af83ae8f8a5112c02e126351af
7
+ data.tar.gz: 81601d2d3376c364ef5437b6d5af7c33bd4b3e47658eda3fa68a220439f4a6580fe0e20b3a6030909b9a52c89ad2e8026cb383dd7d2a7f6ebbd1eea84ee521c1
@@ -23,34 +23,43 @@ module Analyzers
23
23
  def analyze(target_message)
24
24
  @oracle.connect
25
25
 
26
- #target_msg = "I, the server, hereby agree that I will pay $100 to this student"
26
+ # split the target message into chunks of size N (e.g. 32)
27
27
  target_bufs = CryptBuffer(target_message).chunks_of(32)
28
28
 
29
- # add to_crypt_buffer to String!
30
- target_tag1 = CryptBuffer(@oracle.mac(target_bufs[0].chars,target_bufs[0].length)) #.split("").map{|i| i.bytes.first }
29
+ # receive the valid mac for the first chunk of the target message
30
+ tag1 = CryptBuffer(@oracle.mac(target_bufs[0]))
31
31
 
32
- # NOTE t'' = m || [ (m_1' + t ) ||m_2'||...||m_x']
33
- m2_blocks = target_bufs[1].chunks_of(16)
34
- msg2 = CryptBuffer((m2_blocks[0].xor(target_tag1)).bytes + m2_blocks[1].bytes)
32
+ attack_message = assemble_malicious_message(target_bufs,tag1)
33
+ forged_tag = @oracle.mac(attack_message)
35
34
 
36
- # @oracle.tag_for(msg2.chars,msg2.length)
37
- forge_tag = @oracle.mac(msg2.chars,msg2.length)
38
-
39
- # @oracle.verify(target_msg.chars, target_msg.length, forge_tag)
40
- ret = @oracle.verify(target_message.chars, target_message.length, forge_tag)
35
+ ret = @oracle.verify(target_message, forged_tag)
41
36
 
37
+ report_result(ret,forged_tag)
42
38
 
39
+ @oracle.disconnect
40
+ end
41
+
42
+ private
43
+ # Create a message that consists of
44
+ # 1) the first n byte of the second message xored with tag t from the first message
45
+ # 2) the remaining blocks of the second message
46
+ # short: t'' = (m'_0 xor t ) ||m'_1 ||...||m'_n]
47
+ def assemble_malicious_message(target_bufs,tag1)
48
+
49
+ # split the second chunk into blocks of the size of the tag
50
+ m2_blocks = target_bufs[1].chunks_of(tag1.length)
51
+
52
+ CryptBuffer((m2_blocks[0].xor(tag1)).bytes + m2_blocks[1].bytes)
53
+ end
54
+
55
+ def report_result(ret,tag)
43
56
  if forge_successfull?(ret)
44
- puts "result is: #{CryptBuffer(forge_tag).hex}"
45
- puts "Message verified successfully!"
57
+ puts "[Success] Resulting tag is: #{CryptBuffer(tag).pretty_hexstring}"
46
58
  else
47
- puts "Message verification failed."
59
+ puts "[Failure] Message verification failed."
48
60
  end
49
- @oracle.disconnect
50
61
  end
51
62
 
52
- private
53
-
54
63
  def forge_successfull?(retval)
55
64
  retval == 1
56
65
  end
@@ -23,20 +23,20 @@ module Analyzers
23
23
  @mac_socket.close if @mac_socket
24
24
  end
25
25
 
26
- def mac(message,len)
26
+ def mac(message)
27
27
  connect unless @mac_socket
28
28
 
29
- packet = ([message.length] + message + [0]).map(&:chr).join("")
29
+ packet = ([message.length] + message.bytes + [0]).map(&:chr).join("")
30
30
 
31
31
  @mac_socket.write(packet)
32
32
  @mac_socket.read(16)
33
33
  end
34
34
 
35
- def verify(message,len,tag)
35
+ def verify(message,tag)
36
36
  connect unless @verify_socket
37
37
 
38
38
  # Message-length + message-chars + tag-chars + 0
39
- packet = ([message.length] + message + tag.split("") + [0]).map(&:chr).join("")
39
+ packet = ([message.length] + message.bytes + tag.split("") + [0]).map(&:chr).join("")
40
40
 
41
41
  @verify_socket.write(packet)
42
42
  @verify_socket.read(2).to_i
@@ -1,11 +1,10 @@
1
1
  module CryptBufferConcern
2
2
  module PrettyPrint
3
3
  def pp
4
- puts pretty_hexstr
4
+ puts pretty_hexstring
5
5
  end
6
6
 
7
- private
8
- def pretty_hexstr
7
+ def pretty_hexstring
9
8
  str = h.scan(/.{2}/).to_a.join(" ")
10
9
  "0x#{h.upcase} (#{str.upcase})"
11
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia