blob: cfcd8c6ddc8d22690af872923d7fc7a142f49671 [file] [log] [blame]
Qiufang Dai35c31332020-05-13 15:29:06 +08001/*
2 * Amazon FreeRTOS
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * http://aws.amazon.com/freertos
23 * http://www.FreeRTOS.org
24 */
25
26
27#ifndef __AWS_CRYPTO__H__
28#define __AWS_CRYPTO__H__
29
30/**
31 * @brief Commonly used buffer sizes for storing cryptographic hash computation
32 * results.
33 */
34#define cryptoSHA1_DIGEST_BYTES 20
35#define cryptoSHA256_DIGEST_BYTES 32
36
37/**
38 * @brief Configures crypto library heap callouts so that the FreeRTOS heap is
39 * used instead of the C runtime heap. Skipping this call is likely to cause
40 * runtime memory corruption in the application.
41 */
42void CRYPTO_ConfigureHeap( void );
43
44/**
45 * @brief Library-independent cryptographic algorithm identifiers.
46 */
47#define cryptoHASH_ALGORITHM_SHA1 1
48#define cryptoHASH_ALGORITHM_SHA256 2
49#define cryptoASYMMETRIC_ALGORITHM_RSA 1
50#define cryptoASYMMETRIC_ALGORITHM_ECDSA 2
51
52/**
53 * @brief Initializes digital signature verification.
54 *
55 * @param[out] ppvContext Opaque context structure.
56 * @param[in] xAsymmetricAlgorithm Cryptographic public key cryptosystem.
57 * @param[in] xHashAlgorithm Cryptographic hash algorithm that was used for signing.
58 *
59 * @return pdTRUE if initialization succeeds, or pdFALSE otherwise.
60 */
61BaseType_t CRYPTO_SignatureVerificationStart( void ** ppvContext,
62 BaseType_t xAsymmetricAlgorithm,
63 BaseType_t xHashAlgorithm );
64
65/**
66 * @brief Updates a cryptographic hash computation with the specified byte array.
67 *
68 * @param[in] pvContext Opaque context structure.
69 * @param[in] pucData Byte array that was signed.
70 * @param[in] xDataLength Length in bytes of data that was signed.
71 */
72void CRYPTO_SignatureVerificationUpdate( void * pvContext,
73 uint8_t * pucData,
74 size_t xDataLength );
75
76/**
77 * @brief Verifies a digital signature computation using the public key from the
78 * specified certificate.
79 *
80 * @param[in] pvContext Opaque context structure.
81 * @param[in] pucSignerCertificate Base64 and DER encoded X.509 certificate of the
82 * signer.
83 * @param[in] xSignerCertificateLength Length in bytes of the certificate.
84 * @param[in] pucSignature Digital signature result to verify.
85 * @param[in] xSignatureLength in bytes of digital signature result.
86 *
87 * @return pdTRUE if the signature is correct or pdFALSE if the signature is invalid.
88 */
89BaseType_t CRYPTO_SignatureVerificationFinal( void * pvContext,
90 char * pcSignerCertificate,
91 size_t xSignerCertificateLength,
92 uint8_t * pucSignature,
93 size_t xSignatureLength );
94
95#endif /* ifndef __AWS_CRYPTO__H__ */