Skip to content

[rand.eng.philox] Make the round states explicit. #7152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions source/numerics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3100,27 +3100,24 @@
\begin{codeblock}
@$i$@ = @$i$@ + 1
if (@$i$@ == @$n$@) {
@$Y$@ = Philox(@$K$@, @$X$@) // \seebelow
@$Z$@ = @$Z$@ + 1
@$Y$@ = Philox(@$K$@, @$X$@) // \seebelow
@$Z$@ = @$Z$@ + 1 // this updates $X$
@$i$@ = 0
}
\end{codeblock}

\pnum
The \tcode{Philox} function maps the length-$n/2$ sequence $K$ and
the length-$n$ sequence $X$ into a length-$n$ output sequence $Y$.
the length-$n$ sequence $X$ into a length-$n$ output sequence.
Philox applies an $r$-round substitution-permutation network to the values in $X$.
A single round of the generation algorithm performs the following steps:
That is, there are intermediate values $X^{(0)}, X^{(1)}, \dotsc, X^{(r)}$,
where $X^{(0)} \cedef X$, and for each round $q$ (with $q = 1, \dotsc, r$),
$X^{(q)}$ is computed from $X^{(q - 1)}$ as follows. The output sequence is $X^{(r)}$.
\begin{itemize}
\item
The output sequence $X'$ of the previous round
($X$ in case of the first round)
is permuted to obtain the intermediate state $V$:
\begin{codeblock}
@$V_j = X'_{f_n(j)}$@
\end{codeblock}
where $j = 0, \dotsc, n - 1$ and
$f_n(j)$ is defined in \tref{rand.eng.philox.f}.
An intermediate state $V^{(q)}$ is obtained by permuting the previous output,
$V^{(q)}_j \cedef X^{(q - 1)}_{f_n(j)}$,
where $j = 0, \dotsc, n - 1$, and $f_n(j)$ is defined in \tref{rand.eng.philox.f}.

\begin{floattable}{Values for the word permutation $\bm{f}_{\bm{n}}\bm{(j)}$}{rand.eng.philox.f}
{l|l|l|l|l|l}
Expand All @@ -3136,12 +3133,13 @@
\end{note}

\item
The following computations are applied to the elements of the $V$ sequence:
\begin{codeblock}
@$X_{2k + 0} = \mulhi(V_{2k}, M_{k}, w) \xor \mathit{key}^q_k \xor V_{2k + 1}$@
@$X_{2k + 1} = \mullo(V_{2k}, M_{k}, w)$@
\end{codeblock}
where:
The next output $X^{(q)}$ is computed from the elements of the $V^{(q)}$ as follows.
For $k = 0, \dotsc, n/2 - 1$,
\begin{itemize}
\item $X^{(q)}_{2k + 0} = \mulhi(V^{(q)}_{2k}, M_{k}, w) \xor K^{(q)}_k \xor V^{(q)}_{2k + 1}$, and
\item $X^{(q)}_{2k + 1} = \mullo(V^{(q)}_{2k}, M_{k}, w)$,
\end{itemize}
where
\begin{itemize}
\item
$\mullo(\tcode{a}, \tcode{b}, \tcode{w})$ is
Expand All @@ -3154,17 +3152,11 @@
$(\left\lfloor (\tcode{a} \cdot \tcode{b}) / 2^w \right\rfloor)$,

\item
$k = 0, \dotsc, n/2 - 1$ is the index in the sequences,
$K^{(q)}_k$ is the $k^\text{th}$ round key for round $q$,
$K^{(q)}_k \cedef (K_k + (q - 1) \cdot C_k) \mod 2^w$,

\item
$q = 0, \dotsc, r - 1$ is the index of the round,

\item
$\mathit{key}^q_k$ is the $k^\text{th}$ round key for round $q$,
$\mathit{key}^q_k \cedef (K_k + q \cdot C_k) \mod 2^w$,

\item
$K_k$ are the elements of the key sequence $K$,
$K_k$ is the $k^\text{th}$ element of the key sequence $K$,

\item
$M_k$ is \tcode{multipliers[$k$]}, and
Expand All @@ -3174,10 +3166,6 @@
\end{itemize}
\end{itemize}

\pnum
After $r$ applications of the single-round function,
\tcode{Philox} returns the sequence $Y = X'$.

\indexlibraryglobal{philox_engine}%
\indexlibrarymember{result_type}{philox_engine}%
\begin{codeblock}
Expand Down