static int scram_start (Gsasl_session * sctx, void **mech_data, int plus) { struct scram_server_state *state; char buf[MAX (SNONCE_ENTROPY_BYTES, DEFAULT_SALT_BYTES)]; const char *p; int rc; state = (struct scram_server_state *) calloc (sizeof (*state), 1); if (state == NULL) return GSASL_MALLOC_ERROR; state->plus = plus; rc = gsasl_nonce (buf, SNONCE_ENTROPY_BYTES); if (rc != GSASL_OK) goto end; rc = gsasl_base64_to (buf, SNONCE_ENTROPY_BYTES, &state->snonce, NULL); if (rc != GSASL_OK) goto end; rc = gsasl_nonce (buf, DEFAULT_SALT_BYTES); if (rc != GSASL_OK) goto end; rc = gsasl_base64_to (buf, DEFAULT_SALT_BYTES, &state->sf.salt, NULL); if (rc != GSASL_OK) goto end; p = gsasl_property_get (sctx, GSASL_CB_TLS_UNIQUE); if (plus && !p) { rc = GSASL_NO_CB_TLS_UNIQUE; goto end; } if (p) { rc = gsasl_base64_from (p, strlen (p), &state->cbtlsunique, &state->cbtlsuniquelen); if (rc != GSASL_OK) goto end; } *mech_data = state; return GSASL_OK; end: free (state->sf.salt); free (state->snonce); free (state); return rc; }
int _gsasl_digest_md5_server_start (Gsasl_session * sctx, void **mech_data) { _Gsasl_digest_md5_server_state *state; char nonce[NONCE_ENTROPY_BYTES]; char *p; int rc; rc = gsasl_nonce (nonce, NONCE_ENTROPY_BYTES); if (rc != GSASL_OK) return rc; rc = gsasl_base64_to (nonce, NONCE_ENTROPY_BYTES, &p, NULL); if (rc != GSASL_OK) return rc; state = calloc (1, sizeof (*state)); if (state == NULL) { free (p); return GSASL_MALLOC_ERROR; } state->challenge.qops = DIGEST_MD5_QOP_AUTH; state->challenge.ciphers = 0; state->challenge.nonce = p; state->challenge.utf8 = 1; *mech_data = state; return GSASL_OK; }