Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from digicontributer/dev
Browse files Browse the repository at this point in the history
digibyte support
  • Loading branch information
digicontributer committed Dec 20, 2017
2 parents c01ff88 + f715a0a commit d53e945
Show file tree
Hide file tree
Showing 36 changed files with 21,351 additions and 21 deletions.
16 changes: 16 additions & 0 deletions BRCrypto.c
Expand Up @@ -23,6 +23,10 @@
// THE SOFTWARE.

#include "BRCrypto.h"
#include "crypto/groestl.h"
#include "crypto/skein.h"
#include "crypto/qubit.h"

#include <stdlib.h>
#include <string.h>
#include <assert.h>
Expand Down Expand Up @@ -897,3 +901,15 @@ void BRScrypt(void *dk, size_t dkLen, const void *pw, size_t pwLen, const void *
mem_clean(v, 128*r*n);
free(v);
}

void BRSkein(const char* input, char* output) {
skein_hash(input, output);
}

void BRGroestl(const char* input, char* output){
groestl_hash(input, output);
}

void BRQubit(const char* input, char* output) {
qubit_hash(input, output);
}
6 changes: 6 additions & 0 deletions BRCrypto.h
Expand Up @@ -89,6 +89,12 @@ void BRPBKDF2(void *dk, size_t dkLen, void (*hash)(void *, const void *, size_t)
void BRScrypt(void *dk, size_t dkLen, const void *pw, size_t pwLen, const void *salt, size_t saltLen,
unsigned n, unsigned r, unsigned p);

void BRSkein(const char* input, char* output);

void BRGroestl(const char* input, char* output);

void BRQubit(const char* input, char* output);

// zeros out memory in a way that can't be optimized out by the compiler
inline static void mem_clean(void *ptr, size_t len)
{
Expand Down
30 changes: 26 additions & 4 deletions BRMerkleBlock.c
Expand Up @@ -32,7 +32,8 @@
#include <assert.h>

#define MAX_PROOF_OF_WORK 0x1e0fffff // highest value for difficulty target (higher values are less difficult)
#define TARGET_TIMESPAN (0.10*24*60*60) // the targeted timespan between difficulty target adjustments
#define TARGET_TIMESPAN (0.10*24*60*60) // the targeted timespan between difficulty target adjustments
#define BLOCK_VERSION_ALGO (7 << 9)

inline static int _ceil_log2(int x)
{
Expand Down Expand Up @@ -123,7 +124,28 @@ BRMerkleBlock *BRMerkleBlockParse(const uint8_t *buf, size_t bufLen)
}

BRSHA256_2(&block->blockHash, buf, 80);
BRScrypt(&block->powHash, sizeof(block->powHash), buf, 80, buf, 80, 1024, 1, 1);

switch (block->version & BLOCK_VERSION_ALGO) {
case 512:
BRSHA256_2(&block->powHash, buf, 80);
break;

case 1536:
BRSkein(&block->powHash, buf);
break;

case 2048:
BRQubit(&block->powHash, buf);
break;

case 1024:
BRGroestl(&block->powHash, buf);
break;

default:
BRScrypt(&block->powHash, sizeof(block->powHash), buf, 80, buf, 80, 1024, 1, 1);

}
}

return block;
Expand Down Expand Up @@ -289,7 +311,7 @@ int BRMerkleBlockIsValid(const BRMerkleBlock *block, uint32_t currentTime)

if (size > 3) UInt32SetLE(&t.u8[size - 3], target);
else UInt32SetLE(t.u8, target >> (3 - size)*8);

for (int i = sizeof(t) - 1; r && i >= 0; i--) { // check proof-of-work
if (block->powHash.u8[i] < t.u8[i]) break;
if (block->powHash.u8[i] > t.u8[i]) {
Expand All @@ -298,7 +320,7 @@ int BRMerkleBlockIsValid(const BRMerkleBlock *block, uint32_t currentTime)
digi_log("invalid blockHash[%d]: %x - %x", i, block->powHash.u8[i], t.u8[i]);
}
}

return r;
}

Expand Down
2 changes: 1 addition & 1 deletion BRMerkleBlock.h
Expand Up @@ -44,7 +44,7 @@
extern "C" {
#endif

#define BLOCK_DIFFICULTY_INTERVAL 144 // number of blocks between difficulty target adjustments
#define BLOCK_DIFFICULTY_INTERVAL 1 // number of blocks between difficulty target adjustments
#define BLOCK_UNKNOWN_HEIGHT INT32_MAX
#define BLOCK_MAX_TIME_DRIFT (2*60*60) // the furthest in the future a block is allowed to be timestamped

Expand Down
6 changes: 3 additions & 3 deletions BRPeer.c
Expand Up @@ -46,14 +46,14 @@
#if BITCOIN_TESTNET
#define MAGIC_NUMBER 0xdab6c3fau //TODO: When the testnet becomes available update this value
#else
#define MAGIC_NUMBER 0xdab6c3fau
#define MAGIC_NUMBER 0xdab6c3fa
#endif
#define HEADER_LENGTH 24
#define MAX_MSG_LENGTH 0x02000000u
#define MAX_GETDATA_HASHES 50000
#define ENABLED_SERVICES 0ULL // we don't provide full blocks to remote nodes
#define PROTOCOL_VERSION 70015
#define MIN_PROTO_VERSION 70001 // peers earlier than this protocol version not supported (need v0.9 txFee relay rules)
#define MIN_PROTO_VERSION 70002 // peers earlier than this protocol version not supported (need v0.9 txFee relay rules)
#define LOCAL_HOST ((UInt128) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 })
#define CONNECT_TIMEOUT 3.0
#define MESSAGE_TIMEOUT 10.0
Expand Down Expand Up @@ -485,7 +485,7 @@ static int _BRPeerAcceptHeadersMessage(BRPeer *peer, const uint8_t *msg, size_t
BRMerkleBlock *block = BRMerkleBlockParse(&msg[off + 81*i], 81);

if (! BRMerkleBlockIsValid(block, (uint32_t)now)) {
peer_log(peer, "invalid block header: %s", u256_hex_encode(block->blockHash));
peer_log(peer, "invalid block header: %s ", u256_hex_encode(block->blockHash));
BRMerkleBlockFree(block);
r = 0;
}
Expand Down
35 changes: 22 additions & 13 deletions BRPeerManager.c
Expand Up @@ -43,7 +43,7 @@
#define MAX_CONNECT_FAILURES 20 // notify user of network problems after this many connect failures in a row
#define CHECKPOINT_COUNT (sizeof(checkpoint_array)/sizeof(*checkpoint_array))
#define DNS_SEEDS_COUNT (sizeof(dns_seeds)/sizeof(*dns_seeds))
#define GENESIS_BLOCK_HASH (UInt256Reverse(u256_hex_decode("7497ea1b465eb39f1c8f507bc877078fe016d6fcb6dfad3a64c98dcc6e1e8496")))
#define GENESIS_BLOCK_HASH (UInt256Reverse(u256_hex_decode(checkpoint_array[0].hash)))
#define PEER_FLAG_SYNCED 0x01
#define PEER_FLAG_NEEDSUPDATE 0x02

Expand Down Expand Up @@ -78,21 +78,30 @@ static const struct {
uint32_t timestamp;
uint32_t target;
} checkpoint_array[] = {
// { 0, "852c475c605e1f20bbe60219c811abaeef08bf0d4ff87eef59200fd7a7567fa7", 1413145109, 0x1b336ce6 },
// Sitt 2016-02-18 Use Checkpoint from the First day of digiwallet fork (from breadWallet)
{ 145000, "f8d650dda836d5e3809b928b8523f050891c3bb9fa2c201bb04824a8a2fe7df6", 1409596362, 0x1c01f271},
{ 1800000, "72f46e1fff56518dce7e540b407260ea827cb1c4652f24eb1d1917f54b95d65a", 1454769372, 0x1c021355},
{ 2149922, "557846763a5f1eb3205d175724bd26ba7123c17c49eaaadf20b67c7e20e3118a", 1460001303, 0x1c012a26},
{ 4444444, "0000000000000114de2ba1462056d2a9bd9ccfbd406cd2dfedaaef2c12910659", 1494132592, 0x1a01152f}
{ 0, "7497ea1b465eb39f1c8f507bc877078fe016d6fcb6dfad3a64c98dcc6e1e8496", 1389388394, 0x1e0ffff0 },
{ 5000, "95753d284404118788a799ac754a3fdb5d817f5bd73a78697dfe40985c085596", 1389701913, 0x1c32a753 },
{ 10000, "12f90b8744f3b965e107ad9fd8b33ba6d95a91882fbc4b5f8588d70d494bed88", 1389996580, 0x1c1557fc },
{ 12000, "a1266acba91dc3d5737d9e8c6e21b7a91901f7f4c48082ce3d84dd394a13e415", 1390115182, 0x1c0d748e },
{ 14300, "24f665d71b0c6c88f6f72a863e9f1ba8e835cc52d13ad895dc5426021c7d2c48", 1390258861, 0x1c1409e7 },
{ 30000, "17c69ef6b403571b1bd333c91fbe116e451ba8281be12aa6bafb0486764bb315", 1391206674, 0x1c0e8ff5 },
{ 60000, "57b2c612b60462a3d6c388c8b30a68cb6f7e2034eea962b12b7ef506454fa2c1", 1393183580, 0x1c16beae },
{ 110000, "ab2da24656493015f2fd288994661e1cc657d90aa34c755514af044aaaf1569d", 1397850930, 0x1c198d98 },
{ 141100, "145c2cb5239a4e019c730ce8468d927a3955529c2bae077850783da97ddbca05", 1407018505, 0x1c01722c },
{ 141656, "683d27720429f28bcfa22d8385b7a06f307c8fd918d49215148fbd41a0dda595", 1408033242, 0x1c0185fc },
{ 245000, "852c475c605e1f20bbe60219c811abaeef08bf0d4ff87eef59200fd7a7567fa7", 1413145109, 0x1c028e59 },
{ 302000, "fb6d14ac5e0208f00d941db1fcbfe050f093cfd0c05ed151c809e4428bc14286", 1414988281, 0x1b0fb02e },
{ 331000, "bd1a1d002750e1648746eb29c78d30fa1043c8b6f89d82924c4488be06fa3d19", 1415917252, 0x1c07e8f8 },
{ 360000, "8fee7e3f6c38dccd3047a3e4667c63406f835c2890024030a2ab2dc6dba7c912", 1416891634, 0x1b2c1714 },
{ 400100, "82325a97cd97ac14b0a57408f881b1a9fc40174f8430a4580429499ac5d153c8", 1418232367, 0x1c020a1c },
{ 521000, "d23fd1e1f994c0586d761b71bb3530e9ab45bd0fabda3a5a2e394f3dc4d9bb04", 1421875139, 0x1c04531c },
{ 1380000, "00000000000001969b1e5836dd8bf6a001d96f4a16d336e09405b62b29feead6", 1447731080, 0x1a02e03e },
{ 1435000, "f78cc9c2791c8a23720e2efcdaf46584046ee5db8f050e21a3a15a13f5c68da0", 1449312651, 0x1c1f3df6 },
{ 4255555, "23f72e760542bf021ec76d04231ad7cf80142069a79ba702028e074b726f86ef", 1491329321, 0x1b26a4c3 },
{ 5712333, "0000000000000003363ff6207a99a175e8b5adff71c77817a92f127fcefe936e", 1513061829, 0x1924bd79}
};

static const char *dns_seeds[] = {
"digibyte.io.",
"seed.digibyte.io.",
"digiexplorer.info.",
"digiexplorer.info.",
"digihash.co.",
"digihash.co."
"seed.digibyte.io."
};

#endif
Expand Down
26 changes: 26 additions & 0 deletions crypto/groestl.c
@@ -0,0 +1,26 @@
#include "groestl.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "sha3/sph_groestl.h"
#include "sha256.h"


// This is myriadgroestl
void groestl_hash(const char* input, char* output)
{
uint32_t len = 80;
char temp[64];

sph_groestl512_context ctx_groestl;
sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, input, len);
sph_groestl512_close(&ctx_groestl, &temp);

SHA256_CTX ctx_sha256;
SHA256_Init(&ctx_sha256);
SHA256_Update(&ctx_sha256, &temp, 64);
SHA256_Final((unsigned char*) output, &ctx_sha256);
}
15 changes: 15 additions & 0 deletions crypto/groestl.h
@@ -0,0 +1,15 @@
#ifndef GROESTL_H
#define GROESTL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void groestl_hash(const char* input, char* output);
#ifdef __cplusplus
}
#endif

#endif
45 changes: 45 additions & 0 deletions crypto/qubit.c
@@ -0,0 +1,45 @@
#include "qubit.h"

#include <string.h>
#include <stdlib.h>

#include "sha3/sph_cubehash.h"
#include "sha3/sph_luffa.h"
#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
#include "sha3/sph_echo.h"

void qubit_hash(const char* input, char* output)
{
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_echo512_context ctx_echo;

uint32_t len = 80;
char hash1[64];
char hash2[64];

sph_luffa512_init(&ctx_luffa);
sph_luffa512(&ctx_luffa, (const void*) input, len);
sph_luffa512_close(&ctx_luffa, (void*) &hash1); // 1

sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64); // 1
sph_cubehash512_close(&ctx_cubehash, (void*) &hash2); // 2

sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, (const void*) &hash2, 64); // 3
sph_shavite512_close(&ctx_shavite, (void*) &hash1); // 4

sph_simd512_init(&ctx_simd);
sph_simd512(&ctx_simd, (const void*) &hash1, 64); // 4
sph_simd512_close(&ctx_simd, (void*) &hash2); // 5

sph_echo512_init(&ctx_echo);
sph_echo512(&ctx_echo, (const void*) &hash2, 64); // 5
sph_echo512_close(&ctx_echo, (void*) &hash1); // 6

memcpy(output, &hash1, 32);
}
16 changes: 16 additions & 0 deletions crypto/qubit.h
@@ -0,0 +1,16 @@
#ifndef QUBIT_H
#define QUBIT_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

void qubit_hash(const char* input, char* output);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit d53e945

Please sign in to comment.