pic32mz_crypto.h
Go to the documentation of this file.
1 /**
2  * @file pic32mz_crypto.h
3  * @brief PIC32MZ hardware cryptographic accelerator
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _PIC32MZ_CRYPTO_H
32 #define _PIC32MZ_CRYPTO_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //DMA buffer size
38 #ifndef PIC32MZ_CRYPTO_BUFFER_SIZE
39  #define PIC32MZ_CRYPTO_BUFFER_SIZE 1024
40 #elif (PIC32MZ_CRYPTO_BUFFER_SIZE < 64)
41  #error PIC32MZ_CRYPTO_BUFFER_SIZE parameter is not valid
42 #endif
43 
44 //BD_CTRL format
45 #define BD_CTRL_DESC_EN 0x80000000
46 #define BD_CTRL_CRY_MODE 0x38000000
47 #define BD_CTRL_CRY_MODE_NORMAL 0x00000000
48 #define BD_CTRL_CRY_MODE_PREBOOT_AUTH 0x08000000
49 #define BD_CTRL_CRY_MODE_KEK 0x10000000
50 #define BD_CTRL_CRY_MODE_CEK 0x18000000
51 #define BD_CTRL_SA_FETCH_EN 0x00400000
52 #define BD_CTRL_LAST_BD 0x00080000
53 #define BD_CTRL_LIFM 0x00040000
54 #define BD_CTRL_PKT_INT_EN 0x00020000
55 #define BD_CTRL_CBD_INT_EN 0x00010000
56 #define BD_CTRL_BD_BUFLEN 0x0000FFFF
57 
58 //SA_CTRL format
59 #define SA_CTRL_VERIFY 0x20000000
60 #define SA_CTRL_NO_RX 0x08000000
61 #define SA_CTRL_OR_EN 0x04000000
62 #define SA_CTRL_ICVONLY 0x02000000
63 #define SA_CTRL_IRFLAG 0x01000000
64 #define SA_CTRL_LNC 0x00800000
65 #define SA_CTRL_LOADIV 0x00400000
66 #define SA_CTRL_FB 0x00200000
67 #define SA_CTRL_FLAGS 0x00100000
68 #define SA_CTRL_ALGO 0x0001FC00
69 #define SA_CTRL_ALGO_DES 0x00000400
70 #define SA_CTRL_ALGO_TDES 0x00000800
71 #define SA_CTRL_ALGO_AES 0x00001000
72 #define SA_CTRL_ALGO_MD5 0x00002000
73 #define SA_CTRL_ALGO_SHA1 0x00004000
74 #define SA_CTRL_ALGO_SHA256 0x00008000
75 #define SA_CTRL_ALGO_HMAC 0x00010000
76 #define SA_CTRL_ENC 0x00000200
77 #define SA_CTRL_KEYSIZE 0x00000180
78 #define SA_CTRL_KEYSIZE_128 0x00000000
79 #define SA_CTRL_KEYSIZE_192 0x00000080
80 #define SA_CTRL_KEYSIZE_256 0x00000100
81 #define SA_CTRL_MULTITASK 0x00000070
82 #define SA_CTRL_MULTITASK_NO_PASS 0x00000000
83 #define SA_CTRL_MULTITASK_PIPE_PASS 0x00000050
84 #define SA_CTRL_MULTITASK_PARALLEL_PASS 0x00000070
85 #define SA_CTRL_CRYPTOALGO 0x0000000F
86 #define SA_CTRL_CRYPTOALGO_ECB 0x00000000
87 #define SA_CTRL_CRYPTOALGO_CBC 0x00000001
88 #define SA_CTRL_CRYPTOALGO_CFB 0x00000002
89 #define SA_CTRL_CRYPTOALGO_OFB 0x00000003
90 #define SA_CTRL_CRYPTOALGO_TECB 0x00000004
91 #define SA_CTRL_CRYPTOALGO_TCBC 0x00000005
92 #define SA_CTRL_CRYPTOALGO_TCFB 0x00000006
93 #define SA_CTRL_CRYPTOALGO_TOFB 0x00000007
94 #define SA_CTRL_CRYPTOALGO_RECB 0x00000008
95 #define SA_CTRL_CRYPTOALGO_RCBC 0x00000009
96 #define SA_CTRL_CRYPTOALGO_RCFB 0x0000000A
97 #define SA_CTRL_CRYPTOALGO_ROFB 0x0000000B
98 #define SA_CTRL_CRYPTOALGO_RCBC_MAC 0x0000000C
99 #define SA_CTRL_CRYPTOALGO_RCTR 0x0000000D
100 #define SA_CTRL_CRYPTOALGO_AES_GCM 0x0000000E
101 
102 //C++ guard
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
107 
108 /**
109  * @brief Buffer description
110  **/
111 
112 typedef struct {
113  uint32_t BD_CTRL;
114  uint32_t SA_ADDR;
115  uint32_t SRCADDR;
116  uint32_t DSTADDR;
117  uint32_t NXTPTR;
118  uint32_t UPDPTR;
119  uint32_t MSG_LEN;
120  uint32_t ENC_OFF;
122 
123 
124 /**
125  * @brief Security association
126  **/
127 
128 typedef struct {
129  uint32_t SA_CTRL;
130  uint32_t SA_AUTHKEY[8];
131  uint32_t SA_ENCKEY[8];
132  uint32_t SA_AUTHIV[8];
133  uint32_t SA_ENCIV[8];
135 
136 
137 //Global variables
139 
140 //PIC32MZ hardware cryptographic accelerator related functions
142 
143 //C++ guard
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif
OsMutex pic32mzCryptoMutex
Security association.
error_t
Error codes.
Definition: error.h:43
General definitions for cryptographic algorithms.
Mutex object.
error_t pic32mzCryptoInit(void)
Initialize hardware cryptographic accelerator.
Buffer description.