ETSI STF525 / Internal Testing test suite This project provides an internal testing test suite and its associated Test Adapter/Codec

sha256.hh
Go to the documentation of this file.
1
11 #pragma once
12
13 #include <vector>
14
15 #include <openssl/sha.h>
16 #include <openssl/objects.h>
17
22 class sha256 {
23 SHA256_CTX _ctx;
24 public:
29 explicit sha256(): _ctx{} { };
33 virtual ~sha256() { };
34
43 inline int generate(const std::vector<unsigned char> p_buffer, std::vector<unsigned char>& p_hash) {
44 // Sanity check
45 if (p_buffer.size() == 0) {
46 return -1;
47 }
48
49 return generate(p_buffer.data(), p_buffer.size(), p_hash);
50 };
51
61 inline int generate(const unsigned char *p_buffer, const size_t p_length, std::vector<unsigned char>& p_hash) {
62 // Sanity check
63 if (p_buffer == nullptr) {
64 return -1;
65 }
66 // Resize data buffer
67 p_hash.resize(SHA256_DIGEST_LENGTH);
68 // Compute the hash value
69 ::SHA256_Init(&_ctx);
70 ::SHA256_Update(&_ctx, p_buffer, p_length);
71 ::SHA256_Final(static_cast<unsigned char*>(p_hash.data()), &_ctx);
72 return 0;
73 };
74 }; // End of class sha256
sha256
This class provides description of SHA-256 helper methods.
Definition: sha256.hh:22
sha256::~sha256
virtual ~sha256()
Default destructor.
Definition: sha256.hh:33
sha256::_ctx
SHA256_CTX _ctx
Definition: sha256.hh:23
sha256::generate
int generate(const unsigned char *p_buffer, const size_t p_length, std::vector< unsigned char > &p_hash)
Definition: sha256.hh:61
sha256::generate
int generate(const std::vector< unsigned char > p_buffer, std::vector< unsigned char > &p_hash)
Receive bytes formated data from the lower layers.
Definition: sha256.hh:43
sha256::sha256
sha256()
SHA context.
Definition: sha256.hh:29