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 /**   Transport Layer Security (TLS)                                      */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 /* Determine if a C++ compiler is being used.  If so, ensure that standard
24    C is used to process the API information.  */
25 #ifdef __cplusplus
26 
27 /* Yes, C++ compiler is present.  Use standard C.  */
28 extern   "C" {
29 
30 #endif
31 
32 
33 #include "nx_crypto_phash.h"
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  COMPONENT DEFINITION                                   RELEASE        */
38 /*                                                                        */
39 /*    nx_crypto_tls_prf_sha256.h                          PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Timothy Stapko, Microsoft Corporation                               */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This file defines the TLS Pseudo-Random Function (PRF) as described */
48 /*    in RFC 5246. This PRF is used for default key generation in TLS     */
49 /*    version 1.2. Ciphersuites may choose their own PRF in TLS version   */
50 /*    1.2 as well.                                                        */
51 /*                                                                        */
52 /*  RELEASE HISTORY                                                       */
53 /*                                                                        */
54 /*    DATE              NAME                      DESCRIPTION             */
55 /*                                                                        */
56 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
57 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
58 /*                                            resulting in version 6.1    */
59 /*                                                                        */
60 /**************************************************************************/
61 
62 /* Define the control block structure for backward compatibility. */
63 #define NX_SECURE_TLS_PRF_SHA256                NX_CRYPTO_TLS_PRF_SHA256
64 
65 typedef struct NX_CRYPTO_TLS_PRF_SHA256_STRUCT
66 {
67     NX_CRYPTO_PHASH nx_secure_tls_prf_phash_info;
68     UCHAR nx_secure_tls_prf_label_seed_buffer[80]; /* phash_seed = label(13 bytes) || prf_seed(64 bytes) */
69     UCHAR nx_secure_tls_prf_temp_A_buffer[112]; /* The temp_A buffer needs to be large enough to holdthe lable(13 bytes) || prf_seed(64 bytes) || hash_size(32 bytes for SHA256) */
70     UCHAR nx_secure_tls_prf_temp_hmac_output_buffer[32]; /* The temp buffer for the output buffer of hmac(secret, A(i) + seed) */
71     UCHAR nx_secure_tls_prf_hmac_metadata_area[sizeof(NX_CRYPTO_SHA256_HMAC)]; /* metadata buffer for the hmac function */
72 } NX_CRYPTO_TLS_PRF_SHA256;
73 
74 UINT _nx_crypto_method_prf_sha_256_init(struct NX_CRYPTO_METHOD_STRUCT *method,
75                                         UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
76                                         VOID **handle,
77                                         VOID *crypto_metadata,
78                                         ULONG crypto_metadata_size);
79 
80 UINT _nx_crypto_method_prf_sha_256_cleanup(VOID *crypto_metadata);
81 
82 UINT _nx_crypto_method_prf_sha_256_operation(UINT op,      /* Encrypt, Decrypt, Authenticate */
83                                              VOID *handle, /* Crypto handler */
84                                              struct NX_CRYPTO_METHOD_STRUCT *method,
85                                              UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
86                                              UCHAR *input, ULONG input_length_in_byte,
87                                              UCHAR *iv_ptr,
88                                              UCHAR *output, ULONG output_length_in_byte,
89                                              VOID *crypto_metadata, ULONG crypto_metadata_size,
90                                              VOID *packet_ptr,
91                                              VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status));
92 
93 #ifdef __cplusplus
94 }
95 #endif
96