mirror of
https://github.com/kmackay/micro-ecc.git
synced 2026-10-19 22:18:12 +00:00
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:
@@ -920,7 +920,11 @@ uECC_VLI_API void uECC_vli_nativeToBytes(uint8_t *bytes,
|
|||||||
const uint8_t *native) {
|
const uint8_t *native) {
|
||||||
wordcount_t i;
|
wordcount_t i;
|
||||||
for (i = 0; i < num_bytes; ++i) {
|
for (i = 0; i < num_bytes; ++i) {
|
||||||
|
#if uECC_VLI_NATIVE
|
||||||
|
bytes[i] = native[i];
|
||||||
|
#else
|
||||||
bytes[i] = native[(num_bytes - 1) - i];
|
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) {
|
const uECC_word_t *native) {
|
||||||
wordcount_t i;
|
wordcount_t i;
|
||||||
for (i = 0; i < num_bytes; ++i) {
|
for (i = 0; i < num_bytes; ++i) {
|
||||||
|
#if uECC_VLI_NATIVE
|
||||||
|
unsigned b = i;
|
||||||
|
#else
|
||||||
unsigned b = num_bytes - 1 - i;
|
unsigned b = num_bytes - 1 - i;
|
||||||
|
#endif
|
||||||
bytes[i] = native[b / uECC_WORD_SIZE] >> (8 * (b % uECC_WORD_SIZE));
|
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;
|
wordcount_t i;
|
||||||
uECC_vli_clear(native, (num_bytes + (uECC_WORD_SIZE - 1)) / uECC_WORD_SIZE);
|
uECC_vli_clear(native, (num_bytes + (uECC_WORD_SIZE - 1)) / uECC_WORD_SIZE);
|
||||||
for (i = 0; i < num_bytes; ++i) {
|
for (i = 0; i < num_bytes; ++i) {
|
||||||
|
#if uECC_VLI_NATIVE
|
||||||
|
unsigned b = i;
|
||||||
|
#else
|
||||||
unsigned b = num_bytes - 1 - i;
|
unsigned b = num_bytes - 1 - i;
|
||||||
|
#endif
|
||||||
native[b / uECC_WORD_SIZE] |=
|
native[b / uECC_WORD_SIZE] |=
|
||||||
(uECC_word_t)bytes[i] << (8 * (b % uECC_WORD_SIZE));
|
(uECC_word_t)bytes[i] << (8 * (b % uECC_WORD_SIZE));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user