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.
diff --git a/uECC.c b/uECC.c
index f65fe37..1bb3382 100644
--- a/uECC.c
+++ b/uECC.c
@@ -920,7 +920,11 @@
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 @@
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 @@
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));
}