forked from 216k155/phi2_hashing_module
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphi2module.c
More file actions
59 lines (50 loc) · 1.24 KB
/
phi2module.c
File metadata and controls
59 lines (50 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Phi2 module
#include <Python.h>
#include "phi2.h"
static PyObject *phi2_hash_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
phi2_hash((char *)PyBytes_AsString((PyObject*) input), output);
#else
phi2_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 Phi2Methods[] = {
{ "getPoWHash", phi2_hash_getpowhash, METH_VARARGS, "Returns the proof of work hash using phi2 hash" },
{ NULL, NULL, 0, NULL }
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef Phi2Module = {
PyModuleDef_HEAD_INIT,
"phi2_hash",
"...",
-1,
Phi2Methods
};
PyMODINIT_FUNC PyInit_phi2_hash(void) {
return PyModule_Create(&Phi2Module);
}
#else
PyMODINIT_FUNC initphi2_hash(void) {
(void) Py_InitModule("phi2_hash", Phi2Methods);
}
#endif