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  */
219 #ifndef ti_drivers_SHA2__include
220 #define ti_drivers_SHA2__include
221 
222 #include <stdbool.h>
223 #include <stddef.h>
224 #include <stdint.h>
225 
226 #ifdef __cplusplus
227 extern "C" {
228 #endif
229 
242 #define SHA2_STATUS_RESERVED (-32)
243 
250 #define SHA2_STATUS_SUCCESS (0)
251 
258 #define SHA2_STATUS_ERROR (-1)
259 
268 #define SHA2_STATUS_RESOURCE_UNAVAILABLE (-2)
269 
273 #define SHA2_STATUS_CANCELED (-3)
274 
296 typedef enum {
312 
316 typedef enum {
321 } SHA2_HashType;
322 
326 typedef enum {
332 
346 typedef enum {
352 
364 typedef struct {
366  void *object;
367 
369  void const *hwAttrs;
370 } SHA2_Config;
371 
376 
387 typedef void (*SHA2_CallbackFxn) (SHA2_Handle handle, int_fast16_t returnStatus);
388 
397 typedef struct {
403  uint32_t timeout;
406 } SHA2_Params;
407 
416 extern const SHA2_Config SHA2_config[];
417 
425 extern const uint_least8_t SHA2_count;
426 
432 extern const SHA2_Params SHA2_defaultParams;
433 
434 
443 void SHA2_init(void);
444 
457 void SHA2_Params_init(SHA2_Params *params);
458 
475 SHA2_Handle SHA2_open(uint_least8_t index, const SHA2_Params *params);
476 
486 void SHA2_close(SHA2_Handle handle);
487 
511 int_fast16_t SHA2_addData(SHA2_Handle handle, const void* data, size_t length);
512 
539 int_fast16_t SHA2_hashData(SHA2_Handle handle, const void* data, size_t size, void *digest);
540 
560 int_fast16_t SHA2_finalize(SHA2_Handle handle, void *digest);
561 
573 void SHA2_reset(SHA2_Handle handle);
574 
587 int_fast16_t SHA2_cancelOperation(SHA2_Handle handle);
588 
609 int_fast16_t SHA2_setHashType(SHA2_Handle handle, SHA2_HashType type);
610 
611 
612 #ifdef __cplusplus
613 }
614 #endif
615 
616 #endif /* ti_drivers_SHA2__include */
Definition: SHA2.h:330
SHA2_Config * SHA2_Handle
A handle that is returned from an SHA2_open() call.
Definition: SHA2.h:375
SHA2_HashType hashType
Definition: SHA2.h:398
Definition: SHA2.h:328
const SHA2_Config SHA2_config[]
Global SHA2 configuration struct.
void SHA2_reset(SHA2_Handle handle)
Clears internal buffers and aborts an ongoing SHA2 operation.
Definition: SHA2.h:347
const uint_least8_t SHA2_count
Global SHA2 configuration count.
Definition: SHA2.h:297
int_fast16_t SHA2_hashData(SHA2_Handle handle, const void *data, size_t size, void *digest)
Hashes a segment of data with a size in bytes and writes the resulting hash to digest.
const SHA2_Params SHA2_defaultParams
Default SHA2_Params structure.
Definition: SHA2.h:318
Definition: SHA2.h:329
SHA2 Global configuration.
Definition: SHA2.h:364
SHA2_ReturnBehavior returnBehavior
Definition: SHA2.h:401
void SHA2_init(void)
Initializes the SHA2 driver module.
Definition: SHA2.h:303
int_fast16_t SHA2_addData(SHA2_Handle handle, const void *data, size_t length)
Adds a segment of data with a length in bytes to the cryptographic hash.
int_fast16_t SHA2_setHashType(SHA2_Handle handle, SHA2_HashType type)
Selects a new hash algorithm type.
Definition: SHA2.h:307
Definition: SHA2.h:349
void SHA2_close(SHA2_Handle handle)
Closes a SHA2 peripheral specified by handle.
Definition: SHA2.h:327
uint32_t timeout
Definition: SHA2.h:403
SHA2_Handle SHA2_open(uint_least8_t index, const SHA2_Params *params)
Initializes a SHA2 driver instance and returns a handle.
SHA2_ReturnBehavior
The way in which SHA2 function calls return after performing an operation.
Definition: SHA2.h:296
SHA2_HashType
Enum for the hash types supported by the driver.
Definition: SHA2.h:316
Definition: SHA2.h:348
SHA2_DigestLengthBytes
Enum for the hash digest lengths in bytes supported by the driver.
Definition: SHA2.h:326
int_fast16_t SHA2_finalize(SHA2_Handle handle, void *digest)
Finishes hash a operation and writes the result to digest.
Definition: SHA2.h:319
void * object
Definition: SHA2.h:366
Definition: SHA2.h:320
int_fast16_t SHA2_cancelOperation(SHA2_Handle handle)
Aborts an ongoing SHA2 operation and clears internal buffers.
Definition: SHA2.h:350
void const * hwAttrs
Definition: SHA2.h:369
SHA2_CallbackFxn callbackFxn
Definition: SHA2.h:402
SHA2 Parameters.
Definition: SHA2.h:397
void(* SHA2_CallbackFxn)(SHA2_Handle handle, int_fast16_t returnStatus)
The definition of a callback function used by the SHA2 driver when used in SHA2_RETURN_BEHAVIOR_CALLB...
Definition: SHA2.h:387
void SHA2_Params_init(SHA2_Params *params)
Initializes params with default values.
Definition: SHA2.h:317
SHA2_BlockSizeBytes
Enum for the block sizes of the algorithms.
Definition: SHA2.h:346
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale