aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox/curve25519/curve25519.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-12 16:18:22 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-12 16:18:22 +0100
commit395cb950190b94ea6565cbf7cfeb65d05de75209 (patch)
tree5158ac507e90cd7d697b7fd83b71373de91d6e0c /src/libcryptobox/curve25519/curve25519.c
parentd73986b308e2385201c02ca197260d1adc481f03 (diff)
downloadrspamd-395cb950190b94ea6565cbf7cfeb65d05de75209.tar.gz
rspamd-395cb950190b94ea6565cbf7cfeb65d05de75209.zip
Add testing for curve25519 ECDH.
Diffstat (limited to 'src/libcryptobox/curve25519/curve25519.c')
-rw-r--r--src/libcryptobox/curve25519/curve25519.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/libcryptobox/curve25519/curve25519.c b/src/libcryptobox/curve25519/curve25519.c
index 1870d4987..df795a855 100644
--- a/src/libcryptobox/curve25519/curve25519.c
+++ b/src/libcryptobox/curve25519/curve25519.c
@@ -53,6 +53,9 @@ CURVE25519_DECLARE(avx);
#endif
+CURVE25519_DECLARE(ref);
+#define CURVE25519_REF CURVE25519_IMPL(0, "ref", ref)
+
#if !defined(__LP64__)
CURVE25519_DECLARE(donna32);
#define CURVE25519_GENERIC CURVE25519_IMPL(0, "donna32", donna32)
@@ -68,8 +71,52 @@ static const curve25519_impl_t curve25519_list[] = {
#endif
};
+const guchar secA[] = {0x5A, 0xC9, 0x9F, 0x33, 0x63, 0x2E, 0x5A, 0x76, 0x8D,
+ 0xE7, 0xE8, 0x1B, 0xF8, 0x54, 0xC2, 0x7C, 0x46, 0xE3,
+ 0xFB, 0xF2, 0xAB, 0xBA, 0xCD, 0x29, 0xEC, 0x4A, 0xFF,
+ 0x51, 0x73, 0x69, 0xC6, 0x60};
+const guchar secB[] = {0x47, 0xDC, 0x3D, 0x21, 0x41, 0x74, 0x82, 0x0E, 0x11,
+ 0x54, 0xB4, 0x9B, 0xC6, 0xCD, 0xB2, 0xAB, 0xD4, 0x5E,
+ 0xE9, 0x58, 0x17, 0x05, 0x5D, 0x25, 0x5A, 0xA3, 0x58,
+ 0x31, 0xB7, 0x0D, 0x32, 0x60};
+
static const curve25519_impl_t *curve25519_opt = &curve25519_list[0];
+static gboolean
+curve25519_test_impl (const curve25519_impl_t *impl)
+{
+ guchar sec_local[32], sec_ref[32],
+ pubA[32], pubB[32];
+
+ curve25519_impl_t ref_impl = CURVE25519_REF;
+
+ ref_impl.scalarmult (pubA, secA, curve25519_basepoint);
+ ref_impl.scalarmult (pubB, secB, curve25519_basepoint);
+
+ impl->scalarmult (sec_local, secA, pubB);
+ ref_impl.scalarmult (sec_ref, secA, pubB);
+
+ if (memcmp (sec_local, sec_ref, sizeof (sec_ref)) != 0) {
+ return FALSE;
+ }
+
+ impl->scalarmult (sec_local, secB, pubA);
+ ref_impl.scalarmult (sec_ref, secB, pubA);
+
+ if (memcmp (sec_local, sec_ref, sizeof (sec_ref)) != 0) {
+ return FALSE;
+ }
+
+ impl->scalarmult (sec_local, secB, pubA);
+ impl->scalarmult (sec_ref, secA, pubB);
+
+ if (memcmp (sec_local, sec_ref, sizeof (sec_ref)) != 0) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
void
curve25519_load (void)
{
@@ -83,6 +130,7 @@ curve25519_load (void)
}
}
}
+ g_assert (curve25519_test_impl (curve25519_opt));
}
int