Skip to content
Snippets Groups Projects
Commit d0fd0ca9 authored by alexey.stratulat's avatar alexey.stratulat
Browse files

Added lines to the cmake file to include header files in other projects. I...

Added lines to the cmake file to include header files in other projects. I redid the base of libdap-crypto-python so that it is not a module, but a new type of object 'crypto'.
parent 2be74414
No related branches found
No related tags found
1 merge request!26Support 3689
...@@ -4,13 +4,21 @@ cmake_minimum_required(VERSION 2.8) ...@@ -4,13 +4,21 @@ cmake_minimum_required(VERSION 2.8)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON) set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(SUBMODULES_NO_BUILD ON) #set(SUBMODULES_NO_BUILD ON)
add_subdirectory(libdap) if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if (NOT (TARGET dap_core))
add_subdirectory(libdap)
target_compile_options(
dap_core PRIVATE
"-fpic"
)
endif()
endif()
add_subdirectory(libdap-crypto) add_subdirectory(libdap-crypto)
file(GLOB CRYPTO_SRCS src/*.c) file(GLOB CRYPTO_PYTHON_SRCS src/*.c)
file(GLOB CRYPTO_HEADERS include/*.h) file(GLOB CRYPTO_PYTHON_HEADERS include/*.h)
set(Python_ADDITIONAL_VERSIONS 3.7) set(Python_ADDITIONAL_VERSIONS 3.7)
find_package (PythonLibs REQUIRED) find_package (PythonLibs REQUIRED)
...@@ -18,7 +26,7 @@ find_package (PythonLibs REQUIRED) ...@@ -18,7 +26,7 @@ find_package (PythonLibs REQUIRED)
#pkg_check_modules(PC_JSON-C REQUIRED json-c) #pkg_check_modules(PC_JSON-C REQUIRED json-c)
include_directories(${PYTHON_INCLUDE_DIR} include/) include_directories(${PYTHON_INCLUDE_DIR} include/)
add_library(${PROJECT_NAME} SHARED ${CRYPTO_SRCS} ${CRYPTO_HEADERS}) add_library(${PROJECT_NAME} SHARED ${CRYPTO_PYTHON_SRCS} ${CRYPTO_PYTHON_HEADERS})
target_link_libraries(${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME})
...@@ -34,6 +42,8 @@ target_compile_options( ...@@ -34,6 +42,8 @@ target_compile_options(
target_link_libraries(${PROJECT_NAME} dap_core dap_crypto) target_link_libraries(${PROJECT_NAME} dap_core dap_crypto)
target_include_directories(${PROJECT_NAME} PUBLIC include/ )
#if(BUILD_DAP_PYTHON_TESTS) #if(BUILD_DAP_PYTHON_TESTS)
# add_subdirectory(test) # add_subdirectory(test)
# enable_testing() # enable_testing()
......
...@@ -16,57 +16,95 @@ extern "C" { ...@@ -16,57 +16,95 @@ extern "C" {
#undef LOG_TAG #undef LOG_TAG
#define LOG_TAG "libdap-python-crypto" #define LOG_TAG "libdap-python-crypto"
static PyObject *dap_crypto_init(PyObject *self, PyObject *args); typedef struct PyCrypto{
PyObject_HEAD
} PyCryptoObject;
static PyObject *dap_crypto_deinit(); int dap_crypto_init(void);
void dap_crypto_deinit(void);
static PyObject *dap_log_it_debug(PyObject *self, PyObject *args);
static PyObject *dap_log_it_info(PyObject *self, PyObject *args);
static PyMethodDef DapCryptoMethods[] = { static PyMethodDef DapCryptoMethods[] = {
{"init", dap_crypto_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) crypto library"}, {"encodeBase58", (PyCFunction)dap_encode_base58_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base58 algorithm from the DAP crypto library"},
{"deinit", dap_crypto_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) crypto library"}, {"decodeBase58", (PyCFunction)dap_decode_base58_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base58 algorithm from the DAP crypto library"},
{"encodeBase58", dap_encode_base58_py, METH_VARARGS, "Encrypts information using the base58 algorithm from the DAP crypto library"}, {"encodeBase64", (PyCFunction)dap_encode_base64_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base64 algorithm from the DAP crypto library"},
{"decodeBase58", dap_decode_base58_py, METH_VARARGS, "Dencrypts information using the base58 algorithm from the DAP crypto library"}, {"decodeBase64", (PyCFunction)dap_decode_base64_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base64 algorithm from the DAP crypto library"},
{"encodeBase64", dap_encode_base64_py, METH_VARARGS, "Encrypts information using the base64 algorithm from the DAP crypto library"}, {"newKey", (PyCFunction)dap_enc_key_new_py, METH_VARARGS | METH_STATIC, "The function creates a new key, and returns it with PyObject."},
{"decodeBase64", dap_decode_base64_py, METH_VARARGS, "Dencrypts information using the base64 algorithm from the DAP crypto library"}, {"delKey", (PyCFunction)dap_enc_key_delete_py, METH_VARARGS | METH_STATIC, ""},
{"logItDebug", dap_log_it_debug, METH_VARARGS, ""}, {"generateNewKey", (PyCFunction)dap_enc_key_new_generate_py, METH_VARARGS | METH_STATIC, ""},
{"logItInfo", dap_log_it_info, METH_VARARGS, ""}, {"getEncSizeKey", (PyCFunction)dap_enc_key_get_enc_size_py, METH_VARARGS | METH_STATIC, ""},
{"newKey", dap_enc_key_new_py, METH_VARARGS, "The function creates a new key, and returns it with PyObject."}, {"getDecSizeKey", (PyCFunction)dap_enc_key_get_dec_size_py, METH_VARARGS | METH_STATIC, ""},
{"delKey", dap_enc_key_delete_py, METH_VARARGS, ""},
{"generateNewKey", dap_enc_key_new_generate_py, METH_VARARGS, ""},
{"getEncSizeKey", dap_enc_key_get_enc_size_py, METH_VARARGS, ""},
{"getDecSizeKey", dap_enc_key_get_dec_size_py, METH_VARARGS, ""},
/*IAES256*/ /*IAES256*/
{"newKeyIAES", dap_enc_iaes_key_new_py, METH_VARARGS, ""}, {"newKeyIAES", (PyCFunction)dap_enc_iaes_key_new_py, METH_VARARGS | METH_STATIC, ""},
{"deleteKeyIAES", dap_enc_iaes_key_delete_py, METH_VARARGS, ""}, {"deleteKeyIAES", (PyCFunction)dap_enc_iaes_key_delete_py, METH_VARARGS | METH_STATIC, ""},
{"generateKeyIAES", dap_enc_iaes_key_generate_py, METH_VARARGS, ""}, {"generateKeyIAES", (PyCFunction)dap_enc_iaes_key_generate_py, METH_VARARGS | METH_STATIC, ""},
{"encodeSizeIAES256", dap_enc_iaes256_calc_encode_size_py, METH_VARARGS, ""}, {"encodeSizeIAES256", (PyCFunction)dap_enc_iaes256_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""},
{"decodeSizeIAES256", dap_enc_iaes256_calc_decode_size_py, METH_VARARGS, ""}, {"decodeSizeIAES256", (PyCFunction)dap_enc_iaes256_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""},
{"encryptIAES256CBCFast", dap_enc_iaes256_cbc_encrypt_fast_py, METH_VARARGS, ""}, {"encryptIAES256CBCFast", (PyCFunction)dap_enc_iaes256_cbc_encrypt_fast_py, METH_VARARGS | METH_STATIC, ""},
{"decryptIAES256CBCFast", dap_enc_iaes256_cbc_decrypt_fast_py, METH_VARARGS, ""}, {"decryptIAES256CBCFast", (PyCFunction)dap_enc_iaes256_cbc_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""},
/*OAES*/ /*OAES*/
{"newKeyOAES", dap_enc_oaes_key_new_py, METH_VARARGS, ""}, {"newKeyOAES", (PyCFunction)dap_enc_oaes_key_new_py, METH_VARARGS | METH_STATIC, ""},
{"deleteKeyOAES", dap_enc_oaes_key_delete_py, METH_VARARGS, ""}, {"deleteKeyOAES", (PyCFunction)dap_enc_oaes_key_delete_py, METH_VARARGS | METH_STATIC, ""},
{"generateKeyOAES", dap_enc_oaes_key_generate_py, METH_VARARGS, ""}, {"generateKeyOAES", (PyCFunction)dap_enc_oaes_key_generate_py, METH_VARARGS | METH_STATIC, ""},
{"encodeSizeOAES", dap_enc_oaes_calc_encode_size_py, METH_VARARGS, ""}, {"encodeSizeOAES", (PyCFunction)dap_enc_oaes_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""},
{"decodeSizeOAES", dap_enc_oaes_calc_decode_size_py, METH_VARARGS, ""}, {"decodeSizeOAES", (PyCFunction)dap_enc_oaes_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""},
{"encryptOAESFast", dap_enc_oaes_encrypt_fast_py, METH_VARARGS, ""}, {"encryptOAESFast", (PyCFunction)dap_enc_oaes_encrypt_fast_py, METH_VARARGS | METH_VARARGS | METH_STATIC, ""},
{"decryptOAESFast", dap_enc_oaes_decrypt_fast_py, METH_VARARGS, ""}, {"decryptOAESFast", (PyCFunction)dap_enc_oaes_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
static struct PyModuleDef dapcryptomodule = { PyTypeObject dapCrypto_dapCryptoType = {
PyModuleDef_HEAD_INIT, PyVarObject_HEAD_INIT(NULL, 0)
"libdap_crypto_python_module", /* name of module */ "libCellFrame.crypto", /* tp_name */
NULL, /* module documentation, may be NULL */ sizeof(PyCryptoObject), /* tp_basicsize */
-1, /* size of per-interpreter state of the module, 0, /* tp_itemsize */
or -1 if the module keeps state in global variables. */ 0,//(destructor)Noddy_dealloc, /* tp_dealloc */
DapCryptoMethods 0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT |
Py_TPFLAGS_BASETYPE, /* tp_flags */
"Dap crypto objects", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapCryptoMethods,//Noddy_methods, /* tp_methods */
0,//Noddy_members, /* tp_members */
0,//Noddy_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0,//(initproc)PyDapEventsObject_init,//(initproc)Noddy_init, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew,//Noddy_new, /* tp_new */
}; };
PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void);
//static struct PyModuleDef dapcryptomodule = {
// PyModuleDef_HEAD_INIT,
// "libdap_crypto_python_module", /* name of module */
// NULL, /* module documentation, may be NULL */
// -1, /* size of per-interpreter state of the module,
// or -1 if the module keeps state in global variables. */
// DapCryptoMethods
//};
//PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
#include "libdap-crypto-python.h" #include "libdap-crypto-python.h"
static PyObject* dap_crypto_init(PyObject *self, PyObject *args){ int dap_crypto_init(void){
dap_common_init("libdap-crypto","libdap-crypto-python-module.txt");
if(dap_enc_init()!=0){ if(dap_enc_init()!=0){
log_it(L_CRITICAL,"Can't init encryption module"); log_it(L_CRITICAL,"Can't init encryption module");
return PyLong_FromLong(-1); return -1;
} }
if(dap_enc_key_init()!=0){ if(dap_enc_key_init()!=0){
log_it(L_CRITICAL,"Can't init encryption key module"); log_it(L_CRITICAL,"Can't init encryption key module");
return PyLong_FromLong(-2); return -2;
} }
keys = key_list_init(); keys = key_list_init();
keys_iaes = keys; keys_iaes = keys;
keys_oaes = keys; keys_oaes = keys;
return PyLong_FromLong(0); return 0;
} }
static PyObject* dap_crypto_deinit(){ void dap_crypto_deinit(void){
dap_enc_key_deinit(); dap_enc_key_deinit();
dap_enc_deinit(); dap_enc_deinit();
key_list_free(keys); key_list_free(keys);
return PyLong_FromLong(0);
} }
/* Information */
static PyObject *dap_log_it_debug(PyObject *self, PyObject *args){
const char *data;
if (!PyArg_ParseTuple(args,"s", &data)){
return NULL;
}
log_it(L_DEBUG, data);
return PyLong_FromLong(0);
}
static PyObject *dap_log_it_info(PyObject *self, PyObject *args){ //PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void){
return PyLong_FromLong(0); // return PyModule_Create(&dapcryptomodule);
} //}
/*==========================================*/
PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void){ //int main(int argc, char **argv) {
return PyModule_Create(&dapcryptomodule); // wchar_t *program = Py_DecodeLocale(argv[0], NULL);
} // if (program == NULL) {
// fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
// exit(1);
// }
int main(int argc, char **argv) { // /* Add a built-in module, before Py_Initialize */
wchar_t *program = Py_DecodeLocale(argv[0], NULL); // PyImport_AppendInittab("libdap_crypto_python_module", PyInit_libdap_crypto_python_module);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
/* Add a built-in module, before Py_Initialize */
PyImport_AppendInittab("libdap_crypto_python_module", PyInit_libdap_crypto_python_module);
/* Pass argv[0] to the Python interpreter */ // /* Pass argv[0] to the Python interpreter */
Py_SetProgramName(program); // Py_SetProgramName(program);
/* Initialize the Python interpreter. Required. */ // /* Initialize the Python interpreter. Required. */
Py_Initialize(); // Py_Initialize();
/* Optionally import the module; alternatively, // /* Optionally import the module; alternatively,
import can be deferred until the embedded script // import can be deferred until the embedded script
imports it. */ // imports it. */
PyImport_ImportModule("libdap_crypto_python_module"); // PyImport_ImportModule("libdap_crypto_python_module");
PyMem_RawFree(program); // PyMem_RawFree(program);
return 0; // return 0;
} //}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment