New experimental EC implementation (P-256, only 32-bit multiplications, meant for Cortex-M0/M0+).
This commit is contained in:
parent
bf809dfae5
commit
6dd8c51ba7
7 changed files with 1092 additions and 3 deletions
19
src/config.h
19
src/config.h
|
|
@ -60,6 +60,25 @@
|
|||
#define BR_CT_MUL31 1
|
||||
*/
|
||||
|
||||
/*
|
||||
* When BR_CT_MUL15 is enabled, multiplications of 15-bit values (held
|
||||
* in 32-bit words) use an alternate implementation which is slower and
|
||||
* larger than the normal multiplication, but should ensure
|
||||
* constant-time multiplications on most/all architectures where the
|
||||
* basic multiplication is not constant-time.
|
||||
#define BR_CT_MUL15 1
|
||||
*/
|
||||
|
||||
/*
|
||||
* When BR_NO_ARITH_SHIFT is enabled, arithmetic right shifts (with sign
|
||||
* extension) are performed with a sequence of operations which is bigger
|
||||
* and slower than a simple right shift on a signed value. This avoids
|
||||
* relying on an implementation-defined behaviour. However, most if not
|
||||
* all C compilers use sign extension for right shifts on signed values,
|
||||
* so this alternate macro is disabled by default.
|
||||
#define BR_NO_ARITH_SHIFT 1
|
||||
*/
|
||||
|
||||
/*
|
||||
* When BR_USE_URANDOM is enabled, the SSL engine will use /dev/urandom
|
||||
* to automatically obtain quality randomness for seedings its internal
|
||||
|
|
|
|||
1006
src/ec/ec_p256_i15.c
Normal file
1006
src/ec/ec_p256_i15.c
Normal file
File diff suppressed because it is too large
Load diff
37
src/inner.h
37
src/inner.h
|
|
@ -549,6 +549,43 @@ MAX(uint32_t x, uint32_t y)
|
|||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Multiply two words together; each word may contain up to 15 bits of
|
||||
* data. If BR_CT_MUL15 is non-zero, then the macro will contain some
|
||||
* extra operations that help in making the operation constant-time on
|
||||
* some platforms, where the basic 32-bit multiplication is not
|
||||
* constant-time.
|
||||
*/
|
||||
#if BR_CT_MUL15
|
||||
#define MUL15(x, y) (((uint32_t)(x) | (uint32_t)0x80000000) \
|
||||
* ((uint32_t)(x) | (uint32_t)0x80000000) \
|
||||
& (uint32_t)0x3FFFFFFF)
|
||||
#else
|
||||
#define MUL15(x, y) ((uint32_t)(x) * (uint32_t)(y))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Arithmetic right shift (sign bit is copied). What happens when
|
||||
* right-shifting a negative value is _implementation-defined_, so it
|
||||
* does not trigger undefined behaviour, but it is still up to each
|
||||
* compiler to define (and document) what it does. Most/all compilers
|
||||
* will do an arithmetic shift, the sign bit being used to fill the
|
||||
* holes; this is a native operation on the underlying CPU, and it would
|
||||
* make little sense for the compiler to do otherwise. GCC explicitly
|
||||
* documents that it follows that convention.
|
||||
*
|
||||
* Still, if BR_NO_ARITH_SHIFT is defined (and non-zero), then an
|
||||
* alternate version will be used, that does not rely on such
|
||||
* implementation-defined behaviour. Unfortunately, it is also slower
|
||||
* and yields bigger code, which is why it is deactivated by default.
|
||||
*/
|
||||
#if BR_NO_ARITH_SHIFT
|
||||
#define ARSH(x, n) (((uint32_t)(x) >> (n)) \
|
||||
| ((-((uint32_t)(x) >> 31)) << (32 - (n))))
|
||||
#else
|
||||
#define ARSH(x, n) ((*(int32_t *)&(x)) >> (n))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constant-time division. The dividend hi:lo is divided by the
|
||||
* divisor d; the quotient is returned and the remainder is written
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue