| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "config.h" |
| 9 |
#include "crypto/srp.h" |
| 10 |
#include "crypto/srp_constants.h" |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
#if HAVE_MBEDTLS |
| 15 |
#include <mbedtls/base64.h> |
| 16 |
#elif HAVE_NETTLE |
| 17 |
#include <nettle/base64.h> |
| 18 |
#endif |
| 19 |
|
| 20 |
int create_and_print(const char *username, const char *password, const char *n_hex, const char* g_hex, bool correct) { |
| 21 |
uint8_t *salt = NULL; |
| 22 |
size_t salt_len = 0; |
| 23 |
uint8_t *verifier = NULL; |
| 24 |
size_t verifier_len = 0; |
| 25 |
int ret = librist_crypto_srp_create_verifier(n_hex, g_hex, username, password, &salt, &salt_len, &verifier, &verifier_len, correct); |
| 26 |
if (ret != 0) |
| 27 |
return ret; |
| 28 |
|
| 29 |
char salt64[1024] = {0}; |
| 30 |
char verifier64[1024] = {0}; |
| 31 |
#if HAVE_MBEDTLS |
| 32 |
size_t salt_written_len = 0; |
| 33 |
mbedtls_base64_encode((unsigned char*)salt64, sizeof(salt64), &salt_written_len, salt, salt_len); |
| 34 |
size_t verifier_written_len = 0; |
| 35 |
mbedtls_base64_encode((unsigned char*)verifier64, sizeof(verifier64), &verifier_written_len, verifier, verifier_len); |
| 36 |
#elif HAVE_NETTLE |
| 37 |
nettle_base64_encode_raw(salt64, salt_len, salt); |
| 38 |
nettle_base64_encode_raw(verifier64, verifier_len, verifier); |
| 39 |
#endif |
| 40 |
free(salt); |
| 41 |
free(verifier); |
| 42 |
printf("%s:%s:%s:3:%d\n", username, verifier64, salt64, correct? 1 :0); |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
int main(int argc, char *argv[]) |
| 47 |
{ |
| 48 |
if (argc != 3) { |
| 49 |
fprintf(stderr, "Usage: %s [username] [password]\n", argv[0]); |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
const char *username = argv[1]; |
| 54 |
const char *password = argv[2]; |
| 55 |
const char *n_hex = NULL; |
| 56 |
const char *g_hex = NULL; |
| 57 |
|
| 58 |
librist_get_ng_constants(LIBRIST_SRP_NG_DEFAULT, &n_hex, &g_hex); |
| 59 |
#if HAVE_MBEDTLS |
| 60 |
create_and_print(username, password, n_hex, g_hex, false); |
| 61 |
#endif |
| 62 |
create_and_print(username, password, n_hex, g_hex, true); |
| 63 |
} |