Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
easy-connect/stm-spirit1-rf-driver/source/libs/spirit1/SPIRIT1_Library/Inc/SPIRIT_Aes.h@0:a1734fe1ec4b, 2017-04-08 (annotated)
- Committer:
- vpcola
- Date:
- Sat Apr 08 14:43:14 2017 +0000
- Revision:
- 0:a1734fe1ec4b
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vpcola | 0:a1734fe1ec4b | 1 | /** |
vpcola | 0:a1734fe1ec4b | 2 | ****************************************************************************** |
vpcola | 0:a1734fe1ec4b | 3 | * @file SPIRIT_Aes.h |
vpcola | 0:a1734fe1ec4b | 4 | * @author VMA division - AMS |
vpcola | 0:a1734fe1ec4b | 5 | * @version 3.2.2 |
vpcola | 0:a1734fe1ec4b | 6 | * @date 08-July-2015 |
vpcola | 0:a1734fe1ec4b | 7 | * @brief Configuration and management of SPIRIT AES Engine. |
vpcola | 0:a1734fe1ec4b | 8 | * |
vpcola | 0:a1734fe1ec4b | 9 | * @details |
vpcola | 0:a1734fe1ec4b | 10 | * |
vpcola | 0:a1734fe1ec4b | 11 | * In order to encrypt data, the user must manage the AES_END IRQ. |
vpcola | 0:a1734fe1ec4b | 12 | * The data have to be splitted in blocks of 16 bytes and written |
vpcola | 0:a1734fe1ec4b | 13 | * into the <i>AES DATA IN registers</i>. Then, after the key is written |
vpcola | 0:a1734fe1ec4b | 14 | * into the <i>AES KEY registers</i>, a command of <i>Execute encryption</i> |
vpcola | 0:a1734fe1ec4b | 15 | * has to be sent. |
vpcola | 0:a1734fe1ec4b | 16 | * |
vpcola | 0:a1734fe1ec4b | 17 | * <b>Example:</b> |
vpcola | 0:a1734fe1ec4b | 18 | * @code |
vpcola | 0:a1734fe1ec4b | 19 | * |
vpcola | 0:a1734fe1ec4b | 20 | * SpiritAesWriteDataIn(data_buff , N_BYTES); |
vpcola | 0:a1734fe1ec4b | 21 | * SpiritAesExecuteEncryption(); |
vpcola | 0:a1734fe1ec4b | 22 | * |
vpcola | 0:a1734fe1ec4b | 23 | * while(!aes_end_flag); // the flag is set by the ISR routine which manages the AES_END irq |
vpcola | 0:a1734fe1ec4b | 24 | * aes_end_flag=RESET; |
vpcola | 0:a1734fe1ec4b | 25 | * |
vpcola | 0:a1734fe1ec4b | 26 | * SpiritAesReadDataOut(enc_data_buff , N_BYTES); |
vpcola | 0:a1734fe1ec4b | 27 | * |
vpcola | 0:a1734fe1ec4b | 28 | * @endcode |
vpcola | 0:a1734fe1ec4b | 29 | * |
vpcola | 0:a1734fe1ec4b | 30 | * In order to decrypt data, the user must manage the AES_END IRQ and have a decryption key. |
vpcola | 0:a1734fe1ec4b | 31 | * There are two operative modes to make the data decryption: |
vpcola | 0:a1734fe1ec4b | 32 | * <ul> |
vpcola | 0:a1734fe1ec4b | 33 | * <li> Derive the decryption key from the encryption key and decrypt data directly |
vpcola | 0:a1734fe1ec4b | 34 | * using the <i>SpiritAesDeriveDecKeyExecuteDec()</i> function |
vpcola | 0:a1734fe1ec4b | 35 | * |
vpcola | 0:a1734fe1ec4b | 36 | * <b>Example:</b> |
vpcola | 0:a1734fe1ec4b | 37 | * @code |
vpcola | 0:a1734fe1ec4b | 38 | * |
vpcola | 0:a1734fe1ec4b | 39 | * SpiritAesWriteDataIn(enc_data_buff , N_BYTES); |
vpcola | 0:a1734fe1ec4b | 40 | * SpiritAesDeriveDecKeyExecuteDec(); |
vpcola | 0:a1734fe1ec4b | 41 | * |
vpcola | 0:a1734fe1ec4b | 42 | * while(!aes_end_flag); // the flag is set by the ISR routine which manages the AES_END irq |
vpcola | 0:a1734fe1ec4b | 43 | * aes_end_flag=RESET; |
vpcola | 0:a1734fe1ec4b | 44 | * |
vpcola | 0:a1734fe1ec4b | 45 | * SpiritAesReadDataOut(data_buff , N_BYTES); |
vpcola | 0:a1734fe1ec4b | 46 | * |
vpcola | 0:a1734fe1ec4b | 47 | * @endcode |
vpcola | 0:a1734fe1ec4b | 48 | * </li> |
vpcola | 0:a1734fe1ec4b | 49 | * |
vpcola | 0:a1734fe1ec4b | 50 | * <li> Derive the decryption key from the encryption key using the <i>SpiritAesDeriveDecKeyFromEnc()</i> |
vpcola | 0:a1734fe1ec4b | 51 | * function, store it into the <i>AES KEY registers</i> and then decrypt data using the |
vpcola | 0:a1734fe1ec4b | 52 | * <i>SpiritAesExecuteDecryption()</i> function |
vpcola | 0:a1734fe1ec4b | 53 | * |
vpcola | 0:a1734fe1ec4b | 54 | * <b>Example:</b> |
vpcola | 0:a1734fe1ec4b | 55 | * @code |
vpcola | 0:a1734fe1ec4b | 56 | * |
vpcola | 0:a1734fe1ec4b | 57 | * SpiritAesWriteDataIn(key_enc , 16); |
vpcola | 0:a1734fe1ec4b | 58 | * SpiritAesDeriveDecKeyFromEnc(); |
vpcola | 0:a1734fe1ec4b | 59 | * |
vpcola | 0:a1734fe1ec4b | 60 | * while(!aes_end_flag); // the flag is set by the ISR routine which manages the AES_END irq |
vpcola | 0:a1734fe1ec4b | 61 | * aes_end_flag=RESET; |
vpcola | 0:a1734fe1ec4b | 62 | * |
vpcola | 0:a1734fe1ec4b | 63 | * SpiritAesReadDataOut(key_dec , 16); |
vpcola | 0:a1734fe1ec4b | 64 | * |
vpcola | 0:a1734fe1ec4b | 65 | * SpiritAesWriteKey(key_dec); |
vpcola | 0:a1734fe1ec4b | 66 | * SpiritAesWriteDataIn(enc_data_buff , 16); |
vpcola | 0:a1734fe1ec4b | 67 | * SpiritAesExecuteDecryption(); |
vpcola | 0:a1734fe1ec4b | 68 | * |
vpcola | 0:a1734fe1ec4b | 69 | * while(!aes_end_flag); // the flag is set by the ISR routine which manages the AES_END irq |
vpcola | 0:a1734fe1ec4b | 70 | * aes_end_flag=RESET; |
vpcola | 0:a1734fe1ec4b | 71 | * |
vpcola | 0:a1734fe1ec4b | 72 | * SpiritAesReadDataOut(data_buff , N_BYTES); |
vpcola | 0:a1734fe1ec4b | 73 | * |
vpcola | 0:a1734fe1ec4b | 74 | * @endcode |
vpcola | 0:a1734fe1ec4b | 75 | * </li> |
vpcola | 0:a1734fe1ec4b | 76 | * </ul> |
vpcola | 0:a1734fe1ec4b | 77 | * |
vpcola | 0:a1734fe1ec4b | 78 | * @attention |
vpcola | 0:a1734fe1ec4b | 79 | * |
vpcola | 0:a1734fe1ec4b | 80 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
vpcola | 0:a1734fe1ec4b | 81 | * |
vpcola | 0:a1734fe1ec4b | 82 | * Redistribution and use in source and binary forms, with or without modification, |
vpcola | 0:a1734fe1ec4b | 83 | * are permitted provided that the following conditions are met: |
vpcola | 0:a1734fe1ec4b | 84 | * 1. Redistributions of source code must retain the above copyright notice, |
vpcola | 0:a1734fe1ec4b | 85 | * this list of conditions and the following disclaimer. |
vpcola | 0:a1734fe1ec4b | 86 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
vpcola | 0:a1734fe1ec4b | 87 | * this list of conditions and the following disclaimer in the documentation |
vpcola | 0:a1734fe1ec4b | 88 | * and/or other materials provided with the distribution. |
vpcola | 0:a1734fe1ec4b | 89 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
vpcola | 0:a1734fe1ec4b | 90 | * may be used to endorse or promote products derived from this software |
vpcola | 0:a1734fe1ec4b | 91 | * without specific prior written permission. |
vpcola | 0:a1734fe1ec4b | 92 | * |
vpcola | 0:a1734fe1ec4b | 93 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
vpcola | 0:a1734fe1ec4b | 94 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
vpcola | 0:a1734fe1ec4b | 95 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
vpcola | 0:a1734fe1ec4b | 96 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
vpcola | 0:a1734fe1ec4b | 97 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
vpcola | 0:a1734fe1ec4b | 98 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
vpcola | 0:a1734fe1ec4b | 99 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
vpcola | 0:a1734fe1ec4b | 100 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
vpcola | 0:a1734fe1ec4b | 101 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
vpcola | 0:a1734fe1ec4b | 102 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
vpcola | 0:a1734fe1ec4b | 103 | * |
vpcola | 0:a1734fe1ec4b | 104 | ****************************************************************************** |
vpcola | 0:a1734fe1ec4b | 105 | */ |
vpcola | 0:a1734fe1ec4b | 106 | |
vpcola | 0:a1734fe1ec4b | 107 | /* Define to prevent recursive inclusion -------------------------------------*/ |
vpcola | 0:a1734fe1ec4b | 108 | #ifndef __SPIRIT_AES_H |
vpcola | 0:a1734fe1ec4b | 109 | #define __SPIRIT_AES_H |
vpcola | 0:a1734fe1ec4b | 110 | |
vpcola | 0:a1734fe1ec4b | 111 | |
vpcola | 0:a1734fe1ec4b | 112 | /* Includes ------------------------------------------------------------------*/ |
vpcola | 0:a1734fe1ec4b | 113 | |
vpcola | 0:a1734fe1ec4b | 114 | #include "SPIRIT_Regs.h" |
vpcola | 0:a1734fe1ec4b | 115 | #include "SPIRIT_Types.h" |
vpcola | 0:a1734fe1ec4b | 116 | |
vpcola | 0:a1734fe1ec4b | 117 | |
vpcola | 0:a1734fe1ec4b | 118 | #ifdef __cplusplus |
vpcola | 0:a1734fe1ec4b | 119 | extern "C" { |
vpcola | 0:a1734fe1ec4b | 120 | #endif |
vpcola | 0:a1734fe1ec4b | 121 | |
vpcola | 0:a1734fe1ec4b | 122 | |
vpcola | 0:a1734fe1ec4b | 123 | /** |
vpcola | 0:a1734fe1ec4b | 124 | * @addtogroup SPIRIT_Libraries |
vpcola | 0:a1734fe1ec4b | 125 | * @{ |
vpcola | 0:a1734fe1ec4b | 126 | */ |
vpcola | 0:a1734fe1ec4b | 127 | |
vpcola | 0:a1734fe1ec4b | 128 | |
vpcola | 0:a1734fe1ec4b | 129 | /** |
vpcola | 0:a1734fe1ec4b | 130 | * @defgroup SPIRIT_Aes AES |
vpcola | 0:a1734fe1ec4b | 131 | * @brief Configuration and management of SPIRIT AES Engine. |
vpcola | 0:a1734fe1ec4b | 132 | * @details See the file <i>@ref SPIRIT_Aes.h</i> for more details. |
vpcola | 0:a1734fe1ec4b | 133 | * @{ |
vpcola | 0:a1734fe1ec4b | 134 | */ |
vpcola | 0:a1734fe1ec4b | 135 | |
vpcola | 0:a1734fe1ec4b | 136 | /** |
vpcola | 0:a1734fe1ec4b | 137 | * @defgroup Aes_Exported_Types AES Exported Types |
vpcola | 0:a1734fe1ec4b | 138 | * @{ |
vpcola | 0:a1734fe1ec4b | 139 | */ |
vpcola | 0:a1734fe1ec4b | 140 | |
vpcola | 0:a1734fe1ec4b | 141 | /** |
vpcola | 0:a1734fe1ec4b | 142 | * @} |
vpcola | 0:a1734fe1ec4b | 143 | */ |
vpcola | 0:a1734fe1ec4b | 144 | |
vpcola | 0:a1734fe1ec4b | 145 | |
vpcola | 0:a1734fe1ec4b | 146 | /** |
vpcola | 0:a1734fe1ec4b | 147 | * @defgroup Aes_Exported_Constants AES Exported Constants |
vpcola | 0:a1734fe1ec4b | 148 | * @{ |
vpcola | 0:a1734fe1ec4b | 149 | */ |
vpcola | 0:a1734fe1ec4b | 150 | |
vpcola | 0:a1734fe1ec4b | 151 | |
vpcola | 0:a1734fe1ec4b | 152 | /** |
vpcola | 0:a1734fe1ec4b | 153 | * @} |
vpcola | 0:a1734fe1ec4b | 154 | */ |
vpcola | 0:a1734fe1ec4b | 155 | |
vpcola | 0:a1734fe1ec4b | 156 | |
vpcola | 0:a1734fe1ec4b | 157 | /** |
vpcola | 0:a1734fe1ec4b | 158 | * @defgroup Aes_Exported_Macros AES Exported Macros |
vpcola | 0:a1734fe1ec4b | 159 | * @{ |
vpcola | 0:a1734fe1ec4b | 160 | */ |
vpcola | 0:a1734fe1ec4b | 161 | |
vpcola | 0:a1734fe1ec4b | 162 | |
vpcola | 0:a1734fe1ec4b | 163 | /** |
vpcola | 0:a1734fe1ec4b | 164 | * @} |
vpcola | 0:a1734fe1ec4b | 165 | */ |
vpcola | 0:a1734fe1ec4b | 166 | |
vpcola | 0:a1734fe1ec4b | 167 | |
vpcola | 0:a1734fe1ec4b | 168 | /** |
vpcola | 0:a1734fe1ec4b | 169 | * @defgroup Aes_Exported_Functions AES Exported Functions |
vpcola | 0:a1734fe1ec4b | 170 | * @{ |
vpcola | 0:a1734fe1ec4b | 171 | */ |
vpcola | 0:a1734fe1ec4b | 172 | |
vpcola | 0:a1734fe1ec4b | 173 | void SpiritAesMode(SpiritFunctionalState xNewState); |
vpcola | 0:a1734fe1ec4b | 174 | void SpiritAesWriteDataIn(uint8_t* pcBufferDataIn, uint8_t cDataLength); |
vpcola | 0:a1734fe1ec4b | 175 | void SpiritAesReadDataOut(uint8_t* pcBufferDataOut, uint8_t cDataLength); |
vpcola | 0:a1734fe1ec4b | 176 | void SpiritAesWriteKey(uint8_t* pcKey); |
vpcola | 0:a1734fe1ec4b | 177 | void SpiritAesReadKey(uint8_t* pcKey); |
vpcola | 0:a1734fe1ec4b | 178 | void SpiritAesDeriveDecKeyFromEnc(void); |
vpcola | 0:a1734fe1ec4b | 179 | void SpiritAesExecuteEncryption(void); |
vpcola | 0:a1734fe1ec4b | 180 | void SpiritAesExecuteDecryption(void); |
vpcola | 0:a1734fe1ec4b | 181 | void SpiritAesDeriveDecKeyExecuteDec(void); |
vpcola | 0:a1734fe1ec4b | 182 | |
vpcola | 0:a1734fe1ec4b | 183 | /** |
vpcola | 0:a1734fe1ec4b | 184 | * @} |
vpcola | 0:a1734fe1ec4b | 185 | */ |
vpcola | 0:a1734fe1ec4b | 186 | |
vpcola | 0:a1734fe1ec4b | 187 | /** |
vpcola | 0:a1734fe1ec4b | 188 | * @} |
vpcola | 0:a1734fe1ec4b | 189 | */ |
vpcola | 0:a1734fe1ec4b | 190 | |
vpcola | 0:a1734fe1ec4b | 191 | |
vpcola | 0:a1734fe1ec4b | 192 | /** |
vpcola | 0:a1734fe1ec4b | 193 | * @} |
vpcola | 0:a1734fe1ec4b | 194 | */ |
vpcola | 0:a1734fe1ec4b | 195 | |
vpcola | 0:a1734fe1ec4b | 196 | |
vpcola | 0:a1734fe1ec4b | 197 | |
vpcola | 0:a1734fe1ec4b | 198 | |
vpcola | 0:a1734fe1ec4b | 199 | #ifdef __cplusplus |
vpcola | 0:a1734fe1ec4b | 200 | } |
vpcola | 0:a1734fe1ec4b | 201 | #endif |
vpcola | 0:a1734fe1ec4b | 202 | |
vpcola | 0:a1734fe1ec4b | 203 | #endif |
vpcola | 0:a1734fe1ec4b | 204 | |
vpcola | 0:a1734fe1ec4b | 205 | /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/ |