mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 13:45:31 +00:00
Argon2 the first part: Implement key derivation (was: part 0) (#6468)
add a argon2 based kdf, using argon2-cffi
This commit is contained in:
parent
dfd7ea8171
commit
78f041440c
2 changed files with 29 additions and 0 deletions
1
setup.py
1
setup.py
|
@ -65,6 +65,7 @@
|
||||||
# using any other version is not supported by borg development and
|
# using any other version is not supported by borg development and
|
||||||
# any feedback related to issues caused by this will be ignored.
|
# any feedback related to issues caused by this will be ignored.
|
||||||
'packaging',
|
'packaging',
|
||||||
|
'argon2-cffi',
|
||||||
]
|
]
|
||||||
|
|
||||||
# note for package maintainers: if you package borgbackup for distribution,
|
# note for package maintainers: if you package borgbackup for distribution,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from hashlib import pbkdf2_hmac
|
from hashlib import pbkdf2_hmac
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from . import bin_to_hex
|
from . import bin_to_hex
|
||||||
from . import Error
|
from . import Error
|
||||||
|
@ -12,6 +13,8 @@
|
||||||
|
|
||||||
from ..logger import create_logger
|
from ..logger import create_logger
|
||||||
|
|
||||||
|
import argon2.low_level
|
||||||
|
|
||||||
logger = create_logger()
|
logger = create_logger()
|
||||||
|
|
||||||
|
|
||||||
|
@ -139,3 +142,28 @@ def __repr__(self):
|
||||||
|
|
||||||
def kdf(self, salt, iterations, length):
|
def kdf(self, salt, iterations, length):
|
||||||
return pbkdf2_hmac('sha256', self.encode('utf-8'), salt, iterations, length)
|
return pbkdf2_hmac('sha256', self.encode('utf-8'), salt, iterations, length)
|
||||||
|
|
||||||
|
def argon2(
|
||||||
|
self,
|
||||||
|
output_len_in_bytes: int,
|
||||||
|
salt: bytes,
|
||||||
|
time_cost,
|
||||||
|
memory_cost,
|
||||||
|
parallelism,
|
||||||
|
type: Literal['i', 'd', 'id']
|
||||||
|
) -> bytes:
|
||||||
|
type_map = {
|
||||||
|
'i': argon2.low_level.Type.I,
|
||||||
|
'd': argon2.low_level.Type.D,
|
||||||
|
'id': argon2.low_level.Type.ID,
|
||||||
|
}
|
||||||
|
key = argon2.low_level.hash_secret_raw(
|
||||||
|
secret=self.encode("utf-8"),
|
||||||
|
hash_len=output_len_in_bytes,
|
||||||
|
salt=salt,
|
||||||
|
time_cost=time_cost,
|
||||||
|
memory_cost=memory_cost,
|
||||||
|
parallelism=parallelism,
|
||||||
|
type=type_map[type],
|
||||||
|
)
|
||||||
|
return key
|
||||||
|
|
Loading…
Reference in a new issue