| 1 | /* |
| 2 | * Copyright (C) 2026, Stephan Mueller <[email protected]> |
| 3 | * |
| 4 | * License: see LICENSE file in root directory |
| 5 | * |
| 6 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 7 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 8 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF |
| 9 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
| 10 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 11 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| 12 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 13 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 16 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | |
| 22 | #include "jitterentropy.h"cxx . . $ `<file>/jitterentropy.h`/ |
| 23 | #include "jitterentropy-base.h"cxx . . $ `<file>/lib/jitterentropy-base.h`/ |
| 24 | #include "jitterentropy-internal.h"cxx . . $ `<file>/lib/jitterentropy-internal.h`/ |
| 25 | |
| 26 | /* |
| 27 | * Always validate the output with something like "jq -e .", when doing changes here. |
| 28 | * |
| 29 | * No JSON library is used here to keep dependencies slim and this is serialized only |
| 30 | * here. |
| 31 | */ |
| 32 | int jent_statuscxx . . $ jent_status(b830aaa7046db909).(const struct rand_datacxx . . $ rand_data# *ec, char *buf, size_t buflen) |
| 33 | { |
| 34 | size_t used; |
| 35 | |
| 36 | if (!buf || buflen == 0) |
| 37 | return -1; |
| 38 | |
| 39 | #define jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!(...) \ |
| 40 | { \ |
| 41 | used = strlen(buf); \ |
| 42 | if (used < buflen) \ |
| 43 | snprintf(buf + used, buflen - used, __VA_ARGS__);\ |
| 44 | } |
| 45 | |
| 46 | /* needed as plain snprintf to make jent_add_to_status len calculation usable */ |
| 47 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, buflen, "{\n"); |
| 48 | |
| 49 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\"version\": \"%u.%u.%u\",\n", |
| 50 | JENT_MAJVERSIONcxx . . $ `jitterentropy.h:60:9`!, JENT_MINVERSIONcxx . . $ `jitterentropy.h:66:9`!, JENT_PATCHLEVELcxx . . $ `jitterentropy.h:73:9`!) |
| 51 | |
| 52 | if (!ec) |
| 53 | goto out; |
| 54 | |
| 55 | /* |
| 56 | * health |
| 57 | */ |
| 58 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\"healthFailure\": {\n"); |
| 59 | |
| 60 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"apt\": {\n"); |
| 61 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"intermittent\": %s,\n", |
| 62 | ec->health_failure & JENT_APT_FAILUREcxx . . $ `jitterentropy.h:288:9`! ? "true" : "false"); |
| 63 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"permanent\": %s\n", |
| 64 | ec->health_failure & JENT_APT_FAILURE_PERMANENTcxx . . $ `jitterentropy.h:294:9`! ? "true" : "false"); |
| 65 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t},\n"); |
| 66 | |
| 67 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"rct\": {\n"); |
| 68 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"intermittent\": %s,\n", |
| 69 | ec->health_failure & JENT_RCT_FAILUREcxx . . $ `jitterentropy.h:287:9`! ? "true" : "false"); |
| 70 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"permanent\": %s\n", |
| 71 | ec->health_failure & JENT_RCT_FAILURE_PERMANENTcxx . . $ `jitterentropy.h:293:9`! ? "true" : "false"); |
| 72 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t},\n"); |
| 73 | |
| 74 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"rctMemory\": {\n"); |
| 75 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"intermittent\": %s,\n", |
| 76 | ec->health_failure & JENT_RCT_MEM_FAILUREcxx . . $ `jitterentropy.h:290:9`! ? "true" : "false"); |
| 77 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"permanent\": %s\n", |
| 78 | ec->health_failure & JENT_RCT_MEM_FAILURE_PERMANENTcxx . . $ `jitterentropy.h:296:9`! ? "true" : "false"); |
| 79 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t}"); |
| 80 | |
| 81 | #ifdef JENT_HEALTH_LAG_PREDICTORcxx . . $ `lib/jitterentropy-internal.h:86:9`! |
| 82 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!(",\n"); |
| 83 | |
| 84 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"lag\": {\n"); |
| 85 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"intermittent\": %s,\n", |
| 86 | ec->health_failure & JENT_LAG_FAILUREcxx . . $ `jitterentropy.h:289:9`! ? "true" : "false"); |
| 87 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"permanent\": %s\n", |
| 88 | ec->health_failure & JENT_LAG_FAILURE_PERMANENTcxx . . $ `jitterentropy.h:295:9`! ? "true" : "false"); |
| 89 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t}\n"); |
| 90 | #else |
| 91 | jent_add_to_status("\n"); |
| 92 | #endif |
| 93 | |
| 94 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t},\n"); |
| 95 | |
| 96 | /* |
| 97 | * runtime environment |
| 98 | */ |
| 99 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!( "\t\"runtimeEnvironment\": {\n"); |
| 100 | |
| 101 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"cpuCores\": %ld,\n", jent_ncpu()); |
| 102 | |
| 103 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"cpuCache\": {\n"); |
| 104 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"l1Bytes\": %u,\n", jent_cache_size_roundup(0)); |
| 105 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"allBytes\": %u\n", jent_cache_size_roundup(1)); |
| 106 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t}\n"); |
| 107 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t},\n"); |
| 108 | |
| 109 | /* |
| 110 | * configuration |
| 111 | */ |
| 112 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!( "\t\"configuration\": {\n"); |
| 113 | |
| 114 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!( "\t\t\"osr\": %u,\n", ec->osr); |
| 115 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!( "\t\t\"memoryBlockSizeBytes\": %u,\n", jent_memsize(ec->flags)); |
| 116 | |
| 117 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"hashLoopCount\": {\n"); |
| 118 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"runtime\": %u,\n", jent_hashloop_cnt(ec->flags)); |
| 119 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"initialization\": %u\n", jent_hashloop_cnt(ec->flags) * JENT_HASH_LOOP_INITcxx . . $ `lib/jitterentropy-internal.h:225:9`!); |
| 120 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t},\n"); |
| 121 | |
| 122 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"memoryLoopCount\": {\n"); |
| 123 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"runtime\": %u,\n", ec->memaccessloops); |
| 124 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"initialization\": %u\n", ec->memaccessloops * JENT_MEM_ACC_LOOP_INITcxx . . $ `lib/jitterentropy-internal.h:186:9`!); |
| 125 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t},\n"); |
| 126 | |
| 127 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"secureMemory\": %s,\n", jent_secure_memory_supported() ? "true" : "false"); |
| 128 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"internalTimer\": %s,\n", ec->enable_notime ? "true" : "false"); |
| 129 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"fipsMode\": %s,\n", ec->fips_enabled ? "true" : "false"); |
| 130 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"ntg1Mode\": %s,\n", !!(ec->flags & JENT_NTG1cxx . . $ `jitterentropy.h:93:9`!) ? "true" : "false"); |
| 131 | |
| 132 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\"flags\": {\n"); |
| 133 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_DISABLE_MEMORY_ACCESS\": %s,\n", |
| 134 | !!(ec->flags & JENT_DISABLE_MEMORY_ACCESScxx . . $ `jitterentropy.h:83:9`!) ? "true" : "false"); |
| 135 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_FORCE_INTERNAL_TIMER\": %s,\n", |
| 136 | !!(ec->flags & JENT_FORCE_INTERNAL_TIMERcxx . . $ `jitterentropy.h:86:9`!) ? "true" : "false"); |
| 137 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_DISABLE_INTERNAL_TIMER\": %s,\n", |
| 138 | !!(ec->flags & JENT_DISABLE_INTERNAL_TIMERcxx . . $ `jitterentropy.h:88:9`!) ? "true" : "false"); |
| 139 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_FORCE_FIPS\": %s,\n", |
| 140 | !!(ec->flags & JENT_FORCE_FIPScxx . . $ `jitterentropy.h:90:9`!) ? "true" : "false"); |
| 141 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_NTG1\": %s,\n", |
| 142 | !!(ec->flags & JENT_NTG1cxx . . $ `jitterentropy.h:93:9`!) ? "true" : "false"); |
| 143 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t\t\"JENT_CACHE_ALL\": %s\n", |
| 144 | !!(ec->flags & JENT_CACHE_ALLcxx . . $ `jitterentropy.h:94:9`!) ? "true" : "false"); |
| 145 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t\t}\n"); |
| 146 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("\t}\n"); |
| 147 | |
| 148 | out: |
| 149 | jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`!("}\n"); |
| 150 | |
| 151 | used = strlencxx . . $ strlen(751346f8406fd082).(buf); |
| 152 | return (used >= buflen - 1) ? -1 : 0; |
| 153 | #undef jent_add_to_statuscxx . . $ `lib/jitterentropy-status.c:39:10`! |
| 154 | } |