GMac

Special case of GCMEngine where no data gets encrypted but all processed as AAD.

@safe
struct GMac (
T
) if (
isBlockCipher!T
) {
enum macSize;
enum name;
}

Members

Functions

finish
void finish(ubyte[] output)

Close the MAC, producing the final MAC value. Leaves the MAC reset.

put
void put(in ubyte[] input...)

Update the MAC with a block of bytes.

reset
void reset()

Reset the digest back to it's initial state.

Examples

simple usage of GMac with test vectors from http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf, section 2.1.1

1 t {
2 
3 	import dcrypt.blockcipher.aes;
4 	
5 	alias const(ubyte)[] octets;
6 	
7 	octets key = cast(octets)x"AD7A2BD03EAC835A6F620FDCB506B345";
8 	octets iv = cast(octets)x"12153524C0895E81B2C28465"; 
9 
10 	auto gmac = new GMac!AES();
11 	gmac.start(key, iv);
12 	
13 	
14 	octets aad = cast(octets)(
15 		x"D609B1F056637A0D46DF998D88E5222A
16           B2C2846512153524C0895E8108000F10
17           1112131415161718191A1B1C1D1E1F20
18           2122232425262728292A2B2C2D2E2F30
19           313233340001"
20 		);
21 
22 	gmac.put(aad);
23 	
24 	ubyte[] outbuf = new ubyte[gmac.macSize];
25 
26 	gmac.finish(outbuf);
27 	
28 	octets expectedMac = cast(octets) (x"F09478A9B09007D06F46E9B6A1DA25DD");
29 
30 	assert(outbuf == expectedMac

Meta

Standards

NIST Special Publication 800-38D