# Application of a MEMS-Based TRNG in a Chaotic Stream Cipher
## 3 Seed Generator
### Random Bitstream Post-Processing  
After sampling the signal noise, the DC level was eliminated and a sign detection was applied in order to generate a raw bitstream (Figure 8). Once the raw bitstream for key generation was obtained, its viability as a source of random numbers was analyzed. For this purpose, several bitstreams obtained with different sampling rates were subjected to the National Institute of Standards and Technology (NIST) SP 800-22 battery of test [19]. It was observed that none of the bitstream passed all of the NIST tests. However, as the sampling rate decreased, more tests were met, improving the randomness of the bitstream. NIST tests results are shown in Table 1. The list of applied tests with their numeration is the following: Monobit Frequency Test (1), Block Frequency Test (2), Runs Test (3), Longest Runs of Ones (4), Binary Matrix Rank (5), Spectral Test (6), Non Overlapping template Matching (7), Overlapping Template Matching (8), Maurer's Universal Statistic Test (9), Linear Complexity Test (10), Serial Test (11), Approximate Entropy Test (12), Cumulative Sums Test (13), Random Excursions Test (14), Random Excursions Variant Test (15), Cumulative Sums Test Reverse (16), and Lempel-Ziv Compression Test (17). \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Bitstream Type** & \multicolumn{3}{c}{**Raw Bitstream**} & \multicolumn{3}{c}{**Postprocessed Bitstream**} \\ \hline
**Sampling (kSps)** & **250** & **25** & **2.5** & **0.25** & **0.1** & **All** \\ \hline \multicolumn{6}{c}{**NIST Test**} \\ \hline
1 & x & x & x & x & x & \(\surd\) \\
2 & x & x & \(\surd\) & x & \(\surd\) & \(\surd\) \\
3 & x & x & x & \(\surd\) & \(\surd\) & \(\surd\) \\
4 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
5 & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
6 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
7 & x & x & x & \(\surd\) & \(\surd\) & \(\surd\) \\
8 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
9 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
10 & \(\surd\) & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
11 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
12 & x & x & \(\surd\) & x & \(\surd\) & \(\surd\) \\
13 & x & x & x & x & x & \(\surd\) \\
14 & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
15 & \(\surd\) & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\
16 & x & x & x & x & x & \(\surd\) \\
17 & x & x & \(\surd\) & \(\surd\) & \(\surd\) & \(\surd\) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: NIST test results for bitstreams obtained at different sample rates. Figure 7: (**a**) Sample data distribution histogram with a normal fit; (**b**) Empirical Cumulative Distribution Function (CDF) (blue) and CDF of a normal distribution (red). According to NIST recommendations, if it is known that the raw noise-source output is biased, appropriate conditioning components can be included in the design to reduce that bias to a tolerable level [20]. Furthermore, several vetted conditioning functions are listed, such as hash-based, cipher-based, and cipher block chaining message authentication code (HMAC, CMAC, and CBC-MAC). These basic cryptographic primitives are included in many security communication systems, so their use for conditioning randomness sources might not result in extra hardware resources. In case these functions are not available in the communication system, other conditioning techniques can be applied. For example, easier digital techniques such as von Neuman de-biasing [21] can be used. Other zero-bias noise methods such as the one proposed by [PERSON] [22] or [PERSON] [23] can be used, although the resulting analogue part of the conditioning stage would be more complex than that presented in this article. In this work, the raw bitstream has been post-processed using the Secure Hash Algorithm 512 (SHA-512) [10] algorithm.