Commit 4670b23b authored by inso's avatar inso Committed by inso

Add ScryptParams

(cherry picked from commit e6bcfad4)
parent 7f27a608
from .signing_key import SigningKey
from .signing_key import SigningKey, ScryptParams
from .verifying_key import VerifyingKey
from .encryption_key import SecretKey, PublicKey
\ No newline at end of file
......@@ -11,11 +11,12 @@ from .base58 import Base58Encoder
SEED_LENGTH = 32 # Length of the key
crypto_sign_BYTES = 64
SCRYPT_PARAMS = {'N': 4096,
'r': 16,
'p': 1
class ScryptParams:
def __init__(self, N, r, p):
self.N = N
self.r = r
self.p = p
def _ensure_bytes(data):
if isinstance(data, str):
......@@ -25,12 +26,12 @@ def _ensure_bytes(data):
class SigningKey(libnacl.sign.Signer):
def __init__(self, salt, password):
def __init__(self, salt, password, scrypt_params):
salt = _ensure_bytes(salt)
password = _ensure_bytes(password)
seed = scrypt(password, salt,
scrypt_params.N, scrypt_params.r, scrypt_params.p,
self.pubkey = Base58Encoder.encode(self.vk)
from duniterpy.key import VerifyingKey, SigningKey
from duniterpy.key import VerifyingKey, SigningKey, ScryptParams
from duniterpy.documents import Peer
import unittest
class TestVerifyingKey(unittest.TestCase):
def test_from_sign_to_verify(self):
sign_key = SigningKey("saltsalt", "passwordpassword")
sign_key = SigningKey("saltsalt", "passwordpassword", ScryptParams(4096, 16, 1))
verify_key = VerifyingKey(sign_key.pubkey)
self.assertEqual(verify_key.vk, sign_key.vk)
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