Skip to content

Commit

Permalink
Initial Curve448 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Legrandin committed Sep 4, 2024
1 parent ee9a360 commit 68caf78
Show file tree
Hide file tree
Showing 6 changed files with 748 additions and 2 deletions.
44 changes: 44 additions & 0 deletions lib/Crypto/PublicKey/_montgomery.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,47 @@ class EcLib(object):
None,
EcLib)
return curve25519


def curve448_curve():
p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff # 2**448 - 2**224 - 1
order = 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3

_curve448_lib = load_pycryptodome_raw_lib("Crypto.PublicKey._curve448", """
typedef void Curve448Context;
typedef void Curve448Point;
int curve448_new_context(Curve448Context **pec_ctx);
void curve448_free_context(Curve448Context *ec_ctx);
int curve448_new_point(Curve448Point **out,
const uint8_t *x,
size_t len,
const Curve448Context *ec_ctx);
void curve448_free_point(Curve448Point *p);
int curve448_clone(Curve448Point **P, const Curve448Point *Q);
int curve448_get_x(uint8_t *xb, size_t modsize, const Curve448Point *p);
int curve448_scalar(Curve448Point *P, const uint8_t *scalar, size_t scalar_len, uint64_t seed);
int curve448_cmp(const Curve448Point *ecp1, const Curve448Point *ecp2);
""")

class EcLib(object):
new_point = _curve448_lib.curve448_new_point
clone = _curve448_lib.curve448_clone
free_point = _curve448_lib.curve448_free_point
get_x = _curve448_lib.curve448_get_x
scalar = _curve448_lib.curve448_scalar
cmp = _curve448_lib.curve448_cmp

curve448 = _Curve(Integer(p),
None,
Integer(order),
Integer(9),
None,
None,
448,
"1.3.101.111", # RFC8410
None,
"Curve448",
None,
EcLib)
return curve448
7 changes: 5 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CFLAGS=-Werror -Wall -O3 -g -Wno-unused-const-variable -Wconversion -Wsign-conve

CFLAGS += -fanalyzer

all:: modexp ec_ws_p256 ec_ws_p384 ec_ws_p521 ed25519_perf ed448_perf curve25519_perf
all:: modexp ec_ws_p256 ec_ws_p384 ec_ws_p521 ed25519_perf ed448_perf curve25519_perf curve448_perf

ec_ws_p256: ec_ws_p256.c mont.c p256_table.c p384_table.c p521_table.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ -DSYS_BITS=64 -DMAIN
Expand Down Expand Up @@ -39,5 +39,8 @@ p521_table.c: make_ecc_table.py
curve25519_perf: curve25519.c multiply_64.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ -DSYS_BITS=64 -DPROFILE

curve448_perf: curve448.c mont.c
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $^ -DSYS_BITS=64 -DPROFILE

clean::
rm -f ec_ws_p256 ec_ws_p384 ec_ws_p521 mont.o modexp x25519 ed25519_perf ed448_perf curve25519_perf
rm -f ec_ws_p256 ec_ws_p384 ec_ws_p521 mont.o modexp x25519 ed25519_perf ed448_perf curve25519_perf curve448_perf
Loading

0 comments on commit 68caf78

Please sign in to comment.