LPCOpen Platform for LPC18XX/43XX microcontrollers: C:/w/lpcopen_docs/software/lpc_core/lpc_chip/chip_18xx_43xx/aes_18xx_43xx.c Source File

| LPCOpen Platform for LPC18XX/43XX microcontrollers 18XX43XX LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

aes_18xx_43xx.c
Go to the documentation of this file.
1 /*
2 * @brief LPC18xx/43xx AES Engine driver
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * All rights reserved.
7 *
8 * @par
9 * Software that is described herein is for illustrative purposes only
10 * which provides customers with programming information regarding the
11 * LPC products. This software is supplied "AS IS" without any warranties of
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
13 * all warranties, express or implied, including all implied warranties of
14 * merchantability, fitness for a particular purpose and non-infringement of
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
16 * or liability for the use of the software, conveys no license or rights under any
17 * patent, copyright, mask work right, or any other intellectual property rights in
18 * or to any products. NXP Semiconductors reserves the right to make changes
19 * in the software without notification. NXP Semiconductors also makes no
20 * representation or warranty that such application will be suitable for the
21 * specified use without further testing or modification.
22 *
23 * @par
24 * Permission to use, copy, modify, and distribute this software and its
25 * documentation is hereby granted, under NXP Semiconductors' and its
26 * licensor's relevant copyrights in the software, without fee, provided that it
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
28 * copyright, permission, and disclaimer notice must appear in all copies of
29 * this code.
30 */
31
32 #include "chip.h"
33
34 /*****************************************************************************
35 * Private types/enumerations/variables
36 ****************************************************************************/
37
38 #define BOOTROM_BASE 0x10400100
39 #define AES_API_TABLE_OFFSET 0x2
40
41 typedef void (*V_FP_V)(void);
42 typedef uint32_t (*U32_FP_V)(void);
43
44 static unsigned long *BOOTROM_API_TABLE;
45
46 /*****************************************************************************
47 * Public types/enumerations/variables
48 ****************************************************************************/
49
50 /*****************************************************************************
51 * Private functions
52 ****************************************************************************/
53
54 static uint32_t (*aes_SetMode)(CHIP_AES_OP_MODE_T AesMode);
55 static void (*aes_LoadKey1)(void);
56 static void (*aes_LoadKey2)(void);
57 static void (*aes_LoadKeyRNG)(void);
58 static void (*aes_LoadKeySW)(uint8_t *pKey);
59 static void (*aes_LoadIV_SW)(uint8_t *pVector);
60 static void (*aes_LoadIV_IC)(void);
61 static uint32_t (*aes_Operate)(uint8_t *pDatOut, uint8_t *pDatIn, uint32_t size);
62 static uint32_t (*aes_ProgramKey1)(uint8_t *pKey);
63 static uint32_t (*aes_ProgramKey2)(uint8_t *pKey);
64 static uint32_t (*aes_Config_DMA) (uint32_t channel_id);
65 static uint32_t (*aes_Operate_DMA)(uint32_t channel_id, uint8_t *dataOutAddr, uint8_t *dataInAddr, uint32_t size);
66 static uint32_t (*aes_Get_Status_DMA) (uint32_t channel_id);
67
68 /*****************************************************************************
69 * Public functions
70 ****************************************************************************/
71
72 /* CHIP AES Initialisation function */
73 void Chip_AES_Init(void)
74 {
75 uint32_t (*ROM_aes_Init)(void);
76
77 BOOTROM_API_TABLE = *((unsigned long * *) BOOTROM_BASE + AES_API_TABLE_OFFSET);
78
79 ROM_aes_Init = (uint32_t (*)(void))BOOTROM_API_TABLE[0];
80 aes_SetMode = (uint32_t (*)(CHIP_AES_OP_MODE_T AesMode))BOOTROM_API_TABLE[1];
81 aes_LoadKey1 = (void (*)(void))BOOTROM_API_TABLE[2];
82 aes_LoadKey2 = (void (*)(void))BOOTROM_API_TABLE[3];
83 aes_LoadKeyRNG = (void (*)(void))BOOTROM_API_TABLE[4];
84 aes_LoadKeySW = (void (*)(uint8_t *pKey))BOOTROM_API_TABLE[5];
85 aes_LoadIV_SW = (void (*)(uint8_t *pVector))BOOTROM_API_TABLE[6];
86 aes_LoadIV_IC = (void (*)(void))BOOTROM_API_TABLE[7];
87 aes_Operate = (uint32_t (*)(uint8_t *pDatOut, uint8_t *pDatIn, uint32_t Size))BOOTROM_API_TABLE[8];
88 aes_ProgramKey1 = (uint32_t (*)(uint8_t *pKey))BOOTROM_API_TABLE[9];
89 aes_ProgramKey2 = (uint32_t (*)(uint8_t *pKey))BOOTROM_API_TABLE[10];
90 aes_Config_DMA = (uint32_t (*)(uint32_t channel_id))BOOTROM_API_TABLE[11];
91 aes_Operate_DMA = (uint32_t (*)(uint32_t channel_id, uint8_t *dataOutAddr, uint8_t *dataInAddr, uint32_t size))BOOTROM_API_TABLE[12];
92 aes_Get_Status_DMA = (uint32_t (*) (uint32_t channel_id))BOOTROM_API_TABLE[13];
93
94 ROM_aes_Init();
95 }
96
97 /* Set Operation mode in AES Engine */
98 uint32_t Chip_AES_SetMode(CHIP_AES_OP_MODE_T AesMode)
99 {
100 return aes_SetMode(AesMode);
101 }
102
103 /* Load 128-bit user key in AES Engine */
104 void Chip_AES_LoadKey(uint32_t keyNum)
105 {
106 if (keyNum) {
107 aes_LoadKey2();
108 }
109 else {
110 aes_LoadKey1();
111 }
112 }
113
114 /* Load randomly generated key in AES engine */
115 void Chip_AES_LoadKeyRNG(void)
116 {
117 aes_LoadKeyRNG();
118 }
119
120 /* Load 128-bit AES software defined user key */
121 void Chip_AES_LoadKeySW(uint8_t *pKey)
122 {
123 aes_LoadKeySW(pKey);
124 }
125
126 /* Load 128-bit AES initialization vector */
127 void Chip_AES_LoadIV_SW(uint8_t *pVector)
128 {
129 aes_LoadIV_SW(pVector);
130 }
131
132 /* Load IC specific 128-bit AES initialization vector */
133 void Chip_AES_LoadIV_IC(void)
134 {
135 aes_LoadIV_IC();
136 }
137
138 /* Operate AES Engine */
139 uint32_t Chip_AES_Operate(uint8_t *pDatOut, uint8_t *pDatIn, uint32_t Size)
140 {
141 return aes_Operate(pDatOut, pDatIn, Size);
142 }
143
144 /* Program 128-bit AES Key in OTP */
145 uint32_t Chip_AES_ProgramKey(uint32_t KeyNum, uint8_t *pKey)
146 {
147 uint32_t status;
148
149 if (KeyNum) {
150 status = aes_ProgramKey2(pKey);
151 }
152 else {
153 status = aes_ProgramKey1(pKey);
154 }
155 return status;
156 }
157
158 /* Configure DMA channel to process AES block */
159 uint32_t Chip_AES_Config_DMA(uint32_t channel_id)
160 {
161 return aes_Config_DMA(channel_id);
162 }
163
164 /* Enables DMA channel and Operates AES Engine */
165 uint32_t Chip_AES_OperateDMA(uint32_t channel_id, uint8_t *dataOutAddr, uint8_t *dataInAddr, uint32_t size)
166 {
167 return aes_Operate_DMA(channel_id,dataOutAddr,dataInAddr,size);
168 }
169
170 /* Read status of DMA channels that process an AES data block. */
171 uint32_t Chip_AES_GetStatusDMA(uint32_t channel_id)
172 {
173 return aes_Get_Status_DMA(channel_id);
174 }