ANSIX936KDF.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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  */
32 /*!****************************************************************************
33  * @file ANSIX936KDF.h
34  *
35  * @brief ANSIX936KDF driver header
36  *
37  * @anchor ti_drivers_ANSIX936KDF_Overview
38  * # Overview #
39  *
40  * The ANSI X9.63 Key Derivation Function (KDF) driver utilizes the SHA-256 hash
41  * function to derive a key from a shared secret value and optional shared
42  * info. See ANSI X9.63-2011 or SEC-1 v2.0 standard for more information.
43  *
44  * @anchor ti_drivers_ANSIX936KDF_Usage
45  * # Usage #
46  *
47  * Before starting a ANSIX936KDF operation, the application must do the following:
48  * - Call #ANSIX936KDF_init() to initialize the driver.
49  * - Call #ANSIX936KDF_Params_init() to initialize the ANSIX936KDF_Params to default values.
50  * - Modify the #ANSIX936KDF_Params as desired.
51  * - Call #ANSIX936KDF_open() to open an instance of the driver.
52  *
53  * @anchor ti_drivers_ANSIX936KDF_Synopsis
54  * # Synopsis
55  *
56  * @anchor ti_drivers_ANSIX936KDF_Synopsis_Code
57  * @code
58  *
59  * // Import ANSIX936KDF Driver definitions
60  * #include <ti/drivers/ANSIX936KDF.h>
61  *
62  * // Import driver configuration
63  * #include "ti_drivers_config.h"
64  *
65  * // Initialize driver
66  * ANSIX936KDF_init();
67  *
68  * // Open driver instance
69  * handle = ANSIX936KDF_open(CONFIG_ANSIX936KDF_0, NULL);
70  *
71  * // Perform key derivation
72  * result = ANSIX936KDF_deriveKey(handle, input, sizeof(input), sharedInfo,
73  * sizeof(sharedInfo), output, sizeof(output));
74  *
75  * // Close driver instance
76  * ANSIX936KDF_close(handle);
77  * @endcode
78  *
79  * @anchor ti_drivers_ANSIX936KDF_Example
80  * # Example #
81  *
82  * The #ANSIX936KDF_deriveKey() function performs a key derivation operation in
83  * a single call.
84  *
85  * After a ANSIX936KDF operation completes, the application may either start
86  * another operation or close the driver by calling #ANSIX936KDF_close().
87  *
88  * @code
89  * ANSIX936KDF_Params params;
90  * ANSIX936KDF_Handle handle;
91  * int_fast16_t result;
92  * uint8_t sharedInfo[] = {0x75, 0xee, 0xf8, 0x1a, 0xa3, 0x04, 0x1e, 0x33,
93  * 0xb8, 0x09, 0x71, 0x20, 0x3d, 0x2c, 0x0c, 0x52};
94  * uint8_t input[] = {0x22, 0x51, 0x8b, 0x10, 0xe7, 0x0f, 0x2a, 0x3f, 0x24, 0x38, 0x10, 0xae,
95  * 0x32, 0x54, 0x13, 0x9e, 0xfb, 0xee, 0x04, 0xaa, 0x57, 0xc7, 0xaf, 0x7d};
96  * uint8_t output[32] = {0};
97  *
98  * ANSIX936KDF_init();
99  *
100  * ANSIX936KDF_Params_init(&params);
101  * params.returnBehavior = ANSIX936KDF_RETURN_BEHAVIOR_POLLING;
102  *
103  * handle = ANSIX936KDF_open(CONFIG_ANSIX936KDF_0, &params);
104  * assert(handle != NULL);
105  *
106  * result = ANSIX936KDF_deriveKey(handle, input, sizeof(input), sharedInfo,
107  * sizeof(sharedInfo), output, sizeof(output));
108  * assert(result == ANSIX936KDF_STATUS_SUCCESS);
109  *
110  * ANSIX936KDF_close(handle);
111  * @endcode
112  */
113 
114 #ifndef ti_drivers_ANSIX936KDF__include
115 #define ti_drivers_ANSIX936KDF__include
116 
117 #include <stddef.h>
118 #include <stdint.h>
119 
120 #include <ti/drivers/SHA2.h>
121 
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
138 #define ANSIX936KDF_STATUS_RESERVED ((int_fast16_t)-32)
139 
146 #define ANSIX936KDF_STATUS_SUCCESS ((int_fast16_t)0)
147 
154 #define ANSIX936KDF_STATUS_ERROR ((int_fast16_t)-1)
155 
165 #define ANSIX936KDF_STATUS_RESOURCE_UNAVAILABLE ((int_fast16_t)-2)
166 
188 typedef enum
189 {
195 
202 
214 typedef struct
215 {
217  void *object;
218 
220  void const *hwAttrs;
222 
227 
236 typedef struct
237 {
238  ANSIX936KDF_ReturnBehavior returnBehavior;
239  uint32_t timeout;
243 
253 
261 extern const uint_least8_t ANSIX936KDF_count;
262 
269 
278 void ANSIX936KDF_init(void);
279 
291 
309 ANSIX936KDF_Handle ANSIX936KDF_open(uint_least8_t index, const ANSIX936KDF_Params *params);
310 
320 void ANSIX936KDF_close(ANSIX936KDF_Handle handle);
321 
354 int_fast16_t ANSIX936KDF_deriveKey(ANSIX936KDF_Handle handle,
355  const void *input,
356  size_t inputLen,
357  const void *sharedInfo,
358  size_t sharedInfoLen,
359  void *output,
360  size_t outputLen);
361 
385 ANSIX936KDF_Handle ANSIX936KDF_construct(ANSIX936KDF_Config *config, const ANSIX936KDF_Params *params);
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 
391 #endif /* ti_drivers_ANSIX936KDF__include */
ANSIX936KDF_ReturnBehavior returnBehavior
Definition: ANSIX936KDF.h:238
ADC_Params params
Definition: Driver_Init.h:11
const ANSIX936KDF_Config ANSIX936KDF_config[]
Global ANSIX936KDF configuration struct.
ANSIX936KDF Parameters.
Definition: ANSIX936KDF.h:236
void ANSIX936KDF_Params_init(ANSIX936KDF_Params *params)
Initializes params with default values.
const uint_least8_t ANSIX936KDF_count
Global ANSIX936KDF configuration count.
ANSIX936KDF_ReturnBehavior
The way in which ANSIX936KDF function calls return after performing an operation. ...
Definition: ANSIX936KDF.h:188
void const * hwAttrs
Definition: ANSIX936KDF.h:220
int_fast16_t ANSIX936KDF_deriveKey(ANSIX936KDF_Handle handle, const void *input, size_t inputLen, const void *sharedInfo, size_t sharedInfoLen, void *output, size_t outputLen)
Derives a key with the SHA-256 hash function.
void * object
Definition: ANSIX936KDF.h:217
Definition: ANSIX936KDF.h:200
const ANSIX936KDF_Params ANSIX936KDF_defaultParams
Default ANSIX936KDF_Params structure.
Definition: SHA2.h:480
Definition: SHA2.h:484
Definition: ANSIX936KDF.h:194
uint32_t timeout
Definition: ANSIX936KDF.h:239
void ANSIX936KDF_close(ANSIX936KDF_Handle handle)
Closes a ANSIX936KDF peripheral specified by handle.
ANSIX936KDF_Handle ANSIX936KDF_open(uint_least8_t index, const ANSIX936KDF_Params *params)
Initializes a ANSIX936KDF driver instance and returns a handle.
ANSIX936KDF_Handle ANSIX936KDF_construct(ANSIX936KDF_Config *config, const ANSIX936KDF_Params *params)
Constructs a new ANSIX936KDF object.
SHA2 driver header.
ANSIX936KDF Global configuration.
Definition: ANSIX936KDF.h:214
ANSIX936KDF_Config * ANSIX936KDF_Handle
A handle that is returned from an ANSIX936KDF_open() call.
Definition: ANSIX936KDF.h:226
void ANSIX936KDF_init(void)
Initializes the ANSIX936KDF driver module.
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale