update to python class

This commit is contained in:
bsdevlin 2019-04-10 17:52:02 -04:00
parent c3e67f6824
commit 8c62d6144d
1 changed files with 19 additions and 4 deletions

View File

@ -16,9 +16,11 @@ class zcash_fpga:
fpga_msg_type_dict = {'FPGA_IGNORE_RPL':int('80000002', 16),
'FPGA_STATUS_RPL':int('80000001', 16),
'RESET_FPGA_RPL':int('80000000', 16)}
'RESET_FPGA_RPL':int('80000000', 16),
'VERIFY_SECP256K1_SIG_RPL':int('80000101', 16)}
fpga_msg_dict = {fpga_msg_type_dict['FPGA_IGNORE_RPL']:{'name':'FPGA_IGNORE_RPL', 'feilds':[(8, 'ignored_header', byt_to_hex)]},
fpga_msg_dict = {fpga_msg_type_dict['VERIFY_SECP256K1_SIG_RPL']:{'name':'FPGA_IGNORE_RPL', 'feilds':[(8, 'index', byt_to_hex), (1, 'bm', byt_to_hex)]},
fpga_msg_type_dict['FPGA_IGNORE_RPL']:{'name':'FPGA_IGNORE_RPL', 'feilds':[(8, 'ignored_header', byt_to_hex)]},
fpga_msg_type_dict['FPGA_STATUS_RPL']:{'name':'FPGA_STATUS_RPL', 'feilds':[(4, 'version', byt_to_ver), (8, 'build_date', byt_to_str), (8, 'buid_host', byt_to_str), (8, 'cmd_cap', byt_to_hex)]},
fpga_msg_type_dict['RESET_FPGA_RPL']:{'name':'RESET_FPGA_RPL', 'feilds':[]}}
@ -46,7 +48,20 @@ class zcash_fpga:
res = self.s.read(1024)
self.print_reply(res)
return res
def secp256k1_verify_sig(self, index, hsh, r, s, Qx, Qy):
cmd = 'B000000001010000'
cmd += format(index, 'x').ljust(16, '0')
cmd += format(s, 'x').ljust(64, '0')
cmd += format(r, 'x').ljust(64, '0')
cmd += format(hsh, 'x').ljust(64, '0')
cmd += format(Qx, 'x').ljust(64, '0')
cmd += format(Qy, 'x').ljust(64, '0')
self.s.write(self.codecs.decode(cmd, 'hex'))
res = self.get_reply()
if (self.struct.unpack('<I', res[4:8])[0] != self.fpga_msg_type_dict['VERIFY_SECP256K1_SIG_RPL']):
print("ERROR: Reply type was not VERIFY_SECP256K1_SIG_RPL")
def close(self):
self.s.close()
print("Closed...")
@ -71,7 +86,7 @@ class zcash_fpga:
#Example usage:
zf = zcash_fpga()
zf.reset_fpga()
zf.secp256k1_verify_sig(1, 1, 1, 1, 1, 1)
zf.close()