ruby-aes-unroll1 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,265 @@
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>Module: AesShared</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>Module</strong></td>
53
+ <td class="class-name-in-header">AesShared</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_shared_rb.html">
59
+ lib/ruby-aes/aes_shared.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ </table>
66
+ </div>
67
+ <!-- banner header -->
68
+
69
+ <div id="bodyContent">
70
+
71
+
72
+
73
+ <div id="contextContent">
74
+
75
+
76
+
77
+ </div>
78
+
79
+ <div id="method-list">
80
+ <h3 class="section-bar">Methods</h3>
81
+
82
+ <div class="name-list">
83
+ <a href="#M000002">decrypt_blocks</a>&nbsp;&nbsp;
84
+ <a href="#M000004">decrypt_buffer</a>&nbsp;&nbsp;
85
+ <a href="#M000001">encrypt_blocks</a>&nbsp;&nbsp;
86
+ <a href="#M000003">encrypt_buffer</a>&nbsp;&nbsp;
87
+ </div>
88
+ </div>
89
+
90
+ </div>
91
+
92
+
93
+ <!-- if includes -->
94
+
95
+ <div id="section">
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+ <!-- if method_list -->
105
+ <div id="methods">
106
+ <h3 class="section-bar">Public Instance methods</h3>
107
+
108
+ <div id="method-M000002" class="method-detail">
109
+ <a name="M000002"></a>
110
+
111
+ <div class="method-heading">
112
+ <a href="#M000002" class="method-signature">
113
+ <span class="method-name">decrypt_blocks</span><span class="method-args">(buffer)</span>
114
+ </a>
115
+ </div>
116
+
117
+ <div class="method-description">
118
+ <p><a class="source-toggle" href="#"
119
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
120
+ <div class="method-source-code" id="M000002-source">
121
+ <pre>
122
+ <span class="ruby-comment cmt"># File lib/ruby-aes/aes_shared.rb, line 23</span>
123
+ 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
124
+ 24: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad block length&quot;</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>
125
+ 25: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">&quot;&quot;</span>
126
+ 26: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
127
+ 27: <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>
128
+ 28: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
129
+ 29: <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>
130
+ 30: <span class="ruby-identifier">pt</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
131
+ 31: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
132
+ 32: <span class="ruby-keyword kw">end</span>
133
+ 33: <span class="ruby-keyword kw">end</span>
134
+ 34: <span class="ruby-identifier">pt</span>
135
+ 35: <span class="ruby-keyword kw">end</span>
136
+ </pre>
137
+ </div>
138
+ </div>
139
+ </div>
140
+
141
+ <div id="method-M000004" class="method-detail">
142
+ <a name="M000004"></a>
143
+
144
+ <div class="method-heading">
145
+ <a href="#M000004" class="method-signature">
146
+ <span class="method-name">decrypt_buffer</span><span class="method-args">(buffer)</span>
147
+ </a>
148
+ </div>
149
+
150
+ <div class="method-description">
151
+ <p><a class="source-toggle" href="#"
152
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
153
+ <div class="method-source-code" id="M000004-source">
154
+ <pre>
155
+ <span class="ruby-comment cmt"># File lib/ruby-aes/aes_shared.rb, line 55</span>
156
+ 55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
157
+ 56: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">&quot;&quot;</span>
158
+ 57: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
159
+ 58: <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>
160
+ 59: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
161
+ 60: <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>
162
+ 61: <span class="ruby-identifier">pt</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
163
+ 62: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
164
+ 63: <span class="ruby-keyword kw">end</span>
165
+ 64: <span class="ruby-keyword kw">end</span>
166
+ 65: <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">1</span>
167
+ 66: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Bad Block Padding'</span>
168
+ 67: <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">c</span> = <span class="ruby-identifier">block</span>[<span class="ruby-value">-1</span>]).<span class="ruby-identifier">zero?</span>
169
+ 68: <span class="ruby-identifier">pt</span>
170
+ 69: <span class="ruby-keyword kw">else</span>
171
+ 70: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</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>]
172
+ 71: <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>]
173
+ 72: <span class="ruby-keyword kw">else</span>
174
+ 73: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad Block Padding&quot;</span>
175
+ 74: <span class="ruby-keyword kw">end</span>
176
+ 75: <span class="ruby-keyword kw">end</span>
177
+ 76: <span class="ruby-keyword kw">end</span>
178
+ </pre>
179
+ </div>
180
+ </div>
181
+ </div>
182
+
183
+ <div id="method-M000001" class="method-detail">
184
+ <a name="M000001"></a>
185
+
186
+ <div class="method-heading">
187
+ <a href="#M000001" class="method-signature">
188
+ <span class="method-name">encrypt_blocks</span><span class="method-args">(buffer)</span>
189
+ </a>
190
+ </div>
191
+
192
+ <div class="method-description">
193
+ <p><a class="source-toggle" href="#"
194
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
195
+ <div class="method-source-code" id="M000001-source">
196
+ <pre>
197
+ <span class="ruby-comment cmt"># File lib/ruby-aes/aes_shared.rb, line 9</span>
198
+ 9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
199
+ 10: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad block length&quot;</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>
200
+ 11: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">&quot;&quot;</span>
201
+ 12: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
202
+ 13: <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>
203
+ 14: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
204
+ 15: <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>
205
+ 16: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
206
+ 17: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
207
+ 18: <span class="ruby-keyword kw">end</span>
208
+ 19: <span class="ruby-keyword kw">end</span>
209
+ 20: <span class="ruby-identifier">ct</span>
210
+ 21: <span class="ruby-keyword kw">end</span>
211
+ </pre>
212
+ </div>
213
+ </div>
214
+ </div>
215
+
216
+ <div id="method-M000003" class="method-detail">
217
+ <a name="M000003"></a>
218
+
219
+ <div class="method-heading">
220
+ <a href="#M000003" class="method-signature">
221
+ <span class="method-name">encrypt_buffer</span><span class="method-args">(buffer)</span>
222
+ </a>
223
+ </div>
224
+
225
+ <div class="method-description">
226
+ <p><a class="source-toggle" href="#"
227
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
228
+ <div class="method-source-code" id="M000003-source">
229
+ <pre>
230
+ <span class="ruby-comment cmt"># File lib/ruby-aes/aes_shared.rb, line 37</span>
231
+ 37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
232
+ 38: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">&quot;&quot;</span>
233
+ 39: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
234
+ 40: <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>
235
+ 41: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
236
+ 42: <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>
237
+ 43: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
238
+ 44: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
239
+ 45: <span class="ruby-keyword kw">end</span>
240
+ 46: <span class="ruby-keyword kw">end</span>
241
+ 47: <span class="ruby-identifier">c</span> = <span class="ruby-value str">&quot;\000&quot;</span>
242
+ 48: <span class="ruby-keyword kw">if</span> (<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>) <span class="ruby-operator">!=</span> <span class="ruby-value">16</span>
243
+ 49: <span class="ruby-identifier">c</span> = <span class="ruby-identifier">m</span>.<span class="ruby-identifier">chr</span>
244
+ 50: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>)
245
+ 51: <span class="ruby-keyword kw">end</span>
246
+ 52: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">c</span>
247
+ 53: <span class="ruby-keyword kw">end</span>
248
+ </pre>
249
+ </div>
250
+ </div>
251
+ </div>
252
+
253
+
254
+ </div>
255
+
256
+
257
+ </div>
258
+
259
+
260
+ <div id="validator-badges">
261
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
262
+ </div>
263
+
264
+ </body>
265
+ </html>
data/doc/rdoc/created.rid CHANGED
@@ -1 +1 @@
1
- Wed Aug 01 17:33:22 CEST 2007
1
+ Sat, 05 Jan 2008 02:15:37 +0100
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jul 29 21:54:22 CEST 2007</td>
59
+ <td>Sat Jan 05 00:53:21 +0100 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,7 +69,17 @@
69
69
  <div id="contextContent">
70
70
 
71
71
  <div id="description">
72
- <h1>0.1</h1>
72
+ <h1>1.1</h1>
73
+ <h3>2008-01-05</h3>
74
+ <ul>
75
+ <li>Fixed padding problem (bug 15885)
76
+
77
+ </li>
78
+ <li>Fixed encrypt/decrypt stream
79
+
80
+ </li>
81
+ </ul>
82
+ <h1>1.0</h1>
73
83
  <h3>2007-07-30</h3>
74
84
  <ul>
75
85
  <li>Initial release: RAA project import
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jul 29 18:32:22 CEST 2007</td>
59
+ <td>Sun Jul 29 18:32:22 +0200 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -70,7 +70,7 @@
70
70
 
71
71
  <div id="description">
72
72
  <p>
73
- Copyright &#169; 2007 Alex Boussinet
73
+ Copyright (c) 2007 Alex Boussinet
74
74
  </p>
75
75
  <p>
76
76
  Permission is hereby granted, free of charge, to any person obtaining a
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jul 29 18:32:22 CEST 2007</td>
59
+ <td>Sun Jul 29 18:32:22 +0200 2007</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -84,7 +84,7 @@ href="mailto:alex.boussinet@gmail.com">alex.boussinet@gmail.com</a>&gt;
84
84
  </p>
85
85
  <p>
86
86
  This release is mainly an import from the Ruby Application Archive (RAA).
87
- I&#8217;ve added all the versions I was working on (algorithm variations)
87
+ I&#8216;ve added all the versions I was working on (algorithm variations)
88
88
  and a new C extension for improved performance. 6 variations are available:
89
89
  </p>
90
90
  <ul>
@@ -113,7 +113,7 @@ for speed. The SubBytes and ShiftRows methods have been combined.
113
113
  <p>
114
114
  Pure Ruby implementation based on the C code from the Rijndael website. The
115
115
  arrays of constants are bigger because all the operations are already
116
- computed so it&#8217;s mainly based on table look ups.
116
+ computed so it&#8216;s mainly based on table look ups.
117
117
  </p>
118
118
  <ul>
119
119
  <li>&quot;Table Optimized 2&quot;:
@@ -5,7 +5,7 @@
5
5
 
6
6
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
7
  <head>
8
- <title>File: aes_cons.rb</title>
8
+ <title>File: aes_shared.rb</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
11
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
@@ -47,16 +47,16 @@
47
47
 
48
48
 
49
49
  <div id="fileHeader">
50
- <h1>aes_cons.rb</h1>
50
+ <h1>aes_shared.rb</h1>
51
51
  <table class="header-table">
52
52
  <tr class="top-aligned-row">
53
53
  <td><strong>Path:</strong></td>
54
- <td>lib/ruby-aes/aes_cons.rb
54
+ <td>lib/ruby-aes/aes_shared.rb
55
55
  </td>
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Aug 01 17:33:22 CEST 2007</td>
59
+ <td>Fri Jan 04 17:08:17 +0100 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sun Jul 29 18:32:22 CEST 2007</td>
59
+ <td>Fri Jan 04 17:09:17 +0100 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -21,8 +21,7 @@
21
21
  <h1 class="section-bar">Classes</h1>
22
22
  <div id="index-entries">
23
23
  <a href="classes/Aes.html">Aes</a><br />
24
- <a href="classes/AesAlg.html">AesAlg</a><br />
25
- <a href="classes/AesCons.html">AesCons</a><br />
24
+ <a href="classes/AesShared.html">AesShared</a><br />
26
25
  </div>
27
26
  </div>
28
27
  </body>
@@ -24,8 +24,7 @@
24
24
  <a href="files/COPYING.html">COPYING</a><br />
25
25
  <a href="files/README.html">README</a><br />
26
26
  <a href="files/lib/ruby-aes_rb.html">lib/ruby-aes.rb</a><br />
27
- <a href="files/lib/ruby-aes/aes_alg_rb.html">lib/ruby-aes/aes_alg.rb</a><br />
28
- <a href="files/lib/ruby-aes/aes_cons_rb.html">lib/ruby-aes/aes_cons.rb</a><br />
27
+ <a href="files/lib/ruby-aes/aes_shared_rb.html">lib/ruby-aes/aes_shared.rb</a><br />
29
28
  </div>
30
29
  </div>
31
30
  </body>
@@ -20,32 +20,23 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
- <a href="classes/AesAlg.html#M000004">_decrypt_block (AesAlg)</a><br />
24
- <a href="classes/AesAlg.html#M000003">_encrypt_block (AesAlg)</a><br />
25
- <a href="classes/Aes.html#M000014">bs (Aes)</a><br />
26
- <a href="classes/Aes.html#M000015">bs= (Aes)</a><br />
27
- <a href="classes/Aes.html#M000017">check_iv (Aes)</a><br />
28
- <a href="classes/Aes.html#M000016">check_key (Aes)</a><br />
29
- <a href="classes/Aes.html#M000019">check_kl (Aes)</a><br />
30
- <a href="classes/Aes.html#M000018">check_mode (Aes)</a><br />
31
- <a href="classes/Aes.html#M000022">decrypt_block (Aes)</a><br />
32
- <a href="classes/AesAlg.html#M000007">decrypt_block (AesAlg)</a><br />
33
- <a href="classes/AesAlg.html#M000009">decrypt_blocks (AesAlg)</a><br />
34
- <a href="classes/Aes.html#M000024">decrypt_buffer (Aes)</a><br />
35
- <a href="classes/AesAlg.html#M000011">decrypt_buffer (AesAlg)</a><br />
36
- <a href="classes/Aes.html#M000026">decrypt_stream (Aes)</a><br />
37
- <a href="classes/AesAlg.html#M000002">decryption_key_schedule (AesAlg)</a><br />
38
- <a href="classes/Aes.html#M000021">encrypt_block (Aes)</a><br />
39
- <a href="classes/AesAlg.html#M000006">encrypt_block (AesAlg)</a><br />
40
- <a href="classes/AesAlg.html#M000008">encrypt_blocks (AesAlg)</a><br />
41
- <a href="classes/AesAlg.html#M000010">encrypt_buffer (AesAlg)</a><br />
42
- <a href="classes/Aes.html#M000023">encrypt_buffer (Aes)</a><br />
43
- <a href="classes/Aes.html#M000025">encrypt_stream (Aes)</a><br />
44
- <a href="classes/AesAlg.html#M000001">encryption_key_schedule (AesAlg)</a><br />
45
- <a href="classes/AesAlg.html#M000012">init (AesAlg)</a><br />
46
- <a href="classes/Aes.html#M000020">init (Aes)</a><br />
47
- <a href="classes/AesAlg.html#M000013">new (AesAlg)</a><br />
48
- <a href="classes/AesAlg.html#M000005">xor (AesAlg)</a><br />
23
+ <a href="classes/Aes.html#M000005">bs (Aes)</a><br />
24
+ <a href="classes/Aes.html#M000006">bs= (Aes)</a><br />
25
+ <a href="classes/Aes.html#M000008">check_iv (Aes)</a><br />
26
+ <a href="classes/Aes.html#M000007">check_key (Aes)</a><br />
27
+ <a href="classes/Aes.html#M000010">check_kl (Aes)</a><br />
28
+ <a href="classes/Aes.html#M000009">check_mode (Aes)</a><br />
29
+ <a href="classes/Aes.html#M000013">decrypt_block (Aes)</a><br />
30
+ <a href="classes/AesShared.html#M000002">decrypt_blocks (AesShared)</a><br />
31
+ <a href="classes/Aes.html#M000015">decrypt_buffer (Aes)</a><br />
32
+ <a href="classes/AesShared.html#M000004">decrypt_buffer (AesShared)</a><br />
33
+ <a href="classes/Aes.html#M000017">decrypt_stream (Aes)</a><br />
34
+ <a href="classes/Aes.html#M000012">encrypt_block (Aes)</a><br />
35
+ <a href="classes/AesShared.html#M000001">encrypt_blocks (AesShared)</a><br />
36
+ <a href="classes/Aes.html#M000014">encrypt_buffer (Aes)</a><br />
37
+ <a href="classes/AesShared.html#M000003">encrypt_buffer (AesShared)</a><br />
38
+ <a href="classes/Aes.html#M000016">encrypt_stream (Aes)</a><br />
39
+ <a href="classes/Aes.html#M000011">init (Aes)</a><br />
49
40
  </div>
50
41
  </div>
51
42
  </body>
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'ruby-aes'
4
5
  require 'example_helper'
5
6
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'ruby-aes'
4
5
  require 'example_helper'
5
6
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'ruby-aes'
4
5
  require 'example_helper'
5
6
  require 'fileutils'
@@ -11,9 +11,11 @@
11
11
  =end
12
12
 
13
13
  require 'ruby-aes/aes_cons'
14
+ require 'ruby-aes/aes_shared'
14
15
 
15
16
  class AesAlg
16
17
  include AesCons
18
+ include AesShared
17
19
 
18
20
  def encryption_key_schedule(key)
19
21
  i = 0
@@ -507,64 +509,6 @@ class AesAlg
507
509
  end
508
510
  end
509
511
 
510
- def encrypt_blocks(buffer)
511
- raise "Bad block length" unless (buffer.length % 16).zero?
512
- ct = ""
513
- block = ""
514
- buffer.each_byte do |char|
515
- block << char
516
- if block.length == 16
517
- ct << encrypt_block(block)
518
- block = ""
519
- end
520
- end
521
- end
522
-
523
- def decrypt_blocks(buffer)
524
- raise "Bad block length" unless (buffer.length % 16).zero?
525
- pt = ""
526
- block = ""
527
- buffer.each_byte do |char|
528
- block << char
529
- if block.length == 16
530
- pt << decrypt_block(block)
531
- block = ""
532
- end
533
- end
534
- end
535
-
536
- def encrypt_buffer(buffer)
537
- ct = ""
538
- block = ""
539
- buffer.each_byte do |char|
540
- block << char
541
- if block.length == 16
542
- ct << encrypt_block(block)
543
- block = ""
544
- end
545
- end
546
- m = 16 - block.length % 16
547
- ct << (m == 16 ? 0 : encrypt_block(block << m.chr * m))
548
- end
549
-
550
- def decrypt_buffer(buffer)
551
- pt = ""
552
- block = ""
553
- buffer.each_byte do |char|
554
- block << char
555
- if block.length == 16
556
- pt << decrypt_block(block)
557
- block = ""
558
- end
559
- end
560
- if block.length == 0
561
- c = pt[-1]
562
- c.chr * c == pt[-c..-1] ? pt[0..-(c+1)] : (raise "Bad Block Padding")
563
- else
564
- pt
565
- end
566
- end
567
-
568
512
  def init(key_length, mode, key, iv = nil)
569
513
  @nb = 4
570
514
  @ek = []
@@ -0,0 +1,77 @@
1
+ =begin
2
+ This file is a part of ruby-aes <http://rubyforge.org/projects/ruby-aes>
3
+ Written by Alex Boussinet <alex.boussinet@gmail.com>
4
+
5
+ It contains the code shared by all the implementations
6
+ =end
7
+
8
+ module AesShared
9
+ def encrypt_blocks(buffer)
10
+ raise "Bad block length" unless (buffer.length % 16).zero?
11
+ ct = ""
12
+ block = ""
13
+ buffer.each_byte do |char|
14
+ block << char
15
+ if block.length == 16
16
+ ct << encrypt_block(block)
17
+ block = ""
18
+ end
19
+ end
20
+ ct
21
+ end
22
+
23
+ def decrypt_blocks(buffer)
24
+ raise "Bad block length" unless (buffer.length % 16).zero?
25
+ pt = ""
26
+ block = ""
27
+ buffer.each_byte do |char|
28
+ block << char
29
+ if block.length == 16
30
+ pt << decrypt_block(block)
31
+ block = ""
32
+ end
33
+ end
34
+ pt
35
+ end
36
+
37
+ def encrypt_buffer(buffer)
38
+ ct = ""
39
+ block = ""
40
+ buffer.each_byte do |char|
41
+ block << char
42
+ if block.length == 16
43
+ ct << encrypt_block(block)
44
+ block = ""
45
+ end
46
+ end
47
+ c = "\000"
48
+ if (m = 16 - block.length % 16) != 16
49
+ c = m.chr
50
+ ct << encrypt_block(block << c * m)
51
+ end
52
+ ct << c
53
+ end
54
+
55
+ def decrypt_buffer(buffer)
56
+ pt = ""
57
+ block = ""
58
+ buffer.each_byte do |char|
59
+ block << char
60
+ if block.length == 16
61
+ pt << decrypt_block(block)
62
+ block = ""
63
+ end
64
+ end
65
+ if block.length != 1
66
+ raise 'Bad Block Padding'
67
+ elsif (c = block[-1]).zero?
68
+ pt
69
+ else
70
+ if block * c == pt[-c..-1]
71
+ pt[0..-c-1]
72
+ else
73
+ raise "Bad Block Padding"
74
+ end
75
+ end
76
+ end
77
+ end