Patent Publication Number: US-9886362-B2

Title: Checking the integrity of a program executed by an electronic circuit

Description:
CROSS REFERENCE TO RELATED APPLICATIONS 
     This application claims the priority benefit of French patent application number 11/55874, filed on Jun. 30, 2011, entitled CHECKING OF THE INTEGRITY OF A PROGRAM EXECUTED BY AN ELECTRONIC CIRCUIT, which is hereby incorporated by reference to the maximum extent allowable by law. 
     BACKGROUND OF THE INVENTION 
     Technical Field 
     Embodiments generally relate to electronic circuits and, more specifically, to a checking of the integrity of programs executed by a microprocessor. 
     Discussion of the Related Art 
     Electronic circuits, and more specifically microprocessors executing programs, are capable of undergoing disturbances (introduction of viruses or fault injection attack). They are then often equipped with integrity checking mechanisms. 
     A particularly common technique comprises checking whether the executed instructions correspond to the expected instructions. A signature of the program instructions is calculated on design of the program or on recording thereof in a generally non-volatile memory associated with the processing unit. Then, during the execution of the program, a current signature is calculated and compared with the pre-recorded reference signature. 
     Such techniques work well with programs having a set development, but raise issues as soon as the program comprises conditional jumps or variable numbers of iterations of the same calculation. Indeed, it is then particularly complicated to calculate the signature without knowing at the design stage what jumps or how many iterations will be performed. 
     A solution is not to take into account, in the signature calculation, possible sections (instruction, groups of instructions, sub-programs, etc.) linked to conditional jumps or to the iterations. However, the integrity of such sections is then not checked. In cryptographic applications where calculations are often performed by successive iterations and/or where the type of operation often depends on the state of a bit linked to the current iteration, this makes calculations vulnerable to possible fault-injection attacks. 
     SUMMARY 
     An embodiment provides a mechanism for checking the integrity of a program which overcomes all or part of the disadvantages of usual solutions. 
     An embodiment provides an integrity check mechanism compatible with the checking of instructions in conditional jumps and in iterations. 
     An embodiment provides a method for checking the integrity of a program executed by an electronic circuit and comprising at least one conditional jump, wherein: 
     a first value is updated for any instruction which does not correspond to a jump instruction; 
     a second value is updated with the first value for each conditional jump instruction; and 
     the second value is compared with a third value, calculated according to the performed conditional jumps. 
     According to an embodiment, the third value is calculated during the execution of the program from pre-calculated reference values, at least one reference value being assigned to a section called by a conditional jump. 
     According to an embodiment, for each new executed instruction, it is determined whether the instruction is a conditional jump instruction, to update the first value or increment the second value according to cases. 
     According to an embodiment, none of the first and second values is modified in case of an unconditional jump instruction. 
     According to an embodiment, the updating of the first value is performed by a function cumulating the values of the instruction bits. 
     According to an embodiment, the updating of the first value is performed by a CRC calculation function. 
     According to an embodiment, the first value is reset after each increment of the second value. 
     According to an embodiment, the third value is calculated during the development of the program. 
     According to an embodiment, the third value is calculated at the end of the program execution, at least one counter of the number of conditional jumps being updated during the program execution. 
     Another embodiment provides an electronic circuit comprising a circuit for implementing the integrity check method. 
     The foregoing and other objects, features, and advantages will be discussed in detail in the following non-limiting description of specific embodiments in connection with the accompanying drawings. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         FIG. 1  is a partial block diagram of an example of an electronic system of the type to which the described embodiments apply; 
         FIG. 2  is a block diagram illustrating a detail of the circuit of  FIG. 1 ; 
         FIG. 3  illustrates, in the form of blocks, an embodiment of the integrity check mechanism; and 
         FIG. 4  is an example of application of the mechanism of  FIG. 3 . 
     
    
    
     DETAILED DESCRIPTION 
     The same elements have been designated with the same reference numerals in the different drawings. 
     For clarity, only those elements which are useful to the understanding of the described embodiments have been shown and will be detailed. In particular, the functions implemented by the checked programs have not been detailed, embodiments being compatible with usual programs. Further, the use that is made of the result of the integrity check mechanism has not been detailed either, the embodiments being here again compatible with usual uses of integrity check results. 
       FIG. 1  is a partial block diagram of an electronic circuit equipped with an embodiment of an integrity check mechanism. 
     This circuit comprises a processing unit  1  (PU) in charge of executing instructions I of a program. In applications more specifically targeted by the described embodiments, these instructions originate from a non-volatile memory and are capable of undergoing modifications (intentional or incidental) between their extraction from the memory and the execution by the central processing unit. These instructions may also originate from a non-volatile memory through which they transit, from another circuit than that integrating unit  1 , etc., the described embodiments checking the integrity by intercepting the instructions at the time of their loading for execution in the processing unit. 
     To verify that these instructions have not been modified, the circuit of  FIG. 1  comprises a circuit  2 , preferably dedicated, for checking the integrity of the executed instructions (SIGN COMP). This mechanism is a checking of a signature of the instructions. A calculation is performed based on the instructions loaded into the processing unit and the result of this calculation is compared with a value calculated on loading of the program into the non-volatile memory. 
     Circuit  2  provides a result (OK/NOK), for example to the processing unit, which takes the appropriate measures according to this result. Most often, the signature checking is performed at the end of the program or at given steps thereof, and enables to interrupt the execution or to validate/invalidate the provided result. 
       FIG. 2  is a more detailed representation, in the form of blocks, of an embodiment of circuit  2 . This circuit comprises two storage elements  21  (LC) and  22  (GC) intended to contain first and second current values or signatures. Such storage elements are, for example, registers formed with volatile memory elements. Circuit  2  also comprises an element  23  (INST TYPE?) for detecting the type of received instruction I (being executed by the processing unit). The distinguished instruction types are conditional jump instructions (CBI), unconditional jump instructions (UBI), and other instructions (OI). A loop calculation (iterations) corresponds to a conditional jump if the number of iterations is not fixed. 
     According to the instruction type, circuit  2  updates one or the other or none of current values LC or GC. For any instruction which does not correspond to a conditional jump instruction, current signature LC is updated. For any instruction corresponding to a conditional jump, current signature GC is updated. Possibly, in the presence of an instruction corresponding to an unconditional jump, none of the current signatures is updated. Once the possible update of a current signature has been performed, it is proceeded to the next instruction. In one embodiment with a dedicated circuit  2 , said circuit comprises two cells  24  (LC UPD) and  25  (GC UPD) for updating values LC and GC. 
       FIG. 3  is a simplified flowchart of an embodiment of the mechanism of integrity checking by means of circuit  2 . 
     A first step (block  31 , INT) comprises initializing current signatures LC and GC which are, for example, set to a zero value. 
     Then, the first instruction is loaded and it is determined (block  32 , OI?) whether this instruction is an instruction other than a jump instruction. If it is (output Y of block  32 ), signature LC is updated (block  33 , LC=f(LC, I)) by application of a function f to the previous value contained in storage element  21  and to the value of instruction I. Function f for example is a function cumulating the bits of the instruction to the previous total (CHECKSUM). According to another example providing a better diffusion of the signature, function f is a CRC-type (Cyclic Redundancy Check) function. 
     Once value LC has been updated, it is proceeded to the next instruction (block  34 , NEXT I). 
     If the instruction is a jump instruction (output N of block  32 ), it is determined (block  35 , CBI?) whether it is a conditional jump instruction. 
     If it is (output Y of block  35 ), second value GC is updated by being added value LC and value LC is reset (block  36 , GC=GC+LC; LC=0). It is proceeded to the next instruction (block  34 ). The operation is for example performed modulo the register cardinality (modulo 2 n  where n stands for the number of bits of register  22 ). As a variation, the addition is an XOR-type operation, that is, a bit-to-bit addition. 
     If the jump instruction is an unconditional jump instruction (output N of block  35 ), it is directly proceeded to the next instruction (block  34 ) without updating the signatures. 
     The fact of not updating the signature in case of an unconditional jump (UBI) makes it easier for the programmer to implement the method. However, it may also be provided to consider an unconditional jump instruction as any other instruction and then update value LC. 
     When the last instruction has been processed, the current signature calculation loop is ended (END) and the value contained by storage element  22  (GC) contains the value to be checked against a reference value or signature. 
     To perform this checking, the reference signature should take into account the number of conditional jumps performed, as will now be described in relation with a simplified example. 
       FIG. 4  is a simplified example of program  4  capable of being checked by the described mechanism. Program  4  comprises several sections A, B, C, D, and E, for example, written one after the other, and starts in section A. 
     It is assumed that: 
     section A is a systematically executed unconditional section; 
     sections B and C are conditional sections executed according to the result of a conditional jump instruction (COND(k) JUMP TO C) on the value (for example, 0 or 1) taken by a variable k, at the end of section A (k=0/1), instruction COND JUMP for example being an instruction of the type “if . . . then . . . else” performing either a jump to section C, or a carrying on of the execution which corresponds to section B; 
     section D is an unconditional section executed either after section B by an unconditional jump (UNCOND JUMP TO D) or at the end of section C by carrying on the execution; and 
     section E is a loop (LOOP(N)) of N iterations, value N being determined in section D (SELECT N). If N is 0, the loop is skipped and the program directly passes to the next instruction (in the example, the end instruction). 
     In the present example, four reference signatures RC(A), RC(BD), RC(CD), and RC(E) are calculated on installation or loading of the program into the non-volatile memory of the electronic circuit. Such signatures correspond to the value provided by application of function f to the instructions of the sections (for example, A and E) or groups of sections (for example, B and D, and C and D) executed unconditionally. Unconditional jump instruction UNCOND JUMP TO D may be comprised in section B. 
     An advantage of calculating signatures RC(BD) and RC(CD) rather than calculating three signatures RC(B), RC(C), and RC(D), and then cumulating them is that this decreases the number of signatures to be stored. Further, this improves the security by verifying in a row the execution of sections B and D, or C and D. If the program carries on unconditionally after section E, the signature of the corresponding instructions is calculated with that of section A. It can thus be seen that the reference signatures may overlap and share same sections. 
     The four pre-calculated values are used by the integrity check mechanism for, according to the program execution, calculating a current value GC to be compared with reference signature RC. For example, a check instruction CHECK corresponds to the last instruction. 
     According to an embodiment, signature RC is calculated at the same time as the current signature. It is initialized at step  31  ( FIG. 3 ) with value RC(A). Then, according to the result of the conditional jump instruction (taking the example of a signature GC based on an increment modulo 2 n ), value RC(BD) or RC(CD) is added (block  38  in dotted lines) according to the called section C or D. Then, according to value N, a multiple of signature RC(E) is added to the previous sum. 
     On the current signature calculation side (block  36 ), it is not necessary to distinguish the sections. If the execution is correct (unaltered program), value LC contains, at the time of the next update of value GC, value RC(BD) or RC(CD) according to the section which has executed. 
     According to another embodiment, as many counters as there are section signatures are set to zero and are incremented by one each time the corresponding section is called. Then, at the end of the execution (END), reference signature RC is calculated by adding to value RC(A) the respective products of the signatures by the corresponding numbers of executions. 
     In the example of  FIG. 4 , this amounts to calculating the following relation:
 
 RC=RC ( A )+ k*RC ( BD )+(1− k )* RC ( CD )+ N*RC ( E ).
 
     Whatever the way in which it is obtained, reference signature RC is compared with the present signature. 
     The number of reference signatures depends on the number of different sections capable of being called in conditional jumps. In the embodiment where the reference signature is not progressively calculated, the number of counters of the numbers of executions increases correspondingly (unless several sections have the same signature). 
     The signature control may occur at the end of the program or at certain steps, provided for it not to be in the middle of a section. 
     An advantage of the described verification mechanism is that it enables to take into account the presence of conditional jumps in a program without adversely affecting its security. 
     Various embodiments have been described, various alterations and modifications will occur to those skilled in the art. In particular, the selection of function f depends on the application and, for example, on the calculation cells that can easily be formed. More complex signatures may for example be used, provided for the resources of the electronic circuit and for the execution time to enable it. The size of registers  21  and  22  depends on the sizes capable of being taken by values LC and GC. Value GC is incremented modulo 2 n , where n stands for the number of bits of register  22 . Value RC is calculated on a same number of bits as value GC. 
     Finally, the practical implementation of embodiments is within the abilities of those skilled in the art based on the functional indications given hereabove. 
     Such alterations, modifications, and improvements are intended to be part of this disclosure, and are intended to be within the spirit and the scope of the present invention. Accordingly, the foregoing description is by way of example only and is not intended to be limiting. The present invention is limited only as defined in the following claims and the equivalents thereto.