Make crypto_sign() test code more explicit.

crypto_sign() doesn't just need the secret key. The public key has to follow.
Which is why the test vectors are laid out in this order.
But this can confuse static analysis, as well as people looking at the test
in order to better understand how crypto_sign() works.
So, just copy the sk and the pk into a dedicated buffer, for clarity.
This commit is contained in:
Frank Denis
2014-06-09 19:27:49 -07:00
parent 8560366cd8
commit 06e089ef6a
+6 -2
View File
@@ -1054,6 +1054,8 @@ int main(void)
{
unsigned char sm[1024 + crypto_sign_BYTES];
unsigned char m[1024];
unsigned char skpk[crypto_sign_SECRETKEYBYTES +
crypto_sign_PUBLICKEYBYTES];
unsigned char pk[crypto_sign_PUBLICKEYBYTES];
unsigned char sk[crypto_sign_SECRETKEYBYTES];
char pk_hex[crypto_sign_PUBLICKEYBYTES * 2 + 1];
@@ -1063,9 +1065,11 @@ int main(void)
unsigned int i;
for (i = 0U; i < (sizeof test_data) / (sizeof test_data[0]); i++) {
memcpy(skpk, test_data[i].sk, crypto_sign_SECRETKEYBYTES_WITHOUT_PK);
memcpy(skpk + crypto_sign_SECRETKEYBYTES_WITHOUT_PK,
test_data[i].pk, crypto_sign_PUBLICKEYBYTES);
if (crypto_sign(sm, &smlen,
(const unsigned char *) test_data[i].m, i,
test_data[i].sk) != 0) {
(const unsigned char *) test_data[i].m, i, skpk) != 0) {
printf("crypto_sign() failure: [%u]\n", i);
continue;
}