summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2014-02-14 15:37:10 +0100
committerNiels Möller <nisse@lysator.liu.se>2014-02-14 15:37:10 +0100
commitfbac476d4f29e5eb9266ead1f6af255a0c0ef7b0 (patch)
tree3bc77d69bc4a12a0dbf9434a93725e4b5b4d6992
parentd76caf61011c5fbe553ea0f024d9f43edc6f14de (diff)
downloadnettle-aead-api.tar.gz
Added aead.h header file, forgotten in previous commit.aead-api
-rw-r--r--aead.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/aead.h b/aead.h
new file mode 100644
index 00000000..0639d026
--- /dev/null
+++ b/aead.h
@@ -0,0 +1,136 @@
+/* aead.h
+ */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2014 Niels Möller
+ *
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The nettle library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02111-1301, USA.
+ */
+
+#ifndef NETTLE_AEAD_H_INCLUDED
+#define NETTLE_AEAD_H_INCLUDED
+
+#include "nettle-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Name mangling */
+#define aead_encrypt_msg_size nettle_aead_encrypt_msg_size
+#define aead_encrypt_msg nettle_aead_encrypt_msg
+#define aead_decrypt_msg_size nettle_aead_decrypt_msg_size
+#define aead_decrypt_msg nettle_aead_decrypt_msg
+#define aead_encrypt_ctx_size nettle_aead_encrypt_ctx_size
+#define aead_encrypt_init nettle_aead_encrypt_init
+#define aead_encrypt nettle_aead_encrypt
+#define aead_encrypt_final_size nettle_aead_encrypt_final_size
+#define aead_encrypt_final nettle_aead_encrypt_final
+#define aead_decrypt_ctx_size nettle_aead_decrypt_ctx_size
+#define aead_decrypt_init nettle_aead_decrypt_init
+#define aead_decrypt nettle_aead_decrypt
+#define aead_decrypt_final_size nettle_aead_decrypt_final_size
+#define aead_decrypt_final nettle_aead_decrypt_final
+
+struct nettle_aead;
+struct nettle_buffer;
+
+/* Interface for processing a complete message at a time. Application
+ must allocate the context and call the set_key function before
+ using this interface. */
+size_t
+aead_encrypt_msg_size (const struct nettle_aead *aead, size_t size);
+void
+aead_encrypt_msg (const struct nettle_aead *aead,
+ void *ctx, const uint8_t *nonce,
+ size_t ad_size, const uint8_t *ad,
+ size_t plaintext_size,
+ uint8_t *gibberish, const uint8_t *plaintext);
+
+size_t
+aead_decrypt_msg_size (const struct nettle_aead *aead, size_t size);
+int
+aead_decrypt_msg (const struct nettle_aead *aead,
+ void *ctx, const uint8_t *nonce,
+ size_t ad_size, const uint8_t *ad,
+ size_t gibberish_size,
+ uint8_t *plaintext, const uint8_t *gibberish);
+
+/* Streaming interface, including buffering. Uses a context struct
+ corresponding to the aead algorithm, with additional buffers added
+ at the end. Hence, the context can be passed to algorithm-specific
+ functions. Applications should call set_key and set_nonce before
+ using these functions. */
+
+#define aead_update(aead, ctx, size, data) \
+ ((aead)->update((ctx), (size), (data)))
+
+size_t
+aead_encrypt_ctx_size (const struct nettle_aead *aead);
+
+void
+aead_encrypt_init (const struct nettle_aead *aead,
+ void *ctx, const uint8_t *nonce);
+
+/* Attempts to grow the destination buffer as needed. Returns the
+ amount of plaintext that could be processed. */
+size_t
+aead_encrypt (const struct nettle_aead *aead,
+ void *ctx, struct nettle_buffer *buffer,
+ size_t size, const uint8_t *plaintext);
+
+/* Maximum output size for aead_encrypt_final. */
+size_t
+aead_encrypt_final_size (const struct nettle_aead *aead);
+
+/* Returns 1 on success, 0 if buffer was too small and growing it
+ failed. On failure, some output may still be generated, and the
+ function can be called again with more output space. */
+int
+aead_encrypt_final (const struct nettle_aead *aead,
+ void *ctx, struct nettle_buffer *buffer);
+
+size_t
+aead_decrypt_ctx_size (const struct nettle_aead *aead);
+
+void
+aead_decrypt_init (const struct nettle_aead *aead,
+ void *ctx, const uint8_t *nonce);
+
+/* Attempts to grow the destination buffer as needed. Returns the
+ amount of plaintext that could be processed. */
+size_t
+aead_decrypt (const struct nettle_aead *aead,
+ void *ctx, struct nettle_buffer *dst,
+ size_t size, const uint8_t *gibberish);
+
+/* Maximum output size for aead_decrypt_final. */
+size_t
+aead_decrypt_final_size (const struct nettle_aead *aead);
+
+/* Returns 1 on success, 0 if buffer is too small or authentication
+ failed. FIXME: Distinguish between failure cases? */
+int
+aead_decrypt_final (const struct nettle_aead *aead,
+ void *ctx, struct nettle_buffer *dst);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NETTLE_AEAD_H_INCLUDED */