Fork of mbed-dev build 137, last build before FAT file system appears to be broken. Also reduced HSE timeout time in STM4XX HAL

Fork of mbed-dev by mbed official

Committer:
kkado
Date:
Tue Jun 20 11:06:37 2017 +0000
Revision:
167:356ef919c855
Parent:
150:02e0a0aed4ec
Build 137 with reduced HSE timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 150:02e0a0aed4ec 1 /**
<> 150:02e0a0aed4ec 2 * @file aes.h
<> 150:02e0a0aed4ec 3 * @brief Advanced Encryption Standard (AES) function prototypes and data types.
<> 150:02e0a0aed4ec 4 */
<> 150:02e0a0aed4ec 5
<> 150:02e0a0aed4ec 6 /* ****************************************************************************
<> 150:02e0a0aed4ec 7 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
<> 150:02e0a0aed4ec 8 *
<> 150:02e0a0aed4ec 9 * Permission is hereby granted, free of charge, to any person obtaining a
<> 150:02e0a0aed4ec 10 * copy of this software and associated documentation files (the "Software"),
<> 150:02e0a0aed4ec 11 * to deal in the Software without restriction, including without limitation
<> 150:02e0a0aed4ec 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
<> 150:02e0a0aed4ec 13 * and/or sell copies of the Software, and to permit persons to whom the
<> 150:02e0a0aed4ec 14 * Software is furnished to do so, subject to the following conditions:
<> 150:02e0a0aed4ec 15 *
<> 150:02e0a0aed4ec 16 * The above copyright notice and this permission notice shall be included
<> 150:02e0a0aed4ec 17 * in all copies or substantial portions of the Software.
<> 150:02e0a0aed4ec 18 *
<> 150:02e0a0aed4ec 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
<> 150:02e0a0aed4ec 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<> 150:02e0a0aed4ec 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
<> 150:02e0a0aed4ec 22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
<> 150:02e0a0aed4ec 23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
<> 150:02e0a0aed4ec 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
<> 150:02e0a0aed4ec 25 * OTHER DEALINGS IN THE SOFTWARE.
<> 150:02e0a0aed4ec 26 *
<> 150:02e0a0aed4ec 27 * Except as contained in this notice, the name of Maxim Integrated
<> 150:02e0a0aed4ec 28 * Products, Inc. shall not be used except as stated in the Maxim Integrated
<> 150:02e0a0aed4ec 29 * Products, Inc. Branding Policy.
<> 150:02e0a0aed4ec 30 *
<> 150:02e0a0aed4ec 31 * The mere transfer of this software does not imply any licenses
<> 150:02e0a0aed4ec 32 * of trade secrets, proprietary technology, copyrights, patents,
<> 150:02e0a0aed4ec 33 * trademarks, maskwork rights, or any other form of intellectual
<> 150:02e0a0aed4ec 34 * property whatsoever. Maxim Integrated Products, Inc. retains all
<> 150:02e0a0aed4ec 35 * ownership rights.
<> 150:02e0a0aed4ec 36 *
<> 150:02e0a0aed4ec 37 * $Date: 2016-08-02 13:39:05 -0500 (Tue, 02 Aug 2016) $
<> 150:02e0a0aed4ec 38 * $Revision: 23894 $
<> 150:02e0a0aed4ec 39 *
<> 150:02e0a0aed4ec 40 *************************************************************************** */
<> 150:02e0a0aed4ec 41
<> 150:02e0a0aed4ec 42 /* Define to prevent redundant inclusion */
<> 150:02e0a0aed4ec 43 #ifndef _AES_H
<> 150:02e0a0aed4ec 44 #define _AES_H
<> 150:02e0a0aed4ec 45
<> 150:02e0a0aed4ec 46 #include <stdint.h>
<> 150:02e0a0aed4ec 47 #include "aes_regs.h"
<> 150:02e0a0aed4ec 48
<> 150:02e0a0aed4ec 49 #ifdef __cplusplus
<> 150:02e0a0aed4ec 50 extern "C" {
<> 150:02e0a0aed4ec 51 #endif
<> 150:02e0a0aed4ec 52
<> 150:02e0a0aed4ec 53 /**
<> 150:02e0a0aed4ec 54 * @defgroup aes Advanced Encryption Standard (AES)
<> 150:02e0a0aed4ec 55 * @ingroup periphlibs
<> 150:02e0a0aed4ec 56 * @brief High-level API for AES encryption engine
<> 150:02e0a0aed4ec 57 * @{
<> 150:02e0a0aed4ec 58 */
<> 150:02e0a0aed4ec 59
<> 150:02e0a0aed4ec 60 /**
<> 150:02e0a0aed4ec 61 * @page aes_overview Overview and Usage
<> 150:02e0a0aed4ec 62 * @parblock
<> 150:02e0a0aed4ec 63 * #### Key/data format in memory
<> 150:02e0a0aed4ec 64 *
<> 150:02e0a0aed4ec 65 * The API functions require that key and plain/ciphertext will be stored as a
<> 150:02e0a0aed4ec 66 * byte array in LSB .. MSB format.
<> 150:02e0a0aed4ec 67 *
<> 150:02e0a0aed4ec 68 * As an example, given the key @a 0x139a35422f1d61de3c91787fe0507afd, the proper storage order is:
<> 150:02e0a0aed4ec 69 * ~~~~~
<> 150:02e0a0aed4ec 70 * uint8_t key[16] = { 0xfd, 0x7a, 0x50, 0xe0,
<> 150:02e0a0aed4ec 71 * 0x7f, 0x78, 0x91, 0x3c,
<> 150:02e0a0aed4ec 72 * 0xde, 0x61, 0x1d, 0x2f,
<> 150:02e0a0aed4ec 73 * 0x42, 0x35, 0x9a, 0x13 };
<> 150:02e0a0aed4ec 74 * ~~~~~
<> 150:02e0a0aed4ec 75 * This is the same order expected by the underlying hardware.
<> 150:02e0a0aed4ec 76 * @endparblock
<> 150:02e0a0aed4ec 77 */
<> 150:02e0a0aed4ec 78
<> 150:02e0a0aed4ec 79 /* **** Definitions **** */
<> 150:02e0a0aed4ec 80
<> 150:02e0a0aed4ec 81 #define MXC_AES_DATA_LEN (128 / 8) /**< Number of bytes in an AES plaintext or cyphertext block (always 128-bits) */
<> 150:02e0a0aed4ec 82
<> 150:02e0a0aed4ec 83 #define MXC_AES_KEY_128_LEN (128 / 8) /**< Number of bytes in a AES-128 key */
<> 150:02e0a0aed4ec 84 #define MXC_AES_KEY_192_LEN (192 / 8) /**< Number of bytes in a AES-192 key */
<> 150:02e0a0aed4ec 85 #define MXC_AES_KEY_256_LEN (256 / 8) /**< Number of bytes in a AES-256 key */
<> 150:02e0a0aed4ec 86
<> 150:02e0a0aed4ec 87 /**
<> 150:02e0a0aed4ec 88 * Enumeration type for AES key size selection (bits).
<> 150:02e0a0aed4ec 89 */
<> 150:02e0a0aed4ec 90 typedef enum {
<> 150:02e0a0aed4ec 91 MXC_E_AES_MODE_128 = MXC_V_AES_CTRL_KEY_SIZE_128, /**< 128-bit key */
<> 150:02e0a0aed4ec 92 MXC_E_AES_MODE_192 = MXC_V_AES_CTRL_KEY_SIZE_192, /**< 192-bit key */
<> 150:02e0a0aed4ec 93 MXC_E_AES_MODE_256 = MXC_V_AES_CTRL_KEY_SIZE_256 /**< 256-bit key */
<> 150:02e0a0aed4ec 94 } mxc_aes_mode_t;
<> 150:02e0a0aed4ec 95
<> 150:02e0a0aed4ec 96 /**
<> 150:02e0a0aed4ec 97 * Enumeration type for specifying encryption/decrytion and asynchronous or blocking behavior.
<> 150:02e0a0aed4ec 98 */
<> 150:02e0a0aed4ec 99 typedef enum {
<> 150:02e0a0aed4ec 100 MXC_E_AES_ENCRYPT = 0, /**< Encrypt (blocking) */
<> 150:02e0a0aed4ec 101 MXC_E_AES_ENCRYPT_ASYNC = 1, /**< Encrypt (interrupt-driven) */
<> 150:02e0a0aed4ec 102 MXC_E_AES_DECRYPT = 2, /**< Decrypt (blocking) */
<> 150:02e0a0aed4ec 103 MXC_E_AES_DECRYPT_ASYNC = 3 /**< Decrypt (interrupt-driven) */
<> 150:02e0a0aed4ec 104 } mxc_aes_dir_t;
<> 150:02e0a0aed4ec 105
<> 150:02e0a0aed4ec 106 /* **** Function Prototypes **** */
<> 150:02e0a0aed4ec 107
<> 150:02e0a0aed4ec 108 /**
<> 150:02e0a0aed4ec 109 * @brief Configure AES block with keying material
<> 150:02e0a0aed4ec 110 *
<> 150:02e0a0aed4ec 111 * @param key 128, 192, or 256 bit keying material
<> 150:02e0a0aed4ec 112 * @param mode Selects key length, valid modes defined in #mxc_aes_mode_t
<> 150:02e0a0aed4ec 113 *
<> 150:02e0a0aed4ec 114 * @return #E_BAD_PARAM Specified @a mode is invalid, see #mxc_aes_mode_t.
<> 150:02e0a0aed4ec 115 * @return #E_NULL_PTR Invalid/Null pointer for parameter @a key.
<> 150:02e0a0aed4ec 116 * @return #E_SUCCESS Key and mode set up correctly.
<> 150:02e0a0aed4ec 117 */
<> 150:02e0a0aed4ec 118 int AES_SetKey(const uint8_t *key, mxc_aes_mode_t mode);
<> 150:02e0a0aed4ec 119
<> 150:02e0a0aed4ec 120
<> 150:02e0a0aed4ec 121 /**
<> 150:02e0a0aed4ec 122 * @brief Encrypt/decrypt an input block with the loaded AES key.
<> 150:02e0a0aed4ec 123 * @note The parameters @a in and @a out should always be 16 bytes
<> 150:02e0a0aed4ec 124 *
<> 150:02e0a0aed4ec 125 * @param in Pointer to input array of 16 bytes.
<> 150:02e0a0aed4ec 126 * @param out Pointer to output array of 16 bytes.
<> 150:02e0a0aed4ec 127 * @param mode AES key size to use for the transaction, see #mxc_aes_mode_t
<> 150:02e0a0aed4ec 128 * @param dir Encrypt/Decrypt and Blocking or Asynchronous operation, see #mxc_aes_dir_t.
<> 150:02e0a0aed4ec 129 *
<> 150:02e0a0aed4ec 130 * @return #E_SUCCESS Operation completed successfully, output data is stored in @a *out.
<> 150:02e0a0aed4ec 131 * @return ErrorCode An @link MXC_Error_Codes Error Code@endlink.
<> 150:02e0a0aed4ec 132 */
<> 150:02e0a0aed4ec 133 int AES_ECBOp(const uint8_t *in, uint8_t *out, mxc_aes_mode_t mode, mxc_aes_dir_t dir);
<> 150:02e0a0aed4ec 134
<> 150:02e0a0aed4ec 135 /**
<> 150:02e0a0aed4ec 136 * @brief Read the AES output memory, used for asynchronous encryption, and clears interrupt flag.
<> 150:02e0a0aed4ec 137 * @note The parameter @a out is always 16 bytes
<> 150:02e0a0aed4ec 138 *
<> 150:02e0a0aed4ec 139 * @param out Pointer to output array of 16 bytes
<> 150:02e0a0aed4ec 140 *
<> 150:02e0a0aed4ec 141 * @return #E_SUCCESS Output data was written to the location pointed to by @a *out
<> 150:02e0a0aed4ec 142 * @return Error Code indicating the type of error encountered. See @ref MXC_Error_Codes
<> 150:02e0a0aed4ec 143 * for possible return code values.
<> 150:02e0a0aed4ec 144 */
<> 150:02e0a0aed4ec 145 int AES_GetOutput(uint8_t *out);
<> 150:02e0a0aed4ec 146
<> 150:02e0a0aed4ec 147 /**
<> 150:02e0a0aed4ec 148 * @def AES_ECBEncrypt(ptxt, ctxt, mode)s
<> 150:02e0a0aed4ec 149 * @brief Encrypt a block of plaintext with the loaded AES key, blocks until complete
<> 150:02e0a0aed4ec 150 * @hideinitializer
<> 150:02e0a0aed4ec 151 *
<> 150:02e0a0aed4ec 152 * @param ptxt Pointer to plaintext input array (always 16 bytes)
<> 150:02e0a0aed4ec 153 * @param ctxt Pointer to ciphertext output array (always 16 bytes)
<> 150:02e0a0aed4ec 154 * @param mode Selects key length, valid modes found in mxc_aes_mode_t
<> 150:02e0a0aed4ec 155 */
<> 150:02e0a0aed4ec 156 #define AES_ECBEncrypt(ptxt, ctxt, mode) AES_ECBOp(ptxt, ctxt, mode, MXC_E_AES_ENCRYPT)
<> 150:02e0a0aed4ec 157
<> 150:02e0a0aed4ec 158
<> 150:02e0a0aed4ec 159 /**
<> 150:02e0a0aed4ec 160 * @def AES_ECBDecrypt(ctxt, ptxt, mode)
<> 150:02e0a0aed4ec 161 * @hideinitializer
<> 150:02e0a0aed4ec 162 * @brief Decrypt a block of ciphertext with the loaded AES key, blocks until complete
<> 150:02e0a0aed4ec 163 *
<> 150:02e0a0aed4ec 164 * @param ctxt Pointer to ciphertext output array (always 16 bytes)
<> 150:02e0a0aed4ec 165 * @param ptxt Pointer to plaintext input array (always 16 bytes)
<> 150:02e0a0aed4ec 166 * @param mode Selects key length, valid modes found in mxc_aes_mode_t
<> 150:02e0a0aed4ec 167 */
<> 150:02e0a0aed4ec 168 #define AES_ECBDecrypt(ctxt, ptxt, mode) AES_ECBOp(ctxt, ptxt, mode, MXC_E_AES_DECRYPT)
<> 150:02e0a0aed4ec 169
<> 150:02e0a0aed4ec 170 /**
<> 150:02e0a0aed4ec 171 * @def AES_ECBEncryptAsync(ptxt, mode)
<> 150:02e0a0aed4ec 172 * @hideinitializer
<> 150:02e0a0aed4ec 173 * @brief Starts encryption of a block, enables interrupt, and returns immediately.
<> 150:02e0a0aed4ec 174 * Use AES_GetOuput() to retrieve result after interrupt fires
<> 150:02e0a0aed4ec 175 *
<> 150:02e0a0aed4ec 176 *
<> 150:02e0a0aed4ec 177 * @param ptxt Pointer to plaintext input array (always 16 bytes)
<> 150:02e0a0aed4ec 178 * @param mode Selects key length, valid modes found in mxc_aes_mode_t
<> 150:02e0a0aed4ec 179 */
<> 150:02e0a0aed4ec 180 #define AES_ECBEncryptAsync(ptxt, mode) AES_ECBOp(ptxt, NULL, mode, MXC_E_AES_ENCRYPT_ASYNC)
<> 150:02e0a0aed4ec 181
<> 150:02e0a0aed4ec 182 /**
<> 150:02e0a0aed4ec 183 * @def AES_ECBDecryptAsync(ctxt, mode)
<> 150:02e0a0aed4ec 184 * @hideinitializer
<> 150:02e0a0aed4ec 185 * @brief Starts encryption of a block, enables interrupt, and returns immediately.
<> 150:02e0a0aed4ec 186 * Use AES_GetOuput() to retrieve result after interrupt fires
<> 150:02e0a0aed4ec 187 *
<> 150:02e0a0aed4ec 188 * @param ctxt Pointer to ciphertext output array (always 16 bytes)
<> 150:02e0a0aed4ec 189 * @param mode Selects key length, valid modes found in mxc_aes_mode_t
<> 150:02e0a0aed4ec 190 */
<> 150:02e0a0aed4ec 191 #define AES_ECBDecryptAsync(ctxt, mode) AES_ECBOp(ctxt, NULL, mode, MXC_E_AES_DECRYPT_ASYNC)
<> 150:02e0a0aed4ec 192
<> 150:02e0a0aed4ec 193 /**@} end of group aes*/
<> 150:02e0a0aed4ec 194
<> 150:02e0a0aed4ec 195 #ifdef __cplusplus
<> 150:02e0a0aed4ec 196 }
<> 150:02e0a0aed4ec 197 #endif
<> 150:02e0a0aed4ec 198
<> 150:02e0a0aed4ec 199 #endif