Skip to content

Commit

Permalink
diff: import bitcoin bignum class for conversions
Browse files Browse the repository at this point in the history
BIGNUM is defined in OpenSSL...
  • Loading branch information
tpruvot committed Jun 10, 2015
1 parent 5636e2b commit 39238f0
Show file tree
Hide file tree
Showing 7 changed files with 1,491 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
compat/inttypes.h compat/stdbool.h compat/unistd.h \
compat/sys/time.h compat/getopt/getopt.h \
crc32.c hefty1.c \
ccminer.cpp util.cpp \
ccminer.cpp util.cpp bignum.cpp \
api.cpp hashlog.cpp nvml.cpp stats.cpp sysinfos.cpp cuda.cpp \
heavy/heavy.cu \
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
Expand Down
26 changes: 26 additions & 0 deletions bignum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Wrapper to OpenSSL BIGNUM used by net diff (nBits)
*/

#include <stdio.h>

#include "uint256.h"
#include "bignum.hpp"

#include "miner.h" // hex2bin

extern "C" double bn_convert_nbits(const uint32_t nBits)
{
uint256 bn = CBigNum().SetCompact(nBits).getuint256();
return bn.getdouble();
}

// copy the big number to 32-bytes uchar
extern "C" void bn_nbits_to_uchar(const uint32_t nBits, unsigned char *target)
{
char buff[65];
uint256 bn = CBigNum().SetCompact(nBits).getuint256();

snprintf(buff, 65, "%s\n", bn.ToString().c_str()); buff[64] = '\0';
hex2bin(target, buff, 32);
}
Loading

0 comments on commit 39238f0

Please sign in to comment.