From 01f15fb6b345f6c5673aa2063d6ac4009bdbcb8f Mon Sep 17 00:00:00 2001 From: cacu Date: Tue, 1 Mar 2016 22:29:41 +0100 Subject: [PATCH] Add a new compile-time macro to use the local native format for VLI handling. This is useful for little-endian machines that have to interface with protocol stacks using little-endian byte ordering. --- uECC.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/uECC.c b/uECC.c index f65fe37..1bb3382 100644 --- a/uECC.c +++ b/uECC.c @@ -920,7 +920,11 @@ uECC_VLI_API void uECC_vli_nativeToBytes(uint8_t *bytes, const uint8_t *native) { wordcount_t i; for (i = 0; i < num_bytes; ++i) { +#if uECC_VLI_NATIVE + bytes[i] = native[i]; +#else bytes[i] = native[(num_bytes - 1) - i]; +#endif } } @@ -937,7 +941,11 @@ uECC_VLI_API void uECC_vli_nativeToBytes(uint8_t *bytes, const uECC_word_t *native) { wordcount_t i; for (i = 0; i < num_bytes; ++i) { +#if uECC_VLI_NATIVE + unsigned b = i; +#else unsigned b = num_bytes - 1 - i; +#endif bytes[i] = native[b / uECC_WORD_SIZE] >> (8 * (b % uECC_WORD_SIZE)); } } @@ -948,7 +956,11 @@ uECC_VLI_API void uECC_vli_bytesToNative(uECC_word_t *native, wordcount_t i; uECC_vli_clear(native, (num_bytes + (uECC_WORD_SIZE - 1)) / uECC_WORD_SIZE); for (i = 0; i < num_bytes; ++i) { +#if uECC_VLI_NATIVE + unsigned b = i; +#else unsigned b = num_bytes - 1 - i; +#endif native[b / uECC_WORD_SIZE] |= (uECC_word_t)bytes[i] << (8 * (b % uECC_WORD_SIZE)); }