/* * sam_oem_password * * Generate an OEM password. */ int sam_oem_password(oem_password_t *oem_password, unsigned char *new_password, unsigned char *old_password) { smb_wchar_t *unicode_password; int length; #ifdef PBSHORTCUT assert(sizeof (oem_password_t) == SAM_PASSWORD_516); #endif /* PBSHORTCUT */ length = strlen((char const *)new_password); unicode_password = alloca((length + 1) * sizeof (smb_wchar_t)); length = smb_auth_qnd_unicode((unsigned short *)unicode_password, (char *)new_password, length); oem_password->length = length; (void) memcpy(&oem_password->data[512 - length], unicode_password, length); rand_hash((unsigned char *)oem_password, sizeof (oem_password_t), old_password, SAM_KEYLEN); return (0); }
/* * smb_auth_ntlm_hash * * Make NTLM Hash (using MD4) from the given password. * The result will contain a 16-byte NTLM hash. */ int smb_auth_ntlm_hash(const char *password, unsigned char *hash) { smb_wchar_t *unicode_password; int length, unicode_len; int rc; if (password == NULL || hash == NULL) return (SMBAUTH_FAILURE); length = strlen(password); unicode_len = (length + 1) * sizeof (smb_wchar_t); unicode_password = malloc(unicode_len); if (unicode_password == NULL) return (SMBAUTH_FAILURE); length = smb_auth_qnd_unicode(unicode_password, password, length); rc = smb_auth_md4(hash, (unsigned char *)unicode_password, length); (void) memset(unicode_password, 0, unicode_len); free(unicode_password); return (rc); }
/* * smb_auth_ntlmv2_hash * * The NTLM v2 hash will be created from the given NTLM hash, username, * and the NETBIOS name of the domain. * * The NTLMv2 hash will be returned via the ntlmv2_hash parameter which * will be used in the calculation of the NTLMv2 and LMv2 responses. */ int smb_auth_ntlmv2_hash(unsigned char *ntlm_hash, char *username, char *ntdomain, unsigned char *ntlmv2_hash) { smb_wchar_t *data; int data_len; unsigned char *buf; int rc; if (username == NULL || ntdomain == NULL) return (SMBAUTH_FAILURE); (void) smb_strupr(username); data_len = strlen(username) + strlen(ntdomain); buf = (unsigned char *)malloc((data_len + 1) * sizeof (char)); if (buf == NULL) return (SMBAUTH_FAILURE); (void) snprintf((char *)buf, data_len + 1, "%s%s", username, ntdomain); data = (smb_wchar_t *)malloc((data_len + 1) * sizeof (smb_wchar_t)); if (data == NULL) { free(buf); return (SMBAUTH_FAILURE); } data_len = smb_auth_qnd_unicode(data, (char *)buf, data_len); rc = SMBAUTH_HMACT64((unsigned char *)data, data_len, ntlm_hash, SMBAUTH_HASH_SZ, ntlmv2_hash); free(buf); free(data); return (rc); }