diff options
author | Jack Lloyd <[email protected]> | 2019-04-19 07:20:22 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-04-19 12:05:33 -0400 |
commit | 9cb410bf050b56726dbe2f69c43c373a9a3ddf04 (patch) | |
tree | 21e8cebecef303ba3f760c7803fd8ab0f92588dd /src | |
parent | e21bddd79357f2ad8576fd871d387b722192b847 (diff) |
Add support for NIST key wrap in Python
Diffstat (limited to 'src')
-rwxr-xr-x | src/python/botan2.py | 12 | ||||
-rw-r--r-- | src/scripts/test_python.py | 11 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 82eebe576..563638ebf 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -1261,6 +1261,18 @@ class HOTP(object): else: return (False, counter) +def nist_key_wrap(kek, key): + output = create_string_buffer(len(key) + 8) + out_len = c_size_t(len(output)) + _DLL.botan_key_wrap3394(key, len(key), kek, len(kek), output, byref(out_len)) + return output[0:out_len.value] + +def nist_key_unwrap(kek, wrapped): + output = create_string_buffer(len(wrapped)) + out_len = c_size_t(len(output)) + _DLL.botan_key_unwrap3394(wrapped, len(wrapped), kek, len(kek), output, byref(out_len)) + return output[0:out_len.value] + # Typedefs for compat with older versions # Will be removed in a future major release cipher = SymmetricCipher # pylint: disable=invalid-name diff --git a/src/scripts/test_python.py b/src/scripts/test_python.py index b6e8ca9d6..286b29edd 100644 --- a/src/scripts/test_python.py +++ b/src/scripts/test_python.py @@ -397,6 +397,17 @@ ofvkP1EDmpx50fHLawIDAQAB self.assertEqual(value, ptext) + def test_keywrap(self): + key = hex_decode('00112233445566778899aabbccddeeff') + kek = hex_decode('000102030405060708090a0b0c0d0e0f') + + wrapped = botan2.nist_key_wrap(kek, key) + self.assertEqual(hex_encode(wrapped), '1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5') + + self.assertEqual(len(wrapped), 16+8) + unwrapped = botan2.nist_key_unwrap(kek, wrapped) + self.assertEqual(hex_encode(unwrapped), '00112233445566778899aabbccddeeff') + def test_hotp(self): hotp = botan2.HOTP(b'12345678901234567890') |