From b50914f2c782ca16e88ca9d7c371707e77f12066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moise=CC=81s=20Guimara=CC=83es?= Date: Wed, 21 Sep 2016 13:03:11 -0300 Subject: [PATCH] Drops 3DES and adds int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng); for RSA blinding --- wrapper/python/wolfcrypt/test/test_ciphers.py | 55 ------------------- .../python/wolfcrypt/wolfcrypt/build_ffi.py | 8 +-- wrapper/python/wolfcrypt/wolfcrypt/ciphers.py | 30 +--------- 3 files changed, 4 insertions(+), 89 deletions(-) diff --git a/wrapper/python/wolfcrypt/test/test_ciphers.py b/wrapper/python/wolfcrypt/test/test_ciphers.py index c1929c89e..584bc7033 100644 --- a/wrapper/python/wolfcrypt/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/wolfcrypt/wolfcrypt/build_ffi.py b/wrapper/python/wolfcrypt/wolfcrypt/build_ffi.py index 720e96cfc..b5eb7f814 100644 --- a/wrapper/python/wolfcrypt/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/wolfcrypt/ciphers.py b/wrapper/python/wolfcrypt/wolfcrypt/ciphers.py index 4084e6bf7..dd54a3db7 100644 --- a/wrapper/python/wolfcrypt/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):