A method and system for security evaluation of a cryptographic algorithm library

CN123013108APending Publication Date: 2026-10-30ZHIXUN CIPHER (SHANGHAI) TESTING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611091018.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-22
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]鉴于上述问题,本申请实施例提供了一种密码算法库安全性评估方法和系统,克服了上述或者至少部分地解决了上述生成的测试用例缺乏针对性的问题

Benefits of technology

[0025]上述说明仅是本申请实施例技术方案的概述,为了能够更清楚了解本申请实施例的技术手段,而可依照说明书的内容予以实施,并且为了让本申请实施例的上述和其它目的、特征和优点能够更明显易懂,以下特举本申请的具体实施方式。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123013108A_ABST
    Figure CN123013108A_ABST
Patent Text Reader

Abstract

The application provides a cryptographic algorithm library security evaluation method and system, the method comprises the following steps: obtaining the interface specification and common input sample of the target cryptographic algorithm library, building a fuzz testing execution environment, recording the normal output characteristics of the algorithm library, and taking the normal output characteristics as the comparison benchmark for anomaly detection in subsequent tests. Construct a state space for reinforcement learning; construct a reward function and define the calculation rules of the reward value. According to the probability distribution of the current state output mutation operation, the agent selects the mutation operation according to the probability distribution to generate a new test case. Input the generated new test case into the cryptographic algorithm library, record the execution path, return result and exception information. According to the execution path, return result and exception information of this test, substitute into the reward function for calculation to obtain the reward value of this test. Update the parameters of the policy network according to the reward value using the reinforcement learning algorithm. According to the recorded execution path and exception information, determine whether the termination condition is reached.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of security testing technology, specifically to a method and system for security evaluation of cryptographic algorithm libraries. Background Technology

[0002] Cryptographic algorithm libraries are core security components of information systems in fields such as financial transactions, information communication, and network security. Their security is directly related to the confidentiality, integrity, and availability of data. Once a security vulnerability exists, it may lead to serious consequences such as the leakage of user privacy and financial losses. Therefore, it is crucial to conduct a comprehensive and efficient security assessment of cryptographic algorithm libraries.

[0003] Currently, traditional random fuzzing is one of the most widely used techniques in the security assessment of cryptographic algorithm libraries. It triggers anomalous behavior by randomly generating or mutating input data into the target program, thereby discovering potential vulnerabilities. However, the test cases generated by this method lack specificity, and a large number of test inputs fall into invalid or redundant execution paths, resulting in low testing efficiency and insufficient vulnerability discovery capabilities. Summary of the Invention

[0004] In view of the above problems, embodiments of this application provide a method and system for security evaluation of cryptographic algorithm libraries, which overcomes or at least partially solves the problem of the lack of specificity in the generated test cases.

[0005] The first aspect of this application provides a method for security evaluation of a cryptographic algorithm library. The method includes: acquiring the interface specifications and common input samples of the target cryptographic algorithm library; building a fuzzing execution environment; recording the normal output features of the algorithm library; and using the normal output features as a benchmark for anomaly detection in subsequent tests. The current input mutation state of the fuzzing test, the execution path coverage of the algorithm library, and the error triggering state are combined to construct a reinforcement learning state space; and a reward function is constructed using path coverage increment, error type weight, and test efficiency as parameters, defining the rules for calculating the reward value.

[0006] The agent acquires the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state, and the agent samples and selects mutation operations according to the probability distribution to generate new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return result and exception information are recorded.

[0007] Based on the execution path, return results, and exception information of this test, the reward function is substituted to calculate the reward value for this test. The reward value is higher when a new path or serious error is triggered, and lower when a duplicate path or meaningless error is triggered. The parameters of the policy network are updated using a reinforcement learning algorithm based on the reward value. In the probability distribution output by the updated policy network, the probability of mutation operations that obtain high rewards is increased, while the probability of mutation operations that obtain low rewards is decreased.

[0008] Based on the recorded execution paths and exception information, determine whether the termination conditions have been met. The termination conditions are: the path coverage rate reaches the preset target coverage threshold, or the cumulative error count reaches the preset maximum error count threshold. If not, the current test status is fed back to the agent, which then performs the following operations again: generating new test cases and inputting them into the cryptographic algorithm library, recording the execution paths and exception information, calculating the reward value based on the test results, and updating the policy network. If the conditions are met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.

[0009] In this embodiment, a state space is constructed by combining the input mutation state, execution path coverage, and error trigger state, making the testing process quantifiable and perceptible. A reward function is built using path coverage increment, error type weight, and testing efficiency as parameters, providing a clear standard for evaluating the quality of mutation operations and guiding the agent to distinguish between high-value and low-value mutation operations. The agent acquires the current state, and the policy network outputs the probability distribution of mutation operations based on the current state. The agent samples and selects mutation operations according to the probability distribution, ensuring that the selection of mutation operations is no longer random and blind, but rather a directional decision based on the current test state.

[0010] The reward value is calculated based on the actual execution results of this test, and the policy network parameters are updated. This increases the probability of high-reward mutation operations being sampled in subsequent iterations, while decreasing the probability of low-reward mutation operations. Through a positive feedback mechanism, the agent gradually accumulates testing experience. The process involves checking if the termination condition has been met; if not, the current state is fed back, and the next loop begins. This continuous iteration of testing, feedback, learning, and optimization allows the agent to continuously optimize its mutation operation selection preferences. Test cases gradually focus on high-value areas, and a security assessment report is generated based on error records and path coverage. The agent's continuous optimization of mutation operation selection preferences in the iterative loop causes test case generation to gradually converge from blind randomness to high-value areas, thus solving the technical problem of traditional random fuzz testing lacking specificity and improving testing efficiency.

[0011] In one alternative approach, setting up a fuzzing execution environment includes: installing and configuring a fuzzing framework, compiling the target algorithm library and linking it to the test driver, setting environment variables to isolate the test process, configuring the parameters of the fuzzing tool, configuring logging functionality, and verifying tool integration.

[0012] In one alternative approach, each state in the state space is represented by a state vector. The expression represents the sequence of mutation operations for the current test case, where mt is the input mutation state, pt is the execution path coverage, et is the error trigger state, and t represents the time step. The input mutation state is represented by an integer vector encoding the sequence of mutation operations for the current test case. The execution path coverage is obtained by instrumenting tools to obtain the percentage of covered paths. The error trigger state is a binary flag, which is set to 1 when a crash or exception is detected, and set to 0 otherwise.

[0013] In one alternative approach, the path coverage increment Δpt is calculated as the coverage difference between the current step and the previous step, i.e. Error type weights w are assigned based on error severity, and the sum of the weights is normalized to [0,1]. Test efficiency ηt is defined as: in This represents the number of new paths triggered in this step. The execution time is denoted by rt; the reward function rt is in the form of a weighted sum: rt = αΔpt + βwet + γηt, where α, β, and γ are adjustable hyperparameters, w is the error type weight, and et is the error trigger state.

[0014] In one alternative approach, mutation operations include input data perturbation, boundary value expansion, random injection, bit flipping, or length expansion mutation.

[0015] In one alternative approach, the exception information includes a stack overflow or a timing side channel flag.

[0016] In one alternative approach, a high reward is given when a new path is triggered or a serious error occurs. Low rewards are given for repeated paths or meaningless errors. The policy network has network parameters. , The policy network outputs the probability of action at in state st, where action at is the mutation operation selected at the current time step, and J(θ) is the objective function for the expected cumulative reward. Updating the parameters of the policy network includes collecting experience trajectories using a policy gradient reinforcement learning algorithm.

[0017] in This represents the state at the initial time step. The action selected for the initial time step. T is the reward value at the initial time step, and T is the ending time step. Calculate cumulative discount rewards: Where γ is the discount factor and k is the summation variable. For the reward value at time step k, estimate the policy gradient:

[0018] Eτ is the expectation of the empirical trajectory τ; Update network parameters using gradient ascent strategy: Where α is the learning rate.

[0019] In one alternative approach, the target coverage threshold is: The maximum error count threshold is Path coverage:

[0020] Where P is the set of all possible paths, This represents the number of paths that have been covered. This represents the total number of paths; if the termination condition is not met, the current test status is collected and fed back to the agent. The current test status includes path coverage, the error log list Ellist, and the set of uncovered paths U.

[0021] Constructing state vectors Feedback to the agent:

[0022] Where t is the current iteration number. Total number of errors This represents the number of uncovered paths; if the termination condition is met, a security assessment report is generated, including an error summary and path coverage analysis, and a risk index is calculated for each module m. ,in The number of errors in module m. Set risk thresholds for module size. ,like It is then marked as a high-risk module, and all uncovered paths U are listed.

[0023] Another aspect of this application provides a security evaluation system for a cryptographic algorithm library based on reinforcement learning-guided fuzzing, comprising: a test environment setup module, used to acquire the interface specifications and commonly used input samples of the target cryptographic algorithm library, set up a fuzzing execution environment, record the normal output features of the algorithm library, and use the normal output features as a comparison benchmark for anomaly detection in subsequent tests; and a state space and reward function construction module, used to combine the current input mutation state of the fuzzing test, the execution path coverage of the algorithm library, and the error triggering state to construct a reinforcement learning state space; and to construct a reward function using path coverage increment, error type weight, and test efficiency as parameters, defining the calculation rules for the reward value.

[0024] The test case generation and execution module is used to enable the agent to obtain the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state, and the agent samples and selects mutation operations according to the probability distribution to generate new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return results and exception information are recorded. The policy update module is used to calculate the reward value for this test by substituting the execution path, return result, and exception information of this test into the reward function. The reward value is high when a new path is triggered or a serious error is found, and low when a duplicate path or meaningless error is found. The parameters of the policy network are updated using a reinforcement learning algorithm based on the reward value. In the probability distribution output by the updated policy network, the probability of mutation operations that obtain high rewards is increased, and the probability of mutation operations that obtain low rewards is decreased. The termination judgment and report generation module is used to determine whether the termination conditions have been met based on the recorded execution paths and exception information. The termination conditions are: the path coverage rate reaches the preset target coverage threshold, or the cumulative error count reaches the preset maximum error count threshold. If the conditions are not met, the current test status is fed back to the agent, which then performs the following operations again: generating new test cases and inputting them into the cryptographic algorithm library, recording the execution paths and exception information, calculating the reward value based on the test results, and updating the policy network. If the conditions are met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.

[0025] The above description is merely an overview of the technical solutions of the embodiments of this application. In order to better understand the technical means of the embodiments of this application and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of this application more obvious and understandable, specific implementation methods of this application are described below. Attached Figure Description

[0026] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a flowchart illustrating a method for assessing the security of a cryptographic algorithm library, as described in an embodiment of this application.

[0028] Figure 2 This is a schematic diagram of the structure of a security evaluation system for a cryptographic algorithm library based on reinforcement learning-guided fuzz testing, provided as another embodiment of this application. Detailed Implementation

[0029] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.

[0031] The terms "comprising" and "having," and any variations thereof, used in the specification, claims, and drawings of this application are intended to cover without excluding other meanings. The words "a" or "an" do not exclude the presence of multiples.

[0032] The term "embodiment" as used herein means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of the phrase "embodiment" in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0033] Furthermore, the terms "first," "second," etc., in the specification and claims of this application or in the aforementioned drawings are used to distinguish different objects rather than to describe a specific order, and may explicitly or implicitly include one or more of the features.

[0034] In the description of this application, unless otherwise stated, "multiple" means two or more (including two), and similarly, "multiple groups" means two or more (including two groups).

[0035] This application provides a method for security assessment of a cryptographic algorithm library. Please refer to [link / reference]. Figure 1 , Figure 1 This is a flowchart illustrating a method for assessing the security of a cryptographic algorithm library, as described in an embodiment of this application.

[0036] like Figure 1 As shown, the cryptographic algorithm library security assessment method provided in this application includes the following steps 101 to 105: Step 101: Obtain the interface specifications and common input samples of the target cryptographic algorithm library, set up a fuzzing test execution environment, record the normal output features of the algorithm library, and use the normal output features as a comparison benchmark for anomaly detection in subsequent tests.

[0037] The interface specifications of the target cryptographic algorithm library can be obtained by consulting the official documentation, source code comments, or application programming interface reference manual of the target cryptographic algorithm library to extract information such as function signatures, input parameter types, output formats, and error handling mechanisms; or by using tools to automatically generate interface specification documents; common input samples can be obtained from standard test suites or historical logs, or generated by scripts.

[0038] For example, for an AES encryption library, the interface might be defined as `encrypt(key, plaintext)`, where `key` is a 128-bit key and `plaintext` is a plaintext block. Tools such as Doxygen or SWIG should be used to automatically generate interface specification documentation, ensuring coverage of all exported functions and data structures. Simultaneously, common input samples should be collected, obtaining valid input data from standard test suites (such as NIST cryptographic algorithm test vectors) or historical logs; for hash functions, samples should include short messages, long messages, and boundary value inputs, such as empty strings or maximum-length data. Sample generation can be implemented via scripts, for example, using Python's `secrets` module to generate random but valid keys and plaintext, ensuring input diversity covers typical use cases.

[0039] Record the normal output characteristics of the algorithm library, including: performing benchmark tests before fuzzing, running the algorithm using collected common input samples, capturing and analyzing output behavior, which may include return values, output data streams, and side effects (such as file writing or log entries); recording output characteristics by calculating hash values, checksums, or monitoring system calls, and storing the output characteristics in a database or file for subsequent testing.

[0040] For encryption algorithms, the normal output should satisfy the ciphertext. Given the format and randomness requirements, the encryption process is defined as follows: ,in It is an encryption function. It is a fixed key. The input is plaintext. Output characteristics include calculating hash values, checksums, or monitoring system calls using tools like `strace`; for example, for hash functions, normal output... It should be collision-resistant, meaning different inputs should produce different hashes. In fuzz testing, mutated inputs... ,in This indicates a bitwise XOR operation. It is a random perturbation vector (e.g., generated through the mutation strategy of AFL), output Needs to be consistent with normal output Comparison. If Invalid or causing abnormal behavior (such as crashes or incorrect return codes) are marked as potential vulnerabilities; the verification process can be formalized as follows:

[0041] Here, `1` indicates normal and `0` indicates abnormal. Output features are stored in a database or file for subsequent differential testing. The entire process emphasizes repeatability and documentation completeness, ensuring all operations are logged.

[0042] Step 102: Combine the current input mutation state of the fuzz test, the execution path coverage of the algorithm library, and the error trigger state to construct the state space for reinforcement learning; and construct a reward function with path coverage increment, error type weight, and test efficiency as parameters, and define the calculation rules for the reward value.

[0043] Step 103: The agent obtains the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state, and the agent samples and selects mutation operations according to the probability distribution to generate new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return result and exception information are recorded.

[0044] Step 104: Based on the execution path, return result, and exception information of this test, substitute them into the reward function to calculate the reward value for this test; the reward value is higher when a new path or serious error is triggered, and lower when a duplicate path or meaningless error is triggered; the reinforcement learning algorithm updates the parameters of the policy network according to the reward value. In the probability distribution output by the updated policy network, the probability of mutation operations that obtain high rewards being sampled increases, and the probability of mutation operations that obtain low rewards being sampled decreases.

[0045] Step 105: Based on the recorded execution path and exception information, determine whether the termination condition has been met. If not, the current test status is fed back to the agent, which then performs the following operations again: generating new test cases and inputting them into the cryptographic algorithm library, recording the execution path and exception information, calculating the reward value based on the test results, and updating the policy network. If the condition is met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.

[0046] The termination conditions are: the path coverage reaches the preset target coverage threshold, or the cumulative error count reaches the preset maximum error count threshold.

[0047] In this embodiment, a state space is constructed by combining the input mutation state, execution path coverage, and error trigger state, making the testing process quantifiable and perceptible. A reward function is built using path coverage increment, error type weight, and testing efficiency as parameters, providing a clear standard for evaluating the quality of mutation operations and guiding the agent to distinguish between high-value and low-value mutation operations. The agent acquires the current state, and the policy network outputs the probability distribution of mutation operations based on the current state. The agent samples and selects mutation operations according to the probability distribution, ensuring that the selection of mutation operations is no longer random and blind, but rather a directional decision based on the current test state.

[0048] The reward value is calculated based on the actual execution results of this test, and the policy network parameters are updated. This increases the probability of high-reward mutation operations being sampled in subsequent iterations, while decreasing the probability of low-reward mutation operations. Through a positive feedback mechanism, the agent gradually accumulates testing experience. The process involves checking if the termination condition has been met; if not, the current state is fed back, and the next loop begins. This continuous iteration of testing, feedback, learning, and optimization allows the agent to continuously optimize its mutation operation selection preferences. Test cases gradually focus on high-value areas, and a security assessment report is generated based on error records and path coverage. The agent's continuous optimization of mutation operation selection preferences in the iterative loop causes test case generation to gradually converge from blind randomness to high-value areas, thus solving the technical problem of traditional random fuzz testing lacking specificity and improving testing efficiency.

[0049] In some embodiments, setting up a fuzzing execution environment includes: installing and configuring a fuzzing framework, compiling a target algorithm library and linking it to a test driver, setting environment variables to isolate the test process, configuring parameters of the fuzzing tool, configuring logging functionality, and verifying tool integration.

[0050] The fuzzing framework can be American Fuzzy Lop (AFL) or libFuzzer. When compiling the target cryptographic algorithm library, an instrumentation compiler provided by the fuzzing framework (such as afl-gcc or afl-clang) is used instead of the native compiler to insert coverage tracking probes into the target code of the algorithm library during compilation. A test driver is written to link the target cryptographic algorithm library to the test driver, which receives test cases generated by the fuzzing framework and converts them into valid calls to the cryptographic algorithm library interface. The environment variable LD_PRELOAD is set to inject the isolation library, isolating the test process from the host system. Timeout and memory limit parameters for the fuzzing tool are configured, along with logging functionality. The fuzzing framework is run using initial test cases to verify tool integration and the correctness of instrumentation compilation.

[0051] Compile the target algorithm library as a shared object or static library and link it to the test driver; the driver needs to call interface functions and pass input parameters. Set environment variables to isolate the test process, for example, by using `LD_PRELOAD` to inject libraries or containerization technologies such as Docker. Configure the parameters of the fuzzing tool, such as input mutation strategy, timeout settings, and coverage tracking; ensure the environment has logging capabilities to capture runtime standard output, error streams, and memory states. The test environment should verify tool integration by running simple test cases to confirm that the framework works correctly, such as inputting a sample `P` (plaintext) and calling an encryption function to obtain the initial output.

[0052] In some embodiments, each state in the state space is represented by a state vector st=(mt,pt,et), where mt is the input mutation state, pt is the execution path coverage, et is the error trigger state, and t represents the time step; the input mutation state is represented by an integer vector encoding the sequence of mutation operations for the current test case; the execution path coverage is obtained by instrumenting tools to obtain the percentage of covered paths; the error trigger state is a binary flag, set to 1 when a crash or anomaly is detected, and set to 0 otherwise.

[0053] In some embodiments, the return result of the test in step 103 can be compared with the normal output characteristics recorded in step 101 to determine whether the current test case triggers an exception. The specific comparison rules can be as follows: Return value comparison: Check if the return code is within the baseline allowable range (e.g., 0 indicates success, non-zero indicates error). If an unexpected error code or program crash is returned (e.g., SIGSEGV), it is determined to be an exception.

[0054] Output format comparison: For output data such as ciphertext, signature, and hash value, check whether their length and format are consistent with the benchmark (e.g., the length of AES ciphertext should be an integer multiple of the block length, and the digital signature should be a fixed length). If the format deviates, it is judged as abnormal.

[0055] Behavior monitoring: Detect stack overflows, memory leaks, timeouts, or timing-side channel leaks (such as abnormal fluctuations in execution time) by instrumenting or monitoring system calls. If the behavior exceeds the baseline tolerance range, it is judged as abnormal.

[0056] When an anomaly is detected, the error trigger state et is set to 1, and an error type weight w is assigned according to the severity of the error. The weight value ranges from [0,1], with a weight of 1.0 for severe errors such as crashes, 0.5 for general errors such as format deviations, and 0.2 for minor warnings. If the output is consistent with the baseline and there is no abnormal behavior, et and w are set to 0. The anomaly detection result will be used for the reward function calculation in step 104 to distinguish between high-value and low-value mutation operations.

[0057] In some embodiments, the path coverage increment Δpt is calculated as the coverage difference between the current step and the previous step, i.e. Error type weights w are assigned based on error severity, and the sum of the weights is normalized to [0,1]. Test efficiency ηt is defined as:

[0058] in This represents the number of new paths triggered in this step. For execution time; the reward function rt is in weighted sum form: , where α, β, γ are adjustable hyperparameters, w is the error type weight, and et is the error trigger state, where α can be 0.5, β can be 0.3, and γ can be 0.2.

[0059] This embodiment provides a quantitative evaluation standard for the quality of mutation operations by setting three indicators in the reward function: path coverage increment Δpt, error type weight w, and test efficiency ηt. Through this reward function, the optimization goal of the agent is precisely aligned with the actual needs of security assessment of the cryptographic algorithm library, so that the generation of test cases gradually converges to the high-value area, thereby achieving efficient vulnerability detection and comprehensive security assessment.

[0060] In some embodiments, mutation operations include input data perturbation, boundary value expansion, random injection, bit flipping, or length expansion mutation.

[0061] Specifically, input data perturbation is achieved by superimposing a mutation vector δ onto the input vector x (dimension d), i.e., xnew = x + δ, where the element Δi of δ is obtained by sampling from a uniform distribution U(−b, b), and b is the mutation range parameter (default is 0.1 times the input scale); boundary value expansion is achieved by adjusting the value of b or directly injecting boundary values ​​(0, -1, maximum value, etc.) into key fields (such as key length, block length); random injection is achieved by replacing bytes or words at random positions in the input with random values ​​or special values ​​(such as 0x00, 0xFF, 0x7F, etc.); bit flipping is achieved by performing an inversion operation on bits at random positions in the input; and length expansion mutation is achieved by modifying the length field of the input data or by copying, inserting, or deleting data blocks.

[0062] Furthermore, mutation operations may include arithmetic additions and subtractions (e.g., ±1, ±10, ±100) of bytes, 16-bit words, or 32-bit double words at random positions in the input; concatenating portions of two or more test cases to generate new test cases (concatenation mutation); disrupting ASN.1 encoding or TLV structures; and performing anomalous padding for padding formats such as PKCS#7. All of these mutation operations are performed within the constraints of the cryptographic algorithm interface specifications, ensuring that the mutated test cases conform to the algorithm specifications in format (e.g., AES key length constraints). However, they intentionally construct anomalous elements in input content that conforms to the format specifications to probe the security of the algorithm library when receiving data with a valid format but anomalous content.

[0063] After selecting the mutation operation, a new test case is generated. This new test case is then input into the cryptographic algorithm library for execution. The algorithm API (such as the OpenSSL or Libsodium interface) is called, passing the test case as input parameters (such as plaintext or a key). The execution process is monitored using dynamic binary instrumentation (such as the Pin tool), capturing the execution path (recorded as a sequence of basic block IDs) and extracting the return results (such as encrypted output or status codes). An anomaly detection module scans in real time, records anomaly information, and uses signal processing to capture events such as SIGSEGV.

[0064] Record all data into a structured database, including execution path, return results, and exception information, and associate them with the status. and actions Data storage uses timestamp indexes to support subsequent analysis (such as root cause diagnosis of vulnerabilities).

[0065] In some embodiments, the exception information includes a stack overflow or a timing side channel flag.

[0066] In some embodiments, a high reward is given when a new path or a serious error is triggered. Low rewards are given for repeated paths or meaningless errors. The policy network has network parameters. , The policy network outputs the probability of action at in state st, where action at is the mutation operation selected at the current time step, and J(θ) is the objective function for the expected cumulative reward. Updating the parameters of the policy network includes collecting experience trajectories using a policy gradient reinforcement learning algorithm.

[0067] in This represents the state at the initial time step. The action selected for the initial time step. T is the reward value at the initial time step, and T is the ending time step. Calculate cumulative discount rewards: Where γ is the discount factor and k is the summation variable. For the reward value at time step k, estimate the policy gradient:

[0068] Eτ is the expectation of the empirical trajectory τ; Update network parameters using gradient ascent strategy:

[0069] Where α is the learning rate, and α can be 0.001.

[0070] In some embodiments, the target coverage threshold is , It can be 0.95, and the maximum error count threshold is... , It can be 100; Path coverage:

[0071] Where P is the set of all possible paths, This represents the number of paths that have been covered. This represents the total number of paths; if the termination condition is not met, the current test state is collected and fed back to the agent, where the elements are... yes One of the specific paths.

[0072] The current test status includes path coverage, the error log list Ellist, and the set of uncovered paths U.

[0073] Constructing state vectors Feedback to the agent:

[0074] Where t is the current iteration number. Total number of errors This represents the number of uncovered paths; if the termination condition is met, a security assessment report is generated, including an error summary and path coverage analysis, and a risk index is calculated for each module m. ,in The number of errors in module m. Set risk thresholds for module size. ,like It is then marked as a high-risk module, and all uncovered paths U are listed.

[0075] Another embodiment of this application also provides a security evaluation system 2 for a cryptographic algorithm library based on reinforcement learning-guided fuzz testing. Figure 2 A schematic diagram of a security evaluation system for a cryptographic algorithm library based on reinforcement learning-guided fuzz testing, provided in another embodiment of this application, is shown below. Figure 2 It includes: a test environment setup module 21, which is used to obtain the interface specifications and common input samples of the target cryptographic algorithm library, set up a fuzz test execution environment, record the normal output features of the algorithm library, and use the normal output features as a comparison benchmark for anomaly detection in subsequent tests.

[0076] The state space and reward function construction module 22 is used to combine the current input mutation state of fuzzing, the execution path coverage of the algorithm library, and the error trigger state to construct the state space of reinforcement learning; and to construct the reward function with path coverage increment, error type weight, and test efficiency as parameters, and define the calculation rules of the reward value.

[0077] The test case generation and execution module 23 is used to enable the agent to obtain the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state, and the agent samples and selects mutation operations according to the probability distribution to generate new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return result and exception information are recorded.

[0078] The policy update module 24 is used to calculate the reward value for this test by substituting the execution path, return result, and exception information of this test into the reward function. The reward value is higher when a new path or serious error is triggered, and lower when a duplicate path or meaningless error is triggered. The parameters of the policy network are updated using a reinforcement learning algorithm based on the reward value. In the probability distribution output by the updated policy network, the probability of sampling mutation operations that obtain high rewards is increased, and the probability of sampling mutation operations that obtain low rewards is decreased.

[0079] The termination judgment and report generation module 25 is used to determine whether the termination condition has been met based on the recorded execution path and exception information. The termination condition is: the path coverage rate reaches the preset target coverage threshold, or the cumulative error count reaches the preset maximum error count threshold. If the condition is not met, the current test status is fed back to the agent, which then performs the operations of generating new test cases and inputting them into the cryptographic algorithm library, recording the execution path and exception information, calculating the reward value based on the test results, and updating the policy network. If the condition is met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.

[0080] Another embodiment of this application provides a computer device, including: a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, it implements the embodiments of this application. Figure 1 The method for security assessment of cryptographic algorithm libraries is shown.

[0081] Those skilled in the art will understand that although some embodiments herein include certain features included in other embodiments, combinations of features from different embodiments are intended to be within the scope of this application and form different embodiments. For example, in the claims, any of the claimed embodiments can be used in any combination.

[0082] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for security evaluation of a cryptographic algorithm library, characterized in that, The method includes: Obtain the interface specifications and common input samples of the target cryptographic algorithm library, build a fuzz test execution environment, record the normal output characteristics of the algorithm library, and use the normal output characteristics as a comparison benchmark for anomaly detection in subsequent tests. The current input mutation state of the fuzz test, the execution path coverage of the algorithm library, and the error trigger state are combined to construct the state space of reinforcement learning; and the reward function is constructed with path coverage increment, error type weight, and test efficiency as parameters, and the calculation rules of the reward value are defined. The agent acquires the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state; the agent samples and selects mutation operations according to the probability distribution to generate new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return result, and exception information are recorded. Based on the execution path, return results, and exception information of this test, the reward function is substituted to calculate the reward value for this test. The reward value is higher when a new path or serious error is triggered, and lower when a duplicate path or meaningless error is encountered. The parameters of the policy network are updated using a reinforcement learning algorithm based on the reward value. In the probability distribution output by the updated policy network, the probability of sampling mutation operations that yield high rewards increases, while the probability of sampling mutation operations that yield low rewards decreases. Based on the recorded execution paths and anomaly information, determine whether the termination condition has been met. The termination condition is: the path coverage rate reaches a preset target coverage threshold, or the cumulative error count reaches a preset maximum error count threshold. If not met, the current test status is fed back to the agent, which then performs the following operations again: generating new test cases and inputting them into the cryptographic algorithm library, recording the execution paths and anomaly information, calculating the reward value based on the test results, and updating the policy network. If met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.

2. The method according to claim 1, characterized in that, The process of setting up the fuzzing execution environment includes: installing and configuring the fuzzing framework, compiling the target algorithm library and linking it to the test driver, setting environment variables to isolate the test process, configuring the parameters of the fuzzing tool, configuring the logging function, and verifying the tool integration.

3. The method according to claim 1, characterized in that, Each state in the state space is represented by a state vector st=(mt,pt,et), where mt is the input mutation state, pt is the execution path coverage, et is the error trigger state, and t represents the time step. The input mutation state is represented by an integer vector encoding the mutation operation sequence of the current test case. The execution path coverage is obtained by instrumenting tools to obtain the percentage of covered paths. The error trigger state is a binary flag, which is set to 1 when a crash or anomaly is detected, and set to 0 otherwise.

4. The method according to claim 1, characterized in that, The path coverage increment Δpt is calculated as the coverage difference between the current step and the previous step, i.e. The error type weight w is assigned based on the error severity, and the sum of the weights is normalized to [0,1]; the test efficiency ηt is defined as: in This represents the number of new paths triggered in this step. The execution time is denoted as rt; the reward function rt adopts a weighted sum form: rt = αΔpt + βwet + γηt, where α, β, and γ are adjustable hyperparameters, w is the error type weight, and et is the error triggering state.

5. The method according to claim 1, characterized in that, The mutation operations include input data perturbation, boundary value expansion, random injection, bit flipping, or length expansion mutation.

6. The method according to claim 1, characterized in that, The exception information includes stack overflow or timing side channel flags.

7. The method according to claim 1, characterized in that, High rewards are given when a new path is triggered or a serious error occurs. Low rewards are given for repeated paths or meaningless errors. The policy network has network parameters. , The policy network outputs the probability of action at in state st, where action at is the mutation operation selected at the current time step, and J(θ) is the objective function for the expected cumulative reward. Updating the parameters of the policy network includes collecting experience trajectories using a policy gradient reinforcement learning algorithm. in This represents the state at the initial time step. The action selected for the initial time step. T is the reward value at the initial time step, and T is the ending time step. Calculate cumulative discount rewards: Where γ is the discount factor and k is the summation variable. For the reward value at time step k, estimate the policy gradient: Eτ is the expectation of the empirical trajectory τ; Update network parameters using gradient ascent strategy: Where α is the learning rate.

8. The method according to claim 1, characterized in that, The target coverage threshold is: The maximum error count threshold is Path coverage: Where P is the set of all possible paths, This represents the number of paths that have been covered. This represents the total number of paths; if the termination condition is not met, the current test status is collected and fed back to the agent. The current test status includes path coverage, error log list Elit, and set of uncovered paths U. Constructing state vectors Feedback to the agent: Where t is the current iteration number. Total number of errors This represents the number of uncovered paths; if the termination condition is met, a security assessment report is generated, including an error summary and path coverage analysis, and a risk index is calculated for each module m. ,in The number of errors in module m. Set risk thresholds for module size. ,like Then mark This is a high-risk module, and all uncovered paths U are listed.

9. A security evaluation system for cryptographic algorithm libraries based on reinforcement learning-guided fuzz testing, characterized in that, include: The test environment setup module is used to obtain the interface specifications and common input samples of the target cryptographic algorithm library, set up a fuzz test execution environment, record the normal output characteristics of the algorithm library, and use the normal output characteristics as a comparison benchmark for anomaly detection in subsequent tests. The state space and reward function construction module is used to combine the current input mutation state of fuzzing, the execution path coverage of the algorithm library, and the error trigger state to construct the state space for reinforcement learning. A reward function is constructed using path coverage increment, error type weight, and test efficiency as parameters, and the calculation rules for the reward value are defined. The test case generation and execution module is used to enable the agent to obtain the current state, which is the specific value of the state space at the current moment; the policy network outputs the probability distribution of mutation operations based on the current state, the agent samples and selects mutation operations according to the probability distribution, and generates new test cases; the generated new test cases are input into the cryptographic algorithm library, and the execution path, return result and exception information are recorded. The policy update module is used to calculate the reward value for this test by substituting the execution path, return result, and exception information of this test into the reward function. The reward value is higher when a new path or serious error is triggered, and lower when a duplicate path or meaningless error is triggered. The parameters of the policy network are updated using a reinforcement learning algorithm based on the reward value. In the probability distribution output by the updated policy network, the probability of sampling mutation operations that obtain high rewards is increased, and the probability of sampling mutation operations that obtain low rewards is decreased. The termination judgment and report generation module is used to determine whether the termination condition has been met based on the recorded execution path and exception information. The termination condition is: the path coverage rate reaches a preset target coverage threshold, or the cumulative error count reaches a preset maximum error count threshold. If the condition is not met, the current test status is fed back to the agent, which then performs the following operations again: generating new test cases and inputting them into the cryptographic algorithm library, recording the execution path and exception information, calculating the reward value based on the test results, and updating the policy network. If the condition is met, a security assessment report is generated based on the error records and path coverage, marking high-risk modules and uncovered paths.