RTEMS 6.1-rc2
Loading...
Searching...
No Matches
fsl_dcp.h
1/*
2 * Copyright 2017-2020 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef _FSL_DCP_H_
10#define _FSL_DCP_H_
11
12#include "fsl_common.h"
13
14/*******************************************************************************
15 * Definitions
16 *******************************************************************************/
17
58#define FSL_DCP_DRIVER_VERSION (MAKE_VERSION(2, 1, 6))
63{
65};
66
70typedef enum _dcp_ch_enable
71{
79
84{
91
95typedef enum _dcp_channel
96{
97 kDCP_Channel0 = (1u << 16),
98 kDCP_Channel1 = (1u << 17),
99 kDCP_Channel2 = (1u << 18),
100 kDCP_Channel3 = (1u << 19),
102
106typedef enum _dcp_key_slot
107{
116
120typedef enum _dcp_swap
121{
122 kDCP_NoSwap = 0x0U,
123 kDCP_KeyByteSwap = 0x40000U,
124 kDCP_KeyWordSwap = 0x80000U,
125 kDCP_InputByteSwap = 0x100000U,
126 kDCP_InputWordSwap = 0x200000U,
127 kDCP_OutputByteSwap = 0x400000U,
128 kDCP_OutputWordSwap = 0x800000U,
130
132typedef struct _dcp_work_packet
133{
134 uint32_t nextCmdAddress;
135 uint32_t control0;
136 uint32_t control1;
137 uint32_t sourceBufferAddress;
138 uint32_t destinationBufferAddress;
139 uint32_t bufferSize;
140 uint32_t payloadPointer;
141 uint32_t status;
143
145typedef struct _dcp_handle
146{
149 uint32_t swapConfig;
150 uint32_t keyWord[4];
151 uint32_t iv[4];
153
155typedef struct _dcp_context
156{
157 uint32_t x[208 / sizeof(uint32_t)];
159
161typedef struct _dcp_config
162{
169
172#ifndef DCP_USE_DCACHE
173#define DCP_USE_DCACHE 1
174#endif
175/* 1 - driver supports DCACHE, 0 - drivers does not support DCACHE */
176/* When enable (DCP_USE_DCACHE = 1) Input/output buffers and hash ctx should be in */
177/* non-cached memory or handled properly (Clean & Invalidate DCACHE) */
178
179/*******************************************************************************
180 * AES Definitions
181 *******************************************************************************/
182
189#define DCP_AES_BLOCK_SIZE 16
190 /* end of dcp_driver_aes */
194
195/*******************************************************************************
196 * HASH Definitions
197 ******************************************************************************/
203/* DCP cannot correctly compute hash for message with zero size. When enabled, driver bypases DCP and returns correct
204 * hash value. If you are sure, that the driver will never be called with zero sized message, you can disable this
205 * feature to reduce code size */
206#define DCP_HASH_CAVP_COMPATIBLE
207
210{
215
217#define DCP_SHA_BLOCK_SIZE 128U
218#define DCP_HASH_BLOCK_SIZE DCP_SHA_BLOCK_SIZE
221#define DCP_HASH_CTX_SIZE 64
222
224typedef struct _dcp_hash_ctx_t
225{
226 uint32_t x[DCP_HASH_CTX_SIZE];
228 /* end of dcp_driver_hash */
232
233/*******************************************************************************
234 * API
235 ******************************************************************************/
236#if defined(__cplusplus)
237extern "C" {
238#endif
239
253void DCP_Init(DCP_Type *base, const dcp_config_t *config);
254
262void DCP_Deinit(DCP_Type *base);
263
278
290 /* end of dcp_driver */
294
295/*******************************************************************************
296 * AES API
297 ******************************************************************************/
298
322status_t DCP_AES_SetKey(DCP_Type *base, dcp_handle_t *handle, const uint8_t *key, size_t keySize);
323
338 DCP_Type *base, dcp_handle_t *handle, const uint8_t *plaintext, uint8_t *ciphertext, size_t size);
339
354 DCP_Type *base, dcp_handle_t *handle, const uint8_t *ciphertext, uint8_t *plaintext, size_t size);
355
371 dcp_handle_t *handle,
372 const uint8_t *plaintext,
373 uint8_t *ciphertext,
374 size_t size,
375 const uint8_t iv[16]);
376
392 dcp_handle_t *handle,
393 const uint8_t *ciphertext,
394 uint8_t *plaintext,
395 size_t size,
396 const uint8_t iv[16]);
397 /* end of dcp_driver_aes */
401
421 dcp_handle_t *handle,
422 dcp_work_packet_t *dcpPacket,
423 const uint8_t *plaintext,
424 uint8_t *ciphertext,
425 size_t size);
426
442 dcp_handle_t *handle,
443 dcp_work_packet_t *dcpPacket,
444 const uint8_t *ciphertext,
445 uint8_t *plaintext,
446 size_t size);
447
464 dcp_handle_t *handle,
465 dcp_work_packet_t *dcpPacket,
466 const uint8_t *plaintext,
467 uint8_t *ciphertext,
468 size_t size,
469 const uint8_t *iv);
470
487 dcp_handle_t *handle,
488 dcp_work_packet_t *dcpPacket,
489 const uint8_t *ciphertext,
490 uint8_t *plaintext,
491 size_t size,
492 const uint8_t *iv);
493 /* end of dcp_nonblocking_driver_aes */
497
498/*******************************************************************************
499 * HASH API
500 ******************************************************************************/
501
518
534status_t DCP_HASH_Update(DCP_Type *base, dcp_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize);
535
548status_t DCP_HASH_Finish(DCP_Type *base, dcp_hash_ctx_t *ctx, uint8_t *output, size_t *outputSize);
549
565 dcp_handle_t *handle,
566 dcp_hash_algo_t algo,
567 const uint8_t *input,
568 size_t inputSize,
569 uint8_t *output,
570 size_t *outputSize);
571 /* end of dcp_driver_hash */
575
576#if defined(__cplusplus)
577}
578#endif
579
580#endif /* _FSL_DCP_H_ */
status_t DCP_AES_SetKey(DCP_Type *base, dcp_handle_t *handle, const uint8_t *key, size_t keySize)
Set AES key to dcp_handle_t struct and optionally to DCP.
Definition: fsl_dcp.c:316
status_t DCP_AES_DecryptCbc(DCP_Type *base, dcp_handle_t *handle, const uint8_t *ciphertext, uint8_t *plaintext, size_t size, const uint8_t iv[16])
Decrypts AES using CBC block mode.
Definition: fsl_dcp.c:686
status_t DCP_AES_EncryptEcb(DCP_Type *base, dcp_handle_t *handle, const uint8_t *plaintext, uint8_t *ciphertext, size_t size)
Encrypts AES on one or multiple 128-bit block(s).
Definition: fsl_dcp.c:379
status_t DCP_AES_EncryptCbc(DCP_Type *base, dcp_handle_t *handle, const uint8_t *plaintext, uint8_t *ciphertext, size_t size, const uint8_t iv[16])
Encrypts AES using CBC block mode.
Definition: fsl_dcp.c:575
status_t DCP_AES_DecryptEcb(DCP_Type *base, dcp_handle_t *handle, const uint8_t *ciphertext, uint8_t *plaintext, size_t size)
Decrypts AES on one or multiple 128-bit block(s).
Definition: fsl_dcp.c:477
status_t DCP_HASH(DCP_Type *base, dcp_handle_t *handle, dcp_hash_algo_t algo, const uint8_t *input, size_t inputSize, uint8_t *output, size_t *outputSize)
Create HASH on given data.
Definition: fsl_dcp.c:1435
status_t DCP_HASH_Update(DCP_Type *base, dcp_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize)
Add data to current HASH.
Definition: fsl_dcp.c:1253
status_t DCP_HASH_Finish(DCP_Type *base, dcp_hash_ctx_t *ctx, uint8_t *output, size_t *outputSize)
Finalize hashing.
Definition: fsl_dcp.c:1323
enum _dcp_hash_algo_t dcp_hash_algo_t
Supported cryptographic block cipher functions for HASH creation.
#define DCP_HASH_CTX_SIZE
DCP HASH Context size.
Definition: fsl_dcp.h:221
_dcp_hash_algo_t
Supported cryptographic block cipher functions for HASH creation.
Definition: fsl_dcp.h:210
struct _dcp_hash_ctx_t dcp_hash_ctx_t
Storage type used to save hash context.
status_t DCP_HASH_Init(DCP_Type *base, dcp_handle_t *handle, dcp_hash_ctx_t *ctx, dcp_hash_algo_t algo)
Initialize HASH context.
Definition: fsl_dcp.c:1201
@ kDCP_Crc32
Definition: fsl_dcp.h:213
@ kDCP_Sha1
Definition: fsl_dcp.h:211
@ kDCP_Sha256
Definition: fsl_dcp.h:212
void DCP_Deinit(DCP_Type *base)
Disable DCP clock.
Definition: fsl_dcp.c:852
_dcp_channel
DCP channel selection.
Definition: fsl_dcp.h:96
status_t DCP_WaitForChannelComplete(DCP_Type *base, dcp_handle_t *handle)
Poll and wait on DCP channel.
Definition: fsl_dcp.c:872
bool enableContextSwitching
Definition: fsl_dcp.h:165
void DCP_GetDefaultConfig(dcp_config_t *config)
Gets the default configuration structure.
Definition: fsl_dcp.c:795
uint8_t enableChannel
Definition: fsl_dcp.h:166
enum _dcp_ch_int_enable _dcp_ch_int_enable_t
DCP interrupt enable.
dcp_key_slot_t keySlot
Definition: fsl_dcp.h:148
_dcp_status
DCP status return codes.
Definition: fsl_dcp.h:63
enum _dcp_channel dcp_channel_t
DCP channel selection.
_dcp_ch_int_enable
DCP interrupt enable.
Definition: fsl_dcp.h:84
struct _dcp_work_packet dcp_work_packet_t
DCP's work packet.
struct _dcp_handle dcp_handle_t
Specify DCP's key resource and DCP channel.
enum _dcp_key_slot dcp_key_slot_t
DCP key slot selection.
dcp_channel_t channel
Definition: fsl_dcp.h:147
bool gatherResidualWrites
Definition: fsl_dcp.h:163
enum _dcp_swap dcp_swap_t
DCP key, input & output swap options.
void DCP_Init(DCP_Type *base, const dcp_config_t *config)
Enables clock to and enables DCP.
Definition: fsl_dcp.c:820
struct _dcp_config dcp_config_t
DCP's configuration structure.
_dcp_ch_enable
DCP channel enable.
Definition: fsl_dcp.h:71
uint32_t swapConfig
Definition: fsl_dcp.h:149
struct _dcp_context dcp_context_t
DCP's context buffer, used by DCP for context switching between channels.
_dcp_key_slot
DCP key slot selection.
Definition: fsl_dcp.h:107
enum _dcp_ch_enable _dcp_ch_enable_t
DCP channel enable.
_dcp_swap
DCP key, input & output swap options.
Definition: fsl_dcp.h:121
bool enableContextCaching
Definition: fsl_dcp.h:164
uint8_t enableChannelInterrupt
Definition: fsl_dcp.h:167
@ kDCP_Channel2
Definition: fsl_dcp.h:99
@ kDCP_Channel0
Definition: fsl_dcp.h:97
@ kDCP_Channel3
Definition: fsl_dcp.h:100
@ kDCP_Channel1
Definition: fsl_dcp.h:98
@ kStatus_DCP_Again
Definition: fsl_dcp.h:64
@ kDCP_ch1IntEnable
Definition: fsl_dcp.h:87
@ kDCP_ch2IntEnable
Definition: fsl_dcp.h:88
@ kDCP_ch0IntEnable
Definition: fsl_dcp.h:86
@ kDCP_ch3IntEnable
Definition: fsl_dcp.h:89
@ kDCP_chIntDisable
Definition: fsl_dcp.h:85
@ kDCP_chDisable
Definition: fsl_dcp.h:72
@ kDCP_ch0Enable
Definition: fsl_dcp.h:73
@ kDCP_ch3Enable
Definition: fsl_dcp.h:76
@ kDCP_ch2Enable
Definition: fsl_dcp.h:75
@ kDCP_chEnableAll
Definition: fsl_dcp.h:77
@ kDCP_ch1Enable
Definition: fsl_dcp.h:74
@ kDCP_OtpUniqueKey
Definition: fsl_dcp.h:113
@ kDCP_PayloadKey
Definition: fsl_dcp.h:114
@ kDCP_KeySlot0
Definition: fsl_dcp.h:108
@ kDCP_KeySlot1
Definition: fsl_dcp.h:109
@ kDCP_OtpKey
Definition: fsl_dcp.h:112
@ kDCP_KeySlot3
Definition: fsl_dcp.h:111
@ kDCP_KeySlot2
Definition: fsl_dcp.h:110
status_t DCP_AES_DecryptCbcNonBlocking(DCP_Type *base, dcp_handle_t *handle, dcp_work_packet_t *dcpPacket, const uint8_t *ciphertext, uint8_t *plaintext, size_t size, const uint8_t *iv)
Decrypts AES using CBC block mode.
Definition: fsl_dcp.c:733
status_t DCP_AES_EncryptCbcNonBlocking(DCP_Type *base, dcp_handle_t *handle, dcp_work_packet_t *dcpPacket, const uint8_t *plaintext, uint8_t *ciphertext, size_t size, const uint8_t *iv)
Encrypts AES using CBC block mode.
Definition: fsl_dcp.c:622
status_t DCP_AES_DecryptEcbNonBlocking(DCP_Type *base, dcp_handle_t *handle, dcp_work_packet_t *dcpPacket, const uint8_t *ciphertext, uint8_t *plaintext, size_t size)
Decrypts AES using ECB block mode.
Definition: fsl_dcp.c:519
status_t DCP_AES_EncryptEcbNonBlocking(DCP_Type *base, dcp_handle_t *handle, dcp_work_packet_t *dcpPacket, const uint8_t *plaintext, uint8_t *ciphertext, size_t size)
Encrypts AES using the ECB block mode.
Definition: fsl_dcp.c:421
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:225
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:47
@ kStatusGroup_DCP
Definition: fsl_common.h:139
Definition: MIMXRT1052.h:12361
DCP's configuration structure.
Definition: fsl_dcp.h:162
DCP's context buffer, used by DCP for context switching between channels.
Definition: fsl_dcp.h:156
Specify DCP's key resource and DCP channel.
Definition: fsl_dcp.h:146
Storage type used to save hash context.
Definition: fsl_dcp.h:225
DCP's work packet.
Definition: fsl_dcp.h:133
Definition: deflate.c:114