OpenDDS  Snapshot(2023/04/28-20:55)
UtilityImpl.cpp
Go to the documentation of this file.
1 #include "UtilityImpl.h"
2 
3 #include <openssl/rand.h>
4 #include <openssl/hmac.h>
5 #include <openssl/err.h>
6 
8 
9 namespace OpenDDS {
10 namespace Security {
11 
13 
14 void UtilityImpl::generate_random_bytes(void* ptr, size_t size)
15 {
16  int rc = RAND_bytes(static_cast<unsigned char*>(ptr),
17  static_cast<int>(size));
18 
19  if (rc != 1) {
20  unsigned long err = ERR_get_error();
21  char msg[256] = { 0 };
22  ERR_error_string_n(err, msg, sizeof(msg));
24  ACE_TEXT("(%P|%t) UtilityImpl::generate_random_bytes: ERROR '%C' returned by RAND_bytes(...)\n"),
25  msg));
26  }
27 }
28 
29 void UtilityImpl::hmac(void* out, void const* in, size_t size, const std::string& password) const
30 {
31  unsigned char* digest = HMAC(EVP_sha1(), password.c_str(),
32  static_cast<int>(password.size()),
33  static_cast<const unsigned char*>(in),
34  static_cast<int>(size), NULL, NULL);
35  memcpy(out, digest, 20);
36 }
37 
38 } // Security
39 } // OpenDDS
40 
#define ACE_ERROR(X)
void * memcpy(void *t, const void *s, size_t len)
virtual void hmac(void *out, void const *in, size_t size, const std::string &password) const
Definition: UtilityImpl.cpp:29
ACE_TEXT("TCP_Factory")
virtual void generate_random_bytes(void *ptr, size_t size)
Definition: UtilityImpl.cpp:14
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28