libqaeda

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

commit ebe97dca356c3070f0d4d5310aa7db979af07625
parent eef80ebd20752884e5b381bbaefad7e1c8d91cc5
Author: lash <dev@holbrook.no>
Date:   Sun,  2 Mar 2025 01:53:37 +0000

Commence serialize, move msg sigs to cert

Diffstat:
M.gitignore | 3+++
Msrc/Makefile | 4+++-
Asrc/asn1/Makefile | 23+++++++++++++++++++++++
Asrc/asn1/defs.txt | 17+++++++++++++++++
Asrc/asn1/generate.c | 20++++++++++++++++++++
Asrc/lq/cert.c | 19+++++++++++++++++++
Msrc/lq/cert.h | 7+++++--
Msrc/lq/msg.c | 12++++++++----
Msrc/lq/msg.h | 3++-
9 files changed, 100 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,5 @@ *.o *_bin +src/asn1/*_tab.c +src/asn1/*_tab.o +src/asn1/generate_* diff --git a/src/Makefile b/src/Makefile @@ -1,6 +1,8 @@ -all: dummy +all: asn1 dummy make -C lq +asn1: + make -C asn1 dummy: make -C crypto dummy make -C mem std diff --git a/src/asn1/Makefile b/src/asn1/Makefile @@ -0,0 +1,23 @@ +INCLUDES := `pkg-config --cflags libtasn1` +LIBS := `pkg-config --libs libtasn1` +LDFLAGS += $(LIBS) + +all: compile + +src: + $(CC) $(CFLAGS) generate.c -o generate_asn1 $(LDFLAGS) + +%.o: %_asn1_tab.c + $(CC) $< -o $* $(LDFLAGS) + +compile: generate defs_asn1_tab.o + +generate: src + ./generate_asn1 + +clean: + rm -vf *.o + rm -vf *_tab.c + rm -vf generate_asn1 + +.PHONY: clean diff --git a/src/asn1/defs.txt b/src/asn1/defs.txt @@ -0,0 +1,17 @@ +Qaeda DEFINITIONS EXPLICIT TAGS ::= BEGIN + Msg ::= SEQUENCE { + domain OCTET STRING, + data OCTET STRING, +--- timestamp GeneralizedTime, + timestamp OCTET STRING, + pubkey OCTET STRING + } + + Cert ::= SEQUENCE { + parent Cert, + request Msg, + request_sig OCTET STRING, + response Msg, + response_sig OCTET STRING + } +END diff --git a/src/asn1/generate.c b/src/asn1/generate.c @@ -0,0 +1,20 @@ +#include <string.h> +#include <stdio.h> +#include <libtasn1.h> + +int main() { + int r; + char err[1024]; + asn1_node node; + + err[0] = 0; + memset(&node, 0, sizeof(asn1_node)); + + r = asn1_parser2array("./defs.txt", NULL, NULL, err); + if (r) { + fprintf(stderr, "%s\n", err); + return r; + } + return 0; + +} diff --git a/src/lq/cert.c b/src/lq/cert.c @@ -0,0 +1,19 @@ +#include "lq/cert.h" +#include "lq/mem.h" + + +LQCert* lq_certificate_new(LQCert *parent, LQCtx *ctx, LQMsg *req, LQMsg *rsp) { + LQCert *cert; + + cert = lq_alloc(sizeof(LQCert)); + cert->parent = parent; + cert->request = req; + cert->response = rsp; + cert->ctx = ctx; + + return cert; +} + +void lq_certificate_free(LQCert *cert) { + lq_free(cert); +} diff --git a/src/lq/cert.h b/src/lq/cert.h @@ -3,6 +3,7 @@ #include <stddef.h> +#include "lq/crypto.h" #include "lq/msg.h" #include "lq/ctx.h" @@ -10,14 +11,16 @@ typedef struct lq_certificate_t LQCert; struct lq_certificate_t { LQCert *parent; LQMsg *request; + LQSig *request_sig; LQMsg *response; + LQSig *response_sig; LQCtx *ctx; }; -int lq_certificate_sign_request(LQCert *cert, struct LQPrivKey *pk); -int lq_certificate_sign_response(LQCert *cert, struct LQPrivKey *pk); +LQCert* lq_certificate_new(LQCert *parent, LQCtx *ctx, LQMsg *req, LQMsg *rsp); 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); +void lq_certificate_free(LQCert *cert); #endif // LIBQAEDA_CERT_H_ diff --git a/src/lq/msg.c b/src/lq/msg.c @@ -36,7 +36,7 @@ int lq_msg_sign_salted(LQMsg *msg, LQPrivKey *pk, const char *salt, size_t salt_ msg->pubkey = lq_publickey_from_privatekey(pk); r = lq_digest(data, l, (char*)digest); - msg->signature = lq_privatekey_sign(pk, msg->data, msg->len, salt, salt_len); + //msg->signature = lq_privatekey_sign(pk, msg->data, msg->len, salt, salt_len); return r; } @@ -45,8 +45,12 @@ void lq_msg_free(LQMsg *msg) { if (msg->pubkey != 0) { lq_free(msg->pubkey); } - if (msg->signature != 0) { - lq_free(msg->signature); - } + //if (msg->signature != 0) { + // lq_free(msg->signature); + //} lq_free(msg); } + +char* lq_msg_serialize(LQMsg *msg, char *out, size_t *out_len) { + return NULL; +} diff --git a/src/lq/msg.h b/src/lq/msg.h @@ -15,7 +15,6 @@ struct lq_msg_t { char domain[LQ_MSG_DOMAIN_LEN]; int timestamp; LQPubKey *pubkey; - LQSig *signature; }; typedef struct lq_msg_t LQMsg; @@ -23,5 +22,7 @@ LQMsg* lq_msg_new(const char *msg_data, size_t msg_len); void lq_msg_set_domain(LQMsg *msg, const char *domain); int lq_msg_sign(LQMsg *msg, LQPrivKey *pk); int lq_msg_sign_salted(LQMsg *msg, LQPrivKey *pk, const char *salt, size_t salt_len); +char *lq_msg_serialize(LQMsg *msg, char *out, size_t *out_len); +int lq_msg_deserialize(LQMsg *msg, const char *in, size_t in_len); void lq_msg_free(LQMsg *msg); #endif // LIBQAEDA_MSG_H_