summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-08-23 08:50:32 -0400
committerNick Mathewson <nickm@torproject.org>2016-08-23 08:50:32 -0400
commita3d419634bef0bbac4118d08272d59c9fe66a1bb (patch)
tree4f5dcec8a4f6b8bff495f36db345ba80204cd264 /src/test
parentb3f43a22ab921ce6e256dd8f4e1cbedf2d280392 (diff)
parentb8bfdf638e9448ecda9dda1a2c02d7bbf4778341 (diff)
downloadtor-a3d419634bef0bbac4118d08272d59c9fe66a1bb.tar.gz
tor-a3d419634bef0bbac4118d08272d59c9fe66a1bb.zip
Merge remote-tracking branch 'asn/bug19872_v2'
Diffstat (limited to 'src/test')
-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:
;
}