summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/fips_prf/fips_prf.c
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2010-02-23 10:34:14 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2010-02-23 10:34:14 +0000
commited7d79f96177044949744da10f4431c1d6242241 (patch)
tree3aabaa55ed3b5291daef891cfee9befb5235e2b8 /src/libstrongswan/plugins/fips_prf/fips_prf.c
parent7410d3c6d6a9a1cd7aa55083c938946af6ff9498 (diff)
downloadvyos-strongswan-ed7d79f96177044949744da10f4431c1d6242241.tar.gz
vyos-strongswan-ed7d79f96177044949744da10f4431c1d6242241.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.3.6)
Diffstat (limited to 'src/libstrongswan/plugins/fips_prf/fips_prf.c')
-rw-r--r--src/libstrongswan/plugins/fips_prf/fips_prf.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/libstrongswan/plugins/fips_prf/fips_prf.c b/src/libstrongswan/plugins/fips_prf/fips_prf.c
index be28f10bc..123d2a244 100644
--- a/src/libstrongswan/plugins/fips_prf/fips_prf.c
+++ b/src/libstrongswan/plugins/fips_prf/fips_prf.c
@@ -29,22 +29,22 @@ struct private_fips_prf_t {
* Public fips_prf_t interface.
*/
fips_prf_t public;
-
+
/**
* key of prf function, "b" long
*/
u_int8_t *key;
-
+
/**
* size of "b" in bytes
*/
size_t b;
-
+
/**
* Keyed SHA1 prf: It does not use SHA1Final operation
*/
prf_t *keyed_prf;
-
+
/**
* G function, either SHA1 or DES
*/
@@ -57,11 +57,11 @@ struct private_fips_prf_t {
static void add_mod(size_t length, u_int8_t a[], u_int8_t b[], u_int8_t sum[])
{
int i, c = 0;
-
+
for(i = length - 1; i >= 0; i--)
{
u_int32_t tmp;
-
+
tmp = a[i] + b[i] + c;
sum[i] = 0xff & tmp;
c = tmp >> 8;
@@ -114,14 +114,13 @@ static void get_bytes(private_fips_prf_t *this, chunk_t seed, u_int8_t w[])
u_int8_t sum[this->b];
u_int8_t *xkey = this->key;
u_int8_t one[this->b];
- chunk_t xval_chunk = chunk_from_buf(xval);
-
+
memset(one, 0, this->b);
one[this->b - 1] = 0x01;
-
+
/* 3.1 */
chunk_mod(this->b, seed, xseed);
-
+
/* 3.2 */
for (i = 0; i < 2; i++) /* twice */
{
@@ -129,14 +128,14 @@ static void get_bytes(private_fips_prf_t *this, chunk_t seed, u_int8_t w[])
add_mod(this->b, xkey, xseed, xval);
DBG3("XVAL %b", xval, this->b);
/* b. wi = G(t, XVAL ) */
- this->g(this, xval_chunk, &w[i * this->b]);
+ this->g(this, chunk_create(xval, this->b), &w[i * this->b]);
DBG3("w[%d] %b", i, &w[i * this->b], this->b);
/* c. XKEY = (1 + XKEY + wi) mod 2b */
add_mod(this->b, xkey, &w[i * this->b], sum);
add_mod(this->b, sum, one, xkey);
DBG3("XKEY %b", xkey, this->b);
}
-
+
/* 3.3 done already, mod q not used */
}
@@ -179,7 +178,7 @@ static void set_key(private_fips_prf_t *this, chunk_t key)
void g_sha1(private_fips_prf_t *this, chunk_t c, u_int8_t res[])
{
u_int8_t buf[64];
-
+
if (c.len < sizeof(buf))
{
/* pad c with zeros */
@@ -193,7 +192,7 @@ void g_sha1(private_fips_prf_t *this, chunk_t c, u_int8_t res[])
/* not more than 512 bits can be G()-ed */
c.len = sizeof(buf);
}
-
+
/* use the keyed hasher, but use an empty key to use SHA1 IV */
this->keyed_prf->set_key(this->keyed_prf, chunk_empty);
this->keyed_prf->get_bytes(this->keyed_prf, c, res);
@@ -215,14 +214,14 @@ static void destroy(private_fips_prf_t *this)
fips_prf_t *fips_prf_create(pseudo_random_function_t algo)
{
private_fips_prf_t *this = malloc_thing(private_fips_prf_t);
-
+
this->public.prf_interface.get_bytes = (void (*) (prf_t *,chunk_t,u_int8_t*))get_bytes;
this->public.prf_interface.allocate_bytes = (void (*) (prf_t*,chunk_t,chunk_t*))allocate_bytes;
this->public.prf_interface.get_block_size = (size_t (*) (prf_t*))get_block_size;
this->public.prf_interface.get_key_size = (size_t (*) (prf_t*))get_key_size;
this->public.prf_interface.set_key = (void (*) (prf_t *,chunk_t))set_key;
this->public.prf_interface.destroy = (void (*) (prf_t *))destroy;
-
+
switch (algo)
{
case PRF_FIPS_SHA1_160:
@@ -244,7 +243,7 @@ fips_prf_t *fips_prf_create(pseudo_random_function_t algo)
return NULL;
}
this->key = malloc(this->b);
-
+
return &this->public;
}