Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2015 The Darkcoin Developers
Copyright (c) 2014-2015 The Dash Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
darkcoin_hash (python) v1.3
dash_hash (python) v1.3
===========================

Python module for Darkcoin's X11 hashing.
Python module for Dash's X11 hashing.


Install
Expand All @@ -13,9 +13,9 @@ Python 2.7 is required as well as a gcc.

Or use pip:

$ pip install darkcoin_hash
$ pip install dash_hash

[pypi.python.org/pypi/darkcoin_hash](https://pypi.python.org/pypi/darkcoin_hash)
[pypi.python.org/pypi/dash_hash](https://pypi.python.org/pypi/dash_hash)

Test
-------
Expand All @@ -29,5 +29,5 @@ Credits

* Module written by @chaeplin https://github.com/chaeplin/xcoin-hash
* Module maintained by @eduffield https://github.com/darkcoinproject/xcoin-hash
* Module maintained by @flare https://github.com/nightlydarkcoin/xcoin-hash
* Module maintained by @flare https://github.com/nightlydash/xcoin-hash
* Module maintained by @vertoe https://github.com/vertoe/darkcoin_hash
85 changes: 85 additions & 0 deletions dash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "dash.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "sha3/sph_blake.h"
#include "sha3/sph_bmw.h"
#include "sha3/sph_groestl.h"
#include "sha3/sph_jh.h"
#include "sha3/sph_keccak.h"
#include "sha3/sph_skein.h"
#include "sha3/sph_luffa.h"
#include "sha3/sph_cubehash.h"
#include "sha3/sph_shavite.h"
#include "sha3/sph_simd.h"
#include "sha3/sph_echo.h"


void dash_hash(const char* input, char* output)
{
sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_skein512_context ctx_skein;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;

sph_luffa512_context ctx_luffa1;
sph_cubehash512_context ctx_cubehash1;
sph_shavite512_context ctx_shavite1;
sph_simd512_context ctx_simd1;
sph_echo512_context ctx_echo1;

//these uint512 in the c++ source of the client are backed by an array of uint32
uint32_t hashA[16], hashB[16];

sph_blake512_init(&ctx_blake);
sph_blake512 (&ctx_blake, input, 80);
sph_blake512_close (&ctx_blake, hashA);

sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, hashA, 64);
sph_bmw512_close(&ctx_bmw, hashB);

sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, hashB, 64);
sph_groestl512_close(&ctx_groestl, hashA);

sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, hashA, 64);
sph_skein512_close (&ctx_skein, hashB);

sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, hashB, 64);
sph_jh512_close(&ctx_jh, hashA);

sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, hashA, 64);
sph_keccak512_close(&ctx_keccak, hashB);

sph_luffa512_init (&ctx_luffa1);
sph_luffa512 (&ctx_luffa1, hashB, 64);
sph_luffa512_close (&ctx_luffa1, hashA);

sph_cubehash512_init (&ctx_cubehash1);
sph_cubehash512 (&ctx_cubehash1, hashA, 64);
sph_cubehash512_close(&ctx_cubehash1, hashB);

sph_shavite512_init (&ctx_shavite1);
sph_shavite512 (&ctx_shavite1, hashB, 64);
sph_shavite512_close(&ctx_shavite1, hashA);

sph_simd512_init (&ctx_simd1);
sph_simd512 (&ctx_simd1, hashA, 64);
sph_simd512_close(&ctx_simd1, hashB);

sph_echo512_init (&ctx_echo1);
sph_echo512 (&ctx_echo1, hashB, 64);
sph_echo512_close(&ctx_echo1, hashA);

memcpy(output, hashA, 32);

}

14 changes: 14 additions & 0 deletions dash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef DASH_H
#define DASH_H

#ifdef __cplusplus
extern "C" {
#endif

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

#ifdef __cplusplus
}
#endif

#endif
57 changes: 57 additions & 0 deletions dashmodule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <Python.h>

#include "dash.h"

static PyObject *dash_getpowhash(PyObject *self, PyObject *args)
{
char *output;
PyObject *value;
#if PY_MAJOR_VERSION >= 3
PyBytesObject *input;
#else
PyStringObject *input;
#endif
if (!PyArg_ParseTuple(args, "S", &input))
return NULL;
Py_INCREF(input);
output = PyMem_Malloc(32);

#if PY_MAJOR_VERSION >= 3
dash_hash((char *)PyBytes_AsString((PyObject*) input), output);
#else
dash_hash((char *)PyString_AsString((PyObject*) input), output);
#endif
Py_DECREF(input);
#if PY_MAJOR_VERSION >= 3
value = Py_BuildValue("y#", output, 32);
#else
value = Py_BuildValue("s#", output, 32);
#endif
PyMem_Free(output);
return value;
}

static PyMethodDef DashMethods[] = {
{ "getPoWHash", dash_getpowhash, METH_VARARGS, "Returns the proof of work hash using dash hash" },
{ NULL, NULL, 0, NULL }
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef DashModule = {
PyModuleDef_HEAD_INIT,
"dash_hash",
"...",
-1,
DashMethods
};

PyMODINIT_FUNC PyInit_dash_hash(void) {
return PyModule_Create(&DashModule);
}

#else

PyMODINIT_FUNC initdash_hash(void) {
(void) Py_InitModule("dash_hash", DashMethods);
}
#endif
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from distutils.core import setup, Extension

darkcoin_hash_module = Extension('darkcoin_hash',
sources = ['darkcoinmodule.c',
'darkcoin.c',
dash_hash_module = Extension('dash_hash',
sources = ['dashmodule.c',
'dash.c',
'sha3/blake.c',
'sha3/bmw.c',
'sha3/groestl.c',
Expand All @@ -16,7 +16,7 @@
'sha3/shavite.c'],
include_dirs=['.', './sha3'])

setup (name = 'darkcoin_hash',
setup (name = 'dash_hash',
version = '1.3',
description = 'Binding for Darkcoin X11 proof of work hashing.',
ext_modules = [darkcoin_hash_module])
description = 'Binding for Dash X11 proof of work hashing.',
ext_modules = [dash_hash_module])
12 changes: 6 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import darkcoin_hash
import dash_hash
from binascii import unhexlify, hexlify

import unittest

# darkcoin block #1
# moo@b1:~/.darkcoin$ darkcoind getblockhash 1
# dash block #1
# moo@b1:~/.dash$ dashd getblockhash 1
# 000007d91d1254d60e2dd1ae580383070a4ddffa4c64c2eeb4a2f9ecc0414343
# moo@b1:~/.darkcoin$ darkcoind getblock 000007d91d1254d60e2dd1ae580383070a4ddffa4c64c2eeb4a2f9ecc0414343
# moo@b1:~/.dash$ dashd getblock 000007d91d1254d60e2dd1ae580383070a4ddffa4c64c2eeb4a2f9ecc0414343
# {
# "hash" : "000007d91d1254d60e2dd1ae580383070a4ddffa4c64c2eeb4a2f9ecc0414343",
# "confirmations" : 169888,
Expand Down Expand Up @@ -40,8 +40,8 @@ def setUp(self):
self.block_header = unhexlify(header_hex)
self.best_hash = best_hash

def test_darkcoin_hash(self):
self.pow_hash = hexlify(darkcoin_hash.getPoWHash(self.block_header))
def test_dash_hash(self):
self.pow_hash = hexlify(dash_hash.getPoWHash(self.block_header))
self.assertEqual(self.pow_hash, self.best_hash)


Expand Down