Methods and devices for invoking cryptographic services, storage media, and electronic devices

By introducing the structure and factory method of the cryptographic service provider into the distributed ledger system, the decoupling of the system and the cryptographic algorithm library is achieved, which solves the problem of the system being unable to accept new algorithm service providers, and improves the flexibility and flexibility of the system. Adaptability.

CN112035859BActive Publication Date: 2024-09-17EVERBRIGHT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010889888.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-28
Publication Date
2024-09-17
Estimated Expiration
2040-08-28

AI Technical Summary

Technical Problem

The distributed ledger system cannot effectively accommodate new algorithm service providers, making system upgrades difficult and lacking flexibility.

Method used

By adding the structure and factory method of the cryptographic service provider, the system is allowed to easily call and replace the cryptographic service provider, decoupling the system from the cryptographic algorithm library, and reducing changes to the source code.

Benefits of technology

It improves the flexibility of the system, enables the system to easily add or replace cryptographic service providers, reduces the need for source code changes, supports multiple cryptographic algorithms, and improves the adaptability and maintainability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112035859B
    Figure CN112035859B
Patent Text Reader

Abstract

The embodiment of the present invention provides a method and device for calling a cryptographic service, a storage medium, and an electronic device. The method includes adding a structure of a cryptographic service provider, wherein the structure includes parameters for calling the service of the cryptographic service provider; and adding a factory method of the cryptographic service provider; returning the structure instance of the cryptographic service provider through the factory method; calling the cryptographic service of the cryptographic service provider according to the structure instance. Through this method, the system can easily add or replace cryptographic service providers, realize the decoupling of the system and the cryptographic algorithm library, and reduce the changes to the system source code itself. It can solve the technical problem in the related technology that the system cannot well accept new algorithm service providers, and improve the flexibility of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of communications, and in particular, to a method and device for calling a cryptographic service, a storage medium, and an electronic device. Background Art

[0002] In financial distributed ledger technology, the specific cryptographic algorithms used in the current distributed ledger system are some existing standard algorithms. The implementation process of these existing algorithms is implemented in a hard-coded manner. This hard coding is reflected in two points:

[0003] On the one hand, in the Hyperledger Fabric that currently supports new standard algorithms (such as the national secret algorithm), there are multiple libraries for the implementation of the national secret algorithm code library, but the encapsulation and calling of the national secret algorithm code library in the Fabric source code are all implemented in a hard-coded manner; on the other hand, in order to support new standard algorithm libraries, such as the national secret algorithm library, in addition to adding the above-mentioned encapsulation and calling interfaces and implementations, the Fabric source code also involves the modification of its own source code. This modification is usually hard-coded, and there are many modifications that are scattered throughout the source code, which is not conducive to later version upgrades.

[0004] In the related technology, the distributed ledger system cannot accept new algorithm service providers well, which is not conducive to the upgrade of the distributed ledger system. Summary of the invention

[0005] The embodiments of the present invention provide a method and device for calling a cryptographic service, a storage medium, and an electronic device, so as to at least solve the problem in the related art that the distributed ledger system cannot well accept new algorithm service providers, which is not conducive to the upgrade of the distributed ledger system.

[0006] According to an embodiment of the present invention, a method for calling a cryptographic service is provided, which is applied to a consortium chain and includes:

[0007] Adding a structure of a cryptographic service provider, wherein the structure includes parameters for invoking the service of the cryptographic service provider; and adding a factory method of the cryptographic service provider;

[0008] Return the structure instance of the cryptographic service provider through the factory method;

[0009] The cryptographic service of the cryptographic service provider is called according to the structure instance.

[0010] According to another embodiment of the present invention, there is provided a device for invoking a cryptographic service, comprising:

[0011] An adding module, used for adding a structure of a cryptographic service provider, wherein the structure includes parameters for invoking the service of the cryptographic service provider; and a factory method for adding the cryptographic service provider;

[0012] A return module, used to return a structure instance of the cryptographic service provider through the factory method;

[0013] A calling module is used to call the cryptographic service of the cryptographic service provider according to the structure instance.

[0014] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.

[0015] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0016] Through the embodiments of the present invention, a structure of a cryptographic service provider is added, wherein the structure includes parameters for calling the services of the cryptographic service provider; and a factory method of the cryptographic service provider is added; a structure instance of the cryptographic service provider is returned through the factory method; and the cryptographic service of the cryptographic service provider is called according to the structure instance. Through this method, the system can conveniently add or replace cryptographic service providers, realize the decoupling of the system and the cryptographic algorithm library, and reduce the changes to the system source code itself. Therefore, the technical problem in the related technology that the system cannot well accept new algorithm service providers can be solved, thereby improving the flexibility of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is a hardware structure block diagram of a server of a method for calling a cryptographic service according to an embodiment of the present invention;

[0018] Figure 2 is a flow chart of a method for calling a cryptographic service according to an embodiment of the present invention;

[0019] Figure 3 is a structural block diagram of a device for invoking a cryptographic service according to an embodiment of the present invention;

[0020] Figure 4 It is a schematic diagram of the process of providing encryption algorithm services according to an embodiment of the present invention. DETAILED DESCRIPTION

[0021] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.

[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0023] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Figure 1 FIG. 1 is a hardware structure diagram of a server of a method for calling a cryptographic service according to an embodiment of the present invention. Figure 1 As shown, the server may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the server may also include a transmission device 106 and an input / output device 108 for communication functions. A person skilled in the art will understand that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0024] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the calling method of the password service in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the server via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0025] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the server. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0026] The embodiments of the present application can be run on a consortium chain architecture, such as a distributed ledger system.

[0027] In this embodiment, a method for calling a cryptographic service running on the above server or consortium chain architecture is provided. Figure 2 is a flow chart of a method for calling a cryptographic service according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:

[0028] Step S202, adding a structure of a cryptographic service provider, wherein the structure includes parameters for invoking the service of the cryptographic service provider; and adding a factory method of the cryptographic service provider;

[0029] Step S204, returning the structure instance of the cryptographic service provider through the factory method;

[0030] Step S206: calling the cryptographic service of the cryptographic service provider according to the structure instance.

[0031] Through the above steps, due to adding a structure of a cryptographic service provider, wherein the structure includes parameters for calling the service of the cryptographic service provider; and adding a factory method of the cryptographic service provider; returning a structure instance of the cryptographic service provider through the factory method; calling the cryptographic service of the cryptographic service provider according to the structure instance, through this method, the system can easily add or replace cryptographic service providers, realizes the decoupling of the system and the cryptographic algorithm library, and reduces the changes to the system source code itself. Therefore, it can solve the technical problem in the related technology that the system cannot well accept new algorithm service providers, and improve the flexibility of the system.

[0032] In an exemplary embodiment, before returning the structure instance of the cryptographic service provider through the factory method, the method further includes: determining that a service switch of the cryptographic service provider is turned on, wherein the cryptographic service provider is configured with a service switch.

[0033] In an exemplary embodiment, the structure of the cryptographic service provider includes at least one of the following parameters: Keystore parameter, KeyGenerators parameter, KeyImporters parameter, Encryptors parameter, Decryptors parameter, Signers parameter, Verifiers parameter, and Hashers parameter.

[0034] In an exemplary embodiment, before returning the structure instance of the cryptographic service provider through the factory method, the method further includes: specifying a server name parameter of the factory method as the name of the cryptographic service provider.

[0035] In an exemplary embodiment, calling the cryptographic service of the cryptographic service provider according to the structure instance includes: calling the registrar of the structure instance according to the structure instance, returning the registrar interface of the cryptographic service provider; calling the cryptographic service of the cryptographic service provider according to the registrar interface.

[0036] In an exemplary embodiment, after calling the cryptographic service of the cryptographic service provider according to the structure instance, the method further includes: receiving certificate parameters of the cryptographic service provider through cryptogen, wherein the certificate parameters are used to indicate generation of a certificate of the cryptographic service provider.

[0037] In the present embodiment, a device for calling a cryptographic service is also provided, and the device is used to implement the above-mentioned embodiment and the preferred implementation mode, and the description thereof has been made no further. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and contemplated.

[0038] Figure 3 is a structural block diagram of a device for calling a cryptographic service according to an embodiment of the present invention. Figure 3 As shown, the device comprises:

[0039] An adding module 31, used for adding a structure of a cryptographic service provider, wherein the structure includes parameters for calling the service of the cryptographic service provider; and a factory method for adding the cryptographic service provider;

[0040] The return module 33 is used to return the structure instance of the cryptographic service provider through the factory method;

[0041] The calling module 35 is used to call the cryptographic service of the cryptographic service provider according to the structure instance.

[0042] Through the above module, by adding a structure of a cryptographic service provider, wherein the structure includes parameters for calling the services of the cryptographic service provider; and adding a factory method of the cryptographic service provider; returning a structure instance of the cryptographic service provider through the factory method; and calling the cryptographic service of the cryptographic service provider according to the structure instance, through this method, the system can easily add or replace cryptographic service providers, realize the decoupling of the system and the cryptographic algorithm library, and reduce the changes to the system source code itself. Therefore, it can solve the technical problem in the related technology that the system cannot well accept new algorithm service providers, and improve the flexibility of the system.

[0043] In an exemplary embodiment, the device further includes: a switch module, configured to turn on a service switch of the cryptographic service provider before returning the structure instance of the cryptographic service provider through the factory method, wherein the cryptographic service provider is configured with a service switch.

[0044] In an exemplary embodiment, the structure of the cryptographic service provider includes at least one of the following parameters: Keystore parameter, KeyGenerators parameter, KeyImporters parameter, Encryptors parameter, Decryptors parameter, Signers parameter, Verifiers parameter, and Hashers parameter.

[0045] In an exemplary embodiment, the device further includes: a designation module, which is used to designate a server name parameter of the factory device as the name of the cryptographic service provider before returning the structure instance of the cryptographic service provider through the factory device.

[0046] In an exemplary embodiment, the calling module 35 is used to call the registration machine of the structure instance according to the structure instance, return the registration machine interface of the cryptographic service provider; and call the cryptographic service of the cryptographic service provider according to the registration machine interface.

[0047] In an exemplary embodiment, the device also includes: a receiving module, which is used to receive the certificate parameters of the cryptographic service provider through cryptogen after calling the cryptographic service of the cryptographic service provider according to the structure instance, wherein the certificate parameters are used to indicate the generation of the certificate of the cryptographic service provider.

[0048] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0049] Example Implementations

[0050] Exemplarily, the method provided in this embodiment can be run in a consortium chain, such as the Hyperledger Fabric framework. Hyperledger Fabric is a distributed consortium chain framework originally initiated by IBM and Digital Asset. For ease of description, it is hereinafter referred to as Fabric.

[0051] Financial distributed ledgers need to meet certain requirements, and the cryptographic algorithms they use should comply with relevant specifications. With the replacement of technology, new cryptographic algorithms are always generated. So how to make financial distributed ledgers adapt to different cryptographic algorithms is a technical issue that this embodiment focuses on. The following takes the newly added national secret algorithm service of the distributed ledger system as an example to further explain the embodiment of the present invention. Among them, the national secret algorithm is the abbreviation of the national general cryptographic algorithm, which is an autonomous and controllable domestic cryptographic algorithm formulated by the State Cryptography Administration, including SM1, SM2, SM3, SM4, SM7, SM9, Zu Chongzhi Cryptographic Algorithm (ZUC), etc.

[0052] This embodiment is based on the extended development of Fabric, which supports the three national general cryptographic algorithms SM2, SM3, and SM4 formulated by the National Cryptography Administration, and provides modular and pluggable national cryptographic services.

[0053] The solution provided in this embodiment can add support for national cryptographic algorithms based on the most widely used fabric 1.4 version. By implementing the BCCSP (BlockChain Cryptographic Service Provider) interface national cryptographic service provider (GM Crypto Service Provider, referred to as GMCSP), adding national cryptographic switches (GM Options, referred to as GMOPTS), and adding new national cryptographic interfaces, the cryptographic service suite interface and the specific national cryptographic algorithm library are finally completely decoupled. The advantage of this is that the underlying national cryptographic algorithm library suite can be flexibly added to avoid vendor lock-in, and the added national cryptographic support code is avoided from being scattered in multiple places in the fabric project, which is conducive to fabric code upgrades and code maintenance.

[0054] In an exemplary implementation, the national encryption switch is used to determine whether to enable the national encryption algorithm service. The national encryption algorithm switch can be implemented by passing the OPTS parameter when generating the certificate. If the parameter is "national encryption", all cryptographic algorithms related to the fabric system will use the national encryption algorithm, that is, all cryptographic processes such as certificates, transaction signatures / verification, TLS communications, and message encryption / decryption will use the national encryption algorithm; on the contrary, if the parameter is "international", all the above cryptographic processes will use the native international cryptographic algorithms in the fabric accordingly.

[0055] The solution provided in this embodiment can support the national secret algorithm library, which is the golang implementation of the national secret SM2 / SM3 / SM4 and tls. This part adds a large number of unit tests on the basis of the existing national secret algorithm library, and uses a random uid value in the signature verification of sm2, replacing the original empty uid value, which enhances the security of the sm2 algorithm. We put the national secret algorithm library in fabric / vendor for other modules that use the national secret algorithm to call.

[0056] In an exemplary implementation, this embodiment also provides national encryption certificate support.

[0057] In an exemplary implementation, this embodiment implements the BCCSP interface GMCSP, adds GMFactory, and adds GMOPTS.

[0058] Figure 4 is a schematic diagram of a process of providing an encryption algorithm service according to an embodiment of the present invention, such as Figure 4 As shown, cryptography in Fabric is implemented through BCCSP (BlockChain Cryptographic Service Provider), which is a unified interface for cryptographic services.

[0059] The BCCSP interface roughly includes four categories, namely key lifecycle management, hashing, signature verification, and encryption and decryption.

[0060] In an exemplary embodiment, the present scheme includes the following steps:

[0061] First, we first add the GMCSP structure, which mainly contains the following fields:

[0062] Keystore field. It is an interface type used to store the private key of the national secret.

[0063] The KeyGenerators field is a map type, the key is the reflect.Type type, and the value is the KeyGen interface, which is used to generate secret keys.

[0064] The KeyImporters field is a map type, the key is the reflect.Type type, and the value is the KeyImport interface, which is used to import private keys from the keystore.

[0065] The Encryptors and Decryptors fields are both of map type, the key is of reflect.Type type, and the value is the Encryptors interface and the Decryptors interface respectively. They are used to implement the national secret encryption and decryption functions.

[0066] The Signers and Verifiers fields are both of map type, with keys of reflect.Type type and values ​​of Signers interface and Verifiers interface respectively. They are used to implement the signature and verification functions of the national secret.

[0067] Hashers field. It is a map type. The key is reflect.Type type, and the value is Hasher interface, which is used to implement the national secret hash function.

[0068] Second, add Gmfactory.

[0069] Gmfactory is a structure that implements the native BCCSPFactory interface in Fabric, including two methods: Name() and Get(opts*FactoryOpts)*(bccsp.BCCSP,error). In this way, when providing cryptographic services, GMCSP is finally returned through this factory mode.

[0070] In an exemplary implementation, the process is described by taking the KeyGen function of the national cryptographic algorithm library to generate the public and private keys of the national cryptographic algorithm as an example:

[0071] Call the Get method of the BCCSPFactory interface and specify providername="GM" in the FactoryOpts parameter to return a Gmfactory structure instance;

[0072] After obtaining the Gmfatory instance, call the KeyGen of the instance and return a national secret KeyGenerator interface;

[0073] After getting the KeyGenerator interface, call the KeyGen method;

[0074] Call the specific KeyGen function implementation of the underlying national cryptographic algorithm library. For example, the KeyGen function of the sm2 algorithm completes the generation of public and private keys.

[0075] Finally, cryptogen receives a parameter, "gm" or "sw", which determines whether to generate a national secret certificate or an international certificate. If the parameter is "gm", a national secret certificate will be generated, and then it will be converted into GmFactoryOpts in the get factory method of BCCSPFactory. Subsequent cryptographic operations will call Gmfactory and switch to the national secret algorithm.

[0076] In an exemplary implementation, the solution in this embodiment sets a national encryption switch, which can flexibly switch between international cryptographic algorithms or national encryption algorithms, avoiding hard coding.

[0077] In an exemplary implementation, this embodiment provides flexible, plug-in support for national encryption algorithms, which is decoupled from the underlying national encryption algorithm library and has good scalability and maintainability.

[0078] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0079] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.

[0080] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0081] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0082] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0083] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.

[0084] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0085] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for calling a password service, It is characterized in that Applied to consortium chains, including: Adding a structure of a cryptographic service provider, wherein the structure includes parameters for invoking the service of the cryptographic service provider; and adding a factory method of the cryptographic service provider; Return the structure instance of the cryptographic service provider through the factory method; Calling the cryptographic service of the cryptographic service provider according to the structure instance; Before returning the structure instance of the cryptographic service provider through the factory method, the method further includes: Determining that a service switch of the cryptographic service provider is turned on, wherein the cryptographic service provider is configured with a service switch; The structure of the cryptographic service provider includes: Keystore parameters, KeyGenerators parameters, KeyImporters parameters, Encryptors parameters, Decryptors parameters, Signers parameters, Verifiers parameters, and Hashers parameters.

2. The method for calling a password service according to claim 1, It is characterized in that Before returning the structure instance of the cryptographic service provider through the factory method, the method further includes: Specify the factory method's service provider name as the name of the cryptographic service provider.

3. The method for calling a password service according to claim 1, It is characterized in that The calling of the cryptographic service of the cryptographic service provider according to the structure instance comprises: Call the registration machine of the structure instance according to the structure instance, and return the registration machine interface of the cryptographic service provider; The password service of the password service provider is called according to the registration machine interface.

4. The method for calling a password service according to claim 1, It is characterized in that After calling the cryptographic service of the cryptographic service provider according to the structure instance, the method further includes: The certificate parameters of the cryptographic service provider are received through cryptogen, wherein the certificate parameters are used to instruct generation of the certificate of the cryptographic service provider.

5. A device for invoking a cryptographic service, It is characterized in that include: An adding module, used for adding a structure of a cryptographic service provider, wherein the structure includes parameters for invoking the service of the cryptographic service provider; and a factory method for adding the cryptographic service provider; A return module, used to return a structure instance of the cryptographic service provider through the factory method; A calling module, used for calling the cryptographic service of the cryptographic service provider according to the structure instance; The device also includes: A switch module, used for turning on a service switch of the cryptographic service provider before returning the structure instance of the cryptographic service provider through the factory method, wherein the cryptographic service provider is configured with a service switch; The structure of the cryptographic service provider includes: Keystore parameters, KeyGenerators parameters, KeyImporters parameters, Encryptors parameters, Decryptors parameters, Signers parameters, Verifiers parameters, and Hashers parameters.

6. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method for calling the cryptographic service described in any one of claims 1 to 5 when running.

7. An electronic device comprising a memory and a processor, It is characterized in that The memory stores a computer program, and the processor is configured to run the computer program to execute the method for calling the cryptographic service described in any one of claims 1 to 5.