cryptopp 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- 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/jhash.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 __JHASH_H__
|
@@ -17,38 +17,33 @@ using namespace CryptoPP;
|
|
17
17
|
|
18
18
|
class JHash
|
19
19
|
{
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
public:
|
21
|
+
JHash(string plaintext = "", bool hex = false);
|
22
|
+
virtual ~JHash();
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
string getPlaintext(bool hex = false) const;
|
25
|
+
string getHashtext(bool hex = true) const;
|
26
|
+
unsigned int getDigestSize() const;
|
27
|
+
virtual enum HashEnum getHashType() const = 0;
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
void setPlaintext(string plaintext, bool hex = false);
|
30
|
+
void setHashtext(string hashtext, bool hex = true);
|
31
31
|
|
32
|
-
|
32
|
+
void updatePlaintext(string plaintext, bool hex = false);
|
33
33
|
|
34
|
-
|
34
|
+
void clear();
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
virtual bool hash() = 0;
|
37
|
+
virtual bool validate() = 0;
|
38
|
+
virtual bool validate(string plaintext, string hashtext) = 0;
|
39
39
|
|
40
|
-
|
40
|
+
virtual string hashRubyIO(VALUE* in, bool hex = true) = 0;
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
extension... */
|
45
|
-
//virtual string hashFile(const string filename, bool hex = true) = 0;
|
42
|
+
protected:
|
43
|
+
HashTransformation* itsHashModule;
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
string itsPlaintext;
|
51
|
-
string itsHashtext;
|
45
|
+
string itsPlaintext;
|
46
|
+
string itsHashtext;
|
52
47
|
};
|
53
48
|
|
54
49
|
#endif
|
data/ext/jhash_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 __JHASH_T_H__
|
@@ -17,18 +17,18 @@ using namespace CryptoPP;
|
|
17
17
|
template <typename HASH, enum HashEnum TYPE>
|
18
18
|
class JHash_Template : public JHash
|
19
19
|
{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
public:
|
21
|
+
JHash_Template(string plaintext = "");
|
22
|
+
enum HashEnum getHashType() const;
|
23
|
+
bool hash();
|
24
|
+
bool validate();
|
25
|
+
bool validate(string plaintext, string hashtext);
|
26
|
+
string hashRubyIO(VALUE* in, bool hex = true);
|
27
|
+
|
28
|
+
/* This is deprecated. It was used before using RubyIO. Use it
|
29
|
+
if you're using this code in something other than the CryptoPP Ruby
|
30
|
+
extension... */
|
31
|
+
//string hashFile(const string filename, bool hex = true);
|
32
32
|
};
|
33
33
|
|
34
34
|
#define HASH_TYPE TYPE
|
@@ -36,60 +36,60 @@ class JHash_Template : public JHash
|
|
36
36
|
template <typename HASH, enum HashEnum TYPE>
|
37
37
|
JHash_Template<HASH, TYPE>::JHash_Template(string plaintext) : JHash(plaintext)
|
38
38
|
{
|
39
|
-
|
39
|
+
itsHashModule = new HASH;
|
40
40
|
}
|
41
41
|
|
42
42
|
template <typename HASH, enum HashEnum TYPE>
|
43
43
|
HashEnum JHash_Template<HASH, TYPE>::getHashType() const
|
44
44
|
{
|
45
|
-
|
45
|
+
return TYPE;
|
46
46
|
}
|
47
47
|
|
48
48
|
template <typename HASH, enum HashEnum TYPE>
|
49
49
|
bool JHash_Template<HASH, TYPE>::hash()
|
50
50
|
{
|
51
|
-
|
51
|
+
itsHashtext.erase();
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
StringSource s(itsPlaintext, true, new HashFilter(*itsHashModule, new StringSink(itsHashtext)));
|
54
|
+
return true;
|
55
55
|
}
|
56
56
|
|
57
57
|
template <typename HASH, enum HashEnum TYPE>
|
58
58
|
bool JHash_Template<HASH, TYPE>::validate()
|
59
59
|
{
|
60
|
-
|
60
|
+
return validate(itsPlaintext, itsHashtext);
|
61
61
|
}
|
62
62
|
|
63
63
|
template <typename HASH, enum HashEnum TYPE>
|
64
64
|
bool JHash_Template<HASH, TYPE>::validate(string plaintext, string hashtext)
|
65
65
|
{
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
if (itsHashModule == NULL) {
|
67
|
+
throw;
|
68
|
+
}
|
69
69
|
|
70
|
-
|
70
|
+
return itsHashModule->VerifyDigest((const byte*) hashtext.data(), (const byte*) plaintext.data(), plaintext.length());
|
71
71
|
}
|
72
72
|
|
73
73
|
template <typename HASH, enum HashEnum TYPE>
|
74
74
|
string JHash_Template<HASH, TYPE>::hashRubyIO(VALUE* in, bool hex)
|
75
75
|
{
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
76
|
+
if (itsHashModule == NULL) {
|
77
|
+
throw;
|
78
|
+
}
|
79
|
+
|
80
|
+
string retval;
|
81
|
+
try {
|
82
|
+
if (hex) {
|
83
|
+
RubyIOSource f(&in, true, new HashFilter(*itsHashModule, new HexEncoder(new StringSink(retval), false)));
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
RubyIOSource f(&in, true, new HashFilter(*itsHashModule, new StringSink(retval)));
|
87
|
+
}
|
88
|
+
}
|
89
|
+
catch (Exception e) {
|
90
|
+
throw e;
|
91
|
+
}
|
92
|
+
return retval;
|
93
93
|
}
|
94
94
|
|
95
95
|
|
@@ -99,23 +99,23 @@ string JHash_Template<HASH, TYPE>::hashRubyIO(VALUE* in, bool hex)
|
|
99
99
|
/*template <typename HASH, enum HashEnum TYPE>
|
100
100
|
string JHash_Template<HASH, TYPE>::hashFile(const string filename, bool hex)
|
101
101
|
{
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
102
|
+
if (itsHashModule == NULL) {
|
103
|
+
throw;
|
104
|
+
}
|
105
|
+
|
106
|
+
string retval;
|
107
|
+
try {
|
108
|
+
if (hex) {
|
109
|
+
FileSource f(filename.c_str(), true, new HashFilter(*itsHashModule, new HexEncoder(new StringSink(retval), false)));
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
FileSource f(filename.c_str(), true, new HashFilter(*itsHashModule, new StringSink(retval)));
|
113
|
+
}
|
114
|
+
}
|
115
|
+
catch (FileStore::OpenErr e) {
|
116
|
+
throw e;
|
117
|
+
}
|
118
|
+
return retval;
|
119
119
|
}*/
|
120
120
|
|
121
121
|
#endif
|
data/ext/jhaval.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 __JHAVAL_H__
|
@@ -23,40 +23,40 @@ using namespace CryptoPP;
|
|
23
23
|
#if ENABLED_HAVAL_HASH
|
24
24
|
class JHAVAL : public JHash_Template<HAVAL, HAVAL_HASH>
|
25
25
|
{
|
26
|
-
|
27
|
-
|
26
|
+
public:
|
27
|
+
JHAVAL(string plaintext = "") : JHash_Template<HAVAL, HAVAL_HASH>(plaintext) { }
|
28
28
|
|
29
|
-
|
29
|
+
static string getHashName() { return "HAVAL"; }
|
30
30
|
};
|
31
31
|
#endif
|
32
32
|
|
33
33
|
#if ENABLED_HAVAL3_HASH
|
34
34
|
class JHAVAL3 : public JHash_Template<HAVAL3, HAVAL3_HASH>
|
35
35
|
{
|
36
|
-
|
37
|
-
|
36
|
+
public:
|
37
|
+
JHAVAL3(string plaintext = "") : JHash_Template<HAVAL3, HAVAL3_HASH>(plaintext) { }
|
38
38
|
|
39
|
-
|
39
|
+
static string getHashName() { return "HAVAL3"; }
|
40
40
|
};
|
41
41
|
#endif
|
42
42
|
|
43
43
|
#if ENABLED_HAVAL4_HASH
|
44
44
|
class JHAVAL4 : public JHash_Template<HAVAL4, HAVAL4_HASH>
|
45
45
|
{
|
46
|
-
|
47
|
-
|
46
|
+
public:
|
47
|
+
JHAVAL4(string plaintext = "") : JHash_Template<HAVAL4, HAVAL4_HASH>(plaintext) { }
|
48
48
|
|
49
|
-
|
49
|
+
static string getHashName() { return "HAVAL4"; }
|
50
50
|
};
|
51
51
|
#endif
|
52
52
|
|
53
53
|
#if ENABLED_HAVAL5_HASH
|
54
54
|
class JHAVAL5 : public JHash_Template<HAVAL5, HAVAL5_HASH>
|
55
55
|
{
|
56
|
-
|
57
|
-
|
56
|
+
public:
|
57
|
+
JHAVAL5(string plaintext = "") : JHash_Template<HAVAL5, HAVAL5_HASH>(plaintext) { }
|
58
58
|
|
59
|
-
|
59
|
+
static string getHashName() { return "HAVAL5"; }
|
60
60
|
};
|
61
61
|
#endif
|
62
62
|
|
data/ext/jhelpers.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 "jhelpers.h"
|
@@ -11,80 +11,80 @@ using namespace CryptoPP;
|
|
11
11
|
|
12
12
|
string bin2hex(const string bin, const bool uppercase)
|
13
13
|
{
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
string retval;
|
15
|
+
StringSource(bin, true, new HexEncoder(new StringSink(retval), uppercase));
|
16
|
+
return retval;
|
17
17
|
}
|
18
18
|
|
19
19
|
string hex2bin(const string hex)
|
20
20
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
string retval;
|
22
|
+
StringSource(hex, true, new HexDecoder(new StringSink(retval)));
|
23
|
+
return retval;
|
24
24
|
}
|
25
25
|
|
26
26
|
char* bin2hex(const char* bin, size_t length, const bool uppercase)
|
27
27
|
{
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
char* retval = new char[length * 2 + 1];
|
29
|
+
StringSource(bin, true, new HexEncoder(new ArraySink((byte*) retval, length * 2), uppercase));
|
30
|
+
return retval;
|
31
31
|
}
|
32
32
|
|
33
33
|
char* hex2bin(const char* hex, size_t length)
|
34
34
|
{
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
char* retval = new char[length / 2 + 1];
|
36
|
+
StringSource(hex, true, new HexDecoder(new ArraySink((byte*) retval, length / 2)));
|
37
|
+
return retval;
|
38
38
|
}
|
39
39
|
|
40
40
|
string generateIV(const unsigned int size, const enum RNGEnum rng)
|
41
41
|
{
|
42
|
-
|
43
|
-
|
42
|
+
string retval;
|
43
|
+
RandomNumberGenerator* randPool = NULL;
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
#ifdef NONBLOCKING_RNG_AVAILABLE
|
46
|
+
if (rng == NON_BLOCKING_RNG) {
|
47
|
+
randPool = new NonblockingRng;
|
48
|
+
}
|
49
|
+
#endif
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
#if defined(NONBLOCKING_RNG_AVAILABLE) && defined(BLOCKING_RNG_AVAILABLE)
|
52
|
+
else
|
53
|
+
#endif
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
#ifdef BLOCKING_RNG_AVAILABLE
|
56
|
+
if (rng == BLOCKING_RNG) {
|
57
|
+
randPool = new BlockingRng;
|
58
|
+
}
|
59
|
+
#endif
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
if (rng == RAND_RNG) {
|
62
|
+
for (unsigned int i = 0; i < size; i++) {
|
63
|
+
retval += (char)(255.0 * rand() / RAND_MAX);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
else if (randPool != NULL) {
|
67
|
+
for (unsigned int i = 0; i < size; i++) {
|
68
|
+
retval += (char) randPool->GenerateByte();
|
69
|
+
}
|
70
|
+
delete randPool;
|
71
|
+
}
|
72
72
|
|
73
|
-
|
73
|
+
return retval;
|
74
74
|
}
|
75
75
|
|
76
76
|
unsigned int checkBounds(unsigned int length, unsigned int min, unsigned int max, unsigned short int multiple)
|
77
77
|
{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
if (min == max) {
|
79
|
+
return min;
|
80
|
+
}
|
81
|
+
else if (length < min) {
|
82
|
+
return min;
|
83
|
+
}
|
84
|
+
else if (length > max) {
|
85
|
+
return max;
|
86
|
+
}
|
87
|
+
else {
|
88
|
+
return (length + multiple - 1) - ((length + multiple - 1) % multiple);
|
89
|
+
}
|
90
90
|
}
|
data/ext/jhelpers.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 __JHELPERS_H__
|