key = b''
if self['string-to-key-type'] == 'simple':
update_bytes = string
- elif self['string-to-key-type'] == 'salted':
+ elif self['string-to-key-type'] in [
+ 'salted',
+ 'iterated and salted',
+ ]:
update_bytes = self['string-to-key-salt'] + string
+ if self['string-to-key-type'] == 'iterated and salted':
+ count = self['string-to-key-count']
+ if count < len(update_bytes):
+ count = len(update_bytes)
else:
raise NotImplementedError(
'key calculation for string-to-key type {}'.format(
'salted',
]:
string_hash.update(update_bytes)
+ elif self['string-to-key-type'] == 'iterated and salted':
+ remaining = count
+ while remaining > 0:
+ string_hash.update(update_bytes[:remaining])
+ remaining -= len(update_bytes)
key += string_hash.digest()
key = key[:key_size_bytes]
return key