Mistake on this page?
Report an issue in GitHub or email us
sec_main.h
Go to the documentation of this file.
1 /*************************************************************************************************/
2 /*!
3  * \file
4  *
5  * \brief Internal security service structures.
6  *
7  * Copyright (c) 2010-2019 Arm Ltd. All Rights Reserved.
8  *
9  * Copyright (c) 2019 Packetcraft, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 /*************************************************************************************************/
24 #ifndef SEC_MAIN_H
25 #define SEC_MAIN_H
26 
27 #include "hci_api.h"
28 #include "pal_crypto.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**************************************************************************************************
35  Macros
36 **************************************************************************************************/
37 
38 
39 /*! AES, CMAC and HCI algorithm block length */
40 #define SEC_BLOCK_LEN 16
41 
42 /* CMAC constant Rb */
43 #define SEC_CMAC_RB 0x87
44 
45 /*! Number or random bytes to keep in the secCb_t rand data buffer */
46 #define SEC_RAND_DATA_LEN 32
47 
48 /*! Multiple of HCI_RAND_LEN kept in the secCb_t rand data buffer */
49 #define SEC_HCI_RAND_MULT (SEC_RAND_DATA_LEN / HCI_RAND_LEN)
50 
51 /*! Compile time ECC configuration */
52 #define SEC_ECC_CFG_DEBUG 0
53 #define SEC_ECC_CFG_UECC 1
54 #define SEC_ECC_CFG_HCI 2
55 
56 /*! Compile time CMAC configuration */
57 #define SEC_CMAC_CFG_PLATFORM 0
58 #define SEC_CMAC_CFG_HCI 1
59 
60 /*! Compile time CCM configuration */
61 #define SEC_CCM_CFG_PLATFORM 0
62 #define SEC_CCM_CFG_HCI 1
63 
64 /*! CCM Operation (Encryption or Decryption) */
65 #define SEC_CCM_OP_ENCRYPT 0
66 #define SEC_CCM_OP_DECRYPT 1
67 
68 /**************************************************************************************************
69  Data Types
70 **************************************************************************************************/
71 
72 /*! Enumeration of security operation types */
73 enum
74 {
75  SEC_TYPE_AES,
76  SEC_TYPE_CMAC,
77  SEC_TYPE_DH,
78  SEC_TYPE_CCM,
79  SEC_TYPE_AES_REV,
80  SEC_NUM_TYPES
81 };
82 
83 /*! Security queue element for CMAC operations */
84 typedef struct
85 {
86  uint8_t *pPlainText;
87  uint8_t key[SEC_CMAC_KEY_LEN];
88  uint8_t subkey[SEC_CMAC_KEY_LEN];
89  uint16_t position;
90  uint16_t len;
91  wsfHandlerId_t handlerId;
92  uint8_t state;
94 
95 /*! Security queue element for CCM-Mode operations */
96 typedef struct
97 {
98  uint8_t operation;
99  uint8_t *pText;
100  uint8_t *pClear;
101  uint8_t *pRcvMic;
102  uint16_t textLen;
103  uint16_t clearLen;
104  uint8_t micLen;
105  uint8_t key[SEC_CCM_KEY_LEN];
106  uint8_t scratch[SEC_BLOCK_LEN];
107  uint16_t counter;
108  uint16_t position;
109  wsfHandlerId_t handlerId;
110  uint8_t state;
111  uint8_t *pWorking;
112 } secCcmSecCb_t;
113 
114 /*! Security queue element */
115 typedef struct
116 {
117  secMsg_t msg;
118  uint8_t ciphertext[SEC_BLOCK_LEN];
119  uint8_t reserved[SEC_BLOCK_LEN];
120  void *pCb;
121  uint8_t type;
122 } secQueueBuf_t;
123 
124 typedef void secHciCback_t(secQueueBuf_t *pBuf, hciEvt_t *pEvent, wsfHandlerId_t handlerId);
125 typedef secHciCback_t *pSecHciCback_t;
126 
127 /* Control block */
128 typedef struct
129 {
130  uint8_t rand[SEC_RAND_DATA_LEN]; /* Random data buffer */
131  wsfQueue_t aesEncQueue; /* Queue for AES encrypt requests */
132  wsfQueue_t pubKeyQueue; /* Queue for read p256 public key requests */
133  wsfQueue_t dhKeyQueue; /* Queue for generate dh key requests */
134  uint8_t token; /* Token value */
135  uint8_t randTop; /* Random buffer insert point (HCI_RAND_LEN bytes) */
136  uint8_t randBtm; /* Random buffer copy point (HCI_RAND_LEN bytes) */
137  pSecHciCback_t hciCbackTbl[SEC_NUM_TYPES];
138 } secCb_t;
139 
140 /**************************************************************************************************
141  Function Declarations
142 **************************************************************************************************/
143 
144 /*************************************************************************************************/
145 /*!
146  * \brief Queue callback and call LE encrypt given most significant byte ordered key and data.
147  *
148  * \param pKey Pointer to key.
149  * \param pText Pointer to text to encrypt.
150  * \param pBuf Pointer to queue block.
151  * \param handlerId Handler ID.
152  *
153  * \return None.
154  */
155 /*************************************************************************************************/
156 void SecLeEncryptCmd(uint8_t *pKey, uint8_t *pText, void *pBuf, wsfHandlerId_t handlerId);
157 
158 #ifdef __cplusplus
159 };
160 #endif
161 
162 #endif /* SEC_MAIN_H */
HCI subsystem API.
#define SEC_CMAC_KEY_LEN
CMAC algorithm key length.
Definition: sec_api.h:41
Generic security callback parameters structure.
Definition: sec_api.h:103
Crypto driver definition.
void SecLeEncryptCmd(uint8_t *pKey, uint8_t *pText, void *pBuf, wsfHandlerId_t handlerId)
Queue callback and call LE encrypt given most significant byte ordered key and data.
uint8_t wsfHandlerId_t
Event handler ID data type.
Definition: wsf_os.h:80
Queue structure.
Definition: wsf_queue.h:46
#define SEC_BLOCK_LEN
Definition: sec_main.h:40
Union of all event types.
Definition: hci_api.h:931
#define SEC_RAND_DATA_LEN
Definition: sec_main.h:46
#define SEC_CCM_KEY_LEN
CCM-Mode algorithm lengths.
Definition: pal_crypto.h:49
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.