4 * @brief Implementation for hmac_prf_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 #include <crypto/hmac.h>
28 typedef struct private_hmac_prf_t private_hmac_prf_t
;
31 * Private data of a hma_prf_t object.
33 struct private_hmac_prf_t
{
35 * Public hmac_prf_t interface.
40 * Hmac to use for generation.
46 * Implementation of prf_t.get_bytes.
48 static void get_bytes(private_hmac_prf_t
*this, chunk_t seed
, u_int8_t
*buffer
)
50 this->hmac
->get_mac(this->hmac
, seed
, buffer
);
54 * Implementation of prf_t.allocate_bytes.
56 static void allocate_bytes(private_hmac_prf_t
*this, chunk_t seed
, chunk_t
*chunk
)
58 this->hmac
->allocate_mac(this->hmac
, seed
, chunk
);
62 * Implementation of prf_t.get_block_size.
64 static size_t get_block_size(private_hmac_prf_t
*this)
66 return this->hmac
->get_block_size(this->hmac
);
70 * Implementation of prf_t.get_block_size.
72 static size_t get_key_size(private_hmac_prf_t
*this)
74 /* for HMAC prfs, IKEv2 uses block size as key size */
75 return this->hmac
->get_block_size(this->hmac
);
79 * Implementation of prf_t.set_key.
81 static void set_key(private_hmac_prf_t
*this, chunk_t key
)
83 this->hmac
->set_key(this->hmac
, key
);
87 * Implementation of prf_t.destroy.
89 static void destroy(private_hmac_prf_t
*this)
92 this->hmac
->destroy(this->hmac
);
96 * Described in header.
98 hmac_prf_t
*hmac_prf_create(hash_algorithm_t hash_algorithm
)
100 private_hmac_prf_t
*this = malloc_thing(private_hmac_prf_t
);
102 this->public.prf_interface
.get_bytes
= (void (*) (prf_t
*,chunk_t
,u_int8_t
*))get_bytes
;
103 this->public.prf_interface
.allocate_bytes
= (void (*) (prf_t
*,chunk_t
,chunk_t
*))allocate_bytes
;
104 this->public.prf_interface
.get_block_size
= (size_t (*) (prf_t
*))get_block_size
;
105 this->public.prf_interface
.get_key_size
= (size_t (*) (prf_t
*))get_key_size
;
106 this->public.prf_interface
.set_key
= (void (*) (prf_t
*,chunk_t
))set_key
;
107 this->public.prf_interface
.destroy
= (void (*) (prf_t
*))destroy
;
109 this->hmac
= hmac_create(hash_algorithm
);
110 if (this->hmac
== NULL
)
116 return &(this->public);