renames utils functions
parent
1ee485dee3
commit
2287ebad58
|
@ -19,13 +19,13 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
import unittest
|
||||
from wolfcrypt.ciphers import *
|
||||
from wolfcrypt.utils import _t2b, _h2b
|
||||
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")
|
||||
key = h2b("0123456789abcdeffedeba987654321089abcdef01234567")
|
||||
IV = h2b("1234567890abcdef")
|
||||
plain = t2b("Now is the time for all ")
|
||||
cipher = h2b("43a0297ed184f80e8964843212d508981894157487127db0")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
|
@ -52,7 +52,7 @@ class TestDes3(unittest.TestCase):
|
|||
|
||||
|
||||
def test_multi_encryption(self):
|
||||
result = _t2b("")
|
||||
result = t2b("")
|
||||
segments = tuple(self.plain[i:i + Des3.block_size] \
|
||||
for i in range(0, len(self.plain), Des3.block_size))
|
||||
|
||||
|
@ -67,7 +67,7 @@ class TestDes3(unittest.TestCase):
|
|||
|
||||
|
||||
def test_multi_decryption(self):
|
||||
result = _t2b("")
|
||||
result = t2b("")
|
||||
segments = tuple(self.cipher[i:i + Des3.block_size] \
|
||||
for i in range(0, len(self.cipher), Des3.block_size))
|
||||
|
||||
|
@ -80,8 +80,8 @@ class TestDes3(unittest.TestCase):
|
|||
class TestAes(unittest.TestCase):
|
||||
key = "0123456789abcdef"
|
||||
IV = "1234567890abcdef"
|
||||
plain = _t2b("now is the time ")
|
||||
cipher = _h2b("959492575f4281532ccc9d4677a233cb")
|
||||
plain = t2b("now is the time ")
|
||||
cipher = h2b("959492575f4281532ccc9d4677a233cb")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
|
@ -108,7 +108,7 @@ class TestAes(unittest.TestCase):
|
|||
|
||||
|
||||
def test_multi_encryption(self):
|
||||
result = _t2b("")
|
||||
result = t2b("")
|
||||
segments = tuple(self.plain[i:i + self.aes.block_size] \
|
||||
for i in range(0, len(self.plain), self.aes.block_size))
|
||||
|
||||
|
@ -123,7 +123,7 @@ class TestAes(unittest.TestCase):
|
|||
|
||||
|
||||
def test_multi_decryption(self):
|
||||
result = _t2b("")
|
||||
result = t2b("")
|
||||
segments = tuple(self.cipher[i:i + self.aes.block_size] \
|
||||
for i in range(0, len(self.cipher), self.aes.block_size))
|
||||
|
||||
|
@ -154,11 +154,11 @@ class TestRsaPrivate(unittest.TestCase):
|
|||
+ "3989E59C195530BAB7488C48140EF49F7E779743E1B419353123759C3B44AD69" \
|
||||
+ "1256EE0061641666D37C742B15B4A2FEBF086B1A5D3F9012B105863129DBD9E2"
|
||||
|
||||
plain = _t2b("Everyone gets Friday off.")
|
||||
plain = t2b("Everyone gets Friday off.")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.rsa = RsaPrivate(_h2b(self.key))
|
||||
self.rsa = RsaPrivate(h2b(self.key))
|
||||
|
||||
|
||||
def test_raises(self):
|
||||
|
@ -213,12 +213,12 @@ class TestRsaPublic(unittest.TestCase):
|
|||
+ "38CC39A20466B4F7F7F3AADA4D020EBB5E8D6948DC77C9280E22E96BA426BA4C" \
|
||||
+ "E8C1FD4A6F2B1FEF8AAEF69062E5641EEB2B3C67C8DC2700F6916865A90203010001"
|
||||
|
||||
plain = _t2b("Everyone gets Friday off.")
|
||||
plain = t2b("Everyone gets Friday off.")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
self.private = RsaPrivate(_h2b(self.prv))
|
||||
self.public = RsaPublic(_h2b(self.pub))
|
||||
self.private = RsaPrivate(h2b(self.prv))
|
||||
self.public = RsaPublic(h2b(self.pub))
|
||||
|
||||
|
||||
def test_raises(self):
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
import unittest
|
||||
from wolfcrypt.hashes import *
|
||||
from wolfcrypt.utils import _t2b, _h2b
|
||||
from wolfcrypt.utils import t2b, h2b
|
||||
|
||||
|
||||
class TestSha(unittest.TestCase):
|
||||
_class = Sha
|
||||
digest = _t2b("1b6182d68ae91ce0853bd9c6b6edfedd4b6a510d")
|
||||
digest = t2b("1b6182d68ae91ce0853bd9c6b6edfedd4b6a510d")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
|
@ -40,7 +40,7 @@ class TestSha(unittest.TestCase):
|
|||
self.hash.update("wolfcrypt")
|
||||
|
||||
assert self.hash.hexdigest() == self.digest
|
||||
assert self.hash.digest() == _h2b(self.digest)
|
||||
assert self.hash.digest() == h2b(self.digest)
|
||||
|
||||
|
||||
def test_hash_update_002(self):
|
||||
|
@ -48,7 +48,7 @@ class TestSha(unittest.TestCase):
|
|||
self.hash.update("crypt")
|
||||
|
||||
assert self.hash.hexdigest() == self.digest
|
||||
assert self.hash.digest() == _h2b(self.digest)
|
||||
assert self.hash.digest() == h2b(self.digest)
|
||||
|
||||
|
||||
def test_hash_copy(self):
|
||||
|
@ -67,19 +67,19 @@ class TestSha(unittest.TestCase):
|
|||
|
||||
class TestSha256(TestSha):
|
||||
_class = Sha256
|
||||
digest = _t2b("96e02e7b1cbcd6f104fe1fdb4652027a" \
|
||||
digest = t2b("96e02e7b1cbcd6f104fe1fdb4652027a" \
|
||||
+ "5505b68652b70095c6318f9dce0d1844")
|
||||
|
||||
|
||||
class TestSha384(TestSha):
|
||||
_class = Sha384
|
||||
digest = _t2b("4c79d80531203a16f91bee325f18c6aada47f9382fe44fc1" \
|
||||
digest = t2b("4c79d80531203a16f91bee325f18c6aada47f9382fe44fc1" \
|
||||
+ "1f92917837e9b7902f5dccb7d3656f667a1dce3460bc884b")
|
||||
|
||||
|
||||
class TestSha512(TestSha):
|
||||
_class = Sha512
|
||||
digest = _t2b("88fcf67ffd8558d713f9cedcd852db47" \
|
||||
digest = t2b("88fcf67ffd8558d713f9cedcd852db47" \
|
||||
+ "9e6573f0bd9955610a993f609637553c" \
|
||||
+ "e8fff55e644ee8a106aae19c07f91b3f" \
|
||||
+ "2a2a6d40dfa7302c0fa6a1a9a5bfa03f")
|
||||
|
@ -90,7 +90,7 @@ _HMAC_KEY = "python"
|
|||
|
||||
class TestHmacSha(unittest.TestCase):
|
||||
_class = HmacSha
|
||||
digest = _t2b("5dfabcfb3a25540824867cd21f065f52f73491e0")
|
||||
digest = t2b("5dfabcfb3a25540824867cd21f065f52f73491e0")
|
||||
|
||||
|
||||
def setUp(self):
|
||||
|
@ -131,19 +131,19 @@ class TestHmacSha(unittest.TestCase):
|
|||
|
||||
class TestHmacSha256(TestHmacSha):
|
||||
_class = HmacSha256
|
||||
digest = _t2b("4b641d721493d80f019d9447830ebfee" \
|
||||
digest = t2b("4b641d721493d80f019d9447830ebfee" \
|
||||
+ "89234a7d594378b89f8bb73873576bf6")
|
||||
|
||||
|
||||
class TestHmacSha384(TestHmacSha):
|
||||
_class = HmacSha384
|
||||
digest = _t2b("e72c72070c9c5c78e3286593068a510c1740cdf9dc34b512" \
|
||||
digest = t2b("e72c72070c9c5c78e3286593068a510c1740cdf9dc34b512" \
|
||||
+ "ccec97320295db1fe673216b46fe72e81f399a9ec04780ab")
|
||||
|
||||
|
||||
class TestHmacSha512(TestHmacSha):
|
||||
_class = HmacSha512
|
||||
digest = _t2b("c7f48db79314fc2b5be9a93fd58601a1" \
|
||||
digest = t2b("c7f48db79314fc2b5be9a93fd58601a1" \
|
||||
+ "bf42f397ec7f66dba034d44503890e6b" \
|
||||
+ "5708242dcd71a248a78162d815c685f6" \
|
||||
+ "038a4ac8cb34b8bf18986dbd300c9b41")
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
from wolfcrypt._ffi import ffi as _ffi
|
||||
from wolfcrypt._ffi import lib as _lib
|
||||
from wolfcrypt.utils import _t2b
|
||||
from wolfcrypt.utils import t2b
|
||||
from wolfcrypt.random import Random
|
||||
|
||||
from wolfcrypt.exceptions import *
|
||||
|
@ -64,12 +64,12 @@ class _Cipher(object):
|
|||
self._native_object = _ffi.new(self._native_type)
|
||||
self._enc = None
|
||||
self._dec = None
|
||||
self._key = _t2b(key)
|
||||
self._key = t2b(key)
|
||||
|
||||
if IV:
|
||||
self._IV = _t2b(IV)
|
||||
self._IV = t2b(IV)
|
||||
else:
|
||||
self._IV = _t2b("\0" * self.block_size)
|
||||
self._IV = t2b("\0" * self.block_size)
|
||||
|
||||
|
||||
@classmethod
|
||||
|
@ -79,7 +79,7 @@ class _Cipher(object):
|
|||
|
||||
|
||||
def encrypt(self, string):
|
||||
string = _t2b(string)
|
||||
string = t2b(string)
|
||||
|
||||
if not string or len(string) % self.block_size:
|
||||
raise ValueError(
|
||||
|
@ -91,7 +91,7 @@ class _Cipher(object):
|
|||
if ret < 0:
|
||||
raise WolfCryptError("Invalid key error (%d)" % ret)
|
||||
|
||||
result = _t2b("\0" * len(string))
|
||||
result = t2b("\0" * len(string))
|
||||
ret = self._encrypt(result, string)
|
||||
if ret < 0:
|
||||
raise WolfCryptError("Encryption error (%d)" % ret)
|
||||
|
@ -100,7 +100,7 @@ class _Cipher(object):
|
|||
|
||||
|
||||
def decrypt(self, string):
|
||||
string = _t2b(string)
|
||||
string = t2b(string)
|
||||
|
||||
if not string or len(string) % self.block_size:
|
||||
raise ValueError(
|
||||
|
@ -112,7 +112,7 @@ class _Cipher(object):
|
|||
if ret < 0:
|
||||
raise WolfCryptError("Invalid key error (%d)" % ret)
|
||||
|
||||
result = _t2b("\0" * len(string))
|
||||
result = t2b("\0" * len(string))
|
||||
ret = self._decrypt(result, string)
|
||||
if ret < 0:
|
||||
raise WolfCryptError("Decryption error (%d)" % ret)
|
||||
|
@ -182,7 +182,7 @@ class _Rsa(object):
|
|||
|
||||
class RsaPublic(_Rsa):
|
||||
def __init__(self, key):
|
||||
key = _t2b(key)
|
||||
key = t2b(key)
|
||||
|
||||
_Rsa.__init__(self)
|
||||
|
||||
|
@ -199,8 +199,8 @@ class RsaPublic(_Rsa):
|
|||
|
||||
|
||||
def encrypt(self, plaintext):
|
||||
plaintext = _t2b(plaintext)
|
||||
ciphertext = _t2b("\0" * self.output_size)
|
||||
plaintext = t2b(plaintext)
|
||||
ciphertext = t2b("\0" * self.output_size)
|
||||
|
||||
ret = _lib.wc_RsaPublicEncrypt(plaintext, len(plaintext),
|
||||
ciphertext, len(ciphertext),
|
||||
|
@ -214,8 +214,8 @@ class RsaPublic(_Rsa):
|
|||
|
||||
|
||||
def verify(self, signature):
|
||||
signature = _t2b(signature)
|
||||
plaintext = _t2b("\0" * self.output_size)
|
||||
signature = t2b(signature)
|
||||
plaintext = t2b("\0" * self.output_size)
|
||||
|
||||
ret = _lib.wc_RsaSSL_Verify(signature, len(signature),
|
||||
plaintext, len(plaintext),
|
||||
|
@ -229,7 +229,7 @@ class RsaPublic(_Rsa):
|
|||
|
||||
class RsaPrivate(RsaPublic):
|
||||
def __init__(self, key):
|
||||
key = _t2b(key)
|
||||
key = t2b(key)
|
||||
|
||||
_Rsa.__init__(self)
|
||||
|
||||
|
@ -246,8 +246,8 @@ class RsaPrivate(RsaPublic):
|
|||
|
||||
|
||||
def decrypt(self, ciphertext):
|
||||
ciphertext = _t2b(ciphertext)
|
||||
plaintext = _t2b("\0" * self.output_size)
|
||||
ciphertext = t2b(ciphertext)
|
||||
plaintext = t2b("\0" * self.output_size)
|
||||
|
||||
ret = _lib.wc_RsaPrivateDecrypt(ciphertext, len(ciphertext),
|
||||
plaintext, len(plaintext),
|
||||
|
@ -260,8 +260,8 @@ class RsaPrivate(RsaPublic):
|
|||
|
||||
|
||||
def sign(self, plaintext):
|
||||
plaintext = _t2b(plaintext)
|
||||
signature = _t2b("\0" * self.output_size)
|
||||
plaintext = t2b(plaintext)
|
||||
signature = t2b("\0" * self.output_size)
|
||||
|
||||
ret = _lib.wc_RsaSSL_Sign(plaintext, len(plaintext),
|
||||
signature, len(signature),
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
from wolfcrypt._ffi import ffi as _ffi
|
||||
from wolfcrypt._ffi import lib as _lib
|
||||
from wolfcrypt.utils import _t2b, _b2h
|
||||
from wolfcrypt.utils import t2b, b2h
|
||||
|
||||
from wolfcrypt.exceptions import *
|
||||
|
||||
|
@ -54,7 +54,7 @@ class _Hash(object):
|
|||
|
||||
|
||||
def update(self, string):
|
||||
string = _t2b(string)
|
||||
string = t2b(string)
|
||||
|
||||
ret = self._update(string)
|
||||
if ret < 0:
|
||||
|
@ -62,7 +62,7 @@ class _Hash(object):
|
|||
|
||||
|
||||
def digest(self):
|
||||
result = _t2b("\0" * self.digest_size)
|
||||
result = t2b("\0" * self.digest_size)
|
||||
|
||||
if self._native_object:
|
||||
obj = _ffi.new(self._native_type)
|
||||
|
@ -77,7 +77,7 @@ class _Hash(object):
|
|||
|
||||
|
||||
def hexdigest(self):
|
||||
return _b2h(self.digest())
|
||||
return b2h(self.digest())
|
||||
|
||||
|
||||
class Sha(_Hash):
|
||||
|
@ -168,7 +168,7 @@ class _Hmac(_Hash):
|
|||
|
||||
|
||||
def __init__(self, key):
|
||||
key = _t2b(key)
|
||||
key = t2b(key)
|
||||
|
||||
self._native_object = _ffi.new(self._native_type)
|
||||
ret = self._init(self._type, key)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
from wolfcrypt._ffi import ffi as _ffi
|
||||
from wolfcrypt._ffi import lib as _lib
|
||||
from wolfcrypt.utils import _t2b
|
||||
from wolfcrypt.utils import t2b
|
||||
|
||||
from wolfcrypt.exceptions import *
|
||||
|
||||
|
@ -40,7 +40,7 @@ class Random(object):
|
|||
|
||||
|
||||
def byte(self):
|
||||
result = _t2b("\0")
|
||||
result = t2b("\0")
|
||||
|
||||
ret = _lib.wc_RNG_GenerateByte(self.native_object, result)
|
||||
if ret < 0:
|
||||
|
@ -50,7 +50,7 @@ class Random(object):
|
|||
|
||||
|
||||
def bytes(self, length):
|
||||
result = _t2b("\0" * length)
|
||||
result = t2b("\0" * length)
|
||||
|
||||
ret = _lib.wc_RNG_GenerateBlock(self.native_object, result, length)
|
||||
if ret < 0:
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
import sys
|
||||
from binascii import hexlify as _b2h, unhexlify as _h2b
|
||||
from binascii import hexlify as b2h, unhexlify as h2b
|
||||
|
||||
|
||||
if sys.version_info[0] == 3:
|
||||
|
@ -29,7 +29,7 @@ else:
|
|||
_binary_type = str
|
||||
|
||||
|
||||
def _t2b(s):
|
||||
def t2b(s):
|
||||
if isinstance(s, _binary_type):
|
||||
return s
|
||||
return _text_type(s).encode("utf-8")
|
||||
|
|
Loading…
Reference in New Issue