The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
eap_pwd.h
Go to the documentation of this file.
1 #pragma once
2 /**
3  * copyright holder grants permission for redistribution and use in source
4  * and binary forms, with or without modification, provided that the
5  * following conditions are met:
6  * 1. Redistribution of source code must retain the above copyright
7  * notice, this list of conditions, and the following disclaimer
8  * in all source files.
9  * 2. Redistribution in binary form must retain the above copyright
10  * notice, this list of conditions, and the following disclaimer
11  * in the documentation and/or other materials provided with the
12  * distribution.
13  *
14  * "DISCLAIMER OF LIABILITY
15  *
16  * THIS SOFTWARE IS PROVIDED BY DAN HARKINS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INDUSTRIAL LOUNGE BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE."
27  *
28  * This license and distribution terms cannot be changed. In other words,
29  * this code cannot simply be copied and put under a different distribution
30  * license (including the GNU public license).
31  *
32  * @copyright (c) Dan Harkins, 2012
33  */
34 RCSIDH(eap_pwd_h, "$Id: c6aeeb14bbc182b105731f5ed82aa22c57abbf48 $")
35 
36 #include <freeradius-devel/eap/base.h>
37 #include <freeradius-devel/tls/openssl_user_macros.h>
38 #include <openssl/bn.h>
39 #include <openssl/sha.h>
40 #include <openssl/ec.h>
41 #include <openssl/evp.h>
42 #include <openssl/hmac.h>
43 
44 typedef struct {
46 #define EAP_PWD_EXCH_ID 1
47 #define EAP_PWD_EXCH_COMMIT 2
48 #define EAP_PWD_EXCH_CONFIRM 3
49 // uint16_t total_length; /* there if the L-bit is set */
51 } CC_HINT(packed) pwd_hdr;
52 
53 #define EAP_PWD_GET_LENGTH_BIT(x) ((x)->lm_exchange & 0x80)
54 #define EAP_PWD_SET_LENGTH_BIT(x) ((x)->lm_exchange |= 0x80)
55 #define EAP_PWD_GET_MORE_BIT(x) ((x)->lm_exchange & 0x40)
56 #define EAP_PWD_SET_MORE_BIT(x) ((x)->lm_exchange |= 0x40)
57 #define EAP_PWD_GET_EXCHANGE(x) ((x)->lm_exchange & 0x3f)
58 #define EAP_PWD_SET_EXCHANGE(x,y) ((x)->lm_exchange |= (y))
59 
60 typedef struct {
63 #define EAP_PWD_DEF_RAND_FUN 1
65 #define EAP_PWD_DEF_PRF 1
66  uint8_t token[4];
68 #define EAP_PWD_PREP_NONE 0
69 #define EAP_PWD_PREP_MS 1
70 #define EAP_PWD_PREP_SASL 2
71  char identity[];
72 } CC_HINT(packed) pwd_id_packet_t;
73 
74 typedef struct {
76 #define PWD_STATE_ID_REQ 1
77 #define PWD_STATE_COMMIT 2
78 #define PWD_STATE_CONFIRM 3
82  char peer_id[FR_MAX_STRING_LEN];
83  size_t peer_id_len;
84  size_t mtu;
85  uint8_t *in; /* reassembled fragments */
86  size_t in_pos;
87  size_t in_len;
88  uint8_t *out; /* message to fragment */
89  size_t out_pos;
90  size_t out_len;
91  EC_GROUP *group;
92  EC_POINT *pwe;
93  BIGNUM *order;
94  BIGNUM *prime;
95  BIGNUM *k;
96  BIGNUM *private_value;
97  BIGNUM *peer_scalar;
98  BIGNUM *my_scalar;
99  EC_POINT *my_element;
100  EC_POINT *peer_element;
101  uint8_t my_confirm[SHA256_DIGEST_LENGTH];
102 } pwd_session_t;
103 
104 int compute_password_element(request_t *request, pwd_session_t *sess, uint16_t grp_num,
105  char const *password, int password_len,
106  char const *id_server, int id_server_len,
107  char const *id_peer, int id_peer_len,
108  uint32_t *token, BN_CTX *bnctx);
109 int compute_scalar_element(request_t *request, pwd_session_t *sess, BN_CTX *bnctx);
110 int process_peer_commit(request_t *request, pwd_session_t *sess, uint8_t *in, size_t in_len, BN_CTX *bnctx);
111 int compute_server_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx);
112 int compute_peer_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx);
113 int compute_keys(request_t *request, pwd_session_t *sess, uint8_t *peer_confirm,
114  uint8_t *msk, uint8_t *emsk);
115 #ifdef PRINTBUF
116 void print_buf(char *str, uint8_t *buf, int len);
117 #endif /* PRINTBUF */
#define RCSIDH(h, id)
Definition: build.h:482
static fr_slen_t in
Definition: dict.h:821
BIGNUM * private_value
Definition: eap_pwd.h:96
int compute_server_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:684
uint16_t group_num
Definition: eap_pwd.h:79
int compute_password_element(request_t *request, pwd_session_t *sess, uint16_t grp_num, char const *password, int password_len, char const *id_server, int id_server_len, char const *id_peer, int id_peer_len, uint32_t *token, BN_CTX *bnctx)
Definition: eap_pwd.c:253
size_t in_pos
Definition: eap_pwd.h:86
uint8_t lm_exchange
Definition: eap_pwd.h:45
BIGNUM * my_scalar
Definition: eap_pwd.h:98
uint32_t token
Definition: eap_pwd.h:81
int process_peer_commit(request_t *request, pwd_session_t *sess, uint8_t *in, size_t in_len, BN_CTX *bnctx)
Definition: eap_pwd.c:558
uint16_t state
Definition: eap_pwd.h:75
uint16_t group_num
Definition: eap_pwd.h:61
size_t out_len
Definition: eap_pwd.h:90
int compute_scalar_element(request_t *request, pwd_session_t *sess, BN_CTX *bnctx)
Definition: eap_pwd.c:518
size_t peer_id_len
Definition: eap_pwd.h:83
BIGNUM * prime
Definition: eap_pwd.h:94
int compute_peer_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:787
uint8_t prf
Definition: eap_pwd.h:64
uint8_t prep
Definition: eap_pwd.h:67
size_t out_pos
Definition: eap_pwd.h:89
EC_GROUP * group
Definition: eap_pwd.h:91
size_t in_len
Definition: eap_pwd.h:87
BIGNUM * peer_scalar
Definition: eap_pwd.h:97
int compute_keys(request_t *request, pwd_session_t *sess, uint8_t *peer_confirm, uint8_t *msk, uint8_t *emsk)
EC_POINT * pwe
Definition: eap_pwd.h:92
BIGNUM * k
Definition: eap_pwd.h:95
size_t mtu
Definition: eap_pwd.h:84
uint8_t * out
Definition: eap_pwd.h:88
uint8_t random_function
Definition: eap_pwd.h:62
uint8_t * in
Definition: eap_pwd.h:85
uint32_t ciphersuite
Definition: eap_pwd.h:80
BIGNUM * order
Definition: eap_pwd.h:93
EC_POINT * peer_element
Definition: eap_pwd.h:100
EC_POINT * my_element
Definition: eap_pwd.h:99
copyright holder grants permission for redistribution and use in source and binary forms,...
Definition: eap_pwd.h:44
unsigned short uint16_t
Definition: merged_model.c:31
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
static fr_slen_t data
Definition: value.h:1265
#define FR_MAX_STRING_LEN
Definition: value.h:30
static size_t char ** out
Definition: value.h:997