diff --git a/LICENSE b/LICENSE index e7d462e..4a838f4 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 2e9e3b2..e11fbc9 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ------- @@ -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 diff --git a/dash.c b/dash.c new file mode 100755 index 0000000..025c531 --- /dev/null +++ b/dash.c @@ -0,0 +1,85 @@ +#include "dash.h" +#include +#include +#include +#include + +#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); + +} + diff --git a/dash.h b/dash.h new file mode 100755 index 0000000..9372f7e --- /dev/null +++ b/dash.h @@ -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 diff --git a/dashmodule.c b/dashmodule.c new file mode 100755 index 0000000..a8d90ab --- /dev/null +++ b/dashmodule.c @@ -0,0 +1,57 @@ +#include + +#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 diff --git a/setup.py b/setup.py index 7ba3632..7ae0bfa 100755 --- a/setup.py +++ b/setup.py @@ -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', @@ -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]) diff --git a/test.py b/test.py index 30655fb..e5679fa 100755 --- a/test.py +++ b/test.py @@ -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, @@ -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)