|
10 | 10 |
|
11 | 11 | // Return the CRC-32 checksum of the input buffer in network byte order (big endian). |
12 | 12 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
13 | | -#define crc32_nbo(...) crc32(__VA_ARGS__) |
| 13 | +#define crc32_nbo(...) cx_crc32_hw(__VA_ARGS__) |
14 | 14 | #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
15 | | -#define crc32_nbo(...) os_swap_u32(crc32(__VA_ARGS__)) |
| 15 | +#define crc32_nbo(...) os_swap_u32(cx_crc32_hw(__VA_ARGS__)) |
16 | 16 | #else |
17 | 17 | #error "What kind of system is this?" |
18 | 18 | #endif |
19 | 19 |
|
20 | | -// NOTE: |
21 | | -// The implementation of cx_crc32_hw() on Ledger devices is buggy and produces incorrect CRC32 |
22 | | -// checks. Ledger are fixing cx_crc32_hw() on each device either through SDK or OS updates. |
23 | | -// The following function is a temporary workaround that can be removed once cx_crc32_hw() |
24 | | -// works on all Ledger devices |
25 | | - |
26 | | -uint32_t crc32(const uint8_t *data, size_t len) { |
27 | | - uint32_t crc = ~0; |
28 | | - const uint8_t *end = data + len; |
29 | | - |
30 | | - while (data < end) { |
31 | | - crc ^= *data++; |
32 | | - for (uint8_t i = 0; i < 8; i++) { |
33 | | - uint32_t mask = ~((crc & 1) - 1); |
34 | | - crc = (crc >> 1) ^ (0xEDB88320 & mask); |
35 | | - } |
36 | | - } |
37 | | - return ~crc; |
38 | | -} |
39 | | - |
40 | 20 | unsigned int bolos_ux_sskr_size_get(uint8_t bip39_onboarding_kind, |
41 | 21 | uint8_t groups_threshold, |
42 | 22 | unsigned int *group_descriptor, |
@@ -280,7 +260,7 @@ unsigned int bolos_ux_sskr_hex_check(unsigned char *mnemonic_hex, |
280 | 260 |
|
281 | 261 | for (unsigned int i = 0; i < sskr_shares_count; i++) { |
282 | 262 | checksum = crc32_nbo(mnemonic_hex + i * (mnemonic_length / sskr_shares_count), |
283 | | - (mnemonic_length / sskr_shares_count) - checksum_len); |
| 263 | + (mnemonic_length / sskr_shares_count) - checksum_len); |
284 | 264 | // First 8 bytes of all shares in group should be same |
285 | 265 | // Test checksum |
286 | 266 | if ((os_secure_memcmp(cbor, mnemonic_hex + i * mnemonic_length / sskr_shares_count, 3) != |
|
0 commit comments