idnits 2.17.1
draft-roca-tsvwg-tinymt32-01.txt:
Checking boilerplate required by RFC 5378 and the IETF Trust (see
https://trustee.ietf.org/license-info):
----------------------------------------------------------------------------
No issues found here.
Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt:
----------------------------------------------------------------------------
No issues found here.
Checking nits according to https://www.ietf.org/id-info/checklist :
----------------------------------------------------------------------------
No issues found here.
Miscellaneous warnings:
----------------------------------------------------------------------------
== The copyright year in the IETF Trust and authors Copyright Line does not
match the current year
== Line 211 has weird spacing: '...am seed a 32-...'
-- The document date (March 5, 2019) is 1877 days in the past. Is this
intentional?
Checking references for intended status: Proposed Standard
----------------------------------------------------------------------------
(See RFCs 3967 and 4897 for information about using normative references
to lower-maturity documents in RFCs)
No issues found here.
Summary: 0 errors (**), 0 flaws (~~), 2 warnings (==), 1 comment (--).
Run idnits with the --verbose option for more detailed information about
the items above.
--------------------------------------------------------------------------------
2 TSVWG M. Saito
3 Internet-Draft M. Matsumoto
4 Intended status: Standards Track Hiroshima University
5 Expires: September 6, 2019 V. Roca (Ed.)
6 E. Baccelli
7 INRIA
8 March 5, 2019
10 TinyMT32 Pseudo Random Number Generator (PRNG)
11 draft-roca-tsvwg-tinymt32-01
13 Abstract
15 This document describes the TinyMT32 Pseudo Random Number Generator
16 (PRNG) that produces 32-bit pseudo-random unsigned integers and aims
17 at having a simple-to-use and deterministic solution. This PRNG is a
18 small-sized variant of Mersenne Twister (MT) PRNG, also designed by
19 M. Saito and M. Matsumoto. The main advantage of TinyMT32 over MT
20 is the use of a small internal state, compatible with most target
21 platforms including embedded devices, while keeping a reasonably good
22 randomness.
24 Status of This Memo
26 This Internet-Draft is submitted in full conformance with the
27 provisions of BCP 78 and BCP 79.
29 Internet-Drafts are working documents of the Internet Engineering
30 Task Force (IETF). Note that other groups may also distribute
31 working documents as Internet-Drafts. The list of current Internet-
32 Drafts is at https://datatracker.ietf.org/drafts/current/.
34 Internet-Drafts are draft documents valid for a maximum of six months
35 and may be updated, replaced, or obsoleted by other documents at any
36 time. It is inappropriate to use Internet-Drafts as reference
37 material or to cite them other than as "work in progress."
39 This Internet-Draft will expire on September 6, 2019.
41 Copyright Notice
43 Copyright (c) 2019 IETF Trust and the persons identified as the
44 document authors. All rights reserved.
46 This document is subject to BCP 78 and the IETF Trust's Legal
47 Provisions Relating to IETF Documents
48 (https://trustee.ietf.org/license-info) in effect on the date of
49 publication of this document. Please review these documents
50 carefully, as they describe your rights and restrictions with respect
51 to this document. Code Components extracted from this document must
52 include Simplified BSD License text as described in Section 4.e of
53 the Trust Legal Provisions and are provided without warranty as
54 described in the Simplified BSD License.
56 Table of Contents
58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2
59 2. Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 3
60 3. TinyMT32 PRNG Specification . . . . . . . . . . . . . . . . . 3
61 3.1. TinyMT32 Source Code . . . . . . . . . . . . . . . . . . 3
62 3.2. TinyMT32 Usage . . . . . . . . . . . . . . . . . . . . . 7
63 3.3. Specific Implementation Validation and Deterministic
64 Behavior . . . . . . . . . . . . . . . . . . . . . . . . 8
65 4. Security Considerations . . . . . . . . . . . . . . . . . . . 9
66 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9
67 6. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 9
68 7. References . . . . . . . . . . . . . . . . . . . . . . . . . 9
69 7.1. Normative References . . . . . . . . . . . . . . . . . . 9
70 7.2. Informative References . . . . . . . . . . . . . . . . . 9
71 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 10
73 1. Introduction
75 This document specifies the TinyMT32 PRNG, as a specialization of the
76 reference implementation version 1.1 (2015/04/24) by Mutsuo Saito and
77 Makoto Matsumoto, from Hiroshima University:
79 o Official web site:
81 o Official github site and reference implementation:
82
84 This specialisation aims at having a simple-to-use and deterministic
85 PRNG, as explained below.
87 TinyMT is a new small-sized variant of Mersenne Twister (MT)
88 introduced by Mutsuo Saito and Makoto Matsumoto in 2011. This
89 document focusses on the TinyMT32 variant (rather than TinyMT64) of
90 the PRNG, which outputs 32-bit unsigned integers.
92 The purpose of TinyMT is not to replace Mersenne Twister: TinyMT has
93 a far shorter period than MT. The merit of TinyMT is in its small
94 size of the internal state of 127 bits, far smaller than 19937 bits
95 of MT. According to statistical tests (BigCrush in TestU01
96 and AdaptiveCrush
97 ) the
98 quality of the outputs of TinyMT seems pretty good, taking the small
99 size of the internal state into consideration. From this point of
100 view, TinyMT32 represents a major improvement with respect to the
101 Park-Miler Linear Congruential PRNG (e.g., as specified in
102 [RFC5170]).
104 The TinyMT32 PRNG initialization depends, among other things, on a
105 parameter set -- namely (mat1, mat2, tmat) -- that needs to be well
106 chosen (pre-calculated values are available in the official web
107 site). In order to facilitate the use of this PRNG, and unlike the
108 implementation version 1.1 (2015/04/24) by Mutsuo Saito and Makoto
109 Matsumoto, this specification requires the use of a specific
110 parameter set (see Section 3.1). The implementation version 1.1
111 (2015/04/24) also proposes two initialisation functions that differ
112 on the approach to seed the PRNG. A second difference is the removal
113 of the tinymt32_init_by_array() function to keep only the simple
114 initialisation through a single seed value (see Section 3.2).
116 Finally, the determinism of this PRNG, for a given seed, has been
117 carefully checked (see Section 3.3). Indeed, this determinism can be
118 a key requirement as it the case with [RLC-ID] that normatively
119 depends on this specification.
121 2. Definitions
123 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
124 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
125 "OPTIONAL" in this document are to be interpreted as described in BCP
126 14 [RFC2119] [RFC8174] when, and only when, they appear in all
127 capitals, as shown here.
129 3. TinyMT32 PRNG Specification
131 3.1. TinyMT32 Source Code
133 The TinyMT32 PRNG requires to be initialized with a parameter set
134 that needs to be well chosen. In this specification, for the sake of
135 simplicity, the following parameter set MUST be used:
137 o mat1 = 0x8f7011ee = 2406486510
138 o mat2 = 0xfc78ff1f = 4235788063
139 o tmat = 0x3793fdff = 932445695
141 This parameter set is the first entry of the precalculated parameter
142 sets in file tinymt32dc.0.1048576.txt, by Kenji Rikitake, and
143 available at . This is
145 also the parameter set used in [KR12].
147 The TinyMT32 PRNG reference implementation is reproduced in Figure 1,
148 with the following differences with respect to the original source
149 code:
151 o the original copyright and licence have been removed, in
152 accordance with BCP 78 and the IETF Trust's Legal Provisions
153 Relating to IETF Documents (http://trustee.ietf.org/license-info);
154 o the source code initially spread over the tinymt32.h and
155 tinymt32.c files has been merged;
156 o the unused parts of the original source code have been removed.
157 This is the case of the tinymt32_init_by_array() alternative
158 initialisation function;
159 o the unused constants TINYMT32_MEXP and TINYMT32_MUL have been
160 removed;
161 o the appropriate parameter set has been added to the initialization
162 function;
163 o the function order has been changed;
164 o certain internal variables have been renamed for compactness
165 purposes;
166 o the const qualifier has been added to the constant definitions.
168
169 /**
170 * Tiny Mersenne Twister only 127 bit internal state.
171 * Derived from the reference implementation version 1.1 (2015/04/24)
172 * by Mutsuo Saito (Hiroshima University) and Makoto Matsumoto
173 * (Hiroshima University).
174 */
175 #include
177 /**
178 * tinymt32 internal state vector and parameters
179 */
180 typedef struct {
181 uint32_t status[4];
182 uint32_t mat1;
183 uint32_t mat2;
184 uint32_t tmat;
185 } tinymt32_t;
187 static void tinymt32_next_state (tinymt32_t * s);
188 static uint32_t tinymt32_temper (tinymt32_t * s);
190 /**
191 * Parameter set to use for this IETF specification. Don't change.
193 * This parameter set is the first entry of the precalculated
194 * parameter sets in file tinymt32dc.0.1048576.txt, by Kenji
195 * Rikitake, available at:
196 * https://github.com/jj1bdx/tinymtdc-longbatch/blob/master/
197 * tinymt32dc/tinymt32dc.0.1048576.txt
198 * It is also the parameter set used:
199 * Rikitake, K., "TinyMT Pseudo Random Number Generator for
200 * Erlang", ACM 11th SIGPLAN Erlang Workshop (Erlang'12),
201 * September, 2012.
202 */
203 const uint32_t TINYMT32_MAT1_PARAM = UINT32_C(0x8f7011ee);
204 const uint32_t TINYMT32_MAT2_PARAM = UINT32_C(0xfc78ff1f);
205 const uint32_t TINYMT32_TMAT_PARAM = UINT32_C(0x3793fdff);
207 /**
208 * This function initializes the internal state array with a
209 * 32-bit unsigned integer seed.
210 * @param s pointer to tinymt internal state.
211 * @param seed a 32-bit unsigned integer used as a seed.
212 */
213 void tinymt32_init (tinymt32_t * s, uint32_t seed)
214 {
215 const uint32_t MIN_LOOP = 8;
216 const uint32_t PRE_LOOP = 8;
217 s->status[0] = seed;
218 s->status[1] = s->mat1 = TINYMT32_MAT1_PARAM;
219 s->status[2] = s->mat2 = TINYMT32_MAT2_PARAM;
220 s->status[3] = s->tmat = TINYMT32_TMAT_PARAM;
221 for (int i = 1; i < MIN_LOOP; i++) {
222 s->status[i & 3] ^= i + UINT32_C(1812433253)
223 * (s->status[(i - 1) & 3]
224 ^ (s->status[(i - 1) & 3] >> 30));
225 }
226 /*
227 * NB: the parameter set of this specification warrants
228 * that none of the possible 2^^32 seeds leads to an
229 * all-zero 127-bit internal state. Therefore, the
230 * period_certification() function of the original
231 * TinyMT32 source code has been safely removed. If
232 * another parameter set is used, this function will
233 * have to be re-introduced here.
234 */
235 for (int i = 0; i < PRE_LOOP; i++) {
236 tinymt32_next_state(s);
237 }
238 }
240 /**
241 * This function outputs a 32-bit unsigned integer from
242 * the internal state.
243 * @param s pointer to tinymt internal state.
244 * @return 32-bit unsigned integer r (0 <= r < 2^32).
245 */
246 uint32_t tinymt32_generate_uint32 (tinymt32_t * s)
247 {
248 tinymt32_next_state(s);
249 return tinymt32_temper(s);
250 }
252 /**
253 * Internal tinymt32 constants and functions.
254 * Users should not call these functions directly.
255 */
256 const uint32_t TINYMT32_SH0 = 1;
257 const uint32_t TINYMT32_SH1 = 10;
258 const uint32_t TINYMT32_SH8 = 8;
259 const uint32_t TINYMT32_MASK = UINT32_C(0x7fffffff);
261 /**
262 * This function changes the internal state of tinymt32.
263 * @param s pointer to tinymt internal state.
264 */
265 static void tinymt32_next_state (tinymt32_t * s)
266 {
267 uint32_t x;
268 uint32_t y;
270 y = s->status[3];
271 x = (s->status[0] & TINYMT32_MASK)
272 ^ s->status[1]
273 ^ s->status[2];
274 x ^= (x << TINYMT32_SH0);
275 y ^= (y >> TINYMT32_SH0) ^ x;
276 s->status[0] = s->status[1];
277 s->status[1] = s->status[2];
278 s->status[2] = x ^ (y << TINYMT32_SH1);
279 s->status[3] = y;
280 /*
281 * The if (y & 1) {...} block below replaces:
282 * s->status[1] ^= -((int32_t)(y & 1)) & s->mat1;
283 * s->status[2] ^= -((int32_t)(y & 1)) & s->mat2;
284 * The adopted code is equivalent to the original code
285 * but does not depend on the representation of negative
286 * integers by 2's complements. It is therefore more
287 * portable, but includes an if-branch which may slow
288 * down the generation speed.
290 */
291 if (y & 1) {
292 s->status[1] ^= s->mat1;
293 s->status[2] ^= s->mat2;
294 }
295 }
297 /**
298 * This function outputs a 32-bit unsigned integer from
299 * the internal state.
300 * @param s pointer to tinymt internal state.
301 * @return 32-bit unsigned pseudo-random number.
302 */
303 static uint32_t tinymt32_temper (tinymt32_t * s)
304 {
305 uint32_t t0, t1;
306 t0 = s->status[3];
307 t1 = s->status[0] + (s->status[2] >> TINYMT32_SH8);
308 t0 ^= t1;
309 t0 ^= -((int32_t)(t1 & 1)) & s->tmat;
310 return t0;
311 }
312
314 Figure 1: TinyMT32 Reference Implementation
316 3.2. TinyMT32 Usage
318 This PRNG MUST first be initialized with the following function:
320 void tinymt32_init (tinymt32_t * s, uint32_t seed);
322 It takes as input a 32-bit unsigned integer used as a seed (note that
323 value 0 is authorized by TinyMT32). This function also takes as
324 input a pointer to an instance of a tinymt32_t structure that needs
325 to be allocated by the caller but left uninitialized. This structure
326 will then updated by the various TinyMT32 functions in order to keep
327 the internal state of the PRNG. The use of this structure authorizes
328 several instances of this PRNG to be used in parallel, each of them
329 having its own instance of the structure.
331 Then, each time a new 32-bit pseudo-random unsigned integer between 0
332 and 2^32 - 1 inclusive is needed, the following function is used:
334 uint32_t tinymt32_generate_uint32 (tinymt32_t * s);
336 Of course, the tinymt32_t structure must be left unchanged by the
337 caller between successive calls to this function.
339 3.3. Specific Implementation Validation and Deterministic Behavior
341 PRNG determinism, for a given seed, can be a requirement (e.g., with
342 [RLC-ID]). Consequently, any implementation of the TinyMT32 PRNG in
343 line with this specification MUST comply with the following criteria.
344 Using a seed value of 1, the first 50 values returned by
345 tinymt32_generate_uint32(s) as 32-bit unsigned integers MUST be equal
346 to values provided in Figure 2. Note that these values come from the
347 tinymt/check32.out.txt file provided by the PRNG authors to validate
348 implementations of TinyMT32, as part of the MersenneTwister-Lab/
349 TinyMT Github repository.
351 2545341989 981918433 3715302833 2387538352 3591001365
352 3820442102 2114400566 2196103051 2783359912 764534509
353 643179475 1822416315 881558334 4207026366 3690273640
354 3240535687 2921447122 3984931427 4092394160 44209675
355 2188315343 2908663843 1834519336 3774670961 3019990707
356 4065554902 1239765502 4035716197 3412127188 552822483
357 161364450 353727785 140085994 149132008 2547770827
358 4064042525 4078297538 2057335507 622384752 2041665899
359 2193913817 1080849512 33160901 662956935 642999063
360 3384709977 1723175122 3866752252 521822317 2292524454
362 Figure 2: First 50 decimal values returned by
363 tinymt32_generate_uint32(s) as 32-bit unsigned integers, with a seed
364 value of 1.
366 In particular, the deterministic behavior of the Figure 1 source code
367 has been checked across several platforms: high-end laptops running
368 64-bits Mac OSX and Linux/Ubuntu; a board featuring a 32-bits ARM
369 Cortex-A15 and running 32-bit Linux/Ubuntu; several embedded cards
370 featuring either an ARM Cortex-M0+, a Cortex-M3 or a Cortex-M4 32-bit
371 microcontroller, all of them running RIOT [Baccelli18]; two low-end
372 embedded cards featuring either a 16-bit microcontroller (TI MSP430)
373 or a 8-bit microcontroller (Arduino ATMEGA2560), both of them running
374 RIOT.
376 This specification only outputs 32-bit unsigned pseudo-random numbers
377 and does not try to map this output to a smaller integer range (e.g.,
378 between 10 and 49 inclusive). If a specific use-case needs such a
379 mapping, it will have to provide its own function. In that case, if
380 PRNG determinism is also required, the use of floating point (single
381 or double precision) to perform this mapping should probably be
382 avoided, these calculations leading potentially to different rounding
383 errors across different target platforms. Great care should also be
384 put on not introducing biases in the randomness of the mapped output
385 (it may be the case with some mapping algorithms) incompatible with
386 the use-case requirements. The details of how to perform such a
387 mapping are out-of-scope of this document.
389 4. Security Considerations
391 The authors do not believe the present specification generates
392 specific security risks per se.
394 5. IANA Considerations
396 This document does not require any IANA action.
398 6. Acknowledgments
400 The authors would like to thank Belkacem Teibi with whom we explored
401 TinyMT32 specificities when looking to an alternative to the Park-
402 Miler Linear Congruential PRNG. The authors would like to thank the
403 three TSVWG chairs, Wesley Eddy, our shepherd, David Black and Gorry
404 Fairhurst, as well as Spencer Dawkins and Mirja Kuhlewind. Last but
405 not least, the authors are really grateful to the IESG members, in
406 particular Benjamin Kaduk, Eric Rescorla, and Adam Roach for their
407 highly valuable feedbacks that greatly contributed to improve this
408 specification.
410 7. References
412 7.1. Normative References
414 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
415 Requirement Levels", BCP 14, RFC 2119,
416 DOI 10.17487/RFC2119, March 1997,
417 .
419 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
420 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
421 May 2017, .
423 7.2. Informative References
425 [Baccelli18]
426 Baccelli, E., Gundogan, C., Hahm, O., Kietzmann, P.,
427 Lenders, M., Petersen, H., Schleiser, K., Schmidt, T., and
428 M. Wahlisch, "RIOT: An Open Source Operating System for
429 Low-End Embedded Devices in the IoT", IEEE Internet of
430 Things Journal (Volume 5, Issue 6), DOI:
431 10.1109/JIOT.2018.2815038, December 2018.
433 [KR12] Rikitake, K., "TinyMT Pseudo Random Number Generator for
434 Erlang", ACM 11th SIGPLAN Erlang Workshop (Erlang'12),
435 September 14, 2012, Copenhagen, Denmark, DOI:
436 http://dx.doi.org/10.1145/2364489.2364504, September 2012.
438 [RFC5170] Roca, V., Neumann, C., and D. Furodet, "Low Density Parity
439 Check (LDPC) Staircase and Triangle Forward Error
440 Correction (FEC) Schemes", RFC 5170, DOI 10.17487/RFC5170,
441 June 2008, .
443 [RLC-ID] Roca, V. and B. Teibi, "Sliding Window Random Linear Code
444 (RLC) Forward Erasure Correction (FEC) Scheme for
445 FECFRAME", Work in Progress, Transport Area Working Group
446 (TSVWG) draft-ietf-tsvwg-rlc-fec-scheme (Work in
447 Progress), February 2019, .
450 Authors' Addresses
452 Mutsuo Saito
453 Hiroshima University
454 Japan
456 EMail: saito@math.sci.hiroshima-u.ac.jp
458 Makoto Matsumoto
459 Hiroshima University
460 Japan
462 EMail: m-mat@math.sci.hiroshima-u.ac.jp
464 Vincent Roca
465 INRIA
466 Univ. Grenoble Alpes
467 France
469 EMail: vincent.roca@inria.fr
471 Emmanuel Baccelli
472 INRIA
473 France
475 EMail: emmanuel.baccelli@inria.fr