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
@@ -17,3 +17,22 @@
17
17
  ,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
18
18
  ,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
19
19
  ,0xe3,0x55,0xa5
20
+ ,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
21
+ ,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
22
+ ,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73
23
+ ,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce
24
+ ,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4
25
+ ,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a
26
+ ,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b
27
+ ,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72
28
+ ,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2
29
+ ,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38
30
+ ,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a
31
+ ,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae
32
+ ,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea
33
+ ,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda
34
+ ,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde
35
+ ,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3
36
+ ,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
37
+ ,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
38
+ ,0xe3,0x55,0xa5
@@ -1,66 +1,63 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "box2"
4
3
  #include "cmptest.h"
5
4
 
6
- unsigned char bobsk[32] = {
7
- 0x5d,0xab,0x08,0x7e,0x62,0x4a,0x8a,0x4b
8
- ,0x79,0xe1,0x7f,0x8b,0x83,0x80,0x0e,0xe6
9
- ,0x6f,0x3b,0xb1,0x29,0x26,0x18,0xb6,0xfd
10
- ,0x1c,0x2f,0x8b,0x27,0xff,0x88,0xe0,0xeb
11
- } ;
5
+ unsigned char bobsk[32]
6
+ = { 0x5d, 0xab, 0x08, 0x7e, 0x62, 0x4a, 0x8a, 0x4b, 0x79, 0xe1, 0x7f,
7
+ 0x8b, 0x83, 0x80, 0x0e, 0xe6, 0x6f, 0x3b, 0xb1, 0x29, 0x26, 0x18,
8
+ 0xb6, 0xfd, 0x1c, 0x2f, 0x8b, 0x27, 0xff, 0x88, 0xe0, 0xeb };
12
9
 
13
- unsigned char alicepk[32] = {
14
- 0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54
15
- ,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a
16
- ,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4
17
- ,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a
18
- } ;
10
+ unsigned char alicepk[32]
11
+ = { 0x85, 0x20, 0xf0, 0x09, 0x89, 0x30, 0xa7, 0x54, 0x74, 0x8b, 0x7d,
12
+ 0xdc, 0xb4, 0x3e, 0xf7, 0x5a, 0x0d, 0xbf, 0x3a, 0x0d, 0x26, 0x38,
13
+ 0x1a, 0xf4, 0xeb, 0xa4, 0xa9, 0x8e, 0xaa, 0x9b, 0x4e, 0x6a };
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 16 bytes to be 0
27
- unsigned char c[163] = {
28
- 0, 0, 0, 0, 0, 0, 0, 0
29
- , 0, 0, 0, 0, 0, 0, 0, 0
30
- ,0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
31
- ,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
32
- ,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73
33
- ,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce
34
- ,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4
35
- ,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a
36
- ,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b
37
- ,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72
38
- ,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2
39
- ,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38
40
- ,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a
41
- ,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae
42
- ,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea
43
- ,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda
44
- ,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde
45
- ,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3
46
- ,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
47
- ,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
48
- ,0xe3,0x55,0xa5
49
- } ;
20
+ unsigned char c[163]
21
+ = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22
+ 0, 0, 0, 0, 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5,
23
+ 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, 0x8e, 0x99, 0x3b, 0x9f,
24
+ 0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce,
25
+ 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, 0x47, 0x6f, 0xb8, 0xc5,
26
+ 0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b,
27
+ 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, 0x71, 0xd2, 0xc2, 0x0f,
28
+ 0x9b, 0x92, 0x8f, 0xe2, 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38,
29
+ 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a, 0xb9, 0x32, 0x16, 0x45,
30
+ 0x48, 0xe5, 0x26, 0xae, 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea,
31
+ 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, 0x99, 0x83, 0x2b, 0x61,
32
+ 0xca, 0x01, 0xb6, 0xde, 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3,
33
+ 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, 0x59, 0x9b, 0x1f, 0x65,
34
+ 0x4c, 0xb4, 0x5a, 0x74, 0xe3, 0x55, 0xa5 };
50
35
 
51
36
  unsigned char m[163];
52
37
 
53
38
  int main(void)
54
39
  {
55
- int i;
56
- if (crypto_box_curve25519xsalsa20poly1305_open(
57
- m,c,163,nonce,alicepk,bobsk
58
- ) == 0) {
59
- for (i = 32;i < 163;++i) {
60
- printf(",0x%02x",(unsigned int) m[i]);
61
- if (i % 8 == 7) printf("\n");
40
+ unsigned char k[crypto_box_BEFORENMBYTES];
41
+ int i;
42
+
43
+ if (crypto_box_open(m, c, 163, nonce, alicepk, bobsk) == 0) {
44
+ for (i = 32; i < 163; ++i) {
45
+ printf(",0x%02x", (unsigned int)m[i]);
46
+ if (i % 8 == 7)
47
+ printf("\n");
48
+ }
49
+ printf("\n");
50
+ }
51
+
52
+ memset(m, 0, sizeof m);
53
+ crypto_box_beforenm(k, alicepk, bobsk);
54
+ if (crypto_box_open_afternm(m, c, 163, nonce, k) == 0) {
55
+ for (i = 32; i < 163; ++i) {
56
+ printf(",0x%02x", (unsigned int)m[i]);
57
+ if (i % 8 == 7)
58
+ printf("\n");
59
+ }
60
+ printf("\n");
62
61
  }
63
- printf("\n");
64
- }
65
- return 0;
62
+ return 0;
66
63
  }
@@ -15,3 +15,20 @@
15
15
  ,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
16
16
  ,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
17
17
  ,0x5e,0x07,0x05
18
+ ,0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
19
+ ,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
20
+ ,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
21
+ ,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
22
+ ,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
23
+ ,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
24
+ ,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
25
+ ,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
26
+ ,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
27
+ ,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
28
+ ,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
29
+ ,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
30
+ ,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
31
+ ,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
32
+ ,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
33
+ ,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
34
+ ,0x5e,0x07,0x05
@@ -1,4 +1,3 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "box7"
4
3
  #include "cmptest.h"
@@ -14,24 +13,27 @@ unsigned char m2[10000];
14
13
 
15
14
  int main(void)
16
15
  {
17
- size_t mlen;
18
- size_t i;
16
+ size_t mlen;
17
+ size_t i;
19
18
 
20
- for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
21
- crypto_box_keypair(alicepk,alicesk);
22
- crypto_box_keypair(bobpk,bobsk);
23
- randombytes(n,crypto_box_NONCEBYTES);
24
- randombytes(m + crypto_box_ZEROBYTES,mlen);
25
- crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
26
- if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) {
27
- for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i)
28
- if (m2[i] != m[i]) {
29
- printf("bad decryption\n");
30
- break;
19
+ for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
20
+ ++mlen) {
21
+ crypto_box_keypair(alicepk, alicesk);
22
+ crypto_box_keypair(bobpk, bobsk);
23
+ randombytes_buf(n, crypto_box_NONCEBYTES);
24
+ randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
25
+ crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
26
+ if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
27
+ bobsk) == 0) {
28
+ for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
29
+ if (m2[i] != m[i]) {
30
+ printf("bad decryption\n");
31
+ break;
32
+ }
33
+ }
34
+ } else {
35
+ printf("ciphertext fails verification\n");
31
36
  }
32
- } else {
33
- printf("ciphertext fails verification\n");
34
37
  }
35
- }
36
- return 0;
38
+ return 0;
37
39
  }
@@ -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 "box8"
@@ -16,29 +15,32 @@ unsigned char m2[10000];
16
15
 
17
16
  int main(void)
18
17
  {
19
- size_t mlen;
20
- size_t i;
21
- int caught;
18
+ size_t mlen;
19
+ size_t i;
20
+ int caught;
22
21
 
23
- for (mlen = 0;mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;++mlen) {
24
- crypto_box_keypair(alicepk,alicesk);
25
- crypto_box_keypair(bobpk,bobsk);
26
- randombytes(n,crypto_box_NONCEBYTES);
27
- randombytes(m + crypto_box_ZEROBYTES,mlen);
28
- crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,bobpk,alicesk);
29
- caught = 0;
30
- while (caught < 10) {
31
- c[rand() % (mlen + crypto_box_ZEROBYTES)] = rand();
32
- if (crypto_box_open(m2,c,mlen + crypto_box_ZEROBYTES,n,alicepk,bobsk) == 0) {
33
- for (i = 0;i < mlen + crypto_box_ZEROBYTES;++i)
34
- if (m2[i] != m[i]) {
35
- printf("forgery\n");
36
- return 100;
37
- }
38
- } else {
39
- ++caught;
40
- }
22
+ for (mlen = 0; mlen < 1000 && mlen + crypto_box_ZEROBYTES < sizeof m;
23
+ ++mlen) {
24
+ crypto_box_keypair(alicepk, alicesk);
25
+ crypto_box_keypair(bobpk, bobsk);
26
+ randombytes_buf(n, crypto_box_NONCEBYTES);
27
+ randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
28
+ crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
29
+ caught = 0;
30
+ while (caught < 10) {
31
+ c[rand() % (mlen + crypto_box_ZEROBYTES)] = rand();
32
+ if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
33
+ bobsk) == 0) {
34
+ for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
35
+ if (m2[i] != m[i]) {
36
+ printf("forgery\n");
37
+ return 100;
38
+ }
39
+ }
40
+ } else {
41
+ ++caught;
42
+ }
43
+ }
41
44
  }
42
- }
43
- return 0;
45
+ return 0;
44
46
  }
@@ -1,47 +1,33 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "box_easy"
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
- } ;
12
-
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
- } ;
19
-
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
- } ;
25
-
26
- unsigned char m[131] = {
27
- 0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
28
- ,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
29
- ,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
30
- ,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
31
- ,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
32
- ,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
33
- ,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
34
- ,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
35
- ,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
36
- ,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
37
- ,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
38
- ,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
39
- ,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
40
- ,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
41
- ,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
42
- ,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
43
- ,0x5e,0x07,0x05
44
- } ;
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 };
9
+
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 };
14
+
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 };
18
+
19
+ unsigned char m[131]
20
+ = { 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, 0xcf, 0x14, 0x13, 0x16,
21
+ 0xeb, 0xeb, 0x0c, 0x7b, 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4,
22
+ 0x4b, 0x66, 0x84, 0x9b, 0x64, 0x24, 0x4f, 0xfc, 0xe5, 0xec, 0xba, 0xaf,
23
+ 0x33, 0xbd, 0x75, 0x1a, 0x1a, 0xc7, 0x28, 0xd4, 0x5e, 0x6c, 0x61, 0x29,
24
+ 0x6c, 0xdc, 0x3c, 0x01, 0x23, 0x35, 0x61, 0xf4, 0x1d, 0xb6, 0x6c, 0xce,
25
+ 0x31, 0x4a, 0xdb, 0x31, 0x0e, 0x3b, 0xe8, 0x25, 0x0c, 0x46, 0xf0, 0x6d,
26
+ 0xce, 0xea, 0x3a, 0x7f, 0xa1, 0x34, 0x80, 0x57, 0xe2, 0xf6, 0x55, 0x6a,
27
+ 0xd6, 0xb1, 0x31, 0x8a, 0x02, 0x4a, 0x83, 0x8f, 0x21, 0xaf, 0x1f, 0xde,
28
+ 0x04, 0x89, 0x77, 0xeb, 0x48, 0xf5, 0x9f, 0xfd, 0x49, 0x24, 0xca, 0x1c,
29
+ 0x60, 0x90, 0x2e, 0x52, 0xf0, 0xa0, 0x89, 0xbc, 0x76, 0x89, 0x70, 0x40,
30
+ 0xe0, 0x82, 0xf9, 0x37, 0x76, 0x38, 0x48, 0x64, 0x5e, 0x07, 0x05 };
45
31
 
46
32
  unsigned char c[147 + crypto_box_MACBYTES];
47
33
 
@@ -51,9 +37,13 @@ int main(void)
51
37
 
52
38
  crypto_box_easy(c, m, 131, nonce, bobpk, alicesk);
53
39
  for (i = 0; i < 131 + crypto_box_MACBYTES; ++i) {
54
- printf(",0x%02x",(unsigned int) c[i]);
55
- if (i % 8 == 7) printf("\n");
40
+ printf(",0x%02x", (unsigned int)c[i]);
41
+ if (i % 8 == 7)
42
+ printf("\n");
56
43
  }
57
44
  printf("\n");
45
+
46
+ assert(crypto_box_easy(c, m, SIZE_MAX - 1U, nonce, bobpk, alicesk) == -1);
47
+
58
48
  return 0;
59
49
  }
@@ -1,5 +1,3 @@
1
- #include <stdio.h>
2
- #include <string.h>
3
1
 
4
2
  #define TEST_NAME "box_easy2"
5
3
  #include "cmptest.h"
@@ -21,12 +19,12 @@ int main(void)
21
19
 
22
20
  crypto_box_keypair(alicepk, alicesk);
23
21
  crypto_box_keypair(bobpk, bobsk);
24
- mlen = (unsigned long long) randombytes_uniform((uint32_t) sizeof m);
22
+ mlen = (unsigned long long)randombytes_uniform((uint32_t)sizeof m);
25
23
  randombytes_buf(m, mlen);
26
24
  randombytes_buf(nonce, sizeof nonce);
27
25
  crypto_box_easy(c, m, mlen, nonce, bobpk, alicesk);
28
- if (crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES,
29
- nonce, alicepk, bobsk) != 0) {
26
+ if (crypto_box_open_easy(m2, c, mlen + crypto_box_MACBYTES, nonce, alicepk,
27
+ bobsk) != 0) {
30
28
  printf("open() failed");
31
29
  return 1;
32
30
  }
@@ -1,28 +1,28 @@
1
- #include <stdio.h>
2
1
 
3
2
  #define TEST_NAME "box_seed"
4
3
  #include "cmptest.h"
5
4
 
6
- unsigned char seed[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 seed[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
10
  int main(void)
14
11
  {
15
- int i;
16
- unsigned char sk[32];
17
- unsigned char pk[32];
18
- crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
19
- for (i = 0;i < 32;++i) {
20
- printf(",0x%02x",(unsigned int) pk[i]);
21
- if (i % 8 == 7) printf("\n");
22
- }
23
- for (i = 0;i < 32;++i) {
24
- printf(",0x%02x",(unsigned int) sk[i]);
25
- if (i % 8 == 7) printf("\n");
26
- }
27
- return 0;
12
+ int i;
13
+ unsigned char sk[32];
14
+ unsigned char pk[32];
15
+
16
+ crypto_box_seed_keypair(pk, sk, seed);
17
+ for (i = 0; i < 32; ++i) {
18
+ printf(",0x%02x", (unsigned int)pk[i]);
19
+ if (i % 8 == 7)
20
+ printf("\n");
21
+ }
22
+ for (i = 0; i < 32; ++i) {
23
+ printf(",0x%02x", (unsigned int)sk[i]);
24
+ if (i % 8 == 7)
25
+ printf("\n");
26
+ }
27
+ return 0;
28
28
  }
@@ -1,7 +1,4 @@
1
1
 
2
- #include <stdio.h>
3
- #include <string.h>
4
-
5
2
  #define TEST_NAME "chacha20"
6
3
  #include "cmptest.h"
7
4
 
@@ -10,36 +7,59 @@ static void tv(void)
10
7
  static struct {
11
8
  const char *key_hex;
12
9
  const char *nonce_hex;
13
- } tests[] = {
14
- {"0000000000000000000000000000000000000000000000000000000000000000","0000000000000000"},
15
- {"0000000000000000000000000000000000000000000000000000000000000001","0000000000000000"},
16
- {"0000000000000000000000000000000000000000000000000000000000000000","0000000000000001"},
17
- {"0000000000000000000000000000000000000000000000000000000000000000","0100000000000000"},
18
- {"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f","0001020304050607"}
19
- };
10
+ } tests[]
11
+ = { { "0000000000000000000000000000000000000000000000000000000000000000",
12
+ "0000000000000000" },
13
+ { "0000000000000000000000000000000000000000000000000000000000000001",
14
+ "0000000000000000" },
15
+ { "0000000000000000000000000000000000000000000000000000000000000000",
16
+ "0000000000000001" },
17
+ { "0000000000000000000000000000000000000000000000000000000000000000",
18
+ "0100000000000000" },
19
+ { "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
20
+ "0001020304050607" } };
20
21
  unsigned char key[crypto_stream_chacha20_KEYBYTES];
21
22
  unsigned char nonce[crypto_stream_chacha20_NONCEBYTES];
22
- unsigned char out[60];
23
- char out_hex[60 * 2 + 1];
24
- size_t i = 0U;
23
+ unsigned char out[160];
24
+ char out_hex[160 * 2 + 1];
25
+ size_t i = 0U;
25
26
 
26
27
  do {
27
- sodium_hex2bin((unsigned char *) key, sizeof key,
28
- tests[i].key_hex, strlen(tests[i].key_hex),
29
- NULL, NULL, NULL);
30
- sodium_hex2bin(nonce, sizeof nonce,
31
- tests[i].nonce_hex, strlen(tests[i].nonce_hex),
32
- NULL, NULL, NULL);
28
+ sodium_hex2bin((unsigned char *)key, sizeof key, tests[i].key_hex,
29
+ strlen(tests[i].key_hex), NULL, NULL, NULL);
30
+ sodium_hex2bin(nonce, sizeof nonce, tests[i].nonce_hex,
31
+ strlen(tests[i].nonce_hex), NULL, NULL, NULL);
33
32
  crypto_stream_chacha20(out, sizeof out, nonce, key);
34
33
  sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
35
34
  printf("[%s]\n", out_hex);
36
35
  } while (++i < (sizeof tests) / (sizeof tests[0]));
36
+
37
+ memset(out, 0x42, sizeof out);
38
+
39
+ assert(crypto_stream_chacha20(out, 0U, nonce, key) == 0);
40
+ assert(crypto_stream_chacha20_xor(out, out, 0U, nonce, key) == 0);
41
+ assert(crypto_stream_chacha20_xor(out, out, 0U, nonce, key) == 0);
42
+ assert(crypto_stream_chacha20_xor_ic(out, out, 0U, nonce, 1U, key) == 0);
43
+
44
+ crypto_stream_chacha20_xor(out, out, sizeof out, nonce, key);
45
+ sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
46
+ printf("[%s]\n", out_hex);
47
+
48
+ crypto_stream_chacha20_xor_ic(out, out, sizeof out, nonce, 0U, key);
49
+ sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
50
+ printf("[%s]\n", out_hex);
51
+
52
+ crypto_stream_chacha20_xor_ic(out, out, sizeof out, nonce, 1U, key);
53
+ sodium_bin2hex(out_hex, sizeof out_hex, out, sizeof out);
54
+ printf("[%s]\n", out_hex);
37
55
  };
38
56
 
39
57
  int main(void)
40
58
  {
41
59
  tv();
42
60
 
43
- return 0;
44
- }
61
+ assert(crypto_stream_chacha20_keybytes() > 0U);
62
+ assert(crypto_stream_chacha20_noncebytes() > 0U);
45
63
 
64
+ return 0;
65
+ }