Skip to content

Commit 53839d4

Browse files
committed
fix nmac inline math mode
1 parent bd85dfd commit 53839d4

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

crypto/macs.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,15 @@ The output of HMAC is the same number of bits as the underlying hash function, s
7575

7676
To construct the HMAC algorithm, we first start with a more general version, NMAC:
7777

78-
$$
79-
\text{NMAC}(K_1, K_2, M) = H(K_1 \Vert H(K_2 \Vert M))
80-
$$
78+
$$\text{NMAC}(K_1, K_2, M) = H(K_1 \Vert H(K_2 \Vert M))$$
8179

8280
In words, NMAC concatenates $$K_2$$ and $$M$$, hashes the result, concatenates the result with $$K_1$$, and then hashes that result.
8381

8482
Note that NMAC takes two keys, $$K_1$$ and $$K_2$$, both of length $$n$$ (the length of the hash output). If the underlying hash function $$H$$ is cryptographic and $$K_1$$ and $$K_2$$ are unrelated[^2], then NMAC is provably secure.
8583

8684
HMAC is a more specific version of NMAC that only requires one key instead of two unrelated keys:
8785

88-
$$
89-
\text{HMAC}(M,K) = H((K' \oplus opad) \Vert H((K' \oplus ipad) \Vert M ))
90-
$$
86+
$$\text{HMAC}(M,K) = H((K' \oplus opad) \Vert H((K' \oplus ipad) \Vert M ))$$
9187

9288
The HMAC algorithm actually supports a variable-length key $$K$$. However, NMAC uses $$K_1$$ and $$K_2$$ that are the same length as the hash output $$n$$, so we first transform $$K$$ to be length $$n$$. If $$K$$ is shorter than $$n$$ bits, we can pad $$K$$ with zeros until it is $$n$$ bits. If $$K$$ is longer than $$n$$ bits, we can hash $$K$$ to make it $$n$$ bits. The transformed $$n$$-bit version of $$K$$ is now denoted as $$K'$$.
9389

0 commit comments

Comments
 (0)