ID generation and protection method and system based on finite field matrix encryption
Patent Information
- Application Number
- CN202611200286.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-10
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2046-08-10
AI Technical Summary
雪花ID的结构中内嵌了时间戳和机器标识,攻击者可逆向解析出服务器时间、节点编号等信息,存在安全隐患;UUID则长度过长,在高频实时交互场景中,额外的传输与处理开销显著,难以满足游戏服务器高吞吐低延迟的要求
[0055] This invention maps the original ID to GF( After a 3D vector on GF(
On a finite field, a dynamically generated 3×3 encryption matrix and a round-related nonlinear S-box substitution table are used for multi-round iterative encryption. This ensures that the linear transformation matrix and nonlinear substitution mapping relationship in each round change dynamically with the round index. Attackers cannot recover the encryption matrix elements by collecting encrypted ID samples to construct cross-round difference features or solve fixed algebraic equations, thus achieving the inverse and unpredictability of the encrypted ID. At the same time, the length of the encrypted ID is consistent with the length of the original ID after 3D vector mapping, without introducing additional data inflation, ensuring low bandwidth overhead in high-frequency real-time interactive game scenarios. In addition, during the original ID generation stage, a format-preserving encryption operation based on the Feistel network is introduced to randomize the monotonically increasing offset, eliminating the numerical increment pattern of the original ID sequence from the source. This makes it impossible for attackers to use the continuity of the original ID for statistical analysis or to predict other legitimate IDs even if they intercept multiple encrypted ID samples, further enhancing the anti-statistical analysis and anti-prediction capabilities of the encrypted ID sequence.
Smart Images

Figure CN122717840B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of encryption technology, and particularly relates to an ID generation and protection method and system based on finite field matrix encryption. Background Technology
[0002] In online games and real-time online services, unique IDs such as character identifiers and item identifiers are core sensitive data. If auto-incrementing integers or plaintext IDs are used for storage and transmission, malicious users can traverse adjacent IDs or predict them based on generation patterns to massively scrape data or engage in cheating. Existing protection methods mainly use Snowflake IDs or Universally Unique Identifiers (UUIDs). Snowflake IDs embed timestamps and machine identifiers in their structure, allowing attackers to reverse engineer information such as server time and node number, posing a security risk. UUIDs, on the other hand, are too long, resulting in significant additional transmission and processing overhead in high-frequency real-time interaction scenarios, making it difficult to meet the high throughput and low latency requirements of game servers. Therefore, existing ID protection methods cannot simultaneously achieve irreversibility and anti-predictability while maintaining compact identifier length and low generation overhead. This leads to a trade-off between ID security and performance in high-frequency real-time interaction scenarios in games, leaving game object IDs vulnerable to traversal, reverse engineering, or prediction, failing to meet the business requirements of both lightweight design and high security. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention proposes an ID generation and protection method and system based on finite field matrix encryption. This method divides the original ID into multiple groups and maps each group to a Galois field GF(2). 8 A 3-dimensional vector on GF(2) 8 On a finite field, a matrix multiplication operation is performed on each group using a preset 3×3 encryption matrix to obtain a linear transformation result. Then, a preset nonlinear S-box substitution table is used to perform nonlinear byte substitution on each byte to obtain an obfuscation result. The obfuscation result is used as a new input vector for multiple rounds of iteration. The iteration results of each group are concatenated to generate an encrypted ID. This encrypted ID has the properties of being unreversible and unpredictable, and the identifier length is consistent with the original ID, which can balance lightweight and high security in high-frequency game interaction scenarios.
[0004] To achieve the above objectives, the present invention provides the following technical solution:
[0005] ID generation and protection methods based on finite field matrix encryption include:
[0006] Generate the original ID of the game object based on the server fragmentation identifier and offset;
[0007] The original ID is divided into multiple 3-byte groups, and each group is mapped to a Galois field GF( A 3-dimensional vector on )
[0008] In GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result;
[0009] Using a preset nonlinear S-box substitution table, nonlinear byte substitution is performed on each byte in the linear transformation result to obtain an obfuscated result;
[0010] Using the obfuscation result as a new input vector, the matrix multiplication operation and the nonlinear byte replacement are iterated multiple times to generate an encrypted ID.
[0011] Specifically, the original ID of the game object is generated, including:
[0012] Obtain the current server shard identifier and the current offset within that shard, where the offset is a monotonically increasing integer;
[0013] Using a preset bit width as the dividing unit, the offset is divided equally into binary bits to obtain a high-bit part and a low-bit part;
[0014] Using the lower-order part and the preset first-round key as input, the intermediate value is calculated through a preset round function;
[0015] Perform a bitwise XOR operation between the high-order part and the intermediate value to obtain the first XOR result;
[0016] The low-order part is used as the new high-order part, the first XOR result is used as the new low-order part, and the first round key is replaced as the next round key. The round function calculation and the XOR operation are repeated. After a preset number of iterations, the final high-order part and the low-order part are concatenated bit by bit to obtain the randomized offset.
[0017] Using the server fragment identifier as the high-order field and the randomized offset as the low-order field, and combining them according to a predetermined bit order, a fixed-width original ID is generated.
[0018] Specifically, each group is mapped to a Galois domain GF( A 3-dimensional vector on ) includes:
[0019] The original ID is divided into k bytes, each consisting of 8 bits, and is denoted as Byte[1] to Byte[k] in sequence.
[0020] The k bytes are divided into groups of 3 bytes each according to their byte index, resulting in m groups of 3 bytes each. If k is not a multiple of 3, one or more padding bytes with a value of 0x00 are added to the end of the original ID byte sequence, so that the total number of bytes L after padding is a multiple of 3, and m = L / 3 groups are obtained.
[0021] For each 3-byte block, arrange the 3 bytes within the block according to their byte index order and map them as GF( A 3D column vector on ).
[0022] Specifically, in the multiple iterations, the 3×3 encryption matrix used in each round is generated in the following manner, including:
[0023] Get the current iteration round index i, where i is an integer from 1 to the preset total number of rounds N, N≥2;
[0024] The round index i is concatenated with the preset master key, and the concatenation result is input into the SHA-256 hash function to obtain a 256-bit hash value;
[0025] The first 72 bits of the 256-bit hash value are extracted and divided into 9 bytes of 8 bits each, denoted as follows: .
[0026] Specifically, in the multiple iterations, the 3×3 encryption matrix used in each round is generated in the following manner, and also includes:
[0027] The 9 bytes are filled into a 3×3 matrix in row-first, column-second order, where These will be used as elements in the first, second, and third columns of the first row, respectively. These will be used as elements in the first, second, and third columns of the second row, respectively. These will be used as elements in the first, second, and third columns of the third row, respectively.
[0028] Iterate through each element in the filled 3×3 matrix. If the current element value is 0x00, replace the element with the preset non-zero constant 0x01; if the current element value is not 0x00, leave the element unchanged.
[0029] Calculate the 3×3 matrix in GF( The determinant value of the round index i is used; if the determinant is zero, the value of the round index i is incremented by 1, and the process of regenerating 9 bytes and constructing a matrix is repeated until a non-zero invertible matrix is obtained, which serves as the 3×3 encryption matrix used in the current round iteration, where each element is a GF( The non-zero elements in ).
[0030] Specifically, obtaining the linear transformation result includes:
[0031] The Galois domain GF( A 3D vector on a given surface is represented as a column vector. ;
[0032] Obtain the 3×3 encryption matrix M corresponding to the current iteration, and denote the elements of the encryption matrix M as... q=1,2,3, u=1,2,3, each All are GF( The non-zero elements in );
[0033] In the GF( On a finite field, perform the following operations in sequence:
[0034] The first row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the first result component. .
[0035] Specifically, obtaining the linear transformation result also includes:
[0036] The second row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the second result component. ;
[0037] The third row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Adding the components together yields the third component. ;
[0038] Will As the result of the linear transformation, where All are GF( Elements in ).
[0039] Specifically, obtaining obfuscated results includes:
[0040] Get the current iteration index i;
[0041] The binary representation of the round index i is concatenated with a preset 256-bit S-box generation key, and the concatenation result is input into the SHA-256 hash function to obtain the 256-bit current round S-box hash value.
[0042] Initialize a byte array S_box of length 256, and fill it with 0x00 to 0xFF in index order so that S_box[x] = x initially, where x represents the index of the byte array;
[0043] Using the current round S-box hash value as the initial seed, a preset deterministic pseudo-random number generator is input to generate a pseudo-random byte sequence.
[0044] Specifically, achieving obfuscated results also includes:
[0045] Fisher-Yates shuffling is performed on the array S_box to construct a bijective permutation. Specifically, index j is traversed from 255 down to 1. For each j, a uniformly random integer r in the range [0,j] is generated using a pseudo-random sequence. The contents of S_box[j] and S_box[r] are swapped. After all swaps are completed, the S-box replacement table used in the current round is obtained. The S-box replacement table is a bijective permutation on {0x00,…,0xFF}.
[0046] Extracting the results of linear transformation Each component in Using each component value as the lookup offset address, the corresponding replacement value is read from the current S-box replacement table, and then... Replace with S_box( ), Replace with S_box( ), Replace with S_box( );
[0047] The three replaced bytes are then rearranged in their original order to obtain the obfuscation result.
[0048] An ID generation and protection system based on finite field matrix encryption includes:
[0049] The AutoId generator is configured to generate the original ID of the game object based on the server fragment identifier and offset.
[0050] The vector mapping module is configured to: divide the original ID into multiple 3-byte groups, and map each group to a Galois field GF( A 3-dimensional vector on )
[0051] The matrix encryption engine is configured to: in GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result;
[0052] The S-box replacement module is configured to: use a preset nonlinear S-box replacement table to perform nonlinear byte replacement on each byte in the linear transformation result to obtain an obfuscated result;
[0053] The iterative encryption controller is configured to: use the obfuscation result as a new input vector and feed it back to the matrix encryption engine and the S-box replacement module, perform multiple rounds of iteration on the matrix multiplication operation and the nonlinear byte replacement, and generate an encrypted ID.
[0054] Compared with the prior art, the beneficial effects of the present invention are:
[0055] This invention maps the original ID to GF( After a 3D vector on GF( On a finite field, a dynamically generated 3×3 encryption matrix and a round-related nonlinear S-box substitution table are used for multi-round iterative encryption. This ensures that the linear transformation matrix and nonlinear substitution mapping relationship in each round change dynamically with the round index. Attackers cannot recover the encryption matrix elements by collecting encrypted ID samples to construct cross-round difference features or solve fixed algebraic equations, thus achieving the inverse and unpredictability of the encrypted ID. At the same time, the length of the encrypted ID is consistent with the length of the original ID after 3D vector mapping, without introducing additional data inflation, ensuring low bandwidth overhead in high-frequency real-time interactive game scenarios. In addition, during the original ID generation stage, a format-preserving encryption operation based on the Feistel network is introduced to randomize the monotonically increasing offset, eliminating the numerical increment pattern of the original ID sequence from the source. This makes it impossible for attackers to use the continuity of the original ID for statistical analysis or to predict other legitimate IDs even if they intercept multiple encrypted ID samples, further enhancing the anti-statistical analysis and anti-prediction capabilities of the encrypted ID sequence. Attached Figure Description
[0056] Figure 1 This is a flowchart of the ID generation and protection method based on finite field matrix encryption of the present invention;
[0057] Figure 2 This is a block diagram of the ID generation and protection system based on finite field matrix encryption of the present invention. Detailed Implementation
[0058] Example 1
[0059] Please see Figure 1 The present invention provides an embodiment of an ID generation and protection method based on finite field matrix encryption, comprising:
[0060] S1. Generate the original ID of the game object based on the server fragment identifier and offset, specifically:
[0061] S101. Obtain the current server shard identifier and the current offset within the shard, wherein the offset is a monotonically increasing integer; in this embodiment, the server shard identifier is a pre-allocated fixed shard ID, occupying 16 bits; the offset is a 32-bit monotonically increasing integer maintained within the shard, and the offset is the current value of an incrementing counter maintained within the shard. Each time a new character ID is generated, the incrementing counter is automatically incremented by 1 to ensure that the generated original ID is unique within the shard.
[0062] S102. Using a preset bit width as the dividing unit, the offset is divided equally into binary bits to obtain a high bit part and a low bit part. In this embodiment, the preset bit width is 16 bits, that is, the 32-bit offset is divided equally into binary bits from the middle, with the high 16 bits as the high bit part and the low 16 bits as the low bit part.
[0063] S103. Using the low-order part and the preset first round key as input, calculate the intermediate value through the preset round function. In this embodiment, the preset round function is the AES encryption function. Using the low-order part as plaintext input and the first round key as encryption key, perform an encryption operation through the AES encryption function, and extract the value of the bits of the same length as the low-order part from the operation result as the intermediate value.
[0064] S104. Perform a bitwise XOR operation between the high-order part and the intermediate value to obtain a first XOR result. In this embodiment, the 16-bit value of the high-order part and the 16-bit value of the intermediate value are XORed one by one according to the bit position. The XOR operation rule is: the same bit value is 0 and different bit value is 1, so as to obtain the first XOR result with the same length of 16 bits.
[0065] S105. The low-order part is used as the new high-order part, the first XOR result is used as the new low-order part, and the first round key is replaced as the next round key. The round function calculation and the XOR operation are repeated. After a preset number of iterations, the final high-order part and low-order part are concatenated bit by bit to obtain a randomized offset. In this embodiment, the preset number of rounds is 8 rounds. After each round, the left and right parts are swapped and the round key is updated. The next round key is generated by the current round key according to a preset key expansion algorithm. In this embodiment, the implementation logic of the next round key being generated by the current round key according to the preset key expansion algorithm is as follows: For the currently executing Feistel network, the first round key is... Round iteration: Taking the current round key (16 bytes) as input, it is divided into four words, denoted as W[0], W[1], W[2], and W[3], each word being 4 bytes; extract W[3], and perform a cyclic left shift operation of one byte on the four bytes of W[3] to obtain the shift word; perform AES standard S-box replacement on each byte of the shift word to obtain the replacement word; perform bitwise XOR operation between the replacement word and the round constant Rcon[r] corresponding to the current round to obtain the transform word T; and then perform the transformation... The key T is XORed bit by bit with W[0] to generate the first key W[4] of the next round; W[4] is XORed bit by bit with W[1] to generate the second key W[5] of the next round; W[5] is XORed bit by bit with W[2] to generate the third key W[6] of the next round; W[6] is XORed bit by bit with W[3] to generate the fourth key W[7] of the next round; W[4], W[5], W[6] and W[7] are concatenated in order to generate a 16-byte key for the next round.
[0066] After completing 8 rounds of Feistel network iterations, the final 16-bit high-order part and 16-bit low-order part are concatenated bit by bit in the order of high-order bits first and low-order bits last, resulting in a 32-bit randomized offset. This randomized offset is pseudo-randomly distributed within the same value range as the original monotonically increasing offset, and different offsets remain unique after this operation.
[0067] S106. Using the server fragment identifier as the high-order field and the randomized offset as the low-order field, combine them according to a predetermined bit order to generate a fixed-width original ID. In this embodiment, the server fragment identifier has a bit width of 16 bits, the randomized offset has a bit width of 32 bits, and the resulting original ID has a bit width of 48 bits.
[0068] As a concrete example, taking the game character creation scenario, in a game server cluster, shard 1 is assigned a server shard identifier ShardID=1 upon startup, whose 16-bit binary representation is 00000000000000001. When a new player creates a game character on shard 1, the current value of the auto-incrementing counter within that shard is 5000, meaning the current offset is 5000, whose 32-bit binary representation is 000000000000000000001001110001000. Dividing the shard into equal 16-bit units, the high 16 bits are 00000000000000000, and the low 16 bits are 0001001110001000. The preset 16-byte first-round key Key1 is then used, with the low 16 bits as... Plaintext input and Key1 as the encryption key are used. The AES encryption function is applied, and the first 16 bits of the result are extracted as an intermediate value. The high 16 bits are XORed bit-by-bit with this intermediate value to obtain the first XOR result. The low 16 bits are used as the new high-order part, and the first XOR result is used as the new low-order part, replacing the next round key Key2. This round function and XOR operation are repeated. After 8 rounds of iteration, the final high 16 bits and low 16 bits are concatenated bit-by-bit to obtain a 32-bit randomized offset, for example, 0xA7F3C091. The 16-bit server fragment identifier 0000000000000001 is used as the high-order field, and the 32-bit randomized offset 0xA7F3C091 is used as the low-order field. These are combined according to a predetermined bit order to generate a fixed-width 48-bit original ID, whose hexadecimal representation is 0x0001A7F3C091. The original ID eliminates the monotonically increasing pattern carried by the original offset of 5000, and the 48-bit width is exactly an integer multiple of 8. Therefore, no zero padding is needed when dividing it into bytes later, and it can be directly divided into 6 bytes.
[0069] S2. Divide the original ID into multiple groups of 3 bytes each, and map each group to a Galois field GF( A 3D vector on ) specifically includes:
[0070] S201. Divide the original ID into k bytes, each consisting of 8 bits, and denoted as Byte[1] to Byte[k]. The original ID is a binary string composed of the server fragment identifier and the randomized offset in a predetermined bit order, and its bit length is the sum of the number of bits of the fragment identifier and the number of bits of the randomized offset. When the total number of bits of the original ID is not a multiple of 8, zero bits are padded to its high-order bits to extend its total number of bits to the minimum multiple of 8, and then the zero-padded binary string is divided into 8 bytes. In this embodiment, the bit width of the server fragment identifier is 16 bits, the bit width of the randomized offset is 32 bits, and the bit width of the original ID obtained by combination is 48 bits. This bit width is a multiple of 8, so there is no need to pad with zeros, and it is directly divided into 6 bytes, k=6.
[0071] S202. Divide the k bytes into groups of 3 bytes each, according to their byte index, to obtain m groups of 3 bytes each. If k is not a multiple of 3, pad the end of the original ID's byte sequence with one or more padding bytes of value 0x00, making the total number of bytes L after padding a multiple of 3, and obtaining m = L / 3 groups. For each 3-byte group, arrange the 3 bytes within the group according to their byte index, mapping them to GF( The 3D column vectors on the array are used as input vectors. Each group serves as an independent input vector in subsequent matrix multiplication operations and nonlinear byte replacement iterations from S3 to S5. The encryption results of all m groups are concatenated in the order of the groups to form the encryption ID, with a total byte length of L. In this embodiment, k=6 is an integer multiple of 3, L=6, m=2, and the 6 bytes are directly divided into two 3D vectors according to the byte index order: the first vector... =[Byte[1],Byte[2],Byte[3]] T The second vector =[Byte[4],Byte[5],Byte[6]] T .
[0072] As a specific example, in the game character creation scenario of this embodiment, the server shard ID of shard 1 is ShardID=1, and its 16-bit binary representation is 0000000000000001. The 32-bit randomized offset obtained by preserving encryption in the Feistel network format is 0xA7F3C091. The 16-bit shard ID is used as the high-order field, and the 32-bit randomized offset is used as the low-order field. They are combined according to a predetermined bit order to obtain a 48-bit original ID, which is represented in hexadecimal as 0x0001A7F3C091. The 48-bit original ID is divided into 6 bytes of 8 bits each: Byte[1]=0x00, Byte[2]=0x01, Byte[3]=0xA7, Byte[4]=0xF3, Byte[5]=0xC0, Byte[6]=0x91. Since k=6 is an integer multiple of 3, the 6 bytes are directly divided into groups of 3 bytes each according to the byte index, resulting in m=2 groups: the first group is Byte[1] to Byte[3], i.e. [0x00,0x01,0xA7] T The second group consists of Byte[4] to Byte[6], namely [0xF3,0xC0,0x91]. T These two 3D column vectors are used as independent input vectors and sequentially fed into the subsequent encryption processes S3 to S5. After 10 rounds of matrix multiplication and S-box substitution iteration encryption, each group outputs a 3-byte encrypted vector. The two encrypted vectors are concatenated in the order of the groups to obtain an encrypted ID with a total length of 6 bytes. The bit length of this encrypted ID is strictly consistent with the bit length of the original ID, and the entire encryption process constitutes a GF( The bijective transformation on the ) ensures that different original IDs will necessarily be mapped to different encrypted IDs, thus guaranteeing global uniqueness while keeping the length unchanged.
[0073] In this embodiment, the specific implementation of the encryption of each group through 10 rounds of matrix multiplication and S-box replacement is as follows: each 3-byte group obtained from the original ID is mapped to GF( 3D column vector on ) As the first round input, where T is the transpose symbol; the rounds are iterated in ascending order with a preset total of 10 rounds. In the i-th round (i=1,2,…,10), the round index i is concatenated with the preset master key and then hashed using SHA-256. The first 72 bits are extracted and a 3×3 matrix is constructed in row-first-column order. Elements with a value of 0x00 are replaced with 0x01, and the determinant is verified to be non-zero, resulting in GF( A reversible 3×3 encryption matrix on GF( ); concatenate the round index i with the preset S-box generated key and then hash it using SHA-256. Use the resulting hash value as the seed to perform Fisher-Yates shuffling on the identity array S_box, constructing a bijective S-box replacement table on {0x00,…,0xFF}; in GF( Over a finite field, performing matrix multiplication on the input column vectors using the encryption matrix yields a linear transformation result. Each component is used as an index to look up the S-box replacement table and perform byte replacement to generate an obfuscated result. If i < 10, the obfuscated result is used as the input column vector for the next round of iteration. After 10 rounds, the final obfuscated result of the group is the encrypted output. The encrypted outputs of each group are concatenated in order to form an encrypted ID.
[0074] S3, in GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result;
[0075] It should be further explained that in the multiple iterations of this embodiment, the 3×3 encryption matrix used in each round is generated in the following manner, including:
[0076] S301. Obtain the round index i of the current iteration, where i is an integer from 1 to the preset total number of rounds N, and N≥2;
[0077] S302. Concatenate the round index i with the preset master key, and input the concatenation result into the SHA-256 hash function to obtain a 256-bit hash value;
[0078] S303. Extract the first 72 bits of the 256-bit hash value, divide it into 9 bytes of 8 bits each, and denot them as follows: ;
[0079] S304. Fill the 9 bytes into a 3×3 matrix in row-first, column-second order, where These will be used as elements in the first, second, and third columns of the first row, respectively. These will be used as elements in the first, second, and third columns of the second row, respectively. These will be used as elements in the first, second, and third columns of the third row, respectively.
[0080] S305. Traverse each element in the filled 3×3 matrix. If the current element value is 0x00, replace the element with the preset non-zero constant 0x01; if the current element value is not 0x00, keep the element unchanged.
[0081] S306. Calculate the 3×3 matrix in GF( The determinant value of the matrix is calculated; if the determinant is zero, the matrix is not invertible. In this case, the value of the current round index i is incremented by 1, and the process returns to step S301. Nine bytes are re-derived based on the updated round index to construct the matrix, until a non-zero invertible encrypted matrix is obtained. The resulting invertible encrypted matrix is used for the linear transformation in this round, ensuring that the transformation is GF( The bijection on the output vector allows the input vector to be uniquely recovered from the output during decryption.
[0082] It should be further explained that, in this embodiment, obtaining the linear transformation result includes:
[0083] S307, the Galois domain GF( A 3D vector on a given surface is represented as a column vector. ,in All are GF(2) 8 The elements in ); in this embodiment, the column vector This represents a 3-byte block to be encrypted in the current round, where These are the first, second, and third byte values within the group, arranged in byte index order. Each value is defined in the Galois field GF( The elements on the array (i.e., a byte from 0x00 to 0xFF) are taken directly from the three consecutive bytes of the original ID after grouping and mapping in the first iteration; in subsequent iterations, they correspond to the three bytes of the previous round's obfuscation result and continue to be used as the input for the matrix multiplication operation in this round.
[0084] S308. Obtain the 3×3 encryption matrix M corresponding to the current iteration, where the elements of the encryption matrix M are denoted as... q=1,2,3, u=1,2,3, each All are GF( The non-zero elements in );
[0085] S309, in the GF( On a finite field, perform the following operations in sequence:
[0086] S3091, the first row elements of the encryption matrix M are... The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the first result component. ;
[0087] S3092, the second row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the second result component. ;
[0088] S3093, the third row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Adding the components together yields the third component. ;
[0089] S3094, will As the result of the linear transformation, where All are GF( Elements in ).
[0090] As a concrete example, the GF( ) obtained by mapping The three components of the 3D vector W take the following values in order: =0x3F、 =0xA2、 =0x7B. The process of generating the encryption matrix and calculating the linear transformation is explained for the first iteration (round index i=1). The master key is preset to a fixed 16-byte value. The string "1" at round index i=1 is concatenated with this master key and input into the SHA-256 hash function to obtain a 256-bit hash value. The first 72 bits are truncated and divided into 9 bytes, which are then... =0x2A、 =0x00、 =0xF3、 =0x8C、 =0x1E、 =0x00、 =0x4D、 =0xB7、 =0x09. After filling the matrix into a 3×3 matrix by row-first, then column-second order, iterate through each element. =0x00 should be replaced with 0x01. =0x00 is replaced with 0x01, and the rest remain unchanged, resulting in the first round of 3×3 encryption matrix M1. Its first row is [0x2A,0x01,0xF3], the second row is [0x8C,0x1E,0x01], and the third row is [0x4D,0xB7,0x09]. Each element is GF(2). 8 Non-zero elements in GF( ); calculate the matrix in GF( ) The determinant of the matrix is verified to be non-zero, indicating that the matrix is invertible. Representing the 3D vector W as a column vector [0x3F, 0xA2, 0x7B]ᵀ, the determinant of the matrix in GF( Perform matrix multiplication M1·W over a finite field, according to GF( The multiplication and addition rules yield the following result component: =0x3B, second result component =0x9E, third result component =0xD7; This yields the column vector [0x3B,0x9E,0xD7]ᵀ of the first round of linear transformation. In this embodiment, GF( The rules for multiplication and addition over a finite field GF( ) are common knowledge in the field and are well known to those skilled in the art. In this invention, addition is defined as a bitwise XOR operation; multiplication is defined as polynomial multiplication under specific irreducible polynomial constraints. Its standard implementation is the polynomial multiplication of two bytes followed by modulo reduction of the irreducible polynomial, as used in this invention. Those skilled in the art will understand the implications of the GF(...) disclosed in this invention. A finite field and an irreducible polynomial can directly determine GF( The specific operational rules for multiplication and addition do not require any creative effort.
[0091] S4. Using a preset nonlinear S-box replacement table, perform nonlinear byte replacement on each byte in the linear transformation result to obtain an obfuscated result, specifically as follows:
[0092] S401. Obtain the round index i of the current iteration. In this embodiment, the round index i is used to identify the current iteration's position in a total of 10 iterations. When the first iteration is executed, i is 1; in the second iteration, i is 2; and so on, until the tenth iteration, i is 10. The value of this round index i is maintained and incremented by the iteration encryption controller before each iteration to ensure that the i value obtained in each iteration strictly corresponds to the current actual round.
[0093] S402. The binary representation of the round index i is concatenated with a preset 256-bit S-box generation key. The concatenation result is input into the SHA-256 hash function to obtain a 256-bit hash value for the current round S-box. In this embodiment, the binary representation of the round index i is in the binary form of a 32-bit specific-length integer, that is, the value of i is encoded in 32 bits. The preset 256-bit S-box generation key is a fixed key value generated by a secure random number generator and stored in the key management module during the system initialization phase. The concatenation method is as follows: the 32-bit round index binary representation is placed in the high-order bits, and the 256-bit S-box generation key is placed in the low-order bits. The two are concatenated end to end to form a 288-bit concatenated data. This 288-bit concatenated data is input into the SHA-256 hash function for one-way hash operation, and a 256-bit hash value is output. This hash value is used as the hash value for the current round S-box for the generation of subsequent S-boxes.
[0094] S403. Initialize a byte array S_box of length 256, and fill it with 0x00, 0x01, ..., 0xFF in index order, so that S_box[x] = x initially, where x represents the index of the byte array; in this embodiment, the index of the array S_box is from 0 to 255, and the value stored at each index position is equal to the index value, that is, S_box[0] = 0x00, S_box[1] = 0x01, ..., S_box
[255] = 0xFF. At this time, S_box defines an identity mapping from the set {0x00, 0x01, ..., 0xFF} to itself, which will be transformed into a bijective permutation by random shuffling later.
[0095] S404. Using the current round S-box hash value as the initial seed, a preset deterministic pseudo-random number generator is input to generate a pseudo-random byte sequence. The pseudo-random number generator uses a hash-value-based keystream generation method to ensure that the same hash value generates the exact same random sequence. In this embodiment, the deterministic pseudo-random number generator uses the current round S-box hash value as the initial internal state and outputs a pseudo-random byte stream through iterative calculation. For the same input seed, the byte sequence generated by the pseudo-random number generator is exactly the same each time, thereby ensuring that the S-box replacement table generated in each round is consistent during encryption and decryption, and the decryptor can uniquely restore the encryption process.
[0096] S405. Perform Fisher-Yates shuffling on the array S_box to construct a bijective permutation: Let index j traverse downwards from 255 to 1. For each j, generate a uniformly random integer r in the range [0,j] using a pseudo-random sequence, and swap the contents of S_box[j] and S_box[r]. In this embodiment, the specific execution process of the Fisher-Yates shuffling is as follows:
[0097] Step 1: Let j=255, extract enough bits from the pseudo-random byte sequence to construct a random integer r in the range [0,255], and swap the values of S_box
[255] and S_box[r].
[0098] Step 2, let j=254, continue to extract bits from the current reading position of the pseudo-random byte sequence to construct a random integer r in the range of [0,254], and swap the values of S_box
[254] and S_box[r];
[0099] And so on, until j=1, extract bits from the pseudo-random byte sequence to construct a random integer r in the range [0,1], and swap the values of S_box[1] and S_box[r].
[0100] In the above process, the generation of the random integer r uses a modulo operation to achieve a uniform distribution: if the current pseudo-random byte value is B, then r = Bmod(j+1); if the bytes in the pseudo-random sequence are insufficient to complete all shuffling operations, subsequent bytes are obtained from the deterministic pseudo-random number generator until all 255 exchanges are completed. In this embodiment, mod represents the modulo operation, that is, calculating the non-negative integer remainder obtained by dividing the pseudo-random byte value B by (j+1), and using this remainder as the random index r in subsequent shuffling and exchange operations.
[0101] S406. After all swaps are completed, the resulting array S_box is the S-box replacement table used in the current round. This table is a bijective permutation on {0x00, 0x01, ..., 0xFF}. In this embodiment, the bijective permutation means that the 256 byte values stored in S_box each appear exactly once from 0x00 to 0xFF. That is, the replacement table defines a one-to-one mapping from the byte set to itself: for any two different input bytes z1 ≠ z2, its replacement value S_box(x1) ≠ S_box(x2); for any output byte y ∈ {0x00, ..., 0xFF}, there exists a unique input byte z such that S_box(z) = y. This ensures the reversibility of the nonlinear byte replacement, and the byte values before replacement can be uniquely recovered by constructing the inverse S-box replacement table during decryption. Because the round index i is different in different rounds, the hash value of the S-box generated by the SHA-256 hash function for the current round is also different. This leads to different hash values as initial seeds, different pseudo-random sequences, and different shuffling results. Ultimately, this ensures that the S-box replacement tables generated in each round are different in terms of byte replacement mapping relationships. The S-boxes between rounds are independent of each other, and it is impossible to infer the S-box structure of other rounds from the S-box structure of one round. In this embodiment, z represents the input byte argument in the S-box replacement operation, and its value range is the set {0x00,…,0xFF}. This statement means: for any byte value y in the output set, there must exist a unique byte value z in the input set such that when z is used as input to look up the table, the output obtained is exactly equal to y, that is, S_box(z)=y.
[0102] S407. Extract the results of the linear transformation. Each component in Using each component value as the lookup offset address, the corresponding replacement value is read from the current S-box replacement table, and then... Replace with S_box( ), Replace with S_box( ), Replace with S_box( In this embodiment, the linear transformation result This is the 3D column vector output by S3094. All are GF( The elements in the table are each 1 byte in size and have a value range of 0x00 to 0xFF. The byte value of r1 is used as the lookup offset address. The byte value stored at that offset address is read from the current round S-box replacement table generated by S406, denoted as S_box( ), using S_box( Replace the original Value; similarly, with S_box is obtained by reading the offset address. ) and replace ,by S_box is obtained by reading the offset address. ) and replace During the replacement process, the read and write operations of each component are performed independently and do not affect each other.
[0103] S408. Arrange the three replaced bytes in their original order to obtain the obfuscation result. In this embodiment, the three replaced bytes are S_box( ), S_box( ), S_box( ), and arrange them in the original component order Corresponding position Corresponding position The corresponding positions are arranged in order to form a new 3D column vector [S_box( ),S_box( ),S_box( )] T This 3D column vector represents the confusion result of the current round. This confusion result will be used as the input vector for the next iteration, passed into S307 and re-represented as follows: The next round of encryption matrix multiplication and non-linear byte substitution is then performed. After all 10 rounds of iteration are completed, the obfuscated result of the last round is the three-byte component of the final encrypted ID, which is concatenated in the same order and used as the encrypted ID for game operations.
[0104] In this embodiment, based on the example of the first iteration in the game character creation scenario, the column vector of the first round of linear transformation result is [0x3B, 0x9E, 0xD7]. TThe first round of nonlinear byte replacement process will now be explained in detail. It should be noted that the hash input for generating the S-box is the concatenation of the round index and the S-box generation key, which is different from the hash input for generating the encryption matrix (the concatenation of the round index and the master key). Therefore, even if the round index i is 1, the hash values generated by the two are completely different. The current round index i=1 is concatenated with its 32-bit binary representation (000000000000000000000000000001) and the preset 256-bit S-box generation key, and then input into the SHA-256 hash function to obtain the 256-bit S-box hash value of the current round. For ease of explanation, it is assumed that the hexadecimal representation of the first 16 bytes of this hash value is 0xA3,0x7F,0x12,0x9C,0x4B,0x0E,0x8D,0x56,0xF1,0x2A,0x3C,0x78,0x05,0xE9,0xBD,0x60. This hash value is used as the initial seed to input into the deterministic pseudo-random number generator to generate a pseudo-random byte sequence, assuming that its first few bytes are the aforementioned hash value bytes themselves. According to S403 to S405, initialize the S_box array so that S_box[x] = x (x = 0, 1, ..., 255), and then perform the Fisher-Yates shuffle: when j = 255, take the byte 0xA3 = 163, calculate r = 163 mod 256 = 163, and swap S_box
[255] and S_box
[163] ; when j = 254, take the byte 0x7F = 127, calculate r = 127 mod 255 = 127. Swap S_box
[254] with S_box
[127] ; when j=253, take byte 0x12=18, calculate r=18mod254=18, and swap S_box
[253] with S_box
[18] ; and so on, consume pseudo-random bytes one by one from j=252 to 1 to calculate r and perform swaps. If the pseudo-random sequence is exhausted, continue to obtain subsequent bytes from the pseudo-random number generator until all 255 swaps are completed, and obtain the S-box replacement table for the current round. According to S407, using the three components r1=0x3B (decimal 59), r2=0x9E (decimal 158), and r3=0xD7 (decimal 215) of the linear transformation result as the lookup table offset addresses, under the given assumption of the shuffle result, let S_box
[59] =0x8A, S_box
[158] =0xB6, and S_box
[215] =0x4F after shuffling. Then, S_box(0x3B)=0x8A, S_box(0x9E)=0xB6, and S_box(0xD7)=0x4F. After replacing the three components one by one and arranging them in the original order, the first round of confusion result [0x8A, 0xB6, 0x4F] is obtained. TThe obfuscation result is then used as the input vector for the second round of iteration. Let v1=0x8A, v2=0xB6, and v3=0x4F. Return to S307 to reconstruct the column vector and perform the second round of encryption matrix generation (derive 9 bytes based on the round index i=2, and obtain the second round encryption matrix after non-zeroing and determinant invertibility verification), matrix multiplication, and S-box byte replacement. This process continues until all 10 rounds of iteration are completed. The obfuscation result of the last round is the encrypted output of the block.
[0105] S5. Using the obfuscation result as a new input vector, perform multiple iterations on the matrix multiplication operation and the nonlinear byte replacement to generate an encrypted ID, specifically:
[0106] S501. Obtain the preset total number of rounds N, and determine whether the number of iterations completed so far has reached N.
[0107] In this embodiment, the preset total number of rounds N=10. An iteration counter `round` is set, with an initial value of 1. After each round of matrix multiplication and nonlinear byte replacement, the value of `round` is incremented by 1. When `round` ≤ N, the iteration continues; when `round` > N, the iteration terminates and proceeds to S503.
[0108] S502. If the number of iterations completed so far has not reached N, then use the confusion result obtained in the current iteration as the input vector for the next iteration and return to execute S307.
[0109] In this embodiment, let's assume the current round is the _th round. After steps S407 to S408, the obfuscation result [S_box(r1), S_box(r2), S_box(r3)] is obtained. T Then, increment the round value by 1, and use the three bytes from the obfuscation result as the new v1, v2, and v3 respectively, returning to S307 to reconstruct the column vector [v1, v2, v3]. T The next round of encryption matrix generation, matrix multiplication, and non-linear byte substitution is performed in the order of S308 to S408. Loop control is achieved between each iteration by comparing the round counter with N, until the loop ends when round > N.
[0110] S503. If the number of iterations completed so far reaches N, then the obfuscation result obtained in the last iteration is output as the encrypted ID.
[0111] S504. When the original ID is divided into m groups, each group is independently encrypted using iterations S3 to S5, resulting in m 3-byte encrypted vectors. These m encrypted vectors are then concatenated in group order to form the final encrypted ID. During decryption, the encrypted ID is divided into m groups of 3 bytes each. Each group is decrypted sequentially, and any trailing padding bytes are removed to uniquely recover the original ID. The entire encryption process constitutes GF( The bijective transformation on the bitmap ensures that different original IDs are necessarily mapped to different encrypted IDs, achieving global uniqueness while maintaining the same bit length.
[0112] The encrypted ID is irreversible and unpredictable, and its bit length is strictly consistent with that of the original ID. In a preferred embodiment, the original ID is 48 bits and the encrypted ID is also 48 bits, without introducing additional data inflation.
[0113] In this embodiment, the decryption process of the encrypted ID uses the same key system and parameter generation mechanism as the encryption process. By executing the decryption operations in reverse order, the original ID can be uniquely recovered from the encrypted ID. Specifically:
[0114] During decryption, first, the encrypted ID to be decrypted is obtained, and the total byte length of the encrypted ID is L; the encrypted ID is divided into m groups of 3 bytes each, where m = L / 3; for each 3-byte group, the 3 bytes within the group are arranged in byte index order to form GF( The 3D column vector on the array is used as the decryption input vector. For each group's decryption input vector, a decryption iteration with a preset total number of rounds N=10 is performed. The decryption operations in each round are performed in order of decreasing round index from N to 1: For the i-th round of decryption (i=N,N-1,…,1), the same round index i as the i-th round of encryption is used to generate the same 3×3 encryption matrix M_i and S-box substitution table S_box_i as the i-th round of encryption. The encryption matrix M_i is obtained by SHA-256 hashing of the round index i and the master key, followed by non-zeroing and determinant reversibility verification. The S-box substitution table S_box_i is obtained by SHA-256 hashing of the round index i and the S-box generation key, followed by Fisher-Yates shuffling to construct a bijective permutation. Based on this, the inverse S-box substitution table S_box_i is first constructed from the S-box substitution table S_box_i. -1 The inverse S-box substitution table is constructed as follows: for each byte value x∈{0x00,…,0xFF}, let S_box_i -1[S_box_i[x]]=x, and the resulting inverse S-box substitution table is also a bijective permutation on {0x00,…,0xFF}; for each byte of the current decryption input vector, use the value of each byte as the lookup offset address, and retrieve the values from the inverse S-box substitution table S_box_i -1 The replacement value at the corresponding position is read to complete the inverse S-box byte replacement. Then, in GF(2... 8 ) Calculate the inverse matrix M_i of the encryption matrix M_i over a finite field. -1 Using the inverse matrix M_i -1 Perform matrix multiplication on the vector after inverse S-box replacement to obtain the decryption output vector for this round, which serves as the input vector for the next decryption iteration. After completing all N rounds of decryption iterations, the plaintext 3D vector of the block is obtained. Concatenate the decryption results of all m blocks in the order of the blocks, and remove any padding bytes with a trailing value of 0x00 that may have been added during encryption to completely recover the original ID.
[0115] In this embodiment, since the encryption matrix M_i in each round of the encryption process is verified to be an invertible matrix by the non-zero determinant, and the S-box substitution table S_box_i in each round is a bijective permutation, each step of the above decryption process can be uniquely and definitively executed. The decryption output and the original input form a one-to-one correspondence without ambiguity, thereby ensuring the bijective mapping relationship between the encrypted ID and the original ID.
[0116] In this embodiment, taking a game item drop scenario as an example, a certain instance shard in the game server cluster needs to generate a globally unique item ID for the rare equipment dropped after defeating a boss monster. The server shard identifier for this instance shard is ShardID=3, and its 16-bit binary representation is 00000000000000011; the current value of the auto-incrementing counter within the shard is 128, i.e., the current offset is 128. After 8 rounds of Feistel network format-preserved encryption operations, a 32-bit randomized offset is obtained, for example, 0x3B8E4D2A; combining the 16-bit shard identifier with the 32-bit randomized offset yields a 48-bit original ID, which is divided into 6 bytes and then into two 3-dimensional vectors in groups of 3 bytes each. Each group independently performs 10 rounds of iterative encryption. The 3×3 encryption matrix used in each round is derived from the round index and the master key using SHA-256 hashing, non-zeroing processing, and determinant reversibility verification before being used in GF( The matrix multiplication transformation is performed on the matrix. The S-box replacement table for each round is generated by SHA-256 hashing the round index and the S-box generation key, followed by a bijective permutation constructed using Fisher-Yates shuffling. This table is used to perform non-linear replacements on each byte of the linear transformation result. The encrypted results of each group are concatenated to obtain a 6-byte encrypted ID, which serves as the unique identifier for this rare equipment in the game database and client communication protocol. The protection of this scheme lies in the following: even if an attacker obtains multiple encrypted item ID samples by repeatedly killing the same instance boss, the original offset generation stage is randomized by the Feistel network to eliminate the auto-incrementing pattern; each group independently performs multiple rounds of iterative encryption with the encryption process being a bijective transformation; the encryption matrix in each round is verified for reversibility to ensure the transformation is reversible; and the S-box replacement table in each round is shuffled to construct a bijective permutation to ensure a one-to-one mapping. Therefore, the attacker cannot deduce the original auto-incrementing offset from the encrypted ID sequence, nor can they recover the mapping relationship between the encryption matrix and the S-box through differential analysis or algebraic attacks. This ensures the unpredictability and irreversibility of item IDs, effectively preventing cheating behavior of bulk scraping game item data through ID traversal.
[0117] This embodiment addresses the technical challenge of balancing ID security and performance in high-frequency real-time game interaction scenarios. Through a multi-layered security mechanism design, it achieves lightweight, unreverse-decryption, and unpredictable ID protection. In the original ID generation stage, a Feistel network-based format is used to preserve the encryption operation and randomize the monotonically increasing offset. Multiple iterations using round functions and bitwise XOR are used instead of directly using auto-incrementing values, eliminating the numerical increment pattern of the original ID sequence at its source. Even if an attacker intercepts multiple encrypted ID samples, they cannot use the continuity of the original ID to make statistical inferences or predict other legitimate IDs, thus enhancing the encryption ID sequence's resistance to statistical analysis. In the original ID mapping stage, a 3-byte grouping method is used, with each group independently performing subsequent encryption. The encryption result remains 3 bytes, and the total byte length is strictly consistent with the number of bytes in the original ID after padding. This constitutes a GF(2) structure while maintaining the same bit length. 8 The bijective transformation on GF(2) ensures global uniqueness. In the multi-round iterative encryption phase, the 3×3 encryption matrix used in each round is derived from the round index and the master key via SHA-256 hashing, and undergoes non-zeroing processing and determinant invertibility verification to ensure that the linear transformation in each round is GF(2). 8The encryption method employs a reversible bijective over a given period. The S-box substitution table used in each round is generated by SHA-256 hashing of the round index and the S-box generation key, followed by a Fisher-Yates shuffle to construct a bijective permutation, ensuring a one-to-one mapping for non-linear byte substitutions. Both dynamically change with the round index, disrupting the continuity of cross-round difference features and the structural consistency of the fixed algebraic equation system. This prevents attackers from recovering the encryption matrix or S-box mapping by collecting encrypted ID samples, thus achieving the unreversible and unpredictable nature of the encrypted ID. The entire encryption process groups the original ID into 3-byte blocks and performs multiple rounds of matrix multiplication and byte substitution. The bit length of the encrypted ID is strictly consistent with the bit length of the original ID, without introducing any additional data inflation, ensuring low bandwidth overhead and high processing efficiency in high-frequency real-time interactive game scenarios. The randomization process in the original ID generation stage, the grouped bijective design in the mapping stage, the round-related dynamic transformation of the invertible matrix and bijective S-box in the iterative encryption stage, and the fixed-length output design throughout the process work together to form a closed-loop protection system for the entire lifecycle from ID generation to encrypted output. Under the constraints of compact identifier length and low generation overhead, it achieves the security goals of irreversibility and anti-predictability, solves the security risks of game object IDs being traversed, reverse parsed, or predicted in existing technologies, and meets the business needs of lightweight and high security.
[0118] Example 2
[0119] Please see Figure 2 Another embodiment of the present invention provides: an ID generation and protection system based on finite field matrix encryption, comprising:
[0120] The AutoId generator is configured to generate the original ID of the game object based on the server fragment identifier and offset.
[0121] The vector mapping module is configured to: divide the original ID into multiple 3-byte groups, and map each group to a Galois field GF( A 3-dimensional vector on )
[0122] The matrix encryption engine is configured to: in GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result;
[0123] The S-box replacement module is configured to: use a preset nonlinear S-box replacement table to perform nonlinear byte replacement on each byte in the linear transformation result to obtain an obfuscated result;
[0124] An iterative encryption controller is configured to: use the obfuscation result as a new input vector and feed it back to the matrix encryption engine and the S-box replacement module, perform multiple rounds of iteration on the matrix multiplication operation and the nonlinear byte replacement, and generate an encrypted ID; wherein the encrypted ID is irreversible and unpredictable, and the identifier length is consistent with the original ID.
[0125] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments under the guidance of the present invention without departing from the spirit and scope of the claims. All of these variations are within the protection scope of the present invention.
Claims
1. A method for ID generation and protection based on finite field matrix encryption, characterized in that, include: Generate the original ID of the game object based on the server fragmentation identifier and offset; The original ID is divided into multiple 3-byte groups, and each group is mapped to a Galois field GF( A 3-dimensional vector on ) In GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result; Using a preset nonlinear S-box substitution table, nonlinear byte substitution is performed on each byte in the linear transformation result to obtain an obfuscated result; Using the obfuscation result as a new input vector, the matrix multiplication operation and the nonlinear byte replacement are iterated for N rounds to generate an encrypted ID, where N≥2; The original ID of the generated game object includes: Obtain the current server shard identifier and the current offset within that shard, where the offset is a monotonically increasing integer; Using a preset bit width as the dividing unit, the offset is divided equally into binary bits to obtain a high-bit part and a low-bit part; Using the lower-order part and the preset first-round key as input, the intermediate value is calculated through a preset round function; Perform a bitwise XOR operation between the high-order part and the intermediate value to obtain the first XOR result; The low-order part is used as the new high-order part, the first XOR result is used as the new low-order part, and the first round key is replaced as the next round key. The round function calculation and the XOR operation are repeated. After a preset number of iterations, the final high-order part and the low-order part are concatenated bit by bit to obtain the randomized offset. Using the server fragment identifier as the high-order field and the randomized offset as the low-order field, and combining them according to a predetermined bit order, a fixed-width original ID is generated. The mapping of each group to a Galois domain GF( A 3-dimensional vector on ) includes: The original ID is divided into k bytes, each consisting of 8 bits, and is denoted as Byte[1] to Byte[k] in sequence. The k bytes are divided into groups of 3 bytes each according to their byte index, resulting in m groups of 3 bytes each. If k is not a multiple of 3, one or more padding bytes with a value of 0x00 are added to the end of the original ID byte sequence, so that the total number of bytes L after padding is a multiple of 3, and m = L / 3 groups are obtained. For each 3-byte block, arrange the 3 bytes within the block according to their byte index order and map them as GF( A 3D column vector on ) The process of obtaining the obfuscation result includes: Get the current iteration index i; The binary representation of the round index i is concatenated with a preset 256-bit S-box generation key, and the concatenation result is input into the SHA-256 hash function to obtain the 256-bit current round S-box hash value. Initialize a byte array S_box of length 256, and fill it with 0x00 to 0xFF in index order so that S_box[x] = x initially, where x represents the index of the byte array; Using the current round S-box hash value as the initial seed, a preset deterministic pseudo-random number generator is input to generate a pseudo-random byte sequence; Fisher-Yates shuffling is performed on the array S_box to construct a bijective permutation. Specifically, index j is traversed from 255 down to 1. For each j, a uniformly random integer r in the range [0,j] is generated using a pseudo-random sequence. The contents of S_box[j] and S_box[r] are swapped. After all swaps are completed, the S-box replacement table used in the current round is obtained. The S-box replacement table is a bijective permutation on {0x00,…,0xFF}. Extracting the results of linear transformation Each component in Using each component value as the lookup offset address, the corresponding replacement value is read from the current S-box replacement table, and then... Replace with S_box( ), Replace with S_box( ), Replace with S_box( ); The three replaced bytes are then rearranged in their original order to obtain the obfuscation result.
2. The ID generation and protection method based on finite field matrix encryption as described in claim 1, characterized in that, In multiple iterations, the 3×3 encryption matrix used in each round is generated in the following manner: Get the index of the current iteration, i, where i is an integer from 1 to the preset total number of iterations N; The round index i is concatenated with the preset master key, and the concatenation result is input into the SHA-256 hash function to obtain a 256-bit hash value; The first 72 bits of the 256-bit hash value are extracted and divided into 9 bytes, each consisting of 8 bits, and denoted as follows: .
3. The ID generation and protection method based on finite field matrix encryption as described in claim 2, characterized in that, In the multiple iterations, the 3×3 encryption matrix used in each round is generated in the following manner, and also includes: The 9 bytes are filled into a 3×3 matrix in row-first, column-second order, where These will be used as elements in the first, second, and third columns of the first row, respectively. These will be used as elements in the first, second, and third columns of the second row, respectively. These will be used as elements in the first, second, and third columns of the third row, respectively. Iterate through each element in the filled 3×3 matrix. If the current element value is 0x00, replace the element with the preset non-zero constant 0x01; if the current element value is not 0x00, leave the element unchanged. Calculate the 3×3 matrix in GF( The determinant value of the round index i is used; if the determinant is zero, the value of the round index i is incremented by 1, and the process of regenerating 9 bytes and constructing a matrix is repeated until a non-zero invertible matrix is obtained, which serves as the 3×3 encryption matrix used in the current round iteration, where each element is a GF( The non-zero elements in ).
4. The ID generation and protection method based on finite field matrix encryption as described in claim 3, characterized in that, The process of obtaining the linear transformation result includes: The Galois domain GF( A 3D vector on a given surface is represented as a column vector. ; Obtain the 3×3 encryption matrix M corresponding to the current iteration, and denote the elements of the encryption matrix M as... q=1,2,3, u=1,2,3, each All are GF( The non-zero elements in ); In the GF( On a finite field, perform the following operations in sequence: The first row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the first result component. .
5. The ID generation and protection method based on finite field matrix encryption as described in claim 4, characterized in that, The process of obtaining the linear transformation result also includes: The second row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Add the two components together to obtain the second result component. ; The third row element of the encryption matrix M The corresponding elements of the column vectors respectively In GF( Multiply the three products in GF( ) and multiply the product in GF( ) Adding the components together yields the third component. ; Will As the result of the linear transformation, where All are GF( Elements in ).
6. An ID generation and protection system based on finite field matrix encryption, used to implement the ID generation and protection method based on finite field matrix encryption as described in any one of claims 1-5, characterized in that, include: The AutoId generator is configured to generate the original ID of the game object based on the server fragment identifier and offset. The vector mapping module is configured to: divide the original ID into multiple 3-byte groups, and map each group to a Galois field GF( A 3-dimensional vector on ) The matrix encryption engine is configured to: in GF( In a finite field, a matrix multiplication operation is performed on the 3-dimensional vector using a preset 3×3 encryption matrix to obtain a linear transformation result; The S-box replacement module is configured to: use a preset nonlinear S-box replacement table to perform nonlinear byte replacement on each byte in the linear transformation result to obtain an obfuscated result; The iterative encryption controller is configured to: use the obfuscation result as a new input vector and feed it back to the matrix encryption engine and the S-box replacement module, perform multiple rounds of iteration on the matrix multiplication operation and the nonlinear byte replacement, and generate an encrypted ID.
Citation Information
Patent Citations
Encryption method based on RISC-V architecture
CN117978367A
Power secondary equipment fingerprint construction method and system, electronic device and storage medium
CN121278704A