Use meaningful variable names instead of having to comment them
This commit is contained in:
parent
67305902ee
commit
8920cde3a3
50
demos/auth.c
50
demos/auth.c
@ -18,46 +18,42 @@
|
|||||||
static int
|
static int
|
||||||
auth(void)
|
auth(void)
|
||||||
{
|
{
|
||||||
unsigned char k[crypto_auth_KEYBYTES]; /* key */
|
unsigned char key[crypto_auth_KEYBYTES];
|
||||||
unsigned char a[crypto_auth_BYTES]; /* authentication token */
|
unsigned char mac[crypto_auth_BYTES];
|
||||||
unsigned char m[MAX_INPUT_SIZE]; /* message */
|
unsigned char message[MAX_INPUT_SIZE];
|
||||||
size_t mlen; /* message length */
|
size_t message_len;
|
||||||
int r;
|
int ret;
|
||||||
|
|
||||||
puts("Example: crypto_auth\n");
|
puts("Example: crypto_auth\n");
|
||||||
|
|
||||||
/*
|
memset(key, 0, sizeof key);
|
||||||
* Keys are entered as ascii values. The key is zeroed to
|
prompt_input("Enter a key > ", (char*)key, sizeof key);
|
||||||
* maintain consistency. Input is read through a special
|
puts("Complete key:");
|
||||||
* function which reads exactly n bytes into a buffer to
|
print_hex(key, sizeof key);
|
||||||
* prevent buffer overflows.
|
|
||||||
*/
|
|
||||||
memset(k, 0, sizeof k);
|
|
||||||
prompt_input("Input your key > ", (char*)k, sizeof k);
|
|
||||||
puts("Your key that you entered");
|
|
||||||
print_hex(k, sizeof k);
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
mlen = prompt_input("Input your message > ", (char*)m, sizeof m);
|
message_len = prompt_input("Enter a message > ",
|
||||||
|
(char*)message, sizeof message);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
printf("Generating %s authentication...\n", crypto_auth_primitive());
|
printf("Generating %s authentication...\n", crypto_auth_primitive());
|
||||||
crypto_auth(a, m, mlen, k);
|
crypto_auth(mac, message, message_len, key);
|
||||||
|
|
||||||
puts("Format: authentication token::message");
|
puts("Format: authentication tag::message");
|
||||||
print_hex(a, sizeof a);
|
print_hex(mac, sizeof mac);
|
||||||
fputs("::", stdout);
|
fputs("::", stdout);
|
||||||
puts((const char*)m);
|
puts((const char*)message);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
puts("Verifying authentication...");
|
puts("Verifying authentication tag...");
|
||||||
r = crypto_auth_verify(a, m, mlen, k);
|
ret = crypto_auth_verify(mac, message, message_len, key);
|
||||||
print_verification(r);
|
print_verification(ret);
|
||||||
|
|
||||||
sodium_memzero(k, sizeof k); /* wipe sensitive data */
|
sodium_memzero(key, sizeof key); /* wipe sensitive data */
|
||||||
sodium_memzero(a, sizeof a);
|
sodium_memzero(mac, sizeof mac);
|
||||||
sodium_memzero(m, sizeof m);
|
sodium_memzero(message, sizeof message);
|
||||||
return r;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -70,9 +70,9 @@ void
|
|||||||
print_verification(int r)
|
print_verification(int r)
|
||||||
{
|
{
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
puts("Success\n");
|
puts("Success!\n");
|
||||||
else
|
else
|
||||||
puts("Failure\n");
|
puts("Failure.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user