b264e04e9167214a279780a24ccdf980da786763
[freeradius.git] / src / modules / rlm_otp / cardops / cryptocard.h
1 /*
2  * cryptocard.h
3  * $Id$
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Copyright 2005,2006 TRI-D Systems, Inc.
20  */
21
22 #ifndef CRYPTOCARD_H
23 #define CRYPTOCARD_H
24
25 #include "../otp.h"
26 #include "../otp_cardops.h"
27
28 /* card modes */
29 #define CRYPTOCARD_H8_RC (OTP_CF_HD|OTP_CF_R8|OTP_CF_AM|OTP_CF_C8)
30 #define CRYPTOCARD_H7_RC (OTP_CF_HD|OTP_CF_R7|OTP_CF_AM|OTP_CF_C8)
31 #define CRYPTOCARD_HP_RC (OTP_CF_HD|OTP_CF_RP|OTP_CF_AM|OTP_CF_C8)
32 #define CRYPTOCARD_D8_RC (OTP_CF_DD|OTP_CF_R8|OTP_CF_AM|OTP_CF_C8)
33 #define CRYPTOCARD_D7_RC (OTP_CF_DD|OTP_CF_R7|OTP_CF_AM|OTP_CF_C8)
34 #define CRYPTOCARD_DP_RC (OTP_CF_DD|OTP_CF_RP|OTP_CF_AM|OTP_CF_C8)
35 #define CRYPTOCARD_H8_ES (OTP_CF_HD|OTP_CF_R8|OTP_CF_ES|OTP_CF_C8)
36 #define CRYPTOCARD_H7_ES (OTP_CF_HD|OTP_CF_R7|OTP_CF_ES|OTP_CF_C8)
37 #define CRYPTOCARD_HP_ES (OTP_CF_HD|OTP_CF_RP|OTP_CF_ES|OTP_CF_C8)
38 #define CRYPTOCARD_D8_ES (OTP_CF_DD|OTP_CF_R8|OTP_CF_ES|OTP_CF_C8)
39 #define CRYPTOCARD_D7_ES (OTP_CF_DD|OTP_CF_R7|OTP_CF_ES|OTP_CF_C8)
40 #define CRYPTOCARD_DP_ES (OTP_CF_DD|OTP_CF_RP|OTP_CF_ES|OTP_CF_C8)
41 #define CRYPTOCARD_H8_RS (CRYPTOCARD_H8_RC|CRYPTOCARD_H8_ES)
42 #define CRYPTOCARD_H7_RS (CRYPTOCARD_H7_RC|CRYPTOCARD_H7_ES)
43 #define CRYPTOCARD_HP_RS (CRYPTOCARD_HP_RC|CRYPTOCARD_HP_ES)
44 #define CRYPTOCARD_D8_RS (CRYPTOCARD_D8_RC|CRYPTOCARD_D8_ES)
45 #define CRYPTOCARD_D7_RS (CRYPTOCARD_D7_RC|CRYPTOCARD_D7_ES)
46 #define CRYPTOCARD_DP_RS (CRYPTOCARD_DP_RC|CRYPTOCARD_DP_ES)
47
48 static int cryptocard_name2fm(const char *, uint32_t *);
49 static int cryptocard_keystring2keyblock(const char *,
50                                          unsigned char [OTP_MAX_KEY_LEN]);
51 static int cryptocard_nullstate(const otp_option_t *, const otp_card_info_t *,
52                                 otp_user_state_t *, time_t, const char *);
53 static int cryptocard_challenge(const otp_card_info_t *, otp_user_state_t *,
54                                 unsigned char [OTP_MAX_CHALLENGE_LEN], time_t,
55                                 int, int, const char *);
56 static int cryptocard_response(otp_card_info_t *,
57                                const unsigned char [OTP_MAX_CHALLENGE_LEN],
58                                size_t, char [OTP_MAX_RESPONSE_LEN + 1],
59                                const char *);
60 static int cryptocard_updatecsd(otp_user_state_t *, time_t, int, int, int);
61 static int cryptocard_isconsecutive(const otp_card_info_t *,
62                                     const otp_user_state_t *, int,
63                                     const char *);
64 static int cryptocard_maxtwin(const otp_card_info_t *,
65                               const char [OTP_MAX_CSD_LEN + 1]);
66 static char *cryptocard_printchallenge(char [OTP_MAX_CHALLENGE_LEN * 2 + 1],
67                                    const unsigned char [OTP_MAX_CHALLENGE_LEN],
68                                        size_t);
69
70 #ifdef __GNUC__
71 __attribute__ ((constructor))
72 #endif
73 void cryptocard_init(void);
74
75 #endif /* CRYPTOCARD_H */