1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Crypto Component                                                 */
16 /**                                                                       */
17 /**   Transport Layer Security (TLS)                                      */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /* Determine if a C++ compiler is being used.  If so, ensure that standard
23    C is used to process the API information.  */
24 #ifdef __cplusplus
25 
26 /* Yes, C++ compiler is present.  Use standard C.  */
27 extern   "C" {
28 
29 #endif
30 
31 #include "nx_crypto_phash.h"
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  COMPONENT DEFINITION                                   RELEASE        */
36 /*                                                                        */
37 /*    nx_crypto_tls_prf_sha256.h                          PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This file defines the TLS Pseudo-Random Function (PRF) as described */
46 /*    in RFC 5246. This PRF is used for default key generation in TLS     */
47 /*    version 1.2. Ciphersuites may choose their own PRF in TLS version   */
48 /*    1.2 as well.                                                        */
49 /*                                                                        */
50 /*  RELEASE HISTORY                                                       */
51 /*                                                                        */
52 /*    DATE              NAME                      DESCRIPTION             */
53 /*                                                                        */
54 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
55 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
56 /*                                            resulting in version 6.1    */
57 /*                                                                        */
58 /**************************************************************************/
59 
60 typedef struct NX_CRYPTO_TLS_PRF_SHA512_STRUCT
61 {
62     NX_CRYPTO_PHASH nx_secure_tls_prf_phash_info;
63     UCHAR nx_secure_tls_prf_label_seed_buffer[80]; /* phash_seed = label(13 bytes) || prf_seed(64 bytes) */
64     UCHAR nx_secure_tls_prf_temp_A_buffer[144]; /* The temp_A buffer needs to be large enough to holdthe lable(13 bytes) || prf_seed(64 bytes) || hash_size(48 bytes for SHA512) */
65     UCHAR nx_secure_tls_prf_temp_hmac_output_buffer[64]; /* The temp buffer for the output buffer of hmac(secret, A(i) + seed) */
66     UCHAR nx_secure_tls_prf_hmac_metadata_area[sizeof(NX_CRYPTO_SHA512_HMAC)]; /* metadata buffer for the hmac function */
67 } NX_CRYPTO_TLS_PRF_SHA512;
68 
69 UINT _nx_crypto_method_prf_sha512_init(struct NX_CRYPTO_METHOD_STRUCT *method,
70                                        UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
71                                        VOID **handle,
72                                        VOID *crypto_metadata,
73                                        ULONG crypto_metadata_size);
74 
75 UINT _nx_crypto_method_prf_sha512_cleanup(VOID *crypto_metadata);
76 
77 UINT _nx_crypto_method_prf_sha512_operation(UINT op,      /* Encrypt, Decrypt, Authenticate */
78                                             VOID *handle, /* Crypto handler */
79                                             struct NX_CRYPTO_METHOD_STRUCT *method,
80                                             UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
81                                             UCHAR *input, ULONG input_length_in_byte,
82                                             UCHAR *iv_ptr,
83                                             UCHAR *output, ULONG output_length_in_byte,
84                                             VOID *crypto_metadata, ULONG crypto_metadata_size,
85                                             VOID *packet_ptr,
86                                             VOID (*nx_crypto_hw_process_callback)(VOID *packet_ptr, UINT status));
87 
88 
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94