Commit 95ace897 authored by root's avatar root

Initial commit of Groestl

parent 8855c585
/*-
* Copyright 2009 Colin Percival, 2014 phm
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file was originally written by Colin Percival as part of the Tarsnap
* online backup system.
*/
#include "groestl.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "sph/sph_groestl.h"
#include "sph/sph_sha2.h"
/*
* Encode a length len/4 vector of (uint32_t) into a length len vector of
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
*/
void groestl_hash(const char* input, char* output)
{
sph_groestl512_context ctx_groestl;
sph_sha256_context ctx_sha2;
uint32_t hash[16];
sph_groestl512_init(&ctx_groestl);
sph_groestl512(&ctx_groestl, input, 80);
sph_groestl512_close(&ctx_groestl, (void*) hash);
sph_sha256_init(&ctx_sha2);
sph_sha256(&ctx_sha2, hash, 64);
sph_sha256_close(&ctx_sha2, (void*) hash);
memcpy(output, hash, 32);
}
#ifndef GROESTL_H
#define GROESTL_H
#ifdef __cplusplus
extern "C" {
#endif
void groestl_hash(const char* input, char* output);
#ifdef __cplusplus
}
#endif
#endif
#include <Python.h>
#include "groestl.h"
static PyObject *groestl_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
groestl_hash((char *)PyBytes_AsString((PyObject*) input), output);
#else
groestl_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 groestlMethods[] = {
{ "getPoWHash", groestl_getpowhash, METH_VARARGS, "Returns the proof of work hash using groestl hash" },
{ NULL, NULL, 0, NULL }
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef groestlModule = {
PyModuleDef_HEAD_INIT,
"groestl_hash",
"...",
-1,
groestlMethods
};
PyMODINIT_FUNC PyInit_groestl_hash(void) {
return PyModule_Create(&groestlModule);
}
#else
PyMODINIT_FUNC initgroestl_hash(void) {
(void) Py_InitModule("groestl_hash", groestlMethods);
}
#endif
from distutils.core import setup, Extension
quark_hash_module = Extension('quark_hash',
sources = ['quarkmodule.c',
'quark.c',
'sha3/blake.c',
'sha3/bmw.c',
'sha3/groestl.c',
'sha3/jh.c',
'sha3/keccak.c',
'sha3/skein.c'],
include_dirs=['.', './sha3'])
groestl_hash_module = Extension('groestl_hash',
sources = ['groestlmodule.c',
'groestl.c',
'sph/groestl.c',
'sph/sha2.c'],
include_dirs=['.', './sph'])
setup (name = 'quark_hashs',
version = '1.0',
description = 'Bindings for scrypt proof of work used by Quarkcoin',
ext_modules = [quark_hash_module])
setup (name = 'groestl_hashs',
version = '0.1',
description = 'Bindings for Groestl Used by MyriadCoin',
ext_modules = [groestl_hash_module])
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import quark_hash
import groestl_hash
import weakref
import binascii
import StringIO
......@@ -7,4 +7,5 @@ from binascii import unhexlify
teststart = '700000005d385ba114d079970b29a9418fd0549e7d68a95c7f168621a314201000000000578586d149fd07b22f3a8a347c516de7052f034d2b76ff68e0d6ecff9b77a45489e3fd511732011df0731000';
testbin = unhexlify(teststart)
hash_bin = quark_hash.getPoWHash(testbin)
\ No newline at end of file
hash_bin = groestl_hash.getPoWHash(testbin)
print(hash_bin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment