rc6 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +13 -0
- data/ext/rc6/extconf.rb +3 -0
- data/ext/rc6/rc6.c +249 -0
- data/ext/rc6/rc6.h +54 -0
- data/lib/rc6.rb +8 -0
- data/lib/rc6/version.rb +3 -0
- data/rc6.gemspec +27 -0
- data/spec/rc6_spec.rb +126 -0
- data/spec/spec_helper.rb +2 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9226c03923c8234fd3bff49bb26fabf4820f6d1e
|
4
|
+
data.tar.gz: 414bf65ae4bd5bb231d32647f114d3dbeb82da72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfb0f8c3a6377938b05bc111f1331b1af7606e4a9ad2b8ae5b8669e2cb1cf5fac18cf1f198b96fedcf29872997cf4bcd6ed8451802696361d8dfd70119075067
|
7
|
+
data.tar.gz: a86b6fd2a31fa8090e58589e21870749713b707083c52e24832f4280c09cbe609b2f005dc2fdb6c06cff71554b479d0f832d71b6f17c044bc35574b1d5498376
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Bartosz J
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
[![Travis CI ](http://img.shields.io/travis/lolet/rc6/master.svg) ](https://travis-ci.org/lolet/rc6)
|
2
|
+
# Rc6
|
3
|
+
|
4
|
+
TODO: Write a gem description
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rc6'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rc6
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/lolet/rc6/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ext/rc6/extconf.rb
ADDED
data/ext/rc6/rc6.c
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
/* rc6.c */
|
2
|
+
/*
|
3
|
+
This file is part of the AVR-Crypto-Lib.
|
4
|
+
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
5
|
+
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU General Public License as published by
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU General Public License
|
17
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
*/
|
19
|
+
/*
|
20
|
+
* File: rc6.c
|
21
|
+
* Author: Daniel Otte
|
22
|
+
* Date: 06.08.2006
|
23
|
+
* License: GPL
|
24
|
+
* Description: Implementation of the RC6 cipher algorithm.
|
25
|
+
* This implementation is restricted to 32-bit words and to keys up to 65535 bit in length (but this is
|
26
|
+
* quite easy to expand), but free in the choice of number of rounds (0 to 125).
|
27
|
+
* so it is RC6-32/r/b
|
28
|
+
* THIS ONLY WORKS FOR LITTLE ENDIAN!!!
|
29
|
+
*/
|
30
|
+
|
31
|
+
//#include <stdint.h>
|
32
|
+
//#include <stdlib.h>
|
33
|
+
#include <ruby.h>
|
34
|
+
#include "rc6.h"
|
35
|
+
|
36
|
+
#define P32 0xB7E15163 /* e -2 */
|
37
|
+
#define Q32 0x9E3779B9 /* Golden Ratio -1 */
|
38
|
+
|
39
|
+
uint32_t rotl32(uint32_t a, uint8_t n){
|
40
|
+
n &= 0x1f; /* higher rotates would not bring anything */
|
41
|
+
return ( (a<<n)| (a>>(32-n)) );
|
42
|
+
}
|
43
|
+
|
44
|
+
uint32_t rotr32(uint32_t a, uint8_t n){
|
45
|
+
n &= 0x1f; /* higher rotates would not bring anything */
|
46
|
+
return ( (a>>n)| (a<<(32-n)) );
|
47
|
+
}
|
48
|
+
|
49
|
+
void Init_rc6() {
|
50
|
+
VALUE c = rb_define_class("RC6", rb_cObject);
|
51
|
+
|
52
|
+
rb_define_alloc_func(c, method_rc6_alloc);
|
53
|
+
|
54
|
+
rb_define_method(c, "initialize", RUBY_METHOD_FUNC(method_rc6_init), 1);
|
55
|
+
rb_define_method(c, "decrypt!", RUBY_METHOD_FUNC(method_rc6_dec_bang), 1);
|
56
|
+
rb_define_method(c, "decrypt", RUBY_METHOD_FUNC(method_rc6_dec), 1);
|
57
|
+
rb_define_method(c, "encrypt!", RUBY_METHOD_FUNC(method_rc6_enc_bang), 1);
|
58
|
+
rb_define_method(c, "encrypt", RUBY_METHOD_FUNC(method_rc6_enc), 1);
|
59
|
+
rb_define_method(c, "key", RUBY_METHOD_FUNC(method_rc6_key), 0);
|
60
|
+
}
|
61
|
+
|
62
|
+
rc6_ctx_t* get_context(VALUE self) {
|
63
|
+
rc6_ctx_t* p;
|
64
|
+
Data_Get_Struct(self, rc6_ctx_t, p);
|
65
|
+
return p;
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
VALUE method_rc6_key(VALUE self) {
|
70
|
+
rc6_ctx_t* context = get_context(self);
|
71
|
+
VALUE key = rb_ary_new2(44);
|
72
|
+
int i;
|
73
|
+
for(i=0;i<44;++i)
|
74
|
+
rb_ary_store(key, i, INT2FIX(context->s[i]));
|
75
|
+
|
76
|
+
return key;
|
77
|
+
}
|
78
|
+
|
79
|
+
void method_rc6_free(rc6_ctx_t* context) {
|
80
|
+
free(context);
|
81
|
+
}
|
82
|
+
|
83
|
+
VALUE method_rc6_alloc(VALUE self) {
|
84
|
+
return Data_Wrap_Struct(self, NULL, method_rc6_free, calloc(1, sizeof(rc6_ctx_t)));
|
85
|
+
}
|
86
|
+
|
87
|
+
VALUE method_rc6_init(VALUE self, VALUE key) {
|
88
|
+
Check_Type(key, T_STRING);
|
89
|
+
rc6_ctx_t* context = get_context(self);
|
90
|
+
|
91
|
+
rc6_initl(StringValuePtr (key), 256, 20, context);
|
92
|
+
|
93
|
+
return self;
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
uint8_t rc6_initl(void* key, uint16_t keylength_b, uint8_t rounds, rc6_ctx_t *s){
|
98
|
+
uint8_t i,j;
|
99
|
+
uint16_t v,p,c;
|
100
|
+
uint32_t a,b, l=0;
|
101
|
+
|
102
|
+
s->rounds=rounds;
|
103
|
+
|
104
|
+
c = keylength_b/32;
|
105
|
+
if (keylength_b%32) {
|
106
|
+
++c;
|
107
|
+
j=(keylength_b%32)/8;
|
108
|
+
if(keylength_b%8)
|
109
|
+
++j;
|
110
|
+
|
111
|
+
for (i=0; i<j; ++i)
|
112
|
+
((uint8_t*)&l)[i] = ((uint8_t*)key)[(c-1)*4 + i];
|
113
|
+
} else {
|
114
|
+
l = ((uint32_t*)key)[c-1];
|
115
|
+
}
|
116
|
+
|
117
|
+
s->s[0] = P32;
|
118
|
+
for(i=1; i<2*rounds+4; ++i){
|
119
|
+
s->s[i] = s->s[i-1] + Q32;
|
120
|
+
}
|
121
|
+
|
122
|
+
a=b=j=i=0;
|
123
|
+
v = 3 * ((c > 2*rounds+4)?c:(2*rounds+4));
|
124
|
+
|
125
|
+
for(p=1; p<=v; ++p){
|
126
|
+
a = s->s[i] = rotl32(s->s[i] + a + b, 3);
|
127
|
+
if (j==c-1){
|
128
|
+
b = l = rotl32(l+a+b, a+b);
|
129
|
+
} else {
|
130
|
+
b = ((uint32_t*)key)[j] = rotl32(((uint32_t*)key)[j]+a+b, a+b);
|
131
|
+
}
|
132
|
+
i = (i+1) % (2*rounds+4);
|
133
|
+
j = (j+1) % c;
|
134
|
+
}
|
135
|
+
|
136
|
+
return 1;
|
137
|
+
}
|
138
|
+
|
139
|
+
#define LG_W 5
|
140
|
+
#define A (((uint32_t*)block)[0])
|
141
|
+
#define B (((uint32_t*)block)[1])
|
142
|
+
#define C (((uint32_t*)block)[2])
|
143
|
+
#define D (((uint32_t*)block)[3])
|
144
|
+
|
145
|
+
VALUE method_rc6_enc(VALUE self, VALUE data) {
|
146
|
+
VALUE str = rb_str_dup(data);
|
147
|
+
rb_str_modify(str);
|
148
|
+
return method_rc6_enc_bang(self, str);
|
149
|
+
}
|
150
|
+
|
151
|
+
VALUE method_rc6_dec(VALUE self, VALUE data) {
|
152
|
+
VALUE str = rb_str_dup(data);
|
153
|
+
rb_str_modify(str);
|
154
|
+
return method_rc6_dec_bang(self, str);
|
155
|
+
}
|
156
|
+
|
157
|
+
VALUE method_rc6_enc_bang(VALUE self, VALUE data) {
|
158
|
+
rc6_ctx_t* ctx = get_context(self);
|
159
|
+
int i;
|
160
|
+
|
161
|
+
int str_len = RSTRING_LEN(data);
|
162
|
+
char* str = RSTRING_PTR(data);
|
163
|
+
char* end = RSTRING_END(data);
|
164
|
+
rb_str_modify(data);
|
165
|
+
|
166
|
+
if (rb_block_given_p()) {
|
167
|
+
while(str<end) {
|
168
|
+
priv_rc6_enc(ctx, str);
|
169
|
+
rb_yield(rb_tainted_str_new(str, 16));
|
170
|
+
str += 16;
|
171
|
+
}
|
172
|
+
} else {
|
173
|
+
|
174
|
+
while(str<end) {
|
175
|
+
priv_rc6_enc(ctx, str);
|
176
|
+
str+=16;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
return data;
|
180
|
+
}
|
181
|
+
|
182
|
+
VALUE method_rc6_dec_bang(VALUE self, VALUE data) {
|
183
|
+
rc6_ctx_t* ctx = get_context(self);
|
184
|
+
int i;
|
185
|
+
|
186
|
+
int str_len = RSTRING_LEN(data);
|
187
|
+
char* str = RSTRING_PTR(data);
|
188
|
+
char* end = RSTRING_END(data);
|
189
|
+
|
190
|
+
rb_str_modify(data);
|
191
|
+
|
192
|
+
if (rb_block_given_p()) {
|
193
|
+
while(str<end) {
|
194
|
+
priv_rc6_dec(ctx, str);
|
195
|
+
rb_yield(rb_tainted_str_new(str, 16));
|
196
|
+
str += 16;
|
197
|
+
}
|
198
|
+
} else {
|
199
|
+
while(str<end) {
|
200
|
+
priv_rc6_dec(ctx, str);
|
201
|
+
str+=16;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
return data;
|
205
|
+
}
|
206
|
+
|
207
|
+
VALUE priv_rc6_enc(rc6_ctx_t* context, void* block) {
|
208
|
+
uint8_t i;
|
209
|
+
uint32_t t,u,x; /* greetings to Linux? */
|
210
|
+
B += context->s[0];
|
211
|
+
D += context->s[1];
|
212
|
+
for (i=1; i<=20; ++i){
|
213
|
+
t = rotl32(B * (2*B+1), LG_W);
|
214
|
+
u = rotl32(D * (2*D+1), LG_W);
|
215
|
+
A = rotl32((A ^ t), u) + context->s[2*i];
|
216
|
+
C = rotl32((C ^ u), t) + context->s[2*i+1];
|
217
|
+
x = A;
|
218
|
+
A = B;
|
219
|
+
B = C;
|
220
|
+
C = D;
|
221
|
+
D = x;
|
222
|
+
}
|
223
|
+
A += context->s[42];
|
224
|
+
C += context->s[43];
|
225
|
+
return Qnil;
|
226
|
+
}
|
227
|
+
|
228
|
+
VALUE priv_rc6_dec(rc6_ctx_t* context, void* block) {
|
229
|
+
uint8_t i;
|
230
|
+
uint32_t t,u,x; /* greetings to Linux? */
|
231
|
+
|
232
|
+
C -= context->s[43];
|
233
|
+
A -= context->s[42];
|
234
|
+
|
235
|
+
for (i=20; i>0; --i){
|
236
|
+
x=D;
|
237
|
+
D=C;
|
238
|
+
C=B;
|
239
|
+
B=A;
|
240
|
+
A=x;
|
241
|
+
u = rotl32(D * (2*D+1), LG_W);
|
242
|
+
t = rotl32(B * (2*B+1), LG_W);
|
243
|
+
C = rotr32(C - context->s[2*i+1], t) ^ u;
|
244
|
+
A = rotr32(A - context->s[2*i+0], u) ^ t;
|
245
|
+
}
|
246
|
+
D -= context->s[1];
|
247
|
+
B -= context->s[0];
|
248
|
+
return Qnil;
|
249
|
+
}
|
data/ext/rc6/rc6.h
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
/* rc6.h */
|
2
|
+
/*
|
3
|
+
This file is part of the AVR-Crypto-Lib.
|
4
|
+
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
*/
|
16
|
+
/*
|
17
|
+
* File: rc6.h
|
18
|
+
* Author: Daniel Otte
|
19
|
+
* Date: 06.08.2006
|
20
|
+
* License: GPL
|
21
|
+
* Description: Implementation of the RC6 cipher algorithm.
|
22
|
+
* This implementation is restricted to 32-bit words, but free in the choice of number of rounds (0 to 255).
|
23
|
+
* so it is RC6-32/r/b
|
24
|
+
*/
|
25
|
+
|
26
|
+
#ifndef RC6_H_
|
27
|
+
#define RC6_H_
|
28
|
+
|
29
|
+
|
30
|
+
#include <stdint.h>
|
31
|
+
|
32
|
+
typedef struct rc6_ctx_st{
|
33
|
+
uint8_t rounds; /* specifys the number of rounds; default: 20 */
|
34
|
+
uint32_t s[44]; /* the round-keys */
|
35
|
+
} rc6_ctx_t;
|
36
|
+
|
37
|
+
extern void Init_rc6();
|
38
|
+
|
39
|
+
VALUE method_rc6_alloc(VALUE);
|
40
|
+
VALUE method_rc6_init(VALUE, VALUE);
|
41
|
+
VALUE method_rc6_enc(VALUE, VALUE);
|
42
|
+
VALUE method_rc6_dec(VALUE, VALUE);
|
43
|
+
|
44
|
+
VALUE method_rc6_enc_bang(VALUE, VALUE);
|
45
|
+
VALUE method_rc6_dec_bang(VALUE, VALUE);
|
46
|
+
|
47
|
+
VALUE priv_rc6_dec(rc6_ctx_t* context, void* block);
|
48
|
+
VALUE priv_rc6_enc(rc6_ctx_t* context, void* block);
|
49
|
+
|
50
|
+
VALUE method_rc6_key(VALUE self);
|
51
|
+
|
52
|
+
uint8_t rc6_initl(void* key, uint16_t keylength_b, uint8_t rounds, rc6_ctx_t *s);
|
53
|
+
|
54
|
+
#endif /* RC6_H_ */
|
data/lib/rc6.rb
ADDED
data/lib/rc6/version.rb
ADDED
data/rc6.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rc6/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rc6"
|
8
|
+
spec.version = RC6::VERSION
|
9
|
+
spec.authors = ["Daniel Otte, Bartosz J"]
|
10
|
+
spec.email = ["daniel.otte@rub.de, thug1337@gmail.com"]
|
11
|
+
spec.summary = %q{RC6 algorithm implementation}
|
12
|
+
spec.description = %q{Fast RC6 decrypt/encrypt using C extension}
|
13
|
+
spec.homepage = "https://github.com/lolet/rc6"
|
14
|
+
spec.license = "GPL"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
|
18
|
+
spec.extensions << "ext/rc6/extconf.rb"
|
19
|
+
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rake-compiler", "~> 0.9"
|
26
|
+
spec.add_development_dependency "rspec", ">= 2.0.0"
|
27
|
+
end
|
data/spec/rc6_spec.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RC6 do
|
4
|
+
describe '#new' do
|
5
|
+
it 'generates correct context' do
|
6
|
+
rc6 = RC6.new("\0"*31 << "i")
|
7
|
+
expect(rc6.key).to eq([3028870244,3572793723,3718327545,2726201800,
|
8
|
+
1247684175,706195997,2532830521,2555503768,1804502253,2040750103,
|
9
|
+
534494623,1010195888,2475051698,2466917687,252861082,2876697921,
|
10
|
+
1110747983,3412282497,667888956,2113937431,3632818329,2833139191,
|
11
|
+
1317379001,260718507,1024561575,1673043788,4153311956,4195457914,
|
12
|
+
2971504219,3768094437,3017059175,386042906,1264709844,997561140,
|
13
|
+
84212114,704386172,233373835,2030293242,187823311,1758555660,
|
14
|
+
3987267664,2025083350,2035471614,3977062027])
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#encrypt!' do
|
20
|
+
rc6 = RC6.new("\0"*31 << "i")
|
21
|
+
|
22
|
+
it 'encrypts and decrypts a random string of block length' do
|
23
|
+
10.times do
|
24
|
+
sample = (0...16).map{65.+(rand(25)).chr}.join
|
25
|
+
decoded_hash = sample.hash
|
26
|
+
rc6.encrypt!(sample)
|
27
|
+
expect(sample.hash).not_to eq decoded_hash
|
28
|
+
|
29
|
+
rc6.decrypt!(sample)
|
30
|
+
expect(sample.hash).to eq decoded_hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it 'encrypts and decrypts a random string of random length' do
|
34
|
+
10.times do |n|
|
35
|
+
rand_size = rand(128)
|
36
|
+
rand_size+= 16 - (rand_size % 16) # align size to block size
|
37
|
+
sample = (0...rand_size).map{65.+(rand(25)).chr}.join
|
38
|
+
decoded_hash = sample.hash
|
39
|
+
rc6.encrypt!(sample)
|
40
|
+
expect(sample.hash).not_to eq decoded_hash
|
41
|
+
|
42
|
+
rc6.decrypt!(sample)
|
43
|
+
expect(sample.hash).to eq decoded_hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#encrypt' do
|
49
|
+
rc6 = RC6.new("\0"*31 << "i")
|
50
|
+
it 'encrypts and decrypts a random string of block length' do
|
51
|
+
10.times do
|
52
|
+
sample = (0...16).map{65.+(rand(25)).chr}.join
|
53
|
+
coded = rc6.encrypt(sample)
|
54
|
+
expect(coded.hash).not_to eq sample.hash
|
55
|
+
|
56
|
+
decoded = rc6.decrypt(coded)
|
57
|
+
expect(sample.hash).to eq decoded.hash
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it 'encrypts and decrypts a random string of random length' do
|
61
|
+
10.times do |n|
|
62
|
+
rand_size = rand(128)
|
63
|
+
rand_size+= 16 - (rand_size % 16) # align size to block size
|
64
|
+
sample = (0...rand_size).map{65.+(rand(25)).chr}.join
|
65
|
+
coded = rc6.encrypt(sample)
|
66
|
+
expect(coded.hash).not_to eq sample.hash
|
67
|
+
|
68
|
+
decoded = rc6.decrypt(coded)
|
69
|
+
expect(sample.hash).to eq decoded.hash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#decrypt!' do
|
75
|
+
rc6 = RC6.new("\0"*31 << "i")
|
76
|
+
|
77
|
+
it 'decrypts image header using block' do
|
78
|
+
hdr_en = "\x2A\x99\xA2\x80\x46\xD0\x63\x98\x24\xA2\x62\x04\x93\x1E\x03" <<
|
79
|
+
"\x95\x6D\x62\xC1\x0B\xFD\x68\x41\xEE\xC4\xA3\x55\xAD\xCF\x96" <<
|
80
|
+
"\x8B\xF5\x14\x4A\xD3\x68\x69\xC3\x4D\xA3\xA2\x9B\x3C\xAE\x35" <<
|
81
|
+
"\x59\x90\x1B\x3C\xEF\x39\x50\x7E\x3E\x1E\x87\xB2\x6B\x17\xF1" <<
|
82
|
+
"\x01\x2C\xCF\xB0\xBD\xB3\xAF\x19\x7D\x3C\x55\x5B\x63\x62\x5D" <<
|
83
|
+
"\x20\x43\x7A\x37\x2C\x14\x77\xDF\xB9\x8C\xAC\xCE\x2F\xBA\x11" <<
|
84
|
+
"\x98\xAE\x59\x40\x53\xBB"
|
85
|
+
hdr_de = "\x49\x4d\x41\x47\x45\x57\x54\x59\x00\x01\x00\x00\x50\x00\x00" <<
|
86
|
+
"\x00\x00\x00\xd0\x04\x34\x02\x10\x00\x00\xe8\xa5\x17\x00\x04" <<
|
87
|
+
"\x00\x00\x34\x12\x00\x00\x43\x87\x00\x00\x00\x01\x00\x00\x00" <<
|
88
|
+
"\x01\x00\x00\x01\x00\x00\x00\x00\x04\x00\x00\x29\x00\x00\x00" <<
|
89
|
+
"\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" <<
|
90
|
+
"\x00\x00\x00\x00\x00\x69\x6d\x67\x52\x65\x50\x61\x63\x6b\x65" <<
|
91
|
+
"\x72\x20\x20\x20\x20\x20"
|
92
|
+
test_de = String.new
|
93
|
+
rc6.decrypt!(hdr_en) do |str|
|
94
|
+
test_de << str
|
95
|
+
end
|
96
|
+
expect(test_de.b).to eq hdr_de.b
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#decrypt' do
|
101
|
+
rc6 = RC6.new("\0"*31 << "i")
|
102
|
+
|
103
|
+
it 'decrypts image header using block' do
|
104
|
+
hdr_en = "\x2A\x99\xA2\x80\x46\xD0\x63\x98\x24\xA2\x62\x04\x93\x1E\x03" <<
|
105
|
+
"\x95\x6D\x62\xC1\x0B\xFD\x68\x41\xEE\xC4\xA3\x55\xAD\xCF\x96" <<
|
106
|
+
"\x8B\xF5\x14\x4A\xD3\x68\x69\xC3\x4D\xA3\xA2\x9B\x3C\xAE\x35" <<
|
107
|
+
"\x59\x90\x1B\x3C\xEF\x39\x50\x7E\x3E\x1E\x87\xB2\x6B\x17\xF1" <<
|
108
|
+
"\x01\x2C\xCF\xB0\xBD\xB3\xAF\x19\x7D\x3C\x55\x5B\x63\x62\x5D" <<
|
109
|
+
"\x20\x43\x7A\x37\x2C\x14\x77\xDF\xB9\x8C\xAC\xCE\x2F\xBA\x11" <<
|
110
|
+
"\x98\xAE\x59\x40\x53\xBB"
|
111
|
+
hdr_de = "\x49\x4d\x41\x47\x45\x57\x54\x59\x00\x01\x00\x00\x50\x00\x00" <<
|
112
|
+
"\x00\x00\x00\xd0\x04\x34\x02\x10\x00\x00\xe8\xa5\x17\x00\x04" <<
|
113
|
+
"\x00\x00\x34\x12\x00\x00\x43\x87\x00\x00\x00\x01\x00\x00\x00" <<
|
114
|
+
"\x01\x00\x00\x01\x00\x00\x00\x00\x04\x00\x00\x29\x00\x00\x00" <<
|
115
|
+
"\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" <<
|
116
|
+
"\x00\x00\x00\x00\x00\x69\x6d\x67\x52\x65\x50\x61\x63\x6b\x65" <<
|
117
|
+
"\x72\x20\x20\x20\x20\x20"
|
118
|
+
test_de = String.new
|
119
|
+
rc6.decrypt(hdr_en) do |str|
|
120
|
+
test_de << str
|
121
|
+
end
|
122
|
+
expect(test_de.b.hash).to eq hdr_de.b.hash
|
123
|
+
expect(hdr_en.b.hash).not_to eq hdr_de.b.hash
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rc6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Otte, Bartosz J
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.0
|
69
|
+
description: Fast RC6 decrypt/encrypt using C extension
|
70
|
+
email:
|
71
|
+
- daniel.otte@rub.de, thug1337@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/rc6/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- ext/rc6/extconf.rb
|
85
|
+
- ext/rc6/rc6.c
|
86
|
+
- ext/rc6/rc6.h
|
87
|
+
- lib/rc6.rb
|
88
|
+
- lib/rc6/version.rb
|
89
|
+
- rc6.gemspec
|
90
|
+
- spec/rc6_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/lolet/rc6
|
93
|
+
licenses:
|
94
|
+
- GPL
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: RC6 algorithm implementation
|
116
|
+
test_files:
|
117
|
+
- spec/rc6_spec.rb
|
118
|
+
- spec/spec_helper.rb
|