F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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((U8*) data, len, out);
33  FW_ASSERT(ret != NULL);
34  HashBuffer bufferOut(out, sizeof(out));
35  buffer = bufferOut;
36  }
37 
38  void Hash ::
39  init(void)
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, (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 }
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
SHA256
unsigned char * SHA256(const unsigned char *d, size_t n, unsigned char *md)
Utils
Definition: CRCChecker.cpp:20
Utils::Hash::~Hash
~Hash()
Definition: CRC32.cpp:24
Utils::Hash::final
void final(HashBuffer &buffer)
Definition: CRC32.cpp:64
Utils::Hash::init
void init(void)
Definition: CRC32.cpp:47
Hash.hpp
SHA256_Init
int SHA256_Init(SHA256_CTX *c)
SHA256_Final
int SHA256_Final(unsigned char *md, SHA256_CTX *c)
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Utils::Hash::Hash
Hash()
Definition: CRC32.cpp:18
SHA256_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Definition: sha.h:128
Utils::Hash::update
void update(const void *const data, const NATIVE_INT_TYPE len)
Definition: CRC32.cpp:53
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
SHA256_Update
int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
NULL
#define NULL
NULL.
Definition: BasicTypes.hpp:100
Utils::Hash::hash
static void hash(const void *data, const NATIVE_INT_TYPE len, HashBuffer &buffer)
Definition: CRC32.cpp:29