Skip to content
Open
Changes from all commits
Commits
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
137 changes: 103 additions & 34 deletions pkg/vere/comet_miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@
#include "serial.h"
#include <getopt.h>

void
_read_int(const c3_c* str_c, c3_w* out_w)
{
c3_c* end_c;
c3_w par_w = strtoul(str_c, &end_c, 0);

if ( *str_c == '\0' || *end_c != '\0' ) {
fprintf(stderr, "Life/rift must be an integer\n");
exit(EXIT_FAILURE);
}
else
*out_w = par_w;
}

u3_noun
c_ring(uint8_t *seed, size_t tw_len, uint8_t *tweak) {
u3_noun sed = u3i_bytes(64, seed);
u3_noun twe = u3i_bytes(tw_len, tweak);

u3_noun lis = u3i_list(u3nq(u3nc('s', u3_nul), 3, u3nc(1, 'C'), u3_nul),
u3nq(u3nc('s', u3_nul), 3, u3nc(64, sed), u3_nul),
u3qe_mat(twe),
u3_none);
u3_noun res = u3h(u3qg_plot_fax(0, lis));

u3z(twe);
u3z(lis);

return res;
}

void
urcrypt_shaf(uint8_t *salt, size_t salt_length,
const uint8_t *message, size_t message_length,
Expand All @@ -21,7 +52,6 @@ urcrypt_shaf(uint8_t *salt, size_t salt_length,
out[i] = _out[i] ^ _out[i + 16];
}


void set_16_bit(c3_d sar_d[1024], c3_s star) {
sar_d[star >> 6] |= (1ULL << (star & 0x3f));
}
Expand All @@ -46,7 +76,7 @@ c3_o has_16_bit(c3_d sar_d[1024], c3_s star) {
}

static void
_mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s) {
_mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, c3_w lif_w, c3_w rif_w) {
uint8_t salt[32];
memset(salt, 0, 32);
salt[0] = 'b';
Expand All @@ -58,11 +88,12 @@ _mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s) {
uint8_t private[64];
uint8_t public[32];
uint8_t comet[16];
uint8_t ring[64];
uint8_t ring[65];
uint8_t pass[65];
pass[0] = 'b';
ring[0] = 'B';
memset(seed, 0, 64);
memset(ring, 0, 64);
memset(ring + 1, 0, 64);
memset(private, 0, 64);
memset(public, 0, 32);
memset(comet, 0, 16);
Expand All @@ -73,13 +104,10 @@ _mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s) {
if ( c3n == inc_512(seed) ) {
ent_getentropy(seed, 64);
}
urcrypt_shal(seed, 64, ring);
urcrypt_ed_luck(ring, pass + 1, private);
urcrypt_ed_luck(ring + 32, pass + 1 + 32, private);
urcrypt_shal(seed, 64, ring + 1);
urcrypt_ed_luck(ring + 1, pass + 1, private);
urcrypt_ed_luck(ring + 1 + 32, pass + 1 + 32, private);
urcrypt_shaf(salt, 32, pass, 65, comet);
//ed25519_create_keypair(public, private, seed);
//urcrypt_ed_add_scalar_public_private(public, private, public, public_tw, private_tw);
//ed25519_add_scalar(public_tw, private_tw, public);
c3_s sar_s, fep_s;
sar_s = comet[0] + (comet[1] << 8);
fep_s = comet[14] + (comet[15] << 8);
Expand All @@ -94,21 +122,29 @@ _mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s) {


if ( 0 == (tries % 10000) )
printf("tries: %llu\n", tries);
printf("tries: %" PRIu64 "\n", tries);
}
printf("tries: %llu\n", tries);
printf("tries: %" PRIu64 "\n", tries);

u3_noun sed = u3dc("scot", c3__uw, u3i_bytes(64, seed));
c3_c* sed_c = u3r_string(sed);
printf("seed: %s\n", sed_c);
u3z(sed);
c3_free(sed_c);

u3_noun rin = u3dc("scot", c3__uw, u3i_bytes(64, ring));
u3_noun rin = u3dc("scot", c3__uw, u3i_bytes(65, ring));
c3_c* rin_c = u3r_string(rin);
printf("ring: %s\n", rin_c);
u3z(rin);
c3_free(rin_c);

u3_noun kyz = u3nc(u3nc(lif_w, u3i_bytes(65, ring)), u3_nul);
u3_noun fed = u3nq(u3nc(2, u3_nul), u3i_bytes(16, comet), rif_w, kyz);
u3_noun fuw = u3dc("scot", c3__uw, u3ke_jam(fed));
c3_c* fuw_c = u3r_string(fuw);
printf("feed: %s\n", fuw_c);
u3z(fuw);
c3_free(fuw_c);

u3_noun com = u3dc("scot", c3__p, u3i_bytes(16, comet));
c3_c* com_c = u3r_string(com);
Expand All @@ -118,7 +154,8 @@ _mine_b(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s) {
}

static void
_mine_c(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, size_t tw_len, uint8_t* tweak) {
_mine_c(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, size_t tw_len,
uint8_t* tweak, c3_w lif_w, c3_w rif_w) {
uint8_t salt[32];
memset(salt, 0, 32);
salt[0] = 'c';
Expand All @@ -129,14 +166,13 @@ _mine_c(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, size_t tw_len, uint8_t* tweak)
uint8_t seed[64];
uint8_t public[32];
uint8_t private[64];
uint8_t tw_public[32];
uint8_t tw_private[64];
uint8_t comet[16];
uint8_t ring[64];
memset(seed, 0, 64);
memset(ring, 0, 64);
memset(public, 0, 32);
memset(private, 0, 64);
memset(comet, 0, 16);
memset(ring, 0, 64);
uint64_t tries = 0;
uint8_t tw_dat[4096];
uint8_t tw_sca[32];
Expand All @@ -152,10 +188,8 @@ _mine_c(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, size_t tw_len, uint8_t* tweak)
memcpy(tw_dat, public, 32);
memcpy(tw_dat + 32, tweak, tw_len);
urcrypt_shay(tw_dat, 32 + tw_len, tw_sca);
memcpy(tw_public, public, 32);
memcpy(tw_private, private, 64);
urcrypt_ed_add_scalar_public_private(tw_public, tw_private, tw_sca);
urcrypt_shaf(salt, 32, tw_public, 32, comet);
urcrypt_ed_add_scalar_public_private(public, private, tw_sca);
urcrypt_shaf(salt, 32, public, 32, comet);
c3_s sar_s, fep_s;
sar_s = comet[0] + (comet[1] << 8);
fep_s = comet[14] + (comet[15] << 8);
Expand All @@ -168,22 +202,32 @@ _mine_c(c3_d sar_d[1024], c3_o pef_o, c3_s pef_s, size_t tw_len, uint8_t* tweak)
}

if ( 0 == (tries % 10000) )
printf("tries: %llu\n", tries);
printf("tries: %" PRIu64 "\n", tries);
}
printf("tries: %llu\n", tries);
printf("tries: %" PRIu64 "\n", tries);

u3_noun sed = u3dc("scot", c3__uw, u3i_bytes(64, seed));
c3_c* sed_c = u3r_string(sed);
printf("seed: %s\n", sed_c);
u3z(sed);
c3_free(sed_c);

u3_noun rin = u3dc("scot", c3__uw, u3i_bytes(64, ring));
c3_c* rin_c = u3r_string(rin);
u3_noun rin = c_ring(ring, tw_len, tweak);

u3_noun ruw = u3dc("scot", c3__uw, u3k(rin));
c3_c* rin_c = u3r_string(ruw);
printf("ring: %s\n", rin_c);
u3z(rin);
u3z(ruw);
c3_free(rin_c);

u3_noun kyz = u3nc(u3nc(lif_w, rin), u3_nul);
u3_noun fed = u3nq(u3nc(2, u3_nul), u3i_bytes(16, comet), rif_w, kyz);
u3_noun fuw = u3dc("scot", c3__uw, u3ke_jam(fed));
c3_c* fuw_c = u3r_string(fuw);
printf("feed: %s\n", fuw_c);
u3z(fuw);
c3_free(fuw_c);

u3_noun com = u3dc("scot", c3__p, u3i_bytes(16, comet));
c3_c* com_c = u3r_string(com);
printf("comet: %s\n", com_c);
Expand Down Expand Up @@ -244,19 +288,25 @@ main(c3_i argc,
{"suite-b", no_argument, 0, 'b'},
{"suite-c", no_argument, 0, 'c'},
{"tweak", required_argument, 0, 't'},
{"life", required_argument, 0, 'l'},
{"rift", required_argument, 0, 'r'},
{"prefix", required_argument, 0, 'p'},
{"any-star", no_argument, 0, 'a'},
{0, 0, 0, 0} // End of options marker
};

c3_w twe_w = 0;
c3_w twe_w = 0;
c3_c* twe_c = NULL;
c3_y* twe_y = NULL;
c3_c* pef_c = NULL;
c3_d* sar_d = NULL;
c3_o any_o = c3n;
c3_o suite_b = c3n;
c3_o suite_c = c3n;
c3_o any_o = c3n;
c3_o suite_b = c3n;
c3_o suite_c = c3n;
c3_c* lif_c = NULL;
c3_w lif_w = 1;
c3_c* rif_c = NULL;
c3_w rif_w = 0;

c3_i opt_i;
c3_i ind_i = 0;
Expand Down Expand Up @@ -285,6 +335,17 @@ main(c3_i argc,
twe_c = optarg;
break;
}

case 'l': {
lif_c = optarg;
break;
}

case 'r': {
rif_c = optarg;
break;
}

case 'p': {
pef_c = optarg;
break;
Expand Down Expand Up @@ -317,6 +378,14 @@ main(c3_i argc,
twe_y = u3r_bytes_all(&twe_w, twe);
u3z(twe);
}

if ( NULL != lif_c ) {
_read_int(lif_c, &lif_w);
}

if ( NULL != rif_c ) {
_read_int(rif_c, &rif_w);
}

ind_i = optind;
// Process any remaining non-option arguments
Expand All @@ -326,11 +395,11 @@ main(c3_i argc,
exit(EXIT_FAILURE);
}
c3_w len_w = argc - ind_i;
c3_s* sar_s = c3_calloc(len_w);
c3_s* sar_s = c3_calloc(len_w * sizeof(*sar_s));
c3_c star[8];
star[0] = '~';
star[7] = 0;
printf("mining stars");
printf("mining stars\n");
for (c3_w i = 0; i < len_w; i++) {
if ( 6 != strlen(argv[ind_i + i]) ) {
u3l_log("%s is not a star\n", star);
Expand Down Expand Up @@ -386,8 +455,8 @@ main(c3_i argc,
}

if ( c3y == suite_c ) {
_mine_c(sar_d, pef_o, pef_s, twe_w, twe_y);
_mine_c(sar_d, pef_o, pef_s, twe_w, twe_y, lif_w, rif_w);
} else {
_mine_b(sar_d, pef_o, pef_s);
_mine_b(sar_d, pef_o, pef_s, lif_w, rif_w);
}
}
Loading