Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 872e681c00a713e840ebed77a4e05fa0e181f16f authored by Matt Caswell on 15 October 2014, 12:54:46 UTC, committed by Matt Caswell on 15 October 2014, 12:54:46 UTC
Prepare for 1.0.1j release
Reviewed-by: Stephen Henson <steve@openssl.org>
1 parent 38b71ba
  • Files
  • Changes
  • bf85a51
  • /
  • crypto
  • /
  • srp
  • /
  • srptest.c
Raw File
Cook and download a directory from the Software Heritage Vault

You have requested the cooking of the directory with identifier None into a standard tar.gz archive.

Are you sure you want to continue ?

Download a directory from the Software Heritage Vault

You have requested the download of the directory with identifier None as a standard tar.gz archive.

Are you sure you want to continue ?

Cook and download a revision from the Software Heritage Vault

You have requested the cooking of the history heading to revision with identifier swh:1:rev:872e681c00a713e840ebed77a4e05fa0e181f16f into a bare git archive.

Are you sure you want to continue ?

Download a revision from the Software Heritage Vault

You have requested the download of the history heading to revision with identifier swh:1:rev:872e681c00a713e840ebed77a4e05fa0e181f16f as a bare git archive.

Are you sure you want to continue ?

Invalid Email !

The provided email is not well-formed.

Download link has expired

The requested archive is no longer available for download from the Software Heritage Vault.

Do you want to cook it again ?

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • content
revision badge
swh:1:rev:872e681c00a713e840ebed77a4e05fa0e181f16f
content badge Iframe embedding
swh:1:cnt:04b66b454416339d3768ee0fd097f5b2207e2a3e
srptest.c
#include <openssl/opensslconf.h>
#ifdef OPENSSL_NO_SRP

#include <stdio.h>

int main(int argc, char *argv[])
	{
	printf("No SRP support\n");
	return(0);
	}

#else

#include <openssl/srp.h>
#include <openssl/rand.h>
#include <openssl/err.h>

static void showbn(const char *name, const BIGNUM *bn)
	{
	fputs(name, stdout);
	fputs(" = ", stdout);
	BN_print_fp(stdout, bn);
	putc('\n', stdout);
	}

#define RANDOM_SIZE 32	/* use 256 bits on each side */

static int run_srp(const char *username, const char *client_pass, const char *server_pass)
	{
	int ret=-1;
	BIGNUM *s = NULL;
	BIGNUM *v = NULL;
	BIGNUM *a = NULL;
	BIGNUM *b = NULL;
	BIGNUM *u = NULL;
	BIGNUM *x = NULL;
	BIGNUM *Apub = NULL;
	BIGNUM *Bpub = NULL;
	BIGNUM *Kclient = NULL;
	BIGNUM *Kserver = NULL;
	unsigned char rand_tmp[RANDOM_SIZE];
	/* use builtin 1024-bit params */
	SRP_gN *GN = SRP_get_default_gN("1024");

	if(GN == NULL)
		{
		fprintf(stderr, "Failed to get SRP parameters\n");
		return -1;
		}
	/* Set up server's password entry */
	if(!SRP_create_verifier_BN(username, server_pass, &s, &v, GN->N, GN->g))
		{
		fprintf(stderr, "Failed to create SRP verifier\n");
		return -1;
		}

	showbn("N", GN->N);
	showbn("g", GN->g);
	showbn("Salt", s);
	showbn("Verifier", v);

	/* Server random */
	RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp));
	b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);
	/* TODO - check b != 0 */
	showbn("b", b);

	/* Server's first message */
	Bpub = SRP_Calc_B(b, GN->N, GN->g, v);
	showbn("B", Bpub);

	if(!SRP_Verify_B_mod_N(Bpub, GN->N))
		{
		fprintf(stderr, "Invalid B\n");
		return -1;
		}

	/* Client random */
	RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp));
	a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);
	/* TODO - check a != 0 */
	showbn("a", a);

	/* Client's response */
	Apub = SRP_Calc_A(a, GN->N, GN->g);
	showbn("A", Apub);

	if(!SRP_Verify_A_mod_N(Apub, GN->N))
		{
		fprintf(stderr, "Invalid A\n");
		return -1;
		}

	/* Both sides calculate u */
	u = SRP_Calc_u(Apub, Bpub, GN->N);

	/* Client's key */
	x = SRP_Calc_x(s, username, client_pass);
	Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);
	showbn("Client's key", Kclient);

	/* Server's key */
	Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);
	showbn("Server's key", Kserver);

	if(BN_cmp(Kclient, Kserver) == 0)
		{
		ret = 0;
		}
	else
		{
		fprintf(stderr, "Keys mismatch\n");
		ret = 1;
		}

	BN_clear_free(Kclient);
	BN_clear_free(Kserver);
	BN_clear_free(x);
	BN_free(u);
	BN_free(Apub);
	BN_clear_free(a);
	BN_free(Bpub);
	BN_clear_free(b);
	BN_free(s);
	BN_clear_free(v);

	return ret;
	}

int main(int argc, char **argv)
	{
	BIO *bio_err;
	bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);

	CRYPTO_malloc_debug_init();
	CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
	CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);

	ERR_load_crypto_strings();

	/* "Negative" test, expect a mismatch */
	if(run_srp("alice", "password1", "password2") == 0)
		{
		fprintf(stderr, "Mismatched SRP run failed\n");
		return 1;
		}

	/* "Positive" test, should pass */
	if(run_srp("alice", "password", "password") != 0)
		{
		fprintf(stderr, "Plain SRP run failed\n");
		return 1;
		}

	CRYPTO_cleanup_all_ex_data();
	ERR_remove_thread_state(NULL);
	ERR_free_strings();
	CRYPTO_mem_leaks(bio_err);

	return 0;
	}
#endif
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top