mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-27 20:27:12 +09:00
fputs(..., stdout) -> printf()
This reduces the number of functions we use to print something from 5 to 4 (!).
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ auth(void)
|
||||
printf("Generating %s authentication...\n", crypto_auth_primitive());
|
||||
crypto_auth(mac, message, message_len, key);
|
||||
|
||||
fputs("Authentication tag: ", stdout);
|
||||
printf("Authentication tag: ");
|
||||
print_hex(mac, sizeof mac);
|
||||
|
||||
puts("Verifying authentication tag...");
|
||||
|
||||
+7
-7
@@ -70,21 +70,21 @@ box(void)
|
||||
crypto_box_keypair(alice_pk, alice_sk); /* generate Alice's keys */
|
||||
|
||||
puts("Bob");
|
||||
fputs("Public key: ", stdout);
|
||||
printf("Public key: ");
|
||||
print_hex(bob_pk, sizeof bob_pk);
|
||||
fputs("Secret key: ", stdout);
|
||||
printf("Secret key: ");
|
||||
print_hex(bob_sk, sizeof bob_sk);
|
||||
|
||||
puts("Alice");
|
||||
fputs("Public key: ", stdout);
|
||||
printf("Public key: ");
|
||||
print_hex(alice_pk, sizeof alice_pk);
|
||||
fputs("Secret key: ", stdout);
|
||||
printf("Secret key: ");
|
||||
print_hex(alice_sk, sizeof alice_sk);
|
||||
|
||||
/* nonce must be unique per (key, message) - it can be public and deterministic */
|
||||
puts("Generating nonce...");
|
||||
randombytes_buf(nonce, sizeof nonce);
|
||||
fputs("Nonce: ", stdout);
|
||||
printf("Nonce: ");
|
||||
print_hex(nonce, sizeof nonce);
|
||||
|
||||
/* read input */
|
||||
@@ -102,9 +102,9 @@ box(void)
|
||||
printf("Ciphertext len: %zu bytes - Original message length: %zu bytes\n",
|
||||
ciphertext_len, message_len);
|
||||
puts("Notice the prepended 16 byte authentication token\n");
|
||||
fputs("Nonce: ", stdout);
|
||||
printf("Nonce: ");
|
||||
print_hex(nonce, nonce_len);
|
||||
fputs("Ciphertext: ", stdout);
|
||||
printf("Ciphertext: ");
|
||||
print_hex(ciphertext, ciphertext_len);
|
||||
|
||||
/* decrypt the message */
|
||||
|
||||
@@ -70,21 +70,21 @@ box_detached(void)
|
||||
crypto_box_keypair(alice_pk, alice_sk); /* generate Alice's keys */
|
||||
|
||||
puts("Bob");
|
||||
fputs("Public key: ", stdout);
|
||||
printf("Public key: ");
|
||||
print_hex(bob_pk, sizeof bob_pk);
|
||||
fputs("Secret key: ", stdout);
|
||||
printf("Secret key: ");
|
||||
print_hex(bob_sk, sizeof bob_sk);
|
||||
|
||||
puts("Alice");
|
||||
fputs("Public key: ", stdout);
|
||||
printf("Public key: ");
|
||||
print_hex(alice_pk, sizeof alice_pk);
|
||||
fputs("Secret key: ", stdout);
|
||||
printf("Secret key: ");
|
||||
print_hex(alice_sk, sizeof alice_sk);
|
||||
|
||||
/* nonce must be unique per (key, message) - it can be public and deterministic */
|
||||
puts("Generating nonce...");
|
||||
randombytes_buf(nonce, sizeof nonce);
|
||||
fputs("Nonce: ", stdout);
|
||||
printf("Nonce: ");
|
||||
print_hex(nonce, sizeof nonce);
|
||||
|
||||
/* read input */
|
||||
@@ -99,11 +99,11 @@ box_detached(void)
|
||||
|
||||
/* send the nonce, the MAC and the ciphertext */
|
||||
puts("Bob sends the nonce, the MAC and the ciphertext...\n");
|
||||
fputs("Nonce: ", stdout);
|
||||
printf("Nonce: ");
|
||||
print_hex(nonce, sizeof nonce);
|
||||
fputs("MAC: ", stdout);
|
||||
printf("MAC: ");
|
||||
print_hex(mac, sizeof mac);
|
||||
fputs("Ciphertext: ", stdout);
|
||||
printf("Ciphertext: ");
|
||||
print_hex(ciphertext, message_len);
|
||||
|
||||
/* decrypt the message */
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ generichash(void)
|
||||
key, key_len) != 0) {
|
||||
puts("Couldn't hash the message, probably due to the key length");
|
||||
} else {
|
||||
fputs("Hash: ", stdout);
|
||||
printf("Hash: ");
|
||||
print_hex(hash, sizeof hash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ generichash_stream(void)
|
||||
}
|
||||
crypto_generichash_final(&state, hash, sizeof hash);
|
||||
|
||||
fputs("Hash: ", stdout);
|
||||
printf("Hash: ");
|
||||
print_hex(hash, sizeof hash);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ shorthash(void)
|
||||
|
||||
printf("Hashing the message with %s\n", crypto_shorthash_primitive());
|
||||
crypto_shorthash(hash, message, message_len, key);
|
||||
fputs("Hash: ", stdout);
|
||||
printf("Hash: ");
|
||||
print_hex(hash, sizeof hash);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -35,9 +35,9 @@ sign(void)
|
||||
puts("Generating keypair...");
|
||||
crypto_sign_keypair(pk, sk); /* generate Bob's keys */
|
||||
|
||||
fputs("Public key: ", stdout);
|
||||
printf("Public key: ");
|
||||
print_hex(pk, sizeof pk);
|
||||
fputs("Secret key: ", stdout);
|
||||
printf("Secret key: ");
|
||||
print_hex(sk, sizeof sk);
|
||||
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 "
|
||||
@@ -53,9 +53,9 @@ sign(void)
|
||||
printf("A %u bytes signature was prepended to the message\n",
|
||||
crypto_sign_BYTES);
|
||||
|
||||
fputs("Signature: ", stdout);
|
||||
printf("Signature: ");
|
||||
print_hex(message_signed, crypto_sign_BYTES);
|
||||
fputs("Message: ", stdout);
|
||||
printf("Message: ");
|
||||
fwrite(message_signed + crypto_sign_BYTES, 1U,
|
||||
message_signed_len - crypto_sign_BYTES, stdout);
|
||||
putchar('\n');
|
||||
|
||||
Reference in New Issue
Block a user