Skip to content

Commit

Permalink
c backend start at aes gcm
Browse files Browse the repository at this point in the history
  • Loading branch information
smurfd committed Jul 12, 2024
1 parent 201352f commit 0fe4a04
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lotordb/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CL:=clang -O3 -Wall -pedantic
CC:=clang -O3 -Wall -pedantic
BUILD:=.build

all: mkbuilddir db_keystore hash db_tables ciphers keys crypto crypto_server crypto_client client server test
all: mkbuilddir db_keystore hash db_tables ciphers ciphers_aes_gcm keys crypto crypto_server crypto_client client server test

mkbuilddir:
mkdir -p ${BUILD}
Expand All @@ -29,21 +29,27 @@ db_tables:
ciphers:
${CL} -c ciphers.c -o ${BUILD}/ciphers.o

ciphers_aes_gcm:
${CL} -c ciphers_aes_gcm.c -o ${BUILD}/ciphers_aes_gcm.o

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

client:
${CL} -o ${BUILD}/client client.c ${BUILD}/crypto.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/crypto_client.o\
${BUILD}/db_keystore.o ${BUILD}/db_tables.o ${BUILD}/hash_tooling.o ${BUILD}/hash.o -fuse-ld=lld -lpthread -lm
${BUILD}/db_keystore.o ${BUILD}/db_tables.o ${BUILD}/hash_tooling.o ${BUILD}/hash.o ${BUILD}/ciphers_aes_gcm.o\
-fuse-ld=lld -lpthread -lm

server:
${CL} -o ${BUILD}/server server.c ${BUILD}/crypto.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/crypto_server.o\
${BUILD}/db_keystore.o ${BUILD}/db_tables.o ${BUILD}/hash_tooling.o ${BUILD}/hash.o -fuse-ld=lld -lpthread -lm
${BUILD}/db_keystore.o ${BUILD}/db_tables.o ${BUILD}/hash_tooling.o ${BUILD}/hash.o ${BUILD}/ciphers_aes_gcm.o\
-fuse-ld=lld -lpthread -lm

test:
make -Ctests
${BUILD}/tests

clean:
rm ${BUILD}/crypto.o ${BUILD}/crypto_client.o ${BUILD}/crypto_server.o ${BUILD}/db_keystore.o ${BUILD}/db_tables.o\
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/client ${BUILD}/server ${BUILD}/tests
${BUILD}/hash.o ${BUILD}/hash_tooling.o ${BUILD}/ciphers.o ${BUILD}/keys.o ${BUILD}/ciphers_aes_gcm.o\
${BUILD}/client ${BUILD}/server ${BUILD}/tests
7 changes: 7 additions & 0 deletions lotordb/src/ciphers_aes_gcm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "ciphers_aes_gcm.h"
#include "ciphers.h"


// AES GCM
// https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
// https://csrc.nist.rip/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf
6 changes: 6 additions & 0 deletions lotordb/src/ciphers_aes_gcm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Auth: smurfd 2024
#ifndef CIPHERS_AES_GCM_H
#define CIPHERS_AES_GCM_H 1
#include <stdint.h>

#endif
4 changes: 2 additions & 2 deletions lotordb/src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void omega_mul(u64 *a, const u64 *b) {
static void mod_add(u64 *a, const u64 *b, const u64 *c, const u64 *m) {
if (c[0] == 0 && c[1] == 0 && c[2] == 0 && c[3] == 0 && c[4] == 0 && c[5] == 0) set(a, b);
else {
u64 r[DIGITS], rb[DIGITS];
u64 rb[DIGITS];
sub(rb, m, c);
if (compare(b, rb) >= 1) {
sub(a, b, rb);
Expand Down Expand Up @@ -602,7 +602,7 @@ int keys_sign(const uint8_t priv[], const uint8_t hash[], uint8_t sign[], const
// Verify signature
int keys_vrfy(const uint8_t publ[], const uint8_t hash[], const uint8_t sign[]) {
u64 u1[DIGITS] = {0}, u2[DIGITS] = {0}, tx[DIGITS] = {0}, ty[DIGITS] = {0}, tz[DIGITS] = {0};
u64 rx[DIGITS] = {0}, ry[DIGITS] = {0}, rz[DIGITS] = {0}, xx[DIGITS] = {0}, yy[DIGITS] = {0};
u64 rx[DIGITS] = {0}, ry[DIGITS] = {0}, rz[DIGITS] = {0};
pt public, sum;
// TODO: This verification fails "randomly"
pt_decompress(&public, publ);
Expand Down

0 comments on commit 0fe4a04

Please sign in to comment.