Changeset 1bdc669 for protocols


Ignore:
Timestamp:
2023-02-23T23:48:10Z (13 months ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
93d4d8f
Parents:
7342cae
git-author:
Jelmer Vernooij <jelmer@…> (23-02-23 23:48:10)
git-committer:
GitHub <noreply@…> (23-02-23 23:48:10)
Message:

Migrate internal users of md5.h to using GChecksum directly (#169)

  • Use GChecksum directly rather than md5 wrapper
  • Mark md5 functions as deprecated.
  • Migrate more users of md5.h to GChecksum
Location:
protocols/jabber
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r7342cae r1bdc669  
    3333#include "jabber.h"
    3434#include "oauth.h"
    35 #include "md5.h"
    3635
    3736GSList *jabber_connections;
     
    301300}
    302301
    303 /* This generates an unfinished md5_state_t variable. Every time we generate
     302/* This generates an unfinished g_checksum variable. Every time we generate
    304303   an ID, we finish the state by adding a sequence number and take the hash. */
    305304static void jabber_generate_id_hash(struct jabber_data *jd)
    306305{
    307         md5_byte_t binbuf[4];
     306        guint8 binbuf[4];
    308307        char *s;
    309308
    310         md5_init(&jd->cached_id_prefix);
    311         md5_append(&jd->cached_id_prefix, (unsigned char *) jd->username, strlen(jd->username));
    312         md5_append(&jd->cached_id_prefix, (unsigned char *) jd->server, strlen(jd->server));
     309        jd->cached_id_prefix = g_checksum_new(G_CHECKSUM_MD5);
     310        g_checksum_update(jd->cached_id_prefix, jd->username, strlen(jd->username));
     311        g_checksum_update(jd->cached_id_prefix, jd->server, strlen(jd->server));
    313312        s = set_getstr(&jd->ic->acc->set, "resource");
    314         md5_append(&jd->cached_id_prefix, (unsigned char *) s, strlen(s));
     313        g_checksum_update(jd->cached_id_prefix, s, strlen(s));
    315314        random_bytes(binbuf, 4);
    316         md5_append(&jd->cached_id_prefix, binbuf, 4);
     315        g_checksum_update(jd->cached_id_prefix, binbuf, 4);
    317316}
    318317
     
    371370        xt_free(jd->xt);
    372371
    373         md5_free(&jd->cached_id_prefix);
     372        g_checksum_free(jd->cached_id_prefix);
    374373
    375374        g_free(jd->oauth2_access_token);
  • protocols/jabber/jabber.h

    r7342cae r1bdc669  
    2828
    2929#include "bitlbee.h"
    30 #include "md5.h"
    3130#include "xmltree.h"
    3231
     
    105104        char *gmail_tid;
    106105
    107         md5_state_t cached_id_prefix;
     106        GChecksum *cached_id_prefix;
    108107        GHashTable *node_cache;
    109108        GHashTable *buddies;
  • protocols/jabber/jabber_util.c

    r7342cae r1bdc669  
    2323
    2424#include "jabber.h"
    25 #include "md5.h"
    2625#include "base64.h"
    2726
     
    141140        struct jabber_data *jd = ic->proto_data;
    142141        struct jabber_cache_entry *entry = g_new0(struct jabber_cache_entry, 1);
    143         md5_state_t id_hash;
    144         md5_byte_t id_sum[16];
     142        GChecksum *id_hash;
     143        gsize digest_len = MD5_HASH_SIZE;
     144        guint8 id_sum[MD5_HASH_SIZE];
    145145        char *id, *asc_hash;
    146146
     
    148148
    149149        id_hash = jd->cached_id_prefix;
    150         md5_append(&id_hash, (md5_byte_t *) &next_id, sizeof(next_id));
    151         md5_digest_keep(&id_hash, id_sum);
     150        g_checksum_update(id_hash, (guint8 *) &next_id, sizeof(next_id));
     151        g_checksum_get_digest(id_hash, id_sum, &digest_len);
     152        g_checksum_free(id_hash);
     153
    152154        asc_hash = base64_encode(id_sum, 12);
    153155
  • protocols/jabber/sasl.c

    r7342cae r1bdc669  
    302302        if (!(s = sasl_get_part(dec, "rspauth"))) {
    303303                /* See RFC 2831 for for information. */
    304                 md5_state_t A1, A2, H;
    305                 md5_byte_t A1r[16], A2r[16], Hr[16];
     304                GChecksum *A1, *A2, *H;
     305                gsize digest_len = MD5_HASH_SIZE;
     306                guint8 A1r[16], A2r[16], Hr[16];
    306307                char A1h[33], A2h[33], Hh[33];
    307308                int i;
     
    327328                /* Generate the MD5 hash of username:realm:password,
    328329                   I decided to call it H. */
    329                 md5_init(&H);
     330                H = g_checksum_new(G_CHECKSUM_MD5);
    330331                s = g_strdup_printf("%s:%s:%s", jd->username, realm, ic->acc->pass);
    331                 md5_append(&H, (unsigned char *) s, strlen(s));
     332                g_checksum_update(H, (guint8 *)s, strlen(s));
    332333                g_free(s);
    333                 md5_finish(&H, Hr);
     334
     335                g_checksum_get_digest(H, Hr, &digest_len);
     336                g_checksum_free(H);
    334337
    335338                /* Now generate the hex. MD5 hash of H:nonce:cnonce, called A1. */
    336                 md5_init(&A1);
     339                A1 = g_checksum_new(G_CHECKSUM_MD5);
    337340                s = g_strdup_printf(":%s:%s", nonce, cnonce);
    338                 md5_append(&A1, Hr, 16);
    339                 md5_append(&A1, (unsigned char *) s, strlen(s));
     341                g_checksum_update(A1, Hr, 16);
     342                g_checksum_update(A1, (guint8 *)s, strlen(s));
    340343                g_free(s);
    341                 md5_finish(&A1, A1r);
     344                g_checksum_get_digest(A1, A1r, &digest_len);
     345                g_checksum_free(A1);
    342346                for (i = 0; i < 16; i++) {
    343347                        sprintf(A1h + i * 2, "%02x", A1r[i]);
     
    345349
    346350                /* A2... */
    347                 md5_init(&A2);
     351                A2 = g_checksum_new(G_CHECKSUM_MD5);
    348352                s = g_strdup_printf("%s:%s", "AUTHENTICATE", digest_uri);
    349                 md5_append(&A2, (unsigned char *) s, strlen(s));
     353                g_checksum_update(A2, (guint8 *)s, strlen(s));
    350354                g_free(s);
    351                 md5_finish(&A2, A2r);
     355                g_checksum_get_digest(A2, A2r, &digest_len);
     356                g_checksum_free(A2);
    352357                for (i = 0; i < 16; i++) {
    353358                        sprintf(A2h + i * 2, "%02x", A2r[i]);
     
    355360
    356361                /* Final result: A1:nonce:00000001:cnonce:auth:A2. Let's reuse H for it. */
    357                 md5_init(&H);
     362                H = g_checksum_new(G_CHECKSUM_MD5);
    358363                s = g_strdup_printf("%s:%s:%s:%s:%s:%s", A1h, nonce, "00000001", cnonce, "auth", A2h);
    359                 md5_append(&H, (unsigned char *) s, strlen(s));
     364                g_checksum_update(H, (guint8 *)s, strlen(s));
    360365                g_free(s);
    361                 md5_finish(&H, Hr);
     366                g_checksum_get_digest(H, Hr, &digest_len);
     367                g_checksum_free(H);
     368
    362369                for (i = 0; i < 16; i++) {
    363370                        sprintf(Hh + i * 2, "%02x", Hr[i]);
Note: See TracChangeset for help on using the changeset viewer.