1 | /* wolfmath.h
|
---|
2 | *
|
---|
3 | * Copyright (C) 2006-2017 wolfSSL Inc.
|
---|
4 | *
|
---|
5 | * This file is part of wolfSSL.
|
---|
6 | *
|
---|
7 | * wolfSSL is free software; you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation; either version 2 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * wolfSSL is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with this program; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | #if defined(HAVE_WOLF_BIGINT) && !defined(WOLF_BIGINT_DEFINED)
|
---|
23 | /* raw big integer */
|
---|
24 | typedef struct WC_BIGINT {
|
---|
25 | byte* buf;
|
---|
26 | word32 len;
|
---|
27 | void* heap;
|
---|
28 | } WC_BIGINT;
|
---|
29 |
|
---|
30 | #define WOLF_BIGINT_DEFINED
|
---|
31 | #endif
|
---|
32 |
|
---|
33 |
|
---|
34 | /* only define functions if mp_int has been declared */
|
---|
35 | #ifdef MP_INT_DEFINED
|
---|
36 |
|
---|
37 | #ifndef __WOLFMATH_H__
|
---|
38 | #define __WOLFMATH_H__
|
---|
39 |
|
---|
40 | /* timing resistance array */
|
---|
41 | #if !defined(WC_NO_CACHE_RESISTANT) && \
|
---|
42 | ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \
|
---|
43 | (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))
|
---|
44 |
|
---|
45 | extern const wolfssl_word wc_off_on_addr[2];
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | /* common math functions */
|
---|
49 | int get_digit_count(mp_int* a);
|
---|
50 | mp_digit get_digit(mp_int* a, int n);
|
---|
51 | int get_rand_digit(WC_RNG* rng, mp_digit* d);
|
---|
52 | int mp_rand(mp_int* a, int digits, WC_RNG* rng);
|
---|
53 |
|
---|
54 | enum {
|
---|
55 | /* format type */
|
---|
56 | WC_TYPE_HEX_STR = 1,
|
---|
57 | WC_TYPE_UNSIGNED_BIN = 2,
|
---|
58 | };
|
---|
59 |
|
---|
60 | WOLFSSL_API int wc_export_int(mp_int* mp, byte* buf, word32* len,
|
---|
61 | word32 keySz, int encType);
|
---|
62 |
|
---|
63 | #ifdef HAVE_WOLF_BIGINT
|
---|
64 | void wc_bigint_init(WC_BIGINT* a);
|
---|
65 | int wc_bigint_alloc(WC_BIGINT* a, word32 sz);
|
---|
66 | int wc_bigint_from_unsigned_bin(WC_BIGINT* a, const byte* in, word32 inlen);
|
---|
67 | int wc_bigint_to_unsigned_bin(WC_BIGINT* a, byte* out, word32* outlen);
|
---|
68 | void wc_bigint_zero(WC_BIGINT* a);
|
---|
69 | void wc_bigint_free(WC_BIGINT* a);
|
---|
70 |
|
---|
71 | int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst);
|
---|
72 | int wc_mp_to_bigint_sz(mp_int* src, WC_BIGINT* dst, word32 sz);
|
---|
73 | int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst);
|
---|
74 | #endif /* HAVE_WOLF_BIGINT */
|
---|
75 |
|
---|
76 | #endif /* __WOLFMATH_H__ */
|
---|
77 |
|
---|
78 | #endif /* MP_INT_DEFINED */
|
---|