2 * Copyright (c) Dan Harkins, 2012
4 * Copyright holder grants permission for redistribution and use in source
5 * and binary forms, with or without modification, provided that the
6 * following conditions are met:
7 * 1. Redistribution of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer
10 * 2. Redistribution in binary form must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer
12 * in the documentation and/or other materials provided with the
15 * "DISCLAIMER OF LIABILITY
17 * THIS SOFTWARE IS PROVIDED BY DAN HARKINS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INDUSTRIAL LOUNGE BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This license and distribution terms cannot be changed. In other words,
30 * this code cannot simply be copied and put under a different distribution
31 * license (including the GNU public license).
37 #include <freeradius-devel/ident.h>
38 RCSIDH(eap_pwd_h, "$Id$")
40 #include <openssl/bn.h>
41 #include <openssl/sha.h>
42 #include <openssl/ec.h>
43 #include <openssl/evp.h>
44 #include <openssl/hmac.h>
46 typedef struct _pwd_hdr {
48 #define EAP_PWD_EXCH_ID 1
49 #define EAP_PWD_EXCH_COMMIT 2
50 #define EAP_PWD_EXCH_CONFIRM 3
51 // uint16_t total_length; /* there if the L-bit is set */
53 } __attribute__ ((packed)) pwd_hdr;
55 #define EAP_PWD_GET_LENGTH_BIT(x) ((x)->lm_exchange & 0x80)
56 #define EAP_PWD_SET_LENGTH_BIT(x) ((x)->lm_exchange |= 0x80)
57 #define EAP_PWD_GET_MORE_BIT(x) ((x)->lm_exchange & 0x40)
58 #define EAP_PWD_SET_MORE_BIT(x) ((x)->lm_exchange |= 0x40)
59 #define EAP_PWD_GET_EXCHANGE(x) ((x)->lm_exchange & 0x3f)
60 #define EAP_PWD_SET_EXCHANGE(x,y) ((x)->lm_exchange |= (y))
62 typedef struct _pwd_id_packet {
64 uint8_t random_function;
65 #define EAP_PWD_DEF_RAND_FUN 1
67 #define EAP_PWD_DEF_PRF 1
70 #define EAP_PWD_PREP_NONE 0
71 #define EAP_PWD_PREP_MS 1
72 #define EAP_PWD_PREP_SASL 2
74 } __attribute__ ((packed)) pwd_id_packet;
76 typedef struct _pwd_session_t {
78 #define PWD_STATE_ID_REQ 1
79 #define PWD_STATE_COMMIT 2
80 #define PWD_STATE_CONFIRM 3
84 char peer_id[MAX_STRING_LEN];
87 uint8_t *in_buf; /* reassembled fragments */
90 uint8_t *out_buf; /* message to fragment */
98 BIGNUM *private_value;
101 EC_POINT *my_element;
102 EC_POINT *peer_element;
103 uint8_t my_confirm[SHA256_DIGEST_LENGTH];
106 int compute_password_element(pwd_session_t *sess, uint16_t grp_num,
107 char *password, int password_len,
108 char *id_server, int id_server_len,
109 char *id_peer, int id_peer_len,
111 int compute_scalar_element(pwd_session_t *sess, BN_CTX *bnctx);
112 int process_peer_commit (pwd_session_t *sess, uint8_t *commit, BN_CTX *bnctx);
113 int compute_server_confirm(pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx);
114 int compute_peer_confirm(pwd_session_t *sess, uint8_t *buf, BN_CTX *bnctx);
115 int compute_keys(pwd_session_t *sess, uint8_t *peer_confirm,
116 uint8_t *msk, uint8_t *emsk);
118 void print_buf(char *str, uint8_t *buf, int len);
119 #endif /* PRINTBUF */
121 #endif /* _EAP_PWD_H */