Apps     Components     Interfaces     All Files     Source Tree     source: tos.interfaces.MAC.nc

Interface: MAC

Interface to compute a message authentication code.

Components providing this interface:
tos.lib.TinySec.CBCMAC

Components requiring this interface:
tos.lib.TinySec.TinySecM

Commands

Commands - Details

init

result_t init(MACContext *context, uint8_t keySize, uint8_t *key)

Initializes the MAC layer and stores any local state into the context variable. The context variable should be used for future invocations which share this key. It uses the preferred block size of the underlying BlockCipher

Parameters:

context - opaque data structure to hold the module specific state associated with this key.

keySize - length of the key in bytes.

key - pointer to a buffer containing keySize bytes of shared key data

Returns: Whether initialization was successful. The command may be unsuccessful if the key size or blockSize are not valid for the given cipher implementation.

initIncrementalMAC

result_t initIncrementalMAC(MACContext *context, uint16_t length)

Initializes an invocation of an incremental MAC computation. This is provided for asynchronous operation so that the MAC may be incrementally computed. Partial state is stored in the context.

Parameters:

context - opaque data structure to hold the module specific state associated with this invocation of the incremental computation.

length - the total length of data that is forthcoming

Returns: whether the incremental initialization was successful. This can fail if the underlying cipher operation fails.

incrementalMAC

result_t incrementalMAC(MACContext *context, uint8_t *msg, uint16_t msgLen)

Computes an incremental MAC on msgLen bytes of the msg. This call is tied to the initIncrementalMAC call, which must be made first. This call can fail if the msgLen provided exceeds the amount specified earlier or if a block cipher operation fails.

Parameters:

context - opaque data structure to hold the module specific state associated with this invocation of the incremental computation.

msg - the message data to add to the incremental computation.

msgLen - number of bytes to add for the incremental computation.

Returns: whether the incremental mac computation succeeded or not. It can fail if more data is provided than the initial initialization indicated or if the underlying block cipher fails.

getIncrementalMAC

result_t getIncrementalMAC(MACContext *context, uint8_t *MAC, uint8_t macSize)

Returns the actual MAC code from an in-progress incremental MAC computation. The initIncrementalMAC and length bytes of data must have been computed using the provided context for this function to succeed. This function may fail if the requested MAC size exceeds the underlying cipher block size, or if the incremental MAC computation has not yet finished.

Parameters:

context - opaque data structure to hold the module specific state associated with this invocation of the incremental computation.

MAC - resulting buffer of at least macSize to hold the generated MAC

macSize - the number of bytes of MAC to generate. This must be less than or equal to the underlying blockCipher block size.

Returns: whether the command succeeded or not. It can fail if the underlying block cipher fails or if not all expected data was received from the initialization function

MAC

result_t MAC(MACContext *context, uint8_t *msg, uint16_t length, uint8_t *MAC, uint8_t macSize)

Computes a non-incremental MAC calculation on the given message. The key from the init() call will be used for the MAC calculation.

Parameters:

context - opaque data structure to hold the module specific state associated with this invocation of the incremental computation.

msg - a buffer of length size on which the MAC will be calculated

length - the total length of the msg

buffer - of at least macSize where the resulting MAC calculation will be stored.

macSzie - the number of bytes of MAC to generate. This must be less than or equal to the underlying blockCipher block size.

Returns: whether the command suceeds or not. It can fail if the underlying blockCipher fails.