/** * Copyright (C) 2021 Mikael Magnusson * * 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 #include #include #include /* 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 *output2) { uint8_t tmp[16]; md5_end(tmp, &ctx->md5); memcpy(output, tmp, 8); if (output2) memcpy(output2, tmp + 8, 8); } #if 0 void prng_free() { } #endif