2 * Copyright (C) 2008 Martin Willi
3 * 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
20 typedef struct private_xcbc_prf_t private_xcbc_prf_t
;
23 * Private data of a xcbc_prf_t object.
25 struct private_xcbc_prf_t
{
28 * Public xcbc_prf_t interface.
33 * xcbc to use for generation.
38 METHOD(prf_t
, get_bytes
, void,
39 private_xcbc_prf_t
*this, chunk_t seed
, u_int8_t
*buffer
)
41 this->xcbc
->get_mac(this->xcbc
, seed
, buffer
);
44 METHOD(prf_t
, allocate_bytes
, void,
45 private_xcbc_prf_t
*this, chunk_t seed
, chunk_t
*chunk
)
49 *chunk
= chunk_alloc(this->xcbc
->get_block_size(this->xcbc
));
50 get_bytes(this, seed
, chunk
->ptr
);
54 get_bytes(this, seed
, NULL
);
58 METHOD(prf_t
, get_block_size
, size_t,
59 private_xcbc_prf_t
*this)
61 return this->xcbc
->get_block_size(this->xcbc
);
64 METHOD(prf_t
, get_key_size
, size_t,
65 private_xcbc_prf_t
*this)
67 /* in xcbc, block and key size are always equal */
68 return this->xcbc
->get_block_size(this->xcbc
);
71 METHOD(prf_t
, set_key
, void,
72 private_xcbc_prf_t
*this, chunk_t key
)
74 this->xcbc
->set_key(this->xcbc
, key
);
77 METHOD(prf_t
, destroy
, void,
78 private_xcbc_prf_t
*this)
80 this->xcbc
->destroy(this->xcbc
);
85 * Described in header.
87 xcbc_prf_t
*xcbc_prf_create(pseudo_random_function_t algo
)
89 private_xcbc_prf_t
*this;
95 xcbc
= xcbc_create(ENCR_AES_CBC
, 16);
107 .get_bytes
= _get_bytes
,
108 .allocate_bytes
= _allocate_bytes
,
109 .get_block_size
= _get_block_size
,
110 .get_key_size
= _get_key_size
,
117 return &this->public;