Identity is an ASCII string
[freeradius.git] / src / modules / rlm_eap / types / rlm_eap_pwd / eap_pwd.h
1 /*
2  * Copyright (c) Dan Harkins, 2012
3  *
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
9  *        in all source files.
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
13  *        distribution.
14  *
15  *  "DISCLAIMER OF LIABILITY
16  *  
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
27  *  SUCH DAMAGE."
28  *
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).
32  */
33
34 #ifndef _EAP_PWD_H
35 #define _EAP_PWD_H
36
37 #include <freeradius-devel/ident.h>
38 RCSIDH(eap_pwd_h, "$Id$")
39 #include "eap.h"
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>
45
46 typedef struct _pwd_hdr {
47     uint8_t lm_exchange;
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 */
52     uint8_t data[0];
53 } __attribute__ ((packed)) pwd_hdr;
54
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))
61
62 typedef struct _pwd_id_packet {
63     uint16_t group_num;
64     uint8_t random_function;
65 #define EAP_PWD_DEF_RAND_FUN            1
66     uint8_t prf;
67 #define EAP_PWD_DEF_PRF                 1
68     uint8_t token[4];
69     uint8_t prep;
70 #define EAP_PWD_PREP_NONE               0
71 #define EAP_PWD_PREP_MS                 1
72 #define EAP_PWD_PREP_SASL               2
73     char identity[0];
74 } __attribute__ ((packed)) pwd_id_packet;
75
76 typedef struct _pwd_session_t {
77     uint16_t state;
78 #define PWD_STATE_ID_REQ                1
79 #define PWD_STATE_COMMIT                2
80 #define PWD_STATE_CONFIRM               3
81     uint16_t group_num;
82     uint32_t ciphersuite;
83     uint32_t token;
84     char peer_id[MAX_STRING_LEN];
85     int peer_id_len;
86     int mtu;
87     uint8_t *in_buf;      /* reassembled fragments */
88     int in_buf_pos;
89     int in_buf_len;
90     uint8_t *out_buf;     /* message to fragment */
91     int out_buf_pos;
92     int out_buf_len;
93     EC_GROUP *group;
94     EC_POINT *pwe;
95     BIGNUM *order;
96     BIGNUM *prime;
97     BIGNUM *k;
98     BIGNUM *private_value;
99     BIGNUM *peer_scalar;
100     BIGNUM *my_scalar;
101     EC_POINT *my_element;
102     EC_POINT *peer_element;
103     uint8_t my_confirm[SHA256_DIGEST_LENGTH];
104 } pwd_session_t;
105
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, 
110                              uint32_t *token);
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);
117 #ifdef PRINTBUF
118 void print_buf(char *str, uint8_t *buf, int len);
119 #endif  /* PRINTBUF */
120
121 #endif  /* _EAP_PWD_H */