libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

commit 96693450952ec3f9c060e2323b2276e070156e9f
Author: lash <dev@holbrook.no>
Date:   Sat,  1 Mar 2025 16:07:56 +0000

Initial commit

Diffstat:
A.gitignore | 1+
Asrc/Makefile | 6++++++
Asrc/crypto/Makefile | 5+++++
Asrc/crypto/dummy.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Asrc/lq/Makefile | 8++++++++
Asrc/lq/cert.h | 23+++++++++++++++++++++++
Asrc/lq/crypto.h | 34++++++++++++++++++++++++++++++++++
Asrc/lq/ctx.c | 15+++++++++++++++
Asrc/lq/ctx.h | 14++++++++++++++
Asrc/lq/mem.h | 11+++++++++++
Asrc/lq/msg.h | 20++++++++++++++++++++
Asrc/mem/Makefile | 2++
Asrc/mem/std.c | 19+++++++++++++++++++
13 files changed, 204 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/src/Makefile b/src/Makefile @@ -0,0 +1,6 @@ +all: dummy + make -C lq + +dummy: + make -C crypto dummy + make -C mem std diff --git a/src/crypto/Makefile b/src/crypto/Makefile @@ -0,0 +1,5 @@ +INCLUDES := -I.. +CFLAGS += $(INCLUDES) -Wall + +dummy: + $(CC) $(CFLAGS) -g3 -c dummy.c diff --git a/src/crypto/dummy.c b/src/crypto/dummy.c @@ -0,0 +1,46 @@ +#include "lq/crypto.h" +#include "lq/mem.h" + +LQPrivKey* lq_privatekey_new(char *seed, size_t seed_len) { + LQPrivKey *pk; + + pk = lq_alloc(sizeof(LQPrivKey)); + pk->lokey = lq_alloc(seed_len); + lq_cpy(pk->lokey, seed, seed_len); + pk->lolen = seed_len; + return pk; +} + +void lq_privatekey_free(LQPrivKey *pk) { + lq_free(pk->lokey); + lq_free(pk); +} + +LQPubKey* lq_publickey_new(char *full, size_t full_len) { + LQPubKey *pubk; + + pubk = lq_alloc(sizeof(LQPubKey)); + lq_set(pubk->pk, 0, sizeof(LQPrivKey)); + pubk->lokey = lq_alloc(full_len); + lq_cpy(pubk->lokey, full, full_len); + pubk->lolen = full_len; + + return pubk; +} + +LQPubKey* lq_publickey_from_privatekey(LQPrivKey *pk) { + LQPubKey *pubk; + + pubk = lq_alloc(sizeof(LQPubKey)); + + return pubk; +} + +LQSig* lq_privatekey_sign(LQPrivKey *pk, char *sig, size_t *sig_len, const char *salt, size_t salt_len) { + return NULL; +} + +void lq_publickey_free(LQPubKey *pubk) { + lq_free(pubk->lokey); + lq_free(pubk); +} diff --git a/src/lq/Makefile b/src/lq/Makefile @@ -0,0 +1,8 @@ +OBJS := $(patsubst %.c,%.o,$(filter-out main.c,$(wildcard *.c))) +INCLUDES := -I.. +CFLAGS += $(INCLUDES) -Wall + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS) + +all: $(OBJS) diff --git a/src/lq/cert.h b/src/lq/cert.h @@ -0,0 +1,23 @@ +#ifndef LIBQAEDA_CERT_H_ +#define LIBQAEDA_CERT_H_ + +#include <stddef.h> + +#include "lq/msg.h" +#include "lq/ctx.h" + +typedef struct lq_certificate_t LQCert; +struct lq_certificate_t { + LQCert *parent; + LQMsg *request; + LQMsg *response; + LQCtx *ctx; +}; + +int lq_certificate_sign_request(LQCert *cert, struct LQPrivKey *pk); +int lq_certificate_sign_response(LQCert *cert, struct LQPrivKey *pk); +int lq_certificate_serialize(LQCert *cert, char *data, size_t *data_len); +int lq_certificate_deserialize(LQCert *cert, char *data, size_t data_len); +int lq_certificate_verify(LQCert *cert); + +#endif // LIBQAEDA_CERT_H_ diff --git a/src/lq/crypto.h b/src/lq/crypto.h @@ -0,0 +1,34 @@ +#ifndef LIBQAEDA_CRYPTO_H_ +#define LIBQAEDA_CRYPTO_H_ + +#include <stddef.h> + +struct lq_privatekey_t { + int key_typ; + void *lokey; + size_t lolen; +}; +typedef struct lq_privatekey_t LQPrivKey; + +struct lq_publickey_t { + LQPrivKey *pk; + void *lokey; + size_t lolen; +}; +typedef struct lq_publickey_t LQPubKey; + +struct lq_signature_t { + LQPubKey *pubkey; + void *losig; + size_t lolen; +}; +typedef struct lq_signature_t LQSig; + +LQPrivKey* lq_privatekey_new(char *seed, size_t seed_len); +LQPubKey* lq_publickey_new(char *full, size_t full_len); +LQPubKey* lq_publickey_from_privatekey(LQPrivKey *pk); +LQSig* lq_privatekey_sign(LQPrivKey *pk, char *sig, size_t *sig_len, const char *salt, size_t salt_len); +void lq_publickey_free(LQPubKey *pubk); +void lq_privatekey_free(LQPrivKey *pk); + +#endif // LIBQAEDA_CRYPTO_H_ diff --git a/src/lq/ctx.c b/src/lq/ctx.c @@ -0,0 +1,15 @@ +#include <stdlib.h> + +#include "lq/ctx.h" +#include "lq/mem.h" + +LQCtx* lq_ctx_new() { + LQCtx *ctx; + + ctx = lq_alloc(sizeof(LQCtx)); + return ctx; +} + +void lq_ctx_free(LQCtx *ctx) { + lq_free((void*)ctx); +} diff --git a/src/lq/ctx.h b/src/lq/ctx.h @@ -0,0 +1,14 @@ +#ifndef LIBQAEDA_CTX_H_ +#define LIBQAEDA_CTX_H_ + +#define CTX_BITS 64 + +struct lq_ctx_t { + char *flag; +}; +typedef struct lq_ctx_t LQCtx; + +LQCtx* lq_ctx_new(); +void lq_ctx_free(LQCtx *ctx); + +#endif // LIBQAEDA_CTX_H_ diff --git a/src/lq/mem.h b/src/lq/mem.h @@ -0,0 +1,11 @@ +#ifndef LIBQAEDA_MEM_H_ +#define LIBQAEDA_MEM_H_ + +#include <stddef.h> + +void* lq_alloc(size_t bytes); +void lq_free(void *o); +void* lq_cpy(void *dst, void *src, size_t len); +void* lq_set(void *dst, char b, size_t len); + +#endif // LIBQAEDA_MEM_H_ diff --git a/src/lq/msg.h b/src/lq/msg.h @@ -0,0 +1,20 @@ +#ifndef LIBQAEDA_MSG_H_ +#define LIBQAEDA_MSG_H_ + +#include <stddef.h> + +#include "lq/crypto.h" + +struct lq_msg_t { + const char *msg_data; + size_t msg_len; + const char *msg_domain; + size_t *msg_domain_len; + int msg_timestamp; + struct LQPubKey *msg_pubkey; + struct LQSig *msg_signature; +}; +typedef struct lq_msg_t LQMsg; + +#endif // LIBQAEDA_MSG_H_ + diff --git a/src/mem/Makefile b/src/mem/Makefile @@ -0,0 +1,2 @@ +std: + $(CC) $(CFLAGS) -g3 -c std.c diff --git a/src/mem/std.c b/src/mem/std.c @@ -0,0 +1,19 @@ +#include <string.h> +#include <stdlib.h> +#include <stddef.h> + +void* lq_alloc(size_t bytes) { + return malloc(bytes); +} + +void lq_free(void *o) { + free(o); +} + +void* lq_cpy(void *dst, void *src, size_t len) { + return memcpy(dst, src, len); +} + +void* lq_set(void *dst, char b, size_t len) { + return memset(dst, (int)b, len); +}