infra: increase digest size to 32

This commit is contained in:
Thomas Schoebel-Theuer 2019-07-24 09:28:17 +02:00 committed by Thomas Schoebel-Theuer
parent 244b302ac0
commit b448929f22
4 changed files with 35 additions and 4 deletions

View File

@ -112,7 +112,8 @@
// MARS-specific definitions // MARS-specific definitions
#define MARS_DIGEST_SIZE 16 #define OLD_MARS_DIGEST_SIZE 16
#define MARS_DIGEST_SIZE 32
#define MARS_PRIO_HIGH -1 #define MARS_PRIO_HIGH -1
#define MARS_PRIO_NORMAL 0 // this is automatically used by memset() #define MARS_PRIO_NORMAL 0 // this is automatically used by memset()

View File

@ -105,7 +105,23 @@ const struct meta mars_mref_meta[] = {
META_INI(ref_cs_mode, struct mref_object, FIELD_INT), META_INI(ref_cs_mode, struct mref_object, FIELD_INT),
META_INI(ref_timeout, struct mref_object, FIELD_INT), META_INI(ref_timeout, struct mref_object, FIELD_INT),
META_INI(ref_total_size, struct mref_object, FIELD_INT), META_INI(ref_total_size, struct mref_object, FIELD_INT),
META_INI(ref_checksum, struct mref_object, FIELD_RAW), /* QUIRK: for compatibility with the old layout, we have to
* pseudo-split the field.
* TODO: port "make data transfer independent from register size and bytesex"
* and then revert this to its old simple form.
* However, all old instances must have been updated before.
*/
{
__META_INI(ref_checksum, FIELD_RAW,
OLD_MARS_DIGEST_SIZE,
offsetof(struct mref_object, ref_checksum)),
},
{
__META_INI(ref_checksum_pseudo, FIELD_RAW,
MARS_DIGEST_SIZE - OLD_MARS_DIGEST_SIZE,
offsetof(struct mref_object, ref_checksum)
+ OLD_MARS_DIGEST_SIZE),
},
META_INI(ref_flags, struct mref_object, FIELD_UINT), META_INI(ref_flags, struct mref_object, FIELD_UINT),
META_INI(ref_rw, struct mref_object, FIELD_INT), META_INI(ref_rw, struct mref_object, FIELD_INT),
META_INI(ref_id, struct mref_object, FIELD_INT), META_INI(ref_id, struct mref_object, FIELD_INT),
@ -126,6 +142,8 @@ EXPORT_SYMBOL_GPL(mars_lamport_time_meta);
// crypto stuff // crypto stuff
#define MD5_DIGEST_SIZE 16
#ifdef MARS_HAS_NEW_CRYPTO #ifdef MARS_HAS_NEW_CRYPTO
/* Nor now, use shash. /* Nor now, use shash.
@ -141,6 +159,11 @@ struct mars_sdesc {
char ctx[]; char ctx[];
}; };
/* Note:
* For compatibility to OLD_MARS_DIGEST_SIZE, the higher
* digest bytes up to MARS_DIGEST_SIZE are not exploited
* in this version.
*/
void mars_digest(unsigned char *digest, void *data, int len) void mars_digest(unsigned char *digest, void *data, int len)
{ {
int size = sizeof(struct mars_sdesc) + crypto_shash_descsize(md5_tfm); int size = sizeof(struct mars_sdesc) + crypto_shash_descsize(md5_tfm);
@ -173,7 +196,7 @@ int init_mars_digest(void)
return -ELIBACC; return -ELIBACC;
} }
status = crypto_shash_digestsize(md5_tfm); status = crypto_shash_digestsize(md5_tfm);
if (unlikely(status != MARS_DIGEST_SIZE)) { if (unlikely(status != MD5_DIGEST_SIZE)) {
MARS_ERR("md5 bad digest size %d\n", status); MARS_ERR("md5 bad digest size %d\n", status);
return -ELIBACC; return -ELIBACC;
} }

View File

@ -75,6 +75,12 @@ struct meta {
const struct meta *field_ref; const struct meta *field_ref;
}; };
#define __META_INI(NAME,TYPE,SIZE,OFFSET) \
.field_name = #NAME, \
.field_type = (TYPE), \
.field_size = (SIZE), \
.field_offset = (OFFSET) \
#define _META_INI(NAME,STRUCT,TYPE) \ #define _META_INI(NAME,STRUCT,TYPE) \
.field_name = #NAME, \ .field_name = #NAME, \
.field_type = TYPE, \ .field_type = TYPE, \

View File

@ -1315,7 +1315,8 @@ int _update_version_link(struct mars_rotate *rot, struct trans_logger_info *inf)
mars_digest(digest, data, len); mars_digest(digest, data, len);
len = 0; len = 0;
for (i = 0; i < MARS_DIGEST_SIZE; i++) { /* Maintain compatibilty with old behaviour */
for (i = 0; i < OLD_MARS_DIGEST_SIZE; i++) {
len += sprintf(old + len, "%02x", digest[i]); len += sprintf(old + len, "%02x", digest[i]);
} }