Xuyi Wang / wolfcrypt

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wolfmath.h Source File

wolfmath.h

00001 /* wolfmath.h
00002  *
00003  * Copyright (C) 2006-2017 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 #if defined(HAVE_WOLF_BIGINT) && !defined(WOLF_BIGINT_DEFINED)
00023     /* raw big integer */
00024     typedef struct WC_BIGINT {
00025         byte*   buf;
00026         word32  len;
00027         void*   heap;
00028     } WC_BIGINT;
00029 
00030     #define WOLF_BIGINT_DEFINED
00031 #endif
00032 
00033 
00034 /* only define functions if mp_int has been declared */
00035 #ifdef MP_INT_DEFINED
00036 
00037 #ifndef __WOLFMATH_H__
00038 #define __WOLFMATH_H__
00039 
00040     /* timing resistance array */
00041     #if !defined(WC_NO_CACHE_RESISTANT) && \
00042         ((defined(HAVE_ECC) && defined(ECC_TIMING_RESISTANT)) || \
00043          (defined(USE_FAST_MATH) && defined(TFM_TIMING_RESISTANT)))
00044 
00045         extern const wolfssl_word wc_off_on_addr[2];
00046     #endif
00047 
00048     /* common math functions */
00049     int get_digit_count(mp_int* a);
00050     mp_digit get_digit(mp_int* a, int n);
00051     int get_rand_digit(WC_RNG* rng, mp_digit* d);
00052     int mp_rand(mp_int* a, int digits, WC_RNG* rng);
00053 
00054 
00055     #ifdef HAVE_WOLF_BIGINT
00056         void wc_bigint_init(WC_BIGINT* a);
00057         int wc_bigint_alloc(WC_BIGINT* a, word32 sz);
00058         int wc_bigint_from_unsigned_bin(WC_BIGINT* a, const byte* in, word32 inlen);
00059         int wc_bigint_to_unsigned_bin(WC_BIGINT* a, byte* out, word32* outlen);
00060         void wc_bigint_zero(WC_BIGINT* a);
00061         void wc_bigint_free(WC_BIGINT* a);
00062 
00063         int wc_mp_to_bigint(mp_int* src, WC_BIGINT* dst);
00064         int wc_mp_to_bigint_sz(mp_int* src, WC_BIGINT* dst, word32 sz);
00065         int wc_bigint_to_mp(WC_BIGINT* src, mp_int* dst);
00066     #endif /* HAVE_WOLF_BIGINT */
00067 
00068 #endif /* __WOLFMATH_H__ */
00069 
00070 #endif /* MP_INT_DEFINED */
00071