diff --git a/.gitignore b/.gitignore index 52eca59fb..b22328702 100644 --- a/.gitignore +++ b/.gitignore @@ -186,3 +186,6 @@ wolfcrypt/user-crypto/lib/libusercrypto.* # wolfSSL CSharp wrapper wrapper/CSharp/x64/ + +# Visual Studio Code Workspace Files +*.vscode \ No newline at end of file diff --git a/wrapper/include.am b/wrapper/include.am index 56b63fec4..eb6d8f7fc 100644 --- a/wrapper/include.am +++ b/wrapper/include.am @@ -1,3 +1,8 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +include wrapper/python/wolfcrypt/include.am # wolfSSL CSharp wrapper files EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/App.config @@ -28,31 +33,3 @@ EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.Designer.cs EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.resx EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj - -# wolfcrypt python wrapper files -EXTRA_DIST+= wrapper/python/.gitignore -EXTRA_DIST+= wrapper/python/docs/asymmetric.rst -EXTRA_DIST+= wrapper/python/docs/conf.py -EXTRA_DIST+= wrapper/python/docs/digest.rst -EXTRA_DIST+= wrapper/python/docs/index.rst -EXTRA_DIST+= wrapper/python/docs/mac.rst -EXTRA_DIST+= wrapper/python/docs/Makefile -EXTRA_DIST+= wrapper/python/docs/random.rst -EXTRA_DIST+= wrapper/python/docs/symmetric.rst -EXTRA_DIST+= wrapper/python/LICENSING.rst -EXTRA_DIST+= wrapper/python/MANIFEST.in -EXTRA_DIST+= wrapper/python/README.rst -EXTRA_DIST+= wrapper/python/requirements-testing.txt -EXTRA_DIST+= wrapper/python/setup.py -EXTRA_DIST+= wrapper/python/test/test_ciphers.py -EXTRA_DIST+= wrapper/python/test/test_hashes.py -EXTRA_DIST+= wrapper/python/test/test_random.py -EXTRA_DIST+= wrapper/python/tox.ini -EXTRA_DIST+= wrapper/python/wolfcrypt/__about__.py -EXTRA_DIST+= wrapper/python/wolfcrypt/__init__.py -EXTRA_DIST+= wrapper/python/wolfcrypt/build_ffi.py -EXTRA_DIST+= wrapper/python/wolfcrypt/ciphers.py -EXTRA_DIST+= wrapper/python/wolfcrypt/exceptions.py -EXTRA_DIST+= wrapper/python/wolfcrypt/hashes.py -EXTRA_DIST+= wrapper/python/wolfcrypt/random.py -EXTRA_DIST+= wrapper/python/wolfcrypt/utils.py diff --git a/wrapper/python/.centos-provisioner.sh b/wrapper/python/wolfcrypt/.centos-provisioner.sh similarity index 100% rename from wrapper/python/.centos-provisioner.sh rename to wrapper/python/wolfcrypt/.centos-provisioner.sh diff --git a/wrapper/python/.gitignore b/wrapper/python/wolfcrypt/.gitignore similarity index 100% rename from wrapper/python/.gitignore rename to wrapper/python/wolfcrypt/.gitignore diff --git a/wrapper/python/.ubuntu-provisioner.sh b/wrapper/python/wolfcrypt/.ubuntu-provisioner.sh similarity index 100% rename from wrapper/python/.ubuntu-provisioner.sh rename to wrapper/python/wolfcrypt/.ubuntu-provisioner.sh diff --git a/wrapper/python/LICENSING.rst b/wrapper/python/wolfcrypt/LICENSING.rst similarity index 100% rename from wrapper/python/LICENSING.rst rename to wrapper/python/wolfcrypt/LICENSING.rst diff --git a/wrapper/python/MANIFEST.in b/wrapper/python/wolfcrypt/MANIFEST.in similarity index 100% rename from wrapper/python/MANIFEST.in rename to wrapper/python/wolfcrypt/MANIFEST.in diff --git a/wrapper/python/README.rst b/wrapper/python/wolfcrypt/README.rst similarity index 97% rename from wrapper/python/README.rst rename to wrapper/python/wolfcrypt/README.rst index 87121192b..1732c906b 100644 --- a/wrapper/python/README.rst +++ b/wrapper/python/wolfcrypt/README.rst @@ -117,8 +117,8 @@ Testing ``wolfcrypt``'s source code with ``tox`` : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To run the unit tests in the source code, you'll need ``tox`` and a few other -requirements. The source code relies at 'WOLFSSL_DIR/wrapper/python' where -WOLFSSL_DIR is the path of ``wolfssl``'s source code. +requirements. The source code relies at 'WOLFSSL_DIR/wrapper/python/wolfcrypt' +where WOLFSSL_DIR is the path of ``wolfssl``'s source code. 1. Make sure that the testing requirements are installed: diff --git a/wrapper/python/Vagrantfile b/wrapper/python/wolfcrypt/Vagrantfile similarity index 100% rename from wrapper/python/Vagrantfile rename to wrapper/python/wolfcrypt/Vagrantfile diff --git a/wrapper/python/docs/Makefile b/wrapper/python/wolfcrypt/docs/Makefile similarity index 100% rename from wrapper/python/docs/Makefile rename to wrapper/python/wolfcrypt/docs/Makefile diff --git a/wrapper/python/docs/asymmetric.rst b/wrapper/python/wolfcrypt/docs/asymmetric.rst similarity index 100% rename from wrapper/python/docs/asymmetric.rst rename to wrapper/python/wolfcrypt/docs/asymmetric.rst diff --git a/wrapper/python/docs/conf.py b/wrapper/python/wolfcrypt/docs/conf.py similarity index 100% rename from wrapper/python/docs/conf.py rename to wrapper/python/wolfcrypt/docs/conf.py diff --git a/wrapper/python/docs/digest.rst b/wrapper/python/wolfcrypt/docs/digest.rst similarity index 100% rename from wrapper/python/docs/digest.rst rename to wrapper/python/wolfcrypt/docs/digest.rst diff --git a/wrapper/python/docs/index.rst b/wrapper/python/wolfcrypt/docs/index.rst similarity index 100% rename from wrapper/python/docs/index.rst rename to wrapper/python/wolfcrypt/docs/index.rst diff --git a/wrapper/python/docs/mac.rst b/wrapper/python/wolfcrypt/docs/mac.rst similarity index 100% rename from wrapper/python/docs/mac.rst rename to wrapper/python/wolfcrypt/docs/mac.rst diff --git a/wrapper/python/docs/random.rst b/wrapper/python/wolfcrypt/docs/random.rst similarity index 100% rename from wrapper/python/docs/random.rst rename to wrapper/python/wolfcrypt/docs/random.rst diff --git a/wrapper/python/docs/symmetric.rst b/wrapper/python/wolfcrypt/docs/symmetric.rst similarity index 100% rename from wrapper/python/docs/symmetric.rst rename to wrapper/python/wolfcrypt/docs/symmetric.rst diff --git a/wrapper/python/wolfcrypt/include.am b/wrapper/python/wolfcrypt/include.am new file mode 100644 index 000000000..4d62bcf51 --- /dev/null +++ b/wrapper/python/wolfcrypt/include.am @@ -0,0 +1,30 @@ +# vim:ft=automake +# included from Top Level Makefile.am +# All paths should be given relative to the root + +EXTRA_DIST+= wrapper/python/wolfcrypt/.gitignore +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/asymmetric.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/conf.py +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/digest.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/index.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/mac.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/Makefile +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/random.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/docs/symmetric.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/LICENSING.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/MANIFEST.in +EXTRA_DIST+= wrapper/python/wolfcrypt/README.rst +EXTRA_DIST+= wrapper/python/wolfcrypt/requirements-testing.txt +EXTRA_DIST+= wrapper/python/wolfcrypt/setup.py +EXTRA_DIST+= wrapper/python/wolfcrypt/test/test_ciphers.py +EXTRA_DIST+= wrapper/python/wolfcrypt/test/test_hashes.py +EXTRA_DIST+= wrapper/python/wolfcrypt/test/test_random.py +EXTRA_DIST+= wrapper/python/wolfcrypt/tox.ini +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/__about__.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/__init__.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/build_ffi.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/ciphers.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/exceptions.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/hashes.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/random.py +EXTRA_DIST+= wrapper/python/wolfcrypt/wolfcrypt/utils.py diff --git a/wrapper/python/requirements-testing.txt b/wrapper/python/wolfcrypt/requirements-testing.txt similarity index 100% rename from wrapper/python/requirements-testing.txt rename to wrapper/python/wolfcrypt/requirements-testing.txt diff --git a/wrapper/python/setup.py b/wrapper/python/wolfcrypt/setup.py similarity index 100% rename from wrapper/python/setup.py rename to wrapper/python/wolfcrypt/setup.py diff --git a/wrapper/python/test/test_ciphers.py b/wrapper/python/wolfcrypt/test/test_ciphers.py similarity index 82% rename from wrapper/python/test/test_ciphers.py rename to wrapper/python/wolfcrypt/test/test_ciphers.py index c1929c89e..584bc7033 100644 --- a/wrapper/python/test/test_ciphers.py +++ b/wrapper/python/wolfcrypt/test/test_ciphers.py @@ -21,61 +21,6 @@ import unittest from wolfcrypt.ciphers import * from wolfcrypt.utils import t2b, h2b -class TestDes3(unittest.TestCase): - key = h2b("0123456789abcdeffedeba987654321089abcdef01234567") - IV = h2b("1234567890abcdef") - plain = t2b("Now is the time for all ") - cipher = h2b("43a0297ed184f80e8964843212d508981894157487127db0") - - - def setUp(self): - self.des3 = Des3.new(self.key, MODE_CBC, self.IV) - - - def test_raises(self): - # invalid key length - self.assertRaises(ValueError, Des3.new, "key", MODE_CBC, self.IV) - - # invalid mode - self.assertRaises(ValueError, Des3.new, self.key, MODE_ECB, self.IV) - - # invalid iv length - self.assertRaises(ValueError, Des3.new, self.key, MODE_CBC, "IV") - - # invalid data length - self.assertRaises(ValueError, self.des3.encrypt, "foo") - self.assertRaises(ValueError, self.des3.decrypt, "bar") - - - def test_single_encryption(self): - assert self.des3.encrypt(self.plain) == self.cipher - - - def test_multi_encryption(self): - result = t2b("") - segments = tuple(self.plain[i:i + Des3.block_size] \ - for i in range(0, len(self.plain), Des3.block_size)) - - for segment in segments: - result += self.des3.encrypt(segment) - - assert result == self.cipher - - - def test_single_decryption(self): - assert self.des3.decrypt(self.cipher) == self.plain - - - def test_multi_decryption(self): - result = t2b("") - segments = tuple(self.cipher[i:i + Des3.block_size] \ - for i in range(0, len(self.cipher), Des3.block_size)) - - for segment in segments: - result += self.des3.decrypt(segment) - - assert result == self.plain - class TestAes(unittest.TestCase): key = "0123456789abcdef" diff --git a/wrapper/python/test/test_hashes.py b/wrapper/python/wolfcrypt/test/test_hashes.py similarity index 100% rename from wrapper/python/test/test_hashes.py rename to wrapper/python/wolfcrypt/test/test_hashes.py diff --git a/wrapper/python/test/test_random.py b/wrapper/python/wolfcrypt/test/test_random.py similarity index 100% rename from wrapper/python/test/test_random.py rename to wrapper/python/wolfcrypt/test/test_random.py diff --git a/wrapper/python/tox.ini b/wrapper/python/wolfcrypt/tox.ini similarity index 100% rename from wrapper/python/tox.ini rename to wrapper/python/wolfcrypt/tox.ini diff --git a/wrapper/python/wolfcrypt/__about__.py b/wrapper/python/wolfcrypt/wolfcrypt/__about__.py similarity index 98% rename from wrapper/python/wolfcrypt/__about__.py rename to wrapper/python/wolfcrypt/wolfcrypt/__about__.py index b5c05386a..c0482dc17 100644 --- a/wrapper/python/wolfcrypt/__about__.py +++ b/wrapper/python/wolfcrypt/wolfcrypt/__about__.py @@ -20,7 +20,7 @@ metadata = dict( __name__ = "wolfcrypt", - __version__ = "0.1.8", + __version__ = "0.1.9", __license__ = "GPLv2 or Commercial License", __author__ = "wolfSSL Inc.", __author_email__ = "info@wolfssl.com", diff --git a/wrapper/python/wolfcrypt/__init__.py b/wrapper/python/wolfcrypt/wolfcrypt/__init__.py similarity index 100% rename from wrapper/python/wolfcrypt/__init__.py rename to wrapper/python/wolfcrypt/wolfcrypt/__init__.py diff --git a/wrapper/python/wolfcrypt/build_ffi.py b/wrapper/python/wolfcrypt/wolfcrypt/build_ffi.py similarity index 93% rename from wrapper/python/wolfcrypt/build_ffi.py rename to wrapper/python/wolfcrypt/wolfcrypt/build_ffi.py index 720e96cfc..b5eb7f814 100644 --- a/wrapper/python/wolfcrypt/build_ffi.py +++ b/wrapper/python/wolfcrypt/wolfcrypt/build_ffi.py @@ -94,13 +94,6 @@ ffi.cdef( int wc_AesCbcDecrypt(Aes*, byte*, const byte*, word32); - typedef struct { ...; } Des3; - - int wc_Des3_SetKey(Des3*, const byte*, const byte*, int); - int wc_Des3_CbcEncrypt(Des3*, byte*, const byte*, word32); - int wc_Des3_CbcDecrypt(Des3*, byte*, const byte*, word32); - - typedef struct { ...; } WC_RNG; int wc_InitRng(WC_RNG*); @@ -112,6 +105,7 @@ ffi.cdef( typedef struct {...; } RsaKey; int wc_InitRsaKey(RsaKey* key, void*); + int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng); int wc_FreeRsaKey(RsaKey* key); int wc_RsaPrivateKeyDecode(const byte*, word32*, RsaKey*, word32); diff --git a/wrapper/python/wolfcrypt/ciphers.py b/wrapper/python/wolfcrypt/wolfcrypt/ciphers.py similarity index 92% rename from wrapper/python/wolfcrypt/ciphers.py rename to wrapper/python/wolfcrypt/wolfcrypt/ciphers.py index 4084e6bf7..dd54a3db7 100644 --- a/wrapper/python/wolfcrypt/ciphers.py +++ b/wrapper/python/wolfcrypt/wolfcrypt/ciphers.py @@ -178,33 +178,6 @@ class Aes(_Cipher): return _lib.wc_AesCbcDecrypt(self._dec, destination, source,len(source)) -class Des3(_Cipher): - """ - **Triple DES** (3DES) is the common name for the **Triple Data - Encryption Algorithm** (TDEA or Triple DEA) symmetric-key block - cipher, which applies the **Data Encryption Standard** (DES) - cipher algorithm three times to each data block. - """ - block_size = 8 - key_size = 24 - _native_type = "Des3 *" - - - def _set_key(self, direction): - if direction == _ENCRYPTION: - return _lib.wc_Des3_SetKey(self._enc,self._key,self._IV,_ENCRYPTION) - else: - return _lib.wc_Des3_SetKey(self._dec,self._key,self._IV,_DECRYPTION) - - - def _encrypt(self, destination, source): - return _lib.wc_Des3_CbcEncrypt(self._enc,destination,source,len(source)) - - - def _decrypt(self, destination, source): - return _lib.wc_Des3_CbcDecrypt(self._dec,destination,source,len(source)) - - class _Rsa(object): RSA_MIN_PAD_SIZE = 11 @@ -215,6 +188,9 @@ class _Rsa(object): raise WolfCryptError("Invalid key error (%d)" % ret) self._random = Random() + ret = _lib.wc_RsaSetRNG(self.native_object, self._random.native_object) + if ret < 0: + raise WolfCryptError("Key initialization error (%d)" % ret) def __del__(self): diff --git a/wrapper/python/wolfcrypt/exceptions.py b/wrapper/python/wolfcrypt/wolfcrypt/exceptions.py similarity index 100% rename from wrapper/python/wolfcrypt/exceptions.py rename to wrapper/python/wolfcrypt/wolfcrypt/exceptions.py diff --git a/wrapper/python/wolfcrypt/hashes.py b/wrapper/python/wolfcrypt/wolfcrypt/hashes.py similarity index 100% rename from wrapper/python/wolfcrypt/hashes.py rename to wrapper/python/wolfcrypt/wolfcrypt/hashes.py diff --git a/wrapper/python/wolfcrypt/random.py b/wrapper/python/wolfcrypt/wolfcrypt/random.py similarity index 100% rename from wrapper/python/wolfcrypt/random.py rename to wrapper/python/wolfcrypt/wolfcrypt/random.py diff --git a/wrapper/python/wolfcrypt/utils.py b/wrapper/python/wolfcrypt/wolfcrypt/utils.py similarity index 100% rename from wrapper/python/wolfcrypt/utils.py rename to wrapper/python/wolfcrypt/wolfcrypt/utils.py