538008f2c4145425cd47241c46803e4f635774aa
[strongswan.git] / src / libstrongswan / plugins / openssl / openssl_util.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * 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 openssl_util openssl_util
18 * @{ @ingroup openssl_p
19 */
20
21 #ifndef OPENSSL_UTIL_H_
22 #define OPENSSL_UTIL_H_
23
24 #include <library.h>
25 #include <openssl/bn.h>
26
27 /**
28 * Returns the length in bytes of a field element
29 */
30 #define EC_FIELD_ELEMENT_LEN(group) ((EC_GROUP_get_degree(group) + 7) / 8)
31
32 /**
33 * Creates a hash of a given type of a chunk of data.
34 *
35 * Note: this function allocates memory for the hash
36 *
37 * @param hash_type NID of the hash
38 * @param data the chunk of data to hash
39 * @param hash chunk that contains the hash
40 * @return TRUE on success, FALSE otherwise
41 */
42 bool openssl_hash_chunk(int hash_type, chunk_t data, chunk_t *hash);
43
44 /**
45 * Concatenates two bignums into a chunk, thereby enfocing the length of
46 * a single BIGNUM, if necessary, by pre-pending it with zeros.
47 *
48 * Note: this function allocates memory for the chunk
49 *
50 * @param len the length of a single BIGNUM
51 * @param a first BIGNUM
52 * @param b second BIGNUM
53 * @param chunk resulting chunk
54 * @return TRUE on success, FALSE otherwise
55 */
56 bool openssl_bn_cat(int len, BIGNUM *a, BIGNUM *b, chunk_t *chunk);
57
58 /**
59 * Splits a chunk into two bignums of equal binary length.
60 *
61 * @param chunk a chunk that contains the two BIGNUMs
62 * @param a first BIGNUM
63 * @param b second BIGNUM
64 * @return TRUE on success, FALSE otherwise
65 */
66 bool openssl_bn_split(chunk_t chunk, BIGNUM *a, BIGNUM *b);
67
68 #endif /** OPENSSL_UTIL_H_ @}*/