Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/libdap-crypto-python
1 result
Show changes
Commits on Source (17)
Showing
with 791 additions and 40 deletions
...@@ -6,6 +6,7 @@ set(CMAKE_COLOR_MAKEFILE ON) ...@@ -6,6 +6,7 @@ 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_definitions("-fpic") add_definitions("-fpic")
add_definitions("-DDAP_LOG_MT")
if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON))
if (NOT (TARGET dap_core)) if (NOT (TARGET dap_core))
...@@ -27,7 +28,7 @@ endif() ...@@ -27,7 +28,7 @@ endif()
file(GLOB CRYPTO_PYTHON_SRCS src/*.c) file(GLOB CRYPTO_PYTHON_SRCS src/*.c)
file(GLOB CRYPTO_PYTHON_HEADERS include/*.h) file(GLOB CRYPTO_PYTHON_HEADERS include/*.h)
set(Python_ADDITIONAL_VERSIONS 3.7) set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
find_package (PythonLibs REQUIRED) find_package (PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR} include/) include_directories(${PYTHON_INCLUDE_DIR} include/)
......
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define PY_SSIZE_T_CLEAN #define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include "dap_enc.h" #include "dap_enc.h"
#include "dap_enc_key.h" #include "dap_enc_key.h"
#include "dap_common.h" #include "dap_common.h"
#include "wrapping_cert.h"
#include "wrapping_base58.h" #include "wrapping_base58.h"
#include "wrapping_base64.h" #include "wrapping_base64.h"
#include "wrapping_dap_enc_key.h" #include "wrapping_dap_enc_key.h"
...@@ -13,8 +41,6 @@ ...@@ -13,8 +41,6 @@
extern "C" { extern "C" {
#endif #endif
#undef LOG_TAG
#define LOG_TAG "libdap-python-crypto"
typedef struct PyCrypto{ typedef struct PyCrypto{
PyObject_HEAD PyObject_HEAD
...@@ -24,7 +50,7 @@ int dap_crypto_init(void); ...@@ -24,7 +50,7 @@ int dap_crypto_init(void);
void dap_crypto_deinit(void); void dap_crypto_deinit(void);
static PyMethodDef CryptoMethods[] = { static PyMethodDef g_crypto_methods_py[] = {
{"encodeBase58", dap_encode_base58_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base58 algorithm from the DAP crypto library"}, {"encodeBase58", dap_encode_base58_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base58 algorithm from the DAP crypto library"},
{"decodeBase58", dap_decode_base58_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base58 algorithm from the DAP crypto library"}, {"decodeBase58", dap_decode_base58_py, METH_VARARGS | METH_STATIC, "Dencrypts information using the base58 algorithm from the DAP crypto library"},
{"encodeBase64", dap_encode_base64_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base64 algorithm from the DAP crypto library"}, {"encodeBase64", dap_encode_base64_py, METH_VARARGS | METH_STATIC, "Encrypts information using the base64 algorithm from the DAP crypto library"},
...@@ -52,7 +78,7 @@ static PyMethodDef CryptoMethods[] = { ...@@ -52,7 +78,7 @@ static PyMethodDef CryptoMethods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
static PyTypeObject dapCrypto_dapCryptoType = { static PyTypeObject g_crypto_type_py = {
PyVarObject_HEAD_INIT(NULL, 0) PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.Crypto", /* tp_name */ "CellFrame.Crypto", /* tp_name */
sizeof(PyCryptoObject), /* tp_basicsize */ sizeof(PyCryptoObject), /* tp_basicsize */
...@@ -81,7 +107,7 @@ static PyTypeObject dapCrypto_dapCryptoType = { ...@@ -81,7 +107,7 @@ static PyTypeObject dapCrypto_dapCryptoType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
CryptoMethods, /* tp_methods */ g_crypto_methods_py, /* tp_methods */
0, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
......
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_key.h" #include "dap_enc_key.h"
......
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_key.h" #include "dap_enc_key.h"
......
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_base58.h" #include "dap_enc_base58.h"
#include "dap_common.h" #include "dap_common.h"
......
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_base64.h" #include "dap_enc_base64.h"
#include "dap_common.h" #include "dap_common.h"
......
/*
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "dap_common.h"
#include "dap_cert.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyCryptoCert{
PyObject_HEAD;
dap_cert_t * cert;
}PyCryptoCertObject;
int dap_cert_init_py();
void dap_cert_deinit_py();
PyObject* dap_cert_generate_py(PyObject *self, PyObject *args);
PyObject* dap_cert_dump_py(PyObject *self, PyObject *args);
PyObject* dap_cert_pkey_py(PyObject *self, PyObject *args);
PyObject* dap_cert_find_py(PyObject *self, PyObject *args);
PyObject* dap_cert_sign_py(PyObject *self, PyObject *args);
PyObject* dap_cert_cert_sign_add_py(PyObject *self, PyObject *args);
PyObject* dap_cert_cert_signs_py(PyObject *self, PyObject *args);
PyObject* dap_cert_compare_py(PyObject *self, PyObject *args);
PyObject* dap_cert_save_py(PyObject *self, PyObject *args);
PyObject* dap_cert_load_py(PyObject *self, PyObject *args);
void dap_cert_delete_py(PyObject *self);
PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args);
PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args);
static PyMethodDef g_crypto_cert_methods_py[] = {
{"generate",dap_cert_generate_py , METH_VARARGS | METH_STATIC, "Generate from seed or randomly the new certificate"},
{"find", dap_cert_find_py, METH_VARARGS | METH_STATIC, ""},
{"folderAdd", dap_cert_folder_add_py, METH_VARARGS | METH_STATIC, "Add folders with .dcert files in it"},
{"folderGet", dap_cert_folder_get_py, METH_VARARGS | METH_STATIC, "Get folder by number or the default one"},
{"load", dap_cert_load_py, METH_VARARGS | METH_STATIC ,""},
{"dump", dap_cert_dump_py, METH_VARARGS , ""},
{"pkey", dap_cert_pkey_py, METH_VARARGS , ""},
{"sign", dap_cert_sign_py, METH_VARARGS , ""},
{"certSignAdd", dap_cert_cert_sign_add_py, METH_VARARGS, ""},
{"certSigns", dap_cert_cert_signs_py, METH_VARARGS , ""},
{"compare", dap_cert_compare_py, METH_VARARGS, ""},
{"save", dap_cert_save_py, METH_VARARGS , "Save to the first directory in cert folders list"},
{NULL, NULL, 0, NULL}
};
static PyTypeObject g_crypto_cert_type_py = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.Cert", /* tp_name */
sizeof(PyCryptoCertObject), /* tp_basicsize */
0, /* tp_itemsize */
dap_cert_delete_py, /* 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 */
"Crypto cert object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
g_crypto_cert_methods_py, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
};
#ifdef __cplusplus
}
#endif
#ifndef WRAPPING_DAP_ENC_IAES_ /*
#define WRAPPING_DAP_ENC_IAES_ * Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_iaes.h" #include "dap_enc_iaes.h"
...@@ -10,9 +33,6 @@ ...@@ -10,9 +33,6 @@
extern "C" { extern "C" {
#endif #endif
#undef LOG_TAG
#define LOG_TAG "wrapping-dap-enc-iaes"
PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args); PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args);
PyObject* dap_enc_iaes_key_delete_py(PyObject *self, PyObject *args); PyObject* dap_enc_iaes_key_delete_py(PyObject *self, PyObject *args);
...@@ -33,4 +53,3 @@ PyObject* dap_enc_iaes256_cbc_encrypt_fast_py(PyObject *self, PyObject *args); ...@@ -33,4 +53,3 @@ PyObject* dap_enc_iaes256_cbc_encrypt_fast_py(PyObject *self, PyObject *args);
} }
#endif #endif
#endif //WRAPPING_DAP_ENC_IAES_
#ifndef WRAPPING_DAP_ENC_KEY_ /*
#define WRAPPING_DAP_ENC_KEY_ * Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "dap_enc_key.h" #include "dap_enc_key.h"
#include "Python.h" #include "Python.h"
...@@ -10,8 +33,6 @@ ...@@ -10,8 +33,6 @@
extern "C" { extern "C" {
#endif #endif
#undef LOG_TAG
#define LOG_TAG "wrapping-dap-enc-key"
PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t
PyObject* dap_enc_key_get_dec_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t PyObject* dap_enc_key_get_dec_size_py(PyObject *self, PyObject *args);//dap_enc_key_t * a_key, const size_t buf_in_size); -> size_t
...@@ -36,11 +57,7 @@ PyObject *dap_enc_gen_pub_key_from_priv_py(PyObject *self, PyObject *args);//str ...@@ -36,11 +57,7 @@ PyObject *dap_enc_gen_pub_key_from_priv_py(PyObject *self, PyObject *args);//str
PyObject *dap_enc_gen_key_public_size_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key); ->size_t PyObject *dap_enc_gen_key_public_size_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key); ->size_t
PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key, void * a_output); ->int PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args);//dap_enc_key_t *a_key, void * a_output); ->int
PyObject *dap_enc_key_signature_delete_py(PyObject *self, PyObject *args);//dap_enc_key_type_t a_key_type, uint8_t *a_sig_buf); ->void
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif //WRAPPING_DAP_ENC_KEY_
#ifndef WRAPPING_DAP_ENC_OAES_ /*
#define WRAPPING_DAP_ENC_OAES_ * Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Python.h" #include "Python.h"
#include "dap_enc_oaes.h" #include "dap_enc_oaes.h"
...@@ -31,4 +55,4 @@ PyObject *dap_enc_oaes_encrypt_fast_py(PyObject *self, PyObject *args); ...@@ -31,4 +55,4 @@ PyObject *dap_enc_oaes_encrypt_fast_py(PyObject *self, PyObject *args);
} }
#endif #endif
#endif //WRAPPING_DAP_ENC_OAES_
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Python.h>
#include "dap_hash.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct PyDapHashType{
PyObject_HEAD
dap_hash_type_t hash_type;
}PyDapHashTypeObject;
PyObject *DAP_HASH_TYPE_KECCAK_PY();
PyObject *DAP_HASH_TYPE_SLOW_0_PY();
static PyMethodDef DapHashTypeMethods[] = {
{"DAP_HASH_TYPE_KECCAK", (PyCFunction)DAP_HASH_TYPE_KECCAK_PY, METH_NOARGS | METH_STATIC, ""},
{"DAP_HASH_TYPE_SLOW_0", (PyCFunction)DAP_HASH_TYPE_SLOW_0_PY, METH_NOARGS | METH_STATIC, ""},
{NULL, NULL, 0, NULL}
};
static PyTypeObject DapHashTypeObject_DapChainHashTypeObjectType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.HashType", /* tp_name */
sizeof(PyDapHashTypeObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* 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 */
"Hash type object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapHashTypeMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
/*=================*/
/* Chain hash fast */
typedef struct PyDapHashFast{
PyObject_HEAD
dap_chain_hash_fast_t *hash_fast;
}PyDapHashFastObject;
PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args);
PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args);
PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args);
PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args);
static PyMethodDef DapHashFastMethods[] = {
{"strToHashFast", (PyCFunction)dap_chain_str_to_hash_fast_py, METH_VARARGS | METH_STATIC, ""},
{"hashFast", (PyCFunction)dap_hash_fast_py, METH_VARARGS, ""},
{"compare", (PyCFunction)dap_hash_fast_compare_py, METH_VARARGS | METH_STATIC, ""},
{"isBlank", (PyCFunction)dap_hash_fast_is_blank_py, METH_VARARGS, ""},
{"toStr", (PyCFunction)dap_chain_hash_fast_to_str_py, METH_VARARGS, ""},
{"toStrNew", (PyCFunction)dap_chain_hash_fast_to_str_new_py, METH_VARARGS, ""},
{NULL, NULL, 0, NULL}
};
static PyTypeObject DapHashFastObject_DapHashFastObjectType = {
PyVarObject_HEAD_INIT(NULL, 0)
"CellFrame.HashFast", /* tp_name */
sizeof(PyDapHashFastObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* 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 */
"Hash fast object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
DapHashFastMethods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
#ifdef __cplusplus
}
#endif
Subproject commit f91fb3b3b6a69ef53531c8fd729592cdff4ec442 Subproject commit ee6e8617e1f589b45f15e327ed18cddfa87915f8
Subproject commit bb48d2efb77ee770c6f36c296811688f2ad9c348 Subproject commit 16a16e71b9cfae4fd8df530ed8cd6146010ae7e0
/*
* Authors:
* Alexey Stratulat <alexey.stratulat@demlabs.net>
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libdap-crypto-python.h" #include "libdap-crypto-python.h"
#define LOG_TAG "dap_crypto_python"
int dap_crypto_init(void){ int dap_crypto_init(void){
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");
......
/*
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dap_common.h"
#include "dap_cert.h"
#include "dap_strfuncs.h"
#include "wrapping_cert.h"
#include "libdap_crypto_key_type_python.h"
#define LOG_TAG "wrapping_cert"
PyObject* dap_cert_generate_py(PyObject *self, PyObject *args)
{
const char *l_cert_name = NULL;
const char * l_seed = NULL;
const char *l_arg_cert_name = NULL;
dap_enc_key_type_t l_arg_cert_key_type = DAP_ENC_KEY_TYPE_SIG_DILITHIUM;
const char *l_arg_seed_string = NULL;
if (!PyArg_ParseTuple(args, "sis", &l_arg_cert_name, &l_arg_cert_key_type, &l_arg_seed_string) ){
PyErr_SetString(PyExc_SyntaxError, "Wrong arguments list in function call");
return NULL;
}
if (l_arg_cert_name != 0)
l_cert_name = l_arg_cert_name;
else {
PyErr_SetString(PyExc_SyntaxError, "Certificate name is NULL");
return NULL;
}
if (l_arg_seed_string != 0)
l_seed = l_arg_seed_string;
PyCryptoCertObject *obj_cert = (PyCryptoCertObject*)_PyObject_New(&g_crypto_cert_type_py);
obj_cert->cert = l_seed ? dap_cert_generate_mem_with_seed( l_cert_name, l_arg_cert_key_type, l_seed, strlen(l_seed) )
:dap_cert_generate_mem( l_cert_name,l_arg_cert_key_type );
return Py_BuildValue("O", (PyObject*)obj_cert);
}
PyObject* dap_cert_dump_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_pkey_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_find_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_sign_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_cert_sign_add_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_cert_signs_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_compare_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_save_py(PyObject *self, PyObject *args)
{
(void) args;
int res = dap_cert_save_to_folder(((PyCryptoCertObject*)self)->cert, dap_cert_get_folder(0) );
return PyLong_FromLong(res);
}
PyObject* dap_cert_load_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_close_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
void dap_cert_delete_py(PyObject *self)
{
PyCryptoCertObject *certObject = (PyCryptoCertObject *)self;
dap_cert_delete( certObject->cert );
Py_TYPE(certObject)->tp_free((PyObject*)certObject);
}
PyObject* dap_cert_folder_add_py(PyObject *self, PyObject *args)
{
(void) self;
(void) args;
/// TODO: Implement it!
PyErr_SetString(PyExc_TypeError, "Unimplemented function");
return NULL;
}
PyObject* dap_cert_folder_get_py(PyObject *self, PyObject *args)
{
(void)self;
const char *a_folder_path;
if(!PyArg_ParseTuple(args, "s", &a_folder_path))
return NULL;
dap_cert_add_folder(a_folder_path);
return PyLong_FromLong(0);
}
int dap_cert_init_py(void)
{
return dap_cert_init();
}
void dap_cert_deinit_py(void)
{
dap_cert_deinit();
}
#include "wrapping_dap_enc_iaes.h" #include "wrapping_dap_enc_iaes.h"
#define LOG_TAG "wrapping-dap-enc-iaes"
PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args){ PyObject* dap_enc_iaes_key_new_py(PyObject *self, PyObject *args){
PyObject *obj_key; PyObject *obj_key;
......
#include "wrapping_dap_enc_key.h" #include "wrapping_dap_enc_key.h"
#define LOG_TAG "wrapping-dap-enc-key"
PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args){ PyObject* dap_enc_key_get_enc_size_py(PyObject *self, PyObject *args){
PyObject *in_key; PyObject *in_key;
size_t buff_in_size; size_t buff_in_size;
...@@ -117,18 +119,3 @@ PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args){ ...@@ -117,18 +119,3 @@ PyObject *dap_enc_gen_key_public_py(PyObject *self, PyObject *args){
int size = dap_enc_gen_key_public(((PyCryptoKeyObject*)in_key)->key, obj); int size = dap_enc_gen_key_public(((PyCryptoKeyObject*)in_key)->key, obj);
return PyLong_FromLong(size); return PyLong_FromLong(size);
} }
PyObject *dap_enc_key_signature_delete_py(PyObject *self, PyObject *args){
int type_key;
uint8_t *a_sig_buf;
uint8_t sig_buf;
if(!PyArg_ParseTuple(args, "i|h", &type_key, &sig_buf)){
return NULL;
}
if (type_key < 0 || type_key > 16){
return PyLong_FromLong(-1);
}
a_sig_buf = (uint8_t*)sig_buf;
dap_enc_key_signature_delete(type_key, a_sig_buf);
return PyLong_FromLong(0);
}
#include "wrapping_dap_hash.h"
PyObject *DAP_HASH_TYPE_KECCAK_PY(){
PyObject *obj = _PyObject_New(&DapHashTypeObject_DapChainHashTypeObjectType);
((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_KECCAK;
return Py_BuildValue("O", obj);
}
PyObject *DAP_HASH_TYPE_SLOW_0_PY(){
PyObject *obj = _PyObject_New(&DapHashTypeObject_DapChainHashTypeObjectType);
((PyDapHashTypeObject*)obj)->hash_type = DAP_HASH_TYPE_SLOW_0;
return Py_BuildValue("O", obj);
}
PyObject *dap_chain_str_to_hash_fast_py(PyObject *self, PyObject *args){
const char *hash_str;
PyObject *obj_hash_fast;
if (!PyArg_ParseTuple(args, "s|O", &hash_str, &obj_hash_fast))
return NULL;
int res = dap_chain_str_to_hash_fast(hash_str, ((PyDapHashFastObject*)obj_hash_fast)->hash_fast);
return Py_BuildValue("nO", res, obj_hash_fast);
}
PyObject *dap_hash_fast_py(PyObject *self, PyObject *args){
PyObject *obj_bytes;
size_t data_in_size;
if (!PyArg_ParseTuple(args, "O|n", &obj_bytes, &data_in_size))
return NULL;
const void *bytes = (void*)PyBytes_AsString(obj_bytes);
bool res = dap_hash_fast(bytes, data_in_size, ((PyDapHashFastObject*)self)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_hash_fast_compare_py(PyObject *self, PyObject *args){
PyObject *hash1;
PyObject *hash2;
if (!PyArg_ParseTuple(args, "O|O", &hash1, &hash2))
return NULL;
bool res = dap_hash_fast_compare(((PyDapHashFastObject*)hash1)->hash_fast, ((PyDapHashFastObject*)hash2)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_hash_fast_is_blank_py(PyObject *self, PyObject *args){
bool res = dap_hash_fast_is_blank(((PyDapHashFastObject*)self)->hash_fast);
if (res)
return Py_BuildValue("O", Py_True);
else
return Py_BuildValue("O", Py_False);
}
PyObject *dap_chain_hash_fast_to_str_py(PyObject *self, PyObject *args){
char *str;
size_t str_max;
if (!PyArg_ParseTuple(args, "s|n", &str, &str_max))
return NULL;
int res = dap_chain_hash_fast_to_str(((PyDapHashFastObject*)self)->hash_fast, str, str_max);
return Py_BuildValue("sn", &str, &str_max);
}
PyObject *dap_chain_hash_fast_to_str_new_py(PyObject *self, PyObject *args){
char *res = dap_chain_hash_fast_to_str_new(((PyDapHashFastObject*)self)->hash_fast);
return Py_BuildValue("s", res);
}