From 53657dba47c070763b7624513cf3aa059fde1bc7 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 2 Mar 2017 15:03:08 +0100 Subject: [PATCH] Phase 1 of SHA256 support - new variable "digestalg" which defaults to "sha1", but allows "sha256" for those who want to sign using this - Addresses #953 --- src/highlevelcrypto.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index 50f13cce..4a24fe20 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -1,4 +1,5 @@ from binascii import hexlify +from bmconfigparser import BMConfigParser import pyelliptic from pyelliptic import arithmetic as a, OpenSSL def makeCryptor(privkey): @@ -35,8 +36,17 @@ def sign(msg,hexPrivkey): # upgrade PyBitmessage gracefully. # https://github.com/yann2192/pyelliptic/pull/33 # More discussion: https://github.com/yann2192/pyelliptic/issues/32 - return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1) # SHA1 - #return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256) # SHA256. We should switch to this eventually. + digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1') + if digestAlg == "sha1": + # SHA1, this will eventually be deprecated + print "sha1" + return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1) + elif digestAlg == "sha256": + # SHA256. Eventually this will become the default + print "sha256" + return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256) + else: + raise ValueError("Unknown digest algorithm %s" % (digestAlgo)) # Verifies with hex public key def verify(msg,sig,hexPubkey): # As mentioned above, we must upgrade gracefully to use SHA256. So