Skip to content

Commit

Permalink
Used OpenSSL correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf committed Sep 30, 2023
1 parent 3114963 commit 561476c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ add_library(hdrbg SHARED ${sources})
target_include_directories(hdrbg PRIVATE include)
configure_file(hdrbg.pc.in hdrbg.pc @ONLY)

find_package(OpenSSL 3.0.0)
if(OpenSSL_FOUND)
target_compile_definitions(hdrbg PRIVATE TFPF_HASH_DRBG_OPENSSL_FOUND=1)
endif()

set_target_properties(hdrbg PROPERTIES
PUBLIC_HEADER include/hdrbg.h
SOVERSION 1
Expand Down
9 changes: 9 additions & 0 deletions lib/sha256.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include <inttypes.h>
#include <limits.h>
#include <stddef.h>
#include <string.h>

#include "extras.h"
#include "sha.h"

#ifdef TFPF_HASH_DRBG_OPENSSL_FOUND
#include <openssl/sha.h>
#endif

#define ROTR32(x, n) ((x) >> (n) | (x) << (32 - (n)))

// Hash initialiser.
Expand Down Expand Up @@ -46,6 +51,10 @@ sha256_bytes[32];
uint8_t *
sha256(uint8_t const *m_bytes_, size_t m_length_, uint8_t *h_bytes)
{
#if defined TFPF_HASH_DRBG_OPENSSL_FOUND && CHAR_BIT == 8
return SHA256(m_bytes_, m_length_, h_bytes);
#endif

// Initialise the hash.
uint32_t h_words[8];
memcpy(h_words, sha256_init, sizeof sha256_init);
Expand Down

0 comments on commit 561476c

Please sign in to comment.