commit 4e882ad6e1d33574f987d7cf7d4317acee904c5c
parent a2ba4134748996e8a3603bd43a897aac7986bcc1
Author: lash <dev@holbrook.no>
Date: Sat, 1 Mar 2025 17:40:09 +0000
Add digest
Diffstat:
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/src/crypto/dummy.c b/src/crypto/dummy.c
@@ -21,6 +21,14 @@ static const char sig_dummy_transform[64] = {
0x5b, 0xe3, 0xaa, 0x2f, 0xc1, 0xe6, 0xc1, 0x81,
};
+// sha256sum "baz" baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096
+static const char digest_dummy_transform[32] = {
+ 0xba, 0xa5, 0xa0, 0x96, 0x4d, 0x33, 0x20, 0xfb,
+ 0xc0, 0xc6, 0xa9, 0x22, 0x14, 0x04, 0x53, 0xc8,
+ 0x51, 0x3e, 0xa2, 0x4a, 0xb8, 0xfd, 0x05, 0x77,
+ 0x03, 0x48, 0x04, 0xa9, 0x67, 0x24, 0x80, 0x96
+};
+
LQPrivKey* lq_privatekey_new(char *seed, size_t seed_len) {
LQPrivKey *pk;
@@ -112,3 +120,16 @@ void lq_signature_free(LQSig *sig) {
lq_free(sig->losig);
lq_free(sig);
}
+
+int lq_digest(const char *in, size_t in_len, char *out) {
+ int i;
+ int ii;
+ lq_set(out, 0, LQ_DIGEST_LEN);
+
+ for (i = 0; i < in_len; i++) {
+ ii = i % LQ_DIGEST_LEN;
+ *(out + ii) = *(in + i) ^ digest_dummy_transform[ii];
+ }
+
+ return 0;
+}
diff --git a/src/lq/crypto.h b/src/lq/crypto.h
@@ -3,6 +3,10 @@
#include <stddef.h>
+#ifndef LQ_DIGEST_LEN
+#define LQ_DIGEST_LEN 32
+#endif
+
struct lq_privatekey_t {
int key_typ;
void *lokey;
@@ -31,5 +35,6 @@ LQSig* lq_privatekey_sign(LQPrivKey *pk, const char *msg, size_t msg_len, const
void lq_publickey_free(LQPubKey *pubk);
void lq_privatekey_free(LQPrivKey *pk);
void lq_signature_free(LQSig *sig);
+int lq_digest(const char *in, size_t in_len, char *out);
#endif // LIBQAEDA_CRYPTO_H_
diff --git a/src/lq/mem.h b/src/lq/mem.h
@@ -5,7 +5,7 @@
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);
+void* lq_cpy(void *dst, const void *src, size_t len);
+void* lq_set(void *dst, const char b, size_t len);
#endif // LIBQAEDA_MEM_H_
diff --git a/src/lq/msg.c b/src/lq/msg.c
@@ -24,16 +24,21 @@ int lq_msg_sign(LQMsg *msg, LQPrivKey *pk) {
}
int lq_msg_sign_salted(LQMsg *msg, LQPrivKey *pk, const char *salt, size_t salt_len) {
+ size_t l;
+ int r;
char *data;
+ char digest[LQ_DIGEST_LEN];
- data = lq_alloc(LQ_MSG_DOMAIN_LEN + msg->len);
+ l = LQ_MSG_DOMAIN_LEN + msg->len;
+ data = lq_alloc(l);
lq_cpy(data, msg->domain, LQ_MSG_DOMAIN_LEN);
lq_cpy(data + LQ_MSG_DOMAIN_LEN, msg->data, msg->len);
msg->pubkey = lq_publickey_from_privatekey(pk);
- // TODO: digest msg
+ r = lq_digest(data, l, (char*)digest);
msg->signature = lq_privatekey_sign(pk, msg->data, msg->len, salt, salt_len);
- return 0;
+
+ return r;
}
void lq_msg_free(LQMsg *msg) {