diff --git a/demos/auth.c b/demos/auth.c index 6b1dd438..6accf7d6 100644 --- a/demos/auth.c +++ b/demos/auth.c @@ -52,7 +52,6 @@ auth(void) fputs("Authentication tag: ", stdout); print_hex(mac, sizeof mac); - putchar('\n'); puts("Verifying authentication tag..."); ret = crypto_auth_verify(mac, message, message_len, key); diff --git a/demos/box.c b/demos/box.c index 7f44deeb..79dc3144 100644 --- a/demos/box.c +++ b/demos/box.c @@ -72,31 +72,25 @@ box(void) puts("Bob"); fputs("Public key: ", stdout); print_hex(bob_pk, sizeof bob_pk); - putchar('\n'); fputs("Secret key: ", stdout); print_hex(bob_sk, sizeof bob_sk); - putchar('\n'); puts("Alice"); fputs("Public key: ", stdout); print_hex(alice_pk, sizeof alice_pk); - putchar('\n'); fputs("Secret key: ", stdout); print_hex(alice_sk, sizeof alice_sk); - putchar('\n'); /* nonce must be unique per (key, message) - it can be public and deterministic */ puts("Generating nonce..."); randombytes_buf(nonce, sizeof nonce); fputs("Nonce: ", stdout); print_hex(nonce, sizeof nonce); - putchar('\n'); /* read input */ message_len = prompt_input("a message", (char*)message, sizeof message, 1); print_hex(message, message_len); - putchar('\n'); /* encrypt and authenticate the message */ printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive()); @@ -110,17 +104,14 @@ box(void) puts("Notice the prepended 16 byte authentication token\n"); fputs("Nonce: ", stdout); print_hex(nonce, nonce_len); - putchar('\n'); fputs("Ciphertext: ", stdout); print_hex(ciphertext, ciphertext_len); - putchar('\n'); /* decrypt the message */ puts("Alice verifies and decrypts the ciphertext..."); ret = crypto_box_open_easy(message, ciphertext, ciphertext_len, nonce, bob_pk, alice_sk); print_hex(message, message_len); - putchar('\n'); print_verification(ret); if (ret == 0) { diff --git a/demos/box_detached.c b/demos/box_detached.c index 714ce1e8..80478b4a 100644 --- a/demos/box_detached.c +++ b/demos/box_detached.c @@ -72,31 +72,25 @@ box_detached(void) puts("Bob"); fputs("Public key: ", stdout); print_hex(bob_pk, sizeof bob_pk); - putchar('\n'); fputs("Secret key: ", stdout); print_hex(bob_sk, sizeof bob_sk); - putchar('\n'); puts("Alice"); fputs("Public key: ", stdout); print_hex(alice_pk, sizeof alice_pk); - putchar('\n'); fputs("Secret key: ", stdout); print_hex(alice_sk, sizeof alice_sk); - putchar('\n'); /* nonce must be unique per (key, message) - it can be public and deterministic */ puts("Generating nonce..."); randombytes_buf(nonce, sizeof nonce); fputs("Nonce: ", stdout); print_hex(nonce, sizeof nonce); - putchar('\n'); /* read input */ message_len = prompt_input("a message", (char*)message, sizeof message, 1); print_hex(message, message_len); - putchar('\n'); /* encrypt and authenticate the message */ printf("Encrypting and authenticating with %s\n\n", crypto_box_primitive()); @@ -107,20 +101,16 @@ box_detached(void) puts("Bob sends the nonce, the MAC and the ciphertext...\n"); fputs("Nonce: ", stdout); print_hex(nonce, sizeof nonce); - putchar('\n'); fputs("MAC: ", stdout); print_hex(mac, sizeof mac); - putchar('\n'); fputs("Ciphertext: ", stdout); print_hex(ciphertext, message_len); - putchar('\n'); /* decrypt the message */ puts("Alice verifies the MAC and decrypts the ciphertext..."); ret = crypto_box_open_detached(message, ciphertext, mac, message_len, nonce, bob_pk, alice_sk); print_hex(message, message_len); - putchar('\n'); print_verification(ret); if (ret == 0) { diff --git a/demos/generichash.c b/demos/generichash.c index d994e5bb..064a3c53 100644 --- a/demos/generichash.c +++ b/demos/generichash.c @@ -71,7 +71,6 @@ generichash(void) fputs("Hash: ", stdout); print_hex(hash, sizeof hash); } - putchar('\n'); } int diff --git a/demos/generichash_stream.c b/demos/generichash_stream.c index 5b1a3635..67d46df3 100644 --- a/demos/generichash_stream.c +++ b/demos/generichash_stream.c @@ -49,7 +49,6 @@ generichash_stream(void) fputs("Hash: ", stdout); print_hex(hash, sizeof hash); - putchar('\n'); } int diff --git a/demos/shorthash.c b/demos/shorthash.c index 44a9f05c..6aac468c 100644 --- a/demos/shorthash.c +++ b/demos/shorthash.c @@ -49,7 +49,6 @@ shorthash(void) crypto_shorthash(hash, message, message_len, key); fputs("Hash: ", stdout); print_hex(hash, sizeof hash); - putchar('\n'); } int diff --git a/demos/sign.c b/demos/sign.c index f0aa8996..2cbb97f5 100644 --- a/demos/sign.c +++ b/demos/sign.c @@ -37,10 +37,8 @@ sign(void) fputs("Public key: ", stdout); print_hex(pk, sizeof pk); - putchar('\n'); fputs("Secret key: ", stdout); print_hex(sk, sizeof sk); - putchar('\n'); puts("The secret key, as returned by crypto_sign_keypair(), actually includes " "a copy of the public key, in order to avoid a scalar multiplication " "when signing messages."); @@ -52,13 +50,11 @@ sign(void) printf("Signed message:"); print_hex(message_signed, message_signed_len); - putchar('\n'); printf("A %u bytes signature was prepended to the message\n", crypto_sign_BYTES); fputs("Signature: ", stdout); print_hex(message_signed, crypto_sign_BYTES); - putchar('\n'); fputs("Message: ", stdout); fwrite(message_signed + crypto_sign_BYTES, 1U, message_signed_len - crypto_sign_BYTES, stdout); diff --git a/demos/utils.c b/demos/utils.c index 413a74f6..0542aef8 100644 --- a/demos/utils.c +++ b/demos/utils.c @@ -12,7 +12,7 @@ /* * print_hex() is a wrapper around sodium_bin2hex() which allocates - * temporary memory then immediately prints the result. + * temporary memory then immediately prints the result followed by \n */ void print_hex(const void *bin, const size_t bin_len) @@ -31,7 +31,7 @@ print_hex(const void *bin, const size_t bin_len) if (sodium_bin2hex(hex, hex_size, bin, bin_len) == NULL) { abort(); } - fputs(hex, stdout); + puts(hex); free(hex); }