diff options
Diffstat (limited to '3rd_party/libsrp6a-sha512/t_pwd.h')
-rw-r--r-- | 3rd_party/libsrp6a-sha512/t_pwd.h | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/3rd_party/libsrp6a-sha512/t_pwd.h b/3rd_party/libsrp6a-sha512/t_pwd.h new file mode 100644 index 0000000..a90a364 --- /dev/null +++ b/3rd_party/libsrp6a-sha512/t_pwd.h | |||
@@ -0,0 +1,246 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1997-2007 The Stanford SRP Authentication Project | ||
3 | * All Rights Reserved. | ||
4 | * | ||
5 | * Permission is hereby granted, free of charge, to any person obtaining | ||
6 | * a copy of this software and associated documentation files (the | ||
7 | * "Software"), to deal in the Software without restriction, including | ||
8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
9 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
10 | * permit persons to whom the Software is furnished to do so, subject to | ||
11 | * the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be | ||
14 | * included in all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, | ||
17 | * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY | ||
18 | * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. | ||
19 | * | ||
20 | * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL, | ||
21 | * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER | ||
22 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF | ||
23 | * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT | ||
24 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
25 | * | ||
26 | * Redistributions in source or binary form must retain an intact copy | ||
27 | * of this copyright notice. | ||
28 | */ | ||
29 | |||
30 | #ifndef T_PWD_H | ||
31 | #define T_PWD_H | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include "cstr.h" | ||
35 | |||
36 | #define MAXPARAMBITS 2048 | ||
37 | #define MAXPARAMLEN ((MAXPARAMBITS + 7) / 8) | ||
38 | #define MAXB64PARAMLEN ((MAXPARAMBITS + 5) / 6 + 1) | ||
39 | #define MAXHEXPARAMLEN ((MAXPARAMBITS + 3) / 4 + 1) | ||
40 | #define MAXOCTPARAMLEN ((MAXPARAMBITS + 2) / 3 + 1) | ||
41 | |||
42 | #define MAXUSERLEN 32 | ||
43 | #define MAXSALTLEN 32 | ||
44 | #define MAXB64SALTLEN 44 /* 256 bits in b64 + null */ | ||
45 | #define SALTLEN 10 /* Normally 80 bits */ | ||
46 | |||
47 | #define RESPONSE_LEN 20 /* 160-bit proof hashes */ | ||
48 | #define SESSION_KEY_LEN (2 * RESPONSE_LEN) /* 320-bit session key */ | ||
49 | |||
50 | #define DEFAULT_PASSWD "/etc/tpasswd" | ||
51 | #define DEFAULT_CONF "/etc/tpasswd.conf" | ||
52 | |||
53 | struct t_num { /* Standard byte-oriented integer representation */ | ||
54 | int len; | ||
55 | unsigned char * data; | ||
56 | }; | ||
57 | |||
58 | struct t_preconf { /* Structure returned by t_getpreparam() */ | ||
59 | char * mod_b64; | ||
60 | char * gen_b64; | ||
61 | char * comment; | ||
62 | |||
63 | struct t_num modulus; | ||
64 | struct t_num generator; | ||
65 | }; | ||
66 | |||
67 | /* | ||
68 | * The built-in (known good) parameters access routines | ||
69 | * | ||
70 | * "t_getprecount" returns the number of precompiled parameter sets. | ||
71 | * "t_getpreparam" returns the indicated parameter set. | ||
72 | * Memory is statically allocated - callers need not perform any memory mgmt. | ||
73 | */ | ||
74 | _TYPE( int ) t_getprecount(); | ||
75 | _TYPE( struct t_preconf * ) t_getpreparam P((int)); | ||
76 | |||
77 | struct t_confent { /* One configuration file entry (index, N, g) */ | ||
78 | int index; | ||
79 | struct t_num modulus; | ||
80 | struct t_num generator; | ||
81 | }; | ||
82 | |||
83 | struct t_conf { /* An open configuration file */ | ||
84 | FILE * instream; | ||
85 | char close_on_exit; | ||
86 | cstr * modbuf; | ||
87 | cstr * genbuf; | ||
88 | struct t_confent tcbuf; | ||
89 | }; | ||
90 | |||
91 | /* | ||
92 | * The configuration file routines are designed along the lines of the | ||
93 | * "getpw" functions in the standard C library. | ||
94 | * | ||
95 | * "t_openconf" accepts a stdio stream and interprets it as a config file. | ||
96 | * "t_openconfbyname" accepts a filename and does the same thing. | ||
97 | * "t_closeconf" closes the config file. | ||
98 | * "t_getconfent" fetches the next sequential configuration entry. | ||
99 | * "t_getconfbyindex" fetches the configuration entry whose index | ||
100 | * matches the one supplied, or NULL if one can't be found. | ||
101 | * "t_getconflast" fetches the last configuration entry in the file. | ||
102 | * "t_makeconfent" generates a set of configuration entry parameters | ||
103 | * randomly. | ||
104 | * "t_newconfent" returns an empty configuration entry. | ||
105 | * "t_cmpconfent" compares two configuration entries a la strcmp. | ||
106 | * "t_checkconfent" verifies that a set of configuration parameters | ||
107 | * are suitable. N must be prime and should be a safe prime. | ||
108 | * "t_putconfent" writes a configuration entry to a stream. | ||
109 | */ | ||
110 | _TYPE( struct t_conf * ) t_openconf P((FILE *)); | ||
111 | _TYPE( struct t_conf * ) t_openconfbyname P((const char *)); | ||
112 | _TYPE( void ) t_closeconf P((struct t_conf *)); | ||
113 | _TYPE( void ) t_rewindconf P((struct t_conf *)); | ||
114 | _TYPE( struct t_confent * ) t_getconfent P((struct t_conf *)); | ||
115 | _TYPE( struct t_confent * ) t_getconfbyindex P((struct t_conf *, int)); | ||
116 | _TYPE( struct t_confent * ) t_getconflast P((struct t_conf *)); | ||
117 | _TYPE( struct t_confent * ) t_makeconfent P((struct t_conf *, int)); | ||
118 | _TYPE( struct t_confent * ) t_makeconfent_c P((struct t_conf *, int)); | ||
119 | _TYPE( struct t_confent * ) t_newconfent P((struct t_conf *)); | ||
120 | _TYPE( int ) t_cmpconfent P((const struct t_confent *, const struct t_confent *)); | ||
121 | _TYPE( int ) t_checkconfent P((const struct t_confent *)); | ||
122 | _TYPE( void ) t_putconfent P((const struct t_confent *, FILE *)); | ||
123 | |||
124 | /* libc-style system conf file access */ | ||
125 | _TYPE( struct t_confent *) gettcent(); | ||
126 | _TYPE( struct t_confent *) gettcid P((int)); | ||
127 | _TYPE( void ) settcent(); | ||
128 | _TYPE( void ) endtcent(); | ||
129 | |||
130 | #ifdef ENABLE_NSW | ||
131 | extern struct t_confent * _gettcent(); | ||
132 | extern struct t_confent * _gettcid P((int)); | ||
133 | extern void _settcent(); | ||
134 | extern void _endtcent(); | ||
135 | #endif | ||
136 | |||
137 | /* A hack to support '+'-style entries in the passwd file */ | ||
138 | |||
139 | typedef enum fstate { | ||
140 | FILE_ONLY, /* Ordinary file, don't consult NIS ever */ | ||
141 | FILE_NIS, /* Currently accessing file, use NIS if encountered */ | ||
142 | IN_NIS, /* Currently in a '+' entry; use NIS for getXXent */ | ||
143 | } FILE_STATE; | ||
144 | |||
145 | struct t_pwent { /* A single password file entry */ | ||
146 | char * name; | ||
147 | struct t_num password; | ||
148 | struct t_num salt; | ||
149 | int index; | ||
150 | }; | ||
151 | |||
152 | struct t_pw { /* An open password file */ | ||
153 | FILE * instream; | ||
154 | char close_on_exit; | ||
155 | FILE_STATE state; | ||
156 | char userbuf[MAXUSERLEN]; | ||
157 | cstr * pwbuf; | ||
158 | unsigned char saltbuf[SALTLEN]; | ||
159 | struct t_pwent pebuf; | ||
160 | }; | ||
161 | |||
162 | /* | ||
163 | * The password manipulation routines are patterned after the getpw* | ||
164 | * standard C library function calls. | ||
165 | * | ||
166 | * "t_openpw" reads a stream as if it were a password file. | ||
167 | * "t_openpwbyname" opens the named file as a password file. | ||
168 | * "t_closepw" closes an open password file. | ||
169 | * "t_rewindpw" starts the internal file pointer from the beginning | ||
170 | * of the password file. | ||
171 | * "t_getpwent" retrieves the next sequential password entry. | ||
172 | * "t_getpwbyname" looks up the password entry corresponding to the | ||
173 | * specified user. | ||
174 | * "t_makepwent" constructs a password entry from a username, password, | ||
175 | * numeric salt, and configuration entry. | ||
176 | * "t_putpwent" writes a password entry to a stream. | ||
177 | */ | ||
178 | _TYPE( struct t_pw * ) t_newpw(); | ||
179 | _TYPE( struct t_pw * ) t_openpw P((FILE *)); | ||
180 | _TYPE( struct t_pw * ) t_openpwbyname P((const char *)); | ||
181 | _TYPE( void ) t_closepw P((struct t_pw *)); | ||
182 | _TYPE( void ) t_rewindpw P((struct t_pw *)); | ||
183 | _TYPE( struct t_pwent * ) t_getpwent P((struct t_pw *)); | ||
184 | _TYPE( struct t_pwent * ) t_getpwbyname P((struct t_pw *, const char *)); | ||
185 | _TYPE( struct t_pwent * ) t_makepwent P((struct t_pw *, const char *, | ||
186 | const char *, const struct t_num *, | ||
187 | const struct t_confent *)); | ||
188 | _TYPE( void ) t_putpwent P((const struct t_pwent *, FILE *)); | ||
189 | |||
190 | struct t_passwd { | ||
191 | struct t_pwent tp; | ||
192 | struct t_confent tc; | ||
193 | }; | ||
194 | |||
195 | /* libc-style system password file access */ | ||
196 | _TYPE( struct t_passwd * ) gettpent(); | ||
197 | _TYPE( struct t_passwd * ) gettpnam P((const char *)); | ||
198 | _TYPE( void ) settpent(); | ||
199 | _TYPE( void ) endtpent(); | ||
200 | |||
201 | #ifdef ENABLE_NSW | ||
202 | extern struct t_passwd * _gettpent(); | ||
203 | extern struct t_passwd * _gettpnam P((const char *)); | ||
204 | extern void _settpent(); | ||
205 | extern void _endtpent(); | ||
206 | #endif | ||
207 | |||
208 | /* | ||
209 | * Utility functions | ||
210 | * | ||
211 | * "t_verifypw" accepts a username and password, and checks against the | ||
212 | * system password file to see if the password for that user is correct. | ||
213 | * Returns > 0 if it is correct, 0 if not, and -1 if some error occurred | ||
214 | * (i.e. the user doesn't exist on the system). This is intended ONLY | ||
215 | * for local authentication; for remote authentication, look at the | ||
216 | * t_client and t_server source. (That's the whole point of SRP!) | ||
217 | * "t_changepw" modifies the specified file, substituting the given password | ||
218 | * entry for the one already in the file. If no matching entry is found, | ||
219 | * the new entry is simply appended to the file. | ||
220 | * "t_deletepw" removes the specified user from the specified file. | ||
221 | */ | ||
222 | _TYPE( int ) t_verifypw P((const char *, const char *)); | ||
223 | _TYPE( int ) t_changepw P((const char *, const struct t_pwent *)); | ||
224 | _TYPE( int ) t_deletepw P((const char *, const char *)); | ||
225 | |||
226 | /* Conversion utilities */ | ||
227 | |||
228 | /* | ||
229 | * All these calls accept output as the first parameter. In the case of | ||
230 | * t_tohex and t_tob64, the last argument is the length of the byte-string | ||
231 | * input. | ||
232 | */ | ||
233 | _TYPE( char * ) t_tohex P((char *, const char *, unsigned)); | ||
234 | _TYPE( int ) t_fromhex P((char *, const char *)); | ||
235 | _TYPE( char * ) t_tob64 P((char *, const char *, unsigned)); | ||
236 | _TYPE( int ) t_fromb64 P((char *, const char *)); | ||
237 | |||
238 | /* These functions put their output in a cstr object */ | ||
239 | _TYPE( char * ) t_tohexcstr P((cstr *, const char *, unsigned)); | ||
240 | _TYPE( int ) t_cstrfromhex P((cstr *, const char *)); | ||
241 | _TYPE( char * ) t_tob64cstr P((cstr *, const char *, unsigned)); | ||
242 | _TYPE( int ) t_cstrfromb64 P((cstr *, const char *)); | ||
243 | |||
244 | /* Miscellaneous utilities (moved to t_defines.h) */ | ||
245 | |||
246 | #endif | ||