1/*
2 * Copyright (c) 2006 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the Institute nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34/*
35 * $Id$
36 */
37
38#ifndef _HEIM_BN_H
39#define _HEIM_BN_H 1
40
41/* symbol renaming */
42#define BN_GENCB_call hc_BN_GENCB_call
43#define BN_GENCB_set hc_BN_GENCB_set
44#define BN_bin2bn hc_BN_bin2bn
45#define BN_bn2bin hc_BN_bn2bin
46#define BN_bn2hex hc_BN_bn2hex
47#define BN_clear hc_BN_clear
48#define BN_clear_bit hc_BN_clear_bit
49#define BN_clear_free hc_BN_clear_free
50#define BN_cmp hc_BN_cmp
51#define BN_dup hc_BN_dup
52#define BN_free hc_BN_free
53#define BN_is_negative hc_BN_is_negative
54#define BN_get_word hc_BN_get_word
55#define BN_hex2bn hc_BN_hex2bn
56#define BN_is_bit_set hc_BN_is_bit_set
57#define BN_new hc_BN_new
58#define BN_num_bits hc_BN_num_bits
59#define BN_num_bytes hc_BN_num_bytes
60#define BN_rand hc_BN_rand
61#define BN_set_bit hc_BN_set_bit
62#define BN_set_negative hc_BN_set_negative
63#define BN_set_word hc_BN_set_word
64#define BN_uadd hc_BN_uadd
65#define BN_CTX_new hc_BN_CTX_new
66#define BN_CTX_free hc_BN_CTX_free
67#define BN_CTX_get hc_BN_CTX_get
68#define BN_CTX_start hc_BN_CTX_start
69#define BN_CTX_end hc_BN_CTX_end
70
71/*
72 *
73 */
74
75typedef struct BIGNUM BIGNUM;
76typedef struct BN_GENCB BN_GENCB;
77typedef struct BN_CTX BN_CTX;
78typedef struct BN_MONT_CTX BN_MONT_CTX;
79typedef struct BN_BLINDING BN_BLINDING;
80
81struct BN_GENCB {
82    unsigned int ver;
83    void *arg;
84    union {
85	int (*cb_2)(int, int, BN_GENCB *);
86    } cb;
87};
88
89/*
90 *
91 */
92
93BIGNUM *BN_new(void);
94void	BN_free(BIGNUM *);
95void	BN_clear_free(BIGNUM *);
96void	BN_clear(BIGNUM *);
97BIGNUM *BN_dup(const BIGNUM *);
98
99int	BN_num_bits(const BIGNUM *);
100int	BN_num_bytes(const BIGNUM *);
101
102int	BN_cmp(const BIGNUM *, const BIGNUM *);
103
104void	BN_set_negative(BIGNUM *, int);
105int	BN_is_negative(const BIGNUM *);
106
107int	BN_is_bit_set(const BIGNUM *, int);
108int	BN_set_bit(BIGNUM *, int);
109int	BN_clear_bit(BIGNUM *, int);
110
111int	BN_set_word(BIGNUM *, unsigned long);
112unsigned long BN_get_word(const BIGNUM *);
113
114BIGNUM *BN_bin2bn(const void *,int len,BIGNUM *);
115int	BN_bn2bin(const BIGNUM *, void *);
116int 	BN_hex2bn(BIGNUM **, const char *);
117char *	BN_bn2hex(const BIGNUM *);
118
119int	BN_uadd(BIGNUM *, const BIGNUM *, const BIGNUM *);
120
121int	BN_rand(BIGNUM *, int, int, int);
122
123void	BN_GENCB_set(BN_GENCB *, int (*)(int, int, BN_GENCB *), void *);
124int	BN_GENCB_call(BN_GENCB *, int, int);
125
126BN_CTX *BN_CTX_new(void);
127void	BN_CTX_free(BN_CTX *);
128BIGNUM *BN_CTX_get(BN_CTX *);
129void	BN_CTX_start(BN_CTX *);
130void	BN_CTX_end(BN_CTX *);
131
132#endif
133