Method and apparatus for privacy inference of large model based on trusted hardware, and electronic device

By using pseudo-random number initialization and homomorphic encryption with trusted hardware in a large language model, the privacy leakage problem in cloud deployment is solved, and secure and efficient privacy inference is achieved, adapting to the needs of different security scenarios.

CN121098512BActive Publication Date: 2026-03-20TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511268078.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-05
Publication Date
2026-03-20
Estimated Expiration
2045-09-05

AI Technical Summary

Technical Problem

Existing technologies pose privacy risks when deploying large language models in the cloud, making it difficult to balance security and efficiency. Traditional methods suffer from huge overhead for homomorphic encryption, limited security of trusted execution environments, and insufficient flexibility.

Method used

A large-model privacy inference method based on trusted hardware is adopted. The pseudo-random number generator is initialized by the client and server, word embedding is performed using homomorphic encryption and privacy inference protocol, the data is stored in the register, and the execution result is rejected when the result verification fails.

Benefits of technology

It effectively prevents data leakage, improves inference efficiency, balances security and efficiency, and is suitable for both semi-honest and malicious security scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121098512B_ABST
    Figure CN121098512B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of secure computation and privacy protection, in particular to a large model privacy inference method and device based on trusted hardware and electronic equipment, wherein the method comprises the following steps: before performing a large model inference task, a client and a server initialize respective pseudo-random number generators based on information interaction, so as to synchronize initial seeds and generate random numbers based on the seeds; in the inference process, homomorphic encryption is used to complete word embedding of the large model inference, all operators are converted into instruction combinations by using an inference instruction set, privacy inference is performed based on a privacy inference protocol and the random numbers generated by the pseudo-random number generator, and privacy data is masked by using the random numbers; after the task is completed, execution results and proof information provided by the server are acquired, verification is performed, and the results are rejected if the verification fails. Thus, the problems that related technologies have data leakage risks and are difficult to balance security and efficiency are solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of secure computing and privacy protection, and in particular to a large model privacy inference method and device based on trusted hardware and an electronic device. BACKGROUND

[0002] With the popularity of large language models in natural language processing, intelligent question answering and code generation tasks, their deployment gradually shifts from local to cloud, but this brings serious privacy leakage risks. Traditional models need to upload user input to the cloud for inference, and user data, model parameters and intermediate results may be leaked.

[0003] Related technologies include: cryptographic methods based on homomorphic encryption or multi-party secure computation, which have good privacy but high overhead; local trusted computing methods based on trusted execution environments and methods based on customized trusted hardware, which have limited security and complex design; and methods based on customized trusted hardware, which lack flexibility and perfect input and output protection. SUMMARY

[0004] The present application provides a large model privacy inference method and device based on trusted hardware and an electronic device to solve the problem of data leakage risk in related technologies and the difficulty of balancing security and efficiency.

[0005] The first aspect of the present application provides a large model privacy inference method based on trusted hardware, comprising the following steps: before performing a large model inference task, the client and the server initialize their respective pseudo-random number generators based on information interaction to synchronize the initial seeds of the pseudo-random number generators, and the pseudo-random number generators generate random numbers based on the initial seeds; during the execution of the large model inference task, the word embedding of the large model inference is completed based on homomorphic encryption, all operators in the large model inference task are converted into instruction combinations using the inference instruction set, the instruction combinations are subjected to privacy inference using the privacy inference protocol and the random numbers generated by the pseudo-random number generator, the read data is stored in the first register, and the privacy inference result and the random number are stored in the second register; after completing the large model inference task, the execution result and the proof information provided by the server are obtained, the execution result and the proof information are verified, and if the verification fails, the execution result provided by the server is rejected.

[0006] Optionally, in an embodiment of the present application, the trusted hardware is provided with an initialization protocol, the initialization protocol includes a semi-honest initialization protocol and a malicious security initialization protocol, the semi-honest initialization protocol is applied to a semi-honest security scenario, and the malicious security initialization protocol is applied to a malicious security scenario, wherein an execution process of the semi-honest initialization protocol includes that a server generates a true random number as a seed, encrypts the seed by using a public key of a client, signs the seed by using a private key of the server, the client verifies the signature, decrypts the message and restores the seed after receiving the seed, and the two parties initialize pseudo-random number generators of the two parties by using the seed; and an execution process of the malicious security initialization protocol includes that the client generates a random number and sends the random number to the server, the server generates a seed and a random number, encrypts the seed and the random number and sends the seed and the random number back to the client, and the client initializes a local pseudo-random number generator after verifying a session identifier of the encrypted data.

[0007] Optionally, in an embodiment of the present application, the trusted hardware is provided with a result delivery and bidirectional verification protocol, wherein an execution process of the result delivery and bidirectional verification protocol includes that the client and the server exchange respective instruction stream hash values, constants, weight hash values and result hash values, the result hash values are subjected to mask processing, the client uses the trusted hardware, calculates a hash value of a received execution result and performs verification, verifies server remote proof information and content, and if there is a signature inconsistency or a hash check failure, the received execution result provided by the server is rejected.

[0008] Optionally, in an embodiment of the present application, the reasoning instruction set includes a semi-honest security instruction set and a malicious security reasoning instruction, and the privacy reasoning protocol includes a semi-honest security privacy reasoning protocol and a malicious security privacy reasoning protocol, the semi-honest security instruction and the semi-honest security privacy reasoning protocol are used in a semi-honest security scenario, and the malicious security reasoning instruction and the malicious security privacy reasoning protocol are used in a malicious security scenario, wherein the semi-honest security instruction includes a multiplication instruction, an inverse calculation instruction and a sign bit extraction instruction, and the malicious security reasoning instruction includes a multiplication instruction, an inverse calculation instruction, a sign bit extraction instruction and a hash instruction.

[0009] Optionally, in an embodiment of the present application, privacy data of a large model reasoning task is held in a secret sharing form by two parties, a semi-honest security privacy reasoning protocol is based on a semi-honest security instruction and includes that the client and the server each have a synchronous random number stream in the trusted hardware; the client generates a random number stream by using the trusted hardware, masks a secret share held by the client by using the random number stream, and sends a result after the masking to the server; the trusted hardware of the server decodes the result after the masking, restores privacy data by combining a secret share held by the server, and completes calculation, after the completion of the calculation, the trusted hardware of the server generates a new random number, masks a calculation result and outputs the calculation result as a secret share of the server; and the client holds the new random number as a secret share.

[0010] Optionally, in an embodiment of the present application, the malicious secure privacy inference protocol and the semi-honest secure privacy inference protocol have the same inference process under the same instruction, and the inference process of the malicious secure privacy inference protocol based on the hash instruction includes that the client and the server respectively hold a secret share of input data, and the trusted hardware knows the hash value of the secret share; the client generates a random number stream using the trusted hardware, masks the secret share held by the client using the random number stream, the trusted hardware of the client checks the hash value of the secret share, the trusted hardware of the client calculates the hash value according to the result after masking, and outputs the hash value after masking with a random number, and the client sends the mask of the secret share and the mask of the hash value to the server; the trusted hardware of the server internally decodes the secret share sent by the client, simultaneously decodes the hash value thereof, and checks the hash value, if correct, the server outputs the secret share of the server to the trusted hardware of the server, the trusted hardware of the server checks the hash value of the secret share, if correct, the input data can be recovered in the trusted hardware of the server, and calculation is performed, after the calculation is completed, the trusted hardware of the server generates a new random number, and outputs the calculation result after masking as the secret share of the server, at the same time, the trusted hardware of the server calculates the hash value of the secret share and outputs the hash value; the trusted chip of the client generates the same random number as the server as the secret share of the client, and outputs the hash value of the client after calculation.

[0011] Optionally, in an embodiment of the present application, the word embedding protocol is based on homomorphic encryption, and completes the word embedding of large model inference, wherein the execution process of the word embedding protocol applied to a semi-honest secure scene includes that the client selects a corresponding ciphertext vector according to a word identifier input by itself, performs homomorphic masking processing on the ciphertext vector using a randomly generated mask vector, the masked ciphertext is sent back to the server, the server obtains the masked embedding result after decryption using a private key, and the client saves the opposite number of the mask value.

[0012] Optionally, in an embodiment of the present application, the word embedding protocol of large model inference is implemented based on homomorphic encryption, and is completed by trusted hardware for checking, wherein the execution process of the word embedding protocol applied to a malicious secure scene includes that the client selects a corresponding ciphertext vector according to a word identifier input by itself, performs homomorphic masking processing on the ciphertext vector using a randomly generated mask vector, the masked ciphertext is sent back to the server, the server obtains the masked embedding result after decryption using a private key, and the client saves the opposite number of the mask value; the server calculates a hash value of each plaintext embedding vector in a preprocessing stage and sends the hash value to the client as a public commitment, the client selects a corresponding hash digest in the protocol execution process, and performs integrity checking by the trusted hardware of the service party in a hardware random number masking manner.

[0013] The second aspect embodiment of the application provides a large model privacy inference device based on trusted hardware, the device is applied to the trusted hardware of the client and the server respectively, the trusted hardware includes a first register, a second register and a pseudo-random number generator, the client and the server are prohibited from reading the second register of the other party, wherein the trusted hardware includes: an initialization module, configured to initialize the pseudo-random number generator of the client and the server based on information interaction before performing a large model inference task, so as to synchronize the initial seed of the pseudo-random number generator, and the pseudo-random number generator generates a random number based on the initial seed; an inference module, configured to complete the word embedding of the large model inference based on homomorphic encryption during the execution of the large model inference task, convert all operators in the large model inference task into instruction combinations by using an inference instruction set, and complete instruction execution by using the random number generated by the pseudo-random number generator, so as to complete privacy inference; and a verification module, configured to obtain the execution result and proof information provided by the server after completing the large model inference task, and verify the execution result and the proof information, and if the verification fails, the execution result provided by the server is refused.

[0014] Optionally, in an embodiment of the application, the trusted hardware is provided with an initialization protocol, the initialization protocol includes a semi-honest initialization protocol and a malicious security initialization protocol, the semi-honest initialization protocol is applied to a semi-honest security scene, and the malicious security initialization protocol is applied to a malicious security scene, wherein the execution process of the semi-honest initialization protocol includes that the server generates a true random number as a seed, encrypts the seed by using the public key of the client, signs the seed by using the private key of the server, the client verifies the signature, decrypts the message and restores the seed after receiving the seed, and the two parties initialize the pseudo-random number generators of the two parties by using the seed; and the execution process of the malicious security initialization protocol includes that the client generates a random number and sends the random number to the server, the server generates a seed and a random number, encrypts the seed and the random number and sends the seed and the random number back to the client, and the client initializes the local pseudo-random number generator after verifying the session identifier of the encrypted data.

[0015] Optionally, in an embodiment of the application, the trusted hardware is provided with a result delivery and bidirectional verification protocol, wherein the execution process of the result delivery and bidirectional verification protocol includes that the client and the server exchange the instruction stream hash value, the constant, the weight hash value and the result hash value of the two parties, the result hash value is subjected to mask processing, the client uses the trusted hardware to calculate the hash value of the received execution result and verify the execution result, signs the remote proof information of the server and verifies the content of the remote proof information, and if there is a signature inconsistency or a hash check failure, the execution result provided by the server is refused.

[0016] Optionally, in an embodiment of the present application, the reasoning instruction set includes a semi-honest secure instruction set and a malicious secure reasoning instruction, the privacy reasoning protocol includes a semi-honest secure privacy reasoning protocol and a malicious secure privacy reasoning protocol, the semi-honest secure instruction and the semi-honest secure privacy reasoning protocol are used in a semi-honest secure scenario, and the malicious secure reasoning instruction and the malicious secure privacy reasoning protocol are used in a malicious secure scenario, wherein the semi-honest secure instruction includes a multiplication instruction, a reciprocal calculation instruction, and a sign bit extraction instruction, and the malicious secure reasoning instruction includes a multiplication instruction, a reciprocal calculation instruction, a sign bit extraction instruction, and a hash instruction.

[0017] Optionally, in an embodiment of the present application, the privacy data of the large model reasoning task is held in the form of a secret share by two parties, and the semi-honest secure privacy reasoning protocol is based on semi-honest secure instructions for reasoning, including: the client and the server each have a synchronized random number stream in the trusted hardware; the client generates a random number stream using the trusted hardware, masks the secret share held by the client with the random number stream, and sends the masked result to the server; the trusted hardware of the server decodes the masked result, combines the secret share held by the server, restores the privacy data, and completes the calculation, after which the trusted hardware of the server generates a new random number and outputs the calculation result after masking as the secret share of the server; and the client holds the new random number as a secret share.

[0018] Optionally, in an embodiment of the present application, the malicious secure privacy reasoning protocol and the semi-honest secure privacy reasoning protocol have the same reasoning process under the same instruction, and the reasoning process of the malicious secure privacy reasoning protocol based on the hash instruction includes: the client and the server each hold a secret share of input data, and the trusted hardware knows the hash value of the secret share; the client generates a random number stream using the trusted hardware, masks the secret share held by the client with the random number stream, the trusted hardware of the client verifies the hash value of the secret share, the trusted hardware of the client calculates the hash value according to the masked result and outputs the hash value after masking with a random number, and the client sends the mask of the secret share and the mask of the hash value to the server; the trusted hardware of the server decodes the secret share sent by the client and simultaneously decodes the hash value, and verifies the hash value, if correct, the server outputs the secret share of the server to the trusted hardware of the server, the trusted hardware of the server verifies the hash value of the secret share, if correct, the input data can be restored in the trusted hardware of the server, and the calculation is performed, after which the trusted hardware of the server generates a new random number and outputs the calculation result after masking as the secret share of the server, and at the same time, the trusted hardware of the server calculates the hash value of the secret share and outputs it; the trusted chip of the client generates the same random number as the server as the secret share of the client, and outputs the hash value after calculation.

[0019] Optionally, in an embodiment of the present application, the word embedding protocol based on homomorphic encryption completes the word embedding of the large model inference, wherein the execution process of the word embedding protocol applied to the semi-honest security scenario includes: the client selects the corresponding ciphertext vector according to the word identifier input by itself, uses a randomly generated mask vector to perform homomorphic masking on the ciphertext vector, and sends the masked ciphertext back to the server; the server uses the private key to obtain the masked embedding result after decryption; and the client saves the opposite number of the mask value.

[0020] Optionally, in an embodiment of the present application, the word embedding protocol of the large model inference is implemented based on homomorphic encryption and is checked by trusted hardware, wherein the execution process of the word embedding protocol applied to the malicious security scenario includes: the client selects the corresponding ciphertext vector according to the word identifier input by itself, uses a randomly generated mask vector to perform homomorphic masking on the ciphertext vector, and sends the masked ciphertext back to the server; the server uses the private key to obtain the masked embedding result after decryption; and the client saves the opposite number of the mask value; the server calculates the hash value of each plaintext embedding vector in the preprocessing stage and sends it to the client as a public commitment; the client selects the corresponding hash digest in the protocol execution process, and the trusted hardware of the service party performs integrity check in the form of hardware random number masking.

[0021] The third aspect embodiment of the present application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the large model privacy inference method based on trusted hardware as described in the above embodiments.

[0022] Therefore, the present application includes the following beneficial effects:

[0023] Before inference, the client and the server synchronize the initial seed of the pseudo-random number generator through information interaction to generate a random number; in the inference process, the word embedding is completed by using homomorphic encryption, and the inference operator is converted into an instruction combination, and the privacy inference is performed in combination with the privacy inference protocol and the random number, the data is stored in a first register, and the result and the random number are stored in a second register; after the inference is completed, the client verifies the execution result and the proof information returned by the server, and if the verification fails, the result is refused to be received. Therefore, the problem that related technologies have data leakage risk and are difficult to balance security and efficiency is solved.

[0024] Additional aspects and advantages of the present application will be in part apparent and in part pointed out hereinafter in the description of the application. BRIEF DESCRIPTION OF DRAWINGS

[0025] The above and / or additional aspects and advantages of the present application will become apparent and be readily appreciated from the following description of embodiments, taken in conjunction with the accompanying drawings, in which:

[0026] Figure 1 A flowchart of a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0027] Figure 2 A flowchart of a hardware initialization method in a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0028] Figure 3 A communication optimization method schematic diagram of a hardware instruction compilation method in a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0029] Figure 4 A flowchart of a word embedding method in a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0030] Figure 5 A flowchart of a trusted hardware computing result delivery method in a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0031] Figure 6 A design and flowchart of a large model privacy inference method based on trusted hardware according to an embodiment of the present application;

[0032] Figure 7 An example diagram of a large model privacy inference apparatus based on trusted hardware according to an embodiment of the present application;

[0033] Figure 8 A structural schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0034] Embodiments of the present application are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by reference to the accompanying drawings are exemplary and are intended to explain the present application, and cannot be understood as limiting the present application.

[0035] A method, device and electronic equipment for large model privacy inference based on trusted hardware are described below with reference to the accompanying drawings. To solve the problems mentioned in the background art, the present application provides a method for large model privacy inference based on trusted hardware. In this method, before performing a large model inference task, the client and the server initialize their respective pseudo-random number generators based on information interaction to synchronize the initial seeds of the pseudo-random number generators, and the pseudo-random number generators generate random numbers based on the initial seeds. During the execution of the large model inference task, the word embedding of the large model inference is completed based on homomorphic encryption, all operators in the large model inference task are converted into instruction combinations using the inference instruction set, the instruction combinations are privacy-inferred using the privacy inference protocol and the random numbers generated by the pseudo-random number generator, the read data is stored in the first register, and the privacy inference result and the random number are stored in the second register. After completing the large model inference task, the execution result and the proof information provided by the server are obtained, and the execution result and the proof information are verified. If the verification fails, the execution result provided by the server is rejected. Thus, the data leakage risk in the related art is solved, and the problems of difficult to balance security and efficiency are solved.

[0036] Specifically, Figure 1 A flowchart of a method for large model privacy inference based on trusted hardware is provided.

[0037] As Figure 1 shown, the method is applied to the trusted hardware of the client and the server respectively, the trusted hardware includes a first register, a second register and a pseudo-random number generator, the client and the server are prohibited from reading the second register of the other party, and the method for large model privacy inference based on trusted hardware includes the following steps:

[0038] In step S101, before performing a large model inference task, the client and the server initialize their respective pseudo-random number generators based on information interaction to synchronize the initial seeds of the pseudo-random number generators, and the pseudo-random number generators generate random numbers based on the initial seeds.

[0039] Wherein, the first register is a regular register, the second register is a random number register, the client is a party initiating an inference request in a large model inference scenario, such as a user device or an application program, in this application, the client is a data provider in large model privacy inference. The server is a party receiving an inference request and performing inference calculation in a large model inference scenario, such as a cloud server or a model provider, in this application, the server is a model provider in large model privacy inference. The pseudo-random number generator is a module for generating a pseudo-random number sequence based on a seed, used for random number flow in large model privacy inference. The initial seed is the initialization input of the pseudo-random number generator, which ensures consistent and unpredictable sequence, in this application, it is determined by the client and the server. The random number is the output of the pseudo-random number generator, used to mask the input or intermediate result, to ensure the security and privacy of the inference process.

[0040] It can be understood that by initializing the respective pseudo-random number generators based on information interaction by the client and the server before performing the large model inference task and synchronizing the initial seed, it can be ensured that the parties independently generate completely consistent random number sequences in the subsequent inference process, avoiding the communication overhead caused by frequent transmission of random numbers. At the same time, since the random numbers are only indirectly shared through the initial seed, it can effectively prevent the leakage of sensitive information in the inference process. In addition, the local generation of random numbers reduces the waiting and synchronization process, improves the inference execution efficiency, and provides reliable randomness support for masking, secret sharing and other security mechanisms.

[0041] In an embodiment of the present application, the trusted hardware is provided with an initialization protocol, the initialization protocol includes a semi-honest initialization protocol and a malicious security initialization protocol, the semi-honest initialization protocol is applied to a semi-honest security scenario, and the malicious security initialization protocol is applied to a malicious security scenario. Wherein, the execution process of the semi-honest initialization protocol includes: the server generates a true random number as a seed, and encrypts it using the public key of the client, and signs it by the private key of the server, the client receives it, verifies the signature, decrypts the message and restores the seed after receiving it, and both parties initialize their respective pseudo-random number generators with the seed; the execution process of the malicious security initialization protocol includes: the client generates a random number and sends it to the server, the server generates a seed and a random number and sends it back to the client after encryption, and the client initializes the local pseudo-random number generator after verifying the session identifier of the encrypted data.

[0042] Wherein, the trusted hardware is a hardware environment with secure computing and tamper-proofing capability, which is used in the present application to execute the large model privacy inference protocol. The initialization protocol is a process for the client and the server to establish shared randomness and secure communication before inference begins, which includes a semi-honest initialization protocol and a malicious security initialization protocol in the present application. Semi-honest represents that in the security model, the participants will perform operations according to the protocol but may try to obtain additional information from the execution process, which is used to describe that the client and the server comply with the protocol during the inference process, but may try to guess the input data of the other party. Malicious security represents that in the security model, the participants may arbitrarily deviate from the protocol, including tampering with data or sending fake messages, which is used to describe that the client and the server need to guard against arbitrary malicious behavior during the inference process to ensure the correctness and privacy of the calculation result. True random number is a random number derived from a non-deterministic process such as physical noise, which is generated by the server in the present application to construct a secure seed. Public key is the public key of an asymmetric cryptography system, which is used to encrypt information or verify signatures, which is provided by the client in the present application; private key is one part of a pair of keys, corresponding to the public key; private key signature is a signature operation on a message using a private key, which is used to ensure the integrity and source of the message, which is usually generated by the server in the present application. Session identifier is a value that uniquely marks a communication session, which is verified by the client in the present application to prevent replay attacks.

[0043] It can be understood that through the initialization protocol, the client and the server can securely and synchronously generate a sequence of pseudo-random numbers before the large model privacy inference begins, ensuring the randomness consistency of subsequent masking, secret sharing and calculation process. In the semi-honest security scenario, the embodiments of the present application can make both parties correctly synchronize randomness without trusting each other's data processing; in the malicious security scenario, the embodiments of the present application further prevent seed reuse, data tampering or forgery attacks through session identifiers and encryption mechanisms.

[0044] In the embodiments of the present application, before using trusted hardware to complete large model inference, a corresponding initialization protocol is selected according to the security model to ensure that the random number sequences generated by the trusted hardware of both parties are synchronized and secure. The initialization protocol sets the initial seed for the cryptographic secure pseudo-random number generator of both parties before the inference begins, realizing randomness consistency and unpredictability.

[0045] In the implementation process, each trusted hardware is built-in with a public-private key pair, wherein the private key is saved in a read-only memory and cannot be exported. Through the public key verification service, the client and the server can confirm the authenticity of the other party's hardware and exchange trusted public keys to carry out initialization.

[0046] In the semi-honest security scenario, the trusted hardware of the server first generates a true random number as a seed, encrypts it using the public key of the client, and signs it with the private key of the server to ensure the confidentiality and integrity of the message. After receiving the message, the client verifies the signature, decrypts and recovers the seed, and then both parties initialize their respective cryptographic secure pseudo-random number generators with the seed, thereby ensuring the randomness synchronization of subsequent calculations.

[0047] In the malicious security scenario, to prevent seed reuse and replay attacks, the system introduces a challenge and response mechanism for enhanced initialization. The client first generates a random session number and sends it to the server. The server encrypts the random number and sends it back to the client while generating the seed. After verifying the session identifier, the client confirms that the seed is fresh and initializes the local cryptographic secure pseudo-random number generator accordingly, thereby preventing the server from performing correlation attacks on multiple reasoning results by reusing the seed.

[0048] In step S102, during the execution of the large model reasoning task, the word embedding of the large model reasoning is completed based on homomorphic encryption, all operators in the large model reasoning task are converted into instruction combinations using the reasoning instruction set, and the instruction combinations are subjected to privacy reasoning using the random number generated by the privacy reasoning protocol and the pseudo-random number generator. The read data is stored in the first register, and the privacy reasoning result and the random number are stored in the second register.

[0049] Among them, the word embedding is the process of mapping the words in the input text to vector representation, in this application, the word embedding is completed by homomorphic encryption to protect the privacy of the input word identifier. The reasoning instruction set is a set of computing and storage instructions that can be executed on trusted hardware, in this application, the reasoning instruction set converts the large model operators into instruction combinations executable by hardware. The privacy reasoning protocol is a computing protocol under secret sharing or random number masking, in this application, the privacy reasoning protocol combines the random number generated by the pseudo-random number generator to perform secure calculation on the instruction combination to prevent information leakage. The first register is a conventional register, denoted as , which is used to save the original data read in this application. The second register is a random number register, denoted as , which is used to save the random number generated by the pseudo-random number generator in this application.

[0050] It can be understood that through the word embedding based on homomorphic encryption, the privacy protection of the input word identifier is realized, and the original text information leakage is avoided; at the same time, the operator is converted into an instruction combination executable by hardware using the reasoning instruction set, and calculation is performed in combination with the privacy reasoning protocol and the pseudo-random number, ensuring the data privacy of the large model reasoning process;

[0051] In an embodiment of the present application, the inference instruction set includes a semi-honest secure instruction set and a malicious secure inference instruction, the privacy inference protocol includes a semi-honest secure privacy inference protocol and a malicious secure privacy inference protocol, the semi-honest secure instruction and the semi-honest secure privacy inference protocol are used in a semi-honest secure scenario, and the malicious secure inference instruction and the malicious secure privacy inference protocol are used in a malicious secure scenario, wherein the semi-honest secure instruction includes a multiplication instruction, a reciprocal calculation instruction, and a sign bit extraction instruction, and the malicious secure inference instruction includes a multiplication instruction, a reciprocal calculation instruction, a sign bit extraction instruction, and a hash instruction.

[0052] The semi-honest secure instruction is a specific instruction type included in the semi-honest secure instruction set, including a multiplication instruction, a reciprocal calculation instruction, and a sign bit extraction instruction, etc. The malicious secure inference instruction is a specific instruction type included in the malicious secure instruction set, including a multiplication instruction, a reciprocal calculation instruction, a sign bit extraction instruction, and a hash instruction, etc.

[0053] It can be understood that the inference instruction set and the privacy inference protocol are distinguished according to different security levels, so that the large model inference can adapt to both semi-honest secure scenarios and malicious secure scenarios. In a semi-honest secure scenario, only necessary calculation instructions are used to complete the inference; in a malicious secure scenario, additional hash instructions and integrity checks are introduced to prevent data tampering and replay attacks.

[0054] The trusted hardware instruction set for large model privacy inference includes a trusted hardware instruction set for semi-honest secure large model privacy inference and a trusted hardware instruction set for malicious secure large model privacy inference.

[0055] The trusted hardware instruction set for semi-honest secure large model privacy inference includes multiplication, reciprocal calculation, sign bit extraction, etc., and specific operation instructions include:

[0056] The multiplication instruction ( ) is used to remove the random number mask of two registers in the hardware and multiply them, and then perform a random number mask on the calculation result and store it in a specified register in the hardware.

[0057] The instruction format is:

[0058]

[0059] The function is to calculate , wherein is a random number newly generated by a pseudo-random number generator, and the result is stored in .

[0060] The multiplication instruction ( ) which is used to remove the random number mask from a register in the hardware and multiply directly with the value in another register, then random number mask the result and store in a specified register in the hardware.

[0061] The instruction format is:

[0062]

[0063] The function is to calculate , and the result is stored in .

[0064] The sign bit instruction ( ) which is used to remove the random number mask from a register in the hardware and take out the sign bit, then random number mask the sign bit and store in a specified register in the hardware.

[0065] The instruction format is:

[0066]

[0067] The function is to calculate , and the result is stored in .

[0068] The reciprocal instruction ( ) which is used to remove the random number mask from a register in the hardware and calculate the initial value of the iterative calculation, then random number mask the initial value and store in a specified register in the hardware.

[0069] The instruction format is:

[0070]

[0071] The function is to calculate the initial value of the reciprocal iterative calculation of , and store in after random number masking.

[0072] The square root reciprocal instruction ( ) which is used to remove the random number mask from a register in the hardware and calculate the initial value of the iterative calculation, then random number mask the initial value and store in a specified register in the hardware.

[0073] The instruction format is:

[0074]

[0075] The function is to calculate the initial value of the reciprocal iterative calculation of , and store in after random number masking.

[0076] To improve the inference efficiency, the above hardware instructions are all vectorized, for example, the multiplication instruction calculates 32 multiplications at the same time, and other instructions are the same.

[0077] For the trusted hardware instruction set of malicious security large model privacy inference, specifically, additional hash instructions are added on the basis of the semi-honest security instruction set, which ensures that the input hardware instruction stream and data stream cannot be maliciously tampered with, so that the privacy inference protocol can resist malicious participants. The random number used by the random number mask comes from a cryptographically secure random number stream, which is generated in trusted hardware and cannot be read or tampered with in the form of instructions.

[0078] In an embodiment of the present application, the privacy data of the large model inference task is held in the form of secret sharing by two parties, and the semi-honest security privacy inference protocol is based on semi-honest security instructions for inference, including: the client and the server each have a synchronized random number stream in the trusted hardware; the client generates a random number stream using trusted hardware, and masks the secret share it holds with the random number stream, and sends the masked result to the server; the trusted hardware of the server decodes the masked result, combines the secret share held by the server, restores the privacy data, and completes the calculation, after the calculation is completed, the trusted hardware of the server generates a new random number, and the calculation result is masked and output as the secret share of the server; the client holds the new random number as a secret share.

[0079] Among them, the privacy data of the large model inference task is held in the form of secret sharing by the client and the server respectively, the secret share of the input data held by the client is , and the secret share of the input data held by the server is , , is the same random number generated by the trusted hardware of both parties, the mask of the client's secret share is , and the model parameters of the server are .

[0080] It can be understood that in the semi-honest security scenario, the large model privacy inference realizes data protection through the cooperative calculation of the client and the server. Through random number masking and trusted hardware register management, large model inference can be completed under the premise of ensuring data privacy, effectively preventing semi-honest participants from obtaining plaintext data.

[0081] Specifically, in order to perform privacy inference, both parties need to hold one of the above trusted chips, and the instructions supported by the chips are slightly different. Specifically, the client can read the value of the second register in the trusted chip, while the server cannot read the second register. The instructions related to register reading and writing are as follows:

[0082] : Write the specified data on the memory into a first register on the trusted chip.

[0083] : Read the value in a first register on the trusted chip and write it to the memory.

[0084] : A random number generator on the trusted chip generates a new set of random numbers and writes them into a second register on the chip.

[0085] : Read the value in a second register on the trusted chip and write it to the memory. This instruction is disabled on the trusted chip of the server side.

[0086] Based on the above hardware structure, the application can construct a simple two-party linear layer calculation protocol.

[0087] Let the linear layer parameter be , held by the server, and the input be , , which represents the variable in the form of a secret share . Specifically, the client holds the secret share , and the server holds the secret share , satisfying . The calculation goal is to obtain , and the protocol is shown in Table 1.

[0088] Table 1

[0089]

[0090] In the above protocol, because the server cannot read the values of the second register on the chip, the first random number and the second random number , it cannot obtain any information about the first data from the first mask result , and it cannot obtain any information about .

[0091] When the application constructs a privacy inference protocol matching the hardware instruction set, the protocol is applicable to common inference operators in large language models, and the supported inference operators specifically include: matrix multiplication operation, layer normalization operation (such as layer normalization, mean square normalization), attention mechanism operation, and activation function operation (Gaussian error linear unit, Sigmoid linear unit); the privacy inference protocols proposed for the above operators are divided into two versions of semi-honest security and malicious security, the difference lies in whether to introduce hash operation.

[0092] The process of calculating other operators in large model inference using a trusted chip is similar to protocol 1, that is, the client sends the masked input to the server, the server performs calculation in the trusted chip after unmasking, and finally outputs the calculation result after masking, so that both parties obtain the secret sharing of the calculation result.

[0093] All operators in large model inference can be converted into a combination of the above instructions, thereby constructing a privacy inference protocol for each operator.

[0094] The embodiment of the application designs a trusted hardware instruction compiler, which automatically generates instruction sequences for different types of large model operators and security settings, and optimizes the communication amount and execution order, including: for the instruction order arrangement strategy optimization of the linear layer operator, the purpose is to send the intermediate variable only once, that is, for the weight matrix and the intermediate variable , the execution order is to multiply each element of column by column. For the instruction order arrangement strategy optimization of the convolution layer operator, the purpose is to send the intermediate variable participating in the convolution operation only once, that is, for the intermediate variable , multiply each element of the input channel dimension .

[0095] Specifically, for the linear layer, the process of calculating in protocol 1 is replaced by a multiplication instruction.

[0096] For the normalization layer, the calculation formula is:

[0097]

[0098] Among them, the calculation of only involves addition, which is simple in secret sharing calculation. The process of calculating only involves multiplication in addition, which can be realized by a multiplication instruction. For , a square root reciprocal instruction can be used.

[0099] For the Gaussian error linear unit layer, the calculation formula is:

[0100]

[0101] Among them, is the distribution function of the Gaussian normal function. In order to calculate , the common method is to segment the value of , and use different polynomial functions for fitting on different segments. Using instruction, the segmentation of the value of can be realized, and Instructions can implement the calculation of a polynomial function, thereby enabling the complete calculation of a Gaussian error linear unit function.

[0102] For the normalized exponential function layer, the calculation formula is:

[0103]

[0104] For the purpose of numerical stability, the actual input is The comparison operation that takes the maximum value needs to be implemented by a sign bit instruction. For the exponential function , it can be calculated by polynomial fitting, thereby being converted into a multiplication instruction. For the reciprocal form in the normalized exponential function, a reciprocal instruction can be used to implement it.

[0105] For the maximum index layer, it is to find the maximum value of the input parameter. In order to implement the maximum index, multiple comparison operations are needed, and the comparison can be converted into a subtraction and then a sign judgment, thereby can be implemented.

[0106] Taking matrix multiplication as an example, the embodiment of the application adopts the strategy of "accessing the input matrix by column" to sequentially arrange the multiplication operation during compilation. As Figure 3 shown, when calculating in , the value is taken column by column in the unit of , and the broadcast and multiplication operations are performed on each element, thereby ensuring that each element of the intermediate variable only needs to be read and transmitted once in hardware. This strategy significantly reduces the number of communications of input data between trusted hardware.

[0107] For the convolution layer operator, during the compilation process, the input tensor is preferentially unfolded according to the channel dimension , each input channel is processed one by one, and the corresponding output index position is calculated for different positions of the center element of the convolution kernel. Each input element participates in the operation of all convolution kernels within its receptive field, and combines the weight loading and broadcast random mask to perform a point multiplication operation. This strategy can also effectively reduce the repeated transmission of intermediate variables.

[0108] In addition, in order to improve the efficiency of instruction execution, all operators containing a loop structure are loop-unfolded when compiled and generated, that is, the instructions within the loop are explicitly unfolded into a sequential structure according to the number of times, thereby reducing the waiting period caused by pipeline instruction switching and data dependency, and improving the overall inference performance.

[0109] In an embodiment of the present application, the malicious security privacy inference protocol and the semi-honest security privacy inference protocol have the same inference process under the same instruction. The inference process of the malicious security privacy inference protocol based on the hash instruction includes that the client and the server respectively hold a secret share of input data, and the trusted hardware knows the hash value of the secret share; the client generates a random number stream using the trusted hardware, masks the secret share held by the client using the random number stream, the trusted hardware of the client verifies the hash value of the secret share, the trusted hardware of the client calculates the hash value according to the masked result, and outputs the hash value after random number masking, and the client sends the mask of the secret share and the mask of the hash value to the server; the trusted hardware of the server internally decodes the secret share sent by the client, simultaneously decodes the hash value thereof, and verifies the hash value. If correct, the server outputs the secret share of the server to the trusted hardware of the server. The trusted hardware of the server verifies the hash value of the secret share. If correct, the input data can be recovered in the trusted hardware of the server, and calculation is performed. After the calculation is completed, the trusted hardware of the server generates a new random number, and outputs the calculation result after masking as the secret share of the server. At the same time, the trusted hardware of the server calculates the hash value of the secret share and outputs the hash value.

[0110] It can be understood that the embodiments of the present application retain the privacy protection capability of the semi-honest protocol, and effectively prevent malicious tampering of input, mask value or intermediate result by introducing a hash verification mechanism, thereby ensuring the integrity and security of the inference calculation.

[0111] In the malicious security scenario, the participants may steal privacy information or destroy the inference process by tampering with the input in the inference process (such as injecting incorrect instructions or fake data into the trusted chip). To counter such threats, the present application introduces a hash calculation function in the trusted hardware to perform integrity verification on the data, instructions and model parameters involved in the inference process, thereby fundamentally preventing them from being maliciously tampered with. To support efficient and reliable verification, multiple hash calculation modules (denoted as ) are configured in the trusted hardware, which can perform hash operations in parallel.

[0112] Specifically, the additional instructions added mainly include:

[0113] The instruction format is:

[0114]

[0115] The function is to load data from address to register on the chip, at the same time, the hash calculation module The hash value will be updated according to the loaded data.

[0116] The instruction format is:

[0117]

[0118] The function is to write the data in the first register on the chip to the memory at the address , and at the same time, the hash calculation module will update the hash value according to the written data.

[0119] The chip outputs the hash value as K, which actually outputs a message authentication code derived from the hash value and the key on the chip. The key on the chip cannot be directly read, which ensures that the user cannot tamper with the data or forge other false hash values.

[0120] Using the above two instructions, all data output from the chip will be calculated to a corresponding hash value and stored on the chip, and at the same time, the data input by the user to the chip will also be calculated to a corresponding hash value. The chip can determine whether the user has tampered with the data under the chip by comparing whether the hash values are the same.

[0121] The maliciously secure two-party linear layer calculation protocol of the present application is shown in Table 2:

[0122] Table 2

[0123]

[0124] In the above protocol, because the client does not know the hidden key in the chip, it cannot forge the hash value of the first data , so it cannot provide false first data . At the same time, because the server will verify the hash value of the mask value , it cannot send a false result mask value to the server.

[0125] Similarly, on the server side, it cannot forge the hash value of the second data , and cannot provide false . At the same time, because the server cannot obtain the fourth random number , it avoids replay attacks by the server. For model parameters , in the present protocol, they will not be immediately verified, but only the hash values thereof are calculated. In the last step of the large model inference protocol, the chip will verify the hash of all the input parameter values.

[0126] The above protocol ensures that during the inference process, both parties cannot provide incorrect input data.

[0127] In addition, the malicious participant can still provide incorrect instruction information, that is, not in accordance with the flow of protocol 2, and for this, in addition to calculating the hash value of the data, the chip also calculates the hash value of the instruction code input into the chip in the malicious security mode, ensuring that the participant cannot provide incorrect instructions.

[0128] In summary, the above protocol ensures the integrity of the input data, model parameters, and instruction information in the privacy inference process, achieving the purpose of malicious security.

[0129] In an embodiment of the present application, the word embedding protocol is based on homomorphic encryption, which completes the word embedding of large model inference. The execution flow of the word embedding protocol applied to the semi-honest security scenario includes: the client selects the corresponding ciphertext vector according to the word identifier input by itself, uses a randomly generated mask vector to perform homomorphic masking processing on the ciphertext vector, and sends the masked ciphertext back to the server. The server uses the private key to obtain the masked embedding result after decryption, and the client saves the opposite number of the mask value.

[0130] The word embedding protocol safely maps discrete word identifiers to continuous word vectors. The ciphertext vector is a vector form obtained by encrypting the original vector through an encryption algorithm such as homomorphic encryption. Homomorphic masking is a random mask vector used to perform encryption domain operation processing on the ciphertext vector in the homomorphic encryption environment.

[0131] It can be understood that after the client selects the ciphertext vector, it uses a random mask vector for homomorphic masking processing to ensure that the input word identifier is not directly exposed to the server; the server can only obtain the masked embedding result and cannot infer the true input, while the opposite number of the mask value saved by the client can be eliminated in subsequent calculations, thereby ensuring the correctness of the final inference result.

[0132] The present application supports the word embedding protocol of homomorphic encryption, and the function under the semi-honest security model is: the semi-honest security word embedding protocol requires the service provider to homomorphically encrypt and send the embedding vector of each word token to the service user, and the service user sends back the corresponding word token vector in the ciphertext form after masking with a random number, forming a secret sharing of the embedded result.

[0133] Specifically, the server first homomorphically encrypts all word vectors in the embedding matrix row by row using the client public key, and sends the ciphertext form of the embedding matrix to the client. As shown in the left half, Figure 4 As shown in the left half, the client selects the corresponding ciphertext vector according to the word identifier input by itself, and uses a randomly generated mask vector to perform homomorphic masking processing to hide the specific index position. The masked ciphertext is sent back to the server, and the server uses the private key to obtain the masked embedding result after decryption and the client saves the opposite of the random mask value, denoted as , and the sum of the two can restore the true embedding result . This method avoids the high calculation and memory overhead of traditional one-hot encoding matrix multiplication, is suitable for efficient inference scenarios when the embedding matrix is large, and is particularly suitable for deployment in trusted hardware with limited resources.

[0134] In an embodiment of the present application, the word embedding protocol of large model inference is implemented based on homomorphic encryption, and is checked by trusted hardware. The execution process of the word embedding protocol applied to the malicious security scenario includes: the client selects the corresponding ciphertext vector according to the word identifier input by itself, uses a randomly generated mask vector to perform homomorphic masking on the ciphertext vector, and sends the masked ciphertext back to the server. The server uses the private key to obtain the masked embedding result after decryption, and the client saves the opposite of the mask value. The server calculates the hash value of each plaintext embedding vector in the preprocessing stage and sends it to the client as a public commitment. The client selects the corresponding hash digest in the protocol execution process, and performs integrity checking by the trusted hardware of the service party in a hardware random number masking manner.

[0135] It can be understood that by calculating the hash value of each plaintext embedding vector by the server in the preprocessing stage and sending it to the client as a public commitment, the server can be prevented from replacing or tampering with the embedding vector during the execution process. The client selects the corresponding hash digest during the inference process, and performs integrity verification in combination with the random number mask in the trusted hardware, so that the embedding result after homomorphic masking and private key decryption is consistent with the original commitment.

[0136] The present application supports a word embedding protocol based on homomorphic encryption, and the function under the malicious security model is: the malicious security word embedding protocol is based on the semi-honest security word embedding protocol, and requires the service provider to provide the hash value of each word embedding vector. The service user sends the hash value masked with a random number, and the trusted hardware of the service provider performs integrity checking on the result of the word embedding protocol.

[0137] In the application to the malicious security scenario, in order to prevent the server or the client from forging the embedding result or tampering with the input index, the present application further introduces a lightweight verification mechanism based on a deterministic pseudo-random number generator and a hash function. The server calculates the hash value of each plaintext embedding vector in the preprocessing stage and sends it to the client as a public commitment. As shown in the right half of Figure 4 , the client selects the corresponding hash digest in the protocol execution process, and performs integrity checking by the trusted hardware of the service party in a hardware random number masking manner, preventing index tampering and data forgery. This mechanism has low calculation and communication overhead, and is suitable for scenarios that require integrity protection during the inference input stage.

[0138] In step S103, after completing the large model inference task, the execution result and proof information provided by the server are obtained, the execution result and proof information are verified, and if the verification fails, the execution result provided by the server is rejected.

[0139] It can be understood that by verifying the execution result returned by the server and the corresponding proof information after the inference task is completed, the client can effectively detect whether the inference process is tampered with, has calculation errors or malicious behavior. If the verification fails, the result is rejected, thereby avoiding privacy leakage or inference distortion due to incorrect or attacked results.

[0140] In an embodiment of the present application, the trusted hardware is provided with a result delivery and bidirectional verification protocol, wherein the execution flow of the result delivery and bidirectional verification protocol includes: the client and the server exchange respective instruction stream hash values, constants, weight hash values and result hash values, the result hash values are subjected to mask processing, the client uses the trusted hardware to calculate the hash value of the received execution result and verify, and the server remote proof information signature and content are verified. If there is a signature inconsistency or hash check failure, the execution result provided by the server is rejected.

[0141] It can be understood that through the result delivery and bidirectional verification protocol, the client and the server exchange instruction stream hash values, constants, weight hash values and result hash values after the large model inference task is completed, and the result hash values are subjected to mask processing, which can ensure the correctness and integrity of the inference result, and ensure that the result returned by the server is not tampered with, while preventing malicious servers from forging or modifying the result

[0142] After the large model inference is completed, the result delivery and bidirectional verification protocol of the present application also needs to be executed, as shown in Figure 5 to ensure that the inference result is not tampered with and the calculation correctness is verified. The protocol flow includes exchanging respective instruction stream hash values, constants and weight hash values and result hash values by both parties, and the result hash values are subjected to random number mask processing, thereby preventing potential tampering or forgery. The client uses the trusted hardware to verify the received calculation result and the proof information provided by the server, and if there is a signature inconsistency or hash check failure, the result is rejected, effectively preventing model reverse and result forgery attacks.

[0143] In a malicious security scenario, the protocol further relies on remote proof and hash verification to ensure the integrity of the result: before delivering the final calculation result, the service initiates a remote proof to the service provider, confirming that the hash values of the constant stream and the instruction stream in the hardware meet the expectations; then, the service provider initiates a remote proof to the service user, confirming the correctness of the hash values of the constant stream and the instruction stream in the hardware. For the calculation result , the service provider provides its hash value at the same time XOR value of the random number generated by the cryptographically secure pseudo-random number generator XOR value of the random number generated by the cryptographically secure pseudo-random number generator The service user can use hardware to verify the result, thereby ensuring the security and integrity of the calculation result.

[0144] In summary, the design and process of the large model privacy inference method based on trusted hardware according to the embodiments of the present application are as shown in Figure 6

[0145] The left part outlines the privacy inference method based on trusted hardware, covering linear layers, normalization layers, activation functions, normalization exponential functions, and matrix multiplication operators. These operators implement private operations on hardware through protocols. The gray area at the bottom of the figure indicates the implementation difficulties, including multi-operator link combination, matrix multiplication, and secure calculation of nonlinear functions. These operations require the assistance of semi-honest or malicious secure instruction sets to ensure the privacy of data and models.

[0146] The middle part shows the trusted hardware instruction set and protocol design. In the semi-honest security scenario, cryptographically secure pseudo-random numbers generated by hardware are used for data masking to prevent plaintext leakage. Malicious security instructions add hash verification and integrity verification on this basis to verify inputs, parameters, and intermediate results to prevent malicious tampering. The register module is responsible for storing inputs, masks, and instruction parameters, and supports hash and random number operations to ensure secure and reliable instruction execution.

[0147] The right side shows the inference system architecture, including user programs and hardware interface modules, which are responsible for receiving requests, managing hardware resources, calculating instruction streams, and completing encryption operations and privacy protection through trusted hardware. At the same time, it interacts with the cloud service to ensure the security of sensitive information during transmission and calculation. The process part is divided into five stages: trusted hardware initialization, word embedding processing, instruction compilation, instruction execution, and result delivery. The client and server complete initialization, data masking, hash generation, instruction execution, and result verification through hardware, ensuring data security at each step. Finally, it completes the ciphertext calculation and result exchange and provides integrity proof.

[0148] According to the large model privacy inference method based on trusted hardware according to the embodiments of the present application, before inference, the client and the server synchronize the initial seed of the pseudo-random number generator through information interaction to generate random numbers; during the inference process, homomorphic encryption is used to complete word embedding, and inference operators are converted into instruction combinations, combined with the privacy inference protocol and random numbers to perform privacy inference; after the inference is completed, the client verifies the execution result and proof information returned by the server, and if the verification fails, it refuses to receive the result. Thus, the problem of data leakage risk in related technologies is solved, and the problems of difficult to balance security and efficiency, etc. are solved. ​

[0149] Secondly, the device for large model privacy inference based on trusted hardware according to the embodiments of the present application is described with reference to the accompanying drawings.

[0150] Figure 7 is a block schematic diagram of the device for large model privacy inference based on trusted hardware according to the embodiments of the present application.

[0151] As Figure 7 shown, the device for large model privacy inference based on trusted hardware 10 includes an initialization module 100, an inference module 200, and a verification module 300.

[0152] The device is applied to trusted hardware of a client and a server respectively, the trusted hardware includes a first register, a second register, and a pseudo-random number generator, the client and the server are prohibited from reading the second register of the other party, wherein the trusted hardware includes: the initialization module 100, configured to initialize the pseudo-random number generator of each party based on information interaction before performing a large model inference task, so as to synchronize the initial seed of the pseudo-random number generator, and the pseudo-random number generator generates a random number based on the initial seed; the inference module 200, configured to, in the process of performing the large model inference task, complete word embedding of the large model inference based on homomorphic encryption, convert all operators in the large model inference task into instruction combinations by using an inference instruction set, perform privacy inference on the instruction combinations by using a privacy inference protocol and the random number generated by the pseudo-random number generator, store the read data into the first register, and store the privacy inference result and the random number into the second register; and the verification module 300, configured to, after completing the large model inference task, acquire an execution result and proof information provided by the server, verify the execution result and the proof information, and if the verification fails, refuse to receive the execution result provided by the server.

[0153] In an embodiment of the present application, the trusted hardware is provided with an initialization protocol, the initialization protocol includes a semi-honest initialization protocol and a malicious security initialization protocol, the semi-honest initialization protocol is applied to a semi-honest security scenario, and the malicious security initialization protocol is applied to a malicious security scenario, wherein the execution process of the semi-honest initialization protocol includes that the server generates a true random number as a seed, encrypts the seed by using a public key of the client, signs the seed by using a private key of the server, the client verifies the signature, decrypts the message, and recovers the seed after receiving the seed, and the both parties initialize the pseudo-random number generator of each party by using the seed; and the execution process of the malicious security initialization protocol includes that the client generates a random number and sends the random number to the server, the server generates a seed and a random number, encrypts the seed and the random number, and sends the seed and the random number back to the client, and the client initializes the local pseudo-random number generator after verifying the session identifier of the encrypted data.

[0154] In an embodiment of the present application, the trusted hardware is provided with a result delivery and bidirectional verification protocol, wherein the execution flow of the result delivery and bidirectional verification protocol includes: the client and the server exchange respective instruction stream hash values, constants, weight hash values and result hash values, the result hash values are subjected to mask processing, the client uses the trusted hardware to calculate a hash value of the received execution result and verify, sign and verify the content of the server remote proof information, and if there is a signature inconsistency or hash check failure, the received execution result provided by the server is rejected.

[0155] In an embodiment of the present application, the inference instruction set includes a semi-honest secure instruction set and a malicious secure inference instruction, the privacy inference protocol includes a semi-honest secure privacy inference protocol and a malicious secure privacy inference protocol, the semi-honest secure instruction and the semi-honest secure privacy inference protocol are used in a semi-honest secure scenario, and the malicious secure inference instruction and the malicious secure privacy inference protocol are used in a malicious secure scenario, wherein the semi-honest secure instruction includes a multiplication instruction, an inverse calculation instruction and a sign bit extraction instruction, and the malicious secure inference instruction includes a multiplication instruction, an inverse calculation instruction, a sign bit extraction instruction and a hash instruction.

[0156] In an embodiment of the present application, the privacy data of a large model inference task is held in the form of a secret share by two parties, and the semi-honest secure privacy inference protocol is based on a semi-honest secure instruction to perform inference, including: the client and the server each have a synchronized random number stream in the trusted hardware; the client uses the trusted hardware to generate a random number stream, and uses the random number stream to mask the secret share held by the client, and sends the masked result to the server; the trusted hardware of the server decodes the masked result, combines the secret share held by the server, restores the privacy data, and completes the calculation, after the calculation is completed, the trusted hardware of the server generates a new random number, and outputs the calculation result after masking as the secret share of the server; the client holds the new random number as a secret share.

[0157] In an embodiment of the present application, the malicious secure privacy inference protocol and the semi-honest secure privacy inference protocol have the same inference process under the same instruction. The inference process of the malicious secure privacy inference protocol based on the hash instruction includes that the client and the server respectively hold a secret share of input data, and the trusted hardware knows the hash value of the secret share; the client generates a random number stream using the trusted hardware, masks the secret share held by the client using the random number stream, the trusted hardware of the client checks the hash value of the secret share, the trusted hardware of the client calculates the hash value according to the result after masking, and outputs the hash value after masking with a random number, and the client sends the mask of the secret share and the mask of the hash value to the server; the trusted hardware of the server internally decodes the secret share sent by the client, simultaneously decodes the hash value thereof, and checks the hash value. If correct, the server outputs the secret share of the server to the trusted hardware of the server. The trusted hardware of the server checks the hash value of the secret share. If correct, the input data can be recovered in the trusted hardware of the server, and calculation is performed. After the calculation is completed, the trusted hardware of the server generates a new random number, masks the calculation result, and outputs the calculation result as the secret share of the server. At the same time, the trusted hardware of the server calculates the hash value of the secret share and outputs the hash value. The trusted chip of the client generates the same random number as the server as the secret share of the client, calculates the hash value of the client, and outputs the hash value.

[0158] In an embodiment of the present application, the word embedding protocol is based on homomorphic encryption, and completes the word embedding of large model inference. The execution process of the word embedding protocol applied to a semi-honest secure scene includes that the client selects a corresponding ciphertext vector according to a word identifier input by the client, performs homomorphic masking processing on the ciphertext vector using a randomly generated mask vector, the masked ciphertext is sent back to the server, the server decrypts using a private key to obtain a masked embedding result, and the client saves an inverse number of the mask value.

[0159] In an embodiment of the present application, the word embedding protocol of large model inference is implemented based on homomorphic encryption, and is completed by trusted hardware for checking. The execution process of the word embedding protocol applied to a malicious secure scene includes that the client selects a corresponding ciphertext vector according to a word identifier input by the client, performs homomorphic masking processing on the ciphertext vector using a randomly generated mask vector, the masked ciphertext is sent back to the server, the server decrypts using a private key to obtain a masked embedding result, and the client saves an inverse number of the mask value. The server calculates a hash value of each plaintext embedding vector in a preprocessing stage and sends the hash value to the client as a public commitment. The client selects a corresponding hash digest in a protocol execution process, and performs integrity checking by the trusted hardware of the service party in a hardware random number masking manner.

[0160] It should be noted that the foregoing explanation and description of the method for privacy inference of a large model based on trusted hardware also applies to the device for privacy inference of a large model based on trusted hardware, and will not be repeated here.

[0161] The device for privacy inference of a large model based on trusted hardware according to the embodiments of the present application, before inference, the client and the server synchronize the initial seed of the pseudo-random number generator through information interaction to generate a random number; in the inference process, the homomorphic encryption is used to complete the word embedding, and the inference operator is converted into an instruction combination, and the privacy inference is performed in combination with the privacy inference protocol and the random number, the data is stored in the first register, and the result and the random number are stored in the second register; after the inference is completed, the client verifies the execution result and the proof information returned by the server, and if the verification fails, the result is refused to be received. Thus, the problems of data leakage risk, difficulty in balancing security and efficiency, etc. in the related art are solved.

[0162] Figure 8 The structure schematic diagram of the electronic device provided by the embodiments of the present application is provided. The electronic device can include:

[0163] The memory 801, the processor 802 and the computer program stored in the memory 801 and executable on the processor 802.

[0164] The processor 802 implements the method for privacy inference of a large model based on trusted hardware provided in the above embodiments when executing the program.

[0165] Further, the electronic device further includes:

[0166] The communication interface 803 is used for communication between the memory 801 and the processor 802.

[0167] The memory 801 is used to store the computer program executable on the processor 802.

[0168] The memory 801 can include a high-speed RAM (Random Access Memory, Random Access Memory) memory, and can also include a non-volatile memory, such as at least one disk memory.

[0169] If the memory 801, the processor 802 and the communication interface 803 are implemented independently, the communication interface 803, the memory 801 and the processor 802 can be connected with each other through a bus and complete communication between each other. The bus can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, Figure 8 Only one thick line is used in the figure to represent the bus, but it does not mean that there is only one bus or only one type of bus.

[0170] Optionally, in a specific implementation, if the memory 801, the processor 802 and the communication interface 803 are integrated on a chip, the memory 801, the processor 802 and the communication interface 803 can complete communication between each other through an internal interface.

[0171] The processor 802 can be a CPU (Central Processing Unit), or an ASIC (Application Specific Integrated Circuit), or an integrated circuit configured to implement one or more embodiments of the present application.

[0172] In the description of the present specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example" or "some examples" means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In the present specification, the illustrative description of the above terms is not necessarily for the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or N embodiments or examples in a suitable manner. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the present specification and the features of the different embodiments or examples without contradiction.

[0173] In addition, the terms "first", "second" are only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present application, the meaning of "N" is at least two, for example, two, three, etc., unless otherwise specifically limited.

[0174] Any procedural or methodological descriptions in flow charts or otherwise described herein can be understood to represent modules, segments or portions of code that include executable instructions for implementing custom logic functions or procedures that are one or N steps, and the scope of the preferred embodiments of the present application includes further implementations in which the steps are performed in an order other than that shown or discussed, including substantially simultaneously, in reverse order, or in an order that is otherwise dependent on the functionality involved, as will be understood by those skilled in the art to which embodiments of the present application pertain.

[0175] It should be understood that portions of the present application can be realized with hardware, software, firmware or any combination thereof. In the above embodiments, the steps or methods can be realized with software or firmware stored in memory and executed by a suitable instruction execution system. As such, if realized with hardware and in another embodiment, any one or combination of the following technologies known in the art can be used: discrete logic circuitry having logic gates for implementing logic functions on data signals, application specific integrated circuits having appropriate combinational logic gates, programmable gate arrays, field programmable gate arrays, etc.

[0176] Those skilled in the art of the present technology can understand that all or part of the steps carried out by the method of the above-mentioned embodiments can be completed by programs instructing relevant hardware, and the above-mentioned programs can be stored in a computer readable storage medium, and when executed, include one or a combination of steps of the method embodiments.

[0177] Although the embodiments of the present application have been shown and described above, it can be understood that the above-mentioned embodiments are exemplary and cannot be understood as limiting the present application, and those skilled in the art can make changes, modifications, replacements and variations to the above-mentioned embodiments within the scope of the present application.

Claims

1. A privacy-preserving inference method for large models based on trusted hardware, characterized in that, The method is applied to trusted hardware of both the client and the server. The trusted hardware includes a first register, a second register, and a pseudo-random number generator. Neither the client nor the server is allowed to read the other's second register. The trusted hardware is configured to perform the following steps: Before performing a large model inference task, the client and the server initialize their respective pseudo-random number generators based on information interaction to synchronize the initial seeds of the pseudo-random number generators, and the pseudo-random number generators generate random numbers based on the initial seeds; During the execution of the large model inference task, word embedding for large model inference is completed based on homomorphic encryption. All operators in the large model inference task are converted into instruction combinations using the inference instruction set. Privacy inference is performed on the instruction combinations using the privacy inference protocol and the random number generated by the pseudo-random number generator. The read data is stored in the first register. The privacy inference result and the random number are stored in the second register. After completing the large model inference task, the execution result and proof information provided by the server are obtained, and the execution result and proof information are verified. If the verification fails, the execution result provided by the server is rejected.

2. The large-model privacy inference method based on trusted hardware according to claim 1, characterized in that, The trusted hardware is equipped with an initialization protocol, which includes a semi-honest initialization protocol and a malicious security initialization protocol. The semi-honest initialization protocol is applied to semi-honest security scenarios, and the malicious security initialization protocol is applied to malicious security scenarios. The execution process of the semi-honest initialization protocol includes: the server generates a true random number as a seed, encrypts it using the client's public key, signs it with the server's private key, the client receives the seed, verifies the signature, decrypts the message and restores the seed, and both parties initialize their respective pseudo-random number generators with the seed. The execution process of the malicious security initialization protocol includes: the client generates a random number and sends it to the server; the server generates a seed and encrypts the random number and sends it back to the client; after verifying the session identifier of the encrypted data, the client initializes a local pseudo-random number generator.

3. The large-model privacy inference method based on trusted hardware according to claim 1, characterized in that, The trusted hardware is equipped with a result delivery and two-way verification protocol. The execution process of the result delivery and two-way verification protocol includes: the client and the server exchanging their respective instruction stream hash values, constants, weight hash values, and result hash values; masking the result hash values; the client using the trusted hardware to calculate and verify the hash value of the received execution result, and verifying the signature and content of the server's remote proof information; if there is a signature mismatch or hash verification failure, the client refuses to receive the execution result provided by the server.

4. The large-model privacy inference method based on trusted hardware according to claim 1, characterized in that, The inference instruction set includes a semi-honest security instruction set and a malicious security inference instruction set. The privacy inference protocol includes a semi-honest security privacy inference protocol and a malicious security privacy inference protocol. The semi-honest security instructions and the semi-honest security privacy inference protocol are used in semi-honest security scenarios. The malicious security inference instructions and the malicious security privacy inference protocol are used in malicious security scenarios. The semi-honest security instructions include multiplication instructions, reciprocal calculation instructions, and sign-bit extraction instructions. The malicious security inference instructions include multiplication instructions, reciprocal calculation instructions, sign-bit extraction instructions, and hash instructions.

5. The large-model privacy inference method based on trusted hardware according to claim 4, characterized in that, In the large model inference task, the privacy data is held by both parties in a secret sharing manner. The semi-honest secure privacy inference protocol performs inference based on the semi-honest secure instructions, including: The client and server each have a synchronized random number stream in their trusted hardware. The client uses trusted hardware to generate a random number stream, and uses the random number stream to mask the secret it holds, and sends the masked result to the server. Within the trusted hardware of the server, the masking result is decoded, and combined with the secret sharing held by the server, the private data is recovered and the calculation is completed. After the calculation is completed, the trusted hardware of the server generates a new random number and outputs the calculation result after masking as the secret sharing of the server. The client holds a new random number as a secret to share.

6. The large-model privacy inference method based on trusted hardware according to claim 5, characterized in that, The malicious security and privacy inference protocol and the semi-honest security and privacy inference protocol have the same inference process under the same instructions. The inference process of the malicious security and privacy inference protocol based on the hash instructions includes: The client and server each hold a secret share of the input data, and the trusted hardware knows the hash value of this secret share; The client uses trusted hardware to generate a random number stream, uses the random number stream to mask the secret share held by the client, the client's trusted hardware verifies the hash value of the secret share, the client's trusted hardware calculates the hash value according to the masked result, and outputs the hash value after random number masking, and the client sends the mask of the secret share and the mask of the hash value to the server together. Inside the trusted hardware of the server, the secret share sent by the client is decoded, and its hash value is also decoded and verified. If the hash value is correct, the server outputs the secret share to the trusted hardware. The trusted hardware verifies the hash value of the secret share. If the hash value is correct, the input data can be recovered in the trusted hardware and calculations are performed. After the calculation is completed, the trusted hardware generates a new random number and outputs the calculation result after masking as the secret share of the server. At the same time, the trusted hardware calculates the hash value of this secret share and outputs it. The client's trusted chip generates the same random number as the server as the client's secret sharing, calculates the client's hash value, and outputs it.

7. The large-model privacy inference method based on trusted hardware according to claim 1, characterized in that, The word embedding protocol is based on homomorphic encryption and completes word embedding for large model inference. The execution flow of the word embedding protocol in a semi-honest security scenario includes: The client selects the corresponding ciphertext vector based on its input word identifier, performs homomorphic masking on the ciphertext vector using a randomly generated mask vector, and sends the masked ciphertext back to the server. The server decrypts the ciphertext using its private key to obtain the masked embedding result, and the client saves the inverse of the mask value.

8. The large-model privacy inference method based on trusted hardware according to claim 1, characterized in that, The word embedding protocol supports homomorphic encryption for word embedding in large model inference. The execution flow of the word embedding protocol in malicious security scenarios includes: The client selects the corresponding ciphertext vector based on the word identifier it inputs, and performs homomorphic masking on the ciphertext vector using a randomly generated mask vector. The masked ciphertext is sent back to the server, and the server decrypts it using its private key to obtain the masked embedding result. The client saves the inverse of the mask value. During the preprocessing phase, the server calculates a hash value for each plaintext embedding vector and sends it to the client as a public commitment. During protocol execution, the client selects the corresponding hash digest, which is then masked by a hardware random number and its integrity is checked by the server's trusted hardware.

9. A large-model privacy inference device based on trusted hardware, characterized in that, The device is applied to trusted hardware on both the client and the server. The trusted hardware includes a first register, a second register, and a pseudo-random number generator. Neither the client nor the server is allowed to read the other's second register. The trusted hardware includes: An initialization module is used to initialize the pseudo-random number generators of the client and the server based on information interaction before executing a large model inference task, so as to synchronize the initial seeds of the pseudo-random number generators, and the pseudo-random number generators generate random numbers based on the initial seeds; The inference module is used to complete word embedding for large model inference based on homomorphic encryption during the execution of the large model inference task, convert all operators in the large model inference task into instruction combinations using the inference instruction set, and perform privacy inference on the instruction combinations using the privacy inference protocol and the random numbers generated by the pseudo-random number generator. The verification module is used to obtain the execution results and proof information provided by the server after completing the large model inference task, and to verify the execution results and proof information. If the verification fails, the execution results provided by the server will be rejected.

10. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to implement the large model privacy inference method based on trusted hardware as described in any one of claims 1-8.