Method for generating one-way function, system, device, and storage medium
By reusing mappings and key spaces to construct one-way functions in symmetric encryption algorithms, the problems introduced by complex mathematics and hash algorithm modules in existing technologies are solved, achieving the effect of reducing cost and space occupation.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
- Filing Date
- 2025-09-15
- Publication Date
- 2026-05-15
AI Technical Summary
Constructing one-way functions using existing technologies requires complex mathematical knowledge and the introduction of hash algorithm modules, leading to increased product costs and space requirements.
By reusing the mapping and key space in the symmetric encryption algorithm, a one-way function is constructed, avoiding the introduction of a hash algorithm module, and generating the one-way function using the mapping relationship of the symmetric encryption algorithm.
This reduces the application cost of one-way functions and the hardware overhead of products, reduces the space occupied by storage units and dedicated cryptographic chips, and improves the efficiency of generation and use.
Smart Images

Figure CN2025121351_15052026_PF_FP_ABST
Abstract
Description
Methods, systems, devices, and storage media for generating one-way functions
[0001] Related applications
[0002] This application claims priority to Chinese patent application filed on November 6, 2024, application number 202411580687.0, entitled "Method, System, Apparatus and Storage Medium for Generating One-Way Functions", the entire contents of which are incorporated herein by reference. Technical Field
[0003] This application relates to the field of cryptography technology, and in particular to a method, system, device and storage medium for generating one-way functions. Background Technology
[0004] A one-way function is an important concept in cryptography. It is a mathematical function that is easy to compute but difficult to reverse engineer. Specifically, given an input value x, the output value y = f(x) can be easily computed using a one-way function f. However, if only the output value y is known, it is computationally infeasible to find the original input value x through reverse computation. Based on these characteristics, one-way functions have wide applications in the field of information security. Summary of the Invention
[0005] One aspect of this application provides a method for generating a one-way function, applied in an electronic device, wherein the electronic device is configured with a preset symmetric encryption algorithm, and the method includes:
[0006] Obtain the preset symmetric encryption algorithm, the zeroth mapping, and the first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0007] The first ciphertext is obtained by performing encryption calculations using the symmetric encryption algorithm, with the plaintext as input of the zeroth mapping value and the key as input of the first mapping value.
[0008] The mapping relationship between the first ciphertext and the independent variable is used as a generated one-way function.
[0009] In some embodiments, the method further includes:
[0010] Obtain a second mapping, which is a one-to-one mapping and has the same independent variables as the first mapping;
[0011] The second ciphertext is obtained by performing encryption calculations using the first ciphertext as input plaintext and the mapping value of the second mapping as input key through the symmetric encryption algorithm.
[0012] The mapping relationship between the second ciphertext and the independent variable is used as a generated one-way function.
[0013] In some embodiments, the method further includes:
[0014] Obtain the Nth mapping, wherein the Nth mapping is a one-to-one mapping and the Nth mapping and the first mapping have the same independent variables;
[0015] The Nth ciphertext is obtained by performing encryption calculations using the plaintext as input and the mapping value of the Nth mapping as input key through the symmetric encryption algorithm.
[0016] If the current value of N is less than the preset value, increment N by 1 and return to the step of obtaining the Nth mapping; or, if the current value of N is equal to the preset value, use the mapping relationship between the current Nth ciphertext and the independent variable as a generated one-way function.
[0017] The initial value of N is 2, and the preset value is an integer value greater than 2.
[0018] On the other hand, embodiments of this application provide a method for using a symmetric encryption algorithm in an electronic device, wherein the electronic device is configured with a preset symmetric encryption algorithm, and the method includes:
[0019] The input data, the preset zeroth mapping, the first mapping, and the symmetric encryption algorithm are obtained; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0020] The zeroth mapping value is obtained by processing the input data through the zeroth mapping, and the first mapping value is obtained by processing the input data through the first mapping.
[0021] The symmetric encryption algorithm is used to perform encryption calculations on plaintext with the zeroth mapping value as input and the first mapping value as input key to obtain target ciphertext, which is then used as a one-way function value with respect to the input data.
[0022] In some embodiments, processing the input data through the first mapping to obtain the first mapping value includes:
[0023] Perform a target operation on the input data and a preset constant to obtain the first mapping value;
[0024] The target operation includes at least one of summation, difference, or XOR operation.
[0025] In some embodiments, processing the input data through the first mapping to obtain the first mapping value includes:
[0026] The input data is segmented to obtain multiple data segments; each data segment includes several bits of data content.
[0027] The data segments are reordered according to preset rules and combined to obtain the first mapping value.
[0028] On the other hand, embodiments of this application provide a system for generating one-way functions, the system comprising:
[0029] The first acquisition unit is used to acquire a preset symmetric encryption algorithm, a zeroth mapping, and a first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0030] The first processing unit is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input and the mapping value of the zeroth mapping as input, and the mapping value of the first mapping as input, to obtain the first ciphertext.
[0031] The first output unit is used to generate a one-way function with the mapping relationship between the first ciphertext and the independent variable as a function.
[0032] On the other hand, embodiments of this application provide a system for using a symmetric encryption algorithm, the system comprising:
[0033] The second acquisition unit is used to acquire input data, a preset zeroth mapping, a first mapping, and a symmetric encryption algorithm; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0034] The second processing unit is configured to process the input data through the zeroth mapping to obtain a zeroth mapping value, and to process the input data through the first mapping to obtain a first mapping value;
[0035] The second output unit is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input (the zeroth mapping value) and the key as input (the first mapping value), to obtain the target ciphertext, and to use the target ciphertext as a one-way function value with respect to the input data.
[0036] On the other hand, embodiments of this application provide an electronic device, including:
[0037] Symmetric encryption module;
[0038] At least one processor;
[0039] At least one memory for storing at least one program;
[0040] When the at least one program is executed by the at least one processor, the at least one processor performs the aforementioned method.
[0041] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program that is executed by a processor to implement the aforementioned method.
[0042] Details of one or more embodiments of this application are set forth in the following drawings and description. Other features, objects, and advantages of this application will become apparent from the specification, drawings, and claims. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following description is provided with accompanying drawings of the relevant technical solutions in the embodiments of this application or the prior art. It should be understood that the accompanying drawings described below are only for the purpose of clearly illustrating some embodiments of the technical solutions in this application. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.
[0044] Figure 1 is a schematic diagram of an implementation environment provided in an embodiment of this application;
[0045] Figure 2 is a flowchart illustrating a method for generating a one-way function according to an embodiment of this application;
[0046] Figure 3 is a schematic diagram illustrating the principle of constructing a one-way function according to an embodiment of this application;
[0047] Figure 4 is a flowchart illustrating another method for generating a one-way function provided in an embodiment of this application;
[0048] Figure 5 is a flowchart of a method for using a symmetric encryption algorithm provided in an embodiment of this application;
[0049] Figure 6 is a schematic diagram of a process for obtaining a first mapping value through a first mapping process according to an embodiment of this application;
[0050] Figure 7 is a schematic diagram of the principle of a first mapping provided in an embodiment of this application;
[0051] Figure 8 is a schematic diagram of the structure of a one-way function generation system provided in an embodiment of this application;
[0052] Figure 9 is a schematic diagram of the structure of a system using a symmetric encryption algorithm according to an embodiment of this application;
[0053] Figure 10 is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0054] The present application will be further described below with reference to the accompanying drawings and specific embodiments. The described embodiments should not be considered as limitations on the present application, and all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of the present application.
[0055] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0057] The terminology used in this application is described below.
[0058] 1) Mapping: One of the fundamental concepts in mathematics, it describes the relationship between elements in one set and elements in another set. Formally, let A and B be two sets. If there exists a rule f such that for every element a in set A, a unique element b in set B can be found to correspond to it according to rule f, then this rule f is called a mapping from set A to set B.
[0059] 2) One-to-one mapping (bijective mapping): also known as bijection, is a special type of mapping. For a mapping f from set A to set B, if any element b in set B is a mapping value obtained by f according to some element a in set A, and such a is unique, then the mapping f is a one-to-one mapping.
[0060] 3) Encryption and Decryption: The process of transforming understandable plaintext into incomprehensible ciphertext is called encryption, and the reverse process is decryption. Common encryption algorithms are symmetric encryption algorithms, which use the same key for both encryption and decryption.
[0061] 4) Block Ciphers and Stream Ciphers: Block cipher algorithms are a common type of symmetric encryption algorithm. They treat plaintext as fixed-length data blocks (called blocks, one or more) concatenated together and require specific operating modes. Block cipher algorithms (such as SM1, SM4, SM7) and their operating modes (such as ECB) are standardized by corresponding technical standards. Stream cipher algorithms, represented by the Chinese national standard ZUC, are another type of symmetric encryption algorithm that do not impose requirements on the length of the plaintext.
[0062] A one-way function is an important concept in cryptography. It is a mathematical function that is easy to compute but difficult to reverse engineer. Specifically, given an input value x, the output value y = f(x) can be easily computed using a one-way function f. However, if only the output value y is known, it is computationally infeasible to find the original input value x by reverse engineering (for example, it would require the computing power of a national computing center for thousands of years). Based on these characteristics, one-way functions have wide applications in the field of information security.
[0063] In related technologies, constructing one-way functions requires advanced and complex mathematical knowledge. For example, one-way functions can be constructed based on modular exponentiation over finite fields or dot product (also called scalar multiplication) over elliptic curves, but this method has a high computational cost. Hash functions are a special type of one-way function. In addition to their one-way nature, they also possess other useful properties, and related technical standards are mature. Therefore, in conventional applications, hash functions are usually used in scenarios where one-way functions are required (even if the other properties of hash functions besides one-wayness are not needed). In actual products, using hash functions requires introducing hash algorithm modules (whether in software or hardware), which may complicate the product and affect its cost and size.
[0064] In the field of information security, encryption algorithms used to protect data confidentiality are the most common cryptographic algorithms, among which symmetric encryption algorithms are typically used to protect business data. Table 1 below summarizes commonly used symmetric encryption algorithms.
[0065] Table 1
[0066] For symmetric encryption algorithms, the underlying principle can be summarized as c = E(k, p), where k is the key, p is the plaintext, and c is the ciphertext. For the encryption algorithm E, k, p, and c are all binary bit strings. A key of length |k| bits means there are a total of 2^k possible keys. |k| These _p_ bits constitute the so-called key space. Similarly, for block ciphers, a |p|-bit plaintext block means that there are a total of 2_p_bits of possible plaintext blocks.|p| These constitute what is known as plaintext space.
[0067] Currently, the most widely used symmetric encryption algorithm in China is SM4, described in the Chinese national standard GB / T 32907-2016, while internationally, AES-128, described in the American national standard FIPS 197, is more commonly used. Both are block ciphers: they divide business data into fixed-length binary bit blocks, encrypting (and decrypting) each block; each basic operation involves transforming the current plaintext block p into a ciphertext block c under the influence of the key k, denoted as c = E(k, p), where the key length |k| = 128 bits. Each encryption operation takes a plaintext block of length |p| = 128 bits as input and outputs a ciphertext block of length |c| = 128 bits (in a block cipher, |p| is always equal to |c|, called the block length, but not necessarily equal to |k|). It's easy to understand that plaintext usually needs to be padded to make its length an integer multiple of |p| before it can be processed by the block cipher algorithm. Stream ciphers, also symmetric encryption algorithms, do not require dividing the plaintext into fixed-length blocks and do not impose requirements on the plaintext length.
[0068] In practical applications, symmetric encryption algorithms are more common than hash algorithms, and are almost essential in cryptographic applications. Most products involving encryption applications deploy symmetric encryption modules such as block ciphers or stream ciphers. Therefore, in this embodiment, to save costs (R&D costs, product space, etc.), a one-way function is constructed by reusing symmetric encryption algorithms. Compared to related technical solutions that introduce hash algorithm modules, the technical solution in this embodiment adopts a locally sourced and flexibly reusable approach, which helps reduce the hardware and software costs of algorithm implementation. This is expected to allow cryptographic application products to occupy fewer storage units or dedicated cryptographic chips, thus enabling them to operate within a smaller physical space.
[0069] It is understood that the one-way function generation method and the symmetric encryption algorithm usage method provided in the embodiments of this application can be applied to any computer device with data processing and computing capabilities, and this computer device can be various terminals or servers. When the computer device in the embodiments is a server, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal can be a smartphone, tablet, laptop, or desktop computer, but it is not limited to these.
[0070] As shown in Figure 1, Figure 1 is a schematic diagram of the implementation environment for a method for generating a one-way function and a method for using a symmetric encryption algorithm provided in this application. Referring to Figure 1, the implementation environment includes at least one terminal 102 and a server 101. The terminal 102 and the server 101 can be connected via a network through wireless or wired means to complete data transmission and exchange.
[0071] Server 101 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0072] Additionally, server 101 can also be a node server in a blockchain network. Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms.
[0073] Terminal 102 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, IoT device, etc., but is not limited to these. Terminal 102 and server 101 can be directly or indirectly connected via wired or wireless communication, and this embodiment of the application does not impose any limitations.
[0074] Exemplarily, based on the implementation environment shown in Figure 1, this application embodiment provides a method for generating a one-way function and a method for using a symmetric encryption algorithm. The following description uses the application of this one-way function generation method and symmetric encryption algorithm in terminal 102 as an example. It is understood that this one-way function generation method and symmetric encryption algorithm usage method can also be applied to server 101, and this application does not limit this application. The terminal or server applying the one-way function generation method and symmetric encryption algorithm usage method is configured with a preset symmetric encryption algorithm.
[0075] It is understood that the implementation environment shown in Figure 1 is for illustrative purposes only and does not imply any limitation on the specific implementation environment involved in the method provided in this application.
[0076] Referring to Figure 2, Figure 2 shows a flowchart of a method for generating a one-way function according to an embodiment of this application. The method for generating a one-way function provided in this embodiment includes at least the following steps:
[0077] Step 210: Obtain a preset symmetric encryption algorithm, a zeroth mapping, and a first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0078] Step 220: Using the symmetric encryption algorithm, with the plaintext as input of the zeroth mapping value and the key as input of the first mapping value, perform encryption calculation to obtain the first ciphertext;
[0079] Step 230: Use the mapping relationship between the first ciphertext and the independent variable as a generated one-way function.
[0080] This application provides a method for generating one-way functions. Considering that symmetric encryption modules are frequently used in current cryptographic applications, the method in this application constructs one-way functions by simply reusing symmetric encryption algorithms. It does not require the introduction of a hash algorithm module or the use of complex mathematical methods to construct one-way functions, which can reduce the application cost of one-way functions and save on the expenses of related products.
[0081] Specifically, when applying the one-way function generation method provided in the embodiments of this application, it is necessary to obtain a preset symmetric encryption algorithm and two mappings. Here, the symmetric encryption algorithm can be the symmetric encryption algorithm used by the existing symmetric encryption module in the relevant system or product. The two mappings can be denoted as the zeroth mapping and the first mapping. The number of independent variables in the zeroth mapping and the first mapping is 1, and the independent variables of the two mappings are the same. Among them, the first mapping is a one-to-one mapping. This application does not limit the type of the zeroth mapping.
[0082] In this embodiment, the symmetric encryption algorithm is denoted as c = E(k, p). The zeroth mapping can be any pre-defined mapping from the key space of the symmetric encryption algorithm to the plaintext space of the symmetric encryption algorithm, denoted as g0(x); the first mapping can be a pre-defined one-to-one mapping from the key space of the symmetric encryption algorithm to the key space of the symmetric encryption algorithm, denoted as g1(x). For example, more specifically, the zeroth mapping can be g0(x) = 0, and the first mapping can be g1(x) = x.
[0083] Taking the first mapping g1(x) as an example, in some embodiments, the first mapping can be g1(x) = x + a, where a is a constant, truncating the lowest |x| bits of the calculation result, i.e., keeping the word length unchanged. For example, a can be decimal -1, which is all 1s in binary. In this way, when x is 1, g1(x) is equal to 0; when x is 0, g1(x) is equal to all 1s in binary; and when x is all 1s in binary, g1(x) is equal to decimal -2.
[0084] For example, in some embodiments, the first mapping can be g1(x) = x⊕a, where a is a constant and ⊕ is the XOR operation in computer computing. For example, a can be all 1s in binary, in which case g1(x) is the bitwise inversion of x. In this way, when x is -1 in decimal, g1(x) is equal to 0; when x is 0, g1(x) is equal to all 1s in binary; and when x is 1, g1(x) is equal to -2 in decimal.
[0085] Of course, it is understood that the above is only used to illustrate the zeroth mapping and the first mapping provided in the embodiments of this application. In actual applications, they can be flexibly set according to specific needs, and this application does not limit them.
[0086] In this embodiment, after obtaining the symmetric encryption algorithm, the zeroth mapping, and the first mapping, a one-way function can be generated based on them. For example, the mapping value of the zeroth mapping can be used as the plaintext input to the symmetric encryption algorithm, and the mapping value of the first mapping can be used as the key input to the symmetric encryption algorithm. The ciphertext output by the symmetric encryption algorithm is obtained through encryption calculation, and in this embodiment, it is denoted as the first ciphertext. Referring to Figure 3, which shows a schematic diagram of the principle of constructing a one-way function provided in this embodiment, in this embodiment, taking the aforementioned g0(x) and g1(x) as the zeroth mapping and the first mapping, the first ciphertext can be represented as E(g1(x), g0(x)). In this embodiment, the mapping relationship between the first ciphertext and the independent variable x can be used as a generated one-way function, which can be represented as y = E(g1(x), g0(x)).
[0087] It is understood that the one-way function generation method provided in this application embodiment generates a one-way function by providing a pre-defined zeroth mapping and a first mapping, based on the symmetric encryption algorithm used by the existing symmetric encryption module in the relevant system or product. Compared with the mode of introducing a hash algorithm module in related technical solutions, the technical solution in this application embodiment adopts a technical approach of using local resources and flexible reuse, which helps to reduce the hardware and software costs of algorithm implementation and is expected to enable cryptographic application products to occupy fewer storage units or dedicated cryptographic chips, thereby achieving implementation in a smaller physical space. Compared with the mode of using complex mathematical methods to construct one-way functions, the technical solution in this application embodiment is easier to implement and is conducive to improving the generation and use efficiency of one-way functions.
[0088] It should be noted that the one-way function generation method provided in this application embodiment is applicable to scenarios where symmetric encryption modules already exist in the relevant systems or products. Obviously, in cryptographic applications that do not originally involve symmetric encryption algorithms, it is impossible to reuse symmetric encryption algorithms to construct one-way functions. In this case, a hash algorithm module can be introduced as a one-way function, and this application does not impose any restrictions on this.
[0089] Specifically, referring to Figure 4, in some embodiments, the method further includes:
[0090] Step 410: Obtain the second mapping, which is a one-to-one mapping and has the same independent variable as the first mapping;
[0091] Step 420: Using the symmetric encryption algorithm, with the first ciphertext as the input plaintext and the mapping value of the second mapping as the input key, perform encryption calculation to obtain the second ciphertext;
[0092] Step 430: Use the mapping relationship between the second ciphertext and the independent variable as a generated one-way function.
[0093] In this embodiment, a symmetric encryption algorithm can be further used when constructing the one-way function. For example, in this embodiment, another mapping, namely the second mapping, can be obtained in advance. The second mapping is also a one-to-one mapping and has the same independent variable as the first mapping. After obtaining the first ciphertext, a symmetric encryption algorithm can be used, with the first ciphertext as the plaintext input to the symmetric encryption algorithm and the mapping value of the second mapping as the key input to the symmetric encryption algorithm, to perform encryption calculation again and obtain a new ciphertext, which can be recorded as the second ciphertext in this embodiment. Then, the mapping relationship between the second ciphertext and the independent variable can be used as a generated one-way function.
[0094] Similarly, in this embodiment, the second mapping can be a pre-defined one-to-one mapping from the key space of the symmetric encryption algorithm to the key space of the symmetric encryption algorithm, denoted as g2(x). Taking the aforementioned g0(x) and g1(x) as the zeroth mapping and the first mapping, respectively, the first ciphertext can be represented as E(g1(x), g0(x)), and the second ciphertext can be represented as E(g2(x), E(g1(x), g0(x))). At this time, the new one-way function can be represented as y = E(g2(x), E(g1(x), g0(x))). For example, if g0(x) = x⊕p, g1(x) = x+d, g2(x) = x⊕q (d, p, and q are constants), the one-way function can be represented as y = E(x⊕q, E(x+d, x⊕p)).
[0095] Of course, it is understood that the above is only used to illustrate the second mapping provided in the embodiments of this application. In actual applications, it can be flexibly set according to specific needs, and this application does not limit it.
[0096] Furthermore, it should be noted that the method in this embodiment can iteratively call a symmetric encryption algorithm to generate a one-way function. As a further extension of the aforementioned generation of a new one-way function based on the second mapping, this embodiment can further obtain a third mapping, a fourth mapping, a fifth mapping, etc., and generate corresponding one-way functions through nested logic. The second mapping, third mapping, fourth mapping, fifth mapping, etc., are mappings of the same category as the first mapping. Moreover, these mappings can be the same or different.
[0097] Specifically, in this embodiment, a preset value can be used as an indicator to mark the end of iterative calls to the symmetric encryption algorithm. That is, when the nested mapping reaches a preset threshold, the call to the symmetric encryption algorithm ends, and the mapping relationship between the currently obtained ciphertext and the independent variable is used as a generated one-way function. Its implementation process can be described as follows:
[0098] Obtain the Nth mapping, wherein the Nth mapping is a one-to-one mapping and the Nth mapping and the first mapping have the same independent variables;
[0099] The Nth ciphertext is obtained by performing encryption calculations using the plaintext as input and the mapping value of the Nth mapping as input key through the symmetric encryption algorithm.
[0100] If the current value of N is less than the preset value, increment N by 1 and return to the step of obtaining the Nth mapping; or, if the current value of N is equal to the preset value, use the mapping relationship between the current Nth ciphertext and the independent variable as a generated one-way function.
[0101] The initial value of N is 2, and the preset value is an integer value greater than 2.
[0102] In this embodiment, the encryption can begin with the second mapping, where N is 2. A symmetric encryption algorithm is used to perform encryption calculations based on the second mapping and the first ciphertext to obtain the second ciphertext. The value of N is then compared with a preset value, which can be any integer greater than 2, such as 4. If N is less than 4, it is incremented by 1 (N = N + 1), resulting in a new value of 3. The process then returns to obtain a new mapping, the third mapping. The requirements for the third mapping are similar to those for the second mapping and will not be elaborated here. The symmetric encryption algorithm is then used to perform encryption calculations based on the third mapping and the second ciphertext to obtain the third ciphertext. The current value of N is then compared with the preset value. If N is less than 4, it is incremented by 1 (N = N + 1), resulting in a new value of 4. The process then returns to obtain a new mapping, the fourth mapping. The requirements for the fourth mapping are similar to those for the second mapping and will not be elaborated here. The symmetric encryption algorithm performs encryption calculations based on the fourth mapping and the third ciphertext to obtain the fourth ciphertext. The current value of N is compared with the preset value. At this time, the value of N is equal to 4, so the call to the symmetric encryption algorithm can be ended. The mapping relationship between the fourth ciphertext and the independent variable is used as a generated one-way function.
[0103] It is understood that in the embodiments of this application, the size of the preset value can be flexibly set according to actual needs, and each mapping from the second mapping to the Nth mapping can be selected with reference to the aforementioned requirements and examples. This application does not impose any restrictions on this.
[0104] Referring to Figure 5, Figure 5 shows a flowchart of a method for using a symmetric encryption algorithm provided in an embodiment of this application. The method for using the symmetric encryption algorithm provided in this embodiment includes at least the following steps:
[0105] Step 510: Obtain input data, a preset zeroth mapping, a first mapping, and a symmetric encryption algorithm; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0106] Step 520: Obtain the zeroth mapping value by applying the zeroth mapping to the input data, and obtain the first mapping value by applying the first mapping to the input data;
[0107] Step 530: Using the symmetric encryption algorithm, with the plaintext as input (the zeroth mapping value) and the key as input (the first mapping value), perform encryption calculations to obtain the target ciphertext, and use the target ciphertext as a one-way function value with respect to the input data.
[0108] In this embodiment of the application, based on the aforementioned principle of generating one-way functions, a method for using a symmetric encryption algorithm is provided. This method can construct a one-way function based on the symmetric encryption algorithm used by the existing symmetric encryption module in the relevant system or product and the pre-set zeroth mapping and first mapping.
[0109] Specifically, in this embodiment, when it is necessary to use a one-way function to calculate the function value corresponding to the input data, the input data, two preset mappings, and a symmetric encryption algorithm can be obtained. Here, the symmetric encryption algorithm can be the symmetric encryption algorithm used by the existing symmetric encryption module in the relevant system or product. The two mappings can be denoted as the zeroth mapping and the first mapping. The number of independent variables in the zeroth mapping and the first mapping is 1, and the independent variables of the two mappings are the same. Among them, the first mapping is a one-to-one mapping. This application does not limit the type of the zeroth mapping. For examples of the zeroth mapping and the first mapping, refer to the foregoing embodiments for implementation.
[0110] In this embodiment, the zeroth mapping can be used to process the input data, and the result is denoted as the zeroth mapping value. Similarly, the first mapping can be used to process the input data, and the result is denoted as the first mapping value. The calculation order of the zeroth mapping and the first mapping is not limited in this application; the first mapping value can be calculated first, followed by the zeroth mapping value, or vice versa, or both mapping values can be calculated simultaneously. After obtaining the zeroth mapping value and the first mapping value, the zeroth mapping value can be used as the plaintext input to the symmetric encryption algorithm, and the first mapping value can be used as the key input to the symmetric encryption algorithm. Encryption calculations are then performed to obtain the corresponding ciphertext, which in this embodiment is denoted as the target ciphertext. The target ciphertext can then be used as a one-way function value related to the input data.
[0111] It is understood that the content of the above one-way function generation method embodiments is applicable to the usage method embodiments of this symmetric encryption algorithm. The specific functions implemented by the usage method embodiments of this symmetric encryption algorithm are similar to those of the above one-way function generation method embodiments, and the beneficial effects achieved are also similar to those achieved by the above one-way function generation method embodiments. Therefore, they will not be elaborated here.
[0112] Specifically, in some embodiments, processing the input data through the first mapping to obtain the first mapping value includes:
[0113] Perform a target operation on the input data and a preset constant to obtain the first mapping value;
[0114] The target operation includes at least one of summation, difference, or XOR operation.
[0115] As described above, the first mapping can be g1(x), which can be a target operation performed on the input data (i.e. x) and a preset constant. The operation method can include, but is not limited to, at least one of the following: summation operation, difference operation, or XOR operation. The result of the operation is the first mapping value.
[0116] Specifically, referring to Figure 6, in the embodiments of this application, the first mapping can also be some data processing rules. For example, in some embodiments, the method of processing the input data through the first mapping to obtain the first mapping value may include:
[0117] Step 610: Segment the input data into multiple data segments, each of which may include several bits of data content;
[0118] Step 620: Reorder each data segment according to a preset rule, and use the reordered data as the first mapping value. Of course, the data processing rule corresponding to the first mapping needs to be preset.
[0119] For example, suppose the input data is 128 bits, i.e., |x| = 128 bits. The input data is represented in bytes, denoted as x = x[1]x[2]x[3]x[4]...x
[0015] x
[0016] , where x[i] represents the i-th byte starting from the most significant bit, and x
[0016] is the least significant byte. The first mapping can be to group the input data in pairs of bytes and swap the two bytes in each group. For example, referring to Figure 7, which shows a schematic diagram of the principle of a first mapping provided in this application embodiment, in Figure 7, adjacent bytes can be grouped together, and the two bytes in each group can be swapped. The resulting first mapping value can be expressed as: g1(x) = x[2]x[1]x[4]x[3]...x
[0016] x
[0015]
[0120] Of course, it is understood that in the embodiments of this application, the first mapping of the input data segmentation and recombination does not need to be as neat and standardized as shown in Figure 7. For example, it can be segmented in units of bits, and the rules used during recombination can be flexibly set as long as they meet the requirements of one-to-one mapping. This application does not impose any restrictions on this. In some embodiments, after segmenting the input data to obtain multiple data segments, one or more of the data segments can be transformed, such as by adding a set constant, XORing with a set constant, etc., and then recombination is performed to obtain the first mapping value.
[0121] The technical solutions in this application help improve the output-input ratio and user experience of information security applications, generating positive economic and social benefits. Below, the technical solutions in the embodiments of this application are introduced and explained in conjunction with specific application scenarios.
[0122] Example 1
[0123] A certain company is an artificial intelligence enterprise. Its smart community solution uses cameras placed throughout the community to record video in real time and upload it to a central control server. The server uses AI algorithms to detect various predefined scenarios and send corresponding alarms. These scenarios include: an elderly person falling on a road or in a building corridor; a large flame appearing near a kitchen window; someone climbing over a wall or fence; cars parked in non-parking areas; fights or even armed fights occurring within the community; thick smoke in electric garages or elevators; non-small animals appearing in the community without leashes; objects being thrown from high-rise buildings; and young children walking alone from the community to an exit. To achieve the appropriate security level, all video recordings are encrypted during transmission and storage using the ZUC stream cipher algorithm, a standard in Chinese national standards.
[0124] It is inappropriate for any camera to always encrypt video with a fixed symmetric key and transmit it to the central control server. For example, assuming the symmetric key x is leaked to a hacker at time t, then even encrypted traffic intercepted by the hacker before time t can be decrypted. The standard approach to overcome this flaw is to update the key x. For example, at midnight every day, the camera processes the current key x using a pre-agreed one-way function f, replaces x with the calculated one-way function value f(x), and notifies the server accordingly. The server can then update its key and decrypt the traffic accordingly. In this way, even if a key is leaked, a hacker cannot reverse engineer an earlier key to decrypt previous traffic. Obviously, this is exactly the scenario considered in this application: the symmetric encryption module is already in place (here, the ZUC stream cipher algorithm in the Chinese national standard), and a new one-way function f is needed.
[0125] Applying the technical solution in this application, the company can specify an instance of ZUC as p = E(k,c); for stream ciphers like ZUC, this only requires fixing the initial vector (iv), for example, specifying iv as 128 bits all 1s. The formulas for specifying the zeroth mapping and the first mapping are g0(x) = g1(x) = x. Whenever the current key x needs to be replaced with a new f(x), x itself is encrypted using the current key x, resulting in f(x) = E(x,x) as the new version of the key. It is understandable that since x is the ZUC key for encrypting video traffic, |x| = 128 bits, and the ciphertext output by the stream cipher algorithm is the same length as the plaintext, therefore |f(x)| = |E(x,x)| is also 128 bits. Therefore, f(x) can be used as a new key to encrypt video traffic, and can be iteratively calculated and updated periodically (e.g., at midnight every day).
[0126] In other words, the one-way function generation method can be applied to data encryption and transmission scenarios. Therefore, some embodiments of this application also provide a data encryption and transmission method. In the data encryption and transmission method, after the one-way function is generated according to the one-way function generation method, electronic devices such as cameras can obtain the current key, use the current key as the input of the one-way function, and use the output value of the one-way function as the new current key. Then, the new current key is used to encrypt the data to be encrypted, and the encrypted data is transmitted.
[0127] Example 2
[0128] A certain information security company already has a well-selling product, a handheld smart mobile device. Its core function is to encrypt, decrypt, and send / receive sensitive data using a block cipher algorithm (SM1, SM4, or SM7) from the Chinese national standard. Based on customer needs research, the company plans to upgrade the product: adding support for password-based authentication, so that the product can also be used as an electronic key. The company hopes to complete this functional upgrade with minimal investment, rather than developing a new electronic key product like other companies in the industry. This strategy is easy to understand: the more devices users need to carry, the worse the user experience becomes.
[0129] Therefore, the company selected Lamport One-Time Password Protocol (or an improved version thereof) as its authentication protocol. The main features of this protocol are: each time a device sends authentication data to the authentication server, it is different (the so-called one-time password); there is a preset upper limit to the number of authentication attempts; and the core operation involved in this one-time password protocol is the iterative calling of a one-way function f.
[0130] Applying the technical solution in this application, the company can easily implement the one-way function f based on the existing block cipher algorithm without introducing the code or circuit of hash algorithms such as SM3 according to the conventional technical route. A possible specific embodiment is as follows: The user password is limited to a string containing at most 16 uppercase and lowercase letters, numbers, and special symbols. Each character is converted into 8 bits according to the ASCII code table. For those with less than 16 characters, they are filled with 8 zero bits per character at the end. In this way, the user password is converted into a 128-bit input x.
[0131] Specify the formula corresponding to the zero mapping as g0(x) = x + 1, that is, x is incremented by 1 and only the lower 128 bits of the result are retained. Specify the formula corresponding to the first mapping as g1(x) = x ⊕ 0x000102030405060708090A0B0C0D0E0F, that is, x is XORed with a 128-bit constant. Specify E as the existing block cipher algorithm, with the ECB working mode. First, calculate g0(x) and g1(x) respectively, and then calculate and output f(x) = E(g1(x), g0(x)).
[0132] It should be added that in the embodiments of this application, when the password consists only of ASCII characters, it is recommended that the password contain 15 or 16 characters. When the password also contains at least one Chinese character, the password can be appropriately shortened. For example, the GBK encoding includes a total of 21,000 commonly used Chinese characters, and each encoding is 16 bits. For example, the encoding of "科" is 0xBFC6, and the encoding of "学" is 0xD1A7. As long as the password掺入 with Chinese characters can be accommodated in 128 bits, it can be used as the input of f(x) = E(g1(x), g0(x)). For example, the hexadecimal encoding of "ABC科abc学123&\#" is 0x414243BFC6616263D1A7313233232425, with a length of 128 bits, which can better resist attacks.
[0133] That is to say, the method for generating the one-way function can also be applied to the identity authentication scenario. Among them, after an electronic device such as a handheld intelligent mobile device generates the one-way function according to the method for generating the one-way function, it obtains the user password, generates authentication data according to the user password according to the one-time password protocol, and then sends the authentication data to the server for the server to perform identity authentication. Among them, in the process of generating authentication data according to the one-time password protocol, the one-way function will be iteratively called to generate authentication data based on the user password.
[0134] Referring to FIG. 8, in the embodiments of this application, a system for generating a one-way function is further provided. The system includes:
[0135] The first acquisition unit 810 is used to acquire a preset symmetric encryption algorithm, a zeroth mapping, and a first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0136] The first processing unit 820 is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input and the mapping value of the zeroth mapping as input, and the mapping value of the first mapping as input, to obtain the first ciphertext.
[0137] The first output unit 830 is used to generate a one-way function with the mapping relationship between the first ciphertext and the independent variable.
[0138] Referring to Figure 9, this application embodiment also provides a system for using a symmetric encryption algorithm, the system comprising:
[0139] The second acquisition unit 910 is used to acquire input data, a preset zeroth mapping, a first mapping, and a symmetric encryption algorithm; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping;
[0140] The second processing unit 920 is configured to process the input data according to the input data through the zeroth mapping to obtain a zeroth mapping value, and to process the input data through the first mapping to obtain a first mapping value;
[0141] The second output unit 930 is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input to the zeroth mapping value and the key as input to the first mapping value, to obtain the target ciphertext, and to use the target ciphertext as a one-way function value with respect to the input data.
[0142] It is understood that the methods for using symmetric encryption algorithms in the above embodiments are applicable to the system using symmetric encryption algorithms in this embodiment. The specific functions implemented by the system in this embodiment are the same as those in the above embodiments, and the beneficial effects achieved are the same as those achieved by the methods in the above embodiments.
[0143] Referring to Figure 10, this application embodiment also provides an electronic device, including:
[0144] Symmetric encryption module 1010 is used to execute symmetric encryption algorithms;
[0145] At least one processor 1020;
[0146] At least one memory 1030 is used to store at least one program;
[0147] When at least one program is executed by at least one processor 1020, the at least one processor 1020 implements the above-described method for generating one-way functions or the method for using symmetric encryption algorithms.
[0148] In some embodiments, the memory 1030 also stores at least the programs corresponding to the zeroth mapping and the first mapping. When the at least one processor 1020 executes the above-described method for generating single functions or the method for using symmetric encryption algorithms, the memory calls the programs corresponding to the zeroth mapping and the first mapping.
[0149] In some embodiments, after executing the above-described one-way function generation method or the method of using a symmetric encryption algorithm, the at least one processor 1020 is further configured to: process the user-input data to be processed according to the one-way function or the value of the one-way function. The processing includes, but is not limited to, encryption, decryption, and identity authentication.
[0150] The electronic device in the embodiments of this application may be a terminal device, a computer device, or a server device.
[0151] Similarly, the methods described in the above embodiments are all applicable to the electronic device in this embodiment. The specific functions implemented by the electronic device in this embodiment are the same as those of the methods described in the above embodiments, and the beneficial effects achieved are also the same as those achieved by the methods described in the above embodiments.
[0152] This application also provides a computer-readable storage medium storing a program executable by a central processing unit (CPU). When executed by the CPU, the CPU-executable program is used to perform the aforementioned method for generating a one-way function or the method for using a symmetric encryption algorithm.
[0153] Similarly, the methods described in the above embodiments are all applicable to the computer-readable storage medium in this embodiment. The specific functions implemented by the computer-readable storage medium in this embodiment are the same as those in the above embodiments, and the beneficial effects achieved are also the same as those achieved by the methods in the above embodiments.
[0154] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this application are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and sub-operations described as part of a larger operation are executed independently.
[0155] Furthermore, although this application is described in the context of functional modules / units, it should be understood that, unless otherwise stated to the contrary, one or more of the functions and / or features may be integrated into a single hardware device and / or software module, or one or more functions and / or features may be implemented in a separate hardware device or software module. It is also understood that a detailed discussion of the actual implementation of each module / unit is unnecessary for understanding this application. Rather, given the properties, functions, and internal relationships of the various functional modules / units in the apparatus disclosed herein, the actual implementation of such modules / units will be understood within the realm of ordinary skill for an engineer. Therefore, those skilled in the art can implement the application set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of this application, which is determined by the full scope of the appended claims and their equivalents.
[0156] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0157] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0158] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0159] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0160] In the foregoing description of this specification, the references to terms such as "one embodiment," "another embodiment," or "some embodiments," etc., indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0161] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
[0162] The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. A method for generating a one-way function, applied in electronic devices, wherein, The electronic device is equipped with a preset symmetric encryption algorithm, and the method includes: Obtain the preset symmetric encryption algorithm, the zeroth mapping, and the first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping; The first ciphertext is obtained by performing encryption calculations using the symmetric encryption algorithm, with the plaintext as input of the zeroth mapping value and the key as input of the first mapping value. The mapping relationship between the first ciphertext and the independent variable is used as a generated one-way function.
2. The method for generating a one-way function according to claim 1, wherein, The method further includes: Obtain a second mapping, which is a one-to-one mapping and has the same independent variables as the first mapping; The second ciphertext is obtained by performing encryption calculations using the first ciphertext as input plaintext and the mapping value of the second mapping as input key through the symmetric encryption algorithm. The mapping relationship between the second ciphertext and the independent variable is used as a generated one-way function.
3. The method for generating a one-way function according to claim 1, wherein, The method further includes: Obtain the Nth mapping, wherein the Nth mapping is a one-to-one mapping and the Nth mapping and the first mapping have the same independent variables; The Nth ciphertext is obtained by performing encryption calculations using the plaintext as input and the mapping value of the Nth mapping as input key through the symmetric encryption algorithm. If the current value of N is less than the preset value, increment N by 1 and return to the step of obtaining the Nth mapping; or, if the current value of N is equal to the preset value, use the mapping relationship between the current Nth ciphertext and the independent variable as a generated one-way function. The initial value of N is 2, and the preset value is an integer value greater than 2.
4. A method for using a symmetric encryption algorithm in electronic devices, wherein, The electronic device is equipped with a preset symmetric encryption algorithm, and the method includes: The input data, the preset zeroth mapping, the first mapping, and the symmetric encryption algorithm are obtained; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping; The zeroth mapping value is obtained by processing the input data through the zeroth mapping, and the first mapping value is obtained by processing the input data through the first mapping. The symmetric encryption algorithm is used to perform encryption calculations on plaintext with the zeroth mapping value as input and the first mapping value as input key to obtain target ciphertext, and the target ciphertext is used as a one-way function value with respect to the input data.
5. A method of using a symmetric encryption algorithm according to claim 4, wherein, The step of processing the input data through the first mapping to obtain the first mapping value includes: Perform a target operation on the input data and a preset constant to obtain the first mapping value; The target operation includes at least one of summation, difference, or XOR operation.
6. A method of using a symmetric encryption algorithm according to claim 4, wherein, The step of processing the input data through the first mapping to obtain the first mapping value includes: The input data is segmented to obtain multiple data segments; each data segment includes several bits of data content. The data segments are reordered according to preset rules and combined to obtain the first mapping value.
7. A system for generating a one-way function, the system comprising: The first acquisition unit is used to acquire a preset symmetric encryption algorithm, a zeroth mapping, and a first mapping; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping; The first processing unit is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input and the mapping value of the zeroth mapping as input, and the mapping value of the first mapping as input, to obtain the first ciphertext. The first output unit is used to generate a one-way function with the mapping relationship between the first ciphertext and the independent variable as a function.
8. A system for using a symmetric encryption algorithm, the system comprising: The second acquisition unit is used to acquire input data, a preset zeroth mapping, a first mapping, and a symmetric encryption algorithm; wherein the zeroth mapping and the first mapping have a single and identical independent variable, and the first mapping is a one-to-one mapping; The second processing unit is configured to process the input data through the zeroth mapping to obtain a zeroth mapping value, and to process the input data through the first mapping to obtain a first mapping value; The second output unit is used to perform encryption calculations using the symmetric encryption algorithm, with the plaintext as input (the zeroth mapping value) and the key as input (the first mapping value), to obtain the target ciphertext, and to use the target ciphertext as a one-way function value with respect to the input data.
9. An electronic device, comprising: Symmetric encryption module; At least one processor; At least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the method as described in any one of claims 1-6.
10. A computer-readable storage medium storing a processor-executable program, which, when executed by a processor, is used to implement the method as described in any one of claims 1-6.