6cde2c01f74fa370ad6d78e9e269f4990478ee72
[p2pool.git] / litecoin_scrypt / scryptmodule.c
1 //#include "stdint.h"
2
3 typedef char uint8_t;
4
5 #include <Python.h>
6
7 //#include "scrypt.h"
8
9 static PyObject *scrypt_getpowhash(PyObject *self, PyObject *args)
10 {
11     uint8_t *output;
12     PyObject *value;
13     PyStringObject *input;
14     if (!PyArg_ParseTuple(args, "S", &input))
15         return NULL;
16     Py_INCREF(input);
17     output = PyMem_Malloc(32);
18
19     scrypt_1024_1_1_256((uint8_t *)PyString_AsString((PyObject*) input), output);
20     Py_DECREF(input);
21     value = Py_BuildValue("s#", output, 32);
22     PyMem_Free(output);
23     return value;
24 }
25
26 static PyMethodDef ScryptMethods[] = {
27     { "getPoWHash", scrypt_getpowhash, METH_VARARGS, "Returns the proof of work hash using scrypt" },
28     { NULL, NULL, 0, NULL }
29 };
30
31 PyMODINIT_FUNC initltc_scrypt(void) {
32     (void) Py_InitModule("ltc_scrypt", ScryptMethods);
33 }