mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-26 02:19:26 +01:00
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:
parent
71902e2291
commit
db690ebe73
31
src/ecc.c
31
src/ecc.c
@ -33,6 +33,8 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <ell/ell.h>
|
||||||
|
|
||||||
#include "ecc.h"
|
#include "ecc.h"
|
||||||
|
|
||||||
#define MAX_TRIES 16
|
#define MAX_TRIES 16
|
||||||
@ -755,6 +757,35 @@ bool ecc_valid_point(struct ecc_point *point)
|
|||||||
return vli_equal(tmp1, tmp2);
|
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 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
|
* The above ECC implementation did not include functionality for point
|
||||||
|
@ -62,6 +62,10 @@ void ecc_point_add(struct ecc_point *ret, struct ecc_point *p,
|
|||||||
|
|
||||||
bool ecc_valid_point(struct ecc_point *point);
|
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);
|
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);
|
void vli_mod_inv(uint64_t *result, const uint64_t *input, const uint64_t *mod);
|
||||||
|
Loading…
Reference in New Issue
Block a user