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/extconf.rb
CHANGED
|
@@ -1,39 +1,81 @@
|
|
|
1
1
|
|
|
2
2
|
require 'mkmf'
|
|
3
|
+
require 'rbconfig'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
if RbConfig::CONFIG["arch"] =~ /-darwin\d/
|
|
6
|
+
if $warnflags
|
|
7
|
+
$warnflags << ' -Wno-shorten-64-to-32'
|
|
8
|
+
$warnflags.gsub!('-Wdeclaration-after-statement', '')
|
|
9
|
+
$warnflags.gsub!('-Wimplicit-function-declaration', '')
|
|
10
|
+
end
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if Config::CONFIG["arch"] =~ /-darwin\d/
|
|
11
|
-
Config::CONFIG['LDSHARED']="g++ -dynamic -bundle -undefined suppress -flat_namespace"
|
|
12
|
+
CONFIG["CXX"] = "clang++"
|
|
13
|
+
elsif RbConfig::CONFIG["arch"] =~ /x86_64-freebsd/
|
|
14
|
+
$LDFLAGS << " -fPIC -shared"
|
|
12
15
|
else
|
|
13
|
-
|
|
16
|
+
$LDFLAGS << " -shared"
|
|
14
17
|
end
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
version = File.read(File.join(File.dirname(__FILE__), *%w{ .. VERSION })).strip
|
|
20
|
+
ruby_version = RbConfig::CONFIG.values_at('MAJOR', 'MINOR', 'TEENY').join
|
|
21
|
+
|
|
22
|
+
$defs.concat([
|
|
23
|
+
"-DNDEBUG",
|
|
24
|
+
"-DCRYPTOPP_DISABLE_ASM",
|
|
25
|
+
"-DRUBY_VERSION_CODE=#{ruby_version}",
|
|
26
|
+
"-DEXT_VERSION_CODE=#{version}"
|
|
27
|
+
])
|
|
17
28
|
|
|
18
29
|
def error msg
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
message msg + "\n"
|
|
31
|
+
abort
|
|
21
32
|
end
|
|
22
33
|
|
|
23
|
-
unless
|
|
24
|
-
|
|
34
|
+
unless find_library('cryptopp', nil, *%w{
|
|
35
|
+
/usr/local/lib
|
|
36
|
+
/usr/local/lib/cryptopp
|
|
37
|
+
/opt/local/lib
|
|
38
|
+
/opt/local/lib/cryptopp
|
|
39
|
+
/usr/lib
|
|
40
|
+
/usr/lib/cryptopp
|
|
41
|
+
})
|
|
42
|
+
error "Can't find cryptopp library"
|
|
25
43
|
end
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
# For the C++ headers, we need to compile using a C++ compiler since the header
|
|
46
|
+
# files can't compile cleanly in C.
|
|
47
|
+
puts "NOTE: The following warning is NORMAL due to an mkmf hack."
|
|
48
|
+
|
|
49
|
+
if defined?(MakeMakefile)
|
|
50
|
+
MakeMakefile::CONFTEST_C = 'conftest.cc'
|
|
51
|
+
else
|
|
52
|
+
CONFTEST_C = 'conftest.cc'
|
|
29
53
|
end
|
|
30
54
|
|
|
31
55
|
unless find_header('cryptlib.h', *%w{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
56
|
+
/usr/local/include
|
|
57
|
+
/usr/local/include/cryptopp
|
|
58
|
+
/opt/local/include
|
|
59
|
+
/opt/local/include/cryptopp
|
|
60
|
+
/usr/include
|
|
61
|
+
/usr/include/cryptopp
|
|
35
62
|
})
|
|
36
|
-
|
|
63
|
+
error "Can't find cryptlib.h"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
have_blocksize = try_link(<<SRC)
|
|
67
|
+
#include "cryptlib.h"
|
|
68
|
+
#include "sha3.h"
|
|
69
|
+
|
|
70
|
+
int main() {
|
|
71
|
+
CryptoPP::SHA3_224::BLOCKSIZE;
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
SRC
|
|
75
|
+
|
|
76
|
+
if have_blocksize
|
|
77
|
+
$defs << "-DHAVE_CRYPTOPP_SHA3_BLOCKSIZE"
|
|
37
78
|
end
|
|
38
79
|
|
|
39
80
|
create_makefile('cryptopp')
|
|
81
|
+
|
data/ext/j3way.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"
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
BlockCipher* J3Way::getEncryptionObject()
|
|
13
13
|
{
|
|
14
|
-
|
|
14
|
+
return new ThreeWayEncryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
BlockCipher* J3Way::getDecryptionObject()
|
|
18
18
|
{
|
|
19
|
-
|
|
19
|
+
return new ThreeWayDecryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
#endif
|
data/ext/j3way.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 __J3WAY_H__
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
class J3Way : public JCipher_Template<ThreeWay_Info, THREEWAY_CIPHER, 11, 1, INT_MAX>
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
protected:
|
|
24
|
+
BlockCipher* getEncryptionObject();
|
|
25
|
+
BlockCipher* getDecryptionObject();
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
#endif
|
data/ext/jadler32.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 __JADLER32_H__
|
|
@@ -22,10 +22,10 @@ using namespace CryptoPP;
|
|
|
22
22
|
|
|
23
23
|
class JAdler32 : public JHash_Template<Adler32, ADLER32_CHECKSUM>
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
public:
|
|
26
|
+
JAdler32(string plaintext = "") : JHash_Template<Adler32, ADLER32_CHECKSUM>(plaintext) { }
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
static string getHashName() { return "Adler32"; }
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
#endif
|
data/ext/jaes.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 "jaes.h"
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
BlockCipher* JAES::getEncryptionObject()
|
|
13
13
|
{
|
|
14
|
-
|
|
14
|
+
return new AESEncryption((byte*) itsKey.data(), itsKeylength);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
BlockCipher* JAES::getDecryptionObject()
|
|
18
18
|
{
|
|
19
|
-
|
|
19
|
+
return new AESDecryption((byte*) itsKey.data(), itsKeylength);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
#endif
|
data/ext/jaes.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 __JAES_H__
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
class JAES : public JCipher_Template<Rijndael_Info, AES_CIPHER>
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
protected:
|
|
24
|
+
BlockCipher* getEncryptionObject();
|
|
25
|
+
BlockCipher* getDecryptionObject();
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
typedef JAES JRijndael;
|
data/ext/jarc4.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 "jarc4.h"
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|
|
12
12
|
SymmetricCipher* JARC4::getEncryptionObject()
|
|
13
13
|
{
|
|
14
|
-
|
|
14
|
+
return new Weak::ARC4((byte*) itsKey.data(), itsKeylength);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
SymmetricCipher* JARC4::getDecryptionObject()
|
|
18
18
|
{
|
|
19
|
-
|
|
19
|
+
return getEncryptionObject();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
#endif
|
data/ext/jarc4.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 __JARC4_H__
|
|
@@ -26,9 +26,9 @@ using namespace CryptoPP;
|
|
|
26
26
|
|
|
27
27
|
class JARC4 : public JStream_Template<Weak::ARC4_Base, ARC4_CIPHER>
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
protected:
|
|
30
|
+
SymmetricCipher* getEncryptionObject();
|
|
31
|
+
SymmetricCipher* getDecryptionObject();
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
#undef CRYPTOPP_ENABLE_NAMESPACE_WEAK
|
data/ext/jbase.cpp
CHANGED
|
@@ -1,172 +1,172 @@
|
|
|
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 "jbase.h"
|
|
9
9
|
|
|
10
10
|
JBase::JBase()
|
|
11
11
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
itsPlaintext = "";
|
|
13
|
+
itsIV = "";
|
|
14
|
+
itsRNG = DEFAULT_RNG;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
string JBase::getPlaintext(const bool hex) const
|
|
18
18
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (hex) {
|
|
20
|
+
return bin2hex(itsPlaintext);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return itsPlaintext;
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
string JBase::getCiphertext(const bool hex) const
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (hex) {
|
|
30
|
+
return bin2hex(itsCiphertext);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return itsCiphertext;
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
string JBase::getKey(const bool hex) const
|
|
38
38
|
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
if (hex) {
|
|
40
|
+
return bin2hex(itsKey);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return itsKey;
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
unsigned int JBase::getKeylength() const
|
|
48
48
|
{
|
|
49
|
-
|
|
49
|
+
return itsKeylength;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
void JBase::setPlaintext(const string plaintext, const bool hex)
|
|
53
53
|
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
if (hex) {
|
|
55
|
+
itsPlaintext = hex2bin(plaintext);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
itsPlaintext = plaintext;
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
void JBase::setCiphertext(const string ciphertext, const bool hex)
|
|
63
63
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (hex) {
|
|
65
|
+
itsCiphertext = hex2bin(ciphertext);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
itsCiphertext = ciphertext;
|
|
69
|
+
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
unsigned int JBase::setKey(const string key, const bool hex)
|
|
73
73
|
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
if (hex) {
|
|
75
|
+
itsKey = hex2bin(key);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
itsKey = key;
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
setKeylength(itsKey.length());
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
return itsKeylength;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
unsigned int JBase::setKeylength(const unsigned int keylength)
|
|
87
87
|
{
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
itsKeylength = getValidKeylength(keylength);
|
|
89
|
+
itsKey.resize(itsKeylength);
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
return itsKeylength;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
string JBase::getRNGName() const
|
|
95
95
|
{
|
|
96
|
-
|
|
96
|
+
return getRNGName(itsRNG);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
string JBase::getRNGName(const enum RNGEnum rng)
|
|
100
100
|
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
switch (rng) {
|
|
102
|
+
#ifdef NONBLOCKING_RNG_AVAILABLE
|
|
103
|
+
case NON_BLOCKING_RNG:
|
|
104
|
+
#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(USE_MS_CRYPTOAPI)
|
|
105
|
+
return "Non-blocking (Microsoft CryptoAPI)";
|
|
106
|
+
#else
|
|
107
|
+
return "Non-blocking (/dev/urandom, etc.)";
|
|
108
|
+
#endif
|
|
109
|
+
#endif
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
#ifdef BLOCKING_RNG_AVAILABLE
|
|
112
|
+
case BLOCKING_RNG:
|
|
113
|
+
return "Blocking (/dev/random, etc.)";
|
|
114
|
+
#endif
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
case RAND_RNG:
|
|
117
|
+
return "System rand() function";
|
|
118
|
+
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
return "Unknown";
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
enum RNGEnum JBase::getRNG() const
|
|
124
124
|
{
|
|
125
|
-
|
|
125
|
+
return itsRNG;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
enum RNGEnum JBase::setRNG(const enum RNGEnum rng)
|
|
129
129
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
#ifdef NONBLOCKING_RNG_AVAILABLE
|
|
131
|
+
if (rng == NON_BLOCKING_RNG) {
|
|
132
|
+
itsRNG = rng;
|
|
133
|
+
}
|
|
134
|
+
#endif
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
#ifdef BLOCKING_RNG_AVAILABLE
|
|
137
|
+
if (rng == BLOCKING_RNG) {
|
|
138
|
+
itsRNG = rng;
|
|
139
|
+
}
|
|
140
|
+
#endif
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
if (rng == RAND_RNG) {
|
|
143
|
+
itsRNG = rng;
|
|
144
|
+
}
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
return itsRNG;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
string JBase::getIV(bool hex) const
|
|
150
150
|
{
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
if (hex) {
|
|
152
|
+
return bin2hex(itsIV);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return itsIV;
|
|
156
|
+
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
void JBase::setIV(string iv, bool hex)
|
|
160
160
|
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
if (hex) {
|
|
162
|
+
itsIV = hex2bin(iv);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
itsIV = iv;
|
|
166
|
+
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
void JBase::setRandIV(const unsigned int size)
|
|
170
170
|
{
|
|
171
|
-
|
|
171
|
+
itsIV = generateIV(size, itsRNG);
|
|
172
172
|
}
|