~aleteoryx/muditaos

3bdc27a10428cfd22c1122bd3859f346cba07a7b — Marek Niepieklo 4 years ago c47f7bf
[CP-270] Replace CRC32 library

Replaced CRC-32 lib from csbruce.com/software/ with
github.com/stbrumme/hash-library
M .gitmodules => .gitmodules +4 -3
@@ 8,9 8,6 @@
[submodule "module-utils/segger"]
	path = module-utils/segger
	url = ../segger-utils.git
[submodule "module-utils/crc32"]
	path = third-party/crc32/src
	url = ../crc32
[submodule "module-utils/protobuf"]
	path = third-party/protobuf/src
	url = ../protobuf.git


@@ 92,3 89,7 @@
[submodule "third-party/base64/src"]
	path = third-party/base64/src
	url = https://github.com/rafagafe/base64.git
[submodule "third-party/hash-library/src"]
	path = third-party/hash-library/src
	url = https://github.com/mudita/hash-library.git
	branch = rt1051

M module-services/service-desktop/CMakeLists.txt => module-services/service-desktop/CMakeLists.txt +1 -1
@@ 57,7 57,6 @@ target_include_directories(${PROJECT_NAME}

target_link_libraries(${PROJECT_NAME}
    PRIVATE
        crc32
        microtar
        module-utils
        service-cellular


@@ 70,6 69,7 @@ target_link_libraries(${PROJECT_NAME}
    PUBLIC
        module-cellular
        eventstore
        hash-library::hash-library
)

if (${ENABLE_TESTS})

M module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp => module-services/service-desktop/endpoints/update/UpdateMuditaOS.cpp +5 -1
@@ 497,6 497,8 @@ bool UpdateMuditaOS::unpackFileToTemp(mtar_header_t &h, unsigned long *crc32)
        return false;
    }

    CRC32 digest;

    for (uint32_t i = 0; i < blocksToRead; i++) {
        if (i + 1 == blocksToRead) {
            sizeToRead = h.size % boot::consts::tar_buf;


@@ 524,9 526,11 @@ bool UpdateMuditaOS::unpackFileToTemp(mtar_header_t &h, unsigned long *crc32)

        currentExtractedBytes += dataWritten;

        *crc32 = Crc32_ComputeBuf(*crc32, readBuf.get(), sizeToRead);
        digest.add(readBuf.get(), sizeToRead);
    }
    std::fclose(fp);

    *crc32 = digest.getHashValue();
    return true;
}


M module-utils/CMakeLists.txt => module-utils/CMakeLists.txt +3 -3
@@ 22,15 22,15 @@ add_library(${PROJECT_NAME} STATIC ${SOURCES})
include(segger/rtt/CMakeLists.txt)

target_link_libraries(${PROJECT_NAME}
PUBLIC 
PUBLIC
    board
    libphonenumber::libphonenumber
    log
    magic_enum
    module-os 
    module-os
    module-vfs
PRIVATE
    crc32
    hash-library::hash-library
    json::json
    time
)

M module-utils/Utils.cpp => module-utils/Utils.cpp +4 -4
@@ 19,17 19,17 @@ namespace utils::filesystem
    {
        auto buf = std::make_unique<unsigned char[]>(crc_buf_len);

        unsigned long crc32 = 0;
        CRC32 digestCrc32;
        while (!std::feof(file)) {
            size_t dataLen = std::fread(buf.get(), 1, crc_buf_len, file);
            if (dataLen == 0) {
                return crc32;
                break;
            }

            crc32 = Crc32_ComputeBuf(crc32, buf.get(), dataLen);
            digestCrc32.add(buf.get(), dataLen);
        }

        return crc32;
        return digestCrc32.getHashValue();
    }

    std::string generateRandomId(std::size_t length) noexcept

M module-utils/bootconfig/CMakeLists.txt => module-utils/bootconfig/CMakeLists.txt +1 -1
@@ 18,7 18,7 @@ target_link_libraries( ${PROJECT_NAME}
   PRIVATE
      module-utils
      module-vfs
      crc32
      hash-library::hash-library
      Microsoft.GSL::GSL
      json::json
)

M module-utils/bootconfig/src/bootconfig.cpp => module-utils/bootconfig/src/bootconfig.cpp +0 -1
@@ 11,7 11,6 @@
#include <ticks.hpp>
#include <cstdio>
#include <log.hpp>
#include <crc32.h>
#include <array>
#include <Utils.hpp>


M third-party/CMakeLists.txt => third-party/CMakeLists.txt +1 -1
@@ 1,4 1,3 @@
add_subdirectory(crc32)
add_subdirectory(magic_enum)
add_subdirectory(microtar)
add_subdirectory(date)


@@ 20,3 19,4 @@ if (${PROJECT_TARGET} STREQUAL "TARGET_RT1051")
endif()
add_subdirectory(fatfs)
add_subdirectory(base64)
add_subdirectory(hash-library)

D third-party/crc32/CMakeLists.txt => third-party/crc32/CMakeLists.txt +0 -13
@@ 1,13 0,0 @@

add_library(crc32)
target_sources(crc32
   PRIVATE
      ${CMAKE_CURRENT_SOURCE_DIR}/src/crc32.c
      ${CMAKE_CURRENT_SOURCE_DIR}/src/crc32.h
)

target_include_directories(crc32
   PUBLIC
      $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)


D third-party/crc32/src => third-party/crc32/src +0 -1
@@ 1,1 0,0 @@
Subproject commit f38cbc9267a4cc24aeb92c04452d9ade803d168c

A third-party/hash-library/CMakeLists.txt => third-party/hash-library/CMakeLists.txt +27 -0
@@ 0,0 1,27 @@

add_library(hash-library)
add_library(hash-library::hash-library ALIAS hash-library)
target_sources(hash-library
   PRIVATE
      src/crc32.cpp
      src/keccak.cpp
      src/md5.cpp
      src/sha1.cpp
      src/sha256.cpp
      src/sha3.cpp

   PUBLIC
      src/crc32.h
      src/hmac.h
      src/keccak.h
      src/md5.h
      src/sha1.h
      src/sha256.h
      src/sha3.h
    )

target_include_directories(hash-library
   PUBLIC
       $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
)


A third-party/hash-library/src => third-party/hash-library/src +1 -0
@@ 0,0 1,1 @@
Subproject commit 9b1d3f3fbb22bbbe0c8b2efceac8e41fb4c7957b