Skip to content

Commit 4dc2a02

Browse files
committed
New issue from Thomas Köppe: "Make the round states in [rand.eng.philox] explicit"
1 parent 14d244f commit 4dc2a02

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

xml/issue4212.xml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4212" status="New">
5+
<title>Make the round states in [rand.eng.philox] explicit</title>
6+
<section>
7+
<sref ref="[rand.eng.philox]"/>
8+
</section>
9+
<submitter>Thomas Köppe</submitter>
10+
<date>12 Feb 2025</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
The current wording that specifies the operation of the Philox random bit generator seems needlessly vague.
16+
We can add precision by defining a few more terms, instead of requiring the reader to fill in the blanks.
17+
<p/>
18+
Concretely, the variable <math><mi>X</mi><mi>'</mi></math> is only vaguely defined at the moment, and the definition of the
19+
"r-round network", "rounds", and how they fit together, is somewhat informal and imprecise. The statement
20+
that `Philox` "returns the sequence <math><mi>Y</mi></math> = <math><mi>X</mi><mi>'</mi></math>" is needlessly
21+
ambiguous (what is <math><mi>X</mi><mi>'</mi></math> here?).
22+
<p/>
23+
I propose the change that I drafted at <a href="https://github.com/cplusplus/draft/pull/7152">draft/pull/7152</a>:
24+
Namely, spell out the meaning of the "rounds" and create a distinct name for every value in every round.
25+
This allows us to state the result precisely, and makes it clear how each round computes a new value from the
26+
values of the previous rounds.
27+
<p/>
28+
It seems convenient to change the round counter <math><mi>q</mi></math> to be 1-based (and
29+
<math><msup><mi>X</mi><mrow>(<mn>0</mn>)</mrow></msup></math>
30+
is an alias for the initial value, <math><mi>X</mi></math>), so that the final result is
31+
<math><msup><mi>X</mi><mrow>(<mi>r</mi>)</mrow></msup></math>.
32+
</p>
33+
</discussion>
34+
35+
<resolution>
36+
<p>
37+
This wording is relative to <paper num="N5001"/>.
38+
</p>
39+
40+
<ol>
41+
<li><p>Modify <sref ref="[rand.eng.philox]"/> as indicated:</p>
42+
43+
<blockquote>
44+
<p>
45+
-2- The generation algorithm returns <math><msub><mi>Y</mi><mrow><mi>i</mi></mrow></msub></math>, the value stored in
46+
the <math><mi>i</mi></math>th element of <math><mi>Y</mi></math> after applying the transition algorithm.
47+
<p/>
48+
-3- The state transition is performed as if by the following algorithm:
49+
</p>
50+
<blockquote><pre>
51+
<math><mi>i</mi><mo>=</mo><mi>i</mi><mo>+</mo><mn>1</mn></math>
52+
<tt>if (<math><mi>i</mi></math> == <math><mi>n</mi></math>) {</tt>
53+
<math><mi>Y</mi><mo>=</mo></math><tt>Philox</tt>(<math><mi>K</mi></math>, <math><mi>X</mi></math>) <i>// see below</i>
54+
<math><mi>Z</mi><mo>=</mo><mi>Z</mi><mo>+</mo><mn>1</mn></math> <ins><i>// this updates <math><mi>X</mi></math></i></ins>
55+
<math><mi>i</mi><mo>=</mo><mn>0</mn></math>
56+
}
57+
</pre></blockquote>
58+
<p>
59+
-4- The <tt>Philox</tt> function maps the length-<math><mi>n</mi></math>/2 sequence <math><mi>K</mi></math>
60+
and the length-<math><mi>n</mi></math> sequence <math><mi>X</mi></math> into a length-<math><mi>n</mi></math> output
61+
sequence <math><mi>Y</mi></math>. Philox applies an <math><mi>r</mi></math>-round substitution-permutation network to
62+
the values in <math><mi>X</mi></math>. <del>A single round of the generation algorithm performs the following steps:</del>
63+
<ins>That is, there are intermediate values <math><msup><mi>X</mi><mrow>(<mn>0</mn>)</mrow></msup></math>,
64+
<math><msup><mi>X</mi><mrow>(<mn>1</mn>)</mrow></msup></math>, &hellip;,
65+
<math><msup><mi>X</mi><mrow>(<mi>r</mi>)</mrow></msup></math>, where
66+
<math><msup><mi>X</mi><mrow>(<mn>0</mn>)</mrow></msup><mo>:=</mo><mi>X</mi></math>, and for each round
67+
<math><mi>q</mi></math> (with <math><mi>q</mi><mo>=</mo><mn>1</mn>, &hellip;, <mi>r</mi></math>),
68+
<math><msup><mi>X</mi><mrow>(<mi>q</mi>)</mrow></msup></math> is computed from
69+
<math><msup><mi>X</mi><mrow>(<mi>q</mi><mo>-</mo><mn>1</mn>)</mrow></msup></math> as follows. The output sequence
70+
is <math><msup><mi>X</mi><mrow>(<mi>r</mi>)</mrow></msup></math>.</ins>
71+
</p>
72+
<ol style="list-style-type: none">
73+
<li><p>(4.1) &mdash; <del>The output sequence <math><mi>X</mi><mi>'</mi></math> of the previous round (<math><mi>X</mi></math>
74+
in case of the first round) is permuted to obtain the intermediate state <math><mi>V</mi></math>:</del></p>
75+
<blockquote><pre>
76+
<del><math><msub><mi>V</mi><mrow><mi>j</mi></mrow></msub><mo>=</mo><msub><mi>X</mi>'<mrow><msub><mi>f</mi><mrow><mi>n</mi></mrow></msub>(<mi>j</mi>)</mrow></msub></math></del>
77+
</pre></blockquote>
78+
<p>
79+
<ins>An intermediate state <math><msup><mi>V</mi><mrow>(<mi>q</mi>)</mrow></msup></math> is obtained
80+
by permuting the previous output,
81+
<math><msubsup><mi>V</mi><mi>j</mi><mrow>(<mi>q</mi>)</mrow></msubsup><mo>:=</mo><msubsup><mi>X</mi><mrow><msub><mi>f</mi><mrow><mi>n</mi></mrow></msub>(<mi>j</mi>)</mrow><mrow>(<mi>q</mi><mo>-</mo><mn>1</mn>)</mrow></msubsup></math>,</ins>
82+
where <math><mi>j</mi><mo>=</mo><mn>0</mn>, &hellip; , <mi>n</mi><mo>−</mo><mn>1</mn></math> and
83+
<math><msub><mi>f</mi><mrow><mi>n</mi></mrow></msub>(<mi>j</mi>)</math> is defined in Table 124.
84+
</p>
85+
</li>
86+
<li><p>(4.2) &mdash; <del>The following computations are applied to the elements of the <math><mi>V</mi></math> sequence:</del>
87+
<ins>The next output <math><msup><mi>X</mi><mrow>(<mi>q</mi>)</mrow></msup></math> is computed from the elements of the
88+
<math><msup><mi>V</mi><mrow>(<mi>q</mi>)</mrow></msup></math> as follows. For <math><mi>k</mi><mo>=</mo><mn>0</mn>,&hellip;,<mi>n</mi><mo>/</mo><mn>2</mn><mo>-</mo><mn>1</mn>,</math></ins></p>
89+
<ol style="list-style-type: none">
90+
<li><p><ins>(4.2.?) &mdash;</ins><math><msub><mi>X</mi><mrow><mn>2</mn><mi>k</mi><mo>+</mo><mn>0</mn></mrow></msub></math> = mulhi(<math><msub><mi>V</mi><mrow><mn>2</mn><mi>k</mi></mrow></msub></math>,<math><msub><mi>M</mi><mi>k</mi></msub></math>,<i>w</i>) xor <math><msubsup><mi style="font-style: italic">key</mi><mi>k</mi><mi>q</mi></msubsup></math> xor <math><msub><mi>V</mi><mrow><mn>2</mn><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub></math><ins>, and</ins></p></li>
91+
<li><p><ins>(4.2.?) &mdash;</ins><math><msub><mi>X</mi><mrow><mn>2</mn><mi>k</mi><mo>+</mo><mn>1</mn></mrow></msub></math> = mullo(<math><msub><mi>V</mi><mrow><mn>2</mn><mi>k</mi></mrow></msub></math>,<math><msub><mi>M</mi><mi>k</mi></msub></math>,<i>w</i>)<ins>,</ins></p></li>
92+
</ol>
93+
<p>
94+
where:
95+
</p>
96+
<ol style="list-style-type: none">
97+
<li><p>(4.2.1) &mdash; mullo(<math><mi>a</mi>,<mi>b</mi>,<mi>w</mi></math>) is the low half of the modular multiplication of
98+
<math><mi>a</mi></math> and <math><mi>b</mi></math>: <math>(<mi>a</mi><mo>&#8901;</mo><mi>b</mi>)<mo>mod</mo><msup><mn>2</mn><mi>w</mi></msup></math>,</p></li>
99+
<li><p>(4.2.2) &mdash; mulhi(<math><mi>a</mi>,<mi>b</mi>,<mi>w</mi></math>) is the high half of the modular multiplication of
100+
<math><mi>a</mi></math> and <math><mi>b</mi></math>: <math>(&#x230A;(<mi>a</mi><mo>&#8901;</mo><mi>b</mi>)<mo>/</mo><msup><mn>2</mn><mi>w</mi></msup>&#x230B;)</math>,</p></li>
101+
<li><p>(4.2.3) &mdash;
102+
<del><math><mi>k</mi><mo>=</mo><mn>0</mn>, &hellip; , <mi>n</mi><mo>/</mo><mn>2</mn><mo>−</mo><mn>1</mn></math> is the index in the sequences,</del>
103+
<ins><math><msubsup><mi>K</mi><mi>k</mi><mrow>(<mi>q</mi>)</mrow></msubsup></math> is the
104+
<math><msup><mi>k</mi><mtext>th</mtext></msup></math> round key for round <math><mi>q</mi></math>,
105+
<math><msubsup><mi>K</mi><mi>k</mi><mrow>(<mi>q</mi>)</mrow></msubsup><mo>:=</mo>(<msub><mi>K</mi><mi>k</mi></msub><mo>+</mo>(<mi>q</mi><mo>-</mo><mn>1</mn>)<mo>&#8901;</mo><msub><mi>C</mi><mi>k</mi></msub>)<mo>mod</mo><msup><mn>2</mn><mi>w</mi></msup></math>,</ins></p></li>
106+
<li><p>(4.2.4) &mdash; <del><math><mi>q</mi><mo>=</mo><mn>0</mn>, &hellip; , <mi>r</mi><mo>−</mo><mn>1</mn></math> is the index of the round,</del>
107+
<ins><math><msub><mi>K</mi><mi>k</mi></msub></math> is the <math><msup><mi>k</mi><mtext>th</mtext></msup></math> element of the key sequence
108+
<math><mi>K</mi></math>,</ins></p></li>
109+
<li><p><del>(4.2.5) &mdash; <math><msubsup><mi style="font-style: italic">key</mi><mi>k</mi><mi>q</mi></msubsup></math> is the
110+
<math><msup><mi>k</mi><mtext>th</mtext></msup></math> round key for round <math><mi>q</mi></math>,
111+
<math><msubsup><mi style="font-style: italic">key</mi><mi>k</mi><mi>q</mi></msubsup><mo>:=</mo>(<msub><mi>K</mi><mi>k</mi></msub><mo>+</mo><mi>q</mi><mo>&#8901;</mo><msub><mi>C</mi><mi>k</mi></msub>)<mo>mod</mo><msup><mn>2</mn><mi>w</mi></msup></math>,</del></p></li>
112+
<li><p><del>(4.2.6) &mdash; <math><msub><mi>K</mi><mi>k</mi></msub></math> are the elements of the key sequence <math><mi>K</mi></math>,</del></p></li>
113+
<li><p>(4.2.7) &mdash; <math><msub><mi>M</mi><mi>k</mi></msub></math> is <tt>multipliers[<math><mi>k</mi></math>]</tt>, and</p></li>
114+
<li><p>(4.2.8) &mdash; <math><msub><mi>C</mi><mi>k</mi></msub></math> is <tt>round_consts[<math><mi>k</mi></math>]</tt>.</p></li>
115+
</ol>
116+
</li>
117+
118+
</ol>
119+
</blockquote>
120+
</li>
121+
</ol>
122+
</resolution>
123+
124+
</issue>

0 commit comments

Comments
 (0)