Skip to content

Commit

Permalink
-Can specify full 256-bit vlaues for --stride instead of 64-bit values
Browse files Browse the repository at this point in the history
-Added missing error check in OpenCL initialization
-Fixed bug where hex formatted with h suffix (e.g. 1234h) was not parsed properly
  • Loading branch information
brichard19 committed Nov 28, 2018
1 parent e19aea6 commit 0d55dbd
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
19 changes: 11 additions & 8 deletions CLKeySearchDevice/CLKeySearchDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ CLKeySearchDevice::CLKeySearchDevice(uint64_t device, int threads, int pointsPer
// Create the context
_clContext = new cl::CLContext(_device);
Logger::log(LogLevel::Info, "Compiling OpenCL kernels...");
//_clProgram = new cl::CLProgram(*_clContext, util::getExeDirectory() + "KeySearch.cl");
_clProgram = new cl::CLProgram(*_clContext, _bitcrack_cl);

// Load the kernels
Expand Down Expand Up @@ -187,7 +186,7 @@ void CLKeySearchDevice::setIncrementor(secp256k1::ecpoint &p)
_clContext->copyHostToDevice(buf, _yInc, 8 * sizeof(unsigned int));
}

void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression, uint64_t stride)
void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride)
{
if(start.cmp(secp256k1::N) >= 0) {
throw KeySearchException("Starting key is out of range");
Expand All @@ -199,15 +198,19 @@ void CLKeySearchDevice::init(const secp256k1::uint256 &start, int compression, u

_compression = compression;

allocateBuffers();
try {
allocateBuffers();

generateStartingPoints();
generateStartingPoints();

// Set the incrementor
secp256k1::ecpoint g = secp256k1::G();
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread).mul(secp256k1::uint256(_stride)), g);
// Set the incrementor
secp256k1::ecpoint g = secp256k1::G();
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256((uint64_t)_threads * _blocks * _pointsPerThread) * _stride, g);

setIncrementor(p);
setIncrementor(p);
} catch(cl::CLException ex) {
throw KeySearchException(ex.msg);
}
}

void CLKeySearchDevice::doStep()
Expand Down
6 changes: 3 additions & 3 deletions CLKeySearchDevice/CLKeySearchDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class CLKeySearchDevice : public KeySearchDevice {

int _compression = PointCompressionType::COMPRESSED;

uint64_t _iterations;
uint64_t _iterations = 0;

uint64_t _stride = 1;
secp256k1::uint256 _stride = 1;

std::string _deviceName;

Expand Down Expand Up @@ -113,7 +113,7 @@ class CLKeySearchDevice : public KeySearchDevice {


// Initialize the device
virtual void init(const secp256k1::uint256 &start, int compression, uint64_t stride);
virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride);

// Perform one iteration
virtual void doStep();
Expand Down
4 changes: 2 additions & 2 deletions CudaKeySearchDevice/CudaKeySearchDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CudaKeySearchDevice::CudaKeySearchDevice(int device, int threads, int pointsPerT
_pointsPerThread = pointsPerThread;
}

void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression, uint64_t stride)
void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride)
{
if(start.cmp(secp256k1::N) >= 0) {
throw KeySearchException("Starting key is out of range");
Expand Down Expand Up @@ -89,7 +89,7 @@ void CudaKeySearchDevice::init(const secp256k1::uint256 &start, int compression,

// Set the incrementor
secp256k1::ecpoint g = secp256k1::G();
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256(_threads * _blocks * _pointsPerThread).mul(secp256k1::uint256(_stride)), g);
secp256k1::ecpoint p = secp256k1::multiplyPoint(secp256k1::uint256((uint64_t)_threads * _blocks * _pointsPerThread) * _stride, g);

cudaCall(_resultList.init(sizeof(CudaDeviceResult), 16));

Expand Down
4 changes: 2 additions & 2 deletions CudaKeySearchDevice/CudaKeySearchDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class CudaKeySearchDevice : public KeySearchDevice {

uint32_t getPrivateKeyOffset(int thread, int block, int point);

uint64_t _stride;
secp256k1::uint256 _stride;

bool verifyKey(const secp256k1::uint256 &privateKey, const secp256k1::ecpoint &publicKey, const unsigned int hash[5], bool compressed);

public:

CudaKeySearchDevice(int device, int threads, int pointsPerThread, int blocks = 0);

virtual void init(const secp256k1::uint256 &start, int compression, uint64_t stride);
virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride);

virtual void doStep();

Expand Down
21 changes: 16 additions & 5 deletions KeyFinder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ typedef struct {

uint64_t totalkeys = 0;
unsigned int elapsed = 0;
uint64_t stride = 1;

secp256k1::uint256 stride = 1;
}RunConfig;

static RunConfig _config;
Expand Down Expand Up @@ -309,7 +308,7 @@ void writeCheckpoint(secp256k1::uint256 nextKey)
tmp << "compression=" << getCompressionString(_config.compression) << std::endl;
tmp << "device=" << _config.device << std::endl;
tmp << "elapsed=" << (_config.elapsed + util::getSystemTime() - _startTime) << std::endl;
tmp << "stride=" << (_config.stride);
tmp << "stride=" << _config.stride.toString();
tmp.close();
}

Expand Down Expand Up @@ -365,7 +364,7 @@ int run()
Logger::log(LogLevel::Info, "Compression: " + getCompressionString(_config.compression));
Logger::log(LogLevel::Info, "Starting at: " + _config.nextKey.toString());
Logger::log(LogLevel::Info, "Ending at: " + _config.endKey.toString());
Logger::log(LogLevel::Info, "Counting by: " + util::format(_config.stride));
Logger::log(LogLevel::Info, "Counting by: " + _config.stride.toString());

try {

Expand Down Expand Up @@ -563,7 +562,19 @@ int main(int argc, char **argv)
}
optShares = true;
} else if(optArg.equals("", "--stride")) {
_config.stride = util::parseUInt64(optArg.arg);
try {
_config.stride = secp256k1::uint256(optArg.arg);
} catch(...) {
throw std::string("invalid argument: : expected hex string");
}

if(_config.stride.cmp(secp256k1::N) >= 0) {
throw std::string("argument is out of range");
}

if(_config.stride.cmp(0) == 0) {
throw std::string("argument is out of range");
}
}

} catch(std::string err) {
Expand Down
2 changes: 1 addition & 1 deletion KeyFinderLib/KeyFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void KeyFinder::defaultStatusCallback(KeySearchStatus status)
// Do nothing
}

KeyFinder::KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, uint64_t stride)
KeyFinder::KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, const secp256k1::uint256 &stride)
{
_total = 0;
_statusInterval = 1000;
Expand Down
4 changes: 2 additions & 2 deletions KeyFinderLib/KeyFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class KeyFinder {

uint64_t _statusInterval;

uint64_t _stride = 1;
secp256k1::uint256 _stride = 1;
uint64_t _iterCount;
uint64_t _total;
uint64_t _totalTime;
Expand All @@ -45,7 +45,7 @@ class KeyFinder {

public:

KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, uint64_t stride);
KeyFinder(const secp256k1::uint256 &startKey, const secp256k1::uint256 &endKey, int compression, KeySearchDevice* device, const secp256k1::uint256 &stride);

~KeyFinder();

Expand Down
2 changes: 1 addition & 1 deletion KeyFinderLib/KeySearchDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class KeySearchDevice {
public:

// Initialize the device
virtual void init(const secp256k1::uint256 &start, int compression, uint64_t stride) = 0;
virtual void init(const secp256k1::uint256 &start, int compression, const secp256k1::uint256 &stride) = 0;

// Perform one iteration
virtual void doStep() = 0;
Expand Down
7 changes: 6 additions & 1 deletion secp256k1lib/secp256k1.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace secp256k1 {

// 'h' suffix
if(t.length() >= 1 && t[t.length() - 1] == 'h') {
t = t.substr(0, t.length() - 2);
t = t.substr(0, t.length() - 1);
}

if(t.length() == 0) {
Expand Down Expand Up @@ -129,6 +129,11 @@ namespace secp256k1 {
return mul(x);
}

uint256 operator*(const uint256 &x) const
{
return mul(x);
}

uint256 operator*(uint64_t x) const
{
return mul(x);
Expand Down

0 comments on commit 0d55dbd

Please sign in to comment.