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)
hsh, _void = kdf (pw, nacl)
- return hsh, nacl, params
+ return hsh, nacl, hdr ["version"], pver
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
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"]