Kyber_SM2

Module Contents

Functions

key_gen_hybrid(→ Tuple[str, str])

Generates the public key and private key for the hybrid encryption scheme.

enc_hybrid(pk)

Encrypts the given message using the hybrid encryption scheme.

dec_hybrid(→ [str, str])

Decrypts the given ciphertext using the hybrid encryption scheme.

xor_hex_strings(hex_str1, hex_str2)

Performs a bitwise XOR operation on two hexadecimal strings.

sm4_encode(key, IV, data)

Encrypts the given data using the SM4 encryption algorithm.

sm4_decode(key, IV, data)

Kyber_SM2.key_gen_hybrid() Tuple[str, str][源代码]

Generates the public key and private key for the hybrid encryption scheme.

Returns:

Tuple containing the public key and private key. - pk (bytes): Public key containing two parts of information. - sk (bytes): Private key containing two parts of information,

private key for Kyber algorithm and private key for SM2 encryption.

Kyber_SM2.enc_hybrid(pk: str)[源代码]

Encrypts the given message using the hybrid encryption scheme.

Args:
  • pk (bytes): Public key containing two parts of information, Kyber pk || SM2 pk .

  • msg (list): List of messages to be encrypted.

Returns:

Tuple containing the encrypted ciphertext, symmetric key, and encrypted message. - c_text (bytes): Encrypted ciphertext containing two parts of information,

ciphertext encrypted using Kyber algorithm and ciphertext encrypted using SM2 encryption.

  • sym_key (str): Symmetric key used for encryption.

  • msg_enc (list): Encrypted message.

Kyber_SM2.dec_hybrid(c_text1, c_text2, sk) [str, str][源代码]

Decrypts the given ciphertext using the hybrid encryption scheme.

Args:
  • c_text (bytes): Ciphertext to be decrypted, containing two parts of information, ciphertext encrypted using Kyber algorithm and ciphertext encrypted using SM2 encryption.

  • sk (bytes): Private key containing two parts of information, private key for Kyber algorithm and private key for SM2 encryption.

  • msg_enc (list): Encrypted message.

Returns:

Decrypted message.

Kyber_SM2.xor_hex_strings(hex_str1: str, hex_str2: str)[源代码]

Performs a bitwise XOR operation on two hexadecimal strings.

Args:

hex_str1 (str): The first hexadecimal string. hex_str2 (str): The second hexadecimal string.

Returns:

The result of the XOR operation as a hexadecimal string.

Kyber_SM2.sm4_encode(key, IV, data)[源代码]

Encrypts the given data using the SM4 encryption algorithm.

Args:

key (str): The encryption key. data (str): The data to be encrypted.

Returns:

The encrypted data as a hexadecimal string. :param key: :param data: :param IV:

Kyber_SM2.sm4_decode(key, IV, data)[源代码]