tem_ruby 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +1 -10
- data/Rakefile +1 -1
- data/bin/tem_proxy +4 -4
- data/lib/tem/apdus/buffers.rb +15 -8
- data/lib/tem/apdus/keys.rb +11 -5
- data/lib/tem/apdus/lifecycle.rb +10 -3
- data/lib/tem/apdus/tag.rb +10 -3
- data/lib/tem/auto_conf.rb +8 -5
- data/lib/tem/benchmarks/benchmarks.rb +7 -0
- data/lib/tem/benchmarks/blank_bound_secpack.rb +10 -0
- data/lib/tem/benchmarks/blank_sec.rb +14 -0
- data/lib/tem/benchmarks/devchip_decrypt.rb +12 -0
- data/lib/tem/benchmarks/post_buffer.rb +8 -0
- data/lib/tem/benchmarks/simple_apdu.rb +11 -0
- data/lib/tem/benchmarks/vm_perf.rb +11 -0
- data/lib/tem/benchmarks/vm_perf_bound.rb +12 -0
- data/lib/tem/builders/abi.rb +19 -13
- data/lib/tem/builders/assembler.rb +23 -16
- data/lib/tem/builders/crypto.rb +9 -3
- data/lib/tem/builders/isa.rb +10 -4
- data/lib/tem/definitions/abi.rb +9 -0
- data/lib/tem/definitions/assembler.rb +10 -0
- data/lib/tem/definitions/isa.rb +10 -0
- data/lib/tem/seclosures.rb +5 -5
- data/lib/tem/tem.rb +2 -1
- data/lib/tem_ruby.rb +0 -12
- data/tem_ruby.gemspec +9 -9
- data/test/builders/test_abi_builder.rb +4 -2
- data/test/tem_test_case.rb +3 -2
- data/test/tem_unit/test_tem_alu.rb +1 -1
- data/test/tem_unit/test_tem_bound_secpack.rb +1 -1
- data/test/tem_unit/test_tem_branching.rb +1 -1
- data/test/tem_unit/test_tem_crypto_asymmetric.rb +1 -1
- data/test/tem_unit/test_tem_crypto_hash.rb +1 -1
- data/test/tem_unit/test_tem_crypto_pstore.rb +1 -1
- data/test/tem_unit/test_tem_crypto_random.rb +1 -1
- data/test/tem_unit/test_tem_emit.rb +1 -1
- data/test/tem_unit/test_tem_memory.rb +1 -1
- data/test/tem_unit/test_tem_memory_compare.rb +1 -1
- data/test/tem_unit/test_tem_output.rb +1 -1
- data/test/tem_unit/test_tem_yaml_secpack.rb +4 -3
- data/test/test_auto_conf.rb +2 -0
- data/test/test_driver.rb +2 -1
- data/test/test_exceptions.rb +12 -6
- metadata +5 -24
- data/lib/tem/transport/auto_configurator.rb +0 -87
- data/lib/tem/transport/java_card_mixin.rb +0 -99
- data/lib/tem/transport/jcop_remote_protocol.rb +0 -59
- data/lib/tem/transport/jcop_remote_server.rb +0 -171
- data/lib/tem/transport/jcop_remote_transport.rb +0 -65
- data/lib/tem/transport/pcsc_transport.rb +0 -87
- data/lib/tem/transport/transport.rb +0 -10
- data/test/transport/test_auto_configurator.rb +0 -114
- data/test/transport/test_java_card_mixin.rb +0 -90
- data/test/transport/test_jcop_remote.rb +0 -82
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -40,13 +40,6 @@ lib/tem/seclosures.rb
|
|
40
40
|
lib/tem/secpack.rb
|
41
41
|
lib/tem/tem.rb
|
42
42
|
lib/tem/toolkit.rb
|
43
|
-
lib/tem/transport/auto_configurator.rb
|
44
|
-
lib/tem/transport/java_card_mixin.rb
|
45
|
-
lib/tem/transport/jcop_remote_protocol.rb
|
46
|
-
lib/tem/transport/jcop_remote_server.rb
|
47
|
-
lib/tem/transport/jcop_remote_transport.rb
|
48
|
-
lib/tem/transport/pcsc_transport.rb
|
49
|
-
lib/tem/transport/transport.rb
|
50
43
|
lib/tem_ruby.rb
|
51
44
|
LICENSE
|
52
45
|
Manifest
|
@@ -67,8 +60,6 @@ test/tem_unit/test_tem_memory.rb
|
|
67
60
|
test/tem_unit/test_tem_memory_compare.rb
|
68
61
|
test/tem_unit/test_tem_output.rb
|
69
62
|
test/tem_unit/test_tem_yaml_secpack.rb
|
63
|
+
test/test_auto_conf.rb
|
70
64
|
test/test_driver.rb
|
71
65
|
test/test_exceptions.rb
|
72
|
-
test/transport/test_auto_configurator.rb
|
73
|
-
test/transport/test_java_card_mixin.rb
|
74
|
-
test/transport/test_jcop_remote.rb
|
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ Echoe.new('tem_ruby') do |p|
|
|
10
10
|
p.email = 'victor@costan.us'
|
11
11
|
p.summary = 'TEM (Trusted Execution Module) driver, written in and for ruby.'
|
12
12
|
p.url = 'http://tem.rubyforge.org'
|
13
|
-
p.dependencies = ['smartcard >=0.
|
13
|
+
p.dependencies = ['smartcard >=0.4.0']
|
14
14
|
|
15
15
|
p.need_tar_gz = !Platform.windows?
|
16
16
|
p.need_zip = !Platform.windows?
|
data/bin/tem_proxy
CHANGED
@@ -10,7 +10,7 @@ require 'tem_ruby'
|
|
10
10
|
|
11
11
|
# JCOP remote serving logic implementing a proxy to another transport.
|
12
12
|
class ServingLogic
|
13
|
-
include
|
13
|
+
include Smartcard::Iso::JcopRemoteServingStubs
|
14
14
|
def initialize(serving_transport, logging = false)
|
15
15
|
@serving = serving_transport
|
16
16
|
@logger = Logger.new STDERR
|
@@ -47,15 +47,15 @@ def serve(options)
|
|
47
47
|
@logger = Logger.new STDERR
|
48
48
|
@logger.level = options[:logging] ? Logger::DEBUG : Logger::FATAL
|
49
49
|
|
50
|
-
serving_transport =
|
50
|
+
serving_transport = Smartcard::Iso.auto_transport
|
51
51
|
unless serving_transport
|
52
|
-
@logger.error "
|
52
|
+
@logger.error "ISO7816 smart-card transport auto-configuration failed"
|
53
53
|
return
|
54
54
|
end
|
55
55
|
@logger.info "Proxying to #{serving_transport.inspect}\n"
|
56
56
|
@logger.info "Serving with #{options.inspect}\n"
|
57
57
|
serving_logic = ServingLogic.new serving_transport, options[:logging]
|
58
|
-
|
58
|
+
Smartcard::Iso::JcopRemoteServer.new(options, serving_logic).run
|
59
59
|
end
|
60
60
|
|
61
61
|
# Parses the commmand-line arguments into an options hash suitable for #serve.
|
data/lib/tem/apdus/buffers.rb
CHANGED
@@ -1,23 +1,30 @@
|
|
1
|
+
# TEM buffer management using the APDU API.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
# :nodoc: namespace
|
2
8
|
module Tem::Apdus
|
3
9
|
|
10
|
+
|
4
11
|
module Buffers
|
5
12
|
def alloc_buffer(length)
|
6
|
-
response = @transport.
|
13
|
+
response = @transport.iso_apdu! :ins => 0x20,
|
7
14
|
:p12 => to_tem_short(length)
|
8
15
|
return read_tem_byte(response, 0)
|
9
16
|
end
|
10
17
|
|
11
18
|
def release_buffer(buffer_id)
|
12
|
-
@transport.
|
19
|
+
@transport.iso_apdu! :ins => 0x21, :p1 => buffer_id
|
13
20
|
end
|
14
21
|
|
15
22
|
def flush_buffers
|
16
|
-
@transport.
|
23
|
+
@transport.iso_apdu! :ins => 0x26
|
17
24
|
end
|
18
25
|
|
19
26
|
def get_buffer_length(buffer_id)
|
20
|
-
response = @transport.
|
27
|
+
response = @transport.iso_apdu! :ins => 0x22, :p1 => buffer_id
|
21
28
|
return read_tem_short(response, 0)
|
22
29
|
end
|
23
30
|
|
@@ -27,7 +34,7 @@ module Buffers
|
|
27
34
|
buffer = []
|
28
35
|
chunk_id = 0
|
29
36
|
while true do
|
30
|
-
response = @transport.
|
37
|
+
response = @transport.iso_apdu! :ins => 0x23, :p1 => buffer_id,
|
31
38
|
:p2 => chunk_id
|
32
39
|
buffer += response
|
33
40
|
break if response.length != @buffer_chunk_size
|
@@ -42,7 +49,7 @@ module Buffers
|
|
42
49
|
chunk_id, offset = 0, 0
|
43
50
|
while offset < data.length do
|
44
51
|
write_size = [data.length - offset, @buffer_chunk_size].min
|
45
|
-
@transport.
|
52
|
+
@transport.iso_apdu! :ins => 0x24, :p1 => buffer_id, :p2 => chunk_id,
|
46
53
|
:data => data[offset, write_size]
|
47
54
|
chunk_id += 1
|
48
55
|
offset += write_size
|
@@ -54,12 +61,12 @@ module Buffers
|
|
54
61
|
end
|
55
62
|
|
56
63
|
def guess_buffer_chunk_size!
|
57
|
-
response = @transport.
|
64
|
+
response = @transport.iso_apdu! :ins => 0x25
|
58
65
|
return read_tem_short(response, 0)
|
59
66
|
end
|
60
67
|
|
61
68
|
def stat_buffers
|
62
|
-
response = @transport.
|
69
|
+
response = @transport.iso_apdu! :ins => 0x27
|
63
70
|
|
64
71
|
memory_types = [:persistent, :clear_on_reset, :clear_on_deselect]
|
65
72
|
stat = {:free => {}, :buffers => []}
|
data/lib/tem/apdus/keys.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
|
+
# TEM cryptographic key manipulation using the APDU API.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
# :nodoc: namespace
|
2
8
|
module Tem::Apdus
|
3
9
|
|
4
10
|
module Keys
|
5
11
|
def devchip_generate_key_pair
|
6
|
-
response = @transport.
|
12
|
+
response = @transport.iso_apdu! :ins => 0x40
|
7
13
|
return { :privkey_id => read_tem_byte(response, 0),
|
8
14
|
:pubkey_id => read_tem_byte(response, 1) }
|
9
15
|
end
|
10
16
|
|
11
17
|
def devchip_release_key(key_id)
|
12
|
-
@transport.
|
18
|
+
@transport.iso_apdu! :ins => 0x41, :p1 => key_id
|
13
19
|
return true
|
14
20
|
end
|
15
21
|
|
16
22
|
def devchip_save_key(key_id)
|
17
|
-
response = @transport.
|
23
|
+
response = @transport.iso_apdu! :ins => 0x43, :p1 => key_id
|
18
24
|
buffer_id = read_tem_byte response, 0
|
19
25
|
buffer_length = read_tem_short response, 1
|
20
26
|
key_buffer = read_buffer buffer_id
|
@@ -26,7 +32,7 @@ module Keys
|
|
26
32
|
def devchip_encrypt_decrypt(data, key_id, opcode)
|
27
33
|
buffer_id = post_buffer data
|
28
34
|
begin
|
29
|
-
response = @transport.
|
35
|
+
response = @transport.iso_apdu! :ins => opcode, :p1 => key_id,
|
30
36
|
:p2 => buffer_id
|
31
37
|
ensure
|
32
38
|
release_buffer buffer_id
|
@@ -47,7 +53,7 @@ module Keys
|
|
47
53
|
end
|
48
54
|
|
49
55
|
def stat_keys
|
50
|
-
response = @transport.
|
56
|
+
response = @transport.iso_apdu! :ins => 0x27, :p1 => 0x01
|
51
57
|
key_types = { 0x99 => :symmetric, 0x55 => :private, 0xAA => :public }
|
52
58
|
stat = {:keys => {}}
|
53
59
|
offset = 0
|
data/lib/tem/apdus/lifecycle.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
+
# TEM life-cycle management using the APDU API.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
# :nodoc: namespace
|
2
8
|
module Tem::Apdus
|
3
|
-
|
9
|
+
|
10
|
+
|
4
11
|
module Lifecycle
|
5
12
|
def activate
|
6
|
-
@transport.
|
13
|
+
@transport.iso_apdu(:ins => 0x10)[:status] == 0x9000
|
7
14
|
end
|
8
15
|
def kill
|
9
|
-
@transport.
|
16
|
+
@transport.iso_apdu(:ins => 0x11)[:status] == 0x9000
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
data/lib/tem/apdus/tag.rb
CHANGED
@@ -1,25 +1,32 @@
|
|
1
|
+
# TEM tag management using the APDU API.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
# :nodoc: namespace
|
2
8
|
module Tem::Apdus
|
3
9
|
|
10
|
+
|
4
11
|
module Tag
|
5
12
|
def set_tag(tag_data)
|
6
13
|
buffer_id = post_buffer tag_data
|
7
14
|
begin
|
8
|
-
@transport.
|
15
|
+
@transport.iso_apdu! :ins => 0x30, :p1 => buffer_id
|
9
16
|
ensure
|
10
17
|
release_buffer buffer_id
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
14
21
|
def get_tag_length
|
15
|
-
response = @transport.
|
22
|
+
response = @transport.iso_apdu! :ins => 0x31
|
16
23
|
return read_tem_short(response, 0)
|
17
24
|
end
|
18
25
|
|
19
26
|
def get_tag_data(offset, length)
|
20
27
|
buffer_id = alloc_buffer length
|
21
28
|
begin
|
22
|
-
@transport.
|
29
|
+
@transport.iso_apdu! :ins => 0x32, :p1 => buffer_id,
|
23
30
|
:data => [to_tem_short(offset),
|
24
31
|
to_tem_short(length)].flatten
|
25
32
|
tag_data = read_buffer buffer_id
|
data/lib/tem/auto_conf.rb
CHANGED
@@ -7,10 +7,13 @@ module Tem
|
|
7
7
|
#
|
8
8
|
# It is safe to call auto_conf multiple times. A single session will be open.
|
9
9
|
def self.auto_conf
|
10
|
-
return
|
11
|
-
|
12
|
-
|
10
|
+
return @tem if defined?(@tem) and @tem
|
11
|
+
|
12
|
+
@tem = auto_tem
|
13
|
+
$tem = @tem
|
14
|
+
class << @tem
|
13
15
|
def disconnect
|
16
|
+
Tem.instance_variable_set :@tem, nil
|
14
17
|
$tem = nil
|
15
18
|
super
|
16
19
|
end
|
@@ -24,8 +27,8 @@ module Tem
|
|
24
27
|
# In case of success, returns a Tem::Session that can be used to talk to some
|
25
28
|
# TEM. An exception will be raised if the session creation fails.
|
26
29
|
def self.auto_tem
|
27
|
-
transport =
|
28
|
-
raise 'No suitable
|
30
|
+
transport = Smartcard::Iso.auto_transport
|
31
|
+
raise 'No suitable ISO7816 smart-card was found' unless transport
|
29
32
|
Tem::Session.new transport
|
30
33
|
end
|
31
34
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
+
# Master file for running the TEM benchmarks.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
require 'tem_ruby'
|
2
8
|
|
3
9
|
require 'tem/benchmarks/blank_bound_secpack.rb'
|
@@ -8,6 +14,7 @@ require 'tem/benchmarks/simple_apdu.rb'
|
|
8
14
|
require 'tem/benchmarks/vm_perf.rb'
|
9
15
|
require 'tem/benchmarks/vm_perf_bound.rb'
|
10
16
|
|
17
|
+
|
11
18
|
class Tem::Benchmarks
|
12
19
|
def setup
|
13
20
|
@tem = Tem.auto_tem
|
@@ -1,3 +1,13 @@
|
|
1
|
+
# Benchmarks decrypting a bound SECpack.
|
2
|
+
#
|
3
|
+
# This is a lower bound on the time it takes to execute any bound SECpack.
|
4
|
+
#
|
5
|
+
# Author:: Victor Costan
|
6
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
7
|
+
# License:: MIT
|
8
|
+
|
9
|
+
|
10
|
+
# :nodoc:
|
1
11
|
class Tem::Benchmarks
|
2
12
|
def time_blank_bound_secpack
|
3
13
|
secpack = @tem.assemble { |s|
|
@@ -1,3 +1,17 @@
|
|
1
|
+
# Benchmarks SECpack loading.
|
2
|
+
#
|
3
|
+
# Any SECpack execution will take the overhead of loading the SECpack. Loading a
|
4
|
+
# SECpack requires placing the SECpack's contents into a buffer. The difference
|
5
|
+
# between the time it takes to post a buffer and the time it takes to load a
|
6
|
+
# SECpack is overhead in the TEM firmware. This overhead should be kept to a
|
7
|
+
# minimum.
|
8
|
+
#
|
9
|
+
# Author:: Victor Costan
|
10
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
11
|
+
# License:: MIT
|
12
|
+
|
13
|
+
|
14
|
+
# :nodoc:
|
1
15
|
class Tem::Benchmarks
|
2
16
|
def time_blank_sec
|
3
17
|
secpack = @tem.assemble { |s|
|
@@ -1,3 +1,15 @@
|
|
1
|
+
# Benchmarks the TEM hardware's decryption facility.
|
2
|
+
#
|
3
|
+
# This is the chip's native decryption speed. The difference between this time
|
4
|
+
# and the time it takes to decrypt a bound SECpack is overhead added by the TEM
|
5
|
+
# firmware. That overhead should be kept to a minimum.
|
6
|
+
#
|
7
|
+
# Author:: Victor Costan
|
8
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
9
|
+
# License:: MIT
|
10
|
+
|
11
|
+
|
12
|
+
# :nodoc:
|
1
13
|
class Tem::Benchmarks
|
2
14
|
def time_devchip_decrypt
|
3
15
|
pubek = @tem.pubek
|
@@ -1,3 +1,11 @@
|
|
1
|
+
# Benchmarks the TEM's buffer management code.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
|
8
|
+
# :nodoc:
|
1
9
|
class Tem::Benchmarks
|
2
10
|
def time_post_buffer
|
3
11
|
data = (0...490).map { |i| (39 * i * i + 91 * i + 17) % 256 }
|
@@ -1,3 +1,14 @@
|
|
1
|
+
# Benchmarks the TEM hardware's overhead for an APDU round-trip.
|
2
|
+
#
|
3
|
+
# This overhead applies to any TEM operation, because each operation involves
|
4
|
+
# one or more APDU exchanges.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
8
|
+
# License:: MIT
|
9
|
+
|
10
|
+
|
11
|
+
# :nodoc:
|
1
12
|
class Tem::Benchmarks
|
2
13
|
def time_simple_apdu
|
3
14
|
do_timing { @tem.get_tag_length }
|
@@ -1,3 +1,14 @@
|
|
1
|
+
# Benchmarks the TEM virtual machine's execution speed.
|
2
|
+
#
|
3
|
+
# The difference between this time and the time it takes to execute a blank
|
4
|
+
# SECpack is pure VM execution time.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
8
|
+
# License:: MIT
|
9
|
+
|
10
|
+
|
11
|
+
# :nodoc:
|
1
12
|
class Tem::Benchmarks
|
2
13
|
def time_vm_perf
|
3
14
|
secpack = @tem.assemble { |s|
|
@@ -1,3 +1,15 @@
|
|
1
|
+
# Benchmarks the TEM virtual machine's execution speed on bound SECpacks.
|
2
|
+
#
|
3
|
+
# The difference between this time and the time it takes to execute a blank
|
4
|
+
# bound SECpack is pure VM execution time. This execution time should not be
|
5
|
+
# significantly different from the execution time for unbound SECpacks.
|
6
|
+
#
|
7
|
+
# Author:: Victor Costan
|
8
|
+
# Copyright:: Copyright (C) 2008 Massachusetts Institute of Technology
|
9
|
+
# License:: MIT
|
10
|
+
|
11
|
+
|
12
|
+
# :nodoc:
|
1
13
|
class Tem::Benchmarks
|
2
14
|
def time_vm_perf_bound
|
3
15
|
secpack = @tem.assemble { |s|
|
data/lib/tem/builders/abi.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
|
1
|
+
# ABI (Abstract Binary Interface) builder.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
2
6
|
|
7
|
+
require 'openssl'
|
3
8
|
|
4
9
|
# :nodoc: namespace
|
5
10
|
module Tem::Builders
|
6
11
|
|
12
|
+
|
7
13
|
# Builder class for the ABI (Abstract Binary Interface) builder.
|
8
14
|
class Abi
|
9
15
|
# Creates a builder targeting a module / class.
|
@@ -44,8 +50,8 @@ class Abi
|
|
44
50
|
define_method(:"#{name}_length") { bytes }
|
45
51
|
end
|
46
52
|
|
47
|
-
@target.class_eval
|
48
|
-
(class << @target; self; end).module_eval
|
53
|
+
@target.class_eval(&defines)
|
54
|
+
(class << @target; self; end).module_eval(&defines)
|
49
55
|
end
|
50
56
|
|
51
57
|
# Defines the methods for handling a variable-length number type in an ABI.
|
@@ -86,8 +92,8 @@ class Abi
|
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
|
-
@target.class_eval
|
90
|
-
(class << @target; self; end).module_eval
|
95
|
+
@target.class_eval(&defines)
|
96
|
+
(class << @target; self; end).module_eval(&defines)
|
91
97
|
end
|
92
98
|
|
93
99
|
# Defines the methods for handling a group of packed variable-length numbers
|
@@ -160,8 +166,8 @@ class Abi
|
|
160
166
|
define_method(:"#{name}_components") { sub_names }
|
161
167
|
end
|
162
168
|
|
163
|
-
@target.class_eval
|
164
|
-
(class << @target; self; end).module_eval
|
169
|
+
@target.class_eval(&defines)
|
170
|
+
(class << @target; self; end).module_eval(&defines)
|
165
171
|
end
|
166
172
|
|
167
173
|
# Defines the methods for handling a fixed-length string type in an ABI.
|
@@ -190,8 +196,8 @@ class Abi
|
|
190
196
|
define_method(:"#{name}_length") { bytes }
|
191
197
|
end
|
192
198
|
|
193
|
-
@target.class_eval
|
194
|
-
(class << @target; self; end).module_eval
|
199
|
+
@target.class_eval(&defines)
|
200
|
+
(class << @target; self; end).module_eval(&defines)
|
195
201
|
end
|
196
202
|
|
197
203
|
# Defines methods for handling a complex ABI structure wrapped into an object.
|
@@ -299,9 +305,9 @@ class Abi
|
|
299
305
|
define_method(:"#{name}_tohook", &hooks[:to]) if hooks[:to]
|
300
306
|
end
|
301
307
|
|
302
|
-
@target.class_eval
|
308
|
+
@target.class_eval(&defines)
|
303
309
|
@target.class_eval define_str
|
304
|
-
(class << @target; self; end).module_eval
|
310
|
+
(class << @target; self; end).module_eval(&defines)
|
305
311
|
(class << @target; self; end).module_eval define_str
|
306
312
|
end
|
307
313
|
|
@@ -351,8 +357,8 @@ class Abi
|
|
351
357
|
define_method(:"#{name}_length") { bytes }
|
352
358
|
end
|
353
359
|
|
354
|
-
@target.class_eval
|
355
|
-
(class << @target; self; end).module_eval
|
360
|
+
@target.class_eval(&defines)
|
361
|
+
(class << @target; self; end).module_eval(&defines)
|
356
362
|
end
|
357
363
|
|
358
364
|
# The module / class impacted by the builder.
|
@@ -1,6 +1,13 @@
|
|
1
|
+
# Assembler (as in opcode assembler) builder.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
6
|
+
|
1
7
|
# :nodoc: namespace
|
2
8
|
module Tem::Builders
|
3
9
|
|
10
|
+
|
4
11
|
# Builder class for the code assembler builder.
|
5
12
|
class Assembler
|
6
13
|
# Creates a builder targeting a module / class.
|
@@ -56,8 +63,8 @@ class Assembler
|
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
59
|
-
@proxy_class.class_eval
|
60
|
-
(class << @proxy_class; self; end).module_eval
|
66
|
+
@proxy_class.class_eval(&proxy_defines)
|
67
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
61
68
|
end
|
62
69
|
|
63
70
|
# Defines the methods for implementing a labeling directive.
|
@@ -73,8 +80,8 @@ class Assembler
|
|
73
80
|
@assembler.emit_label label_name.to_sym
|
74
81
|
end
|
75
82
|
end
|
76
|
-
@proxy_class.class_eval
|
77
|
-
(class << @proxy_class; self; end).module_eval
|
83
|
+
@proxy_class.class_eval(&proxy_defines)
|
84
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
78
85
|
end
|
79
86
|
|
80
87
|
# Defines the methods for implementing a special label directive.
|
@@ -90,8 +97,8 @@ class Assembler
|
|
90
97
|
@assembler.emit_label label_name.to_sym
|
91
98
|
end
|
92
99
|
end
|
93
|
-
@proxy_class.class_eval
|
94
|
-
(class << @proxy_class; self; end).module_eval
|
100
|
+
@proxy_class.class_eval(&proxy_defines)
|
101
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
95
102
|
end
|
96
103
|
|
97
104
|
# Defines the methods for implementing a zero-inserting directive.
|
@@ -115,8 +122,8 @@ class Assembler
|
|
115
122
|
@assembler.emit_bytes name, :emit => Array.new(bytes, 0)
|
116
123
|
end
|
117
124
|
end
|
118
|
-
@proxy_class.class_eval
|
119
|
-
(class << @proxy_class; self; end).module_eval
|
125
|
+
@proxy_class.class_eval(&proxy_defines)
|
126
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
120
127
|
end
|
121
128
|
|
122
129
|
# Defines the methods for implementing a data-emitting directive.
|
@@ -137,8 +144,8 @@ class Assembler
|
|
137
144
|
@assembler.emit_bytes :immed, :emit => data
|
138
145
|
end
|
139
146
|
end
|
140
|
-
@proxy_class.class_eval
|
141
|
-
(class << @proxy_class; self; end).module_eval
|
147
|
+
@proxy_class.class_eval(&proxy_defines)
|
148
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
142
149
|
end
|
143
150
|
|
144
151
|
# (private) Defines the builder class used during assembly.
|
@@ -194,8 +201,8 @@ class Assembler
|
|
194
201
|
end
|
195
202
|
end
|
196
203
|
end
|
197
|
-
@proxy_class.class_eval
|
198
|
-
(class << @proxy_class; self; end).module_eval
|
204
|
+
@proxy_class.class_eval(&proxy_defines)
|
205
|
+
(class << @proxy_class; self; end).module_eval(&proxy_defines)
|
199
206
|
end
|
200
207
|
private :define_proxy_class
|
201
208
|
|
@@ -226,8 +233,8 @@ class Assembler
|
|
226
233
|
end
|
227
234
|
private :_assemble
|
228
235
|
end
|
229
|
-
@target.class_eval
|
230
|
-
(class << @target; self; end).module_eval
|
236
|
+
@target.class_eval(&defines)
|
237
|
+
(class << @target; self; end).module_eval(&defines)
|
231
238
|
end
|
232
239
|
|
233
240
|
# The module / class impacted by the builder.
|
@@ -306,8 +313,8 @@ module Assembler::CodeBuilderBase
|
|
306
313
|
end
|
307
314
|
|
308
315
|
# Wrap all the built data into a nice package and return it.
|
309
|
-
{ :bytes => @bytes, :link_directives => @
|
310
|
-
:line_info => @line_info }
|
316
|
+
{ :bytes => @bytes, :link_directives => @link_directives,
|
317
|
+
:labels => @labels, :line_info => @line_info }
|
311
318
|
end
|
312
319
|
end
|
313
320
|
|
data/lib/tem/builders/crypto.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
|
1
|
+
# Cryptography ABI builder.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
2
6
|
|
7
|
+
require 'openssl'
|
3
8
|
|
4
9
|
# :nodoc: namespace
|
5
10
|
module Tem::Builders
|
6
11
|
|
12
|
+
|
7
13
|
# Builder class and namespace for the cryptography builder.
|
8
14
|
class Crypto < Abi
|
9
15
|
# Creates a builder targeting a module / class.
|
@@ -100,8 +106,8 @@ class Crypto < Abi
|
|
100
106
|
define_method(:"#{name}_length") { digest_length }
|
101
107
|
end
|
102
108
|
|
103
|
-
@target.class_eval
|
104
|
-
(class << @target; self; end).module_eval
|
109
|
+
@target.class_eval(&defines)
|
110
|
+
(class << @target; self; end).module_eval(&defines)
|
105
111
|
end
|
106
112
|
end # class Crypto
|
107
113
|
|
data/lib/tem/builders/isa.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
|
1
|
+
# ISA (Instruction Set Architeture) builder.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Massachusetts Institute of Technology
|
5
|
+
# License:: MIT
|
2
6
|
|
7
|
+
require 'openssl'
|
3
8
|
|
4
9
|
# :nodoc: namespace
|
5
10
|
module Tem::Builders
|
6
11
|
|
12
|
+
|
7
13
|
# Builder class for the ISA (Instruction Set Architecture) builder.
|
8
14
|
class Isa
|
9
15
|
# Creates a builder targeting a module / class.
|
@@ -82,7 +88,7 @@ class Isa
|
|
82
88
|
emit = encoded_opcode
|
83
89
|
link_directives = []
|
84
90
|
fargs.each_with_index do |arg, i|
|
85
|
-
if
|
91
|
+
if arg.kind_of?(Numeric) && !iargs[i][:reladdr]
|
86
92
|
emit += abi.send arg_encode_msgs[i], arg
|
87
93
|
else
|
88
94
|
link_directive = { :type => iargs[i][:type], :offset => emit.length,
|
@@ -100,8 +106,8 @@ class Isa
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
|
-
@target.class_eval
|
104
|
-
(class << @target; self; end).module_eval
|
109
|
+
@target.class_eval(&defines)
|
110
|
+
(class << @target; self; end).module_eval(&defines)
|
105
111
|
end
|
106
112
|
|
107
113
|
# The module / class impacted by the builder.
|
data/lib/tem/definitions/abi.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# The TEM's ABI (Abstract Binary Interface) definition.
|
2
|
+
#
|
3
|
+
# This code is the official specification, because Victor likes executable
|
4
|
+
# specifications.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2007 Massachusetts Institute of Technology
|
8
|
+
# License:: MIT
|
9
|
+
|
1
10
|
require 'openssl'
|
2
11
|
require 'digest/sha1'
|
3
12
|
|