The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Thu Oct 27 16:45:56 2016 +0100
Revision:
128:9bcdf88f62b0
Parent:
113:f141b2784e32
Child:
139:856d2700e60b
Release 128 of the mbed library

Ports for Upcoming Targets


Fixes and Changes

2966: Add kw24 support https://github.com/ARMmbed/mbed-os/pull/2966
3068: MultiTech mDot - clean up PeripheralPins.c and add new pin names https://github.com/ARMmbed/mbed-os/pull/3068
3089: Kinetis HAL: Remove clock initialization code from serial and ticker https://github.com/ARMmbed/mbed-os/pull/3089
2943: [NRF5] NVIC_SetVector functionality https://github.com/ARMmbed/mbed-os/pull/2943
2938: InterruptIn changes in NCS36510 HAL. https://github.com/ARMmbed/mbed-os/pull/2938
3108: Fix sleep function for NRF52. https://github.com/ARMmbed/mbed-os/pull/3108
3076: STM32F1: Correct timer master value reading https://github.com/ARMmbed/mbed-os/pull/3076
3085: Add LOWPOWERTIMER capability for NUCLEO_F303ZE https://github.com/ARMmbed/mbed-os/pull/3085
3046: [BEETLE] Update BLE stack on Beetle board https://github.com/ARMmbed/mbed-os/pull/3046
3122: [Silicon Labs] Update of Silicon Labs HAL https://github.com/ARMmbed/mbed-os/pull/3122
3022: OnSemi RAM usage fix https://github.com/ARMmbed/mbed-os/pull/3022
3121: STM32F3: Correct UART4 and UART5 defines when using DEVICE_SERIAL_ASYNCH https://github.com/ARMmbed/mbed-os/pull/3121
3142: Targets- NUMAKER_PFM_NUC47216 remove mbed 2 https://github.com/ARMmbed/mbed-os/pull/3142

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 113:f141b2784e32 1 /***************************************************************************//**
Kojto 113:f141b2784e32 2 * @file em_crypto.h
Kojto 113:f141b2784e32 3 * @brief Cryptography accelerator peripheral API
<> 128:9bcdf88f62b0 4 * @version 5.0.0
Kojto 113:f141b2784e32 5 *******************************************************************************
Kojto 113:f141b2784e32 6 * @section License
<> 128:9bcdf88f62b0 7 * <b>Copyright 2016 Silicon Laboratories, Inc. http://www.silabs.com</b>
Kojto 113:f141b2784e32 8 *******************************************************************************
Kojto 113:f141b2784e32 9 *
Kojto 113:f141b2784e32 10 * Permission is granted to anyone to use this software for any purpose,
Kojto 113:f141b2784e32 11 * including commercial applications, and to alter it and redistribute it
Kojto 113:f141b2784e32 12 * freely, subject to the following restrictions:
Kojto 113:f141b2784e32 13 *
Kojto 113:f141b2784e32 14 * 1. The origin of this software must not be misrepresented; you must not
Kojto 113:f141b2784e32 15 * claim that you wrote the original software.
Kojto 113:f141b2784e32 16 * 2. Altered source versions must be plainly marked as such, and must not be
Kojto 113:f141b2784e32 17 * misrepresented as being the original software.
Kojto 113:f141b2784e32 18 * 3. This notice may not be removed or altered from any source distribution.
Kojto 113:f141b2784e32 19 *
Kojto 113:f141b2784e32 20 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
Kojto 113:f141b2784e32 21 * obligation to support this Software. Silicon Labs is providing the
Kojto 113:f141b2784e32 22 * Software "AS IS", with no express or implied warranties of any kind,
Kojto 113:f141b2784e32 23 * including, but not limited to, any implied warranties of merchantability
Kojto 113:f141b2784e32 24 * or fitness for any particular purpose or warranties against infringement
Kojto 113:f141b2784e32 25 * of any proprietary rights of a third party.
Kojto 113:f141b2784e32 26 *
Kojto 113:f141b2784e32 27 * Silicon Labs will not be liable for any consequential, incidental, or
Kojto 113:f141b2784e32 28 * special damages, or any other relief, or for any claim by any third party,
Kojto 113:f141b2784e32 29 * arising from your use of this Software.
Kojto 113:f141b2784e32 30 *
Kojto 113:f141b2784e32 31 ******************************************************************************/
<> 128:9bcdf88f62b0 32 #ifndef EM_CRYPTO_H
<> 128:9bcdf88f62b0 33 #define EM_CRYPTO_H
Kojto 113:f141b2784e32 34
Kojto 113:f141b2784e32 35 #include "em_device.h"
Kojto 113:f141b2784e32 36
Kojto 113:f141b2784e32 37 #if defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0)
Kojto 113:f141b2784e32 38
Kojto 113:f141b2784e32 39 #include "em_bus.h"
Kojto 113:f141b2784e32 40 #include <stdbool.h>
Kojto 113:f141b2784e32 41
Kojto 113:f141b2784e32 42 #ifdef __cplusplus
Kojto 113:f141b2784e32 43 extern "C" {
Kojto 113:f141b2784e32 44 #endif
Kojto 113:f141b2784e32 45
Kojto 113:f141b2784e32 46 /***************************************************************************//**
<> 128:9bcdf88f62b0 47 * @addtogroup emlib
Kojto 113:f141b2784e32 48 * @{
Kojto 113:f141b2784e32 49 ******************************************************************************/
Kojto 113:f141b2784e32 50
Kojto 113:f141b2784e32 51 /***************************************************************************//**
Kojto 113:f141b2784e32 52 * @addtogroup CRYPTO
<> 128:9bcdf88f62b0 53 *
<> 128:9bcdf88f62b0 54 * @brief Cryptography accelerator peripheral API
<> 128:9bcdf88f62b0 55 *
<> 128:9bcdf88f62b0 56 * @details
<> 128:9bcdf88f62b0 57 * In order for cryptographic support, users are recommended to consider the
<> 128:9bcdf88f62b0 58 * crypto APIs of the mbedTLS library provided by Silicon Labs instead of the
<> 128:9bcdf88f62b0 59 * interface provided in em_crypto.h. The mbedTLS library provides a much
<> 128:9bcdf88f62b0 60 * richer crypto API, including hardware acceleration of several functions.
<> 128:9bcdf88f62b0 61 *
<> 128:9bcdf88f62b0 62 * The main purpose of em_crypto.h is to implement a thin software interface
<> 128:9bcdf88f62b0 63 * for the CRYPTO hardware functions especially for the accelerated APIs of
<> 128:9bcdf88f62b0 64 * the mbedTLS library. Additionally em_crypto.h implement the AES API of the
<> 128:9bcdf88f62b0 65 * em_aes.h (supported by classic EFM32) for backwards compatibility. The
<> 128:9bcdf88f62b0 66 * following list summarizes the em_crypto.h inteface:
<> 128:9bcdf88f62b0 67 * @li AES (Advanced Encryption Standard) @ref crypto_aes
<> 128:9bcdf88f62b0 68 * @li SHA (Secure Hash Algorithm) @ref crypto_sha
<> 128:9bcdf88f62b0 69 * @li Big Integer multiplier @ref crypto_mul
<> 128:9bcdf88f62b0 70 * @li Functions for loading data and executing instruction sequences @ref crypto_exec
<> 128:9bcdf88f62b0 71 *
<> 128:9bcdf88f62b0 72 * @n @section crypto_aes AES
<> 128:9bcdf88f62b0 73 * The AES APIs include support for AES-128 and AES-256 with block cipher
<> 128:9bcdf88f62b0 74 * modes:
<> 128:9bcdf88f62b0 75 * @li CBC - Cipher Block Chaining mode
<> 128:9bcdf88f62b0 76 * @li CFB - Cipher Feedback mode
<> 128:9bcdf88f62b0 77 * @li CTR - Counter mode
<> 128:9bcdf88f62b0 78 * @li ECB - Electronic Code Book mode
<> 128:9bcdf88f62b0 79 * @li OFB - Output Feedback mode
<> 128:9bcdf88f62b0 80 *
<> 128:9bcdf88f62b0 81 * For the AES APIs Input/output data (plaintext, ciphertext, key etc) are
<> 128:9bcdf88f62b0 82 * treated as byte arrays, starting with most significant byte. Ie, 32 bytes
<> 128:9bcdf88f62b0 83 * of plaintext (B0...B31) is located in memory in the same order, with B0 at
<> 128:9bcdf88f62b0 84 * the lower address and B31 at the higher address.
<> 128:9bcdf88f62b0 85 *
<> 128:9bcdf88f62b0 86 * Byte arrays must always be a multiple of AES block size, ie. a multiple
<> 128:9bcdf88f62b0 87 * of 16. Padding, if required, is done at the end of the byte array.
<> 128:9bcdf88f62b0 88 *
<> 128:9bcdf88f62b0 89 * Byte arrays should be word (32 bit) aligned for performance
<> 128:9bcdf88f62b0 90 * considerations, since the array is accessed with 32 bit access type.
<> 128:9bcdf88f62b0 91 * The core MCUs supports unaligned accesses, but with a performance penalty.
<> 128:9bcdf88f62b0 92 *
<> 128:9bcdf88f62b0 93 * It is possible to specify the same output buffer as input buffer as long
<> 128:9bcdf88f62b0 94 * as they point to the same address. In that case the provided input buffer
<> 128:9bcdf88f62b0 95 * is replaced with the encrypted/decrypted output. Notice that the buffers
<> 128:9bcdf88f62b0 96 * must be exactly overlapping. If partly overlapping, the behavior is
<> 128:9bcdf88f62b0 97 * undefined.
<> 128:9bcdf88f62b0 98 *
<> 128:9bcdf88f62b0 99 * It is up to the user to use a cipher mode according to its requirements
<> 128:9bcdf88f62b0 100 * in order to not break security. Please refer to specific cipher mode
<> 128:9bcdf88f62b0 101 * theory for details.
<> 128:9bcdf88f62b0 102 *
<> 128:9bcdf88f62b0 103 * References:
<> 128:9bcdf88f62b0 104 * @li Wikipedia - Cipher modes, http://en.wikipedia.org/wiki/Cipher_modes
<> 128:9bcdf88f62b0 105 *
<> 128:9bcdf88f62b0 106 * @li Recommendation for Block Cipher Modes of Operation,
<> 128:9bcdf88f62b0 107 * NIST Special Publication 800-38A, 2001 Edition,
<> 128:9bcdf88f62b0 108 * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
<> 128:9bcdf88f62b0 109 *
<> 128:9bcdf88f62b0 110 * @li Recommendation for Block Cipher Modes of Operation,
<> 128:9bcdf88f62b0 111 * http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf
<> 128:9bcdf88f62b0 112 *
<> 128:9bcdf88f62b0 113 * @n @section crypto_sha SHA
<> 128:9bcdf88f62b0 114 * The SHA APIs include support for
<> 128:9bcdf88f62b0 115 * @li SHA-1 @ref CRYPTO_SHA_1
<> 128:9bcdf88f62b0 116 * @li SHA-256 @ref CRYPTO_SHA_256
<> 128:9bcdf88f62b0 117 *
<> 128:9bcdf88f62b0 118 * The SHA-1 implementation is FIPS-180-1 compliant, ref:
<> 128:9bcdf88f62b0 119 * @li Wikipedia - SHA-1, https://en.wikipedia.org/wiki/SHA-1
<> 128:9bcdf88f62b0 120 * @li SHA-1 spec - http://www.itl.nist.gov/fipspubs/fip180-1.htm
<> 128:9bcdf88f62b0 121 *
<> 128:9bcdf88f62b0 122 * The SHA-256 implementation is FIPS-180-2 compliant, ref:
<> 128:9bcdf88f62b0 123 * @li Wikipedia - SHA-2, https://en.wikipedia.org/wiki/SHA-2
<> 128:9bcdf88f62b0 124 * @li SHA-2 spec - http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
<> 128:9bcdf88f62b0 125 *
<> 128:9bcdf88f62b0 126 * @n @section crypto_mul CRYPTO_Mul
<> 128:9bcdf88f62b0 127 * @ref CRYPTO_Mul is a function for multiplying big integers that are
<> 128:9bcdf88f62b0 128 * bigger than the operand size of the MUL instruction which is 128 bits.
<> 128:9bcdf88f62b0 129 * CRYPTO_Mul multiplies all partial operands of the input operands using
<> 128:9bcdf88f62b0 130 * MUL to form a resulting number which may be twice the size of
<> 128:9bcdf88f62b0 131 * the operands.
<> 128:9bcdf88f62b0 132 *
<> 128:9bcdf88f62b0 133 * CRPYTO_Mul is typically used by RSA implementations which perform a
<> 128:9bcdf88f62b0 134 * huge amount of multiplication and square operations in order to
<> 128:9bcdf88f62b0 135 * implement modular exponentiation.
<> 128:9bcdf88f62b0 136 * Some RSA implementations use a number representation including arrays
<> 128:9bcdf88f62b0 137 * of 32bit words of variable size. The user should compile with
<> 128:9bcdf88f62b0 138 * -D USE_VARIABLE_SIZED_DATA_LOADS in order to load these numbers
<> 128:9bcdf88f62b0 139 * directly into CRYPTO without converting the number representation.
<> 128:9bcdf88f62b0 140 *
<> 128:9bcdf88f62b0 141 * @n @section crypto_exec Load and Execute Instruction Sequences
<> 128:9bcdf88f62b0 142 * The functions for loading data and executing instruction sequences can
<> 128:9bcdf88f62b0 143 * be used to implement complex algorithms like elliptic curve cryptography
<> 128:9bcdf88f62b0 144 * (ECC)) and authenticated encryption algorithms. There are two typical
<> 128:9bcdf88f62b0 145 * modes of operation:
<> 128:9bcdf88f62b0 146 * @li Multi sequence operation
<> 128:9bcdf88f62b0 147 * @li Single static instruction sequence operation
<> 128:9bcdf88f62b0 148 *
<> 128:9bcdf88f62b0 149 * In multi sequence mode the software starts by loading input data, then
<> 128:9bcdf88f62b0 150 * an instruction sequence, execute, and finally read the result. This
<> 128:9bcdf88f62b0 151 * process is repeated until the full crypto operation is complete.
<> 128:9bcdf88f62b0 152 *
<> 128:9bcdf88f62b0 153 * When using a single static instruction sequence, there is just one
<> 128:9bcdf88f62b0 154 * instruction sequence which is loaded initially. The sequence can be setup
<> 128:9bcdf88f62b0 155 * to run multiple times. The data can be loaded during the execution of the
<> 128:9bcdf88f62b0 156 * sequence by using DMA, BUFC and/or programmed I/O directly from the MCU
<> 128:9bcdf88f62b0 157 * core. For details on how to program the instruction sequences please refer
<> 128:9bcdf88f62b0 158 * to the reference manual of the particular Silicon Labs device.
<> 128:9bcdf88f62b0 159 *
<> 128:9bcdf88f62b0 160 * In order to load input data to the CRYPTO module use any of the following
<> 128:9bcdf88f62b0 161 * functions:
<> 128:9bcdf88f62b0 162 * @li @ref CRYPTO_DataWrite - Write 128 bits to a DATA register.
<> 128:9bcdf88f62b0 163 * @li @ref CRYPTO_DDataWrite - Write 256 bits to a DDATA register.
<> 128:9bcdf88f62b0 164 * @li @ref CRYPTO_QDataWrite - Write 512 bits to a QDATA register.
<> 128:9bcdf88f62b0 165 *
<> 128:9bcdf88f62b0 166 * In order to read output data from the CRYPTO module use any of the
<> 128:9bcdf88f62b0 167 * following functions:
<> 128:9bcdf88f62b0 168 * @li @ref CRYPTO_DataRead - Read 128 bits from a DATA register.
<> 128:9bcdf88f62b0 169 * @li @ref CRYPTO_DDataRead - Read 256 bits from a DDATA register.
<> 128:9bcdf88f62b0 170 * @li @ref CRYPTO_QDataRead - Read 512 bits from a QDATA register.
<> 128:9bcdf88f62b0 171 *
<> 128:9bcdf88f62b0 172 * In order to load an instruction sequence to the CRYPTO module use
<> 128:9bcdf88f62b0 173 * @ref CRYPTO_InstructionSequenceLoad.
<> 128:9bcdf88f62b0 174 *
<> 128:9bcdf88f62b0 175 * In order to execute the current instruction sequence in the CRYPTO module
<> 128:9bcdf88f62b0 176 * use @ref CRYPTO_InstructionSequenceExecute.
<> 128:9bcdf88f62b0 177 *
<> 128:9bcdf88f62b0 178 * In order to check whether an instruction sequence has completed
<> 128:9bcdf88f62b0 179 * use @ref CRYPTO_InstructionSequenceDone.
<> 128:9bcdf88f62b0 180 *
<> 128:9bcdf88f62b0 181 * In order to wait for an instruction sequence to complete
<> 128:9bcdf88f62b0 182 * use @ref CRYPTO_InstructionSequenceWait.
<> 128:9bcdf88f62b0 183 *
<> 128:9bcdf88f62b0 184 * In order to optimally load (with regards to speed) and execute an
<> 128:9bcdf88f62b0 185 * instruction sequence use any of the CRYPTO_EXECUTE_X macros (where X is
<> 128:9bcdf88f62b0 186 * in the range 1-20) defined in @ref em_crypto.h. E.g. CRYPTO_EXECUTE_19.
Kojto 113:f141b2784e32 187 * @{
Kojto 113:f141b2784e32 188 ******************************************************************************/
Kojto 113:f141b2784e32 189
Kojto 113:f141b2784e32 190 /*******************************************************************************
Kojto 113:f141b2784e32 191 ****************************** DEFINES ***********************************
Kojto 113:f141b2784e32 192 ******************************************************************************/
Kojto 113:f141b2784e32 193
Kojto 113:f141b2784e32 194 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 113:f141b2784e32 195 /** Data sizes used by CRYPTO operations. */
Kojto 113:f141b2784e32 196 #define CRYPTO_DATA_SIZE_IN_BITS (128)
Kojto 113:f141b2784e32 197 #define CRYPTO_DATA_SIZE_IN_BYTES (CRYPTO_DATA_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 198 #define CRYPTO_DATA_SIZE_IN_32BIT_WORDS (CRYPTO_DATA_SIZE_IN_BYTES/sizeof(uint32_t))
Kojto 113:f141b2784e32 199
Kojto 113:f141b2784e32 200 #define CRYPTO_KEYBUF_SIZE_IN_BITS (256)
Kojto 113:f141b2784e32 201 #define CRYPTO_KEYBUF_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 202 #define CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
Kojto 113:f141b2784e32 203
Kojto 113:f141b2784e32 204 #define CRYPTO_DDATA_SIZE_IN_BITS (256)
Kojto 113:f141b2784e32 205 #define CRYPTO_DDATA_SIZE_IN_BYTES (CRYPTO_DDATA_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 206 #define CRYPTO_DDATA_SIZE_IN_32BIT_WORDS (CRYPTO_DDATA_SIZE_IN_BYTES/sizeof(uint32_t))
Kojto 113:f141b2784e32 207
Kojto 113:f141b2784e32 208 #define CRYPTO_QDATA_SIZE_IN_BITS (512)
Kojto 113:f141b2784e32 209 #define CRYPTO_QDATA_SIZE_IN_BYTES (CRYPTO_QDATA_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 210 #define CRYPTO_QDATA_SIZE_IN_32BIT_WORDS (CRYPTO_QDATA_SIZE_IN_BYTES/sizeof(uint32_t))
Kojto 113:f141b2784e32 211
Kojto 113:f141b2784e32 212 #define CRYPTO_DATA260_SIZE_IN_32BIT_WORDS (9)
Kojto 113:f141b2784e32 213
Kojto 113:f141b2784e32 214 /** SHA-1 digest sizes */
Kojto 113:f141b2784e32 215 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BITS (160)
Kojto 113:f141b2784e32 216 #define CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA1_DIGEST_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 217
Kojto 113:f141b2784e32 218 /** SHA-256 digest sizes */
Kojto 113:f141b2784e32 219 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BITS (256)
Kojto 113:f141b2784e32 220 #define CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES (CRYPTO_SHA256_DIGEST_SIZE_IN_BITS/8)
Kojto 113:f141b2784e32 221
Kojto 113:f141b2784e32 222 /**
Kojto 113:f141b2784e32 223 * Read and write all 260 bits of DDATA0 when in 260 bit mode.
Kojto 113:f141b2784e32 224 */
<> 128:9bcdf88f62b0 225 #define CRYPTO_DDATA0_260_BITS_READ(crypto, bigint260) CRYPTO_DData0Read260(crypto, bigint260)
<> 128:9bcdf88f62b0 226 #define CRYPTO_DDATA0_260_BITS_WRITE(crypto, bigint260) CRYPTO_DData0Write260(crypto, bigint260)
Kojto 113:f141b2784e32 227 /** @endcond */
Kojto 113:f141b2784e32 228
Kojto 113:f141b2784e32 229 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 113:f141b2784e32 230 /**
Kojto 113:f141b2784e32 231 * Instruction sequence load macros CRYPTO_SEQ_LOAD_X (where X is in the range
Kojto 113:f141b2784e32 232 * 1-20). E.g. @ref CRYPTO_SEQ_LOAD_20.
Kojto 113:f141b2784e32 233 * Use these macros in order for faster execution than the function API.
Kojto 113:f141b2784e32 234 */
<> 128:9bcdf88f62b0 235 #define CRYPTO_SEQ_LOAD_1(crypto, a1) { \
<> 128:9bcdf88f62b0 236 crypto->SEQ0 = a1 | (CRYPTO_CMD_INSTR_END<<8);}
<> 128:9bcdf88f62b0 237 #define CRYPTO_SEQ_LOAD_2(crypto, a1, a2) { \
<> 128:9bcdf88f62b0 238 crypto->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_END<<16);}
<> 128:9bcdf88f62b0 239 #define CRYPTO_SEQ_LOAD_3(crypto, a1, a2, a3) { \
<> 128:9bcdf88f62b0 240 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_END<<24);}
<> 128:9bcdf88f62b0 241 #define CRYPTO_SEQ_LOAD_4(crypto, a1, a2, a3, a4) { \
<> 128:9bcdf88f62b0 242 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 243 crypto->SEQ1 = CRYPTO_CMD_INSTR_END;}
<> 128:9bcdf88f62b0 244 #define CRYPTO_SEQ_LOAD_5(crypto, a1, a2, a3, a4, a5) { \
<> 128:9bcdf88f62b0 245 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 246 crypto->SEQ1 = a5 | (CRYPTO_CMD_INSTR_END<<8);}
<> 128:9bcdf88f62b0 247 #define CRYPTO_SEQ_LOAD_6(crypto, a1, a2, a3, a4, a5, a6) { \
<> 128:9bcdf88f62b0 248 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 249 crypto->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_END<<16);}
<> 128:9bcdf88f62b0 250 #define CRYPTO_SEQ_LOAD_7(crypto, a1, a2, a3, a4, a5, a6, a7) { \
<> 128:9bcdf88f62b0 251 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 252 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_END<<24);}
<> 128:9bcdf88f62b0 253 #define CRYPTO_SEQ_LOAD_8(crypto, a1, a2, a3, a4, a5, a6, a7, a8) { \
<> 128:9bcdf88f62b0 254 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 255 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 256 crypto->SEQ2 = CRYPTO_CMD_INSTR_END;}
<> 128:9bcdf88f62b0 257 #define CRYPTO_SEQ_LOAD_9(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
<> 128:9bcdf88f62b0 258 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 259 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 260 crypto->SEQ2 = a9 | (CRYPTO_CMD_INSTR_END<<8);}
<> 128:9bcdf88f62b0 261 #define CRYPTO_SEQ_LOAD_10(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
<> 128:9bcdf88f62b0 262 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 263 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 264 crypto->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_END<<16);}
<> 128:9bcdf88f62b0 265 #define CRYPTO_SEQ_LOAD_11(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
<> 128:9bcdf88f62b0 266 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 267 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 268 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_END<<24);}
<> 128:9bcdf88f62b0 269 #define CRYPTO_SEQ_LOAD_12(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
<> 128:9bcdf88f62b0 270 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 271 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 272 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 273 crypto->SEQ3 = CRYPTO_CMD_INSTR_END;}
<> 128:9bcdf88f62b0 274 #define CRYPTO_SEQ_LOAD_13(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
<> 128:9bcdf88f62b0 275 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 276 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 277 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 278 crypto->SEQ3 = a13 | (CRYPTO_CMD_INSTR_END<<8);}
<> 128:9bcdf88f62b0 279 #define CRYPTO_SEQ_LOAD_14(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
<> 128:9bcdf88f62b0 280 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 281 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 282 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 283 crypto->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_END<<16);}
<> 128:9bcdf88f62b0 284 #define CRYPTO_SEQ_LOAD_15(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
<> 128:9bcdf88f62b0 285 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 286 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 287 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 288 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_END<<24);}
<> 128:9bcdf88f62b0 289 #define CRYPTO_SEQ_LOAD_16(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
<> 128:9bcdf88f62b0 290 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 291 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 292 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 293 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 294 crypto->SEQ4 = CRYPTO_CMD_INSTR_END;}
<> 128:9bcdf88f62b0 295 #define CRYPTO_SEQ_LOAD_17(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
<> 128:9bcdf88f62b0 296 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 297 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 298 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 299 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 300 crypto->SEQ4 = a17 | (CRYPTO_CMD_INSTR_END<<8);}
<> 128:9bcdf88f62b0 301 #define CRYPTO_SEQ_LOAD_18(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
<> 128:9bcdf88f62b0 302 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 303 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 304 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 305 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 306 crypto->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_END<<16);}
<> 128:9bcdf88f62b0 307 #define CRYPTO_SEQ_LOAD_19(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
<> 128:9bcdf88f62b0 308 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 309 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 310 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 311 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 312 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_END<<24);}
<> 128:9bcdf88f62b0 313 #define CRYPTO_SEQ_LOAD_20(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
<> 128:9bcdf88f62b0 314 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 315 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 316 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 317 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 318 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24);}
Kojto 113:f141b2784e32 319 /** @endcond */
Kojto 113:f141b2784e32 320
Kojto 113:f141b2784e32 321 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 113:f141b2784e32 322 /**
Kojto 113:f141b2784e32 323 * Instruction sequence execution macros CRYPTO_EXECUTE_X (where X is in the range
Kojto 113:f141b2784e32 324 * 1-20). E.g. @ref CRYPTO_EXECUTE_19.
Kojto 113:f141b2784e32 325 * Use these macros in order for faster execution than the function API.
Kojto 113:f141b2784e32 326 */
<> 128:9bcdf88f62b0 327 #define CRYPTO_EXECUTE_1(crypto, a1) { \
<> 128:9bcdf88f62b0 328 crypto->SEQ0 = a1 | (CRYPTO_CMD_INSTR_EXEC<<8); }
<> 128:9bcdf88f62b0 329 #define CRYPTO_EXECUTE_2(crypto, a1, a2) { \
<> 128:9bcdf88f62b0 330 crypto->SEQ0 = a1 | (a2<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
<> 128:9bcdf88f62b0 331 #define CRYPTO_EXECUTE_3(crypto, a1, a2, a3) { \
<> 128:9bcdf88f62b0 332 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
<> 128:9bcdf88f62b0 333 #define CRYPTO_EXECUTE_4(crypto, a1, a2, a3, a4) { \
<> 128:9bcdf88f62b0 334 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 335 crypto->SEQ1 = CRYPTO_CMD_INSTR_EXEC; }
<> 128:9bcdf88f62b0 336 #define CRYPTO_EXECUTE_5(crypto, a1, a2, a3, a4, a5) { \
<> 128:9bcdf88f62b0 337 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 338 crypto->SEQ1 = a5 | (CRYPTO_CMD_INSTR_EXEC<<8); }
<> 128:9bcdf88f62b0 339 #define CRYPTO_EXECUTE_6(crypto, a1, a2, a3, a4, a5, a6) { \
<> 128:9bcdf88f62b0 340 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 341 crypto->SEQ1 = a5 | (a6<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
<> 128:9bcdf88f62b0 342 #define CRYPTO_EXECUTE_7(crypto, a1, a2, a3, a4, a5, a6, a7) { \
<> 128:9bcdf88f62b0 343 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 344 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
<> 128:9bcdf88f62b0 345 #define CRYPTO_EXECUTE_8(crypto, a1, a2, a3, a4, a5, a6, a7, a8) { \
<> 128:9bcdf88f62b0 346 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 347 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 348 crypto->SEQ2 = CRYPTO_CMD_INSTR_EXEC; }
<> 128:9bcdf88f62b0 349 #define CRYPTO_EXECUTE_9(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9) { \
<> 128:9bcdf88f62b0 350 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 351 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 352 crypto->SEQ2 = a9 | (CRYPTO_CMD_INSTR_EXEC<<8); }
<> 128:9bcdf88f62b0 353 #define CRYPTO_EXECUTE_10(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { \
<> 128:9bcdf88f62b0 354 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 355 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 356 crypto->SEQ2 = a9 | (a10<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
<> 128:9bcdf88f62b0 357 #define CRYPTO_EXECUTE_11(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { \
<> 128:9bcdf88f62b0 358 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 359 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 360 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
<> 128:9bcdf88f62b0 361 #define CRYPTO_EXECUTE_12(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { \
<> 128:9bcdf88f62b0 362 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 363 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 364 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 365 crypto->SEQ3 = CRYPTO_CMD_INSTR_EXEC; }
<> 128:9bcdf88f62b0 366 #define CRYPTO_EXECUTE_13(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { \
<> 128:9bcdf88f62b0 367 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 368 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 369 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 370 crypto->SEQ3 = a13 | (CRYPTO_CMD_INSTR_EXEC<<8); }
<> 128:9bcdf88f62b0 371 #define CRYPTO_EXECUTE_14(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { \
<> 128:9bcdf88f62b0 372 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 373 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 374 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 375 crypto->SEQ3 = a13 | (a14<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
<> 128:9bcdf88f62b0 376 #define CRYPTO_EXECUTE_15(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) { \
<> 128:9bcdf88f62b0 377 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 378 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 379 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 380 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
<> 128:9bcdf88f62b0 381 #define CRYPTO_EXECUTE_16(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) { \
<> 128:9bcdf88f62b0 382 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 383 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 384 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 385 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 386 crypto->SEQ4 = CRYPTO_CMD_INSTR_EXEC; }
<> 128:9bcdf88f62b0 387 #define CRYPTO_EXECUTE_17(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17) { \
<> 128:9bcdf88f62b0 388 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 389 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 390 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 391 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 392 crypto->SEQ4 = a17 | (CRYPTO_CMD_INSTR_EXEC<<8); }
<> 128:9bcdf88f62b0 393 #define CRYPTO_EXECUTE_18(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) { \
<> 128:9bcdf88f62b0 394 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 395 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 396 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 397 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 398 crypto->SEQ4 = a17 | (a18<<8) | (CRYPTO_CMD_INSTR_EXEC<<16); }
<> 128:9bcdf88f62b0 399 #define CRYPTO_EXECUTE_19(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) { \
<> 128:9bcdf88f62b0 400 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 401 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 402 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 403 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 404 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (CRYPTO_CMD_INSTR_EXEC<<24); }
<> 128:9bcdf88f62b0 405 #define CRYPTO_EXECUTE_20(crypto, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) { \
<> 128:9bcdf88f62b0 406 crypto->SEQ0 = a1 | (a2<<8) | (a3<<16) | (a4<<24); \
<> 128:9bcdf88f62b0 407 crypto->SEQ1 = a5 | (a6<<8) | (a7<<16) | (a8<<24); \
<> 128:9bcdf88f62b0 408 crypto->SEQ2 = a9 | (a10<<8) | (a11<<16) | (a12<<24); \
<> 128:9bcdf88f62b0 409 crypto->SEQ3 = a13 | (a14<<8) | (a15<<16) | (a16<<24); \
<> 128:9bcdf88f62b0 410 crypto->SEQ4 = a17 | (a18<<8) | (a19<<16) | (a20<<24); \
Kojto 113:f141b2784e32 411 CRYPTO_InstructionSequenceExecute();}
Kojto 113:f141b2784e32 412 /** @endcond */
Kojto 113:f141b2784e32 413
Kojto 113:f141b2784e32 414 /*******************************************************************************
Kojto 113:f141b2784e32 415 ****************************** TYPEDEFS ***********************************
Kojto 113:f141b2784e32 416 ******************************************************************************/
Kojto 113:f141b2784e32 417
Kojto 113:f141b2784e32 418 /**
Kojto 113:f141b2784e32 419 * CRYPTO data types used for data load functions. This data type is
Kojto 113:f141b2784e32 420 * capable of storing a 128 bits value as used in the crypto DATA
Kojto 113:f141b2784e32 421 * registers
Kojto 113:f141b2784e32 422 */
Kojto 113:f141b2784e32 423 typedef uint32_t CRYPTO_Data_TypeDef[CRYPTO_DATA_SIZE_IN_32BIT_WORDS];
Kojto 113:f141b2784e32 424
Kojto 113:f141b2784e32 425 /**
Kojto 113:f141b2784e32 426 * CRYPTO data type used for data load functions. This data type
Kojto 113:f141b2784e32 427 * is capable of storing a 256 bits value as used in the crypto DDATA
Kojto 113:f141b2784e32 428 * registers
Kojto 113:f141b2784e32 429 */
Kojto 113:f141b2784e32 430 typedef uint32_t CRYPTO_DData_TypeDef[CRYPTO_DDATA_SIZE_IN_32BIT_WORDS];
Kojto 113:f141b2784e32 431
Kojto 113:f141b2784e32 432 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
Kojto 113:f141b2784e32 433 typedef uint32_t* CRYPTO_DDataPtr_TypeDef;
Kojto 113:f141b2784e32 434 /** @endcond */
Kojto 113:f141b2784e32 435
Kojto 113:f141b2784e32 436 /**
Kojto 113:f141b2784e32 437 * CRYPTO data type used for data load functions. This data type is
Kojto 113:f141b2784e32 438 * capable of storing a 512 bits value as used in the crypto QDATA
Kojto 113:f141b2784e32 439 * registers
Kojto 113:f141b2784e32 440 */
Kojto 113:f141b2784e32 441 typedef uint32_t CRYPTO_QData_TypeDef[CRYPTO_QDATA_SIZE_IN_32BIT_WORDS];
Kojto 113:f141b2784e32 442
Kojto 113:f141b2784e32 443 /**
Kojto 113:f141b2784e32 444 * CRYPTO data type used for data load functions. This data type is
Kojto 113:f141b2784e32 445 * capable of storing a 260 bits value as used by the @ref CRYPTO_DData0Write260
Kojto 113:f141b2784e32 446 * function.
Kojto 113:f141b2784e32 447 *
Kojto 113:f141b2784e32 448 * Note that this data type is multiple of 32 bit words, so the
Kojto 113:f141b2784e32 449 * actual storage used by this type is 32x9=288 bits.
Kojto 113:f141b2784e32 450 */
Kojto 113:f141b2784e32 451 typedef uint32_t CRYPTO_Data260_TypeDef[CRYPTO_DATA260_SIZE_IN_32BIT_WORDS];
Kojto 113:f141b2784e32 452
Kojto 113:f141b2784e32 453 /**
Kojto 113:f141b2784e32 454 * CRYPTO data type used for data load functions. This data type is
Kojto 113:f141b2784e32 455 * capable of storing 256 bits as used in the crypto KEYBUF register.
Kojto 113:f141b2784e32 456 */
Kojto 113:f141b2784e32 457 typedef uint32_t CRYPTO_KeyBuf_TypeDef[CRYPTO_KEYBUF_SIZE_IN_32BIT_WORDS];
Kojto 113:f141b2784e32 458
Kojto 113:f141b2784e32 459 /**
<> 128:9bcdf88f62b0 460 * CRYPTO 128 bit Data register pointer type. The 128 bit registers are used to
<> 128:9bcdf88f62b0 461 * load 128 bit values as input and output data for cryptographic and big
<> 128:9bcdf88f62b0 462 * integer arithmetic functions of the CRYPTO module.
Kojto 113:f141b2784e32 463 */
<> 128:9bcdf88f62b0 464 typedef volatile uint32_t* CRYPTO_DataReg_TypeDef;
Kojto 113:f141b2784e32 465
Kojto 113:f141b2784e32 466 /**
<> 128:9bcdf88f62b0 467 * CRYPTO 256 bit DData (Double Data) register pointer type. The 256 bit
<> 128:9bcdf88f62b0 468 * registers are used to load 256 bit values as input and output data for
<> 128:9bcdf88f62b0 469 * cryptographic and big integer arithmetic functions of the CRYPTO module.
Kojto 113:f141b2784e32 470 */
<> 128:9bcdf88f62b0 471 typedef volatile uint32_t* CRYPTO_DDataReg_TypeDef;
Kojto 113:f141b2784e32 472
Kojto 113:f141b2784e32 473 /**
<> 128:9bcdf88f62b0 474 * CRYPTO 512 bit QData (Quad data) register pointer type. The 512 bit
<> 128:9bcdf88f62b0 475 * registers are used to load 512 bit values as input and output data for
<> 128:9bcdf88f62b0 476 * cryptographic and big integer arithmetic functions of the CRYPTO module.
Kojto 113:f141b2784e32 477 */
<> 128:9bcdf88f62b0 478 typedef volatile uint32_t* CRYPTO_QDataReg_TypeDef;
Kojto 113:f141b2784e32 479
<> 128:9bcdf88f62b0 480 /** CRYPTO modulus identifiers. */
Kojto 113:f141b2784e32 481 typedef enum
Kojto 113:f141b2784e32 482 {
Kojto 113:f141b2784e32 483 cryptoModulusBin256 = CRYPTO_WAC_MODULUS_BIN256, /**< Generic 256 bit modulus 2^256 */
Kojto 113:f141b2784e32 484 cryptoModulusBin128 = CRYPTO_WAC_MODULUS_BIN128, /**< Generic 128 bit modulus 2^128 */
Kojto 113:f141b2784e32 485 cryptoModulusGcmBin128 = CRYPTO_WAC_MODULUS_GCMBIN128, /**< GCM 128 bit modulus = 2^128 + 2^7 + 2^2 + 2 + 1 */
Kojto 113:f141b2784e32 486 cryptoModulusEccB233 = CRYPTO_WAC_MODULUS_ECCBIN233P, /**< ECC B233 prime modulus = 2^233 + 2^74 + 1 */
Kojto 113:f141b2784e32 487 cryptoModulusEccB163 = CRYPTO_WAC_MODULUS_ECCBIN163P, /**< ECC B163 prime modulus = 2^163 + 2^7 + 2^6 + 2^3 + 1 */
Kojto 113:f141b2784e32 488 cryptoModulusEccP256 = CRYPTO_WAC_MODULUS_ECCPRIME256P, /**< ECC P256 prime modulus = 2^256 - 2^224 + 2^192 + 2^96 - 1 */
Kojto 113:f141b2784e32 489 cryptoModulusEccP224 = CRYPTO_WAC_MODULUS_ECCPRIME224P, /**< ECC P224 prime modulus = 2^224 - 2^96 - 1 */
Kojto 113:f141b2784e32 490 cryptoModulusEccP192 = CRYPTO_WAC_MODULUS_ECCPRIME192P, /**< ECC P192 prime modulus = 2^192 - 2^64 - 1 */
Kojto 113:f141b2784e32 491 cryptoModulusEccB233Order = CRYPTO_WAC_MODULUS_ECCBIN233N, /**< ECC B233 order modulus */
Kojto 113:f141b2784e32 492 cryptoModulusEccB233KOrder = CRYPTO_WAC_MODULUS_ECCBIN233KN, /**< ECC B233K order modulus */
Kojto 113:f141b2784e32 493 cryptoModulusEccB163Order = CRYPTO_WAC_MODULUS_ECCBIN163N, /**< ECC B163 order modulus */
Kojto 113:f141b2784e32 494 cryptoModulusEccB163KOrder = CRYPTO_WAC_MODULUS_ECCBIN163KN, /**< ECC B163K order modulus */
Kojto 113:f141b2784e32 495 cryptoModulusEccP256Order = CRYPTO_WAC_MODULUS_ECCPRIME256N, /**< ECC P256 order modulus */
Kojto 113:f141b2784e32 496 cryptoModulusEccP224Order = CRYPTO_WAC_MODULUS_ECCPRIME224N, /**< ECC P224 order modulus */
Kojto 113:f141b2784e32 497 cryptoModulusEccP192Order = CRYPTO_WAC_MODULUS_ECCPRIME192N /**< ECC P192 order modulus */
<> 128:9bcdf88f62b0 498 } CRYPTO_ModulusId_TypeDef;
Kojto 113:f141b2784e32 499
Kojto 113:f141b2784e32 500 /** CRYPTO multiplication widths for wide arithmetic operations. */
Kojto 113:f141b2784e32 501 typedef enum
Kojto 113:f141b2784e32 502 {
Kojto 113:f141b2784e32 503 cryptoMulOperand256Bits = CRYPTO_WAC_MULWIDTH_MUL256, /**< 256 bits operands */
Kojto 113:f141b2784e32 504 cryptoMulOperand128Bits = CRYPTO_WAC_MULWIDTH_MUL128, /**< 128 bits operands */
Kojto 113:f141b2784e32 505 cryptoMulOperandModulusBits = CRYPTO_WAC_MULWIDTH_MULMOD /**< MUL operand width
Kojto 113:f141b2784e32 506 is specified by the
Kojto 113:f141b2784e32 507 modulus type.*/
Kojto 113:f141b2784e32 508 } CRYPTO_MulOperandWidth_TypeDef;
Kojto 113:f141b2784e32 509
Kojto 113:f141b2784e32 510 /** CRYPTO result widths for MUL operations. */
Kojto 113:f141b2784e32 511 typedef enum
Kojto 113:f141b2784e32 512 {
Kojto 113:f141b2784e32 513 cryptoResult128Bits = CRYPTO_WAC_RESULTWIDTH_128BIT, /**< Multiplication result width is 128 bits*/
Kojto 113:f141b2784e32 514 cryptoResult256Bits = CRYPTO_WAC_RESULTWIDTH_256BIT, /**< Multiplication result width is 256 bits*/
Kojto 113:f141b2784e32 515 cryptoResult260Bits = CRYPTO_WAC_RESULTWIDTH_260BIT /**< Multiplication result width is 260 bits*/
Kojto 113:f141b2784e32 516 } CRYPTO_ResultWidth_TypeDef;
Kojto 113:f141b2784e32 517
Kojto 113:f141b2784e32 518 /** CRYPTO result widths for MUL operations. */
Kojto 113:f141b2784e32 519 typedef enum
Kojto 113:f141b2784e32 520 {
Kojto 113:f141b2784e32 521 cryptoInc1byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH1, /**< inc width is 1 byte*/
Kojto 113:f141b2784e32 522 cryptoInc2byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH2, /**< inc width is 2 byte*/
Kojto 113:f141b2784e32 523 cryptoInc3byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH3, /**< inc width is 3 byte*/
Kojto 113:f141b2784e32 524 cryptoInc4byte = CRYPTO_CTRL_INCWIDTH_INCWIDTH4 /**< inc width is 4 byte*/
Kojto 113:f141b2784e32 525 } CRYPTO_IncWidth_TypeDef;
Kojto 113:f141b2784e32 526
Kojto 113:f141b2784e32 527 /** CRYPTO key width. */
Kojto 113:f141b2784e32 528 typedef enum
Kojto 113:f141b2784e32 529 {
Kojto 113:f141b2784e32 530 cryptoKey128Bits = 8, /**< Key width is 128 bits*/
Kojto 113:f141b2784e32 531 cryptoKey256Bits = 16, /**< Key width is 256 bits*/
Kojto 113:f141b2784e32 532 } CRYPTO_KeyWidth_TypeDef;
Kojto 113:f141b2784e32 533
Kojto 113:f141b2784e32 534 /**
Kojto 113:f141b2784e32 535 * The max number of crypto instructions in an instruction sequence
Kojto 113:f141b2784e32 536 */
Kojto 113:f141b2784e32 537 #define CRYPTO_MAX_SEQUENCE_INSTRUCTIONS (20)
Kojto 113:f141b2784e32 538
Kojto 113:f141b2784e32 539 /**
Kojto 113:f141b2784e32 540 * Instruction sequence type.
Kojto 113:f141b2784e32 541 * The user should fill in the desired operations from step1, then step2 etc.
Kojto 113:f141b2784e32 542 * The CRYPTO_CMD_INSTR_END marks the end of the sequence.
Kojto 113:f141b2784e32 543 * Bit fields are used to format the memory layout of the struct equal to the
Kojto 113:f141b2784e32 544 * sequence registers in the CRYPTO module.
Kojto 113:f141b2784e32 545 */
Kojto 113:f141b2784e32 546 typedef uint8_t CRYPTO_InstructionSequence_TypeDef[CRYPTO_MAX_SEQUENCE_INSTRUCTIONS];
Kojto 113:f141b2784e32 547
Kojto 113:f141b2784e32 548 /** Default instruction sequence consisting of all ENDs. The user can
Kojto 113:f141b2784e32 549 initialize the instruction sequence with this default value set, and fill
Kojto 113:f141b2784e32 550 in the desired operations from step 1. The first END instruction marks
Kojto 113:f141b2784e32 551 the end of the sequence. */
Kojto 113:f141b2784e32 552 #define CRYPTO_INSTRUCTIONSEQUENSE_DEFAULT \
Kojto 113:f141b2784e32 553 {CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 554 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 555 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 556 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 557 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 558 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END, \
Kojto 113:f141b2784e32 559 CRYPTO_CMD_INSTR_END, CRYPTO_CMD_INSTR_END}
Kojto 113:f141b2784e32 560
Kojto 113:f141b2784e32 561 /** SHA-1 Digest type. */
Kojto 113:f141b2784e32 562 typedef uint8_t CRYPTO_SHA1_Digest_TypeDef[CRYPTO_SHA1_DIGEST_SIZE_IN_BYTES];
Kojto 113:f141b2784e32 563
Kojto 113:f141b2784e32 564 /** SHA-256 Digest type. */
Kojto 113:f141b2784e32 565 typedef uint8_t CRYPTO_SHA256_Digest_TypeDef[CRYPTO_SHA256_DIGEST_SIZE_IN_BYTES];
Kojto 113:f141b2784e32 566
Kojto 113:f141b2784e32 567 /**
Kojto 113:f141b2784e32 568 * @brief
Kojto 113:f141b2784e32 569 * AES counter modification function pointer.
Kojto 113:f141b2784e32 570 *
Kojto 113:f141b2784e32 571 * @note
Kojto 113:f141b2784e32 572 * This is defined in order for backwards compatibility with EFM32 em_aes.h.
Kojto 113:f141b2784e32 573 * The CRYPTO implementation of Counter mode does not support counter update
Kojto 113:f141b2784e32 574 * callbacks.
<> 128:9bcdf88f62b0 575 *
Kojto 113:f141b2784e32 576 * @param[in] ctr Counter value to be modified.
Kojto 113:f141b2784e32 577 */
Kojto 113:f141b2784e32 578 typedef void (*CRYPTO_AES_CtrFuncPtr_TypeDef)(uint8_t * ctr);
Kojto 113:f141b2784e32 579
Kojto 113:f141b2784e32 580 /*******************************************************************************
Kojto 113:f141b2784e32 581 ***************************** PROTOTYPES **********************************
Kojto 113:f141b2784e32 582 ******************************************************************************/
Kojto 113:f141b2784e32 583
Kojto 113:f141b2784e32 584 /***************************************************************************//**
Kojto 113:f141b2784e32 585 * @brief
Kojto 113:f141b2784e32 586 * Set the modulus type used for wide arithmetic operations.
Kojto 113:f141b2784e32 587 *
Kojto 113:f141b2784e32 588 * @details
Kojto 113:f141b2784e32 589 * This function sets the modulus type to be used by the Modulus instructions
Kojto 113:f141b2784e32 590 * of the CRYPTO module.
Kojto 113:f141b2784e32 591 *
<> 128:9bcdf88f62b0 592 * @param[in] crypto
<> 128:9bcdf88f62b0 593 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 594 *
<> 128:9bcdf88f62b0 595 * @param[in] modType
<> 128:9bcdf88f62b0 596 * Modulus type.
Kojto 113:f141b2784e32 597 ******************************************************************************/
<> 128:9bcdf88f62b0 598 void CRYPTO_ModulusSet(CRYPTO_TypeDef * crypto,
<> 128:9bcdf88f62b0 599 CRYPTO_ModulusId_TypeDef modType);
Kojto 113:f141b2784e32 600
Kojto 113:f141b2784e32 601 /***************************************************************************//**
Kojto 113:f141b2784e32 602 * @brief
Kojto 113:f141b2784e32 603 * Set the number of bits in the operands of the MUL instruction.
Kojto 113:f141b2784e32 604 *
Kojto 113:f141b2784e32 605 * @details
Kojto 113:f141b2784e32 606 * This function sets the number of bits to be used in the operands of
Kojto 113:f141b2784e32 607 * the MUL instruction.
Kojto 113:f141b2784e32 608 *
<> 128:9bcdf88f62b0 609 * @param[in] crypto
<> 128:9bcdf88f62b0 610 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 611 *
<> 128:9bcdf88f62b0 612 * @param[in] mulOperandWidth
<> 128:9bcdf88f62b0 613 * Multiplication width in bits.
Kojto 113:f141b2784e32 614 ******************************************************************************/
<> 128:9bcdf88f62b0 615 __STATIC_INLINE
<> 128:9bcdf88f62b0 616 void CRYPTO_MulOperandWidthSet(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 617 CRYPTO_MulOperandWidth_TypeDef mulOperandWidth)
Kojto 113:f141b2784e32 618 {
<> 128:9bcdf88f62b0 619 uint32_t temp = crypto->WAC & (~_CRYPTO_WAC_MULWIDTH_MASK);
<> 128:9bcdf88f62b0 620 crypto->WAC = temp | mulOperandWidth;
Kojto 113:f141b2784e32 621 }
Kojto 113:f141b2784e32 622
Kojto 113:f141b2784e32 623 /***************************************************************************//**
Kojto 113:f141b2784e32 624 * @brief
Kojto 113:f141b2784e32 625 * Set the width of the results of the non-modulus instructions.
Kojto 113:f141b2784e32 626 *
Kojto 113:f141b2784e32 627 * @details
Kojto 113:f141b2784e32 628 * This function sets the result width of the non-modulus instructions.
Kojto 113:f141b2784e32 629 *
<> 128:9bcdf88f62b0 630 * @param[in] crypto
<> 128:9bcdf88f62b0 631 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 632 *
<> 128:9bcdf88f62b0 633 * @param[in] resultWidth
<> 128:9bcdf88f62b0 634 * Result width of non-modulus instructions.
Kojto 113:f141b2784e32 635 ******************************************************************************/
<> 128:9bcdf88f62b0 636 __STATIC_INLINE
<> 128:9bcdf88f62b0 637 void CRYPTO_ResultWidthSet(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 638 CRYPTO_ResultWidth_TypeDef resultWidth)
Kojto 113:f141b2784e32 639 {
<> 128:9bcdf88f62b0 640 uint32_t temp = crypto->WAC & (~_CRYPTO_WAC_RESULTWIDTH_MASK);
<> 128:9bcdf88f62b0 641 crypto->WAC = temp | resultWidth;
Kojto 113:f141b2784e32 642 }
Kojto 113:f141b2784e32 643
Kojto 113:f141b2784e32 644 /***************************************************************************//**
Kojto 113:f141b2784e32 645 * @brief
Kojto 113:f141b2784e32 646 * Set the width of the DATA1 increment instruction DATA1INC.
Kojto 113:f141b2784e32 647 *
Kojto 113:f141b2784e32 648 * @details
Kojto 113:f141b2784e32 649 * This function sets the width of the DATA1 increment instruction
Kojto 113:f141b2784e32 650 * @ref CRYPTO_CMD_INSTR_DATA1INC.
Kojto 113:f141b2784e32 651 *
<> 128:9bcdf88f62b0 652 * @param[in] crypto
<> 128:9bcdf88f62b0 653 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 654 *
<> 128:9bcdf88f62b0 655 * @param[in] incWidth
<> 128:9bcdf88f62b0 656 * incrementation width.
Kojto 113:f141b2784e32 657 ******************************************************************************/
<> 128:9bcdf88f62b0 658 __STATIC_INLINE void CRYPTO_IncWidthSet(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 659 CRYPTO_IncWidth_TypeDef incWidth)
Kojto 113:f141b2784e32 660 {
<> 128:9bcdf88f62b0 661 uint32_t temp = crypto->CTRL & (~_CRYPTO_CTRL_INCWIDTH_MASK);
<> 128:9bcdf88f62b0 662 crypto->CTRL = temp | incWidth;
Kojto 113:f141b2784e32 663 }
Kojto 113:f141b2784e32 664
Kojto 113:f141b2784e32 665 /***************************************************************************//**
Kojto 113:f141b2784e32 666 * @brief
Kojto 113:f141b2784e32 667 * Write a 128 bit value into a crypto register.
Kojto 113:f141b2784e32 668 *
Kojto 113:f141b2784e32 669 * @note
Kojto 113:f141b2784e32 670 * This function provide a low-level api for writing to the multi-word
Kojto 113:f141b2784e32 671 * registers in the crypto peripheral. Applications should prefer to use
Kojto 113:f141b2784e32 672 * @ref CRYPTO_DataWrite, @ref CRYPTO_DDataWrite or @ref CRYPTO_QDataWrite
Kojto 113:f141b2784e32 673 * for writing to the DATA, DDATA and QDATA registers.
Kojto 113:f141b2784e32 674 *
Kojto 113:f141b2784e32 675 * @param[in] reg
Kojto 113:f141b2784e32 676 * Pointer to the crypto register.
Kojto 113:f141b2784e32 677 *
Kojto 113:f141b2784e32 678 * @param[in] val
Kojto 113:f141b2784e32 679 * This is a pointer to 4 32 bit integers that contains the 128 bit value
Kojto 113:f141b2784e32 680 * which will be written to the crypto register.
Kojto 113:f141b2784e32 681 ******************************************************************************/
<> 128:9bcdf88f62b0 682 __STATIC_INLINE void CRYPTO_BurstToCrypto(volatile uint32_t * reg,
<> 128:9bcdf88f62b0 683 const uint32_t * val)
Kojto 113:f141b2784e32 684 {
Kojto 113:f141b2784e32 685 /* Load data from memory into local registers. */
Kojto 113:f141b2784e32 686 register uint32_t v0 = val[0];
Kojto 113:f141b2784e32 687 register uint32_t v1 = val[1];
Kojto 113:f141b2784e32 688 register uint32_t v2 = val[2];
Kojto 113:f141b2784e32 689 register uint32_t v3 = val[3];
Kojto 113:f141b2784e32 690 /* Store data to CRYPTO */
Kojto 113:f141b2784e32 691 *reg = v0;
Kojto 113:f141b2784e32 692 *reg = v1;
Kojto 113:f141b2784e32 693 *reg = v2;
Kojto 113:f141b2784e32 694 *reg = v3;
Kojto 113:f141b2784e32 695 }
Kojto 113:f141b2784e32 696
Kojto 113:f141b2784e32 697 /***************************************************************************//**
Kojto 113:f141b2784e32 698 * @brief
Kojto 113:f141b2784e32 699 * Read a 128 bit value from a crypto register.
Kojto 113:f141b2784e32 700 *
Kojto 113:f141b2784e32 701 * @note
Kojto 113:f141b2784e32 702 * This function provide a low-level api for reading one of the multi-word
Kojto 113:f141b2784e32 703 * registers in the crypto peripheral. Applications should prefer to use
Kojto 113:f141b2784e32 704 * @ref CRYPTO_DataRead, @ref CRYPTO_DDataRead or @ref CRYPTO_QDataRead
Kojto 113:f141b2784e32 705 * for reading the value of the DATA, DDATA and QDATA registers.
Kojto 113:f141b2784e32 706 *
Kojto 113:f141b2784e32 707 * @param[in] reg
Kojto 113:f141b2784e32 708 * Pointer to the crypto register.
Kojto 113:f141b2784e32 709 *
Kojto 113:f141b2784e32 710 * @param[out] val
Kojto 113:f141b2784e32 711 * This is a pointer to an array that is capable of holding 4 32 bit integers
Kojto 113:f141b2784e32 712 * that will be filled with the 128 bit value from the crypto register.
Kojto 113:f141b2784e32 713 ******************************************************************************/
Kojto 113:f141b2784e32 714 __STATIC_INLINE void CRYPTO_BurstFromCrypto(volatile uint32_t * reg, uint32_t * val)
Kojto 113:f141b2784e32 715 {
Kojto 113:f141b2784e32 716 /* Load data from CRYPTO into local registers. */
Kojto 113:f141b2784e32 717 register uint32_t v0 = *reg;
Kojto 113:f141b2784e32 718 register uint32_t v1 = *reg;
Kojto 113:f141b2784e32 719 register uint32_t v2 = *reg;
Kojto 113:f141b2784e32 720 register uint32_t v3 = *reg;
Kojto 113:f141b2784e32 721 /* Store data to memory */
Kojto 113:f141b2784e32 722 val[0] = v0;
Kojto 113:f141b2784e32 723 val[1] = v1;
Kojto 113:f141b2784e32 724 val[2] = v2;
Kojto 113:f141b2784e32 725 val[3] = v3;
Kojto 113:f141b2784e32 726 }
Kojto 113:f141b2784e32 727
Kojto 113:f141b2784e32 728 /***************************************************************************//**
Kojto 113:f141b2784e32 729 * @brief
Kojto 113:f141b2784e32 730 * Write 128 bits of data to a DATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 731 *
Kojto 113:f141b2784e32 732 * @details
Kojto 113:f141b2784e32 733 * Write 128 bits of data to a DATAX register in the crypto module. The data
Kojto 113:f141b2784e32 734 * value is typically input to a big integer operation (see crypto
Kojto 113:f141b2784e32 735 * instructions).
Kojto 113:f141b2784e32 736 *
Kojto 113:f141b2784e32 737 * @param[in] dataReg The 128 bit DATA register.
Kojto 113:f141b2784e32 738 * @param[in] val Value of the data to write to the DATA register.
Kojto 113:f141b2784e32 739 ******************************************************************************/
Kojto 113:f141b2784e32 740 __STATIC_INLINE void CRYPTO_DataWrite(CRYPTO_DataReg_TypeDef dataReg,
Kojto 113:f141b2784e32 741 const CRYPTO_Data_TypeDef val)
Kojto 113:f141b2784e32 742 {
Kojto 113:f141b2784e32 743 CRYPTO_BurstToCrypto((volatile uint32_t *)dataReg, val);
Kojto 113:f141b2784e32 744 }
Kojto 113:f141b2784e32 745
Kojto 113:f141b2784e32 746 /***************************************************************************//**
Kojto 113:f141b2784e32 747 * @brief
Kojto 113:f141b2784e32 748 * Read 128 bits of data from a DATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 749 *
Kojto 113:f141b2784e32 750 * @details
Kojto 113:f141b2784e32 751 * Read 128 bits of data from a DATAX register in the crypto module. The data
Kojto 113:f141b2784e32 752 * value is typically output from a big integer operation (see crypto
Kojto 113:f141b2784e32 753 * instructions)
Kojto 113:f141b2784e32 754 *
Kojto 113:f141b2784e32 755 * @param[in] dataReg The 128 bit DATA register.
Kojto 113:f141b2784e32 756 * @param[out] val Location where to store the value in memory.
Kojto 113:f141b2784e32 757 ******************************************************************************/
Kojto 113:f141b2784e32 758 __STATIC_INLINE void CRYPTO_DataRead(CRYPTO_DataReg_TypeDef dataReg,
Kojto 113:f141b2784e32 759 CRYPTO_Data_TypeDef val)
Kojto 113:f141b2784e32 760 {
Kojto 113:f141b2784e32 761 CRYPTO_BurstFromCrypto((volatile uint32_t *)dataReg, val);
Kojto 113:f141b2784e32 762 }
Kojto 113:f141b2784e32 763
Kojto 113:f141b2784e32 764 /***************************************************************************//**
Kojto 113:f141b2784e32 765 * @brief
Kojto 113:f141b2784e32 766 * Write 256 bits of data to a DDATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 767 *
Kojto 113:f141b2784e32 768 * @details
Kojto 113:f141b2784e32 769 * Write 256 bits of data into a DDATAX (Double Data) register in the crypto
Kojto 113:f141b2784e32 770 * module. The data value is typically input to a big integer operation (see
Kojto 113:f141b2784e32 771 * crypto instructions).
Kojto 113:f141b2784e32 772 *
Kojto 113:f141b2784e32 773 * @param[in] ddataReg The 256 bit DDATA register.
Kojto 113:f141b2784e32 774 * @param[in] val Value of the data to write to the DDATA register.
Kojto 113:f141b2784e32 775 ******************************************************************************/
Kojto 113:f141b2784e32 776 __STATIC_INLINE void CRYPTO_DDataWrite(CRYPTO_DDataReg_TypeDef ddataReg,
Kojto 113:f141b2784e32 777 const CRYPTO_DData_TypeDef val)
Kojto 113:f141b2784e32 778 {
Kojto 113:f141b2784e32 779 CRYPTO_BurstToCrypto((volatile uint32_t *)ddataReg, &val[0]);
Kojto 113:f141b2784e32 780 CRYPTO_BurstToCrypto((volatile uint32_t *)ddataReg, &val[4]);
Kojto 113:f141b2784e32 781 }
Kojto 113:f141b2784e32 782
Kojto 113:f141b2784e32 783 /***************************************************************************//**
Kojto 113:f141b2784e32 784 * @brief
Kojto 113:f141b2784e32 785 * Read 256 bits of data from a DDATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 786 *
Kojto 113:f141b2784e32 787 * @details
Kojto 113:f141b2784e32 788 * Read 256 bits of data from a DDATAX (Double Data) register in the crypto
Kojto 113:f141b2784e32 789 * module. The data value is typically output from a big integer operation
Kojto 113:f141b2784e32 790 * (see crypto instructions).
Kojto 113:f141b2784e32 791 *
Kojto 113:f141b2784e32 792 * @param[in] ddataReg The 256 bit DDATA register.
Kojto 113:f141b2784e32 793 * @param[out] val Location where to store the value in memory.
Kojto 113:f141b2784e32 794 ******************************************************************************/
<> 128:9bcdf88f62b0 795 __STATIC_INLINE void CRYPTO_DDataRead(CRYPTO_DDataReg_TypeDef ddataReg,
<> 128:9bcdf88f62b0 796 CRYPTO_DData_TypeDef val)
Kojto 113:f141b2784e32 797 {
Kojto 113:f141b2784e32 798 CRYPTO_BurstFromCrypto((volatile uint32_t *)ddataReg, &val[0]);
Kojto 113:f141b2784e32 799 CRYPTO_BurstFromCrypto((volatile uint32_t *)ddataReg, &val[4]);
Kojto 113:f141b2784e32 800 }
Kojto 113:f141b2784e32 801
Kojto 113:f141b2784e32 802 /***************************************************************************//**
Kojto 113:f141b2784e32 803 * @brief
Kojto 113:f141b2784e32 804 * Write 512 bits of data to a QDATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 805 *
Kojto 113:f141b2784e32 806 * @details
Kojto 113:f141b2784e32 807 * Write 512 bits of data into a QDATAX (Quad Data) register in the crypto module
Kojto 113:f141b2784e32 808 * The data value is typically input to a big integer operation (see crypto
Kojto 113:f141b2784e32 809 * instructions).
Kojto 113:f141b2784e32 810 *
Kojto 113:f141b2784e32 811 * @param[in] qdataReg The 512 bits QDATA register.
Kojto 113:f141b2784e32 812 * @param[in] val Value of the data to write to the QDATA register.
Kojto 113:f141b2784e32 813 ******************************************************************************/
<> 128:9bcdf88f62b0 814 __STATIC_INLINE void CRYPTO_QDataWrite(CRYPTO_QDataReg_TypeDef qdataReg,
<> 128:9bcdf88f62b0 815 CRYPTO_QData_TypeDef val)
Kojto 113:f141b2784e32 816 {
Kojto 113:f141b2784e32 817 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[0]);
Kojto 113:f141b2784e32 818 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[4]);
Kojto 113:f141b2784e32 819 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[8]);
Kojto 113:f141b2784e32 820 CRYPTO_BurstToCrypto((volatile uint32_t *)qdataReg, &val[12]);
Kojto 113:f141b2784e32 821 }
Kojto 113:f141b2784e32 822
Kojto 113:f141b2784e32 823 /***************************************************************************//**
Kojto 113:f141b2784e32 824 * @brief
Kojto 113:f141b2784e32 825 * Read 512 bits of data from a QDATAX register in the CRYPTO module.
Kojto 113:f141b2784e32 826 *
Kojto 113:f141b2784e32 827 * @details
Kojto 113:f141b2784e32 828 * Read 512 bits of data from a QDATAX register in the crypto module. The data
Kojto 113:f141b2784e32 829 * value is typically input to a big integer operation (see crypto
Kojto 113:f141b2784e32 830 * instructions).
Kojto 113:f141b2784e32 831 *
Kojto 113:f141b2784e32 832 * @param[in] qdataReg The 512 bits QDATA register.
Kojto 113:f141b2784e32 833 * @param[in] val Value of the data to write to the QDATA register.
Kojto 113:f141b2784e32 834 ******************************************************************************/
Kojto 113:f141b2784e32 835 __STATIC_INLINE void CRYPTO_QDataRead(CRYPTO_QDataReg_TypeDef qdataReg,
Kojto 113:f141b2784e32 836 CRYPTO_QData_TypeDef val)
Kojto 113:f141b2784e32 837 {
Kojto 113:f141b2784e32 838 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[0]);
Kojto 113:f141b2784e32 839 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[4]);
Kojto 113:f141b2784e32 840 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[8]);
Kojto 113:f141b2784e32 841 CRYPTO_BurstFromCrypto((volatile uint32_t *)qdataReg, &val[12]);
Kojto 113:f141b2784e32 842 }
Kojto 113:f141b2784e32 843
Kojto 113:f141b2784e32 844 /***************************************************************************//**
Kojto 113:f141b2784e32 845 * @brief
Kojto 113:f141b2784e32 846 * Set the key value to be used by the CRYPTO module.
Kojto 113:f141b2784e32 847 *
Kojto 113:f141b2784e32 848 * @details
Kojto 113:f141b2784e32 849 * Write 128 or 256 bit key to the KEYBUF register in the crypto module.
Kojto 113:f141b2784e32 850 *
<> 128:9bcdf88f62b0 851 * @param[in] crypto
<> 128:9bcdf88f62b0 852 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 853 *
<> 128:9bcdf88f62b0 854 * @param[in] val
<> 128:9bcdf88f62b0 855 * Value of the data to write to the KEYBUF register.
<> 128:9bcdf88f62b0 856 *
<> 128:9bcdf88f62b0 857 * @param[in] keyWidth
<> 128:9bcdf88f62b0 858 * Key width - 128 or 256 bits
Kojto 113:f141b2784e32 859 ******************************************************************************/
<> 128:9bcdf88f62b0 860 __STATIC_INLINE void CRYPTO_KeyBufWrite(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 861 CRYPTO_KeyBuf_TypeDef val,
Kojto 113:f141b2784e32 862 CRYPTO_KeyWidth_TypeDef keyWidth)
Kojto 113:f141b2784e32 863 {
Kojto 113:f141b2784e32 864 if (keyWidth == cryptoKey256Bits)
Kojto 113:f141b2784e32 865 {
Kojto 113:f141b2784e32 866 /* Set AES-256 mode */
<> 128:9bcdf88f62b0 867 BUS_RegBitWrite(&crypto->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES256);
Kojto 113:f141b2784e32 868 /* Load key in KEYBUF register (= DDATA4) */
<> 128:9bcdf88f62b0 869 CRYPTO_DDataWrite(&crypto->DDATA4, (uint32_t *)val);
Kojto 113:f141b2784e32 870 }
Kojto 113:f141b2784e32 871 else
Kojto 113:f141b2784e32 872 {
Kojto 113:f141b2784e32 873 /* Set AES-128 mode */
<> 128:9bcdf88f62b0 874 BUS_RegBitWrite(&crypto->CTRL, _CRYPTO_CTRL_AES_SHIFT, _CRYPTO_CTRL_AES_AES128);
<> 128:9bcdf88f62b0 875 CRYPTO_BurstToCrypto(&crypto->KEYBUF, &val[0]);
Kojto 113:f141b2784e32 876 }
Kojto 113:f141b2784e32 877 }
Kojto 113:f141b2784e32 878
<> 128:9bcdf88f62b0 879 void CRYPTO_KeyRead(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 880 CRYPTO_KeyBuf_TypeDef val,
Kojto 113:f141b2784e32 881 CRYPTO_KeyWidth_TypeDef keyWidth);
Kojto 113:f141b2784e32 882
Kojto 113:f141b2784e32 883 /***************************************************************************//**
Kojto 113:f141b2784e32 884 * @brief
Kojto 113:f141b2784e32 885 * Quick write 128 bit key to the CRYPTO module.
Kojto 113:f141b2784e32 886 *
Kojto 113:f141b2784e32 887 * @details
Kojto 113:f141b2784e32 888 * Quick write 128 bit key to the KEYBUF register in the CRYPTO module.
Kojto 113:f141b2784e32 889 *
<> 128:9bcdf88f62b0 890 * @param[in] crypto
<> 128:9bcdf88f62b0 891 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 892 *
<> 128:9bcdf88f62b0 893 * @param[in] val
<> 128:9bcdf88f62b0 894 * Value of the data to write to the KEYBUF register.
Kojto 113:f141b2784e32 895 ******************************************************************************/
<> 128:9bcdf88f62b0 896 __STATIC_INLINE void CRYPTO_KeyBuf128Write(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 897 const uint32_t * val)
Kojto 113:f141b2784e32 898 {
<> 128:9bcdf88f62b0 899 CRYPTO_BurstToCrypto(&crypto->KEYBUF, val);
Kojto 113:f141b2784e32 900 }
Kojto 113:f141b2784e32 901
Kojto 113:f141b2784e32 902 /***************************************************************************//**
Kojto 113:f141b2784e32 903 * @brief
Kojto 113:f141b2784e32 904 * Quick read access of the Carry bit from arithmetic operations.
Kojto 113:f141b2784e32 905 *
Kojto 113:f141b2784e32 906 * @details
Kojto 113:f141b2784e32 907 * This function reads the carry bit of the CRYPTO ALU.
Kojto 113:f141b2784e32 908 *
<> 128:9bcdf88f62b0 909 * @param[in] crypto
<> 128:9bcdf88f62b0 910 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 911 *
Kojto 113:f141b2784e32 912 * @return
Kojto 113:f141b2784e32 913 * Returns 'true' if carry is 1, and 'false' if carry is 0.
Kojto 113:f141b2784e32 914 ******************************************************************************/
<> 128:9bcdf88f62b0 915 __STATIC_INLINE bool CRYPTO_CarryIsSet(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 916 {
<> 128:9bcdf88f62b0 917 return (crypto->DSTATUS & _CRYPTO_DSTATUS_CARRY_MASK)
Kojto 113:f141b2784e32 918 >> _CRYPTO_DSTATUS_CARRY_SHIFT;
Kojto 113:f141b2784e32 919 }
Kojto 113:f141b2784e32 920
Kojto 113:f141b2784e32 921 /***************************************************************************//**
Kojto 113:f141b2784e32 922 * @brief
Kojto 113:f141b2784e32 923 * Quick read access of the 4 LSbits of the DDATA0 register.
Kojto 113:f141b2784e32 924 *
Kojto 113:f141b2784e32 925 * @details
Kojto 113:f141b2784e32 926 * This function quickly retrieves the 4 least significant bits of the
Kojto 113:f141b2784e32 927 * DDATA0 register via the DDATA0LSBS bit field in the DSTATUS register.
Kojto 113:f141b2784e32 928 *
<> 128:9bcdf88f62b0 929 * @param[in] crypto
<> 128:9bcdf88f62b0 930 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 931 *
Kojto 113:f141b2784e32 932 * @return
Kojto 113:f141b2784e32 933 * Returns the 4 LSbits of DDATA0.
Kojto 113:f141b2784e32 934 ******************************************************************************/
<> 128:9bcdf88f62b0 935 __STATIC_INLINE uint8_t CRYPTO_DData0_4LSBitsRead(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 936 {
<> 128:9bcdf88f62b0 937 return (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA0LSBS_MASK)
Kojto 113:f141b2784e32 938 >> _CRYPTO_DSTATUS_DDATA0LSBS_SHIFT;
Kojto 113:f141b2784e32 939 }
Kojto 113:f141b2784e32 940
Kojto 113:f141b2784e32 941 /***************************************************************************//**
Kojto 113:f141b2784e32 942 * @brief
Kojto 113:f141b2784e32 943 * Read 260 bits from the DDATA0 register.
Kojto 113:f141b2784e32 944 *
Kojto 113:f141b2784e32 945 * @details
Kojto 113:f141b2784e32 946 * This functions reads 260 bits from the DDATA0 register in the CRYPTO
Kojto 113:f141b2784e32 947 * module. The data value is typically output from a big integer operation
Kojto 113:f141b2784e32 948 * (see crypto instructions) when the result width is set to 260 bits by
Kojto 113:f141b2784e32 949 * calling @ref CRYPTO_ResultWidthSet(cryptoResult260Bits);
Kojto 113:f141b2784e32 950 *
<> 128:9bcdf88f62b0 951 * @param[in] crypto
<> 128:9bcdf88f62b0 952 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 953 *
<> 128:9bcdf88f62b0 954 * @param[out] val
<> 128:9bcdf88f62b0 955 * Location where to store the value in memory.
Kojto 113:f141b2784e32 956 ******************************************************************************/
<> 128:9bcdf88f62b0 957 __STATIC_INLINE void CRYPTO_DData0Read260(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 958 CRYPTO_Data260_TypeDef val)
<> 128:9bcdf88f62b0 959 {
<> 128:9bcdf88f62b0 960 CRYPTO_DDataRead(&crypto->DDATA0, val);
<> 128:9bcdf88f62b0 961 val[8] = (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA0MSBS_MASK)
Kojto 113:f141b2784e32 962 >> _CRYPTO_DSTATUS_DDATA0MSBS_SHIFT;
Kojto 113:f141b2784e32 963 }
Kojto 113:f141b2784e32 964
Kojto 113:f141b2784e32 965 /***************************************************************************//**
Kojto 113:f141b2784e32 966 * @brief
Kojto 113:f141b2784e32 967 * Write 260 bits to the DDATA0 register.
Kojto 113:f141b2784e32 968 *
Kojto 113:f141b2784e32 969 * @details
Kojto 113:f141b2784e32 970 * This functions writes 260 bits to the DDATA0 register in the CRYPTO
Kojto 113:f141b2784e32 971 * module. The data value is typically input to a big integer operation
Kojto 113:f141b2784e32 972 * (see crypto instructions) when the result width is set to 260 bits by
Kojto 113:f141b2784e32 973 * calling @ref CRYPTO_ResultWidthSet(cryptoResult260Bits);
Kojto 113:f141b2784e32 974 *
<> 128:9bcdf88f62b0 975 * @param[in] crypto
<> 128:9bcdf88f62b0 976 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 977 *
<> 128:9bcdf88f62b0 978 * @param[out] val
<> 128:9bcdf88f62b0 979 * Location where of the value in memory.
Kojto 113:f141b2784e32 980 ******************************************************************************/
<> 128:9bcdf88f62b0 981 __STATIC_INLINE void CRYPTO_DData0Write260(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 982 const CRYPTO_Data260_TypeDef val)
Kojto 113:f141b2784e32 983 {
<> 128:9bcdf88f62b0 984 CRYPTO_DDataWrite(&crypto->DDATA0, val);
<> 128:9bcdf88f62b0 985 crypto->DDATA0BYTE32 = val[8] & _CRYPTO_DDATA0BYTE32_DDATA0BYTE32_MASK;
Kojto 113:f141b2784e32 986 }
Kojto 113:f141b2784e32 987
Kojto 113:f141b2784e32 988 /***************************************************************************//**
Kojto 113:f141b2784e32 989 * @brief
Kojto 113:f141b2784e32 990 * Quick read the MSbit of the DDATA1 register.
Kojto 113:f141b2784e32 991 *
Kojto 113:f141b2784e32 992 * @details
Kojto 113:f141b2784e32 993 * This function reads the most significant bit (bit 255) of the DDATA1
Kojto 113:f141b2784e32 994 * register via the DDATA1MSB bit field in the DSTATUS register. This can
Kojto 113:f141b2784e32 995 * be used to quickly check the signedness of a big integer resident in the
Kojto 113:f141b2784e32 996 * CRYPTO module.
Kojto 113:f141b2784e32 997 *
<> 128:9bcdf88f62b0 998 * @param[in] crypto
<> 128:9bcdf88f62b0 999 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1000 *
Kojto 113:f141b2784e32 1001 * @return
Kojto 113:f141b2784e32 1002 * Returns 'true' if MSbit is 1, and 'false' if MSbit is 0.
Kojto 113:f141b2784e32 1003 ******************************************************************************/
<> 128:9bcdf88f62b0 1004 __STATIC_INLINE bool CRYPTO_DData1_MSBitRead(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1005 {
<> 128:9bcdf88f62b0 1006 return (crypto->DSTATUS & _CRYPTO_DSTATUS_DDATA1MSB_MASK)
Kojto 113:f141b2784e32 1007 >> _CRYPTO_DSTATUS_DDATA1MSB_SHIFT;
Kojto 113:f141b2784e32 1008 }
Kojto 113:f141b2784e32 1009
Kojto 113:f141b2784e32 1010 /***************************************************************************//**
Kojto 113:f141b2784e32 1011 * @brief
Kojto 113:f141b2784e32 1012 * Load a sequence of instructions to be executed on the current values in
Kojto 113:f141b2784e32 1013 * the data registers.
Kojto 113:f141b2784e32 1014 *
Kojto 113:f141b2784e32 1015 * @details
Kojto 113:f141b2784e32 1016 * This function loads a sequence of instructions to the crypto module. The
Kojto 113:f141b2784e32 1017 * instructions will be executed when the CRYPTO_InstructionSequenceExecute
Kojto 113:f141b2784e32 1018 * function is called. The first END marks the end of the sequence.
Kojto 113:f141b2784e32 1019 *
<> 128:9bcdf88f62b0 1020 * @param[in] crypto
<> 128:9bcdf88f62b0 1021 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1022 *
<> 128:9bcdf88f62b0 1023 * @param[in] instructionSequence
<> 128:9bcdf88f62b0 1024 * Instruction sequence to load.
Kojto 113:f141b2784e32 1025 ******************************************************************************/
<> 128:9bcdf88f62b0 1026 __STATIC_INLINE
<> 128:9bcdf88f62b0 1027 void CRYPTO_InstructionSequenceLoad(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1028 const CRYPTO_InstructionSequence_TypeDef instructionSequence)
Kojto 113:f141b2784e32 1029 {
Kojto 113:f141b2784e32 1030 const uint32_t * pas = (const uint32_t *) instructionSequence;
Kojto 113:f141b2784e32 1031
<> 128:9bcdf88f62b0 1032 crypto->SEQ0 = pas[0];
<> 128:9bcdf88f62b0 1033 crypto->SEQ1 = pas[1];
<> 128:9bcdf88f62b0 1034 crypto->SEQ2 = pas[2];
<> 128:9bcdf88f62b0 1035 crypto->SEQ3 = pas[3];
<> 128:9bcdf88f62b0 1036 crypto->SEQ4 = pas[4];
Kojto 113:f141b2784e32 1037 }
Kojto 113:f141b2784e32 1038
Kojto 113:f141b2784e32 1039 /***************************************************************************//**
Kojto 113:f141b2784e32 1040 * @brief
Kojto 113:f141b2784e32 1041 * Execute the current programmed instruction sequence.
Kojto 113:f141b2784e32 1042 *
Kojto 113:f141b2784e32 1043 * @details
Kojto 113:f141b2784e32 1044 * This function starts the execution of the current instruction sequence
Kojto 113:f141b2784e32 1045 * in the CRYPTO module.
<> 128:9bcdf88f62b0 1046 *
<> 128:9bcdf88f62b0 1047 * @param[in] crypto
<> 128:9bcdf88f62b0 1048 * Pointer to CRYPTO peripheral register block.
Kojto 113:f141b2784e32 1049 ******************************************************************************/
<> 128:9bcdf88f62b0 1050 __STATIC_INLINE void CRYPTO_InstructionSequenceExecute(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1051 {
Kojto 113:f141b2784e32 1052 /* Start the command sequence. */
<> 128:9bcdf88f62b0 1053 crypto->CMD = CRYPTO_CMD_SEQSTART;
Kojto 113:f141b2784e32 1054 }
Kojto 113:f141b2784e32 1055
Kojto 113:f141b2784e32 1056 /***************************************************************************//**
Kojto 113:f141b2784e32 1057 * @brief
Kojto 113:f141b2784e32 1058 * Check whether the execution of an instruction sequence has completed.
Kojto 113:f141b2784e32 1059 *
Kojto 113:f141b2784e32 1060 * @details
Kojto 113:f141b2784e32 1061 * This function checks whether an instruction sequence has completed.
Kojto 113:f141b2784e32 1062 *
<> 128:9bcdf88f62b0 1063 * @param[in] crypto
<> 128:9bcdf88f62b0 1064 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1065 *
Kojto 113:f141b2784e32 1066 * @return
Kojto 113:f141b2784e32 1067 * Returns 'true' if the instruction sequence is done, and 'false' if not.
Kojto 113:f141b2784e32 1068 ******************************************************************************/
<> 128:9bcdf88f62b0 1069 __STATIC_INLINE bool CRYPTO_InstructionSequenceDone(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1070 {
Kojto 113:f141b2784e32 1071 /* Return true if operation has completed. */
<> 128:9bcdf88f62b0 1072 return !(crypto->STATUS
Kojto 113:f141b2784e32 1073 & (CRYPTO_STATUS_INSTRRUNNING | CRYPTO_STATUS_SEQRUNNING));
Kojto 113:f141b2784e32 1074 }
Kojto 113:f141b2784e32 1075
Kojto 113:f141b2784e32 1076 /***************************************************************************//**
Kojto 113:f141b2784e32 1077 * @brief
Kojto 113:f141b2784e32 1078 * Wait for completion of the current sequence of instructions.
Kojto 113:f141b2784e32 1079 *
Kojto 113:f141b2784e32 1080 * @details
Kojto 113:f141b2784e32 1081 * This function "busy"-waits until the execution of the ongoing instruction
Kojto 113:f141b2784e32 1082 * sequence has completed.
<> 128:9bcdf88f62b0 1083 *
<> 128:9bcdf88f62b0 1084 * @param[in] crypto
<> 128:9bcdf88f62b0 1085 * Pointer to CRYPTO peripheral register block.
Kojto 113:f141b2784e32 1086 ******************************************************************************/
<> 128:9bcdf88f62b0 1087 __STATIC_INLINE void CRYPTO_InstructionSequenceWait(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1088 {
<> 128:9bcdf88f62b0 1089 while (!CRYPTO_InstructionSequenceDone(crypto))
Kojto 113:f141b2784e32 1090 ;
Kojto 113:f141b2784e32 1091 }
Kojto 113:f141b2784e32 1092
Kojto 113:f141b2784e32 1093 /***************************************************************************//**
Kojto 113:f141b2784e32 1094 * @brief
Kojto 113:f141b2784e32 1095 * Wait for completion of the current command.
Kojto 113:f141b2784e32 1096 *
Kojto 113:f141b2784e32 1097 * @details
Kojto 113:f141b2784e32 1098 * This function "busy"-waits until the execution of the ongoing instruction
Kojto 113:f141b2784e32 1099 * has completed.
<> 128:9bcdf88f62b0 1100 *
<> 128:9bcdf88f62b0 1101 * @param[in] crypto
<> 128:9bcdf88f62b0 1102 * Pointer to CRYPTO peripheral register block.
Kojto 113:f141b2784e32 1103 ******************************************************************************/
<> 128:9bcdf88f62b0 1104 __STATIC_INLINE void CRYPTO_InstructionWait(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1105 {
Kojto 113:f141b2784e32 1106 /* Wait for completion */
<> 128:9bcdf88f62b0 1107 while (!(crypto->IF & CRYPTO_IF_INSTRDONE))
Kojto 113:f141b2784e32 1108 ;
<> 128:9bcdf88f62b0 1109 crypto->IFC = CRYPTO_IF_INSTRDONE;
Kojto 113:f141b2784e32 1110 }
Kojto 113:f141b2784e32 1111
<> 128:9bcdf88f62b0 1112 void CRYPTO_SHA_1(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1113 const uint8_t *msg,
<> 128:9bcdf88f62b0 1114 uint64_t msgLen,
<> 128:9bcdf88f62b0 1115 CRYPTO_SHA1_Digest_TypeDef digest);
Kojto 113:f141b2784e32 1116
<> 128:9bcdf88f62b0 1117 void CRYPTO_SHA_256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1118 const uint8_t *msg,
Kojto 113:f141b2784e32 1119 uint64_t msgLen,
Kojto 113:f141b2784e32 1120 CRYPTO_SHA256_Digest_TypeDef digest);
Kojto 113:f141b2784e32 1121
<> 128:9bcdf88f62b0 1122 void CRYPTO_Mul(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1123 uint32_t * A, int aSize,
Kojto 113:f141b2784e32 1124 uint32_t * B, int bSize,
Kojto 113:f141b2784e32 1125 uint32_t * R, int rSize);
Kojto 113:f141b2784e32 1126
<> 128:9bcdf88f62b0 1127 void CRYPTO_AES_CBC128(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1128 uint8_t * out,
Kojto 113:f141b2784e32 1129 const uint8_t * in,
Kojto 113:f141b2784e32 1130 unsigned int len,
Kojto 113:f141b2784e32 1131 const uint8_t * key,
Kojto 113:f141b2784e32 1132 const uint8_t * iv,
Kojto 113:f141b2784e32 1133 bool encrypt);
Kojto 113:f141b2784e32 1134
<> 128:9bcdf88f62b0 1135 void CRYPTO_AES_CBC256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1136 uint8_t * out,
Kojto 113:f141b2784e32 1137 const uint8_t * in,
Kojto 113:f141b2784e32 1138 unsigned int len,
Kojto 113:f141b2784e32 1139 const uint8_t * key,
Kojto 113:f141b2784e32 1140 const uint8_t * iv,
Kojto 113:f141b2784e32 1141 bool encrypt);
Kojto 113:f141b2784e32 1142
<> 128:9bcdf88f62b0 1143 void CRYPTO_AES_CFB128(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1144 uint8_t * out,
Kojto 113:f141b2784e32 1145 const uint8_t * in,
Kojto 113:f141b2784e32 1146 unsigned int len,
Kojto 113:f141b2784e32 1147 const uint8_t * key,
Kojto 113:f141b2784e32 1148 const uint8_t * iv,
Kojto 113:f141b2784e32 1149 bool encrypt);
Kojto 113:f141b2784e32 1150
<> 128:9bcdf88f62b0 1151 void CRYPTO_AES_CFB256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1152 uint8_t * out,
Kojto 113:f141b2784e32 1153 const uint8_t * in,
Kojto 113:f141b2784e32 1154 unsigned int len,
Kojto 113:f141b2784e32 1155 const uint8_t * key,
Kojto 113:f141b2784e32 1156 const uint8_t * iv,
Kojto 113:f141b2784e32 1157 bool encrypt);
Kojto 113:f141b2784e32 1158
<> 128:9bcdf88f62b0 1159 void CRYPTO_AES_CTR128(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1160 uint8_t * out,
Kojto 113:f141b2784e32 1161 const uint8_t * in,
Kojto 113:f141b2784e32 1162 unsigned int len,
Kojto 113:f141b2784e32 1163 const uint8_t * key,
Kojto 113:f141b2784e32 1164 uint8_t * ctr,
Kojto 113:f141b2784e32 1165 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
Kojto 113:f141b2784e32 1166
<> 128:9bcdf88f62b0 1167 void CRYPTO_AES_CTR256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1168 uint8_t * out,
Kojto 113:f141b2784e32 1169 const uint8_t * in,
Kojto 113:f141b2784e32 1170 unsigned int len,
Kojto 113:f141b2784e32 1171 const uint8_t * key,
Kojto 113:f141b2784e32 1172 uint8_t * ctr,
Kojto 113:f141b2784e32 1173 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc);
Kojto 113:f141b2784e32 1174
Kojto 113:f141b2784e32 1175 void CRYPTO_AES_CTRUpdate32Bit(uint8_t * ctr);
<> 128:9bcdf88f62b0 1176 void CRYPTO_AES_DecryptKey128(CRYPTO_TypeDef *crypto, uint8_t * out, const uint8_t * in);
<> 128:9bcdf88f62b0 1177 void CRYPTO_AES_DecryptKey256(CRYPTO_TypeDef *crypto, uint8_t * out, const uint8_t * in);
Kojto 113:f141b2784e32 1178
<> 128:9bcdf88f62b0 1179 void CRYPTO_AES_ECB128(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1180 uint8_t * out,
Kojto 113:f141b2784e32 1181 const uint8_t * in,
Kojto 113:f141b2784e32 1182 unsigned int len,
Kojto 113:f141b2784e32 1183 const uint8_t * key,
Kojto 113:f141b2784e32 1184 bool encrypt);
Kojto 113:f141b2784e32 1185
<> 128:9bcdf88f62b0 1186 void CRYPTO_AES_ECB256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1187 uint8_t * out,
Kojto 113:f141b2784e32 1188 const uint8_t * in,
Kojto 113:f141b2784e32 1189 unsigned int len,
Kojto 113:f141b2784e32 1190 const uint8_t * key,
Kojto 113:f141b2784e32 1191 bool encrypt);
Kojto 113:f141b2784e32 1192
<> 128:9bcdf88f62b0 1193 void CRYPTO_AES_OFB128(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1194 uint8_t * out,
Kojto 113:f141b2784e32 1195 const uint8_t * in,
Kojto 113:f141b2784e32 1196 unsigned int len,
Kojto 113:f141b2784e32 1197 const uint8_t * key,
Kojto 113:f141b2784e32 1198 const uint8_t * iv);
Kojto 113:f141b2784e32 1199
<> 128:9bcdf88f62b0 1200 void CRYPTO_AES_OFB256(CRYPTO_TypeDef *crypto,
<> 128:9bcdf88f62b0 1201 uint8_t * out,
Kojto 113:f141b2784e32 1202 const uint8_t * in,
Kojto 113:f141b2784e32 1203 unsigned int len,
Kojto 113:f141b2784e32 1204 const uint8_t * key,
Kojto 113:f141b2784e32 1205 const uint8_t * iv);
Kojto 113:f141b2784e32 1206
Kojto 113:f141b2784e32 1207 /***************************************************************************//**
Kojto 113:f141b2784e32 1208 * @brief
Kojto 113:f141b2784e32 1209 * Clear one or more pending CRYPTO interrupts.
Kojto 113:f141b2784e32 1210 *
<> 128:9bcdf88f62b0 1211 * @param[in] crypto
<> 128:9bcdf88f62b0 1212 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1213 *
Kojto 113:f141b2784e32 1214 * @param[in] flags
Kojto 113:f141b2784e32 1215 * Pending CRYPTO interrupt source to clear. Use a bitwise logic OR combination of
Kojto 113:f141b2784e32 1216 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
Kojto 113:f141b2784e32 1217 ******************************************************************************/
<> 128:9bcdf88f62b0 1218 __STATIC_INLINE void CRYPTO_IntClear(CRYPTO_TypeDef *crypto, uint32_t flags)
Kojto 113:f141b2784e32 1219 {
<> 128:9bcdf88f62b0 1220 crypto->IFC = flags;
Kojto 113:f141b2784e32 1221 }
Kojto 113:f141b2784e32 1222
Kojto 113:f141b2784e32 1223 /***************************************************************************//**
Kojto 113:f141b2784e32 1224 * @brief
Kojto 113:f141b2784e32 1225 * Disable one or more CRYPTO interrupts.
Kojto 113:f141b2784e32 1226 *
<> 128:9bcdf88f62b0 1227 * @param[in] crypto
<> 128:9bcdf88f62b0 1228 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1229 *
Kojto 113:f141b2784e32 1230 * @param[in] flags
Kojto 113:f141b2784e32 1231 * CRYPTO interrupt sources to disable. Use a bitwise logic OR combination of
Kojto 113:f141b2784e32 1232 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
Kojto 113:f141b2784e32 1233 ******************************************************************************/
<> 128:9bcdf88f62b0 1234 __STATIC_INLINE void CRYPTO_IntDisable(CRYPTO_TypeDef *crypto, uint32_t flags)
Kojto 113:f141b2784e32 1235 {
<> 128:9bcdf88f62b0 1236 crypto->IEN &= ~(flags);
Kojto 113:f141b2784e32 1237 }
Kojto 113:f141b2784e32 1238
Kojto 113:f141b2784e32 1239 /***************************************************************************//**
Kojto 113:f141b2784e32 1240 * @brief
Kojto 113:f141b2784e32 1241 * Enable one or more CRYPTO interrupts.
Kojto 113:f141b2784e32 1242 *
Kojto 113:f141b2784e32 1243 * @note
Kojto 113:f141b2784e32 1244 * Depending on the use, a pending interrupt may already be set prior to
Kojto 113:f141b2784e32 1245 * enabling the interrupt. Consider using CRYPTO_IntClear() prior to enabling
Kojto 113:f141b2784e32 1246 * if such a pending interrupt should be ignored.
Kojto 113:f141b2784e32 1247 *
<> 128:9bcdf88f62b0 1248 * @param[in] crypto
<> 128:9bcdf88f62b0 1249 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1250 *
Kojto 113:f141b2784e32 1251 * @param[in] flags
Kojto 113:f141b2784e32 1252 * CRYPTO interrupt sources to enable. Use a bitwise logic OR combination of
Kojto 113:f141b2784e32 1253 * valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
Kojto 113:f141b2784e32 1254 ******************************************************************************/
<> 128:9bcdf88f62b0 1255 __STATIC_INLINE void CRYPTO_IntEnable(CRYPTO_TypeDef *crypto, uint32_t flags)
Kojto 113:f141b2784e32 1256 {
<> 128:9bcdf88f62b0 1257 crypto->IEN |= flags;
Kojto 113:f141b2784e32 1258 }
Kojto 113:f141b2784e32 1259
Kojto 113:f141b2784e32 1260 /***************************************************************************//**
Kojto 113:f141b2784e32 1261 * @brief
Kojto 113:f141b2784e32 1262 * Get pending CRYPTO interrupt flags.
Kojto 113:f141b2784e32 1263 *
Kojto 113:f141b2784e32 1264 * @note
Kojto 113:f141b2784e32 1265 * The event bits are not cleared by the use of this function.
Kojto 113:f141b2784e32 1266 *
<> 128:9bcdf88f62b0 1267 * @param[in] crypto
<> 128:9bcdf88f62b0 1268 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1269 *
Kojto 113:f141b2784e32 1270 * @return
Kojto 113:f141b2784e32 1271 * CRYPTO interrupt sources pending. A bitwise logic OR combination of valid
Kojto 113:f141b2784e32 1272 * interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
Kojto 113:f141b2784e32 1273 ******************************************************************************/
<> 128:9bcdf88f62b0 1274 __STATIC_INLINE uint32_t CRYPTO_IntGet(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1275 {
<> 128:9bcdf88f62b0 1276 return crypto->IF;
Kojto 113:f141b2784e32 1277 }
Kojto 113:f141b2784e32 1278
Kojto 113:f141b2784e32 1279 /***************************************************************************//**
Kojto 113:f141b2784e32 1280 * @brief
Kojto 113:f141b2784e32 1281 * Get enabled and pending CRYPTO interrupt flags.
Kojto 113:f141b2784e32 1282 * Useful for handling more interrupt sources in the same interrupt handler.
Kojto 113:f141b2784e32 1283 *
Kojto 113:f141b2784e32 1284 * @note
Kojto 113:f141b2784e32 1285 * Interrupt flags are not cleared by the use of this function.
Kojto 113:f141b2784e32 1286 *
<> 128:9bcdf88f62b0 1287 * @param[in] crypto
<> 128:9bcdf88f62b0 1288 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1289 *
Kojto 113:f141b2784e32 1290 * @return
Kojto 113:f141b2784e32 1291 * Pending and enabled CRYPTO interrupt sources
Kojto 113:f141b2784e32 1292 * The return value is the bitwise AND of
Kojto 113:f141b2784e32 1293 * - the enabled interrupt sources in CRYPTO_IEN and
Kojto 113:f141b2784e32 1294 * - the pending interrupt flags CRYPTO_IF
Kojto 113:f141b2784e32 1295 ******************************************************************************/
<> 128:9bcdf88f62b0 1296 __STATIC_INLINE uint32_t CRYPTO_IntGetEnabled(CRYPTO_TypeDef *crypto)
Kojto 113:f141b2784e32 1297 {
<> 128:9bcdf88f62b0 1298 uint32_t tmp;
<> 128:9bcdf88f62b0 1299
<> 128:9bcdf88f62b0 1300 /* Store IEN in temporary variable in order to define explicit order
<> 128:9bcdf88f62b0 1301 * of volatile accesses. */
<> 128:9bcdf88f62b0 1302 tmp = crypto->IEN;
<> 128:9bcdf88f62b0 1303
<> 128:9bcdf88f62b0 1304 /* Bitwise AND of pending and enabled interrupts */
<> 128:9bcdf88f62b0 1305 return crypto->IF & tmp;
Kojto 113:f141b2784e32 1306 }
Kojto 113:f141b2784e32 1307
Kojto 113:f141b2784e32 1308 /***************************************************************************//**
Kojto 113:f141b2784e32 1309 * @brief
Kojto 113:f141b2784e32 1310 * Set one or more pending CRYPTO interrupts from SW.
Kojto 113:f141b2784e32 1311 *
<> 128:9bcdf88f62b0 1312 * @param[in] crypto
<> 128:9bcdf88f62b0 1313 * Pointer to CRYPTO peripheral register block.
<> 128:9bcdf88f62b0 1314 *
Kojto 113:f141b2784e32 1315 * @param[in] flags
Kojto 113:f141b2784e32 1316 * CRYPTO interrupt sources to set to pending. Use a bitwise logic OR combination
Kojto 113:f141b2784e32 1317 * of valid interrupt flags for the CRYPTO module (CRYPTO_IF_nnn).
Kojto 113:f141b2784e32 1318 ******************************************************************************/
<> 128:9bcdf88f62b0 1319 __STATIC_INLINE void CRYPTO_IntSet(CRYPTO_TypeDef *crypto, uint32_t flags)
Kojto 113:f141b2784e32 1320 {
<> 128:9bcdf88f62b0 1321 crypto->IFS = flags;
Kojto 113:f141b2784e32 1322 }
Kojto 113:f141b2784e32 1323
Kojto 113:f141b2784e32 1324 /*******************************************************************************
Kojto 113:f141b2784e32 1325 ***** Static inline wrappers for CRYPTO AES functions in order to *****
Kojto 113:f141b2784e32 1326 ***** preserve backwards compatibility with AES module API functions. *****
Kojto 113:f141b2784e32 1327 ******************************************************************************/
Kojto 113:f141b2784e32 1328
Kojto 113:f141b2784e32 1329 /***************************************************************************//**
Kojto 113:f141b2784e32 1330 * @brief
Kojto 113:f141b2784e32 1331 * AES Cipher-block chaining (CBC) cipher mode encryption/decryption,
Kojto 113:f141b2784e32 1332 * 128 bit key.
Kojto 113:f141b2784e32 1333 *
Kojto 113:f141b2784e32 1334 * @deprecated
Kojto 113:f141b2784e32 1335 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1336 * @ref CRYPTO_AES_CBC128 instead.
Kojto 113:f141b2784e32 1337 ******************************************************************************/
Kojto 113:f141b2784e32 1338 __STATIC_INLINE void AES_CBC128(uint8_t * out,
Kojto 113:f141b2784e32 1339 const uint8_t * in,
Kojto 113:f141b2784e32 1340 unsigned int len,
Kojto 113:f141b2784e32 1341 const uint8_t * key,
Kojto 113:f141b2784e32 1342 const uint8_t * iv,
Kojto 113:f141b2784e32 1343 bool encrypt)
Kojto 113:f141b2784e32 1344 {
<> 128:9bcdf88f62b0 1345 CRYPTO_AES_CBC128(CRYPTO, out, in, len, key, iv, encrypt);
Kojto 113:f141b2784e32 1346 }
Kojto 113:f141b2784e32 1347
Kojto 113:f141b2784e32 1348 /***************************************************************************//**
Kojto 113:f141b2784e32 1349 * @brief
Kojto 113:f141b2784e32 1350 * AES Cipher-block chaining (CBC) cipher mode encryption/decryption, 256 bit
Kojto 113:f141b2784e32 1351 * key.
Kojto 113:f141b2784e32 1352 *
Kojto 113:f141b2784e32 1353 * @deprecated
Kojto 113:f141b2784e32 1354 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1355 * @ref CRYPTO_AES_CBC256 instead.
Kojto 113:f141b2784e32 1356 ******************************************************************************/
Kojto 113:f141b2784e32 1357 __STATIC_INLINE void AES_CBC256(uint8_t * out,
Kojto 113:f141b2784e32 1358 const uint8_t * in,
Kojto 113:f141b2784e32 1359 unsigned int len,
Kojto 113:f141b2784e32 1360 const uint8_t * key,
Kojto 113:f141b2784e32 1361 const uint8_t * iv,
Kojto 113:f141b2784e32 1362 bool encrypt)
Kojto 113:f141b2784e32 1363 {
<> 128:9bcdf88f62b0 1364 CRYPTO_AES_CBC256(CRYPTO, out, in, len, key, iv, encrypt);
Kojto 113:f141b2784e32 1365 }
Kojto 113:f141b2784e32 1366
Kojto 113:f141b2784e32 1367 /***************************************************************************//**
Kojto 113:f141b2784e32 1368 * @brief
Kojto 113:f141b2784e32 1369 * AES Cipher feedback (CFB) cipher mode encryption/decryption, 128 bit key.
Kojto 113:f141b2784e32 1370 *
Kojto 113:f141b2784e32 1371 * @deprecated
Kojto 113:f141b2784e32 1372 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1373 * @ref CRYPTO_AES_CFB128 instead.
Kojto 113:f141b2784e32 1374 ******************************************************************************/
Kojto 113:f141b2784e32 1375 __STATIC_INLINE void AES_CFB128(uint8_t * out,
Kojto 113:f141b2784e32 1376 const uint8_t * in,
Kojto 113:f141b2784e32 1377 unsigned int len,
Kojto 113:f141b2784e32 1378 const uint8_t * key,
Kojto 113:f141b2784e32 1379 const uint8_t * iv,
Kojto 113:f141b2784e32 1380 bool encrypt)
Kojto 113:f141b2784e32 1381 {
<> 128:9bcdf88f62b0 1382 CRYPTO_AES_CFB128(CRYPTO, out, in, len, key, iv, encrypt);
Kojto 113:f141b2784e32 1383 }
Kojto 113:f141b2784e32 1384
Kojto 113:f141b2784e32 1385 /***************************************************************************//**
Kojto 113:f141b2784e32 1386 * @brief
Kojto 113:f141b2784e32 1387 * AES Cipher feedback (CFB) cipher mode encryption/decryption, 256 bit key.
Kojto 113:f141b2784e32 1388 *
Kojto 113:f141b2784e32 1389 * @deprecated
Kojto 113:f141b2784e32 1390 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1391 * @ref CRYPTO_AES_CFB256 instead.
Kojto 113:f141b2784e32 1392 ******************************************************************************/
Kojto 113:f141b2784e32 1393 __STATIC_INLINE void AES_CFB256(uint8_t * out,
Kojto 113:f141b2784e32 1394 const uint8_t * in,
Kojto 113:f141b2784e32 1395 unsigned int len,
Kojto 113:f141b2784e32 1396 const uint8_t * key,
Kojto 113:f141b2784e32 1397 const uint8_t * iv,
Kojto 113:f141b2784e32 1398 bool encrypt)
Kojto 113:f141b2784e32 1399 {
<> 128:9bcdf88f62b0 1400 CRYPTO_AES_CFB256(CRYPTO, out, in, len, key, iv, encrypt);
Kojto 113:f141b2784e32 1401 }
Kojto 113:f141b2784e32 1402
Kojto 113:f141b2784e32 1403 /***************************************************************************//**
Kojto 113:f141b2784e32 1404 * @brief
Kojto 113:f141b2784e32 1405 * AES Counter (CTR) cipher mode encryption/decryption, 128 bit key.
Kojto 113:f141b2784e32 1406 *
Kojto 113:f141b2784e32 1407 * @deprecated
Kojto 113:f141b2784e32 1408 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1409 * @ref CRYPTO_AES_CTR128 instead.
Kojto 113:f141b2784e32 1410 ******************************************************************************/
Kojto 113:f141b2784e32 1411 __STATIC_INLINE void AES_CTR128(uint8_t * out,
Kojto 113:f141b2784e32 1412 const uint8_t * in,
Kojto 113:f141b2784e32 1413 unsigned int len,
Kojto 113:f141b2784e32 1414 const uint8_t * key,
Kojto 113:f141b2784e32 1415 uint8_t * ctr,
Kojto 113:f141b2784e32 1416 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
Kojto 113:f141b2784e32 1417 {
<> 128:9bcdf88f62b0 1418 CRYPTO_AES_CTR128(CRYPTO, out, in, len, key, ctr, ctrFunc);
Kojto 113:f141b2784e32 1419 }
Kojto 113:f141b2784e32 1420
Kojto 113:f141b2784e32 1421 /***************************************************************************//**
Kojto 113:f141b2784e32 1422 * @brief
Kojto 113:f141b2784e32 1423 * AES Counter (CTR) cipher mode encryption/decryption, 256 bit key.
Kojto 113:f141b2784e32 1424 *
Kojto 113:f141b2784e32 1425 * @deprecated
Kojto 113:f141b2784e32 1426 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1427 * @ref CRYPTO_AES_CTR256 instead.
Kojto 113:f141b2784e32 1428 ******************************************************************************/
Kojto 113:f141b2784e32 1429 __STATIC_INLINE void AES_CTR256(uint8_t * out,
Kojto 113:f141b2784e32 1430 const uint8_t * in,
Kojto 113:f141b2784e32 1431 unsigned int len,
Kojto 113:f141b2784e32 1432 const uint8_t * key,
Kojto 113:f141b2784e32 1433 uint8_t * ctr,
Kojto 113:f141b2784e32 1434 CRYPTO_AES_CtrFuncPtr_TypeDef ctrFunc)
Kojto 113:f141b2784e32 1435 {
<> 128:9bcdf88f62b0 1436 CRYPTO_AES_CTR256(CRYPTO, out, in, len, key, ctr, ctrFunc);
Kojto 113:f141b2784e32 1437 }
Kojto 113:f141b2784e32 1438
Kojto 113:f141b2784e32 1439 /***************************************************************************//**
Kojto 113:f141b2784e32 1440 * @brief
Kojto 113:f141b2784e32 1441 * Update last 32 bits of 128 bit counter, by incrementing with 1.
Kojto 113:f141b2784e32 1442 *
Kojto 113:f141b2784e32 1443 * @deprecated
Kojto 113:f141b2784e32 1444 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1445 * @ref CRYPTO_AES_CTRUpdate32Bit instead.
Kojto 113:f141b2784e32 1446 ******************************************************************************/
Kojto 113:f141b2784e32 1447 __STATIC_INLINE void AES_CTRUpdate32Bit(uint8_t * ctr)
Kojto 113:f141b2784e32 1448 {
Kojto 113:f141b2784e32 1449 CRYPTO_AES_CTRUpdate32Bit(ctr);
Kojto 113:f141b2784e32 1450 }
Kojto 113:f141b2784e32 1451
Kojto 113:f141b2784e32 1452 /***************************************************************************//**
Kojto 113:f141b2784e32 1453 * @brief
Kojto 113:f141b2784e32 1454 * Generate 128 bit AES decryption key from 128 bit encryption key. The
Kojto 113:f141b2784e32 1455 * decryption key is used for some cipher modes when decrypting.
Kojto 113:f141b2784e32 1456 *
Kojto 113:f141b2784e32 1457 * @deprecated
Kojto 113:f141b2784e32 1458 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1459 * @ref CRYPTO_AES_DecryptKey128 instead.
Kojto 113:f141b2784e32 1460 ******************************************************************************/
Kojto 113:f141b2784e32 1461 __STATIC_INLINE void AES_DecryptKey128(uint8_t * out, const uint8_t * in)
Kojto 113:f141b2784e32 1462 {
<> 128:9bcdf88f62b0 1463 CRYPTO_AES_DecryptKey128(CRYPTO, out, in);
Kojto 113:f141b2784e32 1464 }
Kojto 113:f141b2784e32 1465
Kojto 113:f141b2784e32 1466 /***************************************************************************//**
Kojto 113:f141b2784e32 1467 * @brief
Kojto 113:f141b2784e32 1468 * Generate 256 bit AES decryption key from 256 bit encryption key. The
Kojto 113:f141b2784e32 1469 * decryption key is used for some cipher modes when decrypting.
Kojto 113:f141b2784e32 1470 *
Kojto 113:f141b2784e32 1471 * @deprecated
Kojto 113:f141b2784e32 1472 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1473 * @ref CRYPTO_AES_DecryptKey256 instead.
Kojto 113:f141b2784e32 1474 ******************************************************************************/
Kojto 113:f141b2784e32 1475 __STATIC_INLINE void AES_DecryptKey256(uint8_t * out, const uint8_t * in)
Kojto 113:f141b2784e32 1476 {
<> 128:9bcdf88f62b0 1477 CRYPTO_AES_DecryptKey256(CRYPTO, out, in);
Kojto 113:f141b2784e32 1478 }
Kojto 113:f141b2784e32 1479
Kojto 113:f141b2784e32 1480 /***************************************************************************//**
Kojto 113:f141b2784e32 1481 * @brief
Kojto 113:f141b2784e32 1482 * AES Electronic Codebook (ECB) cipher mode encryption/decryption,
Kojto 113:f141b2784e32 1483 * 128 bit key.
Kojto 113:f141b2784e32 1484 *
Kojto 113:f141b2784e32 1485 * @deprecated
Kojto 113:f141b2784e32 1486 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1487 * @ref CRYPTO_AES_ECB128 instead.
Kojto 113:f141b2784e32 1488 ******************************************************************************/
Kojto 113:f141b2784e32 1489 __STATIC_INLINE void AES_ECB128(uint8_t * out,
Kojto 113:f141b2784e32 1490 const uint8_t * in,
Kojto 113:f141b2784e32 1491 unsigned int len,
Kojto 113:f141b2784e32 1492 const uint8_t * key,
Kojto 113:f141b2784e32 1493 bool encrypt)
Kojto 113:f141b2784e32 1494 {
<> 128:9bcdf88f62b0 1495 CRYPTO_AES_ECB128(CRYPTO, out, in, len, key, encrypt);
Kojto 113:f141b2784e32 1496 }
Kojto 113:f141b2784e32 1497
Kojto 113:f141b2784e32 1498 /***************************************************************************//**
Kojto 113:f141b2784e32 1499 * @brief
Kojto 113:f141b2784e32 1500 * AES Electronic Codebook (ECB) cipher mode encryption/decryption,
Kojto 113:f141b2784e32 1501 * 256 bit key.
Kojto 113:f141b2784e32 1502 *
Kojto 113:f141b2784e32 1503 * @deprecated
Kojto 113:f141b2784e32 1504 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1505 * @ref CRYPTO_AES_ECB256 instead.
Kojto 113:f141b2784e32 1506 ******************************************************************************/
Kojto 113:f141b2784e32 1507 __STATIC_INLINE void AES_ECB256(uint8_t * out,
Kojto 113:f141b2784e32 1508 const uint8_t * in,
Kojto 113:f141b2784e32 1509 unsigned int len,
Kojto 113:f141b2784e32 1510 const uint8_t * key,
Kojto 113:f141b2784e32 1511 bool encrypt)
Kojto 113:f141b2784e32 1512 {
<> 128:9bcdf88f62b0 1513 CRYPTO_AES_ECB256(CRYPTO, out, in, len, key, encrypt);
Kojto 113:f141b2784e32 1514 }
Kojto 113:f141b2784e32 1515
Kojto 113:f141b2784e32 1516 /***************************************************************************//**
Kojto 113:f141b2784e32 1517 * @brief
Kojto 113:f141b2784e32 1518 * AES Output feedback (OFB) cipher mode encryption/decryption, 128 bit key.
Kojto 113:f141b2784e32 1519 *
Kojto 113:f141b2784e32 1520 * @deprecated
Kojto 113:f141b2784e32 1521 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1522 * @ref CRYPTO_AES_OFB128 instead.
Kojto 113:f141b2784e32 1523 ******************************************************************************/
Kojto 113:f141b2784e32 1524 __STATIC_INLINE void AES_OFB128(uint8_t * out,
Kojto 113:f141b2784e32 1525 const uint8_t * in,
Kojto 113:f141b2784e32 1526 unsigned int len,
Kojto 113:f141b2784e32 1527 const uint8_t * key,
Kojto 113:f141b2784e32 1528 const uint8_t * iv)
Kojto 113:f141b2784e32 1529 {
<> 128:9bcdf88f62b0 1530 CRYPTO_AES_OFB128(CRYPTO, out, in, len, key, iv);
Kojto 113:f141b2784e32 1531 }
Kojto 113:f141b2784e32 1532
Kojto 113:f141b2784e32 1533 /***************************************************************************//**
Kojto 113:f141b2784e32 1534 * @brief
Kojto 113:f141b2784e32 1535 * AES Output feedback (OFB) cipher mode encryption/decryption, 256 bit key.
Kojto 113:f141b2784e32 1536 *
Kojto 113:f141b2784e32 1537 * @deprecated
Kojto 113:f141b2784e32 1538 * This function is present to preserve backwards compatibility. Use
Kojto 113:f141b2784e32 1539 * @ref CRYPTO_AES_OFB256 instead.
Kojto 113:f141b2784e32 1540 ******************************************************************************/
Kojto 113:f141b2784e32 1541 __STATIC_INLINE void AES_OFB256(uint8_t * out,
Kojto 113:f141b2784e32 1542 const uint8_t * in,
Kojto 113:f141b2784e32 1543 unsigned int len,
Kojto 113:f141b2784e32 1544 const uint8_t * key,
Kojto 113:f141b2784e32 1545 const uint8_t * iv)
Kojto 113:f141b2784e32 1546 {
<> 128:9bcdf88f62b0 1547 CRYPTO_AES_OFB256(CRYPTO, out, in, len, key, iv);
Kojto 113:f141b2784e32 1548 }
Kojto 113:f141b2784e32 1549
Kojto 113:f141b2784e32 1550 #ifdef __cplusplus
Kojto 113:f141b2784e32 1551 }
Kojto 113:f141b2784e32 1552 #endif
Kojto 113:f141b2784e32 1553
Kojto 113:f141b2784e32 1554 /** @} (end addtogroup CRYPTO) */
<> 128:9bcdf88f62b0 1555 /** @} (end addtogroup emlib) */
Kojto 113:f141b2784e32 1556
Kojto 113:f141b2784e32 1557 #endif /* defined(CRYPTO_COUNT) && (CRYPTO_COUNT > 0) */
Kojto 113:f141b2784e32 1558
<> 128:9bcdf88f62b0 1559 #endif /* EM_CRYPTO_H */