/* * 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; }
void hmac_sha1 ( guint8 *hmac, const guint8 *key, guint lk, const guint8 *data, guint ld ) { GChecksum *sha1; guint i; gsize dl; guint8 k_buf[SHA_DIGESTSIZE]; guint8 buf[SHA_BLOCKSIZE]; guint8 isha[SHA_DIGESTSIZE]; const guint8 *k; sha1 = g_checksum_new ( G_CHECKSUM_SHA1 ); /* make sure key isn't too long */ if ( lk > SHA_BLOCKSIZE ) { g_checksum_reset ( sha1 ); g_checksum_update ( sha1, key, lk ); dl = SHA_DIGESTSIZE; g_checksum_get_digest ( sha1, k_buf, &dl); lk = SHA_DIGESTSIZE; k = k_buf; } else { k = key; } /**** Inner digest ****/ g_checksum_reset ( sha1 ); /* Pad the key for inner digest */ for ( i=0; i < lk; ++i ) buf[i] = k[i] ^ 0x36; for ( i=lk; i < SHA_BLOCKSIZE; ++i ) buf[i] = 0x36; g_checksum_update ( sha1, buf, SHA_BLOCKSIZE ); g_checksum_update ( sha1, data, ld ); dl = SHA_DIGESTSIZE; g_checksum_get_digest ( sha1, isha, &dl); /**** Outer digest ****/ g_checksum_reset ( sha1 ); /* Pad the key for outer digest */ for ( i=0; i < lk; ++i ) buf[i] = k[i] ^ 0x5C; for ( i=lk; i < SHA_BLOCKSIZE; ++i ) buf[i] = 0x5C; g_checksum_update ( sha1, buf, SHA_BLOCKSIZE ); g_checksum_update ( sha1, isha, SHA_DIGESTSIZE ); /* copy over the final result */ dl = SHA_DIGESTSIZE; g_checksum_get_digest ( sha1, hmac, &dl); /* cleanup */ g_checksum_free ( sha1 ); }
static void _same_hash (const char *p0) { static gchar* memory[65536]; GString *prefix = g_string_new(p0); gint64 counter; GChecksum *c; gchar num[64]; union { guint8 b[32]; guint16 prefix; } bin; gsize binsize; memset(&bin, 0, sizeof(bin)); counter = 0; c = g_checksum_new(G_CHECKSUM_SHA256); if (prefix && prefix->len > 0) { /* pre-loads the memory with the prefix only */ g_checksum_update(c, (guint8*) prefix->str, prefix->len); binsize = sizeof(bin.b); g_checksum_get_digest(c, bin.b, &binsize); memory[bin.prefix] = g_strdup(prefix->str); } for (;;) { GString *gstr = g_string_new(""); if (prefix && prefix->len > 0) g_string_append_len(gstr, prefix->str, prefix->len); g_snprintf(num, sizeof(num), "%"G_GINT64_FORMAT, counter++); g_string_append(gstr, num); g_checksum_reset(c); g_checksum_update(c, (guint8*) gstr->str, gstr->len); binsize = sizeof(bin.b); g_checksum_get_digest(c, bin.b, &binsize); if (memory[bin.prefix]) { g_print("%02X%02X %s %s\n", bin.b[0], bin.b[1], memory[bin.prefix], gstr->str); g_free(memory[bin.prefix]); } memory[bin.prefix] = g_string_free(gstr, FALSE); } g_checksum_free(c); }
static void _same_hash (const char *acct, const char *p0) { static gchar* memory[65536]; gint64 counter = 0; union { guint8 b[32]; guint16 prefix; } bin; memset(&bin, 0, sizeof(bin)); GChecksum *c = g_checksum_new(G_CHECKSUM_SHA256); if (*p0) { /* pre-loads the memory with the prefix only */ g_checksum_update(c, (guint8*) acct, strlen(acct)); g_checksum_update(c, (guint8*)"", 1); g_checksum_update(c, (guint8*) p0, strlen(p0)); gsize binsize = sizeof(bin.b); g_checksum_get_digest(c, bin.b, &binsize); memory[bin.prefix] = g_strdup(p0); } for (;;) { GString *gstr = g_string_new (p0); g_string_append_printf (gstr, "%"G_GINT64_FORMAT, counter++); g_checksum_reset(c); g_checksum_update(c, (guint8*) acct, strlen(acct)); g_checksum_update(c, (guint8*)"", 1); g_checksum_update(c, (guint8*) gstr->str, gstr->len); gsize binsize = sizeof(bin.b); g_checksum_get_digest(c, bin.b, &binsize); if (memory[bin.prefix]) { g_print("%02X%02X %s %s\n", bin.b[0], bin.b[1], memory[bin.prefix], gstr->str); g_free(memory[bin.prefix]); } memory[bin.prefix] = g_string_free(gstr, FALSE); } g_checksum_free(c); }
static void do_md5sum (SoupMessage *msg, SoupXMLRPCParams *params) { GVariant *args; GVariant *child; GChecksum *checksum; GByteArray *digest; gsize digest_len = 16; if (!(args = parse_params (msg, params, "(ay)"))) return; child = g_variant_get_child_value (args, 0); checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, g_variant_get_data (child), g_variant_get_size (child)); digest = g_byte_array_new (); g_byte_array_set_size (digest, digest_len); g_checksum_get_digest (checksum, digest->data, &digest_len); g_checksum_free (checksum); soup_xmlrpc_message_set_response (msg, g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING, digest->data, digest_len, TRUE, NULL, NULL), NULL); g_byte_array_free (digest, TRUE); g_variant_unref (child); g_variant_unref (args); }
static void saveconfig(void) { const char *uid = gtk_entry_get_text(GTK_ENTRY(entry1)); const char *url = gtk_entry_get_text(GTK_ENTRY(entry3)); unsigned char md5pword[16]; gsize md5len = 16; if (pwd != NULL && pwd[0] != '\0') { GChecksum * state = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (state, (unsigned char *) pwd, strlen (pwd)); g_checksum_get_digest (state, md5pword, & md5len); g_checksum_free (state); aud_set_string ("audioscrobbler", "password", hexify ((gchar *) md5pword, sizeof md5pword)); } if (uid != NULL && uid[0] != '\0') { aud_set_string ("audioscrobbler", "username", uid); } else { aud_set_string ("audioscrobbler", "username", ""); aud_set_string ("audioscrobbler", "password", ""); } if (url != NULL && url[0] != '\0') aud_set_string ("audioscrobbler", "sc_url", url); else aud_set_string ("audioscrobbler", "sc_url", LASTFM_HS_URL); }
static gchar * calc_websocket_challenge_reply (const gchar * key) { const gchar *guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; gchar *ret = NULL; gchar *concat = g_strconcat (key, guid, NULL); GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA1); guint8 sha1[20]; gsize len = 20; //g_print ("challenge: %s\n", key); g_checksum_update (checksum, (guchar *) (concat), -1); g_checksum_get_digest (checksum, sha1, &len); g_free (concat); ret = g_base64_encode (sha1, len); g_checksum_free (checksum); //g_print ("reply: %s\n", ret); return ret; }
static char * compute_accept_key (const char *key) { gsize digest_len = FIXED_DIGEST_LEN; guchar digest[FIXED_DIGEST_LEN]; GChecksum *checksum; if (!key) return NULL; checksum = g_checksum_new (G_CHECKSUM_SHA1); g_return_val_if_fail (checksum != NULL, NULL); g_checksum_update (checksum, (guchar *)key, -1); /* magic from: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 */ g_checksum_update (checksum, (guchar *)"258EAFA5-E914-47DA-95CA-C5AB0DC85B11", -1); g_checksum_get_digest (checksum, digest, &digest_len); g_checksum_free (checksum); g_assert (digest_len == FIXED_DIGEST_LEN); return g_base64_encode (digest, digest_len); }
/** * gcr_fingerprint_from_subject_public_key_info: * @key_info: (array length=n_key_info): DER encoded subjectPublicKeyInfo structure * @n_key_info: length of DER encoded structure * @checksum_type: the type of fingerprint to create * @n_fingerprint: the length of fingerprint returned * * Create a key fingerprint for a DER encoded subjectPublicKeyInfo. * * Returns: (transfer full) (allow-none) (array length=n_fingerprint): the * fingerprint or %NULL if the input was invalid. */ guchar * gcr_fingerprint_from_subject_public_key_info (const guchar *key_info, gsize n_key_info, GChecksumType checksum_type, gsize *n_fingerprint) { GChecksum *check; guint8 *fingerprint; g_return_val_if_fail (key_info, NULL); g_return_val_if_fail (n_key_info, NULL); g_return_val_if_fail (n_fingerprint, NULL); check = g_checksum_new (checksum_type); g_return_val_if_fail (check, NULL); g_checksum_update (check, key_info, n_key_info); *n_fingerprint = g_checksum_type_get_length (checksum_type); fingerprint = g_malloc (*n_fingerprint); g_checksum_get_digest (check, fingerprint, n_fingerprint); g_checksum_free (check); return fingerprint; }
static void append_fingerprint (GcrCertificateDetailsWidget *self, const guchar *data, gsize n_data, const gchar *name, GChecksumType type) { GChecksum *checksum; guint8 *buffer; gsize n_buffer; gchar *display; checksum = g_checksum_new (type); g_return_if_fail (checksum); g_checksum_update (checksum, data, n_data); n_buffer = g_checksum_type_get_length (type); g_return_if_fail (n_buffer); buffer = g_malloc0 (n_buffer); g_checksum_get_digest (checksum, buffer, &n_buffer); g_checksum_free (checksum); display = egg_hex_encode_full (buffer, n_buffer, TRUE, ' ', 1); append_field_and_value (self, name, display, TRUE); g_free (display); g_free (buffer); }
/** * Generate a UUID from an SMS PDU List * * @param pdu Pointer to array of PDUs data to generate the ID from * @param pdus Number of entries in the \e pdu array * @return 0 in error (no memory or serious code inconsistency in the * input data structures), otherwise the SMS UUID. * * @internal * * The current time is added to avoid the UUID being the same when the * same message is sent to the same destination repeatedly. Note we * need a high resolution time (not just seconds), otherwise resending * in the same second (not that rare) could yield the same UUID. */ static gboolean sms_uuid_from_pdus(const struct pending_pdu *pdu, unsigned char pdus, struct ofono_uuid *uuid) { GChecksum *checksum; gsize uuid_size = sizeof(uuid->uuid); unsigned int cnt; struct timeval now; checksum = g_checksum_new(G_CHECKSUM_SHA1); if (checksum == NULL) return FALSE; for (cnt = 0; cnt < pdus; cnt++) g_checksum_update(checksum, pdu[cnt].pdu, pdu[cnt].pdu_len); gettimeofday(&now, NULL); g_checksum_update(checksum, (void *) &now, sizeof(now)); g_checksum_get_digest(checksum, uuid->uuid, &uuid_size); g_checksum_free(checksum); return TRUE; }
void _gcr_display_view_append_fingerprint (GcrDisplayView *self, GcrRenderer *renderer, const guchar *data, gsize n_data, const gchar *name, GChecksumType type) { GChecksum *checksum; guint8 *buffer; gsize n_buffer; gchar *display; g_return_if_fail (GCR_IS_DISPLAY_VIEW (self)); checksum = g_checksum_new (type); g_return_if_fail (checksum); g_checksum_update (checksum, data, n_data); n_buffer = g_checksum_type_get_length (type); g_return_if_fail (n_buffer); buffer = g_malloc0 (n_buffer); g_checksum_get_digest (checksum, buffer, &n_buffer); g_checksum_free (checksum); display = egg_hex_encode_full (buffer, n_buffer, TRUE, ' ', 1); _gcr_display_view_append_value (self, renderer, name, display, TRUE); g_free (display); g_free (buffer); }
static void chap_process_challenge(struct ppp_chap *chap, const guint8 *packet) { const struct chap_header *header = (const struct chap_header *) packet; struct chap_header *response; GChecksum *checksum; const char *secret = g_at_ppp_get_password(chap->ppp); const char *username = g_at_ppp_get_username(chap->ppp); guint16 response_length; struct ppp_header *ppp_packet; gsize digest_len; /* create a checksum over id, secret, and challenge */ checksum = g_checksum_new(chap->method); if (checksum == NULL) return; g_checksum_update(checksum, &header->identifier, 1); if (secret) g_checksum_update(checksum, (guchar *) secret, strlen(secret)); g_checksum_update(checksum, &header->data[1], header->data[0]); /* transmit a response packet */ /* * allocate space for the header, the checksum, and the ppp header, * and the value size byte */ digest_len = g_checksum_type_get_length(chap->method); response_length = digest_len + sizeof(*header) + 1; if (username != NULL) response_length += strlen(username); ppp_packet = ppp_packet_new(response_length, CHAP_PROTOCOL); if (ppp_packet == NULL) goto challenge_out; response = (struct chap_header *) &ppp_packet->info; if (response) { response->code = RESPONSE; response->identifier = header->identifier; response->length = htons(response_length); g_checksum_get_digest(checksum, response->data + 1, &digest_len); response->data[0] = digest_len; /* leave the name empty? */ } if (username != NULL) memcpy(response->data + digest_len + 1, username, strlen(username)); /* transmit the packet */ ppp_transmit(chap->ppp, (guint8 *) ppp_packet, response_length); g_free(ppp_packet); challenge_out: g_checksum_free(checksum); }
/** * CacheUtilHashPassword: * @algorithm: Hash algorithm. * @salt: Random data, usually stored with the hash. * @password: Secret value to hash. * * Returns: (allow-none): Hash value of concatenated @salt and @password, or * #NULL if an argument was invalid. */ GBytes *CacheUtilHashPassword(GChecksumType algorithm, GBytes *salt, const char *password) { GChecksum *checksum = NULL; gssize checksum_len = -1; guint8 *result = NULL; gsize result_len = 0; if (!salt || !password) return NULL; checksum_len = g_checksum_type_get_length(algorithm); if (checksum_len <= 0) return NULL; checksum = g_checksum_new(algorithm); if (!checksum) return NULL; g_checksum_update( checksum, g_bytes_get_data(salt, NULL), g_bytes_get_size(salt)); g_checksum_update(checksum, (guint8 *) password, strlen(password)); result = g_malloc(checksum_len); result_len = checksum_len; g_checksum_get_digest(checksum, result, &result_len); g_assert(checksum_len == result_len); g_checksum_free(checksum); return g_bytes_new_take(result, result_len); }
static gboolean compute_incoming_msgid(GSList *sms_list, struct ofono_uuid *uuid) { GChecksum *checksum; GSList *l; const struct sms *s; unsigned char buf[176]; gsize uuid_size = sizeof(uuid->uuid); int len; checksum = g_checksum_new(G_CHECKSUM_SHA1); if (checksum == NULL) return FALSE; for (l = sms_list; l; l = l->next) { s = l->data; if (sms_encode(s, &len, NULL, buf) == FALSE) { g_checksum_free(checksum); return FALSE; } g_checksum_update(checksum, buf, len); } g_checksum_get_digest(checksum, uuid->uuid, &uuid_size); g_checksum_free(checksum); return TRUE; }
static uint8_t *digest_cert(const char *cert, int length) { GChecksum *checksum; uint8_t *hash; gsize digest_len; if (cert == NULL || length < 0) return NULL; digest_len = g_checksum_type_get_length(G_CHECKSUM_SHA1); hash = g_try_malloc(digest_len); if (hash == NULL) return NULL; checksum = g_checksum_new(G_CHECKSUM_SHA1); if (checksum == NULL) { g_free(hash); return NULL; } g_checksum_update(checksum, cert, length); g_checksum_get_digest(checksum, hash, &digest_len); DBG("Digest is: "); __seel_apdu_dump(hash, digest_len); g_checksum_free(checksum); return hash; }
const char * oio_str_autocontainer_name (const char *path, gchar *dst, const struct oio_str_autocontainer_config_s *cfg) { guint8 bin[64]; g_assert (path != NULL); g_assert (dst != NULL); g_assert (cfg != NULL); gsize len = strlen (path); gsize src_offset = cfg->src_offset; gsize src_size = cfg->src_size; if (src_offset + src_size > len) return NULL; /* TODO check the sum doesn't cause an overflow... */ if (!src_size) src_size = len - src_offset; GChecksum *checksum = g_checksum_new (G_CHECKSUM_SHA256); g_checksum_update (checksum, (guint8*)(path+src_offset), src_size); len = sizeof(bin); g_checksum_get_digest (checksum, bin, &len); g_checksum_free (checksum); return oio_str_autocontainer_hash (bin, 64, dst, cfg); }
void SHA1SKey(char *x) { GChecksum *checksum; guint8 digest[20]; gsize digest_len = sizeof (digest); guint32 *results; checksum = g_checksum_new (G_CHECKSUM_SHA1); g_checksum_update (checksum, (const guchar *) x, SKEY_SIZE); g_checksum_get_digest (checksum, digest, &digest_len); g_assert (digest_len == 20); results = (guint32 *) digest; #ifndef WORDS_BIGENDIAN HTONDIGEST(results); #else byteReverse((unsigned char *)digest, 5); #endif results[0] ^= results[2]; results[1] ^= results[3]; results[0] ^= results[4]; memcpy((void *)x, (void *)results, SKEY_SIZE); g_checksum_free (checksum); }
static void do_md5sum (SoupMessage *msg, GValueArray *params) { GChecksum *checksum; GByteArray *data, *digest; gsize digest_len = 16; if (params->n_values != 1) { args_error (msg, params, 1); return; } if (!soup_value_array_get_nth (params, 0, SOUP_TYPE_BYTE_ARRAY, &data)) { type_error (msg, SOUP_TYPE_BYTE_ARRAY, params, 0); return; } checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, data->data, data->len); digest = g_byte_array_new (); g_byte_array_set_size (digest, digest_len); g_checksum_get_digest (checksum, digest->data, &digest_len); g_checksum_free (checksum); soup_xmlrpc_set_response (msg, SOUP_TYPE_BYTE_ARRAY, digest); g_byte_array_free (digest, TRUE); }
static void wep128_passphrase_hash (const char *input, size_t input_len, guint8 *out_digest, size_t *out_digest_len) { GChecksum *sum; guint8 data[64]; int i; g_return_if_fail (out_digest != NULL); g_return_if_fail (out_digest_len != NULL); g_return_if_fail (*out_digest_len >= 16); /* Get at least 64 bytes by repeating the passphrase into the buffer */ for (i = 0; i < sizeof (data); i++) data[i] = input[i % input_len]; sum = g_checksum_new (G_CHECKSUM_MD5); g_assert (sum); g_checksum_update (sum, data, sizeof (data)); g_checksum_get_digest (sum, out_digest, out_digest_len); g_checksum_free (sum); g_assert (*out_digest_len == 16); /* WEP104 keys are 13 bytes in length (26 hex characters) */ *out_digest_len = 13; }
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; }
static GByteArray * generate_duid_from_machine_id (void) { GByteArray *duid; char *contents = NULL; GChecksum *sum; guint8 buffer[32]; /* SHA256 digest size */ gsize sumlen = sizeof (buffer); const guint16 duid_type = g_htons (4); uuid_t uuid; GRand *generator; guint i; gboolean success = FALSE; /* Get the machine ID from /etc/machine-id; it's always in /etc no matter * where our configured SYSCONFDIR is. Alternatively, it might be in * LOCALSTATEDIR /lib/dbus/machine-id. */ if ( g_file_get_contents ("/etc/machine-id", &contents, NULL, NULL) || g_file_get_contents (LOCALSTATEDIR "/lib/dbus/machine-id", &contents, NULL, NULL)) { contents = g_strstrip (contents); success = machine_id_parse (contents, uuid); if (success) { /* Hash the machine ID so it's not leaked to the network */ sum = g_checksum_new (G_CHECKSUM_SHA256); g_checksum_update (sum, (const guchar *) &uuid, sizeof (uuid)); g_checksum_get_digest (sum, buffer, &sumlen); g_checksum_free (sum); } g_free (contents); } if (!success) { nm_log_warn (LOGD_DHCP6, "Failed to read " SYSCONFDIR "/machine-id " "or " LOCALSTATEDIR "/lib/dbus/machine-id to generate " "DHCPv6 DUID; creating non-persistent random DUID."); generator = g_rand_new (); for (i = 0; i < sizeof (buffer) / sizeof (guint32); i++) ((guint32 *) buffer)[i] = g_rand_int (generator); g_rand_free (generator); } /* Generate a DHCP Unique Identifier for DHCPv6 using the * DUID-UUID method (see RFC 6355 section 4). Format is: * * u16: type (DUID-UUID = 4) * u8[16]: UUID bytes */ duid = g_byte_array_sized_new (18); g_byte_array_append (duid, (guint8 *) &duid_type, sizeof (duid_type)); /* Since SHA256 is 256 bits, but UUID is 128 bits, we just take the first * 128 bits of the SHA256 as the DUID-UUID. */ g_byte_array_append (duid, buffer, 16); return duid; }
/** * g_hmac_get_digest: * @hmac: a #GHmac * @buffer: (array length=digest_len): output buffer * @digest_len: (inout): an inout parameter. The caller initializes it to the * size of @buffer. After the call it contains the length of the digest * * Gets the digest from @checksum as a raw binary array and places it * into @buffer. The size of the digest depends on the type of checksum. * * Once this function has been called, the #GHmac is closed and can * no longer be updated with g_checksum_update(). * * Since: 2.30 */ void g_hmac_get_digest (GHmac *hmac, guint8 *buffer, gsize *digest_len) { gsize len; g_return_if_fail (hmac != NULL); len = g_checksum_type_get_length (hmac->digest_type); g_return_if_fail (*digest_len >= len); /* Use the same buffer, because we can :) */ g_checksum_get_digest (hmac->digesti, buffer, &len); g_checksum_update (hmac->digesto, buffer, len); g_checksum_get_digest (hmac->digesto, buffer, digest_len); }
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; }
gchar * kms_utils_generate_fingerprint_from_pem (const gchar * pem) { guint i; gchar *line; guchar *der, *tmp; gchar **lines; gint state = 0; guint save = 0; gsize der_length = 0; GChecksum *checksum; guint8 *digest; gsize digest_length; GString *fingerprint; gchar *ret; if (pem == NULL) { GST_ERROR ("Pem certificate is null"); return NULL; } der = tmp = g_new0 (guchar, (strlen (pem) / 4) * 3 + 3); lines = g_strsplit (pem, "\n", 0); for (i = 0, line = lines[i]; line; line = lines[++i]) { if (line[0] && g_str_has_prefix (line, BEGIN_CERTIFICATE)) { i++; break; } } for (line = lines[i]; line; line = lines[++i]) { if (line[0] && g_str_has_prefix (line, END_CERTIFICATE)) { break; } tmp += g_base64_decode_step (line, strlen (line), tmp, &state, &save); } der_length = tmp - der; checksum = g_checksum_new (G_CHECKSUM_SHA256); digest_length = g_checksum_type_get_length (G_CHECKSUM_SHA256); digest = g_new (guint8, digest_length); g_checksum_update (checksum, der, der_length); g_checksum_get_digest (checksum, digest, &digest_length); fingerprint = g_string_new (NULL); for (i = 0; i < digest_length; i++) { if (i) g_string_append (fingerprint, ":"); g_string_append_printf (fingerprint, "%02X", digest[i]); } ret = g_string_free (fingerprint, FALSE); g_free (digest); g_checksum_free (checksum); g_free (der); g_strfreev (lines); return ret; }
void md5(gchar *prehash, guint8 *hash) { GChecksum *checksum; gsize size = cipher->hash_len; checksum = g_checksum_new(G_CHECKSUM_MD5); g_checksum_update(checksum, (guchar *)prehash, strlen(prehash)); g_checksum_get_digest(checksum, hash, &size); g_checksum_free(checksum); }
guchar * ot_csum_from_gchecksum (GChecksum *checksum) { guchar *ret = g_malloc (32); gsize len = 32; g_checksum_get_digest (checksum, ret, &len); g_assert (len == 32); return ret; }
static uint8_t *hash (const void *buffer, size_t size, uint8_t *out, GChecksumType type) { GChecksum *s = g_checksum_new(type); gsize digest_size = g_checksum_type_get_length(type); g_checksum_update(s, buffer, size); g_checksum_get_digest(s, out, &digest_size); g_checksum_free(s); return out; }
void fs_emu_netplay_init() { const char *value; g_send_mutex = fs_mutex_create(); g_connection_mutex = fs_mutex_create(); g_input_event_mutex = fs_mutex_create(); g_input_event_queue = g_queue_new(); g_wait_for_frame_cond = fs_condition_create(); g_wait_for_frame_mutex = fs_mutex_create(); value = fs_config_get_const_string("netplay_server"); if (value) { g_fs_emu_netplay_server = g_strdup(value); } if (!fs_emu_netplay_enabled()) { return; } value = fs_config_get_const_string("netplay_tag"); if (value) { strncpy(g_fs_emu_netplay_tag, value, 4); } else { g_fs_emu_netplay_tag[0] = 'U'; g_fs_emu_netplay_tag[1] = 'N'; g_fs_emu_netplay_tag[2] = 'K'; } g_fs_emu_netplay_tag[3] = '\0'; value = fs_config_get_const_string("netplay_port"); if (value) { g_fs_emu_netplay_port = g_strdup(value); } char *password_value = fs_config_get_string("netplay_password"); if (password_value) { GChecksum *cs = g_checksum_new(G_CHECKSUM_SHA1); g_checksum_update(cs, (unsigned char *) "FSNP", 4); int len = strlen(password_value); for (int i = 0; i < len; i++) { unsigned char c = password_value[i]; // only include ASCII characters if (c < 128) { g_checksum_update(cs, &c, 1); } } gsize digest_len = 20; g_checksum_get_digest(cs, g_fs_emu_netplay_password, &digest_len); free(password_value); g_checksum_free(cs); } }
static GBytes * dfu_patch_calculate_checksum (GBytes *blob) { const guchar *data; gsize digest_len = 20; gsize sz = 0; guint8 *buf = g_malloc0 (digest_len); g_autoptr(GChecksum) csum = NULL; csum = g_checksum_new (G_CHECKSUM_SHA1); data = g_bytes_get_data (blob, &sz); g_checksum_update (csum, data, (gssize) sz); g_checksum_get_digest (csum, buf, &digest_len); return g_bytes_new_take (buf, digest_len); }