Implemented bitspender based on the MGF1 mask generator function
[strongswan.git] / src / libstrongswan / crypto / mgf1 / mgf1.h
1 /*
2 * Copyright (C) 2013-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 mgf1
18 * @{ @ingroup ntru_p
19 */
20
21 #ifndef MGF1_H_
22 #define MGF1_H_
23
24 typedef struct mgf1_t mgf1_t;
25
26 #include <library.h>
27
28 /**
29 * Implements the PKCS#1 MGF1 Mask Generation Function based on a hash function
30 * defined in section 10.2.1 of RFC 2437
31 */
32 struct mgf1_t {
33
34 /**
35 * Get the hash size of the underlying hash function
36 *
37 * @return hash size in bytes
38 */
39 size_t (*get_hash_size)(mgf1_t *this);
40
41 /**
42 * Generate a mask pattern and copy it to an output buffer
43 * If the maximum number of requests has been reached, reseeding occurs
44 *
45 * @param mask_len number of mask bytes to generate
46 * @param mask output buffer of minimum size mask_len
47 * @return TRUE if successful
48 */
49 bool (*get_mask)(mgf1_t *this, size_t mask_len, u_char *mask);
50
51 /**
52 * Generate a mask pattern and return it in an allocated chunk
53 *
54 * @param mask_len number of mask bytes to generate
55 * @param mask chunk containing generated mask
56 * @return TRUE if successful
57 */
58 bool (*allocate_mask)(mgf1_t *this, size_t mask_len, chunk_t *mask);
59
60 /**
61 * Destroy the MGF1 object
62 */
63 void (*destroy)(mgf1_t *this);
64 };
65
66 /**
67 * Create an MGF1 object
68 *
69 * @param alg hash algorithm to be used by MGF1
70 * @param seed seed used by MGF1 to generate mask from
71 * @param hash_seed hash seed before using it as a seed for MGF1
72 */
73 mgf1_t *mgf1_create(hash_algorithm_t alg, chunk_t seed,
74 bool hash_seed);
75
76 #endif /** MGF1_H_ @}*/
77