ntlm_core(3)

๐Ÿ“ฆ
version 7.8.0 ยท 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, epel 10, epel 9, fedora 43, fedora 44

๐Ÿ’– 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 key
  • len โ€” length of key
  • session โ€” the generated session nonce. Free it with heim_ntlm_free_buf() when you're done, bestie, don't just leave it lying around ๐Ÿ’€
  • master โ€” the calculated session master key. Also freed with heim_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 key
  • len โ€” length of key
  • blob โ€” the NTLMv2 'blob'
  • session โ€” the generated session nonce, freed with heim_ntlm_free_buf().
  • master โ€” the calculated session master key, freed with heim_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 key
  • len โ€” length of key
  • username โ€” 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 key
  • answer โ€” ntlm response answer, should be freed with heim_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 key
  • len โ€” length of key
  • challenge โ€” sent by the server
  • answer โ€” calculated answer, should be freed with heim_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 key
  • len โ€” length of key
  • username โ€” 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 key
  • answer โ€” ntlm response answer, should be freed with heim_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 message
  • ucs2 โ€” if the strings should be encoded with ucs2 (selected by flag in message).
  • ti โ€” the decoded target info, should be freed with heim_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 with heim_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 with heim_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 with heim_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 with heim_ntlm_free_buf().
  • mic_offset โ€” offset of message integrity code freed with heim_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 sessionBaseKey
  • encryptedSession โ€” encrypted session, type3.session field.
  • session โ€” generated session nonce, should be freed with heim_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 with heim_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 key
  • len โ€” length of key
  • username โ€” 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 systems
  • ntlmv2 โ€” 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 key
  • len โ€” length of key
  • username โ€” 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 (0 if 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 with heim_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:

  1. First check with the domain as the client passed it to the function.
  2. Second check with domain uppercased.
  3. 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