From ed4c22473f5fb07006e773137ed047950e25a4d8 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 26 May 2020 15:18:19 -0400 Subject: Wow, python-version-independent hexadecimal is painful --- cryptech_backup | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cryptech_backup') diff --git a/cryptech_backup b/cryptech_backup index be70f8b..1f6f3d1 100755 --- a/cryptech_backup +++ b/cryptech_backup @@ -52,6 +52,7 @@ import base64 import struct import getpass import argparse +import binascii from cryptech.libhal import * @@ -361,14 +362,15 @@ class AESKeyWrapWithPadding(object): R[0], R[i] = self._decrypt(R[0], R[i]) magic, m = struct.unpack(">LL", R[0]) if magic != 0xa65959a6: - raise self.UnwrapError("Magic value in AIV should have been 0xa65959a6, was 0x{:02x}" - .format(magic)) + raise self.UnwrapError("Magic value in AIV should have been 0xa65959a6, was 0x{:08x}" + .format(magic)) if m <= 8 * (n - 1) or m > 8 * n: raise self.UnwrapError("Length encoded in AIV out of range: m {}, n {}".format(m, n)) R = b"".join(R[1:]) assert len(R) == 8 * n if any(r != b"\x00" for r in R[m:]): - raise self.UnwrapError("Nonzero trailing bytes {}".format(R[m:].encode("hex"))) + raise self.UnwrapError("Nonzero trailing bytes {}".format( + binascii.hexlify(R[m:]).decode("ascii"))) return R[:m] -- cgit v1.2.3