Remove trailing spaces in test_srp.c and add option to pass NULL

Now, you can pass NULL as username in srp_user_start_authentication, if you
don't need the username (usually in most cases).
master
est31 2015-04-17 06:53:43 +02:00
parent d98a48df06
commit a7057b41dd
3 changed files with 35 additions and 35 deletions

3
srp.c
View File

@ -868,7 +868,8 @@ void srp_user_start_authentication( struct SRPUser * usr, const char ** usernam
mpz_to_bin( usr->A, (unsigned char *) *bytes_A );
usr->bytes_A = *bytes_A;
*username = usr->username;
if ( username )
*username = usr->username;
}

2
srp.h
View File

@ -148,7 +148,7 @@ const unsigned char * srp_user_get_session_key( struct SRPUser * usr, int * key_
int srp_user_get_session_key_length( struct SRPUser * usr );
/* Output: username, bytes_A, len_A */
/* Output: username, bytes_A, len_A. If you don't want it get written, set username to NULL */
void srp_user_start_authentication( struct SRPUser * usr, const char ** username,
const unsigned char ** bytes_A, int * len_A );

View File

@ -29,107 +29,106 @@ int main( int argc, char * argv[] )
{
struct SRPVerifier * ver;
struct SRPUser * usr;
const unsigned char * bytes_s = 0;
const unsigned char * bytes_v = 0;
const unsigned char * bytes_A = 0;
const unsigned char * bytes_B = 0;
const unsigned char * bytes_M = 0;
const unsigned char * bytes_HAMK = 0;
int len_s = 0;
int len_v = 0;
int len_A = 0;
int len_B = 0;
int len_M = 0;
int i;
unsigned long long start;
unsigned long long duration;
const char * username = "testuser";
const char * password = "password";
const char * auth_username = 0;
const char * n_hex = 0;
const char * g_hex = 0;
SRP_HashAlgorithm alg = TEST_HASH;
SRP_NGType ng_type = SRP_NG_8192; //TEST_NG;
if (ng_type == SRP_NG_CUSTOM)
{
n_hex = test_n_hex;
g_hex = test_g_hex;
}
srp_create_salted_verification_key( alg, ng_type, username,
(const unsigned char *)password,
strlen(password),
&bytes_s, &len_s, &bytes_v, &len_v, n_hex, g_hex );
srp_create_salted_verification_key( alg, ng_type, username,
(const unsigned char *)password,
strlen(password),
&bytes_s, &len_s, &bytes_v, &len_v, n_hex, g_hex );
start = get_usec();
for( i = 0; i < NITER; i++ )
{
usr = srp_user_new( alg, ng_type, username, username,
(const unsigned char *)password,
(const unsigned char *)password,
strlen(password), n_hex, g_hex );
srp_user_start_authentication( usr, &auth_username, &bytes_A, &len_A );
srp_user_start_authentication( usr, NULL, &bytes_A, &len_A );
/* User -> Host: (username, bytes_A) */
ver = srp_verifier_new( alg, ng_type, username, bytes_s, len_s, bytes_v, len_v,
ver = srp_verifier_new( alg, ng_type, username, bytes_s, len_s, bytes_v, len_v,
bytes_A, len_A, & bytes_B, &len_B, n_hex, g_hex );
if ( !bytes_B )
{
printf("Verifier SRP-6a safety check violated!\n");
goto cleanup;
}
/* Host -> User: (bytes_s, bytes_B) */
srp_user_process_challenge( usr, bytes_s, len_s, bytes_B, len_B, &bytes_M, &len_M );
if ( !bytes_M )
{
printf("User SRP-6a safety check violation!\n");
goto cleanup;
}
/* User -> Host: (bytes_M) */
srp_verifier_verify_session( ver, bytes_M, &bytes_HAMK );
if ( !bytes_HAMK )
{
printf("User authentication failed!\n");
goto cleanup;
}
/* Host -> User: (HAMK) */
srp_user_verify_session( usr, bytes_HAMK );
if ( !srp_user_is_authenticated(usr) )
{
printf("Server authentication failed!\n");
}
cleanup:
srp_verifier_delete( ver );
srp_user_delete( usr );
}
duration = get_usec() - start;
printf("Usec per call: %d\n", (int)(duration / NITER));
free( (char *)bytes_s );
free( (char *)bytes_v );
return 0;
}