source: branches/samba-3.5.x/source4/heimdal/lib/hcrypto/rsa.h

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 5.5 KB
Line 
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_RSA_H
39#define _HEIM_RSA_H 1
40
41/* symbol renaming */
42#define RSA_null_method hc_RSA_null_method
43#define RSA_imath_method hc_RSA_imath_method
44#define RSA_gmp_method hc_RSA_gmp_method
45#define RSA_new hc_RSA_new
46#define RSA_new_method hc_RSA_new_method
47#define RSA_free hc_RSA_free
48#define RSA_up_ref hc_RSA_up_ref
49#define RSA_set_default_method hc_RSA_set_default_method
50#define RSA_get_default_method hc_RSA_get_default_method
51#define RSA_set_method hc_RSA_set_method
52#define RSA_get_method hc_RSA_get_method
53#define RSA_set_app_data hc_RSA_set_app_data
54#define RSA_get_app_data hc_RSA_get_app_data
55#define RSA_check_key hc_RSA_check_key
56#define RSA_size hc_RSA_size
57#define RSA_public_encrypt hc_RSA_public_encrypt
58#define RSA_public_decrypt hc_RSA_public_decrypt
59#define RSA_private_encrypt hc_RSA_private_encrypt
60#define RSA_private_decrypt hc_RSA_private_decrypt
61#define RSA_sign hc_RSA_sign
62#define RSA_verify hc_RSA_verify
63#define RSA_generate_key_ex hc_RSA_generate_key_ex
64#define d2i_RSAPrivateKey hc_d2i_RSAPrivateKey
65#define i2d_RSAPrivateKey hc_i2d_RSAPrivateKey
66#define i2d_RSAPublicKey hc_i2d_RSAPublicKey
67
68/*
69 *
70 */
71
72typedef struct RSA RSA;
73typedef struct RSA_METHOD RSA_METHOD;
74
75#include <hcrypto/bn.h>
76#include <hcrypto/engine.h>
77
78struct RSA_METHOD {
79 const char *name;
80 int (*rsa_pub_enc)(int,const unsigned char *, unsigned char *, RSA *,int);
81 int (*rsa_pub_dec)(int,const unsigned char *, unsigned char *, RSA *,int);
82 int (*rsa_priv_enc)(int,const unsigned char *, unsigned char *, RSA *,int);
83 int (*rsa_priv_dec)(int,const unsigned char *, unsigned char *, RSA *,int);
84 void *rsa_mod_exp;
85 void *bn_mod_exp;
86 int (*init)(RSA *rsa);
87 int (*finish)(RSA *rsa);
88 int flags;
89 char *app_data;
90 int (*rsa_sign)(int, const unsigned char *, unsigned int,
91 unsigned char *, unsigned int *, const RSA *);
92 int (*rsa_verify)(int, const unsigned char *, unsigned int,
93 unsigned char *, unsigned int, const RSA *);
94 int (*rsa_keygen)(RSA *, int, BIGNUM *, BN_GENCB *);
95};
96
97struct RSA {
98 int pad;
99 long version;
100 const RSA_METHOD *meth;
101 void *engine;
102 BIGNUM *n;
103 BIGNUM *e;
104 BIGNUM *d;
105 BIGNUM *p;
106 BIGNUM *q;
107 BIGNUM *dmp1;
108 BIGNUM *dmq1;
109 BIGNUM *iqmp;
110 struct rsa_CRYPTO_EX_DATA {
111 void *sk;
112 int dummy;
113 } ex_data;
114 int references;
115 int flags;
116 void *_method_mod_n;
117 void *_method_mod_p;
118 void *_method_mod_q;
119
120 char *bignum_data;
121 void *blinding;
122 void *mt_blinding;
123};
124
125#define RSA_FLAG_NO_BLINDING 0x0080
126
127#define RSA_PKCS1_PADDING 1
128#define RSA_PKCS1_OAEP_PADDING 4
129#define RSA_PKCS1_PADDING_SIZE 11
130
131/*
132 *
133 */
134
135const RSA_METHOD *RSA_null_method(void);
136const RSA_METHOD *RSA_imath_method(void);
137const RSA_METHOD *RSA_gmp_method(void);
138
139/*
140 *
141 */
142
143RSA * RSA_new(void);
144RSA * RSA_new_method(ENGINE *);
145void RSA_free(RSA *);
146int RSA_up_ref(RSA *);
147
148void RSA_set_default_method(const RSA_METHOD *);
149const RSA_METHOD * RSA_get_default_method(void);
150
151const RSA_METHOD * RSA_get_method(const RSA *);
152int RSA_set_method(RSA *, const RSA_METHOD *);
153
154int RSA_set_app_data(RSA *, void *arg);
155void * RSA_get_app_data(RSA *);
156
157int RSA_check_key(const RSA *);
158int RSA_size(const RSA *);
159
160int RSA_public_encrypt(int,const unsigned char*,unsigned char*,RSA *,int);
161int RSA_private_encrypt(int,const unsigned char*,unsigned char*,RSA *,int);
162int RSA_public_decrypt(int,const unsigned char*,unsigned char*,RSA *,int);
163int RSA_private_decrypt(int,const unsigned char*,unsigned char*,RSA *,int);
164
165int RSA_sign(int, const unsigned char *, unsigned int,
166 unsigned char *, unsigned int *, RSA *);
167int RSA_verify(int, const unsigned char *, unsigned int,
168 unsigned char *, unsigned int, RSA *);
169
170int RSA_generate_key_ex(RSA *, int, BIGNUM *, BN_GENCB *);
171
172RSA * d2i_RSAPrivateKey(RSA *, const unsigned char **, size_t);
173int i2d_RSAPrivateKey(RSA *, unsigned char **);
174
175int i2d_RSAPublicKey(RSA *, unsigned char **);
176
177#endif /* _HEIM_RSA_H */
Note: See TracBrowser for help on using the repository browser.