1 /** @file pass_phrase.c
2 *
3 * @brief This file defines passphase hash
4 *
5 * Copyright (C) 2014-2017, Marvell International Ltd.
6 *
7 * This software file (the "File") is distributed by Marvell International
8 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
9 * (the "License"). You may use, redistribute and/or modify this File in
10 * accordance with the terms and conditions of the License, a copy of which
11 * is available by writing to the Free Software Foundation, Inc.,
12 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
13 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 *
15 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
18 * this warranty disclaimer.
19 */
20
21 /******************************************************
22 Change log:
23 03/07/2014: Initial version
24 ******************************************************/
25 #include "wl_macros.h"
26 #include "pass_phrase.h"
27 //#include "keyMgmtSta.h"
28 #include "sha1.h"
29 #include "hostsa_ext_def.h"
30 #include "authenticator.h"
31
32 static INLINE t_u32
pass_strlen(const char * str)33 pass_strlen(const char *str)
34 {
35 t_u32 i;
36
37 for (i = 0; str[i] != 0; i++) {
38 }
39 return i;
40 }
41
42 /*
43 * F(P, S, c, i) = U1 xor U2 xor ... Uc
44 * U1 = PRF(P, S || Int(i))
45 * U2 = PRF(P, U1)
46 * Uc = PRF(P, Uc-1)
47 */
48 void
Mrvl_F(void * priv,char * password,unsigned char * ssid,int ssidlength,int iterations,int count,unsigned char * output)49 Mrvl_F(void *priv, char *password, unsigned char *ssid, int ssidlength,
50 int iterations, int count, unsigned char *output)
51 {
52 phostsa_private psapriv = (phostsa_private)priv;
53 hostsa_util_fns *util_fns = &psapriv->util_fns;
54 static unsigned char digest[36], digest1[A_SHA_DIGEST_LEN];
55 int i, j;
56 int len = pass_strlen(password);
57 int tmpLen = ssidlength + 4;
58 unsigned char *pTemp = digest;
59
60 /* U1 = PRF(P, S || int(i)) */
61 memcpy(util_fns, digest, ssid, ssidlength);
62 digest[ssidlength] = (unsigned char)((count >> 24) & 0xff);
63 digest[ssidlength + 1] = (unsigned char)((count >> 16) & 0xff);
64 digest[ssidlength + 2] = (unsigned char)((count >> 8) & 0xff);
65 digest[ssidlength + 3] = (unsigned char)(count & 0xff);
66
67 Mrvl_hmac_sha1((void *)priv, &pTemp,
68 &tmpLen,
69 1,
70 (unsigned char *)password,
71 len, digest1, A_SHA_DIGEST_LEN);
72
73 /* output = U1 */
74 memcpy(util_fns, output, digest1, A_SHA_DIGEST_LEN);
75 pTemp = digest1;
76 for (i = 1; i < iterations; i++) {
77 tmpLen = A_SHA_DIGEST_LEN;
78
79 /* Un = PRF(P, Un-1) */
80 Mrvl_hmac_sha1((void *)priv, &pTemp,
81 &tmpLen,
82 1,
83 (unsigned char *)password,
84 len, digest, A_SHA_DIGEST_LEN);
85
86 memcpy(util_fns, digest1, digest, A_SHA_DIGEST_LEN);
87
88 /* output = output xor Un */
89 for (j = 0; j < A_SHA_DIGEST_LEN; j++) {
90 output[j] ^= digest[j];
91 }
92 }
93 }
94
95 /*
96 * password - ascii string up to 63 characters in length
97 * ssid - octet string up to 32 octets
98 * ssidlength - length of ssid in octets
99 * output must be 32 octets in length and outputs 256 bits of key
100 */
101 int
Mrvl_PasswordHash(void * priv,char * password,unsigned char * ssid,int ssidlength,unsigned char * output)102 Mrvl_PasswordHash(void *priv, char *password, unsigned char *ssid,
103 int ssidlength, unsigned char *output)
104 {
105 phostsa_private psapriv = (phostsa_private)priv;
106 hostsa_util_fns *util_fns = &psapriv->util_fns;
107 if ((pass_strlen(password) > 63) || (ssidlength > 32)) {
108 return 0;
109 }
110
111 Mrvl_F((void *)priv, password, ssid, ssidlength, 4096, 2, output);
112 memcpy(util_fns, output + A_SHA_DIGEST_LEN, output, 12);
113 Mrvl_F((void *)priv, password, ssid, ssidlength, 4096, 1, output);
114 return 1;
115 }
116