From db690ebe736ed014a6e0fdbcadba7407d3ec93a6 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 4 May 2018 15:11:51 -0700 Subject: [PATCH] ecc: added byte conversion functions EAP-PWD was hard coded to only work on LE architectures. This adds 2 conversion functions to go from network byte order (BE) to any native architecture, and vise versa. --- src/ecc.c | 31 +++++++++++++++++++++++++++++++ src/ecc.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/src/ecc.c b/src/ecc.c index 9c8120a6..06f3447b 100644 --- a/src/ecc.c +++ b/src/ecc.c @@ -33,6 +33,8 @@ #include #include +#include + #include "ecc.h" #define MAX_TRIES 16 @@ -755,6 +757,35 @@ bool ecc_valid_point(struct ecc_point *point) return vli_equal(tmp1, tmp2); } +/* + * These two byte conversion functions were modified to allow for conversion + * to and from both BE and LE architectures. + */ + +/* Big endian byte-array to native conversion */ +void ecc_be2native(uint64_t bytes[NUM_ECC_DIGITS]) +{ + int i; + uint64_t tmp[NUM_ECC_DIGITS]; + + for (i = 0; i < NUM_ECC_DIGITS; i++) + tmp[NUM_ECC_DIGITS - 1 - i] = l_get_be64(&bytes[i]); + + memcpy(bytes, tmp, 32); +} + +/* Native to big endian byte-array conversion */ +void ecc_native2be(uint64_t native[NUM_ECC_DIGITS]) +{ + int i; + uint64_t tmp[NUM_ECC_DIGITS]; + + for (i = 0; i < NUM_ECC_DIGITS; i++) + l_put_be64(native[NUM_ECC_DIGITS - 1 - i], &tmp[i]); + + memcpy(native, tmp, 32); +} + /* * The code below was not in the original file and was added to support EAP-PWD. * The above ECC implementation did not include functionality for point diff --git a/src/ecc.h b/src/ecc.h index d2427187..bb04d37f 100644 --- a/src/ecc.h +++ b/src/ecc.h @@ -62,6 +62,10 @@ void ecc_point_add(struct ecc_point *ret, struct ecc_point *p, bool ecc_valid_point(struct ecc_point *point); +void ecc_be2native(uint64_t bytes[NUM_ECC_DIGITS]); + +void ecc_native2be(uint64_t native[NUM_ECC_DIGITS]); + bool ecc_compute_y(uint64_t *y, uint64_t *x); void vli_mod_inv(uint64_t *result, const uint64_t *input, const uint64_t *mod);