2 * Copyright (C) 2012 Adrian-Ken Rueegsegger
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "nonce_nonceg.h"
18 #include <utils/debug.h>
20 typedef struct private_nonce_nonceg_t private_nonce_nonceg_t
;
23 * Private data of a nonce_nonceg_t object.
25 struct private_nonce_nonceg_t
{
28 * Public nonce_nonceg_t interface.
30 nonce_nonceg_t
public;
33 * Random number generator
38 METHOD(nonce_gen_t
, get_nonce
, bool,
39 private_nonce_nonceg_t
*this, size_t size
, uint8_t *buffer
)
41 return this->rng
->get_bytes(this->rng
, size
, buffer
);
44 METHOD(nonce_gen_t
, allocate_nonce
, bool,
45 private_nonce_nonceg_t
*this, size_t size
, chunk_t
*chunk
)
47 return this->rng
->allocate_bytes(this->rng
, size
, chunk
);
50 METHOD(nonce_gen_t
, destroy
, void,
51 private_nonce_nonceg_t
*this)
53 DESTROY_IF(this->rng
);
58 * Described in header.
60 nonce_nonceg_t
*nonce_nonceg_create()
62 private_nonce_nonceg_t
*this;
67 .get_nonce
= _get_nonce
,
68 .allocate_nonce
= _allocate_nonce
,
74 this->rng
= lib
->crypto
->create_rng(lib
->crypto
, NONCE_RNG_QUALITY
);
77 DBG1(DBG_LIB
, "no RNG found for quality %N", rng_quality_names
,