tahoe-lafs / pycryptopp

Python bindings to the Crypto++ library
https://tahoe-lafs.org/trac/pycryptopp
Other
49 stars 32 forks source link

Crypto++ and upcoming change for byte definition due to C++17 #42

Open noloader opened 7 years ago

noloader commented 7 years ago

The Crypto++ library is getting ready to change the scope of its definition for a byte. The short of it is, Crypto++ byte and C++17 std::byte can cause compile failures due to ambiguous resolutions; and the behavior of byte and std::byte are incompatible. More information can be found at:

We are looking for testers to provide early feedback. Please see:

Recommendations for user programs which rely the library can be found at:

The change will exist in Master, and then be part of the Crypto++ 6.0 release. The change needs a major version bump because it is so disruptive to user programs. We would like to release Crypto++ in the next month or two.

My apologies for opening an issue. Please label it as an enhancement or feature request.

noloader commented 7 years ago

Here are the results from Pycryptopp. It appears Pycryptopp did not import the entire std:: or CryptoPP:: namespace, so they avoided the collisions that would have occurred in C++17.

Pycryptopp needed the following due to the upcoming Crypto++ changes. The changes made to Pycryptopp are compatible with the old version (::byte) and new version (CryptoPP::byte) of the Crypto++ library.

$ cat pycryptopp.diff
diff --git a/src/pycryptopp/cipher/aesmodule.cpp b/src/pycryptopp/cipher/aesmodule.cpp
index 360827d..3d0b95a 100644
--- a/src/pycryptopp/cipher/aesmodule.cpp
+++ b/src/pycryptopp/cipher/aesmodule.cpp
@@ -20,6 +20,9 @@ typedef int Py_ssize_t;
 #include <src-cryptopp/aes.h>
 #endif

+// https://github.com/weidai11/cryptopp/issues/442
+typedef unsigned char byte;
+
 static const char*const aes___doc__ = "_aes counter mode cipher\n\
 You are advised to run aes.start_up_self_test() after importing this module.";

diff --git a/src/pycryptopp/cipher/xsalsa20module.cpp b/src/pycryptopp/cipher/xsalsa20module.cpp
index ab29787..a0b7c71 100644
--- a/src/pycryptopp/cipher/xsalsa20module.cpp
+++ b/src/pycryptopp/cipher/xsalsa20module.cpp
@@ -16,6 +16,9 @@ typedef int Py_ssize_t;
 #include <src-cryptopp/salsa.h>
 #endif

+// https://github.com/weidai11/cryptopp/issues/442
+typedef unsigned char byte;
+
 static const char* const xsalsa20__doc__ = "_xsalsa20 cipher";

 static PyObject *xsalsa20_error;
diff --git a/src/pycryptopp/hash/sha256module.cpp b/src/pycryptopp/hash/sha256module.cpp
index bf9d8e3..8272e6c 100644
--- a/src/pycryptopp/hash/sha256module.cpp
+++ b/src/pycryptopp/hash/sha256module.cpp
@@ -21,6 +21,9 @@ typedef int Py_ssize_t;
 #include <src-cryptopp/filters.h>
 #endif

+// https://github.com/weidai11/cryptopp/issues/442
+typedef unsigned char byte;
+
 static const char*const sha256___doc__ = "_sha256 hash function";

 static PyObject *sha256_error;

Note from Crypto++ and JW: we used Pycryptopp as a test run of the proposed changes. If Pycryptopp merges the change above, then it should not have problems with existing versions of the library or new versions of the library.

The same report was filed at pypa/pypi-legacy | issue tracker. See Issue 671, Crypto++ and upcoming change for byte definition due to C++17.