aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_crypto.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2016-08-23 14:53:01 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2016-08-23 14:53:01 +0300
commitb8bfdf638e9448ecda9dda1a2c02d7bbf4778341 (patch)
tree7f169f62b8a272a68fb3b326010f81193cef90b9 /src/test/test_crypto.c
parent261f4c3f6f028cf4becff1077c08735e308d7d43 (diff)
downloadtor-b8bfdf638e9448ecda9dda1a2c02d7bbf4778341.tar.gz
tor-b8bfdf638e9448ecda9dda1a2c02d7bbf4778341.zip
Introduce ed25519_{sign,checksig}_prefixed functions().
Diffstat (limited to 'src/test/test_crypto.c')
-rw-r--r--src/test/test_crypto.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index ba2fb86246..542512bd44 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -2242,6 +2242,41 @@ test_crypto_ed25519_simple(void *arg)
tt_int_op(0, OP_EQ, ed25519_checksig_batch(NULL, ch, 2));
}
+ /* Test the string-prefixed sign/checksig functions */
+ {
+ ed25519_signature_t manual_sig;
+ char *prefixed_msg;
+
+ /* Generate a signature with a prefixed msg. */
+ tt_int_op(0, OP_EQ, ed25519_sign_prefixed(&sig1, msg, msg_len,
+ "always in the mood",
+ &kp1));
+
+ /* First, check that ed25519_sign_prefixed() returns the exact same sig as
+ if we had manually prefixed the msg ourselves. */
+ tor_asprintf(&prefixed_msg, "%s%s", "always in the mood", msg);
+ tt_int_op(0, OP_EQ, ed25519_sign(&manual_sig, (uint8_t *)prefixed_msg,
+ strlen(prefixed_msg), &kp1));
+ tor_free(prefixed_msg);
+ tt_assert(!memcmp(sig1.sig, manual_sig.sig, sizeof(sig1.sig)));
+
+ /* Test that prefixed checksig verifies it properly. */
+ tt_int_op(0, OP_EQ, ed25519_checksig_prefixed(&sig1, msg, msg_len,
+ "always in the mood",
+ &pub1));
+
+ /* Test that checksig with wrong prefix fails. */
+ tt_int_op(-1, OP_EQ, ed25519_checksig_prefixed(&sig1, msg, msg_len,
+ "always in the moo",
+ &pub1));
+ tt_int_op(-1, OP_EQ, ed25519_checksig_prefixed(&sig1, msg, msg_len,
+ "always in the moon",
+ &pub1));
+ tt_int_op(-1, OP_EQ, ed25519_checksig_prefixed(&sig1, msg, msg_len,
+ "always in the mood!",
+ &pub1));
+ }
+
done:
;
}