mirror of
https://github.com/kmackay/micro-ecc.git
synced 2026-07-27 22:07:45 +00:00
Code cleanup and rearranging things for future work. Added support for 192 and 256-bit curves.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/* TODO small implementation */
|
||||
+3520
File diff suppressed because it is too large
Load Diff
@@ -3,38 +3,50 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Optimization settings. Define as 1 to enable an optimization, 0 to disable it.
|
||||
ECC_SQUARE_FUNC - If enabled, this will cause a specific function to be used for (scalar) squaring instead of the generic
|
||||
multiplication function.
|
||||
*/
|
||||
#define ECC_SQUARE_FUNC 1
|
||||
/* Platform selection options.
|
||||
If ECC_PLATFORM is not defined, the code will try to guess it based on compiler macros.
|
||||
Possible values for ECC_PLATFORM are defined below: */
|
||||
#define ecc_arch_other 0
|
||||
#define ecc_x86 1
|
||||
#define ecc_x86_64 2
|
||||
#define ecc_arm 3
|
||||
#define ecc_arm_thumb 4
|
||||
#define ecc_avr 5
|
||||
|
||||
/* If desired, you can define ECC_WORD_SIZE as appropriate for your platform (1, 4, or 8 bytes).
|
||||
If ECC_WORD_SIZE is not explicitly defined then it will be automatically set based on your platform. */
|
||||
|
||||
/* Inline assembly options.
|
||||
Inline assembly (gcc format) is provided for selected operations for AVR (requires MUL support).
|
||||
*/
|
||||
#define ecc_asm_none 0
|
||||
#define ecc_asm_avr 1
|
||||
ecc_asm_none - Use standard C99 only.
|
||||
ecc_asm_small - Use GCC inline assembly for the target platform (if available), optimized for minimum size.
|
||||
ecc_asm_fast - Use GCC inline assembly optimized for maximum speed. */
|
||||
#define ecc_asm_none 0
|
||||
#define ecc_asm_small 1
|
||||
#define ecc_asm_fast 2
|
||||
#ifndef ECC_ASM
|
||||
#define ECC_ASM ecc_asm_avr
|
||||
#define ECC_ASM ecc_asm_fast
|
||||
#endif
|
||||
|
||||
/* Curve selection options. */
|
||||
#define secp160r1 1
|
||||
#define secp192r1 2
|
||||
#define secp256r1 3
|
||||
#ifndef ECC_CURVE
|
||||
#define ECC_CURVE secp256r1
|
||||
#endif
|
||||
|
||||
/* Optimization settings. Define as 1 to enable an optimization, 0 to disable it.
|
||||
ECC_SQUARE_FUNC - If enabled, this will cause a specific function to be used for (scalar) squaring instead of the generic
|
||||
multiplication function. This will make things faster by about 8% but increases the code size. */
|
||||
#define ECC_SQUARE_FUNC 1
|
||||
|
||||
|
||||
#define ECC_CONCAT1(a, b) a##b
|
||||
#define ECC_CONCAT(a, b) ECC_CONCAT1(a, b)
|
||||
|
||||
/* Curve selection options. */
|
||||
#define secp128r1 1
|
||||
#define secp160r1 2
|
||||
#define secp192r1 3
|
||||
#define secp256r1 4
|
||||
|
||||
#ifndef ECC_CURVE
|
||||
#define ECC_CURVE secp160r1
|
||||
#endif
|
||||
|
||||
#define ecc_size_1 16
|
||||
#define ecc_size_2 20
|
||||
#define ecc_size_3 24
|
||||
#define ecc_size_4 32
|
||||
#define ecc_size_1 20 /* secp160r1 */
|
||||
#define ecc_size_2 24 /* secp192r1 */
|
||||
#define ecc_size_3 32 /* secp256r1 */
|
||||
|
||||
#define ECC_BYTES ECC_CONCAT(ecc_size_, ECC_CURVE)
|
||||
|
||||
@@ -46,6 +58,15 @@ extern "C"
|
||||
/* RNG_Function type
|
||||
The RNG function should fill p_size random bytes into p_dest. It should return 1 if
|
||||
p_dest was filled with random data, or 0 if the random data could not be generated.
|
||||
The filled-in values should be either truly random, or from a cryptographically-secure PRNG.
|
||||
|
||||
A correctly functioning RNG function must be set (using ecc_set_rng()) before calling
|
||||
ecc_make_key() or ecdsa_sign().
|
||||
|
||||
A correct RNG function is set by default when building for Windows, Linux, or OS X.
|
||||
If you are building on another POSIX-compliant system that supports /dev/random or /dev/urandom,
|
||||
you can define ECC_POSIX to use the predefined RNG. For embedded platforms there is no predefined
|
||||
RNG function; you must provide your own.
|
||||
*/
|
||||
typedef int (*RNG_Function)(uint8_t *p_dest, unsigned p_size);
|
||||
|
||||
@@ -53,7 +74,8 @@ typedef int (*RNG_Function)(uint8_t *p_dest, unsigned p_size);
|
||||
Set the function that will be used to generate random bytes. The RNG function should
|
||||
return 1 if the random data was generated, or 0 if the random data could not be generated.
|
||||
|
||||
This must be called before ecc_make_key(), ecdh_shared_secret(), or ecdsa_sign() are used.
|
||||
On platforms where there is no predefined RNG function (eg embedded platforms), this must
|
||||
be called before ecc_make_key() or ecdsa_sign() are used.
|
||||
|
||||
Inputs:
|
||||
p_rng - The function that will be used to generate random bytes.
|
||||
|
||||
Reference in New Issue
Block a user