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.
This commit is contained in:
cacu
2016-03-01 22:29:41 +01:00
parent b970244fa1
commit 01f15fb6b3
+12
View File
@@ -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));
}