aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-04-09 10:39:31 -0400
committerJack Lloyd <[email protected]>2016-04-09 10:39:31 -0400
commit5e75f6db1c3d73fdb778d49751f1b2ef4549b177 (patch)
treeaf2fcece77bc2c7aee2bcaf6dbc86515029b1680 /src
parentd97a1d4555e9e6bf74fb11f0d0e44bcab0a81c98 (diff)
parent02f85e4de578080a7f62c245231151ffb0aeaba8 (diff)
Merge GH #464 fix Python3 bcrypt, add test
Fixes GH #461
Diffstat (limited to 'src')
-rwxr-xr-xsrc/python/botan.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/python/botan.py b/src/python/botan.py
index 1cb141ef5..6e5f457b3 100755
--- a/src/python/botan.py
+++ b/src/python/botan.py
@@ -310,16 +310,16 @@ def bcrypt(passwd, rng, work_factor = 10):
out_len = c_size_t(64)
out = create_string_buffer(out_len.value)
flags = c_uint32(0)
- rc = botan.botan_bcrypt_generate(out, byref(out_len), passwd, rng.rng, c_size_t(work_factor), flags)
+ rc = botan.botan_bcrypt_generate(out, byref(out_len), _ctype_str(passwd), rng.rng, c_size_t(work_factor), flags)
if rc != 0:
raise Exception('botan bcrypt failed, error %s' % (rc))
- b = out.raw[0:out_len.value]
+ b = out.raw[0:out_len.value-1]
if b[-1] == '\x00':
b = b[:-1]
return b
def check_bcrypt(passwd, bcrypt):
- rc = botan.botan_bcrypt_is_valid(passwd, bcrypt)
+ rc = botan.botan_bcrypt_is_valid(_ctype_str(passwd), bcrypt)
return (rc == 0)
"""
@@ -715,6 +715,14 @@ def test():
print('x %s' % hex_encode(psk))
print('y %s\n' % (hex_encode(pbkdf('PBKDF2(SHA-256)', 'xyz', 32, iterations, salt)[2])))
+ def test_bcrypt():
+ print("Testing Bcrypt...")
+ r = rng()
+ phash = bcrypt('testing', r)
+ print("bcrypt returned %s (%d bytes)" % (hex_encode(phash), len(phash)))
+ print("validating the hash produced: %r" % (check_bcrypt('testing', phash)))
+ print("\n")
+
def test_hmac():
hmac = message_authentication_code('HMAC(SHA-256)')
@@ -907,6 +915,7 @@ def test():
test_version()
test_kdf()
test_pbkdf()
+ test_bcrypt()
test_hmac()
test_rng()
test_hash()