DUKPT algorithm processing method based on littlefs file system

By using the combination of littlefs file system and RAM space in the DUKPT algorithm, the device failure and memory problems during key storage are solved, the stability and speed of the algorithm are improved, and the service life of the device is extended.

CN119094122APending Publication Date: 2024-12-06AITIWEIER ELECTRONICS TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411241652.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-05
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

When storing keys, the DUKPT algorithm is prone to damage or loss of keys due to device power loss, memory blocks or memory service life reaching the limit, resulting in transaction failure and data errors. The existing enhanced functions limit the running speed of the algorithm.

Method used

The littlefs file system is used to open up RAM space for the initial and update key reading or writing of the DUKPT algorithm. After completion, the key is written to the Flash storage at one time to avoid frequent Flash read and write operations affecting the speed.

Benefits of technology

It improves the operating stability and speed of the DUKPT algorithm, extends the service life of the equipment, avoids file loss and data errors, and achieves stable operation and speed improvement of the equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094122A_ABST
    Figure CN119094122A_ABST
Patent Text Reader

Abstract

The invention relates to the field of electronic communication and financial payment, and discloses a DUKPT algorithm processing method based on a littlefs file system. The method comprises the steps that a security chip receives a DUKPT initialization key and a KSN from an upper computer, a section of RAM space is developed for storing a DUKPT derived key and 21 sets of keys derived by a DUKPT algorithm, each set of keys is independently encrypted and written into an RAM, after key derivation is completed, all the derived keys are written into FLash at a time through a littlefs file system, and RAM space data storing the keys are reset and released; and when the security chip executes the DUKPT secret key to calculate the MAC and the PIN, a section of RAM space is also split, the secret key is read from the Falsh by using a littlefs file system and is put into the RAM section space, after the MAC and the PIN are calculated, the corresponding secret key is derived again by using a new KSN, and the secret key is written into the Flash from the RAM after the secret key derivation is completed. According to the method, the speed of the DUKPT algorithm can be increased, power failure or reset data storage, erasing and writing balance and Flash bad block processing can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of electronic communication and financial payment, and in particular to a method for DUKPT algorithm processing based on a littlefs file system. Background Art

[0002] DUKPT algorithm key management technology is currently widely used in the field of financial payment. Its one-time pad design uses an irreversible key derivation algorithm to ensure transaction security and data confidentiality. The DUKPT algorithm frequently reads and writes derived keys during the application process. When the current technology operates the DUKPT algorithm to store keys, the device can operate normally in normal state. However, if the device is out of power, the device is shut down, the memory is bad, or the memory service life reaches the limit when writing DUKPT key data, the original DUKPT key file may be damaged or lost, resulting in transaction failure. It may even cause the device to falsely report that a software attack is triggered and clear all protected important file information. In order to solve the problem of data error or data loss in the above abnormal situations, some technologies have implemented power-off recovery, memory bad block detection, and erase and write leveling functions in DUKPT algorithm key storage, but these added functions also bring new problems, such as greatly limiting the running speed of the DUKPT algorithm. Summary of the invention

[0003] The purpose of the present invention is to provide a method for DUKPT algorithm processing based on littlefs file system in view of the above technical defects. When applying the functions of power-off recovery, memory bad block detection and erase-write balance of littlefs file system, a RAM space is opened up in combination with the DUKPT algorithm execution process as a storage space for reading or writing keys in the process of initial derived keys and updating derived keys of DUKPT algorithm. After the derived keys are completed, the generated keys are written into the Flash key storage space through the littlefs file system at one time to avoid frequent reading and writing of data from Flash to affect the algorithm speed, thereby solving the problems of equipment power failure, operation shutdown, memory bad block, short memory service life, etc. when the DUKPT algorithm is in use, avoiding the problems of file loss, data error, slow execution speed, etc., so that the equipment running the DUKPT algorithm can be operated stably, the speed is improved, and the service life is extended. Thus, the above-mentioned problems existing in the prior art are solved.

[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0005] A method for DUKPT algorithm processing based on littlefs file system comprises: a security chip receives a DUKPT initialization key and KSN from a host computer, opens up a RAM space for storing a derived key of DUKPT, 21 groups of keys derived by the DUKPT algorithm, each group of keys is encrypted and written into RAM separately, after key derivation is completed, all derived keys are written into FLash at one time using littlefs file system, and RAM space data storing keys is reset and released.

[0006] Preferably, it also includes: when the security chip executes the DUKPT key to calculate the MAC and PIN, a section of RAM space is also split, and the key is read from Falsh using the littlefs file system and placed in the RAM segment space. After the MAC and PIN are calculated, the corresponding key is re-derived using the new KSN. After the key derivation is completed, the key is written from RAM to Flash.

[0007] Preferably, the specific process of initializing the derived key using the DUKPT algorithm is as follows:

[0008] S1. Receive BDK and KSN: The security chip receives the BDK and KSN number of the DUKPT algorithm from the host computer, and applies for a RAM space to store the derived key, KSN number, verification information, and key management information generated during the initialization process;

[0009] S2. Write BDK to address 21 of the derived key in RAM and store KSN: Before writing data to RAM, calculate the check value of BDK first, encrypt it and write it to address 21 of the derived key in RAM; calculate the check value of KSN and encrypt it and store it in RAM, clear the encryption counter;

[0010] S3, DUKPT derived key: The highest position of the encryption counter is 1, and the 64 bits on the right of the key serial number are placed in encryption register 1. The irreversible key generation algorithm is operated, and the data of encryption register 1 after the operation is placed in the upper 8 bits of the derived key, and the data of encryption register 2 is placed in the lower 8 bits of the derived key;

[0011] S4, the derived key is encrypted and written to RAM: the derived key is added with verification information, storage information, encrypted and written to the corresponding future key address in RAM;

[0012] S5, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to this bit;

[0013] S6, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation, otherwise jump to S3 to continue the key derivation;

[0014] S7, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

[0015] Preferably, after the DUKPT algorithm PIN or MAC is obtained, the specific process of deriving the update key is as follows:

[0016] S8, receiving PIN or MAC calculation instructions: After receiving the PIN or MAC calculation instructions from the host computer, the security chip applies for a RAM space to store the DUKPT key, KSN, and key usage information;

[0017] S9, read DUKPT key and operation information from Flash to RAM: before calculating PIN or MAC, first read the data of DUKPT key storage area from Flash through littlefs file system interface and put it into RAM, then decrypt DUKPT key and KSN data, calculate and compare whether the check value is correct, whether DUKPT key exists, whether the read key ID is the same as the currently used key ID, if all is OK, perform PIN or MAC calculation, otherwise report operation failure error code;

[0018] S10, extracting the key to calculate the PIN or MAC: using the decrypted PIN key or MAC key, calculate the PIN or MAC according to the PIN calculation mode or MAC calculation mode supported by the system;

[0019] S11, whether the number of digits of encryption counter 1 is less than 10: Check whether the number of digits of the lower 21 bits 1 of the encryption counter is less than 10. If it is less than 10, perform the key derivation operation, otherwise clear the information of using the key, add 1 to the encryption counter, exit the key derivation process, and execute S14 operation;

[0020] S12, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to the bit;

[0021] S13, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation and execute S14. Otherwise, after deriving the key, jump to S12 to continue execution.

[0022] S14, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

[0023] Preferably, the specific process of post-processing the derived key and securely writing DUKPT related data is:

[0024] S15, clear the variable information of the key, add one to the encryption counter and write it to RAM: clear the encryption register 1, the encryption register 2, set the calibration value invalid, etc.; add one to the encryption counter and write it to RAM: after the encryption counter is added by 1, calculate the check value, encrypt it, and write it to RAM;

[0025] S16. Write the data stored in RAM to Flash: Call the API encapsulation interface of littlefs to write all the keys, KSN, and key management information stored in RAM into Flash;

[0026] S17, DUKPT algorithm data writing exception handling: If the chip is reset or the device is powered off during the writing process, the data writing fails. After the device is powered on again, the data content of the DUKPT related files remains in the state before writing; if a Flash bad block is detected during data writing, the bad memory block is skipped and the DUKPT data is written to the new Flash block; finally, the calculation result and the corresponding KSN are sent to the host computer;

[0027] S18. Clear all data in RAM: After the key, KSN, and key operation information are written to the Flash storage, the data in RAM is cleared to release the RAM space.

[0028] A security chip, wherein the program executed in the security chip includes a program for implementing the method.

[0029] The beneficial effects of the present invention are:

[0030] The security chip receives the DUKPT initialization key and KSN from the host computer, and opens a RAM space to store the derived key of DUKPT. Each of the 21 groups of keys derived by the DUKPT algorithm is encrypted and written into the RAM separately. After the key derivation is completed, all the derived keys are written into the FLash at one time using the littlefs file system, and the RAM space data storing the key is reset and released. When the security chip executes the DUKPT key to calculate the MAC and PIN, a RAM space is also split, and the key is read from the Falsh and put into the RAM space using the littlefs file system. After calculating the MAC and PIN, the corresponding key is re-derived using the new KSN. After the key derivation is completed, the key is written from the RAM into the Flash. A method for processing the DUKPT algorithm based on the littlefs file system has the advantages of improving the speed of the DUKPT algorithm, preserving data during power failure or reset, erasing and writing leveling, and processing Flash bad blocks. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a schematic block diagram of the present invention;

[0032] Figure 2 It is a schematic diagram of the process of initializing the derived key of the DUKPT algorithm of the present invention;

[0033] Figure 3 It is a schematic diagram of the process of deriving and updating the key after the PIN or MAC of the DUKPT algorithm of the present invention is obtained;

[0034] Figure 4 It is a flow chart of the derived key post-processing and secure writing of DUKPT related data of the present invention. DETAILED DESCRIPTION

[0035] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation methods described herein are only used to explain the present invention and are not used to limit the present invention.

[0036] like Figure 1-Figure 4As shown, the present embodiment provides a method for DUKPT algorithm processing based on the littlefs file system, the method includes the security chip receiving the DUKPT initialization key and KSN from the host computer, opening up a RAM space for storing the derived key of DUKPT, 21 groups of keys derived by the DUKPT algorithm, each group of keys is encrypted and written into the RAM separately, after the key derivation is completed, all the derived keys are written into the FLash at one time using the littlefs file system, the RAM space data storing the key is reset and released; when the security chip executes the DUKPT key to calculate the MAC and PIN, a RAM space is also split, the key is read from the Falsh and put into the RAM segment space using the littlefs file system, after the MAC and PIN are calculated, the corresponding key is re-derived using the new KSN, the key derivation is completed, and the key is written into the Flash from the RAM. A method for DUKPT algorithm processing based on the littlefs file system has the advantages of improving the speed of the DUKPT algorithm, saving data during power failure or reset, erasure leveling and Flash bad block processing.

[0037] Specifically:

[0038] S1. Receive BDK and KSN: The security chip receives the BDK and KSN number of the DUKPT algorithm from the host computer, and applies for a RAM space to store the derived key, KSN number, verification information, and key management information generated during the initialization process;

[0039] S2. Write BDK to address 21 of the derived key in RAM and store KSN: Before writing data to RAM, calculate the check value of BDK first, encrypt it and write it to address 21 of the derived key in RAM; calculate the check value of KSN and encrypt it and store it in RAM, clear the encryption counter;

[0040] S3, DUKPT derived key: The highest position of the encryption counter is 1, and the 64 bits on the right of the key serial number are placed in encryption register 1. The irreversible key generation algorithm is operated, and the data of encryption register 1 after the operation is placed in the upper 8 bits of the derived key, and the data of encryption register 2 is placed in the lower 8 bits of the derived key;

[0041] S4, the derived key is encrypted and written to RAM: the derived key is added with verification information, storage information, encrypted and written to the corresponding future key address in RAM;

[0042] S5, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to this bit;

[0043] S6, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation, otherwise jump to B3 to continue the key derivation;

[0044] S7, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

[0045] S8, receiving PIN or MAC calculation instructions: After receiving the PIN or MAC calculation instructions from the host computer, the security chip applies for a RAM space to store the DUKPT key, KSN, and key usage information;

[0046] S9, read DUKPT key and operation information from Flash to RAM: before calculating PIN or MAC, first read the data of DUKPT key storage area from Flash through littlefs file system interface and put it into RAM, then decrypt DUKPT key and KSN data, calculate and compare whether the check value is correct, whether DUKPT key exists, whether the read key ID is the same as the currently used key ID, if all is OK, perform PIN or MAC calculation, otherwise report operation failure error code;

[0047] S10, extracting the key to calculate the PIN or MAC: using the decrypted PIN key or MAC key, calculate the PIN or MAC according to the PIN calculation mode or MAC calculation mode supported by the system;

[0048] S11, whether the number of digits of encryption counter 1 is less than 10: Check whether the number of digits of the lower 21 bits 1 of the encryption counter is less than 10. If it is less than 10, perform the key derivation operation, otherwise clear the information of using the key, add 1 to the encryption counter, exit the key derivation process, and perform B7 operation;

[0049] S12, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to the bit;

[0050] S13, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation. Otherwise, after deriving the key, jump to B5 to continue execution.

[0051] S14, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

[0052] S15, clear the variable information of the key, add one to the encryption counter and write it to RAM: clear the encryption register 1, the encryption register 2, set the calibration value invalid, etc.; add one to the encryption counter and write it to RAM: after the encryption counter is added by 1, calculate the check value, encrypt it, and write it to RAM;

[0053] S16. Write the data stored in RAM to Flash: Call the API encapsulation interface of littlefs to write all the keys, KSN, and key management information stored in RAM into Flash;

[0054] S17, DUKPT algorithm data writing exception handling: If the chip is reset or the device is powered off during the writing process, the data writing fails. After the device is powered on again, the DUKPT related file data content remains in the state before writing; if a Flash bad block is detected during data writing, the bad memory block is skipped and the DUKPT data is written to a new memory block. Finally, the calculation results and the corresponding KSN are sent to the host computer;

[0055] S18. Clear all data in RAM: After the key, KSN, and key operation information are written to the Flash storage, the data in RAM is cleared to release the RAM space.

[0056] The present invention also discloses a security chip, wherein the program executed in the security chip includes the program of the above-mentioned method.

[0057] By adopting the above technical solution disclosed in the present invention, the following beneficial effects are obtained:

[0058] The method includes the following steps: the security chip receives the DUKPT initialization key and KSN from the host computer, opens a RAM space for storing the derived key of DUKPT, and 21 groups of keys derived by the DUKPT algorithm, each group of keys is encrypted and written into the RAM separately, and after the key derivation is completed, all the derived keys are written into the FLash at one time using the littlefs file system, and the RAM space data storing the key is reset and released; when the security chip executes the DUKPT key to calculate the MAC and PIN, a RAM space is also split, and the key is read from the Falsh and put into the RAM segment space using the littlefs file system. After the calculation of the MAC and PIN is completed, the corresponding key is re-derived using the new KSN, and the key derivation is completed, and the key is written into the Flash from the RAM. A method for processing the DUKPT algorithm based on the littlefs file system has the advantages of improving the speed of the DUKPT algorithm, saving data after power failure or reset, erasing and writing leveling, and processing Flash bad blocks.

[0059] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the scope of protection of the present invention.

Claims

1. A method for DUKPT algorithm processing based on littlefs file system, It is characterized in that include: The security chip receives the DUKPT initialization key and KSN from the host computer, and opens up a RAM space to store the DUKPT derived key. The 21 groups of keys derived by the DUKPT algorithm are encrypted and written into the RAM separately. After the key derivation is completed, all the derived keys are written into the FLash at one time using the littlefs file system, and the RAM space data storing the keys is reset and released.

2. The method for DUKPT algorithm processing based on littlefs file system according to claim 1, It is characterized in that Also includes: When the security chip executes DUKPT key to calculate MAC and PIN, it also splits a section of RAM space, uses the littlefs file system to read the key from Falsh and put it into the RAM segment space, and after calculating MAC and PIN, uses the new KSN to re-derive the corresponding key. After the key derivation is completed, the key is written from RAM to Flash.

3. The method for DUKPT algorithm processing based on littlefs file system according to any one of claims 1 or 2, It is characterized in that The specific process of initializing the derived key of the DUKPT algorithm is as follows: S1. Receive BDK and KSN: The security chip receives the BDK and KSN number of the DUKPT algorithm from the host computer, and applies for a RAM space to store the derived key, KSN number, verification information, and key management information generated during the initialization process; S2. Write BDK to address 21 of the derived key in RAM and store KSN: Before writing data to RAM, calculate the check value of BDK first, encrypt it and write it to address 21 of the derived key in RAM; calculate the check value of KSN and encrypt it and store it in RAM, clear the encryption counter; S3, DUKPT derived key: The highest position of the encryption counter is 1, and the 64 bits on the right of the key serial number are placed in encryption register 1. The irreversible key generation algorithm is operated, and the data of encryption register 1 after the operation is placed in the upper 8 bits of the derived key, and the data of encryption register 2 is placed in the lower 8 bits of the derived key; S4, the derived key is encrypted and written to RAM: the derived key is added with verification information, storage information, encrypted and written to the corresponding future key address in RAM; S5, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to this bit; S6, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation, otherwise jump to S3 to continue the key derivation; S7, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

4. The method for DUKPT algorithm processing based on littlefs file system according to any one of claims 1 or 2, It is characterized in that After the DUKPT algorithm PIN or MAC is obtained, the specific process of deriving the update key is as follows: S8, receiving PIN or MAC calculation instructions: After receiving the PIN or MAC calculation instructions from the host computer, the security chip applies for a RAM space to store the DUKPT key, KSN, and key usage information; S9, read DUKPT key and operation information from Flash to RAM: before calculating PIN or MAC, first read the data of DUKPT key storage area from Flash through littlefs file system interface and put it into RAM, then decrypt DUKPT key and KSN data, calculate and compare whether the check value is correct, whether DUKPT key exists, whether the read key ID is the same as the currently used key ID, if all is OK, perform PIN or MAC calculation, otherwise report operation failure error code; S10, extracting the key to calculate the PIN or MAC: using the decrypted PIN key or MAC key, calculate the PIN or MAC according to the PIN calculation mode or MAC calculation mode supported by the system; S11, whether the number of digits of encryption counter 1 is less than 10: Check whether the number of digits of the lower 21 bits 1 of the encryption counter is less than 10. If it is less than 10, perform the key derivation operation, otherwise clear the information of using the key, add 1 to the encryption counter, exit the key derivation process, and execute S14 operation; S12, shift register right one bit: derive a key, shift register right one bit, the lower 21 bits of the shift register correspond to 21 derived keys, the current bit is 1, derive the future key corresponding to the bit; S13, check whether the shift register is all zero: determine whether the lower 21 bits of the shift register are all zero. If they are all zero, end the key derivation and execute S14. Otherwise, after deriving the key, jump to S12 to continue execution. S14, DUKPT derives the key post-processing, writes the data in RAM to Flash: After DUKPT uses the irreversible algorithm to derive the key, it clears the encryption register and check value information, writes the data in RAM to Flash securely using the littlefs file system, and clears the data in RAM.

5. The method for DUKPT algorithm processing based on littlefs file system according to any one of claims 1 or 2, It is characterized in that The specific process of post-processing the derived key and securely writing DUKPT related data is as follows: S15, clear the variable information of the key, add one to the encryption counter and write it into RAM: clear encryption register 1, encryption register 2, set calibration value invalid, etc.; The encryption counter is incremented by 1 and written into RAM: After the encryption counter is incremented by 1, the check value is calculated, encrypted, and written into RAM; S16. Write the data stored in RAM to Flash: Call the API encapsulation interface of littlefs to write all the keys, KSN, and key management information stored in RAM into Flash; S17, DUKPT algorithm data writing exception handling: If the chip is reset or the device is powered off during the writing process, the data writing fails. After the device is powered on again, the data content of the DUKPT related files remains in the state before writing; if a Flash bad block is detected during data writing, the bad memory block is skipped and the DUKPT data is written to the new Flash block; finally, the calculation result and the corresponding KSN are sent to the host computer; S18. Clear all data in RAM: After the key, KSN, and key operation information are written to the Flash storage, the data in RAM is cleared to release the RAM space.

6. A security chip, It is characterized in that The program executed in the security chip includes a program for implementing any one of the methods of claims 1-5.