MathJax is used to format mathematical expressions and symbols on cryptography site. You can use expressions within single dollar signs for inline math: $0101_2$
which gives and $0101_2$. Use double dollar signs for a centered block instead: $$\mathtt{CAFE}_{16}$$
gives
$$\mathtt{CAFE}_{16}$$
In the remainder of the text the dollar signs are not included to allow easy copying.
Braces / curly brackets {}
are used to group expressions / symbols together within $\mathrm\TeX$. You need to use the backslash \
escape character to use one within an expression: \{\}
gives you $\{\}$. Parentheses ()
and (square) brackets can be used as-is, for instance in a range $[0, 10)$ is just [0, 10)
.
The double backslash: \\
can be used to include a line break into a longer expression that is between double dollar signs.
The following sections will show common contents of math blocks. There are however other ways of finding out how to use $\mathrm\TeX$:
Identifiers
We generally use $K$ for secret keys, $P$ for public keys and $S$ for private keys (private keys are also kept secret, but they are not shared).
The letter $N$ is generally used for the modulus while $n$ is used for the block size. $k$ is the key size.
Greek symbols are referenced by name, prefixed with a slash, for instance \alpha
for $\alpha$ or \phi
for $\phi$. Start with a capital to have the larger variant if available: \Phi
for $\Phi$.
Multi-letter identifiers are written with \mathit
; otherwise the letters are spaced as if for multiplication. Compare:
E_k(message)
$E_k(message)$
E_k(\mathit{message})
$E_k(\mathit{message})$
there should be more whitespace in the first version (this might be more or less pronounced on your screen, and also depends on the characters within the identifier).
Identifiers in roman face are written with \mathrm
. For example: k_{\mathrm{auth}}, k_{\mathrm{enc}}
gives $k_{\mathrm{auth}}, k_{\mathrm{enc}}$.
Undefined functions
Most cryptographic functions are undefined in the $\mathrm\TeX$ packages; it is however important to make sure they are not confused with identifiers.
Use \operatorname
for well-known named functions like SHA-256, which should be set in roman face: \operatorname{SHA-256}(x)
gives $\operatorname{SHA-256}(x)$, \operatorname{GF}(2^{128})
gives $\operatorname{GF}(2^{128})$. This ensures the spacing is correct for a named function with or without parentheses: $\operatorname{Log}(x)$, $\operatorname{Log} x$; compare $\text{Log} x$ using \text
. If you use a well-known named function Foo many times, you can define \Foo
with DeclareMathOperator{\Foo}{Foo}
.
Big-O notation is alternatively written in italic, roman, or calligraphic face, according to the author's taste, or lack thereof: O(n)
gives $O(n)$, \operatorname O(n)
gives the unnecessarily uptight $\operatorname O(n)$, \mathcal O(n)
gives the floofy fancy $\mathcal O(n)$. The related notation $\tilde O(f(n))$ means $O(f(n) \log^k n)$ for some $k$.
For a function definition like $F\colon \Bbb R \to \Bbb Z_n, \quad x \mapsto {\lfloor x\rfloor}^2\bmod n$
one can use F\colon \Bbb R \to \Bbb Z_n, \quad x \mapsto {\lfloor x\rfloor}^2\bmod n
.
Predefined functions
There are some predefined functions that are useful for cryptography.
\Pr(X)
for probability of X happening $\Pr(X)$
\log_2(x)
gives you logarithm base two: $\log_2(x)$
- others are
\gcd
, \exp
, \ln
and so on; for those missing (no \lcm
), see above.
Sub- and superscript
- just
A
gives you $A$
P_A
gives you $P_A$
P^2
gives you $P^2$
- combined:
P_A^2
gives $P_A^2$ while {P_A}^2
gives ${P_A}^2$ and P_{A^2}
gives $P_{A^2}$
P'
gives you $P'$, and P_A''
gives you $P_A''$
P'
, \tilde P
, \hat P
can be used for variations on a variable: $P'$, $\tilde P$, $\hat P$
\widetilde{P + Q}
, \widehat{P + Q}
for tildes and hats on entire expressions: $\widetilde{P + Q}$, $\widehat{P + Q}$
\overline{S \cup T}
for complements or conjugates: $\overline{S \cup T}$, $\overline{z + w}$
Bit-ops
Bit operations can be shown like this:
- bitwise XOR:
x \oplus y
gives you $x \oplus y$
- bitwise AND:
x \wedge y
gives you $x \wedge y$
alternatively, x \mathbin\& y
gives you $x \mathbin\& y$ (note the backslash escape)
- bitwise OR:
x \vee y
gives $x \vee y$
alternatively, x \mathbin| y
gives you $x \mathbin| y$
- negation:
\neg x
gives you $\neg x$
- left shift: use
x \ll n
for $x \ll n$
- right shift: use
x \gg n
for $x \gg n$
- left rotate: use
x \lll n
for $x \lll n$
- right rotate: use
x \ggg n
for $x \ggg n$
Simple math
- addition:
x + y
gives you $x + y$
- subtraction:
x - y
gives you $x - y$
- multiplication:
x \cdot y
gives you $x \cdot y$
- division:
x / y
gives you $x / y$
- divisibility:
x \mid y
gives you $x \mid y$, x \nmid y
gives you $x \nmid y$
- modulo:
- the binary operator on two integer operands:
x \bmod n
gives you $x \bmod n$
- the relation that two integers are congruent modulo a third:
x \equiv y \pmod n
gives you $x \equiv y \pmod n$
x \equiv y \mod n
gives you $x \equiv y \mod n$
- power:
x ^ y
gives you $x ^ y$
- square root:
\sqrt{x}
gives you $\sqrt{x}$
- $n^{\mathit{th}}$ root:
\sqrt[n]{x}
gives you $\sqrt[n]{x}$
For an equation holding modulo $n$, use x \equiv y \pmod n
for $x \equiv y \pmod n$.
You may also want to use division with a divider line using \frac
, for instance c \cdot \frac {x + y} z
: $$c \cdot \frac {x + y} z$$
Floor and ceiling: \lfloor x \rceil
gives $\lfloor x \rceil$. These can be expanded: \bigg\lceil \frac{x}{y} \bigg\rfloor
gives $$\bigg\lceil \frac{x}{y} \bigg\rfloor,$$ and the sizing is automatic with \left\lfloor f(x)^d \right\rceil
gives $\left\lfloor f(x)^d \right\rceil$.
To multiply vectors or sets it may be wise to chose A \times B
over the \cdot
notation giving you $A \times B$.
Comparison
x = y
is equality $x = y$
x \approx y
is approximately equal $x \approx y$
x \neq y
is non-equality $x \neq y$
x < y
is less-than $x < y$ (no need to escape or use <
within dollar signs)
x \le y
is less-than-or-equal $x \le y$
x \ge y
is greater-than-or-equal $x \ge y$
x \equiv y
is equivalence $x \equiv y$
X \implies Y
is used to show implication: $X \implies Y$ , sometimes X \to Y
for $X \to Y$ is used instead
X \iff Y
is used to show equivalence: $X \iff Y$
It is possible to prefix anything with \not
to negate the next symbol, e.g. \not\le
is $\not\le$
Sets, groups
\{ 0, 1 \}
gives the two-elements set $\{ 0, 1 \}$
\emptyset
gives the empty set $\emptyset$
A \cup B
and A \cap B
give $A \cup B$ (union) and $A \cap B$ (intersection)
a \in A
gives $a \in A$, while b \not\in A
gives $b \not\in A$
A \subset B
or A \subseteq B
give $A \subset B$ or $A \subseteq B$
- Standard sets, usually written in blackboard bold with
\mathbb
or \Bbb
:
- $\Bbb N$
\Bbb N
is some set of natural numbers with ambiguity over whether zero is included or not, so avoid this notation
- $\Bbb N^0, \Bbb N_0$
\Bbb N^0, \Bbb N_0
is the set of natural numbers starting at zero
- $\Bbb N^1, \Bbb N_1, \Bbb N^+$
\Bbb N^1, \Bbb N_1, \Bbb N^+
is the set of natural numbers starting at one
- $\Bbb Z$
\Bbb Z
is the ring of integers (from German Zahl)
- $\Bbb Z^-, \Bbb Z^+, \Bbb Z \setminus \{0\}$
\Bbb Z^-, \Bbb Z^+, \Bbb Z \setminus \{0\}
are the sets of negative, positive, and nonzero integers
- $\Bbb Q$
\Bbb Q
is the field of rational numbers; similarly, $\Bbb Q^-, \Bbb Q^+, \Bbb Q \setminus \{0\}$ \Bbb Q^-, \Bbb Q^+, \Bbb Q \setminus \{0\}
for negative, positive, and nonzero
- $\Bbb R$
\Bbb R
is the field of real numbers; similarly, $\Bbb R^-, \Bbb R^+, \Bbb R \setminus \{0\}$ \Bbb R^-, \Bbb R^+, \Bbb R \setminus \{0\}
for negative, positive, and nonzero
- $\Bbb C$
\Bbb C
is the field of complex numbers
- the ring of integers modplo $p$ is alternately written $\Bbb Z/p\Bbb Z$
\Bbb Z/p\Bbb z
or $\Bbb Z_p$ \Bbb Z_p
, but beware $\Bbb Z_p$ also means the $p$-adic integers
- the multiplicative group of integers modulo $n$ is alternately written $(\Bbb Z/n\Bbb Z)^\times$
(\Bbb Z/n\Bbb Z)^\times
, $(\Bbb Z/n\Bbb Z)^*$ (\Bbb Z/n\Bbb Z)^*
, $\Bbb Z_n^*$ (\Bbb Z/n\Bbb Z)^*
, etc.
- $\operatorname{GF}(p^n), \Bbb F_{p^n}$
\operatorname{GF}(p^n), \Bbb F_{p^n}
is the finite field of characteristic $p$ with $p^n$ elements
Others
M \mathbin \| N
is concatenation of strings: $M\mathbin\|N$
- To indicate failure the
\bot
(bottom) sign is often used: $\bot$
x_1, x_2, \ldots
or x_1 + x_2 + \cdots
gives you something that hasn't been finished: $x_1, x_2, \ldots$ or $x_1 + x_2 + \cdots$
\square
is used for Q.E.D. $\square$
Displayed formulas
If $y^2 \equiv x^3 + 486662 x^2 + x \pmod{2^{255} - 19}$ is too unwieldy inline, use $$y^2 \equiv x^3 + 486662 x^2 + x \pmod{2^{255} - 19}$$
to set it in a display: $$y^2 \equiv x^3 + 486662 x^2 + x \pmod{2^{255} - 19}.$$ (Punctuation at the end goes before the closing $$
so it stays in the display.)
Use \begin{align} ... \end{align}
for multiple equations aligned at relations marked with &
, separated by \\
. Write comments with \text
.
\begin{align}
\Pr[E] &= \Pr[E \mid A] \Pr[A] \\
&\quad + \Pr[E \mid B] \Pr[B] \\
&\quad + \Pr[E \mid C] \Pr[C], \\
1 &= \Pr[A] + \Pr[B] + \Pr[C]. &&\text{($A$, $B$, and $C$ are exhaustive)}
\end{align}
\begin{align}
\Pr[E] &= \Pr[E \mid A] \Pr[A] \\
&\quad + \Pr[E \mid B] \Pr[B] \\
&\quad + \Pr[E \mid C] \Pr[C], \\
1 &= \Pr[A] + \Pr[B] + \Pr[C]. &&\text{($A$, $B$, and $C$ are exhaustive)}
\end{align}
Use \begin{gather} ... \end{gather}
for multiple equations centered:
\begin{gather}
M\colon y^2 = x^3 + 486662 x^2 + x, \\
E\colon -x^2 + y^2 = 1 - \frac{121665}{121666} x^2 y^2.
\end{gather}
\begin{gather}
M\colon y^2 = x^3 + 486662 x^2 + x, \\
E\colon -x^2 + y^2 = 1 - \frac{121665}{121666} x^2 y^2.
\end{gather}
Use \begin{multline} ... \end{multline}
for a multi-line equation:
\begin{multline}
\frac{U^{-\xi} - 1}{\xi}
= \frac{1}{\xi} (e^{-\xi \log U} - 1)
= \frac{1}{\xi} \biggl(-\xi \log U + \frac{\xi^2 \log^2 U}{2!} \\
- \frac{\xi^3 \log^3 U}{3!}
+ \frac{\xi^4 \log^4 U}{4!}
- \cdots\biggr)
\end{multline}
\begin{multline}
\frac{U^{-\xi} - 1}{\xi}
= \frac{1}{\xi} (e^{-\xi \log U} - 1)
= \frac{1}{\xi} \biggl(-\xi \log U + \frac{\xi^2 \log^2 U}{2!} \\
- \frac{\xi^3 \log^3 U}{3!}
+ \frac{\xi^4 \log^4 U}{4!}
- \cdots\biggr)
\end{multline}