ruby-aes-table1 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -1
- data/Rakefile +3 -3
- data/doc/rdoc/classes/Aes.html +112 -106
- data/doc/rdoc/classes/AesShared.html +265 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGELOG.html +12 -2
- data/doc/rdoc/files/COPYING.html +2 -2
- data/doc/rdoc/files/README.html +3 -3
- data/doc/rdoc/files/lib/ruby-aes/{aes_cons_rb.html → aes_shared_rb.html} +4 -4
- data/doc/rdoc/files/lib/ruby-aes_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +1 -2
- data/doc/rdoc/fr_file_index.html +1 -2
- data/doc/rdoc/fr_method_index.html +17 -26
- data/examples/encrypt_block.rb +1 -0
- data/examples/encrypt_buffer.rb +1 -0
- data/examples/encrypt_stream.rb +1 -0
- data/lib/ruby-aes.rb +12 -6
- data/lib/ruby-aes/aes_alg.rb +2 -58
- data/lib/ruby-aes/aes_shared.rb +77 -0
- data/test/test_helper.rb +4 -2
- data/test/test_ruby-aes.rb +25 -12
- metadata +14 -15
- data/doc/rdoc/classes/AesAlg.html +0 -731
- data/doc/rdoc/classes/AesCons.html +0 -168
- data/doc/rdoc/files/lib/ruby-aes/aes_alg_rb.html +0 -108
data/examples/encrypt_block.rb
CHANGED
data/examples/encrypt_buffer.rb
CHANGED
data/examples/encrypt_stream.rb
CHANGED
data/lib/ruby-aes.rb
CHANGED
@@ -47,7 +47,7 @@ module Aes
|
|
47
47
|
|
48
48
|
def Aes.check_key(key_string, kl = 128)
|
49
49
|
kl = Aes.check_kl(kl)
|
50
|
-
k = key_string.length
|
50
|
+
k = key_string ? key_string.length : 0
|
51
51
|
raise "Bad key string or bad key length" if (k != kl/8) && (k != kl/4)
|
52
52
|
hex = (key_string =~ /[a-f0-9A-F]{#{k}}/) == 0 && (k == kl/4)
|
53
53
|
bin = ! hex
|
@@ -131,8 +131,11 @@ module Aes
|
|
131
131
|
sout << @@aes.encrypt_buffer(sin)
|
132
132
|
when IO
|
133
133
|
while buf = sin.read(@@bs)
|
134
|
-
|
135
|
-
|
134
|
+
if buf.length == @@bs
|
135
|
+
sout << @@aes.encrypt_blocks(buf)
|
136
|
+
else
|
137
|
+
sout << @@aes.encrypt_buffer(buf)
|
138
|
+
end
|
136
139
|
end
|
137
140
|
else
|
138
141
|
raise "Bad input stream (String, IO)"
|
@@ -150,9 +153,12 @@ module Aes
|
|
150
153
|
when String
|
151
154
|
sout << @@aes.decrypt_buffer(sin)
|
152
155
|
when IO
|
153
|
-
while buf = sin.read(@@bs)
|
154
|
-
|
155
|
-
|
156
|
+
while buf = sin.read(@@bs)#+1)
|
157
|
+
if buf.length == @@bs
|
158
|
+
sout << @@aes.decrypt_blocks(buf)
|
159
|
+
else
|
160
|
+
sout << @@aes.decrypt_buffer(buf)
|
161
|
+
end
|
156
162
|
end
|
157
163
|
else
|
158
164
|
raise "Bad input stream (String, IO)"
|
data/lib/ruby-aes/aes_alg.rb
CHANGED
@@ -10,9 +10,11 @@
|
|
10
10
|
=end
|
11
11
|
|
12
12
|
require 'ruby-aes/aes_cons'
|
13
|
+
require 'ruby-aes/aes_shared'
|
13
14
|
|
14
15
|
class AesAlg
|
15
16
|
include AesCons
|
17
|
+
include AesShared
|
16
18
|
|
17
19
|
def encryption_key_schedule(key)
|
18
20
|
i = 0
|
@@ -265,64 +267,6 @@ class AesAlg
|
|
265
267
|
end
|
266
268
|
end
|
267
269
|
|
268
|
-
def encrypt_blocks(buffer)
|
269
|
-
raise "Bad block length" unless (buffer.length % 16).zero?
|
270
|
-
ct = ""
|
271
|
-
block = ""
|
272
|
-
buffer.each_byte do |char|
|
273
|
-
block << char
|
274
|
-
if block.length == 16
|
275
|
-
ct << encrypt_block(block)
|
276
|
-
block = ""
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
def decrypt_blocks(buffer)
|
282
|
-
raise "Bad block length" unless (buffer.length % 16).zero?
|
283
|
-
pt = ""
|
284
|
-
block = ""
|
285
|
-
buffer.each_byte do |char|
|
286
|
-
block << char
|
287
|
-
if block.length == 16
|
288
|
-
pt << decrypt_block(block)
|
289
|
-
block = ""
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
def encrypt_buffer(buffer)
|
295
|
-
ct = ""
|
296
|
-
block = ""
|
297
|
-
buffer.each_byte do |char|
|
298
|
-
block << char
|
299
|
-
if block.length == 16
|
300
|
-
ct << encrypt_block(block)
|
301
|
-
block = ""
|
302
|
-
end
|
303
|
-
end
|
304
|
-
m = 16 - block.length % 16
|
305
|
-
ct << (m == 16 ? 0 : encrypt_block(block << m.chr * m))
|
306
|
-
end
|
307
|
-
|
308
|
-
def decrypt_buffer(buffer)
|
309
|
-
pt = ""
|
310
|
-
block = ""
|
311
|
-
buffer.each_byte do |char|
|
312
|
-
block << char
|
313
|
-
if block.length == 16
|
314
|
-
pt << decrypt_block(block)
|
315
|
-
block = ""
|
316
|
-
end
|
317
|
-
end
|
318
|
-
if block.length == 0
|
319
|
-
c = pt[-1]
|
320
|
-
c.chr * c == pt[-c..-1] ? pt[0..-(c+1)] : (raise "Bad Block Padding")
|
321
|
-
else
|
322
|
-
pt
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
270
|
def init(key_length, mode, key, iv = nil)
|
327
271
|
@nb = 4
|
328
272
|
@ek = []
|
@@ -0,0 +1,77 @@
|
|
1
|
+
=begin
|
2
|
+
This file is a part of ruby-aes <http://rubyforge.org/projects/ruby-aes>
|
3
|
+
Written by Alex Boussinet <alex.boussinet@gmail.com>
|
4
|
+
|
5
|
+
It contains the code shared by all the implementations
|
6
|
+
=end
|
7
|
+
|
8
|
+
module AesShared
|
9
|
+
def encrypt_blocks(buffer)
|
10
|
+
raise "Bad block length" unless (buffer.length % 16).zero?
|
11
|
+
ct = ""
|
12
|
+
block = ""
|
13
|
+
buffer.each_byte do |char|
|
14
|
+
block << char
|
15
|
+
if block.length == 16
|
16
|
+
ct << encrypt_block(block)
|
17
|
+
block = ""
|
18
|
+
end
|
19
|
+
end
|
20
|
+
ct
|
21
|
+
end
|
22
|
+
|
23
|
+
def decrypt_blocks(buffer)
|
24
|
+
raise "Bad block length" unless (buffer.length % 16).zero?
|
25
|
+
pt = ""
|
26
|
+
block = ""
|
27
|
+
buffer.each_byte do |char|
|
28
|
+
block << char
|
29
|
+
if block.length == 16
|
30
|
+
pt << decrypt_block(block)
|
31
|
+
block = ""
|
32
|
+
end
|
33
|
+
end
|
34
|
+
pt
|
35
|
+
end
|
36
|
+
|
37
|
+
def encrypt_buffer(buffer)
|
38
|
+
ct = ""
|
39
|
+
block = ""
|
40
|
+
buffer.each_byte do |char|
|
41
|
+
block << char
|
42
|
+
if block.length == 16
|
43
|
+
ct << encrypt_block(block)
|
44
|
+
block = ""
|
45
|
+
end
|
46
|
+
end
|
47
|
+
c = "\000"
|
48
|
+
if (m = 16 - block.length % 16) != 16
|
49
|
+
c = m.chr
|
50
|
+
ct << encrypt_block(block << c * m)
|
51
|
+
end
|
52
|
+
ct << c
|
53
|
+
end
|
54
|
+
|
55
|
+
def decrypt_buffer(buffer)
|
56
|
+
pt = ""
|
57
|
+
block = ""
|
58
|
+
buffer.each_byte do |char|
|
59
|
+
block << char
|
60
|
+
if block.length == 16
|
61
|
+
pt << decrypt_block(block)
|
62
|
+
block = ""
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if block.length != 1
|
66
|
+
raise 'Bad Block Padding'
|
67
|
+
elsif (c = block[-1]).zero?
|
68
|
+
pt
|
69
|
+
else
|
70
|
+
if block * c == pt[-c..-1]
|
71
|
+
pt[0..-c-1]
|
72
|
+
else
|
73
|
+
raise "Bad Block Padding"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -3,8 +3,10 @@ require File.dirname(__FILE__) + '/../lib/ruby-aes'
|
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
unless defined? KEY_LENGTH
|
7
|
+
KEY_LENGTH = [128,192,256].freeze
|
8
|
+
MODES = ['ECB','CBC','OFB','CFB'].freeze
|
9
|
+
end
|
8
10
|
|
9
11
|
def random_fill(n, buffer)
|
10
12
|
n.times do
|
data/test/test_ruby-aes.rb
CHANGED
@@ -13,24 +13,28 @@ class TestRubyAES < Test::Unit::TestCase
|
|
13
13
|
random_fill(16, @iv)
|
14
14
|
@pt = ""
|
15
15
|
random_fill(64, @pt)
|
16
|
-
@kl = KEY_LENGTH[(rand * KEY_LENGTH).to_i]
|
16
|
+
@kl = KEY_LENGTH[(rand * KEY_LENGTH.length).to_i]
|
17
17
|
@mode = MODES[(rand * MODES.length).to_i]
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_modes_and_key_lengths
|
21
|
+
pt = @pt[0...16]
|
21
22
|
MODES.each do |mode|
|
22
23
|
KEY_LENGTH.each do |kl|
|
23
|
-
ct = Aes.encrypt_block(kl, mode, @keys[kl], @iv,
|
24
|
+
ct = Aes.encrypt_block(kl, mode, @keys[kl], @iv, pt)
|
24
25
|
npt = Aes.decrypt_block(kl, mode, @keys[kl], @iv, ct)
|
25
|
-
assert_equal(
|
26
|
+
assert_equal(pt, npt, "Error in encryption/decryption (#{kl}-#{mode})")
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
+
def test_encrypt_decrypt_stream
|
31
32
|
file = "_ruby-aes_test_encrypt_stream_"
|
32
33
|
sin = File.open(file, "w+b")
|
33
34
|
random_fill(4242, sin)
|
35
|
+
sin.close
|
36
|
+
|
37
|
+
sin = File.open(file, "rb")
|
34
38
|
sout = File.open("#{file}.aes", "w+b")
|
35
39
|
Aes.encrypt_stream(@kl, @mode, @keys[@kl], @iv, sin, sout)
|
36
40
|
sin.close
|
@@ -42,18 +46,27 @@ class TestRubyAES < Test::Unit::TestCase
|
|
42
46
|
sin.close
|
43
47
|
sout.close
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
pt, npt = IO.read(file), IO.read("#{file}.plain")
|
50
|
+
|
51
|
+
assert_equal pt, npt, "Error in encrypt_decrypt_stream"
|
52
|
+
ensure
|
47
53
|
FileUtils.rm_f [ file, "#{file}.aes", "#{file}.plain" ]
|
48
54
|
end
|
49
55
|
|
50
|
-
def
|
56
|
+
def test_encrypt_decrypt_buffer
|
57
|
+
MODES.each do |mode|
|
58
|
+
KEY_LENGTH.each do |kl|
|
59
|
+
ct = Aes.encrypt_buffer(kl, mode, @keys[kl], @iv, @pt)
|
60
|
+
npt = Aes.decrypt_buffer(kl, mode, @keys[kl], @iv, ct)
|
61
|
+
assert_equal(@pt, npt, "Error in encrypt_decrypt_buffer")
|
62
|
+
end
|
63
|
+
end
|
51
64
|
pt = ""
|
52
65
|
42.times do
|
53
66
|
pt << random_fill(1, pt)
|
54
67
|
ct = Aes.encrypt_buffer(@kl, @mode, @keys[@kl], @iv, pt)
|
55
68
|
npt = Aes.decrypt_buffer(@kl, @mode, @keys[@kl], @iv, ct)
|
56
|
-
assert_equal(pt, npt, "Error in
|
69
|
+
assert_equal(pt, npt, "Error in encrypt_decrypt_buffer")
|
57
70
|
end
|
58
71
|
end
|
59
72
|
|
@@ -79,19 +92,19 @@ class TestRubyAES < Test::Unit::TestCase
|
|
79
92
|
|
80
93
|
def test_check_key
|
81
94
|
assert_raise(RuntimeError) do
|
82
|
-
Aes.check_key(@
|
95
|
+
Aes.check_key(@keys[128], 64)
|
83
96
|
end # bad key length
|
84
97
|
assert_raise(RuntimeError) do
|
85
98
|
Aes.check_key('123', 128)
|
86
99
|
end # bad key string
|
87
100
|
assert_raise(RuntimeError) do
|
88
|
-
Aes.check_key(
|
101
|
+
Aes.check_key(nil, 256)
|
89
102
|
end # bad key string
|
90
103
|
assert_raise(RuntimeError) do
|
91
|
-
Aes.check_key(@
|
104
|
+
Aes.check_key(@keys[128].unpack('H*'), 128)
|
92
105
|
end # bad key string
|
93
106
|
assert_nothing_raised do
|
94
|
-
Aes.check_key(@
|
107
|
+
Aes.check_key(@keys[@kl], @kl)
|
95
108
|
end
|
96
109
|
end
|
97
110
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-aes-table1
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "1.
|
7
|
-
date:
|
6
|
+
version: "1.1"
|
7
|
+
date: 2008-01-05 00:00:00 +01:00
|
8
8
|
summary: ruby-aes is an implementation of the Rijndael algorithm (AES)
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,6 +35,13 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- doc/rdoc
|
37
37
|
- doc/rdoc/files
|
38
|
+
- doc/rdoc/files/lib
|
39
|
+
- doc/rdoc/files/lib/ruby-aes_rb.html
|
40
|
+
- doc/rdoc/files/lib/ruby-aes
|
41
|
+
- doc/rdoc/files/lib/ruby-aes/aes_shared_rb.html
|
42
|
+
- doc/rdoc/files/CHANGELOG.html
|
43
|
+
- doc/rdoc/files/README.html
|
44
|
+
- doc/rdoc/files/COPYING.html
|
38
45
|
- doc/rdoc/index.html
|
39
46
|
- doc/rdoc/rdoc-style.css
|
40
47
|
- doc/rdoc/fr_method_index.html
|
@@ -42,25 +49,15 @@ files:
|
|
42
49
|
- doc/rdoc/fr_file_index.html
|
43
50
|
- doc/rdoc/created.rid
|
44
51
|
- doc/rdoc/classes
|
45
|
-
- doc/rdoc/files/lib
|
46
|
-
- doc/rdoc/files/CHANGELOG.html
|
47
|
-
- doc/rdoc/files/README.html
|
48
|
-
- doc/rdoc/files/COPYING.html
|
49
|
-
- doc/rdoc/files/lib/ruby-aes_rb.html
|
50
|
-
- doc/rdoc/files/lib/ruby-aes
|
51
|
-
- doc/rdoc/files/lib/ruby-aes/aes_cons_rb.html
|
52
|
-
- doc/rdoc/files/lib/ruby-aes/aes_alg_rb.html
|
53
|
-
- doc/rdoc/classes/AesAlg.html
|
54
52
|
- doc/rdoc/classes/Aes.html
|
55
|
-
- doc/rdoc/classes/
|
53
|
+
- doc/rdoc/classes/AesShared.html
|
56
54
|
- examples/encrypt_block.rb
|
57
55
|
- examples/example_helper.rb
|
58
56
|
- examples/encrypt_stream.rb
|
59
57
|
- examples/encrypt_buffer.rb
|
60
58
|
- lib/ruby-aes
|
59
|
+
- lib/ruby-aes/aes_shared.rb
|
61
60
|
- lib/ruby-aes.rb
|
62
|
-
- lib/ruby-aes/aes_alg.rb
|
63
|
-
- lib/ruby-aes/aes_cons.rb
|
64
61
|
- test/test_ruby-aes.rb
|
65
62
|
- test/test_helper.rb
|
66
63
|
- test/KAT_MCT
|
@@ -69,6 +66,8 @@ files:
|
|
69
66
|
- test/KAT_MCT/table.192
|
70
67
|
- test/KAT_MCT/table.256
|
71
68
|
- test/KAT_MCT/aes_kat_mct.rb
|
69
|
+
- lib/ruby-aes/aes_alg.rb
|
70
|
+
- lib/ruby-aes/aes_cons.rb
|
72
71
|
test_files:
|
73
72
|
- test/test_ruby-aes.rb
|
74
73
|
- test/test_helper.rb
|
@@ -1,731 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Class: AesAlg</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">AesAlg</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../files/lib/ruby-aes/aes_alg_rb.html">
|
59
|
-
lib/ruby-aes/aes_alg.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
</td>
|
63
|
-
</tr>
|
64
|
-
|
65
|
-
<tr class="top-aligned-row">
|
66
|
-
<td><strong>Parent:</strong></td>
|
67
|
-
<td>
|
68
|
-
Object
|
69
|
-
</td>
|
70
|
-
</tr>
|
71
|
-
</table>
|
72
|
-
</div>
|
73
|
-
<!-- banner header -->
|
74
|
-
|
75
|
-
<div id="bodyContent">
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<div id="contextContent">
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
</div>
|
84
|
-
|
85
|
-
<div id="method-list">
|
86
|
-
<h3 class="section-bar">Methods</h3>
|
87
|
-
|
88
|
-
<div class="name-list">
|
89
|
-
<a href="#M000004">_decrypt_block</a>
|
90
|
-
<a href="#M000003">_encrypt_block</a>
|
91
|
-
<a href="#M000007">decrypt_block</a>
|
92
|
-
<a href="#M000009">decrypt_blocks</a>
|
93
|
-
<a href="#M000011">decrypt_buffer</a>
|
94
|
-
<a href="#M000002">decryption_key_schedule</a>
|
95
|
-
<a href="#M000006">encrypt_block</a>
|
96
|
-
<a href="#M000008">encrypt_blocks</a>
|
97
|
-
<a href="#M000010">encrypt_buffer</a>
|
98
|
-
<a href="#M000001">encryption_key_schedule</a>
|
99
|
-
<a href="#M000012">init</a>
|
100
|
-
<a href="#M000013">new</a>
|
101
|
-
<a href="#M000005">xor</a>
|
102
|
-
</div>
|
103
|
-
</div>
|
104
|
-
|
105
|
-
</div>
|
106
|
-
|
107
|
-
|
108
|
-
<!-- if includes -->
|
109
|
-
<div id="includes">
|
110
|
-
<h3 class="section-bar">Included Modules</h3>
|
111
|
-
|
112
|
-
<div id="includes-list">
|
113
|
-
<span class="include-name"><a href="AesCons.html">AesCons</a></span>
|
114
|
-
</div>
|
115
|
-
</div>
|
116
|
-
|
117
|
-
<div id="section">
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
<!-- if method_list -->
|
127
|
-
<div id="methods">
|
128
|
-
<h3 class="section-bar">Public Class methods</h3>
|
129
|
-
|
130
|
-
<div id="method-M000013" class="method-detail">
|
131
|
-
<a name="M000013"></a>
|
132
|
-
|
133
|
-
<div class="method-heading">
|
134
|
-
<a href="#M000013" class="method-signature">
|
135
|
-
<span class="method-name">new</span><span class="method-args">(key_length, mode, key, iv = nil)</span>
|
136
|
-
</a>
|
137
|
-
</div>
|
138
|
-
|
139
|
-
<div class="method-description">
|
140
|
-
<p><a class="source-toggle" href="#"
|
141
|
-
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
142
|
-
<div class="method-source-code" id="M000013-source">
|
143
|
-
<pre>
|
144
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 356</span>
|
145
|
-
356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span> = <span class="ruby-keyword kw">nil</span>)
|
146
|
-
357: <span class="ruby-identifier">init</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
|
147
|
-
358: <span class="ruby-keyword kw">end</span>
|
148
|
-
</pre>
|
149
|
-
</div>
|
150
|
-
</div>
|
151
|
-
</div>
|
152
|
-
|
153
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
154
|
-
|
155
|
-
<div id="method-M000007" class="method-detail">
|
156
|
-
<a name="M000007"></a>
|
157
|
-
|
158
|
-
<div class="method-heading">
|
159
|
-
<a href="#M000007" class="method-signature">
|
160
|
-
<span class="method-name">decrypt_block</span><span class="method-args">(block)</span>
|
161
|
-
</a>
|
162
|
-
</div>
|
163
|
-
|
164
|
-
<div class="method-description">
|
165
|
-
<p><a class="source-toggle" href="#"
|
166
|
-
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
167
|
-
<div class="method-source-code" id="M000007-source">
|
168
|
-
<pre>
|
169
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 250</span>
|
170
|
-
250: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
|
171
|
-
251: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@mode</span>
|
172
|
-
252: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>
|
173
|
-
253: <span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">block</span>)
|
174
|
-
254: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CBC'</span>
|
175
|
-
255: <span class="ruby-identifier">o</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">block</span>), <span class="ruby-ivar">@iv</span>)
|
176
|
-
256: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">block</span>
|
177
|
-
257: <span class="ruby-identifier">o</span>
|
178
|
-
258: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'OFB'</span>
|
179
|
-
259: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>)
|
180
|
-
260: <span class="ruby-identifier">xor</span>(<span class="ruby-ivar">@iv</span>, <span class="ruby-identifier">block</span>)
|
181
|
-
261: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CFB'</span>
|
182
|
-
262: <span class="ruby-identifier">o</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>), <span class="ruby-identifier">block</span>)
|
183
|
-
263: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">block</span>
|
184
|
-
264: <span class="ruby-identifier">o</span>
|
185
|
-
265: <span class="ruby-keyword kw">end</span>
|
186
|
-
266: <span class="ruby-keyword kw">end</span>
|
187
|
-
</pre>
|
188
|
-
</div>
|
189
|
-
</div>
|
190
|
-
</div>
|
191
|
-
|
192
|
-
<div id="method-M000009" class="method-detail">
|
193
|
-
<a name="M000009"></a>
|
194
|
-
|
195
|
-
<div class="method-heading">
|
196
|
-
<a href="#M000009" class="method-signature">
|
197
|
-
<span class="method-name">decrypt_blocks</span><span class="method-args">(buffer)</span>
|
198
|
-
</a>
|
199
|
-
</div>
|
200
|
-
|
201
|
-
<div class="method-description">
|
202
|
-
<p><a class="source-toggle" href="#"
|
203
|
-
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
204
|
-
<div class="method-source-code" id="M000009-source">
|
205
|
-
<pre>
|
206
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 281</span>
|
207
|
-
281: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
|
208
|
-
282: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Bad block length"</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>).<span class="ruby-identifier">zero?</span>
|
209
|
-
283: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">""</span>
|
210
|
-
284: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
211
|
-
285: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
|
212
|
-
286: <span class="ruby-identifier">block</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">char</span>
|
213
|
-
287: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
|
214
|
-
288: <span class="ruby-identifier">pt</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
|
215
|
-
289: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
216
|
-
290: <span class="ruby-keyword kw">end</span>
|
217
|
-
291: <span class="ruby-keyword kw">end</span>
|
218
|
-
292: <span class="ruby-keyword kw">end</span>
|
219
|
-
</pre>
|
220
|
-
</div>
|
221
|
-
</div>
|
222
|
-
</div>
|
223
|
-
|
224
|
-
<div id="method-M000011" class="method-detail">
|
225
|
-
<a name="M000011"></a>
|
226
|
-
|
227
|
-
<div class="method-heading">
|
228
|
-
<a href="#M000011" class="method-signature">
|
229
|
-
<span class="method-name">decrypt_buffer</span><span class="method-args">(buffer)</span>
|
230
|
-
</a>
|
231
|
-
</div>
|
232
|
-
|
233
|
-
<div class="method-description">
|
234
|
-
<p><a class="source-toggle" href="#"
|
235
|
-
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
236
|
-
<div class="method-source-code" id="M000011-source">
|
237
|
-
<pre>
|
238
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 308</span>
|
239
|
-
308: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
|
240
|
-
309: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">""</span>
|
241
|
-
310: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
242
|
-
311: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
|
243
|
-
312: <span class="ruby-identifier">block</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">char</span>
|
244
|
-
313: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
|
245
|
-
314: <span class="ruby-identifier">pt</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
|
246
|
-
315: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
247
|
-
316: <span class="ruby-keyword kw">end</span>
|
248
|
-
317: <span class="ruby-keyword kw">end</span>
|
249
|
-
318: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
250
|
-
319: <span class="ruby-identifier">c</span> = <span class="ruby-identifier">pt</span>[<span class="ruby-value">-1</span>]
|
251
|
-
320: <span class="ruby-identifier">c</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">pt</span>[<span class="ruby-operator">-</span><span class="ruby-identifier">c</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-operator">-</span>(<span class="ruby-identifier">c</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>)] <span class="ruby-operator">:</span> (<span class="ruby-identifier">raise</span> <span class="ruby-value str">"Bad Block Padding"</span>)
|
252
|
-
321: <span class="ruby-keyword kw">else</span>
|
253
|
-
322: <span class="ruby-identifier">pt</span>
|
254
|
-
323: <span class="ruby-keyword kw">end</span>
|
255
|
-
324: <span class="ruby-keyword kw">end</span>
|
256
|
-
</pre>
|
257
|
-
</div>
|
258
|
-
</div>
|
259
|
-
</div>
|
260
|
-
|
261
|
-
<div id="method-M000006" class="method-detail">
|
262
|
-
<a name="M000006"></a>
|
263
|
-
|
264
|
-
<div class="method-heading">
|
265
|
-
<a href="#M000006" class="method-signature">
|
266
|
-
<span class="method-name">encrypt_block</span><span class="method-args">(block)</span>
|
267
|
-
</a>
|
268
|
-
</div>
|
269
|
-
|
270
|
-
<div class="method-description">
|
271
|
-
<p><a class="source-toggle" href="#"
|
272
|
-
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
273
|
-
<div class="method-source-code" id="M000006-source">
|
274
|
-
<pre>
|
275
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 236</span>
|
276
|
-
236: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
|
277
|
-
237: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@mode</span>
|
278
|
-
238: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>
|
279
|
-
239: <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">block</span>)
|
280
|
-
240: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CBC'</span>
|
281
|
-
241: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">xor</span>(<span class="ruby-identifier">block</span>, <span class="ruby-ivar">@iv</span>))
|
282
|
-
242: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'OFB'</span>
|
283
|
-
243: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>)
|
284
|
-
244: <span class="ruby-identifier">xor</span>(<span class="ruby-ivar">@iv</span>, <span class="ruby-identifier">block</span>)
|
285
|
-
245: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CFB'</span>
|
286
|
-
246: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>), <span class="ruby-identifier">block</span>)
|
287
|
-
247: <span class="ruby-keyword kw">end</span>
|
288
|
-
248: <span class="ruby-keyword kw">end</span>
|
289
|
-
</pre>
|
290
|
-
</div>
|
291
|
-
</div>
|
292
|
-
</div>
|
293
|
-
|
294
|
-
<div id="method-M000008" class="method-detail">
|
295
|
-
<a name="M000008"></a>
|
296
|
-
|
297
|
-
<div class="method-heading">
|
298
|
-
<a href="#M000008" class="method-signature">
|
299
|
-
<span class="method-name">encrypt_blocks</span><span class="method-args">(buffer)</span>
|
300
|
-
</a>
|
301
|
-
</div>
|
302
|
-
|
303
|
-
<div class="method-description">
|
304
|
-
<p><a class="source-toggle" href="#"
|
305
|
-
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
306
|
-
<div class="method-source-code" id="M000008-source">
|
307
|
-
<pre>
|
308
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 268</span>
|
309
|
-
268: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
|
310
|
-
269: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Bad block length"</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>).<span class="ruby-identifier">zero?</span>
|
311
|
-
270: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">""</span>
|
312
|
-
271: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
313
|
-
272: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
|
314
|
-
273: <span class="ruby-identifier">block</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">char</span>
|
315
|
-
274: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
|
316
|
-
275: <span class="ruby-identifier">ct</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
|
317
|
-
276: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
318
|
-
277: <span class="ruby-keyword kw">end</span>
|
319
|
-
278: <span class="ruby-keyword kw">end</span>
|
320
|
-
279: <span class="ruby-keyword kw">end</span>
|
321
|
-
</pre>
|
322
|
-
</div>
|
323
|
-
</div>
|
324
|
-
</div>
|
325
|
-
|
326
|
-
<div id="method-M000010" class="method-detail">
|
327
|
-
<a name="M000010"></a>
|
328
|
-
|
329
|
-
<div class="method-heading">
|
330
|
-
<a href="#M000010" class="method-signature">
|
331
|
-
<span class="method-name">encrypt_buffer</span><span class="method-args">(buffer)</span>
|
332
|
-
</a>
|
333
|
-
</div>
|
334
|
-
|
335
|
-
<div class="method-description">
|
336
|
-
<p><a class="source-toggle" href="#"
|
337
|
-
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
338
|
-
<div class="method-source-code" id="M000010-source">
|
339
|
-
<pre>
|
340
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 294</span>
|
341
|
-
294: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
|
342
|
-
295: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">""</span>
|
343
|
-
296: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
344
|
-
297: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
|
345
|
-
298: <span class="ruby-identifier">block</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">char</span>
|
346
|
-
299: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
|
347
|
-
300: <span class="ruby-identifier">ct</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
|
348
|
-
301: <span class="ruby-identifier">block</span> = <span class="ruby-value str">""</span>
|
349
|
-
302: <span class="ruby-keyword kw">end</span>
|
350
|
-
303: <span class="ruby-keyword kw">end</span>
|
351
|
-
304: <span class="ruby-identifier">m</span> = <span class="ruby-value">16</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>
|
352
|
-
305: <span class="ruby-identifier">ct</span> <span class="ruby-operator"><<</span> (<span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span> <span class="ruby-operator">?</span> <span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>))
|
353
|
-
306: <span class="ruby-keyword kw">end</span>
|
354
|
-
</pre>
|
355
|
-
</div>
|
356
|
-
</div>
|
357
|
-
</div>
|
358
|
-
|
359
|
-
<div id="method-M000012" class="method-detail">
|
360
|
-
<a name="M000012"></a>
|
361
|
-
|
362
|
-
<div class="method-heading">
|
363
|
-
<a href="#M000012" class="method-signature">
|
364
|
-
<span class="method-name">init</span><span class="method-args">(key_length, mode, key, iv = nil)</span>
|
365
|
-
</a>
|
366
|
-
</div>
|
367
|
-
|
368
|
-
<div class="method-description">
|
369
|
-
<p><a class="source-toggle" href="#"
|
370
|
-
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
371
|
-
<div class="method-source-code" id="M000012-source">
|
372
|
-
<pre>
|
373
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 326</span>
|
374
|
-
326: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">init</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span> = <span class="ruby-keyword kw">nil</span>)
|
375
|
-
327: <span class="ruby-ivar">@nb</span> = <span class="ruby-value">4</span>
|
376
|
-
328: <span class="ruby-ivar">@ek</span> = []
|
377
|
-
329: <span class="ruby-ivar">@rk</span> = []
|
378
|
-
330: <span class="ruby-ivar">@state</span> = <span class="ruby-keyword kw">nil</span>
|
379
|
-
331: <span class="ruby-ivar">@iv</span> = <span class="ruby-value str">"\000"</span> <span class="ruby-operator">*</span> <span class="ruby-value">16</span>
|
380
|
-
332: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">iv</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">iv</span>
|
381
|
-
333: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">key_length</span>
|
382
|
-
334: <span class="ruby-keyword kw">when</span> <span class="ruby-value">128</span>
|
383
|
-
335: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">4</span>
|
384
|
-
336: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">10</span>
|
385
|
-
337: <span class="ruby-keyword kw">when</span> <span class="ruby-value">192</span>
|
386
|
-
338: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">6</span>
|
387
|
-
339: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">12</span>
|
388
|
-
340: <span class="ruby-keyword kw">when</span> <span class="ruby-value">256</span>
|
389
|
-
341: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">8</span>
|
390
|
-
342: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">14</span>
|
391
|
-
343: <span class="ruby-keyword kw">else</span>
|
392
|
-
344: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Bad Key length'</span>
|
393
|
-
345: <span class="ruby-keyword kw">end</span>
|
394
|
-
346: <span class="ruby-ivar">@kl</span> = <span class="ruby-identifier">key_length</span>
|
395
|
-
347: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">mode</span>
|
396
|
-
348: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>, <span class="ruby-value str">'CBC'</span>, <span class="ruby-value str">'OFB'</span>, <span class="ruby-value str">'CFB'</span>
|
397
|
-
349: <span class="ruby-ivar">@mode</span> = <span class="ruby-identifier">mode</span>
|
398
|
-
350: <span class="ruby-keyword kw">else</span>
|
399
|
-
351: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Bad AES mode'</span>
|
400
|
-
352: <span class="ruby-keyword kw">end</span>
|
401
|
-
353: <span class="ruby-identifier">decryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
|
402
|
-
354: <span class="ruby-keyword kw">end</span>
|
403
|
-
</pre>
|
404
|
-
</div>
|
405
|
-
</div>
|
406
|
-
</div>
|
407
|
-
|
408
|
-
<h3 class="section-bar">Protected Instance methods</h3>
|
409
|
-
|
410
|
-
<div id="method-M000004" class="method-detail">
|
411
|
-
<a name="M000004"></a>
|
412
|
-
|
413
|
-
<div class="method-heading">
|
414
|
-
<a href="#M000004" class="method-signature">
|
415
|
-
<span class="method-name">_decrypt_block</span><span class="method-args">(ct)</span>
|
416
|
-
</a>
|
417
|
-
</div>
|
418
|
-
|
419
|
-
<div class="method-description">
|
420
|
-
<p><a class="source-toggle" href="#"
|
421
|
-
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
422
|
-
<div class="method-source-code" id="M000004-source">
|
423
|
-
<pre>
|
424
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 184</span>
|
425
|
-
184: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">ct</span>)
|
426
|
-
185: <span class="ruby-identifier">t0</span> = <span class="ruby-identifier">t1</span> = <span class="ruby-identifier">t2</span> = <span class="ruby-identifier">t3</span> = <span class="ruby-keyword kw">nil</span>
|
427
|
-
186: <span class="ruby-comment cmt"># map byte array block to cipher state and add initial round key:</span>
|
428
|
-
187: <span class="ruby-identifier">s0</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">0</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">1</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">2</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">3</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span>]
|
429
|
-
188: <span class="ruby-identifier">s1</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">4</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">5</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">6</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">7</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span>]
|
430
|
-
189: <span class="ruby-identifier">s2</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">8</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">9</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">10</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">11</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span>]
|
431
|
-
190: <span class="ruby-identifier">s3</span> = (<span class="ruby-identifier">ct</span>[<span class="ruby-value">12</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">13</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">14</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">15</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span>]
|
432
|
-
191: <span class="ruby-identifier">r</span> = <span class="ruby-ivar">@nr</span> <span class="ruby-operator">>></span> <span class="ruby-value">1</span>
|
433
|
-
192: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
434
|
-
193: <span class="ruby-identifier">loop</span> {
|
435
|
-
194: <span class="ruby-identifier">t0</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
436
|
-
195: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s1</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
437
|
-
196: <span class="ruby-identifier">t1</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
438
|
-
197: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s2</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
439
|
-
198: <span class="ruby-identifier">t2</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
440
|
-
199: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s3</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
441
|
-
200: <span class="ruby-identifier">t3</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
442
|
-
201: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s0</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
443
|
-
202: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
|
444
|
-
203: <span class="ruby-identifier">r</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
445
|
-
204: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
446
|
-
205: <span class="ruby-identifier">s0</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
447
|
-
206: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t1</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
448
|
-
207: <span class="ruby-identifier">s1</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
449
|
-
208: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t2</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
450
|
-
209: <span class="ruby-identifier">s2</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
451
|
-
210: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t3</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
452
|
-
211: <span class="ruby-identifier">s3</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
453
|
-
212: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t0</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
454
|
-
213: }
|
455
|
-
214: <span class="ruby-comment cmt"># apply last round and map cipher state to byte array block:</span>
|
456
|
-
215: <span class="ruby-identifier">s0</span> = (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
457
|
-
216: (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t1</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
458
|
-
217: <span class="ruby-identifier">s1</span> = (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
459
|
-
218: (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t2</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
460
|
-
219: <span class="ruby-identifier">s2</span> = (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
461
|
-
220: (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t3</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
462
|
-
221: <span class="ruby-identifier">s3</span> = (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
463
|
-
222: (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Td4</span>[(<span class="ruby-identifier">t0</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
464
|
-
223: [(<span class="ruby-value str">"%08x%08x%08x%08x"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">s0</span>, <span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span>, <span class="ruby-identifier">s3</span>])].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">"H*"</span>)
|
465
|
-
224: <span class="ruby-keyword kw">end</span>
|
466
|
-
</pre>
|
467
|
-
</div>
|
468
|
-
</div>
|
469
|
-
</div>
|
470
|
-
|
471
|
-
<div id="method-M000003" class="method-detail">
|
472
|
-
<a name="M000003"></a>
|
473
|
-
|
474
|
-
<div class="method-heading">
|
475
|
-
<a href="#M000003" class="method-signature">
|
476
|
-
<span class="method-name">_encrypt_block</span><span class="method-args">(pt)</span>
|
477
|
-
</a>
|
478
|
-
</div>
|
479
|
-
|
480
|
-
<div class="method-description">
|
481
|
-
<p><a class="source-toggle" href="#"
|
482
|
-
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
483
|
-
<div class="method-source-code" id="M000003-source">
|
484
|
-
<pre>
|
485
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 141</span>
|
486
|
-
141: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">pt</span>)
|
487
|
-
142: <span class="ruby-identifier">t0</span> = <span class="ruby-identifier">t1</span> = <span class="ruby-identifier">t2</span> = <span class="ruby-identifier">t3</span> = <span class="ruby-keyword kw">nil</span>
|
488
|
-
143: <span class="ruby-comment cmt"># map byte array block to cipher state and add initial round key:</span>
|
489
|
-
144: <span class="ruby-identifier">s0</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">0</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">1</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">2</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">3</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span>]
|
490
|
-
145: <span class="ruby-identifier">s1</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">4</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">5</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">6</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">7</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span>]
|
491
|
-
146: <span class="ruby-identifier">s2</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">8</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">9</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">10</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">11</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span>]
|
492
|
-
147: <span class="ruby-identifier">s3</span> = (<span class="ruby-identifier">pt</span>[<span class="ruby-value">12</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">13</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">14</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">15</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span>]
|
493
|
-
148: <span class="ruby-identifier">r</span> = <span class="ruby-ivar">@nr</span> <span class="ruby-operator">>></span> <span class="ruby-value">1</span>
|
494
|
-
149: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
495
|
-
150: <span class="ruby-identifier">loop</span> {
|
496
|
-
151: <span class="ruby-identifier">t0</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
497
|
-
152: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s3</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
498
|
-
153: <span class="ruby-identifier">t1</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
499
|
-
154: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s0</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
500
|
-
155: <span class="ruby-identifier">t2</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
501
|
-
156: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s1</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
502
|
-
157: <span class="ruby-identifier">t3</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
503
|
-
158: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s2</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
504
|
-
159: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
|
505
|
-
160: <span class="ruby-identifier">r</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
506
|
-
161: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
507
|
-
162: <span class="ruby-identifier">s0</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
508
|
-
163: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t3</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
509
|
-
164: <span class="ruby-identifier">s1</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
510
|
-
165: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t0</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
511
|
-
166: <span class="ruby-identifier">s2</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
512
|
-
167: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t1</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
513
|
-
168: <span class="ruby-identifier">s3</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
514
|
-
169: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t2</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
515
|
-
170: }
|
516
|
-
171: <span class="ruby-comment cmt"># apply last round and map cipher state to byte array block:</span>
|
517
|
-
172: <span class="ruby-identifier">s0</span> = (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)] <span class="ruby-operator">&</span> <span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
518
|
-
173: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t3</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
519
|
-
174: <span class="ruby-identifier">s1</span> = (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
520
|
-
175: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t0</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
521
|
-
176: <span class="ruby-identifier">s2</span> = (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
522
|
-
177: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t1</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
523
|
-
178: <span class="ruby-identifier">s3</span> = (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">>></span><span class="ruby-value">24</span>)]<span class="ruby-operator">&</span><span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">>></span><span class="ruby-value">16</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
524
|
-
179: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">>></span><span class="ruby-value">8</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span> (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">t2</span>)<span class="ruby-operator">&</span><span class="ruby-value">0xff</span>]<span class="ruby-operator">&</span><span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
525
|
-
180: [(<span class="ruby-value str">"%08x%08x%08x%08x"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">s0</span>, <span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span>, <span class="ruby-identifier">s3</span>])].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">"H*"</span>)
|
526
|
-
181: <span class="ruby-keyword kw">end</span>
|
527
|
-
</pre>
|
528
|
-
</div>
|
529
|
-
</div>
|
530
|
-
</div>
|
531
|
-
|
532
|
-
<div id="method-M000002" class="method-detail">
|
533
|
-
<a name="M000002"></a>
|
534
|
-
|
535
|
-
<div class="method-heading">
|
536
|
-
<a href="#M000002" class="method-signature">
|
537
|
-
<span class="method-name">decryption_key_schedule</span><span class="method-args">(key)</span>
|
538
|
-
</a>
|
539
|
-
</div>
|
540
|
-
|
541
|
-
<div class="method-description">
|
542
|
-
<p><a class="source-toggle" href="#"
|
543
|
-
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
544
|
-
<div class="method-source-code" id="M000002-source">
|
545
|
-
<pre>
|
546
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 90</span>
|
547
|
-
90: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
|
548
|
-
91: <span class="ruby-comment cmt"># expand the cipher key:</span>
|
549
|
-
92: <span class="ruby-identifier">encryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
|
550
|
-
93: <span class="ruby-ivar">@ek</span> = <span class="ruby-ivar">@rk</span>.<span class="ruby-identifier">dup</span>
|
551
|
-
94: <span class="ruby-comment cmt"># invert the order of the round keys:</span>
|
552
|
-
95: <span class="ruby-identifier">j</span> = <span class="ruby-value">4</span> <span class="ruby-operator">*</span> <span class="ruby-ivar">@nr</span>
|
553
|
-
96: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
|
554
|
-
97: <span class="ruby-identifier">loop</span> { <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">>=</span> <span class="ruby-identifier">j</span>
|
555
|
-
98: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span>]
|
556
|
-
99: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span>]
|
557
|
-
100: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span>] = <span class="ruby-identifier">temp</span>
|
558
|
-
101: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
|
559
|
-
102: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
|
560
|
-
103: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] = <span class="ruby-identifier">temp</span>
|
561
|
-
104: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>]
|
562
|
-
105: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>]
|
563
|
-
106: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>] = <span class="ruby-identifier">temp</span>
|
564
|
-
107: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>]
|
565
|
-
108: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>]
|
566
|
-
109: <span class="ruby-ivar">@rk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>] = <span class="ruby-identifier">temp</span>
|
567
|
-
110: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
|
568
|
-
111: <span class="ruby-identifier">j</span> <span class="ruby-operator">-=</span> <span class="ruby-value">4</span>
|
569
|
-
112: }
|
570
|
-
113: <span class="ruby-comment cmt"># apply the inverse MixColumn transform</span>
|
571
|
-
114: <span class="ruby-comment cmt"># to all round keys but the first and the last:</span>
|
572
|
-
115: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
573
|
-
116: <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-ivar">@nr</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
|
574
|
-
117: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
|
575
|
-
118: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
576
|
-
119: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
577
|
-
120: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
578
|
-
121: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>]
|
579
|
-
122: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
|
580
|
-
123: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
581
|
-
124: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
582
|
-
125: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
583
|
-
126: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>]
|
584
|
-
127: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
|
585
|
-
128: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
586
|
-
129: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
587
|
-
130: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
588
|
-
131: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>]
|
589
|
-
132: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
|
590
|
-
133: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
591
|
-
134: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
592
|
-
135: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
|
593
|
-
136: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">Te4</span>[(<span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>]
|
594
|
-
137: }
|
595
|
-
138: <span class="ruby-keyword kw">end</span>
|
596
|
-
</pre>
|
597
|
-
</div>
|
598
|
-
</div>
|
599
|
-
</div>
|
600
|
-
|
601
|
-
<div id="method-M000001" class="method-detail">
|
602
|
-
<a name="M000001"></a>
|
603
|
-
|
604
|
-
<div class="method-heading">
|
605
|
-
<a href="#M000001" class="method-signature">
|
606
|
-
<span class="method-name">encryption_key_schedule</span><span class="method-args">(key)</span>
|
607
|
-
</a>
|
608
|
-
</div>
|
609
|
-
|
610
|
-
<div class="method-description">
|
611
|
-
<p><a class="source-toggle" href="#"
|
612
|
-
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
613
|
-
<div class="method-source-code" id="M000001-source">
|
614
|
-
<pre>
|
615
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 17</span>
|
616
|
-
17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
|
617
|
-
18: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
|
618
|
-
19: <span class="ruby-ivar">@rk</span> = []
|
619
|
-
20: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">0</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">1</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">2</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">3</span>]
|
620
|
-
21: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">4</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">5</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">6</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">7</span>]
|
621
|
-
22: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">8</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">9</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">10</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">11</span>]
|
622
|
-
23: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">12</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">13</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">14</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">15</span>]
|
623
|
-
24: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">128</span>
|
624
|
-
25: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
625
|
-
26: <span class="ruby-identifier">loop</span> { <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
626
|
-
27: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
|
627
|
-
28: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span>
|
628
|
-
29: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
629
|
-
30: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span>
|
630
|
-
31: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
|
631
|
-
32: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
632
|
-
33: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
633
|
-
34: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
634
|
-
35: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
635
|
-
36: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">10</span>)
|
636
|
-
37: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
|
637
|
-
38: }
|
638
|
-
39: <span class="ruby-keyword kw">end</span>
|
639
|
-
40: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">4</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">16</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">17</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">18</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">19</span>]
|
640
|
-
41: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">5</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">20</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">21</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">22</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">23</span>]
|
641
|
-
42: <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">192</span>)
|
642
|
-
43: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
643
|
-
44: <span class="ruby-identifier">loop</span> { <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
644
|
-
45: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
|
645
|
-
46: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span>
|
646
|
-
47: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
647
|
-
48: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span>
|
648
|
-
49: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
|
649
|
-
50: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
650
|
-
51: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
651
|
-
52: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
652
|
-
53: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
653
|
-
54: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">8</span>)
|
654
|
-
55: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
655
|
-
56: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
656
|
-
57: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">6</span>
|
657
|
-
58: }
|
658
|
-
59: <span class="ruby-keyword kw">end</span>
|
659
|
-
60: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">6</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">24</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">25</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">26</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">27</span>]
|
660
|
-
61: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">7</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">28</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">29</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">30</span>] <span class="ruby-operator"><<</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">31</span>]
|
661
|
-
62: <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">256</span>)
|
662
|
-
63: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
663
|
-
64: <span class="ruby-identifier">loop</span> { <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
664
|
-
65: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
|
665
|
-
66: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span>
|
666
|
-
67: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
667
|
-
68: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span>
|
668
|
-
69: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0x000000ff</span>) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
|
669
|
-
70: <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
670
|
-
71: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
671
|
-
72: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
672
|
-
73: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
673
|
-
74: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">7</span>)
|
674
|
-
75: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@rk</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
675
|
-
76: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">12</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
|
676
|
-
77: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">&</span> <span class="ruby-value">0xff000000</span>) <span class="ruby-operator">^</span>
|
677
|
-
78: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">16</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x00ff0000</span>) <span class="ruby-operator">^</span>
|
678
|
-
79: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">>></span> <span class="ruby-value">8</span>) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x0000ff00</span>) <span class="ruby-operator">^</span>
|
679
|
-
80: (<span class="ruby-constant">Te4</span>[(<span class="ruby-identifier">temp</span> ) <span class="ruby-operator">&</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">&</span> <span class="ruby-value">0x000000ff</span>)
|
680
|
-
81: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">13</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">12</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
681
|
-
82: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">14</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">13</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
682
|
-
83: <span class="ruby-ivar">@rk</span>[<span class="ruby-value">15</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@rk</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@rk</span>[<span class="ruby-value">14</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
|
683
|
-
84: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
|
684
|
-
85: }
|
685
|
-
86: <span class="ruby-keyword kw">end</span>
|
686
|
-
87: <span class="ruby-keyword kw">end</span>
|
687
|
-
</pre>
|
688
|
-
</div>
|
689
|
-
</div>
|
690
|
-
</div>
|
691
|
-
|
692
|
-
<div id="method-M000005" class="method-detail">
|
693
|
-
<a name="M000005"></a>
|
694
|
-
|
695
|
-
<div class="method-heading">
|
696
|
-
<a href="#M000005" class="method-signature">
|
697
|
-
<span class="method-name">xor</span><span class="method-args">(a,b)</span>
|
698
|
-
</a>
|
699
|
-
</div>
|
700
|
-
|
701
|
-
<div class="method-description">
|
702
|
-
<p><a class="source-toggle" href="#"
|
703
|
-
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
704
|
-
<div class="method-source-code" id="M000005-source">
|
705
|
-
<pre>
|
706
|
-
<span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 227</span>
|
707
|
-
227: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">a</span>,<span class="ruby-identifier">b</span>)
|
708
|
-
228: <span class="ruby-identifier">c</span> = <span class="ruby-value str">""</span>
|
709
|
-
229: <span class="ruby-value">16</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
710
|
-
230: <span class="ruby-identifier">c</span> <span class="ruby-operator"><<</span> (<span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">^</span> <span class="ruby-identifier">b</span>[<span class="ruby-identifier">i</span>]).<span class="ruby-identifier">chr</span>
|
711
|
-
231: <span class="ruby-keyword kw">end</span>
|
712
|
-
232: <span class="ruby-identifier">c</span>
|
713
|
-
233: <span class="ruby-keyword kw">end</span>
|
714
|
-
</pre>
|
715
|
-
</div>
|
716
|
-
</div>
|
717
|
-
</div>
|
718
|
-
|
719
|
-
|
720
|
-
</div>
|
721
|
-
|
722
|
-
|
723
|
-
</div>
|
724
|
-
|
725
|
-
|
726
|
-
<div id="validator-badges">
|
727
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
728
|
-
</div>
|
729
|
-
|
730
|
-
</body>
|
731
|
-
</html>
|