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
data/ext/jcipher.h
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
|
#ifndef __JCIPHER_H__
|
|
@@ -16,27 +16,27 @@
|
|
|
16
16
|
|
|
17
17
|
class JCipher : public JBase
|
|
18
18
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
19
|
+
public:
|
|
20
|
+
JCipher();
|
|
21
|
+
|
|
22
|
+
string getModeName() const;
|
|
23
|
+
static string getModeName(const enum ModeEnum mode);
|
|
24
|
+
enum ModeEnum getMode() const;
|
|
25
|
+
void setMode(const enum ModeEnum mode);
|
|
26
|
+
|
|
27
|
+
string getPaddingName() const;
|
|
28
|
+
static string getPaddingName(const enum PaddingEnum padding);
|
|
29
|
+
enum PaddingEnum getPadding() const;
|
|
30
|
+
enum PaddingEnum setPadding(const enum PaddingEnum padding);
|
|
31
|
+
|
|
32
|
+
unsigned int getRounds() const;
|
|
33
|
+
unsigned int setRounds(const unsigned int rounds);
|
|
34
|
+
virtual unsigned int getValidRounds(const unsigned int rounds) const = 0;
|
|
35
|
+
|
|
36
|
+
protected:
|
|
37
|
+
enum ModeEnum itsMode;
|
|
38
|
+
enum PaddingEnum itsPadding;
|
|
39
|
+
unsigned int itsRounds;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
#endif
|
data/ext/jcipher_t.h
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
|
#ifndef __JCIPHER_T_H__
|
|
@@ -13,313 +13,313 @@
|
|
|
13
13
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS = 0, unsigned int MIN_ROUNDS = 0, unsigned int MAX_ROUNDS = 0>
|
|
14
14
|
class JCipher_Template : public JBasicCipherInfo<INFO, JCipher>
|
|
15
15
|
{
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
public:
|
|
17
|
+
JCipher_Template();
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
inline unsigned int getValidRounds(const unsigned int rounds) const;
|
|
20
|
+
inline enum CipherEnum getCipherType() const;
|
|
21
|
+
inline unsigned int getBlockSize() const;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
bool encrypt();
|
|
24
|
+
bool decrypt();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
bool encryptRubyIO(VALUE* in, VALUE* out);
|
|
27
|
+
bool decryptRubyIO(VALUE* in, VALUE* out);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
//
|
|
29
|
+
/* These are deprecated. They were used before using RubyIO. Use them
|
|
30
|
+
if you're using this code in something other than the CryptoPP Ruby
|
|
31
|
+
extension... */
|
|
32
|
+
// bool encryptFile(const string in, const string out);
|
|
33
|
+
// bool decryptFile(const string in, const string out);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
protected:
|
|
36
|
+
virtual BlockCipher* getEncryptionObject() = 0;
|
|
37
|
+
virtual BlockCipher* getDecryptionObject() = 0;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
41
41
|
JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::JCipher_Template()
|
|
42
42
|
{
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
this->itsKeylength = INFO::DEFAULT_KEYLENGTH;
|
|
44
|
+
this->itsRounds = DEFAULT_ROUNDS;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
48
48
|
unsigned int JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::getValidRounds(const unsigned int rounds) const
|
|
49
49
|
{
|
|
50
|
-
|
|
50
|
+
return checkBounds(rounds, MIN_ROUNDS, MAX_ROUNDS);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
54
54
|
CipherEnum JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::getCipherType() const
|
|
55
55
|
{
|
|
56
|
-
|
|
56
|
+
return TYPE;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
60
60
|
unsigned int JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::getBlockSize() const
|
|
61
61
|
{
|
|
62
|
-
|
|
62
|
+
return INFO::BLOCKSIZE;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
66
66
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::encrypt()
|
|
67
67
|
{
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
BlockCipher* bc = NULL;
|
|
69
|
+
CipherModeBase* cipher = NULL;
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
bc = getEncryptionObject();
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
if (bc != NULL) {
|
|
74
|
+
switch (this->itsMode) {
|
|
75
|
+
case ECB_MODE:
|
|
76
|
+
cipher = new ECB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
77
|
+
break;
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
case CBC_MODE:
|
|
80
|
+
cipher = new CBC_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
81
|
+
break;
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
case CBC_CTS_MODE:
|
|
84
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
85
|
+
break;
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
case CFB_MODE:
|
|
88
|
+
cipher = new CFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
89
|
+
break;
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
case CTR_MODE:
|
|
92
|
+
cipher = new CTR_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
93
|
+
break;
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
case OFB_MODE:
|
|
96
|
+
cipher = new OFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
97
|
+
break;
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
default:
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
this->itsCiphertext.erase();
|
|
104
|
+
StringSource(this->itsPlaintext, true, new StreamTransformationFilter(*cipher, new StringSink(this->itsCiphertext), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
delete bc;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
if (cipher != NULL) {
|
|
113
|
+
delete cipher;
|
|
114
|
+
}
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
return true;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
120
120
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::decrypt()
|
|
121
121
|
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
122
|
+
BlockCipher* bc = NULL;
|
|
123
|
+
CipherModeBase* cipher = NULL;
|
|
124
|
+
|
|
125
|
+
switch (this->itsMode) {
|
|
126
|
+
case ECB_MODE:
|
|
127
|
+
case CBC_MODE:
|
|
128
|
+
case CBC_CTS_MODE:
|
|
129
|
+
bc = getDecryptionObject();
|
|
130
|
+
break;
|
|
131
|
+
|
|
132
|
+
case CFB_MODE:
|
|
133
|
+
case CTR_MODE:
|
|
134
|
+
case OFB_MODE:
|
|
135
|
+
bc = getEncryptionObject();
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
default:
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (bc != NULL) {
|
|
143
|
+
switch (this->itsMode) {
|
|
144
|
+
case ECB_MODE:
|
|
145
|
+
cipher = new ECB_Mode_ExternalCipher::Decryption(*bc);
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case CBC_MODE:
|
|
149
|
+
cipher = new CBC_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case CBC_CTS_MODE:
|
|
153
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
case CFB_MODE:
|
|
157
|
+
cipher = new CFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case CTR_MODE:
|
|
161
|
+
cipher = new CTR_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
162
|
+
break;
|
|
163
|
+
|
|
164
|
+
case OFB_MODE:
|
|
165
|
+
cipher = new OFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
166
|
+
break;
|
|
167
|
+
|
|
168
|
+
default:
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
this->itsPlaintext.erase();
|
|
173
|
+
StringSource(this->itsCiphertext, true, new StreamTransformationFilter(*cipher, new StringSink(this->itsPlaintext), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
174
|
+
|
|
175
|
+
delete bc;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (cipher != NULL) {
|
|
182
|
+
delete cipher;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return true;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
189
189
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::encryptRubyIO(VALUE* in, VALUE* out)
|
|
190
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
|
-
|
|
191
|
+
BlockCipher* bc = NULL;
|
|
192
|
+
CipherModeBase* cipher = NULL;
|
|
193
|
+
|
|
194
|
+
bc = getEncryptionObject();
|
|
195
|
+
|
|
196
|
+
if (bc != NULL) {
|
|
197
|
+
switch (this->itsMode) {
|
|
198
|
+
case ECB_MODE:
|
|
199
|
+
cipher = new ECB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
case CBC_MODE:
|
|
203
|
+
cipher = new CBC_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
case CBC_CTS_MODE:
|
|
207
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
208
|
+
break;
|
|
209
|
+
|
|
210
|
+
case CFB_MODE:
|
|
211
|
+
cipher = new CFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
212
|
+
break;
|
|
213
|
+
|
|
214
|
+
case CTR_MODE:
|
|
215
|
+
cipher = new CTR_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
216
|
+
break;
|
|
217
|
+
|
|
218
|
+
case OFB_MODE:
|
|
219
|
+
cipher = new OFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
220
|
+
break;
|
|
221
|
+
|
|
222
|
+
default:
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
RubyIOSource(&in, true, new StreamTransformationFilter(*cipher, new RubyIOSink(&out), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
228
|
+
}
|
|
229
|
+
catch (RubyIOStore::OpenErr e) {
|
|
230
|
+
delete bc;
|
|
231
|
+
if (cipher != NULL)
|
|
232
|
+
delete cipher;
|
|
233
|
+
throw e;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
delete bc;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (cipher != NULL) {
|
|
243
|
+
delete cipher;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return true;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
250
250
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::decryptRubyIO(VALUE* in, VALUE* out)
|
|
251
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
252
|
+
BlockCipher* bc = NULL;
|
|
253
|
+
CipherModeBase* cipher = NULL;
|
|
254
|
+
|
|
255
|
+
switch (this->itsMode) {
|
|
256
|
+
case ECB_MODE:
|
|
257
|
+
case CBC_MODE:
|
|
258
|
+
case CBC_CTS_MODE:
|
|
259
|
+
bc = getDecryptionObject();
|
|
260
|
+
break;
|
|
261
|
+
|
|
262
|
+
case CFB_MODE:
|
|
263
|
+
case CTR_MODE:
|
|
264
|
+
case OFB_MODE:
|
|
265
|
+
bc = getEncryptionObject();
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
default:
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (bc != NULL) {
|
|
273
|
+
switch (this->itsMode) {
|
|
274
|
+
case ECB_MODE:
|
|
275
|
+
cipher = new ECB_Mode_ExternalCipher::Decryption(*bc);
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
case CBC_MODE:
|
|
279
|
+
cipher = new CBC_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case CBC_CTS_MODE:
|
|
283
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
284
|
+
break;
|
|
285
|
+
|
|
286
|
+
case CFB_MODE:
|
|
287
|
+
cipher = new CFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
288
|
+
break;
|
|
289
|
+
|
|
290
|
+
case CTR_MODE:
|
|
291
|
+
cipher = new CTR_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
292
|
+
break;
|
|
293
|
+
|
|
294
|
+
case OFB_MODE:
|
|
295
|
+
cipher = new OFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
296
|
+
break;
|
|
297
|
+
|
|
298
|
+
default:
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
try {
|
|
303
|
+
RubyIOSource(&in, true, new StreamTransformationFilter(*cipher, new RubyIOSink(&out), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
304
|
+
}
|
|
305
|
+
catch (RubyIOStore::OpenErr e) {
|
|
306
|
+
delete bc;
|
|
307
|
+
if (cipher != NULL)
|
|
308
|
+
delete cipher;
|
|
309
|
+
throw e;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
delete bc;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (cipher != NULL) {
|
|
319
|
+
delete cipher;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return true;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
/* These are deprecated. They were used before using RubyIO. Use them
|
|
@@ -328,141 +328,141 @@ bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::decry
|
|
|
328
328
|
/*template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
329
329
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::encryptFile(const string in, const string out)
|
|
330
330
|
{
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
331
|
+
BlockCipher* bc = NULL;
|
|
332
|
+
CipherModeBase* cipher = NULL;
|
|
333
|
+
|
|
334
|
+
bc = getEncryptionObject();
|
|
335
|
+
|
|
336
|
+
if (bc != NULL) {
|
|
337
|
+
switch (this->itsMode) {
|
|
338
|
+
case ECB_MODE:
|
|
339
|
+
cipher = new ECB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
340
|
+
break;
|
|
341
|
+
|
|
342
|
+
case CBC_MODE:
|
|
343
|
+
cipher = new CBC_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
344
|
+
break;
|
|
345
|
+
|
|
346
|
+
case CBC_CTS_MODE:
|
|
347
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
348
|
+
break;
|
|
349
|
+
|
|
350
|
+
case CFB_MODE:
|
|
351
|
+
cipher = new CFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
352
|
+
break;
|
|
353
|
+
|
|
354
|
+
case CTR_MODE:
|
|
355
|
+
cipher = new CTR_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
356
|
+
break;
|
|
357
|
+
|
|
358
|
+
case OFB_MODE:
|
|
359
|
+
cipher = new OFB_Mode_ExternalCipher::Encryption(*bc, (const byte*) this->itsIV.data());
|
|
360
|
+
break;
|
|
361
|
+
|
|
362
|
+
default:
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
try {
|
|
367
|
+
FileSource(in.c_str(), true, new StreamTransformationFilter(*cipher, new FileSink(out.c_str()), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
368
|
+
}
|
|
369
|
+
catch (FileStore::OpenErr e) {
|
|
370
|
+
delete bc;
|
|
371
|
+
if (cipher != NULL) {
|
|
372
|
+
delete cipher;
|
|
373
|
+
}
|
|
374
|
+
throw e;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
delete bc;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (cipher != NULL) {
|
|
384
|
+
delete cipher;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return true;
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
template <typename INFO, enum CipherEnum TYPE, unsigned int DEFAULT_ROUNDS, unsigned int MIN_ROUNDS, unsigned int MAX_ROUNDS>
|
|
391
391
|
bool JCipher_Template<INFO, TYPE, DEFAULT_ROUNDS, MIN_ROUNDS, MAX_ROUNDS>::decryptFile(const string in, const string out)
|
|
392
392
|
{
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
393
|
+
BlockCipher* bc = NULL;
|
|
394
|
+
CipherModeBase* cipher = NULL;
|
|
395
|
+
|
|
396
|
+
switch (this->itsMode) {
|
|
397
|
+
case ECB_MODE:
|
|
398
|
+
case CBC_MODE:
|
|
399
|
+
case CBC_CTS_MODE:
|
|
400
|
+
bc = getDecryptionObject();
|
|
401
|
+
break;
|
|
402
|
+
|
|
403
|
+
case CFB_MODE:
|
|
404
|
+
case CTR_MODE:
|
|
405
|
+
case OFB_MODE:
|
|
406
|
+
bc = getEncryptionObject();
|
|
407
|
+
break;
|
|
408
|
+
|
|
409
|
+
default:
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (bc != NULL) {
|
|
414
|
+
switch (this->itsMode) {
|
|
415
|
+
case ECB_MODE:
|
|
416
|
+
cipher = new ECB_Mode_ExternalCipher::Decryption(*bc);
|
|
417
|
+
break;
|
|
418
|
+
|
|
419
|
+
case CBC_MODE:
|
|
420
|
+
cipher = new CBC_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
421
|
+
break;
|
|
422
|
+
|
|
423
|
+
case CBC_CTS_MODE:
|
|
424
|
+
cipher = new CBC_CTS_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
425
|
+
break;
|
|
426
|
+
|
|
427
|
+
case CFB_MODE:
|
|
428
|
+
cipher = new CFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
429
|
+
break;
|
|
430
|
+
|
|
431
|
+
case CTR_MODE:
|
|
432
|
+
cipher = new CTR_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
433
|
+
break;
|
|
434
|
+
|
|
435
|
+
case OFB_MODE:
|
|
436
|
+
cipher = new OFB_Mode_ExternalCipher::Decryption(*bc, (const byte*) this->itsIV.data());
|
|
437
|
+
break;
|
|
438
|
+
|
|
439
|
+
default:
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
try {
|
|
444
|
+
FileSource(in.c_str(), true, new StreamTransformationFilter(*cipher, new FileSink(out.c_str()), (StreamTransformationFilter::BlockPaddingScheme) this->itsPadding));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
catch (FileStore::OpenErr e) {
|
|
448
|
+
delete bc;
|
|
449
|
+
if (cipher != NULL) {
|
|
450
|
+
delete cipher;
|
|
451
|
+
}
|
|
452
|
+
throw e;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
delete bc;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (cipher != NULL) {
|
|
462
|
+
delete cipher;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return true;
|
|
466
466
|
}
|
|
467
467
|
*/
|
|
468
468
|
|