ruby-aes-table1 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/COPYING +20 -0
- data/README +77 -0
- data/Rakefile +154 -0
- data/doc/rdoc/classes/Aes.html +494 -0
- data/doc/rdoc/classes/AesAlg.html +731 -0
- data/doc/rdoc/classes/AesCons.html +168 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGELOG.html +117 -0
- data/doc/rdoc/files/COPYING.html +129 -0
- data/doc/rdoc/files/README.html +235 -0
- data/doc/rdoc/files/lib/ruby-aes/aes_alg_rb.html +108 -0
- data/doc/rdoc/files/lib/ruby-aes/aes_cons_rb.html +101 -0
- data/doc/rdoc/files/lib/ruby-aes_rb.html +108 -0
- data/doc/rdoc/fr_class_index.html +29 -0
- data/doc/rdoc/fr_file_index.html +32 -0
- data/doc/rdoc/fr_method_index.html +52 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/examples/encrypt_block.rb +22 -0
- data/examples/encrypt_buffer.rb +24 -0
- data/examples/encrypt_stream.rb +39 -0
- data/examples/example_helper.rb +27 -0
- data/lib/ruby-aes/aes_alg.rb +360 -0
- data/lib/ruby-aes/aes_cons.rb +478 -0
- data/lib/ruby-aes.rb +162 -0
- data/test/KAT_MCT/aes_kat_mct.rb +386 -0
- data/test/KAT_MCT/rijndael-vals.zip +0 -0
- data/test/KAT_MCT/table.128 +128 -0
- data/test/KAT_MCT/table.192 +128 -0
- data/test/KAT_MCT/table.256 +128 -0
- data/test/test_helper.rb +14 -0
- data/test/test_ruby-aes.rb +113 -0
- metadata +98 -0
@@ -0,0 +1,731 @@
|
|
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>
|