Skip to content

Commit

Permalink
remove crc, use one from espressif which is sometimes in rom
Browse files Browse the repository at this point in the history
  • Loading branch information
greenaddress committed May 15, 2024
1 parent 56cf4e0 commit de039d6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 103 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ idf_component_register(SRC_DIRS "src"
PRIV_REQUIRES mbedtls cbor
INCLUDE_DIRS "src")

target_compile_features(${COMPONENT_LIB} PRIVATE cxx_std_17)
target_compile_features(${COMPONENT_LIB} PRIVATE cxx_std_20)
target_compile_options(${COMPONENT_LIB} PRIVATE -Ofast)
66 changes: 0 additions & 66 deletions src/crc32.c

This file was deleted.

28 changes: 0 additions & 28 deletions src/crc32.h

This file was deleted.

11 changes: 3 additions & 8 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@

#include "utils.hpp"

extern "C" {

#include "crc32.h"

}

#include <array>
#include <vector>
#include <algorithm>
#include <cctype>
#include <mbedtls/sha256.h>
#include <esp_crc.h>


using namespace std;
Expand All @@ -36,14 +31,14 @@ void sha256(const ByteVector &buf, std::array<uint8_t, SHA256_LEN> &digest) {
}

ByteVector crc32_bytes(const ByteVector &buf) {
uint32_t checksum = ur_crc32n(buf.data(), buf.size());
uint32_t checksum = __builtin_bswap32(crc32_int(buf));
auto *cbegin = (uint8_t*)&checksum;
auto *cend = cbegin + sizeof(uint32_t);
return {cbegin, cend};
}

uint32_t crc32_int(const ByteVector &buf) {
return ur_crc32(buf.data(), buf.size());
return esp_crc32_le(0, buf.data(), buf.size());
}

ByteVector string_to_bytes(const string& s) {
Expand Down

0 comments on commit de039d6

Please sign in to comment.