• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Represents a SHA-256 hash.
59  */
60 typedef otPlatCryptoSha256Hash otCryptoSha256Hash;
61 
62 /**
63  * Performs HMAC computation.
64  *
65  * @param[in]     aKey           A pointer to the key.
66  * @param[in]     aBuf           A pointer to the input buffer.
67  * @param[in]     aBufLength     The length of @p aBuf in bytes.
68  * @param[out]    aHash          A pointer to a `otCryptoSha256Hash` structure to output the hash value.
69  */
70 void otCryptoHmacSha256(const otCryptoKey *aKey, const uint8_t *aBuf, uint16_t aBufLength, otCryptoSha256Hash *aHash);
71 
72 /**
73  * Performs AES CCM computation.
74  *
75  * @param[in]      aKey           A pointer to the key.
76  * @param[in]      aTagLength     Length of tag in bytes.
77  * @param[in]      aNonce         A pointer to the nonce.
78  * @param[in]      aNonceLength   Length of nonce in bytes.
79  *
80  * @param[in]      aHeader        A pointer to the header.
81  * @param[in]      aHeaderLength  Length of header in bytes.
82  *
83  * @param[in,out]  aPlainText     A pointer to the plaintext.
84  * @param[in,out]  aCipherText    A pointer to the ciphertext.
85  * @param[in]      aLength        Plaintext length in bytes.
86  * @param[in]      aEncrypt       `true` on encrypt and `false` on decrypt.
87  *
88  * @param[out]     aTag           A pointer to the tag.
89  */
90 void otCryptoAesCcm(const otCryptoKey *aKey,
91                     uint8_t            aTagLength,
92                     const void        *aNonce,
93                     uint8_t            aNonceLength,
94                     const void        *aHeader,
95                     uint32_t           aHeaderLength,
96                     void              *aPlainText,
97                     void              *aCipherText,
98                     uint32_t           aLength,
99                     bool               aEncrypt,
100                     void              *aTag);
101 
102 /**
103  * @}
104  */
105 
106 #ifdef __cplusplus
107 } // extern "C"
108 #endif
109 
110 #endif // OPENTHREAD_CRYPTO_H_
111