aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/aesni
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/aesni/algorithm.h17
-rw-r--r--include/aesni/all.h3
-rw-r--r--include/aesni/box.h5
-rw-r--r--include/aesni/box_data.h42
-rw-r--r--include/aesni/error.h8
-rw-r--r--include/aesni/mode.h19
-rw-r--r--include/aesni/padding.h32
7 files changed, 82 insertions, 44 deletions
diff --git a/include/aesni/algorithm.h b/include/aesni/algorithm.h
new file mode 100644
index 0000000..8aacfdc
--- /dev/null
+++ b/include/aesni/algorithm.h
@@ -0,0 +1,17 @@
+/**
+ * \file
+ * \author Egor Tensin <Egor.Tensin@gmail.com>
+ * \date 2015
+ * \copyright This file is licensed under the terms of the MIT License.
+ * See LICENSE.txt for details.
+ */
+
+#pragma once
+
+typedef enum
+{
+ AESNI_AES128,
+ AESNI_AES192,
+ AESNI_AES256,
+}
+AesNI_Algorithm;
diff --git a/include/aesni/all.h b/include/aesni/all.h
index dfe9494..144a695 100644
--- a/include/aesni/all.h
+++ b/include/aesni/all.h
@@ -16,9 +16,12 @@
*/
#include "aes.h"
+#include "algorithm.h"
#include "box.h"
#include "box_aes.h"
#include "box_data.h"
#include "buffer.h"
#include "data.h"
#include "error.h"
+#include "mode.h"
+#include "padding.h"
diff --git a/include/aesni/box.h b/include/aesni/box.h
index 12daa2e..1ff7941 100644
--- a/include/aesni/box.h
+++ b/include/aesni/box.h
@@ -8,6 +8,7 @@
#pragma once
+#include "algorithm.h"
#include "box_data.h"
#include "error.h"
@@ -20,9 +21,9 @@ extern "C"
AesNI_StatusCode aesni_box_init(
AesNI_Box* box,
- AesNI_BoxAlgorithm algorithm,
+ AesNI_Algorithm algorithm,
const AesNI_BoxAlgorithmParams* algorithm_params,
- AesNI_BoxMode mode,
+ AesNI_Mode mode,
const AesNI_BoxBlock* iv,
AesNI_ErrorDetails* err_details);
diff --git a/include/aesni/box_data.h b/include/aesni/box_data.h
index 9789f0f..8a1e357 100644
--- a/include/aesni/box_data.h
+++ b/include/aesni/box_data.h
@@ -10,6 +10,7 @@
#include "aes.h"
#include "error.h"
+#include "mode.h"
#include <stdlib.h>
@@ -26,24 +27,6 @@ typedef union
}
AesNI_BoxAlgorithmParams;
-typedef enum
-{
- AESNI_AES128,
- AESNI_AES192,
- AESNI_AES256,
-}
-AesNI_BoxAlgorithm;
-
-typedef enum
-{
- AESNI_ECB,
- AESNI_CBC,
- AESNI_CFB,
- AESNI_OFB,
- AESNI_CTR,
-}
-AesNI_BoxMode;
-
typedef union
{
AesNI_Aes128_RoundKeys aes128_encryption_keys;
@@ -102,29 +85,11 @@ typedef AesNI_StatusCode (*AesNI_BoxStoreBlock)(
const AesNI_BoxBlock*,
AesNI_ErrorDetails*);
-typedef AesNI_StatusCode (*AesNI_BoxStorePartialBlock)(
- void*,
- const AesNI_BoxBlock*,
- size_t,
- AesNI_ErrorDetails*);
-
typedef AesNI_StatusCode (*AesNI_BoxLoadBlock)(
AesNI_BoxBlock*,
const void*,
AesNI_ErrorDetails*);
-typedef AesNI_StatusCode (*AesNI_BoxLoadPartialBlock)(
- AesNI_BoxBlock*,
- const void*,
- size_t,
- AesNI_ErrorDetails*);
-
-typedef AesNI_StatusCode (*AesNI_BoxLoadBlockWithPadding)(
- AesNI_BoxBlock*,
- const void*,
- size_t,
- AesNI_ErrorDetails*);
-
typedef struct
{
AesNI_BoxDeriveParams derive_params;
@@ -134,10 +99,7 @@ typedef struct
AesNI_BoxNextCounter next_counter;
AesNI_BoxGetBlockSize get_block_size;
AesNI_BoxStoreBlock store_block;
- AesNI_BoxStorePartialBlock store_partial_block;
AesNI_BoxLoadBlock load_block;
- AesNI_BoxLoadPartialBlock load_partial_block;
- AesNI_BoxLoadBlockWithPadding load_block_with_padding;
}
AesNI_BoxAlgorithmInterface;
@@ -146,7 +108,7 @@ typedef struct
const AesNI_BoxAlgorithmInterface* algorithm;
AesNI_BoxEncryptionParams encrypt_params;
AesNI_BoxDecryptionParams decrypt_params;
- AesNI_BoxMode mode;
+ AesNI_Mode mode;
AesNI_BoxBlock iv;
}
AesNI_Box;
diff --git a/include/aesni/error.h b/include/aesni/error.h
index e78406a..a51284f 100644
--- a/include/aesni/error.h
+++ b/include/aesni/error.h
@@ -47,7 +47,8 @@ typedef enum
AESNI_PARSE_ERROR, ///< Couldn't parse
AESNI_INVALID_PKCS7_PADDING_ERROR, ///< Invalid PKCS7 padding while decrypting
AESNI_NOT_IMPLEMENTED_ERROR, ///< Not implemented
- AESNI_INVALID_PLAINTEXT_LENGTH_ERROR,
+ AESNI_MISSING_PADDING_ERROR,
+ AESNI_MEMORY_ALLOCATION_ERROR,
}
AesNI_StatusCode;
@@ -168,7 +169,10 @@ AesNI_StatusCode aesni_error_not_implemented(
AesNI_ErrorDetails* err_details,
const char* what);
-AesNI_StatusCode aesni_error_invalid_plaintext_length(
+AesNI_StatusCode aesni_error_missing_padding(
+ AesNI_ErrorDetails* err_details);
+
+AesNI_StatusCode aesni_error_memory_allocation(
AesNI_ErrorDetails* err_details);
#ifdef __cplusplus
diff --git a/include/aesni/mode.h b/include/aesni/mode.h
new file mode 100644
index 0000000..fc00e9c
--- /dev/null
+++ b/include/aesni/mode.h
@@ -0,0 +1,19 @@
+/**
+ * \file
+ * \author Egor Tensin <Egor.Tensin@gmail.com>
+ * \date 2015
+ * \copyright This file is licensed under the terms of the MIT License.
+ * See LICENSE.txt for details.
+ */
+
+#pragma once
+
+typedef enum
+{
+ AESNI_ECB,
+ AESNI_CBC,
+ AESNI_CFB,
+ AESNI_OFB,
+ AESNI_CTR,
+}
+AesNI_Mode;
diff --git a/include/aesni/padding.h b/include/aesni/padding.h
new file mode 100644
index 0000000..f76df16
--- /dev/null
+++ b/include/aesni/padding.h
@@ -0,0 +1,32 @@
+/**
+ * \file
+ * \author Egor Tensin <Egor.Tensin@gmail.com>
+ * \date 2015
+ * \copyright This file is licensed under the terms of the MIT License.
+ * See LICENSE.txt for details.
+ */
+
+#pragma once
+
+#include "error.h"
+
+#include <stdlib.h>
+
+typedef enum
+{
+ AESNI_PADDING_PKCS7,
+}
+AesNI_PaddingMethod;
+
+AesNI_StatusCode aesni_extract_padding_size(
+ AesNI_PaddingMethod,
+ const void* src,
+ size_t src_size,
+ size_t* padding_size,
+ AesNI_ErrorDetails*);
+
+AesNI_StatusCode aesni_fill_with_padding(
+ AesNI_PaddingMethod,
+ void* dest,
+ size_t padding_size,
+ AesNI_ErrorDetails*);