ETSI STF525 / Internal Testing test suite
This project provides an internal testing test suite and its associated Test Adapter/Codec
sha384.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 sha384 {
23  SHA512_CTX _ctx;
24 public:
25 
29  explicit sha384(): _ctx{} { };
33  virtual ~sha384() { };
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(SHA384_DIGEST_LENGTH);
68  // Compute the hash value
69  ::SHA384_Init(&_ctx);
70  ::SHA384_Update(&_ctx, p_buffer, p_length);
71  ::SHA384_Final(static_cast<unsigned char*>(p_hash.data()), &_ctx);
72  return 0;
73  };
74 }; // End of class sha384
This class provides description of SHA-384 helper methods.
Definition: sha384.hh:22
int generate(const unsigned char *p_buffer, const size_t p_length, std::vector< unsigned char > &p_hash)
Definition: sha384.hh:61
sha384()
SHA context.
Definition: sha384.hh:29
virtual ~sha384()
Default destructor.
Definition: sha384.hh:33
SHA512_CTX _ctx
Definition: sha384.hh:23
int generate(const std::vector< unsigned char > p_buffer, std::vector< unsigned char > &p_hash)
Receive bytes formated data from the lower layers.
Definition: sha384.hh:43