Skip to content

Commit 5649c1a

Browse files
committed
update bytewords submodule
1 parent 0139fd3 commit 5649c1a

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

deps/bc-ur-arduino/src/crc32.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// crc32.c
3+
//
4+
// Copyright © 2020 by Blockchain Commons, LLC
5+
// Licensed under the "BSD-2-Clause Plus Patent License"
6+
//
7+
8+
#include "crc32.h"
9+
10+
#ifdef ARDUINO
11+
#define htonl(x) __builtin_bswap32((uint32_t) (x))
12+
#elif _WIN32
13+
#include <winsock2.h>
14+
#include <memory.h>
15+
#else
16+
#include <arpa/inet.h>
17+
#include <memory.h>
18+
#endif
19+
20+
uint32_t crc32(const uint8_t* bytes, size_t len) {
21+
static uint32_t* table = NULL;
22+
23+
if(table == NULL) {
24+
table = malloc(256 * sizeof(uint32_t));
25+
for(int i = 0; i < 256; i++) {
26+
uint32_t c = i;
27+
for(int j = 0; j < 8; j++) {
28+
c = (c % 2 == 0) ? (c >> 1) : (0xEDB88320 ^ (c >> 1));
29+
}
30+
table[i] = c;
31+
}
32+
}
33+
34+
uint32_t crc = ~0;
35+
for(int i = 0; i < len; i++) {
36+
uint32_t byte = bytes[i];
37+
crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
38+
}
39+
return ~crc;
40+
}
41+
42+
uint32_t crc32n(const uint8_t* bytes, size_t len) {
43+
return htonl(crc32(bytes, len));
44+
}

deps/bc-ur-arduino/src/crc32.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// crc32.h
3+
//
4+
// Copyright © 2020 by Blockchain Commons, LLC
5+
// Licensed under the "BSD-2-Clause Plus Patent License"
6+
//
7+
8+
#ifndef BC_UR_CRC32_H
9+
#define BC_UR_CRC32_H
10+
11+
#include <stdint.h>
12+
#include <stdlib.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
// Returns the CRC-32 checksum of the input buffer.
19+
uint32_t crc32(const uint8_t* bytes, size_t len);
20+
21+
// Returns the CRC-32 checksum of the input buffer in network byte order (big endian).
22+
uint32_t crc32n(const uint8_t* bytes, size_t len);
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
#endif // BC_UR_CRC32_H

seedtool/ur.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "bc-bytewords.h"
77
#include "CborEncoder.h"
88
#include "wally_core.h"
9-
#include "crc32.h"
109
#include "wally_bip32.h"
1110
#include "wally_address.h"
1211
#include "keystore.h"

0 commit comments

Comments
 (0)