]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/libstrongswan/crypto/xofs/xof.h
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libstrongswan / crypto / xofs / xof.h
1 /*
2 * Copyright (C) 2017 Tobias Brunner
3 * Copyright (C) 2016 Andreas Steffen
4 *
5 * Copyright (C) secunet Security Networks AG
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup xof xof
20 * @{ @ingroup crypto
21 */
22
23 #ifndef XOF_H_
24 #define XOF_H_
25
26 typedef enum ext_out_function_t ext_out_function_t;
27 typedef struct xof_t xof_t;
28
29 #include <library.h>
30
31 /**
32 * Extendable Output Functions.
33 */
34 enum ext_out_function_t {
35 XOF_UNDEFINED,
36 /** RFC 8017 PKCS#1 */
37 XOF_MGF1_SHA1,
38 /** RFC 8017 PKCS#1 */
39 XOF_MGF1_SHA224,
40 /** RFC 8017 PKCS#1 */
41 XOF_MGF1_SHA256,
42 /** RFC 8017 PKCS#1 */
43 XOF_MGF1_SHA384,
44 /** RFC 8017 PKCS#1 */
45 XOF_MGF1_SHA512,
46 /** FIPS 202 */
47 XOF_SHAKE_128,
48 /** FIPS 202 */
49 XOF_SHAKE_256,
50 /** RFC 7539 ChaCha20 */
51 XOF_CHACHA20,
52 };
53
54 /**
55 * enum name for ext_out_function_t.
56 */
57 extern enum_name_t *ext_out_function_names;
58
59 /**
60 * Generic interface for Extended Output Function (XOF)
61 */
62 struct xof_t {
63
64 /**
65 * Return the type of the Extended Output Function
66 *
67 * @return XOF type
68 */
69 ext_out_function_t (*get_type)(xof_t *this);
70
71 /**
72 * Generates pseudo random bytes and writes them in the buffer.
73 *
74 * @param out_len number of output bytes requested
75 * @param buffer pointer where the generated bytes will be written
76 * @return TRUE if bytes generated successfully
77 */
78 bool (*get_bytes)(xof_t *this, size_t out_len,
79 uint8_t *buffer) __attribute__((warn_unused_result));
80
81 /**
82 * Generates pseudo random bytes and allocate space for them.
83 *
84 * @param out_len number of output bytes requested
85 * @param chunk chunk which will hold generated bytes
86 * @return TRUE if bytes allocated and generated successfully
87 */
88 bool (*allocate_bytes)(xof_t *this, size_t out_len,
89 chunk_t *chunk) __attribute__((warn_unused_result));
90
91 /**
92 * Get the output block size
93 *
94 * @return block size in bytes
95 */
96 size_t (*get_block_size)(xof_t *this);
97
98 /**
99 * Get the recommended minimum seed size
100 *
101 * @return seed size in bytes
102 */
103 size_t (*get_seed_size)(xof_t *this);
104
105 /**
106 * Set the key for this xof_t object.
107 *
108 * @param seed seed to set
109 * @return TRUE if XOF initialized with seed successfully
110 */
111 bool (*set_seed)(xof_t *this,
112 chunk_t seed) __attribute__((warn_unused_result));
113
114 /**
115 * Destroys a xof object.
116 */
117 void (*destroy)(xof_t *this);
118 };
119
120 /**
121 * Determine an MGF1 XOF type for the given hash algorithm.
122 *
123 * @param alg hash algorithm to map
124 * @return MGF1 XOF type if available, XOF_UNDEFINED otherwise
125 */
126 ext_out_function_t xof_mgf1_from_hash_algorithm(hash_algorithm_t alg);
127
128 #endif /** XOF_H_ @}*/