commit e65e112: [Minor] Understand full ed25519 private keys

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Feb 27 15:00:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-27 14:47:29 +0000
URL: https://github.com/rspamd/rspamd/commit/e65e1123fcf918409bba94cf621fac172532769e

[Minor] Understand full ed25519 private keys

---
 src/libserver/dkim.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c
index 2a66146ed..129d78c9c 100644
--- a/src/libserver/dkim.c
+++ b/src/libserver/dkim.c
@@ -2681,13 +2681,25 @@ rspamd_dkim_sign_key_load (const gchar *key, gsize len,
 		key = tmp;
 	}
 
-	if (type == RSPAMD_DKIM_KEY_RAW && len == 32) {
-		unsigned char pk[32];
-		nkey->type = RSPAMD_DKIM_KEY_EDDSA;
-		nkey->key.key_eddsa = g_malloc (
-				rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519));
-		ed25519_seed_keypair (pk, nkey->key.key_eddsa, (char *)key);
-		nkey->keylen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+	if (type == RSPAMD_DKIM_KEY_RAW && (len == 32 ||
+		len == rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519))) {
+		if (len == 32) {
+			/* Seeded key, need scalarmult */
+			unsigned char pk[32];
+			nkey->type = RSPAMD_DKIM_KEY_EDDSA;
+			nkey->key.key_eddsa = g_malloc (
+					rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519));
+			ed25519_seed_keypair (pk, nkey->key.key_eddsa, (char *) key);
+			nkey->keylen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+		}
+		else {
+			/* Full ed25519 key */
+			unsigned klen = rspamd_cryptobox_sk_sig_bytes (RSPAMD_CRYPTOBOX_MODE_25519);
+			nkey->type = RSPAMD_DKIM_KEY_EDDSA;
+			nkey->key.key_eddsa = g_malloc (klen);
+			memcpy (nkey->key.key_eddsa, key, klen);
+			nkey->keylen = klen;
+		}
 	}
 	else {
 		nkey->key_bio = BIO_new_mem_buf (key, len);


More information about the Commits mailing list