cryptopp 0.0.4 → 0.0.5
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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +14 -0
- data/Guardfile +17 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +20 -27
- data/VERSION +1 -0
- data/cryptopp.gemspec +7 -182
- data/ext/Rakefile +2 -2
- data/ext/ciphers.cpp +619 -619
- data/ext/cryptopp.cpp +220 -217
- data/ext/cryptopp_ruby_api.h +7 -7
- data/ext/defs/hashes.def +16 -0
- data/ext/defs/hmacs.def +16 -0
- data/ext/digests.cpp +635 -601
- data/ext/extconf.rb +61 -19
- data/ext/j3way.cpp +5 -5
- data/ext/j3way.h +6 -6
- data/ext/jadler32.h +6 -6
- data/ext/jaes.cpp +5 -5
- data/ext/jaes.h +6 -6
- data/ext/jarc4.cpp +5 -5
- data/ext/jarc4.h +6 -6
- data/ext/jbase.cpp +94 -94
- data/ext/jbase.h +49 -55
- data/ext/jbasiccipherinfo.h +23 -23
- data/ext/jblowfish.cpp +5 -5
- data/ext/jblowfish.h +6 -6
- data/ext/jcamellia.cpp +5 -7
- data/ext/jcamellia.h +6 -8
- data/ext/jcast128.cpp +5 -5
- data/ext/jcast128.h +6 -6
- data/ext/jcast256.cpp +5 -5
- data/ext/jcast256.h +6 -6
- data/ext/jcipher.cpp +62 -62
- data/ext/jcipher.h +24 -24
- data/ext/jcipher_t.h +383 -383
- data/ext/jconfig.h +29 -46
- data/ext/jconstants.h +120 -122
- data/ext/jcrc32.h +6 -6
- data/ext/jdes.cpp +5 -5
- data/ext/jdes.h +6 -6
- data/ext/jdes_ede2.cpp +5 -5
- data/ext/jdes_ede2.h +6 -6
- data/ext/jdes_ede3.cpp +5 -5
- data/ext/jdes_ede3.h +6 -6
- data/ext/jdes_xex3.cpp +5 -5
- data/ext/jdes_xex3.h +6 -6
- data/ext/jdiamond2.cpp +5 -5
- data/ext/jdiamond2.h +6 -6
- data/ext/jdiamond2lite.cpp +5 -5
- data/ext/jdiamond2lite.h +6 -6
- data/ext/jexception.h +5 -5
- data/ext/jgost.cpp +5 -5
- data/ext/jgost.h +6 -6
- data/ext/jhash.cpp +51 -51
- data/ext/jhash.h +22 -27
- data/ext/jhash_t.h +59 -59
- data/ext/jhaval.h +15 -15
- data/ext/jhelpers.cpp +54 -54
- data/ext/jhelpers.h +3 -3
- data/ext/jhmac.cpp +20 -20
- data/ext/jhmac.h +15 -15
- data/ext/jhmac_t.h +40 -72
- data/ext/jidea.cpp +5 -5
- data/ext/jidea.h +6 -6
- data/ext/jmarc4.cpp +5 -5
- data/ext/jmarc4.h +6 -6
- data/ext/jmars.cpp +5 -5
- data/ext/jmars.h +6 -6
- data/ext/jmd2.h +9 -9
- data/ext/jmd4.h +9 -9
- data/ext/jmd5.h +9 -9
- data/ext/jpanamacipher.cpp +7 -7
- data/ext/jpanamacipher.h +9 -9
- data/ext/jpanamahash.h +9 -9
- data/ext/jrc2.cpp +15 -15
- data/ext/jrc2.h +11 -11
- data/ext/jrc5.cpp +5 -5
- data/ext/jrc5.h +6 -6
- data/ext/jrc6.cpp +5 -5
- data/ext/jrc6.h +6 -6
- data/ext/jripemd160.h +28 -28
- data/ext/jsafer.cpp +7 -7
- data/ext/jsafer.h +9 -9
- data/ext/jseal.cpp +7 -7
- data/ext/jseal.h +9 -9
- data/ext/jserpent.cpp +5 -5
- data/ext/jserpent.h +6 -6
- data/ext/jsha.h +38 -37
- data/ext/jsha3.h +130 -0
- data/ext/jsha3_blocksizes.h +73 -0
- data/ext/jshacal2.cpp +5 -5
- data/ext/jshacal2.h +6 -6
- data/ext/jshark.cpp +5 -7
- data/ext/jshark.h +6 -8
- data/ext/jsink.cpp +57 -57
- data/ext/jsink.h +127 -123
- data/ext/jskipjack.cpp +5 -5
- data/ext/jskipjack.h +6 -6
- data/ext/jsquare.cpp +5 -5
- data/ext/jsquare.h +6 -6
- data/ext/jstream.cpp +3 -3
- data/ext/jstream.h +3 -3
- data/ext/jstream_t.h +74 -126
- data/ext/jtea.cpp +5 -5
- data/ext/jtea.h +6 -6
- data/ext/jtiger.h +9 -11
- data/ext/jtwofish.cpp +5 -5
- data/ext/jtwofish.h +6 -6
- data/ext/jwhirlpool.h +9 -11
- data/ext/utils.cpp +3 -3
- data/extras/parser_c.rb +102 -102
- data/test/ciphers_test.rb +24 -30
- data/test/data/ciphers/3desval.yml +13 -0
- data/test/data/ciphers/3wayval.yml +17 -0
- data/test/data/ciphers/arc4.yml +22 -0
- data/test/data/ciphers/blowfish.yml +9 -0
- data/test/data/ciphers/camellia.yml +21 -0
- data/test/data/ciphers/cast128v.yml +13 -0
- data/test/data/ciphers/cast256v.yml +13 -0
- data/test/data/ciphers/descert.yml +723 -0
- data/test/data/ciphers/diamond.yml +31 -0
- data/test/data/ciphers/gostval.yml +33 -0
- data/test/data/ciphers/ideaval.yml +45 -0
- data/test/data/ciphers/marsval.yml +37 -0
- data/test/data/ciphers/panamac.yml +11 -0
- data/test/data/ciphers/rc2val.yml +49 -0
- data/test/data/ciphers/rc5val.yml +26 -0
- data/test/data/ciphers/rc6val.yml +25 -0
- data/test/data/ciphers/rijndael.yml +37 -0
- data/test/data/ciphers/saferval.yml +77 -0
- data/test/data/ciphers/seal.yml +6 -0
- data/test/data/ciphers/serpentv.yml +37 -0
- data/test/data/ciphers/shacal2.yml +21 -0
- data/test/data/ciphers/sharkval.yml +29 -0
- data/test/data/ciphers/skipjack.yml +5 -0
- data/test/data/ciphers/squareva.yml +33 -0
- data/test/data/ciphers/twofishv.yml +37 -0
- data/test/data/digests/adler32.yml +19 -0
- data/test/data/digests/crc32.yml +25 -0
- data/test/data/digests/haval.yml +7 -0
- data/test/data/digests/havalcer.yml +1 -0
- data/test/data/digests/md2.yml +22 -0
- data/test/data/digests/md4.yml +22 -0
- data/test/data/digests/md5.yml +22 -0
- data/test/data/digests/panamah.yml +13 -0
- data/test/data/digests/ripemd.yml +97 -0
- data/test/data/digests/sha.yml +25 -0
- data/test/data/digests/sha3.yml +23 -0
- data/test/data/digests/tiger.yml +30 -0
- data/test/data/digests/whirlpool.yml +25 -0
- data/test/data/hmacs/hmac.yml +14 -0
- data/test/digests_test.rb +17 -23
- data/test/hmacs_test.rb +25 -31
- data/test/test_helper.rb +31 -37
- metadata +70 -82
- data/test/data/ciphers/3desval.dat +0 -7
- data/test/data/ciphers/3wayval.dat +0 -6
- data/test/data/ciphers/arc4.dat +0 -8
- data/test/data/ciphers/blowfish.dat +0 -5
- data/test/data/ciphers/camellia.dat +0 -7
- data/test/data/ciphers/cast128v.dat +0 -5
- data/test/data/ciphers/cast256v.dat +0 -5
- data/test/data/ciphers/descert.dat +0 -198
- data/test/data/ciphers/diamond.dat +0 -9
- data/test/data/ciphers/gostval.dat +0 -10
- data/test/data/ciphers/ideaval.dat +0 -13
- data/test/data/ciphers/marsval.dat +0 -11
- data/test/data/ciphers/panamac.dat +0 -7
- data/test/data/ciphers/rc2val.dat +0 -10
- data/test/data/ciphers/rc5val.dat +0 -7
- data/test/data/ciphers/rc6val.dat +0 -8
- data/test/data/ciphers/rijndael.dat +0 -11
- data/test/data/ciphers/saferval.dat +0 -27
- data/test/data/ciphers/seal.dat +0 -3
- data/test/data/ciphers/serpentv.dat +0 -11
- data/test/data/ciphers/shacal2.dat +0 -7
- data/test/data/ciphers/sharkval.dat +0 -9
- data/test/data/ciphers/skipjack.dat +0 -3
- data/test/data/ciphers/squareva.dat +0 -10
- data/test/data/ciphers/twofishv.dat +0 -11
- data/test/data/digests/adler32.dat +0 -8
- data/test/data/digests/crc32.dat +0 -10
- data/test/data/digests/haval.dat +0 -4
- data/test/data/digests/havalcer.dat +0 -23
- data/test/data/digests/md2.dat +0 -9
- data/test/data/digests/md4.dat +0 -9
- data/test/data/digests/md5.dat +0 -9
- data/test/data/digests/panamah.dat +0 -8
- data/test/data/digests/ripemd.dat +0 -43
- data/test/data/digests/sha.dat +0 -19
- data/test/data/digests/tiger.dat +0 -11
- data/test/data/digests/whirlpool.dat +0 -13
- data/test/data/hmacs/hmac.dat +0 -6
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 68d183271bac57caacfe1f66a50dad317c4de678
|
|
4
|
+
data.tar.gz: a87c4ec4a2469fcbc766435b7072e97106b2b2e3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9a0845962d2279bc631f4212b7a5b2e5ed098216d9fc1af0eed42d47136500986e01baf70e0d1464e9afa889fd684ddc4f9e19487eb4e491abf2046a00691dc5
|
|
7
|
+
data.tar.gz: 236319c0bf9930ae7b7bb859d534fe55d3e42499adc21271f75cd14b064ea79223fbd2864f4ab223af992fa1fb5df9cd0e25eb87c1e1664f8feff3e632cd4a21
|
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Guardfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
guard 'minitest', :test_folders => 'test', :test_file_patterns => '*_test.rb' do
|
|
3
|
+
watch(%r|^test/(.+)_test\.rb|)
|
|
4
|
+
|
|
5
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) do |m|
|
|
6
|
+
"test/#{m[2]}_test.rb"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
watch(%r|^test/test_helper\.rb|) do
|
|
10
|
+
"test"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if File.exists?('Guardfile.local')
|
|
15
|
+
instance_eval File.read('Guardfile.local')
|
|
16
|
+
end
|
|
17
|
+
|
data/MIT-LICENSE
CHANGED
data/Rakefile
CHANGED
|
@@ -1,42 +1,35 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
1
2
|
|
|
2
3
|
# -*- ruby -*-
|
|
3
4
|
|
|
4
5
|
require 'rubygems'
|
|
5
|
-
require '
|
|
6
|
+
require 'rubygems/package_task'
|
|
6
7
|
require 'rake/testtask'
|
|
7
|
-
require '
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
require 'bundler/gem_tasks'
|
|
8
10
|
|
|
9
|
-
$:.push 'lib'
|
|
11
|
+
$:.push File.expand_path(File.dirname(__FILE__), 'lib')
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
require 'jeweler'
|
|
13
|
-
Jeweler::Tasks.new do |gem|
|
|
14
|
-
gem.name = "cryptopp"
|
|
15
|
-
gem.version = "0.0.4"
|
|
16
|
-
gem.summary = "cryptopp is a cryptographic library for Ruby built on Wei Dai's Crypto++."
|
|
17
|
-
gem.description = gem.summary
|
|
18
|
-
gem.email = "dark.panda@gmail.com"
|
|
19
|
-
gem.homepage = "http://github.com/dark-panda/ruby-cryptopp"
|
|
20
|
-
gem.authors = [ "J Smith" ]
|
|
21
|
-
end
|
|
22
|
-
Jeweler::GemcutterTasks.new
|
|
23
|
-
rescue LoadError
|
|
24
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
25
|
-
end
|
|
13
|
+
version = File.read(File.expand_path('VERSION', File.dirname(__FILE__)))
|
|
26
14
|
|
|
27
|
-
desc 'Test
|
|
15
|
+
desc 'Test CryptoPP interface'
|
|
28
16
|
Rake::TestTask.new(:test) do |t|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
18
|
+
t.verbose = !!ENV['VERBOSE_TESTS']
|
|
19
|
+
t.warning = !!ENV['WARNINGS']
|
|
32
20
|
end
|
|
33
21
|
|
|
34
22
|
desc 'Build docs'
|
|
35
23
|
Rake::RDocTask.new do |t|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
t.title = "CryptoPP #{version}"
|
|
25
|
+
t.main = 'README'
|
|
26
|
+
t.rdoc_dir = 'doc'
|
|
27
|
+
t.rdoc_files.include(
|
|
28
|
+
'README',
|
|
29
|
+
'MIT-LICENSE',
|
|
30
|
+
'ext/cryptopp.cpp',
|
|
31
|
+
'ext/ciphers.cpp',
|
|
32
|
+
'ext/digests.cpp'
|
|
33
|
+
)
|
|
41
34
|
end
|
|
42
35
|
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.5
|
data/cryptopp.gemspec
CHANGED
|
@@ -1,199 +1,24 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
5
2
|
|
|
3
|
+
version = File.read(File.expand_path('VERSION', File.dirname(__FILE__)))
|
|
4
|
+
|
|
6
5
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.version =
|
|
6
|
+
s.name = "cryptopp"
|
|
7
|
+
s.version = version
|
|
9
8
|
|
|
10
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
10
|
s.authors = ["J Smith"]
|
|
12
|
-
s.date = %q{2010-07-01}
|
|
13
11
|
s.description = %q{cryptopp is a cryptographic library for Ruby built on Wei Dai's Crypto++.}
|
|
12
|
+
s.summary = s.description
|
|
14
13
|
s.email = %q{dark.panda@gmail.com}
|
|
14
|
+
s.license = "MIT"
|
|
15
15
|
s.extensions = ["ext/extconf.rb"]
|
|
16
16
|
s.extra_rdoc_files = [
|
|
17
17
|
"README"
|
|
18
18
|
]
|
|
19
|
-
s.files =
|
|
20
|
-
".gitignore",
|
|
21
|
-
"MIT-LICENSE",
|
|
22
|
-
"README",
|
|
23
|
-
"Rakefile",
|
|
24
|
-
"cryptopp.gemspec",
|
|
25
|
-
"ext/.gitignore",
|
|
26
|
-
"ext/Rakefile",
|
|
27
|
-
"ext/ciphers.cpp",
|
|
28
|
-
"ext/cryptopp.cpp",
|
|
29
|
-
"ext/cryptopp_ruby_api.h",
|
|
30
|
-
"ext/defs/block_modes.def",
|
|
31
|
-
"ext/defs/checksums.def",
|
|
32
|
-
"ext/defs/ciphers.def",
|
|
33
|
-
"ext/defs/hashes.def",
|
|
34
|
-
"ext/defs/hmacs.def",
|
|
35
|
-
"ext/defs/paddings.def",
|
|
36
|
-
"ext/defs/rngs.def",
|
|
37
|
-
"ext/digests.cpp",
|
|
38
|
-
"ext/extconf.rb",
|
|
39
|
-
"ext/j3way.cpp",
|
|
40
|
-
"ext/j3way.h",
|
|
41
|
-
"ext/jadler32.h",
|
|
42
|
-
"ext/jaes.cpp",
|
|
43
|
-
"ext/jaes.h",
|
|
44
|
-
"ext/jarc4.cpp",
|
|
45
|
-
"ext/jarc4.h",
|
|
46
|
-
"ext/jbase.cpp",
|
|
47
|
-
"ext/jbase.h",
|
|
48
|
-
"ext/jbasiccipherinfo.h",
|
|
49
|
-
"ext/jblowfish.cpp",
|
|
50
|
-
"ext/jblowfish.h",
|
|
51
|
-
"ext/jcamellia.cpp",
|
|
52
|
-
"ext/jcamellia.h",
|
|
53
|
-
"ext/jcast128.cpp",
|
|
54
|
-
"ext/jcast128.h",
|
|
55
|
-
"ext/jcast256.cpp",
|
|
56
|
-
"ext/jcast256.h",
|
|
57
|
-
"ext/jcipher.cpp",
|
|
58
|
-
"ext/jcipher.h",
|
|
59
|
-
"ext/jcipher_t.h",
|
|
60
|
-
"ext/jconfig.h",
|
|
61
|
-
"ext/jconstants.h",
|
|
62
|
-
"ext/jcrc32.h",
|
|
63
|
-
"ext/jdes.cpp",
|
|
64
|
-
"ext/jdes.h",
|
|
65
|
-
"ext/jdes_ede2.cpp",
|
|
66
|
-
"ext/jdes_ede2.h",
|
|
67
|
-
"ext/jdes_ede3.cpp",
|
|
68
|
-
"ext/jdes_ede3.h",
|
|
69
|
-
"ext/jdes_xex3.cpp",
|
|
70
|
-
"ext/jdes_xex3.h",
|
|
71
|
-
"ext/jdiamond2.cpp",
|
|
72
|
-
"ext/jdiamond2.h",
|
|
73
|
-
"ext/jdiamond2lite.cpp",
|
|
74
|
-
"ext/jdiamond2lite.h",
|
|
75
|
-
"ext/jexception.h",
|
|
76
|
-
"ext/jgost.cpp",
|
|
77
|
-
"ext/jgost.h",
|
|
78
|
-
"ext/jhash.cpp",
|
|
79
|
-
"ext/jhash.h",
|
|
80
|
-
"ext/jhash_t.h",
|
|
81
|
-
"ext/jhaval.h",
|
|
82
|
-
"ext/jhelpers.cpp",
|
|
83
|
-
"ext/jhelpers.h",
|
|
84
|
-
"ext/jhmac.cpp",
|
|
85
|
-
"ext/jhmac.h",
|
|
86
|
-
"ext/jhmac_t.h",
|
|
87
|
-
"ext/jidea.cpp",
|
|
88
|
-
"ext/jidea.h",
|
|
89
|
-
"ext/jmarc4.cpp",
|
|
90
|
-
"ext/jmarc4.h",
|
|
91
|
-
"ext/jmars.cpp",
|
|
92
|
-
"ext/jmars.h",
|
|
93
|
-
"ext/jmd2.h",
|
|
94
|
-
"ext/jmd4.h",
|
|
95
|
-
"ext/jmd5.h",
|
|
96
|
-
"ext/jpanamacipher.cpp",
|
|
97
|
-
"ext/jpanamacipher.h",
|
|
98
|
-
"ext/jpanamahash.h",
|
|
99
|
-
"ext/jrc2.cpp",
|
|
100
|
-
"ext/jrc2.h",
|
|
101
|
-
"ext/jrc5.cpp",
|
|
102
|
-
"ext/jrc5.h",
|
|
103
|
-
"ext/jrc6.cpp",
|
|
104
|
-
"ext/jrc6.h",
|
|
105
|
-
"ext/jripemd160.h",
|
|
106
|
-
"ext/jsafer.cpp",
|
|
107
|
-
"ext/jsafer.h",
|
|
108
|
-
"ext/jseal.cpp",
|
|
109
|
-
"ext/jseal.h",
|
|
110
|
-
"ext/jserpent.cpp",
|
|
111
|
-
"ext/jserpent.h",
|
|
112
|
-
"ext/jsha.h",
|
|
113
|
-
"ext/jshacal2.cpp",
|
|
114
|
-
"ext/jshacal2.h",
|
|
115
|
-
"ext/jshark.cpp",
|
|
116
|
-
"ext/jshark.h",
|
|
117
|
-
"ext/jsink.cpp",
|
|
118
|
-
"ext/jsink.h",
|
|
119
|
-
"ext/jskipjack.cpp",
|
|
120
|
-
"ext/jskipjack.h",
|
|
121
|
-
"ext/jsquare.cpp",
|
|
122
|
-
"ext/jsquare.h",
|
|
123
|
-
"ext/jstream.cpp",
|
|
124
|
-
"ext/jstream.h",
|
|
125
|
-
"ext/jstream_t.h",
|
|
126
|
-
"ext/jtea.cpp",
|
|
127
|
-
"ext/jtea.h",
|
|
128
|
-
"ext/jtiger.h",
|
|
129
|
-
"ext/jtwofish.cpp",
|
|
130
|
-
"ext/jtwofish.h",
|
|
131
|
-
"ext/jwhirlpool.h",
|
|
132
|
-
"ext/utils.cpp",
|
|
133
|
-
"extras/parser_c.rb",
|
|
134
|
-
"test/ciphers_test.rb",
|
|
135
|
-
"test/data/ciphers/3desval.dat",
|
|
136
|
-
"test/data/ciphers/3wayval.dat",
|
|
137
|
-
"test/data/ciphers/arc4.dat",
|
|
138
|
-
"test/data/ciphers/blowfish.dat",
|
|
139
|
-
"test/data/ciphers/camellia.dat",
|
|
140
|
-
"test/data/ciphers/cast128v.dat",
|
|
141
|
-
"test/data/ciphers/cast256v.dat",
|
|
142
|
-
"test/data/ciphers/descert.dat",
|
|
143
|
-
"test/data/ciphers/diamond.dat",
|
|
144
|
-
"test/data/ciphers/gostval.dat",
|
|
145
|
-
"test/data/ciphers/ideaval.dat",
|
|
146
|
-
"test/data/ciphers/marsval.dat",
|
|
147
|
-
"test/data/ciphers/panamac.dat",
|
|
148
|
-
"test/data/ciphers/rc2val.dat",
|
|
149
|
-
"test/data/ciphers/rc5val.dat",
|
|
150
|
-
"test/data/ciphers/rc6val.dat",
|
|
151
|
-
"test/data/ciphers/rijndael.dat",
|
|
152
|
-
"test/data/ciphers/saferval.dat",
|
|
153
|
-
"test/data/ciphers/seal.dat",
|
|
154
|
-
"test/data/ciphers/serpentv.dat",
|
|
155
|
-
"test/data/ciphers/shacal2.dat",
|
|
156
|
-
"test/data/ciphers/sharkval.dat",
|
|
157
|
-
"test/data/ciphers/skipjack.dat",
|
|
158
|
-
"test/data/ciphers/squareva.dat",
|
|
159
|
-
"test/data/ciphers/twofishv.dat",
|
|
160
|
-
"test/data/digests/adler32.dat",
|
|
161
|
-
"test/data/digests/crc32.dat",
|
|
162
|
-
"test/data/digests/haval.dat",
|
|
163
|
-
"test/data/digests/havalcer.dat",
|
|
164
|
-
"test/data/digests/md2.dat",
|
|
165
|
-
"test/data/digests/md4.dat",
|
|
166
|
-
"test/data/digests/md5.dat",
|
|
167
|
-
"test/data/digests/panamah.dat",
|
|
168
|
-
"test/data/digests/ripemd.dat",
|
|
169
|
-
"test/data/digests/sha.dat",
|
|
170
|
-
"test/data/digests/tiger.dat",
|
|
171
|
-
"test/data/digests/whirlpool.dat",
|
|
172
|
-
"test/data/hmacs/hmac.dat",
|
|
173
|
-
"test/digests_test.rb",
|
|
174
|
-
"test/hmacs_test.rb",
|
|
175
|
-
"test/test_helper.rb"
|
|
176
|
-
]
|
|
19
|
+
s.files = `git ls-files`.split($\)
|
|
177
20
|
s.homepage = %q{http://github.com/dark-panda/ruby-cryptopp}
|
|
178
21
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
179
22
|
s.require_paths = ["lib"]
|
|
180
|
-
s.rubygems_version = %q{1.3.6}
|
|
181
|
-
s.summary = %q{cryptopp is a cryptographic library for Ruby built on Wei Dai's Crypto++.}
|
|
182
|
-
s.test_files = [
|
|
183
|
-
"test/ciphers_test.rb",
|
|
184
|
-
"test/digests_test.rb",
|
|
185
|
-
"test/hmacs_test.rb",
|
|
186
|
-
"test/test_helper.rb"
|
|
187
|
-
]
|
|
188
|
-
|
|
189
|
-
if s.respond_to? :specification_version then
|
|
190
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
191
|
-
s.specification_version = 3
|
|
192
|
-
|
|
193
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
194
|
-
else
|
|
195
|
-
end
|
|
196
|
-
else
|
|
197
|
-
end
|
|
198
23
|
end
|
|
199
24
|
|
data/ext/Rakefile
CHANGED
data/ext/ciphers.cpp
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c) 2002-
|
|
4
|
-
* Crypto++ copyright (c) 1995-
|
|
5
|
-
* See
|
|
3
|
+
* Copyright (c) 2002-2014 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2013 Wei Dai
|
|
5
|
+
* See MIT-LICENSE for the extact license
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
#include "j3way.h"
|
|
@@ -73,208 +73,208 @@ static VALUE cipher_decrypt(VALUE self, bool hex);
|
|
|
73
73
|
|
|
74
74
|
static CipherEnum cipher_sym_to_const(VALUE c)
|
|
75
75
|
{
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
CipherEnum cipher = UNKNOWN_CIPHER;
|
|
77
|
+
ID id = SYM2ID(c);
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#
|
|
94
|
-
|
|
79
|
+
if (id == rb_intern("rijndael")) {
|
|
80
|
+
cipher = AES_CIPHER;
|
|
81
|
+
}
|
|
82
|
+
else if (id == rb_intern("panama")) {
|
|
83
|
+
cipher = PANAMA_CIPHER;
|
|
84
|
+
}
|
|
85
|
+
else if (id == rb_intern("seal")) {
|
|
86
|
+
cipher = SEAL_CIPHER;
|
|
87
|
+
}
|
|
88
|
+
# define CIPHER_ALGORITHM_X_FORCE 1
|
|
89
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
90
|
+
else if (id == rb_intern(# s)) { \
|
|
91
|
+
cipher = r ## _CIPHER; \
|
|
92
|
+
}
|
|
93
|
+
# include "defs/ciphers.def"
|
|
94
|
+
return cipher;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
static ModeEnum mode_sym_to_const(VALUE m)
|
|
99
99
|
{
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
ModeEnum mode = UNKNOWN_MODE;
|
|
101
|
+
ID id = SYM2ID(m);
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
#
|
|
111
|
-
|
|
103
|
+
if (id == rb_intern("counter")) {
|
|
104
|
+
mode = CTR_MODE;
|
|
105
|
+
}
|
|
106
|
+
# define BLOCK_MODE_X(c, s) \
|
|
107
|
+
else if (id == rb_intern(# s)) { \
|
|
108
|
+
mode = c ## _MODE; \
|
|
109
|
+
}
|
|
110
|
+
# include "defs/block_modes.def"
|
|
111
|
+
return mode;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
static PaddingEnum padding_sym_to_const(VALUE p)
|
|
115
115
|
{
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
#
|
|
133
|
-
|
|
116
|
+
PaddingEnum padding = UNKNOWN_PADDING;
|
|
117
|
+
ID id = SYM2ID(p);
|
|
118
|
+
|
|
119
|
+
if (id == rb_intern("none")) {
|
|
120
|
+
padding = NO_PADDING;
|
|
121
|
+
}
|
|
122
|
+
else if (id == rb_intern("zeroes")) {
|
|
123
|
+
padding = ZEROS_PADDING;
|
|
124
|
+
}
|
|
125
|
+
else if (id == rb_intern("one_and_zeroes")) {
|
|
126
|
+
padding = ONE_AND_ZEROS_PADDING;
|
|
127
|
+
}
|
|
128
|
+
# define PADDING_X(c, s) \
|
|
129
|
+
else if (id == rb_intern(# s)) { \
|
|
130
|
+
padding = c ## _PADDING; \
|
|
131
|
+
}
|
|
132
|
+
# include "defs/paddings.def"
|
|
133
|
+
return padding;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
static RNGEnum rng_sym_to_const(VALUE r)
|
|
137
137
|
{
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
RNGEnum rng = UNKNOWN_RNG;
|
|
139
|
+
ID id = SYM2ID(r);
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
#
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
#
|
|
149
|
-
|
|
141
|
+
if (false) {
|
|
142
|
+
// no-op so we can use our x-macro
|
|
143
|
+
}
|
|
144
|
+
# define RNG_X(c, s) \
|
|
145
|
+
else if (id == rb_intern(# s)) { \
|
|
146
|
+
rng = c ## _RNG; \
|
|
147
|
+
}
|
|
148
|
+
# include "defs/rngs.def"
|
|
149
|
+
return rng;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
|
|
153
153
|
/* See if a cipher algorithm is enabled. */
|
|
154
154
|
static bool cipher_enabled(CipherEnum cipher)
|
|
155
155
|
{
|
|
156
|
-
|
|
157
|
-
#
|
|
158
|
-
|
|
159
|
-
#
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
switch (cipher) {
|
|
157
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
158
|
+
case r ##_CIPHER:
|
|
159
|
+
# include "defs/ciphers.def"
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
|
|
166
166
|
/* Figure out options for a cipher. We only check for Symbols, not Strings. */
|
|
167
167
|
static void cipher_options(VALUE self, VALUE options)
|
|
168
168
|
{
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
#
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
#
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
169
|
+
Check_Type(options, T_HASH);
|
|
170
|
+
|
|
171
|
+
{
|
|
172
|
+
VALUE plaintext = rb_hash_aref(options, ID2SYM(rb_intern("plaintext")));
|
|
173
|
+
VALUE plaintext_hex = rb_hash_aref(options, ID2SYM(rb_intern("plaintext_hex")));
|
|
174
|
+
if (!NIL_P(plaintext) && !NIL_P(plaintext_hex)) {
|
|
175
|
+
rb_raise(rb_eCryptoPP_Error, "can't set both plaintext and plaintext_hex in options");
|
|
176
|
+
}
|
|
177
|
+
else if (!NIL_P(plaintext)) {
|
|
178
|
+
cipher_plaintext_eq(self, plaintext, false);
|
|
179
|
+
}
|
|
180
|
+
else if (!NIL_P(plaintext_hex)) {
|
|
181
|
+
cipher_plaintext_eq(self, plaintext_hex, true);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
{
|
|
186
|
+
VALUE ciphertext = rb_hash_aref(options, ID2SYM(rb_intern("ciphertext")));
|
|
187
|
+
VALUE ciphertext_hex = rb_hash_aref(options, ID2SYM(rb_intern("ciphertext_hex")));
|
|
188
|
+
if (!NIL_P(ciphertext) && !NIL_P(ciphertext_hex)) {
|
|
189
|
+
rb_raise(rb_eCryptoPP_Error, "can't set both ciphertext and ciphertext_hex in options");
|
|
190
|
+
}
|
|
191
|
+
else if (!NIL_P(ciphertext)) {
|
|
192
|
+
cipher_ciphertext_eq(self, ciphertext, false);
|
|
193
|
+
}
|
|
194
|
+
else if (!NIL_P(ciphertext_hex)) {
|
|
195
|
+
cipher_ciphertext_eq(self, ciphertext_hex, true);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
{
|
|
200
|
+
VALUE key = rb_hash_aref(options, ID2SYM(rb_intern("key")));
|
|
201
|
+
VALUE key_hex = rb_hash_aref(options, ID2SYM(rb_intern("key_hex")));
|
|
202
|
+
if (!NIL_P(key) && !NIL_P(key_hex)) {
|
|
203
|
+
rb_raise(rb_eCryptoPP_Error, "can't set both key and key_hex in options");
|
|
204
|
+
}
|
|
205
|
+
else if (!NIL_P(key)) {
|
|
206
|
+
cipher_key_eq(self, key, false);
|
|
207
|
+
}
|
|
208
|
+
else if (!NIL_P(key_hex)) {
|
|
209
|
+
cipher_key_eq(self, key_hex, true);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
{
|
|
214
|
+
VALUE key_length = rb_hash_aref(options, ID2SYM(rb_intern("key_length")));
|
|
215
|
+
if (!NIL_P(key_length)) {
|
|
216
|
+
rb_cipher_key_length_eq(self, key_length);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# if ENABLED_RC2_CIPHER
|
|
221
|
+
{
|
|
222
|
+
VALUE effective_key_length = rb_hash_aref(options, ID2SYM(rb_intern("effective_key_length")));
|
|
223
|
+
if (!NIL_P(effective_key_length)) {
|
|
224
|
+
rb_cipher_effective_key_length_eq(self, effective_key_length);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
# endif
|
|
228
|
+
|
|
229
|
+
{
|
|
230
|
+
VALUE rounds = rb_hash_aref(options, ID2SYM(rb_intern("rounds")));
|
|
231
|
+
if (!NIL_P(rounds)) {
|
|
232
|
+
rb_cipher_rounds_eq(self, rounds);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
{
|
|
237
|
+
VALUE rng = rb_hash_aref(options, ID2SYM(rb_intern("rng")));
|
|
238
|
+
if (!NIL_P(rng)) {
|
|
239
|
+
rb_cipher_rng_eq(self, rng);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
{
|
|
244
|
+
VALUE rand_iv = rb_hash_aref(options, ID2SYM(rb_intern("rand_iv")));
|
|
245
|
+
VALUE iv = rb_hash_aref(options, ID2SYM(rb_intern("iv")));
|
|
246
|
+
VALUE iv_hex = rb_hash_aref(options, ID2SYM(rb_intern("iv_hex")));
|
|
247
|
+
|
|
248
|
+
if (!NIL_P(rand_iv) && (!NIL_P(iv) || !NIL_P(iv_hex))) {
|
|
249
|
+
rb_raise(rb_eCryptoPP_Error, "can't set both rand_iv and iv or iv_hex in options");
|
|
250
|
+
}
|
|
251
|
+
else if (!NIL_P(iv) && !NIL_P(iv_hex)) {
|
|
252
|
+
rb_raise(rb_eCryptoPP_Error, "can't set both iv and iv_hex in options");
|
|
253
|
+
}
|
|
254
|
+
else if (!NIL_P(rand_iv)) {
|
|
255
|
+
cipher_rand_iv(self, rand_iv);
|
|
256
|
+
}
|
|
257
|
+
else if (!NIL_P(iv)) {
|
|
258
|
+
cipher_iv_eq(self, iv, false);
|
|
259
|
+
}
|
|
260
|
+
else if (!NIL_P(iv_hex)) {
|
|
261
|
+
cipher_iv_eq(self, iv_hex, true);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
{
|
|
266
|
+
VALUE block_mode = rb_hash_aref(options, ID2SYM(rb_intern("block_mode")));
|
|
267
|
+
if (!NIL_P(block_mode)) {
|
|
268
|
+
rb_cipher_block_mode_eq(self, block_mode);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
{
|
|
273
|
+
VALUE padding = rb_hash_aref(options, ID2SYM(rb_intern("padding")));
|
|
274
|
+
if (!NIL_P(padding)) {
|
|
275
|
+
rb_cipher_padding_eq(self, padding);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
|
|
@@ -282,43 +282,43 @@ static void cipher_options(VALUE self, VALUE options)
|
|
|
282
282
|
* is found. May throw a JException if no suitable cipher is found. */
|
|
283
283
|
static JBase* cipher_factory(VALUE algorithm)
|
|
284
284
|
{
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
285
|
+
try {
|
|
286
|
+
switch (cipher_sym_to_const(algorithm)) {
|
|
287
|
+
default:
|
|
288
|
+
throw JException("the requested algorithm cannot be found");
|
|
289
|
+
break;
|
|
290
290
|
|
|
291
|
-
#
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
#
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
291
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
292
|
+
case r ## _CIPHER: \
|
|
293
|
+
return static_cast<c*>(new c);
|
|
294
|
+
# include "defs/ciphers.def"
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (Exception e) {
|
|
298
|
+
throw JException("Crypto++ exception: " + e.GetWhat());
|
|
299
|
+
}
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
/* Wraps a Cipher object into a Ruby object. May throw a JException if no
|
|
303
303
|
* suitable Cipher is found. */
|
|
304
304
|
static VALUE wrap_cipher_in_ruby(JBase* cipher)
|
|
305
305
|
{
|
|
306
|
-
|
|
307
|
-
#
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
#
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
306
|
+
const type_info& info = typeid(*cipher);
|
|
307
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
308
|
+
if (info == typeid(c)) { \
|
|
309
|
+
return Data_Wrap_Struct(rb_cCryptoPP_Cipher_## r, cipher_mark, cipher_free, cipher); \
|
|
310
|
+
} \
|
|
311
|
+
else
|
|
312
|
+
# include "defs/ciphers.def"
|
|
313
|
+
{
|
|
314
|
+
throw JException("the requested algorithm has been disabled");
|
|
315
|
+
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
/**
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
319
|
+
* call-seq:
|
|
320
|
+
* cipher_factory(algorithm) => Cipher
|
|
321
|
+
* cipher_factory(algorithm, options) => Cipher
|
|
322
322
|
*
|
|
323
323
|
* Creates a new Cipher object.
|
|
324
324
|
*
|
|
@@ -326,35 +326,35 @@ static VALUE wrap_cipher_in_ruby(JBase* cipher)
|
|
|
326
326
|
*/
|
|
327
327
|
VALUE rb_module_cipher_factory(int argc, VALUE *argv, VALUE self)
|
|
328
328
|
{
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
329
|
+
VALUE algorithm, options, retval;
|
|
330
|
+
rb_scan_args(argc, argv, "11", &algorithm, &options);
|
|
331
|
+
try {
|
|
332
|
+
retval = wrap_cipher_in_ruby(cipher_factory(algorithm));
|
|
333
|
+
}
|
|
334
|
+
catch (Exception& e) {
|
|
335
|
+
rb_raise(rb_eCryptoPP_Error, "%s", e.GetWhat().c_str());
|
|
336
|
+
}
|
|
337
|
+
if (!NIL_P(options)) {
|
|
338
|
+
cipher_options(retval, options);
|
|
339
|
+
}
|
|
340
|
+
return retval;
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
#define CIPHER_ALGORITHM_X(klass, r, n, s) \
|
|
344
344
|
VALUE rb_cipher_ ## r ##_new(int argc, VALUE *argv, VALUE self) \
|
|
345
345
|
{ \
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
346
|
+
VALUE options, retval; \
|
|
347
|
+
rb_scan_args(argc, argv, "01", &options); \
|
|
348
|
+
try { \
|
|
349
|
+
retval = wrap_cipher_in_ruby(cipher_factory(ID2SYM(rb_intern(# s)))); \
|
|
350
|
+
} \
|
|
351
|
+
catch (Exception& e) { \
|
|
352
|
+
rb_raise(rb_eCryptoPP_Error, "%s", e.GetWhat().c_str()); \
|
|
353
|
+
} \
|
|
354
|
+
if (!NIL_P(options)) { \
|
|
355
|
+
cipher_options(retval, options); \
|
|
356
|
+
} \
|
|
357
|
+
return retval; \
|
|
358
358
|
}
|
|
359
359
|
#include "defs/ciphers.def"
|
|
360
360
|
|
|
@@ -362,15 +362,15 @@ VALUE rb_cipher_ ## r ##_new(int argc, VALUE *argv, VALUE self) \
|
|
|
362
362
|
/* Creates a random initialization vector on the cipher. */
|
|
363
363
|
static void cipher_rand_iv(VALUE self, VALUE l)
|
|
364
364
|
{
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
365
|
+
JBase *cipher = NULL;
|
|
366
|
+
unsigned int length = NUM2UINT(rb_funcall(l, rb_intern("to_i"), 0));
|
|
367
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
368
|
+
cipher->setRandIV(length);
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
/**
|
|
372
372
|
* call-seq:
|
|
373
|
-
*
|
|
373
|
+
* rand_iv(length) => nil
|
|
374
374
|
*
|
|
375
375
|
* Sets a random initialization vector on the Cipher. This method uses the
|
|
376
376
|
* random number generator set on the Cipher to produce the IV, so be sure to
|
|
@@ -380,135 +380,135 @@ static void cipher_rand_iv(VALUE self, VALUE l)
|
|
|
380
380
|
*/
|
|
381
381
|
VALUE rb_cipher_rand_iv(VALUE self, VALUE l)
|
|
382
382
|
{
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
JBase *cipher = NULL;
|
|
384
|
+
unsigned int length = NUM2UINT(rb_funcall(l, rb_intern("to_i"), 0));
|
|
385
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
386
|
+
cipher->setRandIV(length);
|
|
387
|
+
return l;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
|
|
391
391
|
/* Sets an IV on the cipher. */
|
|
392
392
|
static string cipher_iv_eq(VALUE self, VALUE iv, bool hex)
|
|
393
393
|
{
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
394
|
+
JBase *cipher = NULL;
|
|
395
|
+
Check_Type(iv, T_STRING);
|
|
396
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
397
|
+
cipher->setIV(string(StringValuePtr(iv), RSTRING_LEN(iv)), hex);
|
|
398
|
+
return cipher->getIV(hex);
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
/**
|
|
402
402
|
* call-seq:
|
|
403
|
-
*
|
|
403
|
+
* iv=(iv) => String
|
|
404
404
|
*
|
|
405
405
|
* Set an initialization vector on the Cipher.
|
|
406
406
|
*/
|
|
407
407
|
VALUE rb_cipher_iv_eq(VALUE self, VALUE iv)
|
|
408
408
|
{
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
cipher_iv_eq(self, iv, false);
|
|
410
|
+
return iv;
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
/**
|
|
414
414
|
* call-seq:
|
|
415
|
-
*
|
|
415
|
+
* iv_hex=(iv) => String
|
|
416
416
|
*
|
|
417
417
|
* Set an initialization vector on the Cipher. This method uses hex data and
|
|
418
418
|
* returns the IV as set.
|
|
419
419
|
*/
|
|
420
420
|
VALUE rb_cipher_iv_hex_eq(VALUE self, VALUE iv)
|
|
421
421
|
{
|
|
422
|
-
|
|
423
|
-
|
|
422
|
+
cipher_iv_eq(self, iv, true);
|
|
423
|
+
return iv;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
|
|
427
427
|
/* Gets the IV. */
|
|
428
428
|
static string cipher_iv(VALUE self, bool hex)
|
|
429
429
|
{
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
JBase *cipher = NULL;
|
|
431
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
432
|
+
return cipher->getIV(hex);
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
/**
|
|
436
436
|
* call-seq:
|
|
437
|
-
*
|
|
437
|
+
* iv => String
|
|
438
438
|
*
|
|
439
439
|
* Returns the Cipher's IV in binary.
|
|
440
440
|
*/
|
|
441
441
|
VALUE rb_cipher_iv(VALUE self)
|
|
442
442
|
{
|
|
443
|
-
|
|
444
|
-
|
|
443
|
+
string retval = cipher_iv(self, false);
|
|
444
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
/**
|
|
448
448
|
* call-seq:
|
|
449
|
-
*
|
|
449
|
+
* iv => String
|
|
450
450
|
*
|
|
451
451
|
* Returns the Cipher's IV in hex.
|
|
452
452
|
*/
|
|
453
453
|
VALUE rb_cipher_iv_hex(VALUE self)
|
|
454
454
|
{
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
string retval = cipher_iv(self, true);
|
|
456
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
457
457
|
}
|
|
458
458
|
|
|
459
459
|
|
|
460
460
|
/**
|
|
461
461
|
* call-seq:
|
|
462
|
-
*
|
|
462
|
+
* block_mode=(mode) => Symbol
|
|
463
463
|
*
|
|
464
464
|
* Set the block mode on block ciphers. Returns the mode as set and may raise
|
|
465
465
|
* a CryptoPPError if the mode is invalid or you are using a stream cipher.
|
|
466
466
|
*/
|
|
467
467
|
VALUE rb_cipher_block_mode_eq(VALUE self, VALUE m)
|
|
468
468
|
{
|
|
469
|
-
|
|
470
|
-
|
|
469
|
+
JBase *cipher = NULL;
|
|
470
|
+
ModeEnum mode = mode_sym_to_const(m);
|
|
471
471
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
472
|
+
if (!VALID_MODE(mode)) {
|
|
473
|
+
rb_raise(rb_eCryptoPP_Error, "invalid cipher mode");
|
|
474
|
+
}
|
|
475
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
476
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
477
|
+
rb_raise(rb_eCryptoPP_Error, "can't set mode on stream ciphers");
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
((JCipher*) cipher)->setMode(mode);
|
|
481
|
+
return m;
|
|
482
|
+
}
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
|
|
486
486
|
/**
|
|
487
487
|
* call-seq:
|
|
488
|
-
*
|
|
488
|
+
* block_mode => Fixnum
|
|
489
489
|
*
|
|
490
490
|
* Get the block mode. Returns <tt>nil</tt> if you try to use this on a stream
|
|
491
491
|
* cipher.
|
|
492
492
|
*/
|
|
493
493
|
VALUE rb_cipher_block_mode(VALUE self)
|
|
494
494
|
{
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
#
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
#
|
|
495
|
+
JBase *cipher = NULL;
|
|
496
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
497
|
+
ModeEnum mode = ((JCipher*) cipher)->getMode();
|
|
498
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
499
|
+
return Qnil;
|
|
500
|
+
}
|
|
501
|
+
# define BLOCK_MODE_X(c, s) \
|
|
502
|
+
else if (mode == c ## _MODE) { \
|
|
503
|
+
return ID2SYM(rb_intern(# s)); \
|
|
504
|
+
}
|
|
505
|
+
# include "defs/block_modes.def"
|
|
506
506
|
}
|
|
507
507
|
|
|
508
508
|
|
|
509
509
|
/**
|
|
510
510
|
* call-seq:
|
|
511
|
-
*
|
|
511
|
+
* padding=(padding) => Symbol
|
|
512
512
|
*
|
|
513
513
|
* Set the padding on block ciphers.
|
|
514
514
|
*
|
|
@@ -521,54 +521,54 @@ VALUE rb_cipher_block_mode(VALUE self)
|
|
|
521
521
|
*/
|
|
522
522
|
VALUE rb_cipher_padding_eq(VALUE self, VALUE p)
|
|
523
523
|
{
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
JBase *cipher = NULL;
|
|
525
|
+
PaddingEnum padding = padding_sym_to_const(p);
|
|
526
526
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
527
|
+
if (!VALID_PADDING(padding)) {
|
|
528
|
+
rb_raise(rb_eCryptoPP_Error, "invalid cipher padding");
|
|
529
|
+
}
|
|
530
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
531
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
532
|
+
rb_raise(rb_eCryptoPP_Error, "can't set padding on stream ciphers");
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
((JCipher*) cipher)->setPadding(padding);
|
|
536
|
+
if (((JCipher*) cipher)->getPadding() != padding) {
|
|
537
|
+
rb_raise(rb_eCryptoPP_Error, "Padding '%s' cannot be used with mode '%s'", JCipher::getPaddingName(padding).c_str(), ((JCipher*) cipher)->getModeName().c_str());
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
return p;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
|
|
546
546
|
/**
|
|
547
547
|
* call-seq:
|
|
548
|
-
*
|
|
548
|
+
* padding => Fixnum
|
|
549
549
|
*
|
|
550
550
|
* Get the cipher padding being used. Returns <tt>nil</tt> if you try to use
|
|
551
551
|
* this on a stream cipher.
|
|
552
552
|
*/
|
|
553
553
|
VALUE rb_cipher_padding(VALUE self)
|
|
554
554
|
{
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
#
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
#
|
|
555
|
+
JBase *cipher = NULL;
|
|
556
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
557
|
+
PaddingEnum padding = ((JCipher*) cipher)->getPadding();
|
|
558
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
559
|
+
return Qnil;
|
|
560
|
+
}
|
|
561
|
+
# define PADDING_X(c, s) \
|
|
562
|
+
else if (padding == c ## _PADDING) { \
|
|
563
|
+
return ID2SYM(rb_intern(# s)); \
|
|
564
|
+
}
|
|
565
|
+
# include "defs/paddings.def"
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
|
|
569
569
|
/**
|
|
570
570
|
* call-seq:
|
|
571
|
-
*
|
|
571
|
+
* rng=(rng) => Symbol
|
|
572
572
|
*
|
|
573
573
|
* Set the random number generator to use for IVs. A CryptoPPError will be
|
|
574
574
|
* raised if an RNG is not available on the system.
|
|
@@ -579,178 +579,178 @@ VALUE rb_cipher_padding(VALUE self)
|
|
|
579
579
|
*/
|
|
580
580
|
VALUE rb_cipher_rng_eq(VALUE self, VALUE r)
|
|
581
581
|
{
|
|
582
|
-
|
|
583
|
-
|
|
582
|
+
JBase *cipher = NULL;
|
|
583
|
+
RNGEnum rng = rng_sym_to_const(r);
|
|
584
584
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
585
|
+
if (!VALID_RNG(rng)) {
|
|
586
|
+
rb_raise(rb_eCryptoPP_Error, "invalid cipher RNG");
|
|
587
|
+
}
|
|
588
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
589
|
+
((JCipher*) cipher)->setRNG(rng);
|
|
590
|
+
if (((JCipher*) cipher)->getRNG() != rng) {
|
|
591
|
+
rb_raise(rb_eCryptoPP_Error, "RNG '%s' is unavailable", JBase::getRNGName(rng).c_str());
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
return r;
|
|
595
|
+
}
|
|
596
596
|
}
|
|
597
597
|
|
|
598
598
|
|
|
599
599
|
/**
|
|
600
600
|
* call-seq:
|
|
601
|
-
*
|
|
601
|
+
* rng => Fixnum
|
|
602
602
|
*
|
|
603
603
|
* Get the RNG being used.
|
|
604
604
|
*/
|
|
605
605
|
VALUE rb_cipher_rng(VALUE self)
|
|
606
606
|
{
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
#
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
#
|
|
607
|
+
JBase *cipher = NULL;
|
|
608
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
609
|
+
RNGEnum rng = ((JCipher*) cipher)->getRNG();
|
|
610
|
+
if (false) {
|
|
611
|
+
// no-op so we can use our x-macro
|
|
612
|
+
}
|
|
613
|
+
# define RNG_X(c, s) \
|
|
614
|
+
else if (rng == c ## _RNG) { \
|
|
615
|
+
return ID2SYM(rb_intern(# s)); \
|
|
616
|
+
}
|
|
617
|
+
# include "defs/rngs.def"
|
|
618
618
|
}
|
|
619
619
|
|
|
620
620
|
|
|
621
621
|
/* Set the plaintext. */
|
|
622
622
|
static string cipher_plaintext_eq(VALUE self, VALUE plaintext, bool hex)
|
|
623
623
|
{
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
624
|
+
JBase *cipher = NULL;
|
|
625
|
+
Check_Type(plaintext, T_STRING);
|
|
626
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
627
|
+
cipher->setPlaintext(string(StringValuePtr(plaintext), RSTRING_LEN(plaintext)), hex);
|
|
628
|
+
return cipher->getPlaintext(hex);
|
|
629
629
|
}
|
|
630
630
|
|
|
631
631
|
/**
|
|
632
632
|
* call-seq:
|
|
633
|
-
*
|
|
633
|
+
* plaintext=(string) => String
|
|
634
634
|
*
|
|
635
635
|
* Sets the plaintext on the Cipher in binary and returns the same.
|
|
636
636
|
*/
|
|
637
637
|
VALUE rb_cipher_plaintext_eq(VALUE self, VALUE plaintext)
|
|
638
638
|
{
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
cipher_plaintext_eq(self, plaintext, false);
|
|
640
|
+
return plaintext;
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
/**
|
|
644
644
|
* call-seq:
|
|
645
|
-
*
|
|
645
|
+
* plaintext_hex=(string) => String
|
|
646
646
|
*
|
|
647
647
|
* Sets the plaintext on the Cipher in hex and returns the same.
|
|
648
648
|
*/
|
|
649
649
|
VALUE rb_cipher_plaintext_hex_eq(VALUE self, VALUE plaintext)
|
|
650
650
|
{
|
|
651
|
-
|
|
652
|
-
|
|
651
|
+
cipher_plaintext_eq(self, plaintext, true);
|
|
652
|
+
return plaintext;
|
|
653
653
|
}
|
|
654
654
|
|
|
655
655
|
|
|
656
656
|
/* Get the plaintext. */
|
|
657
657
|
static string cipher_plaintext(VALUE self, bool hex)
|
|
658
658
|
{
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
659
|
+
JBase *cipher = NULL;
|
|
660
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
661
|
+
return cipher->getPlaintext(hex);
|
|
662
662
|
}
|
|
663
663
|
|
|
664
664
|
/**
|
|
665
665
|
* call-seq:
|
|
666
|
-
*
|
|
666
|
+
* plaintext => String
|
|
667
667
|
*
|
|
668
668
|
* Gets the plaintext from the Cipher in binary.
|
|
669
669
|
*/
|
|
670
670
|
VALUE rb_cipher_plaintext(VALUE self)
|
|
671
671
|
{
|
|
672
|
-
|
|
673
|
-
|
|
672
|
+
string retval = cipher_plaintext(self, false);
|
|
673
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
674
674
|
}
|
|
675
675
|
|
|
676
676
|
/**
|
|
677
677
|
* call-seq:
|
|
678
|
-
*
|
|
678
|
+
* plaintext_hex => String
|
|
679
679
|
*
|
|
680
680
|
* Gets the plaintext from the Cipher in hex.
|
|
681
681
|
*/
|
|
682
682
|
VALUE rb_cipher_plaintext_hex(VALUE self)
|
|
683
683
|
{
|
|
684
|
-
|
|
685
|
-
|
|
684
|
+
string retval = cipher_plaintext(self, true);
|
|
685
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
|
|
689
689
|
/* Set the ciphertext. */
|
|
690
690
|
static string cipher_ciphertext_eq(VALUE self, VALUE ciphertext, bool hex)
|
|
691
691
|
{
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
692
|
+
JBase *cipher = NULL;
|
|
693
|
+
Check_Type(ciphertext, T_STRING);
|
|
694
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
695
|
+
cipher->setCiphertext(string(StringValuePtr(ciphertext), RSTRING_LEN(ciphertext)), hex);
|
|
696
|
+
return cipher->getCiphertext(hex);
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
/**
|
|
700
700
|
* call-seq:
|
|
701
|
-
*
|
|
701
|
+
* ciphertext=(string) => String
|
|
702
702
|
*
|
|
703
703
|
* Sets the ciphertext on the Cipher in binary and returns the same.
|
|
704
704
|
*/
|
|
705
705
|
VALUE rb_cipher_ciphertext_eq(VALUE self, VALUE ciphertext)
|
|
706
706
|
{
|
|
707
|
-
|
|
708
|
-
|
|
707
|
+
cipher_ciphertext_eq(self, ciphertext, false);
|
|
708
|
+
return ciphertext;
|
|
709
709
|
}
|
|
710
710
|
|
|
711
711
|
/**
|
|
712
712
|
* call-seq:
|
|
713
|
-
*
|
|
713
|
+
* ciphertext_hex=(string) => String
|
|
714
714
|
*
|
|
715
715
|
* Sets the ciphertext on the Cipher in hex and returns the same.
|
|
716
716
|
*/
|
|
717
717
|
VALUE rb_cipher_ciphertext_hex_eq(VALUE self, VALUE ciphertext)
|
|
718
718
|
{
|
|
719
|
-
|
|
720
|
-
|
|
719
|
+
cipher_ciphertext_eq(self, ciphertext, true);
|
|
720
|
+
return ciphertext;
|
|
721
721
|
}
|
|
722
722
|
|
|
723
723
|
|
|
724
724
|
/* Get the ciphertext. */
|
|
725
725
|
static string cipher_ciphertext(VALUE self, bool hex)
|
|
726
726
|
{
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
727
|
+
JBase *cipher = NULL;
|
|
728
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
729
|
+
return cipher->getCiphertext(hex);
|
|
730
730
|
}
|
|
731
731
|
|
|
732
732
|
/**
|
|
733
733
|
* call-seq:
|
|
734
|
-
*
|
|
734
|
+
* ciphertext => String
|
|
735
735
|
*
|
|
736
736
|
* Gets the ciphertext from the Cipher in binary.
|
|
737
737
|
*/
|
|
738
738
|
VALUE rb_cipher_ciphertext(VALUE self)
|
|
739
739
|
{
|
|
740
|
-
|
|
741
|
-
|
|
740
|
+
string retval = cipher_ciphertext(self, false);
|
|
741
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
742
742
|
}
|
|
743
743
|
|
|
744
744
|
/**
|
|
745
745
|
* call-seq:
|
|
746
|
-
*
|
|
746
|
+
* ciphertext_hex => String
|
|
747
747
|
*
|
|
748
748
|
* Gets the ciphertext from the Cipher in hex.
|
|
749
749
|
*/
|
|
750
750
|
VALUE rb_cipher_ciphertext_hex(VALUE self)
|
|
751
751
|
{
|
|
752
|
-
|
|
753
|
-
|
|
752
|
+
string retval = cipher_ciphertext(self, true);
|
|
753
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
754
754
|
}
|
|
755
755
|
|
|
756
756
|
|
|
@@ -759,16 +759,16 @@ VALUE rb_cipher_ciphertext_hex(VALUE self)
|
|
|
759
759
|
* of 12 bytes, while Blowfish can use keys of 1 to 72 bytes. */
|
|
760
760
|
static string cipher_key_eq(VALUE self, VALUE key, bool hex)
|
|
761
761
|
{
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
762
|
+
JBase *cipher = NULL;
|
|
763
|
+
Check_Type(key, T_STRING);
|
|
764
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
765
|
+
cipher->setKey(string(StringValuePtr(key), RSTRING_LEN(key)), hex);
|
|
766
|
+
return cipher->getKey(hex);
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
/**
|
|
770
770
|
* call-seq:
|
|
771
|
-
*
|
|
771
|
+
* key=(string) => String
|
|
772
772
|
*
|
|
773
773
|
* Sets the key on the Cipher in binary and returns the same. Note that the
|
|
774
774
|
* key try to set may be truncated or padded depending on its length. Some
|
|
@@ -785,13 +785,13 @@ static string cipher_key_eq(VALUE self, VALUE key, bool hex)
|
|
|
785
785
|
*/
|
|
786
786
|
VALUE rb_cipher_key_eq(VALUE self, VALUE key)
|
|
787
787
|
{
|
|
788
|
-
|
|
789
|
-
|
|
788
|
+
cipher_key_eq(self, key, false);
|
|
789
|
+
return key;
|
|
790
790
|
}
|
|
791
791
|
|
|
792
792
|
/**
|
|
793
793
|
* call-seq:
|
|
794
|
-
*
|
|
794
|
+
* key_hex=(string) => String
|
|
795
795
|
*
|
|
796
796
|
* Sets the key on the Cipher in hex and returns the same. Note that the
|
|
797
797
|
* key try to set may be truncated or padded depending on its length. Some
|
|
@@ -808,47 +808,47 @@ VALUE rb_cipher_key_eq(VALUE self, VALUE key)
|
|
|
808
808
|
*/
|
|
809
809
|
VALUE rb_cipher_key_hex_eq(VALUE self, VALUE key)
|
|
810
810
|
{
|
|
811
|
-
|
|
812
|
-
|
|
811
|
+
cipher_key_eq(self, key, true);
|
|
812
|
+
return key;
|
|
813
813
|
}
|
|
814
814
|
|
|
815
815
|
|
|
816
816
|
/* Get the key. */
|
|
817
817
|
static string cipher_key(VALUE self, bool hex)
|
|
818
818
|
{
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
819
|
+
JBase *cipher = NULL;
|
|
820
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
821
|
+
return cipher->getKey(hex);
|
|
822
822
|
}
|
|
823
823
|
|
|
824
824
|
/**
|
|
825
825
|
* call-seq:
|
|
826
|
-
*
|
|
826
|
+
* key => String
|
|
827
827
|
*
|
|
828
828
|
* Returns the key set on the Cipher in binary.
|
|
829
829
|
*/
|
|
830
830
|
VALUE rb_cipher_key(VALUE self)
|
|
831
831
|
{
|
|
832
|
-
|
|
833
|
-
|
|
832
|
+
string retval = cipher_key(self, false);
|
|
833
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
834
834
|
}
|
|
835
835
|
|
|
836
836
|
/**
|
|
837
837
|
* call-seq:
|
|
838
|
-
*
|
|
838
|
+
* key => String
|
|
839
839
|
*
|
|
840
840
|
* Returns the key set on the Cipher in hex.
|
|
841
841
|
*/
|
|
842
842
|
VALUE rb_cipher_key_hex(VALUE self)
|
|
843
843
|
{
|
|
844
|
-
|
|
845
|
-
|
|
844
|
+
string retval = cipher_key(self, true);
|
|
845
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
846
846
|
}
|
|
847
847
|
|
|
848
848
|
|
|
849
849
|
/**
|
|
850
850
|
* call-seq:
|
|
851
|
-
*
|
|
851
|
+
* key_length=(length) => Fixnum
|
|
852
852
|
*
|
|
853
853
|
* Sets the key length. Some ciphers require rather specific key lengths,
|
|
854
854
|
* and if the key length you attempt to set is invalid, an exception will
|
|
@@ -857,31 +857,31 @@ VALUE rb_cipher_key_hex(VALUE self)
|
|
|
857
857
|
*/
|
|
858
858
|
VALUE rb_cipher_key_length_eq(VALUE self, VALUE l)
|
|
859
859
|
{
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
860
|
+
JBase *cipher = NULL;
|
|
861
|
+
unsigned int length = NUM2UINT(rb_funcall(l, rb_intern("to_i"), 0));
|
|
862
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
863
|
+
cipher->setKeylength(length);
|
|
864
|
+
if (cipher->getKeylength() != length) {
|
|
865
|
+
rb_raise(rb_eCryptoPP_Error, "tried to set a key length of %d but %d was used", length, cipher->getKeylength());
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
return l;
|
|
869
|
+
}
|
|
870
870
|
}
|
|
871
871
|
|
|
872
872
|
|
|
873
873
|
/**
|
|
874
874
|
* call-seq:
|
|
875
|
-
*
|
|
875
|
+
* key_length => Fixnum
|
|
876
876
|
*
|
|
877
877
|
* Gets the key length. The key length being returned in terms of bytes
|
|
878
878
|
* in binary, not hex characters.
|
|
879
879
|
*/
|
|
880
880
|
VALUE rb_cipher_key_length(VALUE self)
|
|
881
881
|
{
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
882
|
+
JBase *cipher = NULL;
|
|
883
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
884
|
+
return rb_fix_new(cipher->getKeylength());
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
|
|
@@ -890,9 +890,9 @@ VALUE rb_cipher_key_length(VALUE self)
|
|
|
890
890
|
*/
|
|
891
891
|
VALUE rb_cipher_default_key_length(VALUE self)
|
|
892
892
|
{
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
893
|
+
JBase *cipher = NULL;
|
|
894
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
895
|
+
return rb_fix_new(cipher->getDefaultKeylength());
|
|
896
896
|
}
|
|
897
897
|
|
|
898
898
|
/**
|
|
@@ -900,9 +900,9 @@ VALUE rb_cipher_default_key_length(VALUE self)
|
|
|
900
900
|
*/
|
|
901
901
|
VALUE rb_cipher_min_key_length(VALUE self)
|
|
902
902
|
{
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
903
|
+
JBase *cipher = NULL;
|
|
904
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
905
|
+
return rb_fix_new(cipher->getMinKeylength());
|
|
906
906
|
}
|
|
907
907
|
|
|
908
908
|
/**
|
|
@@ -910,9 +910,9 @@ VALUE rb_cipher_min_key_length(VALUE self)
|
|
|
910
910
|
*/
|
|
911
911
|
VALUE rb_cipher_max_key_length(VALUE self)
|
|
912
912
|
{
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
913
|
+
JBase *cipher = NULL;
|
|
914
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
915
|
+
return rb_fix_new(cipher->getMaxKeylength());
|
|
916
916
|
}
|
|
917
917
|
|
|
918
918
|
/**
|
|
@@ -920,9 +920,9 @@ VALUE rb_cipher_max_key_length(VALUE self)
|
|
|
920
920
|
*/
|
|
921
921
|
VALUE rb_cipher_mult_key_length(VALUE self)
|
|
922
922
|
{
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
923
|
+
JBase *cipher = NULL;
|
|
924
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
925
|
+
return rb_fix_new(cipher->getMultKeylength());
|
|
926
926
|
}
|
|
927
927
|
|
|
928
928
|
/**
|
|
@@ -930,17 +930,17 @@ VALUE rb_cipher_mult_key_length(VALUE self)
|
|
|
930
930
|
*/
|
|
931
931
|
VALUE rb_cipher_valid_key_length(VALUE self, VALUE l)
|
|
932
932
|
{
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
933
|
+
JBase *cipher = NULL;
|
|
934
|
+
unsigned int length = NUM2UINT(l);
|
|
935
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
936
|
+
return rb_fix_new(cipher->getValidKeylength(length));
|
|
937
937
|
}
|
|
938
938
|
|
|
939
939
|
|
|
940
940
|
#if ENABLED_RC2_CIPHER
|
|
941
941
|
/**
|
|
942
942
|
* call-seq:
|
|
943
|
-
*
|
|
943
|
+
* effect_key_length=(length) => Fixnum
|
|
944
944
|
*
|
|
945
945
|
* Set the effective keylength on the RC2 algorithm. This function can
|
|
946
946
|
* only be used with RC2. Returns the actual effective keylength set. The
|
|
@@ -948,21 +948,21 @@ VALUE rb_cipher_valid_key_length(VALUE self, VALUE l)
|
|
|
948
948
|
*/
|
|
949
949
|
VALUE rb_cipher_effective_key_length_eq(VALUE self, VALUE l)
|
|
950
950
|
{
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
951
|
+
JBase *cipher = NULL;
|
|
952
|
+
unsigned int length = NUM2UINT(rb_funcall(l, rb_intern("to_i"), 0));
|
|
953
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
954
|
+
if (cipher->getCipherType() != RC2_CIPHER) {
|
|
955
|
+
rb_raise(rb_eCryptoPP_Error, "effective key lengths can only be used with the RC2 cipher");
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
((JRC2*) cipher)->setEffectiveKeylength(length);
|
|
959
|
+
if (((JRC2*) cipher)->getEffectiveKeylength() != length) {
|
|
960
|
+
rb_raise(rb_eCryptoPP_Error, "tried to set an effective key length of %d but %d was used", length, ((JRC2*) cipher)->getEffectiveKeylength());
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
return l;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
966
|
}
|
|
967
967
|
|
|
968
968
|
|
|
@@ -972,30 +972,30 @@ VALUE rb_cipher_effective_key_length_eq(VALUE self, VALUE l)
|
|
|
972
972
|
*/
|
|
973
973
|
VALUE rb_cipher_effective_key_length(VALUE self)
|
|
974
974
|
{
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
975
|
+
JBase *cipher = NULL;
|
|
976
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
977
|
+
return rb_fix_new(((JRC2*) cipher)->getEffectiveKeylength());
|
|
978
978
|
}
|
|
979
979
|
#endif
|
|
980
980
|
|
|
981
981
|
|
|
982
982
|
/**
|
|
983
983
|
* call-seq:
|
|
984
|
-
*
|
|
984
|
+
* block_size => Fixnum
|
|
985
985
|
*
|
|
986
986
|
* Gets the block size.
|
|
987
987
|
*/
|
|
988
988
|
VALUE rb_cipher_block_size(VALUE self)
|
|
989
989
|
{
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
990
|
+
JBase *cipher = NULL;
|
|
991
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
992
|
+
return rb_fix_new(cipher->getBlockSize());
|
|
993
993
|
}
|
|
994
994
|
|
|
995
995
|
|
|
996
996
|
/**
|
|
997
997
|
* call-seq:
|
|
998
|
-
*
|
|
998
|
+
* rounds=(rounds) => Fixnum
|
|
999
999
|
*
|
|
1000
1000
|
* Sets the number of rounds to perform on block ciphers. Some block ciphers
|
|
1001
1001
|
* have different requirements for their rounds than others. An exception
|
|
@@ -1003,41 +1003,41 @@ VALUE rb_cipher_block_size(VALUE self)
|
|
|
1003
1003
|
*/
|
|
1004
1004
|
VALUE rb_cipher_rounds_eq(VALUE self, VALUE r)
|
|
1005
1005
|
{
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1006
|
+
JBase *cipher = NULL;
|
|
1007
|
+
unsigned int rounds = NUM2UINT(rb_funcall(r, rb_intern("to_i"), 0));
|
|
1008
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1009
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
1010
|
+
rb_raise(rb_eCryptoPP_Error, "can't set rounds on stream ciphers");
|
|
1011
|
+
}
|
|
1012
|
+
else {
|
|
1013
|
+
((JCipher*) cipher)->setRounds(rounds);
|
|
1014
|
+
if (((JCipher*) cipher)->getRounds() != rounds) {
|
|
1015
|
+
rb_raise(rb_eCryptoPP_Error, "tried set the number of rounds to %d but %d was used instead", rounds, ((JCipher*) cipher)->getRounds());
|
|
1016
|
+
}
|
|
1017
|
+
else {
|
|
1018
|
+
return r;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
1023
1023
|
|
|
1024
1024
|
/**
|
|
1025
1025
|
* call-seq:
|
|
1026
|
-
*
|
|
1026
|
+
* rounts => Fixnum
|
|
1027
1027
|
*
|
|
1028
1028
|
* Gets the number of rounds to perform on block ciphers. Returns nil if you
|
|
1029
1029
|
* try to use this on a stream cipher.
|
|
1030
1030
|
*/
|
|
1031
1031
|
VALUE rb_cipher_rounds(VALUE self)
|
|
1032
1032
|
{
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1033
|
+
JBase *cipher = NULL;
|
|
1034
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1035
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
1036
|
+
return Qnil;
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
return rb_fix_new(((JCipher*) cipher)->getRounds());
|
|
1040
|
+
}
|
|
1041
1041
|
}
|
|
1042
1042
|
|
|
1043
1043
|
|
|
@@ -1046,20 +1046,20 @@ VALUE rb_cipher_rounds(VALUE self)
|
|
|
1046
1046
|
* will always be available through the ciphertext methods regardless. */
|
|
1047
1047
|
static VALUE cipher_encrypt(VALUE self, bool hex)
|
|
1048
1048
|
{
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1049
|
+
JBase *cipher = NULL;
|
|
1050
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1051
|
+
try {
|
|
1052
|
+
cipher->encrypt();
|
|
1053
|
+
return rb_tainted_str_new(cipher->getCiphertext(hex).data(), cipher->getCiphertext(hex).length());
|
|
1054
|
+
}
|
|
1055
|
+
catch (Exception e) {
|
|
1056
|
+
rb_raise(rb_eCryptoPP_Error, "Crypto++ exception: %s", e.GetWhat().c_str());
|
|
1057
|
+
}
|
|
1058
1058
|
}
|
|
1059
1059
|
|
|
1060
1060
|
/**
|
|
1061
1061
|
* call-seq:
|
|
1062
|
-
*
|
|
1062
|
+
* encrypt => String
|
|
1063
1063
|
*
|
|
1064
1064
|
* Encrypt the plaintext using the options set on the Cipher. This method will
|
|
1065
1065
|
* return the ciphertext in binary. The raw ciphertext will always be available
|
|
@@ -1067,12 +1067,12 @@ static VALUE cipher_encrypt(VALUE self, bool hex)
|
|
|
1067
1067
|
*/
|
|
1068
1068
|
VALUE rb_cipher_encrypt(VALUE self)
|
|
1069
1069
|
{
|
|
1070
|
-
|
|
1070
|
+
return cipher_encrypt(self, false);
|
|
1071
1071
|
}
|
|
1072
1072
|
|
|
1073
1073
|
/**
|
|
1074
1074
|
* call-seq:
|
|
1075
|
-
*
|
|
1075
|
+
* encrypt_hex => String
|
|
1076
1076
|
*
|
|
1077
1077
|
* Encrypt the plaintext using the options set on the Cipher. This method will
|
|
1078
1078
|
* return the ciphertext in hex. The raw ciphertext will always be available
|
|
@@ -1080,7 +1080,7 @@ VALUE rb_cipher_encrypt(VALUE self)
|
|
|
1080
1080
|
*/
|
|
1081
1081
|
VALUE rb_cipher_encrypt_hex(VALUE self)
|
|
1082
1082
|
{
|
|
1083
|
-
|
|
1083
|
+
return cipher_encrypt(self, true);
|
|
1084
1084
|
}
|
|
1085
1085
|
|
|
1086
1086
|
|
|
@@ -1090,21 +1090,21 @@ VALUE rb_cipher_encrypt_hex(VALUE self)
|
|
|
1090
1090
|
* available through the plaintext methods regardless. */
|
|
1091
1091
|
static VALUE cipher_decrypt(VALUE self, bool hex)
|
|
1092
1092
|
{
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1093
|
+
JBase *cipher = NULL;
|
|
1094
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1095
|
+
try {
|
|
1096
|
+
cipher->decrypt();
|
|
1097
|
+
string retval = cipher->getPlaintext(hex);
|
|
1098
|
+
return rb_tainted_str_new(retval.data(), retval.length());
|
|
1099
|
+
}
|
|
1100
|
+
catch (Exception e) {
|
|
1101
|
+
rb_raise(rb_eCryptoPP_Error, "Crypto++ exception: %s", e.GetWhat().c_str());
|
|
1102
|
+
}
|
|
1103
1103
|
}
|
|
1104
1104
|
|
|
1105
1105
|
/**
|
|
1106
1106
|
* call-seq:
|
|
1107
|
-
*
|
|
1107
|
+
* decrypt => String
|
|
1108
1108
|
*
|
|
1109
1109
|
* Decrypt the ciphertext using the options set on the Cipher. This method
|
|
1110
1110
|
* will return the plaintext in binary. The raw plaintext will always be
|
|
@@ -1112,12 +1112,12 @@ static VALUE cipher_decrypt(VALUE self, bool hex)
|
|
|
1112
1112
|
*/
|
|
1113
1113
|
VALUE rb_cipher_decrypt(VALUE self)
|
|
1114
1114
|
{
|
|
1115
|
-
|
|
1115
|
+
return cipher_decrypt(self, false);
|
|
1116
1116
|
}
|
|
1117
1117
|
|
|
1118
1118
|
/**
|
|
1119
1119
|
* call-seq:
|
|
1120
|
-
*
|
|
1120
|
+
* decrypt_hex => String
|
|
1121
1121
|
*
|
|
1122
1122
|
* Decrypt the ciphertext using the options set on the Cipher. This method
|
|
1123
1123
|
* will return the plaintext in hex. The raw plaintext will always be
|
|
@@ -1125,13 +1125,13 @@ VALUE rb_cipher_decrypt(VALUE self)
|
|
|
1125
1125
|
*/
|
|
1126
1126
|
VALUE rb_cipher_decrypt_hex(VALUE self)
|
|
1127
1127
|
{
|
|
1128
|
-
|
|
1128
|
+
return cipher_decrypt(self, true);
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
1131
|
|
|
1132
1132
|
/**
|
|
1133
1133
|
* call-seq:
|
|
1134
|
-
*
|
|
1134
|
+
* encrypt_io(in, out) => true
|
|
1135
1135
|
*
|
|
1136
1136
|
* Encrypts a Ruby IO object and spits the result into another one. You can use
|
|
1137
1137
|
* any sort of Ruby object as long as it implements <tt>eof?</tt>,
|
|
@@ -1139,28 +1139,28 @@ VALUE rb_cipher_decrypt_hex(VALUE self)
|
|
|
1139
1139
|
*
|
|
1140
1140
|
* Examples:
|
|
1141
1141
|
*
|
|
1142
|
-
*
|
|
1142
|
+
* cipher.encrypt_io(File.open("http://example.com/"), File.open("test.out", 'w'))
|
|
1143
1143
|
*
|
|
1144
|
-
*
|
|
1145
|
-
*
|
|
1144
|
+
* output = StringIO.new
|
|
1145
|
+
* cipher.encrypt_io(File.open('test.enc'), output)
|
|
1146
1146
|
*/
|
|
1147
1147
|
VALUE rb_cipher_encrypt_io(VALUE self, VALUE in, VALUE out)
|
|
1148
1148
|
{
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1149
|
+
JBase *cipher = NULL;
|
|
1150
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1151
|
+
try {
|
|
1152
|
+
cipher->encryptRubyIO(&in, &out);
|
|
1153
|
+
return Qtrue;
|
|
1154
|
+
}
|
|
1155
|
+
catch (Exception e) {
|
|
1156
|
+
rb_raise(rb_eCryptoPP_Error, "Crypto++ exception: %s", e.GetWhat().c_str());
|
|
1157
|
+
}
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
1160
|
|
|
1161
1161
|
/**
|
|
1162
1162
|
* call-seq:
|
|
1163
|
-
*
|
|
1163
|
+
* decrypt_io(in, out) => true
|
|
1164
1164
|
*
|
|
1165
1165
|
* Decrypts a Ruby IO object and spits the result into another one. You can use
|
|
1166
1166
|
* any sort of Ruby object as long as it implements <tt>eof?</tt>,
|
|
@@ -1168,235 +1168,235 @@ VALUE rb_cipher_encrypt_io(VALUE self, VALUE in, VALUE out)
|
|
|
1168
1168
|
*
|
|
1169
1169
|
* Examples:
|
|
1170
1170
|
*
|
|
1171
|
-
*
|
|
1171
|
+
* cipher.decrypt_io(File.open("http://example.com/"), File.open("test.out", 'w'))
|
|
1172
1172
|
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1173
|
+
* output = StringIO.new
|
|
1174
|
+
* cipher.decrypt_io(File.open('test.enc'), output)
|
|
1175
1175
|
*/
|
|
1176
1176
|
VALUE rb_cipher_decrypt_io(VALUE self, VALUE in, VALUE out)
|
|
1177
1177
|
{
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1178
|
+
JBase *cipher = NULL;
|
|
1179
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1180
|
+
try {
|
|
1181
|
+
cipher->decryptRubyIO(&in, &out);
|
|
1182
|
+
return Qtrue;
|
|
1183
|
+
}
|
|
1184
|
+
catch (Exception e) {
|
|
1185
|
+
rb_raise(rb_eCryptoPP_Error, "Crypto++ exception: %s", e.GetWhat().c_str());
|
|
1186
|
+
}
|
|
1187
1187
|
}
|
|
1188
1188
|
|
|
1189
1189
|
|
|
1190
1190
|
/**
|
|
1191
1191
|
* call-seq:
|
|
1192
|
-
*
|
|
1192
|
+
* cipher_name(algorithm) => String
|
|
1193
1193
|
*
|
|
1194
1194
|
* Returns the name of a Cipher.
|
|
1195
1195
|
*/
|
|
1196
1196
|
VALUE rb_module_cipher_name(VALUE self, VALUE c)
|
|
1197
1197
|
{
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1198
|
+
switch (cipher_sym_to_const(c)) {
|
|
1199
|
+
default:
|
|
1200
|
+
rb_raise(rb_eCryptoPP_Error, "could not find a valid cipher type");
|
|
1201
|
+
break;
|
|
1202
1202
|
|
|
1203
|
-
#
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
#
|
|
1207
|
-
|
|
1203
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
1204
|
+
case r ## _CIPHER: \
|
|
1205
|
+
return rb_tainted_str_new2(c::getStaticCipherName().c_str());
|
|
1206
|
+
# include "defs/ciphers.def"
|
|
1207
|
+
}
|
|
1208
1208
|
}
|
|
1209
1209
|
|
|
1210
1210
|
|
|
1211
1211
|
/**
|
|
1212
1212
|
* call-seq:
|
|
1213
|
-
*
|
|
1213
|
+
* algorithm_name() => String
|
|
1214
1214
|
*
|
|
1215
1215
|
* Returns the name of the cipher algorithm being used.
|
|
1216
1216
|
*/
|
|
1217
1217
|
VALUE rb_cipher_algorithm_name(VALUE self)
|
|
1218
1218
|
{
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1219
|
+
JBase *cipher = NULL;
|
|
1220
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1221
|
+
return rb_tainted_str_new2(cipher->getCipherName().c_str());
|
|
1222
1222
|
}
|
|
1223
1223
|
|
|
1224
1224
|
|
|
1225
1225
|
/**
|
|
1226
1226
|
* call-seq:
|
|
1227
|
-
*
|
|
1227
|
+
* block_mode_name(block_mode) => String
|
|
1228
1228
|
*
|
|
1229
1229
|
* Singleton method to return the name of a block cipher mode.
|
|
1230
1230
|
*/
|
|
1231
1231
|
VALUE rb_module_block_mode_name(VALUE self, VALUE m)
|
|
1232
1232
|
{
|
|
1233
|
-
|
|
1233
|
+
return rb_tainted_str_new2(JCipher::getModeName(mode_sym_to_const(m)).c_str());
|
|
1234
1234
|
}
|
|
1235
1235
|
|
|
1236
1236
|
|
|
1237
1237
|
/**
|
|
1238
1238
|
* call-seq:
|
|
1239
|
-
*
|
|
1239
|
+
* block_mode_name() => String
|
|
1240
1240
|
*
|
|
1241
1241
|
* Returns the name of the mode being used.
|
|
1242
1242
|
*/
|
|
1243
1243
|
VALUE rb_cipher_block_mode_name(VALUE self)
|
|
1244
1244
|
{
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1245
|
+
JBase *cipher = NULL;
|
|
1246
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1247
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
1248
|
+
return Qnil;
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
return rb_tainted_str_new2(JCipher::getModeName(((JCipher*) cipher)->getMode()).c_str());
|
|
1252
|
+
}
|
|
1253
1253
|
}
|
|
1254
1254
|
|
|
1255
1255
|
|
|
1256
1256
|
/**
|
|
1257
1257
|
* call-seq:
|
|
1258
|
-
*
|
|
1258
|
+
* padding_name(padding) => String
|
|
1259
1259
|
*
|
|
1260
1260
|
* Singleton method to return the name of the a block cipher padding mode.
|
|
1261
1261
|
*/
|
|
1262
1262
|
VALUE rb_module_padding_name(VALUE self, VALUE p)
|
|
1263
1263
|
{
|
|
1264
|
-
|
|
1264
|
+
return rb_tainted_str_new2(JCipher::getPaddingName(padding_sym_to_const(p)).c_str());
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
1267
1267
|
|
|
1268
1268
|
/**
|
|
1269
1269
|
* call-seq:
|
|
1270
|
-
*
|
|
1270
|
+
* padding_name() => String
|
|
1271
1271
|
*
|
|
1272
1272
|
* Returns the name of the padding being used.
|
|
1273
1273
|
*/
|
|
1274
1274
|
VALUE rb_cipher_padding_name(VALUE self)
|
|
1275
1275
|
{
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1276
|
+
JBase *cipher = NULL;
|
|
1277
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1278
|
+
if (IS_STREAM_CIPHER(cipher->getCipherType())) {
|
|
1279
|
+
return Qnil;
|
|
1280
|
+
}
|
|
1281
|
+
else {
|
|
1282
|
+
return rb_tainted_str_new2(JCipher::getPaddingName(((JCipher*) cipher)->getPadding()).c_str());
|
|
1283
|
+
}
|
|
1284
1284
|
}
|
|
1285
1285
|
|
|
1286
1286
|
|
|
1287
1287
|
/**
|
|
1288
1288
|
* call-seq:
|
|
1289
|
-
*
|
|
1289
|
+
* rng_name(rng) => String
|
|
1290
1290
|
*
|
|
1291
1291
|
* Singleton method to return the name of the random number generator being
|
|
1292
1292
|
* used.
|
|
1293
1293
|
*/
|
|
1294
1294
|
VALUE rb_module_rng_name(VALUE self, VALUE r)
|
|
1295
1295
|
{
|
|
1296
|
-
|
|
1296
|
+
return rb_tainted_str_new2(JCipher::getRNGName(rng_sym_to_const(r)).c_str());
|
|
1297
1297
|
}
|
|
1298
1298
|
|
|
1299
1299
|
|
|
1300
1300
|
/**
|
|
1301
1301
|
* call-seq:
|
|
1302
|
-
*
|
|
1302
|
+
* rng_name() => String
|
|
1303
1303
|
*
|
|
1304
1304
|
* Returns the name of the random number generator being used.
|
|
1305
1305
|
*/
|
|
1306
1306
|
VALUE rb_cipher_rng_name(VALUE self)
|
|
1307
1307
|
{
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1308
|
+
JBase *cipher = NULL;
|
|
1309
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1310
|
+
return rb_tainted_str_new2(JCipher::getRNGName(cipher->getRNG()).c_str());
|
|
1311
1311
|
}
|
|
1312
1312
|
|
|
1313
1313
|
|
|
1314
1314
|
/**
|
|
1315
1315
|
* call-seq:
|
|
1316
|
-
*
|
|
1316
|
+
* cipher_type() => Symbol
|
|
1317
1317
|
*
|
|
1318
1318
|
* Returns the type of cipher being used as a Symbol.
|
|
1319
1319
|
*/
|
|
1320
1320
|
VALUE rb_cipher_cipher_type(VALUE self)
|
|
1321
1321
|
{
|
|
1322
|
-
|
|
1323
|
-
|
|
1322
|
+
JBase *cipher = NULL;
|
|
1323
|
+
Data_Get_Struct(self, JBase, cipher);
|
|
1324
1324
|
|
|
1325
|
-
|
|
1326
|
-
#
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
#
|
|
1325
|
+
switch (cipher->getCipherType()) {
|
|
1326
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
1327
|
+
case r ## _CIPHER: \
|
|
1328
|
+
return ID2SYM(rb_intern(# s));
|
|
1329
|
+
# include "defs/ciphers.def"
|
|
1330
1330
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1331
|
+
default:
|
|
1332
|
+
return Qnil;
|
|
1333
|
+
}
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
1336
|
|
|
1337
1337
|
/**
|
|
1338
1338
|
* call-seq:
|
|
1339
|
-
*
|
|
1339
|
+
* cipher_enabled?(algorithm) => boolean
|
|
1340
1340
|
*
|
|
1341
1341
|
* Singleton method to check for the availability of a cipher algorithm.
|
|
1342
1342
|
*/
|
|
1343
1343
|
VALUE rb_module_cipher_enabled(VALUE self, VALUE c)
|
|
1344
1344
|
{
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1345
|
+
switch (cipher_sym_to_const(c)) {
|
|
1346
|
+
default:
|
|
1347
|
+
return Qfalse;
|
|
1348
1348
|
|
|
1349
|
-
#
|
|
1350
|
-
|
|
1351
|
-
#
|
|
1352
|
-
|
|
1353
|
-
|
|
1349
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
1350
|
+
case r ## _CIPHER:
|
|
1351
|
+
# include "defs/ciphers.def"
|
|
1352
|
+
return Qtrue;
|
|
1353
|
+
}
|
|
1354
1354
|
}
|
|
1355
1355
|
|
|
1356
1356
|
|
|
1357
1357
|
/**
|
|
1358
1358
|
* call-seq:
|
|
1359
|
-
*
|
|
1359
|
+
* rng_available?(rng) => boolean
|
|
1360
1360
|
*
|
|
1361
1361
|
* Singleton method to check for the availability of a random number generator.
|
|
1362
1362
|
*/
|
|
1363
1363
|
VALUE rb_module_rng_available(VALUE self, VALUE r)
|
|
1364
1364
|
{
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
#
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
#
|
|
1365
|
+
ID id = SYM2ID(r);
|
|
1366
|
+
if (id == rb_intern("rand")) {
|
|
1367
|
+
return Qtrue;
|
|
1368
|
+
}
|
|
1369
|
+
# ifdef NONBLOCKING_RNG_AVAILABLE
|
|
1370
|
+
else if (id == rb_intern("non_blocking")) {
|
|
1371
|
+
return Qtrue;
|
|
1372
|
+
}
|
|
1373
|
+
# endif
|
|
1374
1374
|
|
|
1375
|
-
#
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
#
|
|
1375
|
+
# ifdef BLOCKING_RNG_AVAILABLE
|
|
1376
|
+
else if (id == rb_intern("blocking")) {
|
|
1377
|
+
return Qtrue;
|
|
1378
|
+
}
|
|
1379
|
+
# endif
|
|
1380
1380
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1381
|
+
else {
|
|
1382
|
+
return Qfalse;
|
|
1383
|
+
}
|
|
1384
1384
|
}
|
|
1385
1385
|
|
|
1386
1386
|
|
|
1387
1387
|
/**
|
|
1388
1388
|
* call-seq:
|
|
1389
|
-
*
|
|
1389
|
+
* cipher_list() => Array
|
|
1390
1390
|
*
|
|
1391
1391
|
* Returns an Array of available ciphers.
|
|
1392
1392
|
*/
|
|
1393
1393
|
VALUE rb_module_cipher_list(VALUE self)
|
|
1394
1394
|
{
|
|
1395
|
-
|
|
1395
|
+
VALUE ary = rb_ary_new();
|
|
1396
1396
|
|
|
1397
|
-
#
|
|
1398
|
-
|
|
1399
|
-
#
|
|
1397
|
+
# define CIPHER_ALGORITHM_X(klass, r, c, s) \
|
|
1398
|
+
rb_ary_push(ary, ID2SYM(rb_intern(# s)));
|
|
1399
|
+
# include "defs/ciphers.def"
|
|
1400
1400
|
|
|
1401
|
-
|
|
1401
|
+
return ary;
|
|
1402
1402
|
}
|