-
Notifications
You must be signed in to change notification settings - Fork 12
/
scryptmodule.c
92 lines (71 loc) · 2.33 KB
/
scryptmodule.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) 2013 Free Software Foundation, Inc. <http://fsf.org/>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <Python.h>
//#include "scrypt.h"
/*
static PyObject *scrypt_getpowhash(PyObject *self, PyObject *args)
{
char *output;
PyObject *value;
PyStringObject *input;
if (!PyArg_ParseTuple(args, "S", &input))
return NULL;
Py_INCREF(input);
output = PyMem_Malloc(32);
scrypt_1024_1_1_256((char *)PyString_AsString((PyObject*) input), output);
Py_DECREF(input);
value = Py_BuildValue("s#", output, 32);
PyMem_Free(output);
return value;
}
*/
static PyObject *scrypt_getpowhash(PyObject *self, PyObject *args, PyObject* kwargs) {
char *input;
int inputlen;
char *outbuf;
size_t outbuflen;
static char *g2_kwlist[] = {"input", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#", g2_kwlist,
&input, &inputlen)) {
return NULL;
}
outbuf = PyMem_Malloc(32);
outbuflen = 32;
Py_BEGIN_ALLOW_THREADS;
scrypt_1024_1_1_256(input, outbuf);
Py_END_ALLOW_THREADS;
PyObject *value = NULL;
value = Py_BuildValue("y#", outbuf, 32);
PyMem_Free(outbuf);
return value;
}
static PyMethodDef ScryptMethods[] = {
{ "getPoWHash", (PyCFunction) scrypt_getpowhash, METH_VARARGS | METH_KEYWORDS, "Returns the proof of work hash using scrypt" },
{ NULL, NULL, 0, NULL }
};
static struct PyModuleDef scryptmodule = {
PyModuleDef_HEAD_INIT,
"ltc_scrypt",
NULL,
-1,
ScryptMethods
};
PyMODINIT_FUNC PyInit_ltc_scrypt(void) {
PyObject *m = PyModule_Create(&scryptmodule);
if (m == NULL) {
return NULL;
}
return m;
}