28
28
encodeAddress , encodeVarint , varintDecodeError
29
29
)
30
30
from bmconfigparser import config
31
- from fallback import RIPEMD160Hash
32
31
from helper_sql import (
33
32
sql_ready , sql_timeout , SqlBulkExecute , sqlExecute , sqlQuery )
34
33
from network import knownnodes
@@ -300,31 +299,28 @@ def processpubkey(self, data):
300
299
'(within processpubkey) payloadLength less than 146.'
301
300
' Sanity check failed.' )
302
301
readPosition += 4
303
- publicSigningKey = data [readPosition :readPosition + 64 ]
302
+ pubSigningKey = ' \x04 ' + data [readPosition :readPosition + 64 ]
304
303
# Is it possible for a public key to be invalid such that trying to
305
304
# encrypt or sign with it will cause an error? If it is, it would
306
305
# be easiest to test them here.
307
306
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 :
310
309
return logger .debug (
311
310
'publicEncryptionKey length less than 64. Sanity check'
312
311
' failed.' )
313
312
readPosition += 64
314
313
# The data we'll store in the pubkeys table.
315
314
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 )
320
316
321
317
if logger .isEnabledFor (logging .DEBUG ):
322
318
logger .debug (
323
319
'within recpubkey, addressVersion: %s, streamNumber: %s'
324
320
'\n ripe %s\n publicSigningKey in hex: %s'
325
321
'\n publicEncryptionKey in hex: %s' ,
326
322
addressVersion , streamNumber , hexlify (ripe ),
327
- hexlify (publicSigningKey ), hexlify (publicEncryptionKey )
323
+ hexlify (pubSigningKey ), hexlify (pubEncryptionKey )
328
324
)
329
325
330
326
address = encodeAddress (addressVersion , streamNumber , ripe )
@@ -354,9 +350,9 @@ def processpubkey(self, data):
354
350
' Sanity check failed.' )
355
351
return
356
352
readPosition += 4
357
- publicSigningKey = '\x04 ' + data [readPosition :readPosition + 64 ]
353
+ pubSigningKey = '\x04 ' + data [readPosition :readPosition + 64 ]
358
354
readPosition += 64
359
- publicEncryptionKey = '\x04 ' + data [readPosition :readPosition + 64 ]
355
+ pubEncryptionKey = '\x04 ' + data [readPosition :readPosition + 64 ]
360
356
readPosition += 64
361
357
specifiedNonceTrialsPerByteLength = decodeVarint (
362
358
data [readPosition :readPosition + 10 ])[1 ]
@@ -373,23 +369,21 @@ def processpubkey(self, data):
373
369
signature = data [readPosition :readPosition + signatureLength ]
374
370
if highlevelcrypto .verify (
375
371
data [8 :endOfSignedDataPosition ],
376
- signature , hexlify (publicSigningKey )):
372
+ signature , hexlify (pubSigningKey )):
377
373
logger .debug ('ECDSA verify passed (within processpubkey)' )
378
374
else :
379
375
logger .warning ('ECDSA verify failed (within processpubkey)' )
380
376
return
381
377
382
- sha = hashlib .new ('sha512' )
383
- sha .update (publicSigningKey + publicEncryptionKey )
384
- ripe = RIPEMD160Hash (sha .digest ()).digest ()
378
+ ripe = highlevelcrypto .to_ripe (pubSigningKey , pubEncryptionKey )
385
379
386
380
if logger .isEnabledFor (logging .DEBUG ):
387
381
logger .debug (
388
382
'within recpubkey, addressVersion: %s, streamNumber: %s'
389
383
'\n ripe %s\n publicSigningKey in hex: %s'
390
384
'\n publicEncryptionKey in hex: %s' ,
391
385
addressVersion , streamNumber , hexlify (ripe ),
392
- hexlify (publicSigningKey ), hexlify (publicEncryptionKey )
386
+ hexlify (pubSigningKey ), hexlify (pubEncryptionKey )
393
387
)
394
388
395
389
address = encodeAddress (addressVersion , streamNumber , ripe )
@@ -588,9 +582,7 @@ def processmsg(self, data):
588
582
sigHash = highlevelcrypto .double_sha512 (signature )[32 :]
589
583
590
584
# 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 )
594
586
fromAddress = encodeAddress (
595
587
sendersAddressVersionNumber , sendersStreamNumber , ripe )
596
588
@@ -883,9 +875,8 @@ def processbroadcast(self, data):
883
875
requiredPayloadLengthExtraBytes )
884
876
endOfPubkeyPosition = readPosition
885
877
886
- sha = hashlib .new ('sha512' )
887
- sha .update (sendersPubSigningKey + sendersPubEncryptionKey )
888
- calculatedRipe = RIPEMD160Hash (sha .digest ()).digest ()
878
+ calculatedRipe = highlevelcrypto .to_ripe (
879
+ sendersPubSigningKey , sendersPubEncryptionKey )
889
880
890
881
if broadcastVersion == 4 :
891
882
if toRipe != calculatedRipe :
0 commit comments