1323124Sdes/* $OpenBSD: dh.h,v 1.15 2016/05/02 10:26:04 djm Exp $ */
276259Sgreen
369587Sgreen/*
469587Sgreen * Copyright (c) 2000 Niels Provos.  All rights reserved.
569587Sgreen *
669587Sgreen * Redistribution and use in source and binary forms, with or without
769587Sgreen * modification, are permitted provided that the following conditions
869587Sgreen * are met:
969587Sgreen * 1. Redistributions of source code must retain the above copyright
1069587Sgreen *    notice, this list of conditions and the following disclaimer.
1169587Sgreen * 2. Redistributions in binary form must reproduce the above copyright
1269587Sgreen *    notice, this list of conditions and the following disclaimer in the
1369587Sgreen *    documentation and/or other materials provided with the distribution.
1469587Sgreen *
1569587Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1669587Sgreen * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1769587Sgreen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1869587Sgreen * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1969587Sgreen * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2069587Sgreen * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2169587Sgreen * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2269587Sgreen * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2369587Sgreen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2469587Sgreen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2569587Sgreen */
2669587Sgreen#ifndef DH_H
2769587Sgreen#define DH_H
2869587Sgreen
2969587Sgreenstruct dhgroup {
3069587Sgreen	int size;
3169587Sgreen	BIGNUM *g;
3269587Sgreen	BIGNUM *p;
3369587Sgreen};
3469587Sgreen
3592555SdesDH	*choose_dh(int, int, int);
3676259SgreenDH	*dh_new_group_asc(const char *, const char *);
3776259SgreenDH	*dh_new_group(BIGNUM *, BIGNUM *);
3876259SgreenDH	*dh_new_group1(void);
39137015SdesDH	*dh_new_group14(void);
40323124SdesDH	*dh_new_group16(void);
41323124SdesDH	*dh_new_group18(void);
42295367SdesDH	*dh_new_group_fallback(int);
4369587Sgreen
44295367Sdesint	 dh_gen_key(DH *, int);
4592555Sdesint	 dh_pub_is_valid(DH *, BIGNUM *);
4676259Sgreen
47295367Sdesu_int	 dh_estimate(int);
4876259Sgreen
49296781Sdes/*
50296781Sdes * Max value from RFC4419.
51296781Sdes * Miniumum increased in light of DH precomputation attacks.
52296781Sdes */
53296781Sdes#define DH_GRP_MIN	2048
5476259Sgreen#define DH_GRP_MAX	8192
5576259Sgreen
56181111Sdes/*
57181111Sdes * Values for "type" field of moduli(5)
58181111Sdes * Specifies the internal structure of the prime modulus.
59181111Sdes */
60181111Sdes#define MODULI_TYPE_UNKNOWN		(0)
61181111Sdes#define MODULI_TYPE_UNSTRUCTURED	(1)
62181111Sdes#define MODULI_TYPE_SAFE		(2)
63181111Sdes#define MODULI_TYPE_SCHNORR		(3)
64181111Sdes#define MODULI_TYPE_SOPHIE_GERMAIN	(4)
65181111Sdes#define MODULI_TYPE_STRONG		(5)
66181111Sdes
67181111Sdes/*
68181111Sdes * Values for "tests" field of moduli(5)
69181111Sdes * Specifies the methods used in checking for primality.
70181111Sdes * Usually, more than one test is used.
71181111Sdes */
72181111Sdes#define MODULI_TESTS_UNTESTED		(0x00)
73181111Sdes#define MODULI_TESTS_COMPOSITE		(0x01)
74181111Sdes#define MODULI_TESTS_SIEVE		(0x02)
75181111Sdes#define MODULI_TESTS_MILLER_RABIN	(0x04)
76181111Sdes#define MODULI_TESTS_JACOBI		(0x08)
77181111Sdes#define MODULI_TESTS_ELLIPTIC		(0x10)
78181111Sdes
79181111Sdes
8069587Sgreen#endif
81