F´ Flight Software - C/C++ Documentation  devel
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 ::
18  Hash()
19  {
20  this->init();
21  }
22 
23  Hash ::
24  ~Hash()
25  {
26  }
27 
28  void Hash ::
29  hash(const void *const data, const NATIVE_INT_TYPE len, HashBuffer& buffer)
30  {
32  U8* ret = SHA256(static_cast<const U8*>(data), len, out);
33  FW_ASSERT(ret != nullptr);
34  HashBuffer bufferOut(out, sizeof(out));
35  buffer = bufferOut;
36  }
37 
38  void Hash ::
39  init()
40  {
41  int ret = SHA256_Init(&this->hash_handle);
42  FW_ASSERT(ret == 1);
43  }
44 
45  void Hash ::
46  update(const void *const data, NATIVE_INT_TYPE len)
47  {
48  int ret = SHA256_Update(&this->hash_handle, static_cast<const U8*>(data), len);
49  FW_ASSERT(ret == 1);
50  }
51 
52  void Hash ::
53  final(HashBuffer& buffer)
54  {
56  int ret = SHA256_Final(out, &this->hash_handle);
57  FW_ASSERT(ret == 1);
58  HashBuffer bufferOut(out, sizeof(out));
59  buffer = bufferOut;
60  }
61 
62 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
static void hash(const void *data, const NATIVE_INT_TYPE len, HashBuffer &buffer)
Definition: CRC32.cpp:29
void init()
Definition: CRC32.cpp:47
void update(const void *const data, const NATIVE_INT_TYPE len)
Definition: CRC32.cpp:53
void final(HashBuffer &buffer)
Definition: CRC32.cpp:64
int SHA256_Final(unsigned char *md, SHA256_CTX *c)
int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
#define SHA256_DIGEST_LENGTH
Definition: sha.h:128
unsigned char * SHA256(const unsigned char *d, size_t n, unsigned char *md)
int SHA256_Init(SHA256_CTX *c)