MAX32672 Peripheral Driver API
Peripheral Driver API for the MAX32672
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ctb.h
1
6/******************************************************************************
7 *
8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9 * Analog Devices, Inc.),
10 * Copyright (C) 2023-2024 Analog Devices, Inc.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 ******************************************************************************/
25
26#ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_CTB_H_
27#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_CTB_H_
28
29/***** Includes *****/
30#include "ctb_regs.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
42/* IN ADDITION TO THIS HEADER, FCL WILL BE SUPPORTED AND PROVIDED IN BINARY FORM */
43/***** Definitions *****/
44
49typedef void (*mxc_ctb_complete_cb_t)(void *req, int result);
50
55typedef enum {
56 MXC_CTB_FEATURE_DMA = 1 << 0,
57 MXC_CTB_FEATURE_ECC = 1 << 1,
58 MXC_CTB_FEATURE_CRC = 1 << 2,
59 MXC_CTB_FEATURE_HASH = 1 << 4,
60 MXC_CTB_FEATURE_CIPHER = 1 << 5,
61 MXC_CTB_FEATURE_TRNG = 1 << 6
63
64/* ************************************************************************* */
65/* DMA Definitions */
66/* ************************************************************************* */
67
72struct _mxc_ctb_dma_req_t {
73 uint8_t *sourceBuffer;
74 uint8_t *destBuffer;
75 uint32_t length;
77} typedef mxc_ctb_dma_req_t;
78
83typedef enum {
84 MXC_CTB_DMA_READ_FIFO_DMA = MXC_V_CTB_CTRL_RDSRC_DMAORAPB,
85 MXC_CTB_DMA_READ_FIFO_RNG = MXC_V_CTB_CTRL_RDSRC_RNG
87
92typedef enum {
93 MXC_CTB_DMA_WRITE_FIFO_CIPHER = MXC_V_CTB_CTRL_WRSRC_CIPHEROUTPUT,
94 MXC_CTB_DMA_WRITE_FIFO_READ_FIFO = MXC_V_CTB_CTRL_WRSRC_READFIFO,
95 MXC_CTB_DMA_WRITE_FIFO_NONE = MXC_V_CTB_CTRL_WRSRC_NONE
97
98/* ************************************************************************* */
99/* ECC Definitions */
100/* ************************************************************************* */
101
106struct _mxc_ctb_ecc_req_t {
107 uint8_t *dataBuffer;
108 uint32_t dataLen;
109 uint32_t checksum;
110 mxc_ctb_complete_cb_t callback;
111} typedef mxc_ctb_ecc_req_t;
112
117struct _mxc_ctb_crc_req_t {
118 uint8_t *dataBuffer;
119 uint32_t dataLen;
120 uint32_t resultCRC;
121 mxc_ctb_complete_cb_t callback;
122} typedef mxc_ctb_crc_req_t;
123
128typedef enum { MXC_CTB_CRC_LSB_FIRST, MXC_CTB_CRC_MSB_FIRST } mxc_ctb_crc_bitorder_t;
129
130/* ************************************************************************* */
131/* Hash Definitions */
132/* ************************************************************************* */
133
138struct _mxc_ctb_hash_req_t {
139 uint8_t *msg;
140 uint32_t len;
141 uint8_t *hash;
142 mxc_ctb_complete_cb_t callback;
143} typedef mxc_ctb_hash_req_t;
144
149typedef enum {
150 MXC_CTB_HASH_DIS = MXC_V_CTB_HASH_CTRL_HASH_DIS, // Disable
151 MXC_CTB_HASH_SHA1 = MXC_V_CTB_HASH_CTRL_HASH_SHA1, // Select SHA1
152 MXC_CTB_HASH_SHA224 = MXC_V_CTB_HASH_CTRL_HASH_SHA224, // Select SHA224
153 MXC_CTB_HASH_SHA256 = MXC_V_CTB_HASH_CTRL_HASH_SHA256, // Select SHA256
154 MXC_CTB_HASH_SHA384 = MXC_V_CTB_HASH_CTRL_HASH_SHA384, // Select SHA384
155 MXC_CTB_HASH_SHA512 = MXC_V_CTB_HASH_CTRL_HASH_SHA512 // Select SHA384
157
162typedef enum {
163 MXC_CTB_HASH_SOURCE_INFIFO = 0,
164 MXC_CTB_HASH_SOURCE_OUTFIFO = 1
166
167/* ************************************************************************* */
168/* Cipher Definitions */
169/* ************************************************************************* */
170
175struct _mxc_ctb_cipher_req_t {
176 uint8_t *plaintext;
177 uint32_t ptLen;
178 uint8_t *iv;
179 uint8_t *ciphertext;
180 mxc_ctb_complete_cb_t callback;
181} typedef mxc_ctb_cipher_req_t;
182
187typedef enum {
194
199typedef enum {
207
212typedef enum {
213 MXC_CTB_CIPHER_KEY_SOFTWARE = 0,
214 MXC_CTB_CIPHER_KEY_AES_KEY2 = 2,
215 MXC_CTB_CIPHER_KEY_AES_KEY3 = 3
217
222typedef enum { MXC_CTB_CIPHER_ENCRYPTION, MXC_CTB_CIPHER_DECRYPTION } mxc_ctb_cipher_operation_t;
223
224/***** Function Prototypes *****/
225
226/* ************************************************************************* */
227/* Global Control/Configuration functions */
228/* ************************************************************************* */
229
238int MXC_CTB_Init(uint32_t features);
239
246
252
258
265
271void MXC_CTB_DoneClear(uint32_t features);
272
278uint32_t MXC_CTB_Done(void);
279
285void MXC_CTB_Reset(uint32_t features);
286
292
301int MXC_CTB_Shutdown(uint32_t features);
302
309
315
316/************************************/
317/* CTB DMA - Used for all features */
318/************************************/
319
328
336
344
352
360void MXC_CTB_DMA_SetSource(uint8_t *source);
361
367void MXC_CTB_DMA_SetDestination(uint8_t *dest);
368
379
391
398void MXC_CTB_DMA_StartTransfer(uint32_t length);
399
400/* ************************************************************************* */
401/* True Random Number Generator (TRNG) functions */
402/* ************************************************************************* */
403
410
419int MXC_CTB_TRNG_Random(uint8_t *data, uint32_t len);
420
430void MXC_CTB_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_ctb_complete_cb_t callback);
431
432/* ************************************************************************* */
433/* Error Correction Code (ECC) functions */
434/* ************************************************************************* */
435
436/*******************************/
437/* Low Level Functions */
438/*******************************/
439
446
453
460
461/*******************************/
462/* High Level Functions */
463/*******************************/
464
475
486
496
505
506/* ************************************************************************* */
507/* Cyclic Redundancy Check (CRC) functions */
508/* ************************************************************************* */
509
510/*******************************/
511/* Low Level Functions */
512/*******************************/
513
520
527
533void MXC_CTB_CRC_SetPoly(uint32_t poly);
534
540uint32_t MXC_CTB_CRC_GetPoly(void);
541
548
554void MXC_CTB_CRC_SetInitialValue(uint32_t seed);
555
562
563/*******************************/
564/* High Level Functions */
565/*******************************/
566
577
587
588/* ************************************************************************* */
589/* Hash functions */
590/* ************************************************************************* */
591
592/***********************/
593/* Low Level Functions */
594/***********************/
595
604
613
620
627
635
642
649void MXC_CTB_Hash_GetResult(uint8_t *digest, int *len);
650
657void MXC_CTB_Hash_SetMessageSize(uint32_t size);
658
665
672
680
681/************************/
682/* High Level Functions */
683/************************/
684
694
703
704/* ************************************************************************* */
705/* Cipher functions */
706/* ************************************************************************* */
707
708/************************/
709/* Low Level Functions */
710/************************/
711
720
729
736
743
750
757
764
771
777
784
792void MXC_CTB_Cipher_SetKey(uint8_t *key, uint32_t len);
793
800void MXC_CTB_Cipher_SetIV(uint8_t *iv, uint32_t len);
801
808void MXC_CTB_Cipher_GetIV(uint8_t *ivOut, uint32_t len);
809
810/************************/
811/* High Level Functions */
812/************************/
813
823
833
842
851
852#ifdef __cplusplus
853}
854#endif
857#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_CTB_H_
Registers, Bit Masks and Bit Positions for the CTB Peripheral Module.
#define MXC_V_CTB_CIPHER_CTRL_MODE_OFB
Definition: ctb_regs.h:275
#define MXC_V_CTB_CIPHER_CTRL_MODE_CFB
Definition: ctb_regs.h:273
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_TDES
Definition: ctb_regs.h:264
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_AES128
Definition: ctb_regs.h:256
#define MXC_V_CTB_CIPHER_CTRL_MODE_ECB
Definition: ctb_regs.h:269
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_AES256
Definition: ctb_regs.h:260
#define MXC_V_CTB_CIPHER_CTRL_MODE_CTR
Definition: ctb_regs.h:277
#define MXC_V_CTB_CIPHER_CTRL_MODE_CBC
Definition: ctb_regs.h:271
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_DES
Definition: ctb_regs.h:262
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_AES192
Definition: ctb_regs.h:258
#define MXC_V_CTB_CIPHER_CTRL_CIPHER_DIS
Definition: ctb_regs.h:254
#define MXC_V_CTB_CTRL_WRSRC_CIPHEROUTPUT
Definition: ctb_regs.h:188
#define MXC_V_CTB_CTRL_WRSRC_READFIFO
Definition: ctb_regs.h:190
#define MXC_V_CTB_CTRL_RDSRC_DMAORAPB
Definition: ctb_regs.h:197
#define MXC_V_CTB_CTRL_RDSRC_RNG
Definition: ctb_regs.h:199
#define MXC_V_CTB_CTRL_WRSRC_NONE
Definition: ctb_regs.h:186
#define MXC_V_CTB_HASH_CTRL_HASH_SHA224
Definition: ctb_regs.h:312
#define MXC_V_CTB_HASH_CTRL_HASH_SHA512
Definition: ctb_regs.h:318
#define MXC_V_CTB_HASH_CTRL_HASH_SHA256
Definition: ctb_regs.h:314
#define MXC_V_CTB_HASH_CTRL_HASH_DIS
Definition: ctb_regs.h:308
#define MXC_V_CTB_HASH_CTRL_HASH_SHA384
Definition: ctb_regs.h:316
#define MXC_V_CTB_HASH_CTRL_HASH_SHA1
Definition: ctb_regs.h:310
mxc_ctb_complete_cb_t callback
Null callback indicates a blocking operation.
Definition: ctb.h:76
uint8_t * sourceBuffer
pointer to source data
Definition: ctb.h:73
uint8_t * destBuffer
pointer to destination buffer
Definition: ctb.h:74
uint32_t length
length of source data
Definition: ctb.h:75
void MXC_CTB_ECC_Enable(void)
Enable ECC Calculation.
void MXC_CTB_DMA_SetReadSource(mxc_ctb_dma_read_source_t source)
Set the source the DMA reads from.
void MXC_CTB_CRC_ComputeAsync(mxc_ctb_crc_req_t *req)
Perform a CRC computation asynchronously.
uint32_t MXC_CTB_CheckFeatures(void)
Detects what CTB features exist, see mxc_ctb_features_t.
mxc_ctb_cipher_t MXC_CTB_Cipher_GetCipher(void)
Get the cipher type used for cipher operations.
unsigned int MXC_CTB_Cipher_GetBlockSize(mxc_ctb_cipher_t cipher)
Get the block size for a given cipher type.
void MXC_CTB_ECC_Disable(void)
Disable ECC Calculation.
mxc_ctb_hash_func_t MXC_CTB_Hash_GetFunction(void)
Get the algorithm to use for hash computation.
mxc_ctb_crc_bitorder_t MXC_CTB_CRC_GetDirection(void)
Set the bit-order of CRC calculation.
mxc_ctb_dma_write_source_t
Enumeration type to select write source channel of DMA.
Definition: ctb.h:92
mxc_ctb_cipher_key_t MXC_CTB_Cipher_GetKeySource(void)
Get the cipher type used for cipher operations.
void MXC_CTB_DMA_SetDestination(uint8_t *dest)
Set the destination address of the DMA.
int MXC_CTB_Init(uint32_t features)
Enable portions of the CTB.
int MXC_CTB_CRC_Compute(mxc_ctb_crc_req_t *req)
Perform a CRC computation.
void MXC_CTB_Hash_SetSource(mxc_ctb_hash_source_t source)
Set the source of data for the hash computation.
int MXC_CTB_Cipher_Decrypt(mxc_ctb_cipher_req_t *req)
Perform a decryption using the cipher feature.
mxc_ctb_features_t
Enumeration type for Crypto Toolbox features.
Definition: ctb.h:55
uint32_t MXC_CTB_ECC_GetResult(void)
Get the Result of an ECC Calculation.
void MXC_CTB_CRC_SetDirection(mxc_ctb_crc_bitorder_t bitOrder)
Set the bit-order of CRC calculation.
void MXC_CTB_Hash_SetAutoPad(int pad)
Set whether to use automatic padding of the input data.
void MXC_CTB_CRC_SetPoly(uint32_t poly)
Set the Polynomial for CRC calculation.
void MXC_CTB_Hash_InitializeHash(void)
Initialize the hash computation unit.
mxc_ctb_cipher_mode_t MXC_CTB_Cipher_GetMode(void)
Get the block mode used for cipher operations.
int MXC_CTB_ECC_Compute(mxc_ctb_ecc_req_t *req)
Compute the ECC value for a block of data up to 8kB in size.
void MXC_CTB_Cipher_SetOperation(mxc_ctb_cipher_operation_t operation)
Configure for encryption or decryption.
void MXC_CTB_Hash_SetMessageSize(uint32_t size)
Set the size of the data input into the hash computation.
void MXC_CTB_CRC_SetFinalXORValue(uint32_t xor)
Set the value that will be bitwise XORed with the final output from the CRC computation....
void MXC_CTB_Hash_GetResult(uint8_t *digest, int *len)
Get the result of a hash computation.
mxc_ctb_cipher_t
Enumeration type to select Cipher function.
Definition: ctb.h:199
int MXC_CTB_Ready(void)
Checks the global CTB Ready Status.
uint32_t MXC_CTB_CRC_GetPoly(void)
Get the polynomial for CRC calculation.
int MXC_CTB_Cipher_Encrypt(mxc_ctb_cipher_req_t *req)
Perform an encryption using the cipher feature.
void MXC_CTB_DMA_SetSource(uint8_t *source)
Set the source address of the DMA.
uint32_t MXC_CTB_GetEnabledFeatures(void)
Check which CTB features are enabled.
void MXC_CTB_Cipher_SetMode(mxc_ctb_cipher_mode_t mode)
Set the block mode used for cipher operations.
unsigned int MXC_CTB_Cipher_GetKeySize(mxc_ctb_cipher_t cipher)
Get the key size for a given cipher type.
void MXC_CTB_Hash_ComputeAsync(mxc_ctb_hash_req_t *req)
Compute a Hash Digest.
int MXC_CTB_ECC_ErrorCheck(mxc_ctb_ecc_req_t *req)
Check for single or dual bit errors in a block of data.
void MXC_CTB_Cipher_SetCipher(mxc_ctb_cipher_t cipher)
Set the cipher type used for cipher operations.
int MXC_CTB_DMA_SetupOperation(mxc_ctb_dma_req_t *req)
Set the source and destination addresses of the DMA.
mxc_ctb_hash_source_t MXC_CTB_Hash_GetSource(void)
Get the source of data for the hash computation.
void MXC_CTB_DMA_SetWriteSource(mxc_ctb_dma_write_source_t source)
Set the source the DMA write fifo reads from.
int MXC_CTB_TRNG_Random(uint8_t *data, uint32_t len)
Get a random number of length len.
void MXC_CTB_Cipher_GetIV(uint8_t *ivOut, uint32_t len)
Get the initial value used for cipher operations.
void MXC_CTB_Cipher_SetKeySource(mxc_ctb_cipher_key_t source)
Set the source of the key used in cipher operations.
mxc_ctb_cipher_operation_t
Cipher operation.
Definition: ctb.h:222
void MXC_CTB_Handler(void)
This function should be called from the CTB ISR Handler when using Async functions.
mxc_ctb_cipher_mode_t
Enumeration type to select Cipher mode.
Definition: ctb.h:187
mxc_ctb_dma_read_source_t
Enumeration type to select read source channel of DMA.
Definition: ctb.h:83
void MXC_CTB_Cipher_SetKey(uint8_t *key, uint32_t len)
Set the cipher key.
int MXC_CTB_DMA_DoOperation(mxc_ctb_dma_req_t *req)
Start a DMA transfer defined by the request object Blocks until completion.
uint32_t MXC_CTB_Done(void)
Returns CTB features showing operations complete, see mxc_ctb_features_t.
void MXC_CTB_Cipher_SetIV(uint8_t *iv, uint32_t len)
Set the initial value used for cipher operations.
mxc_ctb_hash_source_t
Enumeration type to select FIFO source for Hash.
Definition: ctb.h:162
void MXC_CTB_DMA_StartTransfer(uint32_t length)
Start a DMA transfer of fixed size.
int MXC_CTB_Hash_Compute(mxc_ctb_hash_req_t *req)
Compute a Hash Digest.
void MXC_CTB_CRC_SetInitialValue(uint32_t seed)
Set the intial value used (the seed) when starting a CRC computation.
void MXC_CTB_ECC_ErrorCheckAsync(mxc_ctb_ecc_req_t *req)
Check for single or dual bit errors in a block of data.
void MXC_CTB_DoneClear(uint32_t features)
Clears the selected feature's done bits, see mxc_ctb_features_t.
int MXC_CTB_Hash_GetAutoPad(void)
Get whether to use automatic padding of the input data.
mxc_ctb_cipher_key_t
Enumeration type to select Cipher key.
Definition: ctb.h:212
mxc_ctb_dma_write_source_t MXC_CTB_DMA_GetWriteSource(void)
Set the source the DMA write fifo reads from.
void MXC_CTB_DisableInt(void)
Disable CTB Interrupts.
mxc_ctb_crc_bitorder_t
CRC data bit order.
Definition: ctb.h:128
uint32_t MXC_CTB_CRC_GetResult(void)
Get the result of a CRC calculation.
void MXC_CTB_CacheInvalidate(void)
Invalidates the CTB's internal cache.
unsigned int MXC_CTB_Hash_GetDigestSize(mxc_ctb_hash_func_t function)
Get the digest size for a given hash function.
void(* mxc_ctb_complete_cb_t)(void *req, int result)
Callback funtion for ctb.
Definition: ctb.h:49
void MXC_CTB_EnableInt(void)
Enable CTB Interrupts.
mxc_ctb_dma_read_source_t MXC_CTB_DMA_GetReadSource(void)
Get the source the DMA reads from.
void MXC_CTB_Cipher_LoadKey(void)
Load the cipher key from the selected source.
int MXC_CTB_Shutdown(uint32_t features)
Disable and reset portions of the CTB.
void MXC_CTB_Cipher_EncryptAsync(mxc_ctb_cipher_req_t *req)
Perform an encryption using the cipher feature.
int MXC_CTB_TRNG_RandomInt(void)
Get a random number.
void MXC_CTB_TRNG_RandomAsync(uint8_t *data, uint32_t len, mxc_ctb_complete_cb_t callback)
Get a random number of length len, do not block while generating data.
void MXC_CTB_Reset(uint32_t features)
Resets the selected features, see mxc_ctb_features_t.
unsigned int MXC_CTB_Hash_GetBlockSize(mxc_ctb_hash_func_t function)
Get the block size for a given hash function.
void MXC_CTB_Hash_SetFunction(mxc_ctb_hash_func_t function)
Set the algorithm to use for hash computation.
void MXC_CTB_ECC_ComputeAsync(mxc_ctb_ecc_req_t *req)
Compute the ECC value for a block of data up to 8kB in size.
void MXC_CTB_Cipher_DecryptAsync(mxc_ctb_cipher_req_t *req)
Perform a decryption using the cipher feature.
mxc_ctb_hash_func_t
Enumeration type to select Hash function.
Definition: ctb.h:149
@ MXC_CTB_CIPHER_DIS
Disable.
Definition: ctb.h:200
@ MXC_CTB_CIPHER_AES128
Select AES-128.
Definition: ctb.h:201
@ MXC_CTB_CIPHER_AES256
Select AES-256.
Definition: ctb.h:203
@ MXC_CTB_CIPHER_AES192
Select AES-192.
Definition: ctb.h:202
@ MXC_CTB_CIPHER_DES
Select DES.
Definition: ctb.h:204
@ MXC_CTB_CIPHER_TDES
Select TDES.
Definition: ctb.h:205
@ MXC_CTB_MODE_ECB
Electronic Code Book.
Definition: ctb.h:188
@ MXC_CTB_MODE_CTR
Counter.
Definition: ctb.h:191
@ MXC_CTB_MODE_CBC
Cipher Block Chaining.
Definition: ctb.h:189
@ MXC_CTB_MODE_OFB
Output Feedback.
Definition: ctb.h:192
@ MXC_CTB_MODE_CFB
Cipher Feedback.
Definition: ctb.h:190
Structure used to set up Cipher request.
Definition: ctb.h:175
Structure used to set up CRC request.
Definition: ctb.h:117
Structure for using DMA with CTB.
Definition: ctb.h:72
Structure used to set up ECC request.
Definition: ctb.h:106
Structure used to set up Hash request.
Definition: ctb.h:138