tem_ruby 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +17 -3
  3. data/lib/tem/apdus/buffers.rb +1 -2
  4. data/lib/tem/builders/abi.rb +2 -2
  5. data/lib/tem/builders/assembler.rb +314 -0
  6. data/lib/tem/builders/crypto.rb +17 -8
  7. data/lib/tem/builders/isa.rb +120 -0
  8. data/lib/tem/definitions/abi.rb +8 -10
  9. data/lib/tem/definitions/assembler.rb +23 -0
  10. data/lib/tem/definitions/isa.rb +188 -0
  11. data/lib/tem/ecert.rb +15 -16
  12. data/lib/tem/sec_exec_error.rb +21 -3
  13. data/lib/tem/seclosures.rb +9 -5
  14. data/lib/tem/secpack.rb +50 -30
  15. data/lib/tem/toolkit.rb +11 -15
  16. data/lib/tem/transport/jcop_remote_protocol.rb +10 -2
  17. data/lib/tem_ruby.rb +4 -2
  18. data/tem_ruby.gemspec +5 -5
  19. data/test/tem_unit/test_tem_alu.rb +33 -0
  20. data/test/tem_unit/test_tem_bound_secpack.rb +51 -0
  21. data/test/tem_unit/test_tem_branching.rb +56 -0
  22. data/test/tem_unit/test_tem_crypto_asymmetric.rb +123 -0
  23. data/test/tem_unit/test_tem_crypto_hash.rb +35 -0
  24. data/test/tem_unit/test_tem_crypto_pstore.rb +53 -0
  25. data/test/tem_unit/test_tem_crypto_random.rb +25 -0
  26. data/test/tem_unit/test_tem_emit.rb +23 -0
  27. data/test/tem_unit/test_tem_memory.rb +48 -0
  28. data/test/tem_unit/test_tem_memory_compare.rb +65 -0
  29. data/test/tem_unit/test_tem_output.rb +32 -0
  30. data/test/tem_unit/test_tem_yaml_secpack.rb +47 -0
  31. data/test/test_exceptions.rb +1 -2
  32. data/timings/blank_bound_secpack.rb +3 -5
  33. data/timings/blank_sec.rb +2 -3
  34. data/timings/timings.rb +7 -2
  35. data/timings/vm_perf.rb +9 -10
  36. data/timings/vm_perf_bound.rb +9 -10
  37. metadata +35 -9
  38. data/lib/tem/sec_assembler.rb +0 -90
  39. data/lib/tem/sec_opcodes.rb +0 -154
  40. data/test/test_tem.rb +0 -524
@@ -116,24 +116,23 @@ class TemTimings
116
116
  s.halt
117
117
 
118
118
  s.label :cmp_lo
119
- s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2C, 0x12]
119
+ s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2C, 0x12]
120
120
  s.label :cmp_med
121
- s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2D, 0x11]
121
+ s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2D, 0x11]
122
122
  s.label :cmp_hi
123
- s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
123
+ s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
124
124
  s.label :cmp_hi2
125
- s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
125
+ s.data :tem_ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
126
126
  s.label :copy_buf
127
- s.filler :ubyte, 6
127
+ s.zeros :tem_ubyte, 6
128
128
  s.label :copy_buf2
129
- s.filler :ubyte, 4
129
+ s.zeros :tem_ubyte, 4
130
130
  s.label :clobber
131
- s.filler :ubyte, 2
131
+ s.zeros :tem_ubyte, 2
132
132
  s.label :clobber2
133
- s.filler :ubyte, 2
133
+ s.zeros :tem_ubyte, 2
134
134
  s.label :stack
135
- s.stack
136
- s.extra 24
135
+ s.stack 12
137
136
  }
138
137
  secpack.bind @tem.pubek, :done, :stack
139
138
  print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
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.10.1
4
+ version: 0.10.2
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-05-26 00:00:00 -04:00
12
+ date: 2009-05-31 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,17 +46,19 @@ extra_rdoc_files:
46
46
  - lib/tem/apdus/tag.rb
47
47
  - lib/tem/auto_conf.rb
48
48
  - lib/tem/builders/abi.rb
49
+ - lib/tem/builders/assembler.rb
49
50
  - lib/tem/builders/crypto.rb
51
+ - lib/tem/builders/isa.rb
50
52
  - lib/tem/ca.rb
51
53
  - lib/tem/definitions/abi.rb
54
+ - lib/tem/definitions/assembler.rb
55
+ - lib/tem/definitions/isa.rb
52
56
  - lib/tem/ecert.rb
53
57
  - lib/tem/hive.rb
54
58
  - lib/tem/keys/asymmetric.rb
55
59
  - lib/tem/keys/key.rb
56
60
  - lib/tem/keys/symmetric.rb
57
- - lib/tem/sec_assembler.rb
58
61
  - lib/tem/sec_exec_error.rb
59
- - lib/tem/sec_opcodes.rb
60
62
  - lib/tem/seclosures.rb
61
63
  - lib/tem/secpack.rb
62
64
  - lib/tem/tem.rb
@@ -89,17 +91,19 @@ files:
89
91
  - lib/tem/apdus/tag.rb
90
92
  - lib/tem/auto_conf.rb
91
93
  - lib/tem/builders/abi.rb
94
+ - lib/tem/builders/assembler.rb
92
95
  - lib/tem/builders/crypto.rb
96
+ - lib/tem/builders/isa.rb
93
97
  - lib/tem/ca.rb
94
98
  - lib/tem/definitions/abi.rb
99
+ - lib/tem/definitions/assembler.rb
100
+ - lib/tem/definitions/isa.rb
95
101
  - lib/tem/ecert.rb
96
102
  - lib/tem/hive.rb
97
103
  - lib/tem/keys/asymmetric.rb
98
104
  - lib/tem/keys/key.rb
99
105
  - lib/tem/keys/symmetric.rb
100
- - lib/tem/sec_assembler.rb
101
106
  - lib/tem/sec_exec_error.rb
102
- - lib/tem/sec_opcodes.rb
103
107
  - lib/tem/seclosures.rb
104
108
  - lib/tem/secpack.rb
105
109
  - lib/tem/tem.rb
@@ -116,12 +120,24 @@ files:
116
120
  - Manifest
117
121
  - Rakefile
118
122
  - README
123
+ - tem_ruby.gemspec
119
124
  - test/_test_cert.rb
120
125
  - test/builders/test_abi_builder.rb
121
126
  - test/tem_test_case.rb
127
+ - test/tem_unit/test_tem_alu.rb
128
+ - test/tem_unit/test_tem_bound_secpack.rb
129
+ - test/tem_unit/test_tem_branching.rb
130
+ - test/tem_unit/test_tem_crypto_asymmetric.rb
131
+ - test/tem_unit/test_tem_crypto_hash.rb
132
+ - test/tem_unit/test_tem_crypto_pstore.rb
133
+ - test/tem_unit/test_tem_crypto_random.rb
134
+ - test/tem_unit/test_tem_emit.rb
135
+ - test/tem_unit/test_tem_memory.rb
136
+ - test/tem_unit/test_tem_memory_compare.rb
137
+ - test/tem_unit/test_tem_output.rb
138
+ - test/tem_unit/test_tem_yaml_secpack.rb
122
139
  - test/test_driver.rb
123
140
  - test/test_exceptions.rb
124
- - test/test_tem.rb
125
141
  - test/transport/test_auto_configurator.rb
126
142
  - test/transport/test_java_card_mixin.rb
127
143
  - test/transport/test_jcop_remote.rb
@@ -133,7 +149,6 @@ files:
133
149
  - timings/timings.rb
134
150
  - timings/vm_perf.rb
135
151
  - timings/vm_perf_bound.rb
136
- - tem_ruby.gemspec
137
152
  has_rdoc: true
138
153
  homepage: http://tem.rubyforge.org
139
154
  licenses: []
@@ -169,9 +184,20 @@ specification_version: 3
169
184
  summary: TEM (Trusted Execution Module) driver, written in and for ruby.
170
185
  test_files:
171
186
  - test/builders/test_abi_builder.rb
187
+ - test/tem_unit/test_tem_alu.rb
188
+ - test/tem_unit/test_tem_bound_secpack.rb
189
+ - test/tem_unit/test_tem_branching.rb
190
+ - test/tem_unit/test_tem_crypto_asymmetric.rb
191
+ - test/tem_unit/test_tem_crypto_hash.rb
192
+ - test/tem_unit/test_tem_crypto_pstore.rb
193
+ - test/tem_unit/test_tem_crypto_random.rb
194
+ - test/tem_unit/test_tem_emit.rb
195
+ - test/tem_unit/test_tem_memory.rb
196
+ - test/tem_unit/test_tem_memory_compare.rb
197
+ - test/tem_unit/test_tem_output.rb
198
+ - test/tem_unit/test_tem_yaml_secpack.rb
172
199
  - test/test_driver.rb
173
200
  - test/test_exceptions.rb
174
- - test/test_tem.rb
175
201
  - test/transport/test_auto_configurator.rb
176
202
  - test/transport/test_java_card_mixin.rb
177
203
  - test/transport/test_jcop_remote.rb
@@ -1,90 +0,0 @@
1
- class Tem::SecAssembler
2
- def initialize(tem_klass)
3
- @tem_klass = tem_klass
4
- @body = []
5
- @labels = {}
6
- @lines = {}
7
- @sp, @ep, @extra_bytes = nil, nil, nil
8
- end
9
-
10
- def self.opcode(name, value, *params)
11
- p_hash = {}
12
- params.each_index { |i| p_hash[params[i][:name]] = i unless params[i][:name].nil? }
13
-
14
- define_method(name.to_sym) do |*m_params|
15
- # linearize the parameters
16
- param_idx = 0
17
- s_params = []
18
- m_params.each_index do |i|
19
- if m_params[i].instance_of? Hash
20
- raise "no embedded hashes please! (check parameter #{param_idx})" unless i == m_params.length - 1
21
- m_params[i].each do |k, v|
22
- raise "no parameter with name #{k} for opcode #{name}" if p_hash[k].nil?
23
- raise "parameter #{k} was already assigned a value" unless (param_idx <= p_hash[k] and s_params[p_hash[k]].nil?)
24
- s_params[p_hash[k]] = v
25
- end
26
- else
27
- s_params[param_idx] = m_params[i]
28
- param_idx += 1
29
- end
30
- end
31
-
32
- # check for missing parameters
33
- raise "opcode #{name} requires more parameters" unless s_params.length == params.length and s_params.all? { |v| !v.nil? }
34
-
35
- # encode parameters
36
- @lines[@body.length] = Kernel.caller(0)
37
- @body += @tem_klass.to_tem_ubyte(value)
38
- s_params.each_index do |i|
39
- if (s_params[i].kind_of? Numeric) && !params[i][:relative]
40
- @body += @tem_klass.send "to_tem_#{params[i][:type]}".to_sym, s_params[i]
41
- else
42
- @body << { :type => params[i][:type], :relative => params[i][:reladdr] ? params[i][:reladdr] : false }.merge!(
43
- (s_params[i].kind_of? Numeric) ? { :address => s_params[i].to_i } : { :label => s_params[i].to_sym })
44
- @body += (@tem_klass.send "to_tem_#{params[i][:type]}".to_sym, 0)[1..-1]
45
- end
46
- end
47
- end
48
- end
49
-
50
- def assemble(&sec_block)
51
- # call the block to build the SECpack
52
- yield self
53
-
54
- # link in label addresses
55
- @body.each_index do |i|
56
- if @body[i].kind_of? Hash
57
- raise "label #{@body[i][:label]} undefined" if (!@body[i][:label].nil? and @labels[@body[i][:label]].nil?)
58
- addr = @body[i][:label].nil? ? @body[i][:address] : @labels[@body[i][:label]]
59
- q = @body[i][:relative] ? (@tem_klass.send "signed_to_tem_#{@body[i][:type]}".to_sym, addr - i - @body[i][:relative]) :
60
- (@tem_klass.send "to_tem_#{@body[i][:type]}".to_sym, addr)
61
- @body[i, q.length] = *q
62
- end
63
- end
64
-
65
- return Tem::SecPack.new(:tem_class => @tem_klass, :body => @body, :labels => @labels,
66
- :ep => @ep || 0, :sp => @sp || @body.length, :extra_bytes => @extra_bytes || 0, :lines => @lines)
67
- end
68
-
69
- def label(name)
70
- raise "label #{name} already defined" unless @labels[name.to_sym].nil?
71
- @labels[name.to_sym] = @body.length
72
- end
73
- def filler(type_name, count = 1)
74
- bytes = count * @tem_klass.send("tem_#{type_name}_length".to_sym)
75
- @body += Array.new(bytes, 0)
76
- end
77
- def immed(type_name, values)
78
- values = [values] unless values.instance_of? Array
79
- @body += values.map { |v| @tem_klass.send "to_tem_#{type_name}".to_sym, v }.flatten
80
- end
81
- def entry
82
- @ep = @body.length
83
- end
84
- def stack
85
- @sp = @body.length
86
- end
87
- def extra(extra_bytes)
88
- @extra_bytes = extra_bytes
89
- end
90
- end
@@ -1,154 +0,0 @@
1
- class Tem::SecAssembler
2
- # 2 ST -> 1 ST
3
- opcode :add, 0x10
4
- # 2 ST -> 1 ST
5
- opcode :sub, 0x11
6
- # 2 ST -> 1 ST
7
- opcode :mul, 0x12
8
- # 2 ST -> 1 ST
9
- opcode :div, 0x13
10
- # 2 ST -> 1 ST
11
- opcode :mod, 0x14
12
- # 2 ST -> 1 ST
13
- opcode :rnd, 0x1E
14
-
15
-
16
- # 2 ST -> 1 ST
17
- opcode :stbv, 0x3A
18
- # 2 ST -> 1 ST
19
- opcode :stwv, 0x3B
20
-
21
- # 2 ST -> 1 ST
22
- opcode :stk, 0x5B
23
-
24
-
25
- # 1 ST, 1 IM -> 1 ST
26
- opcode :stb , 0x38, {:name => :to, :type => :ushort}
27
- # 1 ST, 1 IM -> 1 ST
28
- opcode :stw , 0x39, {:name => :to, :type => :ushort}
29
-
30
-
31
- # 2 IM -> 1 ST
32
- opcode(:psupfxb, 0x48, {:name => :addr, :type => :ushort}, {:name => :from, :type => :ushort})
33
- # 2 ST -> 1 ST
34
- opcode :psupvb, 0x49
35
- # 2 IM -> 1 ST
36
- opcode(:pswrfxb, 0x4A, {:name => :addr, :type => :ushort}, {:name => :from, :type => :ushort})
37
- # 2 ST -> 1 ST
38
- opcode :pswrvb, 0x4B
39
- # 2 IM -> 1 ST
40
- opcode(:psrdfxb, 0x4C, {:name => :addr, :type => :ushort}, {:name => :to, :type => :ushort})
41
- # 2 ST -> 1 ST
42
- opcode :psrdvb, 0x4D
43
- # 2 IM -> 1 ST
44
- opcode :pshkfxb, 0x4E, {:name => :addr, :type => :ushort}
45
- # 2 ST -> 1 ST
46
- opcode :pshkvb, 0x4F
47
-
48
-
49
- # 3 IM -> 1 ST
50
- opcode(:mdfxb, 0x18, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :to, :type => :ushort})
51
- # 3 ST -> 1 ST
52
- opcode :mdvb, 0x19
53
- # 3 IM -> 1 ST
54
- opcode(:mcmpfxb,0x1A, {:name => :size, :type => :ushort}, {:name => :op1, :type => :ushort}, {:name => :op2, :type => :ushort})
55
- # 3 ST -> 1 ST
56
- opcode :mcmpvb, 0x1B
57
- # 3 IM -> 1 ST
58
- opcode(:mcfxb, 0x1C, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :to, :type => :ushort})
59
- # 3 ST -> 1 ST
60
- opcode :mcvb, 0x1D
61
-
62
- # 1 ST, 3 IM -> 1 ST
63
- opcode(:kefxb, 0x50, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :to, :type => :ushort})
64
- # 4 ST -> 1 ST
65
- opcode :kevb, 0x51
66
- # 1 ST, 3 IM -> 1 ST
67
- opcode(:kdfxb, 0x52, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :to, :type => :ushort})
68
- # 4 ST -> 1 ST
69
- opcode :kdvb, 0x53
70
- # 1 ST, 3 IM -> 1 ST
71
- opcode(:ksfxb, 0x54, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :to, :type => :ushort})
72
- # 4 ST -> 1 ST
73
- opcode :ksvb, 0x55
74
- # 1 ST, 3 IM -> 1 ST
75
- opcode(:kvsfxb, 0x56, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort}, {:name => :signature, :type => :ushort})
76
- # 4 ST -> 1 ST
77
- opcode :kvsvb, 0x57
78
-
79
-
80
- # 0 ST -> 0 ST; IP
81
- opcode :jmp, 0x27, {:name => :to, :type => :ushort, :reladdr => 2}
82
- # 1 ST -> 0 ST; IP
83
- opcode :jz, 0x21, {:name => :to, :type => :ushort, :reladdr => 2}
84
- opcode :je, 0x21, {:name => :to, :type => :ushort, :reladdr => 2}
85
- # 1 ST -> 0 ST; IP
86
- opcode :jnz, 0x26, {:name => :to, :type => :ushort, :reladdr => 2}
87
- opcode :jne, 0x26, {:name => :to, :type => :ushort, :reladdr => 2}
88
- # 1 ST -> 0 ST; IP
89
- opcode :ja, 0x22, {:name => :to, :type => :ushort, :reladdr => 2}
90
- opcode :jg, 0x22, {:name => :to, :type => :ushort, :reladdr => 2}
91
- # 1 ST -> 0 ST; IP
92
- opcode :jae, 0x23, {:name => :to, :type => :ushort, :reladdr => 2}
93
- opcode :jge, 0x23, {:name => :to, :type => :ushort, :reladdr => 2}
94
- # 1 ST -> 0 ST; IP
95
- opcode :jb, 0x24, {:name => :to, :type => :ushort, :reladdr => 2}
96
- opcode :jl, 0x24, {:name => :to, :type => :ushort, :reladdr => 2}
97
- # 1 ST -> 0 ST; IP
98
- opcode :jbe, 0x25, {:name => :to, :type => :ushort, :reladdr => 2}
99
- opcode :jle, 0x25, {:name => :to, :type => :ushort, :reladdr => 2}
100
-
101
- # 1 IM_B -> 1 ST
102
- opcode :ldbc, 0x30, {:name => :const, :type => :byte}
103
- # 1 IM -> 1 ST
104
- opcode :ldwc, 0x31, {:name => :const, :type => :short}
105
- # 1 ST -> 1 ST
106
- opcode :ldb , 0x32, {:name => :from, :type => :ushort}
107
- # 1 ST -> 1 ST
108
- opcode :ldw , 0x33, {:name => :from, :type => :ushort}
109
- # 1 ST -> 1 ST
110
- opcode :ldbv, 0x36
111
- # 1 ST -> 1 ST
112
- opcode :ldwv, 0x37
113
-
114
- # 1 ST -> 0 ST
115
- opcode :outnew, 0x42
116
- # 1 ST -> 0 ST
117
- opcode :outb, 0x44
118
- # 1 ST -> 0 ST
119
- opcode :outw, 0x45
120
-
121
- # 1 ST -> 0 ST
122
- opcode :pop, 0x34
123
- # 2 ST -> 0 ST
124
- opcode :pop2, 0x35
125
-
126
- # 1 IM, x ST -> 2x ST
127
- opcode :dupn, 0x3C, {:name => :n, :type => :ubyte}
128
- # 1 IM, x ST -> x ST
129
- opcode :flipn, 0x3D, {:name => :n, :type => :ubyte}
130
-
131
- # 2 IM -> 0 ST
132
- opcode(:outfxb, 0x40, {:name => :size, :type => :ushort}, {:name => :from, :type => :ushort})
133
- # 2 ST -> 0 ST
134
- opcode(:outvlb, 0x41, {:name => :from, :type => :ushort})
135
-
136
-
137
- # 1 IM, 1 ST -> 0 ST
138
- opcode :outvb, 0x43
139
- # 0 ST -> 0 ST;;
140
- opcode :halt, 0x46
141
- # 1 ST -> 0 ST
142
- opcode :psrm, 0x47
143
-
144
- # 1 ST -> 1 ST
145
- opcode :rdk, 0x5A
146
- # 1 ST -> 0 ST
147
- opcode :relk, 0x5C
148
-
149
- opcode :ldkl, 0x5D
150
- # 1 IM_B -> 2 ST
151
- opcode :genkp, 0x5E, {:name => :type, :type => :ubyte }
152
- # 1 ST, 1 IM -> 1 ST
153
- opcode :authk, 0x5F, {:name => :auth, :type => :ushort }
154
- end