summaryrefslogtreecommitdiff
path: root/key.c
diff options
context:
space:
mode:
Diffstat (limited to 'key.c')
-rw-r--r--key.c193
1 files changed, 169 insertions, 24 deletions
diff --git a/key.c b/key.c
index c09f43f19..236e02676 100644
--- a/key.c
+++ b/key.c
@@ -39,6 +39,8 @@
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/types.h> 40#include <sys/types.h>
41 41
42#include "crypto_api.h"
43
42#include <openssl/evp.h> 44#include <openssl/evp.h>
43#include <openbsd-compat/openssl-compat.h> 45#include <openbsd-compat/openssl-compat.h>
44 46
@@ -86,6 +88,8 @@ key_new(int type)
86 k->dsa = NULL; 88 k->dsa = NULL;
87 k->rsa = NULL; 89 k->rsa = NULL;
88 k->cert = NULL; 90 k->cert = NULL;
91 k->ed25519_sk = NULL;
92 k->ed25519_pk = NULL;
89 switch (k->type) { 93 switch (k->type) {
90 case KEY_RSA1: 94 case KEY_RSA1:
91 case KEY_RSA: 95 case KEY_RSA:
@@ -120,6 +124,10 @@ key_new(int type)
120 /* Cannot do anything until we know the group */ 124 /* Cannot do anything until we know the group */
121 break; 125 break;
122#endif 126#endif
127 case KEY_ED25519:
128 case KEY_ED25519_CERT:
129 /* no need to prealloc */
130 break;
123 case KEY_UNSPEC: 131 case KEY_UNSPEC:
124 break; 132 break;
125 default: 133 default:
@@ -164,6 +172,10 @@ key_add_private(Key *k)
164 case KEY_ECDSA_CERT: 172 case KEY_ECDSA_CERT:
165 /* Cannot do anything until we know the group */ 173 /* Cannot do anything until we know the group */
166 break; 174 break;
175 case KEY_ED25519:
176 case KEY_ED25519_CERT:
177 /* no need to prealloc */
178 break;
167 case KEY_UNSPEC: 179 case KEY_UNSPEC:
168 break; 180 break;
169 default: 181 default:
@@ -226,6 +238,19 @@ key_free(Key *k)
226 k->ecdsa = NULL; 238 k->ecdsa = NULL;
227 break; 239 break;
228#endif 240#endif
241 case KEY_ED25519:
242 case KEY_ED25519_CERT:
243 if (k->ed25519_pk) {
244 memset(k->ed25519_pk, 0, ED25519_PK_SZ);
245 free(k->ed25519_pk);
246 k->ed25519_pk = NULL;
247 }
248 if (k->ed25519_sk) {
249 memset(k->ed25519_sk, 0, ED25519_SK_SZ);
250 free(k->ed25519_sk);
251 k->ed25519_sk = NULL;
252 }
253 break;
229 case KEY_UNSPEC: 254 case KEY_UNSPEC:
230 break; 255 break;
231 default: 256 default:
@@ -307,6 +332,10 @@ key_equal_public(const Key *a, const Key *b)
307 BN_CTX_free(bnctx); 332 BN_CTX_free(bnctx);
308 return 1; 333 return 1;
309#endif /* OPENSSL_HAS_ECC */ 334#endif /* OPENSSL_HAS_ECC */
335 case KEY_ED25519:
336 case KEY_ED25519_CERT:
337 return a->ed25519_pk != NULL && b->ed25519_pk != NULL &&
338 memcmp(a->ed25519_pk, b->ed25519_pk, ED25519_PK_SZ) == 0;
310 default: 339 default:
311 fatal("key_equal: bad key type %d", a->type); 340 fatal("key_equal: bad key type %d", a->type);
312 } 341 }
@@ -366,6 +395,7 @@ key_fingerprint_raw(const Key *k, enum fp_type dgst_type,
366 case KEY_DSA: 395 case KEY_DSA:
367 case KEY_ECDSA: 396 case KEY_ECDSA:
368 case KEY_RSA: 397 case KEY_RSA:
398 case KEY_ED25519:
369 key_to_blob(k, &blob, &len); 399 key_to_blob(k, &blob, &len);
370 break; 400 break;
371 case KEY_DSA_CERT_V00: 401 case KEY_DSA_CERT_V00:
@@ -373,6 +403,7 @@ key_fingerprint_raw(const Key *k, enum fp_type dgst_type,
373 case KEY_DSA_CERT: 403 case KEY_DSA_CERT:
374 case KEY_ECDSA_CERT: 404 case KEY_ECDSA_CERT:
375 case KEY_RSA_CERT: 405 case KEY_RSA_CERT:
406 case KEY_ED25519_CERT:
376 /* We want a fingerprint of the _key_ not of the cert */ 407 /* We want a fingerprint of the _key_ not of the cert */
377 to_blob(k, &blob, &len, 1); 408 to_blob(k, &blob, &len, 1);
378 break; 409 break;
@@ -699,11 +730,13 @@ key_read(Key *ret, char **cpp)
699 case KEY_RSA: 730 case KEY_RSA:
700 case KEY_DSA: 731 case KEY_DSA:
701 case KEY_ECDSA: 732 case KEY_ECDSA:
733 case KEY_ED25519:
702 case KEY_DSA_CERT_V00: 734 case KEY_DSA_CERT_V00:
703 case KEY_RSA_CERT_V00: 735 case KEY_RSA_CERT_V00:
704 case KEY_DSA_CERT: 736 case KEY_DSA_CERT:
705 case KEY_ECDSA_CERT: 737 case KEY_ECDSA_CERT:
706 case KEY_RSA_CERT: 738 case KEY_RSA_CERT:
739 case KEY_ED25519_CERT:
707 space = strchr(cp, ' '); 740 space = strchr(cp, ' ');
708 if (space == NULL) { 741 if (space == NULL) {
709 debug3("key_read: missing whitespace"); 742 debug3("key_read: missing whitespace");
@@ -805,6 +838,14 @@ key_read(Key *ret, char **cpp)
805#endif 838#endif
806 } 839 }
807#endif 840#endif
841 if (key_type_plain(ret->type) == KEY_ED25519) {
842 free(ret->ed25519_pk);
843 ret->ed25519_pk = k->ed25519_pk;
844 k->ed25519_pk = NULL;
845#ifdef DEBUG_PK
846 /* XXX */
847#endif
848 }
808 success = 1; 849 success = 1;
809/*XXXX*/ 850/*XXXX*/
810 key_free(k); 851 key_free(k);
@@ -868,6 +909,11 @@ key_write(const Key *key, FILE *f)
868 return 0; 909 return 0;
869 break; 910 break;
870#endif 911#endif
912 case KEY_ED25519:
913 case KEY_ED25519_CERT:
914 if (key->ed25519_pk == NULL)
915 return 0;
916 break;
871 case KEY_RSA: 917 case KEY_RSA:
872 case KEY_RSA_CERT_V00: 918 case KEY_RSA_CERT_V00:
873 case KEY_RSA_CERT: 919 case KEY_RSA_CERT:
@@ -915,6 +961,7 @@ static const struct keytype keytypes[] = {
915 { NULL, "RSA1", KEY_RSA1, 0, 0 }, 961 { NULL, "RSA1", KEY_RSA1, 0, 0 },
916 { "ssh-rsa", "RSA", KEY_RSA, 0, 0 }, 962 { "ssh-rsa", "RSA", KEY_RSA, 0, 0 },
917 { "ssh-dss", "DSA", KEY_DSA, 0, 0 }, 963 { "ssh-dss", "DSA", KEY_DSA, 0, 0 },
964 { "ssh-ed25519", "ED25519", KEY_ED25519, 0, 0 },
918#ifdef OPENSSL_HAS_ECC 965#ifdef OPENSSL_HAS_ECC
919 { "ecdsa-sha2-nistp256", "ECDSA", KEY_ECDSA, NID_X9_62_prime256v1, 0 }, 966 { "ecdsa-sha2-nistp256", "ECDSA", KEY_ECDSA, NID_X9_62_prime256v1, 0 },
920 { "ecdsa-sha2-nistp384", "ECDSA", KEY_ECDSA, NID_secp384r1, 0 }, 967 { "ecdsa-sha2-nistp384", "ECDSA", KEY_ECDSA, NID_secp384r1, 0 },
@@ -938,6 +985,8 @@ static const struct keytype keytypes[] = {
938 KEY_RSA_CERT_V00, 0, 1 }, 985 KEY_RSA_CERT_V00, 0, 1 },
939 { "ssh-dss-cert-v00@openssh.com", "DSA-CERT-V00", 986 { "ssh-dss-cert-v00@openssh.com", "DSA-CERT-V00",
940 KEY_DSA_CERT_V00, 0, 1 }, 987 KEY_DSA_CERT_V00, 0, 1 },
988 { "ssh-ed25519-cert-v01@openssh.com", "ED25519-CERT",
989 KEY_ED25519_CERT, 0, 1 },
941 { NULL, NULL, -1, -1, 0 } 990 { NULL, NULL, -1, -1, 0 }
942}; 991};
943 992
@@ -1009,7 +1058,7 @@ key_ecdsa_nid_from_name(const char *name)
1009} 1058}
1010 1059
1011char * 1060char *
1012key_alg_list(void) 1061key_alg_list(int certs_only, int plain_only)
1013{ 1062{
1014 char *ret = NULL; 1063 char *ret = NULL;
1015 size_t nlen, rlen = 0; 1064 size_t nlen, rlen = 0;
@@ -1018,6 +1067,8 @@ key_alg_list(void)
1018 for (kt = keytypes; kt->type != -1; kt++) { 1067 for (kt = keytypes; kt->type != -1; kt++) {
1019 if (kt->name == NULL) 1068 if (kt->name == NULL)
1020 continue; 1069 continue;
1070 if ((certs_only && !kt->cert) || (plain_only && kt->cert))
1071 continue;
1021 if (ret != NULL) 1072 if (ret != NULL)
1022 ret[rlen++] = '\n'; 1073 ret[rlen++] = '\n';
1023 nlen = strlen(kt->name); 1074 nlen = strlen(kt->name);
@@ -1053,6 +1104,8 @@ key_size(const Key *k)
1053 case KEY_DSA_CERT_V00: 1104 case KEY_DSA_CERT_V00:
1054 case KEY_DSA_CERT: 1105 case KEY_DSA_CERT:
1055 return BN_num_bits(k->dsa->p); 1106 return BN_num_bits(k->dsa->p);
1107 case KEY_ED25519:
1108 return 256; /* XXX */
1056#ifdef OPENSSL_HAS_ECC 1109#ifdef OPENSSL_HAS_ECC
1057 case KEY_ECDSA: 1110 case KEY_ECDSA:
1058 case KEY_ECDSA_CERT: 1111 case KEY_ECDSA_CERT:
@@ -1196,6 +1249,11 @@ key_generate(int type, u_int bits)
1196 case KEY_RSA1: 1249 case KEY_RSA1:
1197 k->rsa = rsa_generate_private_key(bits); 1250 k->rsa = rsa_generate_private_key(bits);
1198 break; 1251 break;
1252 case KEY_ED25519:
1253 k->ed25519_pk = xmalloc(ED25519_PK_SZ);
1254 k->ed25519_sk = xmalloc(ED25519_SK_SZ);
1255 crypto_sign_ed25519_keypair(k->ed25519_pk, k->ed25519_sk);
1256 break;
1199 case KEY_RSA_CERT_V00: 1257 case KEY_RSA_CERT_V00:
1200 case KEY_DSA_CERT_V00: 1258 case KEY_DSA_CERT_V00:
1201 case KEY_RSA_CERT: 1259 case KEY_RSA_CERT:
@@ -1289,6 +1347,14 @@ key_from_private(const Key *k)
1289 (BN_copy(n->rsa->e, k->rsa->e) == NULL)) 1347 (BN_copy(n->rsa->e, k->rsa->e) == NULL))
1290 fatal("key_from_private: BN_copy failed"); 1348 fatal("key_from_private: BN_copy failed");
1291 break; 1349 break;
1350 case KEY_ED25519:
1351 case KEY_ED25519_CERT:
1352 n = key_new(k->type);
1353 if (k->ed25519_pk != NULL) {
1354 n->ed25519_pk = xmalloc(ED25519_PK_SZ);
1355 memcpy(n->ed25519_pk, k->ed25519_pk, ED25519_PK_SZ);
1356 }
1357 break;
1292 default: 1358 default:
1293 fatal("key_from_private: unknown type %d", k->type); 1359 fatal("key_from_private: unknown type %d", k->type);
1294 break; 1360 break;
@@ -1451,7 +1517,9 @@ key_from_blob2(const u_char *blob, u_int blen, int allow_cert)
1451{ 1517{
1452 Buffer b; 1518 Buffer b;
1453 int rlen, type; 1519 int rlen, type;
1520 u_int len;
1454 char *ktype = NULL, *curve = NULL; 1521 char *ktype = NULL, *curve = NULL;
1522 u_char *pk = NULL;
1455 Key *key = NULL; 1523 Key *key = NULL;
1456#ifdef OPENSSL_HAS_ECC 1524#ifdef OPENSSL_HAS_ECC
1457 EC_POINT *q = NULL; 1525 EC_POINT *q = NULL;
@@ -1550,6 +1618,23 @@ key_from_blob2(const u_char *blob, u_int blen, int allow_cert)
1550#endif 1618#endif
1551 break; 1619 break;
1552#endif /* OPENSSL_HAS_ECC */ 1620#endif /* OPENSSL_HAS_ECC */
1621 case KEY_ED25519_CERT:
1622 (void)buffer_get_string_ptr_ret(&b, NULL); /* Skip nonce */
1623 /* FALLTHROUGH */
1624 case KEY_ED25519:
1625 if ((pk = buffer_get_string_ret(&b, &len)) == NULL) {
1626 error("key_from_blob: can't read ed25519 key");
1627 goto badkey;
1628 }
1629 if (len != ED25519_PK_SZ) {
1630 error("key_from_blob: ed25519 len %d != %d",
1631 len, ED25519_PK_SZ);
1632 goto badkey;
1633 }
1634 key = key_new(type);
1635 key->ed25519_pk = pk;
1636 pk = NULL;
1637 break;
1553 case KEY_UNSPEC: 1638 case KEY_UNSPEC:
1554 key = key_new(type); 1639 key = key_new(type);
1555 break; 1640 break;
@@ -1567,6 +1652,7 @@ key_from_blob2(const u_char *blob, u_int blen, int allow_cert)
1567 out: 1652 out:
1568 free(ktype); 1653 free(ktype);
1569 free(curve); 1654 free(curve);
1655 free(pk);
1570#ifdef OPENSSL_HAS_ECC 1656#ifdef OPENSSL_HAS_ECC
1571 if (q != NULL) 1657 if (q != NULL)
1572 EC_POINT_free(q); 1658 EC_POINT_free(q);
@@ -1603,6 +1689,7 @@ to_blob(const Key *key, u_char **blobp, u_int *lenp, int force_plain)
1603 case KEY_DSA_CERT: 1689 case KEY_DSA_CERT:
1604 case KEY_ECDSA_CERT: 1690 case KEY_ECDSA_CERT:
1605 case KEY_RSA_CERT: 1691 case KEY_RSA_CERT:
1692 case KEY_ED25519_CERT:
1606 /* Use the existing blob */ 1693 /* Use the existing blob */
1607 buffer_append(&b, buffer_ptr(&key->cert->certblob), 1694 buffer_append(&b, buffer_ptr(&key->cert->certblob),
1608 buffer_len(&key->cert->certblob)); 1695 buffer_len(&key->cert->certblob));
@@ -1630,6 +1717,11 @@ to_blob(const Key *key, u_char **blobp, u_int *lenp, int force_plain)
1630 buffer_put_bignum2(&b, key->rsa->e); 1717 buffer_put_bignum2(&b, key->rsa->e);
1631 buffer_put_bignum2(&b, key->rsa->n); 1718 buffer_put_bignum2(&b, key->rsa->n);
1632 break; 1719 break;
1720 case KEY_ED25519:
1721 buffer_put_cstring(&b,
1722 key_ssh_name_from_type_nid(type, key->ecdsa_nid));
1723 buffer_put_string(&b, key->ed25519_pk, ED25519_PK_SZ);
1724 break;
1633 default: 1725 default:
1634 error("key_to_blob: unsupported key type %d", key->type); 1726 error("key_to_blob: unsupported key type %d", key->type);
1635 buffer_free(&b); 1727 buffer_free(&b);
@@ -1673,6 +1765,9 @@ key_sign(
1673 case KEY_RSA_CERT: 1765 case KEY_RSA_CERT:
1674 case KEY_RSA: 1766 case KEY_RSA:
1675 return ssh_rsa_sign(key, sigp, lenp, data, datalen); 1767 return ssh_rsa_sign(key, sigp, lenp, data, datalen);
1768 case KEY_ED25519:
1769 case KEY_ED25519_CERT:
1770 return ssh_ed25519_sign(key, sigp, lenp, data, datalen);
1676 default: 1771 default:
1677 error("key_sign: invalid key type %d", key->type); 1772 error("key_sign: invalid key type %d", key->type);
1678 return -1; 1773 return -1;
@@ -1706,6 +1801,9 @@ key_verify(
1706 case KEY_RSA_CERT: 1801 case KEY_RSA_CERT:
1707 case KEY_RSA: 1802 case KEY_RSA:
1708 return ssh_rsa_verify(key, signature, signaturelen, data, datalen); 1803 return ssh_rsa_verify(key, signature, signaturelen, data, datalen);
1804 case KEY_ED25519:
1805 case KEY_ED25519_CERT:
1806 return ssh_ed25519_verify(key, signature, signaturelen, data, datalen);
1709 default: 1807 default:
1710 error("key_verify: invalid key type %d", key->type); 1808 error("key_verify: invalid key type %d", key->type);
1711 return -1; 1809 return -1;
@@ -1725,6 +1823,8 @@ key_demote(const Key *k)
1725 pk->dsa = NULL; 1823 pk->dsa = NULL;
1726 pk->ecdsa = NULL; 1824 pk->ecdsa = NULL;
1727 pk->rsa = NULL; 1825 pk->rsa = NULL;
1826 pk->ed25519_pk = NULL;
1827 pk->ed25519_sk = NULL;
1728 1828
1729 switch (k->type) { 1829 switch (k->type) {
1730 case KEY_RSA_CERT_V00: 1830 case KEY_RSA_CERT_V00:
@@ -1768,8 +1868,17 @@ key_demote(const Key *k)
1768 fatal("key_demote: EC_KEY_set_public_key failed"); 1868 fatal("key_demote: EC_KEY_set_public_key failed");
1769 break; 1869 break;
1770#endif 1870#endif
1871 case KEY_ED25519_CERT:
1872 key_cert_copy(k, pk);
1873 /* FALLTHROUGH */
1874 case KEY_ED25519:
1875 if (k->ed25519_pk != NULL) {
1876 pk->ed25519_pk = xmalloc(ED25519_PK_SZ);
1877 memcpy(pk->ed25519_pk, k->ed25519_pk, ED25519_PK_SZ);
1878 }
1879 break;
1771 default: 1880 default:
1772 fatal("key_free: bad key type %d", k->type); 1881 fatal("key_demote: bad key type %d", k->type);
1773 break; 1882 break;
1774 } 1883 }
1775 1884
@@ -1797,6 +1906,8 @@ key_type_plain(int type)
1797 return KEY_DSA; 1906 return KEY_DSA;
1798 case KEY_ECDSA_CERT: 1907 case KEY_ECDSA_CERT:
1799 return KEY_ECDSA; 1908 return KEY_ECDSA;
1909 case KEY_ED25519_CERT:
1910 return KEY_ED25519;
1800 default: 1911 default:
1801 return type; 1912 return type;
1802 } 1913 }
@@ -1822,6 +1933,13 @@ key_to_certified(Key *k, int legacy)
1822 k->cert = cert_new(); 1933 k->cert = cert_new();
1823 k->type = KEY_ECDSA_CERT; 1934 k->type = KEY_ECDSA_CERT;
1824 return 0; 1935 return 0;
1936 case KEY_ED25519:
1937 if (legacy)
1938 fatal("%s: legacy ED25519 certificates are not "
1939 "supported", __func__);
1940 k->cert = cert_new();
1941 k->type = KEY_ED25519_CERT;
1942 return 0;
1825 default: 1943 default:
1826 error("%s: key has incorrect type %s", __func__, key_type(k)); 1944 error("%s: key has incorrect type %s", __func__, key_type(k));
1827 return -1; 1945 return -1;
@@ -1832,31 +1950,16 @@ key_to_certified(Key *k, int legacy)
1832int 1950int
1833key_drop_cert(Key *k) 1951key_drop_cert(Key *k)
1834{ 1952{
1835 switch (k->type) { 1953 if (!key_type_is_cert(k->type)) {
1836 case KEY_RSA_CERT_V00:
1837 case KEY_RSA_CERT:
1838 cert_free(k->cert);
1839 k->type = KEY_RSA;
1840 return 0;
1841 case KEY_DSA_CERT_V00:
1842 case KEY_DSA_CERT:
1843 cert_free(k->cert);
1844 k->type = KEY_DSA;
1845 return 0;
1846 case KEY_ECDSA_CERT:
1847 cert_free(k->cert);
1848 k->type = KEY_ECDSA;
1849 return 0;
1850 default:
1851 error("%s: key has incorrect type %s", __func__, key_type(k)); 1954 error("%s: key has incorrect type %s", __func__, key_type(k));
1852 return -1; 1955 return -1;
1853 } 1956 }
1957 cert_free(k->cert);
1958 k->type = key_type_plain(k->type);
1959 return 0;
1854} 1960}
1855 1961
1856/* 1962/* Sign a certified key, (re-)generating the signed certblob. */
1857 * Sign a KEY_RSA_CERT, KEY_DSA_CERT or KEY_ECDSA_CERT, (re-)generating
1858 * the signed certblob
1859 */
1860int 1963int
1861key_certify(Key *k, Key *ca) 1964key_certify(Key *k, Key *ca)
1862{ 1965{
@@ -1876,7 +1979,7 @@ key_certify(Key *k, Key *ca)
1876 } 1979 }
1877 1980
1878 if (ca->type != KEY_RSA && ca->type != KEY_DSA && 1981 if (ca->type != KEY_RSA && ca->type != KEY_DSA &&
1879 ca->type != KEY_ECDSA) { 1982 ca->type != KEY_ECDSA && ca->type != KEY_ED25519) {
1880 error("%s: CA key has unsupported type %s", __func__, 1983 error("%s: CA key has unsupported type %s", __func__,
1881 key_type(ca)); 1984 key_type(ca));
1882 return -1; 1985 return -1;
@@ -1915,6 +2018,10 @@ key_certify(Key *k, Key *ca)
1915 buffer_put_bignum2(&k->cert->certblob, k->rsa->e); 2018 buffer_put_bignum2(&k->cert->certblob, k->rsa->e);
1916 buffer_put_bignum2(&k->cert->certblob, k->rsa->n); 2019 buffer_put_bignum2(&k->cert->certblob, k->rsa->n);
1917 break; 2020 break;
2021 case KEY_ED25519_CERT:
2022 buffer_put_string(&k->cert->certblob,
2023 k->ed25519_pk, ED25519_PK_SZ);
2024 break;
1918 default: 2025 default:
1919 error("%s: key has incorrect type %s", __func__, key_type(k)); 2026 error("%s: key has incorrect type %s", __func__, key_type(k));
1920 buffer_clear(&k->cert->certblob); 2027 buffer_clear(&k->cert->certblob);
@@ -2332,6 +2439,18 @@ key_private_serialize(const Key *key, Buffer *b)
2332 buffer_put_bignum2(b, EC_KEY_get0_private_key(key->ecdsa)); 2439 buffer_put_bignum2(b, EC_KEY_get0_private_key(key->ecdsa));
2333 break; 2440 break;
2334#endif /* OPENSSL_HAS_ECC */ 2441#endif /* OPENSSL_HAS_ECC */
2442 case KEY_ED25519:
2443 buffer_put_string(b, key->ed25519_pk, ED25519_PK_SZ);
2444 buffer_put_string(b, key->ed25519_sk, ED25519_SK_SZ);
2445 break;
2446 case KEY_ED25519_CERT:
2447 if (key->cert == NULL || buffer_len(&key->cert->certblob) == 0)
2448 fatal("%s: no cert/certblob", __func__);
2449 buffer_put_string(b, buffer_ptr(&key->cert->certblob),
2450 buffer_len(&key->cert->certblob));
2451 buffer_put_string(b, key->ed25519_pk, ED25519_PK_SZ);
2452 buffer_put_string(b, key->ed25519_sk, ED25519_SK_SZ);
2453 break;
2335 } 2454 }
2336} 2455}
2337 2456
@@ -2341,7 +2460,7 @@ key_private_deserialize(Buffer *blob)
2341 char *type_name; 2460 char *type_name;
2342 Key *k = NULL; 2461 Key *k = NULL;
2343 u_char *cert; 2462 u_char *cert;
2344 u_int len; 2463 u_int len, pklen, sklen;
2345 int type; 2464 int type;
2346#ifdef OPENSSL_HAS_ECC 2465#ifdef OPENSSL_HAS_ECC
2347 char *curve; 2466 char *curve;
@@ -2446,6 +2565,32 @@ key_private_deserialize(Buffer *blob)
2446 buffer_get_bignum2(blob, k->rsa->p); 2565 buffer_get_bignum2(blob, k->rsa->p);
2447 buffer_get_bignum2(blob, k->rsa->q); 2566 buffer_get_bignum2(blob, k->rsa->q);
2448 break; 2567 break;
2568 case KEY_ED25519:
2569 k = key_new_private(type);
2570 k->ed25519_pk = buffer_get_string(blob, &pklen);
2571 k->ed25519_sk = buffer_get_string(blob, &sklen);
2572 if (pklen != ED25519_PK_SZ)
2573 fatal("%s: ed25519 pklen %d != %d",
2574 __func__, pklen, ED25519_PK_SZ);
2575 if (sklen != ED25519_SK_SZ)
2576 fatal("%s: ed25519 sklen %d != %d",
2577 __func__, sklen, ED25519_SK_SZ);
2578 break;
2579 case KEY_ED25519_CERT:
2580 cert = buffer_get_string(blob, &len);
2581 if ((k = key_from_blob(cert, len)) == NULL)
2582 fatal("Certificate parse failed");
2583 free(cert);
2584 key_add_private(k);
2585 k->ed25519_pk = buffer_get_string(blob, &pklen);
2586 k->ed25519_sk = buffer_get_string(blob, &sklen);
2587 if (pklen != ED25519_PK_SZ)
2588 fatal("%s: ed25519 pklen %d != %d",
2589 __func__, pklen, ED25519_PK_SZ);
2590 if (sklen != ED25519_SK_SZ)
2591 fatal("%s: ed25519 sklen %d != %d",
2592 __func__, sklen, ED25519_SK_SZ);
2593 break;
2449 default: 2594 default:
2450 free(type_name); 2595 free(type_name);
2451 buffer_clear(blob); 2596 buffer_clear(blob);