aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto.cpp7
-rw-r--r--src/crypto/oaes_lib.c41
-rw-r--r--src/crypto/slow-hash.c2
-rw-r--r--src/crypto/tree-hash.c7
4 files changed, 51 insertions, 6 deletions
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index bce3b1131..fa0199f20 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -28,7 +28,6 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-#include <alloca.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -42,6 +41,12 @@
#include "crypto.h"
#include "hash.h"
+#ifndef __FreeBSD__
+ #include <alloca.h>
+#else
+ #include <stdlib.h>
+#endif
+
namespace crypto {
using std::abort;
diff --git a/src/crypto/oaes_lib.c b/src/crypto/oaes_lib.c
index 81c8aeff2..c86b8caa0 100644
--- a/src/crypto/oaes_lib.c
+++ b/src/crypto/oaes_lib.c
@@ -33,13 +33,20 @@ static const char _NR[] = {
#include <stddef.h>
#include <time.h>
-#include <sys/timeb.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#ifndef __APPLE__
-#include <malloc.h>
+// Both OS X and FreeBSD don't need malloc.h
+#if !defined(__APPLE__) && !defined(__FreeBSD__)
+ #include <malloc.h>
+#endif
+
+// FreeBSD also doesn't need timeb.h
+#ifndef __FreeBSD__
+ #include <sys/timeb.h>
+#else
+ #include <sys/time.h>
#endif
#ifdef WIN32
@@ -463,6 +470,7 @@ OAES_RET oaes_sprintf(
#ifdef OAES_HAVE_ISAAC
static void oaes_get_seed( char buf[RANDSIZ + 1] )
{
+ #ifndef __FreeBSD__
struct timeb timer;
struct tm *gmTimer;
char * _test = NULL;
@@ -474,13 +482,27 @@ static void oaes_get_seed( char buf[RANDSIZ + 1] )
gmTimer->tm_year + 1900, gmTimer->tm_mon + 1, gmTimer->tm_mday,
gmTimer->tm_hour, gmTimer->tm_min, gmTimer->tm_sec, timer.millitm,
_test + timer.millitm, getpid() );
+ #else
+ struct timeval timer;
+ struct tm *gmTimer;
+ char * _test = NULL;
+ gettimeofday(&timer, NULL);
+ gmTimer = gmtime( &timer.tv_sec );
+ _test = (char *) calloc( sizeof( char ), timer.tv_usec/1000 );
+ sprintf( buf, "%04d%02d%02d%02d%02d%02d%03d%p%d",
+ gmTimer->tm_year + 1900, gmTimer->tm_mon + 1, gmTimer->tm_mday,
+ gmTimer->tm_hour, gmTimer->tm_min, gmTimer->tm_sec, timer.tv_usec/1000,
+ _test + timer.tv_usec/1000, getpid() );
+ #endif
+
if( _test )
free( _test );
}
#else
static uint32_t oaes_get_seed(void)
{
+ #ifndef __FreeBSD__
struct timeb timer;
struct tm *gmTimer;
char * _test = NULL;
@@ -492,6 +514,19 @@ static uint32_t oaes_get_seed(void)
_ret = gmTimer->tm_year + 1900 + gmTimer->tm_mon + 1 + gmTimer->tm_mday +
gmTimer->tm_hour + gmTimer->tm_min + gmTimer->tm_sec + timer.millitm +
(uintptr_t) ( _test + timer.millitm ) + getpid();
+ #else
+ struct timeval timer;
+ struct tm *gmTimer;
+ char * _test = NULL;
+ uint32_t _ret = 0;
+
+ gettimeofday(&timer, NULL);
+ gmTimer = gmtime( &timer.tv_sec );
+ _test = (char *) calloc( sizeof( char ), timer.tv_usec/1000 );
+ _ret = gmTimer->tm_year + 1900 + gmTimer->tm_mon + 1 + gmTimer->tm_mday +
+ gmTimer->tm_hour + gmTimer->tm_min + gmTimer->tm_sec + timer.tv_usec/1000 +
+ (uintptr_t) ( _test + timer.tv_usec/1000 ) + getpid();
+ #endif
if( _test )
free( _test );
diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c
index 4d1594723..3aff7bd5d 100644
--- a/src/crypto/slow-hash.c
+++ b/src/crypto/slow-hash.c
@@ -330,7 +330,7 @@ void slow_hash_allocate_state(void)
hp_state = (uint8_t *) VirtualAlloc(hp_state, MEMORY, MEM_LARGE_PAGES |
MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
#else
-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__FreeBSD__)
hp_state = mmap(0, MEMORY, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, 0, 0);
#else
diff --git a/src/crypto/tree-hash.c b/src/crypto/tree-hash.c
index 573f44643..5a84c8688 100644
--- a/src/crypto/tree-hash.c
+++ b/src/crypto/tree-hash.c
@@ -28,13 +28,18 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-#include <alloca.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include "hash-ops.h"
+#ifndef __FreeBSD__
+ #include <alloca.h>
+#else
+ #include <stdlib.h>
+#endif
+
/// Quick check if this is power of two (use on unsigned types; in this case for size_t only)
bool ispowerof2_size_t(size_t x) {
return x && !(x & (x - 1));