A method and system for constructing a minimum-depth linear layer xor circuit

By extracting and classifying intermediate signals in the XOR circuit and establishing an independent gate selection reference table, the problem of balancing the number and depth of XOR gates in the XOR circuit is solved, and the number of XOR gates is reduced and the circuit structure is optimized under the condition of minimum depth.

CN123139934APending Publication Date: 2026-11-20SHANDONG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611644176.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-23
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing technologies, when constructing minimum-depth linear layer XOR circuits, struggle to reduce the number of XOR gates while maintaining minimum depth, and also fail to avoid forming long input/output paths. Furthermore, different gate selection rules or random operation can lead to differences in intermediate signals and output writing, thus failing to effectively utilize information from multiple reference circuits.

Method used

Intermediate signals and generation methods are extracted from multiple complete reference circuits, and five independent gate selection reference tables are established to guide the step-by-step gate selection process. This ensures that the number of XOR gates is reduced within the theoretical minimum logic depth. Signal combinations and output writing are recalculated through various depth-limited step-by-step gate selection methods.

Benefits of technology

It achieves a reduction in the number of XOR gates during the stepwise gate selection process without increasing the number of other output signals, ensuring that the circuit reaches the lower bound of the matrix depth, and optimizes the circuit structure to suit low-latency implementation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123139934A_ABST
    Figure CN123139934A_ABST
Patent Text Reader

Abstract

The present application provides a kind of minimum depth linear layer xor circuit construction method and system.Read target binary matrix and calculate theoretical minimum depth, generate complete reference circuit using multiple depth limited method, extract intermediate signal, generate input pair and output writing, respectively establish five independent gate selection reference table.Each non-empty table is combined with basic gate selection rule, and the circuit is reconstructed from input signal.Each step solves the minimum signal writing of unfinished output, enumerates the candidate input pair that meets the replacement depth condition, deletes the forbidden item, and then selects the gate according to the priority input pair, priority signal and priority output writing in turn, and uses the basic rule when it is not hit.After all non-zero target outputs are generated, clean up unused gates, check output function and depth, and select the one with the least number of gates in the complete circuit that passes the check.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of depth-constrained logic circuit construction technology, specifically to a method and system for constructing a minimum-depth linear layer XOR circuit. Background Technology

[0002] The linear layer of a symmetric cryptography consists of a binary matrix. Description. Input vector The output vector is obtained through matrix multiplication. Multiplication is performed over a binary finite field, and addition is an XOR operation. In gate-level implementations, each output is obtained by passing the input signal and an intermediate signal through a two-input XOR gate. XOR is an abbreviation for Exclusive OR. The logic depth of a circuit is the maximum number of XOR gates traversed from any input to any output; the depth of the input signal is zero.

[0003] Each additional layer of a two-input XOR gate at most doubles the number of inputs that a single signal depends on. Therefore, the number of inputs each output depends on gives a lower bound on the circuit depth; this lower bound can be reached by calculating each output using a balanced XOR tree. Reducing the number of gates while maintaining minimum depth requires allowing different outputs to share intermediate calculations, while avoiding shared signals that increase the longest path.

[0004] Early constructions of linear-layer XOR circuits primarily aimed to reduce the number of XOR gates. Starting from a unit input vector, an intermediate signal was added at a time, gradually reducing the number of signals required for a given output. This method can quickly produce circuits with fewer gates, but if the signal depth is not limited, the continuous use of certain intermediate signals can create long input-output paths, making the resulting circuit unsuitable for low-latency implementations.

[0005] Depth-constrained Boyar Peralta (BP) gate selection methods incorporate depth conditions during candidate generation, allowing the selection of signal pairs only from XOR expressions that can achieve a given output within a specified depth. This method restricts the circuit to a given depth, selecting only one candidate at a time. Earlier gate selections alter the currently available signals, changing the XOR expression for the output that can be written using the fewest signals. Therefore, different gate selection rules or different random runs can result in complete circuits with similar gate counts but significantly different intermediate signals, signal generation methods, and output expressions.

[0006] To increase the number of gate selection sequences to try, subsequent methods introduced different remaining signal ordering, random selection, output-to-input computation, and combinations of input and output directions. The input-direction method easily ensures that adding a new gate immediately reduces the number of signals needed for a target output, while the output-direction method can directly find the two shallower input signals of the last XOR gate at the output. The intermediate signals obtained by the two methods can complement each other. However, existing practices typically evaluate the complete circuit separately after each gate selection, without compiling the intermediate signals and generation methods from multiple completed circuits into a record that can be directly used in the next round.

[0007] The information that can be extracted from a complete circuit is not limited to the most frequently occurring intermediate signals. Signals that appear together in multiple reference circuits can be reused in various gate selection processes, and signals that appear only in circuits obtained under a certain gate selection rule may also lead to new gate selection orders; the same output can be written in different ways, and the same intermediate signal may be generated by different input pairs at the same minimum depth. If these different types of records are mixed in the same table, the same candidate may be simultaneously promoted and demoted; if the currently available signals are selected directly without checking, the depth limit may be exceeded. Summary of the Invention

[0008] To address the aforementioned problems, this invention proposes a method and system for constructing a minimum-depth linear layer XOR circuit. It extracts reusable intermediate signals and their generation methods from multiple complete two-input XOR circuits, classifies and establishes five independent gate selection reference tables, and uses the records in each table to guide the step-by-step gate selection, thereby reducing the number of XOR gates while maintaining the theoretical minimum logic depth.

[0009] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: A method for constructing a minimum-depth linear layer XOR circuit includes: Read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit; Under the theoretical minimum depth constraint, various depth-limited stepwise gate selection methods are used to re-solve the way to use the fewest signals in all incomplete outputs and satisfy the depth constraint on the current available signal set, so as to obtain a complete reference circuit set. Extract multiple signal combinations from the complete reference circuit set and establish corresponding gate selection reference tables for each; For each non-empty gate selection reference table and each basic gate selection rule, an independent task is formed. Starting from the initial available signal, gates are selected step by step. The incomplete outputs are recalculated from the current available signal and candidates are enumerated to obtain a candidate set that meets the depth condition. Remove unused input pairs from the candidate set, and search the remaining candidates sequentially according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate; if no candidate is found, select a signal from all remaining candidates according to the candidate sorting rules. Create an XOR gate for the selected input pair, add the output signal and depth of the gate to the available signal set, and repeat the candidate generation and gate selection process; all non-zero target rows have appeared as signals after the available signal set, clean up unused gates and check the circuit function and depth, and select the output with the fewest gates from the complete circuit and reference circuit that have passed the check.

[0010] As one embodiment, reading the target matrix and calculating the theoretical minimum depth of the two-input XOR circuit includes: Reading has OK, Target matrix of columns ,in and The number of output bits and the number of input bits are positive integers, respectively; each element is checked to be 0 or 1, and the order of the input columns and output rows is fixed.

[0011] make For the first OK, Take 0 to , The number of 1s in this row. Calculate the upper limit of depth. .in, This indicates taking the maximum value. Represents the logarithm to the base 2. Indicates rounding up. 'minimum' is an abbreviation for minimum, indicating the minimum value; the inner maximum value makes the depth of the zero row zero.

[0012] The zeroth row directly outputs a constant of zero, and rows with a weight of one directly reference the corresponding input; neither requires an additional XOR gate. Establish an initial set of available signals using unit vectors. ; Only in the first The first position is set to 1, and the rest are set to 0, indicating that the first position is 1. One input signal, Take 0 to Repeated output lines reference the same generated signal.

[0013] As one embodiment, under the theoretical minimum depth constraint, various depth-constrained stepwise gate selection methods are employed to resolve the code that uses the fewest signals and satisfies the depth constraint for all incomplete outputs on the currently available signal set, resulting in a complete reference circuit set, including: Let the set of currently available signals be... , For signal The actual depth in the current circuit. For each that has not yet appeared Non-zero target line Solve by XORing different signals yields The syntax is to enumerate the signals used from fewest to most, and retain all valid syntaxes for the minimum number of signals found initially.

[0014] by Describe the set of signals used in a given syntax, requiring... and .in, Indicates XOR, To express summation, Indicates belonging to, Indicates less than or equal to; exponent and These are the upper limits of the signal depth and the total circuit depth, respectively. This condition is used to determine whether these signals can be combined into the target output within the upper depth limit.

[0015] Write each minimum signal method Enumerate disordered input pairs composed of different signals Let the candidate output Its actual depth is Only when Furthermore, the replaced syntax still retains candidates if it meets the depth condition; among which... This indicates that it does not belong. If a candidate is not the target output, it must also satisfy the following conditions: ,in It means less than.

[0016] The reference circuit can be generated using the basic BP method, the randomized BP method, various improved methods sorted by the number of remaining signals, and a method that decomposes from the output to the input and continues construction. The same target matrix and depth limit are used in each run. The candidate check described above is performed during stepwise gate selection in the input direction; when decomposing from the output direction, the signals on both sides of the last gate are first determined, then the signals on both sides are constructed under their respective depth limits, and the complete circuit is checked.

[0017] As one embodiment, multiple signal combinations are extracted from the complete reference circuit set, and corresponding multiple gate selection reference tables are established, including: The cleaned reference circuit is checked item by item according to the output vectors of the target matrix, so as to... This represents the theoretical minimum depth; depths exceeding this limit... Circuits with inconsistent output vectors are not included in the reference circuit set.

[0018] For reference circuits that pass verification, signals are identified by binary coefficient vectors, and generation methods are identified by unordered input pairs formed by two vectors arranged with fixed numbers. Five gate selection reference tables are established. Each table contains a priority signal table, a priority input pair table, a priority output writing table, and a table of unused input pairs; it records the signal, generation method, applicable output number, reference circuit, frequency of occurrence, depth, and number of direct users. The number of direct users is the number of subsequent gates that use the signal as an input.

[0019] As one embodiment, an independent task is constructed for each non-empty gate selection reference table and each basic gate selection rule. Gate selection is performed step-by-step starting from the initial available signal. Unfinished outputs are recalculated from the currently available signal, and candidates are enumerated to obtain a candidate set that satisfies the depth condition, including: The gate selection reference tables are kept independent of each other, and the priority records and unused records in each gate selection reference table are used separately. For each non-empty gate selection reference table and each basic gate selection rule, an independent task is established, and gate selection is performed step by step starting with the initial set of available signals; the basic gate selection rule represents the candidate sorting rule used by the current task when no priority record is found. At each step, based on the latest available signals and their actual depth, the minimum signal writing method for all incomplete outputs is re-solved, and unordered input pairs are enumerated. Each pair is checked to see if a new signal has not yet been generated, if the replaced writing method still meets the depth condition, and if the depth of non-output signals is below the upper limit; duplicate input pairs are merged to form the current candidate set.

[0020] As one embodiment, unused input pairs are removed from the candidate set. The remaining candidates are then searched sequentially according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate. If no candidate is found, a signal is selected from all remaining candidates according to the candidate sorting rules, including: First, remove the unused input pairs recorded in the unused input pair table from the candidate set; if there are no candidates after deletion, end the task. For the remaining candidates, first search for the preferred input pairs in the preferred input pair table, then search for candidates whose generated signals belong to the preferred signal table, and then check the candidates that can form the preferred output writing in the preferred output writing table. When multiple candidates are found at each level, they are first sorted by the number of times the reference circuit appears, then by the number of direct users, and finally by the current generation depth, from small to large. If they are still the same, one is determined according to the basic gate selection rules.

[0021] If none of the three parts are found, the basic selection rules will be used to select from all remaining candidates. Select the input pair. Then, establish the XOR gate. , will signal and its actual depth of inclusion The minimum signal writing method for each incomplete output is recalculated and the next round of candidates is generated.

[0022] A minimum-depth linear-layer XOR circuit construction system includes: The matrix reading and minimum depth calculation module is used to read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit. The reference circuit generation module is used to apply various depth-limited stepwise gate selection methods under the theoretical minimum depth limit to resolve the writing of all incomplete outputs with the fewest signals and satisfying the depth limit on the current available signal set, so as to obtain a complete reference circuit set. The reference circuit recording extraction module is used to extract multiple signal combinations from a complete set of reference circuits. The door selection reference table construction module is used to create multiple corresponding door selection reference tables. The candidate generation module that satisfies the depth condition is used to form an independent task for each non-empty gate selection reference table and each basic gate selection rule, and to select gates step by step starting from the initial available signal. The module recalculates the incomplete outputs and enumerates the candidates based on the current available signal to obtain the candidate set that satisfies the depth condition. The reference table gate selection module is used to remove unused input pairs from the candidate set, and sequentially search the remaining candidates according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate; if no candidate is found, the signal is selected from all remaining candidates according to the candidate sorting rules. The circuit cleaning and verification module is used to create XOR gates for selected input pairs and update available signals. After all non-zero target rows have been generated, unused gates are deleted, each output coefficient vector and actual depth are recalculated, the gate count of the verified complete circuit is compared with that of the reference circuit, and the circuit with the fewest gates is selected for output.

[0023] A computer program product includes a computer program that, when executed by a processor, implements the method for constructing a minimum-depth linear layer XOR circuit.

[0024] A non-transitory computer-readable storage medium is provided for storing computer instructions, which, when executed by a processor, implement the method for constructing a minimum-depth linear layer XOR circuit.

[0025] An electronic device includes a processor, a memory, and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory to enable the electronic device to implement the minimum depth linear layer XOR circuit construction method.

[0026] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention extracts intermediate signals, generation methods, and output formats from multiple complete reference circuits for selection in a new round of search. Each reference table guides a gate selection task, enabling new circuits to combine calculations from different reference circuits without having to follow the complete gate sequence of a particular reference circuit.

[0027] Five gate selection reference tables each hold records of different categories. Prohibited input pairs will not be mixed with priority records from other tables. Before gate selection, the current signal and the depth conditions after replacement are rechecked. A record in the reference table can only be selected if it becomes a current qualified candidate.

[0028] Each selected gate reduces the minimum number of signals for at least one target output. Existing implementations remain usable, and the minimum number of signals for other outputs does not increase. After the complete circuit performs a gate-by-gate function check and reaches the lower bound of the matrix depth, it is then compared with the reference circuit to determine the gate count. Attached Figure Description

[0029] Figure 1 This is an overall flowchart illustrating how an embodiment of the present invention establishes a gate selection reference table from multiple reference circuits and guides step-by-step gate selection. Figure 2 The contents and respective function diagrams of the five gate selection reference tables in this embodiment of the invention; Figure 3 This is a flowchart illustrating the candidate generation and reference table gate selection process that satisfies the depth condition according to an embodiment of the present invention. Detailed Implementation

[0030] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0031] Terminology Explanation The target matrix is ​​denoted as ,in For a binary finite field containing only 0 and 1, For the number of output bits, For the number of input bits, Connect the number of rows and the number of columns. The input column vector is denoted as... The output column vector is Each signal has a length of [missing information]. The binary coefficient vector representation: the first A coefficient of 1 indicates that the XOR expression of the signal contains the input. The XOR operation of two signals corresponds to the bitwise XOR of their coefficient vectors. Identical coefficient vectors represent the same Boolean function, but their actual generation depths in different circuits are recorded separately. Each XOR gate is calculated per layer, and the same signal can be referenced by multiple gates; the reference itself does not increase the logic depth.

[0032] make For the first OK, Take 0 to , The number of 1s in this row. Calculate the upper limit of depth. .in, This indicates taking the maximum value. Represents the logarithm to the base 2. Indicates rounding up. "Minimum" is an abbreviation for "smallest," indicating the minimum value; the innermost maximum value makes the depth of the zero row zero. For non-zero signals... Its theoretical minimum depth is Depth is The signal depends at most on Given a set of inputs, a lower bound is provided; this lower bound can be reached by merging the dependent inputs using a balanced XOR tree. When the matrix is ​​an all-zero matrix, no XOR gates are added, and the circuit depth is zero.

[0033] Example 1 One embodiment of the present invention provides a method for constructing a minimum-depth linear layer XOR circuit, the method comprising the following steps: Step 1: Read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit; Step 2: Under the theoretical minimum depth constraint, use a variety of depth-constrained stepwise gate selection methods to resolve the way to write all incomplete outputs with the fewest signals and satisfy the depth constraint on the current set of available signals, and obtain the complete reference circuit set; Step 3: Extract multiple signal combinations from the complete reference circuit set and establish corresponding gate selection reference tables for each combination. Step 4: For each non-empty gate selection reference table and each basic gate selection rule, form an independent task, and select gates step by step starting from the initial available signal. Recalculate the incomplete outputs from the current available signal and enumerate candidates to obtain a candidate set that satisfies the depth condition. Step 5: Remove unused input pairs from the candidate set, and search the remaining candidates sequentially according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate; if no candidate is found, select a signal from all remaining candidates according to the candidate sorting rules. Step 6: Create an XOR gate for the selected input pair, add the output signal and depth of the gate to the available signal set, and repeat the candidate generation and gate selection process; all non-zero target rows have appeared as signals after the available signal set, clean up unused gates and check the circuit function and depth, and select the output with the fewest gates from the complete circuit and reference circuit that have passed the check.

[0034] The following describes the specific operations in the order of matrix reading, reference circuit generation, reference table extraction, step-by-step gate selection, and verification.

[0035] Step 1: Read the data with... OK, Target matrix of columns ,in and Let be the number of output bits and the number of input bits, respectively, both positive integers; check each element for being 0 or 1, and fix the order of the input columns and output rows. For the first OK, Take 0 to , The number of 1s in this row. Calculate the upper limit of depth. .in, This indicates taking the maximum value. Represents the logarithm to the base 2. Indicates rounding up. "Minimum" is an abbreviation for "smallest," indicating the minimum value. The inner maximum value sets the depth of the zero row to zero. The zero row directly outputs a constant zero, and rows with a weight of one directly reference their corresponding inputs, without adding any XOR gates. Establish an initial set of available signals using unit vectors. ; Only in the first The first position is set to 1, and the rest are set to 0, indicating that the first position is 1. One input signal, Take 0 to Repeated output lines reference the same generated signal. For each non-zero target line, record whether it is already in the current signal set; targets already in the set are no longer considered for candidate enumeration.

[0036] Step 2: Let the current set of available signals be... , For signal The actual depth in the current circuit. For each that has not yet appeared Non-zero target line Solve by XORing different signals yields The syntax is to enumerate the signals used from fewest to most, retaining all valid syntaxes for the minimum number of signals found initially. Describe the set of signals used in a given syntax, requiring... and .in, Indicates XOR, To express summation, Indicates belonging to, Indicates less than or equal to; exponent and These are the upper limits of the signal depth and the total circuit depth, respectively. This condition is used to determine whether these signals can be combined into the target output within the depth upper limit. This indicates the minimum number of signals minus one, representing the number of merging gates still needed for the target output; the target and zero output have already been achieved. It is zero.

[0037] On writing Two different signals and ,make The replaced depth condition is: .in Traversal Except and Other signals, The curly braces denote the difference between sets. Calculate pairwise. And check the inequality. Only keep [the inequality]. Input pairs; If it is not the target output, it must also satisfy the following conditions: When the same input pair is generated by different writing methods, they are merged, and their applicable targets are preserved.

[0038] The replacement check mentioned above takes into account the depth of both the new signal and the other signals in the syntax. For example, if the upper limit of depth is three, and the depths of the three signals are two, one, and one respectively, the sum of the powers of two corresponding to the depths of each signal is eight. First, merge the two signals with a depth of one; the sum of the powers of two after the replacement is still eight. Then, merge the signals with depths of two and one; the sum of the powers of two after the replacement is ten, which exceeds eight. Therefore, the latter input pair is not considered as a candidate for this syntax.

[0039] Step 3: Run multiple depth-constrained construction methods respectively, retain the successfully generated complete reference circuits, and form a set. The subscript "ref" is taken from "reference".

[0040] The reference circuit can be generated using the basic BP method, the randomized BP method, various improved methods sorted by the number of remaining signals, and a method that decomposes from output to input and continues construction. Each run uses the same target matrix and depth limit. The stepwise gate selection in the input direction performs the aforementioned candidate check; when decomposing from the output direction, the signals on both sides of the last gate are first determined, then the signals on both sides are constructed under their respective depth limits, and the complete circuit is checked. Randomized runs use a newly acquired random seed each time. After all non-zero outputs are completed, the marked gates are referenced in reverse from the output along the input, unmarked gates are deleted, and the coefficient vector, actual depth, generated input pair, direct user, and final output are recorded for each signal. Incorrect output or depth exceeding the limit will result in a failure to resolve the issue. The result will not be entered The current round ends if a complete reference circuit is not obtained, and no reference table is constructed.

[0041] Step 4: Extract multiple signal combinations from the complete reference circuit set and establish corresponding gate selection reference tables.

[0042] Each selection reference form is denoted as . For priority signal table, To prioritize the input of the table, To prioritize the output of the syntax table, To avoid using an input pair table, the output format simultaneously stores the target number and the two input vectors of the last gate; the input pair table stores unordered input pairs and their generated signals. Each table can be empty; a gate selection reference table is considered non-empty if at least one record table is not empty.

[0043] Unordered input pairs Indicated by and As input to an XOR gate, its output is Put two The bit coefficient vector is stored after being sorted by a fixed binary number, allowing the merging of identical signals and generation methods in different reference circuits. The actual depth in the reference circuit and the theoretical minimum depth of the signal are stored separately; candidate checks in a new search use the current actual depth. Signals or input pairs that do not appear in the reference circuit have their occurrence count and number of direct users recorded as zero; the theoretical minimum depth of the signal is calculated based on its Hamming weight, while the actual candidate depth is still calculated from the current two inputs.

[0044] As one embodiment, the present invention extracts five types of signal combinations from a complete set of reference circuits and establishes five corresponding gate selection reference tables, as follows: (1) Construct the first door selection reference table .by This indicates the presence of an intermediate signal. The number of reference circuits, in order to Indicates the use of input pairs The number of reference circuits. The same item is counted only once within the same reference circuit. Signals appearing at least twice and generation input pairs are added to the priority signal table and priority input pair table respectively; additionally, repeated signals directly used by at least two subsequent gates are separately retained. When the preset number of records is reached, items with higher frequency of occurrence are prioritized for retention.

[0045] In this embodiment, when extracting non-output intermediate signals, a Hamming weight of two to four and an actual depth of less than [a certain value] are selected. The signal. For the same signal in different reference circuits, the number of occurrences is accumulated according to the circuit number, the number of direct users is taken as the maximum value among these circuits, the reference depth is taken as the minimum value, and the original records are retained for verification.

[0046] (2) Construct the second door selection reference table The selection process proceeds sequentially through each reference circuit, first considering signals that appear only in that circuit; if the number is insufficient, signals appearing in two and three reference circuits are considered in turn. Signals with a Hamming weight of three or four are prioritized over signals with a weight of two, and signals of the same type are further sorted in descending order of the number of direct users and the number of outputs affected. Input pairs that generated the selected signals are retained first. After each circuit completes its selection independently, the results are merged, and duplicates are removed based on the signal vector and unordered input pairs.

[0047] The second table stores the records selected by each reference circuit individually. This table may contain signals that appear only once, or signals shared by multiple circuits. The difference with this table is that it selects signals circuit by circuit first, and then combines the results.

[0048] (3) Construct the third door selection reference table The output format that has already been recorded. Select from the signal with weights of two and the intermediate signal extracted by the reference circuit. ,form , The apostrophe indicates the rewritten signal. When XORed on both sides, they cancel each other out, therefore Retain distinct non-zero values, each with a weight not exceeding four, and satisfying the following conditions: Signals on both sides. Add the new notation. Signals from both sides are added The minimum depth of the non-input signal is generated by adding the input pair. .

[0049] The minimum depth generation input pairs are enumerated according to the signal vector. A signal with a weight of two is XORed directly with its two corresponding inputs; a signal with a weight of three is divided into one-variable and two-variable sets; a signal with a weight of four is divided into two sets, each containing two variables. All different unordered partitions are enumerated to obtain all minimum depth generation methods. Each input side is first generated according to its own minimum depth, and then merged by an XOR gate.

[0050] (4) Construct the fourth door selection reference table For signals with a weight of three or four that appear in at least two reference circuits. The set of all minimum depth input pairs is obtained by enumerating according to the above division. ; Let this be the notation for the set. Indicates that the reference circuit is actually used and belongs to The input pair set, index Refers to the reference circuit. Calculation. When the difference set is not empty, join in No input was used to add Enumeration is not limited to input signals already present in the reference circuit. In a new search, an input can only be selected if both inputs are available and the input pair belongs to the current candidate set.

[0051] The fourth table prioritizes using input pairs not used in the reference circuit to generate the same signal. The generated result is the same, but the preceding signals differ, and the XOR notation that can be used for subsequent targets may also differ.

[0052] (5) Construct the fifth door selection reference table For signals with weights of three or four and multiple minimum depth generation methods... ,statistics The number of occurrences of each input pair is recorded. If the maximum number of occurrences is not less than two, the pair with the most occurrences is selected and denoted as . An asterisk indicates the most frequently used input pair; when inputs are listed side-by-side, they are selected using a fixed binary number. Add this input pair to... ,Will Other inputs in the input At the same time join in .

[0053] The fifth table prohibits the use of the most frequently recorded input pairs, but the same signal can still be generated through other input pairs. Recording is prohibited before all priority records and basic gate selection rules take effect.

[0054] Step 5: Five Tables to Use them separately, without merging priority and forbidden records from each table. Each non-empty table... With each basic gate selection rule Forming independent tasks, from Start choosing a door. This indicates the candidate sorting rule used when the priority record is not hit. Based on the current... Resolve all incomplete outputs, enumerate and check the input pairs as in step 2, and obtain the current candidate set. ; The notation represents the candidate set. Only input pairs in the table belong to the candidate set. Only then can it be selected.

[0055] One basic gate selection rule in this embodiment is based on the outputs after adding candidates. The sums are sorted from smallest to largest; if the sums are the same, they are then sorted from largest to smallest by the number of targets improved and from smallest to largest by the depth of the new signal. If they are still the same, they can be selected by fixed input pair numbers or randomly selected from the tied items. The minimum signal writing method for each target is recalculated after each candidate is added.

[0056] Step 6: First from delete The input pairs in the code. Check each input pair sequentially to see if it belongs to... Does the generated signal belong to Whether it can be promoted The output syntax in the code only checks the earlier levels after a hit. For incomplete code snippets... Advancement includes direct selection or Generate when available or Generate when available ;here and These are the signals on both sides of the record. The selected input pair must still belong to the candidate set after removing prohibited items.

[0057] When multiple candidates are found at each level, they are first sorted by the frequency of reference circuit occurrences from highest to lowest, then by the number of direct users from highest to lowest, and finally by the current generation depth from lowest to highest. If they are still the same, one is selected according to the basic gate selection rules. Alternatively, a candidate can be randomly selected from the same highest priority level. If none of the three priorities are found, then... If no candidates are found after deleting prohibited items, or if the basic rules fail to select a qualified candidate, the task ends and the prohibited input pairs are not restored.

[0058] Step 7: Write the selected door And record ,Will join in The objectives are then resolved, and the next round of candidates is generated. The minimum number of signals for at least one objective is reduced, while the original notation for other objectives is retained. All non-zero objective lines have now appeared. If the condition is met, the task is complete; otherwise, continue selecting gates. If the task is not completed after reaching the preset number of gates or the maximum number of operations, the task ends, and no part of the circuit is included in the result.

[0059] For the complete circuit, mark the gates in reverse order from the output to the input, delete unused gates, renumber them, and calculate the depth of each gate; verify that the output coefficient vector equals the corresponding row of the matrix. Retain gates with consistent functionality and depth not exceeding [a certain threshold]. The complete circuit is compared with all reference circuits in terms of gate count; if the gate counts are the same, gates are selected in ascending order based on the maximum number of direct users, using a fixed gate order. The resulting circuit reaches the theoretical minimum depth of the matrix, and the gate count is the minimum value among the passing results of this round of verification.

[0060] As one embodiment, the detailed process of establishing a gate selection reference table from multiple reference circuits and guiding step-by-step gate selection according to the present invention is as follows: Reference circuit generation can employ various methods, including basic backpropagation (BP), randomized BP, two improved methods sorted by the number of remaining signals, a method combining output decomposition and input direction construction, and a combination method considering both gate count and depth. Different methods are run separately, and successful results are retained. The randomized task records the seed, candidate permutations, and selected gate sequence; each reference circuit records the coefficient vector, actual depth, generation input pair, direct user, output syntax, and method number.

[0061] After verification, the reference circuit is recorded according to the five categories of rules mentioned above, resulting in a multi-circuit shared table, a circuit-by-circuit selection table, an output substitution table, an unused generation method table, and a common input pair exclusion table. Each record stores its source circuit and applicable target, and cross-circuit duplicates are merged according to coefficient vectors and unordered input pairs.

[0062] Figure 1 This diagram illustrates the overall process. First, the theoretical minimum depth is calculated. Then, a reference circuit is generated and verified. Five tables are constructed from the reference circuit, and each non-empty table, along with the basic gate selection rules, forms an independent task. The task restarts gate selection from the input. Successful results are cleaned and verified together with the reference circuit, and the table with the fewest gates is selected. Each rectangle represents a processing operation, and the downward solid arrow indicates the order of operations. Each table in the diagram is used independently; it is not required that all five tables be used simultaneously for the same task.

[0063] Figure 2 List the contents of five gate selection reference tables. The first box retains signals and input pairs shared by multiple reference circuits; the second box first selects within each circuit and then merges the records; the third box XORs the same signal simultaneously and rewrites both sides of the output; the fourth box prioritizes recording the smallest depth input pairs not used by the reference circuits; the fifth box disables the most frequently used input pairs and prioritizes other methods. The five boxes are arranged from top to bottom according to the table number, are independent of each other, and have no execution order. All records are established according to the vector and depth checks in step 4.

[0064] Furthermore, the specific process of selecting doors step by step according to the door selection reference table includes: In the present Next, put each signal Using bit vectors as columns, construct a target row. This is a system of two linear equations with a right-hand vector. Enumerate the set of columns with coefficients of 1 from fewest to most, check their sum against the target using a bitwise XOR check, and verify the depth condition inequality. After finding the minimum number of valid solutions, retain those valid solutions. For each solution, enumerate unordered input pairs, check for replacement inequalities and non-output depth conditions as described in step 2, and remove duplicates to form... .

[0065] First, delete unused input pairs, then sequentially search for priority input pairs, priority signals, and advanceable output implementations. When multiple entries hit the same level, determine one according to the pre-defined level sorting or random selection rules. If no entry is hit, use the basic rules; the candidate value range remains the set after deleting prohibited items. After selection, add a gate and recalculate all implementations for incomplete objectives.

[0066] Once all non-zero target rows have been generated, the corresponding signals are directly referenced as outputs; identical outputs share the same reference, and the zero row outputs a constant of zero. After cleanup, each input reference is checked by gate number to ensure it points to the main input or a gate with a smaller number, and then each output vector and actual depth are checked. Only complete circuits that pass the checks participate in the final comparison.

[0067] Figure 3 This represents a loop for an independent gate selection task. It begins by checking if all non-zero target rows have been generated; if so, it proceeds to cleanup and verification. If not, it calculates the minimum signal writing method, enumerates qualified input pairs for depth, and removes prohibited items. If there are no remaining candidates or the limit is reached, the task ends; otherwise, it selects a gate according to the priority and basic rules in the table, updates the signal, and returns to the completion check. Rectangles represent calculations, diamonds represent judgments, arrows marked yes or no indicate the corresponding branch, and a return arrow indicates recalculating the current state.

[0068] As one example, the verification process and results include: Check from Starting with an input unit vector, the binary coefficient vectors of each output and the actual depth are recalculated according to the gate order and compared with the corresponding rows of the matrix. The output gate type, input reference, output reference, and depth of each gate are verified. For AES (Advanced Encryption Standard) MixColumns, using its standard 32-bit binary matrix representation, a circuit with a depth of three and 98 two-input XOR gates is obtained; the weight of each row of this matrix is ​​five or seven, hence the theoretical minimum depth is three. For ten other publicly available MDS (Maximum Distance Separable) matrices, circuits with fewer gates are obtained at their respective theoretical minimum depths; nine of these matrices have a depth of three, and one has a depth of four. The integrative MDS matrix represents the MDS matrix that recovers the original input after being applied twice consecutively; on a tested 32-bit integrative MDS matrix, a circuit with a depth of three and 82 XOR gates is obtained. All gate numbers are represented using corresponding fixed binary matrices and calculated using two-input XOR gates.

[0069] Example 2 One embodiment of the present invention provides a minimum-depth linear layer XOR circuit construction system, comprising: The matrix reading and minimum depth calculation module is used to read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit. The reference circuit generation module is used to apply various depth-limited stepwise gate selection methods under the theoretical minimum depth limit to resolve the writing of all incomplete outputs with the fewest signals and satisfying the depth limit on the current available signal set, so as to obtain a complete reference circuit set. The reference circuit recording extraction module is used to extract multiple signal combinations from a complete set of reference circuits. The door selection reference table construction module is used to create multiple corresponding door selection reference tables. The candidate generation module that satisfies the depth condition is used to form an independent task for each non-empty gate selection reference table and each basic gate selection rule, and to select gates step by step starting from the initial available signal. The module recalculates the incomplete outputs and enumerates the candidates based on the current available signal to obtain the candidate set that satisfies the depth condition. The reference table gate selection module is used to remove unused input pairs from the candidate set, and sequentially search the remaining candidates according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate; if no candidate is found, the signal is selected from all remaining candidates according to the candidate sorting rules. The circuit cleaning and verification module is used to create XOR gates for selected input pairs and update available signals. After all non-zero target rows have been generated, unused gates are deleted, each output coefficient vector and actual depth are recalculated, the gate count of the verified complete circuit is compared with that of the reference circuit, and the circuit with the fewest gates is selected for output.

[0070] Example 3 The present invention provides a computer program product, including a computer program that, when executed by a processor, implements the method for constructing a minimum depth linear layer XOR circuit.

[0071] Example 4 The present invention provides a non-transitory computer-readable storage medium for storing computer instructions, which, when executed by a processor, implement the method for constructing a minimum-depth linear layer XOR circuit.

[0072] Example 5 The present invention provides an electronic device, comprising: a processor, a memory, and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory to enable the electronic device to implement the minimum depth linear layer XOR circuit construction method described above.

Claims

1. A method for constructing a minimum-depth linear layer XOR circuit, characterized in that, include: Read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit; Under the theoretical minimum depth constraint, various depth-limited stepwise gate selection methods are used to re-solve the way to use the fewest signals in all incomplete outputs and satisfy the depth constraint on the current available signal set, so as to obtain a complete reference circuit set. Extract multiple signal combinations from the complete reference circuit set and establish corresponding gate selection reference tables for each; For each non-empty gate selection reference table and each basic gate selection rule, an independent task is formed. Starting from the initial available signal, gates are selected step by step. The incomplete outputs are recalculated from the current available signal and candidates are enumerated to obtain a candidate set that meets the depth condition. Remove unused input pairs from the candidate set, and search the remaining candidates sequentially according to the priority input pair table, priority signal table, and priority output writing table to determine the candidates; If not found, the signal is selected from all remaining candidates according to the candidate sorting rules; Create an XOR gate for the selected input pair, add the output signal and depth of the gate to the available signal set, and repeat the candidate generation and gate selection process. All non-zero target lines have appeared as signals after the available signal set. Clean up unused gates and verify the circuit function and depth. Select the circuit with the fewest gates from the complete circuit and the reference circuit that have passed the verification and output them.

2. The method for constructing a minimum-depth linear layer XOR circuit as described in claim 1, characterized in that, The process of reading the target matrix and calculating the theoretical minimum depth of the two-input XOR circuit includes: Reading has OK, Target matrix of columns ,in and The number of output bits and the number of input bits are positive integers, respectively; each element is checked to be either 0 or 1, and the order of the input columns and output rows is fixed. make For the first OK, Take 0 to , Calculate the upper limit of depth for the number of 1s in the row. ;in, This indicates taking the maximum value. Represents the logarithm to the base 2. Indicates rounding up. This is an abbreviation for minimum, indicating the minimum value; the innermost maximum value makes the depth of the zero row zero. The zeroth row directly outputs a constant of zero, and the row with a weight of one directly references the corresponding input; neither requires an additional XOR gate. Establish an initial set of available signals using unit vectors. ; Only in the first The first position is set to 1, and the rest are set to 0, indicating that the first position is 1. One input signal, Take 0 to Repeated output lines reference the same generated signal.

3. The method for constructing a minimum-depth linear layer XOR circuit as described in claim 1, characterized in that, Under the theoretical minimum depth constraint, various depth-constrained stepwise gate selection methods are employed to resolve the solution for all incomplete outputs using the fewest signals while satisfying the depth constraint on the currently available signal set, resulting in a complete set of reference circuits, including: Let the set of currently available signals be... , For signal The actual depth in the current circuit; for each that has not yet appeared Non-zero target line ( (For the output row number), solve by XORing different signals yields The writing method is to enumerate the number of signals used from least to most, and retain all the qualified writing methods corresponding to the minimum number of signals found for the first time. by Describe the set of signals used in a given syntax, requiring... and ;in, Indicates XOR, To express summation, Indicates belonging to, Indicates less than or equal to; exponent and These are the upper limits of the signal depth and the total circuit depth, respectively; this condition is used to determine whether these signals can be merged into the target output within the upper limit of the depth. Write each minimum signal method Enumerate disordered input pairs composed of different signals Let the candidate output Its actual depth is Only when Furthermore, the replaced syntax still retains candidates if it meets the depth condition; among which... This indicates that it does not belong; when a candidate is not the target output, it must also satisfy the following conditions: ,in Indicates less than; the replacement depth condition is ,in The remaining signals in the traversal method, Represents the set difference. This indicates taking the maximum value; The reference circuit is generated by the basic Boyar Peralta method, the randomized Boyar Peralta method, different improved methods sorted by the number of remaining signals, and the method of decomposing from the output to the input and continuing to construct. The same target matrix and depth limit are used in each run. The candidate check is performed by stepwise gate selection in the input direction. When decomposing from the output direction, the signals on both sides of the last gate are determined first, and then the signals on both sides are constructed under their respective depth limits, and the complete circuit is checked.

4. The method for constructing a minimum-depth linear layer XOR circuit as described in claim 1, characterized in that, Multiple signal combinations are extracted from the complete reference circuit set, and corresponding gate selection reference tables are established for each combination, including: The cleaned reference circuit is checked item by item according to the output vectors of the target matrix, so as to... This represents the theoretical minimum depth; depths exceeding this limit... Circuits with inconsistent output vectors are not included in the reference circuit set. For the reference circuit that has passed the verification, the signal is identified by a binary coefficient vector, and the identification method is generated by an unordered input pair formed by two vectors arranged in a fixed number order. Five gate selection reference tables are established, each containing a priority signal table, a priority input pair table, a priority output writing table, and a no-input pair table. The signal, generation method, applicable output number, reference circuit, occurrence frequency, depth, and number of direct users are recorded. The number of direct users is the number of subsequent gates that use the signal as an input.

5. The method for constructing a minimum-depth linear layer XOR circuit as described in claim 1, characterized in that, For each non-empty gate selection reference table and each basic gate selection rule, an independent task is constructed. Starting from the initial available signal, gate selection is performed step-by-step. The incomplete outputs are recalculated from the currently available signal, and candidates are enumerated to obtain a candidate set that satisfies the depth condition, including: The gate selection reference tables are kept independent of each other, and the priority records and unused records in each gate selection reference table are used separately. For each non-empty gate selection reference table and each basic gate selection rule, an independent task is established, and gate selection is performed step by step starting with the initial set of available signals; the basic gate selection rule represents the candidate sorting rule used by the current task when no priority record is found. At each step, based on the latest available signals and their actual depth, the minimum signal writing method for all incomplete outputs is re-solved, and the unordered input pairs are enumerated. Each pair of inputs is checked to see if a new signal has not yet been generated, if the replaced input still meets the depth condition, and if the depth of the non-output signal is below the upper limit; duplicate input pairs are merged to form the current candidate set.

6. The method for constructing a minimum-depth linear layer XOR circuit as described in claim 1, characterized in that, Remove unused input pairs from the candidate set, and search the remaining candidates sequentially according to the priority input pair table, priority signal table, and priority output writing table to determine the candidates; If not found, the signal is selected from all remaining candidates according to the candidate ranking rules, including: First, remove the unused input pairs recorded in the unused input pair table from the candidate set; if there are no candidates after deletion, end the task. For the remaining candidates, first search for the preferred input pairs in the preferred input pair table, then search for candidates whose generated signals belong to the preferred signal table, and then check the candidates that can form the preferred output writing in the preferred output writing table. When multiple candidates are found at each level, they are first sorted by the number of times the reference circuit appears, then by the number of direct users, and finally by the current generation depth, from small to large. If they are still the same, one is determined according to the basic gate selection rules. If none of the three parts are found, the basic door selection rules will be used to select from all remaining candidates. Select input pair Then, establish the XOR gate. , will signal Its actual depth is added to the currently available signal set. The minimum signal writing method for each incomplete output is recalculated and the next round of candidates is generated.

7. A minimum-depth linear layer XOR circuit construction system, characterized in that, include: The matrix reading and minimum depth calculation module is used to read the target matrix and calculate the theoretical minimum depth of the two-input XOR circuit. The reference circuit generation module is used to apply various depth-limited stepwise gate selection methods under the theoretical minimum depth limit to resolve the writing of all incomplete outputs with the fewest signals and satisfying the depth limit on the current available signal set, so as to obtain a complete reference circuit set. The reference circuit recording extraction module is used to extract multiple signal combinations from a complete set of reference circuits. The door selection reference table construction module is used to create multiple corresponding door selection reference tables. The candidate generation module that satisfies the depth condition is used to form an independent task for each non-empty gate selection reference table and each basic gate selection rule, and to select gates step by step starting from the initial available signal. The module recalculates the incomplete outputs and enumerates the candidates based on the current available signal to obtain the candidate set that satisfies the depth condition. The reference table gate selection module is used to remove unused input pairs from the candidate set and sequentially search the remaining candidates according to the priority input pair table, priority signal table, and priority output writing table to determine the candidate. If not found, the signal is selected from all remaining candidates according to the candidate sorting rules; The circuit cleanup and verification module is used to create an XOR gate based on the selected input pair and update the available signals. After all non-zero target rows have been generated, unused gates are deleted, each output coefficient vector and the actual depth are recalculated, the gate count of the completed circuit and the reference circuit are compared and verified, and the circuit with the fewest gates is selected for output.

8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the minimum depth linear layer XOR circuit construction method according to any one of claims 1-6.

9. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium is used to store computer instructions, which, when executed by a processor, implement a minimum-depth linear layer XOR circuit construction method as described in any one of claims 1-6.

10. An electronic device, characterized in that, include: The device includes a processor, a memory, and a computer program; wherein the processor is connected to the memory, the computer program is stored in the memory, and when the electronic device is running, the processor executes the computer program stored in the memory to enable the electronic device to implement a minimum depth linear layer XOR circuit construction method as described in any one of claims 1-6.