ntlm_core(3)
๐ ntlm_core(3) โ the Heimdal NTLM library, bestie edition ๐
okay so you found your way into the Heimdal ntlm library manual page and honestly? iconic. this is ntlm_core(3), which means section 3, which means it's a library page, which means we're talking about functions you call, not some command you type into a shell. buckle up. ๐
โจ NAME โจ
ntlm_core โ the Heimdal NTLM library ๐ฆ
๐ธ SYNOPSIS ๐ธ
๐ซถ Functions
here's the whole friend group. every single one of them, exactly as they show up in the header, no cap:
void heim_ntlm_free_buf (struct ntlm_buf *p)
void heim_ntlm_free_targetinfo (struct ntlm_targetinfo *ti)
int heim_ntlm_encode_targetinfo (const struct ntlm_targetinfo *ti, int ucs2, struct ntlm_buf *data)
int heim_ntlm_decode_targetinfo (const struct ntlm_buf *data, int ucs2, struct ntlm_targetinfo *ti)
void heim_ntlm_free_type1 (struct ntlm_type1 *data)
int heim_ntlm_encode_type1 (const struct ntlm_type1 *type1, struct ntlm_buf *data)
void heim_ntlm_free_type2 (struct ntlm_type2 *data)
int heim_ntlm_encode_type2 (const struct ntlm_type2 *type2, struct ntlm_buf *data)
void heim_ntlm_free_type3 (struct ntlm_type3 *data)
int heim_ntlm_encode_type3 (const struct ntlm_type3 *type3, struct ntlm_buf *data, size_t *mic_offset)
int heim_ntlm_nt_key (const char *password, struct ntlm_buf *key)
int heim_ntlm_calculate_ntlm1 (void *key, size_t len, unsigned char challenge[8], struct ntlm_buf *answer)
int heim_ntlm_build_ntlm1_master (void *key, size_t len, struct ntlm_buf *session, struct ntlm_buf *master)
int heim_ntlm_build_ntlm2_master (void *key, size_t len, struct ntlm_buf *blob, struct ntlm_buf *session, struct ntlm_buf *master)
int heim_ntlm_keyex_unwrap (struct ntlm_buf *baseKey, struct ntlm_buf *encryptedSession, struct ntlm_buf *session)
int heim_ntlm_ntlmv2_key (const void *key, size_t len, const char *username, const char *target, int upper_case_target, unsigned char ntlmv2[16])
int heim_ntlm_calculate_lm2 (const void *key, size_t len, const char *username, const char *target, const unsigned char serverchallenge[8], unsigned char ntlmv2[16], struct ntlm_buf *answer)
int heim_ntlm_calculate_ntlm2 (const void *key, size_t len, const char *username, const char *target, const unsigned char serverchallenge[8], const struct ntlm_buf *infotarget, unsigned char ntlmv2[16], struct ntlm_buf *answer)
int heim_ntlm_verify_ntlm2 (const void *key, size_t len, const char *username, const char *target, time_t now, const unsigned char serverchallenge[8], const struct ntlm_buf *answer, struct ntlm_buf *infotarget, unsigned char ntlmv2[16])
the way that there are eighteen of them and they all start with heim_ntlm_... yes. that's the naming convention. it's giving consistency. we love that for us. ๐
๐ Detailed Description ๐
so what do all these functions actually do, you ask? here's the vibe:
the NTLM core functions implement:
- the string2key generation function ๐
- the message encode and decode function โ๏ธ
- and the hash function functions ๐งฎ
that's it. that's the whole scope. keys get made, messages get encoded and decoded, hashes get hashed. main character energy across the board โจ
ngl this page is long โ we're splitting it up, so this is part 1. more is coming, don't go anywhere bestie ๐ซถ
๐ Function Documentation ๐
okay bestie, deep breath, this is the big one ๐ โ every single function in this library, one by one, no skipping. Grab a snack ๐, we're going through all of them.
๐ฆ heim_ntlm_build_ntlm1_master
int heim_ntlm_build_ntlm1_master (void * key, size_t len, struct ntlm_buf * session, struct ntlm_buf * master)
Generates an NTLMv1 session random together with its associated session master key. They come as a matching set, like you and your emotional support playlist ๐.
Parameters
keyโ the ntlm v1 keylenโ length of keysessionโ the generated session nonce. Free it withheim_ntlm_free_buf()when you're done, bestie, don't just leave it lying around ๐masterโ the calculated session master key. Also freed withheim_ntlm_free_buf().
Returns
0 on success, periodt ๐. Otherwise you get an error, and it hands you an errno telling you what went wrong.
๐ฆ heim_ntlm_build_ntlm2_master
int heim_ntlm_build_ntlm2_master (void * key, size_t len, struct ntlm_buf * blob, struct ntlm_buf * session, struct ntlm_buf * master)
Same energy as the one above, but NTLMv2 โจ. Generates an NTLMv2 session random with its associated session master key.
Parameters
keyโ the NTLMv2 keylenโ length of keyblobโ the NTLMv2 'blob'sessionโ the generated session nonce, freed withheim_ntlm_free_buf().masterโ the calculated session master key, freed withheim_ntlm_free_buf().
Returns
0 = success ๐
. Not 0 = an error, with an errno for what went wrong.
๐ธ heim_ntlm_calculate_lm2
int heim_ntlm_calculate_lm2 (const void * key, size_t len, const char * username, const char * target, const unsigned char serverchallenge[8], unsigned char ntlmv2[16], struct ntlm_buf * answer)
Calculates the LMv2 response. That's literally it, that's the whole job ๐ซถ.
Parameters
keyโ the ntlm keylenโ length of keyusernameโ name of the user, as sent in the message, assumed to be in UTF8.targetโ the name of the target, assumed to be in UTF8.serverchallengeโ challenge as sent by the server in the type2 message.ntlmv2โ calculated session keyanswerโ ntlm response answer, should be freed withheim_ntlm_free_buf().
Returns
0 on success โจ. Otherwise, an error, and an errno explaining what went wrong.
๐ธ heim_ntlm_calculate_ntlm1
int heim_ntlm_calculate_ntlm1 (void * key, size_t len, unsigned char challenge[8], struct ntlm_buf * answer)
Calculates the NTLMv1 response hash. Iconic, vintage, we love her ๐.
Parameters
keyโ the ntlm v1 keylenโ length of keychallengeโ sent by the serveranswerโ calculated answer, should be freed withheim_ntlm_free_buf().
Returns
0 if it slayed โ
. Otherwise an error, with an errno for what went wrong.
Examples
test_ntlm.c.
๐ธ heim_ntlm_calculate_ntlm2
int heim_ntlm_calculate_ntlm2 (const void * key, size_t len, const char * username, const char * target, const unsigned char serverchallenge[8], const struct ntlm_buf * infotarget, unsigned char ntlmv2[16], struct ntlm_buf * answer)
Calculates the NTLMv2 response โ the glow-up version ๐.
Parameters
keyโ the ntlm keylenโ length of keyusernameโ name of the user, as sent in the message, assumed to be in UTF8.targetโ the name of the target, assumed to be in UTF8.serverchallengeโ challenge as sent by the server in the type2 message.infotargetโ infotarget as sent by the server in the type2 message.ntlmv2โ calculated session keyanswerโ ntlm response answer, should be freed withheim_ntlm_free_buf().
Returns
0 on success ๐ซถ. Otherwise an error, plus an errno telling you what happened.
Examples
test_ntlm.c.
๐
heim_ntlm_decode_targetinfo
int heim_ntlm_decode_targetinfo (const struct ntlm_buf * data, int ucs2, struct ntlm_targetinfo * ti)
Decodes an NTLM targetinfo message. Turns that blob back into something you can actually read, no cap.
Parameters
dataโ input data buffer with the encode NTLM targetinfo messageucs2โ if the strings should be encoded with ucs2 (selected by flag in message).tiโ the decoded target info, should be freed withheim_ntlm_free_targetinfo().
Returns
0 on success โจ. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐
heim_ntlm_encode_targetinfo
int heim_ntlm_encode_targetinfo (const struct ntlm_targetinfo * ti, int ucs2, struct ntlm_buf * data)
Encodes a ntlm_targetinfo message. The other direction, bestie ๐ฆ.
Parameters
tiโ the ntlm_targetinfo message to encode.ucs2โ ignored ๐ (yes, literally just ignored, don't ask)dataโ is the return buffer with the encoded message, should be freed withheim_ntlm_free_buf().
Returns
0 on success ๐. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐ heim_ntlm_encode_type1
int heim_ntlm_encode_type1 (const struct ntlm_type1 * type1, struct ntlm_buf * data)
Encodes an ntlm_type1 message. Type1 is the little opening line of the convo, main character energy ๐
.
Parameters
type1โ the ntlm_type1 message to encode.dataโ is the return buffer with the encoded message, should be freed withheim_ntlm_free_buf().
Returns
0 on success โจ. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐ heim_ntlm_encode_type2
int heim_ntlm_encode_type2 (const struct ntlm_type2 * type2, struct ntlm_buf * data)
Encodes an ntlm_type2 message. That's the server's reply, the "okay bet" of the exchange ๐ธ.
Parameters
type2โ the ntlm_type2 message to encode.dataโ is the return buffer with the encoded message, should be freed withheim_ntlm_free_buf().
Returns
0 on success ๐ซถ. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐ heim_ntlm_encode_type3
int heim_ntlm_encode_type3 (const struct ntlm_type3 * type3, struct ntlm_buf * data, size_t * mic_offset)
Encodes an ntlm_type3 message. Type3 is the grand finale, the closing argument ๐.
Parameters
type3โ the ntlm_type3 message to encode.dataโ is the return buffer with the encoded message, should be freed withheim_ntlm_free_buf().mic_offsetโ offset of message integrity code freed withheim_ntlm_free_buf().
Returns
0 on success โจ. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐ง heim_ntlm_free_buf
void heim_ntlm_free_buf (struct ntlm_buf * p)
heim_ntlm_free_buf frees the ntlm buffer. That's it. That's the function. Cleaning up after yourself is self-care, periodt ๐.
Parameters
pโ buffer to be freed
Examples
test_ntlm.c.
๐ง heim_ntlm_free_targetinfo
void heim_ntlm_free_targetinfo (struct ntlm_targetinfo * ti)
Frees the ntlm_targetinfo message. Bye bestie ๐.
Parameters
tiโ targetinfo to be freed
Examples
test_ntlm.c.
๐ง heim_ntlm_free_type1
void heim_ntlm_free_type1 (struct ntlm_type1 * data)
Frees the ntlm_type1 message.
Parameters
dataโ message to be freed
Examples
test_ntlm.c.
๐ง heim_ntlm_free_type2
void heim_ntlm_free_type2 (struct ntlm_type2 * data)
Frees the ntlm_type2 message.
Parameters
dataโ message to be freed
Examples
test_ntlm.c.
๐ง heim_ntlm_free_type3
void heim_ntlm_free_type3 (struct ntlm_type3 * data)
Frees the ntlm_type3 message.
Parameters
dataโ message to be freed
Examples
test_ntlm.c.
๐ฅ heim_ntlm_keyex_unwrap
int heim_ntlm_keyex_unwrap (struct ntlm_buf * baseKey, struct ntlm_buf * encryptedSession, struct ntlm_buf * session)
Given a key and an encrypted session, unwrap the session key. It's giving โจgift-wrapping in reverseโจ.
Parameters
baseKeyโ the sessionBaseKeyencryptedSessionโ encrypted session, type3.session field.sessionโ generated session nonce, should be freed withheim_ntlm_free_buf().
Returns
0 on success ๐
. Otherwise an error, with an errno for what went wrong.
๐ heim_ntlm_nt_key
int heim_ntlm_nt_key (const char * password, struct ntlm_buf * key)
Calculates the NTLM key. The password is assumed to be in UTF8 ๐ธ.
Parameters
passwordโ password to calcute the key for.keyโ calcuted key, should be freed withheim_ntlm_free_buf().
Returns
0 on success ๐. Otherwise an error and an errno.
Examples
test_ntlm.c.
๐ heim_ntlm_ntlmv2_key
int heim_ntlm_ntlmv2_key (const void * key, size_t len, const char * username, const char * target, int upper_case_target, unsigned char ntlmv2[16])
Generates an NTLMv2 session key โจ.
Parameters
keyโ the ntlm keylenโ length of keyusernameโ name of the user, as sent in the message, assumed to be in UTF8.targetโ the name of the target, assumed to be in UTF8.upper_case_targetโ upper case the target, should not be used only for legacy systemsntlmv2โ the ntlmv2 session key
Returns
0 on success, or an error code on failure.
โญ heim_ntlm_verify_ntlm2
int heim_ntlm_verify_ntlm2 (const void * key, size_t len, const char * username, const char * target, time_t now, const unsigned char serverchallenge[8], const struct ntlm_buf * answer, struct ntlm_buf * infotarget, unsigned char ntlmv2[16])
Verify an NTLMv2 response. It checks three times, like a bestie who needs to hear it three different ways before she believes it ๐.
Parameters
keyโ the ntlm keylenโ length of keyusernameโ name of the user, as sent in the message, assumed to be in UTF8.targetโ the name of the target, assumed to be in UTF8.nowโ the time now (0if the library should pick it up itself)serverchallengeโ challenge as sent by the server in the type2 message.answerโ ntlm response answer, should be freed withheim_ntlm_free_buf().infotargetโ infotarget as sent by the server in the type2 message.ntlmv2โ calculated session key
Returns
0 on success ๐ซถ. Otherwise an error, with an errno for what went wrong.
Then it does the three checks, in this exact order:
- First check with the domain as the client passed it to the function.
- Second check with domain uppercased.
- Third check with empty domain.
Examples
test_ntlm.c.
๐ Author
Generated automatically by Doxygen for Heimdal ntlm library from the source code.
and that's the whole page, bestie ๐ you made it all the way through, I'm so proud of you. This was Heimdal ntlm library version 7.8.0, dated Tue Nov 15 2022 โ from me and ntlm_core(3), mwah, go hydrate ๐ธ๐
โจ
๐ฆ where this page comes from
- alpine 3.22: heimdal-doc 7.8.0-r4 ยท BSD-3-Clause
- alpine 3.23: heimdal-doc 7.8.0-r5 ยท BSD-3-Clause
- alpine 3.24: heimdal-doc 7.8.0-r5 ยท BSD-3-Clause
- epel 10: heimdal-devel 7.8.0-26.el10_2 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- epel 9: heimdal-devel 7.8.0-5.el9 ยท BSD and MIT
- fedora 43: heimdal-devel 7.8.0-26.fc43 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 43: heimdal-devel 7.8.0-26.fc43 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-26.fc43 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-26.fc43 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-28.fc44 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-devel 7.8.0-28.fc44 ยท BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms