aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/af_alg/af_alg_ops.h
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-11-08 10:59:54 +0100
committerMartin Willi <martin@revosec.ch>2010-12-20 09:52:02 +0100
commit1b5de7ce3bddedab12703c578b7c8fe90bea116e (patch)
treea96ebfe4a051c8cc5936fbbdce79285b7e376f5e /src/libstrongswan/plugins/af_alg/af_alg_ops.h
parenta5c973b9559f03ab036caa076fa119260f1d0ceb (diff)
downloadstrongswan-1b5de7ce3bddedab12703c578b7c8fe90bea116e.tar.bz2
strongswan-1b5de7ce3bddedab12703c578b7c8fe90bea116e.tar.xz
Use a generic AF_ALG wrapper for common operations
Diffstat (limited to 'src/libstrongswan/plugins/af_alg/af_alg_ops.h')
-rw-r--r--src/libstrongswan/plugins/af_alg/af_alg_ops.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/libstrongswan/plugins/af_alg/af_alg_ops.h b/src/libstrongswan/plugins/af_alg/af_alg_ops.h
new file mode 100644
index 000000000..ad164029f
--- /dev/null
+++ b/src/libstrongswan/plugins/af_alg/af_alg_ops.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2010 Martin Willi
+ * Copyright (C) 2010 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+/**
+* @defgroup af_alg_ops af_alg_ops
+ * @{ @ingroup af_alg
+ */
+
+#ifndef AF_ALG_OPS_H_
+#define AF_ALG_OPS_H_
+
+#include <library.h>
+
+#include <linux/if_alg.h>
+
+#ifndef AF_ALG
+#define AF_ALG 38
+#endif /* AF_ALG */
+
+#ifndef SOL_ALG
+#define SOL_ALG 279
+#endif /* SOL_ALG */
+
+typedef struct af_alg_ops_t af_alg_ops_t;
+
+/**
+ * Helper to run AF_ALG operations.
+ */
+struct af_alg_ops_t {
+
+ /**
+ * Hash a chunk of data.
+ *
+ * @param data data to hash
+ * @param out buffer to write hash to, NULL for append mode
+ * @param outlen number of bytes to read into out
+ */
+ void (*hash)(af_alg_ops_t *this, chunk_t data, char *out, size_t outlen);
+
+ /**
+ * Reset hasher state.
+ */
+ void (*reset)(af_alg_ops_t *this);
+
+ /**
+ * En-/Decrypt a chunk of data.
+ *
+ * @param type crypto operation (ALG_OP_DECRYPT/ALG_OP_ENCRYPT)
+ * @param iv iv to use
+ * @param data data to encrypt/decrypt
+ * @param out buffer write processed data to
+ */
+ void (*crypt)(af_alg_ops_t *this, u_int32_t type, chunk_t iv, chunk_t data,
+ char *out);
+
+ /**
+ * Set the key for en-/decryption or HMAC/XCBC operations.
+ *
+ * @param key key to set for transform
+ */
+ void (*set_key)(af_alg_ops_t *this, chunk_t key);
+
+ /**
+ * Destroy a af_alg_ops_t.
+ */
+ void (*destroy)(af_alg_ops_t *this);
+};
+
+/**
+ * Create a af_alg_ops instance.
+ *
+ * @param type algorithm type (hash, skcipher)
+ * @param alg algorithm name
+ * @return TRUE if AF_ALG socket bound successfully
+ */
+af_alg_ops_t *af_alg_ops_create(char *type, char *alg);
+
+#endif /** AF_ALG_OPS_H_ @}*/