1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Crypto Component                                                 */
17 /**                                                                       */
18 /**   HMAC SHA256 Digest Algorithm (SHA256)                               */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    nx_crypto_hmac_sha1.h                                PORTABLE C     */
29 /*                                                           6.1          */
30 /*                                                                        */
31 /*  AUTHOR                                                                */
32 /*                                                                        */
33 /*    Timothy Stapko, Microsoft Corporation                               */
34 /*                                                                        */
35 /*  DESCRIPTION                                                           */
36 /*                                                                        */
37 /*    This file defines the NetX HMAC SHA256 algorithm, derived from      */
38 /*    RFC2202. From a user-specified number of input bytes and key, this  */
39 /*    produces a 32-byte (256-bit) digest or sometimes called a hash      */
40 /*    value. The resulting digest is returned in a 32-byte array supplied */
41 /*    by the caller.                                                      */
42 /*                                                                        */
43 /*    It is assumed that nx_api.h and nx_port.h have already been         */
44 /*    included.                                                           */
45 /*                                                                        */
46 /*  RELEASE HISTORY                                                       */
47 /*                                                                        */
48 /*    DATE              NAME                      DESCRIPTION             */
49 /*                                                                        */
50 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
51 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
52 /*                                            resulting in version 6.1    */
53 /*                                                                        */
54 /**************************************************************************/
55 
56 #ifndef  NX_HMAC_SHA2_H
57 #define  NX_HMAC_SHA2_H
58 
59 /* Determine if a C++ compiler is being used.  If so, ensure that standard
60    C is used to process the API information.  */
61 #ifdef __cplusplus
62 
63 /* Yes, C++ compiler is present.  Use standard C.  */
64 extern   "C" {
65 
66 #endif
67 
68 #include "nx_crypto.h"
69 #include "nx_crypto_sha2.h"
70 #include "nx_crypto_hmac.h"
71 
72 #define NX_CRYPTO_HMAC_SHA256_KEY_LEN_IN_BITS      256
73 
74 #define NX_CRYPTO_HMAC_SHA224_ICV_FULL_LEN_IN_BITS NX_CRYPTO_SHA224_ICV_LEN_IN_BITS
75 #define NX_CRYPTO_HMAC_SHA256_ICV_FULL_LEN_IN_BITS NX_CRYPTO_SHA256_ICV_LEN_IN_BITS
76 
77 /* Define the control block structure for backward compatibility. */
78 #define NX_SHA256_HMAC                          NX_CRYPTO_SHA256_HMAC
79 
80 typedef struct NX_CRYPTO_SHA256_HMAC_STRUCT
81 {
82     NX_CRYPTO_SHA256    nx_sha256_hmac_context;
83     NX_CRYPTO_HMAC      nx_sha256_hmac_metadata;
84 } NX_CRYPTO_SHA256_HMAC;
85 
86 /* Define the function prototypes for HMAC SHA256.  */
87 
88 UINT _nx_crypto_method_hmac_sha256_init(struct  NX_CRYPTO_METHOD_STRUCT *method,
89                                         UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
90                                         VOID  **handle,
91                                         VOID  *crypto_metadata,
92                                         ULONG crypto_metadata_size);
93 
94 UINT _nx_crypto_method_hmac_sha256_cleanup(VOID *crypto_metadata);
95 
96 UINT _nx_crypto_method_hmac_sha256_operation(UINT op,      /* Encrypt, Decrypt, Authenticate */
97                                              VOID *handle, /* Crypto handler */
98                                              struct NX_CRYPTO_METHOD_STRUCT *method,
99                                              UCHAR *key,
100                                              NX_CRYPTO_KEY_SIZE key_size_in_bits,
101                                              UCHAR *input,
102                                              ULONG input_length_in_byte,
103                                              UCHAR *iv_ptr,
104                                              UCHAR *output,
105                                              ULONG output_length_in_byte,
106                                              VOID *crypto_metadata,
107                                              ULONG crypto_metadata_size,
108                                              VOID *packet_ptr,
109                                              VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status));
110 
111 #endif
112 
113 #ifdef __cplusplus
114 }
115 #endif
116