All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
eap_pwd.h
Go to the documentation of this file.
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 RCSIDH(eap_pwd_h, "$Id: 013a6e79926a9427812f5f527b457a5a48a58b6b $")
38 #include "eap.h"
39 
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[];
53 } CC_HINT(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[];
74 } CC_HINT(packed) pwd_id_packet_t;
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  size_t peer_id_len;
86  size_t mtu;
87  uint8_t *in; /* reassembled fragments */
88  size_t in_pos;
89  size_t in_len;
90  uint8_t *out; /* message to fragment */
91  size_t out_pos;
92  size_t out_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 const *password, int password_len,
108  char const *id_server, int id_server_len,
109  char const *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 *in, size_t in_len, BN_CTX *bnctx);
113 int compute_server_confirm(pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx);
114 int compute_peer_confirm(pwd_session_t *sess, uint8_t *out, 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 */
#define RCSIDH(h, id)
Definition: build.h:136
int compute_server_confirm(pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:421
int compute_scalar_element(pwd_session_t *sess, BN_CTX *bnctx)
Definition: eap_pwd.c:273
BIGNUM * k
Definition: eap_pwd.h:97
struct _pwd_session_t pwd_session_t
uint32_t ciphersuite
Definition: eap_pwd.h:82
BIGNUM * peer_scalar
Definition: eap_pwd.h:99
BIGNUM * my_scalar
Definition: eap_pwd.h:100
int process_peer_commit(pwd_session_t *sess, uint8_t *in, size_t in_len, BN_CTX *bnctx)
Definition: eap_pwd.c:315
size_t in_len
Definition: eap_pwd.h:89
uint8_t random_function
Definition: eap_pwd.h:64
BIGNUM * prime
Definition: eap_pwd.h:96
uint8_t prf
Definition: eap_pwd.h:66
size_t out_len
Definition: eap_pwd.h:92
uint32_t token
Definition: eap_pwd.h:83
char identity[]
Definition: eap_pwd.h:73
uint8_t * in
Definition: eap_pwd.h:87
size_t mtu
Definition: eap_pwd.h:86
uint8_t lm_exchange
Definition: eap_pwd.h:47
int compute_password_element(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)
Definition: eap_pwd.c:103
EC_POINT * peer_element
Definition: eap_pwd.h:102
EC_POINT * my_element
Definition: eap_pwd.h:101
uint16_t group_num
Definition: eap_pwd.h:63
uint8_t prep
Definition: eap_pwd.h:69
BIGNUM * private_value
Definition: eap_pwd.h:98
uint8_t * out
Definition: eap_pwd.h:90
struct _pwd_hdr CC_HINT(packed) pwd_hdr
size_t in_pos
Definition: eap_pwd.h:88
uint16_t state
Definition: eap_pwd.h:77
int compute_keys(pwd_session_t *sess, uint8_t *peer_confirm, uint8_t *msk, uint8_t *emsk)
Definition: eap_pwd.c:619
uint8_t token[4]
Definition: eap_pwd.h:625
size_t out_pos
Definition: eap_pwd.h:91
BIGNUM * order
Definition: eap_pwd.h:95
#define MAX_STRING_LEN
Definition: libradius.h:120
uint8_t data[]
Definition: eap_pwd.h:52
uint16_t group_num
Definition: eap_pwd.h:81
EC_POINT * pwe
Definition: eap_pwd.h:94
uint8_t token[4]
Definition: eap_pwd.h:68
EC_GROUP * group
Definition: eap_pwd.h:93
int compute_peer_confirm(pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:520
size_t peer_id_len
Definition: eap_pwd.h:85