Check and forward syscall errors in AF_ALG
[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 * @return TRUE if successful
50 */
51 bool (*hash)(af_alg_ops_t *this, chunk_t data, char *out, size_t outlen);
52
53 /**
54 * Reset hasher state.
55 */
56 void (*reset)(af_alg_ops_t *this);
57
58 /**
59 * En-/Decrypt a chunk of data.
60 *
61 * @param type crypto operation (ALG_OP_DECRYPT/ALG_OP_ENCRYPT)
62 * @param iv iv to use
63 * @param data data to encrypt/decrypt
64 * @param out buffer write processed data to
65 * @return TRUE if successful
66 */
67 bool (*crypt)(af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
68 char *out);
69
70 /**
71 * Set the key for en-/decryption or HMAC/XCBC operations.
72 *
73 * @param key key to set for transform
74 * @return TRUE if successful
75 */
76 bool (*set_key)(af_alg_ops_t *this, chunk_t key);
77
78 /**
79 * Destroy a af_alg_ops_t.
80 */
81 void (*destroy)(af_alg_ops_t *this);
82 };
83
84 /**
85 * Create a af_alg_ops instance.
86 *
87 * @param type algorithm type (hash, skcipher)
88 * @param alg algorithm name
89 * @return TRUE if AF_ALG socket bound successfully
90 */
91 af_alg_ops_t *af_alg_ops_create(char *type, char *alg);
92
93 #endif /** AF_ALG_OPS_H_ @}*/