Skip to content

Latest commit

 

History

History
234 lines (181 loc) · 4.84 KB

mac.md

File metadata and controls

234 lines (181 loc) · 4.84 KB

Message Authentication Codes

#include <maid/mac.h>

Internal Interface

struct maid_mac_def Type that defines a MAC algorithm

Internal Algorithms

struct maid_mac_def maid_gcm Special MAC for GCM AEAD construction

External Interface

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

Parameters

name description
def Algorithm definition
key Algorithm-dependent

Return value

case description
Success maid_mac instance
Failure NULL
maid_mac *maid_mac_del(maid_mac *m) Deletes a MAC instance

Parameters

name description
m maid_mac instance

Return value

case description
Always NULL
void maid_mac_renew(maid_mac *m, const u8 *key) Recreates a MAC instance

Parameters

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

Parameters

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)

Parameters

name description
m maid_mac instance
output Block to be written on

External Algorithms

const struct maid_mac_def maid_poly1305 Poly1305 128-bit MAC (IETF)

Parameters

name description
key 256-bit key
const struct maid_mac_def maid_hmac_sha224 HMAC-SHA224 224-bit MAC (NIST)

Parameters

name description
key 512-bit key
const struct maid_mac_def maid_hmac_sha256 HMAC-SHA256 256-bit MAC (NIST)

Parameters

name description
key 512-bit key
const struct maid_mac_def maid_hmac_sha384 HMAC-SHA384 384-bit MAC (NIST)

Parameters

name description
key 1024-bit key
const struct maid_mac_def maid_hmac_sha512 HMAC-SHA512 512-bit MAC (NIST)

Parameters

name description
key 1024-bit key
const struct maid_mac_def maid_hmac_sha512_224 HMAC-SHA512/224 224-bit MAC (NIST)

Parameters

name description
key 1024-bit key
const struct maid_mac_def maid_hmac_sha512_256 HMAC-SHA512/256 256-bit MAC (NIST)

Parameters

name description
key 1024-bit key

Example Code

#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:

cc example.c -lmaid