The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
chap.c
Go to the documentation of this file.
1 /*
2  * This program is is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2 of the
4  * License as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
14  */
15 
16 /** Functions for parsing raw network packets
17  *
18  * @file src/lib/util/chap.c
19  *
20  * @author Alan DeKok (aland@networkradius.com)
21  * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
22  */
23 #include <freeradius-devel/util/chap.h>
24 
25 /** Encode a CHAP password
26  *
27  * @param[out] out An output buffer of 17 bytes (id + MD5 digest).
28  * @param[in] id CHAP ID, a random ID for request/response matching.
29  * @param[in] challenge the CHAP challenge
30  * @param[in] challenge_len Length of the challenge.
31  * @param[in] password Input password to hash.
32  * @param[in] password_len Length of input password.
33  */
35  uint8_t id, uint8_t const *challenge, size_t challenge_len,
36  char const *password, size_t password_len)
37 {
38  fr_md5_ctx_t *md5_ctx;
39 
40  md5_ctx = fr_md5_ctx_alloc_from_list();
41 
42  /*
43  * First ingest the ID and the password.
44  */
45  fr_md5_update(md5_ctx, (uint8_t const *)&id, 1);
46  fr_md5_update(md5_ctx, (uint8_t const *)password, password_len);
47 
48  fr_md5_update(md5_ctx, challenge, challenge_len);
49  out[0] = id;
50  fr_md5_final(out + 1, md5_ctx);
51  fr_md5_ctx_free_from_list(&md5_ctx);
52 }
void fr_chap_encode(uint8_t out[static 1+FR_CHAP_CHALLENGE_LENGTH], uint8_t id, uint8_t const *challenge, size_t challenge_len, char const *password, size_t password_len)
Encode a CHAP password.
Definition: chap.c:34
#define FR_CHAP_CHALLENGE_LENGTH
Definition: chap.h:33
fr_md5_update_t fr_md5_update
Definition: md5.c:442
fr_md5_final_t fr_md5_final
Definition: md5.c:443
void fr_md5_ctx_free_from_list(fr_md5_ctx_t **ctx)
Definition: md5.c:522
fr_md5_ctx_t * fr_md5_ctx_alloc_from_list(void)
Definition: md5.c:477
void fr_md5_ctx_t
Definition: md5.h:28
unsigned char uint8_t
Definition: merged_model.c:30
static size_t char ** out
Definition: value.h:997