summaryrefslogtreecommitdiff
path: root/lib/gnutls_srp.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@crystal.(none)>2008-06-28 01:25:02 +0300
committerNikos Mavrogiannopoulos <nmav@crystal.(none)>2008-06-28 01:25:02 +0300
commit95c55c0eb57484533f4dd72c10481c66a66a53f2 (patch)
tree3bc580f54abd1775b28415ae8e20aab4fe2baade /lib/gnutls_srp.c
parent0def0a1d7c28de6fd49995755de7b915cf701225 (diff)
downloadgnutls-95c55c0eb57484533f4dd72c10481c66a66a53f2.tar.gz
Initial merge attempt with gnutls_with_ext_mpi
Diffstat (limited to 'lib/gnutls_srp.c')
-rw-r--r--lib/gnutls_srp.c89
1 files changed, 38 insertions, 51 deletions
diff --git a/lib/gnutls_srp.c b/lib/gnutls_srp.c
index 84eb1fd151..35df9dceea 100644
--- a/lib/gnutls_srp.c
+++ b/lib/gnutls_srp.c
@@ -43,12 +43,12 @@
int
_gnutls_srp_gx (opaque * text, size_t textsize, opaque ** result,
- mpi_t g, mpi_t prime, gnutls_alloc_function galloc_func)
+ bigint_t g, bigint_t prime, gnutls_alloc_function galloc_func)
{
- mpi_t x, e;
+ bigint_t x, e;
size_t result_size;
- if (_gnutls_mpi_scan_nz (&x, text, &textsize))
+ if (_gnutls_mpi_scan_nz (&x, text, textsize))
{
gnutls_assert ();
return GNUTLS_E_MPI_SCAN_FAILED;
@@ -66,14 +66,14 @@ _gnutls_srp_gx (opaque * text, size_t textsize, opaque ** result,
_gnutls_mpi_powm (e, g, x, prime);
_gnutls_mpi_release (&x);
- _gnutls_mpi_print (NULL, &result_size, e);
+ _gnutls_mpi_print (e, NULL, &result_size);
if (result != NULL)
{
*result = galloc_func (result_size);
if ((*result) == NULL)
return GNUTLS_E_MEMORY_ERROR;
- _gnutls_mpi_print (*result, &result_size, e);
+ _gnutls_mpi_print (e, *result, &result_size);
}
_gnutls_mpi_release (&e);
@@ -88,23 +88,17 @@ _gnutls_srp_gx (opaque * text, size_t textsize, opaque ** result,
* where k == SHA1(N|g)
* Return: B and if ret_b is not NULL b.
*/
-mpi_t
-_gnutls_calc_srp_B (mpi_t * ret_b, mpi_t g, mpi_t n, mpi_t v)
+bigint_t
+_gnutls_calc_srp_B (bigint_t * ret_b, bigint_t g, bigint_t n, bigint_t v)
{
- mpi_t tmpB = NULL, tmpV = NULL;
- mpi_t b = NULL, B = NULL, k = NULL;
+ bigint_t tmpB = NULL, tmpV = NULL;
+ bigint_t b = NULL, B = NULL, k = NULL;
int bits;
/* calculate: B = (k*v + g^b) % N
*/
bits = _gnutls_mpi_get_nbits (n);
- b = _gnutls_mpi_snew (bits);
- if (b == NULL)
- {
- gnutls_assert ();
- return NULL;
- }
tmpV = _gnutls_mpi_alloc_like (n);
@@ -114,16 +108,16 @@ _gnutls_calc_srp_B (mpi_t * ret_b, mpi_t g, mpi_t n, mpi_t v)
goto error;
}
- _gnutls_mpi_randomize (b, bits, GCRY_STRONG_RANDOM);
+ b = _gnutls_mpi_randomize (NULL, bits, GNUTLS_RND_RANDOM);
- tmpB = _gnutls_mpi_snew (bits);
+ tmpB = _gnutls_mpi_new (bits);
if (tmpB == NULL)
{
gnutls_assert ();
goto error;
}
- B = _gnutls_mpi_snew (bits);
+ B = _gnutls_mpi_new (bits);
if (B == NULL)
{
gnutls_assert ();
@@ -166,21 +160,21 @@ error:
/* This calculates the SHA1(A | B)
* A and B will be left-padded with zeros to fill n_size.
*/
-mpi_t
-_gnutls_calc_srp_u (mpi_t A, mpi_t B, mpi_t n)
+bigint_t
+_gnutls_calc_srp_u (bigint_t A, bigint_t B, bigint_t n)
{
size_t b_size, a_size;
opaque *holder, hd[MAX_HASH_SIZE];
size_t holder_size, hash_size, n_size;
digest_hd_st td;
int ret;
- mpi_t res;
+ bigint_t res;
/* get the size of n in bytes */
- _gnutls_mpi_print (NULL, &n_size, n);
+ _gnutls_mpi_print (n, NULL, &n_size);
- _gnutls_mpi_print (NULL, &a_size, A);
- _gnutls_mpi_print (NULL, &b_size, B);
+ _gnutls_mpi_print (A, NULL, &a_size);
+ _gnutls_mpi_print (B, NULL, &b_size);
if (a_size > n_size || b_size > n_size)
{
@@ -194,8 +188,8 @@ _gnutls_calc_srp_u (mpi_t A, mpi_t B, mpi_t n)
if (holder == NULL)
return NULL;
- _gnutls_mpi_print (&holder[n_size - a_size], &a_size, A);
- _gnutls_mpi_print (&holder[n_size + n_size - b_size], &b_size, B);
+ _gnutls_mpi_print (A, &holder[n_size - a_size], &a_size);
+ _gnutls_mpi_print (B, &holder[n_size + n_size - b_size], &b_size);
ret = _gnutls_hash_init (&td, GNUTLS_MAC_SHA1);
if (ret < 0)
@@ -210,7 +204,7 @@ _gnutls_calc_srp_u (mpi_t A, mpi_t B, mpi_t n)
/* convert the bytes of hd to integer
*/
hash_size = 20; /* SHA */
- ret = _gnutls_mpi_scan_nz (&res, hd, &hash_size);
+ ret = _gnutls_mpi_scan_nz (&res, hd, hash_size);
gnutls_free (holder);
if (ret < 0)
@@ -225,11 +219,11 @@ _gnutls_calc_srp_u (mpi_t A, mpi_t B, mpi_t n)
/* S = (A * v^u) ^ b % N
* this is our shared key (server premaster secret)
*/
-mpi_t
-_gnutls_calc_srp_S1 (mpi_t A, mpi_t b, mpi_t u, mpi_t v, mpi_t n)
+bigint_t
+_gnutls_calc_srp_S1 (bigint_t A, bigint_t b, bigint_t u, bigint_t v, bigint_t n)
{
- mpi_t tmp1 = NULL, tmp2 = NULL;
- mpi_t S = NULL;
+ bigint_t tmp1 = NULL, tmp2 = NULL;
+ bigint_t S = NULL;
S = _gnutls_mpi_alloc_like (n);
if (S == NULL)
@@ -259,24 +253,17 @@ freeall:
/* A = g^a % N
* returns A and a (which is random)
*/
-mpi_t
-_gnutls_calc_srp_A (mpi_t * a, mpi_t g, mpi_t n)
+bigint_t
+_gnutls_calc_srp_A (bigint_t * a, bigint_t g, bigint_t n)
{
- mpi_t tmpa;
- mpi_t A;
+ bigint_t tmpa;
+ bigint_t A;
int bits;
bits = _gnutls_mpi_get_nbits (n);
- tmpa = _gnutls_mpi_snew (bits);
- if (tmpa == NULL)
- {
- gnutls_assert ();
- return NULL;
- }
-
- _gnutls_mpi_randomize (tmpa, bits, GCRY_STRONG_RANDOM);
+ tmpa = _gnutls_mpi_randomize (NULL, bits, GNUTLS_RND_RANDOM);
- A = _gnutls_mpi_snew (bits);
+ A = _gnutls_mpi_new (bits);
if (A == NULL)
{
gnutls_assert ();
@@ -345,11 +332,11 @@ _gnutls_calc_srp_x (char *username, char *password, opaque * salt,
/* S = (B - k*g^x) ^ (a + u * x) % N
* this is our shared key (client premaster secret)
*/
-mpi_t
-_gnutls_calc_srp_S2 (mpi_t B, mpi_t g, mpi_t x, mpi_t a, mpi_t u, mpi_t n)
+bigint_t
+_gnutls_calc_srp_S2 (bigint_t B, bigint_t g, bigint_t x, bigint_t a, bigint_t u, bigint_t n)
{
- mpi_t S = NULL, tmp1 = NULL, tmp2 = NULL;
- mpi_t tmp4 = NULL, tmp3 = NULL, k = NULL;
+ bigint_t S = NULL, tmp1 = NULL, tmp2 = NULL;
+ bigint_t tmp4 = NULL, tmp3 = NULL, k = NULL;
S = _gnutls_mpi_alloc_like (n);
if (S == NULL)
@@ -696,7 +683,7 @@ gnutls_srp_verifier (const char *username, const char *password,
const gnutls_datum_t * generator,
const gnutls_datum_t * prime, gnutls_datum_t * res)
{
- mpi_t _n, _g;
+ bigint_t _n, _g;
int ret;
size_t digest_size = 20, size;
opaque digest[20];
@@ -710,14 +697,14 @@ gnutls_srp_verifier (const char *username, const char *password,
}
size = prime->size;
- if (_gnutls_mpi_scan_nz (&_n, prime->data, &size))
+ if (_gnutls_mpi_scan_nz (&_n, prime->data, size))
{
gnutls_assert ();
return GNUTLS_E_MPI_SCAN_FAILED;
}
size = generator->size;
- if (_gnutls_mpi_scan_nz (&_g, generator->data, &size))
+ if (_gnutls_mpi_scan_nz (&_g, generator->data, size))
{
gnutls_assert ();
return GNUTLS_E_MPI_SCAN_FAILED;