1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 07:18:09 +00:00

tools: fix computation of header fingerprint in binctl tool

This commit is contained in:
Pavol Rusnak 2018-01-08 22:40:00 +01:00
parent 6ac59f426f
commit f806488536
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -54,9 +54,6 @@ class BinImage(object):
assert self.reserved2 == 415 * b'\x00' assert self.reserved2 == 415 * b'\x00'
self.code = data[self.hdrlen:] self.code = data[self.hdrlen:]
assert len(self.code) == self.codelen assert len(self.code) == self.codelen
h = pyblake2.blake2s(data[:IMAGE_HEADER_SIZE - 65])
h.update(b'\x00' * 65)
self.fingerprint = h.hexdigest()
def print(self): def print(self):
if self.magic == b'TRZF': if self.magic == b'TRZF':
@ -79,7 +76,7 @@ class BinImage(object):
print(' * sigmask :', format_sigmask(self.sigmask)) print(' * sigmask :', format_sigmask(self.sigmask))
print(' * sig :', binascii.hexlify(self.sig).decode()) print(' * sig :', binascii.hexlify(self.sig).decode())
print(' * total : %d bytes' % total_len) print(' * total : %d bytes' % total_len)
print(' * fngprnt :', self.fingerprint) print(' * fngprnt :', self.fingerprint())
print() print()
def compute_hashes(self): def compute_hashes(self):
@ -120,6 +117,9 @@ class BinImage(object):
assert len(header) == self.hdrlen assert len(header) == self.hdrlen
return header return header
def fingerprint(self):
return pyblake2.blake2s(self.serialize_header(False)).hexdigest()
def sign(self, sigmask, signature): def sign(self, sigmask, signature):
header = self.serialize_header(sig=False) header = self.serialize_header(sig=False)
data = header + self.code data = header + self.code