1*f2c2b5e4Spatrick /* $OpenBSD: dh.h,v 1.10 2017/11/08 13:33:49 patrick Exp $ */ 22040585eSniklas 32040585eSniklas /* 48978eb1dSreyk * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> 52040585eSniklas * 6fefcb31aSreyk * Permission to use, copy, modify, and distribute this software for any 7fefcb31aSreyk * purpose with or without fee is hereby granted, provided that the above 8fefcb31aSreyk * copyright notice and this permission notice appear in all copies. 92040585eSniklas * 10fefcb31aSreyk * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11fefcb31aSreyk * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12fefcb31aSreyk * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13fefcb31aSreyk * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14fefcb31aSreyk * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15fefcb31aSreyk * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16fefcb31aSreyk * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 172040585eSniklas */ 182040585eSniklas 192040585eSniklas #ifndef _DH_H_ 202040585eSniklas #define _DH_H_ 212040585eSniklas 22fefcb31aSreyk enum group_type { 23fefcb31aSreyk GROUP_MODP = 0, 24fefcb31aSreyk GROUP_EC2N = 1, 25fefcb31aSreyk GROUP_ECP = 2 26fefcb31aSreyk }; 272040585eSniklas 28fefcb31aSreyk struct group_id { 29fefcb31aSreyk enum group_type type; 30fefcb31aSreyk u_int id; 31fefcb31aSreyk int bits; 32fefcb31aSreyk char *prime; 33fefcb31aSreyk char *generator; 34fefcb31aSreyk int nid; 35fefcb31aSreyk }; 36fefcb31aSreyk 37fefcb31aSreyk struct group { 38fefcb31aSreyk int id; 39fefcb31aSreyk struct group_id *spec; 40fefcb31aSreyk 41fefcb31aSreyk void *dh; 42fefcb31aSreyk void *ec; 43fefcb31aSreyk 44fefcb31aSreyk int (*init)(struct group *); 45fefcb31aSreyk int (*getlen)(struct group *); 46*f2c2b5e4Spatrick int (*secretlen)(struct group *); 47fefcb31aSreyk int (*exchange)(struct group *, u_int8_t *); 48fefcb31aSreyk int (*shared)(struct group *, u_int8_t *, u_int8_t *); 49fefcb31aSreyk }; 50fefcb31aSreyk 51fefcb31aSreyk #define DH_MAXSZ 1024 /* 8192 bits */ 52fefcb31aSreyk 53fefcb31aSreyk void group_init(void); 54fefcb31aSreyk void group_free(struct group *); 55fefcb31aSreyk struct group *group_get(u_int32_t); 562040585eSniklas 572040585eSniklas int dh_getlen(struct group *); 58*f2c2b5e4Spatrick int dh_secretlen(struct group *); 597b3cce79Sniklas int dh_create_exchange(struct group *, u_int8_t *); 607b3cce79Sniklas int dh_create_shared(struct group *, u_int8_t *, u_int8_t *); 612040585eSniklas 622040585eSniklas #endif /* _DH_H_ */ 63