Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added candy #283

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c68e662
Read CHANGELOG.md to see the updates
albertobsd Apr 28, 2023
765f23d
Fixed README.md
albertobsd Apr 28, 2023
63aa8fb
some fixes, check CHANGELOG.md
albertobsd Apr 30, 2023
e5d093f
Update keyhunt.cpp
seega May 4, 2023
65987aa
Update Random.cpp
seega May 4, 2023
f08dff0
Merge pull request #208 from seega/main
albertobsd May 4, 2023
d3d9ef6
cygwin fix v2
seega May 6, 2023
ec56e1f
cygwin fix
seega May 6, 2023
0253114
Revert "cygwin fix"
seega May 6, 2023
6a25033
Update Random.cpp
seega May 6, 2023
1cce3bb
Merge pull request #210 from seega/main
albertobsd May 7, 2023
d29ea17
added option -6 to skip checksums, check CHANGELOG.md
albertobsd May 7, 2023
8d54417
Update keyhunt.cpp
seega May 7, 2023
dfb710b
Merge pull request #212 from seega/main
albertobsd May 7, 2023
8a51838
Added warning for BSGS and Endomorphism, they don't work together
albertobsd May 8, 2023
5a8d6c0
Update README.md
mysterek1337 May 12, 2023
84330e6
Merge pull request #213 from mysterek1337/main
albertobsd May 12, 2023
a278e8c
added keyhunt_legacy.cpp legacy version, check README.md
albertobsd May 16, 2023
98b20ef
removed unused flags in the Makefile
albertobsd May 16, 2023
dddd177
fixed some bugs for legacy version
albertobsd May 17, 2023
3cd3376
Small editions of unused variables
albertobsd May 17, 2023
f92555a
endomorphism for eth
albertobsd May 18, 2023
88934c8
endomorphism for eth in legacy version
albertobsd May 18, 2023
d345a3c
Speed x2 for BSGS mode main
albertobsd May 19, 2023
2b3c218
Double BSGS speed for legacy version
albertobsd May 20, 2023
e3c6762
BSGS Server (Only linux)
albertobsd May 30, 2023
a19a745
Solving some BSGS Server issues
albertobsd Jun 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cygwin fix
  • Loading branch information
seega authored May 6, 2023
commit ec56e1f8d216be1e6cf5782fe9dc9fd28fe0abbf
287 changes: 145 additions & 142 deletions secp256k1/Random.cpp
Original file line number Diff line number Diff line change
@@ -1,142 +1,145 @@
/*
* This file is part of the BSGS distribution (https://github.com/JeanLucPons/BSGS).
* Copyright (c) 2020 Jean Luc PONS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "Random.h"

#if defined(_WIN64) && !defined(__CYGWIN__)
#else
#include <sys/random.h>
#endif

#ifdef __unix__
#include <linux/random.h>
#endif

#define RK_STATE_LEN 624

/* State of the RNG */
typedef struct rk_state_
{
unsigned long key[RK_STATE_LEN];
int pos;
} rk_state;

rk_state localState;

/* Maximum generated random value */
#define RK_MAX 0xFFFFFFFFUL

void rk_seed(unsigned long seed, rk_state *state)
{
int pos;
seed &= 0xffffffffUL;

/* Knuth's PRNG as used in the Mersenne Twister reference implementation */
for (pos=0; pos<RK_STATE_LEN; pos++)
{
state->key[pos] = seed;
seed = (1812433253UL * (seed ^ (seed >> 30)) + pos + 1) & 0xffffffffUL;
}

state->pos = RK_STATE_LEN;
}

/* Magic Mersenne Twister constants */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL
#define UPPER_MASK 0x80000000UL
#define LOWER_MASK 0x7fffffffUL

#ifdef _WIN64
// Disable "unary minus operator applied to unsigned type, result still unsigned" warning.
#pragma warning(disable : 4146)
#endif

/* Slightly optimised reference implementation of the Mersenne Twister */
inline unsigned long rk_random(rk_state *state)
{
unsigned long y;

if (state->pos == RK_STATE_LEN)
{
int i;

for (i=0;i<N-M;i++)
{
y = (state->key[i] & UPPER_MASK) | (state->key[i+1] & LOWER_MASK);
state->key[i] = state->key[i+M] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);
}
for (;i<N-1;i++)
{
y = (state->key[i] & UPPER_MASK) | (state->key[i+1] & LOWER_MASK);
state->key[i] = state->key[i+(M-N)] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);
}
y = (state->key[N-1] & UPPER_MASK) | (state->key[0] & LOWER_MASK);
state->key[N-1] = state->key[M-1] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);

state->pos = 0;
}

y = state->key[state->pos++];

/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);

return y;
}

inline double rk_double(rk_state *state)
{
/* shifts : 67108864 = 0x4000000, 9007199254740992 = 0x20000000000000 */
long a = rk_random(state) >> 5, b = rk_random(state) >> 6;
return (a * 67108864.0 + b) / 9007199254740992.0;
}

// Initialise the random generator with the specified seed
void rseed(unsigned long seed) {
rk_seed(seed,&localState);
//srand(seed);
}

#if defined(_WIN64) && !defined(__CYGWIN__)
unsigned long rndl() {
return rk_random(&localState);
}
#else
unsigned long rndl() {
unsigned long r;
int bytes_read = getrandom(&r, sizeof(unsigned long), GRND_NONBLOCK );
if (bytes_read > 0) {
return r;
}
else {
/*Fail safe */
return rk_random(&localState);
}
}

#endif

// Returns a uniform distributed double value in the interval ]0,1[
double rnd() {
return rk_double(&localState);
}
/*
* This file is part of the BSGS distribution (https://github.com/JeanLucPons/BSGS).
* Copyright (c) 2020 Jean Luc PONS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "Random.h"

#if defined(_WIN64) && !defined(__CYGWIN__)
#else
#include <sys/random.h>
#endif

#ifdef __unix__
#ifdef __CYGWIN__
#else
#include <linux/random.h>
#endif
#endif

#define RK_STATE_LEN 624

/* State of the RNG */
typedef struct rk_state_
{
unsigned long key[RK_STATE_LEN];
int pos;
} rk_state;

rk_state localState;

/* Maximum generated random value */
#define RK_MAX 0xFFFFFFFFUL

void rk_seed(unsigned long seed, rk_state *state)
{
int pos;
seed &= 0xffffffffUL;

/* Knuth's PRNG as used in the Mersenne Twister reference implementation */
for (pos=0; pos<RK_STATE_LEN; pos++)
{
state->key[pos] = seed;
seed = (1812433253UL * (seed ^ (seed >> 30)) + pos + 1) & 0xffffffffUL;
}

state->pos = RK_STATE_LEN;
}

/* Magic Mersenne Twister constants */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL
#define UPPER_MASK 0x80000000UL
#define LOWER_MASK 0x7fffffffUL

#ifdef _WIN64
// Disable "unary minus operator applied to unsigned type, result still unsigned" warning.
#pragma warning(disable : 4146)
#endif

/* Slightly optimised reference implementation of the Mersenne Twister */
inline unsigned long rk_random(rk_state *state)
{
unsigned long y;

if (state->pos == RK_STATE_LEN)
{
int i;

for (i=0;i<N-M;i++)
{
y = (state->key[i] & UPPER_MASK) | (state->key[i+1] & LOWER_MASK);
state->key[i] = state->key[i+M] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);
}
for (;i<N-1;i++)
{
y = (state->key[i] & UPPER_MASK) | (state->key[i+1] & LOWER_MASK);
state->key[i] = state->key[i+(M-N)] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);
}
y = (state->key[N-1] & UPPER_MASK) | (state->key[0] & LOWER_MASK);
state->key[N-1] = state->key[M-1] ^ (y>>1) ^ (-(y & 1) & MATRIX_A);

state->pos = 0;
}

y = state->key[state->pos++];

/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18);

return y;
}

inline double rk_double(rk_state *state)
{
/* shifts : 67108864 = 0x4000000, 9007199254740992 = 0x20000000000000 */
long a = rk_random(state) >> 5, b = rk_random(state) >> 6;
return (a * 67108864.0 + b) / 9007199254740992.0;
}

// Initialise the random generator with the specified seed
void rseed(unsigned long seed) {
rk_seed(seed,&localState);
//srand(seed);
}

#if defined(_WIN64) && !defined(__CYGWIN__)
unsigned long rndl() {
return rk_random(&localState);
}
#else
unsigned long rndl() {
unsigned long r;
int bytes_read = getrandom(&r, sizeof(unsigned long), GRND_NONBLOCK );
if (bytes_read > 0) {
return r;
}
else {
/*Fail safe */
return rk_random(&localState);
}
}

#endif

// Returns a uniform distributed double value in the interval ]0,1[
double rnd() {
return rk_double(&localState);
}