AM64x MCU+ SDK  12.01.00
crypto_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
48 #ifndef PKA_UTIL_H_
49 #define PKA_UTIL_H_
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56 
57 /* ========================================================================== */
58 /* Include Files */
59 /* ========================================================================== */
60 
61 #include <stdint.h>
62 
63 /* ========================================================================== */
64 /* Macros & Typedefs */
65 /* ========================================================================== */
66 
73 #define HASH_ALG_SHA1 (0x0U)
74 
75 #define HASH_ALG_SHA2_256 (0x1U)
76 
77 #define HASH_ALG_SHA2_512 (0x2U)
78 
79 #define HASH_ALG_SHA2_384 (0x3U)
80 
82 /* ========================================================================== */
83 /* Global Variables */
84 /* ========================================================================== */
85 
86 /* None */
87 
88 /* ========================================================================== */
89 /* Function Declarations */
90 /* ========================================================================== */
91 
101 void Crypto_Uint8ToUint32(const uint8_t *source, uint32_t sourceLengthInBytes, uint32_t *dest);
102 
112 void Crypto_Uint32ToUint8(const uint32_t *src, uint32_t sourceLengthInBytes, uint8_t *dest);
113 
123 void Crypto_Uint32ToBigInt(uint32_t *source, uint32_t sourceLengthInWords, uint32_t *dest);
124 
134 void Crypto_bigIntToUint32(uint32_t *source, uint32_t sourceLengthInWords, uint32_t *dest);
135 
152 void Crypto_PKCSPaddingForSign(const uint8_t *shaHash, uint32_t keyLengthInBytes, uint32_t typeOfAlgo, uint8_t *output);
153 
174 typedef uint32_t (*Crypto_ShaCallback)(uint8_t *inputBuf, uint32_t inputLenBytes, uint8_t *digestBuf);
175 
188  const uint8_t *msgHash;
190  const uint8_t *salt;
192  uint32_t saltLenInBytes;
193 };
194 
215 uint32_t Crypto_MGF1(Crypto_ShaCallback shaCbFxn, uint32_t hashLenInBytes,
216  uint8_t *seedBuf, uint32_t seedLenInBytes,
217  uint8_t *mask, uint32_t maskLenInBytes);
218 
242 uint32_t Crypto_PSSPaddingForSign(Crypto_ShaCallback shaCbFxn, uint32_t typeOfAlgo,
243  const struct Crypto_PSSSaltInfo *saltInfo,
244  uint32_t modBits, uint32_t emLenInBytes, uint8_t *output);
245 
270 uint32_t Crypto_PSSVerify(Crypto_ShaCallback shaCbFxn, uint32_t typeOfAlgo,
271  const uint8_t *msgHash, uint32_t saltLenInBytes,
272  uint32_t modBits, const uint8_t *EM, uint32_t emLenInBytes);
273 
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 
279 #endif /* PKA_UTIL_H_ */
280 
Crypto_bigIntToUint32
void Crypto_bigIntToUint32(uint32_t *source, uint32_t sourceLengthInWords, uint32_t *dest)
Function to convert Bigint to uint32_t format.
Crypto_PSSSaltInfo
Message hash and salt inputs to Crypto_PSSPaddingForSign, bundled to keep the function's parameter co...
Definition: crypto_util.h:186
Crypto_Uint32ToUint8
void Crypto_Uint32ToUint8(const uint32_t *src, uint32_t sourceLengthInBytes, uint8_t *dest)
Function to convert uint32_t to uint8_t format.
Crypto_PSSVerify
uint32_t Crypto_PSSVerify(Crypto_ShaCallback shaCbFxn, uint32_t typeOfAlgo, const uint8_t *msgHash, uint32_t saltLenInBytes, uint32_t modBits, const uint8_t *EM, uint32_t emLenInBytes)
Verifies an EMSA-PSS encoding for RSA signature verification, refer to RFC 8017 Section 9....
Crypto_PSSSaltInfo::salt
const uint8_t * salt
Definition: crypto_util.h:190
Crypto_PSSPaddingForSign
uint32_t Crypto_PSSPaddingForSign(Crypto_ShaCallback shaCbFxn, uint32_t typeOfAlgo, const struct Crypto_PSSSaltInfo *saltInfo, uint32_t modBits, uint32_t emLenInBytes, uint8_t *output)
Builds the EMSA-PSS encoding for RSA signing, refer to RFC 8017 Section 9.1.1 https://www....
Crypto_PKCSPaddingForSign
void Crypto_PKCSPaddingForSign(const uint8_t *shaHash, uint32_t keyLengthInBytes, uint32_t typeOfAlgo, uint8_t *output)
Padding function for sign.
Crypto_Uint32ToBigInt
void Crypto_Uint32ToBigInt(uint32_t *source, uint32_t sourceLengthInWords, uint32_t *dest)
Function to convert uint32_t to Bigint format.
Crypto_PSSSaltInfo::saltLenInBytes
uint32_t saltLenInBytes
Definition: crypto_util.h:192
source
uint8_t source
Definition: tisci_rm_ra.h:4
Crypto_ShaCallback
uint32_t(* Crypto_ShaCallback)(uint8_t *inputBuf, uint32_t inputLenBytes, uint8_t *digestBuf)
Callback used by Crypto_MGF1/Crypto_PSSPaddingForSign/Crypto_PSSVerify to compute a hash digest....
Definition: crypto_util.h:174
Crypto_Uint8ToUint32
void Crypto_Uint8ToUint32(const uint8_t *source, uint32_t sourceLengthInBytes, uint32_t *dest)
Function to convert uint8_t to uint32_t format.
Crypto_MGF1
uint32_t Crypto_MGF1(Crypto_ShaCallback shaCbFxn, uint32_t hashLenInBytes, uint8_t *seedBuf, uint32_t seedLenInBytes, uint8_t *mask, uint32_t maskLenInBytes)
MGF1 mask generation function, refer to RFC 8017 Appendix B.2.1 https://www.rfc-editor....
Crypto_PSSSaltInfo::msgHash
const uint8_t * msgHash
Definition: crypto_util.h:188