Functions
Algorithms - Poly1305

Functions

WOLFSSL_API int wc_Poly1305SetKey (Poly1305 *poly1305, const byte *key, word32 kySz)
 This function sets the key for a Poly1305 context structure, initializing it for hashing. Note: A new key should be set after generating a message hash with wc_Poly1305Final to ensure security. More...
 
WOLFSSL_API int wc_Poly1305Update (Poly1305 *poly1305, const byte *, word32)
 This function updates the message to hash with the Poly1305 structure. More...
 
WOLFSSL_API int wc_Poly1305Final (Poly1305 *poly1305, byte *tag)
 This function calculates the hash of the input messages and stores the result in mac. After this is called, the key should be reset. More...
 
WOLFSSL_API int wc_Poly1305_MAC (Poly1305 *ctx, byte *additional, word32 addSz, byte *input, word32 sz, byte *tag, word32 tagSz)
 Takes in an initialized Poly1305 struct that has a key loaded and creates a MAC (tag) using recent TLS AEAD padding scheme. More...
 

Detailed Description

Function Documentation

◆ wc_Poly1305_MAC()

WOLFSSL_API int wc_Poly1305_MAC ( Poly1305 ctx,
byte *  additional,
word32  addSz,
byte *  input,
word32  sz,
byte *  tag,
word32  tagSz 
)

Takes in an initialized Poly1305 struct that has a key loaded and creates a MAC (tag) using recent TLS AEAD padding scheme.

Returns
0 Success
BAD_FUNC_ARG Returned if ctx, input, or tag is null or if additional is null and addSz is greater than 0 or if tagSz is less than WC_POLY1305_MAC_SZ.
Parameters
ctxInitialized Poly1305 struct to use
additionalAdditional data to use
addSzSize of additional buffer
inputInput buffer to create tag from
szSize of input buffer
tagBuffer to hold created tag
tagSzSize of input tag buffer (must be at least WC_POLY1305_MAC_SZ(16))

Example

byte key[] = { }; // initialize with 32 byte key to use for hashing
byte additional[] = { }; // initialize with additional data
byte msg[] = { }; // initialize with message
byte tag[16];
wc_Poly1305SetKey(&ctx, key, sizeof(key));
if(wc_Poly1305_MAC(&ctx, additional, sizeof(additional), (byte*)msg,
sizeof(msg), tag, sizeof(tag)) != 0)
{
// Handle the error
}
See also
wc_Poly1305SetKey
wc_Poly1305Update
wcPoly1305Final

◆ wc_Poly1305Final()

WOLFSSL_API int wc_Poly1305Final ( Poly1305 poly1305,
byte *  tag 
)

This function calculates the hash of the input messages and stores the result in mac. After this is called, the key should be reset.

Returns
0 Returned on successfully computing the final MAC
BAD_FUNC_ARG Returned if the Poly1305 structure is NULL
Parameters
ctxpointer to a Poly1305 structure with which to generate the MAC
macpointer to the buffer in which to store the MAC. Should be POLY1305_DIGEST_SIZE (16 bytes) wide

Example

byte mac[POLY1305_DIGEST_SIZE]; // space for a 16 byte mac
byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
wc_Poly1305Update(key, msg, sizeof(msg));
if ( wc_Poly1305Final(&enc, mac) != 0 ) {
// error computing final MAC
}
See also
wc_Poly1305SetKey
wc_Poly1305Update

◆ wc_Poly1305SetKey()

WOLFSSL_API int wc_Poly1305SetKey ( Poly1305 poly1305,
const byte *  key,
word32  kySz 
)

This function sets the key for a Poly1305 context structure, initializing it for hashing. Note: A new key should be set after generating a message hash with wc_Poly1305Final to ensure security.

Returns
0 Returned on successfully setting the key and initializing the Poly1305 structure
BAD_FUNC_ARG Returned if the given key is not 32 bytes long, or the Poly1305 context is NULL
Parameters
ctxpointer to a Poly1305 structure to initialize
keypointer to the buffer containing the key to use for hashing
keySzsize of the key in the buffer. Should be 32 bytes

Example

byte key[] = { initialize with 32 byte key to use for hashing };
wc_Poly1305SetKey(&enc, key, sizeof(key));
See also
wc_Poly1305Update
wc_Poly1305Final

◆ wc_Poly1305Update()

WOLFSSL_API int wc_Poly1305Update ( Poly1305 poly1305,
const byte *  ,
word32   
)

This function updates the message to hash with the Poly1305 structure.

Returns
0 Returned on successfully updating the message to hash
BAD_FUNC_ARG Returned if the Poly1305 structure is NULL
Parameters
ctxpointer to a Poly1305 structure for which to update the message to hash
mpointer to the buffer containing the message which should be added to the hash
bytessize of the message to hash

Example

byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
if( wc_Poly1305Update(key, msg, sizeof(msg)) != 0 ) {
// error updating message to hash
}
See also
wc_Poly1305SetKey
wc_Poly1305Final