A method for scheduling a PCIe cryptographic card based on a finite state machine

By abstracting the state of the PCIe cryptographic card into a finite state machine, the problems of code redundancy and instability are solved, and concise and efficient state management is achieved.

CN115688078BActive Publication Date: 2026-02-06SHANDONG SINOCHIP SEMICON CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211355426.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-01
Publication Date
2026-02-06
Estimated Expiration
2042-11-01

AI Technical Summary

Technical Problem

PCIe cryptographic cards frequently switch states during operation, resulting in redundant code that is difficult to understand and maintain, and also leads to program instability.

Method used

The state of the PCIe cryptographic card is abstracted into 7 states, and modeled using a finite state machine. Functional modules and engines are designed to achieve closed-loop management of state transitions.

Benefits of technology

It achieves a clear firmware architecture, concise code, improved program stability and execution efficiency, and reduced code maintenance difficulty.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115688078B_ABST
    Figure CN115688078B_ABST
Patent Text Reader

Abstract

The application discloses a PCIe cryptographic card scheduling method based on a finite state machine, abstracts several states of a PCIe cryptographic card device in operation, models behaviors of the device through the finite state machine, describes all state sequences of the PCIe device in an operation period and event requests from a host computer, and finally aims at realizing clear firmware program architecture, concise code, and robustness and stability of the program through the abstract method of the finite state machine, saving code overhead, and improving execution efficiency of the code. The method of introducing the finite state machine can make the program code easy to understand, the code architecture level clear, facilitate development and maintenance, reduce difficulty of later maintenance, and improve development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to a PCIe cryptographic card scheduling method based on a finite state machine and belongs to the PCIe cryptographic card scheduling field. BACKGROUND

[0002] A finite state machine (FSM) is a tool for modeling the behavior of an object, and its main function is to describe the state sequence experienced by the object in its life cycle and how to respond to various events from the outside world. In computer science, finite state machines are widely used in the technical fields of application behavior modeling, hardware circuit system design, software design, compilers, network protocols, etc. Usually in the field of firmware development, programmers often need to handle various events and state switching when implementing related business logic during programming, and the implementation is realized through various switch / case and if / else statements. When dealing with some complex business logic requirements, if a finite state machine is used to describe, the business model is abstracted into a finite state machine, and then the code will be particularly clear in logic and particularly structured in structure.

[0003] The PCIe cryptographic card has multiple states when working, and the traditional firmware is used for logical implementation, and the code is redundant. Once an unknown error occurs, the program is prone to crash. The entire firmware processing flow can also be realized through various switch / case and if / else statements, but when the device state frequently changes, the program jumps around, the code logic is more complex, and the code is inevitably redundant and difficult to understand. SUMMARY

[0004] The technical problem to be solved by the application is to provide a PCIe cryptographic card scheduling method based on a finite state machine. The working states of the PCIe cryptographic card device are abstracted and the behavior of the device is modeled through a finite state machine. The state sequence of the PCIe device in the working cycle and the event request from the upper computer are described. The final purpose is to realize clear firmware program architecture, simple code, and robust and stable program through the abstract method of the finite state machine. At the same time, the code overhead is saved, and the execution efficiency of the code is improved.

[0005] To solve the technical problem, the technical solution adopted by the application is as follows: a PCIe cryptographic card scheduling method based on a finite state machine, comprising the following steps:

[0006] S01), the PCIe cryptographic card is refined into seven states, namely, a device initialization state, a self-checking state, a CSP input state, an approval state, a cryptographic subjective supervisor state, a locking state and an error state. The finite state machine of the PCIe cryptographic card includes a set of the above seven states. According to the trigger condition, the PCIe cryptographic card is always switched among the above seven states to form a closed loop.

[0007] S02) Setting up the functional modules and engine of the finite state machine: The functional modules include a state change unit module, a state acquisition unit module, and a state change judgment unit module. The state change unit module sets the current state of the state machine to a new state. The state acquisition unit module returns the current state of the state machine to the state machine engine. The state change judgment unit module judges whether the current state of the state machine has changed. When the engine starts, it sets the initial state of the state machine to the device initialization state, and then enters the main loop, continuously calling the state acquisition unit module. According to the state of the PCIe cryptographic card, it calls the corresponding functional module and executes the corresponding action. After each functional module completes its corresponding processing, it calls the state change judgment unit module. If the state has not changed, it continues to execute the functional module. If the state has changed, it exits the unit module and re-enters the state machine engine.

[0008] Furthermore, after the program completes the hardware module initialization, it starts the finite state machine engine, sets the initial state to the device initialization state, and calls the initialization module. As a PCIe cryptographic card device, the initialization of the algorithm module and file storage module is completed. After the initialization module executes successfully, the device self-test conditions are met. The state unit module changes the state to the self-test state. At this time, the state machine engine detects the state change by obtaining the state unit module and calls the device self-test module to perform a self-test. After the PCIe device completes initialization and self-test, if the CSP input state has been completed, it enters the approval state, which is the normal working state. When the user role is an administrator, after logging in, the state will switch to the password supervisor state. At this time, the encryption card has the highest privileges. When the administrator password exceeds the maximum number of times, it will enter the locked state.

[0009] Furthermore, the CSP input state refers to the unauthorized state, during which only the password card initialization and authorization authentication functions can be performed. When a state change is detected, PCIe exits the CSP input state and enters the approved state.

[0010] Furthermore, the approval state is the state that PCIe cryptographic services enter from the CSP input state after successful authorization. This state is the normal state of PCIe cryptographic services. When a state change is detected, PCIe exits the approval state and enters other states.

[0011] Furthermore, the password supervisor status is the super administrator status after the administrator role authorization authentication is passed. It operates the PCIe password card as an administrator. After deregistering the permissions, it enters the approval status. When a status change is detected, the PCIe changes out of the password supervisor status and enters the approval status.

[0012] Further, the error state is that when the PCIe cryptographic card sends an error, the error state is entered, after the error state occurs, the cryptographic card can still work until the error state is changed; when the state change is detected, the PCIe changes the error state.

[0013] Further, the lock state is that when the administrator login error times exceed the maximum number, the lock state is entered, after the lock, the cryptographic card no longer responds to the CMDQ instruction.

[0014] The beneficial effects of the present application: the present application abstracts several states of the PCIe cryptographic card device during work, and models the behavior of the device through a finite state machine, describes all state sequences of the PCIe device in the work cycle and event requests from the upper computer, and the final purpose is to realize clear firmware program architecture, concise code, and robust and stable program through the abstract method of the finite state machine. At the same time, code overhead is saved, and the execution efficiency of the code is improved.

[0015] The method of introducing the finite state machine can make the program code easy to understand, the code architecture level clear, facilitate development and maintenance, reduce the difficulty of later maintenance, and improve the development efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0016] Figure 1 The flowchart for state machine initialization and device self-checking;

[0017] Figure 2 The CSP input state diagram;

[0018] Figure 3 The approved state diagram;

[0019] Figure 4 The cryptographic supervisor state diagram;

[0020] Figure 5 The error state diagram. DETAILED DESCRIPTION

[0021] The present application will be further described below in combination with the drawings and specific embodiments.

[0022] Embodiment 1

[0023] The professional terms and abbreviations involved in this embodiment are as follows:

[0024] FSM: Finite State Machine.

[0025] CSP: Cryptographic Service Provider.

[0026] Abstracting device states based on finite state machine (FSM):

[0027] As the disclosed technical knowledge, the finite state machine can generally be summarized as four elements, namely, present state, condition, action, and next state. The "present state" and "condition" are causes, and the "action" and "next state" are effects. Present state: refers to the current state; Condition: also known as "event", when a condition is met, an action will be triggered, or a state transition will be performed; Action: the action performed after the condition is met. After the action is performed, it can be migrated to a new state, or it can still remain in the original state. Action is not necessary, when the condition is met, no action can be performed, and it can be directly migrated to a new state; Next state: the new state to be migrated after the condition is met. "Next state" is relative to "present state", and "next state" is activated and becomes a new "present state".

[0028] In this embodiment, the PCIe cryptographic card is refined into 7 states, which are: device initialization state (FSM_DEVICE_INIT), self-test state (FSM_SELF_TEST), CSP input state (FSM_CSP), approval state (FSM_CHECK), cryptographic supervisor state (FSM_ADMIN), lock state (FSM_LOCK), and error state (FSM_ERROR). The design of the finite state machine in this scheme is a collection of the above 7 states, and the device is always switched among the above 7 states according to the trigger condition to form a closed loop. The above trigger condition is the condition for the existing PCIe cryptographic card state transition, and this embodiment will not be described in detail.

[0029] The main unit modules of the finite state machine include a state change unit module (fsm_change_state), a state acquisition unit module (fsm_get_state), and a state change judgment unit module (polling_fsm_state_change). The main function of the state change unit module is to set the current state of the state machine to a new state; the state acquisition unit module returns the current state of the state machine to the state machine engine; and the state change judgment unit module judges whether the current state machine state has changed.

[0030] The embodiment also implements a simple finite state machine engine. When the engine starts, the initial state of the state machine is set as "device initialization state (FSM_DEVICE_INIT)", and then the main loop is entered, "state acquisition unit module (fsm_get_state)" is called constantly, corresponding function modules are called according to the state of the device, and corresponding actions are executed. The state machine engine is equivalent to a device state distribution processor, which sends state changes to each function module and executes corresponding function modules. After each function module executes corresponding processing, a state change judgment unit module is called. If the state does not change, the function module is continued to execute. If the state changes, the unit module is exited, and the state machine engine module is reentered.

[0031] As shown in Figure 1 When the program completes hardware module initialization, the finite state machine engine is started. The initial state is set as the device initialization state (FSM_DEVICE_INIT), the finite state machine engine calls the initialization module, and as a PCIe cryptographic card device, the initialization module mainly completes initialization of algorithm modules and file storage and other necessary modules. After the initialization module is executed successfully, the device self-test condition is met at this time, and the state change unit module sets the state as the device self-test state (FSM_SELF_TEST). At this time, the state machine engine discovers that the state has changed through the state acquisition unit module, and the device self-test module is called for self-test.

[0032] After the PCIe device completes initialization and self-test, if the CSP input state has been completed, that is, the approval state (FSM_CHECK) is entered, and the approval state is the normal working state. When the user role is an administrator, after login, the state is switched to the password supervisor state (FSM_ADMIN), and at this time, the cryptographic card has the highest permission. When the administrator password exceeds the maximum number of times, the lock state (FSM_LOCK) is entered.

[0033] In the embodiment, the main states and the switching between the states include:

[0034] The CSP input state refers to a state in which no authorization is acquired, and at this time, only the initialization and authorization authentication functions of the cryptographic card can be performed; as shown in Figure 2 When the state change is detected, the PCIe changes from the CSP input state to the approval state;

[0035] The approval state is entered from the CSP input state when the authorization is successful, and the state is the normal state of the PCIe cryptographic service; as shown in Figure 3 When the state change is detected, the PCIe changes from the approval state to other states;

[0036] Password supervisor state, super administrator state after administrator role authorization authentication is passed, operating the PCIe password card as an administrator, entering the approved state after logging out the authority; as shown in Figure 4 When the state change is detected, the PCIe changes out of the password supervisor state and enters the approved state;

[0037] Error state, entering the error state when an error occurs in the PCIe password card, the password card can still work after the error state occurs until the error state changes out; as shown in Figure 5 When the state change is detected, the PCIe changes out of the error state;

[0038] Locked state, entering the locked state when the number of administrator login errors exceeds the maximum number, the password card no longer responds to the CMDQ instruction after being locked.

[0039] Although the entire firmware processing flow can also be realized through various switch / case and if / else statements, when the device state frequently changes, the program jumps around, the code logic is more complex, and the code is certainly redundant and difficult to understand. The method of introducing the finite state machine can make the program code easy to understand, the code architecture level is clear, and the development and maintenance are convenient, the difficulty of later maintenance is reduced, and the development efficiency is improved.

[0040] The above only describes the basic principles and preferred embodiments of the present application, and the improvements and replacements made by those skilled in the art based on the present application belong to the protection scope of the present application.

Claims

1. A PCIe cryptographic card scheduling method based on finite state machines, characterized in that: Includes the following steps: S01) The PCIe cryptographic card is further divided into 7 states: device initialization state, self-test state, CSP input state, approval state, cryptographic supervisor state, locked state, and error state. The CSP input state refers to the state where authorization has not been obtained. At this time, only the cryptographic card initialization and authorization authentication functions can be performed. When a state change is detected, the PCIe changes out of the CSP input state and enters the approval state. The approval state is the normal state of the PCIe cryptographic service after successful authorization. When a state change is detected, the PCIe changes out of the approval state and enters other states. The finite state machine of a PCIe cryptographic card includes a set of the above 7 states. Depending on the triggering condition, the PCIe cryptographic card always switches between the above 7 states, forming a closed loop. S02) Setting up the functional modules and engine of the finite state machine: The functional modules include a state change unit module, a state acquisition unit module, and a state change judgment unit module. The state change unit module sets the current state of the state machine to a new state. The state acquisition unit module returns the current state of the state machine to the state machine engine. The state change judgment unit module judges whether the current state of the state machine has changed. When the engine starts, it sets the initial state of the state machine to the device initialization state, and then enters the main loop, continuously calling the state acquisition unit module. According to the state of the PCIe cryptographic card, it calls the corresponding functional module and executes the corresponding action. After each functional module completes its corresponding processing, it calls the state change judgment unit module. If the state has not changed, it continues to execute the functional module. If the state has changed, it exits the unit module and re-enters the state machine engine.

2. The PCIe cryptographic card scheduling method based on a finite state machine according to claim 1, characterized in that: After the program completes the hardware module initialization, it starts the finite state machine engine, sets the initial state to the device initialization state, and calls the initialization module. As a PCIe cryptographic card device, the initialization of the algorithm module and file storage module is completed. After the initialization module executes successfully, the device self-test conditions are met. The state unit module changes the state to the self-test state. At this time, the state machine engine detects the state change by obtaining the state unit module and calls the device self-test module to perform a self-test. After the PCIe device completes initialization and self-test, if the CSP input state has been completed, it enters the approval state, which is the normal working state. When the user role is an administrator, after logging in, the state will switch to the password supervisor state. At this time, the encryption card has the highest privileges. When the administrator password exceeds the maximum number of times, it will enter the locked state.

3. The PCIe cryptographic card scheduling method based on a finite state machine according to claim 1, characterized in that: The Password Supervisor status is the super administrator status after the administrator role has been authorized and authenticated. It allows the administrator to operate the PCIe password card. After deregistering the administrator privileges, the PCIe enters the Approval status. When a status change is detected, the PCIe exits the Password Supervisor status and enters the Approval status.

4. The PCIe cryptographic card scheduling method based on a finite state machine according to claim 1, characterized in that: An error state occurs when a PCIe cryptographic card encounters an error and enters an error state. After the error state occurs, the cryptographic card can still function until the error state is cleared. Once a state change is detected, the PCIe card clears the error state.

5. The PCIe cryptographic card scheduling method based on a finite state machine according to claim 1, characterized in that: The locked state is entered when the administrator's number of incorrect login attempts exceeds the maximum. Once locked, the password card will no longer respond to CMDQ commands.

Citation Information

Patent Citations

  • Business flow execution method and device

    CN105844422A

  • High-performance password card and working method thereof

    CN110765438A