cryptopp 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/MIT-LICENSE +22 -0
- data/README +7 -0
- data/Rakefile +42 -0
- data/cryptopp.gemspec +199 -0
- data/ext/.gitignore +5 -0
- data/ext/Rakefile +16 -0
- data/ext/ciphers.cpp +1402 -0
- data/ext/cryptopp.cpp +285 -0
- data/ext/cryptopp_ruby_api.h +139 -0
- data/ext/defs/block_modes.def +10 -0
- data/ext/defs/checksums.def +10 -0
- data/ext/defs/ciphers.def +136 -0
- data/ext/defs/hashes.def +78 -0
- data/ext/defs/hmacs.def +54 -0
- data/ext/defs/paddings.def +9 -0
- data/ext/defs/rngs.def +7 -0
- data/ext/digests.cpp +1120 -0
- data/ext/extconf.rb +39 -0
- data/ext/j3way.cpp +22 -0
- data/ext/j3way.h +29 -0
- data/ext/jadler32.h +32 -0
- data/ext/jaes.cpp +22 -0
- data/ext/jaes.h +31 -0
- data/ext/jarc4.cpp +22 -0
- data/ext/jarc4.h +37 -0
- data/ext/jbase.cpp +172 -0
- data/ext/jbase.h +92 -0
- data/ext/jbasiccipherinfo.h +74 -0
- data/ext/jblowfish.cpp +22 -0
- data/ext/jblowfish.h +29 -0
- data/ext/jcamellia.cpp +24 -0
- data/ext/jcamellia.h +33 -0
- data/ext/jcast128.cpp +22 -0
- data/ext/jcast128.h +31 -0
- data/ext/jcast256.cpp +22 -0
- data/ext/jcast256.h +31 -0
- data/ext/jcipher.cpp +112 -0
- data/ext/jcipher.h +42 -0
- data/ext/jcipher_t.h +469 -0
- data/ext/jconfig.h +127 -0
- data/ext/jconstants.h +189 -0
- data/ext/jcrc32.h +32 -0
- data/ext/jdes.cpp +22 -0
- data/ext/jdes.h +31 -0
- data/ext/jdes_ede2.cpp +22 -0
- data/ext/jdes_ede2.h +31 -0
- data/ext/jdes_ede3.cpp +22 -0
- data/ext/jdes_ede3.h +31 -0
- data/ext/jdes_xex3.cpp +22 -0
- data/ext/jdes_xex3.h +31 -0
- data/ext/jdiamond2.cpp +22 -0
- data/ext/jdiamond2.h +31 -0
- data/ext/jdiamond2lite.cpp +22 -0
- data/ext/jdiamond2lite.h +31 -0
- data/ext/jexception.h +20 -0
- data/ext/jgost.cpp +22 -0
- data/ext/jgost.h +31 -0
- data/ext/jhash.cpp +92 -0
- data/ext/jhash.h +54 -0
- data/ext/jhash_t.h +121 -0
- data/ext/jhaval.h +64 -0
- data/ext/jhelpers.cpp +90 -0
- data/ext/jhelpers.h +38 -0
- data/ext/jhmac.cpp +44 -0
- data/ext/jhmac.h +34 -0
- data/ext/jhmac_t.h +125 -0
- data/ext/jidea.cpp +22 -0
- data/ext/jidea.h +31 -0
- data/ext/jmarc4.cpp +22 -0
- data/ext/jmarc4.h +37 -0
- data/ext/jmars.cpp +22 -0
- data/ext/jmars.h +31 -0
- data/ext/jmd2.h +56 -0
- data/ext/jmd4.h +56 -0
- data/ext/jmd5.h +56 -0
- data/ext/jpanamacipher.cpp +32 -0
- data/ext/jpanamacipher.h +46 -0
- data/ext/jpanamahash.h +44 -0
- data/ext/jrc2.cpp +44 -0
- data/ext/jrc2.h +39 -0
- data/ext/jrc5.cpp +22 -0
- data/ext/jrc5.h +31 -0
- data/ext/jrc6.cpp +22 -0
- data/ext/jrc6.h +31 -0
- data/ext/jripemd160.h +113 -0
- data/ext/jsafer.cpp +32 -0
- data/ext/jsafer.h +42 -0
- data/ext/jseal.cpp +32 -0
- data/ext/jseal.h +42 -0
- data/ext/jserpent.cpp +22 -0
- data/ext/jserpent.h +31 -0
- data/ext/jsha.h +122 -0
- data/ext/jshacal2.cpp +22 -0
- data/ext/jshacal2.h +31 -0
- data/ext/jshark.cpp +24 -0
- data/ext/jshark.h +33 -0
- data/ext/jsink.cpp +90 -0
- data/ext/jsink.h +154 -0
- data/ext/jskipjack.cpp +22 -0
- data/ext/jskipjack.h +31 -0
- data/ext/jsquare.cpp +22 -0
- data/ext/jsquare.h +31 -0
- data/ext/jstream.cpp +8 -0
- data/ext/jstream.h +20 -0
- data/ext/jstream_t.h +175 -0
- data/ext/jtea.cpp +22 -0
- data/ext/jtea.h +31 -0
- data/ext/jtiger.h +52 -0
- data/ext/jtwofish.cpp +22 -0
- data/ext/jtwofish.h +31 -0
- data/ext/jwhirlpool.h +52 -0
- data/ext/utils.cpp +8 -0
- data/extras/parser_c.rb +114 -0
- data/test/ciphers_test.rb +37 -0
- data/test/data/ciphers/3desval.dat +7 -0
- data/test/data/ciphers/3wayval.dat +6 -0
- data/test/data/ciphers/arc4.dat +8 -0
- data/test/data/ciphers/blowfish.dat +5 -0
- data/test/data/ciphers/camellia.dat +7 -0
- data/test/data/ciphers/cast128v.dat +5 -0
- data/test/data/ciphers/cast256v.dat +5 -0
- data/test/data/ciphers/descert.dat +198 -0
- data/test/data/ciphers/diamond.dat +9 -0
- data/test/data/ciphers/gostval.dat +10 -0
- data/test/data/ciphers/ideaval.dat +13 -0
- data/test/data/ciphers/marsval.dat +11 -0
- data/test/data/ciphers/panamac.dat +7 -0
- data/test/data/ciphers/rc2val.dat +10 -0
- data/test/data/ciphers/rc5val.dat +7 -0
- data/test/data/ciphers/rc6val.dat +8 -0
- data/test/data/ciphers/rijndael.dat +11 -0
- data/test/data/ciphers/saferval.dat +27 -0
- data/test/data/ciphers/seal.dat +3 -0
- data/test/data/ciphers/serpentv.dat +11 -0
- data/test/data/ciphers/shacal2.dat +7 -0
- data/test/data/ciphers/sharkval.dat +9 -0
- data/test/data/ciphers/skipjack.dat +3 -0
- data/test/data/ciphers/squareva.dat +10 -0
- data/test/data/ciphers/twofishv.dat +11 -0
- data/test/data/digests/adler32.dat +8 -0
- data/test/data/digests/crc32.dat +10 -0
- data/test/data/digests/haval.dat +4 -0
- data/test/data/digests/havalcer.dat +23 -0
- data/test/data/digests/md2.dat +9 -0
- data/test/data/digests/md4.dat +9 -0
- data/test/data/digests/md5.dat +9 -0
- data/test/data/digests/panamah.dat +8 -0
- data/test/data/digests/ripemd.dat +43 -0
- data/test/data/digests/sha.dat +19 -0
- data/test/data/digests/tiger.dat +11 -0
- data/test/data/digests/whirlpool.dat +13 -0
- data/test/data/hmacs/hmac.dat +6 -0
- data/test/digests_test.rb +29 -0
- data/test/hmacs_test.rb +38 -0
- data/test/test_helper.rb +42 -0
- metadata +220 -0
data/ext/extconf.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
require 'mkmf'
|
|
3
|
+
|
|
4
|
+
Config::CONFIG['CC'] = 'g++'
|
|
5
|
+
Config::CONFIG['CPP'] = 'g++ -E'
|
|
6
|
+
|
|
7
|
+
# hack to get C++ standard library properly linked into shared
|
|
8
|
+
# object
|
|
9
|
+
# $libs = append_library($libs, "supc++") # doesn't work
|
|
10
|
+
if Config::CONFIG["arch"] =~ /-darwin\d/
|
|
11
|
+
Config::CONFIG['LDSHARED']="g++ -dynamic -bundle -undefined suppress -flat_namespace"
|
|
12
|
+
else
|
|
13
|
+
Config::CONFIG['LDSHARED'] = "g++ -shared"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
$CFLAGS << " -DNDEBUG -DCRYPTOPP_DISABLE_ASM"
|
|
17
|
+
|
|
18
|
+
def error msg
|
|
19
|
+
message msg + "\n"
|
|
20
|
+
abort
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
unless have_library('stdc++')
|
|
24
|
+
error "Can't find libstdc++"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
unless have_library('cryptopp')
|
|
28
|
+
error "Can't find cryptopp library"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
unless find_header('cryptlib.h', *%w{
|
|
32
|
+
/usr/local/include/cryptopp
|
|
33
|
+
/usr/include/cryptopp
|
|
34
|
+
/opt/local/include/cryptopp
|
|
35
|
+
})
|
|
36
|
+
error "Can't find cryptlib.h"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
create_makefile('cryptopp')
|
data/ext/j3way.cpp
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "j3way.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_THREEWAY_CIPHER
|
|
11
|
+
|
|
12
|
+
BlockCipher* J3Way::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new ThreeWayEncryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BlockCipher* J3Way::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return new ThreeWayDecryption((byte*) itsKey.data(), itsKeylength, itsRounds);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/j3way.h
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef __J3WAY_H__
|
|
9
|
+
#define __J3WAY_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_THREEWAY_CIPHER
|
|
14
|
+
|
|
15
|
+
#include "jcipher_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "3way.h"
|
|
20
|
+
|
|
21
|
+
class J3Way : public JCipher_Template<ThreeWay_Info, THREEWAY_CIPHER, 11, 1, INT_MAX>
|
|
22
|
+
{
|
|
23
|
+
protected:
|
|
24
|
+
BlockCipher* getEncryptionObject();
|
|
25
|
+
BlockCipher* getDecryptionObject();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
#endif
|
|
29
|
+
#endif
|
data/ext/jadler32.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef __JADLER32_H__
|
|
9
|
+
#define __JADLER32_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_ADLER32_CHECKSUM
|
|
14
|
+
|
|
15
|
+
#include "jhash_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "adler32.h"
|
|
20
|
+
|
|
21
|
+
using namespace CryptoPP;
|
|
22
|
+
|
|
23
|
+
class JAdler32 : public JHash_Template<Adler32, ADLER32_CHECKSUM>
|
|
24
|
+
{
|
|
25
|
+
public:
|
|
26
|
+
JAdler32(string plaintext = "") : JHash_Template<Adler32, ADLER32_CHECKSUM>(plaintext) { }
|
|
27
|
+
|
|
28
|
+
static string getHashName() { return "Adler32"; }
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
#endif
|
|
32
|
+
#endif
|
data/ext/jaes.cpp
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "jaes.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_AES_CIPHER
|
|
11
|
+
|
|
12
|
+
BlockCipher* JAES::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new AESEncryption((byte*) itsKey.data(), itsKeylength);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BlockCipher* JAES::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return new AESDecryption((byte*) itsKey.data(), itsKeylength);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/jaes.h
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef __JAES_H__
|
|
9
|
+
#define __JAES_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_AES_CIPHER
|
|
14
|
+
|
|
15
|
+
#include "jcipher_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "aes.h"
|
|
20
|
+
|
|
21
|
+
class JAES : public JCipher_Template<Rijndael_Info, AES_CIPHER>
|
|
22
|
+
{
|
|
23
|
+
protected:
|
|
24
|
+
BlockCipher* getEncryptionObject();
|
|
25
|
+
BlockCipher* getDecryptionObject();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
typedef JAES JRijndael;
|
|
29
|
+
|
|
30
|
+
#endif
|
|
31
|
+
#endif
|
data/ext/jarc4.cpp
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "jarc4.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_ARC4_CIPHER
|
|
11
|
+
|
|
12
|
+
SymmetricCipher* JARC4::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new Weak::ARC4((byte*) itsKey.data(), itsKeylength);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
SymmetricCipher* JARC4::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return getEncryptionObject();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/jarc4.h
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef __JARC4_H__
|
|
9
|
+
#define __JARC4_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_ARC4_CIPHER
|
|
14
|
+
|
|
15
|
+
#ifndef CRYPTOPP_ENABLE_NAMESPACE_WEAK
|
|
16
|
+
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#include "jstream_t.h"
|
|
20
|
+
|
|
21
|
+
// Crypto++ headers...
|
|
22
|
+
|
|
23
|
+
#include "arc4.h"
|
|
24
|
+
|
|
25
|
+
using namespace CryptoPP;
|
|
26
|
+
|
|
27
|
+
class JARC4 : public JStream_Template<Weak::ARC4_Base, ARC4_CIPHER>
|
|
28
|
+
{
|
|
29
|
+
protected:
|
|
30
|
+
SymmetricCipher* getEncryptionObject();
|
|
31
|
+
SymmetricCipher* getDecryptionObject();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
#undef CRYPTOPP_ENABLE_NAMESPACE_WEAK
|
|
35
|
+
|
|
36
|
+
#endif
|
|
37
|
+
#endif
|
data/ext/jbase.cpp
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#include "jbase.h"
|
|
9
|
+
|
|
10
|
+
JBase::JBase()
|
|
11
|
+
{
|
|
12
|
+
itsPlaintext = "";
|
|
13
|
+
itsIV = "";
|
|
14
|
+
itsRNG = DEFAULT_RNG;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
string JBase::getPlaintext(const bool hex) const
|
|
18
|
+
{
|
|
19
|
+
if (hex) {
|
|
20
|
+
return bin2hex(itsPlaintext);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return itsPlaintext;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
string JBase::getCiphertext(const bool hex) const
|
|
28
|
+
{
|
|
29
|
+
if (hex) {
|
|
30
|
+
return bin2hex(itsCiphertext);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return itsCiphertext;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
string JBase::getKey(const bool hex) const
|
|
38
|
+
{
|
|
39
|
+
if (hex) {
|
|
40
|
+
return bin2hex(itsKey);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return itsKey;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
unsigned int JBase::getKeylength() const
|
|
48
|
+
{
|
|
49
|
+
return itsKeylength;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void JBase::setPlaintext(const string plaintext, const bool hex)
|
|
53
|
+
{
|
|
54
|
+
if (hex) {
|
|
55
|
+
itsPlaintext = hex2bin(plaintext);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
itsPlaintext = plaintext;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void JBase::setCiphertext(const string ciphertext, const bool hex)
|
|
63
|
+
{
|
|
64
|
+
if (hex) {
|
|
65
|
+
itsCiphertext = hex2bin(ciphertext);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
itsCiphertext = ciphertext;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
unsigned int JBase::setKey(const string key, const bool hex)
|
|
73
|
+
{
|
|
74
|
+
if (hex) {
|
|
75
|
+
itsKey = hex2bin(key);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
itsKey = key;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setKeylength(itsKey.length());
|
|
82
|
+
|
|
83
|
+
return itsKeylength;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
unsigned int JBase::setKeylength(const unsigned int keylength)
|
|
87
|
+
{
|
|
88
|
+
itsKeylength = getValidKeylength(keylength);
|
|
89
|
+
itsKey.resize(itsKeylength);
|
|
90
|
+
|
|
91
|
+
return itsKeylength;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
string JBase::getRNGName() const
|
|
95
|
+
{
|
|
96
|
+
return getRNGName(itsRNG);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
string JBase::getRNGName(const enum RNGEnum rng)
|
|
100
|
+
{
|
|
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
|
+
|
|
111
|
+
#ifdef BLOCKING_RNG_AVAILABLE
|
|
112
|
+
case BLOCKING_RNG:
|
|
113
|
+
return "Blocking (/dev/random, etc.)";
|
|
114
|
+
#endif
|
|
115
|
+
|
|
116
|
+
case RAND_RNG:
|
|
117
|
+
return "System rand() function";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return "Unknown";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
enum RNGEnum JBase::getRNG() const
|
|
124
|
+
{
|
|
125
|
+
return itsRNG;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
enum RNGEnum JBase::setRNG(const enum RNGEnum rng)
|
|
129
|
+
{
|
|
130
|
+
#ifdef NONBLOCKING_RNG_AVAILABLE
|
|
131
|
+
if (rng == NON_BLOCKING_RNG) {
|
|
132
|
+
itsRNG = rng;
|
|
133
|
+
}
|
|
134
|
+
#endif
|
|
135
|
+
|
|
136
|
+
#ifdef BLOCKING_RNG_AVAILABLE
|
|
137
|
+
if (rng == BLOCKING_RNG) {
|
|
138
|
+
itsRNG = rng;
|
|
139
|
+
}
|
|
140
|
+
#endif
|
|
141
|
+
|
|
142
|
+
if (rng == RAND_RNG) {
|
|
143
|
+
itsRNG = rng;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return itsRNG;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
string JBase::getIV(bool hex) const
|
|
150
|
+
{
|
|
151
|
+
if (hex) {
|
|
152
|
+
return bin2hex(itsIV);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return itsIV;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void JBase::setIV(string iv, bool hex)
|
|
160
|
+
{
|
|
161
|
+
if (hex) {
|
|
162
|
+
itsIV = hex2bin(iv);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
itsIV = iv;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
void JBase::setRandIV(const unsigned int size)
|
|
170
|
+
{
|
|
171
|
+
itsIV = generateIV(size, itsRNG);
|
|
172
|
+
}
|
data/ext/jbase.h
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2002-2010 J Smith <dark.panda@gmail.com>
|
|
4
|
+
* Crypto++ copyright (c) 1995-2010 Wei Dai
|
|
5
|
+
* See COPYING for the extact license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#ifndef __JBASE_H__
|
|
9
|
+
#define __JBASE_H__
|
|
10
|
+
|
|
11
|
+
#include <string>
|
|
12
|
+
|
|
13
|
+
#include "jhelpers.h"
|
|
14
|
+
#include "jconstants.h"
|
|
15
|
+
#include "jsink.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "hex.h"
|
|
20
|
+
#include "files.h"
|
|
21
|
+
|
|
22
|
+
using namespace CryptoPP;
|
|
23
|
+
|
|
24
|
+
class JBase
|
|
25
|
+
{
|
|
26
|
+
public:
|
|
27
|
+
JBase();
|
|
28
|
+
virtual ~JBase() {};
|
|
29
|
+
|
|
30
|
+
string getPlaintext(const bool hex = false) const;
|
|
31
|
+
string getCiphertext(const bool hex = false) const;
|
|
32
|
+
string getKey(const bool hex = false) const;
|
|
33
|
+
unsigned int getKeylength() const;
|
|
34
|
+
|
|
35
|
+
void setPlaintext(const string plaintext, const bool hex = false);
|
|
36
|
+
void setCiphertext(const string ciphertext, const bool hex = false);
|
|
37
|
+
unsigned int setKey(const string key, bool hex = false);
|
|
38
|
+
unsigned int setKeylength(const unsigned int keylength);
|
|
39
|
+
|
|
40
|
+
string getRNGName() const;
|
|
41
|
+
static string getRNGName(const enum RNGEnum rng);
|
|
42
|
+
enum RNGEnum getRNG() const;
|
|
43
|
+
enum RNGEnum setRNG(const enum RNGEnum rng);
|
|
44
|
+
|
|
45
|
+
string getIV(bool hex = false) const;
|
|
46
|
+
void setIV(string iv, bool hex = false);
|
|
47
|
+
void setRandIV(const unsigned int size);
|
|
48
|
+
|
|
49
|
+
virtual unsigned int getDefaultKeylength() const = 0;
|
|
50
|
+
virtual unsigned int getMaxKeylength() const = 0;
|
|
51
|
+
virtual unsigned int getMinKeylength() const = 0;
|
|
52
|
+
virtual unsigned int getMultKeylength() const = 0;
|
|
53
|
+
virtual unsigned int getValidKeylength(const unsigned int keylength) const = 0;
|
|
54
|
+
virtual unsigned int getBlockSize() const = 0;
|
|
55
|
+
virtual enum CipherEnum getCipherType() const = 0;
|
|
56
|
+
virtual string getCipherName() const = 0;
|
|
57
|
+
|
|
58
|
+
virtual bool encrypt() = 0;
|
|
59
|
+
virtual bool decrypt() = 0;
|
|
60
|
+
|
|
61
|
+
virtual bool encryptRubyIO(VALUE* in, VALUE* out) = 0;
|
|
62
|
+
virtual bool decryptRubyIO(VALUE* in, VALUE* out) = 0;
|
|
63
|
+
|
|
64
|
+
/* These are deprecated. They were used before using php_streams. Use them
|
|
65
|
+
if you're using this code in something other than the cryptopp PHP
|
|
66
|
+
extension... */
|
|
67
|
+
// virtual bool encryptFile(const string in, const string out) = 0;
|
|
68
|
+
// virtual bool decryptFile(const string in, const string out) = 0;
|
|
69
|
+
|
|
70
|
+
protected:
|
|
71
|
+
string itsPlaintext;
|
|
72
|
+
string itsCiphertext;
|
|
73
|
+
string itsKey;
|
|
74
|
+
string itsIV;
|
|
75
|
+
|
|
76
|
+
unsigned int itsKeylength;
|
|
77
|
+
enum RNGEnum itsRNG;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
#define getKeyHex() getKey(true)
|
|
81
|
+
#define getKeyBin() getKey()
|
|
82
|
+
|
|
83
|
+
#define getPlaintextHex() getPlaintext(true)
|
|
84
|
+
#define getPlaintextBin() getPlaintext()
|
|
85
|
+
|
|
86
|
+
#define getCiphertextHex() getCiphertext(true)
|
|
87
|
+
#define getCiphertextBin() getCiphertext()
|
|
88
|
+
|
|
89
|
+
#define getIVHex() getIV(true)
|
|
90
|
+
#define getIVBin() getIV()
|
|
91
|
+
|
|
92
|
+
#endif
|