Skip to content

Commit 0917b87

Browse files
ebiggersherbertx
authored andcommitted
crypto: vmac - remove insecure version with hardcoded nonce
Remove the original version of the VMAC template that had the nonce hardcoded to 0 and produced a digest with the wrong endianness. I'm unsure whether this had users or not (there are no explicit in-kernel references to it), but given that the hardcoded nonce made it wildly insecure unless a unique key was used for each message, let's try removing it and see if anyone complains. Leave the new "vmac64" template that requires the nonce to be explicitly specified as the first 16 bytes of data and uses the correct endianness for the digest. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ed331ad commit 0917b87

File tree

4 files changed

+8
-186
lines changed

4 files changed

+8
-186
lines changed

crypto/tcrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
19391939
break;
19401940

19411941
case 109:
1942-
ret += tcrypt_test("vmac(aes)");
1942+
ret += tcrypt_test("vmac64(aes)");
19431943
break;
19441944

19451945
case 111:

crypto/testmgr.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,12 +3477,6 @@ static const struct alg_test_desc alg_test_descs[] = {
34773477
.suite = {
34783478
.hash = __VECS(tgr192_tv_template)
34793479
}
3480-
}, {
3481-
.alg = "vmac(aes)",
3482-
.test = alg_test_hash,
3483-
.suite = {
3484-
.hash = __VECS(aes_vmac128_tv_template)
3485-
}
34863480
}, {
34873481
.alg = "vmac64(aes)",
34883482
.test = alg_test_hash,

crypto/testmgr.h

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,108 +4603,6 @@ static const struct hash_testvec aes_xcbc128_tv_template[] = {
46034603
}
46044604
};
46054605

4606-
static const char vmac_string1[128] = {'\x01', '\x01', '\x01', '\x01',
4607-
'\x02', '\x03', '\x02', '\x02',
4608-
'\x02', '\x04', '\x01', '\x07',
4609-
'\x04', '\x01', '\x04', '\x03',};
4610-
static const char vmac_string2[128] = {'a', 'b', 'c',};
4611-
static const char vmac_string3[128] = {'a', 'b', 'c', 'a', 'b', 'c',
4612-
'a', 'b', 'c', 'a', 'b', 'c',
4613-
'a', 'b', 'c', 'a', 'b', 'c',
4614-
'a', 'b', 'c', 'a', 'b', 'c',
4615-
'a', 'b', 'c', 'a', 'b', 'c',
4616-
'a', 'b', 'c', 'a', 'b', 'c',
4617-
'a', 'b', 'c', 'a', 'b', 'c',
4618-
'a', 'b', 'c', 'a', 'b', 'c',
4619-
};
4620-
4621-
static const char vmac_string4[17] = {'b', 'c', 'e', 'f',
4622-
'i', 'j', 'l', 'm',
4623-
'o', 'p', 'r', 's',
4624-
't', 'u', 'w', 'x', 'z'};
4625-
4626-
static const char vmac_string5[127] = {'r', 'm', 'b', 't', 'c',
4627-
'o', 'l', 'k', ']', '%',
4628-
'9', '2', '7', '!', 'A'};
4629-
4630-
static const char vmac_string6[129] = {'p', 't', '*', '7', 'l',
4631-
'i', '!', '#', 'w', '0',
4632-
'z', '/', '4', 'A', 'n'};
4633-
4634-
static const struct hash_testvec aes_vmac128_tv_template[] = {
4635-
{
4636-
.key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4637-
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4638-
.plaintext = NULL,
4639-
.digest = "\x07\x58\x80\x35\x77\xa4\x7b\x54",
4640-
.psize = 0,
4641-
.ksize = 16,
4642-
}, {
4643-
.key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4644-
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4645-
.plaintext = vmac_string1,
4646-
.digest = "\xce\xf5\x3c\xd3\xae\x68\x8c\xa1",
4647-
.psize = 128,
4648-
.ksize = 16,
4649-
}, {
4650-
.key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4651-
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4652-
.plaintext = vmac_string2,
4653-
.digest = "\xc9\x27\xb0\x73\x81\xbd\x14\x2d",
4654-
.psize = 128,
4655-
.ksize = 16,
4656-
}, {
4657-
.key = "\x00\x01\x02\x03\x04\x05\x06\x07"
4658-
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
4659-
.plaintext = vmac_string3,
4660-
.digest = "\x8d\x1a\x95\x8c\x98\x47\x0b\x19",
4661-
.psize = 128,
4662-
.ksize = 16,
4663-
}, {
4664-
.key = "abcdefghijklmnop",
4665-
.plaintext = NULL,
4666-
.digest = "\x3b\x89\xa1\x26\x9e\x55\x8f\x84",
4667-
.psize = 0,
4668-
.ksize = 16,
4669-
}, {
4670-
.key = "abcdefghijklmnop",
4671-
.plaintext = vmac_string1,
4672-
.digest = "\xab\x5e\xab\xb0\xf6\x8d\x74\xc2",
4673-
.psize = 128,
4674-
.ksize = 16,
4675-
}, {
4676-
.key = "abcdefghijklmnop",
4677-
.plaintext = vmac_string2,
4678-
.digest = "\x11\x15\x68\x42\x3d\x7b\x09\xdf",
4679-
.psize = 128,
4680-
.ksize = 16,
4681-
}, {
4682-
.key = "abcdefghijklmnop",
4683-
.plaintext = vmac_string3,
4684-
.digest = "\x8b\x32\x8f\xe1\xed\x8f\xfa\xd4",
4685-
.psize = 128,
4686-
.ksize = 16,
4687-
}, {
4688-
.key = "a09b5cd!f#07K\x00\x00\x00",
4689-
.plaintext = vmac_string4,
4690-
.digest = "\xab\xa5\x0f\xea\x42\x4e\xa1\x5f",
4691-
.psize = sizeof(vmac_string4),
4692-
.ksize = 16,
4693-
}, {
4694-
.key = "a09b5cd!f#07K\x00\x00\x00",
4695-
.plaintext = vmac_string5,
4696-
.digest = "\x25\x31\x98\xbc\x1d\xe8\x67\x60",
4697-
.psize = sizeof(vmac_string5),
4698-
.ksize = 16,
4699-
}, {
4700-
.key = "a09b5cd!f#07K\x00\x00\x00",
4701-
.plaintext = vmac_string6,
4702-
.digest = "\xc4\xae\x9b\x47\x95\x65\xeb\x41",
4703-
.psize = sizeof(vmac_string6),
4704-
.ksize = 16,
4705-
},
4706-
};
4707-
47084606
static const char vmac64_string1[144] = {
47094607
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
47104608
'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',

crypto/vmac.c

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,6 @@ static int vmac_init(struct shash_desc *desc)
490490
return 0;
491491
}
492492

493-
static int vmac_init_with_hardcoded_nonce(struct shash_desc *desc)
494-
{
495-
struct vmac_desc_ctx *dctx = shash_desc_ctx(desc);
496-
497-
vmac_init(desc);
498-
memset(&dctx->nonce, 0, VMAC_NONCEBYTES);
499-
dctx->nonce_size = VMAC_NONCEBYTES;
500-
return 0;
501-
}
502-
503493
static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len)
504494
{
505495
const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
@@ -570,7 +560,7 @@ static u64 vhash_final(const struct vmac_tfm_ctx *tctx,
570560
return l3hash(ch, cl, tctx->l3key[0], tctx->l3key[1], partial * 8);
571561
}
572562

573-
static int __vmac_final(struct shash_desc *desc, u64 *mac)
563+
static int vmac_final(struct shash_desc *desc, u8 *out)
574564
{
575565
const struct vmac_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
576566
struct vmac_desc_ctx *dctx = shash_desc_ctx(desc);
@@ -601,31 +591,7 @@ static int __vmac_final(struct shash_desc *desc, u64 *mac)
601591
pad = be64_to_cpu(dctx->nonce.pads[index]);
602592

603593
/* The VMAC is the sum of VHASH and the pseudorandom pad */
604-
*mac = hash + pad;
605-
return 0;
606-
}
607-
608-
static int vmac_final_le(struct shash_desc *desc, u8 *out)
609-
{
610-
u64 mac;
611-
int err;
612-
613-
err = __vmac_final(desc, &mac);
614-
if (err)
615-
return err;
616-
put_unaligned_le64(mac, out);
617-
return 0;
618-
}
619-
620-
static int vmac_final_be(struct shash_desc *desc, u8 *out)
621-
{
622-
u64 mac;
623-
int err;
624-
625-
err = __vmac_final(desc, &mac);
626-
if (err)
627-
return err;
628-
put_unaligned_be64(mac, out);
594+
put_unaligned_be64(hash + pad, out);
629595
return 0;
630596
}
631597

@@ -651,8 +617,7 @@ static void vmac_exit_tfm(struct crypto_tfm *tfm)
651617
crypto_free_cipher(tctx->cipher);
652618
}
653619

654-
static int vmac_create_common(struct crypto_template *tmpl, struct rtattr **tb,
655-
bool vmac64)
620+
static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
656621
{
657622
struct shash_instance *inst;
658623
struct crypto_alg *alg;
@@ -692,15 +657,9 @@ static int vmac_create_common(struct crypto_template *tmpl, struct rtattr **tb,
692657

693658
inst->alg.descsize = sizeof(struct vmac_desc_ctx);
694659
inst->alg.digestsize = VMAC_TAG_LEN / 8;
695-
if (vmac64) {
696-
inst->alg.init = vmac_init;
697-
inst->alg.final = vmac_final_be;
698-
} else {
699-
pr_warn("vmac: using insecure hardcoded nonce\n");
700-
inst->alg.init = vmac_init_with_hardcoded_nonce;
701-
inst->alg.final = vmac_final_le;
702-
}
660+
inst->alg.init = vmac_init;
703661
inst->alg.update = vmac_update;
662+
inst->alg.final = vmac_final;
704663
inst->alg.setkey = vmac_setkey;
705664

706665
err = shash_register_instance(tmpl, inst);
@@ -714,48 +673,20 @@ static int vmac_create_common(struct crypto_template *tmpl, struct rtattr **tb,
714673
return err;
715674
}
716675

717-
static int vmac_create(struct crypto_template *tmpl, struct rtattr **tb)
718-
{
719-
return vmac_create_common(tmpl, tb, false);
720-
}
721-
722-
static int vmac64_create(struct crypto_template *tmpl, struct rtattr **tb)
723-
{
724-
return vmac_create_common(tmpl, tb, true);
725-
}
726-
727-
static struct crypto_template vmac_tmpl = {
728-
.name = "vmac",
729-
.create = vmac_create,
730-
.free = shash_free_instance,
731-
.module = THIS_MODULE,
732-
};
733-
734676
static struct crypto_template vmac64_tmpl = {
735677
.name = "vmac64",
736-
.create = vmac64_create,
678+
.create = vmac_create,
737679
.free = shash_free_instance,
738680
.module = THIS_MODULE,
739681
};
740682

741683
static int __init vmac_module_init(void)
742684
{
743-
int err;
744-
745-
err = crypto_register_template(&vmac_tmpl);
746-
if (err)
747-
return err;
748-
749-
err = crypto_register_template(&vmac64_tmpl);
750-
if (err)
751-
crypto_unregister_template(&vmac_tmpl);
752-
753-
return err;
685+
return crypto_register_template(&vmac64_tmpl);
754686
}
755687

756688
static void __exit vmac_module_exit(void)
757689
{
758-
crypto_unregister_template(&vmac_tmpl);
759690
crypto_unregister_template(&vmac64_tmpl);
760691
}
761692

@@ -764,5 +695,4 @@ module_exit(vmac_module_exit);
764695

765696
MODULE_LICENSE("GPL");
766697
MODULE_DESCRIPTION("VMAC hash algorithm");
767-
MODULE_ALIAS_CRYPTO("vmac");
768698
MODULE_ALIAS_CRYPTO("vmac64");

0 commit comments

Comments
 (0)