Commit 195cacf2 authored by Davide Galassi's avatar Davide Galassi

ECP secure NIST and Brainpool curves parameters

parent bbc53b75
...@@ -22,7 +22,7 @@ CRY_COVERAGE=y ...@@ -22,7 +22,7 @@ CRY_COVERAGE=y
#CRY_ARCH_x86=y #CRY_ARCH_x86=y
################################################################################ ################################################################################
# Algorithms # Algorithms tweaks
################################################################################ ################################################################################
# Use Extended Euclidean Algorithm to compute inverse. # Use Extended Euclidean Algorithm to compute inverse.
...@@ -48,6 +48,22 @@ CRY_ECP_MUL_WIN=y ...@@ -48,6 +48,22 @@ CRY_ECP_MUL_WIN=y
# Have precedence against the simple windowed one. # Have precedence against the simple windowed one.
CRY_ECP_MUL_SLIDING_WIN=y CRY_ECP_MUL_SLIDING_WIN=y
################################################################################
# Elliptic curves group parameters
################################################################################
CRY_ECP_GRP_SECP192R1_ENABLE=y
CRY_ECP_GRP_SECP224R1_ENABLE=y
CRY_ECP_GRP_SECP256R1_ENABLE=y
CRY_ECP_GRP_SECP384R1_ENABLE=y
CRY_ECP_GRP_SECP521R1_ENABLE=y
CRY_ECP_GRP_SECP192K1_ENABLE=y
CRY_ECP_GRP_SECP224K1_ENABLE=y
CRY_ECP_GRP_SECP256K1_ENABLE=y
CRY_ECP_GRP_BP256R1_ENABLE=y
CRY_ECP_GRP_BP384R1_ENABLE=y
CRY_ECP_GRP_BP512R1_ENABLE=y
################################################################################ ################################################################################
# Miscelanea configurations # Miscelanea configurations
################################################################################ ################################################################################
......
...@@ -8,6 +8,17 @@ ...@@ -8,6 +8,17 @@
#include <cry/mpi.h> #include <cry/mpi.h>
#define CRY_ECP_GRP_SECP192R1 0
#define CRY_ECP_GRP_SECP224R1 1
#define CRY_ECP_GRP_SECP256R1 2
#define CRY_ECP_GRP_SECP384R1 3
#define CRY_ECP_GRP_SECP521R1 4
#define CRY_ECP_GRP_SECP192K1 5
#define CRY_ECP_GRP_SECP224K1 6
#define CRY_ECP_GRP_SECP256K1 7
#define CRY_ECP_GRP_BP256R1 8
#define CRY_ECP_GRP_BP384R1 9
#define CRY_ECP_GRP_BP512R1 10
/** /**
* EC point * EC point
*/ */
...@@ -75,4 +86,7 @@ int cry_ecp_grp_init(cry_ecp_grp *ec); ...@@ -75,4 +86,7 @@ int cry_ecp_grp_init(cry_ecp_grp *ec);
void cry_ecp_grp_clear(cry_ecp_grp *ec); void cry_ecp_grp_clear(cry_ecp_grp *ec);
int cry_ecp_grp_load(cry_ecp_grp *grp, int grp_id);
#endif /* CRY_ECP_H_ */ #endif /* CRY_ECP_H_ */
...@@ -43,11 +43,14 @@ typedef CRY_MPI_DIGIT_TYPE cry_mpi_digit; ...@@ -43,11 +43,14 @@ typedef CRY_MPI_DIGIT_TYPE cry_mpi_digit;
/** Number of bits in one digit */ /** Number of bits in one digit */
#define CRY_MPI_DIGIT_BITS (CRY_MPI_DIGIT_BYTES << 3) #define CRY_MPI_DIGIT_BITS (CRY_MPI_DIGIT_BYTES << 3)
/**
* MPI structure.
*/
struct cry_mpi { struct cry_mpi {
int sign; int sign; /**< Non-zero if negative */
size_t used; size_t used; /**< Number of used digits */
size_t alloc; size_t alloc; /**< Allocated digits */
cry_mpi_digit *data; cry_mpi_digit *data; /**< Pointer to digits */
}; };
typedef struct cry_mpi cry_mpi; typedef struct cry_mpi cry_mpi;
......
...@@ -35,9 +35,8 @@ int cry_ecp_grp_init(cry_ecp_grp *ec) ...@@ -35,9 +35,8 @@ int cry_ecp_grp_init(cry_ecp_grp *ec)
res = cry_mpi_init_list(&ec->p, &ec->a, &ec->b, &ec->n, res = cry_mpi_init_list(&ec->p, &ec->a, &ec->b, &ec->n,
&ec->g.x, &ec->g.y, &ec->g.z, &ec->g.x, &ec->g.y, &ec->g.z,
(cry_mpi *) NULL); (cry_mpi *) NULL);
if (res == 0) { if (res == 0)
cry_ecp_set_zero(&ec->g); cry_ecp_set_zero(&ec->g);
}
return res; return res;
} }
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ static void load_curve(cry_ecp_grp *ec) ...@@ -16,7 +16,7 @@ static void load_curve(cry_ecp_grp *ec)
cry_mpi_init_int(&ec->g.z, 1); cry_mpi_init_int(&ec->g.z, 1);
} }
void ecp_test(void) void ecp_dummy_test(void)
{ {
cry_ecp_grp ec; cry_ecp_grp ec;
cry_ecp p; cry_ecp p;
...@@ -36,3 +36,18 @@ void ecp_test(void) ...@@ -36,3 +36,18 @@ void ecp_test(void)
} while (cry_mpi_cmp(&p.x, &ec.g.x) != 0 || } while (cry_mpi_cmp(&p.x, &ec.g.x) != 0 ||
cry_mpi_cmp(&p.y, &ec.g.y) != 0); cry_mpi_cmp(&p.y, &ec.g.y) != 0);
} }
void nist_grp_load()
{
cry_ecp_grp grp;
cry_ecp_grp_load(&grp, CRY_ECP_GRP_SECP224R1);
cry_mpi_print(&grp.a, 16);
cry_mpi_print(&grp.b, 16);
}
void ecp_test(void)
{
nist_grp_load();
//ecp_dummy_test();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment