xref: /openbsd-src/lib/libcrypto/dh/dh_local.h (revision 1507347831fea71816a2a2738e14838208eb78f0)
1*15073478Stb /* $OpenBSD: dh_local.h,v 1.7 2024/11/29 15:59:57 tb Exp $ */
2a69386beStb /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3a69386beStb  * All rights reserved.
4a69386beStb  *
5a69386beStb  * This package is an SSL implementation written
6a69386beStb  * by Eric Young (eay@cryptsoft.com).
7a69386beStb  * The implementation was written so as to conform with Netscapes SSL.
8a69386beStb  *
9a69386beStb  * This library is free for commercial and non-commercial use as long as
10a69386beStb  * the following conditions are aheared to.  The following conditions
11a69386beStb  * apply to all code found in this distribution, be it the RC4, RSA,
12a69386beStb  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13a69386beStb  * included with this distribution is covered by the same copyright terms
14a69386beStb  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15a69386beStb  *
16a69386beStb  * Copyright remains Eric Young's, and as such any Copyright notices in
17a69386beStb  * the code are not to be removed.
18a69386beStb  * If this package is used in a product, Eric Young should be given attribution
19a69386beStb  * as the author of the parts of the library used.
20a69386beStb  * This can be in the form of a textual message at program startup or
21a69386beStb  * in documentation (online or textual) provided with the package.
22a69386beStb  *
23a69386beStb  * Redistribution and use in source and binary forms, with or without
24a69386beStb  * modification, are permitted provided that the following conditions
25a69386beStb  * are met:
26a69386beStb  * 1. Redistributions of source code must retain the copyright
27a69386beStb  *    notice, this list of conditions and the following disclaimer.
28a69386beStb  * 2. Redistributions in binary form must reproduce the above copyright
29a69386beStb  *    notice, this list of conditions and the following disclaimer in the
30a69386beStb  *    documentation and/or other materials provided with the distribution.
31a69386beStb  * 3. All advertising materials mentioning features or use of this software
32a69386beStb  *    must display the following acknowledgement:
33a69386beStb  *    "This product includes cryptographic software written by
34a69386beStb  *     Eric Young (eay@cryptsoft.com)"
35a69386beStb  *    The word 'cryptographic' can be left out if the rouines from the library
36a69386beStb  *    being used are not cryptographic related :-).
37a69386beStb  * 4. If you include any Windows specific code (or a derivative thereof) from
38a69386beStb  *    the apps directory (application code) you must include an acknowledgement:
39a69386beStb  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40a69386beStb  *
41a69386beStb  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42a69386beStb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43a69386beStb  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44a69386beStb  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45a69386beStb  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46a69386beStb  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47a69386beStb  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48a69386beStb  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49a69386beStb  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50a69386beStb  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51a69386beStb  * SUCH DAMAGE.
52a69386beStb  *
53a69386beStb  * The licence and distribution terms for any publically available version or
54a69386beStb  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55a69386beStb  * copied and put under another distribution licence
56a69386beStb  * [including the GNU Public Licence.]
57a69386beStb  */
58a69386beStb 
59a69386beStb #ifndef HEADER_DH_LOCAL_H
60a69386beStb #define HEADER_DH_LOCAL_H
61a69386beStb 
62a69386beStb __BEGIN_HIDDEN_DECLS
63a69386beStb 
6434372826Stb struct dh_method {
6534372826Stb 	const char *name;
6634372826Stb 	/* Methods here */
6734372826Stb 	int (*generate_key)(DH *dh);
6834372826Stb 	int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh);
6934372826Stb 	int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a,
7034372826Stb 	    const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
7134372826Stb 	int (*init)(DH *dh);
7234372826Stb 	int (*finish)(DH *dh);
7334372826Stb 	int flags;
7434372826Stb 	char *app_data;
7534372826Stb 	/* If this is non-NULL, it will be used to generate parameters */
7634372826Stb 	int (*generate_params)(DH *dh, int prime_len, int generator,
7734372826Stb 	    BN_GENCB *cb);
7834372826Stb };
7934372826Stb 
8034372826Stb struct dh_st {
8134372826Stb 	int version;
8234372826Stb 	BIGNUM *p;
83*15073478Stb 	BIGNUM *q;
8434372826Stb 	BIGNUM *g;
8534372826Stb 	long length; /* optional */
8634372826Stb 	BIGNUM *pub_key;	/* g^x */
8734372826Stb 	BIGNUM *priv_key;	/* x */
8834372826Stb 
8934372826Stb 	int flags;
9034372826Stb 	BN_MONT_CTX *method_mont_p;
9134372826Stb 
9234372826Stb 	int references;
9334372826Stb 	CRYPTO_EX_DATA ex_data;
9434372826Stb 	const DH_METHOD *meth;
9534372826Stb };
9634372826Stb 
97a69386beStb __END_HIDDEN_DECLS
98a69386beStb 
99a69386beStb #endif /* !HEADER_DH_LOCAL_H */
100