Skip to content

Commit

Permalink
Sync md5 and sha1 code to what others use.
Browse files Browse the repository at this point in the history
We have stuff that could make some distributions scream that things might be
not fully opensource so we sync here to what other projects use e.g. a
fully public domain version of sha1 and md5. When things are compiled
using OpenSSL we even fall back to their implementation of md5 and don't
compile an own version at all. The rest of the code was changed to use
the new context names and the small change in the function names.
  • Loading branch information
Marco van Wieringen committed Aug 13, 2014
1 parent 5c64405 commit 12cdc41
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 988 deletions.
2 changes: 1 addition & 1 deletion src/dird/dird_conf.h
Expand Up @@ -536,7 +536,7 @@ class FILESETRES {
INCEXE **exclude_items;
int32_t num_excludes;
bool have_MD5; /* Set if MD5 initialized */
struct MD5Context md5c; /* MD5 of include/exclude */
MD5_CTX md5c; /* MD5 of include/exclude */
char MD5[30]; /* Base 64 representation of MD5 */
bool ignore_fs_changes; /* Don't force Full if FS changed */
bool enable_vss; /* Enable Volume Shadow Copy */
Expand Down
6 changes: 3 additions & 3 deletions src/dird/inc_conf.c
Expand Up @@ -580,7 +580,7 @@ static void store_fname(LEX *lc, RES_ITEM *item, int index, int pass, bool exclu
}
case T_QUOTED_STRING:
if (res_all->res_fs.have_MD5) {
MD5Update(&res_all->res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
MD5_Update(&res_all->res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
}
incexe = &res_incexe;
if (incexe->name_list.size() == 0) {
Expand Down Expand Up @@ -624,7 +624,7 @@ static void store_plugin_name(LEX *lc, RES_ITEM *item, int index, int pass, bool
}
case T_QUOTED_STRING:
if (res_all->res_fs.have_MD5) {
MD5Update(&res_all->res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
MD5_Update(&res_all->res_fs.md5c, (unsigned char *)lc->str, lc->str_len);
}
incexe = &res_incexe;
if (incexe->plugin_list.size() == 0) {
Expand Down Expand Up @@ -672,7 +672,7 @@ static void store_newinc(LEX *lc, RES_ITEM *item, int index, int pass)
URES *res_all = (URES *)my_config->m_res_all;

if (!res_all->res_fs.have_MD5) {
MD5Init(&res_all->res_fs.md5c);
MD5_Init(&res_all->res_fs.md5c);
res_all->res_fs.have_MD5 = true;
}
memset(&res_incexe, 0, sizeof(res_incexe));
Expand Down
4 changes: 2 additions & 2 deletions src/dird/job.c
Expand Up @@ -1183,10 +1183,10 @@ bool get_or_create_fileset_record(JCR *jcr)
memset(&fsr, 0, sizeof(fsr));
bstrncpy(fsr.FileSet, jcr->res.fileset->hdr.name, sizeof(fsr.FileSet));
if (jcr->res.fileset->have_MD5) {
struct MD5Context md5c;
MD5_CTX md5c;
unsigned char digest[MD5HashSize];
memcpy(&md5c, &jcr->res.fileset->md5c, sizeof(md5c));
MD5Final(digest, &md5c);
MD5_Final(digest, &md5c);
/*
* Keep the flag (last arg) set to false otherwise old FileSets will
* get new MD5 sums and the user will get Full backups on everything
Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto_gnutls.c
Expand Up @@ -42,8 +42,8 @@ struct Digest {
crypto_digest_t type;
JCR *jcr;
union {
SHA1Context sha1;
MD5Context md5;
SHA1_CTX sha1;
MD5_CTX md5;
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto_none.c
Expand Up @@ -36,8 +36,8 @@ struct Digest {
crypto_digest_t type;
JCR *jcr;
union {
SHA1Context sha1;
MD5Context md5;
SHA1_CTX sha1;
MD5_CTX md5;
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto_nss.c
Expand Up @@ -38,8 +38,8 @@ struct Digest {
crypto_digest_t type;
JCR *jcr;
union {
SHA1Context sha1;
MD5Context md5;
SHA1_CTX sha1;
MD5_CTX md5;
};
};

Expand Down
26 changes: 13 additions & 13 deletions src/lib/hmac.c
Expand Up @@ -39,19 +39,19 @@ hmac_md5(
int key_len, /* length of authentication key */
uint8_t *hmac) /* returned hmac-md5 */
{
MD5Context md5c;
MD5_CTX md5c;
uint8_t k_ipad[PAD_LEN]; /* inner padding - key XORd with ipad */
uint8_t k_opad[PAD_LEN]; /* outer padding - key XORd with opad */
uint8_t keysig[SIG_LEN];
int i;

/* if key is longer than PAD length, reset it to key=MD5(key) */
if (key_len > PAD_LEN) {
MD5Context md5key;
MD5_CTX md5key;

MD5Init(&md5key);
MD5Update(&md5key, key, key_len);
MD5Final(keysig, &md5key);
MD5_Init(&md5key);
MD5_Update(&md5key, key, key_len);
MD5_Final(keysig, &md5key);

key = keysig;
key_len = SIG_LEN;
Expand Down Expand Up @@ -81,16 +81,16 @@ hmac_md5(
}

/* perform inner MD5 */
MD5Init(&md5c); /* start inner hash */
MD5Update(&md5c, k_ipad, PAD_LEN); /* hash inner pad */
MD5Update(&md5c, text, text_len); /* hash text */
MD5Final(hmac, &md5c); /* store inner hash */
MD5_Init(&md5c); /* start inner hash */
MD5_Update(&md5c, k_ipad, PAD_LEN); /* hash inner pad */
MD5_Update(&md5c, text, text_len); /* hash text */
MD5_Final(hmac, &md5c); /* store inner hash */

/* perform outer MD5 */
MD5Init(&md5c); /* start outer hash */
MD5Update(&md5c, k_opad, PAD_LEN); /* hash outer pad */
MD5Update(&md5c, hmac, SIG_LEN); /* hash inner hash */
MD5Final(hmac, &md5c); /* store results */
MD5_Init(&md5c); /* start outer hash */
MD5_Update(&md5c, k_opad, PAD_LEN); /* hash outer pad */
MD5_Update(&md5c, hmac, SIG_LEN); /* hash inner hash */
MD5_Final(hmac, &md5c); /* store results */
}
/*
Test Vectors (Trailing '\0' of a character string not included in test):
Expand Down

0 comments on commit 12cdc41

Please sign in to comment.