summaryrefslogtreecommitdiff
path: root/cesar/cp/secu/inc/secu_aes.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/secu/inc/secu_aes.h')
-rw-r--r--cesar/cp/secu/inc/secu_aes.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/cesar/cp/secu/inc/secu_aes.h b/cesar/cp/secu/inc/secu_aes.h
new file mode 100644
index 0000000000..2b7fc19199
--- /dev/null
+++ b/cesar/cp/secu/inc/secu_aes.h
@@ -0,0 +1,113 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cp/secu/aes.h
+ * \brief AES method
+ * \ingroup cp_secu
+ */
+
+#ifndef uint8
+#define uint8 unsigned char
+#endif
+
+#ifndef uint32
+#define uint32 unsigned long
+#endif
+
+/*
+ * 32-bit integer manipulation macros (big endian)
+ */
+#ifndef GET_UINT32_BE
+#define GET_UINT32_BE(n,b,i) \
+{ \
+ (n) = ( (uint32) (b)[(i) ] << 24 ) \
+ | ( (uint32) (b)[(i) + 1] << 16 ) \
+ | ( (uint32) (b)[(i) + 2] << 8 ) \
+ | ( (uint32) (b)[(i) + 3] ); \
+}
+#endif
+#ifndef PUT_UINT32_BE
+#define PUT_UINT32_BE(n,b,i) \
+{ \
+ (b)[(i) ] = (uint8) ( (n) >> 24 ); \
+ (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
+ (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
+ (b)[(i) + 3] = (uint8) ( (n) ); \
+}
+#endif
+
+#ifndef _AES_H
+#define _AES_H
+
+#include <string.h>
+
+/**
+ * \brief AES context structure
+ */
+typedef struct
+{
+ unsigned long erk[64]; /*!< encryption round keys */
+ unsigned long drk[64]; /*!< decryption round keys */
+ int nr; /*!< number of rounds */
+} aes_context;
+
+/**
+ * \brief AES key schedule
+ *
+ * \param ctx AES context to be initialized
+ * \param key the secret key
+ * \param keysize must be 128, 192 or 256 bits long
+ */
+void
+aes_set_key (aes_context *ctx, unsigned char *key, int keysize);
+
+/**
+ * \brief AES block encryption (ECB mode)
+ *
+ * \param ctx AES context
+ * \param input plaintext block (16 bytes)
+ * \param output ciphertext block (16 bytes)
+ */
+void
+aes_encrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16]);
+
+/**
+ * \brief AES block decryption (ECB mode)
+ *
+ * \param ctx AES context
+ * \param input ciphertext block (16 bytes)
+ * \param output plaintext block (16 bytes)
+ */
+void
+aes_decrypt (aes_context *ctx, unsigned char input[16], unsigned char output[16]);
+
+/**
+ * \brief AES-CBC buffer encryption
+ *
+ * \param ctx AES context
+ * \param iv initialization vector (modified after use) (16 bytes)
+ * \param input buffer holding the plaintext
+ * \param output buffer holding the ciphertext
+ * \param len length of the data to be encrypted
+ */
+void
+aes_cbc_encrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len);
+
+/**
+ * \brief AES-CBC buffer decryption
+ *
+ * \param ctx AES context
+ * \param iv initialization vector (modified after use)
+ * \param input buffer holding the ciphertext
+ * \param output buffer holding the plaintext
+ * \param len length of the data to be decrypted
+ */
+void
+aes_cbc_decrypt (aes_context *ctx, unsigned char iv[16], unsigned char *input, unsigned char *output, int len);
+
+#endif /* aes.h */