1 /* =========================================================================
2 * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
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.
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.
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
35 * ========================================================================= */
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. */
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,
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,
60 /** Computes PKD or PKH, and SHA-256(PKd || Nd)
65 * Nd = Number of digits on the device.
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).
73 extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
75 /** Computes the DHKEY, and VD.
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.
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.
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.
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);
98 #ifdef DH_TEST_VECTORS
99 extern void dwc_run_dh_test_vectors(void);
106 #endif /* _DWC_DH_H_ */