rbnacl-libsodium 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/ChangeLog +13 -0
- data/vendor/libsodium/THANKS +1 -0
- data/vendor/libsodium/autom4te.cache/output.1 +14 -90
- data/vendor/libsodium/autom4te.cache/output.3 +14 -90
- data/vendor/libsodium/autom4te.cache/requests +127 -127
- data/vendor/libsodium/autom4te.cache/traces.1 +224 -224
- data/vendor/libsodium/autom4te.cache/traces.3 +137 -144
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +3 -0
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +3 -0
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +3 -0
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +3 -0
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +3 -0
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +3 -0
- data/vendor/libsodium/configure +14 -90
- data/vendor/libsodium/configure.ac +5 -12
- data/vendor/libsodium/msvc-scripts/process.bat +2 -2
- data/vendor/libsodium/packaging/nuget/package.config +1 -1
- data/vendor/libsodium/packaging/nuget/package.nuspec +25 -25
- data/vendor/libsodium/packaging/nuget/package.targets +20 -20
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +2 -0
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +7 -0
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +9 -4
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +6 -1
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +4 -4
- data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +2 -0
- data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +2 -0
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +2 -1
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +2 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +13 -13
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +28 -27
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +16 -12
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +3 -3
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +7 -3
- data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sign_edwards25519sha512batch.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +3 -2
- data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +10 -8
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +13 -8
- data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +10 -8
- data/vendor/libsodium/src/libsodium/sodium/core.c +1 -1
- data/vendor/libsodium/src/libsodium/sodium/runtime.c +3 -3
- data/vendor/libsodium/src/libsodium/sodium/utils.c +12 -12
- data/vendor/libsodium/test/default/Makefile.am +9 -1
- data/vendor/libsodium/test/default/Makefile.in +35 -13
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +37 -31
- data/vendor/libsodium/test/default/auth.c +48 -9
- data/vendor/libsodium/test/default/auth.exp +18 -0
- data/vendor/libsodium/test/default/auth2.c +19 -24
- data/vendor/libsodium/test/default/auth3.c +17 -25
- data/vendor/libsodium/test/default/auth5.c +24 -24
- data/vendor/libsodium/test/default/auth6.c +9 -8
- data/vendor/libsodium/test/default/auth7.c +24 -24
- data/vendor/libsodium/test/default/box.c +74 -51
- data/vendor/libsodium/test/default/box.exp +19 -0
- data/vendor/libsodium/test/default/box2.c +48 -51
- data/vendor/libsodium/test/default/box2.exp +17 -0
- data/vendor/libsodium/test/default/box7.c +20 -18
- data/vendor/libsodium/test/default/box8.c +27 -25
- data/vendor/libsodium/test/default/box_easy.c +32 -42
- data/vendor/libsodium/test/default/box_easy2.c +3 -5
- data/vendor/libsodium/test/default/box_seed.c +20 -20
- data/vendor/libsodium/test/default/chacha20.c +41 -21
- data/vendor/libsodium/test/default/chacha20.exp +8 -5
- data/vendor/libsodium/test/default/cmptest.h +4 -0
- data/vendor/libsodium/test/default/core1.c +26 -19
- data/vendor/libsodium/test/default/core2.c +24 -23
- data/vendor/libsodium/test/default/core3.c +30 -26
- data/vendor/libsodium/test/default/core4.c +22 -23
- data/vendor/libsodium/test/default/core5.c +18 -22
- data/vendor/libsodium/test/default/core6.c +33 -34
- data/vendor/libsodium/test/default/ed25519_convert.c +16 -20
- data/vendor/libsodium/test/default/generichash.c +59 -15
- data/vendor/libsodium/test/default/generichash.exp +2 -0
- data/vendor/libsodium/test/default/generichash2.c +30 -13
- data/vendor/libsodium/test/default/generichash3.c +156 -22
- data/vendor/libsodium/test/default/generichash3.exp +11 -0
- data/vendor/libsodium/test/default/hash.c +31 -6
- data/vendor/libsodium/test/default/hash.exp +3 -0
- data/vendor/libsodium/test/default/hash3.c +10 -7
- data/vendor/libsodium/test/default/onetimeauth.c +46 -34
- data/vendor/libsodium/test/default/onetimeauth.exp +2 -0
- data/vendor/libsodium/test/default/onetimeauth2.c +20 -32
- data/vendor/libsodium/test/default/onetimeauth7.c +24 -24
- data/vendor/libsodium/test/default/pwhash.c +276 -68
- data/vendor/libsodium/test/default/pwhash.exp +20 -0
- data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +31 -37
- data/vendor/libsodium/test/default/randombytes.c +85 -8
- data/vendor/libsodium/test/default/randombytes.exp +1 -0
- data/vendor/libsodium/test/default/scalarmult.c +28 -15
- data/vendor/libsodium/test/default/scalarmult2.c +20 -15
- data/vendor/libsodium/test/default/scalarmult5.c +24 -21
- data/vendor/libsodium/test/default/scalarmult6.c +24 -21
- data/vendor/libsodium/test/default/scalarmult7.c +31 -0
- data/vendor/libsodium/test/default/scalarmult7.exp +1 -0
- data/vendor/libsodium/test/default/secretbox.c +50 -45
- data/vendor/libsodium/test/default/secretbox2.c +32 -45
- data/vendor/libsodium/test/default/secretbox7.c +19 -17
- data/vendor/libsodium/test/default/secretbox8.c +26 -24
- data/vendor/libsodium/test/default/secretbox_easy.c +46 -52
- data/vendor/libsodium/test/default/secretbox_easy2.c +3 -5
- data/vendor/libsodium/test/default/shorthash.c +17 -10
- data/vendor/libsodium/test/default/sign.c +74 -39
- data/vendor/libsodium/test/default/sodium_core.c +6 -3
- data/vendor/libsodium/test/default/sodium_utils.c +57 -28
- data/vendor/libsodium/test/default/sodium_utils.exp +6 -0
- data/vendor/libsodium/test/default/sodium_utils2.c +13 -11
- data/vendor/libsodium/test/default/sodium_utils3.c +5 -10
- data/vendor/libsodium/test/default/sodium_version.c +4 -5
- data/vendor/libsodium/test/default/stream.c +23 -17
- data/vendor/libsodium/test/default/stream2.c +17 -15
- data/vendor/libsodium/test/default/stream3.c +17 -19
- data/vendor/libsodium/test/default/stream4.c +36 -45
- data/vendor/libsodium/test/default/verify1.c +20 -18
- metadata +5 -3
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +0 -356
@@ -1,23 +1,14 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <string.h>
|
3
1
|
|
4
2
|
#define TEST_NAME "sign"
|
5
3
|
#include "cmptest.h"
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
static const unsigned char keypair_seed[] = {
|
13
|
-
0x42, 0x11, 0x51, 0xa4, 0x59, 0xfa, 0xea, 0xde,
|
14
|
-
0x3d, 0x24, 0x71, 0x15, 0xf9, 0x4a, 0xed, 0xae,
|
15
|
-
0x42, 0x31, 0x81, 0x24, 0x09, 0x5a, 0xfa, 0xbe,
|
16
|
-
0x4d, 0x14, 0x51, 0xa5, 0x59, 0xfa, 0xed, 0xee
|
17
|
-
};
|
5
|
+
static const unsigned char keypair_seed[]
|
6
|
+
= { 0x42, 0x11, 0x51, 0xa4, 0x59, 0xfa, 0xea, 0xde, 0x3d, 0x24, 0x71,
|
7
|
+
0x15, 0xf9, 0x4a, 0xed, 0xae, 0x42, 0x31, 0x81, 0x24, 0x09, 0x5a,
|
8
|
+
0xfa, 0xbe, 0x4d, 0x14, 0x51, 0xa5, 0x59, 0xfa, 0xed, 0xee };
|
18
9
|
|
19
10
|
typedef struct TestData_ {
|
20
|
-
const unsigned char sk[
|
11
|
+
const unsigned char sk[crypto_sign_SEEDBYTES];
|
21
12
|
const unsigned char pk[crypto_sign_PUBLICKEYBYTES];
|
22
13
|
const unsigned char sig[crypto_sign_BYTES];
|
23
14
|
const char *m;
|
@@ -1052,27 +1043,29 @@ static TestData test_data[] = {
|
|
1052
1043
|
|
1053
1044
|
int main(void)
|
1054
1045
|
{
|
1055
|
-
unsigned char
|
1056
|
-
unsigned char
|
1057
|
-
unsigned char
|
1058
|
-
unsigned char
|
1059
|
-
unsigned char
|
1060
|
-
unsigned char
|
1061
|
-
unsigned char
|
1062
|
-
unsigned char
|
1063
|
-
char
|
1064
|
-
char
|
1046
|
+
unsigned char extracted_seed[crypto_sign_ed25519_SEEDBYTES];
|
1047
|
+
unsigned char extracted_pk[crypto_sign_ed25519_PUBLICKEYBYTES];
|
1048
|
+
unsigned char sig[crypto_sign_BYTES];
|
1049
|
+
unsigned char sm[1024 + crypto_sign_BYTES];
|
1050
|
+
unsigned char m[1024];
|
1051
|
+
unsigned char skpk[crypto_sign_SECRETKEYBYTES];
|
1052
|
+
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
|
1053
|
+
unsigned char sk[crypto_sign_SECRETKEYBYTES];
|
1054
|
+
char pk_hex[crypto_sign_PUBLICKEYBYTES * 2 + 1];
|
1055
|
+
char sk_hex[crypto_sign_SECRETKEYBYTES * 2 + 1];
|
1065
1056
|
unsigned long long siglen;
|
1066
1057
|
unsigned long long smlen;
|
1067
1058
|
unsigned long long mlen;
|
1068
|
-
unsigned int
|
1059
|
+
unsigned int i;
|
1060
|
+
unsigned int j;
|
1069
1061
|
|
1062
|
+
memset(sig, 0, sizeof sig);
|
1070
1063
|
for (i = 0U; i < (sizeof test_data) / (sizeof test_data[0]); i++) {
|
1071
|
-
memcpy(skpk, test_data[i].sk,
|
1072
|
-
memcpy(skpk +
|
1073
|
-
|
1074
|
-
if (crypto_sign(sm, &smlen,
|
1075
|
-
|
1064
|
+
memcpy(skpk, test_data[i].sk, crypto_sign_SEEDBYTES);
|
1065
|
+
memcpy(skpk + crypto_sign_SEEDBYTES, test_data[i].pk,
|
1066
|
+
crypto_sign_PUBLICKEYBYTES);
|
1067
|
+
if (crypto_sign(sm, &smlen, (const unsigned char *)test_data[i].m, i,
|
1068
|
+
skpk) != 0) {
|
1076
1069
|
printf("crypto_sign() failure: [%u]\n", i);
|
1077
1070
|
continue;
|
1078
1071
|
}
|
@@ -1084,7 +1077,7 @@ int main(void)
|
|
1084
1077
|
printf("crypto_sign_open() failure: [%u]\n", i);
|
1085
1078
|
continue;
|
1086
1079
|
}
|
1087
|
-
if (memcmp(test_data[i].m, m, (size_t)
|
1080
|
+
if (memcmp(test_data[i].m, m, (size_t)mlen) != 0) {
|
1088
1081
|
printf("message verification failure: [%u]\n", i);
|
1089
1082
|
continue;
|
1090
1083
|
}
|
@@ -1096,12 +1089,12 @@ int main(void)
|
|
1096
1089
|
if (crypto_sign_open(m, &mlen, sm, i % crypto_sign_BYTES,
|
1097
1090
|
test_data[i].pk) == 0) {
|
1098
1091
|
printf("short signed message verifies: [%u]\n",
|
1099
|
-
i
|
1092
|
+
i % crypto_sign_BYTES);
|
1100
1093
|
continue;
|
1101
1094
|
}
|
1102
1095
|
if (crypto_sign_detached(sig, &siglen,
|
1103
|
-
(const unsigned char *)
|
1104
|
-
|
1096
|
+
(const unsigned char *)test_data[i].m, i, skpk)
|
1097
|
+
!= 0) {
|
1105
1098
|
printf("detached signature failed: [%u]\n", i);
|
1106
1099
|
continue;
|
1107
1100
|
}
|
@@ -1114,7 +1107,7 @@ int main(void)
|
|
1114
1107
|
continue;
|
1115
1108
|
}
|
1116
1109
|
if (crypto_sign_verify_detached(sig,
|
1117
|
-
(const unsigned char *)
|
1110
|
+
(const unsigned char *)test_data[i].m,
|
1118
1111
|
i, test_data[i].pk) != 0) {
|
1119
1112
|
printf("detached signature verification failed: [%u]\n", i);
|
1120
1113
|
continue;
|
@@ -1122,6 +1115,37 @@ int main(void)
|
|
1122
1115
|
}
|
1123
1116
|
printf("%u tests\n", i);
|
1124
1117
|
|
1118
|
+
i--;
|
1119
|
+
|
1120
|
+
memcpy(sm, test_data[i].m, i);
|
1121
|
+
if (crypto_sign(sm, &smlen, sm, i, skpk) != 0) {
|
1122
|
+
printf("crypto_sign() with overlap failed\n");
|
1123
|
+
}
|
1124
|
+
if (crypto_sign_open(sm, &mlen, sm, smlen, test_data[i].pk) != 0) {
|
1125
|
+
printf("crypto_sign_open() with overlap failed\n");
|
1126
|
+
}
|
1127
|
+
if (memcmp(test_data[i].m, sm, (size_t)mlen) != 0) {
|
1128
|
+
printf("crypto_sign_open() with overlap failed (content)\n");
|
1129
|
+
}
|
1130
|
+
|
1131
|
+
for (j = 1U; j < 8U; j++) {
|
1132
|
+
sig[63] ^= (j << 5);
|
1133
|
+
if (crypto_sign_verify_detached(sig,
|
1134
|
+
(const unsigned char *)test_data[i].m,
|
1135
|
+
i, test_data[i].pk) != -1) {
|
1136
|
+
printf("detached signature verification should have failed\n");
|
1137
|
+
continue;
|
1138
|
+
}
|
1139
|
+
sig[63] ^= (j << 5);
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
memset(pk, 0, sizeof pk);
|
1143
|
+
if (crypto_sign_verify_detached(sig,
|
1144
|
+
(const unsigned char *)test_data[i].m,
|
1145
|
+
i, pk) != -1) {
|
1146
|
+
printf("detached signature verification should have failed\n");
|
1147
|
+
}
|
1148
|
+
|
1125
1149
|
if (crypto_sign_keypair(pk, sk) != 0) {
|
1126
1150
|
printf("crypto_sign_keypair() failure\n");
|
1127
1151
|
}
|
@@ -1130,13 +1154,12 @@ int main(void)
|
|
1130
1154
|
return -1;
|
1131
1155
|
}
|
1132
1156
|
crypto_sign_ed25519_sk_to_seed(extracted_seed, sk);
|
1133
|
-
if (memcmp(extracted_seed, keypair_seed,
|
1134
|
-
|
1157
|
+
if (memcmp(extracted_seed, keypair_seed, crypto_sign_ed25519_SEEDBYTES)
|
1158
|
+
!= 0) {
|
1135
1159
|
printf("crypto_sign_ed25519_sk_to_seed() failure\n");
|
1136
1160
|
}
|
1137
1161
|
crypto_sign_ed25519_sk_to_pk(extracted_pk, sk);
|
1138
|
-
if (memcmp(extracted_pk, pk,
|
1139
|
-
crypto_sign_ed25519_PUBLICKEYBYTES) != 0) {
|
1162
|
+
if (memcmp(extracted_pk, pk, crypto_sign_ed25519_PUBLICKEYBYTES) != 0) {
|
1140
1163
|
printf("crypto_sign_ed25519_sk_to_pk() failure\n");
|
1141
1164
|
}
|
1142
1165
|
sodium_bin2hex(pk_hex, sizeof pk_hex, pk, sizeof pk);
|
@@ -1145,5 +1168,17 @@ int main(void)
|
|
1145
1168
|
printf("pk: [%s]\n", pk_hex);
|
1146
1169
|
printf("sk: [%s]\n", sk_hex);
|
1147
1170
|
|
1171
|
+
assert(crypto_sign_bytes() > 0U);
|
1172
|
+
assert(crypto_sign_seedbytes() > 0U);
|
1173
|
+
assert(crypto_sign_publickeybytes() > 0U);
|
1174
|
+
assert(crypto_sign_secretkeybytes() > 0U);
|
1175
|
+
assert(strcmp(crypto_sign_primitive(), "ed25519") == 0);
|
1176
|
+
assert(crypto_sign_bytes() == crypto_sign_ed25519_bytes());
|
1177
|
+
assert(crypto_sign_seedbytes() == crypto_sign_ed25519_seedbytes());
|
1178
|
+
assert(crypto_sign_publickeybytes()
|
1179
|
+
== crypto_sign_ed25519_publickeybytes());
|
1180
|
+
assert(crypto_sign_secretkeybytes()
|
1181
|
+
== crypto_sign_ed25519_secretkeybytes());
|
1182
|
+
|
1148
1183
|
return 0;
|
1149
1184
|
}
|
@@ -1,11 +1,14 @@
|
|
1
|
-
#include <stdio.h>
|
2
1
|
|
3
2
|
#define TEST_NAME "sodium_core"
|
4
3
|
#include "cmptest.h"
|
5
4
|
|
6
5
|
int main(void)
|
7
6
|
{
|
8
|
-
|
7
|
+
printf("%d\n", sodium_init());
|
9
8
|
|
10
|
-
|
9
|
+
(void)sodium_runtime_has_neon();
|
10
|
+
(void)sodium_runtime_has_sse2();
|
11
|
+
(void)sodium_runtime_has_sse3();
|
12
|
+
|
13
|
+
return 0;
|
11
14
|
}
|
@@ -1,35 +1,64 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include <string.h>
|
3
1
|
|
4
2
|
#define TEST_NAME "sodium_utils"
|
5
3
|
#include "cmptest.h"
|
6
4
|
|
7
5
|
int main(void)
|
8
6
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
7
|
+
unsigned char buf1[1000];
|
8
|
+
unsigned char buf2[1000];
|
9
|
+
char buf3[33];
|
10
|
+
unsigned char buf4[4];
|
11
|
+
const char *hex;
|
12
|
+
const char *hex_end;
|
13
|
+
size_t bin_len;
|
14
|
+
|
15
|
+
randombytes_buf(buf1, sizeof buf1);
|
16
|
+
memcpy(buf2, buf1, sizeof buf2);
|
17
|
+
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
18
|
+
sodium_memzero(buf1, 0U);
|
19
|
+
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
20
|
+
sodium_memzero(buf1, sizeof buf1 / 2);
|
21
|
+
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
22
|
+
printf("%d\n", sodium_memcmp(buf1, buf2, 0U));
|
23
|
+
sodium_memzero(buf2, sizeof buf2 / 2);
|
24
|
+
printf("%d\n", sodium_memcmp(buf1, buf2, sizeof buf1));
|
25
|
+
printf("%s\n",
|
26
|
+
sodium_bin2hex(buf3, 33U, (const unsigned char *)"0123456789ABCDEF",
|
27
|
+
16U));
|
28
|
+
hex = "Cafe : 6942";
|
29
|
+
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, &hex_end);
|
30
|
+
printf("%lu:%02x%02x%02x%02x\n", (unsigned long)bin_len, buf4[0], buf4[1],
|
31
|
+
buf4[2], buf4[3]);
|
32
|
+
printf("dt1: %ld\n", (long) (hex_end - hex));
|
33
|
+
|
34
|
+
hex = "Cafe : 6942";
|
35
|
+
sodium_hex2bin(buf4, sizeof buf4, hex, strlen(hex), ": ", &bin_len, NULL);
|
36
|
+
printf("%lu:%02x%02x%02x%02x\n", (unsigned long)bin_len, buf4[2], buf4[3],
|
37
|
+
buf4[2], buf4[3]);
|
38
|
+
|
39
|
+
hex = "deadbeef";
|
40
|
+
if (sodium_hex2bin(buf1, 1U, hex, 8U, NULL, &bin_len, &hex_end) != -1) {
|
41
|
+
printf("sodium_hex2bin() overflow not detected\n");
|
42
|
+
}
|
43
|
+
printf("dt2: %ld\n", (long) (hex_end - hex));
|
44
|
+
|
45
|
+
hex = "de:ad:be:eff";
|
46
|
+
if (sodium_hex2bin(buf1, 4U, hex, 12U, ":", &bin_len, &hex_end) != -1) {
|
47
|
+
printf("sodium_hex2bin() with an odd input length and a short output buffer\n");
|
48
|
+
}
|
49
|
+
printf("dt3: %ld\n", (long) (hex_end - hex));
|
50
|
+
|
51
|
+
hex = "de:ad:be:eff";
|
52
|
+
if (sodium_hex2bin(buf1, sizeof buf1, hex, 12U, ":", &bin_len, &hex_end) != 0) {
|
53
|
+
printf("sodium_hex2bin() with an odd input length\n");
|
54
|
+
}
|
55
|
+
printf("dt4: %ld\n", (long) (hex_end - hex));
|
56
|
+
|
57
|
+
hex = "de:ad:be:eff";
|
58
|
+
if (sodium_hex2bin(buf1, sizeof buf1, hex, 13U, ":", &bin_len, &hex_end) != 0) {
|
59
|
+
printf("sodium_hex2bin() with an odd input length\n");
|
60
|
+
}
|
61
|
+
printf("dt5: %ld\n", (long) (hex_end - hex));
|
62
|
+
|
63
|
+
return 0;
|
35
64
|
}
|
@@ -3,15 +3,11 @@
|
|
3
3
|
|
4
4
|
#include <limits.h>
|
5
5
|
#include <signal.h>
|
6
|
-
#include <string.h>
|
7
|
-
#include <stdio.h>
|
8
|
-
#include <string.h>
|
9
6
|
|
10
7
|
#define TEST_NAME "sodium_utils2"
|
11
8
|
#include "cmptest.h"
|
12
9
|
|
13
|
-
static void
|
14
|
-
segv_handler(int sig)
|
10
|
+
static void segv_handler(int sig)
|
15
11
|
{
|
16
12
|
printf("Intentional segfault / bus error caught\n");
|
17
13
|
printf("OK\n");
|
@@ -27,16 +23,22 @@ segv_handler(int sig)
|
|
27
23
|
exit(0);
|
28
24
|
}
|
29
25
|
|
30
|
-
int
|
31
|
-
main(void)
|
26
|
+
int main(void)
|
32
27
|
{
|
33
|
-
void
|
34
|
-
size_t
|
35
|
-
unsigned int
|
28
|
+
void *buf;
|
29
|
+
size_t size;
|
30
|
+
unsigned int i;
|
36
31
|
|
32
|
+
if (sodium_malloc(SIZE_MAX - 1U) != NULL) {
|
33
|
+
return 1;
|
34
|
+
}
|
37
35
|
if (sodium_allocarray(SIZE_MAX / 2U + 1U, SIZE_MAX / 2U) != NULL) {
|
38
36
|
return 1;
|
39
37
|
}
|
38
|
+
buf = sodium_allocarray(1000U, 50U);
|
39
|
+
memset(buf, 0, 50000U);
|
40
|
+
sodium_free(buf);
|
41
|
+
|
40
42
|
sodium_free(sodium_malloc(0U));
|
41
43
|
sodium_free(NULL);
|
42
44
|
for (i = 0U; i < 10000U; i++) {
|
@@ -61,7 +63,7 @@ main(void)
|
|
61
63
|
buf = sodium_malloc(size);
|
62
64
|
sodium_mprotect_readonly(buf);
|
63
65
|
sodium_mprotect_readwrite(buf);
|
64
|
-
sodium_memzero(((unsigned char *)
|
66
|
+
sodium_memzero(((unsigned char *)buf) + size, 1U);
|
65
67
|
sodium_mprotect_noaccess(buf);
|
66
68
|
sodium_free(buf);
|
67
69
|
printf("Overflow not caught\n");
|
@@ -3,15 +3,11 @@
|
|
3
3
|
|
4
4
|
#include <limits.h>
|
5
5
|
#include <signal.h>
|
6
|
-
#include <string.h>
|
7
|
-
#include <stdio.h>
|
8
|
-
#include <string.h>
|
9
6
|
|
10
7
|
#define TEST_NAME "sodium_utils3"
|
11
8
|
#include "cmptest.h"
|
12
9
|
|
13
|
-
static void
|
14
|
-
segv_handler(int sig)
|
10
|
+
static void segv_handler(int sig)
|
15
11
|
{
|
16
12
|
printf("Intentional segfault / bus error caught\n");
|
17
13
|
printf("OK\n");
|
@@ -27,11 +23,10 @@ segv_handler(int sig)
|
|
27
23
|
exit(0);
|
28
24
|
}
|
29
25
|
|
30
|
-
int
|
31
|
-
main(void)
|
26
|
+
int main(void)
|
32
27
|
{
|
33
|
-
void
|
34
|
-
size_t
|
28
|
+
void *buf;
|
29
|
+
size_t size;
|
35
30
|
|
36
31
|
#ifdef SIGSEGV
|
37
32
|
signal(SIGSEGV, segv_handler);
|
@@ -46,7 +41,7 @@ main(void)
|
|
46
41
|
buf = sodium_malloc(size);
|
47
42
|
sodium_mprotect_noaccess(buf);
|
48
43
|
sodium_mprotect_readwrite(buf);
|
49
|
-
sodium_memzero(((unsigned char *)
|
44
|
+
sodium_memzero(((unsigned char *)buf) - 8, 8U);
|
50
45
|
sodium_mprotect_readonly(buf);
|
51
46
|
sodium_free(buf);
|
52
47
|
printf("Underflow not caught\n");
|
@@ -1,13 +1,12 @@
|
|
1
|
-
#include <stdio.h>
|
2
1
|
|
3
2
|
#define TEST_NAME "sodium_version"
|
4
3
|
#include "cmptest.h"
|
5
4
|
|
6
5
|
int main(void)
|
7
6
|
{
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
printf("%d\n", sodium_version_string() != NULL);
|
8
|
+
printf("%d\n", sodium_library_version_major() > 0);
|
9
|
+
printf("%d\n", sodium_library_version_minor() >= 0);
|
11
10
|
|
12
|
-
|
11
|
+
return 0;
|
13
12
|
}
|
@@ -1,20 +1,15 @@
|
|
1
|
-
#include <stdio.h>
|
2
1
|
|
3
2
|
#define TEST_NAME "stream"
|
4
3
|
#include "cmptest.h"
|
5
4
|
|
6
|
-
unsigned char firstkey[32]
|
7
|
-
0x1b,0x27,0x55,0x64,0x73,0xe9,0x85,0xd4
|
8
|
-
|
9
|
-
,
|
10
|
-
,0x06,0xc4,0xee,0x08,0x44,0xf6,0x83,0x89
|
11
|
-
} ;
|
5
|
+
unsigned char firstkey[32]
|
6
|
+
= { 0x1b, 0x27, 0x55, 0x64, 0x73, 0xe9, 0x85, 0xd4, 0x62, 0xcd, 0x51,
|
7
|
+
0x19, 0x7a, 0x9a, 0x46, 0xc7, 0x60, 0x09, 0x54, 0x9e, 0xac, 0x64,
|
8
|
+
0x74, 0xf2, 0x06, 0xc4, 0xee, 0x08, 0x44, 0xf6, 0x83, 0x89 };
|
12
9
|
|
13
|
-
unsigned char nonce[24] = {
|
14
|
-
|
15
|
-
,
|
16
|
-
,0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37
|
17
|
-
} ;
|
10
|
+
unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
|
11
|
+
0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
|
12
|
+
0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
|
18
13
|
|
19
14
|
unsigned char output[4194304];
|
20
15
|
|
@@ -22,9 +17,20 @@ unsigned char h[32];
|
|
22
17
|
|
23
18
|
int main(void)
|
24
19
|
{
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
20
|
+
int i;
|
21
|
+
|
22
|
+
crypto_stream(output, 4194304, nonce, firstkey);
|
23
|
+
crypto_hash_sha256(h, output, sizeof output);
|
24
|
+
|
25
|
+
for (i = 0; i < 32; ++i)
|
26
|
+
printf("%02x", h[i]);
|
27
|
+
printf("\n");
|
28
|
+
|
29
|
+
assert(crypto_stream_keybytes() > 0U);
|
30
|
+
assert(crypto_stream_noncebytes() > 0U);
|
31
|
+
assert(strcmp(crypto_stream_primitive(), "xsalsa20") == 0);
|
32
|
+
assert(crypto_stream_keybytes() == crypto_stream_xsalsa20_keybytes());
|
33
|
+
assert(crypto_stream_noncebytes() == crypto_stream_xsalsa20_noncebytes());
|
34
|
+
|
35
|
+
return 0;
|
30
36
|
}
|