mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_M480/crypto/crypto-misc.h@180:96ed750bd169, 2018-01-17 (annotated)
- Committer:
- Anna Bridge
- Date:
- Wed Jan 17 15:23:54 2018 +0000
- Revision:
- 180:96ed750bd169
- Child:
- 182:a56a73fd2a6f
mbed-dev libray. Release version 158
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
180:96ed750bd169 | 1 | /* mbed Microcontroller Library |
Anna Bridge |
180:96ed750bd169 | 2 | * Copyright (c) 2015-2016 Nuvoton |
Anna Bridge |
180:96ed750bd169 | 3 | * |
Anna Bridge |
180:96ed750bd169 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Anna Bridge |
180:96ed750bd169 | 5 | * you may not use this file except in compliance with the License. |
Anna Bridge |
180:96ed750bd169 | 6 | * You may obtain a copy of the License at |
Anna Bridge |
180:96ed750bd169 | 7 | * |
Anna Bridge |
180:96ed750bd169 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Anna Bridge |
180:96ed750bd169 | 9 | * |
Anna Bridge |
180:96ed750bd169 | 10 | * Unless required by applicable law or agreed to in writing, software |
Anna Bridge |
180:96ed750bd169 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Anna Bridge |
180:96ed750bd169 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Anna Bridge |
180:96ed750bd169 | 13 | * See the License for the specific language governing permissions and |
Anna Bridge |
180:96ed750bd169 | 14 | * limitations under the License. |
Anna Bridge |
180:96ed750bd169 | 15 | */ |
Anna Bridge |
180:96ed750bd169 | 16 | |
Anna Bridge |
180:96ed750bd169 | 17 | #ifndef MBED_CRYPTO_MISC_H |
Anna Bridge |
180:96ed750bd169 | 18 | #define MBED_CRYPTO_MISC_H |
Anna Bridge |
180:96ed750bd169 | 19 | |
Anna Bridge |
180:96ed750bd169 | 20 | #include <stdbool.h> |
Anna Bridge |
180:96ed750bd169 | 21 | |
Anna Bridge |
180:96ed750bd169 | 22 | #ifdef __cplusplus |
Anna Bridge |
180:96ed750bd169 | 23 | extern "C" { |
Anna Bridge |
180:96ed750bd169 | 24 | #endif |
Anna Bridge |
180:96ed750bd169 | 25 | |
Anna Bridge |
180:96ed750bd169 | 26 | /* Init/Uninit crypto module */ |
Anna Bridge |
180:96ed750bd169 | 27 | void crypto_init(void); |
Anna Bridge |
180:96ed750bd169 | 28 | void crypto_uninit(void); |
Anna Bridge |
180:96ed750bd169 | 29 | |
Anna Bridge |
180:96ed750bd169 | 30 | /* Clear buffer to zero |
Anna Bridge |
180:96ed750bd169 | 31 | * Implementation that should never be optimized out by the compiler */ |
Anna Bridge |
180:96ed750bd169 | 32 | void crypto_zeroize(void *v, size_t n); |
Anna Bridge |
180:96ed750bd169 | 33 | |
Anna Bridge |
180:96ed750bd169 | 34 | /* Acquire/release ownership of AES H/W */ |
Anna Bridge |
180:96ed750bd169 | 35 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
Anna Bridge |
180:96ed750bd169 | 36 | bool crypto_aes_acquire(void); |
Anna Bridge |
180:96ed750bd169 | 37 | void crypto_aes_release(void); |
Anna Bridge |
180:96ed750bd169 | 38 | |
Anna Bridge |
180:96ed750bd169 | 39 | /* Acquire/release ownership of DES H/W */ |
Anna Bridge |
180:96ed750bd169 | 40 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
Anna Bridge |
180:96ed750bd169 | 41 | bool crypto_des_acquire(void); |
Anna Bridge |
180:96ed750bd169 | 42 | void crypto_des_release(void); |
Anna Bridge |
180:96ed750bd169 | 43 | |
Anna Bridge |
180:96ed750bd169 | 44 | /* Acquire/release ownership of SHA H/W */ |
Anna Bridge |
180:96ed750bd169 | 45 | /* NOTE: If "acquire" succeeds, "release" must be done to pair it. */ |
Anna Bridge |
180:96ed750bd169 | 46 | bool crypto_sha_acquire(void); |
Anna Bridge |
180:96ed750bd169 | 47 | void crypto_sha_release(void); |
Anna Bridge |
180:96ed750bd169 | 48 | |
Anna Bridge |
180:96ed750bd169 | 49 | /* Flow control between crypto/xxx start and crypto/xxx ISR |
Anna Bridge |
180:96ed750bd169 | 50 | * |
Anna Bridge |
180:96ed750bd169 | 51 | * crypto_xxx_prestart/crypto_xxx_wait encapsulate control flow between crypto/xxx start and crypto/xxx ISR. |
Anna Bridge |
180:96ed750bd169 | 52 | * |
Anna Bridge |
180:96ed750bd169 | 53 | * crypto_xxx_prestart will also address synchronization issue with memory barrier instruction. |
Anna Bridge |
180:96ed750bd169 | 54 | * |
Anna Bridge |
180:96ed750bd169 | 55 | * On finish, return of crypto_xxx_wait indicates success or not: |
Anna Bridge |
180:96ed750bd169 | 56 | * true if successful |
Anna Bridge |
180:96ed750bd169 | 57 | * false if failed |
Anna Bridge |
180:96ed750bd169 | 58 | * |
Anna Bridge |
180:96ed750bd169 | 59 | * Example: Start AES H/W and wait for its finish |
Anna Bridge |
180:96ed750bd169 | 60 | * crypto_aes_prestart(); |
Anna Bridge |
180:96ed750bd169 | 61 | * AES_Start(); |
Anna Bridge |
180:96ed750bd169 | 62 | * crypto_aes_wait(); |
Anna Bridge |
180:96ed750bd169 | 63 | */ |
Anna Bridge |
180:96ed750bd169 | 64 | void crypto_prng_prestart(void); |
Anna Bridge |
180:96ed750bd169 | 65 | bool crypto_prng_wait(void); |
Anna Bridge |
180:96ed750bd169 | 66 | void crypto_aes_prestart(void); |
Anna Bridge |
180:96ed750bd169 | 67 | bool crypto_aes_wait(void); |
Anna Bridge |
180:96ed750bd169 | 68 | void crypto_des_prestart(void); |
Anna Bridge |
180:96ed750bd169 | 69 | bool crypto_des_wait(void); |
Anna Bridge |
180:96ed750bd169 | 70 | |
Anna Bridge |
180:96ed750bd169 | 71 | |
Anna Bridge |
180:96ed750bd169 | 72 | /* Check if buffer can be used for crypto DMA. It has the following requirements: |
Anna Bridge |
180:96ed750bd169 | 73 | * (1) Word-aligned buffer base address |
Anna Bridge |
180:96ed750bd169 | 74 | * (2) Crypto submodule (AES, DES, SHA, etc.) dependent buffer size alignment. Must be 2 power. |
Anna Bridge |
180:96ed750bd169 | 75 | * (3) Located in 0x20000000-0x2FFFFFFF region |
Anna Bridge |
180:96ed750bd169 | 76 | */ |
Anna Bridge |
180:96ed750bd169 | 77 | bool crypto_dma_buff_compat(const void *buff, size_t buff_size, size_t size_aligned_to); |
Anna Bridge |
180:96ed750bd169 | 78 | |
Anna Bridge |
180:96ed750bd169 | 79 | /* Check if input/output buffers are overlapped */ |
Anna Bridge |
180:96ed750bd169 | 80 | bool crypto_dma_buffs_overlap(const void *in_buff, size_t in_buff_size, const void *out_buff, size_t out_buff_size); |
Anna Bridge |
180:96ed750bd169 | 81 | |
Anna Bridge |
180:96ed750bd169 | 82 | #ifdef __cplusplus |
Anna Bridge |
180:96ed750bd169 | 83 | } |
Anna Bridge |
180:96ed750bd169 | 84 | #endif |
Anna Bridge |
180:96ed750bd169 | 85 | |
Anna Bridge |
180:96ed750bd169 | 86 | #endif |