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