c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen * NTLM and NTLMv2 hash generation.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen * Copyright (c) 2004 Andrey Panin <pazke@donpac.ru>
e074ffeaee1ce283bd42f167c6810e3d013f8218Timo Sirainen * This software is released under the MIT license.
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenstatic unsigned char *
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainent_unicode_str(const char *src, bool ucase, size_t *size)
4b058f90f9e8a2c6b2eed275de4eb8cc5195a71dTimo Sirainen wstr = buffer_create_dynamic(unsafe_data_stack_pool, 32);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen buffer_append_c(wstr, ucase ? i_toupper(*src) : *src);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenvoid lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE])
d43c646d4b84635aa795946555be04a553d5413aTimo Sirainen static const unsigned char lm_magic[8] = "KGS!@#$%";
d43c646d4b84635aa795946555be04a553d5413aTimo Sirainen unsigned int i;
971deedd546f4cb3abb2e3a67d273cc8e214a3c3Timo Sirainen strncpy((char *)buffer, passwd, sizeof(buffer));
d43c646d4b84635aa795946555be04a553d5413aTimo Sirainen for (i = 0; i < sizeof(buffer); i++)
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenvoid ntlm_v1_hash(const char *passwd, unsigned char hash[NTLMSSP_HASH_SIZE])
4cc046655697b1b387fd10ccc7aa821e43495a1eTimo Sirainen void *wpwd = t_unicode_str(passwd, FALSE, &len);
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitzhmac_md5_ucs2le_string_ucase(struct hmac_context *ctx, const char *str)
4cc046655697b1b387fd10ccc7aa821e43495a1eTimo Sirainen unsigned char *wstr = t_unicode_str(str, TRUE, &len);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenntlm_v2_hash(const char *user, const char *target,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen const unsigned char *hash_v1,
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz hmac_init(&ctx, hash_v1, NTLMSSP_HASH_SIZE, &hash_method_md5);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen const unsigned char *challenge,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen unsigned char response[NTLMSSP_RESPONSE_SIZE])
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen unsigned char des_hash[NTLMSSP_DES_KEY_LENGTH * 3];
7d85c4e4e727a48ba7f6d6e6522de8338240ad74Timo Sirainen deshash(response + 8, des_hash + 7, challenge);
7d85c4e4e727a48ba7f6d6e6522de8338240ad74Timo Sirainen deshash(response + 16, des_hash + 14, challenge);
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen const unsigned char *server_challenge,
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen const unsigned char *client_challenge,
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen unsigned char response[NTLMSSP_RESPONSE_SIZE])
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen md5_update(&ctx, server_challenge, NTLMSSP_CHALLENGE_SIZE);
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen md5_update(&ctx, client_challenge, NTLMSSP_CHALLENGE_SIZE);
88c2db95c4a0f8f7986a63cd57cf4b6850d76543Timo Sirainen ntlmssp_v1_response(hash, session_hash, response);
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainenntlmssp_v2_response(const char *user, const char *target,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen const unsigned char *hash_v1,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen const unsigned char *challenge,
c7480644202e5451fbed448508ea29a25cffc99cTimo Sirainen unsigned char response[NTLMSSP_V2_RESPONSE_SIZE])
0a3769a4ef3afbbbd05df38f43ec7382fd65a2b6Florian Zeitz hmac_init(&ctx, hash, NTLMSSP_V2_HASH_SIZE, &hash_method_md5);