srp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,381 @@
1
+ /*
2
+ * Secure Remote Password 6a implementation
3
+ * Copyright (c) 2010 Tom Cocagne. All rights reserved.
4
+ * https://github.com/cocagne/csrp
5
+ *
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2013 Tom Cocagne
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ * this software and associated documentation files (the "Software"), to deal in
12
+ * the Software without restriction, including without limitation the rights to
13
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14
+ * of the Software, and to permit persons to whom the Software is furnished to do
15
+ * so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*
31
+ *
32
+ * Purpose: This is a direct implementation of the Secure Remote Password
33
+ * Protocol version 6a as described by
34
+ * http://srp.stanford.edu/design.html
35
+ *
36
+ * Author: tom.cocagne@gmail.com (Tom Cocagne)
37
+ *
38
+ * Dependencies: OpenSSL (and Advapi32.lib on Windows)
39
+ *
40
+ * Usage: Refer to test_srp.c for a demonstration
41
+ *
42
+ * Notes:
43
+ * This library allows multiple combinations of hashing algorithms and
44
+ * prime number constants. For authentication to succeed, the hash and
45
+ * prime number constants must match between
46
+ * srp_create_salted_verification_key(), srp_user_new(),
47
+ * and srp_verifier_new(). A recommended approach is to determine the
48
+ * desired level of security for an application and globally define the
49
+ * hash and prime number constants to the predetermined values.
50
+ *
51
+ * As one might suspect, more bits means more security. As one might also
52
+ * suspect, more bits also means more processing time. The test_srp.c
53
+ * program can be easily modified to profile various combinations of
54
+ * hash & prime number pairings.
55
+ */
56
+
57
+ #ifndef SRP_H
58
+ #define SRP_H
59
+
60
+
61
+ #include <openssl/bn.h>
62
+ #include <openssl/sha.h>
63
+ #include <openssl/crypto.h>
64
+ #include <openssl/rand.h>
65
+
66
+
67
+ struct SRPVerifier;
68
+ struct SRPUser;
69
+
70
+ typedef enum
71
+ {
72
+ SRP_NG_1024,
73
+ SRP_NG_2048,
74
+ SRP_NG_4096,
75
+ SRP_NG_8192,
76
+ SRP_NG_CUSTOM
77
+ } SRP_NGType;
78
+
79
+ typedef enum
80
+ {
81
+ SRP_SHA1,
82
+ SRP_SHA224,
83
+ SRP_SHA256,
84
+ SRP_SHA384,
85
+ SRP_SHA512
86
+ } SRP_HashAlgorithm;
87
+
88
+
89
+ /* This library will automatically seed the OpenSSL random number generator
90
+ * using cryptographically sound random data on Windows & Linux. If this is
91
+ * undesirable behavior or the host OS does not provide a /dev/urandom file,
92
+ * this function may be called to seed the random number generator with
93
+ * alternate data.
94
+ *
95
+ * The random data should include at least as many bits of entropy as the
96
+ * largest hash function used by the application. So, for example, if a
97
+ * 512-bit hash function is used, the random data requies at least 512
98
+ * bits of entropy.
99
+ *
100
+ * Passing a null pointer to this function will cause this library to skip
101
+ * seeding the random number generator. This is only legitimate if it is
102
+ * absolutely known that the OpenSSL random number generator has already
103
+ * been sufficiently seeded within the running application.
104
+ *
105
+ * Notes:
106
+ * * This function is optional on Windows & Linux and mandatory on all
107
+ * other platforms.
108
+ */
109
+ void srp_random_seed( const unsigned char * random_data, int data_length );
110
+
111
+
112
+ /* Out: bytes_s, len_s, bytes_v, len_v
113
+ *
114
+ * The caller is responsible for freeing the memory allocated for bytes_s and bytes_v
115
+ *
116
+ * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type.
117
+ * If provided, they must contain ASCII text of the hexidecimal notation.
118
+ */
119
+ void srp_create_salted_verification_key( SRP_HashAlgorithm alg,
120
+ SRP_NGType ng_type, const char * username,
121
+ const unsigned char * password, int len_password,
122
+ const unsigned char * bytes_s,
123
+ const unsigned char ** bytes_v, int * len_v,
124
+ const char * n_hex, const char * g_hex );
125
+
126
+
127
+ /* Out: bytes_B, len_B.
128
+ *
129
+ * On failure, bytes_B will be set to NULL and len_B will be set to 0
130
+ *
131
+ * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type
132
+ */
133
+ struct SRPVerifier * srp_verifier_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username,
134
+ const unsigned char * bytes_s, int len_s,
135
+ const unsigned char * bytes_v, int len_v,
136
+ const unsigned char * bytes_A, int len_A,
137
+ const unsigned char ** bytes_B, int * len_B,
138
+ const char * n_hex, const char * g_hex );
139
+
140
+
141
+ void srp_verifier_delete( struct SRPVerifier * ver );
142
+
143
+
144
+ int srp_verifier_is_authenticated( struct SRPVerifier * ver );
145
+
146
+
147
+ const char * srp_verifier_get_username( struct SRPVerifier * ver );
148
+
149
+ /* key_length may be null */
150
+ const unsigned char * srp_verifier_get_session_key( struct SRPVerifier * ver, int * key_length );
151
+
152
+
153
+ int srp_verifier_get_session_key_length( struct SRPVerifier * ver );
154
+
155
+
156
+ /* user_M must be exactly srp_verifier_get_session_key_length() bytes in size */
157
+ void srp_verifier_verify_session( struct SRPVerifier * ver,
158
+ const unsigned char * user_M,
159
+ const unsigned char ** bytes_HAMK );
160
+
161
+ /*******************************************************************************/
162
+
163
+ /* The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type */
164
+ struct SRPUser * srp_user_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username,
165
+ const unsigned char * bytes_password, int len_password,
166
+ const char * n_hex, const char * g_hex );
167
+
168
+ void srp_user_delete( struct SRPUser * usr );
169
+
170
+ int srp_user_is_authenticated( struct SRPUser * usr);
171
+
172
+
173
+ const char * srp_user_get_username( struct SRPUser * usr );
174
+ /*
175
+ * Secure Remote Password 6a implementation
176
+ * Copyright (c) 2010 Tom Cocagne. All rights reserved.
177
+ * https://github.com/cocagne/csrp
178
+ *
179
+ * The MIT License (MIT)
180
+ *
181
+ * Copyright (c) 2013 Tom Cocagne
182
+ *
183
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
184
+ * this software and associated documentation files (the "Software"), to deal in
185
+ * the Software without restriction, including without limitation the rights to
186
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
187
+ * of the Software, and to permit persons to whom the Software is furnished to do
188
+ * so, subject to the following conditions:
189
+ *
190
+ * The above copyright notice and this permission notice shall be included in all
191
+ * copies or substantial portions of the Software.
192
+ *
193
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
194
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
195
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
196
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
198
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
199
+ * SOFTWARE.
200
+ *
201
+ */
202
+
203
+ /*
204
+ *
205
+ * Purpose: This is a direct implementation of the Secure Remote Password
206
+ * Protocol version 6a as described by
207
+ * http://srp.stanford.edu/design.html
208
+ *
209
+ * Author: tom.cocagne@gmail.com (Tom Cocagne)
210
+ *
211
+ * Dependencies: OpenSSL (and Advapi32.lib on Windows)
212
+ *
213
+ * Usage: Refer to test_srp.c for a demonstration
214
+ *
215
+ * Notes:
216
+ * This library allows multiple combinations of hashing algorithms and
217
+ * prime number constants. For authentication to succeed, the hash and
218
+ * prime number constants must match between
219
+ * srp_create_salted_verification_key(), srp_user_new(),
220
+ * and srp_verifier_new(). A recommended approach is to determine the
221
+ * desired level of security for an application and globally define the
222
+ * hash and prime number constants to the predetermined values.
223
+ *
224
+ * As one might suspect, more bits means more security. As one might also
225
+ * suspect, more bits also means more processing time. The test_srp.c
226
+ * program can be easily modified to profile various combinations of
227
+ * hash & prime number pairings.
228
+ */
229
+
230
+ #ifndef SRP_H
231
+ #define SRP_H
232
+
233
+
234
+ struct SRPVerifier;
235
+ struct SRPUser;
236
+
237
+ typedef enum
238
+ {
239
+ SRP_NG_1024,
240
+ SRP_NG_2048,
241
+ SRP_NG_4096,
242
+ SRP_NG_8192,
243
+ SRP_NG_CUSTOM
244
+ } SRP_NGType;
245
+
246
+ typedef enum
247
+ {
248
+ SRP_SHA1,
249
+ SRP_SHA224,
250
+ SRP_SHA256,
251
+ SRP_SHA384,
252
+ SRP_SHA512
253
+ } SRP_HashAlgorithm;
254
+
255
+
256
+ /* This library will automatically seed the OpenSSL random number generator
257
+ * using cryptographically sound random data on Windows & Linux. If this is
258
+ * undesirable behavior or the host OS does not provide a /dev/urandom file,
259
+ * this function may be called to seed the random number generator with
260
+ * alternate data.
261
+ *
262
+ * The random data should include at least as many bits of entropy as the
263
+ * largest hash function used by the application. So, for example, if a
264
+ * 512-bit hash function is used, the random data requies at least 512
265
+ * bits of entropy.
266
+ *
267
+ * Passing a null pointer to this function will cause this library to skip
268
+ * seeding the random number generator. This is only legitimate if it is
269
+ * absolutely known that the OpenSSL random number generator has already
270
+ * been sufficiently seeded within the running application.
271
+ *
272
+ * Notes:
273
+ * * This function is optional on Windows & Linux and mandatory on all
274
+ * other platforms.
275
+ */
276
+ void srp_random_seed( const unsigned char * random_data, int data_length );
277
+
278
+
279
+ /* Out: bytes_s, len_s, bytes_v, len_v
280
+ *
281
+ * The caller is responsible for freeing the memory allocated for bytes_s and bytes_v
282
+ *
283
+ * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type.
284
+ * If provided, they must contain ASCII text of the hexidecimal notation.
285
+ */
286
+ void srp_create_salted_verification_key( SRP_HashAlgorithm alg,
287
+ SRP_NGType ng_type, const char * username,
288
+ const unsigned char * password, int len_password,
289
+ const unsigned char * bytes_s, int * len_s,
290
+ const unsigned char ** bytes_v, int * len_v,
291
+ const char * n_hex, const char * g_hex );
292
+
293
+
294
+ /* Out: bytes_B, len_B.
295
+ *
296
+ * On failure, bytes_B will be set to NULL and len_B will be set to 0
297
+ *
298
+ * The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type
299
+ */
300
+ struct SRPVerifier * srp_verifier_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username,
301
+ const unsigned char * bytes_s, int len_s,
302
+ const unsigned char * bytes_v, int len_v,
303
+ const unsigned char * bytes_A, int len_A,
304
+ const unsigned char ** bytes_B, int * len_B,
305
+ const char * n_hex, const char * g_hex );
306
+
307
+
308
+ void srp_verifier_delete( struct SRPVerifier * ver );
309
+
310
+
311
+ int srp_verifier_is_authenticated( struct SRPVerifier * ver );
312
+
313
+
314
+ const char * srp_verifier_get_username( struct SRPVerifier * ver );
315
+
316
+ /* key_length may be null */
317
+ const unsigned char * srp_verifier_get_session_key( struct SRPVerifier * ver, int * key_length );
318
+
319
+
320
+ int srp_verifier_get_session_key_length( struct SRPVerifier * ver );
321
+
322
+
323
+ /* user_M must be exactly srp_verifier_get_session_key_length() bytes in size */
324
+ void srp_verifier_verify_session( struct SRPVerifier * ver,
325
+ const unsigned char * user_M,
326
+ const unsigned char ** bytes_HAMK );
327
+
328
+ /*******************************************************************************/
329
+
330
+ /* The n_hex and g_hex parameters should be 0 unless SRP_NG_CUSTOM is used for ng_type */
331
+ struct SRPUser * srp_user_new( SRP_HashAlgorithm alg, SRP_NGType ng_type, const char * username,
332
+ const unsigned char * bytes_password, int len_password,
333
+ const char * n_hex, const char * g_hex );
334
+
335
+ void srp_user_delete( struct SRPUser * usr );
336
+
337
+ int srp_user_is_authenticated( struct SRPUser * usr);
338
+
339
+
340
+ const char * srp_user_get_username( struct SRPUser * usr );
341
+
342
+ /* key_length may be null */
343
+ const unsigned char * srp_user_get_session_key( struct SRPUser * usr, int * key_length );
344
+
345
+ int srp_user_get_session_key_length( struct SRPUser * usr );
346
+
347
+ /* Output: username, bytes_A, len_A */
348
+ void srp_user_start_authentication( struct SRPUser * usr, const char ** username,
349
+ const unsigned char ** bytes_A, int * len_A );
350
+
351
+ /* Output: bytes_M, len_M (len_M may be null and will always be
352
+ * srp_user_get_session_key_length() bytes in size) */
353
+ void srp_user_process_challenge( struct SRPUser * usr,
354
+ const unsigned char * bytes_s, int len_s,
355
+ const unsigned char * bytes_B, int len_B,
356
+ const unsigned char ** bytes_M, int * len_M );
357
+
358
+ /* bytes_HAMK must be exactly srp_user_get_session_key_length() bytes in size */
359
+ void srp_user_verify_session( struct SRPUser * usr, const unsigned char * bytes_HAMK );
360
+
361
+ #endif /* Include Guard */
362
+ /* key_length may be null */
363
+ const unsigned char * srp_user_get_session_key( struct SRPUser * usr, int * key_length );
364
+
365
+ int srp_user_get_session_key_length( struct SRPUser * usr );
366
+
367
+ /* Output: username, bytes_A, len_A */
368
+ void srp_user_start_authentication( struct SRPUser * usr, const char ** username,
369
+ const unsigned char ** bytes_A, int * len_A );
370
+
371
+ /* Output: bytes_M, len_M (len_M may be null and will always be
372
+ * srp_user_get_session_key_length() bytes in size) */
373
+ void srp_user_process_challenge( struct SRPUser * usr,
374
+ const unsigned char * bytes_s, int len_s,
375
+ const unsigned char * bytes_B, int len_B,
376
+ const unsigned char ** bytes_M, int * len_M );
377
+
378
+ /* bytes_HAMK must be exactly srp_user_get_session_key_length() bytes in size */
379
+ void srp_user_verify_session( struct SRPUser * usr, const unsigned char * bytes_HAMK );
380
+
381
+ #endif /* Include Guard */
@@ -0,0 +1,2 @@
1
+ require 'srp/native'
2
+ require 'srp/version'
@@ -0,0 +1,3 @@
1
+ module SRP
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Louis Mullie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.12.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.12.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! ' Ruby wrapper around a C interface to the OpenSSL implementation of
47
+ the Secure Remote Password protocol, version 6-A. '
48
+ email:
49
+ - louis.mullie@gmail.com
50
+ executables: []
51
+ extensions:
52
+ - ext/srp/extconf.rb
53
+ extra_rdoc_files: []
54
+ files:
55
+ - lib/srp/version.rb
56
+ - lib/srp.rb
57
+ - ext/srp/native.c
58
+ - ext/srp/srp.c
59
+ - ext/srp/srp.h
60
+ - ext/srp/extconf.rb
61
+ homepage: https://github.com/symeapp/srp
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.25
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Ruby wrapper around a C implementation of the SRP protocol
85
+ test_files: []