2 Unix SMB/CIFS implementation.
3 Wrapper for gnutls hash and encryption functions
5 Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009-2019
7 Copyright (c) Andreas Schneider <asn@samba.org> 2019
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * This (arcfour over data with a key combined from two imputs, one
26 * the key another the confounder), is a common pattern in pre-AES
27 * windows cryptography
29 * Some protocols put the confounder first, others second so both
30 * parameters are named key_input here.
35 #include "lib/util/data_blob.h"
36 #include <gnutls/gnutls.h>
37 #include <gnutls/crypto.h>
38 #include "gnutls_helpers.h"
39 #include "lib/util/memory.h"
41 int samba_gnutls_arcfour_confounded_md5(const DATA_BLOB
*key_input1
,
42 const DATA_BLOB
*key_input2
,
44 enum samba_gnutls_direction encrypt
)
47 gnutls_hash_hd_t hash_hnd
= NULL
;
48 uint8_t confounded_key
[16];
49 gnutls_cipher_hd_t cipher_hnd
= NULL
;
50 gnutls_datum_t confounded_key_datum
= {
51 .data
= confounded_key
,
52 .size
= sizeof(confounded_key
),
55 rc
= gnutls_hash_init(&hash_hnd
, GNUTLS_DIG_MD5
);
59 rc
= gnutls_hash(hash_hnd
, key_input1
->data
, key_input1
->length
);
61 gnutls_hash_deinit(hash_hnd
, NULL
);
64 rc
= gnutls_hash(hash_hnd
, key_input2
->data
, key_input2
->length
);
66 gnutls_hash_deinit(hash_hnd
, NULL
);
70 gnutls_hash_deinit(hash_hnd
, confounded_key
);
72 rc
= gnutls_cipher_init(&cipher_hnd
,
73 GNUTLS_CIPHER_ARCFOUR_128
,
74 &confounded_key_datum
,
80 if (encrypt
== SAMBA_GNUTLS_ENCRYPT
) {
81 rc
= gnutls_cipher_encrypt(cipher_hnd
,
85 rc
= gnutls_cipher_decrypt(cipher_hnd
,
89 gnutls_cipher_deinit(cipher_hnd
);
90 ZERO_ARRAY(confounded_key
);