F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SHA256.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SHA256.cpp
3 // \author dinkel
4 // \brief cpp file for SHA 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 
15 namespace Utils {
16 
17 Hash ::Hash() {
18  this->init();
19 }
20 
21 Hash ::~Hash() {}
22 
23 void Hash ::hash(const void* const data, const FwSizeType len, HashBuffer& buffer) {
25  U8* ret = SHA256(static_cast<const U8*>(data), len, out);
26  FW_ASSERT(ret != nullptr);
27  HashBuffer bufferOut(out, sizeof(out));
28  buffer = bufferOut;
29 }
30 
31 void Hash ::init() {
32  int ret = SHA256_Init(&this->hash_handle);
33  FW_ASSERT(ret == 1);
34 }
35 
36 void Hash ::update(const void* const data, FwSizeType len) {
37  int ret = SHA256_Update(&this->hash_handle, static_cast<const U8*>(data), len);
38  FW_ASSERT(ret == 1);
39 }
40 
41 void Hash ::final(HashBuffer& buffer) {
43  int ret = SHA256_Final(out, &this->hash_handle);
44  FW_ASSERT(ret == 1);
45  HashBuffer bufferOut(out, sizeof(out));
46  buffer = bufferOut;
47 }
48 
49 } // namespace Utils
void update(const void *const data, const FwSizeType len)
Definition: CRC32.cpp:45
PlatformSizeType FwSizeType
unsigned char * SHA256(const unsigned char *d, size_t n, unsigned char *md)
void init()
Definition: CRC32.cpp:41
void final(HashBuffer &buffer)
Definition: CRC32.cpp:54
int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
#define SHA256_DIGEST_LENGTH
Definition: sha.h:133
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
static void hash(const void *data, const FwSizeType len, HashBuffer &buffer)
Definition: CRC32.cpp:25
int SHA256_Init(SHA256_CTX *c)
int SHA256_Final(unsigned char *md, SHA256_CTX *c)
#define FW_ASSERT(...)
Definition: Assert.hpp:14