xref: /openbsd-src/sbin/iked/dh.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: dh.h,v 1.9 2015/08/21 11:59:27 reyk 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_EC2N		= 1,
25 	GROUP_ECP		= 2,
26 	GROUP_CURVE25519	= 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 group {
39 	int		 id;
40 	struct group_id	*spec;
41 
42 	void		*dh;
43 	void		*ec;
44 	void		*curve25519;
45 
46 	int		(*init)(struct group *);
47 	int		(*getlen)(struct group *);
48 	int		(*exchange)(struct group *, uint8_t *);
49 	int		(*shared)(struct group *, uint8_t *, uint8_t *);
50 };
51 
52 #define DH_MAXSZ	1024	/* 8192 bits */
53 
54 void		 group_init(void);
55 void		 group_free(struct group *);
56 struct group	*group_get(uint32_t);
57 
58 int		 dh_getlen(struct group *);
59 int		 dh_create_exchange(struct group *, uint8_t *);
60 int		 dh_create_shared(struct group *, uint8_t *, uint8_t *);
61 
62 #endif /* DH_GROUP_H */
63