xref: /openbsd/sbin/iked/dh.h (revision 9b50bc25)
1 /*	$OpenBSD: dh.h,v 1.15 2021/05/28 18:01:39 tobhe Exp $	*/
2 
3 /*
4  * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef DH_GROUP_H
20 #define DH_GROUP_H
21 
22 enum group_type {
23 	GROUP_MODP		= 0,
24 	GROUP_ECP		= 1,
25 	GROUP_CURVE25519	= 2,
26 	GROUP_SNTRUP761X25519	= 3
27 };
28 
29 struct group_id {
30 	enum group_type	 type;
31 	unsigned int	 id;
32 	int		 bits;
33 	char		*prime;
34 	char		*generator;
35 	int		 nid;
36 };
37 
38 struct dh_group {
39 	int		 id;
40 	const struct group_id
41 			*spec;
42 
43 	void		*dh;
44 	void		*ec;
45 	void		*curve25519;
46 	void		*kemsx;
47 
48 	int		(*init)(struct dh_group *);
49 	int		(*getlen)(struct dh_group *);
50 	int		(*secretlen)(struct dh_group *);
51 	int		(*exchange)(struct dh_group *, uint8_t *);
52 	int		(*exchange2)(struct dh_group *, struct ibuf **, struct ibuf *);
53 	int		(*shared)(struct dh_group *, uint8_t *, uint8_t *);
54 	int		(*shared2)(struct dh_group *, struct ibuf **, struct ibuf *);
55 };
56 
57 #define DH_MAXSZ	1024	/* 8192 bits */
58 
59 void		 group_init(void);
60 void		 group_free(struct dh_group *);
61 struct dh_group	*group_get(uint32_t);
62 const struct group_id
63 		*group_getid(uint32_t);
64 
65 int		 dh_create_exchange(struct dh_group *, struct ibuf **, struct ibuf *);
66 int		 dh_create_shared(struct dh_group *, struct ibuf **, struct ibuf *);
67 
68 #endif /* DH_GROUP_H */
69