Mise à jour de GitLab prévue ce dimanche 25 octobre 2020 à partir de 9h00 CEST | GitLab upgrade planned this Sunday 25th of October 2020 from 9:00 AM CEST

Commit 17e7870a authored by Moul's avatar Moul

[dep] #86: Replace pylibscrypt.scrypt by hashlib.scrypt

Specify parameters since they are mandatory
Remove pylibscrypt dependency
ScryptParams: pass attributes as mandatory since mypy is not happy
parent 0d71120e
Pipeline #9770 waiting for manual action with stages
in 3 minutes and 48 seconds
......@@ -19,7 +19,6 @@ This library is used by two clients:
## Requirements
- Python >= 3.6.8
- [aiohttp >= 3.6.1](https://pypi.org/pypi/aiohttp)
- [pylibscrypt](https://pypi.org/pypi/pylibscrypt)
- [libnacl](https://pypi.org/pypi/libnacl)
- [base58](https://pypi.org/pypi/base58)
- [attr](https://pypi.org/project/attr/)
......
......@@ -6,7 +6,7 @@ duniter public and private keys
from typing import Union, Optional
import libnacl.public
from pylibscrypt import scrypt
from hashlib import scrypt
from .scrypt_params import ScryptParams
from .base58 import Base58Encoder
......@@ -38,11 +38,11 @@ class SecretKey(libnacl.public.SecretKey):
password = ensure_bytes(password)
seed = scrypt(
password,
salt,
scrypt_params.N,
scrypt_params.r,
scrypt_params.p,
scrypt_params.seed_length,
salt=salt,
n=scrypt_params.N,
r=scrypt_params.r,
p=scrypt_params.p,
dklen=scrypt_params.seed_length,
)
super().__init__(seed)
......
from typing import Optional
from .constants import SCRYPT_PARAMS
......@@ -10,18 +8,18 @@ class ScryptParams:
def __init__(
self,
n: Optional[int] = SCRYPT_PARAMS["N"],
r: Optional[int] = SCRYPT_PARAMS["r"],
p: Optional[int] = SCRYPT_PARAMS["p"],
seed_length: Optional[int] = SCRYPT_PARAMS["seed_length"],
n: int = SCRYPT_PARAMS["N"],
r: int = SCRYPT_PARAMS["r"],
p: int = SCRYPT_PARAMS["p"],
seed_length: int = SCRYPT_PARAMS["seed_length"],
) -> None:
"""
Init a ScryptParams instance with crypto parameters
:param n: Optional scrypt param N, default see constant SCRYPT_PARAMS
:param r: Optional scrypt param r, default see constant SCRYPT_PARAMS
:param p: Optional scrypt param p, default see constant SCRYPT_PARAMS
:param seed_length: Optional scrypt param seed_length, default see constant SCRYPT_PARAMS
:param n: scrypt param N, default see constant SCRYPT_PARAMS
:param r: scrypt param r, default see constant SCRYPT_PARAMS
:param p: scrypt param p, default see constant SCRYPT_PARAMS
:param seed_length: scrypt param seed_length, default see constant SCRYPT_PARAMS
"""
self.N = n
self.r = r
......
......@@ -10,7 +10,7 @@ from typing import Optional, Union, TypeVar, Type
import libnacl.sign
import pyaes
from libnacl.utils import load_key
from pylibscrypt import scrypt
from hashlib import scrypt
from .scrypt_params import ScryptParams
from .base58 import Base58Encoder
......@@ -56,11 +56,11 @@ class SigningKey(libnacl.sign.Signer):
password = ensure_bytes(password)
seed = scrypt(
password,
salt,
scrypt_params.N,
scrypt_params.r,
scrypt_params.p,
scrypt_params.seed_length,
salt=salt,
n=scrypt_params.N,
r=scrypt_params.r,
p=scrypt_params.p,
dklen=scrypt_params.seed_length,
)
return cls(seed)
......@@ -394,7 +394,7 @@ Data: {data}""".format(
# SCRYPT
password_bytes = password.encode("utf-8")
scrypt_seed = scrypt(password_bytes, salt, 16384, 8, 8, 64)
scrypt_seed = scrypt(password_bytes, salt=salt, n=16384, r=8, p=8, dklen=64)
derivedhalf1 = scrypt_seed[0:32]
derivedhalf2 = scrypt_seed[32:64]
......@@ -435,7 +435,7 @@ Data: {data}""".format(
# SCRYPT
password_bytes = password.encode("utf-8")
scrypt_seed = scrypt(password_bytes, salt, 16384, 8, 8, 64)
scrypt_seed = scrypt(password_bytes, salt=salt, n=16384, r=8, p=8, dklen=64)
derivedhalf1 = scrypt_seed[0:32]
derivedhalf2 = scrypt_seed[32:64]
......
......@@ -30,7 +30,6 @@ jsonschema = "^3.0.2"
pypeg2 = "^2.15.2"
attrs = "^19.3.0"
base58 = "^2.0.0"
pylibscrypt = "^1.8.0"
libnacl = "^1.6.1"
pyaes = "^1.6.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment