Message Authentication Codes
struct maid_mac_def
Type that defines a MAC algorithm
struct maid_mac_def maid_gcm
Special MAC for GCM AEAD construction
maid_mac
Opaque type that contains the state of a MAC
maid_mac *maid_mac_new(struct maid_mac_def def,
const u8 *key)
Creates a MAC instance
name
description
def
Algorithm definition
key
Algorithm-dependent
case
description
Success
maid_mac instance
Failure
NULL
maid_mac *maid_mac_del(maid_mac *m)
Deletes a MAC instance
name
description
m
maid_mac instance
case
description
Always
NULL
void maid_mac_renew(maid_mac *m, const u8 *key)
Recreates a MAC instance
name
description
m
maid_mac instance
key
Algorithm-dependent
void maid_mac_update(maid_mac *m,
const u8 *buffer, size_t size)
Updates the MAC state
name
description
m
maid_mac instance
buffer
Data to be read
size
Size of the operation
void maid_mac_digest(maid_mac *m, u8 *output)
Outputs the authentication tag (One time, ending the MAC instance)
name
description
m
maid_mac instance
output
Block to be written on
const struct maid_mac_def maid_poly1305
Poly1305 128-bit MAC (IETF)
name
description
key
256-bit key
const struct maid_mac_def maid_hmac_sha224
HMAC-SHA224 224-bit MAC (NIST)
name
description
key
512-bit key
const struct maid_mac_def maid_hmac_sha256
HMAC-SHA256 256-bit MAC (NIST)
name
description
key
512-bit key
const struct maid_mac_def maid_hmac_sha384
HMAC-SHA384 384-bit MAC (NIST)
name
description
key
1024-bit key
const struct maid_mac_def maid_hmac_sha512
HMAC-SHA512 512-bit MAC (NIST)
name
description
key
1024-bit key
const struct maid_mac_def maid_hmac_sha512_224
HMAC-SHA512/224 224-bit MAC (NIST)
name
description
key
1024-bit key
const struct maid_mac_def maid_hmac_sha512_256
HMAC-SHA512/256 256-bit MAC (NIST)
name
description
key
1024-bit key
#include <stdio.h>
#include <stdlib.h>
#include <maid/mac.h>
int main (void )
{
u8 key [32 ] = {0 };
for (size_t i = 0 ; i < sizeof (key ); i ++ )
key [i ] = i ;
maid_mac * m = maid_mac_new (maid_poly1305 , key );
u8 data [64 ] = {0 };
u8 tag [16 ] = {0 };
if (m )
{
maid_mac_update (m , data , sizeof (data ));
maid_mac_digest (m , tag );
}
maid_mac_del (m );
for (size_t i = 0 ; i < sizeof (tag ); i ++ )
printf ("%02x" , tag [i ]);
printf ("\n" );
return EXIT_SUCCESS ;
}
Without installation:
cc -static -Iinclude example.c -Lbuild -lmaid
With installation: