summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/padlock/padlock_rng.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/padlock/padlock_rng.c')
-rw-r--r--src/libstrongswan/plugins/padlock/padlock_rng.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libstrongswan/plugins/padlock/padlock_rng.c b/src/libstrongswan/plugins/padlock/padlock_rng.c
index 8ff46081b..3d805df9d 100644
--- a/src/libstrongswan/plugins/padlock/padlock_rng.c
+++ b/src/libstrongswan/plugins/padlock/padlock_rng.c
@@ -53,15 +53,15 @@ struct private_padlock_rng_t {
*/
static void rng(char *buf, int len, int quality)
{
- while (len > 0)
+ while (len > 0)
{
int status;
/* run XSTORE until we have all bytes needed. We do not use REP, as
* this should not be performance critical and it's easier this way. */
asm volatile (
- ".byte 0x0F,0xA7,0xC0 \n\t"
- : "=D"(buf), "=a"(status)
+ ".byte 0x0F,0xA7,0xC0 \n\t"
+ : "=D"(buf), "=a"(status)
: "d"(quality), "D"(buf));
/* bits[0..4] of status word contains the number of bytes read */
@@ -69,11 +69,8 @@ static void rng(char *buf, int len, int quality)
}
}
-/**
- * Implementation of padlock_rng_t.allocate_bytes.
- */
-static void allocate_bytes(private_padlock_rng_t *this, size_t bytes,
- chunk_t *chunk)
+METHOD(rng_t, allocate_bytes, void,
+ private_padlock_rng_t *this, size_t bytes, chunk_t *chunk)
{
chunk->len = bytes;
/* padlock requires some additional bytes */
@@ -82,11 +79,8 @@ static void allocate_bytes(private_padlock_rng_t *this, size_t bytes,
rng(chunk->ptr, chunk->len, this->quality);
}
-/**
- * Implementation of padlock_rng_t.get_bytes.
- */
-static void get_bytes(private_padlock_rng_t *this, size_t bytes,
- u_int8_t *buffer)
+METHOD(rng_t, get_bytes, void,
+ private_padlock_rng_t *this, size_t bytes, u_int8_t *buffer)
{
chunk_t chunk;
@@ -96,10 +90,8 @@ static void get_bytes(private_padlock_rng_t *this, size_t bytes,
chunk_clear(&chunk);
}
-/**
- * Implementation of padlock_rng_t.destroy.
- */
-static void destroy(private_padlock_rng_t *this)
+METHOD(rng_t, destroy, void,
+ private_padlock_rng_t *this)
{
free(this);
}
@@ -109,11 +101,17 @@ static void destroy(private_padlock_rng_t *this)
*/
padlock_rng_t *padlock_rng_create(rng_quality_t quality)
{
- private_padlock_rng_t *this = malloc_thing(private_padlock_rng_t);
-
- this->public.rng.get_bytes = (void (*) (rng_t *, size_t, u_int8_t*)) get_bytes;
- this->public.rng.allocate_bytes = (void (*) (rng_t *, size_t, chunk_t*)) allocate_bytes;
- this->public.rng.destroy = (void (*) (rng_t *))destroy;
+ private_padlock_rng_t *this;
+
+ INIT(this,
+ .public = {
+ .rng = {
+ .get_bytes = _get_bytes,
+ .allocate_bytes = _allocate_bytes,
+ .destroy = _destroy,
+ },
+ },
+ );
/* map RNG quality to Padlock quality factor */
switch (quality)
@@ -127,8 +125,10 @@ padlock_rng_t *padlock_rng_create(rng_quality_t quality)
case RNG_TRUE:
this->quality = PADLOCK_QF3;
break;
+ default:
+ free(this);
+ return NULL;
}
-
return &this->public;
}