libqaeda

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

commit ebd96095c169e573774a0ff898de3ee216e00c08
parent 28ce06ad1a9bacc70476b7fbdb9b4785f48cd804
Author: lash <dev@holbrook.no>
Date:   Tue,  1 Apr 2025 01:28:03 +0100

Add merged static library builder

Diffstat:
MMakefile | 5++++-
Msrc/Makefile | 21+++++++++++++++++----
Msrc/asn1/Makefile | 5++++-
Msrc/aux/liblash/src/Makefile | 8++++++--
Msrc/cli/Makefile | 10++++++----
Msrc/cli/main.c | 2++
Msrc/crypto/gcrypt.c | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/lq/msg.c | 5++---
8 files changed, 88 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -all: +all: lib make -C src all lib: @@ -10,4 +10,7 @@ test: all clean: make -C src clean +#shared: lib +# make -C src shared-gpg + .PHONY: clean diff --git a/src/Makefile b/src/Makefile @@ -1,13 +1,20 @@ INCLUDES := -I. -I./aux/include CFLAGS += $(INCLUDES) -Wall -DRERR +LIBOBJFILES = ./asn1/*.o ./*.o ./lq/*.o ./store/file.o ./mem/std.o ./io/std.o ./crypto/gcrypt.o +LIBOBJEMBED = ./aux/lib/liblash.a #./aux/lib/libcwalk.a +LIBS := `pkg-config --libs libtasn1 libgcrypt` -L./aux/lib -llash -lcwalk all: all-gpg all-dummy: asn1 aux core dummy all-gpg: asn1 aux core gpg -lib: all -lib: - ar rcs liblq.a lq/config.o crypto/gcrypt.o store/file.o mem/std.o io/std.o debug.o aux/lib/libhashmap.a +dev-lib: all + #ar rcs liblq.a lq/config.o crypto/gcrypt.o store/file.o mem/std.o io/std.o debug.o aux/lib/libhashmap.a + ar rcs liblq.a $(LIBOBJFILES) + libtool --mode=link --tag=CC $(CC) -static -o libqaeda.a liblq.a ./aux/lib/liblash.a ./aux/lib/libcwalk.a + +test-lib: + ar rcs libqaedatest.a $(LIBOBJFILES) aux/lib/libhashmap.a core: dummy $(CC) $(CFLAGS) -c debug.c @@ -31,7 +38,7 @@ dummy: make -C io std make -C store dummy -test: all +test: all test-lib make -C test clean: @@ -40,5 +47,11 @@ clean: make -C test clean make -C mem clean make -C crypto clean + rm -vf *.o *.a *.so + +#shared-gpg: core aux asn1 gpg + #make -C aux/liblash/src lib + #$(CC) $(CFLAGS) -shared -o libqaeda.so $(LIBOBJFILES) $(LIBOBJEMBED) + .PHONY: clean asn1 aux diff --git a/src/asn1/Makefile b/src/asn1/Makefile @@ -2,7 +2,7 @@ INCLUDES := `pkg-config --cflags libtasn1` LIBS := `pkg-config --libs libtasn1` LDFLAGS += $(LIBS) -all: compile +all: compile dynamic src: $(CC) $(CFLAGS) generate.c -o generate_asn1 $(LDFLAGS) @@ -20,4 +20,7 @@ clean: rm -vf *_tab.c rm -vf generate_asn1 +dynamic: + + .PHONY: clean diff --git a/src/aux/liblash/src/Makefile b/src/aux/liblash/src/Makefile @@ -22,7 +22,10 @@ test: all make -C rerr test make -C case test -shared: all +lib: all + $(AR) rcs liblash.a ./endian/*.o ./hex/*.o ./llog/*.o ./rerr/*.o ./case/*.o + +shared: make -C endian shared make -C hex shared make -C llog shared @@ -30,7 +33,7 @@ shared: all make -C case shared $(CC) $(CFLAGS) -shared -o liblash.so endian/strip.so.o endian/endian.so.o hex/hex.so.o llog/llog.so.o rerr/rerr.so.o case/case.so.o -install: shared +install: lib shared cat -v endian/*.h > $(DESTDIR)/include/lash.h install -m0644 -v endian/*.h -t $(DESTDIR)/include cat -v hex/*.h >> $(DESTDIR)/include/lash.h @@ -44,6 +47,7 @@ install: shared #cp -v liblash.so $(DESTDIR)/lib/ install -m0644 -v liblash.so -t $(DESTDIR)/lib cd $(DESTDIR)/lib && ln -svf liblash.so liblash.so.$(VERSION) + install -m0644 -v liblash.a -t $(DESTDIR)/lib .PHONY: clean diff --git a/src/cli/Makefile b/src/cli/Makefile @@ -1,12 +1,14 @@ INCLUDES := -I.. -I../lq -I../aux/include CFLAGS += $(INCLUDES) -Wall -OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/file.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o +#OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/file.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o #OBJFILES += ../asn1/*.o ../*.o ../lq/*.o ../store/mem.o ../mem/std.o ../io/std.o ../crypto/gcrypt.o -LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk +#LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk #LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -L../aux/lib -llash -lcwalk -lhashmap -LDFLAGS += -L../aux/lib -L../ $(LIBS) +LIBS := `pkg-config --libs libtasn1 libgcrypt libxdg-basedir` -lqaeda +LDFLAGS += -L../aux/lib -L.. $(LIBS) all: - gcc $(CFLAGS) main.c -o a.out $(OBJFILES) $(LDFLAGS) + #gcc $(CFLAGS) main.c -o a.out $(OBJFILES) $(LDFLAGS) + gcc $(CFLAGS) main.c -o a.out $(LDFLAGS) .PHONY: clean asn1 aux diff --git a/src/cli/main.c b/src/cli/main.c @@ -138,5 +138,7 @@ int main(int argc, char **argv) { r = lq_certificate_verify(cert, pubk_alice, NULL); + lq_certificate_free(cert); + lq_ui_free(); } diff --git a/src/crypto/gcrypt.c b/src/crypto/gcrypt.c @@ -346,9 +346,11 @@ static int key_create(struct gpg_store *gpg) { // Generate a new key with the given parameters. e = gcry_pk_genkey(&gpg->k, in); if (e) { + gcry_sexp_release(in); p = gcry_strerror(e); return debug_logerr(LLOG_ERROR, ERR_KEYFAIL, (char*)p); } + gcry_sexp_release(in); // Apply the public part of the key to the underlying key structure. r = key_apply_public(gpg); @@ -755,6 +757,7 @@ static int sign(struct gpg_store *gpg, const char *data, size_t data_len, const gcry_sexp_t sig; gcry_error_t e; + lq_zero(&e, sizeof(gcry_error_t)); r = calculate_digest_algo(data, data_len, gpg->last_data, GCRY_MD_SHA512); if (r) { return 1; @@ -768,6 +771,7 @@ static int sign(struct gpg_store *gpg, const char *data, size_t data_len, const e = gcry_pk_sign(&sig, msg, gpg->k); if (e != GPG_ERR_NO_ERROR) { + gcry_sexp_release(msg); return 1; } @@ -775,29 +779,43 @@ static int sign(struct gpg_store *gpg, const char *data, size_t data_len, const pnt = NULL; pnt = gcry_sexp_find_token(sig, "r", 1); if (pnt == NULL) { - return 1; + gcry_sexp_release(sig); + gcry_sexp_release(msg); + return ERR_FAIL; } c = LQ_POINT_LEN; p = (char*)gcry_sexp_nth_data(pnt, 1, &c); if (p == NULL) { - return 1; + gcry_sexp_release(pnt); + gcry_sexp_release(sig); + gcry_sexp_release(msg); + return ERR_SIGVALID; } lq_cpy(gpg->last_signature, p, c); // retrieve s and write it + gcry_sexp_release(pnt); pnt = NULL; pnt = gcry_sexp_find_token(sig, "s", 1); if (pnt == NULL) { - return 1; + gcry_sexp_release(sig); + gcry_sexp_release(msg); + return ERR_FAIL; } c = LQ_POINT_LEN; p = (char*)gcry_sexp_nth_data(pnt, 1, &c); if (p == NULL) { - return 1; + gcry_sexp_release(pnt); + gcry_sexp_release(sig); + gcry_sexp_release(msg); + return ERR_SIGVALID; } lq_cpy(gpg->last_signature + LQ_POINT_LEN, p, c); + gcry_sexp_release(pnt); + gcry_sexp_release(sig); + gcry_sexp_release(msg); - return 0; + return ERR_OK; } LQSig* lq_privatekey_sign(LQPrivKey *pk, const char *data, size_t data_len, const char *salt) { @@ -870,43 +888,67 @@ int lq_signature_verify(LQSig *sig, const char *data, size_t data_len) { c = 0; err = gcry_mpi_scan(&sig_r, GCRYMPI_FMT_STD, sig->impl, LQ_POINT_LEN, &c); if (err != GPG_ERR_NO_ERROR) { + gcry_sexp_release(pubkey); return ERR_KEYFAIL; } if (c != 32) { + gcry_mpi_release(sig_r); + gcry_sexp_release(pubkey); return ERR_KEYFAIL; } c = 0; err = gcry_mpi_scan(&sig_s, GCRYMPI_FMT_STD, sig->impl + LQ_POINT_LEN, LQ_POINT_LEN, &c); if (err != GPG_ERR_NO_ERROR) { + gcry_mpi_release(sig_r); + gcry_sexp_release(pubkey); return ERR_KEYFAIL; } if (c != 32) { + gcry_mpi_release(sig_s); + gcry_mpi_release(sig_r); + gcry_sexp_release(pubkey); return ERR_KEYFAIL; } c = 0; err = gcry_sexp_build(&sigx, &c, "(sig-val(eddsa(r %m)(s %m)))", sig_r, sig_s); if (err != GPG_ERR_NO_ERROR) { + gcry_mpi_release(sig_s); + gcry_mpi_release(sig_r); + gcry_sexp_release(pubkey); return ERR_SIGFAIL; } + gcry_mpi_release(sig_s); + gcry_mpi_release(sig_r); r = calculate_digest_algo(data, data_len, digest, GCRY_MD_SHA512); if (r) { + gcry_sexp_release(sigx); + gcry_sexp_release(pubkey); return ERR_DIGEST; } c = 0; err = gcry_sexp_build(&msgx, &c, "(data(flags eddsa)(hash-algo sha512)(value %b))", LQ_DIGEST_LEN, digest); if (err != GPG_ERR_NO_ERROR) { + gcry_sexp_release(sigx); + gcry_sexp_release(pubkey); return ERR_DIGEST; } err = gcry_pk_verify(sigx, msgx, pubkey); if (err != GPG_ERR_NO_ERROR) { + gcry_sexp_release(msgx); + gcry_sexp_release(sigx); + gcry_sexp_release(pubkey); return ERR_SIGVALID; } + gcry_sexp_release(msgx); + gcry_sexp_release(sigx); + gcry_sexp_release(pubkey); + return ERR_OK; } diff --git a/src/lq/msg.c b/src/lq/msg.c @@ -12,7 +12,7 @@ static char zeros[LQ_PUBKEY_LEN]; static LQPubKey nokey = { - .pk = 0, + .pk = NULL, .impl = zeros, }; @@ -39,7 +39,6 @@ LQSig* lq_msg_sign_extra(LQMsg *msg, LQPrivKey *pk, const char *salt, const char int r; char *data; char digest[LQ_DIGEST_LEN]; - LQSig *sig; if (extra == NULL) { extra_len = 0; @@ -60,7 +59,7 @@ LQSig* lq_msg_sign_extra(LQMsg *msg, LQPrivKey *pk, const char *salt, const char } void lq_msg_free(LQMsg *msg) { - if (msg->pubkey != 0) { + if (msg->pubkey->pk = NULL) { lq_free(msg->pubkey); } lq_free(msg->data);