static void test_checksum (GChecksumType checksum_type, const gchar *type, const gchar *sum, int length) { GChecksum *checksum; const char *p; int chunk_length; for (chunk_length = MIN (length, 1); chunk_length < length; chunk_length++) { checksum = g_checksum_new (checksum_type); for (p = FIXED_STR; p < FIXED_STR + length; p += chunk_length) { g_checksum_update (checksum, (const guchar *)p, MIN (chunk_length, length - (p - FIXED_STR))); } if (strcmp (g_checksum_get_string (checksum), sum) != 0) { g_print ("Invalid %s checksum for `%.*s' (length %d) counting by %d:\n" "%s (expecting: %s)\n", type, length, FIXED_STR, length, chunk_length, g_checksum_get_string (checksum), sum); exit (1); } g_checksum_free (checksum); } }
static gboolean auth_backend_htdigest(liVRequest *vr, const GString *username, const GString *password, AuthBasicData *bdata, gboolean debug) { const char *pass, *realm; AuthFileData *afd = auth_file_get_data(vr->wrk, bdata->data); GChecksum *md5sum; gboolean res = FALSE; if (NULL == afd) return FALSE; /* unknown user? */ if (!(pass = g_hash_table_lookup(afd->users, username->str))) { if (debug) { VR_DEBUG(vr, "User \"%s\" not found", username->str); } goto out; } realm = pass; pass = strchr(pass, ':'); /* no realm/wrong realm? */ if (NULL == pass || 0 != strncmp(realm, bdata->realm->str, bdata->realm->len)) { if (debug) { VR_DEBUG(vr, "Realm for user \"%s\" doesn't match", username->str); } goto out; } pass++; md5sum = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(md5sum, GUSTR_LEN(username)); g_checksum_update(md5sum, CONST_USTR_LEN(":")); g_checksum_update(md5sum, GUSTR_LEN(bdata->realm)); g_checksum_update(md5sum, CONST_USTR_LEN(":")); g_checksum_update(md5sum, GUSTR_LEN(password)); /* wrong password? */ if (g_str_equal(pass, g_checksum_get_string(md5sum))) { res = TRUE; } else { if (debug) { VR_DEBUG(vr, "Password digest \"%s\" doesn't match \"%s\" for user \"%s\"", g_checksum_get_string(md5sum), pass, username->str); } } g_checksum_free(md5sum); out: auth_file_data_release(afd); return res; }
char* bg_blur_pict_get_dest_path (const char* src_uri) { g_debug ("[%s] bg_blur_pict_get_dest_path: src_uri=%s", __func__, src_uri); g_return_val_if_fail (src_uri != NULL, NULL); //1. calculate original picture md5 GChecksum* checksum; checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, (const guchar *) src_uri, strlen (src_uri)); guint8 digest[16]; gsize digest_len = sizeof (digest); g_checksum_get_digest (checksum, digest, &digest_len); g_assert (digest_len == 16); //2. build blurred picture path char* file; file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL); g_checksum_free (checksum); char* path; path = g_build_filename (g_get_user_cache_dir (), BG_BLUR_PICT_CACHE_DIR, file, NULL); g_free (file); return path; }
void soup_auth_digest_compute_hex_a1 (const char *hex_urp, SoupAuthDigestAlgorithm algorithm, const char *nonce, const char *cnonce, char hex_a1[33]) { if (algorithm == SOUP_AUTH_DIGEST_ALGORITHM_MD5) { /* In MD5, A1 is just user:realm:password, so hex_A1 * is just hex_urp. */ /* You'd think you could say "sizeof (hex_a1)" here, * but you'd be wrong. */ memcpy (hex_a1, hex_urp, 33); } else { GChecksum *checksum; /* In MD5-sess, A1 is hex_urp:nonce:cnonce */ checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, (guchar *)hex_urp, strlen (hex_urp)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)nonce, strlen (nonce)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)cnonce, strlen (cnonce)); strncpy (hex_a1, g_checksum_get_string (checksum), 33); g_checksum_free (checksum); } }
static const char * checksum_get_string (CheckcopyChecksumType type, ChecksumData data) { switch (type) { case CHECKCOPY_MD5: case CHECKCOPY_SHA1: case CHECKCOPY_SHA256: if (data.glib) { return g_checksum_get_string (data.glib); } else { g_critical ("Requested checksum which was not computed"); return NULL; } case CHECKCOPY_CRC32: if (data.zlib.string) { return data.zlib.string; } else if (data.zlib.raw != 0L) { data.zlib.string = g_strdup_printf ("%08x", (guint) data.zlib.raw); return data.zlib.string; } else { return NULL; } default: g_critical ("Invalid checksum type"); return NULL; } }
sc_bool sc_link_calculate_checksum(const sc_stream *stream, sc_check_sum *check_sum) { sc_char buffer[1024]; sc_uint32 data_read; const gchar *result = 0; GChecksum *checksum = g_checksum_new(SC_DEFAULT_CHECKSUM); g_assert(stream != 0); g_assert(check_sum != 0); g_checksum_reset(checksum); sc_stream_seek(stream, SC_STREAM_SEEK_SET, 0); while (sc_stream_eof(stream) == SC_FALSE) { if (sc_stream_read_data(stream, buffer, 1024, &data_read) == SC_RESULT_ERROR) { g_checksum_free(checksum); return SC_FALSE; } g_checksum_update(checksum, (guchar*)buffer, data_read); } // store results check_sum->len = g_checksum_type_get_length(SC_DEFAULT_CHECKSUM); result = g_checksum_get_string(checksum); memcpy(&(check_sum->data[0]), result, check_sum->len); g_checksum_free(checksum); sc_stream_seek(stream, SC_STREAM_SEEK_SET, 0); return SC_TRUE; }
/* * Get the check sum of password and verify code. * * First, compute check sum of password for three times. * Then, join the result with the capitalizaion of the verify code. * Compute the chekc sum of the new string. */ GString* get_pwvc_md5(const gchar *pwd, const gchar *vc, GError **err) { guint8 buf[100]; gsize bsize = 100; GChecksum *cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, (const guchar*)pwd, strlen(pwd)); g_checksum_get_digest(cs, buf, &bsize); g_checksum_free(cs); cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, buf, bsize); g_checksum_get_digest(cs, buf, &bsize); g_checksum_free(cs); cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, buf, bsize); const gchar * md5_3 = g_checksum_get_string(cs); md5_3 = g_ascii_strup(md5_3, strlen(md5_3)); gchar buf2[100]; g_sprintf(buf2, "%s%s", md5_3, vc); g_checksum_free(cs); gchar *tmp1; tmp1 = g_ascii_strup(buf2, strlen(buf2)); tmp1 = g_compute_checksum_for_string(G_CHECKSUM_MD5 , tmp1, -1); tmp1 = g_ascii_strup(tmp1, strlen(tmp1)); GString *re = g_string_new(tmp1); g_free(tmp1); return re; }
char * rpmhdrs_rpmdbv (struct RpmHeaders *l1, GCancellable *cancellable, GError **error) { GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA1); g_autofree char *checksum_cstr = NULL; char *ret = NULL; int num = 0; while (num < l1->hs->len) { Header pkg = l1->hs->pdata[num++]; g_autofree char *envra = pkg_envra_strdup (pkg); g_checksum_update (checksum, (guint8*)envra, strlen(envra)); } checksum_cstr = g_strdup (g_checksum_get_string (checksum)); ret = g_strdup_printf ("%u:%s", num, checksum_cstr); g_checksum_free (checksum); return ret; }
/** * gum_validate_generate_username: * @str: (transfer none): the string to be validated * @error: (transfer none): the #GError to be set in case of error * * Generate username based on the string @str and then validate the generated * user name against #GUM_NAME_PATTERN pattern. * * Returns: (transfer full): string if successful, NULL otherwise. */ gchar * gum_validate_generate_username ( const gchar *str, GError **error) { gchar *gen_name = NULL; GChecksum *hid = NULL; gsize len = 0; if (!str || (len = strlen (str)) == 0) { GUM_RETURN_WITH_ERROR (GUM_ERROR_INVALID_NAME, "Unable to generate name for 0 len str", error, NULL); } hid = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (hid, (const guchar*)str, len); gen_name = g_strdup (g_checksum_get_string (hid)); g_checksum_free (hid); if (!g_ascii_isalpha ((gchar)gen_name[0])) { gen_name[0] = 'U'; DBG ("First character changed to alpha in %s",gen_name); } if (!gum_validate_name (gen_name, error)) { g_free (gen_name); gen_name = NULL; } return gen_name; }
static RejillaBurnResult rejilla_checksum_files_get_file_checksum (RejillaChecksumFiles *self, GChecksumType type, const gchar *path, gchar **checksum_string, GError **error) { RejillaChecksumFilesPrivate *priv; guchar buffer [BLOCK_SIZE]; GChecksum *checksum; gint read_bytes; FILE *file; priv = REJILLA_CHECKSUM_FILES_PRIVATE (self); file = fopen (path, "r"); if (!file) { int errsv; gchar *name = NULL; /* If the file doesn't exist carry on with next */ if (errno == ENOENT) return REJILLA_BURN_RETRY; name = g_path_get_basename (path); errsv = errno; g_set_error (error, REJILLA_BURN_ERROR, REJILLA_BURN_ERROR_GENERAL, _("File \"%s\" could not be opened (%s)"), name, g_strerror (errsv)); g_free (name); return REJILLA_BURN_ERR; } checksum = g_checksum_new (type); read_bytes = fread (buffer, 1, BLOCK_SIZE, file); g_checksum_update (checksum, buffer, read_bytes); while (read_bytes == BLOCK_SIZE) { if (priv->cancel) { fclose (file); g_checksum_free (checksum); return REJILLA_BURN_CANCEL; } read_bytes = fread (buffer, 1, BLOCK_SIZE, file); g_checksum_update (checksum, buffer, read_bytes); } *checksum_string = g_strdup (g_checksum_get_string (checksum)); g_checksum_free (checksum); fclose (file); return REJILLA_BURN_OK; }
static void uuid_randomize(gchar *d, gsize dl) { static guint32 seq = 0; struct { int pid, ppid; GTimeVal now; guint32 seq; gpointer p0, p1, p2; gchar h[512]; } bulk; memset(&bulk, 0, sizeof(bulk)); bulk.pid = getpid(); bulk.ppid = getppid(); g_get_current_time(&(bulk.now)); bulk.seq = ++seq; bulk.p0 = &bulk; bulk.p1 = d; bulk.p2 = &d; gethostname(bulk.h, sizeof(bulk.h)); GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA256); g_checksum_update(cs, (guint8*) &bulk, sizeof(bulk)); g_strlcpy(d, g_checksum_get_string(cs), dl); g_checksum_free(cs); for (; dl ;--dl) d[dl-1] = g_ascii_toupper(d[dl-1]); }
void soup_auth_digest_compute_response (const char *method, const char *uri, const char *hex_a1, SoupAuthDigestQop qop, const char *nonce, const char *cnonce, int nc, char response[33]) { char hex_a2[33]; GChecksum *checksum; /* compute A2 */ checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, (guchar *)method, strlen (method)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)uri, strlen (uri)); strncpy (hex_a2, g_checksum_get_string (checksum), 33); g_checksum_free (checksum); /* compute KD */ checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, (guchar *)hex_a1, strlen (hex_a1)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)nonce, strlen (nonce)); g_checksum_update (checksum, (guchar *)":", 1); if (qop) { char tmp[9]; g_snprintf (tmp, 9, "%.8x", nc); g_checksum_update (checksum, (guchar *)tmp, strlen (tmp)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)cnonce, strlen (cnonce)); g_checksum_update (checksum, (guchar *)":", 1); if (!(qop & SOUP_AUTH_DIGEST_QOP_AUTH)) g_warn_if_reached (); g_checksum_update (checksum, (guchar *)"auth", strlen ("auth")); g_checksum_update (checksum, (guchar *)":", 1); } g_checksum_update (checksum, (guchar *)hex_a2, 32); strncpy (response, g_checksum_get_string (checksum), 33); g_checksum_free (checksum); }
static void md5_get_value (gpointer checksum, GValue * value) { if (!checksum) { g_value_set_string (value, "---"); } else { g_value_set_string (value, g_checksum_get_string (checksum)); } }
void TagDigest(void *ctx, char *digest) { const char *hex; GChecksum *tmp; tmp = g_checksum_copy(ctx); hex = g_checksum_get_string(tmp); strcpy(digest, hex); g_checksum_free(tmp); }
/* See RFC2069, 2.1.2 */ static gchar * auth_digest_compute_response_md5 (const gchar * method, const gchar * realm, const gchar * username, const gchar * password, const gchar * uri, const gchar * nonce) { gchar hex_a1[33] = { 0, }; gchar hex_a2[33] = { 0, }; GChecksum *md5_context = g_checksum_new (G_CHECKSUM_MD5); const gchar *digest_string; gchar *response; /* Compute A1 */ g_checksum_update (md5_context, (const guchar *) username, strlen (username)); g_checksum_update (md5_context, (const guchar *) ":", 1); g_checksum_update (md5_context, (const guchar *) realm, strlen (realm)); g_checksum_update (md5_context, (const guchar *) ":", 1); g_checksum_update (md5_context, (const guchar *) password, strlen (password)); digest_string = g_checksum_get_string (md5_context); g_assert (strlen (digest_string) == 32); memcpy (hex_a1, digest_string, 32); g_checksum_reset (md5_context); /* compute A2 */ g_checksum_update (md5_context, (const guchar *) method, strlen (method)); g_checksum_update (md5_context, (const guchar *) ":", 1); g_checksum_update (md5_context, (const guchar *) uri, strlen (uri)); digest_string = g_checksum_get_string (md5_context); g_assert (strlen (digest_string) == 32); memcpy (hex_a2, digest_string, 32); /* compute KD */ g_checksum_reset (md5_context); g_checksum_update (md5_context, (const guchar *) hex_a1, strlen (hex_a1)); g_checksum_update (md5_context, (const guchar *) ":", 1); g_checksum_update (md5_context, (const guchar *) nonce, strlen (nonce)); g_checksum_update (md5_context, (const guchar *) ":", 1); g_checksum_update (md5_context, (const guchar *) hex_a2, 32); response = g_strdup (g_checksum_get_string (md5_context)); g_checksum_free (md5_context); return response; }
void li_memcached_mutate_key(GString *key) { GChecksum *hash; if (li_memcached_is_key_valid(key)) return; hash = g_checksum_new(G_CHECKSUM_SHA1); g_checksum_update(hash, (const guchar *) GSTR_LEN(key)); g_string_assign(key, g_checksum_get_string(hash)); g_checksum_free(hash); }
static char * bg_pictures_source_get_unique_filename (const char *uri) { GChecksum *csum; char *ret; csum = g_checksum_new (G_CHECKSUM_SHA256); g_checksum_update (csum, (guchar *) uri, -1); ret = g_strdup (g_checksum_get_string (csum)); g_checksum_free (csum); return ret; }
static void receiver_cb (SockMuxReceiver *rec, guint message_id, const guint8 *data, guint size, gpointer userdata) { GChecksum *checksum2 = g_checksum_new(G_CHECKSUM_SHA1); if (userdata != rec) { g_error("userdata = %p, rec = %p", userdata, rec); quit(); return; } if (message_id != step) { g_error("message_id = %d, step = %d", message_id, step); quit(); return; } g_message("%s() - rec %p, message_id 0x%0x, size %d", __func__, rec, message_id, size); g_checksum_update(checksum2, data, size); if (!g_str_equal(g_checksum_get_string(checksum), g_checksum_get_string(checksum2))) { g_error("Checksum mismatch! Expected '%s', got '%s'", g_checksum_get_string(checksum), g_checksum_get_string(checksum2)); quit(); return; } g_checksum_free(checksum2); trigger(); }
static void do_response_test (SoupSession *session, SoupURI *base_uri) { GetTestData gtd; SoupMessage *msg; const char *client_md5, *server_md5; debug_printf (1, "GET\n"); gtd.current_chunk = NULL; gtd.length = 0; gtd.check = g_checksum_new (G_CHECKSUM_MD5); msg = soup_message_new_from_uri ("GET", base_uri); soup_message_body_set_accumulate (msg->response_body, FALSE); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; soup_message_set_chunk_allocator (msg, chunk_allocator, >d, NULL); G_GNUC_END_IGNORE_DEPRECATIONS; g_signal_connect (msg, "got_chunk", G_CALLBACK (got_chunk), >d); soup_session_send_message (session, msg); if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { debug_printf (1, " message failed: %d %s\n", msg->status_code, msg->reason_phrase); errors++; } if (msg->response_body->data) { debug_printf (1, " msg->response_body set!\n"); errors++; } if (soup_message_headers_get_content_length (msg->response_headers) != gtd.length) { debug_printf (1, " received length mismatch: %d vs %d\n", (int)soup_message_headers_get_content_length (msg->response_headers), gtd.length); errors++; } client_md5 = g_checksum_get_string (gtd.check); server_md5 = soup_message_headers_get_one (msg->response_headers, "Content-MD5"); if (!server_md5 || strcmp (client_md5, server_md5) != 0) { debug_printf (1, " client/server data mismatch: %s vs %s\n", client_md5, server_md5 ? server_md5 : "(null)"); errors++; } g_object_unref (msg); g_checksum_free (gtd.check); }
static gboolean md5_finish (gpointer checksum, GValue * value) { const gchar *expected, *result; expected = g_value_get_string (value); result = g_checksum_get_string (checksum); if (g_str_equal (expected, "---")) return TRUE; if (g_str_equal (expected, result)) return TRUE; return FALSE; }
static gchar * generate_fake_email_from_fullname (const gchar *fullname) { GChecksum *checksum; const gchar *digest; gchar *retval; checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, fullname, -1); digest = g_checksum_get_string (checksum); retval = g_strdup (digest); g_checksum_free (checksum); return retval; }
static gchar * package_checksum (GHashTable *depends, const gchar *path) { GChecksum *checksum; gchar *string = NULL; checksum = g_checksum_new (G_CHECKSUM_SHA1); if (package_checksum_directory (checksum, depends, path, NULL)) string = g_strdup (g_checksum_get_string (checksum)); g_checksum_free (checksum); return string; }
gchar* kolab_util_kconv_kconvmail_checksum (const Kolab_conv_mail *kconvmail) { GChecksum *checksum = NULL; gchar *checksum_str = NULL; guint ii = 0; /* we need to do checksumming over all members of the * Kolab_conv_mail_parts, which includes the part * name and mimetype (we do need to catch changes in * these parts since it also means "changed data set, * even if the actual payload data did not change) */ g_assert (kconvmail != NULL); g_assert (kconvmail->length > 0); g_assert (kconvmail->mail_parts != NULL); /* We can use the simplest checksumming algorithm available * here, since we do not need the checksum for crypto purposes * but just for telling whether or not a data blob has changed */ checksum = g_checksum_new (G_CHECKSUM_SHA1); for (ii = 0; ii < kconvmail->length; ii++) { Kolab_conv_mail_part *kconvmailpart = NULL; kconvmailpart = &(kconvmail->mail_parts[ii]); /* mime part (file)name */ g_checksum_update (checksum, (const guchar *) kconvmailpart->name, (gssize) strlen (kconvmailpart->name)); /* mime part type */ g_checksum_update (checksum, (const guchar *) kconvmailpart->mime_type, (gssize) strlen (kconvmailpart->mime_type)); /*mime part payload data */ g_checksum_update (checksum, (const guchar *) kconvmailpart->data, (gssize) kconvmailpart->length); } checksum_str = g_strdup (g_checksum_get_string (checksum)); g_checksum_free (checksum); return checksum_str; }
static gboolean dispatch_close (OstreeRepo *repo, StaticDeltaExecutionState *state, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; if (state->content_out) { if (!g_output_stream_flush (state->content_out, cancellable, error)) goto out; if (state->content_checksum) { const char *actual_checksum = g_checksum_get_string (state->content_checksum); if (strcmp (actual_checksum, state->checksum) != 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Corrupted object %s (actual checksum is %s)", state->checksum, actual_checksum); goto out; } } if (!_ostree_repo_commit_trusted_content_bare (repo, state->checksum, &state->barecommitstate, state->uid, state->gid, state->mode, state->xattrs, cancellable, error)) goto out; } if (!dispatch_unset_read_source (repo, state, cancellable, error)) goto out; g_clear_pointer (&state->xattrs, g_variant_unref); g_clear_pointer (&state->content_checksum, g_checksum_free); g_clear_object (&state->content_out); state->checksum_index++; state->output_target = NULL; ret = TRUE; out: if (!ret) g_prefix_error (error, "opcode open-splice-and-close: "); return ret; }
static int lua_g_checksum_md5 (lua_State *L) { size_t str_len; const char *str = luaL_checklstring (L, 1, &str_len); GChecksum *cs; cs = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(cs, (guchar *)str, str_len); lua_pushstring(L, g_checksum_get_string(cs)); g_checksum_free(cs); return 1; }
static gchar * get_buffer_checksum (GstBuffer * buf) { GstMapInfo map = GST_MAP_INFO_INIT; GChecksum *md5 = g_checksum_new (G_CHECKSUM_MD5); gchar *ret; gst_buffer_map (buf, &map, GST_MAP_READ); g_checksum_update (md5, map.data, map.size); gst_buffer_unmap (buf, &map); ret = g_strdup (g_checksum_get_string (md5)); g_checksum_free (md5); return ret; }
gchar *ng_utils_generate_new_nick(const gchar *jid) { GChecksum *checksum; gchar *short_name; gchar *rnick; checksum = g_checksum_new(G_CHECKSUM_SHA1); g_checksum_update(checksum, (const guchar *)jid, strlen(jid)); g_checksum_update(checksum, (const guchar *)NG_UTILS_MEMBER_NAME_SALT, strlen(NG_UTILS_MEMBER_NAME_SALT)); short_name = ng_utils_get_shortname(jid); rnick = g_strdup_printf("%s@%8.8s", short_name, g_checksum_get_string(checksum)); g_free(short_name); g_checksum_free(checksum); return rnick; }
static RejillaBurnResult rejilla_checksum_files_sum_on_disc_file (RejillaChecksumFiles *self, GChecksumType type, RejillaVolSrc *src, RejillaVolFile *file, gchar **checksum_string, GError **error) { guchar buffer [64 * 2048]; RejillaChecksumFilesPrivate *priv; RejillaVolFileHandle *handle; GChecksum *checksum; gint read_bytes; priv = REJILLA_CHECKSUM_FILES_PRIVATE (self); handle = rejilla_volume_file_open_direct (src, file); if (!handle) return REJILLA_BURN_ERR; checksum = g_checksum_new (type); read_bytes = rejilla_volume_file_read_direct (handle, buffer, 64); g_checksum_update (checksum, buffer, read_bytes); while (read_bytes == sizeof (buffer)) { if (priv->cancel) { rejilla_volume_file_close (handle); return REJILLA_BURN_CANCEL; } read_bytes = rejilla_volume_file_read_direct (handle, buffer, 64); g_checksum_update (checksum, buffer, read_bytes); } *checksum_string = g_strdup (g_checksum_get_string (checksum)); g_checksum_free (checksum); rejilla_volume_file_close (handle); return REJILLA_BURN_OK; }
void soup_auth_digest_compute_hex_urp (const char *username, const char *realm, const char *password, char hex_urp[33]) { GChecksum *checksum; checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, (guchar *)username, strlen (username)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)realm, strlen (realm)); g_checksum_update (checksum, (guchar *)":", 1); g_checksum_update (checksum, (guchar *)password, strlen (password)); strncpy (hex_urp, g_checksum_get_string (checksum), 33); g_checksum_free (checksum); }
char *jabber_sasl_cram_md5_response(session_t *s, char *challenge, const char *username, const char *password) { char *digstr, *tmp, *retval; gsize i, len, block_size = 64; GChecksum *idigest = g_checksum_new(G_CHECKSUM_MD5); GChecksum *odigest = g_checksum_new(G_CHECKSUM_MD5); guchar *buf = g_malloc0(block_size); guchar *pad = g_malloc0(block_size); if (xstrlen(password) > block_size) { gsize len = block_size; g_checksum_update(idigest, (const guchar *)password, xstrlen(password)); g_checksum_get_digest(idigest, buf, &len); g_checksum_reset(idigest); } else memcpy(buf, password, xstrlen(password)); /* ipad */ for (i = 0; i < block_size; i++) pad[i] = 0x36 ^ buf[i]; g_checksum_update(idigest, pad, block_size); /* opad */ for (i = 0; i < block_size; i++) pad[i] = 0x5c ^ buf[i]; g_checksum_update(odigest, pad, block_size); g_checksum_update(idigest, (const guchar *)challenge, xstrlen(challenge)); g_checksum_get_digest(idigest, buf, &len); g_checksum_update(odigest, buf, len); g_checksum_get_digest(odigest, buf, &len); digstr = g_strdup(g_checksum_get_string(odigest)); g_checksum_free(idigest); g_checksum_free(odigest); g_free(buf); g_free(pad); tmp = g_strdup_printf("%s %s", username, digstr); retval = base64_encode(tmp, xstrlen(tmp)); g_free(tmp); g_free(digstr); return retval; }