A flash key storage management method

By adopting the flash key storage management method in hardware encryption, secure encrypted storage and efficient storage management of keys are realized, and the problems of low efficiency and leakage risks in the prior art are solved, and storage utilization and key security are improved.

CN114528561BActive Publication Date: 2025-03-14SHANDONG SINOCHIP SEMICON CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210034309.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-13
Publication Date
2025-03-14
Estimated Expiration
2042-01-13

AI Technical Summary

Technical Problem

The prior art cannot effectively improve the utilization rate and utilization efficiency of key storage space in hardware encryption, and at the same time, traditional key storage has the risk of key leakage.

Method used

A flash key storage management method is adopted to ensure the security of key generation, storage and use through key encryption and decryption and key storage management, and to improve storage space utilization and key access efficiency by creating key storage MAP.

Benefits of technology

It realizes secure encrypted storage of keys, improves storage space utilization and key access efficiency, reduces the number of FLASH erases, extends the service life of FLASH, and effectively prevents key leakage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114528561B_ABST
    Figure CN114528561B_ABST
Patent Text Reader

Abstract

The present invention discloses a flash key storage management method, which includes two parts: key encryption and decryption and key storage management. Key encryption and decryption refers to that a key is subjected to encryption and decryption processing when it is generated, stored, and used; key storage management is to store the generated key in the SPI-NORFLASH of an encryption device in the form of a page, and a key management page and a key storage page are provided in the SPI-NORFLASH. The key management page includes a key management MAP1, a key management MAP2, S_ID, WL, and NUM. The key management MAP1 and MAP2 are used to record whether the key has been used, S_ID is used to record key decryption information, WL is used to record the number of times a block is used, NUM is used to record the total number of keys, and a key storage page is used to store keys, and key management is realized based on the key management page. The present invention ensures the security of keys in the process of generation, storage, and use, and can effectively improve the storage space utilization rate and key access efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of hardware encryption, in particular to key storage in hardware encryption, and specifically to a flash key storage management method. Background Art

[0002] In the field of independent hardware encryption, encryption keys imported from outside are often stored in FLASH media. The storage method is to create a file system in the flash to store the keys. This method cannot effectively improve storage space utilization and efficiency. In addition, traditional key storage is often stored in plain text in the storage medium. Once the storage medium is lost, the key will face the risk of leakage. Summary of the invention

[0003] In view of the defects of the prior art, the present invention provides a flash key storage management method, in which keys are stored in encrypted form to ensure the security of keys during generation, storage and use. At the same time, by creating a key storage MAP, the storage space utilization and key access efficiency can be effectively improved.

[0004] In order to solve the technical problem, the technical solution adopted by the present invention is: a flash key storage management method, the method includes two parts: key encryption and decryption and key storage management. Key encryption and decryption means that the key is encrypted during the generation process, stored in an encrypted state during storage, and decrypted when used; key storage management is to store the generated key in the SPI-NORFLASH of the encryption device in the form of a page. The SPI-NORFLASH is provided with a key management page and a key storage page. The key management page includes a key management MAP1, a key management MAP2, S_ID, WL and NUM. The key management MAP1 is used to record whether the encryption key has been used, the key management MAP2 is used to record whether the decryption key has been used, S_ID is used to record key decryption information, WL is used to record the number of times the block is used, NUM is used to record the total number of keys, and the key storage page is used to store the key. Key management is implemented based on the management page.

[0005] Furthermore, key encryption and decryption include key generation and encryption process, key import into SPI-NORFLASH process, key decryption and use process:

[0006] The key generation and encryption process is as follows:

[0007] Step 1: Call UKEY's random number interface to generate multiple sets of keys;

[0008] Step 2: UKEY generates the master key for encryption;

[0009] Step 3: The key management software calls UKEY's encryption algorithm, encrypts the generated keys one by one with the master key, and stores them in UKEY's secure storage area;

[0010] The specific process of importing the key into SPI-NORFLASH is as follows:

[0011] Step 1: Insert UKEY into the encryption device, and the key service software authenticates UKEY;

[0012] Step 2: After the first step is passed, obtain the key component r1 of UKEY and read the device UID of UKEY to perform HMAC operation, obtain the HMAC operation value, and store r1 and the HMAC operation value in the position of S_ID;

[0013] Step 3: Write all keys to the key storage page one by one and update MAP, which includes MAP1 and MAP2;

[0014] The key decryption and usage process is as follows:

[0015] Step 1: The key service software obtains a key skey';

[0016] Step 2: Read the data recorded by S_ID and parse out r1;

[0017] Step 3: Read the key component r2 of the master key from UKEY, and calculate the master key through r1 and r2;

[0018] Step 4: Decrypt skey' by calling the decryption algorithm with the master key to obtain skey;

[0019] Step 5: Send skey to the hardware encryption module.

[0020] Furthermore, the legitimacy of UKEY is verified when the key is used. The verification process is as follows: when the key is used, the encryption device inserts UKEY when the system is turned on, reads the key component r2 of the master key from UKEY and puts it into the memory, and performs HMAC operation on the device ID of UKEY, and compares it with the previously stored HMAC operation value. If the comparison is consistent, it proves that UKEY is legal.

[0021] Furthermore, the process of obtaining the key based on the key management page is as follows:

[0022] 1. First read the WL value. If WL is 0xFFFF, it means that the current storage area has been erased and written more than 5W times. Get the WL value from the offset 33×PAGE_SIZE*n. n is accumulated from 1 until the WL value is not 0xFFFF. Record the PAGE offset n.

[0023] 2. Get the NUM value and read the MAP value of the corresponding length;

[0024] 3. Determine the number of keys that have been used based on the MAP value;

[0025] 4. Read a new key;

[0026] 5. Update the MAP value and mark the key at the corresponding position as used.

[0027] Furthermore, key management MAP1 and key management MAP2 record whether the key has been used bit by bit. A bit of 1 indicates that the key has not been used, and a bit of 0 indicates that the key has been used. When updating MAP after reading a key, there is no need to erase PAGE and rewrite it, only the corresponding bit needs to be set from 1 to 0.

[0028] Furthermore, the process of updating the key based on the key management page is as follows:

[0029] 1. Get the current WL value;

[0030] 2. Read the S_ID of the key management page and store it in the designated area;

[0031] 3. Erase the key management page;

[0032] 4. Update the key management page, write 1 to all MAP, take S_ID read in step 2, WL = WL+1, and write the actual number of keys in NUM;

[0033] 5. Write the key to the key storage page.

[0034] Furthermore, the process of destroying the key based on the key management page is as follows:

[0035] 1. Get the current WL value;

[0036] 2. Erase the key management page;

[0037] 3. Erase the key storage page.

[0038] Furthermore, 2000 groups of keys are generated, each key has a maximum length of 64 bytes, 32 4K key storage pages are provided, and an additional key management page is added.

[0039] Beneficial effects of the present invention: The present invention proposes a flash key storage management method, which can effectively improve the storage space utilization and key access efficiency by creating a key storage MAP, and can also reduce the number of FLASH erasures and improve the service life of FLASH. In view of the problem that existing keys are facing the risk of leakage, the present method proposes a method for encrypting and storing keys, ensuring that the keys are stored in the FLASH in the form of ciphertext, and when actually used, the keys are decrypted in the memory to ensure the security of the keys during generation, storage and use. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 This is a schematic diagram of the key management page;

[0041] Figure 2 A schematic diagram of key storage. DETAILED DESCRIPTION

[0042] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0043] Example 1

[0044] This embodiment discloses a flash key storage management method, which includes two parts: key encryption and decryption and key storage management. Key encryption and decryption refers to the encryption process of the key during the generation process, the storage in an encrypted state during storage, and the decryption process when used, so as to ensure the security of the key during the generation, storage and use processes.

[0045] In this embodiment, key encryption and decryption include a key generation and encryption process, a key import into SPI-NORFLASH process, and a key decryption and use process.

[0046] The key generation and encryption process is as follows:

[0047] Step 1: Call UKEY's random number interface to generate multiple sets of keys;

[0048] Step 2: UKEY generates the master key for encryption;

[0049] Step 3: The key management software calls UKEY's encryption algorithm, encrypts the generated keys one by one with the master key, and stores them in UKEY's secure storage area;

[0050] The specific process of importing the key into SPI-NORFLASH is as follows:

[0051] Step 1: Insert UKEY into the encryption device, and the key service software authenticates UKEY;

[0052] Step 2: After the first step is passed, obtain the key component r1 of UKEY and read the device UID of UKEY to perform HMAC operation, obtain the HMAC operation value, and store r1 and the HMAC operation value in the position of S_ID;

[0053] Step 3: Write all keys to the key storage page one by one and update MAP, which includes MAP1 and MAP2.

[0054] The key decryption and usage process is as follows:

[0055] Step 1: The key service software obtains a key skey';

[0056] Step 2: Read the data recorded by S_ID and parse out r1;

[0057] Step 3: Read the key component r2 of the master key from UKEY, and calculate the master key through r1 and r2;

[0058] Step 4: Decrypt skey' by calling the decryption algorithm with the master key to obtain skey;

[0059] Step 5: Send skey to the hardware encryption module.

[0060] The legitimacy of UKEY is verified when the key is used. The verification process is as follows: when the key is used, the encryption device inserts UKEY when the system is turned on, reads the key component r2 of the master key from UKEY and puts it into the memory, and performs HMAC operation on the device ID of UKEY, and compares it with the previously stored HMAC operation value. If the comparison is consistent, it proves that UKEY is legal.

[0061] In this embodiment, the SM4 encryption and decryption algorithm is used to encrypt and decrypt the key.

[0062] In this solution, the carrier for key storage is SPI-Flash.

[0063] According to the capacity of Flash, it is designed to store up to N (N=2000) groups of keys. The maximum length of each key is 64 bytes. Therefore, 32 4K PAGEs are required to store all the keys, and an additional PAGE is added for key management (i.e., management PAGE).

[0064] Due to the characteristics of Flash, 0 is stored as 1 in Flash, and 1 is stored as 0. Since the value in Flash can only be set from 1 to 0, but not from 0 to 1, first write 1 to a byte [0 0 0 0 0 0 0 1], then write 2 (because it can only be set from 1 to 0, so after writing 2 [0 0 0 0 0 0 0 1 0], the byte becomes [0 0 0 0 0 0 0 0]), the read value is 0. If you first write ~1 to a byte [1 1 1 1 1 1 0], and then write ~2 [1 1 1 1 1 1 0 0], the read value is ~3. This feature can be used to reduce the number of erase and write times. That is, when updating MAP, there is no need to erase PAGE and rewrite, just set the corresponding bit from 1 to 0.

[0065] In addition, the minimum unit of Flash erasure is 4096 bytes (one PAGE), the reliable erase and write times are 100,000 times, and the data read out after erasing is complete is all FF.

[0066] Key storage management is to store the generated key in the form of pages. There are key management pages and key storage pages in the SPI-NORFLASH of the encryption device, such as Figure 1 As shown, the key management page includes key management MAP1, key management MAP2, S_ID, WL and NUM:

[0067] Key management MAP1: 2000 / 8 = 250 bytes (records whether the key has been used bit by bit, encryption key)

[0068] Key management MAP2: 2000 / 8 = 250 bytes (records whether the key has been used bit by bit, decryption key)

[0069] S_ID: records the HMAC calculation value of UKEY's ID and key component r1, 48 bytes.

[0070] WL: Records the number of times the block is used, 2 bytes. If the storage location is changed more than 50,000 times, the number is recorded as 0xFFFF.

[0071] NUM: records the total number of keys, with a maximum of 2000 keys, 2 bytes.

[0072] The key storage page is used to store keys, such as Figure 2 As shown, the first PAGE is the management page, and the next 32 PAGEs store 2000 groups of keys.

[0073] The process of obtaining the key based on the key management page is as follows:

[0074] 1. First read the WL value. If WL is 0xFFFF, it means that the current storage area has been erased and written more than 5W times. Get the WL value from the offset 33×PAGE_SIZE*n. n is accumulated from 1 until the WL value is not 0xFFFF. Record the PAGE offset n.

[0075] Note: The value of 33 means that it includes 1 key management PAGE and 32 key storage PAGEs.

[0076] 2. Get the NUM value and read the MAP value of the corresponding length;

[0077] 3. Determine the number of keys that have been used based on the MAP value;

[0078] 4. Read a new key;

[0079] 5. Update the MAP value and mark the key at the corresponding position as used.

[0080] After reading a key, update the MAP method:

[0081] 1. Get the current MAP:

[0082] char currentMap;

[0083] this->getKeyMap(¤tMap, 1, (int)(usedKeyNum / 8));

[0084] If 65 keys are currently in use, the map offset of the record KEY should be 65 / 8=8, the 8th byte offset.

[0085] 2. Recalculate MAP after obtaining a key:

[0086] currentMap &= ~(1 << (usedKeyNum % 8));

[0087] Note: The value of usedKeyNum % 8 is 1, and the value of 1 shifted left by 1 bit and inverted is 1111...1101

[0088] The current value of currentMap is 1111...1110, which becomes 1111...1100 after the above operation. This operation is to clear the 66th bit byte to 0, that is, after obtaining the key, the 66-bit position where the key is located is set to 0.

[0089] 3. Update Map Value

[0090] this->setKeyMap(¤tMap, 1, (int)(usedKeyNum / 8)).

[0091] The process of updating the key based on the key management page is as follows:

[0092] 1. Get the current WL value;

[0093] 2. Read the S_ID of the key management page and store it in the designated area;

[0094] 3. Erase the key management page;

[0095] 4. Update the key management page, write 1 to all MAP, take S_ID read in step 2, WL = WL+1, and write the actual number of keys in NUM;

[0096] 5. Write the key to the key storage page.

[0097] The process of destroying a key based on the key management page is as follows:

[0098] 1. Get the current WL value;

[0099] 2. Erase the key management page;

[0100] 3. Erase the key storage page.

[0101] In this embodiment, 2000 groups of keys are generated, and the maximum length of each key is 64 bytes. In this embodiment, the length is 16 bytes. There are 32 4K key storage pages, and an additional key management page is added.

[0102] This embodiment implements an encryption and decryption mechanism to ensure the security of the key during generation, storage and use. The key management method adopted improves the security and efficiency of key storage, saves Flash storage space, reduces the number of Flash erases and writes, and thus improves the life and utilization efficiency of Flash.

[0103] The above description is only the basic principle and preferred embodiments of the present invention. Improvements and substitutions made by those skilled in the art based on the present invention belong to the protection scope of the present invention.

Claims

1. A flash key storage management method, characterized in that: The method includes two parts: key encryption and decryption and key storage management. Key encryption and decryption means that the key is encrypted during the generation process, stored in an encrypted state, and decrypted when used; Key storage management is to store the generated key in the form of page in the SPI-NORFLASH of the encryption device. SPI-NORFLASH is provided with key management page and key storage page. The key management page includes key management MAP1, key management MAP2, S_ID, WL and NUM. Key management MAP1 is used to record whether the encryption key has been used, key management MAP2 is used to record whether the decryption key has been used, S_ID is used to record key decryption information, WL is used to record the number of times the block is used, NUM is used to record the total number of keys, and the key storage page is used to store keys. Key management is implemented based on the key management page. Key encryption and decryption includes key generation and encryption process, key import into SPI-NORFLASH process, key decryption and use process: The key generation and encryption process is as follows: Step 1: Call UKEY's random number interface to generate multiple sets of keys; Step 2: UKEY generates the master key for encryption; Step 3: The key management software calls UKEY's encryption algorithm, encrypts the generated keys one by one with the master key, and stores them in UKEY's secure storage area; The specific process of importing the key into SPI-NORFLASH is as follows: Step 1: Insert UKEY into the encryption device, and the key service software authenticates UKEY; Step 2: After the first step is passed, obtain the key component r1 of the master key and read the device UID of UKEY to perform HMAC operation to obtain the HMAC operation value, and store r1 and the HMAC operation value in the position of S_ID; Step 3: Write all keys to the key storage page one by one and update MAP, which includes MAP1 and MAP2; The key decryption and usage process is as follows: Step 1: The key service software obtains a key skey'; Step 2: Read the data recorded by S_ID and parse out r1; Step 3: Read the key component r2 of the master key from UKEY, and calculate the master key through r1 and r2; Step 4: Decrypt skey' by calling the decryption algorithm with the master key to obtain skey; Step 5: Send skey to the hardware encryption module.

2. The flash key storage management method according to claim 1, characterized in that: The legitimacy of UKEY is verified when the key is used. The verification process is as follows: when the key is used, the encryption device inserts UKEY when the system is turned on, reads the key component r2 of the master key from UKEY and puts it into the memory, and performs HMAC operation on the device UID of UKEY, and compares it with the previously stored HMAC operation value. If the comparison is consistent, it proves that UKEY is legal.

3. The flash key storage management method according to claim 1, characterized in that: The process of obtaining the key based on the key management page is as follows:

1. First read the WL value. If WL is 0xFFFF, it means that the current storage area has been erased and written more than 5W times. Get the WL value from the offset N×PAGE_SIZE*n. n is accumulated from 1 until the WL value is not 0xFFFF. Record the PAGE offset n. N is the total number of key management pages and key storage pages.

2. Get the NUM value and read the MAP value of the corresponding length; 3. Determine the number of keys that have been used based on the MAP value; 4. Read a new key; 5. Update the MAP value and mark the key at the corresponding position as used.

4. The flash key storage management method according to claim 1 or 3, characterized in that: Key management MAP1 and key management MAP2 record whether the key has been used bit by bit. A bit of 1 indicates that the key has not been used, and a bit of 0 indicates that the key has been used. When updating MAP after reading a key, there is no need to erase PAGE and rewrite it, but only need to set the corresponding bit from 1 to 0.

5. The flash key storage management method according to claim 1, characterized in that: The process of updating the key based on the key management page is as follows:

1. Get the current WL value; 2. Read the S_ID of the key management page and save it to the specified area; 3. Erase the key storage page; 4. Update the key management page, write 1 to all MAP, take S_ID read in step 2, WL = WL+1, and write the actual number of keys in NUM; 5. Write the key to the key storage page.

6. The flash key storage management method according to claim 1, characterized in that: The process of destroying a key based on the key management page is as follows:

1. Get the current WL value; 2. Erase the key management page; 3. Erase the key storage page.

7. The flash key storage management method according to claim 1, characterized in that: Generate 2000 sets of keys, each with a maximum key length of 64 bytes, with 32 4K key storage pages and an additional key management page.

Citation Information

Patent Citations

  • Method for reducing in-chip FLASH erasing frequency

    CN107608906A

  • Key management method and device for prolonging service life of flash

    CN111832087A