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 #ifndef SRC_NX_SECURE_PHASH_H_
23 #define SRC_NX_SECURE_PHASH_H_
24 
25 /* Determine if a C++ compiler is being used.  If so, ensure that standard
26    C is used to process the API information.  */
27 #ifdef __cplusplus
28 
29 /* Yes, C++ compiler is present.  Use standard C.  */
30 extern   "C" {
31 
32 #endif
33 
34 #include "nx_crypto.h"
35 #include "nx_crypto_hmac_sha2.h"
36 #include "nx_crypto_hmac_sha5.h"
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  COMPONENT DEFINITION                                   RELEASE        */
41 /*                                                                        */
42 /*    nx_crypto_phash.h                                   PORTABLE C      */
43 /*                                                           6.1          */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Timothy Stapko, Microsoft Corporation                               */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This file defines the TLS P-HASH function described in RFCs 2246,   */
51 /*    4346, and 5246. It is used in the TLS PRF function as a wrapper to  */
52 /*    various hash routines to generate arbitrary-length data.            */
53 /*                                                                        */
54 /*  RELEASE HISTORY                                                       */
55 /*                                                                        */
56 /*    DATE              NAME                      DESCRIPTION             */
57 /*                                                                        */
58 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
59 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
60 /*                                            resulting in version 6.1    */
61 /*                                                                        */
62 /**************************************************************************/
63 typedef struct NX_CRYPTO_PHASH_STRUCT
64 {
65     UCHAR *nx_crypto_phash_secret; /* secret */
66     NX_CRYPTO_KEY_SIZE nx_crypto_phash_secret_length;
67     UCHAR *nx_crypto_phash_seed; /* seed */
68     UINT nx_crypto_phash_seed_length;
69     UCHAR *nx_crypto_phash_temp_A; /* the buffer for A(i) */
70     UINT nx_crypto_phash_temp_A_size;
71     NX_CRYPTO_METHOD *nx_crypto_hmac_method; /* hmac method */
72     UCHAR *nx_crypto_hmac_metadata; /* hash_metadata */
73     UINT nx_crypto_hmac_metadata_size;
74     UCHAR *nx_crypto_hmac_output;
75     UINT nx_crypto_hmac_output_size;
76 } NX_CRYPTO_PHASH;
77 
78 extern NX_CRYPTO_METHOD crypto_method_hmac_md5;
79 extern NX_CRYPTO_METHOD crypto_method_hmac_sha1;
80 extern NX_CRYPTO_METHOD crypto_method_hmac_sha256;
81 extern NX_CRYPTO_METHOD crypto_method_hmac_sha384;
82 extern NX_CRYPTO_METHOD crypto_method_hmac_sha512;
83 
84 UINT _nx_crypto_phash(NX_CRYPTO_PHASH *phash, UCHAR *output, UINT desired_length);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif
91 
92