Battery authentication method, device, terminal and computer readable storage medium
By generating random numbers in user space and generating and comparing ciphertext in kernel space, the problem of easy key cracking in traditional battery authentication is solved, thus improving the security and efficiency of battery authentication.
Patent Information
- Application Number
- CN202310335668.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2043-03-30
AI Technical Summary
In traditional battery authentication methods, random numbers are generated and fixed during the terminal's startup phase, making the keys easy to crack and leak, resulting in low security.
In user mode, a random number and a first ciphertext are generated. In kernel mode, an instruction message is sent to the fuel gauge to generate a second ciphertext. The terminal obtains and compares the ciphertexts in kernel mode to determine whether the battery supports the fast charging protocol.
By generating different random numbers, the risk of key cracking and leakage is reduced, thus improving the security and efficiency of battery authentication.
Smart Images

Figure CN116366339B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of fast charging, in particular to a battery authentication method and device, a terminal and a computer readable storage medium. BACKGROUND
[0002] With the development of fast charging technology, more and more terminals use fast charging technology for charging. When the terminal is fast charging, the battery of the terminal needs to be authenticated to confirm whether the battery of the terminal supports the fast charging protocol.
[0003] In the prior art, the terminal generates ciphertext based on a generated random number and a pre-stored key using a DES algorithm in the start-up stage, and determines whether the battery is authenticated based on the ciphertext.
[0004] However, the conventional method has the problem of low security. SUMMARY
[0005] The embodiments of the present application provide a battery authentication method, device, terminal and computer readable storage medium, which can improve the security of authenticating whether the battery of the terminal supports the fast charging protocol.
[0006] In a first aspect, the embodiments of the present application provide a battery authentication method, comprising:
[0007] In response to a battery authentication message, generating a random number and first ciphertext in a user state;
[0008] sending an indication message to the battery gauge in a kernel state; the indication message includes the random number, and the indication message is used to instruct the battery gauge to generate second ciphertext based on the random number;
[0009] obtaining the second ciphertext generated by the battery gauge in the kernel state, and determining whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext.
[0010] In a second aspect, the embodiments of the present application provide a battery authentication device, comprising:
[0011] The generating module is configured to generate a random number and first ciphertext in a user state in response to a battery authentication message;
[0012] The first sending module is configured to send an indication message to the battery gauge in a kernel state; the indication message includes the random number, and the indication message is used to instruct the battery gauge to generate second ciphertext based on the random number;
[0013] The authentication module is configured to acquire the second ciphertext generated by the electric quantity meter in a kernel mode, and determine whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext.
[0014] In a third aspect, an embodiment of the present application provides a terminal, comprising a memory and a processor, the memory stores a computer program, and the computer program is executed by the processor to make the processor execute the steps of the battery authentication method in the first aspect.
[0015] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the battery authentication method in the first aspect.
[0016] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, and the computer program is executed by a processor to implement the steps of the battery authentication method in the first aspect.
[0017] The above battery authentication method, device, terminal and computer readable storage medium can generate a random number and a first ciphertext in a user mode in response to a battery authentication message, and send the random number to the electric quantity meter in a kernel mode, so that the electric quantity meter generates a second ciphertext based on the random number. Thus, the terminal can acquire the second ciphertext generated by the electric quantity meter in the kernel mode, and determine whether the battery of the terminal supports the fast charging protocol according to the first ciphertext and the second ciphertext generated by the electric quantity meter. Since the random number generated in the user mode is generated in response to the battery authentication message when the battery authentication message is received, the random number generated each time is different. Therefore, the risk of cracking and leaking the key for generating the ciphertext is greatly reduced, and the security of authenticating whether the battery of the terminal supports the fast charging protocol is improved. BRIEF DESCRIPTION OF DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0019] Figure 1 It is an application environment diagram of the battery authentication method in an embodiment;
[0020] Figure 2 It is a flowchart of the battery authentication method in an embodiment;
[0021] Figure 3 It is a flowchart of the battery authentication method in another embodiment;
[0022] Figure 4 Flow chart of the battery authentication method in another embodiment;
[0023] Figure 5 Flow chart of the battery authentication method in another embodiment;
[0024] Figure 6 Flow chart of the battery authentication method in another embodiment;
[0025] Figure 7 Flow chart of the battery authentication method in another embodiment;
[0026] Figure 8 Structural block diagram of the battery authentication device in one embodiment;
[0027] Figure 9 Structural block diagram of the battery authentication device in another embodiment;
[0028] Figure 10 Structural block diagram of the battery authentication device in another embodiment;
[0029] Figure 11 Structural block diagram of the battery authentication device in another embodiment;
[0030] Figure 12 Structural block diagram of the battery authentication device in another embodiment;
[0031] Figure 13 Structural block diagram of the battery authentication device in another embodiment;
[0032] Figure 14 Structural block diagram of the battery authentication device in another embodiment;
[0033] Figure 15 Internal structural schematic diagram of the terminal in one embodiment. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application is further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.
[0035] It can be understood that the terms "first", "second", and the like used in the present application can be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from another element. For example, without departing from the scope of the present application, the first client can be called the second client, and similarly, the second client can be called the first client. The first client and the second client are both clients, but they are not the same client. In the present application, the difference in name is not the principle of distinguishing elements, but the difference in function of the elements is the principle of distinguishing elements.
[0036] The battery authentication method provided by the embodiments of the present application can be applied to the application environment as shown in Figure 1 The terminal 102 includes a battery, and the power supply device 104 can supply power to the battery of the terminal 102. The terminal 102 and the power supply device 104 both support multiple charging protocols, and the terminal 102 and the power supply device 104 can select a charging protocol supported by both from the multiple charging protocols supported by both to perform fast charging. Optionally, the power supply device 104 can be a charger, a charging head, a power bank, an adapter, a travel charger, etc. The terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things device can be a smart speaker, a smart television, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc., which are not limited herein.
[0037] Generally, when a terminal performs fast charging, it needs to confirm that the battery of the terminal supports the fast charging protocol, that is, the battery of the terminal needs to be authenticated to confirm whether the battery of the terminal supports the fast charging protocol. In the conventional technology, when the battery of the terminal is authenticated, the terminal generates a random number in the startup stage, generates a ciphertext based on the generated random number and a pre-stored key using a Data Encryption Standard (DES) algorithm, and generates a ciphertext based on the generated ciphertext and a power meter to determine whether the battery is authenticated. However, in the conventional technology, the random number is generated in the startup stage of the terminal. For the entire running period of the terminal, the generated random number is fixed and unchangeable, which increases the risk of cracking and leaking the key for generating the ciphertext, and causes the terminal to have a low security problem when authenticating whether the battery supports the fast charging protocol.
[0038] In one embodiment, as shown in Figure 2 A battery authentication method is provided. Taking the terminal in Figure 1 as an example, the method includes the following steps:
[0039] S201, in response to the battery authentication message, generating a random number and a first ciphertext in a user state.
[0040] First of all, it needs to be pointed out that the central processing unit (CPU) of the terminal has two running states, namely user state and kernel state, the user state refers to the user running state of the computing processor, and the kernel state refers to the kernel running state of the computing processor, in specific implementation, the user state is used for running user processes, and the application program in the user state initiates a data transmission request to the storage system, which is received by the kernel state, and the kernel state is used for running management processes, resource scheduling, memory management and other processes of the operating system, in this embodiment, the kernel state typically needs to do is to load various peripheral drivers, which includes the driver of the power meter, and the driver of the power meter will be loaded to perform encryption authentication of the power meter.
[0041] In this embodiment, the battery authentication message can be generated by the terminal when establishing a connection with the power supply device, for example, the battery authentication message can be generated by the terminal when establishing a connection with the charger, or the terminal can also be generated when establishing a connection with the power bank.
[0042] It can be understood that the random number in this embodiment is a random number used to generate a ciphertext, therefore, the random number has randomness, unpredictability and non-repeatability. Optionally, the random number in this embodiment can be generated by the terminal in the user state using a random number generator. As an optional implementation, the first ciphertext in this embodiment can be generated by the terminal in the user state based on the generated random number and the first key stored in advance by the terminal using the data encryption standard (DES) algorithm, or it can also be generated by the terminal in the user state based on the generated random number and the first key stored in advance by the terminal using other encryption algorithms, which is not limited in this embodiment.
[0043] In addition, it can be understood that in this embodiment, for the entire running cycle of the terminal, when the terminal generates the battery authentication message, the terminal will generate a random number in the user state, therefore, different random numbers corresponding to the battery authentication messages can be generated in the user state in the entire running cycle of the terminal, that is, the random number generated by the terminal in the user state is not fixed, but a variable random number, so that the first ciphertext generated in the entire running cycle of the terminal is also variable, thereby reducing the risk of cracking and leaking the key of generating the first ciphertext.
[0044] S202, sending an indication message to the power meter in the kernel state; the indication message includes a random number, and the indication message is used to instruct the power meter to generate a second ciphertext based on the random number.
[0045] In the embodiment, the terminal generates the indication message based on the random number in the kernel mode, and sends the indication message to the battery gauge of the terminal in the kernel mode, so as to instruct the battery gauge to generate the second ciphertext based on the random number. Optionally, in the embodiment, the terminal can send the indication message to the battery gauge through the I2C bus connection between the terminal and the battery gauge in the kernel mode.
[0046] Optionally, in the embodiment, the battery gauge can generate the second ciphertext based on the received random number and the second key pre-stored in the battery gauge by using the DES algorithm, or can be generated based on the received random number and the second key pre-stored in the battery gauge by using other encryption algorithm, which is not limited in the embodiment, but the encryption algorithm used by the battery gauge should be consistent with the encryption algorithm used by the terminal when the first ciphertext is generated.
[0047] S203, obtaining the second ciphertext generated by the battery gauge in the kernel mode, and determining whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext.
[0048] Optionally, in the embodiment, the terminal can send an acquisition instruction to the battery gauge in the kernel mode to acquire the second ciphertext generated by the battery gauge. Further, the terminal can confirm whether the characters of the first ciphertext and the second ciphertext are consistent in the kernel mode, and determine whether the battery supports the fast charging protocol. For example, if the terminal determines that the characters of the first ciphertext and the second ciphertext are completely consistent in the kernel mode, the terminal can determine that the battery supports the fast charging protocol. Alternatively, the terminal can compare the similarity of the first ciphertext and the second ciphertext in the kernel mode, and determine whether the battery supports the fast charging protocol according to the similarity of the first ciphertext and the second ciphertext and a preset similarity threshold. For example, if the terminal determines that the similarity of the first ciphertext and the second ciphertext is greater than the similarity threshold in the kernel mode, the terminal can determine that the battery supports the fast charging protocol.
[0049] In the above battery authentication method, the random number and the first ciphertext can be generated in the user mode in response to the battery authentication message, and the random number can be carried in the indication message and sent to the battery gauge in the kernel mode, so as to instruct the battery gauge to generate the second ciphertext based on the random number. In this way, the terminal can obtain the second ciphertext generated by the battery gauge in the kernel mode, and determine whether the battery of the terminal supports the fast charging protocol according to the first ciphertext and the second ciphertext generated by the battery gauge. Since the random number generated in the user mode is generated in response to the battery authentication message when the battery authentication message is received, the random number generated each time is different, so that the risk of cracking and leaking the key for generating the ciphertext is greatly reduced, thereby improving the security of authenticating whether the battery of the terminal supports the fast charging protocol.
[0050] In the scenario of determining whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext, the terminal can determine whether the battery supports the fast charging protocol by comparing the first ciphertext and the second ciphertext in the kernel mode. In an embodiment, as shown in FIG. 3, the step S203 of determining whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext includes: Figure 3
[0051] S301, obtaining a comparison result of the first ciphertext and the second ciphertext, the comparison result being used to represent whether the first ciphertext is the same as the second ciphertext.
[0052] Optionally, in this embodiment, the terminal can compare each character of the first ciphertext and the second ciphertext one by one in the kernel mode to obtain the comparison result representing whether the first ciphertext is the same as the second ciphertext. As an optional implementation, the terminal can determine that the first ciphertext is the same as the second ciphertext if each character of the first ciphertext and the second ciphertext is the same. If there is a different character in each character of the first ciphertext and the second ciphertext, the terminal can determine that the first ciphertext is different from the second ciphertext. For example, if the first ciphertext and the second ciphertext each include 8 characters, if the 8 characters of the first ciphertext are completely the same as the 8 characters of the second ciphertext, the terminal can determine that the comparison result of the first ciphertext and the second ciphertext is that the first ciphertext is the same as the second ciphertext. If the 8 characters of the first ciphertext are different from the 8 characters of the second ciphertext, the terminal can determine that the comparison result of the first ciphertext and the second ciphertext is that the first ciphertext is different from the second ciphertext.
[0053] S302, determining whether the battery supports the fast charging protocol according to the comparison result.
[0054] Optionally, in this embodiment, if the comparison result of the first ciphertext and the second ciphertext represents that the first ciphertext is the same as the second ciphertext, it indicates that the encryption authentication of the battery is passed, and the battery of the terminal supports the fast charging protocol and can be charged at a high power. In this embodiment, as another optional implementation, if the comparison result of the first ciphertext and the second ciphertext represents that the first ciphertext is different from the second ciphertext, it indicates that the encryption authentication of the battery fails, and the battery of the terminal does not support the fast charging protocol. At this time, the terminal can output prompt information representing that the battery does not support the fast charging protocol to prompt the user that the battery of the terminal does not support the fast charging protocol and cannot be charged at a high power, thereby avoiding the occurrence of danger.
[0055] In this embodiment, the process of obtaining the comparison result of the first ciphertext and the second ciphertext by the terminal is relatively simple and has a small amount of calculation, which can enable the terminal to quickly obtain the comparison result of the first ciphertext and the second ciphertext, so that the terminal can quickly determine whether the battery of the terminal supports the fast charging protocol according to the comparison result of the first ciphertext and the second ciphertext, thereby ensuring the efficiency of determining whether the battery of the terminal supports the fast charging protocol.
[0056] Generally, the terminal needs to generate the random number in the user state after the user state has loaded the HIDL service, and generate the random number in the HIDL service. In one embodiment, as shown in Figure 4 S201 includes the following steps.
[0057] S401, in response to the battery authentication message, determining whether the target service of the user state is loaded.
[0058] In the embodiment, the target service refers to the HIDL service in the user state. Generally, the kernel state is loaded before the user state, and the user state is loaded slower than the kernel state. When the encryption authentication of the battery is performed, the HIDL service in the user state may not be loaded. In this case, the kernel state ignores the battery authentication message. Therefore, in the embodiment, the terminal determines whether the HIDL service in the user state is loaded in response to the battery authentication message. Optionally, in the embodiment, the terminal can determine whether the target service in the user state is loaded according to the prompt information set by the user state. For example, the user state sets the related flag to false after the target service is loaded, for example, false.
[0059] S402, in the case where it is determined that the target service is loaded, generating the random number and the first ciphertext in the user state.
[0060] In the embodiment, in the case where the terminal determines that the HIDL service in the user state is loaded, the terminal generates the random number for the battery authentication in the user state, and generates the first ciphertext based on the random number and the pre-stored key of the terminal by using the encryption algorithm. As an optional real-time manner, the terminal can call the preset program library, for example, SO library, in the user state in the case where it is determined that the HIDL service in the user state is loaded, and generate the random number and the first ciphertext in the user state by using the program library. It can be understood that the preset program library is called in the user state to generate the random number and the first ciphertext, which is also for the security of the key. The code is not submitted in the form of direct text, so that the related submission link or the downloaded text file cannot be directly seen to obtain the key for the power meter encryption, thereby reducing the risk of cracking and leaking the key. In addition, the preset program library is provided to the user state of the terminal in the form of an API function interface, and the content of “generating the random number and generating the ciphertext by using the random number + key + encryption algorithm” is integrated by using the program library, thereby further avoiding the risk of cracking and leaking the key for generating the first ciphertext.
[0061] In this embodiment, the terminal first determines whether the target service in the user state is loaded by responding to the battery authentication message, generates the random number and the first ciphertext in the user state when it is determined that the target service in the user state is loaded, and ensures the reliability of the generated random number and the first ciphertext, thereby avoiding the case that the random number and the first ciphertext cannot be generated in the user state.
[0062] In the scenario that the terminal sends the indication message including the random number to the battery gauge in the kernel state, the terminal can also carry the check value in the indication message to determine whether the random number is correctly carried in the indication message and sent to the battery gauge. In one embodiment, as shown in Figure 5 S202 includes the following steps:
[0063] S501, performing cyclic redundancy checksum (CRC) check on the random number in the kernel state to obtain a first check value.
[0064] The cyclic redundancy checksum (CRC) is a data check method with error detection and correction capabilities, which can perform CRC check on the random number byte by byte to obtain the first check value. That is, in this embodiment, the terminal performs CRC check on each byte of the random number generated in the user state in the kernel state to obtain the first check value after CRC check on the random number.
[0065] S502, sending the random number and the first check value to the battery gauge in the indication message in the kernel state; the indication information is used to instruct the battery gauge to generate the second ciphertext and feed back the response information representing whether the random number is sent correctly; the response information is the second check value generated by the battery gauge after CRC check on the random number, which is generated according to the first check value and the second check value.
[0066] Optionally, in this embodiment, the terminal can add the first check value to the end of the random number in the kernel state, and send the random number and the first check value to the battery gauge in the indication message.
[0067] Further, after receiving the indication information, the coulomb counter generates second ciphertext based on the random number in the indication information and the second key pre-stored by itself, and generates a second check value by performing CRC check on the random number in the indication information, generates response information according to the first check value and the second check value carried in the indication information, and feeds back the response information to the kernel state of the terminal. The response information generated by the coulomb counter is used to indicate whether the random number sent by the terminal in the kernel state is correct. Optionally, in the case where the coulomb counter determines that the first check value and the second check value are the same, the coulomb counter can send first response information to the kernel state of the terminal, which indicates that the random number sent by the terminal in the kernel state is correct. In the case where the coulomb counter determines that the first check value and the second check value are different, the coulomb counter can send second response information to the kernel state of the terminal, which indicates that the random number sent by the terminal in the kernel state is incorrect.
[0068] In the embodiment, the terminal can obtain the first check value by performing CRC check on the random number generated by the user state in the kernel state, so that the random number and the first check value can be carried in the indication message and sent to the coulomb counter in the kernel state, to instruct the coulomb counter to generate the second ciphertext based on the random number in the indication message, generate the second check value by performing CRC check on the random number in the indication message, and feed back the response information to the kernel state of the terminal according to the first check value and the second check value. The response information is used to feed back to the kernel state of the terminal whether the random number is sent correctly, so that whether the random number sent by the terminal in the kernel state is lost can be detected, and the loss of the random number sent by the terminal in the kernel state is avoided.
[0069] In the above scenario where the terminal obtains the second ciphertext generated by the coulomb counter in the kernel state, the terminal can obtain the second ciphertext from the coulomb counter based on the first response information fed back by the coulomb counter in the kernel state. In one embodiment, the “obtaining the second ciphertext generated by the coulomb counter in the kernel state” in S203 includes: if the first response information is received in the kernel state, reading the second ciphertext from the coulomb counter after a preset time period; and the first response information indicates that the random number is sent correctly.
[0070] In the embodiment, if the terminal receives the first response information fed back by the coulomb counter in the kernel state, which indicates that the random number is sent correctly, the terminal can wait for a preset time period, i.e., wait for the limit time for the coulomb counter to process the authentication encryption, for example, 100 ms. It should be noted that the coulomb integration calculation of the coulomb counter is performed periodically, and it does not take 100 ms from receiving the random number from the coulomb counter to completing the coulomb integration calculation. Therefore, in the embodiment, after the terminal receives the first response information fed back by the coulomb counter in the kernel state, the terminal can read the second ciphertext generated by the coulomb counter from the coulomb counter after waiting for 100 ms.
[0071] In the embodiment, after the terminal receives the first response information in the kernel mode, the terminal makes the coulomb counter perform the coulomb integration calculation by waiting for a preset time length, and reads the second ciphertext generated by the coulomb counter after the preset time length, so as to avoid affecting the coulomb integration operation of the coulomb counter due to the authentication of the battery, and give priority to the coulomb integration calculation based on the principle of priority, while considering the encryption authentication function of the battery without affecting the coulomb integration.
[0072] In some scenarios, the response information received by the terminal in the kernel mode can also be response information representing a random number sending error. In this scenario, the terminal needs to perform an operation based on the number of times of receiving the response information representing the random number sending error. In one embodiment, as shown in Figure 6 The method further includes the following steps:
[0073] S601, if the second response information is received in the kernel mode, the number of times of receiving the second response information is obtained; the second response information represents a random number sending error.
[0074] In the embodiment, if the terminal receives the second response information representing the random number sending error fed back by the coulomb counter in the kernel mode, the terminal can count the number of times of receiving the second response information in the kernel mode, that is, count the number of times of receiving the response information representing the random number sending error fed back by the coulomb counter.
[0075] S602, if the number of times of receiving is less than a preset threshold, a new random number generated in the user mode is re-sent to the coulomb counter.
[0076] As an optional implementation, if the terminal determines that the number of times of receiving the second response information representing the random number sending error fed back by the coulomb counter is less than the preset threshold in the kernel mode, the terminal can determine that the random number sending error occurs, and can re-send a new random number generated in the user mode to the coulomb counter, so that the coulomb counter can perform the encryption authentication based on the received new random number, and determine whether the battery supports the fast charging protocol.
[0077] In the embodiment, as another optional implementation, if the terminal determines that the number of times of receiving the second response information representing the random number sending error fed back by the coulomb counter is greater than or equal to the preset threshold in the kernel mode, the terminal can determine that the encryption authentication of the battery fails this time, and the terminal can output prompt information representing that the battery does not support the fast charging protocol, prompting the user that the battery of the terminal cannot be fast charged, and the battery of the terminal does not support high-power charging.
[0078] In this embodiment, if the terminal receives second response information representing that the random number fed back by the power gauge is sent incorrectly in the kernel state, the terminal can obtain the number of times of receiving the second response information, and resend a new random number generated in the user state to the power gauge in a timely manner in the case that the number of times of receiving the second response information is less than a preset threshold, thereby avoiding the case that the battery cannot perform the encryption authentication because the random number is not received, and ensuring that the battery can perform the encryption authentication based on the random number sent by the terminal in a timely manner.
[0079] For the convenience of those skilled in the art, the battery authentication method provided by the present disclosure is described in detail below. Please refer to Figure 7 The method can include:
[0080] S1, when the terminal kernel state starts running, if the power gauge driver loading is completed, the battery encryption authentication message is initiated.
[0081] S2, in response to the battery authentication message, it is determined whether the HIDL service of the user state is loaded.
[0082] S3, in the case that the HIDL service of the user state is loaded, the encrypted SO dynamic library is called in the user state, the random number is generated using the API in the user state, and the ciphertext A is generated using the pre-stored key and DES algorithm based on the generated random number, and the generated random number and ciphertext A are issued to the kernel state.
[0083] S4, the random number is subjected to cyclic redundancy check code (CRC) check in the kernel state, and a first check value is obtained.
[0084] S5, the random number and the first check value are carried in the indication message and sent to the power gauge in the kernel state; the indication information is used to instruct the power gauge to generate the ciphertext B, and feedback the response information representing whether the random number is sent correctly; the response information is the second check value generated by the power gauge by performing CRC check on the random number.
[0085] S6, if the first response information representing that the random number is sent correctly is received in the kernel state, the ciphertext B is read from the power gauge after a preset time period.
[0086] S7, if the second response information representing that the random number is sent incorrectly is received in the kernel state, the number of times of receiving the second response information is obtained.
[0087] S8, in the case that the number of times of receiving is less than a preset threshold, a new random number generated in the user state is resent to the power gauge; in the case that the number of times of receiving is greater than or equal to the preset threshold, prompt information representing that the battery does not support the fast charging protocol is output.
[0088] S9, obtaining a comparison result of the ciphertext A and the ciphertext B; the comparison result is used to represent whether the ciphertext A is same as the ciphertext B.
[0089] S10, in a case where the comparison result represents that the ciphertext A is same as the ciphertext B, determining that the battery supports the fast charging protocol, and in a case where the comparison result represents that the ciphertext A is different from the ciphertext B, outputting prompt information representing that the battery does not support the fast charging protocol.
[0090] It should be noted that the description in the above steps can refer to the related description in the above embodiments, and the effects are similar, and the present embodiment will not be repeated here.
[0091] It should be understood that, although each step in the flowchart involved in the above embodiments is displayed in sequence according to the arrow, these steps are not necessarily executed in the order indicated by the arrow. Unless otherwise stated herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowchart involved in the above embodiments can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or steps or stages in other steps.
[0092] Based on the same inventive concept, the present application also provides a battery authentication device for implementing the above-mentioned battery authentication method. The implementation scheme of the problem solving provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more battery authentication device embodiments provided below can refer to the limitations of the battery authentication method in the above text, and will not be repeated here.
[0093] In one embodiment, as shown in Figure 8 a battery authentication device is provided, comprising: a generation module 10, a first sending module 11 and an authentication module 12, wherein:
[0094] The generation module 10 is configured to generate a random number and a first ciphertext in a user state in response to a battery authentication message;
[0095] The first sending module 11 is configured to send an indication message to the coulometer in a kernel state; the indication message includes the random number, and the indication message is used to instruct the coulometer to generate a second ciphertext based on the random number;
[0096] The authentication module 12 is configured to obtain the second ciphertext generated by the coulometer in the kernel state, and determine whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext.
[0097] The battery authentication device provided in the embodiment can execute the method embodiments, and has similar implementation principles and technical effects, which will not be described here.
[0098] Based on the above-mentioned embodiments, as shown in Figure 9 Optionally, the authentication module 12 includes a first obtaining unit 121 and a first determining unit 122, where:
[0099] The first obtaining unit 121 is configured to obtain a comparison result of the first ciphertext and the second ciphertext, and the comparison result is used to represent whether the first ciphertext and the second ciphertext are the same.
[0100] The first determining unit 122 is configured to determine, according to the comparison result, whether the battery supports the fast charging protocol.
[0101] The battery authentication device provided in the embodiment can execute the method embodiments, and has similar implementation principles and technical effects, which will not be described here.
[0102] Based on the above-mentioned embodiments, optionally, the first determining unit 122 is configured to, in a case where the comparison result represents that the first ciphertext and the second ciphertext are the same, determine that the battery supports the fast charging protocol; and in a case where the comparison result represents that the first ciphertext and the second ciphertext are different, output prompt information representing that the battery does not support the fast charging protocol.
[0103] The battery authentication device provided in the embodiment can execute the method embodiments, and has similar implementation principles and technical effects, which will not be described here.
[0104] Based on the above-mentioned embodiments, as shown in Figure 10 Optionally, the generation module 10 includes a second determining unit 101 and a generation unit 102, where:
[0105] The second determining unit 101 is configured to, in response to the battery authentication message, determine whether a target service in a user mode is loaded.
[0106] The generation unit 102 is configured to, in a case where it is determined that the target service is loaded, generate, in the user mode, the random number and the first ciphertext.
[0107] The battery authentication device provided in the embodiment can execute the method embodiments, and has similar implementation principles and technical effects, which will not be described here.
[0108] Based on the above-mentioned embodiments, optionally, the generation unit 102 is configured to, in a case where it is determined that the target service is loaded, call a preset program library in the user mode; and generate, in the user mode, the random number and the first ciphertext by using the program library.
[0109] The battery authentication device provided in the embodiment can execute the method embodiment, and has similar implementation principles and technical effects, which will not be described here.
[0110] Based on the above-mentioned embodiment, as shown in Figure 11 Optionally, the first sending module 11 includes a second acquisition unit 111 and a sending unit 112.
[0111] The second acquisition unit 111 is configured to perform a cyclic redundancy check code (CRC) check on the random number in the kernel state, and acquire a first check value.
[0112] The sending unit 112 is configured to send the random number and the first check value in the indication message to the power meter in the kernel state; the indication information is used to instruct the power meter to generate second ciphertext and feed back response information used to represent whether the random number is sent correctly; the response information is a second check value generated by the power meter by performing a CRC check on the random number, and is generated according to the first check value and the second check value.
[0113] The battery authentication device provided in the embodiment can execute the method embodiment, and has similar implementation principles and technical effects, which will not be described here.
[0114] Based on the above-mentioned embodiment, as shown in Figure 12 Optionally, the authentication module 12 includes a reading unit 123.
[0115] The reading unit 123 is configured to read the second ciphertext from the power meter after a preset time length if the first response information is received in the kernel state; the first response information represents that the random number is sent correctly.
[0116] The battery authentication device provided in the embodiment can execute the method embodiment, and has similar implementation principles and technical effects, which will not be described here.
[0117] Based on the above-mentioned embodiment, as shown in Figure 13 Optionally, the device further includes an acquisition module 13 and a second sending module 14.
[0118] The acquisition module 13 is configured to acquire a receiving frequency of the second response information if the second response information is received in the kernel state; the second response information represents that the random number is sent incorrectly.
[0119] The second sending module 14 is configured to resend a new random number generated in the user state to the power meter if the receiving frequency is less than a preset threshold.
[0120] The battery authentication device provided in the embodiment can execute the method embodiment, and has similar implementation principles and technical effects, which will not be described here.
[0121] On the basis of the above-mentioned embodiments, as Figure 14 shown, optionally, the above-mentioned device further comprises: an output module 15, wherein:
[0122] The output module 15 is configured to output prompt information indicating that the battery does not support the fast charging protocol when the number of receiving times is greater than or equal to the preset threshold.
[0123] The battery authentication device provided in the embodiment can execute the above-mentioned method embodiment, and has similar implementation principles and technical effects, which will not be described here again.
[0124] The above-mentioned various modules in the battery authentication device can be realized by software, hardware and combinations thereof in whole or in part. The above-mentioned various modules can be embedded in or independent of the processor in the computer device in hardware form, or can be stored in the memory in the computer device in software form, so as to be called and executed by the processor to execute the operations corresponding to the above-mentioned various modules.
[0125] In one embodiment, a computer device is provided, which can be a terminal, and an internal structure diagram thereof can be as Figure 15 shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium to run. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to perform wired or wireless communication with external terminals, and the wireless communication can be realized through WIFI, mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by the processor to realize a battery authentication method. The display unit of the computer device is configured to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or can be a key, a trackball or a touchpad arranged on the shell of the computer device, or can be an external keyboard, a touchpad or a mouse, etc.
[0126] Those skilled in the art can understand, Figure 15The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. The specific computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0127] The embodiments of the present application also provide a computer readable storage medium. One or more non-volatile computer readable storage media storing computer-executable instructions that, when executed by one or more processors, cause the processors to perform the steps of the battery authentication method.
[0128] The embodiments of the present application also provide a computer program product containing instructions which, when run on a computer, cause the computer to perform the battery authentication method.
[0129] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric memory (Ferroelectric Random Access Memory, FRAM), phase change memory (Phase Change Memory, PCM), graphene memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0130] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.
[0131] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.
Claims
1. A battery authentication method characterized by comprising: The method comprises: in response to a battery authentication message, generating a random number and first ciphertext in a user state; the first ciphertext is generated by a data encryption standard algorithm based on the random number and a pre-stored first key; in the entire running cycle of the terminal, including a plurality of different battery authentication messages, the random number and the first ciphertext generated for different battery authentication messages are all different; sending an indication message to the battery gauge in a kernel state; the indication message includes the random number, and the indication message is used to instruct the battery gauge to generate a second ciphertext based on the random number; in the kernel state, obtaining the second ciphertext generated by the battery gauge, and determining whether the battery supports a fast charging protocol according to the first ciphertext and the second ciphertext.
2. The method of claim 1, wherein, The determination of whether the battery supports the fast charging protocol according to the first ciphertext and the second ciphertext comprises: obtaining a comparison result of the first ciphertext and the second ciphertext; the comparison result is used to represent whether the first ciphertext and the second ciphertext are the same; determining whether the battery supports the fast charging protocol according to the comparison result.
3. The method of claim 2, wherein, The determination of whether the battery supports the fast charging protocol according to the comparison result comprises: in the case that the comparison result represents that the first ciphertext and the second ciphertext are the same, determining that the battery supports the fast charging protocol; in the case that the comparison result represents that the first ciphertext and the second ciphertext are different, outputting prompt information representing that the battery does not support the fast charging protocol.
4. The method according to any one of claims 1 to 3, characterized in that, The generation of the random number and the first ciphertext in the user state in response to the battery authentication message comprises: in response to the battery authentication message, determining whether a target service of the user state is loaded completely; in the case that it is determined that the target service is loaded completely, generating the random number and the first ciphertext in the user state.
5. The method of claim 4, wherein, The generation of the random number and the first ciphertext in the user state in the case that it is determined that the target service is loaded completely comprises: in the case that it is determined that the target service is loaded completely, calling a preset program library in the user state; generating the random number and the first ciphertext by using the program library in the user state.
6. The method according to any one of claims 1 to 3, characterized in that, The sending of the indication message to the battery gauge in the kernel state comprises: performing a cyclic redundancy check (CRC) on the random number in the kernel state to obtain a first check value; carrying the random number and the first check value in the indication message to send to the battery gauge in the kernel state; the indication message is used to instruct the battery gauge to generate the second ciphertext and to feed back response information representing whether the random number is sent correctly; the response information is a second check value generated by the battery gauge by performing a CRC on the random number and the first check value.
7. The method of claim 6, wherein, The obtaining of the second ciphertext generated by the battery gauge in the kernel state comprises: if a first response information is received in the kernel state, reading the second ciphertext from the battery gauge after a preset time length; the first response information represents that the random number is sent correctly.
8. The method of claim 6, wherein, The method further comprises: If a second response information is received in the kernel state, a receiving number of the second response information is acquired; the second response information represents a random number sending error; If the receiving number is less than a preset threshold, a new random number generated in the user state is re-sent to the power gauge.
9. The method of claim 8, wherein, The method further comprises: If the receiving number is greater than or equal to the preset threshold, prompt information representing that the battery does not support the fast charging protocol is output.
10. A battery authentication device characterized by comprising: Comprise: A generating module is configured to generate a random number and a first cipher text in a user state in response to a battery authentication message; the first cipher text is generated based on the random number and a pre-stored first key using a data encryption standard algorithm; The random number and the first cipher text generated for different battery authentication messages are different in a whole running cycle of the terminal; A first sending module is configured to send an indication message to a power gauge in a kernel state; The indication message comprises the random number, and the indication message is used to instruct the power gauge to generate a second cipher text based on the random number; An authentication module is configured to acquire the second cipher text generated by the power gauge in the kernel state, and determine whether the battery supports the fast charging protocol according to the first cipher text and the second cipher text. 11.A terminal, comprising a memory and a processor, wherein the memory stores a computer program, and the computer program comprises the following steps of: The computer program is executed by the processor, so that the processor executes the steps of the battery authentication method in any one of claims 1 to 9.
12. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor, so that the processor executes the steps of the method in any one of claims 1 to 9.
13. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor, so that the processor executes the steps of the method in any one of claims 1 to 9.
Citation Information
Patent Citations
Authority authentication method and device, and server device
CN111708762A
Data transmission method and device
CN113949116A