From c1ecc2e2fa05945ab199819472892ea30eaebaa3 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 22 May 2017 14:10:33 +0200 Subject: [PATCH] include header version info in scrypt handler --- deltatar/crypto.py | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) diff --git a/deltatar/crypto.py b/deltatar/crypto.py index 478e279..f8573db 100755 --- a/deltatar/crypto.py +++ b/deltatar/crypto.py @@ -576,6 +576,14 @@ def scrypt_hashsource (pw, ins): This does not validate whether the first object is encrypted correctly. """ + if isinstance (pw, str) is True: + pw = str.encode (pw) + elif isinstance (pw, bytes) is False: + raise InvalidParameter ("password must be a string, not %s" + % type (password)) + if isinstance (ins, io.BufferedReader) is False and \ + isinstance (ins, io.FileIO) is False: + raise InvalidParameter ("file to hash must be opened in “binary” mode") hdr = None try: hdr = hdr_read_stream (ins) @@ -603,7 +611,7 @@ def scrypt_hashsource (pw, ins): hsh, _void = kdf (pw, nacl) - return hsh, nacl, params + return hsh, nacl, hdr ["version"], pver def scrypt_hashfile (pw, fname): @@ -613,7 +621,7 @@ def scrypt_hashfile (pw, fname): offset zero. """ with deptdcrypt_mk_stream (PDTCRYPT_SOURCE, fname or "-") as ins: - hsh, _void, _void = scrypt_hashsource (pw, ins) + hsh, _void, _void, _void = scrypt_hashsource (pw, ins) return hsh @@ -1482,11 +1490,14 @@ def mode_depdtcrypt (mode, secret, ins, outs): def mode_scrypt (pw, ins): - hsh, nacl, params = scrypt_hashsource (pw, ins) + hsh, nacl, version, paramversion = scrypt_hashsource (pw, ins) + defs = ENCRYPTION_PARAMETERS.get(paramversion, None) + _kdfname, params = defs ["kdf"] import json out = json.dumps ({ "salt" : binascii.hexlify (nacl).decode () , "hash" : binascii.hexlify (hsh).decode () + , "version" : version , "scrypt_params" : { "N" : params ["N"] , "r" : params ["r"] , "p" : params ["p"] -- 1.7.1