jasmin icon indicating copy to clipboard operation
jasmin copied to clipboard

Let's DOIT: Add support for DOIT-instruction list in (S)CT checkers

Open J08nY opened this issue 1 year ago • 6 comments

This PR will add support for ensuring that secret values only go into guaranteed constant-time instructions (Intel DOITM, ARM DIT).

Currently it does the following:

  • Adds a script for semi-automated extraction of the Intel DOIT/ARM DIT lists. This script checks, in the Intel case, whether the opcodes on the list cover all the instruction encodings of the mnemonic on the list.
  • Adds a CLI option -help-instructions to the compiler that is similar to the -help-instrinsics one but prints all of the instructions for the given architecture that Jasmin understands along with their expanded variants. This is necessary for the automated extraction of the DIT/DOIT instructions that Jasmin supports. Example of output:

VPSUB:VPSUBB VPSUB:VPSUBD VPSUB:VPSUBQ VPSUB:VPSUBW

  • Adds a CLI option -doit to the jazzct tool that switches the CT checker list of constant-time instructions from "all but DIV/MOD" to "only those in the DOIT/DIT" lists. This CLI option also checks that the compiler pass selected is during or after lowering, because the mode otherwise does not make sense.

Which compiler pass to run with

It needs to be done at least after lowering, to have the instructions.

When run right after lowering, the CT checker can have false positives in case of lines like: if (_LT(of, cf, sf, zf)) { because it will consider all of the flags, even though the _LT operator only actually considers some. If run after inline variable propagation this problem disappears, because the expression will be replaced with one that contains only the used flags.

J08nY avatar Feb 23 '24 10:02 J08nY