putc('\n', stdout) or putchar('\n') - pick one

And remove duplicate putchar('\n') to improve code clarity
This commit is contained in:
Frank Denis 2015-05-27 20:27:07 +02:00
parent 071c467ff3
commit b1bcecf086
3 changed files with 4 additions and 16 deletions

View File

@ -76,7 +76,6 @@ box(void)
fputs("Secret key: ", stdout); fputs("Secret key: ", stdout);
print_hex(bob_sk, sizeof bob_sk); print_hex(bob_sk, sizeof bob_sk);
putchar('\n'); putchar('\n');
putchar('\n');
puts("Alice"); puts("Alice");
fputs("Public key: ", stdout); fputs("Public key: ", stdout);
@ -85,7 +84,6 @@ box(void)
fputs("Secret key: ", stdout); fputs("Secret key: ", stdout);
print_hex(alice_sk, sizeof alice_sk); print_hex(alice_sk, sizeof alice_sk);
putchar('\n'); putchar('\n');
putchar('\n');
/* nonce must be unique per (key, message) - it can be public and deterministic */ /* nonce must be unique per (key, message) - it can be public and deterministic */
puts("Generating nonce..."); puts("Generating nonce...");
@ -93,14 +91,12 @@ box(void)
fputs("Nonce: ", stdout); fputs("Nonce: ", stdout);
print_hex(nonce, sizeof nonce); print_hex(nonce, sizeof nonce);
putchar('\n'); putchar('\n');
putchar('\n');
/* read input */ /* read input */
message_len = prompt_input("a message", (char*)message, sizeof message, 1); message_len = prompt_input("a message", (char*)message, sizeof message, 1);
print_hex(message, message_len); print_hex(message, message_len);
putchar('\n'); putchar('\n');
putchar('\n');
/* encrypt and authenticate the message */ /* encrypt and authenticate the message */
printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive()); printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive());
@ -118,7 +114,6 @@ box(void)
fputs("Ciphertext: ", stdout); fputs("Ciphertext: ", stdout);
print_hex(ciphertext, ciphertext_len); print_hex(ciphertext, ciphertext_len);
putchar('\n'); putchar('\n');
putchar('\n');
/* decrypt the message */ /* decrypt the message */
puts("Alice verifies and decrypts the ciphertext..."); puts("Alice verifies and decrypts the ciphertext...");

View File

@ -76,7 +76,6 @@ box_detached(void)
fputs("Secret key: ", stdout); fputs("Secret key: ", stdout);
print_hex(bob_sk, sizeof bob_sk); print_hex(bob_sk, sizeof bob_sk);
putchar('\n'); putchar('\n');
putchar('\n');
puts("Alice"); puts("Alice");
fputs("Public key: ", stdout); fputs("Public key: ", stdout);
@ -85,7 +84,6 @@ box_detached(void)
fputs("Secret key: ", stdout); fputs("Secret key: ", stdout);
print_hex(alice_sk, sizeof alice_sk); print_hex(alice_sk, sizeof alice_sk);
putchar('\n'); putchar('\n');
putchar('\n');
/* nonce must be unique per (key, message) - it can be public and deterministic */ /* nonce must be unique per (key, message) - it can be public and deterministic */
puts("Generating nonce..."); puts("Generating nonce...");
@ -93,14 +91,12 @@ box_detached(void)
fputs("Nonce: ", stdout); fputs("Nonce: ", stdout);
print_hex(nonce, sizeof nonce); print_hex(nonce, sizeof nonce);
putchar('\n'); putchar('\n');
putchar('\n');
/* read input */ /* read input */
message_len = prompt_input("a message", (char*)message, sizeof message, 1); message_len = prompt_input("a message", (char*)message, sizeof message, 1);
print_hex(message, message_len); print_hex(message, message_len);
putchar('\n'); putchar('\n');
putchar('\n');
/* encrypt and authenticate the message */ /* encrypt and authenticate the message */
printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive()); printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive());
@ -118,7 +114,6 @@ box_detached(void)
fputs("Ciphertext: ", stdout); fputs("Ciphertext: ", stdout);
print_hex(ciphertext, message_len); print_hex(ciphertext, message_len);
putchar('\n'); putchar('\n');
putchar('\n');
/* decrypt the message */ /* decrypt the message */
puts("Alice verifies the MAC and decrypts the ciphertext..."); puts("Alice verifies the MAC and decrypts the ciphertext...");

View File

@ -37,19 +37,17 @@ sign(void)
fputs("Public: ", stdout); fputs("Public: ", stdout);
print_hex(pk, sizeof pk); print_hex(pk, sizeof pk);
putc('\n', stdout); putchar('\n');
fputs("Secret: ", stdout); fputs("Secret: ", stdout);
print_hex(sk, sizeof sk); print_hex(sk, sizeof sk);
puts("\n"); putchar('\n');
/* read input */
mlen = prompt_input("a message", (char*)m, sizeof m, 1); mlen = prompt_input("a message", (char*)m, sizeof m, 1);
putchar('\n'); putchar('\n');
puts("Notice the message has no prepended padding"); puts("Notice the message has no prepended padding");
print_hex(m, mlen); print_hex(m, mlen);
putchar('\n'); putchar('\n');
putchar('\n');
printf("Signing message with %s...\n", crypto_sign_primitive()); printf("Signing message with %s...\n", crypto_sign_primitive());
crypto_sign(sm, &smlen, m, mlen, sk); crypto_sign(sm, &smlen, m, mlen, sk);
@ -57,7 +55,6 @@ sign(void)
puts("Notice the signed message has prepended signature"); puts("Notice the signed message has prepended signature");
print_hex(sm, smlen); print_hex(sm, smlen);
putchar('\n'); putchar('\n');
putchar('\n');
fputs("Signature: ", stdout); fputs("Signature: ", stdout);
print_hex(sm, crypto_sign_BYTES); print_hex(sm, crypto_sign_BYTES);
@ -71,11 +68,12 @@ sign(void)
print_verification(r); print_verification(r);
if (r == 0) if (r == 0)
printf("Message: %s\n\n", m); printf("Message: %s\n", m);
sodium_memzero(sk, sizeof sk); /* wipe sensitive data */ sodium_memzero(sk, sizeof sk); /* wipe sensitive data */
sodium_memzero(m, sizeof m); sodium_memzero(m, sizeof m);
sodium_memzero(sm, sizeof sm); sodium_memzero(sm, sizeof sm);
return r; return r;
} }