SHA2.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018, 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  */
242 #ifndef ti_drivers_SHA2__include
243 #define ti_drivers_SHA2__include
244 
245 #ifdef __cplusplus
246 extern "C" {
247 #endif
248 
249 #include <stdbool.h>
250 #include <stddef.h>
251 #include <stdint.h>
252 
254 
272 #define SHA2_CMD_RESERVED (32)
273 
286 #define SHA2_STATUS_RESERVED (-32)
287 
301 #define SHA2_STATUS_SUCCESS (0)
302 
309 #define SHA2_STATUS_ERROR (-1)
310 
318 #define SHA2_STATUS_UNDEFINEDCMD (-2)
319 
328 #define SHA2_STATUS_RESOURCE_UNAVAILABLE (-3)
329 
330 
341 /* Add SHA2_CMD_<commands> here */
342 
350 typedef struct SHA2_Config_ *SHA2_Handle;
351 
373 typedef enum SHA2_ReturnBehavior_ {
389 
393 typedef enum SHA2_HashSize_ {
398 } SHA2_HashSize;
399 
409 
423 typedef enum SHA2_BlockSizeBytes_ {
429 
434 typedef struct SHA2_OperationOneStep_ {
438  size_t totalLength;
439  const uint8_t *message;
440  uint8_t *digest;
445 
450 typedef struct SHA2_OperationStartHash_ {
452  size_t length;
457  const uint8_t *message;
468 
469 
470 
477  size_t length;
482  const uint8_t *message;
497 
504  size_t segmentLength;
507  size_t totalLength;
511  const uint8_t *message;
512  const uint8_t *intermediateDigest;
525  uint8_t *finalDigest;
531 
535 typedef union SHA2_Operation_ {
541 
545 typedef enum SHA2_OperationType_ {
551 
563 typedef struct SHA2_Config_ {
565  void *object;
566 
568  void const *hwAttrs;
569 } SHA2_Config;
570 
590 typedef void (*SHA2_CallbackFxn) (SHA2_Handle handle,
591  int_fast16_t returnStatus,
592  SHA2_Operation operation,
593  SHA2_OperationType operationType);
594 
603 typedef struct SHA2_Params_ {
606  uint32_t timeout;
609  void *custom;
612 } SHA2_Params;
613 
619 extern const SHA2_Params SHA2_defaultParams;
620 
629 void SHA2_init(void);
630 
643 void SHA2_Params_init(SHA2_Params *params);
644 
662 SHA2_Handle SHA2_open(uint_least8_t index, SHA2_Params *params);
663 
673 void SHA2_close(SHA2_Handle handle);
674 
712 int_fast16_t SHA2_control(SHA2_Handle handle, uint32_t cmd, void *args);
713 
723 
733 
743 
753 
768 int_fast16_t SHA2_startHash(SHA2_Handle handle, SHA2_OperationStartHash *operation);
769 
790 int_fast16_t SHA2_processHash(SHA2_Handle handle, SHA2_OperationProcessHash *operation);
791 
809 int_fast16_t SHA2_finishHash(SHA2_Handle handle, SHA2_OperationFinishHash *operation);
810 
824 int_fast16_t SHA2_oneStepHash(SHA2_Handle handle, SHA2_OperationOneStepHash *operation);
825 
826 #ifdef __cplusplus
827 }
828 #endif
829 
830 #endif /* ti_drivers_SHA2__include */
Definition: SHA2.h:405
The CryptoKey type is an opaque representation of a cryptographic key.
SHA2_OperationOneStepHash * oneStepHash
Definition: SHA2.h:539
Definition: SHA2.h:427
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:568
size_t segmentLength
Definition: SHA2.h:504
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:590
SHA2_DigestLengthBytes_
Enum for the hash digest lengths in bytes supported by the driver.
Definition: SHA2.h:403
Definition: SHA2.h:380
const SHA2_Params SHA2_defaultParams
Default SHA2_Params structure.
void * custom
Definition: SHA2.h:609
SHA2_OperationFinishHash * finishHash
Definition: SHA2.h:538
Definition: SHA2.h:384
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:502
SHA2_CallbackFxn callbackFxn
Definition: SHA2.h:605
SHA2_BlockSizeBytes_
Enum for the block sizes of the algorithms.
Definition: SHA2.h:423
const uint8_t * message
Definition: SHA2.h:439
void SHA2_OperationFinishHash_init(SHA2_OperationFinishHash *operation)
Function to initialize a SHA2_OperationFinishHash struct to its defaults.
uint8_t * intermediateDigest
Definition: SHA2.h:483
Definition: SHA2.h:426
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:373
size_t length
Definition: SHA2.h:477
void SHA2_close(SHA2_Handle handle)
Function to close a SHA2 peripheral specified by the SHA2 handle.
Definition: SHA2.h:549
Definition: SHA2.h:394
Definition: SHA2.h:406
enum SHA2_HashSize_ SHA2_HashSize
Enum for the hash digest sizes supported by the driver.
const uint8_t * message
Definition: SHA2.h:482
uint8_t * intermediateDigest
Definition: SHA2.h:458
Definition: SHA2.h:407
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:350
SHA2_HashSize hashSize
Definition: SHA2.h:435
SHA2_OperationProcessHash * processHash
Definition: SHA2.h:537
Definition: SHA2.h:548
size_t length
Definition: SHA2.h:452
size_t totalLength
Definition: SHA2.h:438
Definition: SHA2.h:374
enum SHA2_BlockSizeBytes_ SHA2_BlockSizeBytes
Enum for the block sizes of the algorithms.
int_fast16_t SHA2_startHash(SHA2_Handle handle, SHA2_OperationStartHash *operation)
Sets up a SHA2 hash and hashes the first message segment.
Definition: SHA2.h:397
Definition: SHA2.h:424
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:565
uint8_t * finalDigest
Definition: SHA2.h:525
SHA2_HashSize hashSize
Definition: SHA2.h:503
Definition: SHA2.h:546
void SHA2_OperationProcessHash_init(SHA2_OperationProcessHash *operation)
Function to initialize a SHA2_OperationProcessHash struct to its defaults.
Definition: SHA2.h:396
struct SHA2_OperationProcessHash_ SHA2_OperationProcessHash
Struct containing the parameters required to continue hashing a message.
const uint8_t * intermediateDigest
Definition: SHA2.h:512
Union containing pointers to all supported operation structs.
Definition: SHA2.h:535
struct SHA2_OperationOneStep_ SHA2_OperationOneStepHash
Struct containing the parameters required to hash a message in one go.
SHA2_OperationStartHash * startHash
Definition: SHA2.h:536
int_fast16_t SHA2_processHash(SHA2_Handle handle, SHA2_OperationProcessHash *operation)
Performs the SHA2 hash on a segment of the message.
SHA2_ReturnBehavior returnBehavior
Definition: SHA2.h:604
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:450
enum SHA2_OperationType_ SHA2_OperationType
Enum for the operation types supported by the driver.
uint8_t * digest
Definition: SHA2.h:440
Definition: SHA2.h:547
const uint8_t * message
Definition: SHA2.h:457
Definition: SHA2.h:425
Definition: SHA2.h:395
size_t totalLength
Definition: SHA2.h:507
Struct containing the parameters required to continue hashing a message.
Definition: SHA2.h:475
SHA2_HashSize hashSize
Definition: SHA2.h:451
Struct containing the parameters required to hash a message in one go.
Definition: SHA2.h:434
void SHA2_Params_init(SHA2_Params *params)
Function to initialize the SHA2_Params struct to its defaults.
uint32_t timeout
Definition: SHA2.h:606
SHA2_OperationType_
Enum for the operation types supported by the driver.
Definition: SHA2.h:545
SHA2 Global configuration.
Definition: SHA2.h:563
Definition: SHA2.h:404
struct SHA2_Params_ SHA2_Params
SHA2 Parameters.
SHA2_HashSize_
Enum for the hash digest sizes supported by the driver.
Definition: SHA2.h:393
SHA2 Parameters.
Definition: SHA2.h:603
const uint8_t * message
Definition: SHA2.h:511
SHA2_HashSize hashSize
Definition: SHA2.h:476
Copyright 2018, Texas Instruments Incorporated