comctl32: Set label width after editting.
[wine] / dlls / rsaenh / tomcrypt.h
1 /*
2  * dlls/rsaenh/tomcrypt.h
3  * Function prototypes, type definitions and constant definitions
4  * for LibTomCrypt code.
5  *
6  * Copyright 2004 Michael Jung
7  * Based on public domain code by Tom St Denis (tomstdenis@iahu.ca)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public 
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 /*
25  * This file contains code from the LibTomCrypt cryptographic 
26  * library written by Tom St Denis (tomstdenis@iahu.ca). LibTomCrypt
27  * is in the public domain. The code in this file is tailored to
28  * special requirements. Take a look at http://libtomcrypt.org for the
29  * original version. 
30  */
31
32 #ifndef __WINE_TOMCRYPT_H_
33 #define __WINE_TOMCRYPT_H_
34
35 #include <stdio.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <limits.h>
39 #include "basetsd.h"
40
41 /* error codes [will be expanded in future releases] */
42 enum {
43    CRYPT_OK=0,             /* Result OK */
44    CRYPT_ERROR,            /* Generic Error */
45    CRYPT_NOP,              /* Not a failure but no operation was performed */
46
47    CRYPT_INVALID_KEYSIZE,  /* Invalid key size given */
48    CRYPT_INVALID_ROUNDS,   /* Invalid number of rounds */
49    CRYPT_FAIL_TESTVECTOR,  /* Algorithm failed test vectors */
50
51    CRYPT_BUFFER_OVERFLOW,  /* Not enough space for output */
52    CRYPT_INVALID_PACKET,   /* Invalid input packet given */
53
54    CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */
55    CRYPT_ERROR_READPRNG,   /* Could not read enough from PRNG */
56
57    CRYPT_INVALID_CIPHER,   /* Invalid cipher specified */
58    CRYPT_INVALID_HASH,     /* Invalid hash specified */
59    CRYPT_INVALID_PRNG,     /* Invalid PRNG specified */
60
61    CRYPT_MEM,              /* Out of memory */
62
63    CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */
64    CRYPT_PK_NOT_PRIVATE,   /* Requires a private PK key */
65
66    CRYPT_INVALID_ARG,      /* Generic invalid argument */
67    CRYPT_FILE_NOTFOUND,    /* File Not Found */
68
69    CRYPT_PK_INVALID_TYPE,  /* Invalid type of PK key */
70    CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */
71    CRYPT_PK_DUP,           /* Duplicate key already in key ring */
72    CRYPT_PK_NOT_FOUND,     /* Key not found in keyring */
73    CRYPT_PK_INVALID_SIZE,  /* Invalid size input for PK parameters */
74
75    CRYPT_INVALID_PRIME_SIZE/* Invalid size of prime requested */
76 };
77
78 #define CONST64(a,b) ((((ULONG64)(a)) << 32) | (b))
79 typedef ULONG64 ulong64;
80
81 /* this is the "32-bit at least" data type 
82  * Re-define it to suit your platform but it must be at least 32-bits 
83  */
84 typedef ULONG32 ulong32;
85
86 /* ---- HELPER MACROS ---- */
87 #define STORE32H(x, y)                                                                     \
88      { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned char)(((x)>>16)&255);   \
89        (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned char)((x)&255); }
90
91 #define LOAD32H(x, y)                            \
92      { x = ((unsigned long)((y)[0] & 255)<<24) | \
93            ((unsigned long)((y)[1] & 255)<<16) | \
94            ((unsigned long)((y)[2] & 255)<<8)  | \
95            ((unsigned long)((y)[3] & 255)); }
96
97 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && !defined(INTEL_CC)
98
99 static inline unsigned ROR(unsigned word, int i)
100 {
101    __asm__("rorl %%cl,%0"
102       :"=r" (word)
103       :"0" (word),"c" (i));
104    return word;
105 }
106
107 #else
108
109 /* rotates the hard way */
110 #define ROR(x, y) ( ((((unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)((y)&31)) | \
111                     ((unsigned long)(x)<<(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL)
112
113 #endif
114
115 #undef MIN
116 #define MIN(x, y) ( ((x)<(y))?(x):(y) )
117
118 #define byte(x, n) (((x) >> (8 * (n))) & 255)
119
120 typedef struct tag_rc2_key { 
121         unsigned xkey[64]; 
122 } rc2_key;
123
124 typedef struct tag_des_key {
125     ulong32 ek[32], dk[32];
126 } des_key;
127
128 typedef struct tag_des3_key {
129     ulong32 ek[3][32], dk[3][32];
130 } des3_key;
131
132 int rc2_setup(const unsigned char *key, int keylen, int bits, int num_rounds, rc2_key *skey);
133 void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, rc2_key *key);
134 void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, rc2_key *key);
135
136 int des_setup(const unsigned char *key, int keylen, int num_rounds, des_key *skey);
137 void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des_key *key);
138 void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des_key *key);
139
140 int des3_setup(const unsigned char *key, int keylen, int num_rounds, des3_key *skey);
141 void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des3_key *key);
142 void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des3_key *key);
143
144 typedef struct tag_md2_state {
145     unsigned char chksum[16], X[48], buf[16];
146     unsigned long curlen;
147 } md2_state;
148
149 int md2_init(md2_state * md);
150 int md2_process(md2_state * md, const unsigned char *buf, unsigned long len);
151 int md2_done(md2_state * md, unsigned char *hash);
152
153 struct rc4_prng {
154     int x, y;
155     unsigned char buf[256];
156 };
157
158 typedef union Prng_state {
159     struct rc4_prng       rc4;
160 } prng_state;
161
162 int rc4_start(prng_state *prng);
163 int rc4_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
164 int rc4_ready(prng_state *prng);
165 unsigned long rc4_read(unsigned char *buf, unsigned long len, prng_state *prng);
166
167 /* some default configurations.
168  *
169  * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
170  * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
171  *
172  * At the very least a mp_digit must be able to hold 7 bits
173  * [any size beyond that is ok provided it doesn't overflow the data type]
174  */
175 typedef unsigned long      mp_digit;
176 typedef ulong64            mp_word;
177 #define DIGIT_BIT 28
178    
179 #define MP_DIGIT_BIT     DIGIT_BIT
180 #define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
181 #define MP_DIGIT_MAX     MP_MASK
182
183 /* equalities */
184 #define MP_LT        -1   /* less than */
185 #define MP_EQ         0   /* equal to */
186 #define MP_GT         1   /* greater than */
187
188 #define MP_ZPOS       0   /* positive integer */
189 #define MP_NEG        1   /* negative */
190
191 #define MP_OKAY       0   /* ok result */
192 #define MP_MEM        -2  /* out of mem */
193 #define MP_VAL        -3  /* invalid input */
194 #define MP_RANGE      MP_VAL
195
196 #define MP_YES        1   /* yes response */
197 #define MP_NO         0   /* no response */
198
199 /* Primality generation flags */
200 #define LTM_PRIME_BBS      0x0001 /* BBS style prime */
201 #define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
202 #define LTM_PRIME_2MSB_OFF 0x0004 /* force 2nd MSB to 0 */
203 #define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
204
205 typedef int           mp_err;
206
207 /* define this to use lower memory usage routines (exptmods mostly) */
208 /* #define MP_LOW_MEM */
209
210 #define MP_PREC                 64     /* default digits of precision */
211
212 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
213 #define MP_WARRAY               (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
214
215 /* the infamous mp_int structure */
216 typedef struct  {
217     int used, alloc, sign;
218     mp_digit *dp;
219 } mp_int;
220
221 /* callback for mp_prime_random, should fill dst with random bytes and return how many read [up to len] */
222 typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
223
224 #define DIGIT(m,k) ((m)->dp[(k)])
225
226 /* error code to char* string */
227 char *mp_error_to_string(int code);
228
229 /* ---> init and deinit bignum functions <--- */
230 /* init a bignum */
231 int mp_init(mp_int *a);
232
233 /* free a bignum */
234 void mp_clear(mp_int *a);
235
236 /* init a null terminated series of arguments */
237 int mp_init_multi(mp_int *mp, ...);
238
239 /* clear a null terminated series of arguments */
240 void mp_clear_multi(mp_int *mp, ...);
241
242 /* exchange two ints */
243 void mp_exch(mp_int *a, mp_int *b);
244
245 /* shrink ram required for a bignum */
246 int mp_shrink(mp_int *a);
247
248 /* grow an int to a given size */
249 int mp_grow(mp_int *a, int size);
250
251 /* init to a given number of digits */
252 int mp_init_size(mp_int *a, int size);
253
254 /* ---> Basic Manipulations <--- */
255 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
256 #define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
257 #define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
258
259 /* set to zero */
260 void mp_zero(mp_int *a);
261
262 /* set to a digit */
263 void mp_set(mp_int *a, mp_digit b);
264
265 /* set a 32-bit const */
266 int mp_set_int(mp_int *a, unsigned long b);
267
268 /* get a 32-bit value */
269 unsigned long mp_get_int(mp_int * a);
270
271 /* initialize and set a digit */
272 int mp_init_set (mp_int * a, mp_digit b);
273
274 /* initialize and set 32-bit value */
275 int mp_init_set_int (mp_int * a, unsigned long b);
276
277 /* copy, b = a */
278 int mp_copy(const mp_int *a, mp_int *b);
279
280 /* inits and copies, a = b */
281 int mp_init_copy(mp_int *a, const mp_int *b);
282
283 /* trim unused digits */
284 void mp_clamp(mp_int *a);
285
286 /* ---> digit manipulation <--- */
287
288 /* right shift by "b" digits */
289 void mp_rshd(mp_int *a, int b);
290
291 /* left shift by "b" digits */
292 int mp_lshd(mp_int *a, int b);
293
294 /* c = a / 2**b */
295 int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
296
297 /* b = a/2 */
298 int mp_div_2(mp_int *a, mp_int *b);
299
300 /* c = a * 2**b */
301 int mp_mul_2d(mp_int *a, int b, mp_int *c);
302
303 /* b = a*2 */
304 int mp_mul_2(mp_int *a, mp_int *b);
305
306 /* c = a mod 2**d */
307 int mp_mod_2d(mp_int *a, int b, mp_int *c);
308
309 /* computes a = 2**b */
310 int mp_2expt(mp_int *a, int b);
311
312 /* Counts the number of lsbs which are zero before the first zero bit */
313 int mp_cnt_lsb(mp_int *a);
314
315 /* I Love Earth! */
316
317 /* makes a pseudo-random int of a given size */
318 int mp_rand(mp_int *a, int digits);
319
320 /* ---> binary operations <--- */
321 /* c = a XOR b  */
322 int mp_xor(mp_int *a, mp_int *b, mp_int *c);
323
324 /* c = a OR b */
325 int mp_or(mp_int *a, mp_int *b, mp_int *c);
326
327 /* c = a AND b */
328 int mp_and(mp_int *a, mp_int *b, mp_int *c);
329
330 /* ---> Basic arithmetic <--- */
331
332 /* b = -a */
333 int mp_neg(mp_int *a, mp_int *b);
334
335 /* b = |a| */
336 int mp_abs(mp_int *a, mp_int *b);
337
338 /* compare a to b */
339 int mp_cmp(mp_int *a, mp_int *b);
340
341 /* compare |a| to |b| */
342 int mp_cmp_mag(mp_int *a, mp_int *b);
343
344 /* c = a + b */
345 int mp_add(mp_int *a, mp_int *b, mp_int *c);
346
347 /* c = a - b */
348 int mp_sub(mp_int *a, mp_int *b, mp_int *c);
349
350 /* c = a * b */
351 int mp_mul(mp_int *a, mp_int *b, mp_int *c);
352
353 /* b = a*a  */
354 int mp_sqr(mp_int *a, mp_int *b);
355
356 /* a/b => cb + d == a */
357 int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
358
359 /* c = a mod b, 0 <= c < b  */
360 int mp_mod(mp_int *a, mp_int *b, mp_int *c);
361
362 /* ---> single digit functions <--- */
363
364 /* compare against a single digit */
365 int mp_cmp_d(mp_int *a, mp_digit b);
366
367 /* c = a + b */
368 int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
369
370 /* c = a - b */
371 int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
372
373 /* c = a * b */
374 int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
375
376 /* a/b => cb + d == a */
377 int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
378
379 /* a/3 => 3c + d == a */
380 int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
381
382 /* c = a**b */
383 int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
384
385 /* c = a mod b, 0 <= c < b  */
386 int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
387
388 /* ---> number theory <--- */
389
390 /* d = a + b (mod c) */
391 int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
392
393 /* d = a - b (mod c) */
394 int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
395
396 /* d = a * b (mod c) */
397 int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
398
399 /* c = a * a (mod b) */
400 int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
401
402 /* c = 1/a (mod b) */
403 int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
404
405 /* c = (a, b) */
406 int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
407
408 /* produces value such that U1*a + U2*b = U3 */
409 int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
410
411 /* c = [a, b] or (a*b)/(a, b) */
412 int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
413
414 /* finds one of the b'th root of a, such that |c|**b <= |a|
415  *
416  * returns error if a < 0 and b is even
417  */
418 int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
419
420 /* special sqrt algo */
421 int mp_sqrt(mp_int *arg, mp_int *ret);
422
423 /* is number a square? */
424 int mp_is_square(mp_int *arg, int *ret);
425
426 /* computes the jacobi c = (a | n) (or Legendre if b is prime)  */
427 int mp_jacobi(mp_int *a, mp_int *n, int *c);
428
429 /* used to setup the Barrett reduction for a given modulus b */
430 int mp_reduce_setup(mp_int *a, mp_int *b);
431
432 /* Barrett Reduction, computes a (mod b) with a precomputed value c
433  *
434  * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
435  * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
436  */
437 int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
438
439 /* setups the montgomery reduction */
440 int mp_montgomery_setup(mp_int *a, mp_digit *mp);
441
442 /* computes a = B**n mod b without division or multiplication useful for
443  * normalizing numbers in a Montgomery system.
444  */
445 int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
446
447 /* computes x/R == x (mod N) via Montgomery Reduction */
448 int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
449
450 /* returns 1 if a is a valid DR modulus */
451 int mp_dr_is_modulus(mp_int *a);
452
453 /* sets the value of "d" required for mp_dr_reduce */
454 void mp_dr_setup(mp_int *a, mp_digit *d);
455
456 /* reduces a modulo b using the Diminished Radix method */
457 int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
458
459 /* returns true if a can be reduced with mp_reduce_2k */
460 int mp_reduce_is_2k(mp_int *a);
461
462 /* determines k value for 2k reduction */
463 int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
464
465 /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
466 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
467
468 /* d = a**b (mod c) */
469 int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
470
471 /* ---> Primes <--- */
472
473 /* number of primes */
474 #define PRIME_SIZE      256
475
476 /* table of first PRIME_SIZE primes */
477 extern const mp_digit __prime_tab[];
478
479 /* result=1 if a is divisible by one of the first PRIME_SIZE primes */
480 int mp_prime_is_divisible(mp_int *a, int *result);
481
482 /* performs one Fermat test of "a" using base "b".
483  * Sets result to 0 if composite or 1 if probable prime
484  */
485 int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
486
487 /* performs one Miller-Rabin test of "a" using base "b".
488  * Sets result to 0 if composite or 1 if probable prime
489  */
490 int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
491
492 /* This gives [for a given bit size] the number of trials required
493  * such that Miller-Rabin gives a prob of failure lower than 2^-96 
494  */
495 int mp_prime_rabin_miller_trials(int size);
496
497 /* performs t rounds of Miller-Rabin on "a" using the first
498  * t prime bases.  Also performs an initial sieve of trial
499  * division.  Determines if "a" is prime with probability
500  * of error no more than (1/4)**t.
501  *
502  * Sets result to 1 if probably prime, 0 otherwise
503  */
504 int mp_prime_is_prime(mp_int *a, int t, int *result);
505
506 /* finds the next prime after the number "a" using "t" trials
507  * of Miller-Rabin.
508  *
509  * bbs_style = 1 means the prime must be congruent to 3 mod 4
510  */
511 int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
512
513 /* makes a truly random prime of a given size (bytes),
514  * call with bbs = 1 if you want it to be congruent to 3 mod 4 
515  *
516  * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
517  * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
518  * so it can be NULL
519  *
520  * The prime generated will be larger than 2^(8*size).
521  */
522 #define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
523
524 /* makes a truly random prime of a given size (bits),
525  *
526  * Flags are as follows:
527  * 
528  *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
529  *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
530  *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
531  *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
532  *
533  * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
534  * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
535  * so it can be NULL
536  *
537  */
538 int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
539
540 /* ---> radix conversion <--- */
541 int mp_count_bits(mp_int *a);
542
543 int mp_unsigned_bin_size(mp_int *a);
544 int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
545 int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
546
547 int mp_signed_bin_size(mp_int *a);
548 int mp_read_signed_bin(mp_int *a, unsigned char *b, int c);
549 int mp_to_signed_bin(mp_int *a, unsigned char *b);
550
551 int mp_read_radix(mp_int *a, char *str, int radix);
552 int mp_toradix(mp_int *a, char *str, int radix);
553 int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
554 int mp_radix_size(mp_int *a, int radix, int *size);
555
556 int mp_fread(mp_int *a, int radix, FILE *stream);
557 int mp_fwrite(mp_int *a, int radix, FILE *stream);
558
559 #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
560 #define mp_raw_size(mp)           mp_signed_bin_size(mp)
561 #define mp_toraw(mp, str)         mp_to_signed_bin((mp), (str))
562 #define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
563 #define mp_mag_size(mp)           mp_unsigned_bin_size(mp)
564 #define mp_tomag(mp, str)         mp_to_unsigned_bin((mp), (str))
565
566 #define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
567 #define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
568 #define mp_todecimal(M, S) mp_toradix((M), (S), 10)
569 #define mp_tohex(M, S)     mp_toradix((M), (S), 16)
570
571 /* lowlevel functions, do not call! */
572 int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
573 int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
574 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
575 int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
576 int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
577 int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
578 int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
579 int fast_s_mp_sqr(mp_int *a, mp_int *b);
580 int s_mp_sqr(mp_int *a, mp_int *b);
581 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
582 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
583 int mp_karatsuba_sqr(mp_int *a, mp_int *b);
584 int mp_toom_sqr(mp_int *a, mp_int *b);
585 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
586 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
587 int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
588 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
589 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
590 void bn_reverse(unsigned char *s, int len);
591
592 extern const char *mp_s_rmap;
593
594 #define PK_PRIVATE            0        /* PK private keys */
595 #define PK_PUBLIC             1        /* PK public keys */
596
597 /* Min and Max RSA key sizes (in bits) */
598 #define MIN_RSA_SIZE 384
599 #define MAX_RSA_SIZE 16384
600
601 typedef struct Rsa_key {
602     int type;
603     mp_int e, d, N, p, q, qP, dP, dQ;
604 } rsa_key;
605
606 int rsa_make_key(int size, long e, rsa_key *key);
607
608 int rsa_exptmod(const unsigned char *in,   unsigned long inlen,
609                       unsigned char *out,  unsigned long *outlen, int which,
610                       rsa_key *key);
611
612 void rsa_free(rsa_key *key);
613
614 #endif /* __WINE_TOMCRYPT_H_ */