selftest: test des_crypt112 and fix (unused) decryption
authorIsaac Boukris <iboukris@gmail.com>
Tue, 19 Nov 2019 18:49:09 +0000 (19:49 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 10 Dec 2019 00:30:30 +0000 (00:30 +0000)
Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/auth/smbdes.c
libcli/auth/tests/test_gnutls.c

index 6d9a6dc2ce8a82176e1470db8c5708acddc4968f..59cb45d81f0355afd83dd903fb1ad9164c7ab89a 100644 (file)
@@ -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 */
index b1129db14c981cd2950bc07e84c9506d5d6ab281..4ae99b64c31b72c999788ab53f1bc56e25cda8ac 100644 (file)
@@ -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),
        };