aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/bitsliced-aes
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-23 06:13:56 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-23 06:19:16 +0100
commit97f88fff542a88e74ceac85ca886de06443769f4 (patch)
tree5c0eb65def19aae3f38fb287bdb58ce63e589eb4 /test/monniaux/bitsliced-aes
parentf02be0675dd3c855ae34c2f0cd277bcfd1e6fb8a (diff)
downloadcompcert-kvx-97f88fff542a88e74ceac85ca886de06443769f4.tar.gz
compcert-kvx-97f88fff542a88e74ceac85ca886de06443769f4.zip
bitsliced AES in one file
Diffstat (limited to 'test/monniaux/bitsliced-aes')
-rw-r--r--test/monniaux/bitsliced-aes/one_file/bitsliced-aes.c95
1 files changed, 85 insertions, 10 deletions
diff --git a/test/monniaux/bitsliced-aes/one_file/bitsliced-aes.c b/test/monniaux/bitsliced-aes/one_file/bitsliced-aes.c
index 255ea4dd..bfa9dba8 100644
--- a/test/monniaux/bitsliced-aes/one_file/bitsliced-aes.c
+++ b/test/monniaux/bitsliced-aes/one_file/bitsliced-aes.c
@@ -2,12 +2,87 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include "../utils.h"
-#include "../aes.h"
-#include "../bs.h"
-#include "../aes.h"
-#include "../utils.h"
-#include "../../clock.h"
+#include "/home/monniaux/work/Kalray/CompCert/test/monniaux/clock.h"
+
+#define EXIT1
+
+void aes_ecb_encrypt(uint8_t * outputb, uint8_t * inputb, size_t size, uint8_t * key);
+void aes_ecb_decrypt(uint8_t * outputb, uint8_t * inputb, size_t size, uint8_t * key);
+
+void aes_ctr_encrypt(uint8_t * outputb, uint8_t * inputb, size_t size, uint8_t * key, uint8_t * iv);
+#define aes_ctr_decrypt(outputb,inputb,size,key,iv) aes_ctr_encrypt(outputb,inputb,size,key,iv)
+
+#define BLOCK_SIZE 128
+#define KEY_SCHEDULE_SIZE 176
+#define WORD_SIZE 64
+#define BS_BLOCK_SIZE (BLOCK_SIZE * WORD_SIZE / 8)
+#define WORDS_PER_BLOCK (BLOCK_SIZE / WORD_SIZE)
+
+#if (WORD_SIZE==64)
+ typedef uint64_t word_t;
+ #define ONE 1ULL
+ #define MUL_SHIFT 6
+ #define WFMT "lx"
+ #define WPAD "016"
+ #define __builtin_bswap_wordsize(x) __builtin_bswap64(x)
+#elif (WORD_SIZE==32)
+ typedef uint32_t word_t;
+ #define ONE 1UL
+ #define MUL_SHIFT 5
+ #define WFMT "x"
+ #define WPAD "08"
+ #define __builtin_bswap_wordsize(x) __builtin_bswap32(x)
+#elif (WORD_SIZE==16)
+ typedef uint16_t word_t;
+ #define ONE 1
+ #define MUL_SHIFT 4
+ #define WFMT "hx"
+ #define WPAD "04"
+ #define __builtin_bswap_wordsize(x) __builtin_bswap16(x)
+#elif (WORD_SIZE==8)
+ typedef uint8_t word_t;
+ #define ONE 1
+ #define MUL_SHIFT 3
+ #define WFMT "hhx"
+ #define WPAD "02"
+ #define __builtin_bswap_wordsize(x) (x)
+#else
+#error "invalid word size"
+#endif
+
+void bs_transpose(word_t * blocks);
+void bs_transpose_rev(word_t * blocks);
+void bs_transpose_dst(word_t * transpose, word_t * blocks);
+
+void bs_sbox(word_t U[8]);
+void bs_sbox_rev(word_t U[8]);
+
+void bs_shiftrows(word_t * B);
+void bs_shiftrows_rev(word_t * B);
+
+void bs_mixcolumns(word_t * B);
+void bs_mixcolumns_rev(word_t * B);
+
+void bs_shiftmix(word_t * B);
+
+void bs_addroundkey(word_t * B, word_t * rk);
+void bs_apply_sbox(word_t * input);
+void bs_apply_sbox_rev(word_t * input);
+
+
+void expand_key(unsigned char *in);
+void bs_expand_key(word_t (* rk)[BLOCK_SIZE], uint8_t * key);
+
+void bs_cipher(word_t state[BLOCK_SIZE], word_t (* rk)[BLOCK_SIZE]);
+void bs_cipher_rev(word_t state[BLOCK_SIZE], word_t (* rk)[BLOCK_SIZE]);
+
+
+void dump_hex(uint8_t * h, int len);
+void dump_word(word_t * h, int len);
+void dump_block(word_t * h, int len);
+
+#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
+#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
void aes_ecb_encrypt(uint8_t * outputb, uint8_t * inputb, size_t size, uint8_t * key)
{
@@ -1379,12 +1454,12 @@ void aes_ecb_test()
if (memcmp(pt_vector, input, 16) != 0)
{
fprintf(stderr,"error: decrypted ciphertext is not the same as the input plaintext\n");
- exit(1);
+ EXIT1;
}
else if (memcmp(ct_vector, output, 16) != 0)
{
fprintf(stderr,"error: ciphertext is not the same as the test vector\n");
- exit(1);
+ EXIT1;
}
else
{
@@ -1435,12 +1510,12 @@ void aes_ctr_test()
if (memcmp(pt_vector, input, AES_CTR_TESTS_BYTES) != 0)
{
fprintf(stderr,"error: decrypted ciphertext is not the same as the input plaintext\n");
- exit(1);
+ EXIT1;
}
else if (memcmp(ct_vector, output, AES_CTR_TESTS_BYTES) != 0)
{
fprintf(stderr,"error: ciphertext is not the same as the test vector\n");
- exit(1);
+ EXIT1;
}
else
{