| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title CRC32.cpp | ||
| 3 | // \author dinkel | ||
| 4 | // \brief cpp file for CRC32 implementation of Hash class | ||
| 5 | // | ||
| 6 | // \copyright | ||
| 7 | // Copyright 2009-2015, by the California Institute of Technology. | ||
| 8 | // ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 9 | // acknowledged. | ||
| 10 | // | ||
| 11 | // ====================================================================== | ||
| 12 | |||
| 13 | #include <Utils/Hash/Hash.hpp> | ||
| 14 | #include "Crc32.hpp" | ||
| 15 | |||
| 16 | namespace Utils { | ||
| 17 | |||
| 18 | 103315 | Hash ::Hash() { | |
| 19 | 103315 | this->init(); | |
| 20 | 103315 | } | |
| 21 | |||
| 22 | 103506 | Hash ::~Hash() = default; | |
| 23 | |||
| 24 | 54368 | void Hash ::hash(const void* const data, const FwSizeType len, HashBuffer& buffer) { | |
| 25 |
1/1✓ Branch 2 taken 54368 times.
|
54368 | Hash crc32; |
| 26 |
1/1✓ Branch 1 taken 54368 times.
|
54368 | crc32.update(data, len); |
| 27 |
1/1✓ Branch 1 taken 54368 times.
|
54368 | crc32.finalize(buffer); |
| 28 | 108736 | } | |
| 29 | |||
| 30 | 132236 | void Hash ::init() { | |
| 31 | 132236 | this->hash_handle = 0xffffffffL; | |
| 32 | 132236 | } | |
| 33 | |||
| 34 | 2372587 | void Hash ::update(const void* const data, FwSizeType len) { | |
| 35 | static_assert(sizeof(Utils::Hash::hash_handle) == sizeof(U32), "hash handle size must match CRC32 size"); | ||
| 36 | 2372587 | FW_ASSERT(data != nullptr); | |
| 37 | 2372587 | this->hash_handle = crc32_ieee802_3_update(static_cast<const U8*>(data), len, this->hash_handle); | |
| 38 | 2372587 | } | |
| 39 | |||
| 40 | 56426 | void Hash ::finalize(HashBuffer& buffer) const { | |
| 41 |
1/1✓ Branch 2 taken 56426 times.
|
56426 | HashBuffer bufferOut; |
| 42 | // For CRC32 we need to return the one's complement of the result: | ||
| 43 |
1/1✓ Branch 3 taken 56426 times.
|
56426 | Fw::SerializeStatus status = bufferOut.serializeFrom(~(this->hash_handle)); |
| 44 | 56426 | FW_ASSERT(Fw::FW_SERIALIZE_OK == status, status, static_cast<FwAssertArgType>(bufferOut.getCapacity())); | |
| 45 |
1/1✓ Branch 4 taken 56426 times.
|
56426 | buffer = bufferOut; |
| 46 | 112852 | } | |
| 47 | |||
| 48 | 7394 | void Hash ::finalize(U32& hashvalue) const { | |
| 49 | // For CRC32 we need to return the one's complement of the result: | ||
| 50 | 7394 | hashvalue = ~(this->hash_handle); | |
| 51 | 7394 | } | |
| 52 | |||
| 53 | 3 | void Hash ::setHashValue(HashBuffer& value) { | |
| 54 | 3 | Fw::SerializeStatus status = value.deserializeTo(this->hash_handle); | |
| 55 | 3 | FW_ASSERT(Fw::FW_SERIALIZE_OK == status); | |
| 56 | // Expecting `value` to already be one's complement; so doing one's complement | ||
| 57 | // here for correct hash updates | ||
| 58 | 3 | this->hash_handle = ~this->hash_handle; | |
| 59 | 3 | } | |
| 60 | |||
| 61 | 22 | void Hash ::setHashValue(U32 value) { | |
| 62 | 22 | this->hash_handle = ~value; | |
| 63 | 22 | } | |
| 64 | |||
| 65 | } // namespace Utils | ||
| 66 |