Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if context._._.transformed_key is not None:
transformed_key = context._._.transformed_key
elif kdf_parameters['$UUID'].value == kdf_uuids['argon2']:
transformed_key = argon2.low_level.hash_secret_raw(
secret=key_composite,
salt=kdf_parameters['S'].value,
hash_len=32,
type=argon2.low_level.Type.D,
time_cost=kdf_parameters['I'].value,
memory_cost=kdf_parameters['M'].value // 1024,
parallelism=kdf_parameters['P'].value,
version=kdf_parameters['V'].value
)
elif kdf_parameters['$UUID'].value == kdf_uuids['aeskdf']:
key_composite = compute_key_composite(
password=context._._.password,
keyfile=context._._.keyfile
)
transformed_key = aes_kdf(
kdf_parameters['S'].value,
kdf_parameters['R'].value,
key_composite
)
else:
raise Exception('Unsupported key derivation method')
return transformed_key
def compute_transformed(context):
"""Compute transformed key for opening database"""
key_composite = compute_key_composite(
password=context._._.password,
keyfile=context._._.keyfile
)
kdf_parameters = context._.header.value.dynamic_header.kdf_parameters.data.dict
if context._._.transformed_key is not None:
transformed_key = context._._.transformed_key
elif kdf_parameters['$UUID'].value == kdf_uuids['argon2']:
transformed_key = argon2.low_level.hash_secret_raw(
secret=key_composite,
salt=kdf_parameters['S'].value,
hash_len=32,
type=argon2.low_level.Type.D,
time_cost=kdf_parameters['I'].value,
memory_cost=kdf_parameters['M'].value // 1024,
parallelism=kdf_parameters['P'].value,
def compute_transformed(context):
"""Compute transformed key for opening database"""
if context._._.transformed_key is not None:
transformed_key = context._._.transformed_key
else:
key_composite = compute_key_composite(
password=context._._.password,
keyfile=context._._.keyfile
)
transformed_key = aes_kdf(
context._.header.value.dynamic_header.transform_seed.data,
context._.header.value.dynamic_header.transform_rounds.data,
key_composite
)
return transformed_key