Skip to content

Commit

Permalink
c backend rewrite, move aes back
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfd committed Jan 7, 2025
1 parent 65cfa0b commit 3d21147
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 124 deletions.
39 changes: 22 additions & 17 deletions lotordb/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
CL := gcc -O3 -Wall -pedantic -std=c99
CC := gcc -O3 -Wall -pedantic -std=c99
BUILD:=.build

all: mkbuilddir hash ciphers keys db_keystore db_tables crypto crypto_server crypto_client test
all: mkbuilddir hash aes ciphers keys db_keystore db_tables crypto crypto_server crypto_client test
local: mkbuilddir hash aes ciphers keys db_keystore db_tables crypto crypto_server crypto_client test_local

mkbuilddir:
mkdir -p ${BUILD}

crypto:
${CL} -c crypto.c -o ${BUILD}/crypto.o
${CC} -c crypto.c -o ${BUILD}/crypto.o

crypto_server:
${CL} -c examples/tables_example_server.c -o ${BUILD}/tables_server.o
${CL} -c examples/keys_example_server.c -o ${BUILD}/keys_server.o
${CL} -c crypto_server.c -o ${BUILD}/crypto_server.o
${CC} -c examples/tables_example_server.c -o ${BUILD}/tables_server.o
${CC} -c examples/keys_example_server.c -o ${BUILD}/keys_server.o
${CC} -c crypto_server.c -o ${BUILD}/crypto_server.o

crypto_client:
${CL} -c examples/tables_example_client.c -o ${BUILD}/tables_client.o
${CL} -c examples/keys_example_client.c -o ${BUILD}/keys_client.o
${CL} -c crypto_client.c -o ${BUILD}/crypto_client.o
${CC} -c examples/tables_example_client.c -o ${BUILD}/tables_client.o
${CC} -c examples/keys_example_client.c -o ${BUILD}/keys_client.o
${CC} -c crypto_client.c -o ${BUILD}/crypto_client.o

db_keystore:
${CL} -c db_keystore.c -o ${BUILD}/db_keystore.o
${CC} -c db_keystore.c -o ${BUILD}/db_keystore.o

hash:
${CL} -c hash_tooling.c -o ${BUILD}/hash_tooling.o
${CL} -c hash.c -o ${BUILD}/hash.o
${CC} -c hash_tooling.c -o ${BUILD}/hash_tooling.o
${CC} -c hash.c -o ${BUILD}/hash.o

db_tables:
${CL} -c db_tables.c -o ${BUILD}/db_tables.o
${CC} -c db_tables.c -o ${BUILD}/db_tables.o

ciphers:
${CL} -c ciphers.c -o ${BUILD}/ciphers.o
${CC} -c ciphers.c -o ${BUILD}/ciphers.o

keys:
${CL} -c keys.c -o ${BUILD}/keys.o
${CC} -c keys.c -o ${BUILD}/keys.o

aes:
${CC} -c aes.c -o .build/aes.o

test:
make -Ctests
${BUILD}/tests

test_local:
make -Ctests local

clean:
rm ${BUILD}/crypto.o ${BUILD}/keys_client.o ${BUILD}/tables_client.o ${BUILD}/tests ${BUILD}/ciphers_aes_gcm.o \
${BUILD}/crypto_client.o ${BUILD}/tables_server.o ${BUILD}/keys_server.o ${BUILD}/crypto_server.o ${BUILD}/db_keystore.o \
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/db_tables.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/*bin.b
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/db_tables.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/aes.o ${BUILD}/*bin.b
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions lotordb/src/rewrite/lotordb/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
CC := gcc -O3 -Wall -pedantic -std=c99
BUILD := .build

all: mkbuilddir hash aes ecc crypto crypto_server crypto_client db_keystore db_tables test
local: mkbuilddir hash aes ecc crypto crypto_server crypto_client db_keystore db_tables test_local
all: mkbuilddir hash ecc crypto crypto_server crypto_client db_keystore db_tables test
local: mkbuilddir hash ecc crypto crypto_server crypto_client db_keystore db_tables test_local

mkbuilddir:
mkdir -p ${BUILD}

hash:
${CC} -c hash.c -o .build/hash.o

aes:
${CC} -c aes.c -o .build/aes.o

ecc:
${CC} -c ecc.c -o .build/ecc.o

Expand Down
2 changes: 1 addition & 1 deletion lotordb/src/rewrite/lotordb/src/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ all: build runner
local: build runner_local

build:
${CC} -o ${BUILD}/tests tests.c ${BUILD}/hash.o ${BUILD}/aes.o ${BUILD}/ecc.o ${BUILD}/crypto.o \
${CC} -o ${BUILD}/tests tests.c ${BUILD}/hash.o ${BUILD}/ecc.o ${BUILD}/crypto.o \
${BUILD}/keys_client.o ${BUILD}/tables_client.o ${BUILD}/crypto_client.o ${BUILD}/tables_server.o ${BUILD}/keys_server.o ${BUILD}/crypto_server.o \
${BUILD}/db_keystore.o ${BUILD}/db_tables.o -lpthread -lm

Expand Down
95 changes: 0 additions & 95 deletions lotordb/src/rewrite/lotordb/src/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string.h>
#include <assert.h>
#include "../hash.h"
#include "../aes.h"
#include "../ecc.h"
#include "../crypto_server.h"
#include "../crypto_client.h"
Expand Down Expand Up @@ -47,91 +46,6 @@ uint8_t test_hashshakeloop(void) {
return 1;
}

uint8_t test_aes(void) {
uint32_t key[8] = {0x603deb10, 0x15ca71be, 0x2b73aef0, 0x857d7781, 0x1f352c07, 0x3b6108d7, 0x2d9810a3, 0x0914dff4};
uint32_t plain[4] = {0xf69f2445, 0xdf4f9b17, 0xad2b417b, 0xe66c3710};
uint32_t expect[4] = {0x23304b7a, 0x39f9f3ff, 0x067d8d8f, 0x9e24ecc7};
uint32_t resultenc[64] = {0}, resultdec[64] = {0};
cipher(resultenc, key, plain);
inv_cipher(resultdec, key, resultenc);
assert(memcmp(resultenc, expect, 4 * sizeof(uint32_t)) == 0 && memcmp(resultdec, plain, 4 * sizeof(uint32_t)) == 0);
return 1;
}

uint8_t test_aesloop(void) {
uint8_t res = 0;
uint32_t key[8] = {0x603deb10, 0x15ca71be, 0x2b73aef0, 0x857d7781, 0x1f352c07, 0x3b6108d7, 0x2d9810a3, 0x0914dff4};
uint32_t plain[4] = {0xf69f2445, 0xdf4f9b17, 0xad2b417b, 0xe66c3710};
uint32_t expect[4] = {0x23304b7a, 0x39f9f3ff, 0x067d8d8f, 0x9e24ecc7};
uint32_t resultenc[64] = {0}, resultdec[64] = {0};
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
cipher(resultenc, key, plain);
inv_cipher(resultdec, key, resultenc);
res += memcmp(resultenc, expect, 4 * sizeof(uint32_t));
res += memcmp(resultdec, plain, 4 * sizeof(uint32_t));
}
assert(res == 0);
printf("aesloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

uint8_t test_aesgcm(void) {
uint8_t iv[32] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
key[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
plain[32] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
gcm_ciphertag(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 32 * sizeof(uint8_t));
assert(res == 0);
return 1;
}

uint8_t test_aesgcmloop(void) {
uint8_t iv[32] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
key[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
plain[32] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
gcm_ciphertag(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 32 * sizeof(uint8_t));
}
assert(res == 0);
printf("aesgcmloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

uint8_t test_aesgcm32bit(void) {
uint32_t iv[32] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
key[32] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f},
plain[32] = {0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
gcm_ciphertag32bit(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag32bit(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 8 * sizeof(uint32_t));
assert(res == 0);
return 1;
}

uint8_t test_aesgcm32bitloop(void) {
uint32_t iv[32] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
key[32] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f},
plain[32] = {0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
gcm_ciphertag32bit(cipher, tag, key, iv, plain, aad, 8);
gcm_inv_ciphertag32bit(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 8 * sizeof(uint32_t));
}
assert(res == 0);
printf("aesgcm32bitloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

static void table_filltestdata(ctx **c, binary **bin, FILE *write_ptr) {
for (u64 i = 0; i < DBLENGTH; i++) {
struct tabletest p = {i, 6.8, "testsmurfan", 666, 1};
Expand Down Expand Up @@ -182,21 +96,12 @@ int main(int argc, char** argv) {
uint8_t ret = 1;
if (argc == 1) { // When run without arguments or in CI
ret &= test_hash();
ret &= test_aes();
ret &= test_aesgcm();
ret &= test_aesgcm32bit();
ret &= test_db_table();
ret &= test_ecc();
} else {
ret &= test_hash();
ret &= test_hashloop();
ret &= test_hashshakeloop();
ret &= test_aes();
ret &= test_aesloop();
ret &= test_aesgcm();
ret &= test_aesgcmloop();
ret &= test_aesgcm32bit();
ret &= test_aesgcm32bitloop();
ret &= test_db_table();
ret &= test_ecc();
}
Expand Down
16 changes: 11 additions & 5 deletions lotordb/src/tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
CL:=gcc -O3 -Wall -pedantic -std=c99
CC:=gcc -O3 -Wall -pedantic -std=c99
BUILD:=../.build

all: tests
all: build runner
local: build runner_local

tests:
${CL} -o ${BUILD}/tests tests.c ${BUILD}/crypto.o ${BUILD}/keys_client.o ${BUILD}/tables_client.o \
build:
${CC} -o ${BUILD}/tests tests.c ${BUILD}/crypto.o ${BUILD}/keys_client.o ${BUILD}/tables_client.o \
${BUILD}/crypto_client.o ${BUILD}/tables_server.o ${BUILD}/keys_server.o ${BUILD}/crypto_server.o ${BUILD}/db_keystore.o \
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/db_tables.o ${BUILD}/ciphers.o ${BUILD}/keys.o -lpthread -lm
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/db_tables.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/aes.o -lpthread -lm

runner:
${BUILD}/tests

runner_local:
${BUILD}/tests local
107 changes: 106 additions & 1 deletion lotordb/src/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../ciphers.h"
#include "../crypto_server.h"
#include "../crypto_client.h"
#include "../aes.h"
#include "../keys.h"
#include "../hash.h"
#include "../crypto.h"
Expand Down Expand Up @@ -120,16 +121,103 @@ uint8_t test_db_table(void) {
return 0;
}

uint8_t test_aes(void) {
uint32_t key[8] = {0x603deb10, 0x15ca71be, 0x2b73aef0, 0x857d7781, 0x1f352c07, 0x3b6108d7, 0x2d9810a3, 0x0914dff4};
uint32_t plain[4] = {0xf69f2445, 0xdf4f9b17, 0xad2b417b, 0xe66c3710};
uint32_t expect[4] = {0x23304b7a, 0x39f9f3ff, 0x067d8d8f, 0x9e24ecc7};
uint32_t resultenc[64] = {0}, resultdec[64] = {0};
cipher(resultenc, key, plain);
inv_cipher(resultdec, key, resultenc);
assert(memcmp(resultenc, expect, 4 * sizeof(uint32_t)) == 0 && memcmp(resultdec, plain, 4 * sizeof(uint32_t)) == 0);
return 1;
}

uint8_t test_aesloop(void) {
uint8_t res = 0;
uint32_t key[8] = {0x603deb10, 0x15ca71be, 0x2b73aef0, 0x857d7781, 0x1f352c07, 0x3b6108d7, 0x2d9810a3, 0x0914dff4};
uint32_t plain[4] = {0xf69f2445, 0xdf4f9b17, 0xad2b417b, 0xe66c3710};
uint32_t expect[4] = {0x23304b7a, 0x39f9f3ff, 0x067d8d8f, 0x9e24ecc7};
uint32_t resultenc[64] = {0}, resultdec[64] = {0};
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
cipher(resultenc, key, plain);
inv_cipher(resultdec, key, resultenc);
res += memcmp(resultenc, expect, 4 * sizeof(uint32_t));
res += memcmp(resultdec, plain, 4 * sizeof(uint32_t));
}
assert(res == 0);
printf("aesloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

uint8_t test_aesgcm(void) {
uint8_t iv[32] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
key[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
plain[32] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
gcm_ciphertag(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 32 * sizeof(uint8_t));
assert(res == 0);
return 1;
}

uint8_t test_aesgcmloop(void) {
uint8_t iv[32] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
key[32] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
plain[32] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
gcm_ciphertag(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 32 * sizeof(uint8_t));
}
assert(res == 0);
printf("aesgcmloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

uint8_t test_aesgcm32bit(void) {
uint32_t iv[32] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
key[32] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f},
plain[32] = {0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
gcm_ciphertag32bit(cipher, tag, key, iv, plain, aad, 32);
gcm_inv_ciphertag32bit(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 8 * sizeof(uint32_t));
assert(res == 0);
return 1;
}

uint8_t test_aesgcm32bitloop(void) {
uint32_t iv[32] = {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
key[32] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f},
plain[32] = {0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff, 0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff},
cipher[32] = {0}, tag[32] = {0}, tag2[32] = {0}, aad[32] = {0}, plain2[32] = {0}, res = 0;
clock_t start = clock();
for (int i = 0; i < 1000000; i++) {
gcm_ciphertag32bit(cipher, tag, key, iv, plain, aad, 8);
gcm_inv_ciphertag32bit(plain2, tag2, key, iv, cipher, aad, tag);
res += memcmp(plain, plain2, 8 * sizeof(uint32_t));
}
assert(res == 0);
printf("aesgcm32bitloop: Time %us %ums\n", (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) / 1000, (uint32_t)((clock() - start) * 1000 / CLOCKS_PER_SEC) % 1000);
return 1;
}

int main(int argc, char** argv) {
int ret = 1;
if (argc == 1) { // When run without arguments
printf("\"[o.o]\" \t testing .... \t \"[o.o]\"\n\n");
ret &= test_hash();
ret &= test_hashshake();
ret &= test_aes();
ret &= test_aesgcm();
ret &= test_aesgcm32bit();
ret &= test_genkeys();
ret &= test_keys_verify();
ret &= test_ciphers_aes_gcm_text32();
ret &= test_ciphers_aes_gcm_text32loop();
ret &= test_db_table();
if (ret) printf("\nOK\n");
else printf("\nNot OK\n");
Expand All @@ -145,6 +233,23 @@ int main(int argc, char** argv) {
exit(0);
}
client_end(c);
} else if (strcmp(argv[1], "local") == 0) { // When run locally to measure speed
printf("\"[o.o]\" \t testing locally.... \t \"[o.o]\"\n\n");
ret &= test_hash();
ret &= test_hashshake();
ret &= test_aes();
ret &= test_aesloop();
ret &= test_aesgcm();
ret &= test_aesgcmloop();
ret &= test_aesgcm32bit();
ret &= test_aesgcm32bitloop();
ret &= test_genkeys();
ret &= test_keys_verify();
ret &= test_ciphers_aes_gcm_text32();
ret &= test_ciphers_aes_gcm_text32loop();
ret &= test_db_table();
if (ret) printf("\nOK\n");
else printf("\nNot OK\n");
}
}
}

0 comments on commit 3d21147

Please sign in to comment.