xref: /freebsd-src/crypto/openssh/sshkey.h (revision 535af610a4fdace6d50960c0ad9be0597eea7a1b)
1*535af610SEd Maste /* $OpenBSD: sshkey.h,v 1.62 2023/06/21 05:10:26 djm Exp $ */
2a0ee8cc6SDag-Erling Smørgrav 
3a0ee8cc6SDag-Erling Smørgrav /*
4a0ee8cc6SDag-Erling Smørgrav  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
5a0ee8cc6SDag-Erling Smørgrav  *
6a0ee8cc6SDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
7a0ee8cc6SDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
8a0ee8cc6SDag-Erling Smørgrav  * are met:
9a0ee8cc6SDag-Erling Smørgrav  * 1. Redistributions of source code must retain the above copyright
10a0ee8cc6SDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer.
11a0ee8cc6SDag-Erling Smørgrav  * 2. Redistributions in binary form must reproduce the above copyright
12a0ee8cc6SDag-Erling Smørgrav  *    notice, this list of conditions and the following disclaimer in the
13a0ee8cc6SDag-Erling Smørgrav  *    documentation and/or other materials provided with the distribution.
14a0ee8cc6SDag-Erling Smørgrav  *
15a0ee8cc6SDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16a0ee8cc6SDag-Erling Smørgrav  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a0ee8cc6SDag-Erling Smørgrav  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a0ee8cc6SDag-Erling Smørgrav  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19a0ee8cc6SDag-Erling Smørgrav  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a0ee8cc6SDag-Erling Smørgrav  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a0ee8cc6SDag-Erling Smørgrav  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a0ee8cc6SDag-Erling Smørgrav  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a0ee8cc6SDag-Erling Smørgrav  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24a0ee8cc6SDag-Erling Smørgrav  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a0ee8cc6SDag-Erling Smørgrav  */
26a0ee8cc6SDag-Erling Smørgrav #ifndef SSHKEY_H
27a0ee8cc6SDag-Erling Smørgrav #define SSHKEY_H
28a0ee8cc6SDag-Erling Smørgrav 
29a0ee8cc6SDag-Erling Smørgrav #include <sys/types.h>
30a0ee8cc6SDag-Erling Smørgrav 
31a0ee8cc6SDag-Erling Smørgrav #ifdef WITH_OPENSSL
32a0ee8cc6SDag-Erling Smørgrav #include <openssl/rsa.h>
33a0ee8cc6SDag-Erling Smørgrav #include <openssl/dsa.h>
34a0ee8cc6SDag-Erling Smørgrav # ifdef OPENSSL_HAS_ECC
35a0ee8cc6SDag-Erling Smørgrav #  include <openssl/ec.h>
3619261079SEd Maste #  include <openssl/ecdsa.h>
37a0ee8cc6SDag-Erling Smørgrav # else /* OPENSSL_HAS_ECC */
38a0ee8cc6SDag-Erling Smørgrav #  define EC_KEY	void
39a0ee8cc6SDag-Erling Smørgrav #  define EC_GROUP	void
40a0ee8cc6SDag-Erling Smørgrav #  define EC_POINT	void
41a0ee8cc6SDag-Erling Smørgrav # endif /* OPENSSL_HAS_ECC */
4219261079SEd Maste #define SSH_OPENSSL_VERSION OpenSSL_version(OPENSSL_VERSION)
43a0ee8cc6SDag-Erling Smørgrav #else /* WITH_OPENSSL */
442a01feabSEd Maste # define BIGNUM		void
45a0ee8cc6SDag-Erling Smørgrav # define RSA		void
46a0ee8cc6SDag-Erling Smørgrav # define DSA		void
47a0ee8cc6SDag-Erling Smørgrav # define EC_KEY		void
48a0ee8cc6SDag-Erling Smørgrav # define EC_GROUP	void
49a0ee8cc6SDag-Erling Smørgrav # define EC_POINT	void
5019261079SEd Maste #define SSH_OPENSSL_VERSION "without OpenSSL"
51a0ee8cc6SDag-Erling Smørgrav #endif /* WITH_OPENSSL */
52a0ee8cc6SDag-Erling Smørgrav 
534f52dfbbSDag-Erling Smørgrav #define SSH_RSA_MINIMUM_MODULUS_SIZE	1024
54a0ee8cc6SDag-Erling Smørgrav #define SSH_KEY_MAX_SIGN_DATA_SIZE	(1 << 20)
55a0ee8cc6SDag-Erling Smørgrav 
56a0ee8cc6SDag-Erling Smørgrav struct sshbuf;
57a0ee8cc6SDag-Erling Smørgrav 
58a0ee8cc6SDag-Erling Smørgrav /* Key types */
59a0ee8cc6SDag-Erling Smørgrav enum sshkey_types {
60a0ee8cc6SDag-Erling Smørgrav 	KEY_RSA,
61a0ee8cc6SDag-Erling Smørgrav 	KEY_DSA,
62a0ee8cc6SDag-Erling Smørgrav 	KEY_ECDSA,
63a0ee8cc6SDag-Erling Smørgrav 	KEY_ED25519,
64a0ee8cc6SDag-Erling Smørgrav 	KEY_RSA_CERT,
65a0ee8cc6SDag-Erling Smørgrav 	KEY_DSA_CERT,
66a0ee8cc6SDag-Erling Smørgrav 	KEY_ECDSA_CERT,
67a0ee8cc6SDag-Erling Smørgrav 	KEY_ED25519_CERT,
6847dd1d1bSDag-Erling Smørgrav 	KEY_XMSS,
6947dd1d1bSDag-Erling Smørgrav 	KEY_XMSS_CERT,
7019261079SEd Maste 	KEY_ECDSA_SK,
7119261079SEd Maste 	KEY_ECDSA_SK_CERT,
7219261079SEd Maste 	KEY_ED25519_SK,
7319261079SEd Maste 	KEY_ED25519_SK_CERT,
74a0ee8cc6SDag-Erling Smørgrav 	KEY_UNSPEC
75a0ee8cc6SDag-Erling Smørgrav };
76a0ee8cc6SDag-Erling Smørgrav 
77bc5531deSDag-Erling Smørgrav /* Default fingerprint hash */
78bc5531deSDag-Erling Smørgrav #define SSH_FP_HASH_DEFAULT	SSH_DIGEST_SHA256
79a0ee8cc6SDag-Erling Smørgrav 
80a0ee8cc6SDag-Erling Smørgrav /* Fingerprint representation formats */
81a0ee8cc6SDag-Erling Smørgrav enum sshkey_fp_rep {
82bc5531deSDag-Erling Smørgrav 	SSH_FP_DEFAULT = 0,
83a0ee8cc6SDag-Erling Smørgrav 	SSH_FP_HEX,
84bc5531deSDag-Erling Smørgrav 	SSH_FP_BASE64,
85a0ee8cc6SDag-Erling Smørgrav 	SSH_FP_BUBBLEBABBLE,
86a0ee8cc6SDag-Erling Smørgrav 	SSH_FP_RANDOMART
87a0ee8cc6SDag-Erling Smørgrav };
88a0ee8cc6SDag-Erling Smørgrav 
8947dd1d1bSDag-Erling Smørgrav /* Private key serialisation formats, used on the wire */
9047dd1d1bSDag-Erling Smørgrav enum sshkey_serialize_rep {
9147dd1d1bSDag-Erling Smørgrav 	SSHKEY_SERIALIZE_DEFAULT = 0,
9219261079SEd Maste 	SSHKEY_SERIALIZE_STATE = 1,	/* only state is serialized */
9319261079SEd Maste 	SSHKEY_SERIALIZE_FULL = 2,	/* include keys for saving to disk */
9419261079SEd Maste 	SSHKEY_SERIALIZE_SHIELD = 3,	/* everything, for encrypting in ram */
9519261079SEd Maste 	SSHKEY_SERIALIZE_INFO = 254,	/* minimal information */
9619261079SEd Maste };
9719261079SEd Maste 
9819261079SEd Maste /* Private key disk formats */
9919261079SEd Maste enum sshkey_private_format {
10019261079SEd Maste 	SSHKEY_PRIVATE_OPENSSH = 0,
10119261079SEd Maste 	SSHKEY_PRIVATE_PEM = 1,
10219261079SEd Maste 	SSHKEY_PRIVATE_PKCS8 = 2,
10347dd1d1bSDag-Erling Smørgrav };
10447dd1d1bSDag-Erling Smørgrav 
105a0ee8cc6SDag-Erling Smørgrav /* key is stored in external hardware */
106a0ee8cc6SDag-Erling Smørgrav #define SSHKEY_FLAG_EXT		0x0001
107a0ee8cc6SDag-Erling Smørgrav 
108a0ee8cc6SDag-Erling Smørgrav #define SSHKEY_CERT_MAX_PRINCIPALS	256
109a0ee8cc6SDag-Erling Smørgrav /* XXX opaquify? */
110a0ee8cc6SDag-Erling Smørgrav struct sshkey_cert {
111a0ee8cc6SDag-Erling Smørgrav 	struct sshbuf	*certblob; /* Kept around for use on wire */
112a0ee8cc6SDag-Erling Smørgrav 	u_int		 type; /* SSH2_CERT_TYPE_USER or SSH2_CERT_TYPE_HOST */
113a0ee8cc6SDag-Erling Smørgrav 	u_int64_t	 serial;
114a0ee8cc6SDag-Erling Smørgrav 	char		*key_id;
115a0ee8cc6SDag-Erling Smørgrav 	u_int		 nprincipals;
116a0ee8cc6SDag-Erling Smørgrav 	char		**principals;
117a0ee8cc6SDag-Erling Smørgrav 	u_int64_t	 valid_after, valid_before;
118a0ee8cc6SDag-Erling Smørgrav 	struct sshbuf	*critical;
119a0ee8cc6SDag-Erling Smørgrav 	struct sshbuf	*extensions;
120a0ee8cc6SDag-Erling Smørgrav 	struct sshkey	*signature_key;
1212f513db7SEd Maste 	char		*signature_type;
122a0ee8cc6SDag-Erling Smørgrav };
123a0ee8cc6SDag-Erling Smørgrav 
124a0ee8cc6SDag-Erling Smørgrav /* XXX opaquify? */
125a0ee8cc6SDag-Erling Smørgrav struct sshkey {
126a0ee8cc6SDag-Erling Smørgrav 	int	 type;
127a0ee8cc6SDag-Erling Smørgrav 	int	 flags;
12819261079SEd Maste 	/* KEY_RSA */
129a0ee8cc6SDag-Erling Smørgrav 	RSA	*rsa;
13019261079SEd Maste 	/* KEY_DSA */
131a0ee8cc6SDag-Erling Smørgrav 	DSA	*dsa;
13219261079SEd Maste 	/* KEY_ECDSA and KEY_ECDSA_SK */
133a0ee8cc6SDag-Erling Smørgrav 	int	 ecdsa_nid;	/* NID of curve */
134a0ee8cc6SDag-Erling Smørgrav 	EC_KEY	*ecdsa;
13519261079SEd Maste 	/* KEY_ED25519 and KEY_ED25519_SK */
136a0ee8cc6SDag-Erling Smørgrav 	u_char	*ed25519_sk;
137a0ee8cc6SDag-Erling Smørgrav 	u_char	*ed25519_pk;
13819261079SEd Maste 	/* KEY_XMSS */
13947dd1d1bSDag-Erling Smørgrav 	char	*xmss_name;
14047dd1d1bSDag-Erling Smørgrav 	char	*xmss_filename;	/* for state file updates */
14147dd1d1bSDag-Erling Smørgrav 	void	*xmss_state;	/* depends on xmss_name, opaque */
14247dd1d1bSDag-Erling Smørgrav 	u_char	*xmss_sk;
14347dd1d1bSDag-Erling Smørgrav 	u_char	*xmss_pk;
14419261079SEd Maste 	/* KEY_ECDSA_SK and KEY_ED25519_SK */
14519261079SEd Maste 	char	*sk_application;
14619261079SEd Maste 	uint8_t	sk_flags;
14719261079SEd Maste 	struct sshbuf *sk_key_handle;
14819261079SEd Maste 	struct sshbuf *sk_reserved;
14919261079SEd Maste 	/* Certificates */
150a0ee8cc6SDag-Erling Smørgrav 	struct sshkey_cert *cert;
15119261079SEd Maste 	/* Private key shielding */
15219261079SEd Maste 	u_char	*shielded_private;
15319261079SEd Maste 	size_t	shielded_len;
15419261079SEd Maste 	u_char	*shield_prekey;
15519261079SEd Maste 	size_t	shield_prekey_len;
156a0ee8cc6SDag-Erling Smørgrav };
157a0ee8cc6SDag-Erling Smørgrav 
158a0ee8cc6SDag-Erling Smørgrav #define	ED25519_SK_SZ	crypto_sign_ed25519_SECRETKEYBYTES
159a0ee8cc6SDag-Erling Smørgrav #define	ED25519_PK_SZ	crypto_sign_ed25519_PUBLICKEYBYTES
160a0ee8cc6SDag-Erling Smørgrav 
16119261079SEd Maste /* Additional fields contained in signature */
16219261079SEd Maste struct sshkey_sig_details {
16319261079SEd Maste 	uint32_t sk_counter;	/* U2F signature counter */
16419261079SEd Maste 	uint8_t sk_flags;	/* U2F signature flags; see ssh-sk.h */
16519261079SEd Maste };
16619261079SEd Maste 
167f374ba41SEd Maste struct sshkey_impl_funcs {
168f374ba41SEd Maste 	u_int (*size)(const struct sshkey *);	/* optional */
169f374ba41SEd Maste 	int (*alloc)(struct sshkey *);		/* optional */
170f374ba41SEd Maste 	void (*cleanup)(struct sshkey *);	/* optional */
171f374ba41SEd Maste 	int (*equal)(const struct sshkey *, const struct sshkey *);
172f374ba41SEd Maste 	int (*serialize_public)(const struct sshkey *, struct sshbuf *,
173f374ba41SEd Maste 	    enum sshkey_serialize_rep);
174f374ba41SEd Maste 	int (*deserialize_public)(const char *, struct sshbuf *,
175f374ba41SEd Maste 	    struct sshkey *);
176f374ba41SEd Maste 	int (*serialize_private)(const struct sshkey *, struct sshbuf *,
177f374ba41SEd Maste 	    enum sshkey_serialize_rep);
178f374ba41SEd Maste 	int (*deserialize_private)(const char *, struct sshbuf *,
179f374ba41SEd Maste 	    struct sshkey *);
180f374ba41SEd Maste 	int (*generate)(struct sshkey *, int);	/* optional */
181f374ba41SEd Maste 	int (*copy_public)(const struct sshkey *, struct sshkey *);
182f374ba41SEd Maste 	int (*sign)(struct sshkey *, u_char **, size_t *,
183f374ba41SEd Maste 	    const u_char *, size_t, const char *,
184f374ba41SEd Maste 	    const char *, const char *, u_int); /* optional */
185f374ba41SEd Maste 	int (*verify)(const struct sshkey *, const u_char *, size_t,
186f374ba41SEd Maste 	    const u_char *, size_t, const char *, u_int,
187f374ba41SEd Maste 	    struct sshkey_sig_details **);
188f374ba41SEd Maste };
189f374ba41SEd Maste 
190f374ba41SEd Maste struct sshkey_impl {
191f374ba41SEd Maste 	const char *name;
192f374ba41SEd Maste 	const char *shortname;
193f374ba41SEd Maste 	const char *sigalg;
194f374ba41SEd Maste 	int type;
195f374ba41SEd Maste 	int nid;
196f374ba41SEd Maste 	int cert;
197f374ba41SEd Maste 	int sigonly;
198f374ba41SEd Maste 	int keybits;
199f374ba41SEd Maste 	const struct sshkey_impl_funcs *funcs;
200f374ba41SEd Maste };
201f374ba41SEd Maste 
202a0ee8cc6SDag-Erling Smørgrav struct sshkey	*sshkey_new(int);
203a0ee8cc6SDag-Erling Smørgrav void		 sshkey_free(struct sshkey *);
204a0ee8cc6SDag-Erling Smørgrav int		 sshkey_equal_public(const struct sshkey *,
205a0ee8cc6SDag-Erling Smørgrav     const struct sshkey *);
206a0ee8cc6SDag-Erling Smørgrav int		 sshkey_equal(const struct sshkey *, const struct sshkey *);
207a0ee8cc6SDag-Erling Smørgrav char		*sshkey_fingerprint(const struct sshkey *,
208bc5531deSDag-Erling Smørgrav     int, enum sshkey_fp_rep);
209a0ee8cc6SDag-Erling Smørgrav int		 sshkey_fingerprint_raw(const struct sshkey *k,
210bc5531deSDag-Erling Smørgrav     int, u_char **retp, size_t *lenp);
211a0ee8cc6SDag-Erling Smørgrav const char	*sshkey_type(const struct sshkey *);
212a0ee8cc6SDag-Erling Smørgrav const char	*sshkey_cert_type(const struct sshkey *);
2134f52dfbbSDag-Erling Smørgrav int		 sshkey_format_text(const struct sshkey *, struct sshbuf *);
214a0ee8cc6SDag-Erling Smørgrav int		 sshkey_write(const struct sshkey *, FILE *);
215a0ee8cc6SDag-Erling Smørgrav int		 sshkey_read(struct sshkey *, char **);
216a0ee8cc6SDag-Erling Smørgrav u_int		 sshkey_size(const struct sshkey *);
217a0ee8cc6SDag-Erling Smørgrav 
218a0ee8cc6SDag-Erling Smørgrav int		 sshkey_generate(int type, u_int bits, struct sshkey **keyp);
219a0ee8cc6SDag-Erling Smørgrav int		 sshkey_from_private(const struct sshkey *, struct sshkey **);
22019261079SEd Maste 
22119261079SEd Maste int		 sshkey_is_shielded(struct sshkey *);
22219261079SEd Maste int		 sshkey_shield_private(struct sshkey *);
22319261079SEd Maste int		 sshkey_unshield_private(struct sshkey *);
22419261079SEd Maste 
225a0ee8cc6SDag-Erling Smørgrav int	 sshkey_type_from_name(const char *);
226a0ee8cc6SDag-Erling Smørgrav int	 sshkey_is_cert(const struct sshkey *);
22719261079SEd Maste int	 sshkey_is_sk(const struct sshkey *);
228a0ee8cc6SDag-Erling Smørgrav int	 sshkey_type_is_cert(int);
229a0ee8cc6SDag-Erling Smørgrav int	 sshkey_type_plain(int);
2301323ec57SEd Maste 
2311323ec57SEd Maste /* Returns non-zero if key name match sigalgs pattern list. (handles RSA) */
2321323ec57SEd Maste int	 sshkey_match_keyname_to_sigalgs(const char *, const char *);
2331323ec57SEd Maste 
234eccfee6eSDag-Erling Smørgrav int	 sshkey_to_certified(struct sshkey *);
235a0ee8cc6SDag-Erling Smørgrav int	 sshkey_drop_cert(struct sshkey *);
236a0ee8cc6SDag-Erling Smørgrav int	 sshkey_cert_copy(const struct sshkey *, struct sshkey *);
23719261079SEd Maste int	 sshkey_cert_check_authority(const struct sshkey *, int, int, int,
23819261079SEd Maste     uint64_t, const char *, const char **);
23919261079SEd Maste int	 sshkey_cert_check_authority_now(const struct sshkey *, int, int, int,
240a0ee8cc6SDag-Erling Smørgrav     const char *, const char **);
24119261079SEd Maste int	 sshkey_cert_check_host(const struct sshkey *, const char *,
24219261079SEd Maste     int , const char *, const char **);
243acc1a9efSDag-Erling Smørgrav size_t	 sshkey_format_cert_validity(const struct sshkey_cert *,
244acc1a9efSDag-Erling Smørgrav     char *, size_t) __attribute__((__bounded__(__string__, 2, 3)));
2452f513db7SEd Maste int	 sshkey_check_cert_sigtype(const struct sshkey *, const char *);
246a0ee8cc6SDag-Erling Smørgrav 
24719261079SEd Maste int	 sshkey_certify(struct sshkey *, struct sshkey *,
24819261079SEd Maste     const char *, const char *, const char *);
2494f52dfbbSDag-Erling Smørgrav /* Variant allowing use of a custom signature function (e.g. for ssh-agent) */
25019261079SEd Maste typedef int sshkey_certify_signer(struct sshkey *, u_char **, size_t *,
25119261079SEd Maste     const u_char *, size_t, const char *, const char *, const char *,
25219261079SEd Maste     u_int, void *);
2534f52dfbbSDag-Erling Smørgrav int	 sshkey_certify_custom(struct sshkey *, struct sshkey *, const char *,
25419261079SEd Maste     const char *, const char *, sshkey_certify_signer *, void *);
2554f52dfbbSDag-Erling Smørgrav 
256a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ecdsa_nid_from_name(const char *);
257a0ee8cc6SDag-Erling Smørgrav int		 sshkey_curve_name_to_nid(const char *);
258a0ee8cc6SDag-Erling Smørgrav const char *	 sshkey_curve_nid_to_name(int);
259a0ee8cc6SDag-Erling Smørgrav u_int		 sshkey_curve_nid_to_bits(int);
260a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ecdsa_bits_to_nid(int);
261a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ecdsa_key_to_nid(EC_KEY *);
262a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ec_nid_to_hash_alg(int nid);
263a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ec_validate_public(const EC_GROUP *, const EC_POINT *);
264a0ee8cc6SDag-Erling Smørgrav int		 sshkey_ec_validate_private(const EC_KEY *);
265a0ee8cc6SDag-Erling Smørgrav const char	*sshkey_ssh_name(const struct sshkey *);
266a0ee8cc6SDag-Erling Smørgrav const char	*sshkey_ssh_name_plain(const struct sshkey *);
267*535af610SEd Maste int		 sshkey_names_valid2(const char *, int, int);
268d93a896eSDag-Erling Smørgrav char		*sshkey_alg_list(int, int, int, char);
269a0ee8cc6SDag-Erling Smørgrav 
270a0ee8cc6SDag-Erling Smørgrav int	 sshkey_from_blob(const u_char *, size_t, struct sshkey **);
271bc5531deSDag-Erling Smørgrav int	 sshkey_fromb(struct sshbuf *, struct sshkey **);
272bc5531deSDag-Erling Smørgrav int	 sshkey_froms(struct sshbuf *, struct sshkey **);
273a0ee8cc6SDag-Erling Smørgrav int	 sshkey_to_blob(const struct sshkey *, u_char **, size_t *);
274557f75e5SDag-Erling Smørgrav int	 sshkey_to_base64(const struct sshkey *, char **);
275bc5531deSDag-Erling Smørgrav int	 sshkey_putb(const struct sshkey *, struct sshbuf *);
276bc5531deSDag-Erling Smørgrav int	 sshkey_puts(const struct sshkey *, struct sshbuf *);
27747dd1d1bSDag-Erling Smørgrav int	 sshkey_puts_opts(const struct sshkey *, struct sshbuf *,
27847dd1d1bSDag-Erling Smørgrav     enum sshkey_serialize_rep);
279a0ee8cc6SDag-Erling Smørgrav int	 sshkey_plain_to_blob(const struct sshkey *, u_char **, size_t *);
280bc5531deSDag-Erling Smørgrav int	 sshkey_putb_plain(const struct sshkey *, struct sshbuf *);
281a0ee8cc6SDag-Erling Smørgrav 
28219261079SEd Maste int	 sshkey_sign(struct sshkey *, u_char **, size_t *,
28319261079SEd Maste     const u_char *, size_t, const char *, const char *, const char *, u_int);
284a0ee8cc6SDag-Erling Smørgrav int	 sshkey_verify(const struct sshkey *, const u_char *, size_t,
28519261079SEd Maste     const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
286190cef3dSDag-Erling Smørgrav int	 sshkey_check_sigtype(const u_char *, size_t, const char *);
287190cef3dSDag-Erling Smørgrav const char *sshkey_sigalg_by_name(const char *);
28819261079SEd Maste int	 sshkey_get_sigtype(const u_char *, size_t, char **);
289a0ee8cc6SDag-Erling Smørgrav 
290a0ee8cc6SDag-Erling Smørgrav /* for debug */
291a0ee8cc6SDag-Erling Smørgrav void	sshkey_dump_ec_point(const EC_GROUP *, const EC_POINT *);
292a0ee8cc6SDag-Erling Smørgrav void	sshkey_dump_ec_key(const EC_KEY *);
293a0ee8cc6SDag-Erling Smørgrav 
294a0ee8cc6SDag-Erling Smørgrav /* private key parsing and serialisation */
29519261079SEd Maste int	sshkey_private_serialize(struct sshkey *key, struct sshbuf *buf);
29619261079SEd Maste int	sshkey_private_serialize_opt(struct sshkey *key, struct sshbuf *buf,
29747dd1d1bSDag-Erling Smørgrav     enum sshkey_serialize_rep);
298a0ee8cc6SDag-Erling Smørgrav int	sshkey_private_deserialize(struct sshbuf *buf,  struct sshkey **keyp);
299a0ee8cc6SDag-Erling Smørgrav 
300a0ee8cc6SDag-Erling Smørgrav /* private key file format parsing and serialisation */
301a0ee8cc6SDag-Erling Smørgrav int	sshkey_private_to_fileblob(struct sshkey *key, struct sshbuf *blob,
302a0ee8cc6SDag-Erling Smørgrav     const char *passphrase, const char *comment,
30319261079SEd Maste     int format, const char *openssh_format_cipher, int openssh_format_rounds);
304a0ee8cc6SDag-Erling Smørgrav int	sshkey_parse_private_fileblob(struct sshbuf *buffer,
305acc1a9efSDag-Erling Smørgrav     const char *passphrase, struct sshkey **keyp, char **commentp);
306a0ee8cc6SDag-Erling Smørgrav int	sshkey_parse_private_fileblob_type(struct sshbuf *blob, int type,
307a0ee8cc6SDag-Erling Smørgrav     const char *passphrase, struct sshkey **keyp, char **commentp);
30819261079SEd Maste int	sshkey_parse_pubkey_from_private_fileblob_type(struct sshbuf *blob,
30919261079SEd Maste     int type, struct sshkey **pubkeyp);
310a0ee8cc6SDag-Erling Smørgrav 
31138a52bd3SEd Maste int sshkey_check_rsa_length(const struct sshkey *, int);
3124f52dfbbSDag-Erling Smørgrav /* XXX should be internal, but used by ssh-keygen */
3132a01feabSEd Maste int ssh_rsa_complete_crt_parameters(struct sshkey *, const BIGNUM *);
3144f52dfbbSDag-Erling Smørgrav 
31547dd1d1bSDag-Erling Smørgrav /* stateful keys (e.g. XMSS) */
31647dd1d1bSDag-Erling Smørgrav int	 sshkey_set_filename(struct sshkey *, const char *);
31747dd1d1bSDag-Erling Smørgrav int	 sshkey_enable_maxsign(struct sshkey *, u_int32_t);
31847dd1d1bSDag-Erling Smørgrav u_int32_t sshkey_signatures_left(const struct sshkey *);
31919261079SEd Maste int	 sshkey_forward_state(const struct sshkey *, u_int32_t, int);
32019261079SEd Maste int	 sshkey_private_serialize_maxsign(struct sshkey *key,
32119261079SEd Maste     struct sshbuf *buf, u_int32_t maxsign, int);
32219261079SEd Maste 
32319261079SEd Maste void	 sshkey_sig_details_free(struct sshkey_sig_details *);
32447dd1d1bSDag-Erling Smørgrav 
325a0ee8cc6SDag-Erling Smørgrav #ifdef SSHKEY_INTERNAL
326f374ba41SEd Maste int	sshkey_sk_fields_equal(const struct sshkey *a, const struct sshkey *b);
327f374ba41SEd Maste void	sshkey_sk_cleanup(struct sshkey *k);
328f374ba41SEd Maste int	sshkey_serialize_sk(const struct sshkey *key, struct sshbuf *b);
329f374ba41SEd Maste int	sshkey_copy_public_sk(const struct sshkey *from, struct sshkey *to);
330f374ba41SEd Maste int	sshkey_deserialize_sk(struct sshbuf *b, struct sshkey *key);
331f374ba41SEd Maste int	sshkey_serialize_private_sk(const struct sshkey *key,
332f374ba41SEd Maste     struct sshbuf *buf);
333f374ba41SEd Maste int	sshkey_private_deserialize_sk(struct sshbuf *buf, struct sshkey *k);
334f374ba41SEd Maste #ifdef WITH_OPENSSL
335f374ba41SEd Maste int	check_rsa_length(const RSA *rsa); /* XXX remove */
336f374ba41SEd Maste #endif
337a0ee8cc6SDag-Erling Smørgrav #endif
338a0ee8cc6SDag-Erling Smørgrav 
339a0ee8cc6SDag-Erling Smørgrav #if !defined(WITH_OPENSSL)
340a0ee8cc6SDag-Erling Smørgrav # undef RSA
341a0ee8cc6SDag-Erling Smørgrav # undef DSA
342a0ee8cc6SDag-Erling Smørgrav # undef EC_KEY
343a0ee8cc6SDag-Erling Smørgrav # undef EC_GROUP
344a0ee8cc6SDag-Erling Smørgrav # undef EC_POINT
345a0ee8cc6SDag-Erling Smørgrav #elif !defined(OPENSSL_HAS_ECC)
346a0ee8cc6SDag-Erling Smørgrav # undef EC_KEY
347a0ee8cc6SDag-Erling Smørgrav # undef EC_GROUP
348a0ee8cc6SDag-Erling Smørgrav # undef EC_POINT
349a0ee8cc6SDag-Erling Smørgrav #endif
350a0ee8cc6SDag-Erling Smørgrav 
351a0ee8cc6SDag-Erling Smørgrav #endif /* SSHKEY_H */
352