SHA2.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Texas Instruments Incorporated
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
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
237 #ifndef ti_drivers_SHA2__include
238 #define ti_drivers_SHA2__include
239 
240 #ifdef __cplusplus
241 extern "C" {
242 #endif
243 
244 #include <stdbool.h>
245 #include <stddef.h>
246 #include <stdint.h>
247 
249 
267 #define SHA2_CMD_RESERVED (32)
268 
281 #define SHA2_STATUS_RESERVED (-32)
282 
296 #define SHA2_STATUS_SUCCESS (0)
297 
304 #define SHA2_STATUS_ERROR (-1)
305 
313 #define SHA2_STATUS_UNDEFINEDCMD (-2)
314 
323 #define SHA2_STATUS_RESOURCE_UNAVAILABLE (-3)
324 
325 
336 /* Add SHA2_CMD_<commands> here */
337 
345 typedef struct SHA2_Config_ *SHA2_Handle;
346 
368 typedef enum SHA2_ReturnBehavior_ {
384 
388 typedef enum SHA2_HashSize_ {
393 } SHA2_HashSize;
394 
404 
409 typedef struct SHA2_OperationOneStep_ {
413  size_t totalLength;
414  const uint8_t *message;
415  uint8_t *digest;
420 
425 typedef struct SHA2_OperationStartHash_ {
427  size_t length;
432  const uint8_t *message;
442 
443 
444 
451  size_t length;
456  const uint8_t *message;
469 
476  size_t segmentLength;
479  size_t totalLength;
483  const uint8_t *message;
484  const uint8_t *intermediateDigest;
495  uint8_t *finalDigest;
501 
505 typedef union SHA2_Operation_ {
511 
515 typedef enum SHA2_OperationType_ {
521 
533 typedef struct SHA2_Config_ {
535  void *object;
536 
538  void const *hwAttrs;
539 } SHA2_Config;
540 
559 typedef void (*SHA2_CallbackFxn) (SHA2_Handle handle,
560  int_fast16_t returnStatus,
561  SHA2_Operation operation,
562  SHA2_OperationType operationType);
563 
572 typedef struct SHA2_Params_ {
575  uint32_t timeout;
578  void *custom;
581 } SHA2_Params;
582 
588 extern const SHA2_Params SHA2_defaultParams;
589 
598 void SHA2_init(void);
599 
612 void SHA2_Params_init(SHA2_Params *params);
613 
631 SHA2_Handle SHA2_open(uint_least8_t index, SHA2_Params *params);
632 
642 void SHA2_close(SHA2_Handle handle);
643 
681 int_fast16_t SHA2_control(SHA2_Handle handle, uint32_t cmd, void *args);
682 
692 
702 
712 
722 
737 int_fast16_t SHA2_startHash(SHA2_Handle handle, SHA2_OperationStartHash *operation);
738 
759 int_fast16_t SHA2_processHash(SHA2_Handle handle, SHA2_OperationProcessHash *operation);
760 
778 int_fast16_t SHA2_finishHash(SHA2_Handle handle, SHA2_OperationFinishHash *operation);
779 
793 int_fast16_t SHA2_oneStepHash(SHA2_Handle handle, SHA2_OperationOneStepHash *operation);
794 
795 #ifdef __cplusplus
796 }
797 #endif
798 
799 #endif /* ti_drivers_SHA2__include */
Definition: SHA2.h:400
The CryptoKey type is an opaque representation of a cryptographic key.
SHA2_OperationOneStepHash * oneStepHash
Definition: SHA2.h:509
int_fast16_t SHA2_finishHash(SHA2_Handle handle, SHA2_OperationFinishHash *operation)
Completes final block(s) of hash and returns a final output hash value.
void const * hwAttrs
Definition: SHA2.h:538
size_t segmentLength
Definition: SHA2.h:476
void SHA2_OperationOneStepHash_init(SHA2_OperationOneStepHash *operation)
Function to initialize a SHA2_OperationOneStepHash struct to its defaults.
SHA2_Handle SHA2_open(uint_least8_t index, SHA2_Params *params)
This function opens a given SHA2 peripheral.
void(* SHA2_CallbackFxn)(SHA2_Handle handle, int_fast16_t returnStatus, SHA2_Operation operation, SHA2_OperationType operationType)
The definition of a callback function used by the SHA2 driver when used in SHA2_RETURN_BEHAVIOR_CALLB...
Definition: SHA2.h:559
SHA2_DigestLengthBytes_
Enum for the hash digest lengths in bytes supported by the driver.
Definition: SHA2.h:398
Definition: SHA2.h:375
const SHA2_Params SHA2_defaultParams
Default SHA2_Params structure.
void * custom
Definition: SHA2.h:578
SHA2_OperationFinishHash * finishHash
Definition: SHA2.h:508
Definition: SHA2.h:379
void SHA2_init(void)
This function initializes the SHA2 module.
void SHA2_OperationStartHash_init(SHA2_OperationStartHash *operation)
Function to initialize a SHA2_OperationStartHash struct to its defaults.
int_fast16_t SHA2_control(SHA2_Handle handle, uint32_t cmd, void *args)
Function performs implementation specific features on a given SHA2_Handle.
enum SHA2_DigestLengthBytes_ SHA2_DigestLengthBytes
Enum for the hash digest lengths in bytes supported by the driver.
Struct containing the parameters required to process the last blocks of a message and finalize the ha...
Definition: SHA2.h:474
SHA2_CallbackFxn callbackFxn
Definition: SHA2.h:574
const uint8_t * message
Definition: SHA2.h:414
void SHA2_OperationFinishHash_init(SHA2_OperationFinishHash *operation)
Function to initialize a SHA2_OperationFinishHash struct to its defaults.
uint8_t * intermediateDigest
Definition: SHA2.h:457
struct SHA2_Config_ SHA2_Config
SHA2 Global configuration.
SHA2_ReturnBehavior_
The way in which SHA2 function calls return after performing an operation.
Definition: SHA2.h:368
size_t length
Definition: SHA2.h:451
void SHA2_close(SHA2_Handle handle)
Function to close a SHA2 peripheral specified by the SHA2 handle.
Definition: SHA2.h:519
Definition: SHA2.h:389
Definition: SHA2.h:401
enum SHA2_HashSize_ SHA2_HashSize
Enum for the hash digest sizes supported by the driver.
const uint8_t * message
Definition: SHA2.h:456
uint8_t * intermediateDigest
Definition: SHA2.h:433
Definition: SHA2.h:402
struct SHA2_OperationStartHash_ SHA2_OperationStartHash
Struct containing the parameters required to start hashing a message.
union SHA2_Operation_ SHA2_Operation
Union containing pointers to all supported operation structs.
struct SHA2_Config_ * SHA2_Handle
A handle that is returned from an SHA2_open() call.
Definition: SHA2.h:345
SHA2_HashSize hashSize
Definition: SHA2.h:410
SHA2_OperationProcessHash * processHash
Definition: SHA2.h:507
Definition: SHA2.h:518
size_t length
Definition: SHA2.h:427
size_t totalLength
Definition: SHA2.h:413
Definition: SHA2.h:369
int_fast16_t SHA2_startHash(SHA2_Handle handle, SHA2_OperationStartHash *operation)
Sets up a SHA2 hash.
Definition: SHA2.h:392
struct SHA2_OperationFinishlHash_ SHA2_OperationFinishHash
Struct containing the parameters required to process the last blocks of a message and finalize the ha...
enum SHA2_ReturnBehavior_ SHA2_ReturnBehavior
The way in which SHA2 function calls return after performing an operation.
void * object
Definition: SHA2.h:535
uint8_t * finalDigest
Definition: SHA2.h:495
SHA2_HashSize hashSize
Definition: SHA2.h:475
Definition: SHA2.h:516
void SHA2_OperationProcessHash_init(SHA2_OperationProcessHash *operation)
Function to initialize a SHA2_OperationProcessHash struct to its defaults.
Definition: SHA2.h:391
struct SHA2_OperationProcessHash_ SHA2_OperationProcessHash
Struct containing the parameters required to continue hashing a message.
const uint8_t * intermediateDigest
Definition: SHA2.h:484
Union containing pointers to all supported operation structs.
Definition: SHA2.h:505
struct SHA2_OperationOneStep_ SHA2_OperationOneStepHash
Struct containing the parameters required to hash a message in one go.
SHA2_OperationStartHash * startHash
Definition: SHA2.h:506
int_fast16_t SHA2_processHash(SHA2_Handle handle, SHA2_OperationProcessHash *operation)
Performs the SHA2 hash on a part of the message.
SHA2_ReturnBehavior returnBehavior
Definition: SHA2.h:573
int_fast16_t SHA2_oneStepHash(SHA2_Handle handle, SHA2_OperationOneStepHash *operation)
Hashes an input message.
Struct containing the parameters required to start hashing a message.
Definition: SHA2.h:425
enum SHA2_OperationType_ SHA2_OperationType
Enum for the operation types supported by the driver.
uint8_t * digest
Definition: SHA2.h:415
Definition: SHA2.h:517
const uint8_t * message
Definition: SHA2.h:432
Definition: SHA2.h:390
size_t totalLength
Definition: SHA2.h:479
Struct containing the parameters required to continue hashing a message.
Definition: SHA2.h:449
SHA2_HashSize hashSize
Definition: SHA2.h:426
Struct containing the parameters required to hash a message in one go.
Definition: SHA2.h:409
void SHA2_Params_init(SHA2_Params *params)
Function to initialize the SHA2_Params struct to its defaults.
uint32_t timeout
Definition: SHA2.h:575
SHA2_OperationType_
Enum for the operation types supported by the driver.
Definition: SHA2.h:515
SHA2 Global configuration.
Definition: SHA2.h:533
Definition: SHA2.h:399
struct SHA2_Params_ SHA2_Params
SHA2 Parameters.
SHA2_HashSize_
Enum for the hash digest sizes supported by the driver.
Definition: SHA2.h:388
SHA2 Parameters.
Definition: SHA2.h:572
const uint8_t * message
Definition: SHA2.h:483
SHA2_HashSize hashSize
Definition: SHA2.h:450
Copyright 2017, Texas Instruments Incorporated