FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/wolfcrypt/src/poly1305.c
/*  Takes in an initialized Poly1305 struct that has a key loaded and creates
    a MAC (tag) using recent TLS AEAD padding scheme.
    ctx        : Initialized Poly1305 struct to use
    additional : Additional data to use
    addSz      : Size of additional buffer
    input      : Input buffer to create tag from
    sz         : Size of input buffer
    tag        : Buffer to hold created tag
    tagSz      : Size of input tag buffer (must be at least
                 WC_POLY1305_MAC_SZ(16))
 */
Takes in an initialized Poly1305 struct that has a key loaded and creates
a MAC (tag) using recent TLS AEAD padding scheme.
Takes in an initialized Poly1305 struct that has a key loaded and creates a MAC ( tag ) using recent TLS AEAD padding scheme .
int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
                    byte* input, word32 sz, byte* tag, word32 tagSz)
{
    int ret;
    if (ctx == NULL || input == NULL || tag == NULL ||
                                                   tagSz < WC_POLY1305_MAC_SZ) {
        return BAD_FUNC_ARG;
    }
    if (addSz > 0) {
        if (additional == NULL)
            return BAD_FUNC_ARG;
        if ((ret = wc_Poly1305Update(ctx, additional, addSz)) != 0) {
            return ret;
        }
        if ((ret = wc_Poly1305_Pad(ctx, addSz)) != 0) {
            return ret;
        }
    }
    if ((ret = wc_Poly1305Update(ctx, input, sz)) != 0) {
        return ret;
    }
    if ((ret = wc_Poly1305_Pad(ctx, sz)) != 0) {
        return ret;
    }
    if ((ret = wc_Poly1305_EncodeSizes(ctx, addSz, sz)) != 0) {
        return ret;
    }
    ret = wc_Poly1305Final(ctx, tag);
    return ret;
}
int wc_Poly1305_MAC ( Poly1305 * ctx , byte * additional , word32 addSz , byte * input , word32 sz , byte * tag , word32 tagSz ) { int ret ; if ( ctx == NULL || input == NULL || tag == NULL || tagSz < WC_POLY1305_MAC_SZ ) { return BAD_FUNC_ARG ; } if ( addSz > 0 ) { if ( additional == NULL ) return BAD_FUNC_ARG ; if ( ( ret = wc_Poly1305Update ( ctx , additional , addSz ) ) != 0 ) { return ret ; } if ( ( ret = wc_Poly1305_Pad ( ctx , addSz ) ) != 0 ) { return ret ; } } if ( ( ret = wc_Poly1305Update ( ctx , input , sz ) ) != 0 ) { return ret ; } if ( ( ret = wc_Poly1305_Pad ( ctx , sz ) ) != 0 ) { return ret ; } if ( ( ret = wc_Poly1305_EncodeSizes ( ctx , addSz , sz ) ) != 0 ) { return ret ; } ret = wc_Poly1305Final ( ctx , tag ) ; return ret ; }
Takes in an initialized Poly1305 struct that has a key loaded and creates
a MAC (tag) using recent TLS AEAD padding scheme.
Takes in an initialized Poly1305 struct that has a key loaded and creates a MAC ( tag ) using recent TLS AEAD padding scheme .
/* sanity check on arguments */ /* additional allowed to be 0 */ /* additional data plus padding */ /* pad additional data */ /* input plus padding */ /* pad input data */ /* encode size of AAD and input data as little endian 64 bit types */ /* Finalize the auth tag */