summaryrefslogtreecommitdiff
path: root/include/nvcounter.h
Commit message (Collapse)AuthorAgeFilesLines
* Add non-volatile flash counterVincent Palatin2017-06-021-0/+20
Add the implementation of a robust non-volatile incrementing counter using 2 pages from the underlying flash. It is used to implement the U2F functionality. The main goal of the counter is providing a strictly incrementing value whatever adverse events (malicious or not) happen as it is used to prevent rollback attacks in the U2F protocol. Given the limitation of the flash process: ie wear-out endurance and 2kB-page erase granularity only and possible isolated bit-flips (accentuated by power losses), the counting is done by pulling down several bits at a time from their erased state (1) to 0. The counting is implemented this way with 2 pages called LOW and HIGH: The LOW page is implemented in a strike style, with each "strike" zero-ing out 4 bits at a time, meaning each word can be struck a total of 8 times. Once the LOW page is completely struck, the HIGH page is incremented by 2. The even increment is for the value, the odd increment is a guard signal that the LOW page must be erased. So as an example: If HIGH is 2, the LOW page would increment to 3, erase itself, and then increment to 4. If this process is interrupted for some reason (power loss or user intervention) and the HIGH left at 3, on next resume, the HI page will recognize something was left pending and erase again. For a platform with 2-kB flash pages, it can count up to 8388608, then it is stuck at 0xFFFFFFF indefinitely. Mostly copied over from Marius code in cr52 code-base. Signed-off-by: Marius Schilder <mschilder@google.com> Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=cr50 BUG=b:35545754 TEST=with follow-up CLs, run U2FTest on Eve Change-Id: Idd0756078e3641c4a24f9c4ccf6611909bd5f00f Reviewed-on: https://chromium-review.googlesource.com/518135 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>