fast-aes 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +110 -0
- data/ext/extconf.rb +11 -0
- data/ext/fast_aes.c +1023 -0
- data/ext/fast_aes.h +66 -0
- data/lib/fast-aes.rb +4 -0
- data/lib/fast_aes_static.rb +8 -0
- data/spec/fast_aes_spec.rb +48 -0
- data/test/benchmark.rb +40 -0
- metadata +63 -0
data/ext/fast_aes.h
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
/*//////////////////////////////////////////////////////////////////////////////
|
2
|
+
////////////////////////////////////////////////////////////////////////////////
|
3
|
+
//
|
4
|
+
// Part of the FastAES Ruby/C library implementation.
|
5
|
+
//
|
6
|
+
// Original implementation: http://www.cycom.se/dl/sbd
|
7
|
+
// File: sbd-1.27.tar.gz
|
8
|
+
//
|
9
|
+
// This Ruby extension, which is a derivitive work from Christophe Devine's original
|
10
|
+
// AEScrypt optimized C sources, provides an implementation of the United States
|
11
|
+
// Government's Advanced Encryption Standard (AES) (aka "Rijndael" algorithm).
|
12
|
+
// This is a 256-bit private-key block cipher written entirely in C for maximum
|
13
|
+
// portability across a perverse number of target architectures.
|
14
|
+
//
|
15
|
+
// The Rijndael algorithm is 100% patent-free and completely unencumbered in any
|
16
|
+
// way, much unlike the RSA algorithms used in other software. We can use this
|
17
|
+
// cipher.
|
18
|
+
//
|
19
|
+
////////////////////////////////////////////////////////////////////////////////
|
20
|
+
//////////////////////////////////////////////////////////////////////////////*/
|
21
|
+
#ifndef __fast_aes_h
|
22
|
+
#define __fast_aes_h
|
23
|
+
|
24
|
+
/* structure to store our key and keysize */
|
25
|
+
typedef struct {
|
26
|
+
char key[256]; /* max key is 256 */
|
27
|
+
int key_bits; /* 128, 192, 256 */
|
28
|
+
|
29
|
+
/* Encryption Round Keys */
|
30
|
+
unsigned int erk[64];
|
31
|
+
unsigned int initial_erk[64];
|
32
|
+
|
33
|
+
/* Decryption Round Keys */
|
34
|
+
unsigned int drk[64];
|
35
|
+
unsigned int initial_drk[64];
|
36
|
+
|
37
|
+
/* Number of rounds. */
|
38
|
+
int nr;
|
39
|
+
} fast_aes_t;
|
40
|
+
|
41
|
+
/* functions */
|
42
|
+
void Init_fast_aes();
|
43
|
+
VALUE fast_aes_alloc(VALUE klass);
|
44
|
+
VALUE fast_aes_initialize(VALUE self, VALUE key);
|
45
|
+
void fast_aes_gen_tables();
|
46
|
+
int fast_aes_initialize_state(fast_aes_t* fast_aes_config);
|
47
|
+
VALUE fast_aes_key(VALUE self);
|
48
|
+
|
49
|
+
/* garbage collection */
|
50
|
+
void fast_aes_mark(fast_aes_t* fast_aes_config);
|
51
|
+
void fast_aes_free(fast_aes_t* fast_aes_config);
|
52
|
+
void fast_aes_module_shutdown(fast_aes_t* fast_aes_config);
|
53
|
+
|
54
|
+
/* and actual, bonafide encryption */
|
55
|
+
VALUE fast_aes_encrypt(VALUE self, VALUE buffer);
|
56
|
+
|
57
|
+
VALUE fast_aes_decrypt(VALUE self, VALUE buffer);
|
58
|
+
|
59
|
+
void fast_aes_encrypt_block(fast_aes_t* fast_aes, unsigned char input[16], unsigned char output[16]);
|
60
|
+
void fast_aes_decrypt_block(fast_aes_t* fast_aes, unsigned char input[16], unsigned char output[16]);
|
61
|
+
|
62
|
+
int fast_aes_reinitialize_state();
|
63
|
+
int fast_aes_initialize_state();
|
64
|
+
|
65
|
+
#endif // __fast_aes_h
|
66
|
+
|
data/lib/fast-aes.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../ext/#{RUBY_PLATFORM}"
|
3
|
+
|
4
|
+
describe 'FastAES' do
|
5
|
+
before :all do
|
6
|
+
puts "building extension..."
|
7
|
+
# Build our extension each time
|
8
|
+
Dir.chdir("#{File.dirname(__FILE__)}/../ext") do
|
9
|
+
system "ruby extconf.rb"
|
10
|
+
system "make clean"
|
11
|
+
system "make && make install RUBYARCHDIR=#{RUBY_PLATFORM}"
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'fast-aes'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept 128, 192, and 256-bit keys" do
|
18
|
+
[128, 192, 256].each do |bits|
|
19
|
+
key = 'a' * (bits/8)
|
20
|
+
aes = FastAES.new(key)
|
21
|
+
aes.key.should == key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should encrypt and decrypt messages (what a concept)" do
|
26
|
+
phrases = [
|
27
|
+
'Hey there, how are you?',
|
28
|
+
'You know, encryption is just so gosh-darned cool I wish I had a girlfriend to tell about it!!',
|
29
|
+
'A subject for a great poet would be God\'s boredom after the seventh day of creation.',
|
30
|
+
'The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, '+
|
31
|
+
'you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.',
|
32
|
+
'But although all our knowledge begins with experience, it does not follow that it arises from experience.',
|
33
|
+
'Some with nulls\x00in-between\x00\x00 you know'
|
34
|
+
]
|
35
|
+
|
36
|
+
phrases.each do |text|
|
37
|
+
[128, 192, 256].each do |bits|
|
38
|
+
key = 'a' * (bits/8)
|
39
|
+
aes = FastAES.new(key)
|
40
|
+
aes.key.should == key
|
41
|
+
data = aes.encrypt(text)
|
42
|
+
aes.decrypt(data).should == text
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
data/test/benchmark.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Comparison of AES encryption libraries
|
3
|
+
#
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../ext/#{RUBY_PLATFORM}"
|
6
|
+
|
7
|
+
require 'benchmark'
|
8
|
+
require 'fast_aes'
|
9
|
+
require 'crypt/rijndael'
|
10
|
+
|
11
|
+
CHARS = ('A'..'z').collect{|x| x.to_s}
|
12
|
+
|
13
|
+
def random_key(bits)
|
14
|
+
str = ''
|
15
|
+
(bits/8).times do
|
16
|
+
str += CHARS[rand(CHARS.length)]
|
17
|
+
end
|
18
|
+
str
|
19
|
+
end
|
20
|
+
|
21
|
+
Benchmark.bmbm(20) do |bm|
|
22
|
+
bm.report 'crypt/rijndael' do
|
23
|
+
1000.times do
|
24
|
+
rijndael = Crypt::Rijndael.new(random_key(256))
|
25
|
+
plainBlock = "ABCDEFGH12345678"
|
26
|
+
encryptedBlock = rijndael.encrypt_block(plainBlock)
|
27
|
+
decryptedBlock = rijndael.decrypt_block(encryptedBlock)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
bm.report 'fast_aes' do
|
32
|
+
10000.times do
|
33
|
+
aes = FastAES.new(random_key(256))
|
34
|
+
plainBlock = "ABCDEFGH12345678"
|
35
|
+
encryptedBlock = aes.encrypt(plainBlock)
|
36
|
+
decryptedBlock = aes.decrypt(encryptedBlock)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast-aes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nate Wiger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Fast AES implementation in C. Works with Ruby 1.8 and 1.9.
|
17
|
+
email: nate@wiger.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- ext/extconf.rb
|
26
|
+
- ext/fast_aes.c
|
27
|
+
- ext/fast_aes.h
|
28
|
+
- lib/fast-aes.rb
|
29
|
+
- lib/fast_aes_static.rb
|
30
|
+
- spec/fast_aes_spec.rb
|
31
|
+
- test/benchmark.rb
|
32
|
+
- README.rdoc
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/nateware/fast-aes
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --title
|
40
|
+
- FastAES -- Fast AES implementation for Ruby in C
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: fast-aes
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Fast AES implementation in C. Works with Ruby 1.8 and 1.9
|
62
|
+
test_files: []
|
63
|
+
|