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.
This commit is contained in:
James Prestwood 2018-05-04 15:11:51 -07:00 committed by Denis Kenzior
parent 71902e2291
commit db690ebe73
2 changed files with 35 additions and 0 deletions

View File

@ -33,6 +33,8 @@
#include <sys/types.h>
#include <string.h>
#include <ell/ell.h>
#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

View File

@ -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);