ruby-mcrypt 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Manifest +14 -0
- data/README.rdoc +84 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/ext/.gitignore +8 -0
- data/ext/extconf.rb +46 -0
- data/ext/mcrypt_wrapper.c +588 -0
- data/lib/.gitignore +3 -0
- data/lib/mcrypt.rb +472 -0
- data/ruby-mcrypt.gemspec +147 -0
- data/test/generate/.gitignore +3 -0
- data/test/generate/Makefile +11 -0
- data/test/generate/generate_testcases.c +389 -0
- data/test/helper.rb +13 -0
- data/test/test_basics.rb +216 -0
- data/test/test_brute.rb +3386 -0
- data/test/test_reciprocity.rb +50 -0
- metadata +174 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__),"helper.rb")
|
4
|
+
|
5
|
+
class McryptReciprocityTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def generate(len)
|
8
|
+
"0" * len
|
9
|
+
end
|
10
|
+
|
11
|
+
def make_mcrypt(algo,mode,padding)
|
12
|
+
mc = Mcrypt.new(algo,mode)
|
13
|
+
mc.key = generate(mc.key_size)
|
14
|
+
mc.iv = generate(mc.iv_size) if mc.has_iv?
|
15
|
+
mc.padding = padding
|
16
|
+
mc
|
17
|
+
end
|
18
|
+
|
19
|
+
# test a few algorithms
|
20
|
+
# with both stream and block modes,
|
21
|
+
# with different padding implementations
|
22
|
+
# with different input sizes
|
23
|
+
# with on-boundary and off-boundary
|
24
|
+
|
25
|
+
[:tripledes,:twofish,:rijndael_256].each do |algorithm|
|
26
|
+
[:cbc, :cfb, :ecb].each do |mode|
|
27
|
+
[:zeros,:pkcs,:none].each do |padding_type|
|
28
|
+
[1,2,3].each do |blocks|
|
29
|
+
|
30
|
+
define_method("test_#{algorithm}_#{mode}_#{padding_type}_#{blocks}_on_boundary") do
|
31
|
+
mc = make_mcrypt(algorithm,mode,padding_type)
|
32
|
+
plaintext = generate(mc.block_size * blocks)
|
33
|
+
assert_equal plaintext, mc.decrypt(mc.encrypt(plaintext))
|
34
|
+
end
|
35
|
+
|
36
|
+
# off-boundary only works without padding for stream modes
|
37
|
+
if padding_type != :none || Mcrypt.stream_mode?(mode)
|
38
|
+
define_method("test_#{algorithm}_#{mode}_#{padding_type}_#{blocks}_off_boundary") do
|
39
|
+
mc = make_mcrypt(algorithm,mode,padding_type)
|
40
|
+
plaintext = generate((mc.block_size * blocks) - 1)
|
41
|
+
assert_equal plaintext, mc.decrypt(mc.encrypt(plaintext))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-mcrypt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Philip Garrett
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-23 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |
|
23
|
+
= Mcrypt - libmcrypt bindings for Ruby
|
24
|
+
|
25
|
+
Mcrypt provides Ruby-language bindings for libmcrypt(3), a
|
26
|
+
symmetric cryptography library. {Libmcrypt}[http://mcrypt.sourceforge.net/]
|
27
|
+
supports lots of different ciphers and encryption modes.
|
28
|
+
|
29
|
+
== You will need
|
30
|
+
|
31
|
+
* A working Ruby installation (>= 1.8.6 or 1.9)
|
32
|
+
* A working libmcrypt installation (2.5.x or 2.6.x, tested with 2.5.8)
|
33
|
+
* A sane build environment
|
34
|
+
|
35
|
+
== Installation
|
36
|
+
|
37
|
+
Install the gem:
|
38
|
+
gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
|
39
|
+
|
40
|
+
If you want to run the longer test suite, do this instead:
|
41
|
+
MCRYPT_TEST_BRUTE=1 \
|
42
|
+
gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
|
43
|
+
|
44
|
+
Put this in your code:
|
45
|
+
require 'rubygems'
|
46
|
+
require 'mcrypt'
|
47
|
+
|
48
|
+
Or in Rails' environment.rb:
|
49
|
+
gem "ruby-mcrypt", :lib => "mcrypt"
|
50
|
+
|
51
|
+
== Usage
|
52
|
+
|
53
|
+
crypto = Mcrypt.new(:twofish, :cbc, MY_KEY, MY_IV, :pkcs)
|
54
|
+
|
55
|
+
# encryption and decryption in one step
|
56
|
+
ciphertext = crypto.encrypt(plaintext)
|
57
|
+
plaintext = crypto.decrypt(ciphertext)
|
58
|
+
|
59
|
+
# encrypt in smaller steps
|
60
|
+
while chunk = $stdin.read(4096)
|
61
|
+
$stdout << crypto.encrypt_more(chunk)
|
62
|
+
end
|
63
|
+
$stdout << crypto.encrypt_finish
|
64
|
+
|
65
|
+
# or decrypt:
|
66
|
+
while chunk = $stdin.read(4096)
|
67
|
+
$stdout << crypto.decrypt_more(chunk)
|
68
|
+
end
|
69
|
+
$stdout << crypto.decrypt_finish
|
70
|
+
|
71
|
+
== Known Issues
|
72
|
+
|
73
|
+
* Test coverage is lacking.
|
74
|
+
|
75
|
+
If you find any bugs, please let the author know.
|
76
|
+
|
77
|
+
== Wish List
|
78
|
+
|
79
|
+
* IO-like behavior, e.g. crypto.open($stdin) { |stream| ... }
|
80
|
+
|
81
|
+
== Author
|
82
|
+
|
83
|
+
* Philip Garrett <philgarr at gmail.com>
|
84
|
+
|
85
|
+
== Copyright and License
|
86
|
+
|
87
|
+
Copyright (c) 2009-2010 Philip Garrett.
|
88
|
+
|
89
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
90
|
+
copy of this software and associated documentation files (the
|
91
|
+
"Software"), to deal in the Software without restriction, including
|
92
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
93
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
94
|
+
permit persons to whom the Software is furnished to do so, subject to
|
95
|
+
the following conditions:
|
96
|
+
|
97
|
+
The above copyright notice and this permission notice shall be included
|
98
|
+
in all copies or substantial portions of the Software.
|
99
|
+
|
100
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
101
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
102
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
103
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
104
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
105
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
106
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
107
|
+
|
108
|
+
email: philgarr@gmail.com
|
109
|
+
executables: []
|
110
|
+
|
111
|
+
extensions:
|
112
|
+
- ext/extconf.rb
|
113
|
+
extra_rdoc_files:
|
114
|
+
- README.rdoc
|
115
|
+
files:
|
116
|
+
- .gitignore
|
117
|
+
- Manifest
|
118
|
+
- README.rdoc
|
119
|
+
- Rakefile
|
120
|
+
- VERSION
|
121
|
+
- ext/.gitignore
|
122
|
+
- ext/extconf.rb
|
123
|
+
- ext/mcrypt_wrapper.c
|
124
|
+
- lib/.gitignore
|
125
|
+
- lib/mcrypt.rb
|
126
|
+
- ruby-mcrypt.gemspec
|
127
|
+
- test/generate/.gitignore
|
128
|
+
- test/generate/Makefile
|
129
|
+
- test/generate/generate_testcases.c
|
130
|
+
- test/helper.rb
|
131
|
+
- test/test_basics.rb
|
132
|
+
- test/test_brute.rb
|
133
|
+
- test/test_reciprocity.rb
|
134
|
+
has_rdoc: true
|
135
|
+
homepage: http://github.com/kingpong/ruby-mcrypt
|
136
|
+
licenses: []
|
137
|
+
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options:
|
140
|
+
- --charset=UTF-8
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 59
|
149
|
+
segments:
|
150
|
+
- 1
|
151
|
+
- 8
|
152
|
+
- 6
|
153
|
+
version: 1.8.6
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
hash: 3
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
version: "0"
|
163
|
+
requirements:
|
164
|
+
- libmcrypt (2.5.x or 2.6.x, tested with 2.5.8)
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.3.7
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Ruby bindings for libmcrypt
|
170
|
+
test_files:
|
171
|
+
- test/helper.rb
|
172
|
+
- test/test_basics.rb
|
173
|
+
- test/test_brute.rb
|
174
|
+
- test/test_reciprocity.rb
|