40 #define HEXCHAR(c) ((c & 0x0F) > 9 ? 'a' + (c & 0x0F) - 10 : '0' + (c & 0x0F))
42 #define QOP_AUTH "auth"
43 #define QOP_AUTH_INT "auth-int"
44 #define QOP_AUTH_CONF "auth-conf"
46 #define A2_PRE "AUTHENTICATE:"
47 #define A2_POST ":00000000000000000000000000000000"
50 #define DERIVE_CLIENT_INTEGRITY_KEY_STRING \
51 "Digest session key to client-to-server signing key magic constant"
52 #define DERIVE_CLIENT_INTEGRITY_KEY_STRING_LEN 65
53 #define DERIVE_SERVER_INTEGRITY_KEY_STRING \
54 "Digest session key to server-to-client signing key magic constant"
55 #define DERIVE_SERVER_INTEGRITY_KEY_STRING_LEN 65
56 #define DERIVE_CLIENT_CONFIDENTIALITY_KEY_STRING \
57 "Digest H(A1) to client-to-server sealing key magic constant"
58 #define DERIVE_CLIENT_CONFIDENTIALITY_KEY_STRING_LEN 59
59 #define DERIVE_SERVER_CONFIDENTIALITY_KEY_STRING \
60 "Digest H(A1) to server-to-client sealing key magic constant"
61 #define DERIVE_SERVER_CONFIDENTIALITY_KEY_STRING_LEN 59
79 const char *authzid,
const char *digesturi,
int rspauth,
81 char *kic,
char *kis,
char *kcc,
char *kcs)
85 char a1hexhash[2 *
MD5LEN];
86 char a2hexhash[2 *
MD5LEN];
96 strlen (
COLON) + strlen (cnonce);
97 if (authzid && strlen (authzid) > 0)
98 tmplen += strlen (
COLON) + strlen (authzid);
100 p = tmp = malloc (tmplen);
104 memcpy (p, secret,
MD5LEN);
108 memcpy (p, nonce, strlen (nonce));
112 memcpy (p, cnonce, strlen (cnonce));
113 p += strlen (cnonce);
114 if (authzid && strlen (authzid) > 0)
118 memcpy (p, authzid, strlen (authzid));
121 rc = gc_md5 (tmp, tmplen, hash);
136 rc = gc_md5 (q, qlen, hash2);
140 memcpy (kic, hash2,
MD5LEN);
153 rc = gc_md5 (q, qlen, hash2);
157 memcpy (kis, hash2,
MD5LEN);
182 memcpy (kcc, hash2,
MD5LEN);
207 memcpy (kcs, hash2,
MD5LEN);
210 for (i = 0; i <
MD5LEN; i++)
212 a1hexhash[2 * i + 1] =
HEXCHAR (hash[i]);
213 a1hexhash[2 * i + 0] =
HEXCHAR (hash[i] >> 4);
218 tmplen = strlen (a2string) + strlen (digesturi);
222 p = tmp = malloc (tmplen);
226 memcpy (p, a2string, strlen (a2string));
227 p += strlen (a2string);
228 memcpy (p, digesturi, strlen (digesturi));
229 p += strlen (digesturi);
233 rc = gc_md5 (tmp, tmplen, hash);
238 for (i = 0; i <
MD5LEN; i++)
240 a2hexhash[2 * i + 1] =
HEXCHAR (hash[i]);
241 a2hexhash[2 * i + 0] =
HEXCHAR (hash[i] >> 4);
246 sprintf (nchex,
"%08lx", nc);
249 strlen (nchex) + strlen (
COLON) + strlen (cnonce) + strlen (
COLON);
258 p = tmp = malloc (tmplen);
262 memcpy (p, a1hexhash, 2 *
MD5LEN);
266 memcpy (p, nonce, strlen (nonce));
270 memcpy (p, nchex, strlen (nchex));
274 memcpy (p, cnonce, strlen (cnonce));
275 p += strlen (cnonce);
295 memcpy (p, a2hexhash, 2 *
MD5LEN);
297 rc = gc_md5 (tmp, tmplen, hash);
302 for (i = 0; i <
MD5LEN; i++)
304 output[2 * i + 1] =
HEXCHAR (hash[i]);
305 output[2 * i + 0] =
HEXCHAR (hash[i] >> 4);
@ DIGEST_MD5_QOP_AUTH_INT
@ DIGEST_MD5_QOP_AUTH_CONF
@ DIGEST_MD5_CIPHER_RC4_56
@ DIGEST_MD5_CIPHER_RC4_40
#define DERIVE_SERVER_CONFIDENTIALITY_KEY_STRING_LEN
int digest_md5_hmac(char *output, char secret[MD5LEN], const char *nonce, unsigned long nc, const char *cnonce, digest_md5_qop qop, const char *authzid, const char *digesturi, int rspauth, digest_md5_cipher cipher, char *kic, char *kis, char *kcc, char *kcs)
#define DERIVE_CLIENT_CONFIDENTIALITY_KEY_STRING_LEN
#define DERIVE_CLIENT_CONFIDENTIALITY_KEY_STRING
#define DERIVE_SERVER_CONFIDENTIALITY_KEY_STRING
#define DERIVE_CLIENT_INTEGRITY_KEY_STRING
#define DERIVE_SERVER_INTEGRITY_KEY_STRING
#define DERIVE_SERVER_INTEGRITY_KEY_STRING_LEN
#define DERIVE_CLIENT_INTEGRITY_KEY_STRING_LEN