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
|
@@ -0,0 +1,74 @@
|
|
|
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 __JBASICCIPHERINFO_H__
|
|
9
|
+
#define __JBASICCIPHERINFO_H__
|
|
10
|
+
|
|
11
|
+
#include "jcipher.h"
|
|
12
|
+
#include "jstream.h"
|
|
13
|
+
|
|
14
|
+
template <typename INFO, typename BASE>
|
|
15
|
+
class JBasicCipherInfo : public BASE
|
|
16
|
+
{
|
|
17
|
+
public:
|
|
18
|
+
unsigned int getValidKeylength(const unsigned int length) const;
|
|
19
|
+
unsigned int getDefaultKeylength() const;
|
|
20
|
+
unsigned int getMaxKeylength() const;
|
|
21
|
+
unsigned int getMinKeylength() const;
|
|
22
|
+
unsigned int getMultKeylength() const;
|
|
23
|
+
string getCipherName() const;
|
|
24
|
+
static string getStaticCipherName();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
template <typename INFO, typename BASE>
|
|
28
|
+
unsigned int JBasicCipherInfo<INFO, BASE>::getValidKeylength(const unsigned int keylength) const
|
|
29
|
+
{
|
|
30
|
+
return INFO::StaticGetValidKeyLength(keylength);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
template <typename INFO, typename BASE>
|
|
34
|
+
unsigned int JBasicCipherInfo<INFO, BASE>::getDefaultKeylength() const
|
|
35
|
+
{
|
|
36
|
+
return INFO::DEFAULT_KEYLENGTH;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
template <typename INFO, typename BASE>
|
|
40
|
+
unsigned int JBasicCipherInfo<INFO, BASE>::getMaxKeylength() const
|
|
41
|
+
{
|
|
42
|
+
return INFO::MAX_KEYLENGTH;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
template <typename INFO, typename BASE>
|
|
46
|
+
unsigned int JBasicCipherInfo<INFO, BASE>::getMinKeylength() const
|
|
47
|
+
{
|
|
48
|
+
return INFO::MIN_KEYLENGTH;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
template <typename INFO, typename BASE>
|
|
52
|
+
unsigned int JBasicCipherInfo<INFO, BASE>::getMultKeylength() const
|
|
53
|
+
{
|
|
54
|
+
if (INFO::MIN_KEYLENGTH == INFO::MAX_KEYLENGTH) {
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return INFO::StaticGetValidKeyLength(INFO::MIN_KEYLENGTH + 1) - INFO::MIN_KEYLENGTH;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
template <typename INFO, typename BASE>
|
|
63
|
+
string JBasicCipherInfo<INFO, BASE>::getCipherName() const
|
|
64
|
+
{
|
|
65
|
+
return INFO::StaticAlgorithmName();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
template <typename INFO, typename BASE>
|
|
69
|
+
string JBasicCipherInfo<INFO, BASE>::getStaticCipherName()
|
|
70
|
+
{
|
|
71
|
+
return INFO::StaticAlgorithmName();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#endif
|
data/ext/jblowfish.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 "jblowfish.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_BLOWFISH_CIPHER
|
|
11
|
+
|
|
12
|
+
BlockCipher* JBlowfish::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new BlowfishEncryption((byte*) itsKey.data(), itsKeylength);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BlockCipher* JBlowfish::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return new BlowfishDecryption((byte*) itsKey.data(), itsKeylength);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/jblowfish.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 __JBLOWFISH_H__
|
|
9
|
+
#define __JBLOWFISH_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_BLOWFISH_CIPHER
|
|
14
|
+
|
|
15
|
+
#include "jcipher_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "blowfish.h"
|
|
20
|
+
|
|
21
|
+
class JBlowfish : public JCipher_Template<Blowfish_Info, BLOWFISH_CIPHER>
|
|
22
|
+
{
|
|
23
|
+
protected:
|
|
24
|
+
BlockCipher* getEncryptionObject();
|
|
25
|
+
BlockCipher* getDecryptionObject();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
#endif
|
|
29
|
+
#endif
|
data/ext/jcamellia.cpp
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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 "jcamellia.h"
|
|
9
|
+
|
|
10
|
+
#ifdef WORD64_AVAILABLE
|
|
11
|
+
#if ENABLED_CAMELLIA_CIPHER
|
|
12
|
+
|
|
13
|
+
BlockCipher* JCamellia::getEncryptionObject()
|
|
14
|
+
{
|
|
15
|
+
return new CamelliaEncryption((byte*) itsKey.data(), itsKeylength);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
BlockCipher* JCamellia::getDecryptionObject()
|
|
19
|
+
{
|
|
20
|
+
return new CamelliaDecryption((byte*) itsKey.data(), itsKeylength);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#endif
|
|
24
|
+
#endif
|
data/ext/jcamellia.h
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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 __JCAMELLIA_H__
|
|
9
|
+
#define __JCAMELLIA_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#ifdef WORD64_AVAILABLE
|
|
14
|
+
#if ENABLED_CAMELLIA_CIPHER
|
|
15
|
+
|
|
16
|
+
#include "jcipher_t.h"
|
|
17
|
+
|
|
18
|
+
// Crypto++ headers...
|
|
19
|
+
|
|
20
|
+
#include "camellia.h"
|
|
21
|
+
|
|
22
|
+
using namespace CryptoPP;
|
|
23
|
+
|
|
24
|
+
class JCamellia : public JCipher_Template<Camellia_Info, CAMELLIA_CIPHER>
|
|
25
|
+
{
|
|
26
|
+
protected:
|
|
27
|
+
BlockCipher* getEncryptionObject();
|
|
28
|
+
BlockCipher* getDecryptionObject();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
#endif
|
|
32
|
+
#endif
|
|
33
|
+
#endif
|
data/ext/jcast128.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 "jcast128.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_CAST128_CIPHER
|
|
11
|
+
|
|
12
|
+
BlockCipher* JCAST128::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new CAST128Encryption((byte*) itsKey.data(), itsKeylength);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BlockCipher* JCAST128::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return new CAST128Decryption((byte*) itsKey.data(), itsKeylength);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/jcast128.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 __JCAST128_H__
|
|
9
|
+
#define __JCAST128_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_CAST128_CIPHER
|
|
14
|
+
|
|
15
|
+
#include "jcipher_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "cast.h"
|
|
20
|
+
|
|
21
|
+
using namespace CryptoPP;
|
|
22
|
+
|
|
23
|
+
class JCAST128 : public JCipher_Template<CAST128_Info, CAST128_CIPHER>
|
|
24
|
+
{
|
|
25
|
+
protected:
|
|
26
|
+
BlockCipher* getEncryptionObject();
|
|
27
|
+
BlockCipher* getDecryptionObject();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#endif
|
|
31
|
+
#endif
|
data/ext/jcast256.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 "jcast256.h"
|
|
9
|
+
|
|
10
|
+
#if ENABLED_CAST256_CIPHER
|
|
11
|
+
|
|
12
|
+
BlockCipher* JCAST256::getEncryptionObject()
|
|
13
|
+
{
|
|
14
|
+
return new CAST256Encryption((byte*) itsKey.data(), itsKeylength);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BlockCipher* JCAST256::getDecryptionObject()
|
|
18
|
+
{
|
|
19
|
+
return new CAST256Decryption((byte*) itsKey.data(), itsKeylength);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#endif
|
data/ext/jcast256.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 __JCAST256_H__
|
|
9
|
+
#define __JCAST256_H__
|
|
10
|
+
|
|
11
|
+
#include "jconfig.h"
|
|
12
|
+
|
|
13
|
+
#if ENABLED_CAST256_CIPHER
|
|
14
|
+
|
|
15
|
+
#include "jcipher_t.h"
|
|
16
|
+
|
|
17
|
+
// Crypto++ headers...
|
|
18
|
+
|
|
19
|
+
#include "cast.h"
|
|
20
|
+
|
|
21
|
+
using namespace CryptoPP;
|
|
22
|
+
|
|
23
|
+
class JCAST256 : public JCipher_Template<CAST256_Info, CAST256_CIPHER>
|
|
24
|
+
{
|
|
25
|
+
protected:
|
|
26
|
+
BlockCipher* getEncryptionObject();
|
|
27
|
+
BlockCipher* getDecryptionObject();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#endif
|
|
31
|
+
#endif
|
data/ext/jcipher.cpp
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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 "jcipher.h"
|
|
9
|
+
|
|
10
|
+
JCipher::JCipher()
|
|
11
|
+
{
|
|
12
|
+
itsMode = ECB_MODE;
|
|
13
|
+
itsPadding = ZEROS_PADDING;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
string JCipher::getModeName() const
|
|
17
|
+
{
|
|
18
|
+
return getModeName(itsMode);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
string JCipher::getModeName(const enum ModeEnum mode)
|
|
22
|
+
{
|
|
23
|
+
switch (mode) {
|
|
24
|
+
case ECB_MODE:
|
|
25
|
+
return "ECB";
|
|
26
|
+
case CBC_MODE:
|
|
27
|
+
return "CBC";
|
|
28
|
+
case CBC_CTS_MODE:
|
|
29
|
+
return "CBC with CTS";
|
|
30
|
+
case CFB_MODE:
|
|
31
|
+
return "CFB";
|
|
32
|
+
case CTR_MODE:
|
|
33
|
+
return "CTR";
|
|
34
|
+
case OFB_MODE:
|
|
35
|
+
return "OFB";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return "Unknown";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
enum ModeEnum JCipher::getMode() const
|
|
42
|
+
{
|
|
43
|
+
return itsMode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void JCipher::setMode(const enum ModeEnum mode)
|
|
47
|
+
{
|
|
48
|
+
itsMode = mode;
|
|
49
|
+
itsPadding = DEFAULT_PADDING;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
string JCipher::getPaddingName() const
|
|
53
|
+
{
|
|
54
|
+
if (itsPadding == DEFAULT_PADDING) {
|
|
55
|
+
if (itsMode == ECB_MODE || itsMode == CBC_MODE)
|
|
56
|
+
return "Default cipher padding (PKCS)";
|
|
57
|
+
else
|
|
58
|
+
return "Default cipher padding (none)";
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return getPaddingName(itsPadding);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
string JCipher::getPaddingName(const enum PaddingEnum padding)
|
|
66
|
+
{
|
|
67
|
+
switch (padding) {
|
|
68
|
+
case NO_PADDING:
|
|
69
|
+
return "None";
|
|
70
|
+
case ZEROS_PADDING:
|
|
71
|
+
return "Zeroes";
|
|
72
|
+
case PKCS_PADDING:
|
|
73
|
+
return "PKCS";
|
|
74
|
+
case ONE_AND_ZEROS_PADDING:
|
|
75
|
+
return "One and zeroes";
|
|
76
|
+
case DEFAULT_PADDING:
|
|
77
|
+
return "Default cipher padding";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return "Unknown";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
enum PaddingEnum JCipher::getPadding() const
|
|
84
|
+
{
|
|
85
|
+
return itsPadding;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
enum PaddingEnum JCipher::setPadding(const enum PaddingEnum padding)
|
|
89
|
+
{
|
|
90
|
+
if (padding == NO_PADDING && (itsMode == ECB_MODE || itsMode == CBC_MODE)) {
|
|
91
|
+
return itsPadding;
|
|
92
|
+
}
|
|
93
|
+
else if ((padding == PKCS_PADDING || padding == ONE_AND_ZEROS_PADDING) && (itsMode == CBC_CTS_MODE || itsMode == CTR_MODE || itsMode == OFB_MODE || itsMode == CFB_MODE)) {
|
|
94
|
+
return itsPadding;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
itsPadding = padding;
|
|
98
|
+
return itsPadding;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
unsigned int JCipher::getRounds() const
|
|
103
|
+
{
|
|
104
|
+
return itsRounds;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
unsigned int JCipher::setRounds(const unsigned int rounds)
|
|
108
|
+
{
|
|
109
|
+
itsRounds = getValidRounds(rounds);
|
|
110
|
+
|
|
111
|
+
return itsRounds;
|
|
112
|
+
}
|
data/ext/jcipher.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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 __JCIPHER_H__
|
|
9
|
+
#define __JCIPHER_H__
|
|
10
|
+
|
|
11
|
+
#include "jbase.h"
|
|
12
|
+
|
|
13
|
+
// Crypto++ headers...
|
|
14
|
+
|
|
15
|
+
#include "modes.h"
|
|
16
|
+
|
|
17
|
+
class JCipher : public JBase
|
|
18
|
+
{
|
|
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
|
+
};
|
|
41
|
+
|
|
42
|
+
#endif
|