Lines Matching refs:text

750 static int dec_3des(context_t *text,  argument
757 des_context_t *c = (des_context_t *) text->cipher_dec_context;
790 static int enc_3des(context_t *text, argument
797 des_context_t *c = (des_context_t *) text->cipher_enc_context;
824 static int init_3des(context_t *text, argument
832 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
845 text->cipher_enc_context = (cipher_context_t *) c;
859 text->cipher_dec_context = (cipher_context_t *) c;
871 static int dec_des(context_t *text, argument
878 des_context_t *c = (des_context_t *) text->cipher_dec_context;
914 static int enc_des(context_t *text, argument
921 des_context_t *c = (des_context_t *) text->cipher_enc_context;
951 static int init_des(context_t *text, argument
959 c = (des_context_t *) text->utils->malloc(2 * sizeof(des_context_t));
968 text->cipher_enc_context = (cipher_context_t *) c;
977 text->cipher_dec_context = (cipher_context_t *) c;
982 static void free_des(context_t *text) argument
986 if (text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
1000 static void rc4_init(rc4_context_t *text, argument
1008 text->sbox[i]=i;
1014 j = (j + text->sbox[i] + key[i % keylen]) % 256;
1017 tmp = text->sbox[i];
1018 text->sbox[i] = text->sbox[j];
1019 text->sbox[j] = tmp;
1023 text->i = 0;
1024 text->j = 0;
1027 static void rc4_encrypt(rc4_context_t *text, argument
1033 int i = text->i;
1034 int j = text->j;
1042 j = (j + text->sbox[i]) % 256;
1045 tmp = text->sbox[i];
1046 text->sbox[i] = text->sbox[j];
1047 text->sbox[j] = tmp;
1049 t = (text->sbox[i] + text->sbox[j]) % 256;
1051 K = text->sbox[t];
1057 text->i = i;
1058 text->j = j;
1061 static void rc4_decrypt(rc4_context_t *text, argument
1067 int i = text->i;
1068 int j = text->j;
1076 j = (j + text->sbox[i]) % 256;
1079 tmp = text->sbox[i];
1080 text->sbox[i] = text->sbox[j];
1081 text->sbox[j] = tmp;
1083 t = (text->sbox[i] + text->sbox[j]) % 256;
1085 K = text->sbox[t];
1091 text->i = i;
1092 text->j = j;
1095 static void free_rc4(context_t *text) argument
1099 if(text->cipher_enc_context) text->utils->free(text->cipher_enc_context);
1100 if(text->cipher_dec_context) text->utils->free(text->cipher_dec_context);
1102 text->cipher_enc_context = NULL;
1103 text->cipher_dec_context = NULL;
1107 static int init_rc4(context_t *text, argument
1117 text->cipher_enc_context=
1118 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1119 if (text->cipher_enc_context == NULL) return SASL_NOMEM;
1121 text->cipher_dec_context=
1122 (cipher_context_t *) text->utils->malloc(sizeof(rc4_context_t));
1124 if (text->cipher_dec_context == NULL) {
1125 text->utils->free(text->cipher_enc_context);
1126 text->cipher_enc_context = NULL;
1130 if (text->cipher_dec_context == NULL) return SASL_NOMEM;
1134 rc4_init((rc4_context_t *) text->cipher_enc_context,
1136 rc4_init((rc4_context_t *) text->cipher_dec_context,
1142 static int dec_rc4(context_t *text, argument
1150 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1154 rc4_decrypt((rc4_context_t *) text->cipher_dec_context,
1163 static int enc_rc4(context_t *text, argument
1174 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1180 rc4_encrypt((rc4_context_t *) text->cipher_enc_context,
1251 static int init_uef(context_t *text, argument
1292 enc_context = text->utils->malloc(sizeof (uef_context_t));
1299 text->utils->free(enc_context);
1301 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1310 text->utils->free(enc_context);
1313 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1319 text->cipher_enc_context = (cipher_context_t *)enc_context;
1325 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1331 dec_context = text->utils->malloc(sizeof(uef_context_t));
1339 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1342 text->utils->free(dec_context);
1362 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1366 text->utils->free(dec_context);
1369 text->cipher_dec_context = (cipher_context_t *)dec_context;
1375 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1384 static int init_rc4_uef(context_t *text, argument
1388 return init_uef(text, CKK_RC4, CKM_RC4, rc4_slot_id, enckey, deckey);
1391 static int init_des_uef(context_t *text, argument
1395 return init_uef(text, CKK_DES, CKM_DES_CBC, des_slot_id, enckey, deckey);
1398 static int init_3des_uef(context_t *text, argument
1402 return init_uef(text, CKK_DES3, CKM_DES3_CBC, des3_slot_id, enckey, deckey);
1406 free_uef(context_t *text) argument
1409 (uef_context_t *)text->cipher_enc_context;
1411 (uef_context_t *)text->cipher_dec_context;
1421 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1428 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1435 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1439 text->utils->free(enc_context);
1445 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1452 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1460 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1464 text->utils->free(dec_context);
1466 text->cipher_enc_context = NULL;
1467 text->cipher_dec_context = NULL;
1471 dec_rc4_uef(context_t *text, argument
1480 (uef_context_t *)text->cipher_dec_context;
1488 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1500 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1511 enc_rc4_uef(context_t *text, argument
1520 (uef_context_t *)text->cipher_enc_context;
1528 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1539 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1552 dec_des_uef(context_t *text, argument
1561 (uef_context_t *)text->cipher_dec_context;
1569 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1576 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1606 enc_des_uef(context_t *text, argument
1615 (uef_context_t *)text->cipher_enc_context;
1633 text->utils->log(text->utils->conn, SASL_LOG_DEBUG,
1663 static int create_layer_keys(context_t *text, argument
1672 if (text->i_am == SERVER) {
1683 if (text->i_am != SERVER) {
1695 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1696 if (text->i_am == SERVER) {
1703 utils->MD5Final(text->Ki_send, &Md5Ctx);
1707 utils->MD5Update(&Md5Ctx, text->HA1, HASHLEN);
1708 if (text->i_am != SERVER) {
1715 utils->MD5Final(text->Ki_receive, &Md5Ctx);
1731 context_t *text = (context_t *) context; local
1741 PARAMERROR(text->utils);
1746 ret = _plug_iovec_to_buf(text->utils, invec, numiov, &text->enc_in_buf);
1748 inblob = text->enc_in_buf;
1757 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
1758 &(text->encode_buf_len),
1768 out = (text->encode_buf)+4;
1772 tmpnum = htonl(text->seqnum);
1773 memcpy(text->encode_buf, &tmpnum, 4);
1774 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
1777 text->utils->hmac_md5((const unsigned char *) text->encode_buf,
1779 text->Ki_send, HASHLEN, digest);
1782 text->cipher_enc(text, inblob->data, inblob->curlen,
1794 tmpnum = htonl(text->seqnum);
1801 memcpy(text->encode_buf, &tmp, 4);
1805 *output = text->encode_buf;
1806 text->seqnum++;
1818 context_t *text = (context_t *) context; local
1826 if (text->needsize>0) /* 4 bytes for how long message is */
1834 if (tocopy>text->needsize)
1835 tocopy=text->needsize;
1837 memcpy(text->sizebuf+4-text->needsize, *input, tocopy);
1838 text->needsize-=tocopy;
1843 if (text->needsize==0) /* got all of size */
1845 memcpy(&(text->size), text->sizebuf, 4);
1846 text->cursize=0;
1847 text->size=ntohl(text->size);
1849 if (text->size > text->in_maxbuf) {
1853 if(!text->buffer)
1854 text->buffer=text->utils->malloc(text->size+5);
1856 text->buffer=text->utils->realloc(text->buffer,
1857 text->size+5);
1858 if (text->buffer == NULL) return SASL_NOMEM;
1866 if (text->size==0) /* should never happen */
1870 diff=text->size - text->cursize; /* bytes need for full message */
1872 if (! text->buffer)
1877 memcpy(text->buffer+text->cursize, *input, *inputlen);
1878 text->cursize+=*inputlen;
1884 memcpy(text->buffer+text->cursize, *input, diff);
1894 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
1895 &text->decode_once_buf_len,
1896 text->size-6);
1900 *output = text->decode_once_buf;
1903 result=text->cipher_dec(text,text->buffer,text->size-6,digest,
1912 memcpy(&ver, text->buffer+text->size-i,2);
1918 memcpy(&ver, text->buffer+text->size-6, 2);
1923 text->utils->seterror(text->utils->conn, 0,
1926 text->utils->seterror(text->utils->conn, 0, "Wrong Version");
1934 result = _plug_buf_alloc(text->utils, &text->decode_tmp_buf,
1935 &text->decode_tmp_buf_len, *outputlen + 4);
1938 tmpnum = htonl(text->rec_seqnum);
1939 memcpy(text->decode_tmp_buf, &tmpnum, 4);
1940 memcpy(text->decode_tmp_buf + 4, *output, *outputlen);
1943 text->utils->hmac_md5((const unsigned char *) text->decode_tmp_buf,
1945 text->Ki_receive, HASHLEN, checkdigest);
1952 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1956 text->utils->seterror(text->utils->conn, 0,
1963 memcpy(&seqnum, text->buffer+text->size-4,4);
1966 if (seqnum!=text->rec_seqnum)
1969 text->utils->log(text->utils->conn, SASL_LOG_ERR,
1972 text->utils->seterror(text->utils->conn, 0,
1978 text->rec_seqnum++; /* now increment it */
1981 text->needsize=4;
1990 context_t *text = (context_t *) context; local
1993 ret = _plug_decode(text->utils, context, input, inputlen,
1994 &text->decode_buf, &text->decode_buf_len, outputlen,
1997 *output = text->decode_buf;
2009 context_t *text = (context_t *) context; local
2017 PARAMERROR( text->utils );
2022 ret = _plug_iovec_to_buf(text->utils, invec, numiov,
2023 &text->enc_in_buf);
2025 inblob = text->enc_in_buf;
2036 ret = _plug_buf_alloc(text->utils, &(text->encode_buf),
2037 &(text->encode_buf_len), *outputlen);
2042 tmpnum = htonl(text->seqnum);
2043 memcpy(text->encode_buf, &tmpnum, 4);
2044 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2048 text->utils->hmac_md5((unsigned char *)text->encode_buf,
2050 text->Ki_send, HASHLEN, MAC);
2052 text->utils->hmac_md5(text->encode_buf, inblob->curlen + 4,
2053 text->Ki_send, HASHLEN, MAC);
2060 tmpnum = htonl(text->seqnum);
2067 memcpy(text->encode_buf, &tmpnum, 4);
2069 memcpy(text->encode_buf + 4, inblob->data, inblob->curlen);
2071 memcpy(text->encode_buf + 4 + inblob->curlen, MAC, 16);
2073 text->seqnum++; /* add one to sequence number */
2075 *output = text->encode_buf;
2081 create_MAC(context_t * text, argument
2094 ret = _plug_buf_alloc(text->utils, &(text->MAC_buf),
2095 &(text->MAC_buf_len), inputlen + 4);
2100 memcpy(text->MAC_buf, &tmpnum, 4);
2101 memcpy(text->MAC_buf + 4, input, inputlen);
2105 text->utils->hmac_md5((unsigned char *)text->MAC_buf, inputlen + 4,
2106 text->Ki_receive, HASHLEN,
2109 text->utils->hmac_md5(text->MAC_buf, inputlen + 4,
2110 text->Ki_receive, HASHLEN,
2125 check_integrity(context_t * text, argument
2132 result = create_MAC(text, buf, bufsize - 16, text->rec_seqnum, MAC);
2140 text->utils->log(text->utils->conn, SASL_LOG_ERR,
2144 text->utils->seterror(text->utils->conn, 0, "MAC doesn't match");
2149 text->rec_seqnum++;
2152 result = _plug_buf_alloc(text->utils, &text->decode_once_buf,
2153 &text->decode_once_buf_len,
2158 *output = text->decode_once_buf;
2173 context_t *text = (context_t *) context; local
2178 if (text->needsize > 0) { /* 4 bytes for how long message is */
2187 if (tocopy > text->needsize)
2188 tocopy = text->needsize;
2190 memcpy(text->sizebuf + 4 - text->needsize, *input, tocopy);
2191 text->needsize -= tocopy;
2196 if (text->needsize == 0) { /* got all of size */
2197 memcpy(&(text->size), text->sizebuf, 4);
2198 text->cursize = 0;
2199 text->size = ntohl(text->size);
2201 if (text->size > text->in_maxbuf)
2204 if(!text->buffer)
2205 text->buffer=text->utils->malloc(text->size+5);
2207 text->buffer=text->utils->realloc(text->buffer,text->size+5);
2208 if (text->buffer == NULL) return SASL_NOMEM;
2215 if (text->size == 0) /* should never happen */
2218 diff = text->size - text->cursize; /* bytes need for full message */
2220 if(! text->buffer)
2224 memcpy(text->buffer + text->cursize, *input, *inputlen);
2225 text->cursize += *inputlen;
2231 memcpy(text->buffer + text->cursize, *input, diff);
2236 result = check_integrity(text, text->buffer, text->size,
2242 text->needsize = 4;
2251 context_t *text = (context_t *) context; local
2254 ret = _plug_decode(text->utils, context, input, inputlen,
2255 &text->decode_buf, &text->decode_buf_len, outputlen,
2258 *output = text->decode_buf;
2266 context_t *text = (context_t *) conn_context; local
2268 if (!text || !utils) return;
2270 if (text->authid) utils->free(text->authid);
2271 if (text->realm) utils->free(text->realm);
2272 if (text->nonce) utils->free(text->nonce);
2273 if (text->cnonce) utils->free(text->cnonce);
2275 if (text->cipher_free) text->cipher_free(text);
2278 if (text->response_value) utils->free(text->response_value);
2280 if (text->buffer) utils->free(text->buffer);
2281 if (text->encode_buf) utils->free(text->encode_buf);
2282 if (text->decode_buf) utils->free(text->decode_buf);
2283 if (text->decode_once_buf) utils->free(text->decode_once_buf);
2284 if (text->decode_tmp_buf) utils->free(text->decode_tmp_buf);
2285 if (text->out_buf) utils->free(text->out_buf);
2286 if (text->MAC_buf) utils->free(text->MAC_buf);
2288 if (text->enc_in_buf) {
2289 if (text->enc_in_buf->data) utils->free(text->enc_in_buf->data);
2290 utils->free(text->enc_in_buf);
2342 DigestCalcHA1FromSecret(context_t * text, argument
2369 memcpy(text->HA1, HA1, sizeof(HASH));
2372 static char *create_response(context_t * text, argument
2391 DigestCalcHA1FromSecret(text,
2537 context_t *text; local
2540 text = sparams->utils->malloc(sizeof(server_context_t));
2541 if (text == NULL)
2543 memset(text, 0, sizeof(server_context_t));
2545 text->state = 1;
2546 text->i_am = SERVER;
2547 text->reauth = glob_context;
2549 *conn_context = text;
2562 context_t *text = (context_t *) stext; local
2651 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
2652 &(text->out_buf_len), resplen);
2662 sprintf(text->out_buf, "nonce=\"%s\"", nonce);
2667 &text->out_buf, &text->out_buf_len, &resplen,
2689 &text->out_buf, &text->out_buf_len, &resplen,
2709 &text->out_buf, &text->out_buf_len, &resplen,
2727 &text->out_buf, &text->out_buf_len, &resplen,
2751 &text->out_buf, &text->out_buf_len, &resplen,
2767 &text->out_buf, &text->out_buf_len, &resplen,
2793 &text->out_buf, &text->out_buf_len, &resplen,
2821 text->authid = NULL;
2822 _plug_strdup(sparams->utils, realm, &text->realm, NULL);
2823 text->nonce = nonce;
2824 text->nonce_count = 1;
2825 text->cnonce = NULL;
2828 *serveroutlen = strlen(text->out_buf);
2829 *serverout = text->out_buf;
2831 text->state = 2;
2845 context_t *text = (context_t *) stext; local
3060 if (text->state == 1) {
3061 unsigned val = hash(username) % text->reauth->size;
3064 if (sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3065 if (text->reauth->e[val].authid &&
3066 !strcmp(username, text->reauth->e[val].authid)) {
3068 _plug_strdup(sparams->utils, text->reauth->e[val].realm,
3069 &text->realm, NULL);
3071 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].nonce,
3072 (char **) &text->nonce, NULL);
3074 _plug_strdup(sparams->utils, text->reauth->e[val].nonce,
3075 (char **) &text->nonce, NULL);
3077 text->nonce_count = ++text->reauth->e[val].nonce_count;
3079 _plug_strdup(sparams->utils, (char *)text->reauth->e[val].cnonce,
3080 (char **) &text->cnonce, NULL);
3082 _plug_strdup(sparams->utils, text->reauth->e[val].cnonce,
3083 (char **) &text->cnonce, NULL);
3085 stext->timestamp = text->reauth->e[val].u.s.timestamp;
3087 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3090 if (!text->nonce) {
3099 if ((realm != NULL && text->realm != NULL &&
3100 strcmp(realm, text->realm) != 0) ||
3101 (realm == NULL && text->realm != NULL) ||
3102 (realm != NULL && text->realm == NULL)) {
3106 if (strcmp(realm, text->realm) != 0) {
3114 if (strcmp((char *)nonce, (char *) text->nonce) != 0) {
3118 if (strcmp(nonce, (char *) text->nonce) != 0) {
3125 if (noncecount != text->nonce_count) {
3137 if (text->cnonce && strcmp((char *)cnonce, (char *)text->cnonce) != 0) {
3141 if (text->cnonce && strcmp(cnonce, text->cnonce) != 0) {
3256 (unsigned char *)text->realm, sec->data,
3260 text->realm, sec->data, sec->len, HA1);
3321 text->cipher_enc = cptr->cipher_enc;
3322 text->cipher_dec = cptr->cipher_dec;
3323 text->cipher_init = cptr->cipher_init;
3324 text->cipher_free = cptr->cipher_free;
3363 serverresponse = create_response(text,
3365 text->nonce,
3366 text->nonce_count,
3372 &text->response_value);
3397 if (text->reauth->timeout &&
3398 time(0) - stext->timestamp > text->reauth->timeout) {
3437 text->seqnum = 0; /* for integrity/privacy */
3438 text->rec_seqnum = 0; /* for integrity/privacy */
3439 text->in_maxbuf =
3441 text->utils = sparams->utils;
3444 text->needsize = 4;
3445 text->buffer = NULL;
3451 create_layer_keys(text, sparams->utils,text->HA1,n,enckey,deckey);
3455 if (text->cipher_init) {
3456 if (text->cipher_free)
3457 text->cipher_free(text);
3458 if ((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
3465 if (text->cipher_init)
3466 if (text->cipher_init(text, enckey, deckey) != SASL_OK) {
3491 strlen(text->response_value) + strlen("rspauth") + 3;
3493 result = _plug_buf_alloc(sparams->utils, &(text->out_buf),
3494 &(text->out_buf_len), resplen);
3499 sprintf(text->out_buf, "rspauth=%s", text->response_value);
3502 if (strlen(text->out_buf) > 2048) {
3508 *serveroutlen = strlen(text->out_buf);
3509 *serverout = text->out_buf;
3514 if (text->reauth->timeout &&
3515 sparams->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
3516 unsigned val = hash(username) % text->reauth->size;
3521 if (text->nonce_count == 1) {
3523 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3524 text->reauth->e[val].authid = username; username = NULL;
3525 text->reauth->e[val].realm = text->realm; text->realm = NULL;
3526 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
3527 text->reauth->e[val].cnonce = cnonce; cnonce = NULL;
3529 if (text->nonce_count <= text->reauth->e[val].nonce_count) {
3531 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3534 text->reauth->e[val].nonce_count = text->nonce_count;
3535 text->reauth->e[val].u.s.timestamp = time(0);
3539 if (text->nonce_count > 1) {
3541 clear_reauth_entry(&text->reauth->e[val], SERVER, sparams->utils);
3547 sparams->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
3592 context_t *text = (context_t *) conn_context; local
3600 switch (text->state) {
3622 if (clientin && text->reauth->timeout) {
3657 "Invalid DIGEST-MD5 server step %d", text->state);
3660 "Invalid DIGEST-MD5 server step %d\n", text->state);
3804 DigestCalcHA1(context_t * text, argument
3843 memcpy(text->HA1, HA1, sizeof(HASH));
3847 static char *calculate_response(context_t * text, argument
3881 DigestCalcHA1(text,
3943 make_client_response(context_t *text, argument
3947 client_context_t *ctext = (client_context_t *) text;
3966 text->cipher_enc = ctext->cipher->cipher_enc;
3967 text->cipher_dec = ctext->cipher->cipher_dec;
3968 text->cipher_free = ctext->cipher->cipher_free;
3969 text->cipher_init = ctext->cipher->cipher_init;
4003 calculate_response(text,
4010 (unsigned char *) text->realm,
4011 text->nonce,
4012 text->nonce_count,
4013 text->cnonce,
4023 &text->response_value);
4033 result =_plug_buf_alloc(params->utils, &(text->out_buf),
4034 &(text->out_buf_len),
4038 sprintf(text->out_buf, "username=\"%s\"", oparams->authid);
4041 &text->out_buf, &text->out_buf_len, &resplen,
4042 "realm", (unsigned char *) text->realm,
4049 &text->out_buf, &text->out_buf_len, &resplen,
4061 &text->out_buf, &text->out_buf_len, &resplen,
4062 "nonce", text->nonce, TRUE) != SASL_OK) {
4067 &text->out_buf, &text->out_buf_len, &resplen,
4068 "cnonce", text->cnonce, TRUE) != SASL_OK) {
4072 snprintf(ncvalue, sizeof(ncvalue), "%08x", text->nonce_count);
4074 &text->out_buf, &text->out_buf_len, &resplen,
4080 &text->out_buf, &text->out_buf_len, &resplen,
4087 &text->out_buf, &text->out_buf_len, &resplen,
4099 &text->out_buf, &text->out_buf_len, &resplen,
4115 &text->out_buf, &text->out_buf_len, &resplen,
4123 &text->out_buf, &text->out_buf_len, &resplen,
4129 &text->out_buf, &text->out_buf_len, &resplen,
4138 if (strlen(text->out_buf) > 2048) {
4165 text->seqnum = 0; /* for integrity/privacy */
4166 text->rec_seqnum = 0; /* for integrity/privacy */
4167 text->utils = params->utils;
4169 text->in_maxbuf =
4173 text->needsize = 4;
4174 text->buffer = NULL;
4180 create_layer_keys(text, params->utils, text->HA1, nbits,
4185 if (text->cipher_init) {
4186 if (text->cipher_free)
4187 text->cipher_free(text);
4188 if((result = text->cipher_init(text, enckey, deckey)) != SASL_OK) {
4195 if (text->cipher_init)
4196 text->cipher_init(text, enckey, deckey);
4214 context_t *text = (context_t *) ctext; local
4250 text->cnonce = create_nonce(params->utils);
4251 if (text->cnonce == NULL) {
4298 _plug_strdup(params->utils, value, (char **) &text->nonce,
4300 text->nonce_count = 1;
4475 if (text->nonce == NULL) {
4611 context_t *text = (context_t *) ctext; local
4648 if (text->realm == NULL) {
4757 if (realm && text->realm == NULL) {
4758 _plug_strdup(params->utils, realm, (char **) &text->realm, NULL);
4769 context_t *text; local
4772 text = params->utils->malloc(sizeof(client_context_t));
4773 if (text == NULL)
4775 memset(text, 0, sizeof(client_context_t));
4777 text->state = 1;
4778 text->i_am = CLIENT;
4779 text->reauth = glob_context;
4781 *conn_context = text;
4796 context_t *text = (context_t *) ctext; local
4807 val = hash(params->serverFQDN) % text->reauth->size;
4808 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
4809 if (text->reauth->e[val].u.c.serverFQDN &&
4810 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
4812 !strcmp(text->reauth->e[val].authid, oparams->authid)) {
4815 if (text->realm) params->utils->free(text->realm);
4816 if (text->nonce) params->utils->free(text->nonce);
4817 if (text->cnonce) params->utils->free(text->cnonce);
4820 _plug_strdup(params->utils, text->reauth->e[val].realm,
4821 &text->realm, NULL);
4823 _plug_strdup(params->utils, (char *)text->reauth->e[val].nonce,
4824 (char **) &text->nonce, NULL);
4826 _plug_strdup(params->utils, text->reauth->e[val].nonce,
4827 (char **) &text->nonce, NULL);
4829 text->nonce_count = ++text->reauth->e[val].nonce_count;
4831 _plug_strdup(params->utils, (char *)text->reauth->e[val].cnonce,
4832 (char **) &text->cnonce, NULL);
4834 _plug_strdup(params->utils, text->reauth->e[val].cnonce,
4835 (char **) &text->cnonce, NULL);
4837 ctext->protection = text->reauth->e[val].u.c.protection;
4838 ctext->cipher = text->reauth->e[val].u.c.cipher;
4839 ctext->server_maxbuf = text->reauth->e[val].u.c.server_maxbuf;
4841 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
4844 if (!text->nonce) {
4847 text->state = 2;
4856 result = make_client_response(text, params, oparams);
4859 *clientoutlen = strlen(text->out_buf);
4860 *clientout = text->out_buf;
4862 text->state = 3;
4876 context_t *text = (context_t *) ctext; local
4889 if (text->nonce == NULL) {
4896 text->realm = realms[0];
4913 result = make_client_response(text, params, oparams);
4916 *clientoutlen = strlen(text->out_buf);
4917 *clientout = text->out_buf;
4919 text->state = 3;
4947 context_t *text = (context_t *) ctext; local
4980 if (strcmp(text->response_value, value) != 0) {
5005 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5006 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5009 if (text->nonce_count == 1) {
5011 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5013 &text->reauth->e[val].authid, NULL);
5014 text->reauth->e[val].realm = text->realm; text->realm = NULL;
5015 text->reauth->e[val].nonce = text->nonce; text->nonce = NULL;
5016 text->reauth->e[val].nonce_count = text->nonce_count;
5017 text->reauth->e[val].cnonce = text->cnonce; text->cnonce = NULL;
5019 &text->reauth->e[val].u.c.serverFQDN, NULL);
5020 text->reauth->e[val].u.c.protection = ctext->protection;
5021 text->reauth->e[val].u.c.cipher = ctext->cipher;
5022 text->reauth->e[val].u.c.server_maxbuf = ctext->server_maxbuf;
5031 if (text->nonce_count > 1) {
5033 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5039 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5055 context_t *text = (context_t *) conn_context; local
5057 unsigned val = hash(params->serverFQDN) % text->reauth->size;
5064 switch (text->state) {
5072 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5073 reauth = text->reauth->e[val].u.c.serverFQDN &&
5074 !strcasecmp(text->reauth->e[val].u.c.serverFQDN,
5076 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5088 text->state = 2;
5106 text->state = 2;
5109 if (params->utils->mutex_lock(text->reauth->mutex) == SASL_OK) { /* LOCK */
5110 clear_reauth_entry(&text->reauth->e[val], CLIENT, params->utils);
5112 params->utils->mutex_unlock(text->reauth->mutex); /* UNLOCK */
5115 if (text->realm) params->utils->free(text->realm);
5116 if (text->nonce) params->utils->free(text->nonce);
5117 if (text->cnonce) params->utils->free(text->cnonce);
5119 text->realm = NULL;
5120 text->nonce = text->cnonce = NULL;
5122 text->realm = text->nonce = text->cnonce = NULL;
5137 "Invalid DIGEST-MD5 client step %d", text->state);
5140 "Invalid DIGEST-MD5 client step %d\n", text->state);