Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / usb / host / dwc_common_port / dwc_dh.h
1 /* =========================================================================
2  * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
3  * $Revision: #4 $
4  * $Date: 2010/09/28 $
5  * $Change: 1596182 $
6  *
7  * Synopsys Portability Library Software and documentation
8  * (hereinafter, "Software") is an Unsupported proprietary work of
9  * Synopsys, Inc. unless otherwise expressly agreed to in writing
10  * between Synopsys and you.
11  *
12  * The Software IS NOT an item of Licensed Software or Licensed Product
13  * under any End User Software License Agreement or Agreement for
14  * Licensed Product with Synopsys or any supplement thereto. You are
15  * permitted to use and redistribute this Software in source and binary
16  * forms, with or without modification, provided that redistributions
17  * of source code must retain this notice. You may not view, use,
18  * disclose, copy or distribute this file or any information contained
19  * herein except pursuant to this license grant from Synopsys. If you
20  * do not agree with this notice, including the disclaimer below, then
21  * you are not authorized to use the Software.
22  *
23  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
24  * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
27  * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
33  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
34  * DAMAGE.
35  * ========================================================================= */
36 #ifndef _DWC_DH_H_
37 #define _DWC_DH_H_
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 #include "dwc_os.h"
44
45 /** @file
46  *
47  * This file defines the common functions on device and host for performing
48  * numeric association as defined in the WUSB spec.  They are only to be
49  * used internally by the DWC UWB modules. */
50
51 extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
52 extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
53                               uint8_t *key, uint32_t keylen,
54                               uint8_t *out);
55 extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
56                          void *exp, uint32_t exp_len,
57                          void *mod, uint32_t mod_len,
58                          void *out);
59
60 /** Computes PKD or PKH, and SHA-256(PKd || Nd)
61  *
62  * PK = g^exp mod p.
63  *
64  * Input:
65  * Nd = Number of digits on the device.
66  *
67  * Output:
68  * exp = A 32-byte buffer to be filled with a randomly generated number.
69  *       used as either A or B.
70  * pk = A 384-byte buffer to be filled with the PKH or PKD.
71  * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
72  */
73 extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
74
75 /** Computes the DHKEY, and VD.
76  *
77  * If called from host, then it will comput DHKEY=PKD^exp % p.
78  * If called from device, then it will comput DHKEY=PKH^exp % p.
79  *
80  * Input:
81  * pkd = The PKD value.
82  * pkh = The PKH value.
83  * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
84  * is_host = Set to non zero if a WUSB host is calling this function.
85  *
86  * Output:
87
88  * dd = A pointer to an buffer to be set to the displayed digits string to be shown
89  *      to the user.  This buffer should be at 5 bytes long to hold 4 digits plus a
90  *      null termination character.  This buffer can be used directly for display.
91  * ck = A 16-byte buffer to be filled with the CK.
92  * kdk = A 32-byte buffer to be filled with the KDK.
93  */
94 extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
95                               uint8_t *exp, int is_host,
96                               char *dd, uint8_t *ck, uint8_t *kdk);
97
98 #ifdef DH_TEST_VECTORS
99 extern void dwc_run_dh_test_vectors(void);
100 #endif
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif /* _DWC_DH_H_ */