diff options
author | Isaac Boukris <iboukris@gmail.com> | 2019-11-19 19:49:09 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2019-12-10 00:30:30 +0000 |
commit | 394debac6b2f0838cde5d850335e0cdff14b411d (patch) | |
tree | 2685b924db2f5f87ac1f54beff8e91ba60e0dad0 /libcli | |
parent | e2f8f686d1e3fce91f10aadb9667854cf2a1219a (diff) | |
download | samba-394debac6b2f0838cde5d850335e0cdff14b411d.tar.gz |
selftest: test des_crypt112 and fix (unused) decryption
Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r-- | libcli/auth/smbdes.c | 9 | ||||
-rw-r--r-- | libcli/auth/tests/test_gnutls.c | 24 |
2 files changed, 31 insertions, 2 deletions
diff --git a/libcli/auth/smbdes.c b/libcli/auth/smbdes.c index 6d9a6dc2ce8..59cb45d81f0 100644 --- a/libcli/auth/smbdes.c +++ b/libcli/auth/smbdes.c @@ -342,8 +342,13 @@ void des_crypt128(uint8_t out[8], const uint8_t in[8], const uint8_t key[16]) void des_crypt112(uint8_t out[8], const uint8_t in[8], const uint8_t key[14], int forw) { uint8_t buf[8]; - des_crypt56(buf, in, key, forw); - des_crypt56(out, buf, key+7, forw); + if (forw) { + des_crypt56(buf, in, key, forw); + des_crypt56(out, buf, key+7, forw); + } else { + des_crypt56(buf, in, key+7, forw); + des_crypt56(out, buf, key, forw); + } } /* des encryption of a 16 byte lump of data with a 112 bit key */ diff --git a/libcli/auth/tests/test_gnutls.c b/libcli/auth/tests/test_gnutls.c index b1129db14c9..4ae99b64c31 100644 --- a/libcli/auth/tests/test_gnutls.c +++ b/libcli/auth/tests/test_gnutls.c @@ -351,6 +351,29 @@ static void torture_gnutls_des_crypt128(void **state) assert_memory_equal(crypt, crypt_expected, 8); } +static void torture_gnutls_des_crypt112(void **state) +{ + static uint8_t key[14] = { + 0x98, 0xFD, 0xCB, 0x3A, 0xF7, 0xB5, 0x1C, 0xF8, + 0x88, 0x96, 0x8E, 0xB5, 0x3A, 0x24 + }; + static const uint8_t clear[8] = { + 0x2F, 0x49, 0x5B, 0x20, 0xD7, 0x84, 0xC2, 0x34 + }; + static const uint8_t crypt_expected[8] = { + 0x87, 0x35, 0xFA, 0xA4, 0x5D, 0x7A, 0xA5, 0x05 + }; + + uint8_t crypt[8]; + uint8_t decrypt[8]; + + des_crypt112(crypt, clear, key, 1); + assert_memory_equal(crypt, crypt_expected, 8); + + des_crypt112(decrypt, crypt, key, 0); + assert_memory_equal(decrypt, clear, 8); +} + static void torture_gnutls_sam_rid_crypt(void **state) { static const uint8_t clear[16] = { @@ -384,6 +407,7 @@ int main(int argc, char *argv[]) cmocka_unit_test(torture_gnutls_SMBOWFencrypt), cmocka_unit_test(torture_gnutls_E_old_pw_hash), cmocka_unit_test(torture_gnutls_des_crypt128), + cmocka_unit_test(torture_gnutls_des_crypt112), cmocka_unit_test(torture_gnutls_sam_rid_crypt), }; |