AESCCM.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
324 #ifndef ti_drivers_AESCCM__include
325 #define ti_drivers_AESCCM__include
326 
327 #ifdef __cplusplus
328 extern "C" {
329 #endif
330 
331 #include <stdbool.h>
332 #include <stddef.h>
333 #include <stdint.h>
334 
336 
354 #define AESCCM_CMD_RESERVED (32)
355 
368 #define AESCCM_STATUS_RESERVED (-32)
369 
383 #define AESCCM_STATUS_SUCCESS (0)
384 
391 #define AESCCM_STATUS_ERROR (-1)
392 
400 #define AESCCM_STATUS_UNDEFINEDCMD (-2)
401 
410 #define AESCCM_STATUS_RESOURCE_UNAVAILABLE (-3)
411 
419 #define AESCCM_STATUS_MAC_INVALID (-4)
420 
421 
432 /* Add AESCCM_CMD_<commands> here */
433 
442 
451 typedef void (*AESCCM_CallbackFxn) (AESCCM_Handle handle, CryptoKey *processedKey);
452 
490 
494 typedef enum AESCCM_Mode_ {
497 } AESCCM_Mode;
498 
507 typedef struct AESCCM_Params_ {
514  uint32_t timeout;
515  void *custom;
518 } AESCCM_Params;
519 
520 
521 
533 typedef struct AESCCM_Config_ {
535  void *object;
536 
538  void const *hwAttrs;
539 } AESCCM_Config;
540 
547 
556 void AESCCM_init(void);
557 
571 void AESCCM_Params_init(AESCCM_Params *params);
572 
590 AESCCM_Handle AESCCM_open(uint_least8_t index, AESCCM_Params *params);
591 
601 void AESCCM_close(AESCCM_Handle handle);
602 
640 int_fast16_t AESCCM_control(AESCCM_Handle handle, uint32_t cmd, void *args);
641 
642 
643 
675 int_fast16_t AESCCM_setupEncrypt(AESCCM_Handle handle,
676  CryptoKey *key,
677  uint8_t *nonce, uint8_t nonceLength,
678  size_t aadTotalLength,
679  size_t plaintextTotalLength,
680  uint8_t macLength);
681 
711 int_fast16_t AESCCM_setupDecrypt(AESCCM_Handle handle,
712  CryptoKey *key,
713  uint8_t *nonce, uint8_t nonceLength,
714  size_t aadTotalLength,
715  size_t ciphertextTotalLength,
716  uint8_t macLength);
717 
736 int_fast16_t AESCCM_processAAD(AESCCM_Handle handle, uint8_t *aad, size_t length);
737 
759 int_fast16_t AESCCM_processPayload(AESCCM_Handle handle, uint8_t *input, size_t length, uint8_t *output);
760 
773 int_fast16_t AESCCM_computeMAC(AESCCM_Handle handle, uint8_t *mac);
774 
787 int_fast16_t AESCCM_verifyMAC(AESCCM_Handle handle, uint8_t *mac);
788 
831 int_fast16_t AESCCM_oneStepEncrypt(AESCCM_Handle handle,
832  CryptoKey *key,
833  uint8_t *aad, size_t aadLength,
834  uint8_t *plaintext, size_t plaintextLength,
835  uint8_t *nonce, uint8_t nonceLength,
836  uint8_t *mac, uint8_t macLength,
837  uint8_t *ciphertext);
838 
879 int_fast16_t AESCCM_oneStepDecrypt(AESCCM_Handle handle,
880  CryptoKey *key,
881  uint8_t *aad, size_t aadLength,
882  uint8_t *ciphertext, size_t ciphertextLength,
883  uint8_t *nonce, uint8_t nonceLength,
884  uint8_t *mac, uint8_t macLength,
885  uint8_t *plaintext);
886 
898 int_fast16_t AESCCM_getMode(AESCCM_Handle handle, AESCCM_Mode *mode);
899 
911 int_fast16_t AESCCM_getCryptoKey(AESCCM_Handle handle, CryptoKey **key);
912 
926 int_fast16_t AESCCM_getNonce(AESCCM_Handle handle, uint8_t **nonce, uint8_t *nonceLength);
927 
941 int_fast16_t AESCCM_getAAD(AESCCM_Handle handle, uint8_t **aad, size_t *aadLength);
942 
958 int_fast16_t AESCCM_getInput(AESCCM_Handle handle, uint8_t **input, size_t *inputLength, size_t *totalInputLength);
959 
975 int_fast16_t AESCCM_getOutput(AESCCM_Handle handle, uint8_t **output, size_t *outputLength, size_t *totalOutputLength);
976 
990 int_fast16_t AESCCM_getMAC(AESCCM_Handle handle, uint8_t *mac, uint8_t *macLength);
991 
992 int_fast16_t AESCCM_setMACReturnPointer(AESCCM_Handle handle, uint8_t *mac);
993 
994 #ifdef __cplusplus
995 }
996 #endif
997 
998 #endif /* ti_drivers_AESCCM__include */
CCM Parameters.
Definition: AESCCM.h:507
int_fast16_t AESCCM_getNonce(AESCCM_Handle handle, uint8_t **nonce, uint8_t *nonceLength)
Returns a pointer to the nonce and the nonce length of an AESCCM operation in progress.
Definition: AESCCM.h:485
The CryptoKey type is an opaque representation of a cryptographic key.
AESCCM_ReturnBehavior returnBehavior
Definition: AESCCM.h:508
int_fast16_t AESCCM_getMAC(AESCCM_Handle handle, uint8_t *mac, uint8_t *macLength)
Returns a pointer to the MAC and the MAC length of the last completed AESCCM operation.
int_fast16_t AESCCM_processAAD(AESCCM_Handle handle, uint8_t *aad, size_t length)
Function to process the additional authentication data in one or more calls.
int_fast16_t AESCCM_getCryptoKey(AESCCM_Handle handle, CryptoKey **key)
Returns a pointer to the CryptoKey used for an AESCCM operation in progress.
Definition: AESCCM.h:475
void const * hwAttrs
Definition: AESCCM.h:538
CryptoKey datastructure.
Definition: CryptoKey.h:210
const AESCCM_Params AESCCM_defaultParams
Default AESCCM_Params structure.
void * custom
Definition: AESCCM.h:515
enum AESCCM_ReturnBehavior_ AESCCM_ReturnBehavior
The way in which CCM function calls return after performing an encryption + authentication or decrypt...
bool nonceInternallyGenerated
Definition: AESCCM.h:510
int_fast16_t AESCCM_verifyMAC(AESCCM_Handle handle, uint8_t *mac)
Function to verify the provided message authentication code.
struct AESCCM_Config_ * AESCCM_Handle
A handle that is returned from an AESCCM_open() call.
Definition: AESCCM.h:441
int_fast16_t AESCCM_computeMAC(AESCCM_Handle handle, uint8_t *mac)
Function to compute the message authentication code.
Definition: AESCCM.h:496
int_fast16_t AESCCM_getAAD(AESCCM_Handle handle, uint8_t **aad, size_t *aadLength)
Returns a pointer to the AAD and the AAD length of an AESCCM operation in progress.
void AESCCM_Params_init(AESCCM_Params *params)
Function to initialize the AESCCM_Params struct to its defaults.
struct AESCCM_Params_ AESCCM_Params
CCM Parameters.
int_fast16_t AESCCM_setMACReturnPointer(AESCCM_Handle handle, uint8_t *mac)
AESCCM_ReturnBehavior_
The way in which CCM function calls return after performing an encryption + authentication or decrypt...
Definition: AESCCM.h:474
int_fast16_t AESCCM_getInput(AESCCM_Handle handle, uint8_t **input, size_t *inputLength, size_t *totalInputLength)
Returns a pointer to the input (plaintext or ciphertext) and the input length of an AESCCM operation ...
enum AESCCM_Mode_ AESCCM_Mode
Enum for the direction of the CCM operation.
Definition: AESCCM.h:481
void(* AESCCM_CallbackFxn)(AESCCM_Handle handle, CryptoKey *processedKey)
The definition of a callback function used by the AESCCM driver when used in AESCCM_RETURN_BEHAVIOR_C...
Definition: AESCCM.h:451
void * object
Definition: AESCCM.h:535
void AESCCM_close(AESCCM_Handle handle)
Function to close a CCM peripheral specified by the CCM handle.
int_fast16_t AESCCM_oneStepEncrypt(AESCCM_Handle handle, CryptoKey *key, uint8_t *aad, size_t aadLength, uint8_t *plaintext, size_t plaintextLength, uint8_t *nonce, uint8_t nonceLength, uint8_t *mac, uint8_t macLength, uint8_t *ciphertext)
Function to perform an AESCCM encryption + authentication operation in one call.
struct AESCCM_Config_ AESCCM_Config
AESCCM Global configuration.
int_fast16_t AESCCM_control(AESCCM_Handle handle, uint32_t cmd, void *args)
Function performs implementation specific features on a given AESCCM_Handle.
int_fast16_t AESCCM_processPayload(AESCCM_Handle handle, uint8_t *input, size_t length, uint8_t *output)
Function to process the input data in one or more calls.
int_fast16_t AESCCM_getOutput(AESCCM_Handle handle, uint8_t **output, size_t *outputLength, size_t *totalOutputLength)
Returns a pointer to the output (plaintext or ciphertext) and the output length of an AESCCM operatio...
int_fast16_t AESCCM_setupDecrypt(AESCCM_Handle handle, CryptoKey *key, uint8_t *nonce, uint8_t nonceLength, size_t aadTotalLength, size_t ciphertextTotalLength, uint8_t macLength)
Function to set up an AESCCM decryption + verification operation in multiple calls.
int_fast16_t AESCCM_oneStepDecrypt(AESCCM_Handle handle, CryptoKey *key, uint8_t *aad, size_t aadLength, uint8_t *ciphertext, size_t ciphertextLength, uint8_t *nonce, uint8_t nonceLength, uint8_t *mac, uint8_t macLength, uint8_t *plaintext)
Function to perform an AESCCM decryption + verification operation in one call.
int_fast16_t AESCCM_setupEncrypt(AESCCM_Handle handle, CryptoKey *key, uint8_t *nonce, uint8_t nonceLength, size_t aadTotalLength, size_t plaintextTotalLength, uint8_t macLength)
Function to set up an AESCCM encryption + authentication operation in multiple calls.
void AESCCM_init(void)
This function initializes the CCM module.
uint32_t timeout
Definition: AESCCM.h:514
int_fast16_t AESCCM_getMode(AESCCM_Handle handle, AESCCM_Mode *mode)
Returns the AESCCM_Mode of an AESCCM operation in progress.
AESCCM Global configuration.
Definition: AESCCM.h:533
Definition: AESCCM.h:495
AESCCM_CallbackFxn callbackFxn
Definition: AESCCM.h:509
AESCCM_Mode_
Enum for the direction of the CCM operation.
Definition: AESCCM.h:494
AESCCM_Handle AESCCM_open(uint_least8_t index, AESCCM_Params *params)
This function opens a given CCM peripheral.
Copyright 2017, Texas Instruments Incorporated