1 NeuG - a random number generator implementation (for STM32F103)
6 Free Software Initiative of Japan
11 NeuG is a set of routines of random number generator (RNG) which is
12 based on physical noise. It supports STM32F103. It can be stand
13 alone USB RNG device (with main routine), too.
15 The name comes from Japanized English word "noidgy" (from English word
16 "noisy"), where many Japanese (including me) don't distinguish
17 pronunciations of "gee" and "zee". NeuG includes my important letters
18 of "g", "n", and "u", and the word "neu" (German spelling of "new").
20 My primary intention was to incorporate NeuG routines into Gnuk for
21 random number generation, but the stand alone version could be useful
24 Gnuk was named after my son who loved the pacifier when he was baby.
25 NeuG was named after my daughter, but I don't say she is noisy.
31 This is the fourth release of NeuG, which is still experimental.
32 Basic features (generating random numbers) are stable, but newly added
33 things like reGNUal support should be considered unstable. Note that
34 you need the snapshot of ChibiOS/RT (from trunk). This means that it
35 is covered by GNU GPL. No "linking exception" option is available for
42 Q0: How NeuG device is good?
43 A0: I believe it's good enough if we compare to other hardware RNGs.
44 If its usage is as an entropy source for RNG-tools, or use for
45 computer simulations, I think that it's good enough. I evaluated
46 it with rngtest of RNG-tools, NIST STS test suite and Dieharder.
47 See the directory neug/test-results/.
48 A0-dash: For better entropy device with embedded test, you could get
49 EntropyKey. See http://www.entropykey.co.uk/
50 A0-double-dash: STM32F2xx and STM32F4xx have built-in TRNG, it would
51 be better for you (although the quality of randomness
54 Q1: How fast is NeuG device?
55 A1: It's more than 50 Ki-byte/second.
57 Q2: Should we check condition of noise sources?
58 A2: Yes, we should. Three continuous tests are implemented, following
59 (Draft of) NIST SP 800-90B. Those are Repetition Count Test,
60 Adaptive Proportion Test (for 64 samples), and another Adaptive
61 Proportion Test (for 4096 samples). When it detect an error (it
62 is really rare, but it could occur even for normal condition), the
63 generation of random bits restart again.
69 FST-01, STBee Mini, Olimex STM32-H103, CQ-STARM, and STBee are
76 NeuG source code is under src/ directory.
82 It is distributed under GNU General Public Licence version 3 or later
83 (GPLv3+). Please see src/COPYING.
89 To build NeuG device, we need external source code.
91 * chibios/ -- ChibiOS/RT 2.3.x snapshot
93 Please get it from http://chibios.sourceforge.net/
94 We use ChibiOS/RT as the kernel for NeuG device.
100 You need GNU toolchain and newlib for 'arm-none-eabi' target.
102 See http://github.com/uwehermann/summon-arm-toolchain/ for preparation
103 of GNU Toolchain for 'arm-none-eabi' target.
105 Change directory to `src':
107 $ cd neug-VERSION/src
109 Then, run `configure':
117 Then, we will have "neug.elf".
126 Reset the board with "USER" switch pushed. Type following to write
130 # ./dfuse.py ../src/neug.hex
132 Then, reset the board.
135 Olimex STM32-H103 board
136 -----------------------
138 If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD:
140 $ openocd -f interface/olimex-jtag-tiny.cfg -f board/olimex_stm32_h103.cfg
142 Then, with another terminal, type following to write "gnuk.elf" to Flash ROM:
144 $ telnet localhost 4444
146 > flash write_image erase neug.elf
156 It is USB CDC ACM device. On GNU/Linux, it can be /dev/ttyACM0 or like.
157 Before using /dev/ttyACM0, you need to configure its TTY discipline.
159 $ stty -F /dev/ttyACM0 -echo raw
161 Then, you can use output of /dev/ttyACM0.
163 When you want to get raw output (not conditioned), you can configure:
165 $ stty -F /dev/ttyACM0 parenb parodd
167 for raw data after filter. For direct raw data of samples, configure:
169 $ stty -F /dev/ttyACM0 parenb -parodd
171 And you can get conditioned output by configuring:
173 $ stty -F /dev/ttyACM0 -parenb
176 Structure of the NeuG
177 =====================
179 Here is a figure of the circuit.
183 /|<---+--- [ Analog input Vref ]
184 16 | |<-+-|--- [ Analog input Temperature Sensor ]
185 +---/-[ADC1] <==| | | |
189 +----| | MUX CTL >--+
192 | | 16 | |<------- [ Analog input 0 ] (pull up to Vdd)
193 | +---/-[ADC2] <==| |
194 | | |<------- [ Analog input 1 ] (pull up to Vdd)
199 +------------------+ <============ (*1)
203 | Put 4 times to output 32-bit
207 | Put 35 times to output 1120-bit
208 +---------------------------------+ <====== (*2)
216 | Conditioning | 1120 |
217 | Component |<------------/------------+
227 +---------------------------+
232 Random Number Output <========== (*3)
236 Specifying by "stty", you can get (*3) with -parenb, (*2) with parenb
237 parodd, and (*1) with parenb 0parodd.
239 STM32F103 has two built-in A/D converters. NeuG uses A/D converters'
240 outputs as entropy sources. It is considered noise of quantization
241 error, plus noise from power supply, etc.
243 We chose four analog input sources of: built-in voltage reference,
244 temperature sensor and two analog inputs which are pull-up to Vdd.
246 By a single sampling of two channel, we get 32-bit (not all 32-bit is
247 valid, as a A/D converter resolution is 12-bit only). We take four
248 sampling of different combinations: (Vref, IN0), (Temp, IN1), (Vref,
249 IN1), and (Temp, IN0). Those 32-bit * 4 is fed into CRC32 filter.
251 We use STM32F103's CRC32 calculation unit as a kind of filter. We put
252 output of A/D converters into CRC32 calculation unit, four times, to
255 Output of CRC32 filter is collected 35 times, and it becomes 1120-bit
256 (32 * 35). This is the noise source bits.
258 We put this 1120-bit and half of previous output (128-bit) to
259 conditioning component.
261 Conditioning Component is implemented by Hash_df function which is
262 composed by SHA-256. Since the noise source is not "white", signal is
263 whiten by this Conditioning Component.
265 My experience with STM32F103 and NeuG shows that noise source is
266 stable at least for a year.
272 See files under the directory test-results, for test result of
273 "rngtest" in rng-tools, NIST STS 2.1.1, and Dieharder.
275 For Dieharder, I correct 13GiB (it took five days and six hours
276 and more), and use scripts to invoke dieharder.
279 Read-only Git Repository
280 ========================
282 You can browse at http://www.gniibe.org/gitweb?p=neug.git;a=summary
286 $ git clone git://www.gniibe.org/neug.git/
290 $ git clone http://www.gniibe.org/git/neug.git/
293 I put ChibiOS/RT as a submodule of Git. Please do this:
296 $ git submodule update
300 Information on the Web
301 ======================
310 FSIJ welcomes your contributions. Please assign your copyright
311 to FSIJ (if possible).