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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/ChangeLog +13 -0
  5. data/vendor/libsodium/THANKS +1 -0
  6. data/vendor/libsodium/autom4te.cache/output.1 +14 -90
  7. data/vendor/libsodium/autom4te.cache/output.3 +14 -90
  8. data/vendor/libsodium/autom4te.cache/requests +127 -127
  9. data/vendor/libsodium/autom4te.cache/traces.1 +224 -224
  10. data/vendor/libsodium/autom4te.cache/traces.3 +137 -144
  11. data/vendor/libsodium/builds/msvc/version.h +2 -2
  12. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +3 -0
  13. data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +3 -0
  14. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +3 -0
  15. data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +3 -0
  16. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +3 -0
  17. data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +3 -0
  18. data/vendor/libsodium/configure +14 -90
  19. data/vendor/libsodium/configure.ac +5 -12
  20. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  21. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  22. data/vendor/libsodium/packaging/nuget/package.nuspec +25 -25
  23. data/vendor/libsodium/packaging/nuget/package.targets +20 -20
  24. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +2 -0
  25. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +7 -0
  26. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +1 -1
  27. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +9 -4
  28. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +6 -1
  29. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/generichash_blake2b.c +4 -4
  30. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +2 -0
  31. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +2 -0
  32. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/auth_poly1305_donna.c +2 -1
  33. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +2 -0
  34. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +13 -13
  35. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +28 -27
  36. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +16 -12
  37. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +2 -2
  38. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -2
  39. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +3 -3
  40. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +1 -1
  41. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +7 -3
  42. data/vendor/libsodium/src/libsodium/crypto_sign/edwards25519sha512batch/ref/sign_edwards25519sha512batch.c +1 -1
  43. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +3 -2
  44. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +10 -8
  45. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +13 -8
  46. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +10 -8
  47. data/vendor/libsodium/src/libsodium/sodium/core.c +1 -1
  48. data/vendor/libsodium/src/libsodium/sodium/runtime.c +3 -3
  49. data/vendor/libsodium/src/libsodium/sodium/utils.c +12 -12
  50. data/vendor/libsodium/test/default/Makefile.am +9 -1
  51. data/vendor/libsodium/test/default/Makefile.in +35 -13
  52. data/vendor/libsodium/test/default/aead_chacha20poly1305.c +37 -31
  53. data/vendor/libsodium/test/default/auth.c +48 -9
  54. data/vendor/libsodium/test/default/auth.exp +18 -0
  55. data/vendor/libsodium/test/default/auth2.c +19 -24
  56. data/vendor/libsodium/test/default/auth3.c +17 -25
  57. data/vendor/libsodium/test/default/auth5.c +24 -24
  58. data/vendor/libsodium/test/default/auth6.c +9 -8
  59. data/vendor/libsodium/test/default/auth7.c +24 -24
  60. data/vendor/libsodium/test/default/box.c +74 -51
  61. data/vendor/libsodium/test/default/box.exp +19 -0
  62. data/vendor/libsodium/test/default/box2.c +48 -51
  63. data/vendor/libsodium/test/default/box2.exp +17 -0
  64. data/vendor/libsodium/test/default/box7.c +20 -18
  65. data/vendor/libsodium/test/default/box8.c +27 -25
  66. data/vendor/libsodium/test/default/box_easy.c +32 -42
  67. data/vendor/libsodium/test/default/box_easy2.c +3 -5
  68. data/vendor/libsodium/test/default/box_seed.c +20 -20
  69. data/vendor/libsodium/test/default/chacha20.c +41 -21
  70. data/vendor/libsodium/test/default/chacha20.exp +8 -5
  71. data/vendor/libsodium/test/default/cmptest.h +4 -0
  72. data/vendor/libsodium/test/default/core1.c +26 -19
  73. data/vendor/libsodium/test/default/core2.c +24 -23
  74. data/vendor/libsodium/test/default/core3.c +30 -26
  75. data/vendor/libsodium/test/default/core4.c +22 -23
  76. data/vendor/libsodium/test/default/core5.c +18 -22
  77. data/vendor/libsodium/test/default/core6.c +33 -34
  78. data/vendor/libsodium/test/default/ed25519_convert.c +16 -20
  79. data/vendor/libsodium/test/default/generichash.c +59 -15
  80. data/vendor/libsodium/test/default/generichash.exp +2 -0
  81. data/vendor/libsodium/test/default/generichash2.c +30 -13
  82. data/vendor/libsodium/test/default/generichash3.c +156 -22
  83. data/vendor/libsodium/test/default/generichash3.exp +11 -0
  84. data/vendor/libsodium/test/default/hash.c +31 -6
  85. data/vendor/libsodium/test/default/hash.exp +3 -0
  86. data/vendor/libsodium/test/default/hash3.c +10 -7
  87. data/vendor/libsodium/test/default/onetimeauth.c +46 -34
  88. data/vendor/libsodium/test/default/onetimeauth.exp +2 -0
  89. data/vendor/libsodium/test/default/onetimeauth2.c +20 -32
  90. data/vendor/libsodium/test/default/onetimeauth7.c +24 -24
  91. data/vendor/libsodium/test/default/pwhash.c +276 -68
  92. data/vendor/libsodium/test/default/pwhash.exp +20 -0
  93. data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +31 -37
  94. data/vendor/libsodium/test/default/randombytes.c +85 -8
  95. data/vendor/libsodium/test/default/randombytes.exp +1 -0
  96. data/vendor/libsodium/test/default/scalarmult.c +28 -15
  97. data/vendor/libsodium/test/default/scalarmult2.c +20 -15
  98. data/vendor/libsodium/test/default/scalarmult5.c +24 -21
  99. data/vendor/libsodium/test/default/scalarmult6.c +24 -21
  100. data/vendor/libsodium/test/default/scalarmult7.c +31 -0
  101. data/vendor/libsodium/test/default/scalarmult7.exp +1 -0
  102. data/vendor/libsodium/test/default/secretbox.c +50 -45
  103. data/vendor/libsodium/test/default/secretbox2.c +32 -45
  104. data/vendor/libsodium/test/default/secretbox7.c +19 -17
  105. data/vendor/libsodium/test/default/secretbox8.c +26 -24
  106. data/vendor/libsodium/test/default/secretbox_easy.c +46 -52
  107. data/vendor/libsodium/test/default/secretbox_easy2.c +3 -5
  108. data/vendor/libsodium/test/default/shorthash.c +17 -10
  109. data/vendor/libsodium/test/default/sign.c +74 -39
  110. data/vendor/libsodium/test/default/sodium_core.c +6 -3
  111. data/vendor/libsodium/test/default/sodium_utils.c +57 -28
  112. data/vendor/libsodium/test/default/sodium_utils.exp +6 -0
  113. data/vendor/libsodium/test/default/sodium_utils2.c +13 -11
  114. data/vendor/libsodium/test/default/sodium_utils3.c +5 -10
  115. data/vendor/libsodium/test/default/sodium_version.c +4 -5
  116. data/vendor/libsodium/test/default/stream.c +23 -17
  117. data/vendor/libsodium/test/default/stream2.c +17 -15
  118. data/vendor/libsodium/test/default/stream3.c +17 -19
  119. data/vendor/libsodium/test/default/stream4.c +36 -45
  120. data/vendor/libsodium/test/default/verify1.c +20 -18
  121. metadata +5 -3
  122. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +0 -356
@@ -1,4 +1,3 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "auth"
4
3
  #include "cmptest.h"
@@ -7,15 +6,55 @@
7
6
  unsigned char key[32] = "Jefe";
8
7
  unsigned char c[] = "what do ya want for nothing?";
9
8
 
10
- unsigned char a[32];
9
+ /* Hacker manifesto */
10
+ unsigned char key2[] = "Another one got caught today, it's all over the papers. \"Teenager Arrested in Computer Crime Scandal\", \"Hacker Arrested after Bank Tampering\"... Damn kids. They're all alike.";
11
+
12
+ unsigned char a[crypto_auth_BYTES];
13
+ unsigned char a2[crypto_auth_hmacsha512_BYTES];
11
14
 
12
15
  int main(void)
13
16
  {
14
- int i;
15
- crypto_auth_hmacsha512256(a,c,sizeof c - 1U,key);
16
- for (i = 0;i < 32;++i) {
17
- printf(",0x%02x",(unsigned int) a[i]);
18
- if (i % 8 == 7) printf("\n");
19
- }
20
- return 0;
17
+ crypto_auth_hmacsha512_state st;
18
+ int i;
19
+
20
+ crypto_auth(a, c, sizeof c - 1U, key);
21
+ for (i = 0; i < sizeof a; ++i) {
22
+ printf(",0x%02x", (unsigned int)a[i]);
23
+ if (i % 8 == 7)
24
+ printf("\n");
25
+ }
26
+ printf("\n");
27
+
28
+ crypto_auth_hmacsha512_init(&st, key, sizeof key);
29
+ crypto_auth_hmacsha512_update(&st, c, 1U);
30
+ crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
31
+ crypto_auth_hmacsha512_final(&st, a2);
32
+ for (i = 0; i < sizeof a2; ++i) {
33
+ printf(",0x%02x", (unsigned int)a2[i]);
34
+ if (i % 8 == 7)
35
+ printf("\n");
36
+ }
37
+ printf("\n");
38
+
39
+ crypto_auth_hmacsha512_init(&st, key2, sizeof key2);
40
+ crypto_auth_hmacsha512_update(&st, c, 1U);
41
+ crypto_auth_hmacsha512_update(&st, c, sizeof c - 2U);
42
+ crypto_auth_hmacsha512_final(&st, a2);
43
+ for (i = 0; i < sizeof a2; ++i) {
44
+ printf(",0x%02x", (unsigned int)a2[i]);
45
+ if (i % 8 == 7)
46
+ printf("\n");
47
+ }
48
+
49
+ assert(crypto_auth_bytes() > 0U);
50
+ assert(crypto_auth_keybytes() > 0U);
51
+ assert(strcmp(crypto_auth_primitive(), "hmacsha512256") == 0);
52
+ assert(crypto_auth_hmacsha256_bytes() > 0U);
53
+ assert(crypto_auth_hmacsha256_keybytes() > 0U);
54
+ assert(crypto_auth_hmacsha512_bytes() > 0U);
55
+ assert(crypto_auth_hmacsha512_keybytes() > 0U);
56
+ assert(crypto_auth_hmacsha512256_bytes() == crypto_auth_bytes());
57
+ assert(crypto_auth_hmacsha512256_keybytes() == crypto_auth_keybytes());
58
+
59
+ return 0;
21
60
  }
@@ -2,3 +2,21 @@
2
2
  ,0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3
3
3
  ,0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6
4
4
  ,0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54
5
+
6
+ ,0x7b,0x9d,0x83,0x38,0xeb,0x1e,0x3d,0xdd
7
+ ,0xba,0x8a,0x9a,0x35,0x08,0xd0,0x34,0xa1
8
+ ,0xec,0xbe,0x75,0x11,0x37,0xfa,0x1b,0xcb
9
+ ,0xa0,0xf9,0x2a,0x3e,0x6d,0xfc,0x79,0x80
10
+ ,0xb8,0x81,0xa8,0x64,0x5f,0x92,0x67,0x22
11
+ ,0x74,0x37,0x96,0x4b,0xf3,0x07,0x0b,0xe2
12
+ ,0xb3,0x36,0xb3,0xa3,0x20,0xf8,0x25,0xce
13
+ ,0xc9,0x87,0x2d,0xb2,0x50,0x4b,0xf3,0x6d
14
+
15
+ ,0x73,0xe0,0x0d,0xcb,0xf4,0xf8,0xa3,0x33
16
+ ,0x30,0xac,0x52,0xed,0x2c,0xc9,0xd1,0xb2
17
+ ,0xef,0xb1,0x77,0x13,0xd3,0xec,0xe3,0x96
18
+ ,0x14,0x9f,0x37,0x65,0x3c,0xfe,0x70,0xe7
19
+ ,0x1f,0x2c,0x6f,0x9a,0x62,0xc3,0xc5,0x3a
20
+ ,0x31,0x8a,0x9a,0x0b,0x3b,0x78,0x60,0xa4
21
+ ,0x31,0x6f,0x72,0x9b,0x8d,0x30,0x0f,0x15
22
+ ,0x9b,0x2f,0x60,0x93,0xa8,0x60,0xc1,0xed
@@ -1,36 +1,31 @@
1
1
  /* "Test Case AUTH256-4" from RFC 4868 */
2
2
 
3
- #include <stdio.h>
4
-
5
3
  #define TEST_NAME "auth2"
6
4
  #include "cmptest.h"
7
5
 
8
- unsigned char key[32] = {
9
- 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
10
- ,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10
11
- ,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
12
- ,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20
13
- } ;
6
+ unsigned char key[32]
7
+ = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
8
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
9
+ 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 };
14
10
 
15
- unsigned char c[50] = {
16
- 0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
17
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
18
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
19
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
20
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
21
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
22
- ,0xcd,0xcd
23
- } ;
11
+ unsigned char c[50]
12
+ = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
13
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
14
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
15
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
16
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd };
24
17
 
25
18
  unsigned char a[32];
26
19
 
27
20
  int main(void)
28
21
  {
29
- int i;
30
- crypto_auth_hmacsha256(a,c,sizeof c,key);
31
- for (i = 0;i < 32;++i) {
32
- printf(",0x%02x",(unsigned int) a[i]);
33
- if (i % 8 == 7) printf("\n");
34
- }
35
- return 0;
22
+ int i;
23
+
24
+ crypto_auth_hmacsha256(a, c, sizeof c, key);
25
+ for (i = 0; i < 32; ++i) {
26
+ printf(",0x%02x", (unsigned int)a[i]);
27
+ if (i % 8 == 7)
28
+ printf("\n");
29
+ }
30
+ return 0;
36
31
  }
@@ -1,36 +1,28 @@
1
1
  /* "Test Case AUTH256-4" from RFC 4868 */
2
2
 
3
- #include <stdio.h>
4
-
5
3
  #define TEST_NAME "auth3"
6
4
  #include "cmptest.h"
7
5
 
8
- unsigned char key[32] = {
9
- 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
10
- ,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10
11
- ,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18
12
- ,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20
13
- } ;
6
+ unsigned char key[32]
7
+ = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
8
+ 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
9
+ 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 };
14
10
 
15
- unsigned char c[50] = {
16
- 0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
17
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
18
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
19
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
20
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
21
- ,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd
22
- ,0xcd,0xcd
23
- } ;
11
+ unsigned char c[50]
12
+ = { 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
13
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
14
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
15
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd,
16
+ 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd };
24
17
 
25
- unsigned char a[32] = {
26
- 0x37,0x2e,0xfc,0xf9,0xb4,0x0b,0x35,0xc2
27
- ,0x11,0x5b,0x13,0x46,0x90,0x3d,0x2e,0xf4
28
- ,0x2f,0xce,0xd4,0x6f,0x08,0x46,0xe7,0x25
29
- ,0x7b,0xb1,0x56,0xd3,0xd7,0xb3,0x0d,0x3f
30
- } ;
18
+ unsigned char a[32]
19
+ = { 0x37, 0x2e, 0xfc, 0xf9, 0xb4, 0x0b, 0x35, 0xc2, 0x11, 0x5b, 0x13,
20
+ 0x46, 0x90, 0x3d, 0x2e, 0xf4, 0x2f, 0xce, 0xd4, 0x6f, 0x08, 0x46,
21
+ 0xe7, 0x25, 0x7b, 0xb1, 0x56, 0xd3, 0xd7, 0xb3, 0x0d, 0x3f };
31
22
 
32
23
  int main(void)
33
24
  {
34
- printf("%d\n",crypto_auth_hmacsha256_verify(a,c,sizeof c,key));
35
- return 0;
25
+ printf("%d\n", crypto_auth_hmacsha256_verify(a, c, sizeof c, key));
26
+
27
+ return 0;
36
28
  }
@@ -1,5 +1,4 @@
1
- #include <stdio.h>
2
- #include <stdlib.h>
1
+
3
2
  #include "windows/windows-quirks.h"
4
3
 
5
4
  #define TEST_NAME "auth5"
@@ -11,27 +10,28 @@ unsigned char a[32];
11
10
 
12
11
  int main(void)
13
12
  {
14
- int clen;
15
- for (clen = 0;clen < 10000;++clen) {
16
- randombytes(key,sizeof key);
17
- randombytes(c,clen);
18
- crypto_auth_hmacsha512256(a,c,clen,key);
19
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) != 0) {
20
- printf("fail %d\n",clen);
21
- return 100;
22
- }
23
- if (clen > 0) {
24
- c[rand() % clen] += 1 + (rand() % 255);
25
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
26
- printf("forgery %d\n",clen);
27
- return 100;
28
- }
29
- a[rand() % sizeof a] += 1 + (rand() % 255);
30
- if (crypto_auth_hmacsha512256_verify(a,c,clen,key) == 0) {
31
- printf("forgery %d\n",clen);
32
- return 100;
33
- }
13
+ size_t clen;
14
+
15
+ for (clen = 0; clen < 10000; ++clen) {
16
+ randombytes_buf(key, sizeof key);
17
+ randombytes_buf(c, clen);
18
+ crypto_auth(a, c, clen, key);
19
+ if (crypto_auth_verify(a, c, clen, key) != 0) {
20
+ printf("fail %u\n", (unsigned int) clen);
21
+ return 100;
22
+ }
23
+ if (clen > 0) {
24
+ c[rand() % clen] += 1 + (rand() % 255);
25
+ if (crypto_auth_verify(a, c, clen, key) == 0) {
26
+ printf("forgery %u\n", (unsigned int) clen);
27
+ return 100;
28
+ }
29
+ a[rand() % sizeof a] += 1 + (rand() % 255);
30
+ if (crypto_auth_verify(a, c, clen, key) == 0) {
31
+ printf("forgery %u\n", (unsigned int) clen);
32
+ return 100;
33
+ }
34
+ }
34
35
  }
35
- }
36
- return 0;
36
+ return 0;
37
37
  }
@@ -1,4 +1,3 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "auth6"
4
3
  #include "cmptest.h"
@@ -11,11 +10,13 @@ unsigned char a[64];
11
10
 
12
11
  int main(void)
13
12
  {
14
- int i;
15
- crypto_auth_hmacsha512(a,c,sizeof c - 1U,key);
16
- for (i = 0;i < 64;++i) {
17
- printf(",0x%02x",(unsigned int) a[i]);
18
- if (i % 8 == 7) printf("\n");
19
- }
20
- return 0;
13
+ int i;
14
+
15
+ crypto_auth_hmacsha512(a, c, sizeof c - 1U, key);
16
+ for (i = 0; i < 64; ++i) {
17
+ printf(",0x%02x", (unsigned int)a[i]);
18
+ if (i % 8 == 7)
19
+ printf("\n");
20
+ }
21
+ return 0;
21
22
  }
@@ -1,5 +1,4 @@
1
- #include <stdio.h>
2
- #include <stdlib.h>
1
+
3
2
  #include "windows/windows-quirks.h"
4
3
 
5
4
  #define TEST_NAME "auth7"
@@ -11,27 +10,28 @@ unsigned char a[64];
11
10
 
12
11
  int main(void)
13
12
  {
14
- int clen;
15
- for (clen = 0;clen < 10000;++clen) {
16
- randombytes(key,sizeof key);
17
- randombytes(c,clen);
18
- crypto_auth_hmacsha512(a,c,clen,key);
19
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) != 0) {
20
- printf("fail %d\n",clen);
21
- return 100;
22
- }
23
- if (clen > 0) {
24
- c[rand() % clen] += 1 + (rand() % 255);
25
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) == 0) {
26
- printf("forgery %d\n",clen);
27
- return 100;
28
- }
29
- a[rand() % sizeof a] += 1 + (rand() % 255);
30
- if (crypto_auth_hmacsha512_verify(a,c,clen,key) == 0) {
31
- printf("forgery %d\n",clen);
32
- return 100;
33
- }
13
+ int clen;
14
+
15
+ for (clen = 0; clen < 10000; ++clen) {
16
+ randombytes_buf(key, sizeof key);
17
+ randombytes_buf(c, clen);
18
+ crypto_auth_hmacsha512(a, c, clen, key);
19
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) != 0) {
20
+ printf("fail %d\n", clen);
21
+ return 100;
22
+ }
23
+ if (clen > 0) {
24
+ c[rand() % clen] += 1 + (rand() % 255);
25
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
26
+ printf("forgery %d\n", clen);
27
+ return 100;
28
+ }
29
+ a[rand() % sizeof a] += 1 + (rand() % 255);
30
+ if (crypto_auth_hmacsha512_verify(a, c, clen, key) == 0) {
31
+ printf("forgery %d\n", clen);
32
+ return 100;
33
+ }
34
+ }
34
35
  }
35
- }
36
- return 0;
36
+ return 0;
37
37
  }
@@ -1,65 +1,88 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "box"
4
3
  #include "cmptest.h"
5
4
 
6
- unsigned char alicesk[32] = {
7
- 0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d
8
- ,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45
9
- ,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a
10
- ,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a
11
- } ;
5
+ unsigned char alicesk[32]
6
+ = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1,
7
+ 0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0,
8
+ 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a };
12
9
 
13
- unsigned char bobpk[32] = {
14
- 0xde,0x9e,0xdb,0x7d,0x7b,0x7d,0xc1,0xb4
15
- ,0xd3,0x5b,0x61,0xc2,0xec,0xe4,0x35,0x37
16
- ,0x3f,0x83,0x43,0xc8,0x5b,0x78,0x67,0x4d
17
- ,0xad,0xfc,0x7e,0x14,0x6f,0x88,0x2b,0x4f
18
- } ;
10
+ unsigned char bobpk[32]
11
+ = { 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 0x61,
12
+ 0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78,
13
+ 0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f };
19
14
 
20
- unsigned char nonce[24] = {
21
- 0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73
22
- ,0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6
23
- ,0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37
24
- } ;
15
+ unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73,
16
+ 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6,
17
+ 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 };
25
18
 
26
19
  // API requires first 32 bytes to be 0
27
- unsigned char m[163] = {
28
- 0, 0, 0, 0, 0, 0, 0, 0
29
- , 0, 0, 0, 0, 0, 0, 0, 0
30
- , 0, 0, 0, 0, 0, 0, 0, 0
31
- , 0, 0, 0, 0, 0, 0, 0, 0
32
- ,0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
33
- ,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
34
- ,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
35
- ,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
36
- ,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
37
- ,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
38
- ,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
39
- ,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
40
- ,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
41
- ,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
42
- ,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
43
- ,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
44
- ,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
45
- ,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
46
- ,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
47
- ,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
48
- ,0x5e,0x07,0x05
49
- } ;
20
+ unsigned char m[163]
21
+ = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23
+ 0, 0, 0, 0, 0, 0, 0, 0, 0xbe, 0x07, 0x5f, 0xc5,
24
+ 0x3c, 0x81, 0xf2, 0xd5, 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b,
25
+ 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, 0x4b, 0x66, 0x84, 0x9b,
26
+ 0x64, 0x24, 0x4f, 0xfc, 0xe5, 0xec, 0xba, 0xaf, 0x33, 0xbd, 0x75, 0x1a,
27
+ 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29, 0x6c, 0xdc, 0x3c, 0x01,
28
+ 0x23, 0x35, 0x61, 0xf4, 0x1d, 0xb6, 0x6c, 0xce, 0x31, 0x4a, 0xdb, 0x31,
29
+ 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d, 0xce, 0xea, 0x3a, 0x7f,
30
+ 0xa1, 0x34, 0x80, 0x57, 0xe2, 0xf6, 0x55, 0x6a, 0xd6, 0xb1, 0x31, 0x8a,
31
+ 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde, 0x04, 0x89, 0x77, 0xeb,
32
+ 0x48, 0xf5, 0x9f, 0xfd, 0x49, 0x24, 0xca, 0x1c, 0x60, 0x90, 0x2e, 0x52,
33
+ 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40, 0xe0, 0x82, 0xf9, 0x37,
34
+ 0x76, 0x38, 0x48, 0x64, 0x5e, 0x07, 0x05 };
50
35
 
51
36
  unsigned char c[163];
52
37
 
53
38
  int main(void)
54
39
  {
55
- int i;
56
- crypto_box_curve25519xsalsa20poly1305(
57
- c,m,163,nonce,bobpk,alicesk
58
- );
59
- for (i = 16;i < 163;++i) {
60
- printf(",0x%02x",(unsigned int) c[i]);
61
- if (i % 8 == 7) printf("\n");
62
- }
63
- printf("\n");
64
- return 0;
40
+ unsigned char k[crypto_box_BEFORENMBYTES];
41
+ int i;
42
+
43
+ crypto_box(c, m, 163, nonce, bobpk, alicesk);
44
+ for (i = 16; i < 163; ++i) {
45
+ printf(",0x%02x", (unsigned int)c[i]);
46
+ if (i % 8 == 7)
47
+ printf("\n");
48
+ }
49
+ printf("\n");
50
+
51
+ memset(c, 0, sizeof c);
52
+ crypto_box_beforenm(k, bobpk, alicesk);
53
+ crypto_box_afternm(c, m, 163, nonce, k);
54
+ for (i = 16; i < 163; ++i) {
55
+ printf(",0x%02x", (unsigned int)c[i]);
56
+ if (i % 8 == 7)
57
+ printf("\n");
58
+ }
59
+ printf("\n");
60
+
61
+ assert(crypto_box_seedbytes() > 0U);
62
+ assert(crypto_box_publickeybytes() > 0U);
63
+ assert(crypto_box_secretkeybytes() > 0U);
64
+ assert(crypto_box_beforenmbytes() > 0U);
65
+ assert(crypto_box_noncebytes() > 0U);
66
+ assert(crypto_box_zerobytes() > 0U);
67
+ assert(crypto_box_boxzerobytes() > 0U);
68
+ assert(crypto_box_macbytes() > 0U);
69
+ assert(strcmp(crypto_box_primitive(), "curve25519xsalsa20poly1305") == 0);
70
+ assert(crypto_box_curve25519xsalsa20poly1305_seedbytes()
71
+ == crypto_box_seedbytes());
72
+ assert(crypto_box_curve25519xsalsa20poly1305_publickeybytes()
73
+ == crypto_box_publickeybytes());
74
+ assert(crypto_box_curve25519xsalsa20poly1305_secretkeybytes()
75
+ == crypto_box_secretkeybytes());
76
+ assert(crypto_box_curve25519xsalsa20poly1305_beforenmbytes()
77
+ == crypto_box_beforenmbytes());
78
+ assert(crypto_box_curve25519xsalsa20poly1305_noncebytes()
79
+ == crypto_box_noncebytes());
80
+ assert(crypto_box_curve25519xsalsa20poly1305_zerobytes()
81
+ == crypto_box_zerobytes());
82
+ assert(crypto_box_curve25519xsalsa20poly1305_boxzerobytes()
83
+ == crypto_box_boxzerobytes());
84
+ assert(crypto_box_curve25519xsalsa20poly1305_macbytes()
85
+ == crypto_box_macbytes());
86
+
87
+ return 0;
65
88
  }