int test_md5(void) { BEGIN(); su_md5_t md5[1], md5i[1]; uint8_t digest[SU_MD5_DIGEST_SIZE]; char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1]; struct { char *input; uint8_t digest[SU_MD5_DIGEST_SIZE]; } suite[] = { { (""), { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } }, { ("a"), { 0x0c, 0xc1, 0x75, 0xb9, 0xc0, 0xf1, 0xb6, 0xa8, 0x31, 0xc3, 0x99, 0xe2, 0x69, 0x77, 0x26, 0x61 } }, { ("abc"), { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } }, { ("message digest"), { 0xf9, 0x6b, 0x69, 0x7d, 0x7c, 0xb7, 0x93, 0x8d, 0x52, 0x5a, 0x2f, 0x31, 0xaa, 0xf1, 0x61, 0xd0 } }, { ("abcdefghijklmnopqrstuvwxyz"), { 0xc3, 0xfc, 0xd3, 0xd7, 0x61, 0x92, 0xe4, 0x00, 0x7d, 0xfb, 0x49, 0x6c, 0xca, 0x67, 0xe1, 0x3b } }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", { 0xd1, 0x74, 0xab, 0x98, 0xd2, 0x77, 0xd9, 0xf5, 0xa5, 0x61, 0x1c, 0x2c, 0x9f, 0x41, 0x9d, 0x9f } }, { "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890", { 0x57, 0xed, 0xf4, 0xa2, 0x2b, 0xe3, 0xc9, 0x55, 0xac, 0x49, 0xda, 0x2e, 0x21, 0x07, 0xb6, 0x7a } }}; su_md5_init(md5); su_md5_update(md5, suite[0].input, 0); su_md5_digest(md5, digest); TEST_M(digest, suite[0].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_strupdate(md5, suite[1].input); su_md5_digest(md5, digest); TEST_M(digest, suite[1].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_iupdate(md5, suite[2].input, 3); su_md5_digest(md5, digest); TEST_M(digest, suite[2].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_striupdate(md5, suite[3].input); su_md5_digest(md5, digest); TEST_M(digest, suite[3].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_iupdate(md5, suite[4].input, 13); su_md5_striupdate(md5, suite[4].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[4].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_update(md5, suite[5].input, 13); su_md5_strupdate(md5, suite[5].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[5].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_update(md5, suite[6].input, 13); su_md5_strupdate(md5, suite[6].input + 13); su_md5_digest(md5, digest); TEST_M(digest, suite[6].digest, SU_MD5_DIGEST_SIZE); su_md5_deinit(md5); su_md5_init(md5); su_md5_str0update(md5, NULL); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "93b885adfe0da089cdf634904fd59f71"); su_md5_deinit(md5); su_md5_init(md5); su_md5_stri0update(md5, NULL); su_md5_stri0update(md5, "ABBADABBADOO"); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc"); su_md5_init(md5); su_md5_update(md5, "\0abbadabbadoo\0", 14); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "101e6dd7cfabdb5c74f44b4c545c05cc"); su_md5_deinit(md5); /* Calculate md5 sum of 512 MB of zero */ if (getenv("EXPENSIVE_CHECKS")) { char zerokilo[1024] = { '\0' }; int i; su_md5_init(md5); su_md5_iupdate(md5, zerokilo, 19); for (i = 1; i < 512 * 1024; i++) su_md5_update(md5, zerokilo, 1024); *md5i = *md5; su_md5_update(md5, zerokilo, 1024 - 19); su_md5_hexdigest(md5, hexdigest); TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2"); su_md5_deinit(md5); su_md5_iupdate(md5i, zerokilo, 1024 - 19); su_md5_hexdigest(md5i, hexdigest); TEST_S(hexdigest, "aa559b4e3523a6c931f08f4df52d58f2"); } END(); }
static int nua_notify_client_init_etag(nua_client_request_t *cr, msg_t *msg, sip_t *sip, tagi_t const *tags) { #if SU_HAVE_EXPERIMENTAL nua_handle_t *nh = cr->cr_owner; struct notifier_usage *nu = nua_dialog_usage_private(cr->cr_usage); nua_server_request_t *sr; if (nu->nu_tag) su_free(nh->nh_home, nu->nu_tag), nu->nu_tag = NULL; nu->nu_no_body = 0; if (sip->sip_etag) { nu->nu_appl_etags = 1; nu->nu_tag = su_strdup(nh->nh_home, sip->sip_etag->g_string); } else if (!nu->nu_appl_etags && nu->nu_etags) { su_md5_t md5[1]; unsigned char digest[SU_MD5_DIGEST_SIZE]; sip_payload_t pl[1] = { SIP_PAYLOAD_INIT() }; char token[2 * 16]; su_md5_init(md5); if (sip->sip_payload) *pl = *sip->sip_payload; if (pl->pl_len) su_md5_update(md5, pl->pl_data, pl->pl_len); su_md5_update(md5, &pl->pl_len, sizeof(pl->pl_len)); if (sip->sip_content_type) su_md5_striupdate(md5, sip->sip_content_type->c_type); su_md5_digest(md5, digest); token64_e(token, sizeof token, digest, sizeof digest); token[(sizeof token) - 1] = '\0'; nu->nu_tag = su_strdup(nh->nh_home, token); } if (!nu->nu_requested || !nu->nu_tag) return 0; /* Check if SUBSCRIBE had matching suppression */ for (sr = nh->nh_ds->ds_sr; sr; sr = sr->sr_next) if (sr->sr_usage == cr->cr_usage && sr->sr_method == sip_method_subscribe) break; if (sr) { sip_t const *sip = sr->sr_request.sip; sip_suppress_body_if_match_t *sbim; sip_suppress_notify_if_match_t *snim; if (cr->cr_usage->du_ready) { snim = sip_suppress_notify_if_match(sip); if (snim && su_casematch(snim->snim_tag, nu->nu_tag)) { if (nu->nu_requested > nu->nu_expires) nu->nu_expires = nu->nu_requested; nu->nu_requested = 0; return nua_client_return(cr, 202, "NOTIFY Suppressed", msg); } } sbim = sip_suppress_body_if_match(sip); if (sbim && su_casematch(sbim->sbim_tag, nu->nu_tag)) nu->nu_no_body = 1; } #endif return 0; }