tem_ruby 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +35 -0
- data/LICENSE +21 -0
- data/Manifest +45 -0
- data/README +6 -0
- data/bin/tem_bench +9 -0
- data/bin/tem_ca +13 -0
- data/bin/tem_irb +18 -0
- data/bin/tem_stat +39 -0
- data/dev_ca/ca_cert.cer +0 -0
- data/dev_ca/ca_cert.pem +32 -0
- data/dev_ca/ca_key.pem +27 -0
- data/dev_ca/config.yml +12 -0
- data/lib/scard/java_card.rb +31 -0
- data/lib/scard/jcop_remote_terminal.rb +52 -0
- data/lib/scard/pcsc_terminal.rb +83 -0
- data/lib/tem/_cert.rb +158 -0
- data/lib/tem/abi.rb +55 -0
- data/lib/tem/buffers.rb +98 -0
- data/lib/tem/ca.rb +114 -0
- data/lib/tem/crypto_abi.rb +216 -0
- data/lib/tem/ecert.rb +78 -0
- data/lib/tem/hive.rb +18 -0
- data/lib/tem/keys.rb +60 -0
- data/lib/tem/lifecycle.rb +8 -0
- data/lib/tem/sec_assembler.rb +91 -0
- data/lib/tem/sec_exec_error.rb +45 -0
- data/lib/tem/sec_opcodes.rb +154 -0
- data/lib/tem/seclosures.rb +82 -0
- data/lib/tem/secpack.rb +86 -0
- data/lib/tem/tag.rb +28 -0
- data/lib/tem/tem.rb +47 -0
- data/lib/tem/toolkit.rb +104 -0
- data/lib/tem_ruby.rb +29 -0
- data/tem_ruby.gemspec +53 -0
- data/test/_test_cert.rb +81 -0
- data/test/test_driver.rb +127 -0
- data/test/test_exceptions.rb +55 -0
- data/test/test_tem.rb +542 -0
- data/timings/blank_bound_secpack.rb +20 -0
- data/timings/blank_sec.rb +15 -0
- data/timings/devchip_decrypt.rb +9 -0
- data/timings/post_buffer.rb +10 -0
- data/timings/simple_apdu.rb +5 -0
- data/timings/timings.rb +66 -0
- data/timings/vm_perf.rb +141 -0
- data/timings/vm_perf_bound.rb +142 -0
- metadata +143 -0
data/timings/vm_perf.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
class TemTimings
|
2
|
+
def time_vm_perf
|
3
|
+
secpack = @tem.assemble { |s|
|
4
|
+
s.ldwc 48 * 10
|
5
|
+
s.outnew
|
6
|
+
|
7
|
+
s.ldwc 10 # number of times to loop (4 instructions in loop)
|
8
|
+
s.label :main_loop
|
9
|
+
|
10
|
+
# arithmetic (18 instructions, 10 bytes out)
|
11
|
+
s.ldwc 0x1234
|
12
|
+
s.ldwc 0x5678
|
13
|
+
s.dupn :n => 2
|
14
|
+
s.add
|
15
|
+
s.outw
|
16
|
+
s.sub
|
17
|
+
s.outw
|
18
|
+
s.ldwc 0x0155
|
19
|
+
s.ldwc 0x02AA
|
20
|
+
s.mul
|
21
|
+
s.outw
|
22
|
+
s.ldwc 0x390C
|
23
|
+
s.ldwc 0x00AA
|
24
|
+
s.dupn :n => 2
|
25
|
+
s.div
|
26
|
+
s.outw
|
27
|
+
s.mod
|
28
|
+
s.outw
|
29
|
+
|
30
|
+
# memory (28 instructions, 16 bytes out)
|
31
|
+
s.ldwc 0x55AA
|
32
|
+
s.stw :clobber
|
33
|
+
s.ldb :clobber
|
34
|
+
s.outw
|
35
|
+
s.ldw :clobber
|
36
|
+
s.outw
|
37
|
+
s.ldbc 0xA5 - (1 << 8)
|
38
|
+
s.stb :clobber
|
39
|
+
s.ldw :clobber
|
40
|
+
s.outw
|
41
|
+
s.ldwc :clobber2
|
42
|
+
s.dupn :n => 1
|
43
|
+
s.dupn :n => 2
|
44
|
+
s.ldwc 0x9966 - (1 << 16)
|
45
|
+
s.stwv
|
46
|
+
s.ldbv
|
47
|
+
s.outw
|
48
|
+
s.ldbc 0x98 - (1 << 8)
|
49
|
+
s.stbv
|
50
|
+
s.ldwv
|
51
|
+
s.outw
|
52
|
+
s.ldwc 0x1122
|
53
|
+
s.ldwc 0x3344
|
54
|
+
s.ldwc 0x5566
|
55
|
+
s.flipn :n => 3
|
56
|
+
s.outw
|
57
|
+
s.outw
|
58
|
+
s.outw
|
59
|
+
|
60
|
+
# memory comparisons (22 instructions, 16 bytes out)
|
61
|
+
s.ldwc :const => 6
|
62
|
+
s.ldwc :cmp_med
|
63
|
+
s.ldwc :cmp_lo
|
64
|
+
s.mcmpvb
|
65
|
+
s.outw
|
66
|
+
s.mcmpfxb :size => 6, :op1 => :cmp_med, :op2 => :cmp_hi
|
67
|
+
s.outw
|
68
|
+
s.ldwc :const => 4
|
69
|
+
s.ldwc :cmp_lo
|
70
|
+
s.ldwc :cmp_med
|
71
|
+
s.mcmpvb
|
72
|
+
s.outw
|
73
|
+
s.mcfxb :size => 6, :from => :cmp_hi, :to => :copy_buf
|
74
|
+
s.pop
|
75
|
+
s.outfxb :size => 6, :from => :copy_buf
|
76
|
+
s.ldwc :const => 4
|
77
|
+
s.ldwc :cmp_hi
|
78
|
+
s.ldwc :copy_buf2
|
79
|
+
s.mcvb
|
80
|
+
s.pop
|
81
|
+
s.outfxb :size => 4, :from => :copy_buf2
|
82
|
+
|
83
|
+
# jumps (30 instructions, 6 bytes) from 6 * (5 instructions, 1 byte)
|
84
|
+
failed = 0xFA - (1 << 8)
|
85
|
+
[
|
86
|
+
[:ja, [1, 1, failed]],
|
87
|
+
[:jae, [1, 4, failed]],
|
88
|
+
[:jb, [1, failed, 7]],
|
89
|
+
[:jbe, [1, failed, 10]],
|
90
|
+
[:jz, [1, failed, 13]],
|
91
|
+
[:jne, [1, 16, failed]],
|
92
|
+
].each do |op_line|
|
93
|
+
op = op_line.shift
|
94
|
+
op_line.each_index do |i|
|
95
|
+
then_label = "#{op}_l#{i}_t".to_sym
|
96
|
+
out_label = "#{op}_l#{i}_o".to_sym
|
97
|
+
|
98
|
+
s.ldbc op_line[i][0]
|
99
|
+
s.send op, :to => then_label
|
100
|
+
s.ldbc op_line[i][2]
|
101
|
+
s.jmp :to => out_label
|
102
|
+
s.label then_label
|
103
|
+
s.ldbc op_line[i][1]
|
104
|
+
s.label out_label
|
105
|
+
s.outb
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# loop back
|
110
|
+
s.ldbc 1
|
111
|
+
s.sub
|
112
|
+
s.dupn :n => 1
|
113
|
+
s.ja :to => :main_loop
|
114
|
+
|
115
|
+
s.label :done
|
116
|
+
s.halt
|
117
|
+
|
118
|
+
s.label :cmp_lo
|
119
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2C, 0x12]
|
120
|
+
s.label :cmp_med
|
121
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2D, 0x11]
|
122
|
+
s.label :cmp_hi
|
123
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
|
124
|
+
s.label :cmp_hi2
|
125
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
|
126
|
+
s.label :copy_buf
|
127
|
+
s.filler :ubyte, 6
|
128
|
+
s.label :copy_buf2
|
129
|
+
s.filler :ubyte, 4
|
130
|
+
s.label :clobber
|
131
|
+
s.filler :ubyte, 2
|
132
|
+
s.label :clobber2
|
133
|
+
s.filler :ubyte, 2
|
134
|
+
s.label :stack
|
135
|
+
s.stack
|
136
|
+
s.extra 24
|
137
|
+
}
|
138
|
+
print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
|
139
|
+
do_timing { @tem.execute secpack }
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
class TemTimings
|
2
|
+
def time_vm_perf_bound
|
3
|
+
secpack = @tem.assemble { |s|
|
4
|
+
s.ldwc 48 * 10
|
5
|
+
s.outnew
|
6
|
+
|
7
|
+
s.ldwc 10 # number of times to loop (4 instructions in loop)
|
8
|
+
s.label :main_loop
|
9
|
+
|
10
|
+
# arithmetic (18 instructions, 10 bytes out)
|
11
|
+
s.ldwc 0x1234
|
12
|
+
s.ldwc 0x5678
|
13
|
+
s.dupn :n => 2
|
14
|
+
s.add
|
15
|
+
s.outw
|
16
|
+
s.sub
|
17
|
+
s.outw
|
18
|
+
s.ldwc 0x0155
|
19
|
+
s.ldwc 0x02AA
|
20
|
+
s.mul
|
21
|
+
s.outw
|
22
|
+
s.ldwc 0x390C
|
23
|
+
s.ldwc 0x00AA
|
24
|
+
s.dupn :n => 2
|
25
|
+
s.div
|
26
|
+
s.outw
|
27
|
+
s.mod
|
28
|
+
s.outw
|
29
|
+
|
30
|
+
# memory (28 instructions, 16 bytes out)
|
31
|
+
s.ldwc 0x55AA
|
32
|
+
s.stw :clobber
|
33
|
+
s.ldb :clobber
|
34
|
+
s.outw
|
35
|
+
s.ldw :clobber
|
36
|
+
s.outw
|
37
|
+
s.ldbc 0xA5 - (1 << 8)
|
38
|
+
s.stb :clobber
|
39
|
+
s.ldw :clobber
|
40
|
+
s.outw
|
41
|
+
s.ldwc :clobber2
|
42
|
+
s.dupn :n => 1
|
43
|
+
s.dupn :n => 2
|
44
|
+
s.ldwc 0x9966 - (1 << 16)
|
45
|
+
s.stwv
|
46
|
+
s.ldbv
|
47
|
+
s.outw
|
48
|
+
s.ldbc 0x98 - (1 << 8)
|
49
|
+
s.stbv
|
50
|
+
s.ldwv
|
51
|
+
s.outw
|
52
|
+
s.ldwc 0x1122
|
53
|
+
s.ldwc 0x3344
|
54
|
+
s.ldwc 0x5566
|
55
|
+
s.flipn :n => 3
|
56
|
+
s.outw
|
57
|
+
s.outw
|
58
|
+
s.outw
|
59
|
+
|
60
|
+
# memory comparisons (22 instructions, 16 bytes out)
|
61
|
+
s.ldwc :const => 6
|
62
|
+
s.ldwc :cmp_med
|
63
|
+
s.ldwc :cmp_lo
|
64
|
+
s.mcmpvb
|
65
|
+
s.outw
|
66
|
+
s.mcmpfxb :size => 6, :op1 => :cmp_med, :op2 => :cmp_hi
|
67
|
+
s.outw
|
68
|
+
s.ldwc :const => 4
|
69
|
+
s.ldwc :cmp_lo
|
70
|
+
s.ldwc :cmp_med
|
71
|
+
s.mcmpvb
|
72
|
+
s.outw
|
73
|
+
s.mcfxb :size => 6, :from => :cmp_hi, :to => :copy_buf
|
74
|
+
s.pop
|
75
|
+
s.outfxb :size => 6, :from => :copy_buf
|
76
|
+
s.ldwc :const => 4
|
77
|
+
s.ldwc :cmp_hi
|
78
|
+
s.ldwc :copy_buf2
|
79
|
+
s.mcvb
|
80
|
+
s.pop
|
81
|
+
s.outfxb :size => 4, :from => :copy_buf2
|
82
|
+
|
83
|
+
# jumps (30 instructions, 6 bytes) from 6 * (5 instructions, 1 byte)
|
84
|
+
failed = 0xFA - (1 << 8)
|
85
|
+
[
|
86
|
+
[:ja, [1, 1, failed]],
|
87
|
+
[:jae, [1, 4, failed]],
|
88
|
+
[:jb, [1, failed, 7]],
|
89
|
+
[:jbe, [1, failed, 10]],
|
90
|
+
[:jz, [1, failed, 13]],
|
91
|
+
[:jne, [1, 16, failed]],
|
92
|
+
].each do |op_line|
|
93
|
+
op = op_line.shift
|
94
|
+
op_line.each_index do |i|
|
95
|
+
then_label = "#{op}_l#{i}_t".to_sym
|
96
|
+
out_label = "#{op}_l#{i}_o".to_sym
|
97
|
+
|
98
|
+
s.ldbc op_line[i][0]
|
99
|
+
s.send op, :to => then_label
|
100
|
+
s.ldbc op_line[i][2]
|
101
|
+
s.jmp :to => out_label
|
102
|
+
s.label then_label
|
103
|
+
s.ldbc op_line[i][1]
|
104
|
+
s.label out_label
|
105
|
+
s.outb
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# loop back
|
110
|
+
s.ldbc 1
|
111
|
+
s.sub
|
112
|
+
s.dupn :n => 1
|
113
|
+
s.ja :to => :main_loop
|
114
|
+
|
115
|
+
s.label :done
|
116
|
+
s.halt
|
117
|
+
|
118
|
+
s.label :cmp_lo
|
119
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2C, 0x12]
|
120
|
+
s.label :cmp_med
|
121
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2D, 0x11]
|
122
|
+
s.label :cmp_hi
|
123
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
|
124
|
+
s.label :cmp_hi2
|
125
|
+
s.immed :ubyte, [0xA3, 0x2C, 0x51, 0x63, 0x2E, 0x10]
|
126
|
+
s.label :copy_buf
|
127
|
+
s.filler :ubyte, 6
|
128
|
+
s.label :copy_buf2
|
129
|
+
s.filler :ubyte, 4
|
130
|
+
s.label :clobber
|
131
|
+
s.filler :ubyte, 2
|
132
|
+
s.label :clobber2
|
133
|
+
s.filler :ubyte, 2
|
134
|
+
s.label :stack
|
135
|
+
s.stack
|
136
|
+
s.extra 24
|
137
|
+
}
|
138
|
+
secpack.seal @tem.pubek, :done, :stack
|
139
|
+
print "SECpack has #{secpack.body.length} bytes, runs 1020 instructions and produces 470 bytes\n"
|
140
|
+
do_timing { @tem.execute secpack }
|
141
|
+
end
|
142
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tem_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-11 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: smartcard
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.2
|
23
|
+
version:
|
24
|
+
description: TEM (Trusted Execution Module) driver, written in and for ruby.
|
25
|
+
email: victor@costan.us
|
26
|
+
executables:
|
27
|
+
- tem_stat
|
28
|
+
- tem_ca
|
29
|
+
- tem_irb
|
30
|
+
- tem_bench
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
34
|
+
- bin/tem_stat
|
35
|
+
- bin/tem_ca
|
36
|
+
- bin/tem_irb
|
37
|
+
- bin/tem_bench
|
38
|
+
- LICENSE
|
39
|
+
- lib/scard/java_card.rb
|
40
|
+
- lib/scard/jcop_remote_terminal.rb
|
41
|
+
- lib/scard/pcsc_terminal.rb
|
42
|
+
- lib/tem_ruby.rb
|
43
|
+
- lib/tem/tag.rb
|
44
|
+
- lib/tem/keys.rb
|
45
|
+
- lib/tem/sec_opcodes.rb
|
46
|
+
- lib/tem/_cert.rb
|
47
|
+
- lib/tem/buffers.rb
|
48
|
+
- lib/tem/toolkit.rb
|
49
|
+
- lib/tem/tem.rb
|
50
|
+
- lib/tem/abi.rb
|
51
|
+
- lib/tem/crypto_abi.rb
|
52
|
+
- lib/tem/ca.rb
|
53
|
+
- lib/tem/secpack.rb
|
54
|
+
- lib/tem/sec_exec_error.rb
|
55
|
+
- lib/tem/sec_assembler.rb
|
56
|
+
- lib/tem/lifecycle.rb
|
57
|
+
- lib/tem/ecert.rb
|
58
|
+
- lib/tem/hive.rb
|
59
|
+
- lib/tem/seclosures.rb
|
60
|
+
- README
|
61
|
+
- CHANGELOG
|
62
|
+
files:
|
63
|
+
- bin/tem_stat
|
64
|
+
- bin/tem_ca
|
65
|
+
- bin/tem_irb
|
66
|
+
- bin/tem_bench
|
67
|
+
- Manifest
|
68
|
+
- LICENSE
|
69
|
+
- test/test_driver.rb
|
70
|
+
- test/test_tem.rb
|
71
|
+
- test/test_exceptions.rb
|
72
|
+
- test/_test_cert.rb
|
73
|
+
- timings/vm_perf.rb
|
74
|
+
- timings/devchip_decrypt.rb
|
75
|
+
- timings/simple_apdu.rb
|
76
|
+
- timings/post_buffer.rb
|
77
|
+
- timings/blank_bound_secpack.rb
|
78
|
+
- timings/vm_perf_bound.rb
|
79
|
+
- timings/timings.rb
|
80
|
+
- timings/blank_sec.rb
|
81
|
+
- lib/scard/java_card.rb
|
82
|
+
- lib/scard/jcop_remote_terminal.rb
|
83
|
+
- lib/scard/pcsc_terminal.rb
|
84
|
+
- lib/tem_ruby.rb
|
85
|
+
- lib/tem/tag.rb
|
86
|
+
- lib/tem/keys.rb
|
87
|
+
- lib/tem/sec_opcodes.rb
|
88
|
+
- lib/tem/_cert.rb
|
89
|
+
- lib/tem/buffers.rb
|
90
|
+
- lib/tem/toolkit.rb
|
91
|
+
- lib/tem/tem.rb
|
92
|
+
- lib/tem/abi.rb
|
93
|
+
- lib/tem/crypto_abi.rb
|
94
|
+
- lib/tem/ca.rb
|
95
|
+
- lib/tem/secpack.rb
|
96
|
+
- lib/tem/sec_exec_error.rb
|
97
|
+
- lib/tem/sec_assembler.rb
|
98
|
+
- lib/tem/lifecycle.rb
|
99
|
+
- lib/tem/ecert.rb
|
100
|
+
- lib/tem/hive.rb
|
101
|
+
- lib/tem/seclosures.rb
|
102
|
+
- README
|
103
|
+
- CHANGELOG
|
104
|
+
- dev_ca/ca_cert.cer
|
105
|
+
- dev_ca/ca_cert.pem
|
106
|
+
- dev_ca/ca_key.pem
|
107
|
+
- dev_ca/config.yml
|
108
|
+
- tem_ruby.gemspec
|
109
|
+
has_rdoc: true
|
110
|
+
homepage: http://tem.rubyforge.org
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options:
|
113
|
+
- --line-numbers
|
114
|
+
- --inline-source
|
115
|
+
- --title
|
116
|
+
- Tem_ruby
|
117
|
+
- --main
|
118
|
+
- README
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: "0"
|
126
|
+
version:
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
132
|
+
version:
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project: tem
|
136
|
+
rubygems_version: 1.1.1
|
137
|
+
signing_key:
|
138
|
+
specification_version: 2
|
139
|
+
summary: TEM (Trusted Execution Module) driver, written in and for ruby.
|
140
|
+
test_files:
|
141
|
+
- test/test_driver.rb
|
142
|
+
- test/test_tem.rb
|
143
|
+
- test/test_exceptions.rb
|