aboutsummaryrefslogtreecommitdiffstats
path: root/libar2simplified_crypt.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-02-14 21:28:52 +0100
committerMattias Andrée <maandree@kth.se>2022-02-14 21:28:52 +0100
commitea565f8d945db5dd0a638973fecae37318412bbf (patch)
treeac86bfd810383102010c82736684cc872f8cee2a /libar2simplified_crypt.c
parentXOR seed provided to srand with data depending on current seed, in case it is already seed in a better manner (diff)
downloadlibar2simplified-ea565f8d945db5dd0a638973fecae37318412bbf.tar.gz
libar2simplified-ea565f8d945db5dd0a638973fecae37318412bbf.tar.bz2
libar2simplified-ea565f8d945db5dd0a638973fecae37318412bbf.tar.xz
Add libar2simplified_crypt and fix threading
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libar2simplified_crypt.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libar2simplified_crypt.c b/libar2simplified_crypt.c
new file mode 100644
index 0000000..7d255d4
--- /dev/null
+++ b/libar2simplified_crypt.c
@@ -0,0 +1,43 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+char *
+libar2simplified_crypt(char *msg, const char *paramstr, char *rv)
+{
+ struct libar2_argon2_parameters *params = NULL;
+ char *end, *ret = NULL, *hash = NULL;
+ size_t size;
+
+ params = libar2simplified_decode(paramstr, NULL, &end, NULL);
+ if (!params)
+ goto out;
+ if (*end) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ if (!rv) {
+ size = libar2_hash_buf_size(params);
+ if (!size || !(hash = malloc(size))) {
+ errno = ENOMEM;
+ goto out;
+ }
+ }
+ if (libar2simplified_hash(rv ? rv : hash, msg, strlen(msg), params))
+ goto out;
+
+ ret = libar2simplified_encode(params, rv ? rv : hash);
+ if (rv) {
+ stpcpy(rv, ret);
+ free(ret);
+ ret = rv;
+ }
+
+out:
+ if (params)
+ libar2_erase(params->salt, params->saltlen);
+ free(params);
+ free(hash);
+ return ret;
+}