1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_AES_AES_REVB_H_
22 #define LIBRARIES_PERIPHDRIVERS_SOURCE_AES_AES_REVB_H_
23 
24 #include <stdint.h>
25 #include "aes.h"
26 #include "aes_revb_regs.h"
27 #include "aeskeys_revb_regs.h"
28 #include "trng_revb_regs.h"
29 
30 /**
31   * @brief  Enumeration type to select AES key
32   *
33   */
34 typedef enum {
35     MXC_AES_REVB_128BITS = MXC_S_AES_REVB_CTRL_KEY_SIZE_AES128, ///< Select AES-128 bit key
36     MXC_AES_REVB_192BITS = MXC_S_AES_REVB_CTRL_KEY_SIZE_AES192, ///< Select AES-192 bit key
37     MXC_AES_REVB_256BITS = MXC_S_AES_REVB_CTRL_KEY_SIZE_AES256, ///< Select AES-256 bit key
38 } mxc_aes_revb_keys_t;
39 
40 /**
41   * @brief  Enumeration type to select AES key source and encryption type
42   *
43   */
44 typedef enum {
45     MXC_AES_REVB_ENCRYPT_EXT_KEY = 0, ///< Encryption using External key
46     MXC_AES_REVB_DECRYPT_EXT_KEY = 1, ///< Encryption using internal key
47     MXC_AES_REVB_DECRYPT_INT_KEY = 2 ///< Decryption using internal key
48 } mxc_aes_revb_enc_type_t;
49 
50 /**
51   * @brief  Structure used to set up AES request
52   *
53   */
54 typedef struct _mxc_aes_revb_cipher_req_t {
55     uint32_t length; ///< Length of the data
56     uint32_t *inputData; ///< Pointer to input data
57     uint32_t *resultData; ///< Pointer to encrypted data
58     mxc_aes_revb_keys_t keySize; ///< Size of AES key
59     mxc_aes_revb_enc_type_t encryption; ///< Encrytion type or \ref mxc_aes_enc_type_t
60     mxc_aes_complete_t callback; ///< Callback function
61 } mxc_aes_revb_req_t;
62 
63 int MXC_AES_RevB_Init(mxc_aes_revb_regs_t *aes);
64 void MXC_AES_RevB_EnableInt(mxc_aes_revb_regs_t *aes, uint32_t interrupt);
65 void MXC_AES_RevB_DisableInt(mxc_aes_revb_regs_t *aes, uint32_t interrupt);
66 int MXC_AES_RevB_IsBusy(mxc_aes_revb_regs_t *aes);
67 int MXC_AES_RevB_Shutdown(mxc_aes_revb_regs_t *aes);
68 void MXC_AES_RevB_GenerateKey(mxc_trng_revb_regs_t *trng);
69 void MXC_AES_RevB_SetKeySize(mxc_aes_revb_regs_t *aes, mxc_aes_revb_keys_t key);
70 mxc_aes_keys_t MXC_AES_RevB_GetKeySize(mxc_aes_revb_regs_t *aes);
71 void MXC_AES_RevB_FlushInputFIFO(mxc_aes_revb_regs_t *aes);
72 void MXC_AES_RevB_FlushOutputFIFO(mxc_aes_revb_regs_t *aes);
73 void MXC_AES_RevB_Start(mxc_aes_revb_regs_t *aes);
74 uint32_t MXC_AES_RevB_GetFlags(mxc_aes_revb_regs_t *aes);
75 void MXC_AES_RevB_ClearFlags(mxc_aes_revb_regs_t *aes, uint32_t flags);
76 int MXC_AES_RevB_Generic(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req);
77 int MXC_AES_RevB_Encrypt(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req);
78 int MXC_AES_RevB_Decrypt(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req);
79 int MXC_AES_RevB_TXDMAConfig(void *src_addr, int len);
80 int MXC_AES_RevB_RXDMAConfig(void *dest_addr, int len);
81 int MXC_AES_RevB_GenericAsync(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req, uint8_t enc);
82 int MXC_AES_RevB_EncryptAsync(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req);
83 int MXC_AES_RevB_DecryptAsync(mxc_aes_revb_regs_t *aes, mxc_aes_revb_req_t *req);
84 void MXC_AES_RevB_DMACallback(int ch, int error);
85 void MXC_AES_RevB_SetExtKey(mxc_aeskeys_revb_regs_t *aeskey, const void *key, mxc_aes_keys_t len);
86 
87 #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_AES_AES_REVB_H_
88