@@ -432,6 +432,27 @@ def prompt_unicode_password(prompt, error_msg):
432
432
error_exit (error_msg )
433
433
return password
434
434
435
+ def _dispatch_to_cpu_or_gpu (wallet_instance , passwords ):
436
+ """Dispatches password verification to the appropriate CPU or GPU/OpenCL implementation."""
437
+ # Legacy GPU path for WalletBitcoinCore
438
+ if hasattr (wallet_instance , "_cl_devices" ):
439
+ return wallet_instance ._return_verified_password_or_false_gpu (passwords )
440
+
441
+ # Determine if OpenCL should be used
442
+ use_opencl = False
443
+ # The check for self.opencl is for BIP39, Cardano, Yoroi, Brainwallet
444
+ if hasattr (wallet_instance , 'opencl' ) and wallet_instance .opencl :
445
+ use_opencl = not isinstance (wallet_instance .opencl_algo , int )
446
+ # The check for just opencl_algo is for most other wallets
447
+ elif hasattr (wallet_instance , 'opencl_algo' ):
448
+ use_opencl = not isinstance (wallet_instance .opencl_algo , int )
449
+
450
+ if use_opencl :
451
+ return wallet_instance ._return_verified_password_or_false_opencl (passwords )
452
+ else :
453
+ return wallet_instance ._return_verified_password_or_false_cpu (passwords )
454
+
455
+
435
456
############### Bitcoin Core ###############
436
457
437
458
@register_wallet_class
@@ -582,14 +603,8 @@ def load_from_data_extract(cls, mkey_data):
582
603
def difficulty_info (self ):
583
604
return "{:,} SHA-512 iterations" .format (self ._iter_count )
584
605
585
- # Defer to either the cpu or OpenCL implementation
586
606
def return_verified_password_or_false (self , passwords ): # Bitcoin Core
587
- if hasattr (self , "_cl_devices" ):
588
- return self ._return_verified_password_or_false_gpu (passwords )
589
- elif not isinstance (self .opencl_algo ,int ):
590
- return self ._return_verified_password_or_false_opencl (passwords )
591
- else :
592
- return self ._return_verified_password_or_false_cpu (passwords )
607
+ return _dispatch_to_cpu_or_gpu (self , passwords )
593
608
594
609
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
595
610
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -930,11 +945,7 @@ def difficulty_info(self):
930
945
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
931
946
assert b"1" < b"9" < b"A" < b"Z" < b"a" < b"z" # the b58 check below assumes ASCII ordering in the interest of speed
932
947
def return_verified_password_or_false (self , orig_passwords ): # Multibit
933
- # Add OpenCL dispatch like other wallet types
934
- if not isinstance (self .opencl_algo , int ):
935
- return self ._return_verified_password_or_false_opencl (orig_passwords )
936
- else :
937
- return self ._return_verified_password_or_false_cpu (orig_passwords )
948
+ return _dispatch_to_cpu_or_gpu (self , orig_passwords )
938
949
939
950
def _return_verified_password_or_false_cpu (self , orig_passwords ): # Multibit
940
951
# Copy a few globals into local for a small speed boost
@@ -2057,8 +2068,7 @@ def difficulty_info(self):
2057
2068
return "1024 PBKDF2-SHA512 iterations + ECC"
2058
2069
2059
2070
def return_verified_password_or_false (self , passwords ): # Electrum28
2060
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo ,int )) \
2061
- else self ._return_verified_password_or_false_cpu (passwords )
2071
+ return _dispatch_to_cpu_or_gpu (self , passwords )
2062
2072
2063
2073
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
2064
2074
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -2417,8 +2427,7 @@ def check_blockchain_decrypted_block(self, unencrypted_block, password):
2417
2427
return False
2418
2428
2419
2429
def return_verified_password_or_false (self , passwords ): # Blockchain.com Main Password
2420
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo ,int )) \
2421
- else self ._return_verified_password_or_false_cpu (passwords )
2430
+ return _dispatch_to_cpu_or_gpu (self , passwords )
2422
2431
2423
2432
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
2424
2433
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -2676,8 +2685,7 @@ def difficulty_info(self):
2676
2685
return ("{:,}" .format (self ._iter_count ) if self ._iter_count else "1-10" ) + " SHA-256 iterations"
2677
2686
2678
2687
def return_verified_password_or_false (self , passwords ): # Blockchain.com second Password
2679
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo ,int )) \
2680
- else self ._return_verified_password_or_false_cpu (passwords )
2688
+ return _dispatch_to_cpu_or_gpu (self , passwords )
2681
2689
2682
2690
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
2683
2691
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -3155,8 +3163,7 @@ def check_decrypted_block(self, unencrypted_block, password):
3155
3163
return False
3156
3164
3157
3165
def return_verified_password_or_false (self , passwords ): # dogechain.info Main Password
3158
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo , int )) \
3159
- else self ._return_verified_password_or_false_cpu (passwords )
3166
+ return _dispatch_to_cpu_or_gpu (self , passwords )
3160
3167
3161
3168
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
3162
3169
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -3482,8 +3489,7 @@ def dump_wallet(self,key):
3482
3489
logfile .write (json .dumps (decrypted_vault_json ))
3483
3490
3484
3491
def return_verified_password_or_false (self , passwords ): # Metamask
3485
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo , int )) \
3486
- else self ._return_verified_password_or_false_cpu (passwords )
3492
+ return _dispatch_to_cpu_or_gpu (self , passwords )
3487
3493
3488
3494
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
3489
3495
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -3931,8 +3937,7 @@ def difficulty_info(self):
3931
3937
return "sCrypt N=14, r=8, p=8"
3932
3938
3933
3939
def return_verified_password_or_false (self , passwords ): # BIP38 Encrypted Private Keys
3934
- return self ._return_verified_password_or_false_opencl (passwords ) if (not isinstance (self .opencl_algo ,int )) \
3935
- else self ._return_verified_password_or_false_cpu (passwords )
3940
+ return _dispatch_to_cpu_or_gpu (self , passwords )
3936
3941
3937
3942
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
3938
3943
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -4065,8 +4070,7 @@ def difficulty_info(self):
4065
4070
return "2048 PBKDF2-SHA512 iterations + ECC"
4066
4071
4067
4072
def return_verified_password_or_false (self , mnemonic_ids_list ): # BIP39-Passphrase
4068
- return self ._return_verified_password_or_false_opencl (mnemonic_ids_list ) if (self .opencl and not isinstance (self .opencl_algo ,int )) \
4069
- else self ._return_verified_password_or_false_cpu (mnemonic_ids_list )
4073
+ return _dispatch_to_cpu_or_gpu (self , mnemonic_ids_list )
4070
4074
4071
4075
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
4072
4076
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -4252,8 +4256,7 @@ def difficulty_info(self):
4252
4256
return "40,000 PBKDF2-SHA256 iterations + ECC"
4253
4257
4254
4258
def return_verified_password_or_false (self , mnemonic_ids_list ): # BIP39-Passphrase
4255
- return self ._return_verified_password_or_false_opencl (mnemonic_ids_list ) if (self .opencl and not isinstance (self .opencl_algo ,int )) \
4256
- else self ._return_verified_password_or_false_cpu (mnemonic_ids_list )
4259
+ return _dispatch_to_cpu_or_gpu (self , mnemonic_ids_list )
4257
4260
4258
4261
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
4259
4262
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -4362,9 +4365,7 @@ def difficulty_info(self):
4362
4365
return "4096 PBKDF2-SHA512 iterations (2048 for Ledger)"
4363
4366
4364
4367
def return_verified_password_or_false (self , mnemonic_ids_list ): # BIP39-Passphrase
4365
- return self ._return_verified_password_or_false_opencl (mnemonic_ids_list ) if (
4366
- self .opencl and not isinstance (self .opencl_algo , int )) \
4367
- else self ._return_verified_password_or_false_cpu (mnemonic_ids_list )
4368
+ return _dispatch_to_cpu_or_gpu (self , mnemonic_ids_list )
4368
4369
4369
4370
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
4370
4371
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -4633,8 +4634,7 @@ def difficulty_info(self):
4633
4634
return "19162 PBKDF2-SHA512 iterations + ChaCha20_Poly1305"
4634
4635
4635
4636
def return_verified_password_or_false (self , mnemonic_ids_list ): # Yoroi Cadano Wallet
4636
- return self ._return_verified_password_or_false_opencl (mnemonic_ids_list ) if (self .opencl and not isinstance (self .opencl_algo ,int )) \
4637
- else self ._return_verified_password_or_false_cpu (mnemonic_ids_list )
4637
+ return _dispatch_to_cpu_or_gpu (self , mnemonic_ids_list )
4638
4638
4639
4639
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
4640
4640
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
@@ -4783,8 +4783,7 @@ def difficulty_info(self):
4783
4783
return "1 SHA-256 iteration"
4784
4784
4785
4785
def return_verified_password_or_false (self , password_list ): # Brainwallet
4786
- return self ._return_verified_password_or_false_opencl (password_list ) if (self .opencl and not isinstance (self .opencl_algo ,int )) \
4787
- else self ._return_verified_password_or_false_cpu (password_list )
4786
+ return _dispatch_to_cpu_or_gpu (self , password_list )
4788
4787
4789
4788
# This is the time-consuming function executed by worker thread(s). It returns a tuple: if a password
4790
4789
# is correct return it, else return False for item 0; return a count of passwords checked for item 1
0 commit comments