AM243x MCU+ SDK  08.01.00
crypto_sha.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018-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 
41 #ifndef CRYPTO_SHA_H_
42 #define CRYPTO_SHA_H_
43 
44 /* ========================================================================== */
45 /* Include Files */
46 /* ========================================================================== */
47 
48 #include <stdint.h>
49 #include <security/crypto.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /* ========================================================================== */
56 /* Macros & Typedefs */
57 /* ========================================================================== */
58 
65 #define CRYPTO_SHA_AUTHMODE_NULL (0U)
66 
67 #define CRYPTO_SHA_AUTHMODE_SHA1 (1U)
68 
69 #define CRYPTO_SHA_AUTHMODE_SHA2_224 (2U)
70 
71 #define CRYPTO_SHA_AUTHMODE_SHA2_256 (3U)
72 
73 #define CRYPTO_SHA_AUTHMODE_SHA2_384 (4U)
74 
75 #define CRYPTO_SHA_AUTHMODE_SHA2_512 (5U)
76 
77 #define CRYPTO_SHA_AUTHMODE_HMAC_SHA1 (6U)
78 
79 #define CRYPTO_SHA_AUTHMODE_HMAC_SHA2_224 (7U)
80 
81 #define CRYPTO_SHA_AUTHMODE_HMAC_SHA2_256 (8U)
82 
83 #define CRYPTO_SHA_AUTHMODE_HMAC_SHA2_384 (9U)
84 
85 #define CRYPTO_SHA_AUTHMODE_HMAC_SHA2_512 (10U)
86 
93 /* Key length for HMAC-SHA Process */
94 #define CRYPTO_HMAC_SHA_SW_MAX_KEYLEN_BYTES (128U)
95 
98 typedef void *Crypto_ShaHandle;
99 
101 typedef struct Crypto_ShaContext_s Crypto_ShaContext;
102 
103 /* ========================================================================== */
104 /* Structure Declarations */
105 /* ========================================================================== */
106 
110 typedef struct Crypto_ShaParams_s
111 {
112  uint32_t authMode;
114  uint32_t type;
118  uint32_t keySizeInBits;
121 
123 typedef int32_t (*Crypto_ShaOpenFxn)(Crypto_ShaContext *ctx, const Crypto_ShaParams *params);
124 typedef int32_t (*Crypto_ShaCloseFxn)(Crypto_ShaContext *ctx);
125 typedef int32_t (*Crypto_ShaStartFxn)(Crypto_ShaContext *ctx);
126 typedef int32_t (*Crypto_ShaUpdateFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen);
127 typedef int32_t (*Crypto_ShaFinishFxn)(Crypto_ShaContext *ctx, uint8_t *output);
128 typedef int32_t (*Crypto_ShaSingleShotFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output);
129 typedef int32_t (*Crypto_hmacShaFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output);
130 
132 typedef struct Crypto_ShaFxns_s
133 {
149 
152 {
157  void *drvHandle;
159  uintptr_t rsv[60U];
161 };
162 
169 typedef struct
170 {
174 
176 extern Crypto_ShaConfig gCryptoShaConfig[CRYPTO_NUM_TYPE];
177 
178 /* ========================================================================== */
179 /* Function Declarations */
180 /* ========================================================================== */
181 
191 
198 Crypto_ShaHandle Crypto_shaOpen(Crypto_ShaContext *ctx, const Crypto_ShaParams *params);
199 
209 
220 
234 int32_t Crypto_shaUpdate(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen);
235 
247 int32_t Crypto_shaFinish(Crypto_ShaHandle handle, uint8_t *output);
248 
269 int32_t Crypto_shaSingleShot(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output);
270 
288 int32_t Crypto_hmacSha(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output);
289 
290 /* ========================================================================== */
291 /* Static Function Definitions */
292 /* ========================================================================== */
293 
294 /* None */
295 
296 /* ========================================================================== */
297 /* Internal/Private Structure Declarations */
298 /* ========================================================================== */
299 
300 /* None */
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif /* CRYPTO_SHA_H_ */
307 
Crypto_shaStarts
int32_t Crypto_shaStarts(Crypto_ShaHandle handle)
This function starts a Secure Hash Algorithm (SHA ) checksum calculation.
Crypto_shaFinish
int32_t Crypto_shaFinish(Crypto_ShaHandle handle, uint8_t *output)
This function finishes the Secure Hash Algorithm (SHA ) operation, and writes the result to the outpu...
Crypto_shaUpdate
int32_t Crypto_shaUpdate(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen)
This function feeds an input buffer into an ongoing Secure Hash Algorithm (SHA ) checksum calculation...
Crypto_ShaFxns::updateFxn
Crypto_ShaUpdateFxn updateFxn
Definition: crypto_sha.h:140
Crypto_ShaFxns::startFxn
Crypto_ShaStartFxn startFxn
Definition: crypto_sha.h:138
Crypto_ShaFinishFxn
int32_t(* Crypto_ShaFinishFxn)(Crypto_ShaContext *ctx, uint8_t *output)
Definition: crypto_sha.h:127
Crypto_ShaSingleShotFxn
int32_t(* Crypto_ShaSingleShotFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output)
Definition: crypto_sha.h:128
Crypto_ShaParams::authMode
uint32_t authMode
Definition: crypto_sha.h:112
Crypto_hmacSha
int32_t Crypto_hmacSha(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output)
This function calculates the Keyed-Hash Message Authentication Code Secure Hash Algorithm (HMAC-SHA) ...
Crypto_ShaFxns::singleShotFxn
Crypto_ShaSingleShotFxn singleShotFxn
Definition: crypto_sha.h:144
Crypto_ShaContext_s::rsv
uintptr_t rsv[60U]
Definition: crypto_sha.h:159
Crypto_ShaConfig
CRYPTO SHA global configuration array.
Definition: crypto_sha.h:170
Crypto_ShaContext_s::params
Crypto_ShaParams params
Definition: crypto_sha.h:153
Crypto_ShaFxns::closeFxn
Crypto_ShaCloseFxn closeFxn
Definition: crypto_sha.h:136
Crypto_ShaUpdateFxn
int32_t(* Crypto_ShaUpdateFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen)
Definition: crypto_sha.h:126
Crypto_ShaParams
Parameters passed during Crypto_shaOpen()
Definition: crypto_sha.h:111
Crypto_ShaFxns
Driver implementation callbacks.
Definition: crypto_sha.h:133
Crypto_ShaContext_s::drvHandle
void * drvHandle
Definition: crypto_sha.h:157
Crypto_ShaCloseFxn
int32_t(* Crypto_ShaCloseFxn)(Crypto_ShaContext *ctx)
Definition: crypto_sha.h:124
CRYPTO_HMAC_SHA_SW_MAX_KEYLEN_BYTES
#define CRYPTO_HMAC_SHA_SW_MAX_KEYLEN_BYTES
Definition: crypto_sha.h:94
Crypto_ShaFxns::hmacShaFxn
Crypto_hmacShaFxn hmacShaFxn
Definition: crypto_sha.h:146
Crypto_ShaContext_s::fxns
Crypto_ShaFxns * fxns
Definition: crypto_sha.h:155
Crypto_shaSingleShot
int32_t Crypto_shaSingleShot(Crypto_ShaHandle handle, const uint8_t *input, uint32_t ilen, uint8_t *output)
This function calculates the Secure Hash Algorithm (SHA) checksum of a buffer.
gCryptoShaConfig
Crypto_ShaConfig gCryptoShaConfig[CRYPTO_NUM_TYPE]
Externally defined SHA driver configuration array.
Crypto_ShaConfig::fxns
Crypto_ShaFxns * fxns
Definition: crypto_sha.h:171
Crypto_ShaParams::keySizeInBits
uint32_t keySizeInBits
Definition: crypto_sha.h:118
Crypto_ShaHandle
void * Crypto_ShaHandle
Handle to the Crypto SHA driver returned by Crypto_shaOpen()
Definition: crypto_sha.h:98
Crypto_ShaParams::type
uint32_t type
Definition: crypto_sha.h:114
Crypto_shaOpen
Crypto_ShaHandle Crypto_shaOpen(Crypto_ShaContext *ctx, const Crypto_ShaParams *params)
This function gives the configuration based on type.
Crypto_ShaContext_s
CRYPTO SHA driver context.
Definition: crypto_sha.h:152
Crypto_ShaFxns::finishFxn
Crypto_ShaFinishFxn finishFxn
Definition: crypto_sha.h:142
Crypto_shaClose
int32_t Crypto_shaClose(Crypto_ShaHandle handle)
This function clears a Secure Hash Algorithm (SHA ) context.
Crypto_hmacShaFxn
int32_t(* Crypto_hmacShaFxn)(Crypto_ShaContext *ctx, const uint8_t *input, uint32_t ilen, uint8_t *output)
Definition: crypto_sha.h:129
Crypto_ShaFxns::openFxn
Crypto_ShaOpenFxn openFxn
Definition: crypto_sha.h:134
Crypto_ShaOpenFxn
int32_t(* Crypto_ShaOpenFxn)(Crypto_ShaContext *ctx, const Crypto_ShaParams *params)
callback functions declarations
Definition: crypto_sha.h:123
Crypto_ShaStartFxn
int32_t(* Crypto_ShaStartFxn)(Crypto_ShaContext *ctx)
Definition: crypto_sha.h:125
Crypto_ShaParams_init
void Crypto_ShaParams_init(Crypto_ShaParams *params)
Set default parameters in the Crypto_ShaParams structure.