mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-26 11:47:13 +09:00
patched all notied issues #192 except for crypto_box_afternm
This commit is contained in:
+3
-3
@@ -1,11 +1,11 @@
|
||||
auth
|
||||
box
|
||||
generhash
|
||||
generhashstream
|
||||
generichash
|
||||
generichashstream
|
||||
hash
|
||||
Makefile
|
||||
onetimeauth
|
||||
sretbox
|
||||
secretbox
|
||||
shorthash
|
||||
sign
|
||||
stream
|
||||
|
||||
+12
-2
@@ -27,11 +27,21 @@ auth(void)
|
||||
size_t mlen; /* message length */
|
||||
int r;
|
||||
|
||||
sodium_memzero(k, sizeof k); /* must zero the key */
|
||||
|
||||
puts("Example: crypto_auth\n");
|
||||
|
||||
|
||||
/*
|
||||
* Keys are entered as ascii values. The key is zeroed to
|
||||
* maintain consistency. Input is read through a special
|
||||
* function which reads exactly n bytes into a buffer to
|
||||
* prevent buffer overflows.
|
||||
*/
|
||||
sodium_memzero(k, sizeof k);
|
||||
prompt_input("Input your key > ", (char*) k, sizeof k);
|
||||
puts("Your key that you entered");
|
||||
print_hex(k, sizeof k);
|
||||
putchar('\n');
|
||||
|
||||
mlen = prompt_input("Input your message > ", (char*) m, sizeof m);
|
||||
putchar('\n');
|
||||
|
||||
|
||||
+3
-2
@@ -16,7 +16,8 @@
|
||||
* ================================================================== */
|
||||
|
||||
/*
|
||||
* Print hex.
|
||||
* Print hex is a wrapper around sodium_bin2hex which uses calloc
|
||||
* to allocate temporary memory then immediately printing the result.
|
||||
*/
|
||||
void
|
||||
print_hex(const void *buf, const size_t len)
|
||||
@@ -25,7 +26,7 @@ print_hex(const void *buf, const size_t len)
|
||||
char *p;
|
||||
|
||||
b = buf;
|
||||
p = malloc((len * 2 + 1) * (sizeof *b));
|
||||
p = calloc(len * 2 + 1, sizeof *b);
|
||||
|
||||
/* the library supplies a few utility functions like the one below */
|
||||
sodium_bin2hex(p, len * 2 + 1, b, len);
|
||||
|
||||
@@ -33,7 +33,18 @@ onetimeauth(void)
|
||||
|
||||
puts("Example: crypto_onetimeauth\n");
|
||||
|
||||
/*
|
||||
* Keys are entered as ascii values. The key is zeroed to
|
||||
* maintain consistency. Input is read through a special
|
||||
* function which reads exactly n bytes into a buffer to
|
||||
* prevent buffer overflows.
|
||||
*/
|
||||
sodium_memzero(k, sizeof k);
|
||||
prompt_input("Input your key > ", (char*) k, sizeof k);
|
||||
puts("Your key that you entered");
|
||||
print_hex(k, sizeof k);
|
||||
putchar('\n');
|
||||
|
||||
mlen = prompt_input("Input your message > ", (char*) m, sizeof m);
|
||||
putchar('\n');
|
||||
|
||||
|
||||
+11
-1
@@ -26,7 +26,7 @@ sign(void)
|
||||
{
|
||||
unsigned char pk[crypto_sign_PUBLICKEYBYTES]; /* Bob public */
|
||||
unsigned char sk[crypto_sign_SECRETKEYBYTES]; /* Bob secret */
|
||||
unsigned char m[BUFFER_SIZE + crypto_sign_BYTES]; /* message */
|
||||
unsigned char m[BUFFER_SIZE]; /* message */
|
||||
unsigned char sm[BUFFER_SIZE + crypto_sign_BYTES]; /* signed message */
|
||||
unsigned long long int mlen; /* message length */
|
||||
unsigned long long int smlen; /* signed length */
|
||||
@@ -48,10 +48,20 @@ sign(void)
|
||||
mlen = prompt_input("Input your message > ",
|
||||
(char*) m, sizeof m - crypto_sign_BYTES);
|
||||
putc('\n', stdout);
|
||||
|
||||
puts("Notice the message has no prepended padding");
|
||||
print_hex(m, mlen);
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
|
||||
printf("Signing message with %s...\n", crypto_sign_primitive());
|
||||
crypto_sign(sm, &smlen, m, mlen, sk);
|
||||
|
||||
puts("Notice the signed message has prepended signature");
|
||||
print_hex(sm, smlen);
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
|
||||
puts("Format: signature::message");
|
||||
fputs("Signed: ", stdout);
|
||||
print_hex(sm, crypto_sign_BYTES);
|
||||
|
||||
Reference in New Issue
Block a user