aboutsummaryrefslogtreecommitdiffstats
path: root/libar2_encode_params.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-16 19:58:57 +0100
committerMattias Andrée <maandree@kth.se>2022-01-16 19:58:57 +0100
commit8bdc2e4929068210d523c34c0b171b51ce96057f (patch)
treec77331e77b9777a37716bffb7365c4486a6df9a0 /libar2_encode_params.c
downloadlibar2-8bdc2e4929068210d523c34c0b171b51ce96057f.tar.gz
libar2-8bdc2e4929068210d523c34c0b171b51ce96057f.tar.bz2
libar2-8bdc2e4929068210d523c34c0b171b51ce96057f.tar.xz
First commit1.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libar2_encode_params.c')
-rw-r--r--libar2_encode_params.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libar2_encode_params.c b/libar2_encode_params.c
new file mode 100644
index 0000000..cdf634a
--- /dev/null
+++ b/libar2_encode_params.c
@@ -0,0 +1,31 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+size_t
+libar2_encode_params(char *buf, const struct libar2_argon2_parameters *params)
+{
+ size_t off;
+
+#define FMT_AND_ARGS\
+ "$%s$v=%i$m=%ju,t=%ju,p=%ju$",\
+ libar2_type_to_string(params->type, LIBAR2_LOWER_CASE),\
+ (int)params->version,\
+ (uintmax_t)params->m_cost,\
+ (uintmax_t)params->t_cost,\
+ (uintmax_t)params->lanes
+
+ if (buf) {
+ off = (size_t)sprintf(buf, FMT_AND_ARGS);
+ off += libar2_encode_base64(&buf[off], params->salt, params->saltlen) - 1;
+ buf[off++] = '$';
+ buf[off++] = '\0';
+
+ } else {
+ off = (size_t)snprintf(NULL, 0, FMT_AND_ARGS);
+ off += libar2_encode_base64(NULL, params->salt, params->saltlen) - 1;
+ off += 2;
+ }
+
+ return off;
+}