1 /* $OpenBSD: dh.h,v 1.10 2017/11/08 13:33:49 patrick 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_H_ 20 #define _DH_H_ 21 22 enum group_type { 23 GROUP_MODP = 0, 24 GROUP_EC2N = 1, 25 GROUP_ECP = 2 26 }; 27 28 struct group_id { 29 enum group_type type; 30 u_int id; 31 int bits; 32 char *prime; 33 char *generator; 34 int nid; 35 }; 36 37 struct group { 38 int id; 39 struct group_id *spec; 40 41 void *dh; 42 void *ec; 43 44 int (*init)(struct group *); 45 int (*getlen)(struct group *); 46 int (*secretlen)(struct group *); 47 int (*exchange)(struct group *, u_int8_t *); 48 int (*shared)(struct group *, u_int8_t *, u_int8_t *); 49 }; 50 51 #define DH_MAXSZ 1024 /* 8192 bits */ 52 53 void group_init(void); 54 void group_free(struct group *); 55 struct group *group_get(u_int32_t); 56 57 int dh_getlen(struct group *); 58 int dh_secretlen(struct group *); 59 int dh_create_exchange(struct group *, u_int8_t *); 60 int dh_create_shared(struct group *, u_int8_t *, u_int8_t *); 61 62 #endif /* _DH_H_ */ 63