micro-ECC for mbed, ported from GCC version from Github,

Dependents:   mbed_microECC Wallet_v1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers types.h Source File

types.h

00001 /* Copyright 2015, Kenneth MacKay. Licensed under the BSD 2-clause license. */
00002 
00003 #ifndef _UECC_TYPES_H_
00004 #define _UECC_TYPES_H_
00005 
00006 #ifndef uECC_PLATFORM
00007     #if __AVR__
00008         #define uECC_PLATFORM uECC_avr
00009     #elif defined(__thumb2__) || defined(_M_ARMT) /* I think MSVC only supports Thumb-2 targets */
00010         #define uECC_PLATFORM uECC_arm_thumb2
00011     #elif defined(__thumb__)
00012         #define uECC_PLATFORM uECC_arm_thumb
00013     #elif defined(__arm__) || defined(_M_ARM)
00014         #define uECC_PLATFORM uECC_arm
00015     #elif defined(__aarch64__)
00016         #define uECC_PLATFORM uECC_arm64
00017     #elif defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__I86__)
00018         #define uECC_PLATFORM uECC_x86
00019     #elif defined(__amd64__) || defined(_M_X64)
00020         #define uECC_PLATFORM uECC_x86_64
00021     #else
00022         #define uECC_PLATFORM uECC_arch_other
00023     #endif
00024 #endif
00025 
00026 #ifndef uECC_ARM_USE_UMAAL
00027     #if (uECC_PLATFORM == uECC_arm) && (__ARM_ARCH >= 6)
00028         #define uECC_ARM_USE_UMAAL 1
00029     #elif (uECC_PLATFORM == uECC_arm_thumb2) && (__ARM_ARCH >= 6) && !__ARM_ARCH_7M__
00030         #define uECC_ARM_USE_UMAAL 1
00031     #else
00032         #define uECC_ARM_USE_UMAAL 0
00033     #endif
00034 #endif
00035 
00036 #ifndef uECC_WORD_SIZE
00037     #if uECC_PLATFORM == uECC_avr
00038         #define uECC_WORD_SIZE 1
00039     #elif (uECC_PLATFORM == uECC_x86_64 || uECC_PLATFORM == uECC_arm64)
00040         #define uECC_WORD_SIZE 8
00041     #else
00042         #define uECC_WORD_SIZE 4
00043     #endif
00044 #endif
00045 
00046 #if (uECC_WORD_SIZE != 1) && (uECC_WORD_SIZE != 4) && (uECC_WORD_SIZE != 8)
00047     #error "Unsupported value for uECC_WORD_SIZE"
00048 #endif
00049 
00050 #if ((uECC_PLATFORM == uECC_avr) && (uECC_WORD_SIZE != 1))
00051     #pragma message ("uECC_WORD_SIZE must be 1 for AVR")
00052     #undef uECC_WORD_SIZE
00053     #define uECC_WORD_SIZE 1
00054 #endif
00055 
00056 #if ((uECC_PLATFORM == uECC_arm || uECC_PLATFORM == uECC_arm_thumb || \
00057         uECC_PLATFORM ==  uECC_arm_thumb2) && \
00058      (uECC_WORD_SIZE != 4))
00059     #pragma message ("uECC_WORD_SIZE must be 4 for ARM")
00060     #undef uECC_WORD_SIZE
00061     #define uECC_WORD_SIZE 4
00062 #endif
00063 
00064 #if defined(__SIZEOF_INT128__) || ((__clang_major__ * 100 + __clang_minor__) >= 302)
00065     #define SUPPORTS_INT128 1
00066 #else
00067     #define SUPPORTS_INT128 0
00068 #endif
00069 
00070 typedef int8_t wordcount_t;
00071 typedef int16_t bitcount_t;
00072 typedef int8_t cmpresult_t;
00073 
00074 #if (uECC_WORD_SIZE == 1)
00075 
00076 typedef uint8_t uECC_word_t;
00077 typedef uint16_t uECC_dword_t;
00078 
00079 #define HIGH_BIT_SET 0x80
00080 #define uECC_WORD_BITS 8
00081 #define uECC_WORD_BITS_SHIFT 3
00082 #define uECC_WORD_BITS_MASK 0x07
00083 
00084 #elif (uECC_WORD_SIZE == 4)
00085 
00086 typedef uint32_t uECC_word_t;
00087 typedef uint64_t uECC_dword_t;
00088 
00089 #define HIGH_BIT_SET 0x80000000
00090 #define uECC_WORD_BITS 32
00091 #define uECC_WORD_BITS_SHIFT 5
00092 #define uECC_WORD_BITS_MASK 0x01F
00093 
00094 #elif (uECC_WORD_SIZE == 8)
00095 
00096 typedef uint64_t uECC_word_t;
00097 #if SUPPORTS_INT128
00098 typedef unsigned __int128 uECC_dword_t;
00099 #endif
00100 
00101 #define HIGH_BIT_SET 0x8000000000000000ull
00102 #define uECC_WORD_BITS 64
00103 #define uECC_WORD_BITS_SHIFT 6
00104 #define uECC_WORD_BITS_MASK 0x03F
00105 
00106 #endif /* uECC_WORD_SIZE */
00107 
00108 #endif /* _UECC_TYPES_H_ */