source: azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/wolfssl/wolfcrypt/wolfmath.h@ 464

Last change on this file since 464 was 464, checked in by coas-nagasima, 3 years ago

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 2.9 KB
Line 
1/* wolfmath.h
2 *
3 * Copyright (C) 2006-2020 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/*
23DESCRIPTION
24This library provides big integer math functions.
25
26*/
27#ifndef __WOLFMATH_H__
28#define __WOLFMATH_H__
29
30#ifdef __cplusplus
31 extern "C" {
32#endif
33
34#ifdef WOLFSSL_PUBLIC_MP
35 #define MP_API WOLFSSL_API
36#else
37 #define MP_API WOLFSSL_LOCAL
38#endif
39
40#ifndef MIN
41 #define MIN(x,y) ((x)<(y)?(x):(y))
42#endif
43
44#ifndef MAX
45 #define MAX(x,y) ((x)>(y)?(x):(y))
46#endif
47
48/* timing resistance array */
49#if !defined(WC_NO_CACHE_RESISTANT) && \
50 ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \
51 (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))
52
53 extern const wolfssl_word wc_off_on_addr[2];
54#endif
55
56
57/* common math functions */
58MP_API int get_digit_count(mp_int* a);
59MP_API mp_digit get_digit(mp_int* a, int n);
60MP_API int get_rand_digit(WC_RNG* rng, mp_digit* d);
61
62WOLFSSL_API int mp_cond_copy(mp_int* a, int copy, mp_int* b);
63WOLFSSL_API int mp_rand(mp_int* a, int digits, WC_RNG* rng);
64
65enum {
66 /* format type */
67 WC_TYPE_HEX_STR = 1,
68 WC_TYPE_UNSIGNED_BIN = 2,
69};
70
71WOLFSSL_API int wc_export_int(mp_int* mp, byte* buf, word32* len,
72 word32 keySz, int encType);
73
74#ifdef HAVE_WOLF_BIGINT
75 #if !defined(WOLF_BIGINT_DEFINED)
76 /* raw big integer */
77 typedef struct WC_BIGINT {
78 byte* buf;
79 word32 len;
80 void* heap;
81 } WC_BIGINT;
82 #define WOLF_BIGINT_DEFINED
83 #endif
84
85 WOLFSSL_LOCAL void wc_bigint_init(WC_BIGINT* a);
86 WOLFSSL_LOCAL int wc_bigint_alloc(WC_BIGINT* a, word32 sz);
87 WOLFSSL_LOCAL int wc_bigint_from_unsigned_bin(WC_BIGINT* a, const byte* in, word32 inlen);
88 WOLFSSL_LOCAL int wc_bigint_to_unsigned_bin(WC_BIGINT* a, byte* out, word32* outlen);
89 WOLFSSL_LOCAL void wc_bigint_zero(WC_BIGINT* a);
90 WOLFSSL_LOCAL void wc_bigint_free(WC_BIGINT* a);
91
92 WOLFSSL_LOCAL int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst);
93 WOLFSSL_LOCAL int wc_mp_to_bigint_sz(mp_int* src, WC_BIGINT* dst, word32 sz);
94 WOLFSSL_LOCAL int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst);
95#endif /* HAVE_WOLF_BIGINT */
96
97
98#ifdef __cplusplus
99 } /* extern "C" */
100#endif
101
102#endif /* __WOLFMATH_H__ */
Note: See TracBrowser for help on using the repository browser.