Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove pbkdf2 dependency, use stdlib instead #4563

Merged
merged 1 commit into from Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion contrib/requirements/requirements.txt
@@ -1,6 +1,5 @@
pyaes>=0.1a1
ecdsa>=0.9
pbkdf2
requests
qrcode
protobuf
Expand Down
7 changes: 3 additions & 4 deletions electrum/keystore.py
Expand Up @@ -552,13 +552,12 @@ def bip39_normalize_passphrase(passphrase):
return normalize('NFKD', passphrase or '')

def bip39_to_seed(mnemonic, passphrase):
import pbkdf2, hashlib, hmac
import hashlib, hmac
PBKDF2_ROUNDS = 2048
mnemonic = normalize('NFKD', ' '.join(mnemonic.split()))
passphrase = bip39_normalize_passphrase(passphrase)
return pbkdf2.PBKDF2(mnemonic, 'mnemonic' + passphrase,
iterations = PBKDF2_ROUNDS, macmodule = hmac,
digestmodule = hashlib.sha512).read(64)
return hashlib.pbkdf2_hmac('sha512', mnemonic.encode('utf-8'),
b'mnemonic' + passphrase.encode('utf-8'), iterations = PBKDF2_ROUNDS)

# returns tuple (is_checksum_valid, is_wordlist_valid)
def bip39_is_checksum_valid(mnemonic):
Expand Down
3 changes: 1 addition & 2 deletions electrum/mnemonic.py
Expand Up @@ -30,7 +30,6 @@
import string

import ecdsa
import pbkdf2

from .util import print_error
from .bitcoin import is_old_seed, is_new_seed
Expand Down Expand Up @@ -131,7 +130,7 @@ def mnemonic_to_seed(self, mnemonic, passphrase):
PBKDF2_ROUNDS = 2048
mnemonic = normalize_text(mnemonic)
passphrase = normalize_text(passphrase)
return pbkdf2.PBKDF2(mnemonic, 'electrum' + passphrase, iterations = PBKDF2_ROUNDS, macmodule = hmac, digestmodule = hashlib.sha512).read(64)
return hashlib.pbkdf2_hmac('sha512', mnemonic.encode('utf-8'), b'electrum' + passphrase.encode('utf-8'), iterations = PBKDF2_ROUNDS)

def mnemonic_encode(self, i):
n = len(self.wordlist)
Expand Down
4 changes: 2 additions & 2 deletions electrum/plugins/digitalbitbox/digitalbitbox.py
Expand Up @@ -120,8 +120,8 @@ def dbb_has_password(self):


def stretch_key(self, key):
import pbkdf2, hmac
return to_hexstr(pbkdf2.PBKDF2(key, b'Digital Bitbox', iterations = 20480, macmodule = hmac, digestmodule = hashlib.sha512).read(64))
import hmac
return to_hexstr(hashlib.pbkdf2_hmac('sha512', key.encode('utf-8'), b'Digital Bitbox', iterations = 20480))


def backup_password_dialog(self):
Expand Down
6 changes: 3 additions & 3 deletions electrum/storage.py
Expand Up @@ -29,7 +29,7 @@
import copy
import re
import stat
import pbkdf2, hmac, hashlib
import hmac, hashlib
import base64
import zlib
from collections import defaultdict
Expand Down Expand Up @@ -165,7 +165,7 @@ def file_exists(self):

@staticmethod
def get_eckey_from_password(password):
secret = pbkdf2.PBKDF2(password, '', iterations=1024, macmodule=hmac, digestmodule=hashlib.sha512).read(64)
secret = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), b'', iterations=1024)
ec_key = ecc.ECPrivkey.from_arbitrary_size_secret(secret)
return ec_key

Expand Down Expand Up @@ -637,7 +637,7 @@ def raise_unsupported_version(self, seed_version):
# version 1.9.8 created v6 wallets when an incorrect seed was entered in the restore dialog
msg += '\n\nThis file was created because of a bug in version 1.9.8.'
if self.get('master_public_keys') is None and self.get('master_private_keys') is None and self.get('imported_keys') is None:
# pbkdf2 was not included with the binaries, and wallet creation aborted.
# pbkdf2 (at that time an additional dependency) was not included with the binaries, and wallet creation aborted.
msg += "\nIt does not contain any keys, and can safely be removed."
else:
# creation was complete if electrum was run from source
Expand Down
1 change: 0 additions & 1 deletion run_electrum
Expand Up @@ -46,7 +46,6 @@ def check_imports():
import ecdsa
import requests
import qrcode
import pbkdf2
import google.protobuf
import jsonrpclib
except ImportError as e:
Expand Down