1/* 2 * dh.h: Diffie-Hellman header file. 3 * 4 * Code copied from openssl distribution and 5 * Modified just enough so that compiles and runs standalone 6 * 7 * Copyright 2004, Broadcom Corporation 8 * All Rights Reserved. 9 * 10 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY 11 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM 12 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 13 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. 14 * 15 * $Id: dh.h,v 1.1.1.1 2008/10/15 03:31:22 james26_jang Exp $ 16 */ 17/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 18 * All rights reserved. 19 * 20 * This package is an SSL implementation written 21 * by Eric Young (eay@cryptsoft.com). 22 * The implementation was written so as to conform with Netscapes SSL. 23 * 24 * This library is free for commercial and non-commercial use as long as 25 * the following conditions are aheared to. The following conditions 26 * apply to all code found in this distribution, be it the RC4, RSA, 27 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 28 * included with this distribution is covered by the same copyright terms 29 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 30 * 31 * Copyright remains Eric Young's, and as such any Copyright notices in 32 * the code are not to be removed. 33 * If this package is used in a product, Eric Young should be given attribution 34 * as the author of the parts of the library used. 35 * This can be in the form of a textual message at program startup or 36 * in documentation (online or textual) provided with the package. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * "This product includes cryptographic software written by 49 * Eric Young (eay@cryptsoft.com)" 50 * The word 'cryptographic' can be left out if the rouines from the library 51 * being used are not cryptographic related :-). 52 * 4. If you include any Windows specific code (or a derivative thereof) from 53 * the apps directory (application code) you must include an acknowledgement: 54 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 55 * 56 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 59 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 66 * SUCH DAMAGE. 67 * 68 * The licence and distribution terms for any publically available version or 69 * derivative of this code cannot be changed. i.e. this code cannot simply be 70 * copied and put under another distribution licence 71 * [including the GNU Public Licence.] 72 */ 73 74#ifndef HEADER_DH_H 75#define HEADER_DH_H 76 77#include <bcmcrypto/bn.h> 78 79#define DH_FLAG_CACHE_MONT_P 0x01 80 81typedef struct dh_st 82 { 83 BIGNUM *p; 84 BIGNUM *g; 85 long length; /* optional */ 86 BIGNUM *pub_key; /* g^x */ 87 BIGNUM *priv_key; /* x */ 88 89 int flags; 90 char *method_mont_p; 91 /* Place holders if we want to do X9.42 DH */ 92 BIGNUM *q; 93 BIGNUM *j; 94 unsigned char *seed; 95 int seedlen; 96 BIGNUM *counter; 97 } DH; 98 99#define DH_GENERATOR_2 2 100/* #define DH_GENERATOR_3 3 */ 101#define DH_GENERATOR_5 5 102 103/* DH_check error codes */ 104#define DH_CHECK_P_NOT_PRIME 0x01 105#define DH_CHECK_P_NOT_SAFE_PRIME 0x02 106#define DH_UNABLE_TO_CHECK_GENERATOR 0x04 107#define DH_NOT_SUITABLE_GENERATOR 0x08 108 109/* primes p where (p-1)/2 is prime too are called "safe"; we define 110 this for backward compatibility: */ 111#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME 112 113 114DH * DH_new(void); 115void DH_free(DH *dh); 116int DH_generate_key(unsigned char *key,DH *dh); 117int DH_compute_key(unsigned char *key,unsigned char *pubbuf,int buflen,DH *dh); 118DH *DH_init(unsigned char *pbuf, int plen, int g); 119 120/* for standalone test purposes */ 121int DH_size(const DH *dh); 122DH * DH_generate_parameters(DH *dh, int prime_len,int generator, 123 void (*callback)(int,int,void *),void *cb_arg); 124int DH_check(const DH *dh,int *codes); 125 126#endif 127