![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_NUVOTON/TARGET_M2351/crypto/crypto-misc.h@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2017-2018 Nuvoton |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #ifndef MBED_CRYPTO_MISC_H |
kadonotakashi | 0:8fdf9a60065b | 18 | #define MBED_CRYPTO_MISC_H |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | #include <stdbool.h> |
kadonotakashi | 0:8fdf9a60065b | 21 | #include "partition_M2351.h" |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | /* Policy for configuring secure attribute of CRYPTO/CRPT module: |
kadonotakashi | 0:8fdf9a60065b | 24 | * |
kadonotakashi | 0:8fdf9a60065b | 25 | * There's only one CRYPTO/CRPT module and we have the following policy for configuring its secure attribute: |
kadonotakashi | 0:8fdf9a60065b | 26 | * |
kadonotakashi | 0:8fdf9a60065b | 27 | * 1. TRNG or mbedtls H/W support can be enabled on either secure target or non-secure target, but not both. |
kadonotakashi | 0:8fdf9a60065b | 28 | * 2. TRNG and mbedtls H/W supports cannot be enabled on different targets. |
kadonotakashi | 0:8fdf9a60065b | 29 | * 3. On secure target, if TRNG or mbedtls H/W support is enabled, CRYPTO/CRPT must configure to secure. |
kadonotakashi | 0:8fdf9a60065b | 30 | * 4. On non-secure target, if TRNG or mbedtls H/W support is enabled, CRYPTO/CRPT must configure to non-secure. |
kadonotakashi | 0:8fdf9a60065b | 31 | */ |
kadonotakashi | 0:8fdf9a60065b | 32 | #if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT) |
kadonotakashi | 0:8fdf9a60065b | 33 | #if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) |
kadonotakashi | 0:8fdf9a60065b | 34 | #if defined(SCU_INIT_PNSSET1_VAL) && (SCU_INIT_PNSSET1_VAL & (1 << 18)) |
kadonotakashi | 0:8fdf9a60065b | 35 | #error("CRYPTO/CRPT must configure to secure for secure target which supports TRNG or mbedtls H/W") |
kadonotakashi | 0:8fdf9a60065b | 36 | #endif |
kadonotakashi | 0:8fdf9a60065b | 37 | #else |
kadonotakashi | 0:8fdf9a60065b | 38 | #if (! defined(SCU_INIT_PNSSET1_VAL)) || (! (SCU_INIT_PNSSET1_VAL & (1 << 18))) |
kadonotakashi | 0:8fdf9a60065b | 39 | #error("CRYPTO/CRPT must configure to non-secure for non-secure target which supports TRNG or mbedtls H/W") |
kadonotakashi | 0:8fdf9a60065b | 40 | #endif |
kadonotakashi | 0:8fdf9a60065b | 41 | #endif |
kadonotakashi | 0:8fdf9a60065b | 42 | #endif |
kadonotakashi | 0:8fdf9a60065b | 43 | |
kadonotakashi | 0:8fdf9a60065b | 44 | #if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT) |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 47 | extern "C" { |
kadonotakashi | 0:8fdf9a60065b | 48 | #endif |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | /* Get Crypto module base dependent on security state */ |
kadonotakashi | 0:8fdf9a60065b | 51 | __STATIC_INLINE CRPT_T *CRYPTO_MODBASE(void) |
kadonotakashi | 0:8fdf9a60065b | 52 | { |
kadonotakashi | 0:8fdf9a60065b | 53 | #if defined(SCU_INIT_PNSSET1_VAL) && (SCU_INIT_PNSSET1_VAL & (1<<18)) |
kadonotakashi | 0:8fdf9a60065b | 54 | return CRPT_NS; |
kadonotakashi | 0:8fdf9a60065b | 55 | #else |
kadonotakashi | 0:8fdf9a60065b | 56 | return CRPT; |
kadonotakashi | 0:8fdf9a60065b | 57 | #endif |
kadonotakashi | 0:8fdf9a60065b | 58 | } |
kadonotakashi | 0:8fdf9a60065b | 59 | |
kadonotakashi | 0:8fdf9a60065b | 60 | /* Init/Uninit crypto module */ |
kadonotakashi | 0:8fdf9a60065b | 61 | void crypto_init(void); |
kadonotakashi | 0:8fdf9a60065b | 62 | void crypto_uninit(void); |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | /* Clear buffer to zero |
kadonotakashi | 0:8fdf9a60065b | 65 | * Implementation that should never be optimized out by the compiler */ |
kadonotakashi | 0:8fdf9a60065b | 66 | void crypto_zeroize(void *v, size_t n); |
kadonotakashi | 0:8fdf9a60065b | 67 | void crypto_zeroize32(uint32_t *v, size_t n); |
kadonotakashi | 0:8fdf9a60065b | 68 | |
kadonotakashi | 0:8fdf9a60065b | 69 | /* Acquire/release ownership of AES H/W */ |
kadonotakashi | 0:8fdf9a60065b | 70 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
kadonotakashi | 0:8fdf9a60065b | 71 | bool crypto_aes_acquire(void); |
kadonotakashi | 0:8fdf9a60065b | 72 | void crypto_aes_release(void); |
kadonotakashi | 0:8fdf9a60065b | 73 | |
kadonotakashi | 0:8fdf9a60065b | 74 | /* Acquire/release ownership of DES H/W */ |
kadonotakashi | 0:8fdf9a60065b | 75 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
kadonotakashi | 0:8fdf9a60065b | 76 | bool crypto_des_acquire(void); |
kadonotakashi | 0:8fdf9a60065b | 77 | void crypto_des_release(void); |
kadonotakashi | 0:8fdf9a60065b | 78 | |
kadonotakashi | 0:8fdf9a60065b | 79 | /* Acquire/release ownership of SHA H/W */ |
kadonotakashi | 0:8fdf9a60065b | 80 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
kadonotakashi | 0:8fdf9a60065b | 81 | bool crypto_sha_acquire(void); |
kadonotakashi | 0:8fdf9a60065b | 82 | void crypto_sha_release(void); |
kadonotakashi | 0:8fdf9a60065b | 83 | |
kadonotakashi | 0:8fdf9a60065b | 84 | /* Acquire/release ownership of ECC H/W */ |
kadonotakashi | 0:8fdf9a60065b | 85 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
kadonotakashi | 0:8fdf9a60065b | 86 | bool crypto_ecc_acquire(void); |
kadonotakashi | 0:8fdf9a60065b | 87 | void crypto_ecc_release(void); |
kadonotakashi | 0:8fdf9a60065b | 88 | |
kadonotakashi | 0:8fdf9a60065b | 89 | /* Flow control between crypto/xxx start and crypto/xxx ISR |
kadonotakashi | 0:8fdf9a60065b | 90 | * |
kadonotakashi | 0:8fdf9a60065b | 91 | * crypto_xxx_prestart/crypto_xxx_wait encapsulate control flow between crypto/xxx start and crypto/xxx ISR. |
kadonotakashi | 0:8fdf9a60065b | 92 | * |
kadonotakashi | 0:8fdf9a60065b | 93 | * crypto_xxx_prestart will also address synchronization issue with memory barrier instruction. |
kadonotakashi | 0:8fdf9a60065b | 94 | * |
kadonotakashi | 0:8fdf9a60065b | 95 | * On finish, return of crypto_xxx_wait indicates success or not: |
kadonotakashi | 0:8fdf9a60065b | 96 | * true if successful |
kadonotakashi | 0:8fdf9a60065b | 97 | * false if failed |
kadonotakashi | 0:8fdf9a60065b | 98 | * |
kadonotakashi | 0:8fdf9a60065b | 99 | * Example: Start AES H/W and wait for its finish |
kadonotakashi | 0:8fdf9a60065b | 100 | * crypto_aes_prestart(); |
kadonotakashi | 0:8fdf9a60065b | 101 | * AES_Start(); |
kadonotakashi | 0:8fdf9a60065b | 102 | * crypto_aes_wait(); |
kadonotakashi | 0:8fdf9a60065b | 103 | */ |
kadonotakashi | 0:8fdf9a60065b | 104 | void crypto_prng_prestart(void); |
kadonotakashi | 0:8fdf9a60065b | 105 | bool crypto_prng_wait(void); |
kadonotakashi | 0:8fdf9a60065b | 106 | void crypto_aes_prestart(void); |
kadonotakashi | 0:8fdf9a60065b | 107 | bool crypto_aes_wait(void); |
kadonotakashi | 0:8fdf9a60065b | 108 | void crypto_des_prestart(void); |
kadonotakashi | 0:8fdf9a60065b | 109 | bool crypto_des_wait(void); |
kadonotakashi | 0:8fdf9a60065b | 110 | void crypto_ecc_prestart(void); |
kadonotakashi | 0:8fdf9a60065b | 111 | bool crypto_ecc_wait(void); |
kadonotakashi | 0:8fdf9a60065b | 112 | |
kadonotakashi | 0:8fdf9a60065b | 113 | |
kadonotakashi | 0:8fdf9a60065b | 114 | /* Check if buffer can be used for crypto DMA. It has the following requirements: |
kadonotakashi | 0:8fdf9a60065b | 115 | * (1) Word-aligned buffer base address |
kadonotakashi | 0:8fdf9a60065b | 116 | * (2) Crypto submodule (AES, DES, SHA, etc.) dependent buffer size alignment. Must be 2 power. |
kadonotakashi | 0:8fdf9a60065b | 117 | * (3) Located in 0x20000000-0x2FFFFFFF region |
kadonotakashi | 0:8fdf9a60065b | 118 | */ |
kadonotakashi | 0:8fdf9a60065b | 119 | bool crypto_dma_buff_compat(const void *buff, size_t buff_size, size_t size_aligned_to); |
kadonotakashi | 0:8fdf9a60065b | 120 | |
kadonotakashi | 0:8fdf9a60065b | 121 | /* Check if input/output buffers are overlapped */ |
kadonotakashi | 0:8fdf9a60065b | 122 | bool crypto_dma_buffs_overlap(const void *in_buff, size_t in_buff_size, const void *out_buff, size_t out_buff_size); |
kadonotakashi | 0:8fdf9a60065b | 123 | |
kadonotakashi | 0:8fdf9a60065b | 124 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 125 | } |
kadonotakashi | 0:8fdf9a60065b | 126 | #endif |
kadonotakashi | 0:8fdf9a60065b | 127 | |
kadonotakashi | 0:8fdf9a60065b | 128 | #endif /* #if DEVICE_TRNG || defined(MBEDTLS_CONFIG_HW_SUPPORT) */ |
kadonotakashi | 0:8fdf9a60065b | 129 | |
kadonotakashi | 0:8fdf9a60065b | 130 | #endif |