Skip to content

Conversation

@milahu
Copy link

@milahu milahu commented Jul 29, 2023

fix build of pycryptopp

update sources with git modules:

support python3 → fix #46

todo: use pkg-config to find incldir and libdir of cryptopp

building cryptopp takes forever, so the build should use the system's cryptopp library

setup.py: DISABLE_EMBEDDED_CRYPTOPP should be True by default

DISABLE_EMBEDDED_CRYPTOPP=False
if "--disable-embedded-cryptopp" in sys.argv:
    DISABLE_EMBEDDED_CRYPTOPP=True
    sys.argv.remove("--disable-embedded-cryptopp")

example on nixos:

$ nix-shell -p cryptopp.dev pkg-config

$ pkg-config --cflags --libs libcryptopp
-I/nix/store/jqlripd5k7i013xhx5aggz0cm4w2gmfh-crypto++-8.7.0-dev/include -L/nix/store/ydrm5m969x6gwsgd3qbsmyb0q8xrm9vs-crypto++-8.7.0/lib -lcryptopp

$ pkg-config --variable=includedir libcryptopp
/nix/store/jqlripd5k7i013xhx5aggz0cm4w2gmfh-crypto++-8.7.0-dev/include

$ pkg-config --variable=libdir libcryptopp
/nix/store/ydrm5m969x6gwsgd3qbsmyb0q8xrm9vs-crypto++-8.7.0/lib

/nix/store/jqlripd5k7i013xhx5aggz0cm4w2gmfh-crypto++-8.7.0-dev/lib/pkgconfig/libcryptopp.pc

# Crypto++ package configuration file

prefix=/nix/store/ydrm5m969x6gwsgd3qbsmyb0q8xrm9vs-crypto++-8.7.0
libdir=${prefix}/lib
includedir=/nix/store/jqlripd5k7i013xhx5aggz0cm4w2gmfh-crypto++-8.7.0-dev/include
datadir=${prefix}/share

Name: Crypto++
Description: Crypto++ cryptographic library
Version: 8.7
URL: https://cryptopp.com/

Cflags: -I${includedir}
Libs: -L${libdir} -lcryptopp

fix build error with python3: Py_InitModule3

done: fixed in 204e5b3

currently, the build fails with error: ‘Py_InitModule3’ was not declared in this scope

g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/nix/store/pf3si7nkxwdbg07q0m5zx9mkgzdp9g9y-libxcrypt-4.4.35/include -fPIC -DCRYPTOPP_DISABLE_ASM=1 -I. -I/nix/store/5a457g4zr7q11b4mz0ifc9z88kwcp8g7-python3-3.10.12/include/python3.10 -c src/pycryptopp/_pycryptoppmodule.cpp -o build/temp.linux-x86_64-cpython-310/src/pycryptopp/_pycryptoppmodule.o -w
src/pycryptopp/_pycryptoppmodule.cpp: In function ‘PyObject* init_pycryptopp()’:
src/pycryptopp/_pycryptoppmodule.cpp:42:14: error: ‘Py_InitModule3’ was not declared in this scope
   42 |     module = Py_InitModule3("_pycryptopp", _pycryptopp_functions, _pycryptopp__doc__);
      |              ^~~~~~~~~~~~~~
src/pycryptopp/_pycryptoppmodule.cpp:44:7: error: return-statement with no value, in function returning ‘PyObject*’ {aka ‘_object*’} [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-fpermissive-fpermissive8;;]
   44 |       return;
      |       ^~~~~~
src/pycryptopp/_pycryptoppmodule.cpp:57:53: error: ‘cryptopp_extra_version’ was not declared in this scope
   57 |     version = Py_BuildValue("is", CRYPTOPP_VERSION, cryptopp_extra_version);
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~
src/pycryptopp/_pycryptoppmodule.cpp:64:9: error: return-statement with no value, in function returning ‘PyObject*’ {aka ‘_object*’} [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-fpermissive-fpermissive8;;]
   64 |         return;
      |         ^~~~~~
error: command '/nix/store/8phn3d072kcfvwvf6p5ys8pk8yxh236x-gcc-wrapper-12.3.0/bin/g++' failed with exit code 1

todo: fix build error with python3: PyString

currently, the build fails with error: ‘PyString_CheckExact’ was not declared in this scope

g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/nix/store/pf3si7nkxwdbg07q0m5zx9mkgzdp9g9y-libxcrypt-4.4.35/include -fPIC -DDISABLE_EMBEDDED_CRYPTOPP=1 -I/usr/local/include -I/nix/store/5a457g4zr7q11b4mz0ifc9z88kwcp8g7-python3-3.10.12/include/python3.10 -c src/pycryptopp/cipher/aesmodule.cpp -o build/temp.linux-x86_64-cpython-310/src/pycryptopp/cipher/aesmodule.o -w
src/pycryptopp/cipher/aesmodule.cpp: In function ‘PyObject* AES_process(AES*, PyObject*)’:
src/pycryptopp/cipher/aesmodule.cpp:58:10: error: ‘PyString_CheckExact’ was not declared in this scope; did you mean ‘PyLong_CheckExact’?
   58 |     if (!PyString_CheckExact(msgobj)) {
      |          ^~~~~~~~~~~~~~~~~~~
      |          PyLong_CheckExact
src/pycryptopp/cipher/aesmodule.cpp:59:9: error: ‘PyStringObject’ was not declared in this scope; did you mean ‘PySliceObject’?
   59 |         PyStringObject* typerepr = reinterpret_cast<PyStringObject*>(PyObject_Repr(reinterpret_cast<PyObject*>(msgobj->ob_type)));
      |         ^~~~~~~~~~~~~~
      |         PySliceObject

in python3, there is no PyString_CheckExact
but PyUnicode_CheckExact, PyBytes_CheckExact, PyByteArray_CheckExact

$ grep -r CheckExact  /nix/store/zm62kx9sv8hgb7pnvafg8j4pkwj17b4d-python3-3.10.12/include/python3.10/ | grep -i -e byte -e unicode
/nix/store/zm62kx9sv8hgb7pnvafg8j4pkwj17b4d-python3-3.10.12/include/python3.10/unicodeobject.h:#define PyUnicode_CheckExact(op) Py_IS_TYPE(op, &PyUnicode_Type)
/nix/store/zm62kx9sv8hgb7pnvafg8j4pkwj17b4d-python3-3.10.12/include/python3.10/bytesobject.h:#define PyBytes_CheckExact(op) Py_IS_TYPE(op, &PyBytes_Type)
/nix/store/zm62kx9sv8hgb7pnvafg8j4pkwj17b4d-python3-3.10.12/include/python3.10/bytearrayobject.h:#define PyByteArray_CheckExact(self) Py_IS_TYPE(self, &PyByteArray_Type)

my use case

  • pyload requires beaker no, pyload does not require beaker any more → low priority for me, but im almost done, so let me finish this...
  • beaker requires pycryptopp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Python 3 Crypto++ and upcoming change for byte definition due to C++17

1 participant