rbnacl-libsodium 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -2
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/ChangeLog +24 -0
  5. data/vendor/libsodium/LICENSE +2 -0
  6. data/vendor/libsodium/Makefile.in +6 -1
  7. data/vendor/libsodium/aclocal.m4 +1 -0
  8. data/vendor/libsodium/autom4te.cache/output.1 +1896 -1136
  9. data/vendor/libsodium/autom4te.cache/output.7 +19837 -0
  10. data/vendor/libsodium/autom4te.cache/requests +1271 -1031
  11. data/vendor/libsodium/autom4te.cache/traces.1 +532 -491
  12. data/vendor/libsodium/autom4te.cache/traces.7 +3614 -0
  13. data/vendor/libsodium/builds/msvc/version.h +2 -2
  14. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +22 -1
  15. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +23 -20
  16. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +13 -2
  17. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +12 -9
  18. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +12 -1
  19. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +3 -0
  20. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +2 -1
  21. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +14 -11
  22. data/vendor/libsodium/configure +1887 -1127
  23. data/vendor/libsodium/configure.ac +44 -11
  24. data/vendor/libsodium/dist-build/Makefile.am +4 -2
  25. data/vendor/libsodium/dist-build/Makefile.in +9 -2
  26. data/vendor/libsodium/dist-build/android-armv8-a.sh +1 -1
  27. data/vendor/libsodium/dist-build/android-build.sh +40 -3
  28. data/vendor/libsodium/dist-build/android-mips64.sh +1 -1
  29. data/vendor/libsodium/dist-build/android-x86_64.sh +4 -0
  30. data/vendor/libsodium/dist-build/emscripten-symbols.def +25 -25
  31. data/vendor/libsodium/dist-build/emscripten.sh +69 -35
  32. data/vendor/libsodium/dist-build/msys2-win32.sh +8 -2
  33. data/vendor/libsodium/dist-build/msys2-win64.sh +8 -2
  34. data/vendor/libsodium/dist-build/{nativeclient.sh → nativeclient-pnacl.sh} +3 -4
  35. data/vendor/libsodium/dist-build/nativeclient-x86.sh +19 -0
  36. data/vendor/libsodium/dist-build/nativeclient-x86_64.sh +19 -0
  37. data/vendor/libsodium/logo.png +0 -0
  38. data/vendor/libsodium/m4/ax_pthread.m4 +485 -0
  39. data/vendor/libsodium/msvc-scripts/Makefile.in +5 -0
  40. data/vendor/libsodium/msvc-scripts/process.bat +2 -2
  41. data/vendor/libsodium/packaging/nuget/package.bat +3 -3
  42. data/vendor/libsodium/src/Makefile.in +5 -0
  43. data/vendor/libsodium/src/libsodium/Makefile.am +2 -1
  44. data/vendor/libsodium/src/libsodium/Makefile.in +13 -8
  45. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +70 -87
  46. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +6 -0
  47. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +1 -1
  48. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +9 -1
  49. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +11 -4
  50. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +14 -8
  51. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +0 -1
  52. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +10 -6
  53. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +2 -1
  54. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +1 -1
  55. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +11 -11
  56. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +2 -2
  57. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_nsquare.S +3 -0
  58. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_pack.S +3 -0
  59. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.S +830 -826
  60. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.S +732 -728
  61. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +3 -0
  62. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +1 -1
  63. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/amd64_xmm6/stream_salsa20_amd64_xmm6.S +8 -0
  64. data/vendor/libsodium/src/libsodium/include/Makefile.in +5 -0
  65. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +1 -1
  66. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +1 -1
  67. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth.h +1 -1
  68. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha256.h +1 -1
  69. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512.h +1 -1
  70. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h +1 -1
  71. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box.h +3 -3
  72. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +1 -1
  73. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash.h +1 -1
  74. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +1 -1
  75. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash.h +1 -1
  76. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +1 -1
  77. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +1 -1
  78. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +1 -1
  79. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +1 -1
  80. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +1 -1
  81. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +1 -1
  82. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +1 -1
  83. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +1 -1
  84. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +1 -1
  85. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash.h +1 -1
  86. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +1 -1
  87. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +3 -3
  88. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +1 -1
  89. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +1 -1
  90. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +1 -1
  91. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +1 -1
  92. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +1 -1
  93. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +1 -1
  94. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +1 -1
  95. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +1 -1
  96. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +1 -1
  97. data/vendor/libsodium/src/libsodium/include/sodium/private/curve25519_ref10.h +2 -2
  98. data/vendor/libsodium/src/libsodium/include/sodium/private/mutex.h +7 -0
  99. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +1 -1
  100. data/vendor/libsodium/src/libsodium/randombytes/nativeclient/randombytes_nativeclient.c +15 -4
  101. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +25 -15
  102. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +72 -15
  103. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +43 -4
  104. data/vendor/libsodium/src/libsodium/sodium/core.c +131 -2
  105. data/vendor/libsodium/src/libsodium/sodium/runtime.c +5 -2
  106. data/vendor/libsodium/src/libsodium/sodium/utils.c +16 -8
  107. data/vendor/libsodium/test/Makefile.in +5 -0
  108. data/vendor/libsodium/test/default/Makefile.in +5 -0
  109. data/vendor/libsodium/test/default/generichash2.c +8 -2
  110. data/vendor/libsodium/test/default/nacl-test-wrapper.sh +19 -17
  111. data/vendor/libsodium/test/default/randombytes.c +4 -2
  112. data/vendor/libsodium/test/quirks/quirks.h +23 -2
  113. metadata +11 -15
  114. data/vendor/libsodium/README +0 -1
  115. data/vendor/libsodium/dist-build/android-x86-64.sh +0 -4
  116. data/vendor/libsodium/examples/Makefile +0 -21
  117. data/vendor/libsodium/examples/auth.c +0 -68
  118. data/vendor/libsodium/examples/box.c +0 -135
  119. data/vendor/libsodium/examples/box_detached.c +0 -134
  120. data/vendor/libsodium/examples/generichash.c +0 -80
  121. data/vendor/libsodium/examples/generichash_stream.c +0 -58
  122. data/vendor/libsodium/examples/shorthash.c +0 -58
  123. data/vendor/libsodium/examples/sign.c +0 -78
  124. data/vendor/libsodium/examples/utils.h +0 -110
@@ -1,134 +0,0 @@
1
- /*
2
- * GraxRabble
3
- * example programs for libsodium.
4
- */
5
-
6
- #include <sodium.h> /* library header */
7
-
8
- #include "utils.h" /* utility functions shared by examples */
9
-
10
- /*
11
- * Using public-key authenticated encryption, Bob can encrypt a
12
- * confidential message specifically for Alice, using Alice's public
13
- * key.
14
- *
15
- * Using Bob's public key, Alice can verify that the encrypted
16
- * message was actually created by Bob and was not tampered with,
17
- * before eventually decrypting it.
18
- *
19
- * Alice only needs Bob's public key, the nonce and the ciphertext.
20
- * Bob should never ever share his secret key, even with Alice.
21
- *
22
- * And in order to send messages to Alice, Bob only needs Alice's
23
- * public key. Alice should never ever share her secret key either,
24
- * even with Bob.
25
- *
26
- * Alice can reply to Bob using the same system, without having to
27
- * generate a distinct key pair.
28
- *
29
- * The nonce doesn't have to be confidential, but it should be used
30
- * with just one invokation of crypto_box_open_easy() for a
31
- * particular pair of public and secret keys.
32
- *
33
- * One easy way to generate a nonce is to use randombytes_buf(),
34
- * considering the size of nonces the risk of any random collisions
35
- * is negligible. For some applications, if you wish to use nonces to
36
- * detect missing messages or to ignore replayed messages, it is also
37
- * ok to use a simple incrementing counter as a nonce.
38
- *
39
- * When doing so you must ensure that the same value can never be
40
- * re-used (for example you may have multiple threads or even hosts
41
- * generating messages using the same key pairs).
42
- *
43
- * This system provides mutual authentication. However, a typical use
44
- * case is to secure communications between a server, whose public
45
- * key is known in advance, and clients connecting anonymously.
46
- */
47
- static int
48
- box_detached(void)
49
- {
50
- unsigned char bob_pk[crypto_box_PUBLICKEYBYTES]; /* Bob's public key */
51
- unsigned char bob_sk[crypto_box_SECRETKEYBYTES]; /* Bob's secret key */
52
-
53
- unsigned char alice_pk[crypto_box_PUBLICKEYBYTES]; /* Alice's public key */
54
- unsigned char alice_sk[crypto_box_SECRETKEYBYTES]; /* Alice's secret key */
55
-
56
- unsigned char nonce[crypto_box_NONCEBYTES];
57
- unsigned char message[MAX_INPUT_LEN];
58
- unsigned char mac[crypto_box_MACBYTES];
59
- unsigned char ciphertext[MAX_INPUT_LEN];
60
- size_t message_len;
61
- int ret;
62
-
63
- puts("Example: crypto_box_detached\n");
64
-
65
- puts("Generating keypairs...\n");
66
- crypto_box_keypair(bob_pk, bob_sk); /* generate Bob's keys */
67
- crypto_box_keypair(alice_pk, alice_sk); /* generate Alice's keys */
68
-
69
- puts("Bob");
70
- printf("Public key: ");
71
- print_hex(bob_pk, sizeof bob_pk);
72
- printf("Secret key: ");
73
- print_hex(bob_sk, sizeof bob_sk);
74
-
75
- puts("Alice");
76
- printf("Public key: ");
77
- print_hex(alice_pk, sizeof alice_pk);
78
- printf("Secret key: ");
79
- print_hex(alice_sk, sizeof alice_sk);
80
-
81
- /* nonce must be unique per (key, message) - it can be public and deterministic */
82
- puts("Generating nonce...");
83
- randombytes_buf(nonce, sizeof nonce);
84
- printf("Nonce: ");
85
- print_hex(nonce, sizeof nonce);
86
-
87
- /* read input */
88
- message_len = prompt_input("a message", (char*)message, sizeof message, 1);
89
-
90
- print_hex(message, message_len);
91
-
92
- /* encrypt and authenticate the message */
93
- printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive());
94
- if (crypto_box_detached(ciphertext, mac, message, message_len, nonce,
95
- alice_pk, bob_sk) != 0) {
96
- abort();
97
- }
98
-
99
- /* send the nonce, the MAC and the ciphertext */
100
- puts("Bob sends the nonce, the MAC and the ciphertext...\n");
101
- printf("Nonce: ");
102
- print_hex(nonce, sizeof nonce);
103
- printf("MAC: ");
104
- print_hex(mac, sizeof mac);
105
- printf("Ciphertext: ");
106
- print_hex(ciphertext, message_len);
107
-
108
- /* decrypt the message */
109
- puts("Alice verifies the MAC and decrypts the ciphertext...");
110
- ret = crypto_box_open_detached(message, ciphertext, mac, message_len, nonce,
111
- bob_pk, alice_sk);
112
- print_hex(message, message_len);
113
-
114
- print_verification(ret);
115
- if (ret == 0) {
116
- printf("Plaintext: ");
117
- fwrite(message, 1U, message_len, stdout);
118
- putchar('\n');
119
- }
120
- sodium_memzero(bob_sk, sizeof bob_sk); /* wipe sensitive data */
121
- sodium_memzero(alice_sk, sizeof alice_sk);
122
- sodium_memzero(message, sizeof message);
123
- sodium_memzero(ciphertext, sizeof ciphertext);
124
-
125
- return ret;
126
- }
127
-
128
- int
129
- main(void)
130
- {
131
- init();
132
-
133
- return box_detached() != 0;
134
- }
@@ -1,80 +0,0 @@
1
- /*
2
- * GraxRabble
3
- * example programs for libsodium.
4
- */
5
-
6
- #include <sodium.h> /* library header */
7
-
8
- #include "utils.h" /* utility functions shared by examples */
9
-
10
- /*
11
- * This function computes a fixed-length fingerprint for an arbitrary long message.
12
- *
13
- * Sample use cases:
14
- *
15
- * File integrity checking
16
- * Creating unique identifiers to index arbitrary long data
17
- *
18
- * The crypto_generichash() function puts a fingerprint of the
19
- * message in whose length is inlen bytes into out. The output size
20
- * can be chosen by the application.
21
- *
22
- * The minimum recommended output size is crypto_generichash_BYTES.
23
- * This size makes it practically impossible for two messages to
24
- * produce the same fingerprint.
25
- *
26
- * But for specific use cases, the size can be any value between
27
- * crypto_generichash_BYTES_MIN (included) and
28
- * crypto_generichash_BYTES_MAX (included).
29
- *
30
- * key can be NULL and keylen can be 0. In this case, a message will
31
- * always have the same fingerprint, similar to the MD5 or SHA-1
32
- * functions for which crypto_generichash() is a faster and more
33
- * secure alternative.
34
- *
35
- * But a key can also be specified. A message will always have the
36
- * same fingerprint for a given key, but different keys used to hash
37
- * the same message are very likely to produce distinct fingerprints.
38
- *
39
- * In particular, the key can be used to make sure that different
40
- * applications generate different fingerprints even if they process
41
- * the same data.
42
- *
43
- * The recommended key size is crypto_generichash_KEYBYTES bytes.
44
- *
45
- * However, the key size can by any value between
46
- * crypto_generichash_KEYBYTES_MIN (included) and
47
- * crypto_generichash_KEYBYTES_MAX (included).
48
- */
49
- void
50
- generichash(void)
51
- {
52
- unsigned char key[crypto_generichash_KEYBYTES_MAX];
53
- unsigned char hash[crypto_generichash_BYTES];
54
- unsigned char message[MAX_INPUT_LEN];
55
- size_t message_len;
56
- size_t key_len;
57
-
58
- puts("Example: crypto_generichash\n");
59
-
60
- key_len = prompt_input("a key", (char*)key, sizeof key, 1);
61
- message_len = prompt_input("a message", (char*)message, sizeof message, 1);
62
-
63
- printf("Hashing message with %s\n", crypto_generichash_primitive());
64
- if (crypto_generichash(hash, sizeof hash, message, message_len,
65
- key, key_len) != 0) {
66
- puts("Couldn't hash the message, probably due to the key length");
67
- } else {
68
- printf("Hash: ");
69
- print_hex(hash, sizeof hash);
70
- }
71
- }
72
-
73
- int
74
- main(void)
75
- {
76
- init();
77
- generichash();
78
-
79
- return 0;
80
- }
@@ -1,58 +0,0 @@
1
- /*
2
- * GraxRabble
3
- * example programs for libsodium.
4
- */
5
-
6
- #include <sodium.h> /* library header */
7
-
8
- #include "utils.h" /* utility functions shared by examples */
9
-
10
- /*
11
- * Streaming variant of generic hash. This has the ability to hash
12
- * data in chunks at a time and compute the same result as hashing
13
- * all of the data at once.
14
- */
15
- void
16
- generichash_stream(void)
17
- {
18
- unsigned char key[crypto_generichash_KEYBYTES_MAX];
19
- unsigned char hash[crypto_generichash_BYTES];
20
- unsigned char message_part[MAX_INPUT_LEN];
21
- crypto_generichash_state state;
22
- size_t message_part_len;
23
-
24
- puts("Example: crypto_generichashstream\n");
25
-
26
- prompt_input("a key", (char*)key, sizeof key, 1);
27
-
28
- printf("Hashing message with %s\n", crypto_generichash_primitive());
29
-
30
- /* initialize the stream */
31
- if (crypto_generichash_init(&state, key, sizeof key, sizeof hash) != 0) {
32
- puts("Couldn't hash the message, probably due to the key length");
33
- exit(EXIT_FAILURE);
34
- }
35
-
36
- for(;;) {
37
- message_part_len = prompt_input("the next part of the message",
38
- (char*)message_part, sizeof message_part, 1);
39
- if (message_part_len == 0)
40
- break;
41
-
42
- /* keep appending data */
43
- crypto_generichash_update(&state, message_part, message_part_len);
44
- }
45
- crypto_generichash_final(&state, hash, sizeof hash);
46
-
47
- printf("Hash: ");
48
- print_hex(hash, sizeof hash);
49
- }
50
-
51
- int
52
- main(void)
53
- {
54
- init();
55
- generichash_stream();
56
-
57
- return 0;
58
- }
@@ -1,58 +0,0 @@
1
- /*
2
- * GraxRabble
3
- * example programs for libsodium.
4
- */
5
-
6
- #include <sodium.h> /* library header */
7
-
8
- #include "utils.h" /* utility functions shared by examples */
9
-
10
- /*
11
- * Many applications and programming language implementations were
12
- * recently found to be vulnerable to denial-of-service attacks when
13
- * a hash function with weak security guarantees, such as Murmurhash
14
- * 3, was used to construct a hash table.
15
- *
16
- * In order to address this, Sodium provides the crypto_shorthash()
17
- * function, which outputs short but unpredictable (without knowing
18
- * the secret key) values suitable for picking a list in a hash table
19
- * for a given key.
20
- *
21
- * This function is optimized for short inputs.
22
- *
23
- * The output of this function is only 64 bits. Therefore, it should
24
- * not be considered collision-resistant.
25
- *
26
- * Use cases:
27
- *
28
- * - Hash tables
29
- * - Probabilistic data structures such as Bloom filters
30
- * - Integrity checking in interactive protocols
31
- */
32
- void
33
- shorthash(void)
34
- {
35
- unsigned char key[crypto_shorthash_KEYBYTES];
36
- unsigned char hash[crypto_shorthash_BYTES];
37
- unsigned char message[MAX_INPUT_LEN];
38
- size_t message_len;
39
-
40
- puts("Example: crypto_shorthash\n");
41
-
42
- prompt_input("a key", (char*)key, sizeof key, 0);
43
- message_len = prompt_input("a message", (char*)message, sizeof message, 1);
44
-
45
- printf("Hashing the message with %s\n", crypto_shorthash_primitive());
46
- crypto_shorthash(hash, message, message_len, key);
47
- printf("Hash: ");
48
- print_hex(hash, sizeof hash);
49
- }
50
-
51
- int
52
- main(void)
53
- {
54
- init();
55
- shorthash();
56
-
57
- return 0;
58
- }
@@ -1,78 +0,0 @@
1
- /*
2
- * GraxRabble
3
- * example programs for libsodium.
4
- */
5
-
6
- #include <sodium.h> /* library header */
7
-
8
- #include "utils.h" /* utility functions shared by examples */
9
-
10
- /*
11
- * Signs a message with secret key which will authenticate a message.
12
- * Everybody else can use the public key to ensure that the message is both
13
- * valid and untampered.
14
- *
15
- * Note that the signed message will have 16 bytes of signature prepended.
16
- * Ensure that the signed buffer is at least crypto_sign_BYTES longer then
17
- * the actual message.
18
- */
19
- static int
20
- sign(void)
21
- {
22
- unsigned char pk[crypto_sign_PUBLICKEYBYTES]; /* Bob's public key */
23
- unsigned char sk[crypto_sign_SECRETKEYBYTES]; /* Bob's secret key */
24
- unsigned char message[MAX_INPUT_LEN];
25
- unsigned char message_signed[crypto_sign_BYTES + MAX_INPUT_LEN];
26
- unsigned long long message_len;
27
- unsigned long long message_signed_len;
28
- int ret;
29
-
30
- puts("Example: crypto_sign\n");
31
-
32
- puts("Generating keypair...");
33
- crypto_sign_keypair(pk, sk); /* generate Bob's keys */
34
-
35
- printf("Public key: ");
36
- print_hex(pk, sizeof pk);
37
- printf("Secret key: ");
38
- print_hex(sk, sizeof sk);
39
- puts("The secret key, as returned by crypto_sign_keypair(), actually includes "
40
- "a copy of the public key, in order to avoid a scalar multiplication "
41
- "when signing messages.");
42
-
43
- message_len = prompt_input("a message", (char*)message, sizeof message, 1);
44
-
45
- printf("Signing message with %s...\n", crypto_sign_primitive());
46
- crypto_sign(message_signed, &message_signed_len, message, message_len, sk);
47
-
48
- sodium_memzero(sk, sizeof sk); /* wipe sensitive data */
49
-
50
- printf("Signed message:");
51
- print_hex(message_signed, message_signed_len);
52
- printf("A %u bytes signature was prepended to the message\n",
53
- crypto_sign_BYTES);
54
-
55
- printf("Signature: ");
56
- print_hex(message_signed, crypto_sign_BYTES);
57
- printf("Message: ");
58
- fwrite(message_signed + crypto_sign_BYTES, 1U,
59
- message_signed_len - crypto_sign_BYTES, stdout);
60
- putchar('\n');
61
-
62
- puts("Validating message...");
63
- ret = crypto_sign_open(message, &message_len, message_signed,
64
- message_signed_len, pk);
65
- print_verification(ret);
66
- if (ret == 0)
67
- printf("Message: %s\n", message);
68
-
69
- return ret;
70
- }
71
-
72
- int
73
- main(void)
74
- {
75
- init();
76
-
77
- return sign() != 0;
78
- }
@@ -1,110 +0,0 @@
1
- /*
2
- * Utility functions shared by all the demo programs.
3
- */
4
- #ifndef UTILS_H
5
- #define UTILS_H
6
-
7
- #include <limits.h>
8
- #include <stdio.h>
9
- #include <stdlib.h>
10
- #include <string.h>
11
-
12
- #include <sodium.h>
13
-
14
- #define MAX_INPUT_LEN 4096
15
-
16
- /*
17
- * print_hex() is a wrapper around sodium_bin2hex() which allocates
18
- * temporary memory then immediately prints the result followed by \n
19
- */
20
- static void
21
- print_hex(const void *bin, const size_t bin_len)
22
- {
23
- char *hex;
24
- size_t hex_size;
25
-
26
- if (bin_len >= SIZE_MAX / 2) {
27
- abort();
28
- }
29
- hex_size = bin_len * 2 + 1;
30
- if ((hex = malloc(hex_size)) == NULL) {
31
- abort();
32
- }
33
- /* the library supplies a few utility functions like the one below */
34
- if (sodium_bin2hex(hex, hex_size, bin, bin_len) == NULL) {
35
- abort();
36
- }
37
- puts(hex);
38
- free(hex);
39
- }
40
-
41
- /*
42
- * Display a prompt for input by user. It will save the input into a buffer
43
- * of a specific size with room for the null terminator while removing
44
- * trailing newline characters.
45
- */
46
- static size_t
47
- prompt_input(const char *prompt, char *input, const size_t max_input_len,
48
- int variable_length)
49
- {
50
- char input_tmp[MAX_INPUT_LEN + 1U];
51
- size_t actual_input_len;
52
-
53
- if (variable_length != 0) {
54
- printf("\nEnter %s (%zu bytes max) > ", prompt, max_input_len);
55
- } else {
56
- printf("\nEnter %s (%zu bytes) > ", prompt, max_input_len);
57
- }
58
- fflush(stdout);
59
- if (fgets(input_tmp, sizeof input_tmp, stdin) == NULL) {
60
- input_tmp[0] = '\0';
61
- }
62
- actual_input_len = strlen(input_tmp);
63
-
64
- /* trim \n */
65
- if (actual_input_len > 0 && input_tmp[actual_input_len - 1] == '\n') {
66
- input_tmp[actual_input_len - 1] = '\0';
67
- --actual_input_len;
68
- }
69
-
70
- if (actual_input_len > max_input_len) {
71
- printf("Warning: truncating input to %zu bytes\n\n", max_input_len);
72
- actual_input_len = max_input_len;
73
- } else if (actual_input_len < max_input_len && variable_length == 0) {
74
- printf("Warning: %zu bytes expected, %zu bytes given: padding with zeros\n\n",
75
- max_input_len, actual_input_len);
76
- memset(input, 0, max_input_len);
77
- } else {
78
- printf("Length: %zu bytes\n\n", actual_input_len);
79
- }
80
-
81
- memcpy(input, input_tmp, actual_input_len);
82
- if (variable_length == 0) {
83
- return max_input_len;
84
- } else {
85
- return actual_input_len;
86
- }
87
- }
88
-
89
- /*
90
- * Display whether the function was sucessful or failed.
91
- */
92
- static void
93
- print_verification(int ret)
94
- {
95
- if (ret == 0)
96
- puts("Success!\n");
97
- else
98
- puts("Failure.\n");
99
- }
100
-
101
- static void
102
- init(void)
103
- {
104
- if (sodium_init() != 0) {
105
- abort();
106
- }
107
- printf("Using libsodium %s\n", sodium_version_string());
108
- }
109
-
110
- #endif /* UTILS_H */