summaryrefslogtreecommitdiff
path: root/src/rexmpp_jingle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rexmpp_jingle.c')
-rw-r--r--src/rexmpp_jingle.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/rexmpp_jingle.c b/src/rexmpp_jingle.c
index 25cbdb4..1e0674c 100644
--- a/src/rexmpp_jingle.c
+++ b/src/rexmpp_jingle.c
@@ -17,8 +17,7 @@ The following XEPs are handled here so far:
#include <errno.h>
#include <libgen.h>
#include <gsasl.h>
-#include <nettle/sha2.h>
-#include <nettle/sha3.h>
+#include <gcrypt.h>
#include "rexmpp.h"
#include "rexmpp_jingle.h"
@@ -279,38 +278,43 @@ rexmpp_jingle_send_file (rexmpp_t *s,
char buf[4096];
- char hash_sha256[SHA256_DIGEST_SIZE];
- struct sha256_ctx sha2_ctx;
- sha256_init(&sha2_ctx);
- char hash_sha3_256[SHA3_256_DIGEST_SIZE];
- struct sha3_256_ctx sha3_ctx;
- sha3_256_init(&sha3_ctx);
+ gcry_md_hd_t hd;
+ /* todo: check for hashing errors */
+ gcry_md_open(&hd, GCRY_MD_SHA256, 0);
+ gcry_md_enable(hd, GCRY_MD_SHA3_256);
size_t len = fread(buf, 1, 4096, fh);
while (len > 0) {
- sha256_update(&sha2_ctx, len, buf);
- sha3_256_update(&sha3_ctx, len, buf);
+ gcry_md_write(hd, buf, len);
len = fread(buf, 1, 4096, fh);
}
- sha256_digest(&sha2_ctx, SHA256_DIGEST_SIZE, hash_sha256);
+ gcry_md_final(hd);
+
char *hash_base64 = NULL;
size_t hash_base64_len = 0;
- gsasl_base64_to(hash_sha256, SHA256_DIGEST_SIZE, &hash_base64, &hash_base64_len);
+ gsasl_base64_to(gcry_md_read(hd, GCRY_MD_SHA256),
+ gcry_md_get_algo_dlen(GCRY_MD_SHA256),
+ &hash_base64,
+ &hash_base64_len);
xmlNodePtr file_hash = rexmpp_xml_new_node("hash", "urn:xmpp:hashes:2");
xmlNewProp(file_hash, "algo", "sha-256");
xmlNodeAddContent(file_hash, hash_base64);
free(hash_base64);
xmlAddChild(file, file_hash);
- sha3_256_digest(&sha3_ctx, SHA3_256_DIGEST_SIZE, hash_sha3_256);
hash_base64 = NULL;
hash_base64_len = 0;
- gsasl_base64_to(hash_sha3_256, SHA3_256_DIGEST_SIZE, &hash_base64, &hash_base64_len);
+ gsasl_base64_to(gcry_md_read(hd, GCRY_MD_SHA3_256),
+ gcry_md_get_algo_dlen(GCRY_MD_SHA3_256),
+ &hash_base64,
+ &hash_base64_len);
file_hash = rexmpp_xml_new_node("hash", "urn:xmpp:hashes:2");
xmlNewProp(file_hash, "algo", "sha3-256");
xmlNodeAddContent(file_hash, hash_base64);
free(hash_base64);
xmlAddChild(file, file_hash);
+ gcry_md_close(hd);
+
long fsize = ftell(fh);
fseek(fh, 0, SEEK_SET);
snprintf(buf, 11, "%ld", fsize);