METHOD FOR EXECUTING A MACHINE CODE BY A MICROPROCESSOR

The method enhances microprocessor security by constructing and using masks for each instruction to counter fault attacks, ensuring robust execution and control flow integrity in machine code execution.

FR3122746B1Active Publication Date: 2024-09-20COMMISSARIAT A LENERGIE ATOMIQUE ET AUX ENERGIES ALTERNATIVES
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
FR2021004896
Authority / Receiving Office
FR · FR
Patent Type
Patents
Current Assignee / Owner
Filing Date
2021-05-10
Publication Date
2024-09-20
Estimated Expiration
2041-05-10

AI Technical Summary

Technical Problem

Existing methods for executing machine code by a microprocessor are vulnerable to fault injection attacks, which can alter the integrity of instructions or data, leading to security breaches such as unauthorized access to cryptographic keys or disruption of critical system functions.

Method used

A method and hardware implementation that includes a hardware instruction processing chain with an instruction loader, decoder, and arithmetic and logic unit, which constructs a mask for each instruction and unmask the next instruction using the constructed mask, and optionally includes unconditional branch instructions to enhance robustness against fault attacks.

Benefits of technology

The method effectively detects and counters alterations in machine code execution, reducing vulnerability to fault attacks by ensuring correct instruction execution and maintaining control flow integrity with minimal additional code size and computational overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000026_0000
    Figure 00000026_0000
  • Figure 00000026_0001
    Figure 00000026_0001
  • Figure 00000027_0000
    Figure 00000027_0000
Patent Text Reader

Abstract

METHOD FOR EXECUTING MACHINE CODE BY A MICROPROCESSOR This method for executing machine code by a microprocessor comprises: - after decoding a currently loaded instruction, constructing (164) a mask from the signals generated by an instruction decoder in response to the decoding of this currently loaded instruction by this decoder, this constructed mask thus varying according to the currently loaded instruction, then - before decoding a subsequent loaded instruction, unmasking (162) the next loaded instruction using the constructed mask. Fig. 3
Need to check novelty before this filing date? Find Prior Art

Description

Description Title of the invention: METHOD FOR EXECUTING A CODE MACHINE BY A MICROPROCESSOR

[0001] — The invention relates to a method of executing a machine code by a micro- processor as well as the machine code executed by this method. The invention relates to also : - an information recording medium and a microprocessor for putting into implementation of this execution process, and - a compiler to generate this machine code.

[0002] — To obtain information about a machine code or to cause an operation unexpected machine code, it is known to subject it to attacks known as term "fault injection" or "fault attack" in English. These attacks consist of disrupt the operation of the microprocessor when executing machine code by various physical means such as changes in supply voltages, changes in the clock signal, exposure of the microprocessor to electro- magnetic and others.

[0003] Using such disturbances, an attacker can alter the integrity of instructions machines or data to, for example, find a secret key to a system cryptographic, bypass security mechanisms such as verification of a PIN code during authentication or simply prevent the execution of a essential function for the security of a critical system.

[0004] — A fault injection attack can cause an alteration of the operation of the microprocessor, for example, by modifications of the instructions which are executed by the arithmetic and logic unit. For this reason, it is common for faults to occur injected aim to disrupt the operation of the micro- instruction decoder processor to produce faulty instructions. Fault injection can also seek to disrupt the operation of the arithmetic and logic unit of the micro- processor.

[0005] — When the decoder disturbance only prevents the execution of one or several of the machine code instructions or when the alteration has an effect on the processor equivalent to not executing the faulty instruction, we then speak of instruction skip. When the decoder disturbance leads to replacing one or several of the machine code instructions by other instructions executable by the microprocessor, we then speak of instruction replacement.

[0006] When the decoder disturbance modifies a branch instruction or when the disturbance of the arithmetic and logic unit consists of skipping an ins- branch instruction, a control flow diversion effect is observed. The control flow corresponds to the execution path followed during the execution of the machine code. The control flow is classically represented in the form of a directed graph known as a control flow graph. The control flow diversion effect can be observed when a branch instruction is altered or when the condition involved in a conditional branch is modified or when the return address of a function is modified. To make machine code execution more robust against such alterations, it has already been proposed to instrument the machine code to include instructions that detect these alterations when they occur. For example, application US20200272475 describes such a solution. This solution works well but requires adding many instructions to the machine code. In addition, it does not necessarily detect an alteration of an instruction that occurs at the time of decoding of this instruction by the microprocessor. The invention aims to propose a method for executing a machine code which makes it possible to signal an alteration of an instruction, an instruction jump and an alteration of the operation of the instruction decoder of the microprocessor. Its subject is therefore such a method for executing a machine code by a microprocessor comprising a hardware instruction processing chain, this hardware processing chain comprising the following stages: an instruction loader, a decoder and an arithmetic and logic unit, this method comprising, for each instruction of the machine code to be executed, successively the following operations: - the loading, by the instruction loader, of the instruction designated by an ordinal counter to obtain a loaded instruction, then - decoding the loaded instruction, by the decoder, to generate signals which configure the microprocessor to execute the loaded instruction, then, - the execution, by the arithmetic and logic unit, of the loaded instruction, wherein the method also comprises the following operations: - after the decoding operation of a current loaded instruction, the construction of a mask from the signals generated by the decoder in response to the decoding of this current loaded instruction, this constructed mask thus varying according to the current loaded instruction, then - before the decoding operation of the next loaded instruction, unmasking the next loaded instruction using the constructed mask. Embodiments of this method of execution may include one or more of the following features: 1) - in response to detecting that a loaded instruction is a branch instruction which, when executed by the arithmetic logic unit, replaces the value of an ordinal counter with a new value, this new value being a function of the operands of this branch instruction, the method comprises unmasking the next loaded instruction using a pre-recorded jump mask which is constant and identical for all branch instructions executed by the microprocessor, and - in response to not detecting that the loaded instruction is a branch instruction, the method comprises unmasking the next loaded instruction using the constructed mask. 2) the process comprises: - freezing the execution of the decoding operation for one or more cycles of a microprocessor clock, and - in response to the freezing of the execution of the decoding operation, the method comprises storing the constructed mask in a register, and - when the execution of the decoding operation resumes, the next loaded instruction is unmasked using the constructed mask stored in this register. 3) the method comprises: - in response to the interruption of the execution of the machine code, called "first machine code", and to the triggering of the execution of a second machine code, the method comprises saving the execution context of the first machine code, this saving of the execution context of the first machine code comprising saving the constructed mask, then - in response to the resumption of the execution of the first machine code and the interruption of the execution of the second machine code, the method comprises restoring the execution context of the first machine code, this restoration of the execution context of the first machine code comprising writing, in a register of the microprocessor, the saved constructed mask, then - unmasking the next loaded instruction after resuming execution of the first machine code using the constructed mask written in this register. 4) unmasking the loaded instruction using the constructed mask consists of performing an "EXCLUSIVE OR" between the bits of the loaded instruction and the bits of the constructed mask. The invention also relates to a machine code executable by a microprocessor, this machine code comprising at least one basic block comprising only instructions to be executed systematically one after the other, in which each instruction of this basic block, with the exception of the first instruction, is masked using a mask constructed from the instruction which immediately precedes in this basic block, this constructed mask being identical to the mask constructed after the decoding operation of the instruction which immediately precedes it during the execution of this machine code according to the above method. Embodiments of this machine code may include the following feature: the first instruction of the basic block is masked using the same jump mask as that used when executing this machine code according to the above execution method. The invention also relates to an information recording medium readable by a microprocessor, this information recording medium containing the above machine code. The invention also relates to a microprocessor for implementing the above execution method, this microprocessor comprising a hardware instruction processing chain, this hardware processing chain comprising the following stages: an instruction loader, a decoder and an arithmetic and logic unit, this hardware processing chain being capable, for each instruction of the machine code to be executed, of successively executing the following operations: - the loading, by the instruction loader, of the instruction designated by an ordinal counter to obtain a loaded instruction, then - decoding the loaded instruction, by the decoder, to generate signals which configure the microprocessor to execute the loaded instruction, then, - the execution, by the arithmetic and logic unit, of the loaded instruction, in which the hardware processing chain also includes a hardware unmasking module capable of carrying out the following operations: - after the decoding operation of a current loaded instruction, the construction of a mask from the signals generated by the decoder in response to the decoding of this current loaded instruction, this constructed mask thus varying according to the current loaded instruction, then - before the decoding operation of the next loaded instruction, unmasking the next loaded instruction using the constructed mask. Finally, the invention also relates to a compiler capable of automatically transforming a source code of a computer program into a binary code comprising a machine code executable by a microprocessor comprising a hardware instruction processing chain, this hardware processing chain comprising the following stages: an instruction loader, a decoder and an arithmetic and logic unit, in which the compiler is capable of automatically transforming the source code into a machine code conforming to the above machine code. Embodiments of this compiler may include the following feature: the compiler is capable of automatically inserting an instruction of unconditional branch that causes a unitary jump, in the machine code, immediately before each machine code instruction that is the destination of a branch instruction that, when executed by the arithmetic logic unit, causes a jump of several instructions. The invention will be better understood on reading the description which follows, given solely as a non-limiting example and made with reference to the drawings in which: - [fig.1] is a schematic illustration of the architecture of an electronic device capable of executing machine code; - [fig.2] is a schematic illustration of the architecture of a processing chain of the device of [fig.1]; - [fig.3] is a flowchart of a method for executing machine code using the processing chain of [fig.2]; - [fig.4] is a schematic illustration of a compiler capable of generating the machine code executed by the device of [fig.1]. CHAPTER I: Notati finiti In these figures, the same references are used to designate the same elements. In the remainder of this description, the characteristics and functions well known to those skilled in the art are not described in detail. In this description, the following definitions are adopted. A "program" refers to a set of one or more predetermined functions that one wishes to have executed by a microprocessor. A "source code" is a representation of the program in a computer language, not being directly executable by a microprocessor and being intended to be transformed, by a compiler, into machine code directly executable by the microprocessor. A program or code is said to be "directly executable" when it is capable of being executed by a microprocessor without the microprocessor first needing to compile it using a compiler or interpret it using an interpreter. An "instruction" means a machine instruction executable by a microprocessor. Such an instruction consists of: - an opcode, or operation code, encoding the nature of the operation to be executed, and -one or more operands defining the value(s) of the parameters of this operation. The "value of an instruction" is a numerical value obtained, using a bijective function, from the succession of "0" and "1" which codes, in machine language, this instruction. This bijective function can be the identity function. A "machine code" is a set of machine instructions. It is typically a file containing a succession of bits with the value "0" or "|", these bits encoding the instructions to be executed by the microprocessor. Machine code is directly executable by the microprocessor, that is to say without requiring prior compilation or interpretation. Machine code comprises a succession of instructions classified one after the other and which forms, in the machine code, an ordered sequence of instructions. Machine code begins with an initial instruction and ends with a final instruction. With respect to a given instruction I; of the machine code, the instruction L,, located on the side of the initial instruction is called the "previous instruction" and the instruction L,,, located on the side of the final instruction, is called the "next instruction". The index "i" is the order number of the instruction I, in the machine code.In this text, this machine code is divided into a succession of basic blocks immediately consecutive or separated by data blocks. A "binary code" is a file containing a succession of bits with the value "0" or "1". These bits encode data and instructions to be executed by the microprocessor. Thus, the binary code includes at least a machine code and, in addition, generally, digital data processed by this machine code. An "instruction stream" is a succession of instructions executed one after the other. In this text, a "basic block" is a group of machine code instructions that are systematically executed one after the other. A basic block begins at a branch address and ends with a single explicit or implicit branch instruction. An explicit branch instruction is characterized by the explicit presence of an opcode in the machine code that encodes the branch instruction. An implicit branch instruction corresponds to the case where the execution of a previous basic block systematically continues with the execution of a subsequent basic block located, in the machine code, immediately after the previous basic block.In this case, since in the absence of an explicit branch instruction, the machine code instructions are executed in order one after the other, it is not necessary to introduce at the end of the previous basic block an explicit branch instruction to the next basic block. In this description, we say that in this case, the previous basic block ends with an implicit branch instruction because it is not explicitly coded in the machine code. In this case, the previous basic block ends just before the branch address of the next basic block. In this application, the expression "branch instruction" designates an explicit branch instruction unless otherwise stated. Thus, the execution of a basic block systematically begins with the execution of the instruction located at its branch address and systematically ends with the execution of the branch instruction which ends this basic block. A basic block does not contain any other branch instructions than the one located at the end of this basic block. Thus, the instructions of a basic block are systematically all executed by the microprocessor one after the other in the order in which they are present in this basic block. The branch instruction can direct, when it is executed, the control flow systematically to the same branch address or, alternately, to different branch addresses. This last case is encountered, for example, when at the end of the executed basic block, the control flow can continue to a first and, alternately, to a second basic block. A "branch instruction" is an instruction which, when executed by the microprocessor, triggers a jump to the branch address of another basic block. This branch instruction therefore includes at least as a parameter the branch address of this other basic block. Typically, for this purpose, this instruction replaces the current value of the ordinal counter with the value of the branch address. Remember that the ordinal counter contains the address of the next instruction to be executed by the microprocessor. In the absence of a branch instruction, each time an instruction is executed, the ordinal counter is incremented by the size of the currently executed instruction. In the absence of a branch instruction, the instructions are systematically executed sequentially one after the other in the order in which they are recorded in a main memory, that is to say in the order of their index "i".The branch instruction can be unconditional, meaning that the jump to the branch address is systematically performed as soon as this instruction is executed. An unconditional branch instruction is, for example, the "JMP" instruction in assembler language for x86 series microprocessors. The branch instruction can also be conditional, meaning that the jump to the branch address is triggered during its execution only if a particular condition is verified. For example, a conditional branch instruction is a "JE", "JA" or "JNE" instruction in assembler. The branch instruction can also be a call to a function. In this text, the term "branch instruction" refers to both direct and indirect branch instructions.A direct branch instruction is a branch instruction that directly contains the numeric value of the branch address. An indirect branch instruction is a branch instruction to a branch address contained in a memory or register of the microprocessor. Thus, unlike a direct branch instruction, an indirect branch instruction does not directly contain the numeric value of the branch address. A "branch address" is the address in main memory where the first executed instruction of a basic block is located. In the following, we speak of a branch address even for basic blocks whose first instruction is executed following the execution of an implicit branch instruction. We speak of execution of a function to designate the execution of the instructions performing this function. CHAPTER II: Examples of embodiment [Fig. 1] represents an electronic device 1 comprising a microprocessor 2, a main memory 4 and a mass storage medium 6. For example, the device 1 is a computer, a smartphone, an electronic tablet, a smart card or the like. Microprocessor 2 here includes: - a hardware chain 10 for processing the instructions to be executed; - a set of 12 registers; - a control module 14, and - a 16 data input / output interface. The memory 4 is configured to store instructions of a binary code 30 of a program to be executed by the microprocessor 2. The memory 4 is a random access memory. Typically, the memory 4 is a volatile memory. The memory 4 may be a memory external to the microprocessor 2 as shown in [fig.1]. In this case, the memory 4 is, for example, produced on a substrate mechanically separated from the substrate on which the various elements of the microprocessor 2 are produced, such as the chain 10. In this exemplary embodiment, the binary code 30 includes in particular a machine code 32. For illustration purposes, microprocessor 2 complies with the ARM architecture (“Advanced Risk Machine”) version 7 and supports instruction sets such as Thumbl and / or Thumb2. An instruction set defines in a restrictive manner the syntax of the instructions that microprocessor 2 is capable of executing. This instruction set therefore defines in particular the set of possible opcodes for an instruction. The syntax of an instruction is incorrect if its syntax does not correspond to any of the possible syntaxes for an instruction executable by microprocessor 2. For example, if the bit range of an instruction I; which corresponds to the bit range used to encode the instruction’s opcode contains a value that is different from all possible values ​​for an opcode, then its syntax is incorrect. Chain 10 is better known as a “pipeline”. Chain 10 allows you to start executing a machine code instruction while the processing of the previous machine code instruction by chain 10 is not finished. yet completed, Such processing chains are well known and only the elements of the chain 10 necessary for understanding the invention are described in more detail. Chain 10 typically has the following stages: - an 18 instruction loader, - a 20 instruction decoder, and - an arithmetic and logic unit 22 which executes the instructions. The loader 18 loads the next instruction to be executed by the unit 22 from the memory 4. More precisely, the loader 18 loads the instruction of the machine code 32 to which an ordinal counter 26 points. Unless its value is modified by the execution of a branch instruction, the value of the ordinal counter 26 is incremented by a regular step at each cycle of a microprocessor clock. The regular step is equal to the difference between the addresses of two immediately consecutive instructions in the machine code 32. This step is subsequently called the "unit step". The decoder 20 decodes the instruction loaded by the loader 18 to obtain configuration signals which configure the microprocessor 2 to execute, at the next clock cycle, the loaded instruction. One of these configuration signals codes the nature of the operation to be executed by the unit 22. This configuration signal corresponds to the opcode of the loaded instruction. Other configuration signals indicate, for example, whether the loaded instruction is an instruction to load data from the memory 4 or to write data to the memory 4. These configuration signals are transmitted to the unit 22. Other configuration signals comprise the values ​​of the loaded operands. Depending on the instruction to be executed, these signals are transmitted to the set 12 of registers or to the unit 22. When the decoder 20 fails to decode an instruction, it generates an error signal. Typically, this occurs if the syntax of the loaded instruction is incorrect. Unit 22 executes the loaded instructions one after the other. Unit 22 is also capable of recording the result of these executed instructions in one or more of the registers of set 12. In this description, the terms "execution by microprocessor 2" and "execution by unit 10" will be used as synonyms. A given instruction I; of the machine code must successively be processed, in order, by the loader 18, the decoder 20 and the unit 22. In addition, the loader 18, the decoder 20 and the unit 22 are capable of working in parallel with each other. Thus, at a given instant, the loader 18 may be loading the next instruction L,,, the decoder 20 decoding the instruction I; and the unit 22 executing the previous instruction I,.,. The chain 10 thus makes it possible to process in parallel at least three machine code instructions 30. In addition, the chain 10 includes a hardware module 28 for unmasking the instructions loaded by the loader 18. Module 28 is capable of automatically performing the following operations: 1) in response to the decoding, by the decoder 20, of an instruction I, the module 28 constructs a mask M, 2) before starting the decoding of the next instruction [,,, the module unmasks the instruction L,,,, using a current mask M, chosen from the group composed of the constructed mask M; and a jump mask MI, before transmitting the unmasked instruction to the decoder 20. To perform operation 1) above, module 28 implements and executes a pre-programmed function Fcy(i;). To perform operation 2) above, module 28 implements and executes a pre-programmed unmasking function Fp(i*,,,, M.), where: - M, is the current mask chosen from the group composed of the constructed mask M; and the jump mask MI, and - P*,, is the masked instruction I,,,, that is to say as it appears before being unmasked by module 28. Subsequently, the notation "I*" designates the hidden instruction I and the notation "I', without the symbol "*", designates the clear instruction I, that is to say the result of the function Fp(i*; M). These functions Fcm() and Fp() are secret functions. For this purpose, there is no machine code to execute these functions in a memory located outside the microprocessor 2. Typically, they are implemented in hardware form inside the module 28. The Fey() function is a function that constructs the mask M; from the configuration signals generated by the decoder 20 during the decoding of the instruction I. Here, the mask M, is coded on the same number of bits as the instruction L. In this embodiment, the function Fp() is a function that combines each bit of the instruction I*,,, with the bits located at the same locations in the current mask M, Here, the function F() is defined by the following relation: I,,, = P,, XOR M., where the symbol "XOR" denotes the logical operation "EXCLUSIVE OR". In this embodiment, the assembly 12 comprises general registers usable for storing any type of data and dedicated registers. Unlike the general registers, the dedicated registers are dedicated to the storage of particular data generally automatically generated by the microprocessor 2. The module 14 is configured to move data between the set 12 of registers and the interface 16. The interface 16 is in particular capable of acquiring data and instructions, for example, from the memory 4 and / or the support 6 external to the mi- 2. The microprocessor 2 here comprises a bus 24 which connects the different components of the microprocessor 2 together. The medium 6 is typically a non-volatile memory. For example, it is a memory of the EEPROM or Flash type. Here, it contains a backup copy 40 of the binary code 30. Typically, it is this copy 40 which is automatically copied into the memory 4 to restore the code 30, for example, after a power outage or similar or just before the execution of the code 30 begins. Machine code 32 consists of a succession of basic blocks that must be executed one after the other. [Fig.2] shows in more detail an example of the implementation of module 28. Module 28 comprises: - a register 30 in which the mask M is recorded, constructed from the configuration signals generated by the decoder 20 at the end of the decoding of the instruction I, - a register 32 in which the MI mask is recorded, - a multiplexer 34 comprising two inputs for receiving, respectively, the mask M; and the mask MT, - a control circuit 36 ​​which selects, as a function of different signals received, the current mask M,, from among the masks M; and MJ, which will be delivered to the output of the multiplexer 34, - a logic gate 38 which executes the logic operation “EXCLUSIVE WHERE” between the current mask M, delivered on the output of the multiplexer 34 and the instruction 1,,, loaded by the loader 18, and - a logic gate 40 which performs the logical operation “NAND” between a signal S; and a signal S, and delivers the result of this logical operation to an output. The signal Sy is a Boolean signal which takes the value "1" when the operation of the decoder 20 is interrupted for several clock cycles. Such an interruption is for example necessary to wait for the result of other calculations, for example, carried out by the unit 22. This scenario occurs for example when a conditional branch instruction is executed. Indeed, in this case, it is not possible to indicate to the loader 18 what is the next instruction to be loaded as long as it is not known whether the execution of this conditional branch instruction will cause or not a jump of several instructions of the machine code 32. The Sp signal is a Boolean signal that takes the value "1" when the instruction decoding is complete and the configuration signals are ready to be used to execute this instruction. Thus, the signal at the output of gate 40 takes the value “Ô” only when the operation of the charger 18 and the decoder 20 is interrupted and that configuration signals generated by the decoder 20 are ready for use. An input 44 of the register 30 is connected to the output of the gate 40. As long as this input 44 receives a signal equal to "1", at each clock cycle, the register 30 records the value of the configuration signals generated by the decoder 20. The value recorded in the register 30 is coded on as many bits as there are bits in the mask M. Here, the value recorded in the register 30 is the value of the mask M; constructed in response to the decoding of the instruction I, by the decoder 20. Conversely, when the input 44 receives a signal equal to "0", no new value is recorded in the register 30. Thus, in the latter case, the last mask M, constructed is memorized for several clock cycles and in particular, as long as the signal S; is equal to "1". Circuit 36 ​​selects register 32 if the instruction decoded by decoder 20 is an unconditional branch instruction. Circuit 36 ​​also selects register 32 if the instruction executed by unit 22 is a conditional branch instruction which, when executed, causes a jump of several machine code instructions. For this purpose, circuit 36 ​​receives, on the one hand, a signal Say generated by decoder 20 and, on the other hand, a signal S2. generated by unit 22. The signal Sy allows circuit 36 ​​to identify the instruction which has just been decoded by decoder 20 and therefore to identify whether it is an unconditional branch instruction. For example, the signal S-, contains the Opcode of the instruction which has just been decoded. The signal S takes a particular value when the unit 22 has just executed a conditional branch instruction for which the condition is satisfied. In this case, this causes a jump of several instructions of the machine code. Conversely, this signal S,, does not take this particular value, this means that the condition of the conditional branch instruction is not satisfied. In this latter case, the next instruction executed by the microprocessor is the instruction which immediately follows this conditional branch instruction in the machine code. When circuit 36 ​​selects register 32, then it commands multiplexer 34 so that it delivers on its output the contents of register 32, that is to say the mask MI. Conversely, when circuit 36 ​​selects register 30, it is the mask M, which is delivered on the output of multiplexer 34. [Figure 3] represents a method of executing the binary code 30 by the microprocessor 2. The method begins with a step 150 of providing the binary code 30 in the memory 4. For this, for example, the microprocessor 2 copies the copy 40 inside the memory 4 to obtain the binary code 30 recorded in the memory 4. Previously, this binary code 30 was generated by the compiler of [fig.4]. When compilation, each instruction li of a plaintext machine code has been transformed into a corresponding masked instruction I*i using a masking function FM(). The FM() function is the inverse of the FD() function, i.e. it satisfies the following relation: Ii = FD(FM(Ii)). The FM() function is defined by the following relation: I*i = FM([li; Mc), where Mc is the same current mask as the one that will be used, by the module 28, during the execution of this machine code 32 to unmask the instruction I*i. More precisely, in this example, the FM() function is defined by the following relation: I*i = Ii XOR Mc. An example of the implementation of the FM() function is described in more detail with reference to [fig.4]. Then, during a phase 152, the microprocessor 2 executes the binary code 30 and, in particular, the machine code 32. To do this, for each instruction I“. pointed to by the ordinal counter 26, the chain 10 successively executes the following steps: - a step 154 ​​of loading, by the loader 18, of the instruction I; pointed to by the current value of the ordinal counter 26, then - a step 156 of unmasking, by the module 28, of the instruction I“; loaded to obtain the instruction I; in clear, then - a step 158 of decoding, by the decoder 20, of the instruction I; in clear, then - a step 160 of execution, by the unit 22, of the decoded instruction L;. Steps 154, 158 and 160 are typically each executed in one clock cycle. In addition, they can be executed in parallel for different successive instructions of the machine code 32. Thus, chain 10 can execute in parallel: - step 154 ​​for an instruction I*,,1, - step 158 for an L instruction, and - step 160 for an I instruction. Thus, chain 10 allows one instruction to be executed per clock cycle. However, as previously indicated, there are situations where it is necessary to freeze the execution of steps 154 and 158 for several clock cycles. In this case, the signal Sy is set to "1" for the duration of the clock cycles in which the execution of steps 154 and 158 is frozen. At the end of step 158 of decoding instruction L, the decoder 20 transmits the signal Sy to the circuit 36. This signal Sy makes it possible to detect whether the instruction I, which has just been decoded, is an unconditional branch instruction. Furthermore, during step 158, if an instruction I; cannot be decoded because its syntax is incorrect, the method continues with a step 170 of reporting an execution fault. During this step 170, the decoder 20 triggers the reporting of an execution fault. In response to such a signal, during a step 172, the microprocessor 2 implements one or more countermeasures. A large number of countermeasures are possible. The countermeasures implemented may have very different degrees of severity. For example, the countermeasures implemented may range from a simple display of an error message without interrupting the normal execution of the machine code 32 to a permanent shutdown of the microprocessor 2. The microprocessor 2 is considered to be out of service when it is permanently placed in a state where it is incapable of executing any machine code. Between these extreme degrees of severity, there are many other possible countermeasures such as: - indication via a human-machine interface of fault detection, - immediate interruption of the execution of the 32 machine code and / or its reinitialization, and - the deletion of the machine code 32 from the memory 4 and / or the deletion of the backup copy 40 and / or the deletion of the secret data. In step 160, if the executed instruction is a conditional branch instruction and if the execution of this instruction causes a jump of several instructions, then the unit 22 generates a signal S3, which indicates to the circuit 36 ​​that the execution of this conditional branch instruction caused a jump of several instructions. For this, typically, during the execution of the conditional branch instruction, a condition is tested. If this condition is not satisfied, the execution of this conditional branch instruction does not cause any instruction jump. In this case, the ordinal counter is simply incremented by a unit step, that is to say by a single instruction. It is therefore the following instruction I,,, of the machine code 32 which is executed. In this case, the signal S>; remains for example equal to "0". If, on the contrary, the condition of the conditional branch instruction is satisfied, the execution of this instruction by the unit 22 causes a jump of several instructions of the machine code 32. In this case, typically, a new value is written in the register containing the ordinal counter. The difference between this new value and the previous value is greater than several times the unit incrementation step of the ordinal counter. In this latter case, the signal S, takes for example the value "1". Step 156 is executed between the end of the execution of step 158 for instruction I and before the start of the execution of step 158 for the next instruction I. The next instruction I is: - either the following instruction I when the execution of instruction I; does not cause a jump of several instructions, - or another instruction of the machine code 32, different from the instruction I,,, when executing instruction I; causes a jump of several instructions. Step 156 mainly comprises an operation 164 of constructing the mask M, and an operation 162 of unmasking the next instruction I, loaded by the loader 18. Operation 164 is executed each time the decoder 20 has finished decoding an instruction and at the same time the signal S; is equal to “0”. During operation 164, the module 28 records in the register 30 the values ​​of a predetermined set of configuration signals of the decoder 20. Preferably, this set of configuration signals contains: - the signal which codes the Opcode of instruction I; which has just been decoded, and - the signals which code the values ​​of the operands of the L instruction. Here, the recording of these configuration signals is triggered, for example, at each end of a clock cycle unless the signal S; is equal to “1”. Thus, a new mask M, is constructed each time a new instruction I; is decoded by the decoder 20. This new mask M; varies depending on the decoded instruction and, in particular, depending on its opcode and the values ​​of its operands. Since the instructions decoded one after the other are generally different, the mask M, constructed is different each time the operation 164 is executed. In the case where the signal Sç is equal to “1”, no new configuration signal is recorded in the register 30 so that the register 30 stores the value of the last mask M, constructed. Operation 162 is executed each time the decoder 20 decodes a new loaded instruction I'. It is recalled here that since each instruction of the machine code 32 is masked, the loaded instructions are masked. In operation 162, circuit 36 ​​first selects, from among the masks M; and MJ, stored in registers 30 and 32, the mask which is to be used as the current mask M.. More precisely, circuit 36 ​​selects the mask MJ only in the following two cases: - case |: the signal Szy corresponds to the signal generated when the instruction I which has just been decoded by the decoder 20 is an unconditional branch instruction, and - case 2: the received signal S7 is equal to “1”, which means that the branch instruction I; which has just been executed by unit 22 has caused a jump of several instructions. Apart from the two cases above, circuit 36 ​​systematically selects mask M. Here, to select mask MJ, circuit 36 ​​controls multiplexer 34 to deliver the contents of register 32 on its output. Similarly, to select mask M, circuit 36 ​​controls multiplexer 34 to deliver, this time, the contents of register 30 on its output. Thus, the output of multiplexer 34 delivers the current mask M. Then, gate 38 executes the unmasking function Fp(I*, ; M£). Here, for this, gate 38 executes an "EXCLUSIVE OR" between the bits of the mask M, delivered on the output of the multiplexer 34 and the corresponding bits of the loaded instruction I*, delivered by the loader 18 at the same time. The result of the function Fp(), that is to say the instruction I, in clear, is delivered at the input of the decoder 20 to be decoded during the next clock cycle. Therefore, when the decoded instruction I“; is not a branch instruction, the next instruction I*, is unmasked using the mask M,, i.e. using a mask whose value depends on the value of the previous decoded instruction I,. If at that moment, the decoder 20 is subjected to a fault injection attack so that the generated configuration signals do not correspond to those expected, i.e. those corresponding to a correct decoding of the instruction L, then the module 28 constructs a mask M, which is different from the expected mask M;. This mask My is then used to unmask the next instruction I*,. Since the mask M, is different from the expected mask M;, the unmasked instruction obtained Ip, is different from the expected instruction I, in plaintext. There are then two cases: - Case 1: The Ip instruction is an instruction whose syntax is incorrect. In this case, the process continues with step 170. - Case 2: The instruction Ip,; is an instruction whose syntax is correct. In this second case, the decoding of the instruction In,1 does not cause any error and the module 28 constructs a new mask My, from the configuration signals generated in response to the decoding of this instruction In, Since the decoded instruction Ip,, is different from the expected instruction I,,, the constructed mask Mp,, is different from the expected mask M,. Therefore, the execution of the operation 162 generates an instruction Ip, different from the expected instruction I,,;. At this stage, as has just been described previously, the syntax of this instruction Ip,» can be either correct or incorrect. Therefore, it is practically certain that after a certain number of clock cycles, the instruction decoded by the decoder 20 is an instruction whose syntax is incorrect. So it is certain that after a certain number of clock cycles, an execution fault will be reported. When an instruction [ is the destination of a branch instruction, that is, it is at a branch address, there are two paths to reach this instruction I. The first path reaches the instruction I; by a jump of several instructions when an unconditional branch instruction is executed or when the condition of a conditional branch instruction is satisfied. The second path corresponds to the case where the instruction [,, is executed and then the ordinal counter is incremented by the unit step. Depending on the path taken, the instruction executed by the microprocessor just before the execution of the instruction [; is not the same. When the first path is taken, the previous instruction is a branch instruction. When the second path is taken, the previous instruction is the instruction I, Here, during compilation, before each instruction I; which is at a branch address, an unconditional branch instruction is inserted. This unconditional branch instruction causes, when executed by the microprocessor 2, a jump of one instruction, that is to say that the value of the ordinal counter is replaced by a value incremented by a unit step. Thus, in the case of the machine code 32 generated by such a compiler, the instruction I,, which precedes the instruction I; is systematically an unconditional branch instruction which causes a jump to the instruction I; when it is executed by the unit 22. Therefore, whatever path is taken to arrive at instruction I, the instruction executed just before this instruction L is a branch instruction. In the case where it is the first path that is taken, the branch instruction can be an unconditional branch instruction or a conditional branch instruction. Here, the unconditional branch instruction is detected by the circuit 36 ​​from the signal S3 generated by the decoder 20. In the case of a conditional branch instruction, the fact that its execution causes a jump of several instructions is detected from the signal S3, generated by the unit 22. It should be noted that in the latter case, after decoding the conditional branch instruction, the operation of the loader 18 and the decoder 20 is frozen.Indeed, as long as the conditional branch instruction has not been executed by the unit 22, it is not possible to know whether the condition is satisfied or not and therefore to know what will be the next instruction to be loaded by the loader 18. Thus, the operation of the loader 18 resumes only after the execution of the conditional branch instruction, that is to say at a time when the address of the next instruction I, to be executed is known. The branch instruction executed when the first path is taken is different from the branch instruction executed when the second path is taken. However, in both cases, circuit 36 ​​selects mask MJ as the current mask M, to be used to unmask instruction I. Since this mask MJ is the same for all branch instructions, instruction I”; can be correctly unmasked regardless of the path taken to arrive at this instruction. The execution of the machine code 32 may be interrupted for several clock cycles. For example, this occurs when the execution of the machine code 32 is interrupted to execute, instead, another machine code. In this case, during a step 180, the microprocessor 2 saves in the set 12 or in the memory 4, the execution context of the machine code 32. The execution context includes all the information necessary for the microprocessor 2 to be able to subsequently resume the execution of this machine code 32 at the location of the instruction where its execution stopped. Step 180 includes in particular the saving of the current value of the mask M, contained in the register 30 and of the current mask selected by the circuit 36. After several clock cycles, the execution of the machine code 32 by the microprocessor 2 is resumed from the location of the instruction where this execution had been interrupted. On this occasion, during a step 182, the execution context is restored. This step 182 includes in particular the writing, in the register 30, of the mask M; saved during the step 180. It also includes the restoration of the state of the circuit 36 ​​so that it selects the same mask M, as that which would have been selected if the execution of the machine code 32 had not been interrupted. When the interruption of the execution of the machine code 32 is caused by the need to execute another machine code, in this case, this other machine code is executed between the steps 180 and 182. The same principle of saving the mask M, and the state of the circuit 36 ​​is implemented when the interruption of the execution of the machine code 32 is caused by a hardware interrupt. [Fig. 4] represents a compiler 190 capable of automatically generating the machine code 32 from a source code 192. For this purpose, the compiler 190 typically comprises a programmable microprocessor 194 and a memory 196. The memory 196 contains the instructions and data necessary for, when executed by the microprocessor 194, automatically generating the machine code 32 from the source code 192. In particular, the compilation of the source code 192 comprises the following steps: a) the compiler performs an initial compilation of the source code 192 to obtain a plain machine code in which the instructions [; are not masked, then b) the compiler 190 identifies, in the plain machine code, the instructions which are at a branch address, then c) before each of these identified instructions, the compiler 190 automatically inserts an unconditional branch instruction which, when executed by the microprocessor 2, causes a jump to the identified instruction, then d) the compiler generates the machine code 32, that is to say a machine code in which each instruction I; is replaced by the corresponding masked instruction I*;. Step c) consists of replacing each implicit branch instruction with an explicit branch instruction. Therefore, following step c), the instruction executed before each identified instruction is systematically a branch instruction. For example, to carry out step d), the compiler scans the machine code obtained at the end of step c) in ascending order of instructions I. For each instruction I; in clear text encountered, it constructs the mask M, to be used to obtain the corresponding masked instruction I*;. The mask M, constructed by the compiler 190 is the same as that constructed by the module 28 to unmask the instruction I*; during the execution of the machine code by the microprocessor 2. For this, for example, the compiler 190 implements a software emulator which reproduces the operation of the chain 10 and, in particular, of the decoder 20 and of the module 28. For example, for each instruction L,, of the machine code in clear text: - the emulator selects, as mask M, the mask MJ if the previous instruction I; is a branch instruction, otherwise - the emulator produces the same configuration signals as those generated by the decoder 20 when it has finished decoding the previous instruction I, then it constructs the mask M; from these signals, the mask M. constructed is then taken equal to the mask M; constructed. Once the mask M, is constructed, the compiler 190 obtains the masked instruction I* 141 using the relation I*,,; = Fy(L+1; Mc), that is to say in this example using the following relation: I*,,, = L,, XOR M... CHAPTER II; Variants Device variants: Memory 4 can also be non-volatile memory. In this case, it is not necessary to copy the binary code 30 into this memory before starting its execution since it is already there. Alternatively, the memory 4 can also be an internal memory integrated inside the microprocessor 2. In the latter case, it is produced on the same substrate as the other elements of the microprocessor 2. Finally, in other configurations, the memory 4 is composed of several memories, some of which are internal memories and others external memories. Variants of masking and unmasking: In a simplified embodiment, the mask M is constructed solely from the configuration signal which codes the opcode of the instruction I; or solely from the configuration signal which varies according to the value(s) of the operand(s) of the instruction L. Other Fp() functions are possible. For example, the Fp() function is defined by the following relation: i = i*; modulo M, where “modulo” is the modular arithmetic operation which associates the remainder of the Euclidean division of a by b to the pair (a, b) of integers. The Fp() function can also be defined by the following relation: i; = i*; XOR M. XOR k,, where k, is a secret key known only to the microprocessor 2. If the computing power allows, the function Fp() can also be an encryption function, for example, symmetric. In the latter case, the mask M, is better known as the "decryption key". Each time the function Fp() is modified, the function F,,() must be adapted accordingly. The Fp() function may be different depending on whether the mask used for unmasking the next I* instruction is the MJ mask or the M mask; for example, when the M mask is selected, the "XOR" function is replaced by another function, such as a decryption function that uses the bits of the MJ mask to decrypt the I* instruction. The compiler emulator 190 must then be adapted to take this operation into account. In the case of machine code without branch instructions, the MJ mask and its use are omitted. Alternatively, only certain instructions in the machine code are masked. For example, for this purpose, a specific instruction is added to the instruction set of microprocessor 2. When this specific instruction is executed by unit 22, it indicates to the microprocessor that the next T instructions are not masked instructions and therefore should not be unmasked. Typically, the number T is an integer greater than or equal to 1 or 10 or 100. According to another variant, it is a specific bit of a status or control register of the microprocessor 2 which indicates whether or not the loaded instruction is a masked instruction. More precisely, when this specific bit takes a predetermined value, the loaded instruction is unmasked by the module 28. If this specific bit takes a value different from this predetermined value, then the loaded instruction is not unmasked by the module 28. The different embodiments described here can be combined with each other. CHAPTER IV: Advantages of the implementation described The embodiments described here make it possible to trigger the reporting of an execution fault in the event of modification of an instruction, instruction skipping or error in the decoding of the instruction. Such an execution fault is also reported if the execution of a conditional branch instruction is disturbed. Indeed, in this case, the mask M, used to unmask the next instruction I*, is not the correct one since, following the execution of the previous conditional branch instruction, the expected path was not followed. Thus, the method described also makes it possible to detect an alteration of the control flow. The embodiments described herein also have the following advantages: - module 28 is simple to implement, - the overhead in terms of machine code size is very low since only additional unconditional branch instructions are added to the code machine, - the fact that machine code instructions are unmasked only before decoding reinforces the robustness of microprocessor 2 against side-channel attacks, - the machine code instructions are not stored in clear text in the main memory, which makes it more difficult to disassemble this machine code. Using the mask M] as the current mask M, whenever the previous instruction is a branch instruction, allows the implementation of the described method even in the case where the machine code includes branch instructions. Storing the constructed mask M; in register 30 as long as the execution of the loader 18 and the decoder 20 is frozen, allows the implementation of the described method even if the operation of the loader 18 and the decoder 20 is frozen for several clock cycles. Saving the constructed mask M; in the event of interruption of the execution of the machine code, allows the execution of this machine code to be interrupted and then resumed later. The fact that the Fp{) function is a simple "EXCLUSIVE OR" gate simplifies and speeds up the implementation of unmasking.

Claims

Claims

1. Method of executing a machine code by a microprocessor comprising a hardware instruction processing chain, this hardware processing chain comprising the following stages: a instruction loader, a decoder and an arithmetic unit and logic, this process comprising, for each instruction of the code machine to carry out, successively, the following operations: - the loading (154), by the instruction loader, of the instruction designated by an ordinal counter to obtain a loaded instruction, Then - the decoding (158) of the loaded instruction, by the decoder, for generate signals that configure the microprocessor to execute the loaded instruction, then, - the execution (160), by the arithmetic and logic unit, of the instruction loaded, characterized in that the method also comprises the operations following: - after the decoding operation of a currently loaded instruction, the construction (164) of a mask from the signals generated by the decoder in response to decoding this current loaded instruction, this constructed mask thus varying according to the loaded instruction current, then - before the decoding operation of the next loaded instruction, the unmasking (162) the next loaded instruction using the constructed mask.

2. A method according to claim !, wherein: - in response to detecting that a loaded instruction is an instruction branching which, when executed by the arithmetic unit and logical, replaces the value of an ordinal counter with a new one value, this new value being a function of the operands of this ins- branch instruction, the method comprises unmasking (162) the next instruction loaded using a pre- jump mask registered constant and identical for all instructions of connections executed by the microprocessor, and - in response to the failure to detect that the loaded instruction is a branch instruction, the method comprises unmasking (162) of the next instruction loaded using the constructed mask.

3. A method according to any preceding claim, in which the process comprises: - freezes the execution of the decoding operation for one or several cycles of a microprocessor clock, and - in response to the freezing of the execution of the decoding operation, the method involves storing the constructed mask in a register, And - when the execution of the decoding operation resumes, the next loaded instruction is unmasked using the mask constructed in- registered in this register.

4. A method according to any preceding claim, in which the process comprises: - in response to the interruption of the execution of the machine code, called “first machine code”, and triggering the execution of a second machine code, the method comprises saving (180) the context execution of the first machine code, this saving of the context execution of the first machine code including the saving of the constructed mask, then - in response to the resumption of execution of the first machine code and the interruption of the execution of the second machine code, the method includes the restoration (182) of the execution context of the first code machine, this restoration of the execution context of the first code machine comprising the writing, in a register of the microprocessor, of the saved constructed mask, then - unmasking the next loaded instruction following the resumption of execution of the first machine code using the constructed mask written in this register.

5. A method according to any preceding claim, in which unmasks the loaded instruction using the mask constructed by performing an "EXCLUSIVE OR" between the bits of the loaded instruction and the bits of the constructed mask.

6. Machine code executable by a microprocessor, this machine code comprising at least one basic block comprising only ins- instructions to be executed systematically one after the other, characterized in that each instruction of this basic block, except of the first instruction, is masked using a mask constructed at from the instruction immediately preceding it in this block of base, this constructed mask being identical to the mask constructed after the decoding operation of the instruction immediately preceding it when executing this machine code according to a process conforming to any one of the preceding claims.

7. Machine code according to claim 6, wherein the first ins- instruction of the basic block is masked using the same jump mask than that used when executing this machine code according to a process according to claim 2.

8. Information recording medium, readable by a microprocessor, characterized in that it comprises a machine code conforming to one of any of claims 6 to 7.

9. Microprocessor for implementing an execution method according to any one of claims 1 to 5, this micro- processor comprising a hardware processing chain (10) instructions, this hardware processing chain comprising the following stages: an instruction loader (18), a decoder (20) and a arithmetic and logic unit (22), this hardware processing chain being able, for each instruction of the machine code to be executed, to carry out the following operations successively: - the loading, by the instruction loader, of the designated instruction by an ordinal counter to obtain a loaded instruction, then - decoding the loaded instruction, by the decoder, to generate signals that configure the microprocessor to execute the instruction loaded, then, - the execution, by the arithmetic and logic unit, of the loaded instruction, characterized in that the hardware processing chain also includes a hardware unmasking module (28) capable of carrying out the operations following: - after the decoding operation of a currently loaded instruction, the construction of a mask from the signals generated by the decoder in response to the decoding of this current loaded instruction, this constructed mask thus varying depending on the loaded instruction current, then - before the decoding operation of the next loaded instruction, the unmasking the next loaded instruction using the mask built.

10. Compiler capable of automatically transforming a source code of a computer program in binary code including machine code executable by a microprocessor comprising a hardware chain of instruction processing, this hardware processing chain comprising the following stages: an instruction loader, a decoder and an arithmetic and logic unit, characterized in that the compiler is able to automatically transform source code into code machine according to claim 6 or 7.

11. | A compiler according to claim 10, wherein the compiler is able to automatically insert an incon- branch instruction additional which causes a unit jump, in the machine code, imme- immediately before each instruction of the machine code which is the des- destination of a branch instruction which, when executed by the arithmetic and logic unit, causes a jump of several ins- instructions.