ad164029f0bbaf9b3e699d04639155f55ec13d11
[strongswan.git] / src / libstrongswan / plugins / af_alg / af_alg_ops.h
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
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 af_alg_ops af_alg_ops
18 * @{ @ingroup af_alg
19 */
20
21 #ifndef AF_ALG_OPS_H_
22 #define AF_ALG_OPS_H_
23
24 #include <library.h>
25
26 #include <linux/if_alg.h>
27
28 #ifndef AF_ALG
29 #define AF_ALG 38
30 #endif /* AF_ALG */
31
32 #ifndef SOL_ALG
33 #define SOL_ALG 279
34 #endif /* SOL_ALG */
35
36 typedef struct af_alg_ops_t af_alg_ops_t;
37
38 /**
39 * Helper to run AF_ALG operations.
40 */
41 struct af_alg_ops_t {
42
43 /**
44 * Hash a chunk of data.
45 *
46 * @param data data to hash
47 * @param out buffer to write hash to, NULL for append mode
48 * @param outlen number of bytes to read into out
49 */
50 void (*hash)(af_alg_ops_t *this, chunk_t data, char *out, size_t outlen);
51
52 /**
53 * Reset hasher state.
54 */
55 void (*reset)(af_alg_ops_t *this);
56
57 /**
58 * En-/Decrypt a chunk of data.
59 *
60 * @param type crypto operation (ALG_OP_DECRYPT/ALG_OP_ENCRYPT)
61 * @param iv iv to use
62 * @param data data to encrypt/decrypt
63 * @param out buffer write processed data to
64 */
65 void (*crypt)(af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
66 char *out);
67
68 /**
69 * Set the key for en-/decryption or HMAC/XCBC operations.
70 *
71 * @param key key to set for transform
72 */
73 void (*set_key)(af_alg_ops_t *this, chunk_t key);
74
75 /**
76 * Destroy a af_alg_ops_t.
77 */
78 void (*destroy)(af_alg_ops_t *this);
79 };
80
81 /**
82 * Create a af_alg_ops instance.
83 *
84 * @param type algorithm type (hash, skcipher)
85 * @param alg algorithm name
86 * @return TRUE if AF_ALG socket bound successfully
87 */
88 af_alg_ops_t *af_alg_ops_create(char *type, char *alg);
89
90 #endif /** AF_ALG_OPS_H_ @}*/