aboutsummaryrefslogtreecommitdiff
path: root/src/mbedtls.c
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2020-09-28 17:46:33 +0930
committerDavid Timber <mieabby@gmail.com>2020-09-28 17:46:33 +0930
commit5dbfcb1f66b681fbb6cdec8836efe2c2d84f957e (patch)
treeea0412b8e33ee991f83b3832f93852d7d4c5484e /src/mbedtls.c
parent909e45f775fb5908ab7a4d68eabf9beb91e36ef2 (diff)
The 80 column rule ...
* Remove prne_rnd_anum_str()
Diffstat (limited to 'src/mbedtls.c')
-rw-r--r--src/mbedtls.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/mbedtls.c b/src/mbedtls.c
index 3b1919a..7af5e80 100644
--- a/src/mbedtls.c
+++ b/src/mbedtls.c
@@ -13,12 +13,21 @@
#include <mbedtls/entropy_poll.h>
-int prne_mbedtls_x509_crt_verify_cb (void *param, mbedtls_x509_crt *crt, int crt_depth, uint32_t *flags) {
+int prne_mbedtls_x509_crt_verify_cb (
+ void *param,
+ mbedtls_x509_crt *crt,
+ int crt_depth,
+ uint32_t *flags)
+{
*flags &= ~(uint32_t)MBEDTLS_X509_BADCERT_EXPIRED;
return 0;
}
-int prne_mbedtls_ssl_send_cb (void *ctx, const unsigned char *buf, size_t len) {
+int prne_mbedtls_ssl_send_cb (
+ void *ctx,
+ const unsigned char *buf,
+ size_t len)
+{
const int fd = *(int*)ctx;
ssize_t ret;
@@ -58,7 +67,12 @@ int prne_mbedtls_ssl_recv_cb (void *ctx, unsigned char *buf, size_t len) {
return ret;
}
-static int prne_mbedtls_entropy_urand_src_f (void *data, unsigned char *output, size_t len, size_t *olen) {
+static int prne_mbedtls_entropy_urand_src_f (
+ void *data,
+ unsigned char *output,
+ size_t len,
+ size_t *olen)
+{
const int fd = open("/dev/urandom", O_RDONLY);
int func_ret = 0;
@@ -82,7 +96,12 @@ typedef struct {
struct timespec datetime;
} ent_buf_t;
-static int prne_mbedtls_entropy_proc_src_f (void *data, unsigned char *output, size_t len, size_t *olen) {
+static int prne_mbedtls_entropy_proc_src_f (
+ void *data,
+ unsigned char *output,
+ size_t len,
+ size_t *olen)
+{
ent_buf_t buf;
prne_memzero(&buf, sizeof(buf));
@@ -101,14 +120,31 @@ static int prne_mbedtls_entropy_proc_src_f (void *data, unsigned char *output, s
void prne_mbedtls_entropy_init (mbedtls_entropy_context *ctx) {
mbedtls_entropy_init(ctx);
- // Remove platform source, which could call getrandom()
+ /*
+ * Remove platform source, which could call getrandom().
+ * Add our own implementation as the one just got removed could be the only
+ * source.
+ */
for (int i = 0; i < ctx->source_count; i += 1) {
if (ctx->source[i].f_source == mbedtls_platform_entropy_poll) {
- memmove(ctx->source + i, ctx->source + i + 1, sizeof(mbedtls_entropy_source_state) * (ctx->source_count - i - 1));
+ memmove(
+ ctx->source + i,
+ ctx->source + i + 1,
+ sizeof(mbedtls_entropy_source_state) *
+ (ctx->source_count - i - 1));
ctx->source_count -= 1;
- // Add our own implementation as the one just got removed could be the only source.
- mbedtls_entropy_add_source(ctx, prne_mbedtls_entropy_urand_src_f, NULL, MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_SOURCE_STRONG);
- mbedtls_entropy_add_source(ctx, prne_mbedtls_entropy_proc_src_f, NULL, sizeof(ent_buf_t), MBEDTLS_ENTROPY_SOURCE_STRONG);
+ mbedtls_entropy_add_source(
+ ctx,
+ prne_mbedtls_entropy_urand_src_f,
+ NULL,
+ MBEDTLS_ENTROPY_MIN_PLATFORM,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
+ mbedtls_entropy_add_source(
+ ctx,
+ prne_mbedtls_entropy_proc_src_f,
+ NULL,
+ sizeof(ent_buf_t),
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
break;
}
}