From 95fb9204c0f3e64bf851f1e896f205dee3f8f1c2 Mon Sep 17 00:00:00 2001 From: Alexey Stratulat <alexey.stratulat@demlabs.net> Date: Mon, 9 Sep 2019 16:57:33 +0700 Subject: [PATCH] [-] Deleted the key list since the Crypto.Key object will be used in its place. --- include/key_list.h | 32 --------- include/libdap-crypto-python.h | 120 +++++++++++---------------------- src/key_list.c | 57 ---------------- 3 files changed, 41 insertions(+), 168 deletions(-) delete mode 100644 include/key_list.h delete mode 100644 src/key_list.c diff --git a/include/key_list.h b/include/key_list.h deleted file mode 100644 index 2159cb9f..00000000 --- a/include/key_list.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef KEY_LIST_H -#define KEY_LIST_H - - -#include "dap_common.h" -#include "dap_enc_key.h" -#include <stdint.h> -#include <string.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#undef LOG_TAG -#define LOG_TAG "key-list" - -typedef struct key_list{ - dap_enc_key_t **keys; - uint8_t lenght; -}key_list_t; - -key_list_t *key_list_init(void); -void key_list_free(key_list_t* list); -uint8_t key_list_add_element(key_list_t *list, dap_enc_key_t* key); -bool key_list_del_element(key_list_t *list, uint8_t key); -dap_enc_key_t *key_list_get_key(key_list_t *list, uint8_t key); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/libdap-crypto-python.h b/include/libdap-crypto-python.h index 3d576303..d08e4011 100644 --- a/include/libdap-crypto-python.h +++ b/include/libdap-crypto-python.h @@ -16,95 +16,57 @@ extern "C" { #undef LOG_TAG #define LOG_TAG "libdap-python-crypto" -typedef struct PyCrypto{ - PyObject_HEAD -} PyCryptoObject; +static PyObject *dap_crypto_init(PyObject *self, PyObject *args); -int dap_crypto_init(void); -void dap_crypto_deinit(void); +static PyObject *dap_crypto_deinit(); + +static PyObject *dap_log_it_debug(PyObject *self, PyObject *args); + +static PyObject *dap_log_it_info(PyObject *self, PyObject *args); static PyMethodDef DapCryptoMethods[] = { - {"encodeBase58", (PyCFunction)dap_encode_base58_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base58 algorithm from the DAP crypto library"}, - {"decodeBase58", (PyCFunction)dap_decode_base58_py, METH_VARARGS | METH_STATIC, "Dencrypts 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"}, - {"decodeBase64", (PyCFunction)dap_decode_base64_py, METH_VARARGS | METH_STATIC, "Dencrypts 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."}, - {"delKey", (PyCFunction)dap_enc_key_delete_py, METH_VARARGS | METH_STATIC, ""}, - {"generateNewKey", (PyCFunction)dap_enc_key_new_generate_py, METH_VARARGS | METH_STATIC, ""}, - {"getEncSizeKey", (PyCFunction)dap_enc_key_get_enc_size_py, METH_VARARGS | METH_STATIC, ""}, - {"getDecSizeKey", (PyCFunction)dap_enc_key_get_dec_size_py, METH_VARARGS | METH_STATIC, ""}, + {"init", dap_crypto_init, METH_VARARGS, "Initialization of the DAP (Deus Applicaions Prototypes) crypto library"}, + {"deinit", dap_crypto_deinit, METH_NOARGS, "Deinitialization of the DAP (Deus Applicaions Prototypes) crypto library"}, + {"encodeBase58", dap_encode_base58_py, METH_VARARGS, "Encrypts information using the base58 algorithm from the DAP crypto library"}, + {"decodeBase58", dap_decode_base58_py, METH_VARARGS, "Dencrypts information using the base58 algorithm from the DAP crypto library"}, + {"encodeBase64", dap_encode_base64_py, METH_VARARGS, "Encrypts information using the base64 algorithm from the DAP crypto library"}, + {"decodeBase64", dap_decode_base64_py, METH_VARARGS, "Dencrypts information using the base64 algorithm from the DAP crypto library"}, + {"logItDebug", dap_log_it_debug, METH_VARARGS, ""}, + {"logItInfo", dap_log_it_info, METH_VARARGS, ""}, + {"newKey", dap_enc_key_new_py, METH_VARARGS, "The function creates a new key, and returns it with PyObject."}, + {"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*/ - {"newKeyIAES", (PyCFunction)dap_enc_iaes_key_new_py, METH_VARARGS | METH_STATIC, ""}, - {"deleteKeyIAES", (PyCFunction)dap_enc_iaes_key_delete_py, METH_VARARGS | METH_STATIC, ""}, - {"generateKeyIAES", (PyCFunction)dap_enc_iaes_key_generate_py, METH_VARARGS | METH_STATIC, ""}, - {"encodeSizeIAES256", (PyCFunction)dap_enc_iaes256_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""}, - {"decodeSizeIAES256", (PyCFunction)dap_enc_iaes256_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""}, - {"encryptIAES256CBCFast", (PyCFunction)dap_enc_iaes256_cbc_encrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, - {"decryptIAES256CBCFast", (PyCFunction)dap_enc_iaes256_cbc_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + {"newKeyIAES", dap_enc_iaes_key_new_py, METH_VARARGS, ""}, + {"deleteKeyIAES", dap_enc_iaes_key_delete_py, METH_VARARGS, ""}, + {"generateKeyIAES", dap_enc_iaes_key_generate_py, METH_VARARGS, ""}, + {"encodeSizeIAES256", dap_enc_iaes256_calc_encode_size_py, METH_VARARGS, ""}, + {"decodeSizeIAES256", dap_enc_iaes256_calc_decode_size_py, METH_VARARGS, ""}, + {"encryptIAES256CBCFast", dap_enc_iaes256_cbc_encrypt_fast_py, METH_VARARGS, ""}, + {"decryptIAES256CBCFast", dap_enc_iaes256_cbc_decrypt_fast_py, METH_VARARGS, ""}, /*OAES*/ - {"newKeyOAES", (PyCFunction)dap_enc_oaes_key_new_py, METH_VARARGS | METH_STATIC, ""}, - {"deleteKeyOAES", (PyCFunction)dap_enc_oaes_key_delete_py, METH_VARARGS | METH_STATIC, ""}, - {"generateKeyOAES", (PyCFunction)dap_enc_oaes_key_generate_py, METH_VARARGS | METH_STATIC, ""}, - {"encodeSizeOAES", (PyCFunction)dap_enc_oaes_calc_encode_size_py, METH_VARARGS | METH_STATIC, ""}, - {"decodeSizeOAES", (PyCFunction)dap_enc_oaes_calc_decode_size_py, METH_VARARGS | METH_STATIC, ""}, - {"encryptOAESFast", (PyCFunction)dap_enc_oaes_encrypt_fast_py, METH_VARARGS | METH_VARARGS | METH_STATIC, ""}, - {"decryptOAESFast", (PyCFunction)dap_enc_oaes_decrypt_fast_py, METH_VARARGS | METH_STATIC, ""}, + {"newKeyOAES", dap_enc_oaes_key_new_py, METH_VARARGS, ""}, + {"deleteKeyOAES", dap_enc_oaes_key_delete_py, METH_VARARGS, ""}, + {"generateKeyOAES", dap_enc_oaes_key_generate_py, METH_VARARGS, ""}, + {"encodeSizeOAES", dap_enc_oaes_calc_encode_size_py, METH_VARARGS, ""}, + {"decodeSizeOAES", dap_enc_oaes_calc_decode_size_py, METH_VARARGS, ""}, + {"encryptOAESFast", dap_enc_oaes_encrypt_fast_py, METH_VARARGS, ""}, + {"decryptOAESFast", dap_enc_oaes_decrypt_fast_py, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; -PyTypeObject dapCrypto_dapCryptoType = { - PyVarObject_HEAD_INIT(NULL, 0) - "libCellFrame.crypto", /* tp_name */ - sizeof(PyCryptoObject), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0,//(destructor)Noddy_dealloc, /* tp_dealloc */ - 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 */ +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 }; - -//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); +PyMODINIT_FUNC PyInit_libdap_crypto_python_module(void); #ifdef __cplusplus } diff --git a/src/key_list.c b/src/key_list.c deleted file mode 100644 index 83e35a9d..00000000 --- a/src/key_list.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "key_list.h" - -key_list_t *key_list_init() -{ - key_list_t *keyList = (key_list_t *)malloc(sizeof(key_list_t)); - keyList->lenght = 0; - return keyList; -} - -void key_list_free(key_list_t* list){ - for (int i=0; i < list->lenght;i++){ - free(list->keys[i]); - } - free(list); -} - -uint8_t key_list_add_element(key_list_t *list, dap_enc_key_t* key){ - uint8_t new_len = list->lenght; - new_len++; - dap_enc_key_t **new_keys = calloc(new_len, sizeof(dap_enc_key_t)); - if (list->lenght != 0) { - memcpy(new_keys, list->keys, list->lenght); - free(list->keys); - } - new_keys[new_len - 1] = key; - list->keys = new_keys; - list->lenght = new_len; - return new_len; - -} - -bool key_list_del_element(key_list_t *list, uint8_t key_id){ - if ((list->lenght-1) > 0) { - return false; - } - uint8_t new_len = list->lenght; - new_len--; - dap_enc_key_t **new_keys = calloc(new_len, sizeof(dap_enc_key_t)); - if (list->lenght - 1 == key_id){ - memcpy(new_keys, list->keys, key_id); - } else if (list->lenght > 1 && key_id < list->lenght) { - memcpy(new_keys, list->keys, key_id); - memcpy(new_keys + key_id, list->keys + (key_id + 1), list->lenght); - } - free(list->keys); - list->keys = new_keys; - list->lenght = new_len; - return true; -} - -dap_enc_key_t *key_list_get_key(key_list_t *list, uint8_t key){ - uint8_t index = key - 1; - if (list->lenght < index) { - return NULL; - } - return list->keys[index]; -} -- GitLab