Masking for the execution of code containing Boolean and arithmetic operations
Low-entropy masking using {0, 2^n-1} masks and XOR operations efficiently transitions between Boolean and arithmetic masking, addressing inefficiencies and vulnerabilities in existing methods, ensuring secure and fast execution of cryptographic codes.
Patent Information
- Authority / Receiving Office
- FR · FR
- Patent Type
- Applications
- Current Assignee / Owner
- COMMISSARIAT A LENERGIE ATOMIQUE ET AUX ENERGIES ALTERNATIVES
- Filing Date
- 2024-12-17
- Publication Date
- 2026-06-19
AI Technical Summary
Existing methods for executing codes containing both Boolean and arithmetic operations in cryptographic applications are inefficient and resource-intensive, particularly in converting between masking types, leading to increased execution time and security vulnerabilities against side-channel attacks.
A method involving low-entropy masking using masks chosen from the set {0, 2^n-1} and bitwise XOR operations to transition between Boolean and arithmetic masking, reducing the number of operations required and maintaining security by ensuring average leakage is independent of secret values.
The method achieves fast and resource-efficient execution of codes with reduced additional cost in execution time while maintaining a high level of security against side-channel attacks.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Title of the invention: Masking for the execution of code containing Boolean and arithmetic operations. Technical context
[0001] The invention falls within the field of cryptography, and is of particular interest in the context of protection against side-channel attacks.
[0002] Side-channel attacks exploit the measurement of a physical quantity, such as the power consumption or electromagnetic emissions of a processor, in order to deduce all or part of the instructions or data manipulated by it. This type of attack is particularly effective for discovering encryption keys used by an entity.
[0003] A widely studied and used countermeasure against this type of attack is masking. A mask is applied to any data that must be kept secret; this data is called the secret and can typically be a key. The secret takes, for example, the form of a long word in binary—an integer written in base 2.
[0004] The masking technique consists of separating or decomposing a secret, such as a key, into several parts commonly called shares. The definition of the shares from the secret is carried out in such a way that simultaneous knowledge of all the shares is necessary to reconstruct the secret. The different shares are stored in separate variables in the program and the computer hardware. Furthermore, calculations dependent on the secret are performed by manipulating the shares, without recombining them, so as not to reveal the secret, even to an attacker observing the processor during the calculation via a side-channel attack.
[0005] We are particularly interested in first-order masking, whereby each secret data is decomposed into two shares.
[0006] We know of so-called boolean masking and so-called arithmetic masking.
[0007] Boolean masking uses an integer called a mask and the XOR logical exclusive OR operator to decompose the secret into shares. If the secret is denoted s, and if a mask r is chosen, typically by random generation, and if the symbol ® denotes the bitwise XOR exclusive OR operator, the secret is decomposed into two shares sO and si. These two shares are defined by sO = s®r and si = r. They efficiently encode the secret s since knowing sO alone does not allow us to deduce s, and knowing si alone also does not allow us to deduce s. The latter can nevertheless be reconstructed by the operation sO® sl=s, which is possible at the legitimate entity, but not the attacker, except for the latter to mount a higher-order attack with greater complexity.
[0008] Arithmetic masking, on the other hand, uses modular addition to decompose a secret into shares. This technique also uses a random number r that constitutes the mask. It uses the congruence relation in the domain of integers. Here, we are interested in a congruence relation modulo a positive integer power of 2, denoted n and chosen in a fixed manner; this congruence is therefore denoted [2n]. The two generated shares are defined as $0 - s4 - r [2n] and si = r. This results in the following congruence for reconstructing the secret when the two shares are known: $0 - si = S [2n]-
[0009] Boolean masking is preferred for securing cryptographic applications mainly involving Boolean operations, while arithmetic masking is used for cryptographic applications involving arithmetic operations.
[0010] When a code contains a mixture of Boolean and arithmetic operations, the two types of masking must be used sequentially, performing a conversion when changing masking types. This conversion must adhere to the same security condition as each masking method: the secret must not be deducible from any intermediate variable used during the conversion. This constraint impacts the performance of the conversion processes.
[0011] Low-entropy masking is also known, the principle of which is to restrict the choice of random numbers used for the decomposition of the secret into shares in order to improve performance. This technique is described in the article Nassar, M., Guilley, S., Danger, JL. (2011). Formai Analysis of the Entropy / Security Trade-off in First-Order Masking Countermeasures against Side-Channel Attacks. In: Bernstein, DJ, Chatterjee, S. (eds) Progress in Cryptology - INDOCRYPT 2011. INDOCRYPT 2011. Lecture Notes in Computer Science, vol 7107. Springer, Berlin, Heidelberg.
[0012] On the other hand, schemes for converting from Boolean masking to arithmetic masking or from arithmetic masking to Boolean masking are known, as well as associated approaches which allow an arithmetic addition to be performed on information masked in a Boolean manner without going through a double conversion, from Boolean masking to arithmetic masking and vice versa.
[0013] For example, the document Efficient Side-Channel Protections of ARX Ciphers. (2018). IACR Transactions on Cryptography Hardware and Embedded Systems, 2018(3), 627-653. presents a method for performing arithmetic addition on variables masked using Boolean masking, by decomposing the addition into A series of Boolean operations. This is an example of an iterative algorithm that allows for arithmetic operations on variables masked using Boolean masking. The number of instructions required is high, making the method computationally expensive, which is a drawback.
[0014] Methods for accelerating the conversion from arithmetic to boolean masking via the use of tables, in which the results of certain calculations are tabulated, are also known from Van Beirendonck, Michiel, Jan-Pieter D'Anvers, and Ingrid Verbauwhede. "Analysis and comparison of table-based arithmetic to boolean masking." IACR Transactions on Cryptography Hardware and Embedded Systems (2021): 275-297. The algorithm using these tables is faster than a classical iterative algorithm. However, it is resource-intensive and inefficient in terms of execution time due to the precomputation of the tables and the conversion itself.
[0015] Furthermore, document US11822704B2 discloses a method for converting Boolean masking into arithmetic masking,
[0016] And we know from document US7334133B23 a method of implementing a cryptographic algorithm using boolean operations and arithmetic operations.
[0017] It can also be reasonably estimated that during a side-channel attack, the different bits of an intermediate variable leak independently of each other: the leakage observed by an attacker can be written in the form + °where the are the bits of a variable, and where the h are functions any. This corresponds quite well to what is observed, for example, for leaks due to consumption or electromagnetic emissions from circuits. Characteristics of the invention and advantages
[0018] We therefore wish to allow the masked execution of codes containing boolean and arithmetic operations while limiting the additional cost in execution time, and maintaining a good level of security against side-channel attacks.
[0019] For this purpose, a method of processing a protected secret by a processor is proposed, comprising a step of choosing and setting up on the secret protected by an initial mask a low-entropy masking, then the implementation on the secret maintained under the protection of said low-entropy masking of an operation including a removal of the initial mask.
[0020] Remarkably, since an encoding is on n bits, low-entropy masking uses a mask chosen from the set {0 ; 2”-1}, and applied by a bitwise exclusive or operator.
[0021] The implementation of the operation can thus be adapted, for example, using code such as that presented in the detailed embodiments detailed for illustrative purposes below, to the low-entropy mask chosen by taking advantage of an n-bit integer encoding, where n is a positive integer. In this context, the number 2′ - 1 has all its bits set to 1. The invention relies on the following modulo 2′ congruence which follows from this observation: xX0R(2n-l) = -x - 1.
[0022] It is then possible to have an average leak independent of the secret values, while achieving very fast and resource-efficient realizations.
[0023] According to optional and advantageous features:
[0024] - the operation may include an arithmetic operation combining the secret and a other data.
[0025] - the operation may include a logical operation combining the secret and another data.
[0026] - the operation may include the application of a destination mask distinct from the mask originally worn by the secret.
[0027] - the operation may include the placement of a mask over the secret arithmetic whereas the mask initially worn was a boolean mask.
[0028] - the operation may include applying a Boolean mask to the secret whereas the mask initially worn was an arithmetic mask.
[0029] - the operation may include applying the same low-entropy mask to a second secret piece of data to which the secret is then combined during the operation.
[0030] - the operation may include a corrective arithmetic operation depending on the low-entropy mask chosen and carried out during the removal of the initial mask or during the application of an arithmetic mask or during an arithmetic operation combining the secret with a second secret data.
[0031] - the operation may include, in certain specific variants, the installation of a destination mask and the processing method may also include a step of random selection of the destination mask from a set of possible masks having a higher entropy than said low-entropy masking, the operation being followed by a removal of the low-entropy mask.
[0032] - the protected secret can be initially protected by a first-order masking.
[0033] The invention, in one embodiment, relies on the use of Boolean masking where the choice of masks is restricted to the two numbers 0 and 2. This is a low-entropy masking method since the number of possible masks is reduced. This particular Boolean masking method then serves, for example, as a bridge between a Boolean masking method, which can be a classic Boolean masking method, and an arithmetic masking method.
[0034] The invention thus consists, according to one embodiment, of a procedure for switching from arithmetic masking to Boolean masking. Other embodiments are nevertheless presented.
[0035] Thus the invention also proposes, among other variants, a variant in which an arithmetic addition is performed between two data masked in a boolean manner, without having switched to arithmetic masking. List of figures
[0036] Figures 1 to 5 each present an embodiment of the invention. Description related to the figures
[0037] All additions and subtractions in the text are understood modulo 2n, where n is any integer chosen according to the architecture and the application to be masked.
[0038] The symbol © denotes, as already mentioned, the logical or exclusive operator (XOR). The symbol & denotes the Boolean AND operator.
[0039] A Boolean masking where the masks are chosen randomly from the two-element set {0, 2n-l} makes the average of a leak obtained by side-channel attack independent of the masked secret.
[0040] The average leakage m is calculated by adding half the leakage in the case where the mask is 0, and half in the case where the mask is 2n-1 m = ((f| / bo)+:^)+ ... + f„-l(b„-1)) + + ... + fn-l(bll4© 1))) / 2
[0041] Or again m = = (f( / b0)+ f0(b0© 1) + f / hj-r f^©!^ ... + fn_](bn-1) + ^-1(^.^1)) / 2
[0042] Now for any bit b, b=0 implies b® 1=1, and b=l implies b® 1=0, therefore f(b)+f(b® 1) = f(0)+f(l) whatever the value of b.
[0043] Hence, whatever the choice of bobi.. .bn i, we obtain: m = (f0(0)+ f0(l) + f ,(0) + £ / 1)+ ... + 1,.,(0) + 1,.,(1)) / 2
[0044] It follows that the average leakage is constant, that is to say independent of the value b0bl...bn-l.
[0045] [Fig.1] In [Fig.1], a first embodiment has been shown.
[0046] aO and al are two shares encoding a secret s in arithmetic masking. We therefore have aO - al = s [2n].
[0047] To move from arithmetic masking to destination Boolean masking, the following steps are then carried out:
[0048] During a step E0, we choose between the two n-bit strings 0 and 2n- 1- H it is advantageous that this choice be totally random.
[0049] The string thus chosen according to a low-entropy selection will serve as an intermediate Boolean mask, and is written in extenso in an n-bit variable rwide, the n bits then all being 0 or all 1, rwide = rand{0, 2n - 1} and also in a condensed form in a single bit variable rbit, which is 0 in the first case, and 1 in the second case (the generation of this boolean value is carried out by the use of an AND operator symbolized by &). rbit = rwide & 1
[0050] The wide notation refers to writing in extenso on n bits.
[0051] Other methods of generating rwide and rbit are possible.
[0052] In parallel, in a step El, the destination boolean mask is generated, among a large number of possible masks, in this case 2n possible values. bO = rand[0, 2n[
[0053] This secret is a string of n bits, all strings being advantageously equiprobable in the generation of this secret, and the result of the random draw being stored in a variable bO, which is intended to be used as such as one of the two shares of the final boolean masking.
[0054] It is specified here that, like the generation of the secret bO, carried out during the El step, this can in a variant be carried out before the E0 step.
[0055] In a step E2, the intermediate Boolean mask (with low entropy) is applied to the share aO. This implies, since the intermediate mask is special but nevertheless of Boolean type, the implementation of the XOR operator. The result is stored in a variable d. d = aO ® rwide
[0056] Then an EOP operation is performed on the masked secret s, comprising removing the arithmetic masking and applying the destination mask. The EOP operation is adapted taking into account rwide.
[0057] The intermediate mask is implemented on the share al, during a step E3-1. The result is placed in a variable e. e = al ® rwide
[0058] The two operations, E2 for the share aO and E3-1 for the share al, are independent of each other - and therefore can be implemented in a given order or the reverse order.
[0059] Then, once these masked values are obtained, in step E3-2, they are used to remove the arithmetic mask from the share aO, using the share al, which is its function by construction. This implies, since it is an arithmetic mask, the realization of a difference modulo 2n. The operation is performed on the variables d and e, which are heirs of aO and al. However, given the presence of the intermediate Boolean mask on these two shares, the result of the subtraction is corrected by deducting the value of rbit from its result. The result is stored in an intermediate variable f. f = d - e - rbit
[0060] The procedure can then be interrupted, the secret remaining protected by low-entropy masking and being subjected to various operations.
[0061] The procedure can conversely be continued, or resumed after various operations, in the following manner.
[0062] In step E8, the destination boolean mask is added to the content of the intermediate variable f by performing the XOR operation between the content of f and the secret b0. The resulting string is stored in an intermediate variable g. g = f© b0
[0063] It is specified here that since the secret bO, generated during step El, is not used before the implementation of step E8, step El can in different variants be carried out after step E2 and even just before step E8.
[0064] We resume the sequence of [Fig. 1]: the EOP operation is complete (it has been adapted taking into account the value of rwide at steps E3-1 and E3-2) and only after the execution of step E8, in step E9, is the intermediate Boolean mask removed from the result stored in the variable g, by performing the XOR operation between the content of g and the share rwide, and the result is written to a variable bl, which is the second share of the final Boolean mask, bl = g ® rwide
[0065] The strings bO and bl then correctly encode the secret s, in boolean masking.
[0066] The variable rbit makes it possible to ensure that the final result does not depend on the choice of rwide, by compensating for the appearance of certain constants when rwide is 2” - 1, without the sequence of operations performed depending on the choice of rwide.
[0067] [Fig.2] In [Fig.2], a second embodiment is shown. It relates to the transition from a Boolean masking to an arithmetic masking.
[0068] bO and bl are two shares encoding a secret s using Boolean masking: bO ® bl = s. The procedure is as follows:
[0069] During a step F0, similar to step E0 of the embodiment of [Fig.1], we choose from the two n-bit strings 0 and 2n-1- The string thus chosen according to a low-entropy choice is intended to serve as an intermediate boolean mask, and is written in extenso in an n-bit variable rwide, the n bits then all being 0 or all 1. rwide = rand{0, 2n - 1}
[0070] The low-entropy mask is also written in a condensed form in a single-bit variable rbit, which is 0 in the first case and 1 in the second case. rbit = rwide & 1
[0071] Then, during a step Fl, the destination arithmetic mask is generated from among a large number of possible masks. This secret is a string of n bits, all the possible chains - there are 2n of them, being advantageously equiprobable in the generation of this secret, and the result of the random draw being stored in a variable rarith, which is intended to be used as such as one of the two shares of the final arithmetic masking. rarith = rand[0, 2n[
[0072] This generation during step Fl is similar to the generation during step El of the embodiment of [Fig.l], but the produced string is intended to serve as an arithmetic mask and not a boolean one.
[0073] It is specified here that since the generation of the secret rarith, carried out during the Fl step, does not require knowledge of the intermediate boolean mask, the Fl step can in a variant be carried out before the FO step.
[0074] During step F2, the intermediate mask is set on the share bO. The result is stored in a variable c. It is obtained by performing the XOR operator between the string bO and the secret rwide. c = bO ® rwide
[0075] Then a FOP operation is performed on the secret, including the removal of the initial mask and the application of the destination mask. The FOP operation is adapted taking into account rwide.
[0076] During step F3, the initial Boolean mask is removed from the result c, the heir of bO, using the share bl. The result is stored in an intermediate variable d. It is obtained by performing the XOR operator between the string c and the share bl. d = c ® bl
[0077] In a step F8, the arithmetic mask generated in step F1 is adapted to the fact that it is to be applied to a string that has undergone a particular Boolean masking, and the adapted arithmetic mask is stored in a variable e. To do this, the XOR operator is applied to the secret rarith and the secret rwide, adding the value 0 or 1 contained in rbit. e = (rarith ® rwide) + rbit
[0078] Then the adapted arithmetic mask is applied to the intermediate variable d, and the result is stored in an intermediate variable f. It is obtained by the modular addition of the contents of the variables d and e. f = d + e
[0079] It is specified here that since the secret rarith, generated during step Fl, is not used before the implementation of step F8, step Fl can in different variants be carried out after step F2 and even just before step F8.
[0080] The FOP operation is complete (it has been adapted taking into account the value of rwide at the stage of step F8). We resume the process shown in [Fig. 2]: only after the execution of step F8, during a step F9, is the low-entropy Boolean mask removed from the content of the variable f. The result is stored in the variable aO. To do this, the XOR operator is applied to the content of the variable f and to the mask rwide. aO = f ® rwide
[0081] The shares aO and rarith, which are renamed al, then encode the secret, in arithmetic masking.
[0082] [Fig.3] In [Fig.3], a third embodiment has been shown.
[0083] Two secrets i and j are masked by Boolean masking. The respective Boolean masking encodings of i and j of order 1 are denoted {i0,il} and {j0,jl}. Thus, i0 and il are the shares of i and j0 and jl are the shares of j.
[0084] An arithmetic addition is performed between secrets i and j without converting their masking into an arithmetic mask, and this is done via the following procedure:
[0085] During a step G0, similar to step E0 of the embodiment of [Fig. 1], and also to step F0 of the embodiment of [Fig. 2], a string of n bits, 0 and 2n, is chosen from among two strings of n bits. The string thus chosen according to a low-entropy selection is intended to serve as an intermediate Boolean mask, and is written in full into an n-bit variable rwide, the n bits then all being either 0 or all 1, rwide = rand{0, 2n - 1}
[0086] and also condensed into a single-bit variable rbit, which is 0 in the first case, and 1 in the second case. rbit = rwide & 1
[0087] In parallel, during a step Gl, an n-bit Boolean mask is chosen from 2n possible values (this is a high-entropy mask). It is stored in the n-bit variable rbool. The process is similar to that of step El of the embodiment of [Fig. 1]. rbool = rand[0, 2n[
[0088] During a G2i step, the intermediate Boolean mask is applied to the share iO. The result is stored in the intermediate variable a. a = iO ® rwide
[0089] Then a GOP operation is performed on secret i, comprising removing the arithmetic mask, an arithmetic addition with j, and setting up the destination mask. The GOP operation is adapted taking into account rwide.
[0090] Thus, during a step G3i, the initial Boolean mask that had been used for i is removed from the intermediate variable a. For this removal of the Boolean mask Initially, it is the share and the XOR operator that are used - the result is stored in an intermediate variable b. b = a ® il
[0091] In parallel, the same treatment is applied to the share jO, during steps G2j and G3j. The intermediate variables are called c and d. And notably, the intermediate mask used is the same as that which was used for i, namely rwide. c = jO ® rwide
[0092] And once this mask has been applied, the initial boolean mask is removed, by applying dejl. d = c ® jl
[0093] Then, in a step G4, the values obtained b and d are added together, correcting the sum using the condensed value rbit of the intermediate mask. This involves combining i and j for the purpose of addition, but under the rwide mask. Furthermore, the addition is corrected to account for the presence of the mask. This entails completing the modular addition of b and d by adding the value of rbit to the sum. The result is stored in a variable e. e = b + d + rbit
[0094] Remarkably, this addition, that is to say an arithmetic operation, is carried out even though the secrets are masked, but without an arithmetic masking being used: the masking is in fact boolean.
[0095] The procedure can then be interrupted, the secret (the result of the addition) remaining protected by low-entropy masking and subjected to various operations.
[0096] The procedure can conversely be continued, or resumed after various operations, in the following manner.
[0097] During a step G8, the final Boolean mask is applied to the content of the intermediate variable e. f = e ® rbool
[0098] The result is stored in an intermediate variable f.
[0099] The GOP operation is then completed (it has been adapted taking into account the value of rwide at the stage of step G2-j and step G4)
[0100] During a step G9, the low-entropy Boolean mask, now unnecessary, is removed from the contents of the variable f to terminate the process, and free the share resO, which is a share of the result of adding i and j. resO = f ® rwide
[0101] This is the secret rbool, renamed resl, which is the second share of the result of adding i and j. res 1 = rbool
[0102] The shares resO and resl then correctly encode the sum i+j, in boolean masking, namely the same type of masking as initially used before an arithmetic operation is requested.
[0103] [Fig.4] In [Fig.4], an embodiment is shown in which an addition (a particular arithmetic operation) is performed between two secrets, one masked by boolean masking and the other by arithmetic masking.
[0104] i and j are the two secrets that we wish to add.
[0105] It is i that has been arithmetic masked. iaO and ial are the shares encoding i. We therefore have the congruence i = iaO-ial [2n]
[0106] ja has been subjected to a boolean masking of order 1. jO and j 1 are the shares coding j.
[0107] The addition procedure is as follows:
[0108] During a step H0, we choose between two n-bit strings 0 and 2n - 1-. The string thus chosen according to a low-entropy selection is intended to serve as an intermediate Boolean mask, and is written in full into an n-bit variable rwide, the n bits then all being either 0 or all 1: rwide = rand{0, 2n - 1}
[0109] This is a step similar to steps E0, F0 and G0 of the previous embodiments. However, a boolean variable rbit is not used, as it is unnecessary.
[0110] During a step H1, a destination mask of type Boolean and of n bits is chosen from 2n possible values (it is a Boolean mask with high entropy). It is stored in the n-bit variable rbool. This is a step similar to steps E1 and G1 of the embodiments of Figures 1 and 3. rbool = rand[0, 2n[
[0111] Then the intermediate mask is applied to the secret j. During a step H2j, the low-entropy Boolean mask is applied to a share of j. More precisely, the low-entropy Boolean mask is applied to the share j0. The result is stored in the intermediate variable c. c = jO ® rwide
[0112] Then a HOP operation is performed on secret j, comprising removing the initial mask, adding it to secret i, and setting the destination mask. The HOP operation is adapted taking into account rwide.
[0113] Thus, during a step H2i-0, the intermediate Boolean mask is applied to a first share of i. More precisely, the low-entropy Boolean mask is applied to the share iaO. The result is stored in the intermediate variable iawO. iawO = iaO ® rwide
[0114] In parallel, the low-entropy mask is applied to the second share of i ial, during a step H2i-1. The result is stored in an intermediate variable iawl. iawl = ial ® rwide
[0115] In parallel, during a step H3j, the secret j being protected by the intermediate mask, the initial boolean mask is removed, using the share jl whose function is to do so. The result is stored in an intermediate variable d. d = c ® jl
[0116] The arithmetic mask of ia is maintained at this stage: iaO and ial are not combined.
[0117] Then, during a step H4, the intermediate mask having been applied to the two terms to be added (i and j), and the arithmetic mask having been retained on the term that carried it (namely i), the desired arithmetic operation is performed, in this case a modular addition. Since the operation is performed only with one of the shares of i, namely iaO (in the form iawO), the addition is called a partial addition of i and j. The result is stored in an intermediate variable f. f = d + iawO
[0118] During a step H3i, the arithmetic mask is removed from the result f of the partial addition of i and j using the contents of the intermediate variable iawl. This is done by performing a modular subtraction, subtracting iawl from f, with the result being placed in a variable h. h = f - iawl
[0119] The procedure can then be interrupted, the secret (the result of the addition) remaining protected by low-entropy masking and subjected to various operations.
[0120] The procedure can conversely be continued, or resumed after various operations, in the following manner.
[0121] Then, during a step H8, the destination boolean mask is applied to this result of the addition, the result being placed in a variable k. k = h © rbool
[0122] The HOP operation is then completed (it has been adapted taking into account the value of rwide at the stage of step H2i-0 and step H2i-1).
[0123] Finally, during a step H9, the intermediate mask is removed to obtain the first share of the result in the destination masking. resO = k ® rwide
[0124] rbool also called resl is the second share of the result in the destination masking. res 1 = rbool
[0125] The contents of the variables resO and resl constitute shares which then correctly encode the sum i+j, using Boolean masking. An arithmetic operation was performed without converting the secret protected by a Boolean mask to protection by arithmetic masking, and this was done with a limited number of operations.
[0126] [Fig. 5] Figure 5 shows an embodiment in which an operator or The exclusive XOR ( ® ) is performed between two secrets masked arithmetically.
[0127] i and j are the secrets that we wish to process by a logical operator.
[0128] iaO and ial and respectively jaO and jal are their respective arithmetic masking encodings.
[0129] We therefore have the congruences iaO - ial = i [2”] and jaO-jal = j [2”].
[0130] The proposed procedure for performing an XOR (exclusive or exclusive) operator between i and j is the following:
[0131] During a step KOi, similar to step E0 of the embodiment of [Fig. 1], and also to step F0 of the embodiment of [Fig. 2], to step G0 of [Fig. 3], and to step H0 of [Fig. 4], the two n-bit strings 0 and 2n are chosen. The string thus chosen according to a low-entropy selection is intended to serve as an intermediate Boolean mask, and is written in full into an n-bit variable rwide, the n bits then all being either 0 or all 1, rwidei = rand{0, 2n - 1}
[0132] and also condensed into a single-bit variable rbit, which is 0 in the first case, and 1 in the second case. rbiti = rwidei & 1
[0133] In parallel, during a step Kl, the secret of the destination arithmetic masking is generated from among a large number of possible masks. This secret is a string of n bits, all possible strings—of which there are 2n—being advantageously equiprobable in the generation of this secret, and the result of the random draw being stored in a variable rarith. The operation is similar to the operation Fl of [Fig.2], rarith = rand[0, 2n[
[0134] In a K2i-0 step, the intermediate mask is set up on the iaO share. This involves implementing the XOR operator. The result is stored in a variable di. di = iaO ® rwidei
[0135] Then a KOP operation is performed on secret i, comprising removing the arithmetic mask, a logical operation with secret j, and setting up the destination mask. The KOP operation is adapted taking into account rwide.
[0136] In a KOj step, a second low-entropy mask is generated, different from the first, and for the secret j.
[0137] We choose between the two n-bit strings 0 and 7n -1- The string thus chosen is written in extenso in an n-bit variable rwide, the n bits then all being 0 or all 1, rwidej = rand{0, 2n - 1}
[0138] and also condensed into a single-bit variable rbit, which is 0 in the first case, and 1 in the second case. rbitj = rwidej & 1
[0139] The two low-entropy masks are combined into variables rwide for the n-bit version, and rbit for the 1-bit version, using an exclusive OR (XOR) operator for the former and an AND operator for the latter, rwide = rwidei ® rwidej rbit = rwide & 1
[0140] In steps K2i-1, K2j-0, and K2j-1, intermediate (low-entropy) Boolean masks are applied to the ial share, and in parallel, to the jaO and jal shares. The results are stored in variables ei, dj, and ej. ei = ial ® rwidei dj = jaO ® rwidej ej = jal ® rwidej
[0141] Then, once these masked values are obtained, in a step K3, they are used to remove the arithmetic masks. This involves performing two differences modulo 2n. The operations are performed on the variables di and ei, as well as dj and ej. Given the presence of the intermediate Boolean mask on these two shares, it is necessary to correct the result of the subtraction by deducting the value of rbit from its result. The results are stored in intermediate variables fi and fj. fi = di - ei - rbiti fj = dj - ej - rbitj
[0142] The XOR (exclusive or exclusive) operation is then performed between fi and fj. The result is stored in a variable g. g = fi ® fj
[0143] Then, in a step K8, the arithmetic mask generated in step K1 is adapted to the fact that it is to be applied to a string that has undergone a particular Boolean masking, and the adapted arithmetic mask is stored in a variable h. To do this, the XOR operator is applied to the secret rarith and the secret rwide, adding the value 0 or 1 contained in rbit. h = (rarith ® rwide) + rbit
[0144] Then the adapted arithmetic mask is applied to the result of the logical operation stored in the intermediate variable g, and the result is stored in an intermediate variable k. It is obtained by the modular addition of the contents of the variables g and h. k = g + h
[0145] It is specified here that as the secret rarith is not used before the implementation of step K8, it can be generated in different variants at any time up to just before step K8.
[0146] The KOP operation is then completed (it has been adapted taking into account the value of rwidei at the stage of step K2i-1, step K3 and step K8).
[0147] Only after step K8 has been performed, during a step K9, is the intermediate boolean mask removed from the content of the variable k. The result is stored in the variable aO. To do this, the XOR operator is applied to the content of the variable k and to the secret rwide. aO = k ® rwide
[0148] The shares aO and rarith, which are renamed al, then encode the result of the logical operation, in arithmetic masking.
[0149] Although only one procedure for adding variables masked by boolean masking and another for logical or exclusive operation (XOR) on variables masked by arithmetic masking have been presented, other analogous procedures can be developed to perform other operations quickly.
[0150] Such procedures adapted to an operation allow better performance than the conversion of the two operands, then the conversion of the result.
[0151] The invention can be advantageously combined with other countermeasures, such as random preloading, which consists of writing random data into each physical resource used by the implementation (e.g. registers, memory) before each writing of sensitive data into that same resource.
[0152] Arithmetic masking could be defined by choosing two shares aO and al such that aO + al = s [2n] instead of aO - al = s [2n].
[0153] The procedures adapt by choosing a'0 = aO and a'1 = -al, and we then have a'0 - a'1 = aO - (-al) = aO+al = s [2n]. We can then continue the chosen procedure using a'0 and a'1.
[0154] The invention can be used to mask encryption functions based on the ARX (addition, rotation, or exclusive) principle, or to mask certain post-quantum cryptography algorithms (e.g., Kyber), which require conversions between Boolean and arithmetic masking.
Claims
Demands
1. A method of processing a protected secret by a processor, comprising a step of choosing (EO; FO, GO, HO, KOi) and setting up (E2; F2; G2i; H2j; K2i), on the secret protected by an initial mask, a low-entropy masking, then implementing on the secret maintained under the protection of said low-entropy masking an operation (EOP; FOP; GOP; HOP; KOP) including a removal (E3-2; F3; G3i; H3j; K3i) of the initial mask, the processing method being characterized in that, an encoding being on n bits, the low-entropy masking comprises the choice and application of a mask chosen from the set {0; 2W-1} and applied by a bitwise exclusive or operator.
2. Method of processing a protected secret according to claim 1, characterized in that the operation (GOP; HOP) comprises an arithmetic operation combining the secret and another data.
3. Method of processing a protected secret according to claim 1 or claim 2, characterized in that the operation (KOP) comprises a logical operation combining the secret and another data.
4. Method of processing a protected secret according to any one of claims 1 to 3, characterized in that the operation (EOP; FOP; HOP) comprises the application of a destination mask distinct from the mask initially carried by the secret.
5. Method of processing a protected secret according to claim 4, characterized in that the operation (FOP) comprises placing an arithmetic mask on the secret whereas the mask initially worn was a boolean mask.
6. Method of processing a protected secret according to claim 4, characterized in that the operation (EOP) comprises applying a Boolean mask to the secret whereas the mask initially applied was an arithmetic mask.
7. Method of processing a protected secret according to any one of claims 1 to 6, characterized in that the (GOP; HOP) operation applies the same low-entropy mask to a second secret data item with which the secret is then combined during the (GOP; HOP) operation.
8. Method of processing a protected secret according to any one of claims 1 to 7, characterized in that the operation (EOP; FOP; GOP; KOP) comprises a corrective arithmetic operation dependent on the chosen low-entropy mask and carried out during the removal of the initial mask or during the application of an arithmetic mask or during an arithmetic operation combining the secret with a second secret data.
9. A method of processing a protected secret according to any one of claims 1 to 8, characterized in that the operation comprises the setting up (E8; F8; G8; H8; K8) of a destination mask and the processing method also comprising a step (E1; F1; G1; H1, K1) of random selection of the destination mask from a set of possible masks having a higher entropy than said low-entropy masking, the operation (EOP; FOP; GOP; HOP; KOP) being followed by a removal (E9; F9; G9; H9; K9) of the low-entropy mask.
10. Method of processing a protected secret according to any one of claims 1 to 9, characterized in that the protected secret is initially protected by a first-order masking.