1 /* 2 * Copyright (c) 2016, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * @brief 32 * This file defines the OpenThread crypto C APIs. 33 */ 34 35 #ifndef OPENTHREAD_CRYPTO_H_ 36 #define OPENTHREAD_CRYPTO_H_ 37 38 #include <stdbool.h> 39 #include <stdint.h> 40 41 #include <openthread/error.h> 42 #include <openthread/platform/crypto.h> 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 /** 49 * @addtogroup api-crypto 50 * 51 * @brief 52 * This module includes cryptographic functions. 53 * 54 * @{ 55 * 56 */ 57 58 /** 59 * @struct otCryptoSha256Hash 60 * 61 * Represents a SHA-256 hash. 62 * 63 */ 64 typedef otPlatCryptoSha256Hash otCryptoSha256Hash; 65 66 /** 67 * Performs HMAC computation. 68 * 69 * @param[in] aKey A pointer to the key. 70 * @param[in] aBuf A pointer to the input buffer. 71 * @param[in] aBufLength The length of @p aBuf in bytes. 72 * @param[out] aHash A pointer to a `otCryptoSha256Hash` structure to output the hash value. 73 * 74 */ 75 void otCryptoHmacSha256(const otCryptoKey *aKey, const uint8_t *aBuf, uint16_t aBufLength, otCryptoSha256Hash *aHash); 76 77 /** 78 * Performs AES CCM computation. 79 * 80 * @param[in] aKey A pointer to the key. 81 * @param[in] aTagLength Length of tag in bytes. 82 * @param[in] aNonce A pointer to the nonce. 83 * @param[in] aNonceLength Length of nonce in bytes. 84 * 85 * @param[in] aHeader A pointer to the header. 86 * @param[in] aHeaderLength Length of header in bytes. 87 * 88 * @param[in,out] aPlainText A pointer to the plaintext. 89 * @param[in,out] aCipherText A pointer to the ciphertext. 90 * @param[in] aLength Plaintext length in bytes. 91 * @param[in] aEncrypt `true` on encrypt and `false` on decrypt. 92 * 93 * @param[out] aTag A pointer to the tag. 94 * 95 */ 96 void otCryptoAesCcm(const otCryptoKey *aKey, 97 uint8_t aTagLength, 98 const void *aNonce, 99 uint8_t aNonceLength, 100 const void *aHeader, 101 uint32_t aHeaderLength, 102 void *aPlainText, 103 void *aCipherText, 104 uint32_t aLength, 105 bool aEncrypt, 106 void *aTag); 107 108 /** 109 * @} 110 * 111 */ 112 113 #ifdef __cplusplus 114 } // extern "C" 115 #endif 116 117 #endif // OPENTHREAD_CRYPTO_H_ 118