aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/aes.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/aes.c')
-rw-r--r--src/aes.c212
1 files changed, 106 insertions, 106 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;
}