mbed TLS v2.2.0
slcl_device.h
Go to the documentation of this file.
1 /*
2  * \file slcl_device.h
3  *
4  * \brief Silicon Labs CRYPTO/AES device interface
5  *
6  * \details This file defines the CRYPTO/AES device driver interface
7  * including per device contexts, preemption contexts, and
8  * user callbacks for events associated with device preemption
9  * and device busy.
10  *
11  * Copyright (C) 2016 Silicon Labs, http://www.silabs.com
12  * SPDX-License-Identifier: Apache-2.0
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License"); you may
15  * not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  */
26 #ifndef MBEDTLS_SLCL_DEVICE_H
27 #define MBEDTLS_SLCL_DEVICE_H
28 
29 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include "config.h"
31 #else
32 #include MBEDTLS_CONFIG_FILE
33 #endif
34 
35 #include "em_device.h"
36 
37 #if ( defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) ) || \
38  ( defined(AES_COUNT) && (AES_COUNT > 0) )
39 
40 #include "mbedtls_ecode.h"
41 #include "slpal.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /*******************************************************************************
48  ******************************* DEFINES **********************************
49  ******************************************************************************/
50 
51 /* Error codes: */
52 #define MBEDTLS_ERR_DEVICE_NOT_SUPPORTED ((int)MBEDTLS_ERR_DEVICE_BASE | 0x1)
53 
54 /* Device counts supported. */
55 #if defined(AES_COUNT) && (AES_COUNT > 0)
56 #define MBEDTLS_DEVICE_COUNT AES_COUNT
57 #endif
58 #if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0)
59 #define MBEDTLS_DEVICE_COUNT CRYPTO_COUNT
60 #endif
61 
62 /*******************************************************************************
63  ******************************* TYPEDEFS **********************************
64  ******************************************************************************/
65 
67 typedef struct
68 {
69  unsigned int devno; /* Device instance number */
70 
71 #if defined(MBEDTLS_CRYPTO_DEVICE_PREEMPTION)
72  /* Device owner context. The owner pointer serves as the anchor to a
73  double linked list of all current "active" contexts. The ownership
74  may be won when calling the mbedTLS API if the priority is higher than
75  the current owner context and the current context is not inside a
76  critical section. If ownership is won the new owner context will
77  be added in front of the double linked list. The context will be removed
78  when the operation is complete before the mbedTLS API returns. */
79  void *owner;
80 
81  /* Mutex used to protect the data associated with the device
82  when running in critical sections. */
83  SLPAL_Mutex_t lock;
84 
85 #endif /* #if defined(MBEDTLS_CRYPTO_DEVICE_PREEMPTION) */
86 
87 #if defined(MBEDTLS_DEVICE_YIELD_WHEN_BUSY)
88  SLPAL_Completion_t operation; /* Device operation completion
89  object. */
90 #endif
91 
93 
94 /*******************************************************************************
95  ******************************* GLOBALS **********************************
96  ******************************************************************************/
97 
98 /* Table of pointers to mbedtls device contexts of each CRYPTO/AES hardware
99  instance. */
101 
102 /*******************************************************************************
103  ******************************* FUNCTIONS **********************************
104  ******************************************************************************/
105 
135 
150 
181  unsigned int devno );
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 #endif /* #if ( defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) ) || \
188  ( defined(AES_COUNT) && (AES_COUNT > 0) ) */
189 
190 #endif /* #ifndef MBEDTLS_SLCL_DEVICE_H */
volatile unsigned int SLPAL_Mutex_t
void mbedtls_device_init(mbedtls_device_context *ctx)
Initialize an mbedtls device context.
Device context structure.
Definition: slcl_device.h:67
Compatibility names (set of defines)
mbedtls_device_context * p_mbedtls_device_context[MBEDTLS_DEVICE_COUNT]
Silicon Labs specific mbedtls error code definitions.
volatile bool SLPAL_Completion_t
#define MBEDTLS_DEVICE_COUNT
Definition: slcl_device.h:59
int mbedtls_device_set_instance(mbedtls_device_context *ctx, unsigned int devno)
Set the device instance of an mbedtls device context.
unsigned int devno
Definition: slcl_device.h:69
void mbedtls_device_free(mbedtls_device_context *ctx)
Free an mbedtls device context.