tem_ruby 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.14.1. Benchmarks for symmetric encryption.
2
+
1
3
  v0.14.0. Finalized symmetric encryption (fw 1.14).
2
4
 
3
5
  v0.13.0. Public bits in TEM buffer stats (fw 1.13).
@@ -16,6 +16,8 @@ require 'tem/benchmarks/vm_perf_bound.rb'
16
16
 
17
17
 
18
18
  class Tem::Benchmarks
19
+ attr_reader :timing
20
+
19
21
  def setup
20
22
  @tem = Tem.auto_tem
21
23
 
@@ -43,13 +45,19 @@ class Tem::Benchmarks
43
45
  end
44
46
  avg_time = timings.inject { |a,v| a + v } / timings.length
45
47
  max_diff = timings.map { |t| (t - avg_time).abs }.max
46
- uncertainty = 100 * max_diff / avg_time
48
+ uncertainty = max_diff / avg_time
47
49
  print "%8d: %3.8fs per run, %3.8fs uncertainty (%2.5f%%)\n" %
48
50
  [n, avg_time / n, max_diff / n, 100 * uncertainty]
49
51
 
50
- return avg_time / n unless max_diff / avg_time >= 0.01
51
- n *= 2
52
+ if max_diff / avg_time >= 0.01
53
+ n *= 2
54
+ next
55
+ end
56
+
57
+ @timing = avg_time / n
58
+ break
52
59
  end
60
+ @timing
53
61
  end
54
62
 
55
63
  def self.all_benchmarks
@@ -58,7 +66,8 @@ class Tem::Benchmarks
58
66
  t.setup
59
67
  t.methods.select { |m| m =~ /time_/ }.each do |m|
60
68
  print "Timing: #{m[5..-1]}...\n"
61
- benchmarks[m] = t.send m.to_sym
69
+ t.send m.to_sym
70
+ benchmarks[m] = t.timing
62
71
  end
63
72
  t.teardown
64
73
  benchmarks
@@ -9,20 +9,27 @@
9
9
 
10
10
  # :nodoc:
11
11
  class Tem::Benchmarks
12
- def time_blank_bound_secpack
13
- secpack = @tem.assemble { |s|
14
- s.ldbc 0
15
- s.outnew
16
- s.halt
17
- s.label :secret
18
- s.zeros :tem_ubyte, 50
19
- s.label :plain
20
- s.zeros :tem_ubyte, 220
21
- s.stack 1
22
- }
12
+ def time_blank_bound_secpack_rsa
13
+ secpack = blank_seclosure
23
14
  secpack.bind @tem.pubek, :secret, :plain
24
-
25
- print "SECpack has #{secpack.body.length} bytes, runs 3 instructions and produces 0 bytes\n"
15
+ print "RSA-bound SECpack has #{secpack.body.length} bytes, " +
16
+ "executes #{blank_seclosure_opcount} instructions and produces " +
17
+ "#{blank_seclosure_outcount} bytes\n"
26
18
  do_timing { @tem.execute secpack }
27
19
  end
20
+
21
+ def time_blank_bound_secpack_3des
22
+ key = Tem::Keys::Symmetric.generate
23
+ authz = [1] * 20
24
+ key_id = @tem.tk_post_key key, authz
25
+
26
+ secpack = blank_seclosure
27
+ secpack.bind key, :secret, :plain
28
+ print "3DES-bound SECpack has #{secpack.body.length} bytes, " +
29
+ "executes #{blank_seclosure_opcount} instructions and produces " +
30
+ "#{blank_seclosure_outcount} bytes\n"
31
+ do_timing { @tem.execute secpack, key_id }
32
+
33
+ @tem.tk_delete_key key_id, authz
34
+ end
28
35
  end
@@ -13,16 +13,35 @@
13
13
 
14
14
  # :nodoc:
15
15
  class Tem::Benchmarks
16
- def time_blank_sec
17
- secpack = @tem.assemble { |s|
16
+ # The SEClosure used in the blank benchmark.
17
+ def blank_seclosure
18
+ @tem.assemble { |s|
18
19
  s.ldbc 0
19
20
  s.outnew
20
21
  s.halt
21
- s.zeros :tem_ubyte, 70
22
+ s.label :secret
23
+ s.zeros :tem_ubyte, 50
24
+ s.label :plain
25
+ s.zeros :tem_ubyte, 220
22
26
  s.stack 1
23
27
  }
24
-
25
- print "SECpack has #{secpack.body.length} bytes, runs 3 instructions and produces 0 bytes\n"
28
+ end
29
+
30
+ # Number of opcodes executed by the blank SEClosure.
31
+ def blank_seclosure_opcount
32
+ 3
33
+ end
34
+
35
+ # Number of bytes output by the blank SEClosure.
36
+ def blank_seclosure_outcount
37
+ 0
38
+ end
39
+
40
+ def time_blank_sec
41
+ secpack = blank_seclosure
42
+ print "SECpack has #{secpack.body.length} bytes, " +
43
+ "executes #{blank_seclosure_opcount} instructions and produces " +
44
+ "#{blank_seclosure_outcount} bytes\n"
26
45
  do_timing { @tem.execute secpack }
27
46
  end
28
47
  end
@@ -11,11 +11,33 @@
11
11
 
12
12
  # :nodoc:
13
13
  class Tem::Benchmarks
14
- def time_devchip_decrypt
14
+ def time_devchip_decrypt_rsa_long
15
15
  pubek = @tem.pubek
16
16
  data = (1...120).map { |i| (i * i * 217 + i * 661 + 393) % 256 }
17
17
  encrypted_data = pubek.encrypt data
18
- print "Encrypted blob has #{encrypted_data.length} bytes\n"
18
+ print "RSA-encrypted blob has #{encrypted_data.length} bytes\n"
19
19
  do_timing { @tem.devchip_decrypt encrypted_data, 0 }
20
20
  end
21
+
22
+ def time_devchip_decrypt_3des
23
+ key = Tem::Keys::Symmetric.generate
24
+ authz = [1] * 20
25
+ key_id = @tem.tk_post_key key, authz
26
+ data = (1...23).map { |i| (i * i * 217 + i * 661 + 393) % 256 }
27
+ encrypted_data = key.encrypt data
28
+ print "3DES-encrypted blob has #{encrypted_data.length} bytes\n"
29
+ do_timing { @tem.devchip_decrypt encrypted_data, key_id }
30
+ @tem.tk_delete_key key_id, authz
31
+ end
32
+
33
+ def time_devchip_decrypt_3des_long
34
+ key = Tem::Keys::Symmetric.generate
35
+ authz = [1] * 20
36
+ key_id = @tem.tk_post_key key, authz
37
+ data = (1...120).map { |i| (i * i * 217 + i * 661 + 393) % 256 }
38
+ encrypted_data = key.encrypt data
39
+ print "3DES-encrypted blob has #{encrypted_data.length} bytes\n"
40
+ do_timing { @tem.devchip_decrypt encrypted_data, key_id }
41
+ @tem.tk_delete_key key_id, authz
42
+ end
21
43
  end
@@ -11,6 +11,6 @@
11
11
  # :nodoc:
12
12
  class Tem::Benchmarks
13
13
  def time_simple_apdu
14
- do_timing { @tem.get_tag_length }
14
+ do_timing { @tem.fw_version }
15
15
  end
16
16
  end
@@ -10,8 +10,9 @@
10
10
 
11
11
  # :nodoc:
12
12
  class Tem::Benchmarks
13
- def time_vm_perf
14
- secpack = @tem.assemble { |s|
13
+ # The SEClosure used in the vm_perf benchmark.
14
+ def vm_perf_seclosure
15
+ @tem.assemble { |s|
15
16
  s.ldwc 48 * 10
16
17
  s.outnew
17
18
 
@@ -145,7 +146,23 @@ class Tem::Benchmarks
145
146
  s.label :stack
146
147
  s.stack 12
147
148
  }
148
- print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
149
+ end
150
+
151
+ # Number of opcodes executed by the vm_perf SEClosure.
152
+ def vm_perf_seclosure_opcount
153
+ 1020
154
+ end
155
+
156
+ # Number of bytes output by the vm_perf SEClosure.
157
+ def vm_perf_seclosure_outcount
158
+ 470
159
+ end
160
+
161
+ def time_vm_perf
162
+ secpack = vm_perf_seclosure
163
+ print "SECpack has #{secpack.body.length} bytes, " +
164
+ "executes #{vm_perf_seclosure_opcount} instructions and produces " +
165
+ "#{vm_perf_seclosure_outcount} bytes\n"
149
166
  do_timing { @tem.execute secpack }
150
- end
167
+ end
151
168
  end
@@ -11,143 +11,27 @@
11
11
 
12
12
  # :nodoc:
13
13
  class Tem::Benchmarks
14
- def time_vm_perf_bound
15
- secpack = @tem.assemble { |s|
16
- s.ldwc 48 * 10
17
- s.outnew
18
-
19
- s.ldwc 10 # number of times to loop (4 instructions in loop)
20
- s.label :main_loop
21
-
22
- # arithmetic (18 instructions, 10 bytes out)
23
- s.ldwc 0x1234
24
- s.ldwc 0x5678
25
- s.dupn :n => 2
26
- s.add
27
- s.outw
28
- s.sub
29
- s.outw
30
- s.ldwc 0x0155
31
- s.ldwc 0x02AA
32
- s.mul
33
- s.outw
34
- s.ldwc 0x390C
35
- s.ldwc 0x00AA
36
- s.dupn :n => 2
37
- s.div
38
- s.outw
39
- s.mod
40
- s.outw
41
-
42
- # memory (28 instructions, 16 bytes out)
43
- s.ldwc 0x55AA
44
- s.stw :clobber
45
- s.ldb :clobber
46
- s.outw
47
- s.ldw :clobber
48
- s.outw
49
- s.ldbc 0xA5 - (1 << 8)
50
- s.stb :clobber
51
- s.ldw :clobber
52
- s.outw
53
- s.ldwc :clobber2
54
- s.dupn :n => 1
55
- s.dupn :n => 2
56
- s.ldwc 0x9966 - (1 << 16)
57
- s.stwv
58
- s.ldbv
59
- s.outw
60
- s.ldbc 0x98 - (1 << 8)
61
- s.stbv
62
- s.ldwv
63
- s.outw
64
- s.ldwc 0x1122
65
- s.ldwc 0x3344
66
- s.ldwc 0x5566
67
- s.flipn :n => 3
68
- s.outw
69
- s.outw
70
- s.outw
71
-
72
- # memory comparisons (22 instructions, 16 bytes out)
73
- s.ldwc :const => 6
74
- s.ldwc :cmp_med
75
- s.ldwc :cmp_lo
76
- s.mcmpvb
77
- s.outw
78
- s.mcmpfxb :size => 6, :op1 => :cmp_med, :op2 => :cmp_hi
79
- s.outw
80
- s.ldwc :const => 4
81
- s.ldwc :cmp_lo
82
- s.ldwc :cmp_med
83
- s.mcmpvb
84
- s.outw
85
- s.mcfxb :size => 6, :from => :cmp_hi, :to => :copy_buf
86
- s.pop
87
- s.outfxb :size => 6, :from => :copy_buf
88
- s.ldwc :const => 4
89
- s.ldwc :cmp_hi
90
- s.ldwc :copy_buf2
91
- s.mcvb
92
- s.pop
93
- s.outfxb :size => 4, :from => :copy_buf2
94
-
95
- # jumps (30 instructions, 6 bytes) from 6 * (5 instructions, 1 byte)
96
- failed = 0xFA - (1 << 8)
97
- [
98
- [:ja, [1, 1, failed]],
99
- [:jae, [1, 4, failed]],
100
- [:jb, [1, failed, 7]],
101
- [:jbe, [1, failed, 10]],
102
- [:jz, [1, failed, 13]],
103
- [:jne, [1, 16, failed]],
104
- ].each do |op_line|
105
- op = op_line.shift
106
- op_line.each_index do |i|
107
- then_label = "#{op}_l#{i}_t".to_sym
108
- out_label = "#{op}_l#{i}_o".to_sym
109
-
110
- s.ldbc op_line[i][0]
111
- s.send op, :to => then_label
112
- s.ldbc op_line[i][2]
113
- s.jmp :to => out_label
114
- s.label then_label
115
- s.ldbc op_line[i][1]
116
- s.label out_label
117
- s.outb
118
- end
119
- end
120
-
121
- # loop back
122
- s.ldbc 1
123
- s.sub
124
- s.dupn :n => 1
125
- s.ja :to => :main_loop
126
-
127
- s.label :done
128
- s.halt
129
-
130
- s.label :cmp_lo
131
- s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2C, 0x12]
132
- s.label :cmp_med
133
- s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2D, 0x11]
134
- s.label :cmp_hi
135
- s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
136
- s.label :cmp_hi2
137
- s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
138
- s.label :copy_buf
139
- s.zeros :tem_ubyte, 6
140
- s.label :copy_buf2
141
- s.zeros :tem_ubyte, 4
142
- s.label :clobber
143
- s.zeros :tem_ubyte, 2
144
- s.label :clobber2
145
- s.zeros :tem_ubyte, 2
146
- s.label :stack
147
- s.stack 12
148
- }
14
+ def time_vm_perf_bound_rsa
15
+ secpack = vm_perf_seclosure
149
16
  secpack.bind @tem.pubek, :done, :stack
150
- print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
17
+ print "RSA-bound SECpack has #{secpack.body.length} bytes, " +
18
+ "executes #{vm_perf_seclosure_opcount} instructions and produces " +
19
+ "#{vm_perf_seclosure_outcount} bytes\n"
151
20
  do_timing { @tem.execute secpack }
152
- end
153
- end
21
+ end
22
+
23
+ def time_vm_perf_bound_3des
24
+ key = Tem::Keys::Symmetric.generate
25
+ authz = [1] * 20
26
+ key_id = @tem.tk_post_key key, authz
27
+
28
+ secpack = vm_perf_seclosure
29
+ secpack.bind key, :done, :stack
30
+ print "3DES-bound SECpack has #{secpack.body.length} bytes, " +
31
+ "executes #{vm_perf_seclosure_opcount} instructions and produces " +
32
+ "#{vm_perf_seclosure_outcount} bytes\n"
33
+ do_timing { @tem.execute secpack, key_id }
34
+
35
+ @tem.tk_delete_key key_id, authz
36
+ end
37
+ end
data/tem_ruby.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tem_ruby}
5
- s.version = "0.14.0"
5
+ s.version = "0.14.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Victor Costan"]
9
- s.date = %q{2009-11-12}
9
+ s.date = %q{2009-11-16}
10
10
  s.description = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
11
11
  s.email = %q{victor@costan.us}
12
12
  s.executables = ["tem_bench", "tem_ca", "tem_irb", "tem_proxy", "tem_stat", "tem_upload_fw"]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.rubyforge_project = %q{tem}
19
19
  s.rubygems_version = %q{1.3.5}
20
20
  s.summary = %q{TEM (Trusted Execution Module) driver, written in and for ruby.}
21
- s.test_files = ["test/builders/test_abi_builder.rb", "test/firmware/test_uploader.rb", "test/tem_unit/test_tem_alu.rb", "test/tem_unit/test_tem_bound_secpack.rb", "test/tem_unit/test_tem_branching.rb", "test/tem_unit/test_tem_crypto_hash.rb", "test/tem_unit/test_tem_crypto_keys.rb", "test/tem_unit/test_tem_crypto_pstore.rb", "test/tem_unit/test_tem_crypto_random.rb", "test/tem_unit/test_tem_emit.rb", "test/tem_unit/test_tem_memory.rb", "test/tem_unit/test_tem_memory_compare.rb", "test/tem_unit/test_tem_output.rb", "test/tem_unit/test_tem_yaml_secpack.rb", "test/test_auto_conf.rb", "test/test_crypto_engine.rb", "test/test_driver.rb", "test/test_exceptions.rb"]
21
+ s.test_files = ["test/test_driver.rb", "test/firmware/test_uploader.rb", "test/test_auto_conf.rb", "test/builders/test_abi_builder.rb", "test/tem_unit/test_tem_emit.rb", "test/tem_unit/test_tem_crypto_keys.rb", "test/tem_unit/test_tem_yaml_secpack.rb", "test/tem_unit/test_tem_alu.rb", "test/tem_unit/test_tem_crypto_hash.rb", "test/tem_unit/test_tem_bound_secpack.rb", "test/tem_unit/test_tem_memory_compare.rb", "test/tem_unit/test_tem_output.rb", "test/tem_unit/test_tem_crypto_random.rb", "test/tem_unit/test_tem_memory.rb", "test/tem_unit/test_tem_branching.rb", "test/tem_unit/test_tem_crypto_pstore.rb", "test/test_exceptions.rb", "test/test_crypto_engine.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tem_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Costan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-12 00:00:00 -05:00
12
+ date: 2009-11-16 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -204,21 +204,21 @@ signing_key:
204
204
  specification_version: 3
205
205
  summary: TEM (Trusted Execution Module) driver, written in and for ruby.
206
206
  test_files:
207
- - test/builders/test_abi_builder.rb
207
+ - test/test_driver.rb
208
208
  - test/firmware/test_uploader.rb
209
+ - test/test_auto_conf.rb
210
+ - test/builders/test_abi_builder.rb
211
+ - test/tem_unit/test_tem_emit.rb
212
+ - test/tem_unit/test_tem_crypto_keys.rb
213
+ - test/tem_unit/test_tem_yaml_secpack.rb
209
214
  - test/tem_unit/test_tem_alu.rb
210
- - test/tem_unit/test_tem_bound_secpack.rb
211
- - test/tem_unit/test_tem_branching.rb
212
215
  - test/tem_unit/test_tem_crypto_hash.rb
213
- - test/tem_unit/test_tem_crypto_keys.rb
214
- - test/tem_unit/test_tem_crypto_pstore.rb
215
- - test/tem_unit/test_tem_crypto_random.rb
216
- - test/tem_unit/test_tem_emit.rb
217
- - test/tem_unit/test_tem_memory.rb
216
+ - test/tem_unit/test_tem_bound_secpack.rb
218
217
  - test/tem_unit/test_tem_memory_compare.rb
219
218
  - test/tem_unit/test_tem_output.rb
220
- - test/tem_unit/test_tem_yaml_secpack.rb
221
- - test/test_auto_conf.rb
222
- - test/test_crypto_engine.rb
223
- - test/test_driver.rb
219
+ - test/tem_unit/test_tem_crypto_random.rb
220
+ - test/tem_unit/test_tem_memory.rb
221
+ - test/tem_unit/test_tem_branching.rb
222
+ - test/tem_unit/test_tem_crypto_pstore.rb
224
223
  - test/test_exceptions.rb
224
+ - test/test_crypto_engine.rb