summaryrefslogtreecommitdiff
path: root/validat4.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-03-27 20:47:20 -0400
committerJeffrey Walton <noloader@gmail.com>2018-03-27 20:47:20 -0400
commit3958fad099f109d4547f0caf62ceb9b10f74c773 (patch)
tree7c61378b2223a3995efc19dcfed107c3244ba370 /validat4.cpp
parent1c60f6480f8132e345c77e066e0fa52e20808fe7 (diff)
downloadcryptopp-git-3958fad099f109d4547f0caf62ceb9b10f74c773.tar.gz
Add sbyte, sword16, sword32 and sword64 (GH #608, GH #609)
Visual Studio 2008 kind of forced out hand with this. VS2008 lacks <stdint.h> and <cstdint> and it caused compile problems in NaCl gear. We were being a tad bit lazy by relying on int8_t, int32_t and int64_t, but the compiler errors made us act
Diffstat (limited to 'validat4.cpp')
-rw-r--r--validat4.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/validat4.cpp b/validat4.cpp
index a7f3ca69..cf7ef70b 100644
--- a/validat4.cpp
+++ b/validat4.cpp
@@ -45,31 +45,31 @@ USING_NAMESPACE(NaCl)
bool TestCryptoBox()
{
// https://github.com/jedisct1/libsodium/blob/master/test/default/box.c
- const uint8_t alicesk[32] = {
+ const byte alicesk[32] = {
0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a
};
- const uint8_t bobpk[32] = {
+ const byte bobpk[32] = {
0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 0x61,
0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78,
0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f
};
- const uint8_t small_order_p[crypto_box_PUBLICKEYBYTES] = {
+ const byte small_order_p[crypto_box_PUBLICKEYBYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3,
0xfa, 0xf1, 0x9f, 0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32,
0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00
};
- const uint8_t nonce[24] = {
+ const byte nonce[24] = {
0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
};
/* API requires first 32 bytes to be 0 */
- const uint8_t m[163] = {
+ const byte m[163] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0xbe, 0x07, 0x5f, 0xc5,
@@ -86,7 +86,7 @@ bool TestCryptoBox()
0x76, 0x38, 0x48, 0x64, 0x5e, 0x07, 0x05
};
- const uint8_t exp1[] = {
+ const byte exp1[] = {
0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5 ,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9,
0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73 ,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce,
0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4 ,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a,
@@ -99,7 +99,7 @@ bool TestCryptoBox()
0xe3,0x55,0xa5
};
- const uint8_t exp2[] = {
+ const byte exp2[] = {
0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5 ,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9,
0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73 ,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce,
0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4 ,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a,
@@ -112,8 +112,8 @@ bool TestCryptoBox()
0xe3,0x55,0xa5
};
- uint8_t c[163];
- uint8_t k[crypto_box_BEFORENMBYTES];
+ byte c[163];
+ byte k[crypto_box_BEFORENMBYTES];
bool pass = true; int rc;
@@ -161,31 +161,31 @@ bool TestCryptoBox()
bool TestCryptoBoxOpen()
{
// https://github.com/jedisct1/libsodium/blob/master/test/default/box2.c
- const uint8_t bobsk[32] = {
+ const byte bobsk[32] = {
0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f, 0x8b, 0x83, 0x80,
0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18, 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27,
0xff, 0x88, 0xe0, 0xeb
};
- const uint8_t alicepk[32] = {
+ const byte alicepk[32] = {
0x85, 0x20, 0xf0, 0x09, 0x89, 0x30, 0xa7, 0x54, 0x74, 0x8b, 0x7d, 0xdc, 0xb4, 0x3e,
0xf7, 0x5a, 0x0d, 0xbf, 0x3a, 0x0d, 0x26, 0x38, 0x1a, 0xf4, 0xeb, 0xa4, 0xa9, 0x8e,
0xaa, 0x9b, 0x4e, 0x6a
};
- static const uint8_t small_order_p[crypto_box_PUBLICKEYBYTES] = {
+ static const byte small_order_p[crypto_box_PUBLICKEYBYTES] = {
0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, 0x16, 0x56, 0xe3, 0xfa, 0xf1, 0x9f,
0xc4, 0x6a, 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32, 0xb1, 0xfd, 0x86, 0x62, 0x05, 0x16,
0x5f, 0x49, 0xb8, 0x00
};
- const uint8_t nonce[24] = {
+ const byte nonce[24] = {
0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8,
0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
};
/* API requires first 16 bytes to be 0 */
- const uint8_t c[163] = {
+ const byte c[163] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, 0x8e, 0x99, 0x3b, 0x9f,
@@ -202,7 +202,7 @@ bool TestCryptoBoxOpen()
0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5
};
- const uint8_t exp1[] = {
+ const byte exp1[] = {
0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5, 0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b,
0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4, 0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc,
0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a, 0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29,
@@ -214,7 +214,7 @@ bool TestCryptoBoxOpen()
0x5e,0x07,0x05
};
- const uint8_t exp2[] = {
+ const byte exp2[] = {
0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5, 0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b,
0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4, 0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc,
0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a, 0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29,
@@ -226,8 +226,8 @@ bool TestCryptoBoxOpen()
0x5e,0x07,0x05
};
- uint8_t m[163];
- uint8_t k[crypto_box_BEFORENMBYTES];
+ byte m[163];
+ byte k[crypto_box_BEFORENMBYTES];
bool pass = true; int rc;
@@ -273,14 +273,14 @@ bool TestCryptoBoxKeys()
const unsigned int MAX_TEST = 64;
const unsigned int MAX_MESSAGE = 4096;
- uint8_t alicesk[crypto_box_SECRETKEYBYTES];
- uint8_t alicepk[crypto_box_PUBLICKEYBYTES];
- uint8_t bobsk[crypto_box_SECRETKEYBYTES];
- uint8_t bobpk[crypto_box_PUBLICKEYBYTES];
+ byte alicesk[crypto_box_SECRETKEYBYTES];
+ byte alicepk[crypto_box_PUBLICKEYBYTES];
+ byte bobsk[crypto_box_SECRETKEYBYTES];
+ byte bobpk[crypto_box_PUBLICKEYBYTES];
- // uint8_t m[MAX_MESSAGE+32];
- // uint8_t c[MAX_MESSAGE+32];
- // uint8_t r[MAX_MESSAGE+32];
+ // byte m[MAX_MESSAGE+32];
+ // byte c[MAX_MESSAGE+32];
+ // byte r[MAX_MESSAGE+32];
bool pass = true, fail; int rc;
for (unsigned int i=0; i < MAX_TEST; ++i)
@@ -291,7 +291,7 @@ bool TestCryptoBoxKeys()
pass = !fail && pass;
SecByteBlock m, c, r, n;
- const uint32_t len = (i == 0 ? 0 : GlobalRNG().GenerateWord32(1, MAX_MESSAGE));
+ const word32 len = (i == 0 ? 0 : GlobalRNG().GenerateWord32(1, MAX_MESSAGE));
m.New(len+crypto_box_ZEROBYTES);
c.New(len+crypto_box_BOXZEROBYTES+crypto_box_MACBYTES);
@@ -319,10 +319,10 @@ bool TestCryptoBoxKeys()
}
struct TestData {
- const uint8_t sk[crypto_sign_SEEDBYTES];
- const uint8_t pk[crypto_sign_PUBLICKEYBYTES];
- const uint8_t sig[crypto_sign_BYTES];
- const uint32_t len;
+ const byte sk[crypto_sign_SEEDBYTES];
+ const byte pk[crypto_sign_PUBLICKEYBYTES];
+ const byte sig[crypto_sign_BYTES];
+ const word32 len;
const char* msg;
};
@@ -401,8 +401,8 @@ bool TestCryptoSign()
// https://github.com/jedisct1/libsodium/blob/master/test/default/sign.c
const unsigned int MAX_MESSAGE = 65; // Sync with test data
- uint8_t pk[crypto_sign_PUBLICKEYBYTES];
- uint8_t sk[crypto_sign_SECRETKEYBYTES];
+ byte pk[crypto_sign_PUBLICKEYBYTES];
+ byte sk[crypto_sign_SECRETKEYBYTES];
SecByteBlock sm(MAX_MESSAGE+crypto_sign_BYTES);
SecByteBlock rm(MAX_MESSAGE+crypto_sign_BYTES);
@@ -415,20 +415,20 @@ bool TestCryptoSign()
std::memcpy(sk+crypto_sign_SEEDBYTES, data.pk, crypto_sign_PUBLICKEYBYTES);
std::memcpy(pk, data.pk, crypto_sign_PUBLICKEYBYTES);
- const uint8_t* m = reinterpret_cast<const uint8_t*>(data.msg);
- const uint64_t l = data.len;
- uint64_t smlen;
+ const byte* m = reinterpret_cast<const byte*>(data.msg);
+ const word64 l = data.len;
+ word64 smlen;
rc = crypto_sign(sm, &smlen, m, l, sk);
fail = (rc != 0); pass = !fail && pass;
- uint64_t s = STDMIN(smlen, (uint64_t)crypto_sign_BYTES);
+ word64 s = STDMIN(smlen, (word64)crypto_sign_BYTES);
pass = (s >= crypto_sign_BYTES) && pass;
fail = std::memcmp(sm, data.sig, (size_t)s) != 0;
pass = !fail && pass;
- uint64_t rmlen;
+ word64 rmlen;
rc = crypto_sign_open(rm, &rmlen, sm, smlen, pk);
fail = (rc != 0); pass = !fail && pass;
@@ -446,8 +446,8 @@ bool TestCryptoSignKeys()
const unsigned int MAX_TEST = 64;
const unsigned int MAX_MESSAGE = 4096;
- uint8_t pk[crypto_sign_PUBLICKEYBYTES];
- uint8_t sk[crypto_sign_SECRETKEYBYTES];
+ byte pk[crypto_sign_PUBLICKEYBYTES];
+ byte sk[crypto_sign_SECRETKEYBYTES];
bool pass = true, fail; int rc;
@@ -456,11 +456,11 @@ bool TestCryptoSignKeys()
fail = (crypto_sign_keypair(pk, sk) != 0);
pass = !fail && pass;
- const uint32_t len = (i == 0 ? 0 : GlobalRNG().GenerateWord32(1, MAX_MESSAGE));
+ const word32 len = (i == 0 ? 0 : GlobalRNG().GenerateWord32(1, MAX_MESSAGE));
SecByteBlock m(len), sm(len+crypto_sign_BYTES), rm(len+crypto_sign_BYTES);
if (len) { GlobalRNG().GenerateBlock(m, len); }
- uint64_t mlen = len, smlen, rmlen;
+ word64 mlen = len, smlen, rmlen;
rc = crypto_sign(sm, &smlen, m, mlen, sk);
fail = (rc != 0); pass = !fail && pass;