ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
BigNumberUtil.h
1 /*
2  * Copyright (C) 2015 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef CRYPTO_BIGNUMBERUTIL_h
24 #define CRYPTO_BIGNUMBERUTIL_h
25 
26 #include <inttypes.h>
27 
28 // Define exactly one of these to 1 to set the size of the basic limb type.
29 // 16-bit limbs seem to give the best performance on 8-bit AVR micros.
30 #define BIGNUMBER_LIMB_8BIT 0
31 #define BIGNUMBER_LIMB_16BIT 1
32 #define BIGNUMBER_LIMB_32BIT 0
33 
34 // Define the limb types to use on this platform.
35 #if BIGNUMBER_LIMB_8BIT
36 typedef uint8_t limb_t;
37 typedef int8_t slimb_t;
38 typedef uint16_t dlimb_t;
39 #elif BIGNUMBER_LIMB_16BIT
40 typedef uint16_t limb_t;
41 typedef int16_t slimb_t;
42 typedef uint32_t dlimb_t;
43 #elif BIGNUMBER_LIMB_32BIT
44 typedef uint32_t limb_t;
45 typedef int32_t slimb_t;
46 typedef uint64_t dlimb_t;
47 #else
48 #error "limb_t must be 8, 16, or 32 bits in size"
49 #endif
50 
51 #endif