<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Security on LoomLoops</title><link>https://loomloops.com/tags/security/</link><description>PostgreSQL and SQLite errors, payments, and how everyday tech works. Taken apart to see how it works.</description><language>en-us</language><lastBuildDate>Tue, 19 May 2026 10:45:00 +0000</lastBuildDate><atom:link href="https://loomloops.com/tags/security/index.xml" rel="self" type="application/rss+xml"/><item><title>How Password Managers Store Passwords Without Being Able to Read Them</title><link>https://loomloops.com/post/how-password-managers-store-passwords/</link><pubDate>Tue, 19 May 2026 10:45:00 +0000</pubDate><dc:creator>Rafi Loom</dc:creator><guid>https://loomloops.com/post/how-password-managers-store-passwords/</guid><description>&lt;p&gt;You save a login on your laptop. A second later it is on your phone. In&#10;between, the vault passed through a server that a company runs. That company&#10;has staff, backups, and a hosting provider, so it is fair to ask: could any of&#10;them read your passwords?&lt;/p&gt;&#10;&lt;p&gt;For the designs I read about below, the answer is meant to be no. The server&#10;keeps a locked box and never gets the key. This post shows how the key is made,&#10;why making it slow is the whole point, what an attacker gets if the server is&#10;copied, and what passkeys change.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Short version:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Your device scrambles (encrypts) the vault before it syncs. The key comes&#10;from your master password, and the password itself is never sent.&lt;/li&gt;&#10;&lt;li&gt;The key is made with a deliberately slow function (PBKDF2 or Argon2id). If&#10;someone copies the server, that slowness is the only thing between them and&#10;your master password. A weak master password still falls.&lt;/li&gt;&#10;&lt;li&gt;A passkey replaces the shared secret with a key pair per site. The server&#10;keeps only a public key, and the browser ties each signature to the real&#10;site address, so a lookalike site gets nothing.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="what-lives-where"&gt;What lives where&lt;/h2&gt;&#10;&lt;p&gt;A password manager has two jobs. It stores your logins, and it keeps them in&#10;step across devices. The trick is to do the second job without trusting the&#10;server with the first.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/device-vs-server.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/device-vs-server.svg" alt="A password manager keeps the master password, the key made from it and your readable logins on your device. The server only holds the scrambled vault, a login proof and account details such as your email." loading="lazy" decoding="async" width="640" height="410"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;Two words need explaining:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Encryption&lt;/strong&gt; scrambles data so it can only be read with a key. With the&#10;key you can get the original back.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;A hash&lt;/strong&gt; is a one-way scramble. You cannot get the original back from it.&#10;You can only check a guess by hashing the guess and comparing.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;The vault is encrypted on your device. Bitwarden&amp;rsquo;s &lt;a href="https://bitwarden.com/help/what-encryption-is-used/"&gt;encryption&#10;page&lt;/a&gt; says it uses AES&#10;with 256-bit keys in CBC mode, plus an HMAC (a check code that shows whether&#10;anyone changed the data). Vendors call this &amp;ldquo;zero knowledge&amp;rdquo;. It means the&#10;company has no key to read your data.&lt;/p&gt;&#10;&lt;p&gt;The server stores what it needs to sync and to check that you are you.&#10;Bitwarden&amp;rsquo;s &lt;a href="https://bitwarden.com/help/bitwarden-security-white-paper/"&gt;security white&#10;paper&lt;/a&gt; lists four&#10;kinds of data on its server: authentication data, the data used to open the&#10;vault, the encrypted vault, and encrypted key pairs.&#10;1Password&amp;rsquo;s &lt;a href="https://agilebits.github.io/security-design/infra.html"&gt;security design&#10;document&lt;/a&gt; says the&#10;vault items on its server hold encrypted overview and detail data, and that it&#10;never has an unencrypted vault key. It also says some account fields, such as a&#10;user name and email address, are stored in the clear. Read each vendor&amp;rsquo;s page&#10;for what is and is not encrypted. It is not the same everywhere.&lt;/p&gt;&#10;&lt;h2 id="from-a-master-password-to-a-key"&gt;From a master password to a key&lt;/h2&gt;&#10;&lt;p&gt;You type a master password. The app turns it into an encryption key with a&#10;&lt;strong&gt;key derivation function&lt;/strong&gt; (KDF). A KDF takes a password and some extra&#10;input, and produces a fixed-size key. The extra input is a &lt;strong&gt;salt&lt;/strong&gt;: a value&#10;that differs per user, so two people with the same password still get&#10;different keys. Bitwarden uses your email address as the salt. The &lt;a href="https://www.rfc-editor.org/rfc/rfc8018.html"&gt;PKCS #5&#10;standard&lt;/a&gt; says a salt exists so&#10;that an attacker cannot precompute all the keys in advance.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/key-derivation-steps.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/key-derivation-steps.svg" alt="The master password and your email go through 600,000 PBKDF2 rounds to make the master key. It opens the vault key on your device, and a second hash of it goes to the server as the login proof." loading="lazy" decoding="async" width="640" height="450"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;The master key does two jobs, and they are kept apart on purpose. One path&#10;opens the vault on your device. The other makes a separate hash that goes to&#10;the server so it can check you. The server learns something that proves you&#10;know the password. It does not learn anything that opens the vault. Bitwarden&amp;rsquo;s&#10;white paper describes the first path as the master key being stretched with&#10;HKDF (a way to turn one key into several) into the key that decrypts your vault&#10;key. The login hash is a second PBKDF2 run, with the master key as input and&#10;the master password as the salt. The server then hashes it again with its own&#10;salt before it stores it.&lt;/p&gt;&#10;&lt;p&gt;Here is the slow part in about ten lines. I ran this in a Python container on&#10;my laptop:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;import&lt;/span&gt; hashlib&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;import&lt;/span&gt; time&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;password &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;correct horse battery staple&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;salt &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;user@example.com&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;for&lt;/span&gt; rounds &lt;span style="color:#ff79c6"&gt;in&lt;/span&gt; (&lt;span style="color:#bd93f9"&gt;5_000&lt;/span&gt;, &lt;span style="color:#bd93f9"&gt;100_000&lt;/span&gt;, &lt;span style="color:#bd93f9"&gt;600_000&lt;/span&gt;):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; start &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; time&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;perf_counter()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; key &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; hashlib&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;pbkdf2_hmac(&lt;span style="color:#f1fa8c"&gt;&amp;#34;sha256&amp;#34;&lt;/span&gt;, password, salt, rounds)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ms &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; (time&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;perf_counter() &lt;span style="color:#ff79c6"&gt;-&lt;/span&gt; start) &lt;span style="color:#ff79c6"&gt;*&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;1000&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;f&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;{&lt;/span&gt;rounds&lt;span style="color:#f1fa8c"&gt;:&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;gt;7&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;}&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt; rounds: &lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;{&lt;/span&gt;ms&lt;span style="color:#f1fa8c"&gt;:&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;5.1f&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;}&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt; ms key starts &lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;{&lt;/span&gt;key&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;hex()[:&lt;span style="color:#bd93f9"&gt;16&lt;/span&gt;]&lt;span style="color:#f1fa8c"&gt;}&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;typo &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; hashlib&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;pbkdf2_hmac(&lt;span style="color:#f1fa8c"&gt;&amp;#34;sha256&amp;#34;&lt;/span&gt;, &lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;correct horse battery stapl3&amp;#34;&lt;/span&gt;, salt, &lt;span style="color:#bd93f9"&gt;600_000&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;f&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;one character off: key starts &lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;{&lt;/span&gt;typo&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;hex()[:&lt;span style="color:#bd93f9"&gt;16&lt;/span&gt;]&lt;span style="color:#f1fa8c"&gt;}&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 5000 rounds: 0.6 ms key starts 52ce2d33e007a7c1&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 100000 rounds: 10.5 ms key starts a69d536a06ad8572&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 600000 rounds: 67.2 ms key starts 55dc4a94e4881ffd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;one character off: key starts d2c537bf2cdab8e2&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Two things to see. A one-character typo gives a completely different key, so&#10;there is no &amp;ldquo;close&amp;rdquo;. And 600,000 rounds takes about 67 ms. (The chart below comes from a separate&#10;run of 15, with a median of 65.5 ms.) You will never notice that once when you&#10;open the app. Keep it in mind for the next section.&lt;/p&gt;&#10;&lt;h2 id="why-slow-is-the-point"&gt;Why slow is the point&lt;/h2&gt;&#10;&lt;p&gt;A normal hash is built to be fast. A KDF is built to be slow, and you choose how&#10;slow with the number of &lt;strong&gt;rounds&lt;/strong&gt; (also called iterations): how many times the&#10;hash is repeated for each password. The PKCS #5 standard puts it plainly: an&#10;iteration count &amp;ldquo;has traditionally served the purpose of increasing the cost of&#10;producing keys from a password&amp;rdquo;. It recommends a minimum of 1,000 and, quoting&#10;NIST, says to choose a count &amp;ldquo;as large as possible&amp;rdquo; while users can still wait&#10;for it.&lt;/p&gt;&#10;&lt;p&gt;That standard dates from 2017. Today&amp;rsquo;s numbers are far higher. The &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html"&gt;OWASP&#10;password storage cheat&#10;sheet&lt;/a&gt;&#10;lists these settings:&lt;/p&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Function&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;OWASP setting&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;PBKDF2 with HMAC-SHA-256&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;600,000 rounds&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;PBKDF2 with HMAC-SHA-512&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;220,000 rounds&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;PBKDF2 with HMAC-SHA-1&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;1,400,000 rounds, legacy only&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Argon2id&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;19 MiB of memory, 2 passes, 1 lane (one of five equal trade-offs, from 46 MiB with 1 pass to 7 MiB with 5 passes)&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;p&gt;The vendors sit in the same place. Bitwarden&amp;rsquo;s &lt;a href="https://bitwarden.com/help/kdf-algorithms/"&gt;KDF&#10;page&lt;/a&gt; gives 600,000 rounds of&#10;PBKDF2 as the default, and for Argon2id 64 MiB of memory, 3 passes and 4 lanes (as of this post&amp;rsquo;s date;&#10;the page may change).&#10;1Password&amp;rsquo;s &lt;a href="https://agilebits.github.io/security-design/deepKeys.html"&gt;design&#10;document&lt;/a&gt; says &amp;ldquo;there&#10;are 650,000 iterations of PBKDF2&amp;rdquo; in the current version, and adds that an&#10;account made before 27 January 2023 may still use a lower count until its&#10;password or Secret Key changes.&lt;/p&gt;&#10;&lt;p&gt;The chart below is what those settings cost on one CPU core. I measured them&#10;myself.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/kdf-guess-cost.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/kdf-guess-cost.svg" alt="Bar chart of CPU time per password guess on one laptop: PBKDF2 at 5,000 rounds 0.55 ms, at 600,000 rounds 65.5 ms. Argon2id at 19 MiB and 2 passes 13.9 ms, at 64 MiB and 3 passes 67.4 ms." loading="lazy" decoding="async" width="640" height="466"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;PBKDF2 grows in a straight line: 20 times the rounds costs about 20 times the&#10;time. That is also the cost for the attacker, on a CPU. The chart does not show&#10;the real difference between PBKDF2 and Argon2id, because that difference is&#10;memory, not time. Argon2 is what RFC 9106 calls &amp;ldquo;a memory-hard function&amp;rdquo;: each&#10;guess must hold a block of memory (19 MiB or 64 MiB above) while it works. A&#10;graphics card has thousands of cores but a limited pool of memory, so a guess&#10;that needs tens of megabytes limits how many can run side by side. PBKDF2&#10;needs almost no memory, which is why graphics cards are good at it. RFC 9106&amp;rsquo;s&#10;two recommended settings use 2 GiB or 64 MiB of memory, far above the OWASP&#10;minimums in the table.&lt;/p&gt;&#10;&lt;h2 id="if-the-server-is-copied"&gt;If the server is copied&lt;/h2&gt;&#10;&lt;p&gt;Now the part that many explainers skip. Suppose someone gets a copy of the&#10;server&amp;rsquo;s data.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/server-copied.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/server-copied.svg" alt="If an attacker copies the scrambled vaults, the only way in is guessing the master password offline, with no lockout. A weak password can fall in hours. A long random passphrase holds." loading="lazy" decoding="async" width="640" height="490"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;They have scrambled vaults. They do not have the key. The only way to get it&#10;is to guess the master password: derive a key from the guess, try it on the&#10;vault, see if it works. This happens on the attacker&amp;rsquo;s own computers, so there&#10;is no login page to lock them out and no limit on tries. The server is not&#10;involved at all. This is called an &lt;strong&gt;offline attack&lt;/strong&gt;, and the only brake on it&#10;is the cost of each guess.&lt;/p&gt;&#10;&lt;p&gt;So how much does the slowness buy? For a number, I used a public benchmark. A&#10;hashcat run on one NVIDIA RTX 4090 graphics card, published as &lt;a href="https://gist.github.com/Chick3nman/32e662a5bb63bc4f51b847bb422222fd"&gt;a GitHub&#10;gist&lt;/a&gt;,&#10;measured PBKDF2-HMAC-SHA256 at 8,865.7 kH/s, about 8.87 million guesses a&#10;second, with each guess being 999 rounds. Cost scales with the number of&#10;rounds, so I divided: at 600,000 rounds that card does about 14,800 guesses a&#10;second. At 5,000 rounds it does about 1.8 million.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/offline-guessing-time.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/offline-guessing-time.svg" alt="Log-scale chart of worst-case guessing time on one RTX 4090 at 600,000 PBKDF2 rounds: 1 billion listed guesses about 19 hours, 8 random lowercase letters 164 days, 4 random words 7,800 years." loading="lazy" decoding="async" width="640" height="568"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;How to read it. The axis is logarithmic, so each gridline is far above the one&#10;before. The groups on the bottom are the sets of passwords the attacker has to&#10;try:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;1 billion listed guesses&lt;/strong&gt; is a round number I picked, standing for a&#10;password that sits on a list of likely passwords. At 600,000 rounds it takes&#10;about 19 hours to try them all. At 5,000 rounds it takes about 9 minutes.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;8 random lowercase letters&lt;/strong&gt; is 26 to the power of 8, about 209 billion&#10;options.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;4 random words&lt;/strong&gt; and &lt;strong&gt;6 random words&lt;/strong&gt; come from a 7,776-word list, such as&#10;the long list from the &lt;a href="https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases"&gt;EFF&lt;/a&gt;.&#10;The EFF says each word adds about 12.9 bits, and each extra bit doubles the&#10;guesses an attacker needs. Six words give about 77 bits.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;8 random characters&lt;/strong&gt; is 94 keyboard characters to the power of 8.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Four things to know before trusting any of it.&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&lt;strong&gt;It is one card, and it is the worst case.&lt;/strong&gt; On average an attacker finds&#10;the password halfway through. A real attacker can rent many cards, and the&#10;time divides by the number of cards. Ten thousand cards turn the 4-word&#10;figure from 7,800 years into about 9 months. Six words are still tens of&#10;millions of years.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;The groups assume the password is random.&lt;/strong&gt; People are not random. They&#10;add a number to a name, or reuse an old password with a change. An attacker&#10;tries those patterns first. The &amp;ldquo;listed guesses&amp;rdquo; group is closer to how a&#10;human-made password behaves than the 8-random-characters one.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;The scaling is my arithmetic.&lt;/strong&gt; The benchmark ran 999 rounds. I assumed&#10;the cost grows in a straight line with the rounds, which holds for PBKDF2.&#10;Treat the numbers as a size, not a measurement of any real attack.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;The rounds multiply the time, not the password.&lt;/strong&gt; Going from 5,000 to&#10;600,000 rounds makes every row 120 times longer. For a password on a list,&#10;that turns minutes into hours. It does not make a listed password safe.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;The 1Password design document is blunt about this. It says its slow hashing&#10;&amp;ldquo;goes some way to increase the work&amp;rdquo; an attacker needs, but &amp;ldquo;cannot substitute&#10;a strong account password&amp;rdquo;. It then adds a second protection for this exact&#10;case. Your account password is combined with a &lt;strong&gt;Secret Key&lt;/strong&gt;, a random&#10;128-bit value that is kept on your devices and not on the server. The document&#10;says an attacker who captures only server data would have to guess the&#10;password and also have the Secret Key, and that &amp;ldquo;the information held on our&#10;systems cannot be used to check whether an account password guess is correct&#10;or not.&amp;rdquo; The cost: you have to keep the Secret Key safe yourself, and it does&#10;nothing if your own device is compromised.&lt;/p&gt;&#10;&lt;h2 id="where-it-breaks"&gt;Where it breaks&lt;/h2&gt;&#10;&lt;p&gt;The design protects against a copied server. These cases it does not cover:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;A weak or reused master password.&lt;/strong&gt; Everything above depends on it. The&#10;KDF only slows the guessing down.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Your own device.&lt;/strong&gt; When the vault is open, the key and the decrypted logins&#10;are in memory. Malware on that device sees what you see. Neither vendor&amp;rsquo;s&#10;design claims otherwise. 1Password says plainly that the Secret Key plays no&#10;part if your own system is breached.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;The app you run.&lt;/strong&gt; The encryption happens in code the vendor ships. If that&#10;code were changed to send the master password, the design would not help.&#10;Some vendors publish their client code and commission audits, so that&#10;others can check what it does.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Old settings.&lt;/strong&gt; A vault made years ago may use fewer rounds, because the&#10;count is stored per account. Check your own account&amp;rsquo;s setting&#10;rather than assume it moved.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;What is not encrypted.&lt;/strong&gt; As above, some account details are stored in the&#10;clear. The server can also see when you sync and roughly how large the vault is.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="what-passkeys-change"&gt;What passkeys change&lt;/h2&gt;&#10;&lt;p&gt;A password is a shared secret. You and the site both know it, so the site has&#10;to store something derived from it, and an attacker who steals that has&#10;something to crack. A passkey removes the shared secret. The FIDO Alliance, which&#10;develops the passkey standards, says &lt;a href="https://fidoalliance.org/passkeys/"&gt;passkeys are &amp;ldquo;designed so that there are no&#10;shared secrets&amp;rdquo;&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Under the hood, a passkey is a &lt;strong&gt;key pair&lt;/strong&gt;: two linked keys made together. The&#10;private key signs. The public key checks the signature. Anything signed with&#10;the private key can be checked with the public key, but the public key cannot&#10;be used to sign. The W3C&amp;rsquo;s &lt;a href="https://www.w3.org/TR/webauthn-2/"&gt;Web Authentication&#10;standard&lt;/a&gt; (WebAuthn) describes it with two&#10;parties: the &lt;strong&gt;relying party&lt;/strong&gt; (the website) and the &lt;strong&gt;authenticator&lt;/strong&gt; (the thing&#10;that holds the private key, such as a phone, a laptop or a hardware key).&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/passkey-flow.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/passkey-flow.svg" alt="How a passkey works: sign up stores only a public key on the site. Log in: the site sends a challenge, you approve with fingerprint, face or PIN, and the device signs it. The private key is never sent." loading="lazy" decoding="async" width="640" height="400"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;At sign-up the device makes a pair for that site. The standard says the server&#10;&amp;ldquo;stores the credential public key in its database and associates it with the&#10;user&amp;rdquo;. At log-in the site sends a random &lt;strong&gt;challenge&lt;/strong&gt;. Your device signs it&#10;after you approve with a fingerprint, face or PIN. The site checks the&#10;signature with the stored public key.&lt;/p&gt;&#10;&lt;p&gt;Compare that with a copied server. A copy of the passkey table holds public&#10;keys. There is nothing to guess and nothing that can sign. The challenge is a&#10;fresh random number each time, so a recorded login cannot be played back. The&#10;site has to hand out each challenge once and check it, the opposite problem&#10;from the one in &lt;a href="https://loomloops.com/post/idempotency-keys-explained/"&gt;idempotency keys explained&lt;/a&gt;,&#10;where a repeated request has to be accepted safely.&lt;/p&gt;&#10;&lt;h3 id="the-address-check"&gt;The address check&lt;/h3&gt;&#10;&lt;p&gt;The part that matters for phishing is where the site address comes from. When&#10;your browser asks the device to sign, it adds the address of the page into the&#10;data that gets signed. WebAuthn calls this the origin. The login step in the&#10;standard (section 7.2) has the server check the &lt;code&gt;type&lt;/code&gt;, the &lt;code&gt;challenge&lt;/code&gt; and the&#10;&lt;code&gt;origin&lt;/code&gt;, then verify the signature. The data looks like this, simplified:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;&amp;#34;type&amp;#34;&lt;/span&gt;: &lt;span style="color:#f1fa8c"&gt;&amp;#34;webauthn.get&amp;#34;&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;&amp;#34;challenge&amp;#34;&lt;/span&gt;: &lt;span style="color:#f1fa8c"&gt;&amp;#34;dGhpcyBpcyBhIHJhbmRvbSBudW1iZXI&amp;#34;&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;&amp;#34;origin&amp;#34;&lt;/span&gt;: &lt;span style="color:#f1fa8c"&gt;&amp;#34;https://bank.example&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Each credential is also scoped to a &lt;strong&gt;Relying Party ID&lt;/strong&gt;, in practice the site&amp;rsquo;s&#10;domain. The standard says the ID must equal the origin&amp;rsquo;s domain or a parent&#10;domain of it, and that the credential &amp;ldquo;can only be accessed by origins&#10;belonging to that Relying Party&amp;rdquo;.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/fake-site.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/fake-site.svg" alt="A password typed into a lookalike site goes to the attacker. A passkey is tied to the real address, so the device finds no key for the lookalike and there is nothing to sign." loading="lazy" decoding="async" width="640" height="410"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;You type a password into whatever page is in front of you, so a good enough&#10;copy of the page gets it. A passkey does not depend on what you think the page&#10;is. The browser reports the real address, and a device has no key for&#10;&lt;code&gt;bank-login.example&lt;/code&gt;. Nothing is left to hand over. The FIDO Alliance calls&#10;phishing resistance &amp;ldquo;a core design goal&amp;rdquo;.&lt;/p&gt;&#10;&lt;h3 id="passkeys-and-password-managers-together"&gt;Passkeys and password managers together&lt;/h3&gt;&#10;&lt;p&gt;They are not rivals. A passkey has to live somewhere. FIDO says it can be&#10;&amp;ldquo;securely synced across a user&amp;rsquo;s devices, or bound to a particular device&amp;rdquo;.&#10;Bitwarden&amp;rsquo;s &lt;a href="https://bitwarden.com/help/storing-passkeys/"&gt;passkey help&#10;page&lt;/a&gt; says passkeys saved in&#10;Bitwarden are protected with its end-to-end encryption and synced between your&#10;devices.&lt;/p&gt;&#10;&lt;p&gt;That changes the plain wording &amp;ldquo;the private key never leaves the device&amp;rdquo;. For a&#10;device-bound passkey, such as one on a hardware key, it is true. The standard&#10;says the private key is &amp;ldquo;expected to never be exposed to any other party, not&#10;even to the owner of the authenticator&amp;rdquo;. For a synced passkey, copies of the&#10;private key travel, encrypted, through the sync. You are back to the first half&#10;of this post: the passkey is only as safe as the vault that holds it, and the&#10;vault is only as safe as its master password.&lt;/p&gt;&#10;&lt;h2 id="questions-people-ask"&gt;Questions people ask&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Can a password manager company see my passwords?&lt;/strong&gt;&#10;In the designs described here, no. The vault is encrypted on your device with a&#10;key made from your master password, and the server never receives the password&#10;or the key. The company can still see some account data, such as your email&#10;address. Check the vendor&amp;rsquo;s white paper for the exact list.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;What happens if a password manager is hacked?&lt;/strong&gt;&#10;It depends on what was taken. A copy of the server gives the attacker locked&#10;vaults, and they then try to guess master passwords offline. The slow key&#10;derivation sets the cost per guess, and the strength of your master password&#10;sets how many guesses it takes. A weak one can fall in hours. A long random one&#10;holds, going by the chart above. If your own device is infected, the server&amp;rsquo;s&#10;design does not matter.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Is PBKDF2 or Argon2id better?&lt;/strong&gt;&#10;Argon2id is built to need a lot of memory per guess, which makes graphics cards&#10;less useful for guessing. RFC 9106 gives recommended Argon2id settings, and OWASP lists it first.&#10;PBKDF2 is simpler and has FIPS 140 validated implementations, which is why&#10;OWASP says to prefer it where that is required. Both are fine at the vendors'&#10;default settings. The weakest link is still the master password.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Does a passkey replace my password manager?&lt;/strong&gt;&#10;No. A passkey replaces the password for one site. Something still has to hold&#10;the passkeys, and many people use their password manager for that. The vault&#10;itself is still protected by the master password.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Why does my vault take a moment to open?&lt;/strong&gt;&#10;That pause is the key derivation. On my laptop 600,000 rounds of PBKDF2 took&#10;about 67 ms. A slower phone takes longer. The cost is the same one the attacker&#10;pays on every guess.&lt;/p&gt;&#10;&lt;h2 id="cheat-sheet"&gt;Cheat sheet&lt;/h2&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-password-managers-store-passwords/cheat-sheet.svg"&gt;&lt;img src="https://loomloops.com/images/how-password-managers-store-passwords/cheat-sheet.svg" alt="Password manager cheat sheet: the vault is encrypted on your device with a key from a slow hash (PBKDF2 or Argon2id). If a server leaks, a long random master password holds. Passkeys resist phishing." loading="lazy" decoding="async" width="640" height="590"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;h2 id="further-reading"&gt;Further reading&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://bitwarden.com/help/bitwarden-security-white-paper/"&gt;Bitwarden security white paper&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://bitwarden.com/help/kdf-algorithms/"&gt;Bitwarden: encryption key derivation (KDF algorithms)&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://bitwarden.com/help/storing-passkeys/"&gt;Bitwarden: storing passkeys&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://agilebits.github.io/security-design/modernauth.html"&gt;1Password security design: making verifiers uncrackable with 2SKD&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://agilebits.github.io/security-design/leopard.html"&gt;1Password security design: vulnerability of server data&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html"&gt;OWASP password storage cheat sheet&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc8018.html"&gt;RFC 8018: PKCS #5, password-based cryptography&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9106.html"&gt;RFC 9106: Argon2&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.w3.org/TR/webauthn-2/"&gt;W3C Web Authentication, level 2&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://fidoalliance.org/passkeys/"&gt;FIDO Alliance: passkeys&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases"&gt;EFF: new wordlists for random passphrases&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://loomloops.com/post/idempotency-keys-explained/"&gt;Idempotency keys explained&lt;/a&gt; on this site, for the other side of the &amp;ldquo;same request twice&amp;rdquo; problem&lt;/li&gt;&#10;&lt;/ul&gt;&#10;</description></item><item><title>How Contactless Payment Works: NFC, the Chip and the Cryptogram</title><link>https://loomloops.com/post/how-contactless-payment-nfc-works/</link><pubDate>Tue, 09 Sep 2025 18:05:00 +0000</pubDate><dc:creator>Rafi Loom</dc:creator><guid>https://loomloops.com/post/how-contactless-payment-nfc-works/</guid><description>&lt;p&gt;You tap a card on a reader. It beeps. The coffee is paid for.&lt;/p&gt;&#10;&lt;p&gt;The card has no battery, no screen and no button. Nobody ever charged it. Yet&#10;something inside it woke up, did some maths and helped a bank say yes, all&#10;while you held it still for a moment.&lt;/p&gt;&#10;&lt;p&gt;Two things are odd about that. Where did the power come from? And if a card&#10;just answers a reader, what stops someone from recording the answer and using&#10;it again?&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Short version:&lt;/strong&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;The terminal&amp;rsquo;s coil makes a magnetic field that swings 13.56 million times a&#10;second. The card&amp;rsquo;s coil turns that into a small voltage. That is the card&amp;rsquo;s&#10;whole power supply, and it is why a tap only works within a few centimetres.&lt;/li&gt;&#10;&lt;li&gt;The card answers by loading its own coil, which the terminal can feel. It&#10;sends a code made from the amount, a random number from the terminal and a&#10;counter. The code is good for one payment.&lt;/li&gt;&#10;&lt;li&gt;A copy of a tap fails at the bank: the counter was already used, or the code&#10;does not match. Phone wallets also swap the card number for a stand-in&#10;number (a token). The open problem is a relay, not a replay.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-card-is-a-coil-and-a-chip"&gt;The card is a coil and a chip&lt;/h2&gt;&#10;&lt;p&gt;A contactless card holds a chip and a loop of wire, the antenna, inside the&#10;plastic. The standards call the terminal a proximity coupling device (PCD)&#10;and the card a proximity integrated circuit card (PICC). The standard for&#10;both is ISO/IEC 14443, and it is the radio layer under contactless payments.&#10;NFC phones talk to the same kind of card: the NFC Forum says its devices work&#10;with ISO/IEC 14443 Type A and Type B readers and cards.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/field-coupling.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/field-coupling.svg" alt="Side view of a terminal and a card. The terminal coil makes a magnetic field that passes through the card’s coil, makes a voltage there and powers the chip. The card has no battery." loading="lazy" decoding="async" width="640" height="492"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;The trick is called induction. A magnetic field that changes through a loop&#10;of wire pushes a voltage into that loop. A steady field does nothing. It has&#10;to change, and at 13.56 MHz it changes 13.56 million times a second. The&#10;Rohde &amp;amp; Schwarz test note for ISO/IEC 14443 puts it in one line: the carrier&#10;supplies power to the card &amp;ldquo;via a transformer coupling and the resulting&#10;induced voltage&amp;rdquo;.&lt;/p&gt;&#10;&lt;p&gt;How much voltage? The size of the voltage in a coil is &lt;code&gt;V = 2 * pi * f * mu0 * H * N * A&lt;/code&gt;,&#10;where &lt;code&gt;f&lt;/code&gt; is the frequency, &lt;code&gt;mu0&lt;/code&gt; is a physical constant, &lt;code&gt;H&lt;/code&gt; is the field&#10;strength, &lt;code&gt;N&lt;/code&gt; is the number of turns and &lt;code&gt;A&lt;/code&gt; is the area of one turn. I ran&#10;the numbers in a container. I had to guess the coil, so take this as a size&#10;estimate and not a spec: 4 turns, 7 cm by 4 cm, and the lowest field the&#10;standard allows, 1.5 amps per metre (A/m).&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;H = 1.5 A/m -&amp;gt; 1.80 V rms, open circuit&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;H = 7.5 A/m -&amp;gt; 8.99 V rms, open circuit&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So a card sitting in the field gets volts, which is plenty to run a small&#10;chip. Real cards differ in turns, size and tuning.&lt;/p&gt;&#10;&lt;h2 id="why-it-only-works-within-a-few-centimetres"&gt;Why it only works within a few centimetres&lt;/h2&gt;&#10;&lt;p&gt;The standard says the terminal&amp;rsquo;s field in its working zone is between 1.5 and&#10;7.5 A/m. A card has to run at the low end. Now ask how far you can be before&#10;the field drops to 1.5.&lt;/p&gt;&#10;&lt;p&gt;For a round loop of radius &lt;code&gt;a&lt;/code&gt;, the field on its axis at distance &lt;code&gt;z&lt;/code&gt; is&#10;&lt;code&gt;H(z) = H0 / (1 + (z/a)^2)^1.5&lt;/code&gt;. Far from the loop, that falls with the cube of&#10;the distance. Researchers at the University of Surrey write the same thing in&#10;their 2013 paper: the field strength &amp;ldquo;is inversely proportional to the cube of&#10;the distance&amp;rdquo;.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/field-vs-distance.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/field-vs-distance.svg" alt="Line chart of terminal field strength against distance. A 7.5 A/m reader falls below the 1.5 A/m a card needs at about 4.2 cm, and a 3 A/m reader at about 2.3 cm. Limits from ISO/IEC 14443." loading="lazy" decoding="async" width="640" height="450"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;I drew two readers on the same 3 cm loop. The strong one makes the standard&amp;rsquo;s&#10;maximum of 7.5 A/m at the coil. The weak one makes 3. The card runs out of&#10;power at about 4.2 cm for the strong one and 2.3 cm for the weak one. Between&#10;6 cm and 12 cm the field drops from 0.67 to 0.11 A/m, about six times.&lt;/p&gt;&#10;&lt;p&gt;The curve shows the shape, not a spec. Real terminal antennas are not round&#10;3 cm loops. The NFC Forum gives &amp;ldquo;a typical range of up to 2cm&amp;rdquo; for its own&#10;devices. The point is the same: a few centimetres, then nothing.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Powering a card and listening to a card are different jobs.&lt;/strong&gt; In a shielded&#10;lab, the Surrey team used a loop antenna and cheap electronics to listen to an&#10;emulated tap. They recovered the messages from 20 to 90 cm away near the 7.5 A/m&#10;maximum, and reliably up to 40 cm near the 1.5 A/m minimum. A listener does not&#10;need to power anything. It only needs to hear. What it hears is one payment&amp;rsquo;s&#10;worth of data, which the section on copying shows is not much use.&lt;/p&gt;&#10;&lt;h2 id="how-the-two-sides-talk"&gt;How the two sides talk&lt;/h2&gt;&#10;&lt;p&gt;A card has no transmitter. Both sides use the one field.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/load-modulation.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/load-modulation.svg" alt="Two waveform sketches. Terminal to card: the 13.56 MHz carrier is switched off for short gaps that carry data. Card to terminal: the card loads its coil at 847.5 kHz. The start-up rate is 106 kbit/s." loading="lazy" decoding="async" width="640" height="430"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;&lt;strong&gt;Terminal to card.&lt;/strong&gt; The terminal switches its field off for a very short&#10;moment. The pattern of gaps is the data. The Rohde &amp;amp; Schwarz note lists this&#10;for Type A as 100% amplitude-shift keying with modified Miller coding. (There&#10;is also a Type B, with 10% modulation. The numbers here are Type A.)&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Card to terminal.&lt;/strong&gt; The card cannot make its own signal, so it changes how&#10;much it loads its own coil. It does this at 847.5 kHz, which is the carrier&#10;divided by 16. A coil that draws more current is felt by the coil that feeds&#10;it, the same way a transformer&amp;rsquo;s input feels its output. The terminal sees its&#10;own carrier swell and dip, 16 carrier cycles per swell, and decodes the&#10;pattern. The same note lists this as on-off keying with Manchester coding at&#10;106 kbit/s for Type A. That bit rate is also the carrier divided by 128, and&#10;communication always starts there.&lt;/p&gt;&#10;&lt;h2 id="what-they-say-to-each-other"&gt;What they say to each other&lt;/h2&gt;&#10;&lt;p&gt;Once the card has power, the terminal and card swap a handful of short&#10;messages. This is from a trace of a Visa card in a 2019 Black Hat Europe paper&#10;by Leigh-Anne Galloway and Tim Yunusov. Other card schemes use other&#10;&amp;ldquo;kernels&amp;rdquo; (the terminal software that runs the exchange) and differ in the&#10;details.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/tap-conversation.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/tap-conversation.svg" alt="A contactless tap in five steps: the terminal asks for payment apps, the card lists them, the terminal sends the amount and a random number, the card returns a one-time cryptogram, and the bank decides." loading="lazy" decoding="async" width="640" height="600"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;Four terms from the picture:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;PPSE&lt;/strong&gt; is the proximity payment system environment. It is a directory on&#10;the card that lists which payment apps it carries.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;AID&lt;/strong&gt; is the application ID of one of those apps, such as a Visa one.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Cryptogram&lt;/strong&gt; is the one-time code. The spec calls it the application&#10;cryptogram (AC).&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;ATC&lt;/strong&gt; is the application transaction counter. The card adds 1 to it on&#10;every transaction.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Not every tap asks for a PIN. Terminals have limits. The UK limit for a card&#10;tap went up to £100 in 2021, according to UK Finance. Above a limit, the&#10;terminal asks for something extra, such as a PIN or a face or fingerprint check on the phone.&lt;/p&gt;&#10;&lt;p&gt;The tap itself only asks the bank to approve. The money moves later, when the&#10;shop&amp;rsquo;s card payments are settled. &lt;a href="https://loomloops.com/post/payment-reconciliation/"&gt;Payment reconciliation in&#10;SQL&lt;/a&gt; is about matching those later records to&#10;the bank&amp;rsquo;s.&lt;/p&gt;&#10;&lt;h2 id="why-a-copied-tap-does-not-pay"&gt;Why a copied tap does not pay&lt;/h2&gt;&#10;&lt;p&gt;Suppose a thief records everything in the conversation above. What can they&#10;do with it?&lt;/p&gt;&#10;&lt;p&gt;The code is a &lt;strong&gt;MAC&lt;/strong&gt;, a message authentication code. It is a short tag made&#10;from some data and a secret key. Anyone who has the key can compute it again.&#10;Nobody else can make a valid one. The card holds the key inside the chip, and&#10;the bank holds the same key. The key never goes over the air.&lt;/p&gt;&#10;&lt;p&gt;In the Cambridge paper &amp;ldquo;Chip and Skim&amp;rdquo; (arXiv 2012; IEEE S&amp;amp;P 2014), the code the card sends is a&#10;MAC over data that includes the amount, a random number from the terminal and&#10;the card&amp;rsquo;s counter (ATC). The bank recomputes it. The paper adds the rule that&#10;stops replays: &amp;ldquo;a competent issuer prevents replay by rejecting any&#10;transaction whose application transaction counter it has already seen&amp;rdquo;.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/copy-check.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/copy-check.svg" alt="Table of four cases at the bank: a real tap is approved; a replayed recording is declined because the counter was used; a changed amount fails the code; a clone without the secret key fails the code." loading="lazy" decoding="async" width="640" height="600"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;I wrote a toy version to watch it happen. It uses HMAC-SHA256 from Python&amp;rsquo;s&#10;standard library, not the MAC a real EMV card uses, and it has far fewer&#10;fields. I ran it on Python 3.12 in a container.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;import&lt;/span&gt; hmac&lt;span style="color:#ff79c6"&gt;,&lt;/span&gt; hashlib&lt;span style="color:#ff79c6"&gt;,&lt;/span&gt; os&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;def&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;mac&lt;/span&gt;(key, &lt;span style="color:#ff79c6"&gt;*&lt;/span&gt;fields):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;return&lt;/span&gt; hmac&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;new(key, &lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;|&amp;#34;&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;join(fields), hashlib&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;sha256)&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;digest()[:&lt;span style="color:#bd93f9"&gt;8&lt;/span&gt;]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;class&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;Card&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;def&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;__init__&lt;/span&gt;(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;, key):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;_key &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; key &lt;span style="color:#6272a4"&gt;# never leaves the chip&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;atc &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;0&lt;/span&gt; &lt;span style="color:#6272a4"&gt;# counter, +1 on every tap&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;def&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;tap&lt;/span&gt;(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;, amount, unpredictable):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;atc &lt;span style="color:#ff79c6"&gt;+=&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; atc &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;str&lt;/span&gt;(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;atc)&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;encode()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;return&lt;/span&gt; atc, mac(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;_key, amount, unpredictable, atc)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;class&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;Issuer&lt;/span&gt;:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;def&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;__init__&lt;/span&gt;(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;, key):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;key &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; key&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;last_atc &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;0&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;def&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;approve&lt;/span&gt;(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;, amount, unpredictable, atc, code):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;if&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;int&lt;/span&gt;(atc) &lt;span style="color:#ff79c6"&gt;&amp;lt;=&lt;/span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;last_atc:&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;return&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;&amp;#34;declined: counter already seen&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;if&lt;/span&gt; &lt;span style="color:#ff79c6"&gt;not&lt;/span&gt; hmac&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;compare_digest(mac(&lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;key, amount, unpredictable, atc), code):&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;return&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;&amp;#34;declined: code does not match&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="font-style:italic"&gt;self&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;last_atc &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;int&lt;/span&gt;(atc)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;return&lt;/span&gt; &lt;span style="color:#f1fa8c"&gt;&amp;#34;approved&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;key &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; os&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;urandom(&lt;span style="color:#bd93f9"&gt;16&lt;/span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;card, bank &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; Card(key), Issuer(key)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;un &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; os&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;urandom(&lt;span style="color:#bd93f9"&gt;4&lt;/span&gt;)&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;hex()&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;encode() &lt;span style="color:#6272a4"&gt;# the terminal&amp;#39;s random number&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;atc, code &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; card&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;tap(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;4.50&amp;#34;&lt;/span&gt;, un)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;real tap &amp;#34;&lt;/span&gt;, bank&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;approve(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;4.50&amp;#34;&lt;/span&gt;, un, atc, code))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;recording, replayed &amp;#34;&lt;/span&gt;, bank&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;approve(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;4.50&amp;#34;&lt;/span&gt;, un, atc, code))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;recording, new amount &amp;#34;&lt;/span&gt;, bank&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;approve(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;450.00&amp;#34;&lt;/span&gt;, un, &lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;2&amp;#34;&lt;/span&gt;, code))&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;clone &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; Card(os&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;urandom(&lt;span style="color:#bd93f9"&gt;16&lt;/span&gt;)) &lt;span style="color:#6272a4"&gt;# has the card number, not the key&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;clone&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;atc &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;1&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;atc2, code2 &lt;span style="color:#ff79c6"&gt;=&lt;/span&gt; clone&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;tap(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;4.50&amp;#34;&lt;/span&gt;, un)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;print&lt;/span&gt;(&lt;span style="color:#f1fa8c"&gt;&amp;#34;clone without the key &amp;#34;&lt;/span&gt;, bank&lt;span style="color:#ff79c6"&gt;.&lt;/span&gt;approve(&lt;span style="color:#f1fa8c"&gt;b&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;4.50&amp;#34;&lt;/span&gt;, un, atc2, code2))&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is what it printed:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;real tap approved&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;recording, replayed declined: counter already seen&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;recording, new amount declined: code does not match&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;clone without the key declined: code does not match&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the &amp;ldquo;new amount&amp;rdquo; line I raised the counter by hand to 2, so the counter&#10;check passes and only the code check is left to fail. That is the point of&#10;the MAC: the thief can change the amount, but cannot change the code to match.&lt;/p&gt;&#10;&lt;p&gt;The bank&amp;rsquo;s counter check is the same idea as an &lt;a href="https://loomloops.com/post/idempotency-keys-explained/"&gt;idempotency&#10;key&lt;/a&gt;: a request that arrives twice must not&#10;pay twice. Here the counter is the key, and the card makes a new one each tap.&lt;/p&gt;&#10;&lt;h3 id="the-part-that-is-easy-to-get-wrong"&gt;The part that is easy to get wrong&lt;/h3&gt;&#10;&lt;p&gt;The counter alone does not prove the code is fresh. A thief could record a&#10;code today and play it tomorrow, if the counter has not moved on at the bank.&#10;The terminal&amp;rsquo;s random number is there to fix that. The Cambridge team found&#10;that some terminals made their &amp;ldquo;unpredictable number&amp;rdquo; from counters,&#10;timestamps or home-grown code. If a thief can guess the number the terminal&#10;will use tomorrow, they can ask your card for a code for each guess today,&#10;and spend them tomorrow. The paper calls this a pre-play attack.&lt;/p&gt;&#10;&lt;p&gt;The team probed 22 cash machines and 5 shop terminals, and told the banks and&#10;card schemes in early 2012 so the software could be patched. The paper notes&#10;that any terminal with a guessable number is exposed in the same way. The fix is a proper random&#10;number generator in the terminal.&lt;/p&gt;&#10;&lt;h2 id="phones-and-tokens"&gt;Phones and tokens&lt;/h2&gt;&#10;&lt;p&gt;A phone wallet adds two things to the card story.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/wallet-token.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/wallet-token.svg" alt="Phone wallet flows. Adding a card puts a token and key in the phone’s secure chip. At each tap you approve on the phone and send the token with a one-time code, so the shop never sees the card number." loading="lazy" decoding="async" width="640" height="596"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;&lt;strong&gt;A stand-in number.&lt;/strong&gt; EMVCo, the body that runs the EMV standards, defines&#10;payment tokenisation. A token replaces the card number with another value that&#10;is &amp;ldquo;constrained in how it can be used&amp;rdquo;, for example to one device. Apple&#10;describes its version: when you add a card, the bank or its service provider&#10;makes a device-specific number, the Device Account Number. It is stored in a&#10;chip called the Secure Element, and it is never stored on Apple&amp;rsquo;s servers. At a&#10;shop, the Secure Element gives the terminal that number and a transaction code,&#10;and Apple says &amp;ldquo;neither Apple nor your device sends your actual payment card&#10;number&amp;rdquo;.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;A check on you.&lt;/strong&gt; Apple says a payment can be made only after the Secure&#10;Element gets the go-ahead from the Secure Enclave, which needs Face ID, Touch&#10;ID or the passcode. (Express Mode for transit cards is an exception that&#10;Apple lists.) The cryptogram is still made from a counter and a key that the&#10;payment network or the issuer knows.&lt;/p&gt;&#10;&lt;p&gt;These are different protections from a plastic card&amp;rsquo;s, not a ranking. A card&#10;has the chip key and the counter. A phone has the same, plus a token and a&#10;lock on the wallet.&lt;/p&gt;&#10;&lt;h2 id="what-can-still-go-wrong"&gt;What can still go wrong&lt;/h2&gt;&#10;&lt;p&gt;Replay, cloning and eavesdropping are covered by the key and the counter. The&#10;open problems are elsewhere.&lt;/p&gt;&#10;&lt;table&gt;&#10;&#9;&lt;thead&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;Attack&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;What the attacker does&lt;/th&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;th&gt;What stops it&lt;/th&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/thead&gt;&#10;&#9;&lt;tbody&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Listen in&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Records a tap from a distance&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;One-time code, so the recording is a replay&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Replay&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Sends the recording again&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;The bank rejects a counter it has seen&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Clone from the number&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Copies the card number&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;The code needs the key, which is not on the number&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Guess the random number&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Collects codes ahead of time&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;A terminal that uses a proper random number generator&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&#9;&#9;&lt;tr&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Relay&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Forwards a live tap to another terminal&lt;/td&gt;&#10;&#9;&#9;&#9;&#9;&#9;&lt;td&gt;Timing checks, spend limits, a lock on the phone&lt;/td&gt;&#10;&#9;&#9;&#9;&lt;/tr&gt;&#10;&#9;&lt;/tbody&gt;&#10;&lt;/table&gt;&#10;&lt;p&gt;&lt;strong&gt;Relay is the one that is hard.&lt;/strong&gt; The attacker has two devices. One acts as a&#10;terminal next to your card. The other acts as a card at a real shop terminal.&#10;The two pass messages along a link. Your real card gets a real challenge and&#10;gives a real, fresh answer, so the counter and the code are both correct. A&#10;2025 survey of attacks on EMV contactless by researchers at ETH Zurich says&#10;this can be built with two NFC Android phones.&lt;/p&gt;&#10;&lt;p&gt;In 2022, researchers at Birmingham and Surrey published a paper on this at the&#10;IEEE Symposium on Security and Privacy. They showed that relaying could get&#10;around the Apple Pay lock screen, and that Visa&amp;rsquo;s relay countermeasure could&#10;be bypassed on rooted phones. They proposed a new relay-resistance protocol and checked it with a&#10;formal tool (Tamarin). I have not checked what&#10;changed in phones or cards since. The 2025 ETH survey says the relay&#10;protection in the kernel it calls Kernel 2 &amp;ldquo;seems&amp;rdquo; not yet available in cards&#10;or terminals.&lt;/p&gt;&#10;&lt;p&gt;The relay needs the attacker&amp;rsquo;s device within a few centimetres of the target&#10;card, which is the same range limit as before.&lt;/p&gt;&#10;&lt;h2 id="how-common-is-it"&gt;How common is it?&lt;/h2&gt;&#10;&lt;p&gt;UK Finance publishes the figures for the United Kingdom. Contactless went from&#10;3% of all UK payments in 2015 to 19% in 2018 and 32% in 2021. In 2023 it was&#10;38%, which was 18.3 billion payments.&lt;/p&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/uk-contactless-share.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/uk-contactless-share.svg" alt="Bar chart of the contactless share of all UK payments: 3 per cent in 2015, 19 in 2018, 32 in 2021 and 38 in 2023, which was 18.3 billion payments. Source: UK Finance." loading="lazy" decoding="async" width="640" height="470"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;p&gt;The 2015, 2018 and 2021 bars come from the UK Finance summary of 2022. The 2023&#10;bar comes from its press release of July 2024. UK Finance revises its series,&#10;so treat the step between 2021 and 2023 as rough.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Update, November 2026:&lt;/strong&gt; later UK Finance reports put contactless at 18.9&#10;billion payments in 2024 (press release of 1 October 2025) and 19.2 billion in&#10;2025, which UK Finance says was 39% of all payments (press release of 19&#10;August 2026).&lt;/p&gt;&#10;&lt;h2 id="questions-people-ask"&gt;Questions people ask&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;How does a contactless card work without a battery?&lt;/strong&gt;&#10;The terminal makes a magnetic field at 13.56 MHz. The card&amp;rsquo;s coil sits in it,&#10;and a changing field makes a voltage in a coil. The chip runs on that voltage.&#10;The card answers by loading its own coil, which the terminal can feel.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;How close does a contactless card have to be?&lt;/strong&gt;&#10;A few centimetres. The standard says the terminal&amp;rsquo;s field is 1.5 to 7.5 A/m, a&#10;card has to run on the low end, and the field of a loop falls with the cube of&#10;the distance once you are away from it. The NFC Forum quotes a typical range of&#10;up to 2 cm for its devices. In a lab, a listener with a loop antenna can hear a&#10;tap from much farther, but hearing is not powering.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Is NFC the same as contactless payment?&lt;/strong&gt;&#10;Not quite. NFC is the short-range radio technology at 13.56 MHz, and NFC Forum&#10;devices can talk to ISO/IEC 14443 cards and readers. Contactless payment is the&#10;EMV payment application that runs on top of that link, with the cryptogram and&#10;the counter.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Can someone copy my card by tapping it?&lt;/strong&gt;&#10;A reader that powers the card can get an answer from it. In the trace above the&#10;card sends its card number and other fixed data. What the reader cannot copy&#10;is the key in the chip, so it cannot make a code the bank will accept for a new&#10;payment. The attack that does work is a relay, which forwards a live tap and&#10;needs a device next to the card.&lt;/p&gt;&#10;&lt;p&gt;&lt;strong&gt;Is a phone tap different from a card tap?&lt;/strong&gt;&#10;The radio and the cryptogram are the same kind. The phone sends a token and&#10;not the card number, and it checks you first. Apple lists Express Mode as a&#10;case where that check is skipped.&lt;/p&gt;&#10;&lt;h2 id="cheat-sheet"&gt;Cheat sheet&lt;/h2&gt;&#10;&lt;figure&gt;&#10; &lt;a href="https://loomloops.com/images/how-contactless-payment-nfc-works/cheat-sheet.svg"&gt;&lt;img src="https://loomloops.com/images/how-contactless-payment-nfc-works/cheat-sheet.svg" alt="Contactless cheat sheet: the terminal’s 13.56 MHz field powers the card, which answers with a one-time code and a counter. The bank refuses replays and clones. A relay attack is the weak spot." loading="lazy" decoding="async" width="640" height="652"&gt;&lt;/a&gt;&#10;&lt;/figure&gt;&lt;h2 id="further-reading"&gt;Further reading&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="https://scdn.rohde-schwarz.com/ur/pws/dl_downloads/dl_application/application_notes/1ma113/1MA113_3e_meas_on_RFID_components.pdf"&gt;Rohde &amp;amp; Schwarz application note 1MA113: measurements on RFID components according to ISO/IEC 14443&lt;/a&gt; (carrier, field strength, modulation, bit rates)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://nfc-forum.org/learn/nfc-technology/"&gt;NFC Forum: NFC technology&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.emvco.com/emv-technologies/contactless/"&gt;EMVCo: EMV Contactless&lt;/a&gt; and &lt;a href="https://www.emvco.com/emv-technologies/payment-tokenisation/"&gt;EMV Payment Tokenisation&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://support.apple.com/en-us/101554"&gt;Apple Support: Apple Pay security and privacy overview&lt;/a&gt; and &lt;a href="https://support.apple.com/en-gb/guide/security/secc1f57e189/web"&gt;Payment authorisation with Apple Pay&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://arxiv.org/pdf/1209.2531"&gt;Bond, Choudary, Murdoch, Skorobogatov and Anderson: Chip and Skim, cloning EMV cards with the pre-play attack&lt;/a&gt; (Cambridge; arXiv 2012, IEEE S&amp;amp;P 2014)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://i.blackhat.com/eu-19/Wednesday/eu-19-Galloway-First-Contact-Vulnerabilities-In-Contactless-Payments-wp.pdf"&gt;Galloway and Yunusov: First Contact, new vulnerabilities in contactless payments&lt;/a&gt; (Black Hat Europe, 2019)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.um.edu.mt/library/oar/bitstream/123456789/100460/1/Eavesdropping_near_field_contactless_payments_a_quantitative_analysis_2013.pdf"&gt;Diakos, Briffa, Brown and Wesemeyer: Eavesdropping near-field contactless payments, a quantitative analysis&lt;/a&gt; (University of Surrey, 2013)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://research.birmingham.ac.uk/en/publications/practical-emv-relay-protection"&gt;Radu, Chothia, Newton, Boureanu and Chen: Practical EMV relay protection&lt;/a&gt; (IEEE S&amp;amp;P 2022)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://arxiv.org/pdf/2504.03363"&gt;Hofmeier, Basin, Sasse and Toro-Pozo: SoK, attacks on modern card payments&lt;/a&gt; (ETH Zurich, 2025)&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://www.ukfinance.org.uk/news-and-insight/press-release/one-third-uk-adults-now-use-mobile-contactless-payments"&gt;UK Finance press release on the Payment Markets Report, July 2024&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://loomloops.com/post/idempotency-keys-explained/"&gt;Idempotency keys explained&lt;/a&gt; on this site&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="https://loomloops.com/post/payment-reconciliation/"&gt;Payment reconciliation in SQL&lt;/a&gt; on this site&lt;/li&gt;&#10;&lt;/ul&gt;&#10;</description></item></channel></rss>