2828 encodeAddress , encodeVarint , varintDecodeError
2929)
3030from bmconfigparser import config
31- from fallback import RIPEMD160Hash
3231from helper_sql import (
3332 sql_ready , sql_timeout , SqlBulkExecute , sqlExecute , sqlQuery )
3433from network import knownnodes
@@ -300,31 +299,28 @@ def processpubkey(self, data):
300299 '(within processpubkey) payloadLength less than 146.'
301300 ' Sanity check failed.' )
302301 readPosition += 4
303- publicSigningKey = data [readPosition :readPosition + 64 ]
302+ pubSigningKey = ' \x04 ' + data [readPosition :readPosition + 64 ]
304303 # Is it possible for a public key to be invalid such that trying to
305304 # encrypt or sign with it will cause an error? If it is, it would
306305 # be easiest to test them here.
307306 readPosition += 64
308- publicEncryptionKey = data [readPosition :readPosition + 64 ]
309- if len (publicEncryptionKey ) < 64 :
307+ pubEncryptionKey = ' \x04 ' + data [readPosition :readPosition + 64 ]
308+ if len (pubEncryptionKey ) < 65 :
310309 return logger .debug (
311310 'publicEncryptionKey length less than 64. Sanity check'
312311 ' failed.' )
313312 readPosition += 64
314313 # The data we'll store in the pubkeys table.
315314 dataToStore = data [20 :readPosition ]
316- sha = hashlib .new ('sha512' )
317- sha .update (
318- '\x04 ' + publicSigningKey + '\x04 ' + publicEncryptionKey )
319- ripe = RIPEMD160Hash (sha .digest ()).digest ()
315+ ripe = highlevelcrypto .to_ripe (pubSigningKey , pubEncryptionKey )
320316
321317 if logger .isEnabledFor (logging .DEBUG ):
322318 logger .debug (
323319 'within recpubkey, addressVersion: %s, streamNumber: %s'
324320 '\n ripe %s\n publicSigningKey in hex: %s'
325321 '\n publicEncryptionKey in hex: %s' ,
326322 addressVersion , streamNumber , hexlify (ripe ),
327- hexlify (publicSigningKey ), hexlify (publicEncryptionKey )
323+ hexlify (pubSigningKey ), hexlify (pubEncryptionKey )
328324 )
329325
330326 address = encodeAddress (addressVersion , streamNumber , ripe )
@@ -354,9 +350,9 @@ def processpubkey(self, data):
354350 ' Sanity check failed.' )
355351 return
356352 readPosition += 4
357- publicSigningKey = '\x04 ' + data [readPosition :readPosition + 64 ]
353+ pubSigningKey = '\x04 ' + data [readPosition :readPosition + 64 ]
358354 readPosition += 64
359- publicEncryptionKey = '\x04 ' + data [readPosition :readPosition + 64 ]
355+ pubEncryptionKey = '\x04 ' + data [readPosition :readPosition + 64 ]
360356 readPosition += 64
361357 specifiedNonceTrialsPerByteLength = decodeVarint (
362358 data [readPosition :readPosition + 10 ])[1 ]
@@ -373,23 +369,21 @@ def processpubkey(self, data):
373369 signature = data [readPosition :readPosition + signatureLength ]
374370 if highlevelcrypto .verify (
375371 data [8 :endOfSignedDataPosition ],
376- signature , hexlify (publicSigningKey )):
372+ signature , hexlify (pubSigningKey )):
377373 logger .debug ('ECDSA verify passed (within processpubkey)' )
378374 else :
379375 logger .warning ('ECDSA verify failed (within processpubkey)' )
380376 return
381377
382- sha = hashlib .new ('sha512' )
383- sha .update (publicSigningKey + publicEncryptionKey )
384- ripe = RIPEMD160Hash (sha .digest ()).digest ()
378+ ripe = highlevelcrypto .to_ripe (pubSigningKey , pubEncryptionKey )
385379
386380 if logger .isEnabledFor (logging .DEBUG ):
387381 logger .debug (
388382 'within recpubkey, addressVersion: %s, streamNumber: %s'
389383 '\n ripe %s\n publicSigningKey in hex: %s'
390384 '\n publicEncryptionKey in hex: %s' ,
391385 addressVersion , streamNumber , hexlify (ripe ),
392- hexlify (publicSigningKey ), hexlify (publicEncryptionKey )
386+ hexlify (pubSigningKey ), hexlify (pubEncryptionKey )
393387 )
394388
395389 address = encodeAddress (addressVersion , streamNumber , ripe )
@@ -588,9 +582,7 @@ def processmsg(self, data):
588582 sigHash = highlevelcrypto .double_sha512 (signature )[32 :]
589583
590584 # calculate the fromRipe.
591- sha = hashlib .new ('sha512' )
592- sha .update (pubSigningKey + pubEncryptionKey )
593- ripe = RIPEMD160Hash (sha .digest ()).digest ()
585+ ripe = highlevelcrypto .to_ripe (pubSigningKey , pubEncryptionKey )
594586 fromAddress = encodeAddress (
595587 sendersAddressVersionNumber , sendersStreamNumber , ripe )
596588
@@ -883,9 +875,8 @@ def processbroadcast(self, data):
883875 requiredPayloadLengthExtraBytes )
884876 endOfPubkeyPosition = readPosition
885877
886- sha = hashlib .new ('sha512' )
887- sha .update (sendersPubSigningKey + sendersPubEncryptionKey )
888- calculatedRipe = RIPEMD160Hash (sha .digest ()).digest ()
878+ calculatedRipe = highlevelcrypto .to_ripe (
879+ sendersPubSigningKey , sendersPubEncryptionKey )
889880
890881 if broadcastVersion == 4 :
891882 if toRipe != calculatedRipe :
0 commit comments