#ifdef __OPTIMIZE__ #error"The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy.c." #endif
/* The entropy pool */ struct rand_data { /* SHA3-256 is used as conditioner */ #define DATA_SIZE_BITS 256 /* all data values that are vital to maintain the security *oftheRNGaremarkedasSENSITIVE.Ausermustnot *accessthatinformationwhiletheRNGexecutesitsloopsto
* calculate the next random value. */ void *hash_state; /* SENSITIVE hash state entropy pool */
__u64 prev_time; /* SENSITIVE Previous time stamp */
__u64 last_delta; /* SENSITIVE stuck test */
__s64 last_delta2; /* SENSITIVE stuck test */
unsignedint flags; /* Flags used to initialize */ unsignedint osr; /* Oversample rate */ #define JENT_MEMORY_ACCESSLOOPS 128 #define JENT_MEMORY_SIZE \
(CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKS * \
CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE) unsignedchar *mem; /* Memory access location with size of
* memblocks * memblocksize */ unsignedint memlocation; /* Pointer to byte in *mem */ unsignedint memblocks; /* Number of memory blocks in *mem */ unsignedint memblocksize; /* Size of one memory block in bytes */ unsignedint memaccessloops; /* Number of memory accesses per random
* bit generation */
/* Repetition Count Test */ unsignedint rct_count; /* Number of stuck values */
/* Adaptive Proportion Test cutoff values */ unsignedint apt_cutoff; /* Intermittent health test failure */ unsignedint apt_cutoff_permanent; /* Permanent health test failure */ #define JENT_APT_WINDOW_SIZE 512/* Data window size */ /* LSB of time stamp to process */ #define JENT_APT_LSB 16 #define JENT_APT_WORD_MASK (JENT_APT_LSB - 1) unsignedint apt_observations; /* Number of collected observations */ unsignedint apt_count; /* APT counter */ unsignedint apt_base; /* APT base reference */ unsignedint health_failure; /* Record health failure */
unsignedint apt_base_set:1; /* APT base reference set? */
};
/* Flags that can be used to initialize the RNG */ #define JENT_DISABLE_MEMORY_ACCESS (1<<2) /* Disable memory access for more *entropy,savesMEMORY_SIZERAMfor
* entropy collector */
/* -- error codes for init function -- */ #define JENT_ENOTIME 1/* Timer service not available */ #define JENT_ECOARSETIME 2/* Timer too coarse for RNG */ #define JENT_ENOMONOTONIC 3/* Timer is not monotonic increasing */ #define JENT_EVARVAR 5/* Timer does not produce variations of *variations(2ndderivationoftimeis
* zero). */ #define JENT_ESTUCK 8/* Too many stuck results during init. */ #define JENT_EHEALTH 9/* Health test failed during initialization */ #define JENT_ERCT 10/* RCT failed during initialization */ #define JENT_EHASH 11/* Hash self test failed */ #define JENT_EMEM 12/* Can't allocate memory for initialization */
#define JENT_RCT_FAILURE 1/* Failure in RCT health test. */ #define JENT_APT_FAILURE 2/* Failure in APT health test. */ #define JENT_PERMANENT_FAILURE_SHIFT 16 #define JENT_PERMANENT_FAILURE(x) (x << JENT_PERMANENT_FAILURE_SHIFT) #define JENT_RCT_FAILURE_PERMANENT JENT_PERMANENT_FAILURE(JENT_RCT_FAILURE) #define JENT_APT_FAILURE_PERMANENT JENT_PERMANENT_FAILURE(JENT_APT_FAILURE)
if (!current_delta || !delta2 || !delta3) { /* RCT with a stuck bit */
jent_rct_insert(ec, 1); return1;
}
/* RCT with a non-stuck bit */
jent_rct_insert(ec, 0);
return0;
}
/* *Reportanyhealthtestfailures * *@ec[in]Referencetoentropycollector * *@returnabitmaskindicatingwhichtestsfailed *0Nohealthtestfailure *1RCTfailure *2APTfailure *1<<JENT_PERMANENT_FAILURE_SHIFTRCTpermanentfailure *2<<JENT_PERMANENT_FAILURE_SHIFTAPTpermanentfailure
*/ staticunsignedint jent_health_failure(struct rand_data *ec)
{ /* Test is only enabled in FIPS mode */ if (!fips_enabled) return0;
int jent_entropy_init(unsignedint osr, unsignedint flags, void *hash_state, struct rand_data *p_ec)
{ /* *Ifcallerprovidesanallocatedec,reuseitwhichimpliesthatthe *healthtestentropydataisusedtofurtherstilltheavailable *entropypool.
*/ struct rand_data *ec = p_ec; int i, time_backwards = 0, ret = 0, ec_free = 0; unsignedint health_test_result;
if (!ec) {
ec = jent_entropy_collector_alloc(osr, flags, hash_state); if (!ec) return JENT_EMEM;
ec_free = 1;
} else { /* Reset the APT */
jent_apt_reset(ec, 0); /* Ensure that a new APT base is obtained */
ec->apt_base_set = 0; /* Reset the RCT */
ec->rct_count = 0; /* Reset intermittent, leave permanent health test result */
ec->health_failure &= (~JENT_RCT_FAILURE);
ec->health_failure &= (~JENT_APT_FAILURE);
}
/* We could perform statistical tests here, but the problem is *thatweonlyhaveafewloopcountstodotesting.These *loopcountsmayshowsomeslightskewandweproduce *falsepositives. * *Moreover,onlyoldsystemsshowpotentiallyproblematic *jitterentropythatcouldpotentiallybecaughthere.But *theRNGisintendedforhardwarethatisavailableorwidely *used,butnotoldsystemsthatarelongoutoffavor.Thus, *nostatisticaltests.
*/
/* test whether timer works */ if (!start_time || !end_time) {
ret = JENT_ENOTIME; goto out;
}
/* *testwhethertimerisfinegrainedenoughtoprovide *deltaevenwhencalledshortlyaftereachother--this *impliesthatwealsohaveahighresolutiontimer
*/ if (!delta || (end_time == start_time)) {
ret = JENT_ECOARSETIME; goto out;
}
/* *uptoherewedidnotmodifyanyvariablethatwillbe *evaluatedlater,butwealreadyperformedsomework.Thuswe *alreadyhavehadanimpactonthecaches,branchprediction, *etc.withthegoaltoclearittogettheworstcase *measurements.
*/ if (i < CLEARCACHE) continue;
/* test whether we have an increasing timer */ if (!(end_time > start_time))
time_backwards++;
}
/* *weallowuptothreetimesthetimerunningbackwards. *CLOCK_REALTIMEisaffectedbyadjtimeandNTPoperations.Thus, *ifsuchanoperationjusthappenstointerferewithourtest,it *shouldnotfail.Thevalueof3shouldcovertheNTPcasebeing *performedduringourtestrun.
*/ if (time_backwards > 3) {
ret = JENT_ENOMONOTONIC; goto out;
}
/* Did we encounter a health test failure? */
health_test_result = jent_health_failure(ec); if (health_test_result) {
ret = (health_test_result & JENT_RCT_FAILURE) ? JENT_ERCT :
JENT_EHEALTH; goto out;
}
out: if (ec_free)
jent_entropy_collector_free(ec);
return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.29 Sekunden
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.