summaryrefslogtreecommitdiffhomepage
path: root/src/prng_md5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prng_md5.c')
-rw-r--r--src/prng_md5.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/prng_md5.c b/src/prng_md5.c
new file mode 100644
index 0000000..77682a2
--- /dev/null
+++ b/src/prng_md5.c
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2021 Mikael Magnusson <mikma@user.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "prng.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libubox/md5.h>
+
+
+/* PRNG using MD5 from libubox. */
+struct prng_context_s
+{
+ md5_ctx_t md5;
+};
+
+
+prng_context_t *prng_alloc()
+{
+ prng_context_t *ctx = calloc(1, sizeof(prng_context_t));
+ return ctx;
+}
+
+void prng_setup(prng_context_t *ctx)
+{
+ memset(ctx, 0, sizeof(*ctx));
+}
+
+void prng_starts(prng_context_t *ctx)
+{
+ md5_begin(&ctx->md5);
+}
+
+void prng_update(prng_context_t *ctx, const uint8_t *input, size_t ilen)
+{
+ md5_hash(input, ilen, &ctx->md5);
+}
+
+void prng_finish(prng_context_t *ctx, uint8_t *output)
+{
+ uint8_t tmp[16];
+ md5_end(tmp, &ctx->md5);
+ memcpy(output, tmp, 8);
+}
+
+#if 0
+void prng_free()
+{
+}
+#endif