Skip to content
Snippets Groups Projects
Commit 9270652f authored by Moul's avatar Moul
Browse files

[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 2101183a
No related branches found
No related tags found
No related merge requests found
Pipeline #9466 passed
...@@ -19,7 +19,6 @@ This library is used by two clients: ...@@ -19,7 +19,6 @@ This library is used by two clients:
## Requirements ## Requirements
- Python >= 3.6.8 - Python >= 3.6.8
- [aiohttp >= 3.6.1](https://pypi.org/pypi/aiohttp) - [aiohttp >= 3.6.1](https://pypi.org/pypi/aiohttp)
- [pylibscrypt](https://pypi.org/pypi/pylibscrypt)
- [libnacl](https://pypi.org/pypi/libnacl) - [libnacl](https://pypi.org/pypi/libnacl)
- [base58](https://pypi.org/pypi/base58) - [base58](https://pypi.org/pypi/base58)
- [attr](https://pypi.org/project/attr/) - [attr](https://pypi.org/project/attr/)
......
...@@ -6,7 +6,7 @@ duniter public and private keys ...@@ -6,7 +6,7 @@ duniter public and private keys
from typing import Union, Optional from typing import Union, Optional
import libnacl.public import libnacl.public
from pylibscrypt import scrypt from hashlib import scrypt
from .scrypt_params import ScryptParams from .scrypt_params import ScryptParams
from .base58 import Base58Encoder from .base58 import Base58Encoder
...@@ -38,11 +38,11 @@ class SecretKey(libnacl.public.SecretKey): ...@@ -38,11 +38,11 @@ class SecretKey(libnacl.public.SecretKey):
password = ensure_bytes(password) password = ensure_bytes(password)
seed = scrypt( seed = scrypt(
password, password,
salt, salt=salt,
scrypt_params.N, n=scrypt_params.N,
scrypt_params.r, r=scrypt_params.r,
scrypt_params.p, p=scrypt_params.p,
scrypt_params.seed_length, dklen=scrypt_params.seed_length,
) )
super().__init__(seed) super().__init__(seed)
......
from typing import Optional
from .constants import SCRYPT_PARAMS from .constants import SCRYPT_PARAMS
...@@ -10,18 +8,18 @@ class ScryptParams: ...@@ -10,18 +8,18 @@ class ScryptParams:
def __init__( def __init__(
self, self,
n: Optional[int] = SCRYPT_PARAMS["N"], n: int = SCRYPT_PARAMS["N"],
r: Optional[int] = SCRYPT_PARAMS["r"], r: int = SCRYPT_PARAMS["r"],
p: Optional[int] = SCRYPT_PARAMS["p"], p: int = SCRYPT_PARAMS["p"],
seed_length: Optional[int] = SCRYPT_PARAMS["seed_length"], seed_length: int = SCRYPT_PARAMS["seed_length"],
) -> None: ) -> None:
""" """
Init a ScryptParams instance with crypto parameters Init a ScryptParams instance with crypto parameters
:param n: Optional scrypt param N, default see constant SCRYPT_PARAMS :param n: scrypt param N, default see constant SCRYPT_PARAMS
:param r: Optional scrypt param r, default see constant SCRYPT_PARAMS :param r: scrypt param r, default see constant SCRYPT_PARAMS
:param p: Optional scrypt param p, default see constant SCRYPT_PARAMS :param p: scrypt param p, default see constant SCRYPT_PARAMS
:param seed_length: Optional scrypt param seed_length, default see constant SCRYPT_PARAMS :param seed_length: scrypt param seed_length, default see constant SCRYPT_PARAMS
""" """
self.N = n self.N = n
self.r = r self.r = r
......
...@@ -10,7 +10,7 @@ from typing import Optional, Union, TypeVar, Type ...@@ -10,7 +10,7 @@ from typing import Optional, Union, TypeVar, Type
import libnacl.sign import libnacl.sign
import pyaes import pyaes
from libnacl.utils import load_key from libnacl.utils import load_key
from pylibscrypt import scrypt from hashlib import scrypt
from .scrypt_params import ScryptParams from .scrypt_params import ScryptParams
from .base58 import Base58Encoder from .base58 import Base58Encoder
...@@ -56,11 +56,11 @@ class SigningKey(libnacl.sign.Signer): ...@@ -56,11 +56,11 @@ class SigningKey(libnacl.sign.Signer):
password = ensure_bytes(password) password = ensure_bytes(password)
seed = scrypt( seed = scrypt(
password, password,
salt, salt=salt,
scrypt_params.N, n=scrypt_params.N,
scrypt_params.r, r=scrypt_params.r,
scrypt_params.p, p=scrypt_params.p,
scrypt_params.seed_length, dklen=scrypt_params.seed_length,
) )
return cls(seed) return cls(seed)
...@@ -394,7 +394,7 @@ Data: {data}""".format( ...@@ -394,7 +394,7 @@ Data: {data}""".format(
# SCRYPT # SCRYPT
password_bytes = password.encode("utf-8") 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] derivedhalf1 = scrypt_seed[0:32]
derivedhalf2 = scrypt_seed[32:64] derivedhalf2 = scrypt_seed[32:64]
...@@ -435,7 +435,7 @@ Data: {data}""".format( ...@@ -435,7 +435,7 @@ Data: {data}""".format(
# SCRYPT # SCRYPT
password_bytes = password.encode("utf-8") 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] derivedhalf1 = scrypt_seed[0:32]
derivedhalf2 = scrypt_seed[32:64] derivedhalf2 = scrypt_seed[32:64]
......
...@@ -30,7 +30,6 @@ jsonschema = "^3.0.2" ...@@ -30,7 +30,6 @@ jsonschema = "^3.0.2"
pypeg2 = "^2.15.2" pypeg2 = "^2.15.2"
attrs = "^19.3.0" attrs = "^19.3.0"
base58 = "^2.0.0" base58 = "^2.0.0"
pylibscrypt = "^1.8.0"
libnacl = "^1.6.1" libnacl = "^1.6.1"
pyaes = "^1.6.1" pyaes = "^1.6.1"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment