A method for the execution of a binary code of a secure function by a microprocessor, said method comprising the following steps:
- a) providing the binary code, the binary code that is provided comprising a machine code containing a sequence of basic blocks, wherein
- each basic block comprises a sequence of instruction lines each containing a cryptogram of an instruction, the instructions coded in these successive instruction lines being intended to be executed automatically by the microprocessor in the order in which they appear in said basic block.
- each basic block starts at a branch address and ends with an instruction line containing the cryptogram of a branch instruction to a branch address of another basic block, said other basic block being called “the following basic block” and the basic block that ends with the instruction line containing the cryptogram of this branch instruction to said following basic block being called “the previous basic block”,
- the cryptogram contained in each encrypted instruction line of a basic block depends on a mask associated with this basic block, said mask being different from the masks associated with the other basic blocks,
- each previous basic block contains an instruction line containing the cryptogram of an instruction to load a mask that, when it is executed by the microprocessor, causes loading, to the microprocessor, of the mask to be used to obtain an instruction from the cryptogram of each instruction line of the following basic block,
- b) execution of the binary code by the microprocessor, in said execution the method comprises:
- recording data in the main memory for each item of data to be recorded, the method comprising:
- executing an algorithm for constructing a data line containing a cryptogram of said item of data constructed using an initialization vector ivj associated with an address @j of the main memory using a relationship ivj=Fiv(@j), where the function Fiv is a pre-programmed function that associates a different initialization vector ivj with each different address @j of the main memory, and then
- recording said constructed data line in the main memory at the address @j,
- execution, by the arithmetic and logic unit, of an instruction to load the data line, said load instruction containing an operand from which the address @j where the data line to be loaded from the main memory is recorded is obtained, followed by verifying that the loaded data line was actually constructed using the initialization vector ivj associated with said address @j by the function Fiv, and when said verification fails, triggering signaling of an execution fault and, when said verification succeeds, preventing said signaling of an execution fault,
- executing previous and following basic blocks, and when executing each instruction of the following basic block:
- loading, from the main memory, the instruction line designated by an ordinal counter of the microprocessor, followed by decrypting the cryptogram contained in the loaded instruction line using the mask loaded to the microprocessor when the previous basic block was executed, and then
- execution of the decrypted instruction by an arithmetic and logic unit of the microprocessor,
- wherein each instruction line of a basic block is constructed by executing the same construction algorithm as the one executed to construct the data line and using the same function Fiv, the item of data for said purpose being taken to be equal to the instruction masked using the mask associated with said basic block, such that loading said instruction line by executing an instruction to load a data line does not automatically trigger signaling of an execution fault.