From 86a438f988094007cf9ee0832dde823a4ebcba36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Stro=CC=88mbergson?= Date: Tue, 3 Jul 2018 10:12:29 +0200 Subject: Adding a lot of verbose output to get the internal values we need. --- src/model/aes_keywrap.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/model/aes_keywrap.py b/src/model/aes_keywrap.py index ef83baa..8b9d2b0 100755 --- a/src/model/aes_keywrap.py +++ b/src/model/aes_keywrap.py @@ -118,23 +118,45 @@ class AESKeyWrapWithPadding(object): else: # RFC 3394 section 2.2.1 + if verbose: + print("") + print("Number of blocks to wrap: %d" % (n - 1)) + print("Blocks before wrap:") + for i in self._start_stop(1, n): + print("R[%d] = %s" % (i, self.bin2hex(R[i]))) + print("A before wrap: %s" % (self.bin2hex(R[0]))) + print("") + + for j in self._start_stop(0, 5): for i in self._start_stop(1, n): if verbose: + print("") print("Iteration %d, %d" % (j, i)) if verbose: - print("Before encrypt: R[0] = %s R[i] = %s" % (self.bin2hex(R[0]), self.bin2hex(R[i]))) + print("Before encrypt: R[0] = %s R[%d] = %s" % (self.bin2hex(R[0]), i, self.bin2hex(R[i]))) R[0], R[i] = self._encrypt(R[0], R[i]) if verbose: - print("After encrypt: R[0] = %s R[i] = %s" % (self.bin2hex(R[0]), self.bin2hex(R[i]))) + print("After encrypt: R[0] = %s R[%d] = %s" % (self.bin2hex(R[0]), i, self.bin2hex(R[i]))) W0, W1 = unpack(">LL", R[0]) xorval = n * j + i W1 ^= xorval R[0] = pack(">LL", W0, W1) + if verbose: + print("xorval = 0x%016x" % (xorval)) + + if verbose: + print("") + print("Blocks after wrap:") + for i in self._start_stop(1, n): + print("R[%d] = %s" % (i, self.bin2hex(R[i]))) + print("A after wrap: %s" % (self.bin2hex(R[0]))) + print("") + assert len(R) == (n + 1) and all(len(r) == 8 for r in R) return "".join(R) @@ -211,6 +233,9 @@ if __name__ == "__main__": Q = self.hex2bin(Q) C = self.hex2bin(C) c = K.wrap_key(Q) + if verbose: + print("Wrapped result: %s" % (self.bin2hex(c))) + q = K.unwrap_key(C) self.assertEqual(q, Q, "Input and output plaintext did not match: {} <> {}".format(self.bin2hex(Q), self.bin2hex(q))) self.assertEqual(c, C, "Input and output ciphertext did not match: {} <> {}".format(self.bin2hex(C), self.bin2hex(c))) -- cgit v1.2.3