Implemented bitspender based on the MGF1 mask generator function
[strongswan.git] / src / libstrongswan / crypto / mgf1 / mgf1_bitspender.h
1 /*
2 * Copyright (C) 2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 /**
17 * @defgroup mgf1_bitspender mgf1_bitspender
18 * @{ @ingroup bliss_p
19 */
20
21 #ifndef MGF1_BITSPENDER_H_
22 #define MGF1_BITSPENDER_H_
23
24 #include <library.h>
25 #include <crypto/hashers/hasher.h>
26
27 typedef struct mgf1_bitspender_t mgf1_bitspender_t;
28
29 #define MGF1_BITSPENDER_ERROR 0xffffffff
30
31 /**
32 * Generates a given number of pseudo-random bits at a time using MFG1
33 */
34 struct mgf1_bitspender_t {
35
36 /**
37 * Get pseudo-random bits
38 *
39 * @param bits_needed Number of needed bits (1..31)
40 * @result Return between 1 and 31 pseudo-random bits
41 */
42 uint32_t (*get_bits)(mgf1_bitspender_t *this, int bits_needed);
43
44 /**
45 * Destroy mgf1_bitspender_t object
46 */
47 void (*destroy)(mgf1_bitspender_t *this);
48 };
49
50 /**
51 * Create a mgf1_bitspender_t object
52 *
53 * @param alg Hash algorithm to be used with MGF1
54 * @param seed Seed used to initialize MGF1
55 * @param hash_seed Hash seed before using it as a seed for MFG1
56 */
57 mgf1_bitspender_t *mgf1_bitspender_create(hash_algorithm_t alg, chunk_t seed,
58 bool hash_seed);
59
60 #endif /** MGF1_BITSPENDER_H_ @}*/