samba/SOURCES/0170-selftest-test-des_crypt112-and-fix-unused-decryption.patch
2021-10-08 16:37:00 +00:00

80 lines
2.5 KiB
Diff

From bd993cbccae8002dd3125d015c6525060fd8914e Mon Sep 17 00:00:00 2001
From: Isaac Boukris <iboukris@gmail.com>
Date: Tue, 19 Nov 2019 19:49:09 +0100
Subject: [PATCH 170/187] selftest: test des_crypt112 and fix (unused)
decryption
Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 394debac6b2f0838cde5d850335e0cdff14b411d)
---
libcli/auth/smbdes.c | 9 +++++++--
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),
};
--
2.23.0