-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathneoscryptmodule.c
More file actions
65 lines (56 loc) · 1.75 KB
/
Copy pathneoscryptmodule.c
File metadata and controls
65 lines (56 loc) · 1.75 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
60
61
62
63
64
65
// Copyright (C) 2019-2025 The Xaya developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "neoscrypt.h"
static PyObject *neoscrypt_gost_getpowhash(PyObject *self, PyObject *args)
{
unsigned 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
neoscrypt((const unsigned char *)PyBytes_AsString((PyObject*) input), output, 0);
#else
neoscrypt((const unsigned char *)PyString_AsString((PyObject*) input), output);
#endif
Py_DECREF(input);
/* With PY_SSIZE_T_CLEAN defined, the length argument for "#" formats
must be a Py_ssize_t (not an int); passing a plain int is undefined
behaviour on platforms where the two differ in size. */
#if PY_MAJOR_VERSION >= 3
value = Py_BuildValue("y#", output, (Py_ssize_t) 32);
#else
value = Py_BuildValue("s#", output, (Py_ssize_t) 32);
#endif
PyMem_Free(output);
return value;
}
static PyMethodDef neoscryptMethods[] = {
{ "getPoWHash", neoscrypt_gost_getpowhash, METH_VARARGS, "Returns the proof of work hash using neoscrypt hash" },
{ NULL, NULL, 0, NULL }
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef neoscryptModule = {
PyModuleDef_HEAD_INIT,
"neoscrypt",
"...",
-1,
neoscryptMethods
};
PyMODINIT_FUNC PyInit_neoscrypt(void) {
return PyModule_Create(&neoscryptModule);
}
#else
PyMODINIT_FUNC initneoscrypt(void) {
(void) Py_InitModule("neoscrypt", neoscryptMethods);
}
#endif