aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aes.c212
-rw-r--r--src/asm/aes128.asm16
-rw-r--r--src/asm/aes192.asm16
-rw-r--r--src/asm/aes256.asm16
-rw-r--r--src/box.c454
-rw-r--r--src/box_aes.c354
-rw-r--r--src/c/aes128.c54
-rw-r--r--src/c/aes192.c52
-rw-r--r--src/c/aes256.c66
-rw-r--r--src/error.c118
-rw-r--r--src/padding.c44
11 files changed, 701 insertions, 701 deletions
diff --git a/src/aes.c b/src/aes.c
index f3dc178..e1af97f 100644
--- a/src/aes.c
+++ b/src/aes.c
@@ -12,48 +12,48 @@
#include <stdio.h>
#include <string.h>
-AesNI_StatusCode aesni_AES_format_block(
- AesNI_AES_BlockString* str,
- const AesNI_AES_Block* block,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES_format_block(
+ AES_AES_BlockString* str,
+ const AES_AES_Block* block,
+ AES_ErrorDetails* err_details)
{
assert(str);
assert(block);
if (str == NULL)
- return aesni_error_null_argument(err_details, "str");
+ return aes_error_null_argument(err_details, "str");
if (block == NULL)
- return aesni_error_null_argument(err_details, "block");
+ return aes_error_null_argument(err_details, "block");
char* cursor = str->str;
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, *block);
+ aes_store_block128_aligned(bytes, *block);
for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
*cursor = '\0';
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES_format_block_as_matrix(
- AesNI_AES_BlockMatrixString* str,
- const AesNI_AES_Block* block,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES_format_block_as_matrix(
+ AES_AES_BlockMatrixString* str,
+ const AES_AES_Block* block,
+ AES_ErrorDetails* err_details)
{
assert(str);
assert(block);
if (str == NULL)
- return aesni_error_null_argument(err_details, "str");
+ return aes_error_null_argument(err_details, "str");
if (block == NULL)
- return aesni_error_null_argument(err_details, "block");
+ return aes_error_null_argument(err_details, "block");
char* cursor = str->str;
__declspec(align(16)) unsigned char bytes[4][4];
- aesni_store_block128_aligned(bytes, *block);
+ aes_store_block128_aligned(bytes, *block);
for (int i = 0; i < 4; ++i, cursor += 3)
{
@@ -63,59 +63,59 @@ AesNI_StatusCode aesni_AES_format_block_as_matrix(
}
*cursor = '\0';
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES_print_block(
- const AesNI_AES_Block* block,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES_print_block(
+ const AES_AES_Block* block,
+ AES_ErrorDetails* err_details)
{
assert(block);
if (block == NULL)
- return aesni_error_null_argument(err_details, "block");
+ return aes_error_null_argument(err_details, "block");
- AesNI_StatusCode ec = AESNI_SUCCESS;
- AesNI_AES_BlockString str;
+ AES_StatusCode ec = AES_SUCCESS;
+ AES_AES_BlockString str;
- if (aesni_is_error(ec = aesni_AES_format_block(&str, block, err_details)))
+ if (aes_is_error(ec = aes_AES_format_block(&str, block, err_details)))
return ec;
printf("%s\n", str.str);
return ec;
}
-AesNI_StatusCode aesni_AES_print_block_as_matrix(
- const AesNI_AES_Block* block,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES_print_block_as_matrix(
+ const AES_AES_Block* block,
+ AES_ErrorDetails* err_details)
{
assert(block);
if (block == NULL)
- return aesni_error_null_argument(err_details, "block");
+ return aes_error_null_argument(err_details, "block");
- AesNI_StatusCode ec = AESNI_SUCCESS;
- AesNI_AES_BlockMatrixString str;
+ AES_StatusCode ec = AES_SUCCESS;
+ AES_AES_BlockMatrixString str;
- if (aesni_is_error(ec = aesni_AES_format_block_as_matrix(&str, block, err_details)))
+ if (aes_is_error(ec = aes_AES_format_block_as_matrix(&str, block, err_details)))
return ec;
printf("%s", str.str);
return ec;
}
-AesNI_StatusCode aesni_AES_parse_block(
- AesNI_AES_Block* dest,
+AES_StatusCode aes_AES_parse_block(
+ AES_AES_Block* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
assert(dest);
assert(src);
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
const char* cursor = src;
@@ -126,58 +126,58 @@ AesNI_StatusCode aesni_AES_parse_block(
int n;
unsigned int byte;
if (sscanf(cursor, "%2x%n", &byte, &n) != 1)
- return aesni_error_parse(err_details, src, "a 128-bit block");
+ return aes_error_parse(err_details, src, "a 128-bit block");
bytes[i] = (unsigned char) byte;
cursor += n;
}
- *dest = aesni_load_block128_aligned(bytes);
- return AESNI_SUCCESS;
+ *dest = aes_load_block128_aligned(bytes);
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES128_format_key(
- AesNI_AES128_KeyString* str,
- const AesNI_AES128_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES128_format_key(
+ AES_AES128_KeyString* str,
+ const AES_AES128_Key* key,
+ AES_ErrorDetails* err_details)
{
assert(str);
assert(key);
if (str == NULL)
- return aesni_error_null_argument(err_details, "str");
+ return aes_error_null_argument(err_details, "str");
if (key == NULL)
- return aesni_error_null_argument(err_details, "key");
+ return aes_error_null_argument(err_details, "key");
char* cursor = str->str;
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, key->key);
+ aes_store_block128_aligned(bytes, key->key);
for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
*cursor = '\0';
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES192_format_key(
- AesNI_AES192_KeyString* str,
- const AesNI_AES192_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES192_format_key(
+ AES_AES192_KeyString* str,
+ const AES_AES192_Key* key,
+ AES_ErrorDetails* err_details)
{
assert(str);
assert(key);
if (str == NULL)
- return aesni_error_null_argument(err_details, "str");
+ return aes_error_null_argument(err_details, "str");
if (key == NULL)
- return aesni_error_null_argument(err_details, "key");
+ return aes_error_null_argument(err_details, "key");
char* cursor = str->str;
{
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, key->lo);
+ aes_store_block128_aligned(bytes, key->lo);
for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
@@ -185,34 +185,34 @@ AesNI_StatusCode aesni_AES192_format_key(
{
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, key->hi);
+ aes_store_block128_aligned(bytes, key->hi);
for (int i = 0; i < 8; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
}
*cursor = '\0';
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES256_format_key(
- AesNI_AES256_KeyString* str,
- const AesNI_AES256_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES256_format_key(
+ AES_AES256_KeyString* str,
+ const AES_AES256_Key* key,
+ AES_ErrorDetails* err_details)
{
assert(str);
assert(key);
if (str == NULL)
- return aesni_error_null_argument(err_details, "str");
+ return aes_error_null_argument(err_details, "str");
if (key == NULL)
- return aesni_error_null_argument(err_details, "key");
+ return aes_error_null_argument(err_details, "key");
char* cursor = str->str;
{
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, key->lo);
+ aes_store_block128_aligned(bytes, key->lo);
for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
@@ -220,81 +220,81 @@ AesNI_StatusCode aesni_AES256_format_key(
{
__declspec(align(16)) unsigned char bytes[16];
- aesni_store_block128_aligned(bytes, key->hi);
+ aes_store_block128_aligned(bytes, key->hi);
for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", bytes[i]);
}
*cursor = '\0';
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES128_print_key(
- const AesNI_AES128_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES128_print_key(
+ const AES_AES128_Key* key,
+ AES_ErrorDetails* err_details)
{
- return aesni_AES_print_block(&key->key, err_details);
+ return aes_AES_print_block(&key->key, err_details);
}
-AesNI_StatusCode aesni_AES192_print_key(
- const AesNI_AES192_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES192_print_key(
+ const AES_AES192_Key* key,
+ AES_ErrorDetails* err_details)
{
assert(key);
if (key == NULL)
- return aesni_error_null_argument(err_details, "key");
+ return aes_error_null_argument(err_details, "key");
- AesNI_StatusCode ec = AESNI_SUCCESS;
- AesNI_AES192_KeyString str;
+ AES_StatusCode ec = AES_SUCCESS;
+ AES_AES192_KeyString str;
- if (aesni_is_error(ec = aesni_AES192_format_key(&str, key, err_details)))
+ if (aes_is_error(ec = aes_AES192_format_key(&str, key, err_details)))
return ec;
printf("%s\n", str.str);
return ec;
}
-AesNI_StatusCode aesni_AES256_print_key(
- const AesNI_AES256_Key* key,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_AES256_print_key(
+ const AES_AES256_Key* key,
+ AES_ErrorDetails* err_details)
{
assert(key);
if (key == NULL)
- return aesni_error_null_argument(err_details, "key");
+ return aes_error_null_argument(err_details, "key");
- AesNI_StatusCode ec = AESNI_SUCCESS;
- AesNI_AES256_KeyString str;
+ AES_StatusCode ec = AES_SUCCESS;
+ AES_AES256_KeyString str;
- if (aesni_is_error(ec = aesni_AES256_format_key(&str, key, err_details)))
+ if (aes_is_error(ec = aes_AES256_format_key(&str, key, err_details)))
return ec;
printf("%s\n", str.str);
return ec;
}
-AesNI_StatusCode aesni_AES128_parse_key(
- AesNI_AES128_Key* dest,
+AES_StatusCode aes_AES128_parse_key(
+ AES_AES128_Key* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- return aesni_AES_parse_block(&dest->key, src, err_details);
+ return aes_AES_parse_block(&dest->key, src, err_details);
}
-AesNI_StatusCode aesni_AES192_parse_key(
- AesNI_AES192_Key* dest,
+AES_StatusCode aes_AES192_parse_key(
+ AES_AES192_Key* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
assert(dest);
assert(src);
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
const char* cursor = src;
@@ -306,12 +306,12 @@ AesNI_StatusCode aesni_AES192_parse_key(
int n;
unsigned int byte;
if (sscanf(cursor, "%2x%n", &byte, &n) != 1)
- return aesni_error_parse(err_details, src, "a 192-bit block");
+ return aes_error_parse(err_details, src, "a 192-bit block");
bytes[i] = (unsigned char) byte;
cursor += n;
}
- dest->lo = aesni_load_block128_aligned(bytes);
+ dest->lo = aes_load_block128_aligned(bytes);
}
{
@@ -322,30 +322,30 @@ AesNI_StatusCode aesni_AES192_parse_key(
int n;
unsigned int byte;
if (sscanf(cursor, "%2x%n", &byte, &n) != 1)
- return aesni_error_parse(err_details, src, "a 192-bit block");
+ return aes_error_parse(err_details, src, "a 192-bit block");
bytes[i] = (unsigned char) byte;
cursor += n;
}
memset(bytes + 8, 0x00, 8);
- dest->hi = aesni_load_block128_aligned(bytes);
+ dest->hi = aes_load_block128_aligned(bytes);
}
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_AES256_parse_key(
- AesNI_AES256_Key* dest,
+AES_StatusCode aes_AES256_parse_key(
+ AES_AES256_Key* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
assert(dest);
assert(src);
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
const char* cursor = src;
@@ -357,12 +357,12 @@ AesNI_StatusCode aesni_AES256_parse_key(
int n;
unsigned int byte;
if (sscanf(cursor, "%2x%n", &byte, &n) != 1)
- return aesni_error_parse(err_details, src, "a 256-bit block");
+ return aes_error_parse(err_details, src, "a 256-bit block");
bytes[i] = (unsigned char) byte;
cursor += n;
}
- dest->lo = aesni_load_block128_aligned(bytes);
+ dest->lo = aes_load_block128_aligned(bytes);
}
{
@@ -373,13 +373,13 @@ AesNI_StatusCode aesni_AES256_parse_key(
int n;
unsigned int byte;
if (sscanf(cursor, "%2x%n", &byte, &n) != 1)
- return aesni_error_parse(err_details, src, "a 256-bit block");
+ return aes_error_parse(err_details, src, "a 256-bit block");
bytes[i] = (unsigned char) byte;
cursor += n;
}
- dest->hi = aesni_load_block128_aligned(bytes);
+ dest->hi = aes_load_block128_aligned(bytes);
}
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
diff --git a/src/asm/aes128.asm b/src/asm/aes128.asm
index af9c839..106e82b 100644
--- a/src/asm/aes128.asm
+++ b/src/asm/aes128.asm
@@ -8,7 +8,7 @@
.code
-@aesni_AES128_encrypt_block_@20 proc
+@aes_AES128_encrypt_block_@20 proc
pxor xmm0, [ecx]
aesenc xmm0, [ecx + 10h]
aesenc xmm0, [ecx + 20h]
@@ -21,9 +21,9 @@
aesenc xmm0, [ecx + 90h]
aesenclast xmm0, [ecx + 0A0h]
ret
-@aesni_AES128_encrypt_block_@20 endp
+@aes_AES128_encrypt_block_@20 endp
-@aesni_AES128_decrypt_block_@20 proc
+@aes_AES128_decrypt_block_@20 proc
pxor xmm0, [ecx]
aesdec xmm0, [ecx + 10h]
aesdec xmm0, [ecx + 20h]
@@ -36,9 +36,9 @@
aesdec xmm0, [ecx + 90h]
aesdeclast xmm0, [ecx + 0A0h]
ret
-@aesni_AES128_decrypt_block_@20 endp
+@aes_AES128_decrypt_block_@20 endp
-@aesni_AES128_expand_key_@20 proc
+@aes_AES128_expand_key_@20 proc
; A "word" (in terms of the FIPS 187 standard) is a 32-bit block.
; Words are denoted by `w[N]`.
;
@@ -165,9 +165,9 @@ aes128_keygen_assist:
add ecx, 10h ; ecx = &w[i+8]
ret
-@aesni_AES128_expand_key_@20 endp
+@aes_AES128_expand_key_@20 endp
-@aesni_AES128_derive_decryption_keys_@8 proc
+@aes_AES128_derive_decryption_keys_@8 proc
movdqa xmm5, [ecx]
movdqa xmm4, [ecx + 0A0h]
movdqa [edx], xmm4
@@ -197,6 +197,6 @@ aes128_keygen_assist:
movdqa [edx + 50h], xmm5
ret
-@aesni_AES128_derive_decryption_keys_@8 endp
+@aes_AES128_derive_decryption_keys_@8 endp
end
diff --git a/src/asm/aes192.asm b/src/asm/aes192.asm
index 05e4f08..c90f55a 100644
--- a/src/asm/aes192.asm
+++ b/src/asm/aes192.asm
@@ -8,7 +8,7 @@
.code
-@aesni_AES192_encrypt_block_@20 proc
+@aes_AES192_encrypt_block_@20 proc
pxor xmm0, [ecx]
aesenc xmm0, [ecx + 10h]
aesenc xmm0, [ecx + 20h]
@@ -23,9 +23,9 @@
aesenc xmm0, [ecx + 0B0h]
aesenclast xmm0, [ecx + 0C0h]
ret
-@aesni_AES192_encrypt_block_@20 endp
+@aes_AES192_encrypt_block_@20 endp
-@aesni_AES192_decrypt_block_@20 proc
+@aes_AES192_decrypt_block_@20 proc
pxor xmm0, [ecx]
aesdec xmm0, [ecx + 10h]
aesdec xmm0, [ecx + 20h]
@@ -40,9 +40,9 @@
aesdec xmm0, [ecx + 0B0h]
aesdeclast xmm0, [ecx + 0C0h]
ret
-@aesni_AES192_decrypt_block_@20 endp
+@aes_AES192_decrypt_block_@20 endp
-@aesni_AES192_expand_key_@36 proc
+@aes_AES192_expand_key_@36 proc
; A "word" (in terms of the FIPS 187 standard) is a 32-bit block.
; Words are denoted by `w[N]`.
;
@@ -206,9 +206,9 @@ aes192_keygen_assist:
; xmm1[31:0] == w[i+10] == RotWord(SubWord(w[i+5]))^Rcon^w[i+4]^w[i+3]^w[i+2]^w[i+1]^w[i]
ret
-@aesni_AES192_expand_key_@36 endp
+@aes_AES192_expand_key_@36 endp
-@aesni_AES192_derive_decryption_keys_@8 proc
+@aes_AES192_derive_decryption_keys_@8 proc
movdqa xmm5, [ecx]
movdqa xmm4, [ecx + 0C0h]
movdqa [edx], xmm4
@@ -243,6 +243,6 @@ aes192_keygen_assist:
movdqa [edx + 60h], xmm5
ret
-@aesni_AES192_derive_decryption_keys_@8 endp
+@aes_AES192_derive_decryption_keys_@8 endp
end
diff --git a/src/asm/aes256.asm b/src/asm/aes256.asm
index 0d19c26..143dd5b 100644
--- a/src/asm/aes256.asm
+++ b/src/asm/aes256.asm
@@ -8,7 +8,7 @@
.code
-@aesni_AES256_encrypt_block_@20 proc
+@aes_AES256_encrypt_block_@20 proc
pxor xmm0, [ecx]
aesenc xmm0, [ecx + 10h]
aesenc xmm0, [ecx + 20h]
@@ -25,9 +25,9 @@
aesenc xmm0, [ecx + 0D0h]
aesenclast xmm0, [ecx + 0E0h]
ret
-@aesni_AES256_encrypt_block_@20 endp
+@aes_AES256_encrypt_block_@20 endp
-@aesni_AES256_decrypt_block_@20 proc
+@aes_AES256_decrypt_block_@20 proc
pxor xmm0, [ecx]
aesdec xmm0, [ecx + 10h]
aesdec xmm0, [ecx + 20h]
@@ -44,9 +44,9 @@
aesdec xmm0, [ecx + 0D0h]
aesdeclast xmm0, [ecx + 0E0h]
ret
-@aesni_AES256_decrypt_block_@20 endp
+@aes_AES256_decrypt_block_@20 endp
-@aesni_AES256_expand_key_@36 proc
+@aes_AES256_expand_key_@36 proc
; A "word" (in terms of the FIPS 187 standard) is a 32-bit block.
; Words are denoted by `w[N]`.
;
@@ -239,9 +239,9 @@ aes256_keygen_assist:
pxor xmm0, xmm1
ret
-@aesni_AES256_expand_key_@36 endp
+@aes_AES256_expand_key_@36 endp
-@aesni_AES256_derive_decryption_keys_@8 proc
+@aes_AES256_derive_decryption_keys_@8 proc
movdqa xmm5, [ecx]
movdqa xmm4, [ecx + 0E0h]
movdqa [edx], xmm4
@@ -281,6 +281,6 @@ aes256_keygen_assist:
movdqa [edx + 70h], xmm5
ret
-@aesni_AES256_derive_decryption_keys_@8 endp
+@aes_AES256_derive_decryption_keys_@8 endp
end
diff --git a/src/box.c b/src/box.c
index 7a26333..ca5479e 100644
--- a/src/box.c
+++ b/src/box.c
@@ -11,26 +11,26 @@
#include <stdlib.h>
#include <string.h>
-static const AesNI_BoxAlgorithmInterface* aesni_box_algorithms[] =
+static const AES_BoxAlgorithmInterface* aes_box_algorithms[] =
{
- &aesni_box_algorithm_aes128,
- &aesni_box_algorithm_aes192,
- &aesni_box_algorithm_aes256,
+ &aes_box_algorithm_aes128,
+ &aes_box_algorithm_aes192,
+ &aes_box_algorithm_aes256,
};
-AesNI_StatusCode aesni_box_init(
- AesNI_Box* box,
- AesNI_Algorithm algorithm,
- const AesNI_BoxKey* box_key,
- AesNI_Mode mode,
- const AesNI_BoxBlock* iv,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_box_init(
+ AES_Box* box,
+ AES_Algorithm algorithm,
+ const AES_BoxKey* box_key,
+ AES_Mode mode,
+ const AES_BoxBlock* iv,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- box->algorithm = aesni_box_algorithms[algorithm];
+ box->algorithm = aes_box_algorithms[algorithm];
- if (aesni_is_error(status = box->algorithm->calc_round_keys(
+ if (aes_is_error(status = box->algorithm->calc_round_keys(
box_key,
&box->encryption_keys,
&box->decryption_keys,
@@ -44,30 +44,30 @@ AesNI_StatusCode aesni_box_init(
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_block_ecb(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_ecb(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
return box->algorithm->encrypt_block(
input, &box->encryption_keys, output, err_details);
}
-static AesNI_StatusCode aesni_box_encrypt_block_cbc(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_cbc(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
- AesNI_BoxBlock xored_input = *input;
+ AES_StatusCode status = AES_SUCCESS;
+ AES_BoxBlock xored_input = *input;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
&xored_input, &box->iv, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->encrypt_block(
+ if (aes_is_error(status = box->algorithm->encrypt_block(
&xored_input, &box->encryption_keys, output, err_details)))
return status;
@@ -75,19 +75,19 @@ static AesNI_StatusCode aesni_box_encrypt_block_cbc(
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_block_cfb(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_cfb(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- if (aesni_is_error(status = box->algorithm->encrypt_block(
+ if (aes_is_error(status = box->algorithm->encrypt_block(
&box->iv, &box->encryption_keys, output, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
output, input, err_details)))
return status;
@@ -95,98 +95,98 @@ static AesNI_StatusCode aesni_box_encrypt_block_cfb(
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_block_ofb(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_ofb(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- if (aesni_is_error(status = box->algorithm->encrypt_block(
+ if (aes_is_error(status = box->algorithm->encrypt_block(
&box->iv, &box->encryption_keys, &box->iv, err_details)))
return status;
*output = box->iv;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
output, input, err_details)))
return status;
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_block_ctr(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_ctr(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- if (aesni_is_error(status = box->algorithm->encrypt_block(
+ if (aes_is_error(status = box->algorithm->encrypt_block(
&box->iv, &box->encryption_keys, output, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
output, input, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->inc_block(
+ if (aes_is_error(status = box->algorithm->inc_block(
&box->iv, err_details)))
return status;
return status;
}
-typedef AesNI_StatusCode (*AesNI_BoxEncryptBlockInMode)(
- AesNI_Box*,
- const AesNI_BoxBlock*,
- AesNI_BoxBlock*,
- AesNI_ErrorDetails*);
+typedef AES_StatusCode (*AES_BoxEncryptBlockInMode)(
+ AES_Box*,
+ const AES_BoxBlock*,
+ AES_BoxBlock*,
+ AES_ErrorDetails*);
-static AesNI_BoxEncryptBlockInMode aesni_box_encrypt_block_in_mode[] =
+static AES_BoxEncryptBlockInMode aes_box_encrypt_block_in_mode[] =
{
- &aesni_box_encrypt_block_ecb,
- &aesni_box_encrypt_block_cbc,
- &aesni_box_encrypt_block_cfb,
- &aesni_box_encrypt_block_ofb,
- &aesni_box_encrypt_block_ctr,
+ &aes_box_encrypt_block_ecb,
+ &aes_box_encrypt_block_cbc,
+ &aes_box_encrypt_block_cfb,
+ &aes_box_encrypt_block_ofb,
+ &aes_box_encrypt_block_ctr,
};
-AesNI_StatusCode aesni_box_encrypt_block(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_box_encrypt_block(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- return aesni_box_encrypt_block_in_mode[box->mode](
+ return aes_box_encrypt_block_in_mode[box->mode](
box, input, output, err_details);
}
-static AesNI_StatusCode aesni_box_decrypt_block_ecb(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_ecb(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
return box->algorithm->decrypt_block(
input, &box->decryption_keys, output, err_details);
}
-static AesNI_StatusCode aesni_box_decrypt_block_cbc(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_cbc(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- if (aesni_is_error(status = box->algorithm->decrypt_block(
+ if (aes_is_error(status = box->algorithm->decrypt_block(
input, &box->decryption_keys, output, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
output, &box->iv, err_details)))
return status;
@@ -194,19 +194,19 @@ static AesNI_StatusCode aesni_box_decrypt_block_cbc(
return status;
}
-static AesNI_StatusCode aesni_box_decrypt_block_cfb(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_cfb(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- if (aesni_is_error(status = box->algorithm->encrypt_block(
+ if (aes_is_error(status = box->algorithm->encrypt_block(
&box->iv, &box->encryption_keys, output, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->xor_block(
+ if (aes_is_error(status = box->algorithm->xor_block(
output, input, err_details)))
return status;
@@ -214,44 +214,44 @@ static AesNI_StatusCode aesni_box_decrypt_block_cfb(
return status;
}
-typedef AesNI_BoxEncryptBlockInMode AesNI_BoxDecryptBlockInMode;
+typedef AES_BoxEncryptBlockInMode AES_BoxDecryptBlockInMode;
-static AesNI_BoxDecryptBlockInMode aesni_box_decrypt_block_in_mode[] =
+static AES_BoxDecryptBlockInMode aes_box_decrypt_block_in_mode[] =
{
- &aesni_box_decrypt_block_ecb,
- &aesni_box_decrypt_block_cbc,
- &aesni_box_decrypt_block_cfb,
- &aesni_box_encrypt_block_ofb,
- &aesni_box_encrypt_block_ctr,
+ &aes_box_decrypt_block_ecb,
+ &aes_box_decrypt_block_cbc,
+ &aes_box_decrypt_block_cfb,
+ &aes_box_encrypt_block_ofb,
+ &aes_box_encrypt_block_ctr,
};
-AesNI_StatusCode aesni_box_decrypt_block(
- AesNI_Box* box,
- const AesNI_BoxBlock* input,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_box_decrypt_block(
+ AES_Box* box,
+ const AES_BoxBlock* input,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- return aesni_box_decrypt_block_in_mode[box->mode](
+ return aes_box_decrypt_block_in_mode[box->mode](
box, input, output, err_details);
}
-static AesNI_StatusCode aesni_box_get_encrypted_buffer_size(
- AesNI_Box* box,
+static AES_StatusCode aes_box_get_encrypted_buffer_size(
+ AES_Box* box,
size_t src_size,
size_t* dest_size,
size_t* padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
switch (box->mode)
{
- case AESNI_ECB:
- case AESNI_CBC:
+ case AES_ECB:
+ case AES_CBC:
{
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
@@ -260,77 +260,77 @@ static AesNI_StatusCode aesni_box_get_encrypted_buffer_size(
return status;
}
- case AESNI_CFB:
- case AESNI_OFB:
- case AESNI_CTR:
+ case AES_CFB:
+ case AES_OFB:
+ case AES_CTR:
*dest_size = src_size;
*padding_size = 0;
return status;
default:
- return aesni_error_not_implemented(
+ return aes_error_not_implemented(
err_details, "unsupported mode of operation");
}
}
-static AesNI_StatusCode aesni_box_encrypt_buffer_block(
- AesNI_Box* box,
+static AES_StatusCode aes_box_encrypt_buffer_block(
+ AES_Box* box,
const void* src,
void* dest,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- AesNI_BoxBlock plaintext;
+ AES_BoxBlock plaintext;
- if (aesni_is_error(status = box->algorithm->load_block(
+ if (aes_is_error(status = box->algorithm->load_block(
&plaintext, src, err_details)))
return status;
- AesNI_BoxBlock ciphertext;
+ AES_BoxBlock ciphertext;
- if (aesni_is_error(status = aesni_box_encrypt_block(
+ if (aes_is_error(status = aes_box_encrypt_block(
box, &plaintext, &ciphertext, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->store_block(
+ if (aes_is_error(status = box->algorithm->store_block(
dest, &ciphertext, err_details)))
return status;
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block_with_padding(
- AesNI_Box* box,
+static AES_StatusCode aes_box_encrypt_buffer_partial_block_with_padding(
+ AES_Box* box,
const void* src,
size_t src_size,
void* dest,
size_t padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
void* plaintext_buf = malloc(block_size);
if (plaintext_buf == NULL)
- return status = aesni_error_memory_allocation(err_details);
+ return status = aes_error_memory_allocation(err_details);
memcpy(plaintext_buf, src, src_size);
- if (aesni_is_error(status = aesni_fill_with_padding(
- AESNI_PADDING_PKCS7,
+ if (aes_is_error(status = aes_fill_with_padding(
+ AES_PADDING_PKCS7,
(char*) plaintext_buf + src_size,
padding_size,
err_details)))
goto FREE_PLAINTEXT_BUF;
- if (aesni_is_error(status = aesni_box_encrypt_buffer_block(
+ if (aes_is_error(status = aes_box_encrypt_buffer_block(
box, plaintext_buf, dest, err_details)))
goto FREE_PLAINTEXT_BUF;
@@ -340,28 +340,28 @@ FREE_PLAINTEXT_BUF:
return status;
}
-static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block(
- AesNI_Box* box,
+static AES_StatusCode aes_box_encrypt_buffer_partial_block(
+ AES_Box* box,
const void* src,
size_t src_size,
void* dest,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
if (src_size == 0)
return status;
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
void* plaintext_buf = malloc(block_size);
if (plaintext_buf == NULL)
- return status = aesni_error_memory_allocation(err_details);
+ return status = aes_error_memory_allocation(err_details);
memset(plaintext_buf, 0x00, block_size);
memcpy(plaintext_buf, src, src_size);
@@ -370,11 +370,11 @@ static AesNI_StatusCode aesni_box_encrypt_buffer_partial_block(
if (ciphertext_buf == NULL)
{
- status = aesni_error_memory_allocation(err_details);
+ status = aes_error_memory_allocation(err_details);
goto FREE_PLAINTEXT_BUF;
}
- if (aesni_is_error(status = aesni_box_encrypt_buffer_block(
+ if (aes_is_error(status = aes_box_encrypt_buffer_block(
box, plaintext_buf, ciphertext_buf, err_details)))
goto FREE_CIPHERTEXT_BUF;
@@ -389,35 +389,35 @@ FREE_PLAINTEXT_BUF:
return status;
}
-AesNI_StatusCode aesni_box_encrypt_buffer(
- AesNI_Box* box,
+AES_StatusCode aes_box_encrypt_buffer(
+ AES_Box* box,
const void* src,
size_t src_size,
void* dest,
size_t* dest_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
if (box == NULL)
- return aesni_error_null_argument(err_details, "box");
+ return aes_error_null_argument(err_details, "box");
if (dest_size == NULL)
- return aesni_error_null_argument(err_details, "dest_size");
+ return aes_error_null_argument(err_details, "dest_size");
size_t padding_size = 0;
- if (aesni_is_error(status = aesni_box_get_encrypted_buffer_size(
+ if (aes_is_error(status = aes_box_get_encrypted_buffer_size(
box, src_size, dest_size, &padding_size, err_details)))
return status;
if (dest == NULL)
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
if (src == NULL && src_size != 0)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
@@ -425,7 +425,7 @@ AesNI_StatusCode aesni_box_encrypt_buffer(
for (size_t i = 0; i < src_len; ++i)
{
- if (aesni_is_error(status = aesni_box_encrypt_buffer_block(
+ if (aes_is_error(status = aes_box_encrypt_buffer_block(
box, src, dest, err_details)))
return status;
@@ -433,103 +433,103 @@ AesNI_StatusCode aesni_box_encrypt_buffer(
}
if (padding_size == 0)
- return aesni_box_encrypt_buffer_partial_block(
+ return aes_box_encrypt_buffer_partial_block(
box, src, src_size % block_size, dest, err_details);
else
- return aesni_box_encrypt_buffer_partial_block_with_padding(
+ return aes_box_encrypt_buffer_partial_block_with_padding(
box, src, src_size % block_size, dest, padding_size, err_details);
}
-static AesNI_StatusCode aesni_box_get_decrypted_buffer_size(
- AesNI_Box* box,
+static AES_StatusCode aes_box_get_decrypted_buffer_size(
+ AES_Box* box,
size_t src_size,
size_t* dest_size,
size_t* max_padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
switch (box->mode)
{
- case AESNI_ECB:
- case AESNI_CBC:
+ case AES_ECB:
+ case AES_CBC:
{
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
if (src_size == 0 || src_size % block_size != 0)
- return aesni_error_missing_padding(err_details);
+ return aes_error_missing_padding(err_details);
*dest_size = src_size;
*max_padding_size = block_size;
return status;
}
- case AESNI_CFB:
- case AESNI_OFB:
- case AESNI_CTR:
+ case AES_CFB:
+ case AES_OFB:
+ case AES_CTR:
*dest_size = src_size;
*max_padding_size = 0;
return status;
default:
- return aesni_error_not_implemented(
+ return aes_error_not_implemented(
err_details, "unsupported mode of operation");
}
}
-static AesNI_StatusCode aesni_box_decrypt_buffer_block(
- AesNI_Box* box,
+static AES_StatusCode aes_box_decrypt_buffer_block(
+ AES_Box* box,
const void* src,
void* dest,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
- AesNI_BoxBlock ciphertext;
+ AES_BoxBlock ciphertext;
- if (aesni_is_error(status = box->algorithm->load_block(
+ if (aes_is_error(status = box->algorithm->load_block(
&ciphertext, src, err_details)))
return status;
- AesNI_BoxBlock plaintext;
+ AES_BoxBlock plaintext;
- if (aesni_is_error(status = aesni_box_decrypt_block(
+ if (aes_is_error(status = aes_box_decrypt_block(
box, &ciphertext, &plaintext, err_details)))
return status;
- if (aesni_is_error(status = box->algorithm->store_block(
+ if (aes_is_error(status = box->algorithm->store_block(
dest, &plaintext, err_details)))
return status;
return status;
}
-static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block(
- AesNI_Box* box,
+static AES_StatusCode aes_box_decrypt_buffer_partial_block(
+ AES_Box* box,
const void* src,
size_t src_size,
void* dest,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
if (src_size == 0)
return status;
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
void* ciphertext_buf = malloc(block_size);
if (ciphertext_buf == NULL)
- return status = aesni_error_memory_allocation(err_details);
+ return status = aes_error_memory_allocation(err_details);
memset(ciphertext_buf, 0x00, block_size);
memcpy(ciphertext_buf, src, src_size);
@@ -538,11 +538,11 @@ static AesNI_StatusCode aesni_box_decrypt_buffer_partial_block(
if (plaintext_buf == NULL)
{
- status = aesni_error_memory_allocation(err_details);
+ status = aes_error_memory_allocation(err_details);
goto FREE_CIPHERTEXT_BUF;
}
- if (aesni_is_error(status = aesni_box_decrypt_buffer_block(
+ if (aes_is_error(status = aes_box_decrypt_buffer_block(
box, ciphertext_buf, plaintext_buf, err_details)))
goto FREE_PLAINTEXT_BUF;
@@ -557,34 +557,34 @@ FREE_CIPHERTEXT_BUF:
return status;
}
-AesNI_StatusCode aesni_box_decrypt_buffer(
- AesNI_Box* box,
+AES_StatusCode aes_box_decrypt_buffer(
+ AES_Box* box,
const void* src,
size_t src_size,
void* dest,
size_t* dest_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (box == NULL)
- return aesni_error_null_argument(err_details, "box");
+ return aes_error_null_argument(err_details, "box");
if (dest_size == NULL)
- return aesni_error_null_argument(err_details, "dest_size");
+ return aes_error_null_argument(err_details, "dest_size");
- AesNI_StatusCode status = AESNI_SUCCESS;
+ AES_StatusCode status = AES_SUCCESS;
size_t max_padding_size = 0;
- if (aesni_is_error(status = aesni_box_get_decrypted_buffer_size(
+ if (aes_is_error(status = aes_box_get_decrypted_buffer_size(
box, src_size, dest_size, &max_padding_size, err_details)))
return status;
if (dest == NULL)
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
size_t block_size;
- if (aesni_is_error(status = box->algorithm->get_block_size(
+ if (aes_is_error(status = box->algorithm->get_block_size(
&block_size, err_details)))
return status;
@@ -592,7 +592,7 @@ AesNI_StatusCode aesni_box_decrypt_buffer(
for (size_t i = 0; i < src_len; ++i)
{
- if (aesni_is_error(status = aesni_box_decrypt_buffer_block(
+ if (aes_is_error(status = aes_box_decrypt_buffer_block(
box, src, dest, err_details)))
return status;
@@ -601,15 +601,15 @@ AesNI_StatusCode aesni_box_decrypt_buffer(
if (max_padding_size == 0)
{
- return aesni_box_decrypt_buffer_partial_block(
+ return aes_box_decrypt_buffer_partial_block(
box, src, src_size % block_size, dest, err_details);
}
else
{
size_t padding_size;
- if (aesni_is_error(status = aesni_extract_padding_size(
- AESNI_PADDING_PKCS7,
+ if (aes_is_error(status = aes_extract_padding_size(
+ AES_PADDING_PKCS7,
(char*) dest - block_size,
block_size,
&padding_size,
@@ -621,62 +621,62 @@ AesNI_StatusCode aesni_box_decrypt_buffer(
}
}
-AesNI_StatusCode aesni_box_parse_block(
- AesNI_BoxBlock* dest,
- AesNI_Algorithm algorithm,
+AES_StatusCode aes_box_parse_block(
+ AES_BoxBlock* dest,
+ AES_Algorithm algorithm,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_box_algorithms[algorithm]->parse_block(
+ return aes_box_algorithms[algorithm]->parse_block(
dest, src, err_details);
}
-AesNI_StatusCode aesni_box_parse_key(
- AesNI_BoxKey* dest,
- AesNI_Algorithm algorithm,
+AES_StatusCode aes_box_parse_key(
+ AES_BoxKey* dest,
+ AES_Algorithm algorithm,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_box_algorithms[algorithm]->parse_key(
+ return aes_box_algorithms[algorithm]->parse_key(
dest, src, err_details);
}
-AesNI_StatusCode aesni_box_format_block(
- AesNI_BoxBlockString* dest,
- AesNI_Algorithm algorithm,
- const AesNI_BoxBlock* src,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_box_format_block(
+ AES_BoxBlockString* dest,
+ AES_Algorithm algorithm,
+ const AES_BoxBlock* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_box_algorithms[algorithm]->format_block(
+ return aes_box_algorithms[algorithm]->format_block(
dest, src, err_details);
}
-AesNI_StatusCode aesni_box_format_key(
- AesNI_BoxKeyString* dest,
- AesNI_Algorithm algorithm,
- const AesNI_BoxKey* src,
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_box_format_key(
+ AES_BoxKeyString* dest,
+ AES_Algorithm algorithm,
+ const AES_BoxKey* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_box_algorithms[algorithm]->format_key(
+ return aes_box_algorithms[algorithm]->format_key(
dest, src, err_details);
}
diff --git a/src/box_aes.c b/src/box_aes.c
index 66eacae..b79f3cc 100644
--- a/src/box_aes.c
+++ b/src/box_aes.c
@@ -11,309 +11,309 @@
#include <stdlib.h>
#include <string.h>
-static AesNI_StatusCode aesni_box_derive_params_aes128(
- const AesNI_BoxKey* box_key,
- AesNI_BoxEncryptionRoundKeys* encryption_keys,
- AesNI_BoxDecryptionRoundKeys* decryption_keys,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_derive_params_aes128(
+ const AES_BoxKey* box_key,
+ AES_BoxEncryptionRoundKeys* encryption_keys,
+ AES_BoxDecryptionRoundKeys* decryption_keys,
+ AES_ErrorDetails* err_details)
{
- aesni_AES128_expand_key_(
+ aes_AES128_expand_key_(
box_key->aes128_key.key,
&encryption_keys->aes128_encryption_keys);
- aesni_AES128_derive_decryption_keys_(
+ aes_AES128_derive_decryption_keys_(
&encryption_keys->aes128_encryption_keys,
&decryption_keys->aes128_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_derive_params_aes192(
- const AesNI_BoxKey* box_key,
- AesNI_BoxEncryptionRoundKeys* encryption_keys,
- AesNI_BoxDecryptionRoundKeys* decryption_keys,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_derive_params_aes192(
+ const AES_BoxKey* box_key,
+ AES_BoxEncryptionRoundKeys* encryption_keys,
+ AES_BoxDecryptionRoundKeys* decryption_keys,
+ AES_ErrorDetails* err_details)
{
- aesni_AES192_expand_key_(
+ aes_AES192_expand_key_(
box_key->aes192_key.lo,
box_key->aes192_key.hi,
&encryption_keys->aes192_encryption_keys);
- aesni_AES192_derive_decryption_keys_(
+ aes_AES192_derive_decryption_keys_(
&encryption_keys->aes192_encryption_keys,
&decryption_keys->aes192_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_derive_params_aes256(
- const AesNI_BoxKey* box_key,
- AesNI_BoxEncryptionRoundKeys* encryption_keys,
- AesNI_BoxDecryptionRoundKeys* decryption_keys,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_derive_params_aes256(
+ const AES_BoxKey* box_key,
+ AES_BoxEncryptionRoundKeys* encryption_keys,
+ AES_BoxDecryptionRoundKeys* decryption_keys,
+ AES_ErrorDetails* err_details)
{
- aesni_AES256_expand_key_(
+ aes_AES256_expand_key_(
box_key->aes256_key.lo,
box_key->aes256_key.hi,
&encryption_keys->aes256_encryption_keys);
- aesni_AES256_derive_decryption_keys_(
+ aes_AES256_derive_decryption_keys_(
&encryption_keys->aes256_encryption_keys,
&decryption_keys->aes256_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_parse_block_aes(
- AesNI_BoxBlock* dest,
+static AES_StatusCode aes_box_parse_block_aes(
+ AES_BoxBlock* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
- return aesni_AES_parse_block(&dest->aes_block, src, err_details);
+ return aes_AES_parse_block(&dest->aes_block, src, err_details);
}
-static AesNI_StatusCode aesni_box_parse_key_aes128(
- AesNI_BoxKey* dest,
+static AES_StatusCode aes_box_parse_key_aes128(
+ AES_BoxKey* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
- return aesni_AES128_parse_key(&dest->aes128_key, src, err_details);
+ return aes_AES128_parse_key(&dest->aes128_key, src, err_details);
}
-static AesNI_StatusCode aesni_box_parse_key_aes192(
- AesNI_BoxKey* dest,
+static AES_StatusCode aes_box_parse_key_aes192(
+ AES_BoxKey* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
- return aesni_AES192_parse_key(&dest->aes192_key, src, err_details);
+ return aes_AES192_parse_key(&dest->aes192_key, src, err_details);
}
-static AesNI_StatusCode aesni_box_parse_key_aes256(
- AesNI_BoxKey* dest,
+static AES_StatusCode aes_box_parse_key_aes256(
+ AES_BoxKey* dest,
const char* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
- return aesni_AES256_parse_key(&dest->aes256_key, src, err_details);
+ return aes_AES256_parse_key(&dest->aes256_key, src, err_details);
}
-static AesNI_StatusCode aesni_box_format_block_aes(
- AesNI_BoxBlockString* dest,
- const AesNI_BoxBlock* src,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_format_block_aes(
+ AES_BoxBlockString* dest,
+ const AES_BoxBlock* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_AES128_format_block(&dest->aes, &src->aes_block, err_details);
+ return aes_AES128_format_block(&dest->aes, &src->aes_block, err_details);
}
-static AesNI_StatusCode aesni_box_format_key_aes128(
- AesNI_BoxKeyString* dest,
- const AesNI_BoxKey* src,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_format_key_aes128(
+ AES_BoxKeyString* dest,
+ const AES_BoxKey* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_AES128_format_key(&dest->aes128, &src->aes128_key, err_details);
+ return aes_AES128_format_key(&dest->aes128, &src->aes128_key, err_details);
}
-static AesNI_StatusCode aesni_box_format_key_aes192(
- AesNI_BoxKeyString* dest,
- const AesNI_BoxKey* src,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_format_key_aes192(
+ AES_BoxKeyString* dest,
+ const AES_BoxKey* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_AES192_format_key(&dest->aes192, &src->aes192_key, err_details);
+ return aes_AES192_format_key(&dest->aes192, &src->aes192_key, err_details);
}
-static AesNI_StatusCode aesni_box_format_key_aes256(
- AesNI_BoxKeyString* dest,
- const AesNI_BoxKey* src,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_format_key_aes256(
+ AES_BoxKeyString* dest,
+ const AES_BoxKey* src,
+ AES_ErrorDetails* err_details)
{
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
- return aesni_AES256_format_key(&dest->aes256, &src->aes256_key, err_details);
+ return aes_AES256_format_key(&dest->aes256, &src->aes256_key, err_details);
}
-static AesNI_StatusCode aesni_box_xor_block_aes(
- AesNI_BoxBlock* dest,
- const AesNI_BoxBlock* src,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_xor_block_aes(
+ AES_BoxBlock* dest,
+ const AES_BoxBlock* src,
+ AES_ErrorDetails* err_details)
{
- dest->aes_block = aesni_AES_xor_blocks(dest->aes_block, src->aes_block);
- return AESNI_SUCCESS;
+ dest->aes_block = aes_AES_xor_blocks(dest->aes_block, src->aes_block);
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_inc_block_aes(
- AesNI_BoxBlock* ctr,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_inc_block_aes(
+ AES_BoxBlock* ctr,
+ AES_ErrorDetails* err_details)
{
- ctr->aes_block = aesni_AES_inc_block(ctr->aes_block);
- return AESNI_SUCCESS;
+ ctr->aes_block = aes_AES_inc_block(ctr->aes_block);
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_get_block_size_aes(
+static AES_StatusCode aes_box_get_block_size_aes(
size_t* block_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
*block_size = 16;
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_store_block_aes(
+static AES_StatusCode aes_box_store_block_aes(
void* dest,
- const AesNI_BoxBlock* src,
- AesNI_ErrorDetails* err_details)
+ const AES_BoxBlock* src,
+ AES_ErrorDetails* err_details)
{
- aesni_store_block128(dest, src->aes_block);
- return AESNI_SUCCESS;
+ aes_store_block128(dest, src->aes_block);
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_load_block_aes(
- AesNI_BoxBlock* dest,
+static AES_StatusCode aes_box_load_block_aes(
+ AES_BoxBlock* dest,
const void* src,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
- dest->aes_block = aesni_load_block128(src);
- return AESNI_SUCCESS;
+ dest->aes_block = aes_load_block128(src);
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_encrypt_block_aes128(
- const AesNI_BoxBlock* input,
- const AesNI_BoxEncryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_aes128(
+ const AES_BoxBlock* input,
+ const AES_BoxEncryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES128_encrypt_block_(
+ output->aes_block = aes_AES128_encrypt_block_(
input->aes_block,
&params->aes128_encryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_decrypt_block_aes128(
- const AesNI_BoxBlock* input,
- const AesNI_BoxDecryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_aes128(
+ const AES_BoxBlock* input,
+ const AES_BoxDecryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES128_decrypt_block_(
+ output->aes_block = aes_AES128_decrypt_block_(
input->aes_block,
&params->aes128_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_encrypt_block_aes192(
- const AesNI_BoxBlock* input,
- const AesNI_BoxEncryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_aes192(
+ const AES_BoxBlock* input,
+ const AES_BoxEncryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES192_encrypt_block_(
+ output->aes_block = aes_AES192_encrypt_block_(
input->aes_block,
&params->aes192_encryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_decrypt_block_aes192(
- const AesNI_BoxBlock* input,
- const AesNI_BoxDecryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_aes192(
+ const AES_BoxBlock* input,
+ const AES_BoxDecryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES192_decrypt_block_(
+ output->aes_block = aes_AES192_decrypt_block_(
input->aes_block,
&params->aes192_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_encrypt_block_aes256(
- const AesNI_BoxBlock* input,
- const AesNI_BoxEncryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_encrypt_block_aes256(
+ const AES_BoxBlock* input,
+ const AES_BoxEncryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES256_encrypt_block_(
+ output->aes_block = aes_AES256_encrypt_block_(
input->aes_block,
&params->aes256_encryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-static AesNI_StatusCode aesni_box_decrypt_block_aes256(
- const AesNI_BoxBlock* input,
- const AesNI_BoxDecryptionRoundKeys* params,
- AesNI_BoxBlock* output,
- AesNI_ErrorDetails* err_details)
+static AES_StatusCode aes_box_decrypt_block_aes256(
+ const AES_BoxBlock* input,
+ const AES_BoxDecryptionRoundKeys* params,
+ AES_BoxBlock* output,
+ AES_ErrorDetails* err_details)
{
- output->aes_block = aesni_AES256_decrypt_block_(
+ output->aes_block = aes_AES256_decrypt_block_(
input->aes_block,
&params->aes256_decryption_keys);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes128 =
+AES_BoxAlgorithmInterface aes_box_algorithm_aes128 =
{
- &aesni_box_derive_params_aes128,
- &aesni_box_parse_block_aes,
- &aesni_box_parse_key_aes128,
- &aesni_box_format_block_aes,
- &aesni_box_format_key_aes128,
- &aesni_box_encrypt_block_aes128,
- &aesni_box_decrypt_block_aes128,
- &aesni_box_xor_block_aes,
- &aesni_box_inc_block_aes,
- &aesni_box_get_block_size_aes,
- &aesni_box_store_block_aes,
- &aesni_box_load_block_aes,
+ &aes_box_derive_params_aes128,
+ &aes_box_parse_block_aes,
+ &aes_box_parse_key_aes128,
+ &aes_box_format_block_aes,
+ &aes_box_format_key_aes128,
+ &aes_box_encrypt_block_aes128,
+ &aes_box_decrypt_block_aes128,
+ &aes_box_xor_block_aes,
+ &aes_box_inc_block_aes,
+ &aes_box_get_block_size_aes,
+ &aes_box_store_block_aes,
+ &aes_box_load_block_aes,
};
-AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes192 =
+AES_BoxAlgorithmInterface aes_box_algorithm_aes192 =
{
- &aesni_box_derive_params_aes192,
- &aesni_box_parse_block_aes,
- &aesni_box_parse_key_aes192,
- &aesni_box_format_block_aes,
- &aesni_box_format_key_aes192,
- &aesni_box_encrypt_block_aes192,
- &aesni_box_decrypt_block_aes192,
- &aesni_box_xor_block_aes,
- &aesni_box_inc_block_aes,
- &aesni_box_get_block_size_aes,
- &aesni_box_store_block_aes,
- &aesni_box_load_block_aes,
+ &aes_box_derive_params_aes192,
+ &aes_box_parse_block_aes,
+ &aes_box_parse_key_aes192,
+ &aes_box_format_block_aes,
+ &aes_box_format_key_aes192,
+ &aes_box_encrypt_block_aes192,
+ &aes_box_decrypt_block_aes192,
+ &aes_box_xor_block_aes,
+ &aes_box_inc_block_aes,
+ &aes_box_get_block_size_aes,
+ &aes_box_store_block_aes,
+ &aes_box_load_block_aes,
};
-AesNI_BoxAlgorithmInterface aesni_box_algorithm_aes256 =
+AES_BoxAlgorithmInterface aes_box_algorithm_aes256 =
{
- &aesni_box_derive_params_aes256,
- &aesni_box_parse_block_aes,
- &aesni_box_parse_key_aes256,
- &aesni_box_format_block_aes,
- &aesni_box_format_key_aes256,
- &aesni_box_encrypt_block_aes256,
- &aesni_box_decrypt_block_aes256,
- &aesni_box_xor_block_aes,
- &aesni_box_inc_block_aes,
- &aesni_box_get_block_size_aes,
- &aesni_box_store_block_aes,
- &aesni_box_load_block_aes,
+ &aes_box_derive_params_aes256,
+ &aes_box_parse_block_aes,
+ &aes_box_parse_key_aes256,
+ &aes_box_format_block_aes,
+ &aes_box_format_key_aes256,
+ &aes_box_encrypt_block_aes256,
+ &aes_box_decrypt_block_aes256,
+ &aes_box_xor_block_aes,
+ &aes_box_inc_block_aes,
+ &aes_box_get_block_size_aes,
+ &aes_box_store_block_aes,
+ &aes_box_load_block_aes,
};
diff --git a/src/c/aes128.c b/src/c/aes128.c
index 94e8a05..3a797a9 100644
--- a/src/c/aes128.c
+++ b/src/c/aes128.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_(
- AesNI_AES_Block plaintext,
- const AesNI_AES128_RoundKeys* encryption_keys)
+AES_AES_Block __fastcall aes_AES128_encrypt_block_(
+ AES_AES_Block plaintext,
+ const AES_AES128_RoundKeys* encryption_keys)
{
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
@@ -28,9 +28,9 @@ AesNI_AES_Block __fastcall aesni_AES128_encrypt_block_(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[10]);
}
-AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_(
- AesNI_AES_Block ciphertext,
- const AesNI_AES128_RoundKeys* decryption_keys)
+AES_AES_Block __fastcall aes_AES128_decrypt_block_(
+ AES_AES_Block ciphertext,
+ const AES_AES128_RoundKeys* decryption_keys)
{
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
@@ -45,11 +45,11 @@ AesNI_AES_Block __fastcall aesni_AES128_decrypt_block_(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[10]);
}
-static AesNI_AES_Block __fastcall aesni_aes128_expand_key_assist(
- AesNI_AES_Block prev,
- AesNI_AES_Block hwgen)
+static AES_AES_Block __fastcall aes_aes128_expand_key_assist(
+ AES_AES_Block prev,
+ AES_AES_Block hwgen)
{
- AesNI_AES_Block tmp = prev;
+ AES_AES_Block tmp = prev;
tmp = _mm_slli_si128(tmp, 4);
prev = _mm_xor_si128(prev, tmp);
@@ -64,26 +64,26 @@ static AesNI_AES_Block __fastcall aesni_aes128_expand_key_assist(
return prev;
}
-void __fastcall aesni_AES128_expand_key_(
- AesNI_AES_Block key,
- AesNI_AES128_RoundKeys* encryption_keys)
+void __fastcall aes_AES128_expand_key_(
+ AES_AES_Block key,
+ AES_AES128_RoundKeys* encryption_keys)
{
- AesNI_Block128 prev = encryption_keys->keys[0] = key;
- prev = encryption_keys->keys[1] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01));
- prev = encryption_keys->keys[2] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02));
- prev = encryption_keys->keys[3] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04));
- prev = encryption_keys->keys[4] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08));
- prev = encryption_keys->keys[5] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10));
- prev = encryption_keys->keys[6] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20));
- prev = encryption_keys->keys[7] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40));
- prev = encryption_keys->keys[8] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80));
- prev = encryption_keys->keys[9] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b));
- prev = encryption_keys->keys[10] = aesni_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36));
+ AES_Block128 prev = encryption_keys->keys[0] = key;
+ prev = encryption_keys->keys[1] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x01));
+ prev = encryption_keys->keys[2] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x02));
+ prev = encryption_keys->keys[3] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x04));
+ prev = encryption_keys->keys[4] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x08));
+ prev = encryption_keys->keys[5] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x10));
+ prev = encryption_keys->keys[6] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x20));
+ prev = encryption_keys->keys[7] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x40));
+ prev = encryption_keys->keys[8] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x80));
+ prev = encryption_keys->keys[9] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x1b));
+ prev = encryption_keys->keys[10] = aes_aes128_expand_key_assist(prev, _mm_aeskeygenassist_si128(prev, 0x36));
}
-void __fastcall aesni_AES128_derive_decryption_keys_(
- const AesNI_AES128_RoundKeys* encryption_keys,
- AesNI_AES128_RoundKeys* decryption_keys)
+void __fastcall aes_AES128_derive_decryption_keys_(
+ const AES_AES128_RoundKeys* encryption_keys,
+ AES_AES128_RoundKeys* decryption_keys)
{
decryption_keys->keys[0] = encryption_keys->keys[10];
decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[9]);
diff --git a/src/c/aes192.c b/src/c/aes192.c
index 570ab0e..4c2d4f4 100644
--- a/src/c/aes192.c
+++ b/src/c/aes192.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_(
- AesNI_AES_Block plaintext,
- const AesNI_AES192_RoundKeys* encryption_keys)
+AES_AES_Block __fastcall aes_AES192_encrypt_block_(
+ AES_AES_Block plaintext,
+ const AES_AES192_RoundKeys* encryption_keys)
{
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
@@ -30,9 +30,9 @@ AesNI_AES_Block __fastcall aesni_AES192_encrypt_block_(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[12]);
}
-AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_(
- AesNI_AES_Block ciphertext,
- const AesNI_AES192_RoundKeys* decryption_keys)
+AES_AES_Block __fastcall aes_AES192_decrypt_block_(
+ AES_AES_Block ciphertext,
+ const AES_AES192_RoundKeys* decryption_keys)
{
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
@@ -49,12 +49,12 @@ AesNI_AES_Block __fastcall aesni_AES192_decrypt_block_(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[12]);
}
-static void __fastcall aesni_aes192_expand_key_assist(
- AesNI_AES_Block* prev_lo,
- AesNI_AES_Block* prev_hi,
- AesNI_AES_Block hwgen)
+static void __fastcall aes_aes192_expand_key_assist(
+ AES_AES_Block* prev_lo,
+ AES_AES_Block* prev_hi,
+ AES_AES_Block hwgen)
{
- AesNI_AES_Block tmp = *prev_lo;
+ AES_AES_Block tmp = *prev_lo;
tmp = _mm_slli_si128(tmp, 4);
*prev_lo = _mm_xor_si128(*prev_lo, tmp);
@@ -74,49 +74,49 @@ static void __fastcall aesni_aes192_expand_key_assist(
*prev_hi = _mm_xor_si128(*prev_hi, tmp);
}
-void __fastcall aesni_AES192_expand_key_(
- AesNI_AES_Block key_lo,
- AesNI_AES_Block key_hi,
- AesNI_AES192_RoundKeys* encryption_keys)
+void __fastcall aes_AES192_expand_key_(
+ AES_AES_Block key_lo,
+ AES_AES_Block key_hi,
+ AES_AES192_RoundKeys* encryption_keys)
{
encryption_keys->keys[0] = key_lo;
encryption_keys->keys[1] = key_hi;
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x01));
encryption_keys->keys[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[1]), _mm_castsi128_pd(key_lo), 0));
encryption_keys->keys[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x02));
encryption_keys->keys[3] = key_lo;
encryption_keys->keys[4] = key_hi;
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x04));
encryption_keys->keys[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[4]), _mm_castsi128_pd(key_lo), 0));
encryption_keys->keys[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x08));
encryption_keys->keys[6] = key_lo;
encryption_keys->keys[7] = key_hi;
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x10));
encryption_keys->keys[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[7]), _mm_castsi128_pd(key_lo), 0));
encryption_keys->keys[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x20));
encryption_keys->keys[9] = key_lo;
encryption_keys->keys[10] = key_hi;
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x40));
encryption_keys->keys[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(encryption_keys->keys[10]), _mm_castsi128_pd(key_lo), 0));
encryption_keys->keys[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(key_lo), _mm_castsi128_pd(key_hi), 1));
- aesni_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80));
+ aes_aes192_expand_key_assist(&key_lo, &key_hi, _mm_aeskeygenassist_si128(key_hi, 0x80));
encryption_keys->keys[12] = key_lo;
}
-void __fastcall aesni_AES192_derive_decryption_keys_(
- const AesNI_AES192_RoundKeys* encryption_keys,
- AesNI_AES192_RoundKeys* decryption_keys)
+void __fastcall aes_AES192_derive_decryption_keys_(
+ const AES_AES192_RoundKeys* encryption_keys,
+ AES_AES192_RoundKeys* decryption_keys)
{
decryption_keys->keys[0] = encryption_keys->keys[12];
decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[11]);
diff --git a/src/c/aes256.c b/src/c/aes256.c
index 23ac9ca..da81f7a 100644
--- a/src/c/aes256.c
+++ b/src/c/aes256.c
@@ -11,9 +11,9 @@
#include <emmintrin.h>
#include <wmmintrin.h>
-AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_(
- AesNI_AES_Block plaintext,
- const AesNI_AES256_RoundKeys* encryption_keys)
+AES_AES_Block __fastcall aes_AES256_encrypt_block_(
+ AES_AES_Block plaintext,
+ const AES_AES256_RoundKeys* encryption_keys)
{
plaintext = _mm_xor_si128(plaintext, encryption_keys->keys[0]);
plaintext = _mm_aesenc_si128(plaintext, encryption_keys->keys[1]);
@@ -32,9 +32,9 @@ AesNI_AES_Block __fastcall aesni_AES256_encrypt_block_(
return _mm_aesenclast_si128(plaintext, encryption_keys->keys[14]);
}
-AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_(
- AesNI_AES_Block ciphertext,
- const AesNI_AES256_RoundKeys* decryption_keys)
+AES_AES_Block __fastcall aes_AES256_decrypt_block_(
+ AES_AES_Block ciphertext,
+ const AES_AES256_RoundKeys* decryption_keys)
{
ciphertext = _mm_xor_si128(ciphertext, decryption_keys->keys[0]);
ciphertext = _mm_aesdec_si128(ciphertext, decryption_keys->keys[1]);
@@ -53,12 +53,12 @@ AesNI_AES_Block __fastcall aesni_AES256_decrypt_block_(
return _mm_aesdeclast_si128(ciphertext, decryption_keys->keys[14]);
}
-static AesNI_AES_Block __fastcall aesni_aes256_expand_key_assist(
- AesNI_AES_Block* prev_lo,
- AesNI_AES_Block* prev_hi,
- AesNI_AES_Block hwgen)
+static AES_AES_Block __fastcall aes_aes256_expand_key_assist(
+ AES_AES_Block* prev_lo,
+ AES_AES_Block* prev_hi,
+ AES_AES_Block hwgen)
{
- AesNI_AES_Block tmp = *prev_lo;
+ AES_AES_Block tmp = *prev_lo;
tmp = _mm_slli_si128(tmp, 4);
*prev_lo = _mm_xor_si128(*prev_lo, tmp);
@@ -76,73 +76,73 @@ static AesNI_AES_Block __fastcall aesni_aes256_expand_key_assist(
return *prev_hi;
}
-void __fastcall aesni_AES256_expand_key_(
- AesNI_AES_Block key_lo,
- AesNI_AES_Block key_hi,
- AesNI_AES256_RoundKeys* encryption_keys)
+void __fastcall aes_AES256_expand_key_(
+ AES_AES_Block key_lo,
+ AES_AES_Block key_hi,
+ AES_AES256_RoundKeys* encryption_keys)
{
- AesNI_AES_Block prev_lo, prev_hi;
- AesNI_AES_Block hwgen;
+ AES_AES_Block prev_lo, prev_hi;
+ AES_AES_Block hwgen;
prev_lo = encryption_keys->keys[0] = key_lo;
prev_hi = encryption_keys->keys[1] = key_hi;
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x01);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[2] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[2] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[3] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[3] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x02);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[4] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[4] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[5] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[5] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x04);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[6] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[6] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[7] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[7] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x08);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[8] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[8] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[9] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[9] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x10);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[10] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[10] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[11] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[11] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x20);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[12] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[12] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0);
hwgen = _mm_shuffle_epi32(hwgen, 0xaa);
- encryption_keys->keys[13] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[13] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
hwgen = _mm_aeskeygenassist_si128(prev_hi, 0x40);
hwgen = _mm_shuffle_epi32(hwgen, 0xff);
- encryption_keys->keys[14] = aesni_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
+ encryption_keys->keys[14] = aes_aes256_expand_key_assist(&prev_lo, &prev_hi, hwgen);
}
-void __fastcall aesni_AES256_derive_decryption_keys_(
- const AesNI_AES256_RoundKeys* encryption_keys,
- AesNI_AES256_RoundKeys* decryption_keys)
+void __fastcall aes_AES256_derive_decryption_keys_(
+ const AES_AES256_RoundKeys* encryption_keys,
+ AES_AES256_RoundKeys* decryption_keys)
{
decryption_keys->keys[0] = encryption_keys->keys[14];
decryption_keys->keys[1] = _mm_aesimc_si128(encryption_keys->keys[13]);
diff --git a/src/error.c b/src/error.c
index 49d8c72..15b2aeb 100644
--- a/src/error.c
+++ b/src/error.c
@@ -13,13 +13,13 @@
#include <stdlib.h>
#include <string.h>
-static void aesni_fill_string(char* dest, size_t dest_size, const char* src)
+static void aes_fill_string(char* dest, size_t dest_size, const char* src)
{
strncpy(dest, src, dest_size);
dest[dest_size - 1] = '\0';
}
-static const char* aesni_strerror_messages[] =
+static const char* aes_strerror_messages[] =
{
"Success",
"Invalid argument value NULL",
@@ -30,28 +30,28 @@ static const char* aesni_strerror_messages[] =
"Couldn't allocate memory",
};
-const char* aesni_strerror(AesNI_StatusCode ec)
+const char* aes_strerror(AES_StatusCode ec)
{
- return aesni_strerror_messages[ec];
+ return aes_strerror_messages[ec];
}
-static size_t aesni_format_error_strerror(
- const AesNI_ErrorDetails* err_details,\
+static size_t aes_format_error_strerror(
+ const AES_ErrorDetails* err_details,\
char* dest,
size_t dest_size)
{
- const AesNI_StatusCode ec = aesni_get_error_code(err_details);
- const char* const msg = aesni_strerror(ec);
+ const AES_StatusCode ec = aes_get_error_code(err_details);
+ const char* const msg = aes_strerror(ec);
if (dest == NULL)
return strlen(msg) + 1;
- aesni_fill_string(dest, dest_size, msg);
+ aes_fill_string(dest, dest_size, msg);
return strlen(dest);
}
-static size_t aesni_format_null_argument_error(
- const AesNI_ErrorDetails* err_details,
+static size_t aes_format_null_argument_error(
+ const AES_ErrorDetails* err_details,
char* dest,
size_t dest_size)
{
@@ -65,8 +65,8 @@ static size_t aesni_format_null_argument_error(
return strlen(dest);
}
-static size_t aesni_format_parse_error(
- const AesNI_ErrorDetails* err_details,
+static size_t aes_format_parse_error(
+ const AES_ErrorDetails* err_details,
char* dest,
size_t dest_size)
{
@@ -81,8 +81,8 @@ static size_t aesni_format_parse_error(
return strlen(dest);
}
-static size_t aesni_format_not_implemented_error(
- const AesNI_ErrorDetails* err_details,
+static size_t aes_format_not_implemented_error(
+ const AES_ErrorDetails* err_details,
char* dest,
size_t dest_size)
{
@@ -96,21 +96,21 @@ static size_t aesni_format_not_implemented_error(
return strlen(dest);
}
-typedef size_t (*AesNI_ErrorFormatter)(const AesNI_ErrorDetails*, char*, size_t);
+typedef size_t (*AES_ErrorFormatter)(const AES_ErrorDetails*, char*, size_t);
-static AesNI_ErrorFormatter err_formatters[] =
+static AES_ErrorFormatter err_formatters[] =
{
- &aesni_format_error_strerror,
- &aesni_format_null_argument_error,
- &aesni_format_parse_error,
- &aesni_format_error_strerror,
- &aesni_format_not_implemented_error,
- &aesni_format_error_strerror,
- &aesni_format_error_strerror,
+ &aes_format_error_strerror,
+ &aes_format_null_argument_error,
+ &aes_format_parse_error,
+ &aes_format_error_strerror,
+ &aes_format_not_implemented_error,
+ &aes_format_error_strerror,
+ &aes_format_error_strerror,
};
-size_t aesni_format_error(
- const AesNI_ErrorDetails* err_details,
+size_t aes_format_error(
+ const AES_ErrorDetails* err_details,
char* dest,
size_t dest_size)
{
@@ -122,63 +122,63 @@ size_t aesni_format_error(
#ifdef WIN32
#include <Windows.h>
-static void aesni_collect_call_stack(AesNI_ErrorDetails* err_details)
+static void aes_collect_call_stack(AES_ErrorDetails* err_details)
{
- err_details->call_stack_size = CaptureStackBackTrace(1, AESNI_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL);
+ err_details->call_stack_size = CaptureStackBackTrace(1, AES_MAX_CALL_STACK_LENGTH, err_details->call_stack, NULL);
}
#else
-static void aesni_collect_call_stack(AesNI_ErrorDetails* err_details)
+static void aes_collect_call_stack(AES_ErrorDetails* err_details)
{
err_details->call_stack_size = 0;
}
#endif
-static AesNI_StatusCode aesni_make_error(
- AesNI_ErrorDetails* err_details,
- AesNI_StatusCode ec)
+static AES_StatusCode aes_make_error(
+ AES_ErrorDetails* err_details,
+ AES_StatusCode ec)
{
if (err_details == NULL)
return ec;
- if (aesni_is_error(ec))
- aesni_collect_call_stack(err_details);
+ if (aes_is_error(ec))
+ aes_collect_call_stack(err_details);
return err_details->ec = ec;
}
-AesNI_StatusCode aesni_success(
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_success(
+ AES_ErrorDetails* err_details)
{
- return aesni_make_error(err_details, AESNI_SUCCESS);
+ return aes_make_error(err_details, AES_SUCCESS);
}
-AesNI_StatusCode aesni_error_null_argument(
- AesNI_ErrorDetails* err_details,
+AES_StatusCode aes_error_null_argument(
+ AES_ErrorDetails* err_details,
const char* param_name)
{
- AesNI_StatusCode status = aesni_make_error(err_details, AESNI_NULL_ARGUMENT_ERROR);
+ AES_StatusCode status = aes_make_error(err_details, AES_NULL_ARGUMENT_ERROR);
if (err_details != NULL)
- aesni_fill_string(
+ aes_fill_string(
err_details->params.null_arg.param_name,
sizeof(err_details->params.null_arg.param_name), param_name);
return status;
}
-AesNI_StatusCode aesni_error_parse(
- AesNI_ErrorDetails* err_details,
+AES_StatusCode aes_error_parse(
+ AES_ErrorDetails* err_details,
const char* src,
const char* what)
{
- AesNI_StatusCode status = aesni_make_error(err_details, AESNI_PARSE_ERROR);
+ AES_StatusCode status = aes_make_error(err_details, AES_PARSE_ERROR);
if (err_details != NULL)
{
- aesni_fill_string(
+ aes_fill_string(
err_details->params.parse_error.src,
sizeof(err_details->params.parse_error.src), src);
- aesni_fill_string(
+ aes_fill_string(
err_details->params.parse_error.what,
sizeof(err_details->params.parse_error.what), what);
}
@@ -186,34 +186,34 @@ AesNI_StatusCode aesni_error_parse(
return status;
}
-AesNI_StatusCode aesni_error_invalid_pkcs7_padding(
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_error_invalid_pkcs7_padding(
+ AES_ErrorDetails* err_details)
{
- return aesni_make_error(err_details, AESNI_INVALID_PKCS7_PADDING_ERROR);
+ return aes_make_error(err_details, AES_INVALID_PKCS7_PADDING_ERROR);
}
-AesNI_StatusCode aesni_error_not_implemented(
- AesNI_ErrorDetails* err_details,
+AES_StatusCode aes_error_not_implemented(
+ AES_ErrorDetails* err_details,
const char* what)
{
- AesNI_StatusCode status = aesni_make_error(err_details, AESNI_NOT_IMPLEMENTED_ERROR);
+ AES_StatusCode status = aes_make_error(err_details, AES_NOT_IMPLEMENTED_ERROR);
if (err_details != NULL)
- aesni_fill_string(
+ aes_fill_string(
err_details->params.not_implemented.what,
sizeof(err_details->params.not_implemented.what), what);
return status;
}
-AesNI_StatusCode aesni_error_missing_padding(
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_error_missing_padding(
+ AES_ErrorDetails* err_details)
{
- return aesni_make_error(err_details, AESNI_MISSING_PADDING_ERROR);
+ return aes_make_error(err_details, AES_MISSING_PADDING_ERROR);
}
-AesNI_StatusCode aesni_error_memory_allocation(
- AesNI_ErrorDetails* err_details)
+AES_StatusCode aes_error_memory_allocation(
+ AES_ErrorDetails* err_details)
{
- return aesni_make_error(err_details, AESNI_MEMORY_ALLOCATION_ERROR);
+ return aes_make_error(err_details, AES_MEMORY_ALLOCATION_ERROR);
}
diff --git a/src/padding.c b/src/padding.c
index f76e7ca..1bbe7f2 100644
--- a/src/padding.c
+++ b/src/padding.c
@@ -11,77 +11,77 @@
#include <stdlib.h>
#include <string.h>
-static AesNI_StatusCode aesni_extract_padding_size_pkcs7(
+static AES_StatusCode aes_extract_padding_size_pkcs7(
const void* src,
size_t src_size,
size_t* padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
const unsigned char* cursor = (const unsigned char*) src + src_size - 1;
*padding_size = *cursor;
for (size_t i = 1; i < *padding_size; ++i)
if (cursor[0 - i] != *padding_size)
- return aesni_error_invalid_pkcs7_padding(err_details);
+ return aes_error_invalid_pkcs7_padding(err_details);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_extract_padding_size(
- AesNI_PaddingMethod method,
+AES_StatusCode aes_extract_padding_size(
+ AES_PaddingMethod method,
const void* src,
size_t src_size,
size_t* padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
assert(src);
assert(padding_size);
if (src == NULL)
- return aesni_error_null_argument(err_details, "src");
+ return aes_error_null_argument(err_details, "src");
if (padding_size == NULL)
- return aesni_error_null_argument(err_details, "padding_size");
+ return aes_error_null_argument(err_details, "padding_size");
switch (method)
{
- case AESNI_PADDING_PKCS7:
- return aesni_extract_padding_size_pkcs7(
+ case AES_PADDING_PKCS7:
+ return aes_extract_padding_size_pkcs7(
src, src_size, padding_size, err_details);
default:
- return aesni_error_not_implemented(
+ return aes_error_not_implemented(
err_details, "unsupported padding method");
}
}
-static AesNI_StatusCode aesni_fill_with_padding_pkcs7(
+static AES_StatusCode aes_fill_with_padding_pkcs7(
void* dest,
size_t padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
memset(dest, padding_size, padding_size);
- return AESNI_SUCCESS;
+ return AES_SUCCESS;
}
-AesNI_StatusCode aesni_fill_with_padding(
- AesNI_PaddingMethod method,
+AES_StatusCode aes_fill_with_padding(
+ AES_PaddingMethod method,
void* dest,
size_t padding_size,
- AesNI_ErrorDetails* err_details)
+ AES_ErrorDetails* err_details)
{
assert(dest);
if (dest == NULL)
- return aesni_error_null_argument(err_details, "dest");
+ return aes_error_null_argument(err_details, "dest");
switch (method)
{
- case AESNI_PADDING_PKCS7:
- return aesni_fill_with_padding_pkcs7(
+ case AES_PADDING_PKCS7:
+ return aes_fill_with_padding_pkcs7(
dest, padding_size, err_details);
default:
- return aesni_error_not_implemented(
+ return aes_error_not_implemented(
err_details, "unsupported padding method");
}
}