Debian Codegraph @

lib/crypto/mac-hmac-md5-generic.c

raw symbols SCIP
1 // clang-format offcxx . . $ `<file>/lib/crypto/mac-hmac-md5-generic.c`/
2 /**
3 * \file mac-hmac-md5-generic.c
4 *
5 * \author Joseph Benden <[email protected]>
6 * \author Jouni Malinen <[email protected]>
7 *
8 * \license BSD-3-CLAUSE
9 *
10 * \ingroup
11 * \cond
12 ******************************************************************************
13 *
14 * Portions Copyright (c) 2003-2016, Jouni Malinen <[email protected]>
15 * SPDX-License-Identifier: BSD-3-CLAUSE
16 *
17 ******************************************************************************
18 * \endcond
19 */
20
21 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
22 # include <config.h>cxx . . $ `<file>/config.h`/
23 #endif
24
25 #include <stddef.h> // {s,ss}ize_t
26 #include <stdint.h> // [u]int[8,16,32,64]_t
27
28 #include "aircrack-ng/defs.h"cxx . . $ `<file>/include/aircrack-ng/defs.h`/
29 #include "aircrack-ng/crypto/crypto.h"cxx . . $ `<file>/include/aircrack-ng/crypto/crypto.h`/
30 #include "aircrack-ng/crypto/md5.h"cxx . . $ `<file>/include/aircrack-ng/crypto/md5.h`/
31 // clang-format on
32
33 API_EXPORTcxx . . $ `include/aircrack-ng/defs.h:94:9`!
34 int MAC_HMAC_MD5_Vectorcxx . . $ MAC_HMAC_MD5_Vector(2564766a35c3f83a).(size_t key_len,
35 const uint8_tcxx . . $ uint8_t# key[static key_len],
36 size_t count,
37 const uint8_tcxx . . $ uint8_t# * addr[],
38 const size_t * len,
39 uint8_tcxx . . $ uint8_t# mac[static DIGEST_MD5_MAC_LENcxx . . $ `include/aircrack-ng/crypto/md5.h:58:9`!])
40 {
41 // clang-format off
42 uint8_tcxx . . $ uint8_t# k_pad[64]; /* padding - key XORd with ipad/opad */
43 uint8_tcxx . . $ uint8_t# tk[DIGEST_MD5_MAC_LENcxx . . $ `include/aircrack-ng/crypto/md5.h:58:9`!];
44 const uint8_tcxx . . $ uint8_t# *_addr[6];
45 size_t i, _len[6];
46 int res;
47 // clang-format on
48
49 if (count > 5)
50 {
51 /*
52 * Fixed limit on the number of fragments to avoid having to
53 * allocate memory (which could fail).
54 */
55 return -1;
56 }
57
58 /* if key is longer than 64 bytes reset it to key = MD5(key) */
59 if (key_len > 64)
60 {
61 if (Digest_MD5_Vectorcxx . . $ Digest_MD5_Vector(f3dd7637603d42b8).(1, &key, &key_len, tk)) return -1;
62 key = tk;
63 key_len = DIGEST_MD5_MAC_LENcxx . . $ `include/aircrack-ng/crypto/md5.h:58:9`!;
64 }
65
66 /* the HMAC_MD5 transform looks like:
67 *
68 * MD5(K XOR opad, MD5(K XOR ipad, text))
69 *
70 * where K is an n byte key
71 * ipad is the byte 0x36 repeated 64 times
72 * opad is the byte 0x5c repeated 64 times
73 * and text is the data being protected */
74
75 /* start out by storing key in ipad */
76 memsetcxx . . $ memset(d1de1e4fb215f1c6).(k_pad, 0, sizeof(k_pad));
77 memcpycxx . . $ memcpy(cc817cb175f282d).(k_pad, key, key_len);
78
79 /* XOR key with ipad values */
80 for (i = 0; i < 64; i++) k_pad[i] ^= 0x36;
81
82 /* perform inner MD5 */
83 _addr[0] = k_pad;
84 _len[0] = 64;
85 for (i = 0; i < count; i++)
86 {
87 _addr[i + 1] = addr[i];
88 _len[i + 1] = len[i];
89 }
90 if (Digest_MD5_Vectorcxx . . $ Digest_MD5_Vector(f3dd7637603d42b8).(1 + count, _addr, _len, mac)) return -1;
91
92 memsetcxx . . $ memset(d1de1e4fb215f1c6).(k_pad, 0, sizeof(k_pad));
93 memcpycxx . . $ memcpy(cc817cb175f282d).(k_pad, key, key_len);
94
95 /* XOR key with opad values */
96 for (i = 0; i < 64; i++) k_pad[i] ^= 0x5c;
97
98 /* perform outer MD5 */
99 // clang-format off
100 _addr[0] = k_pad;
101 _len[0] = 64;
102 _addr[1] = mac;
103 _len[1] = DIGEST_MD5_MAC_LENcxx . . $ `include/aircrack-ng/crypto/md5.h:58:9`!;
104 // clang-format on
105
106 res = Digest_MD5_Vectorcxx . . $ Digest_MD5_Vector(f3dd7637603d42b8).(2, _addr, _len, mac);
107
108 return res;
109 }
110
111 API_EXPORTcxx . . $ `include/aircrack-ng/defs.h:94:9`!
112 int MAC_HMAC_MD5cxx . . $ MAC_HMAC_MD5(31978f7f0f9137e4).(size_t key_len,
113 const uint8_tcxx . . $ uint8_t# key[static key_len],
114 size_t data_len,
115 const uint8_tcxx . . $ uint8_t# data[static data_len],
116 uint8_tcxx . . $ uint8_t# output[static DIGEST_MD5_MAC_LENcxx . . $ `include/aircrack-ng/crypto/md5.h:58:9`!])
117 {
118 return MAC_HMAC_MD5_Vectorcxx . . $ MAC_HMAC_MD5_Vector(2564766a35c3f83a).(key_len, key, 1, &data, &data_len, output);
119 }