CoolrfulDARkness/moontlcp/crypto/sm4 does not have a README file

    Sm4Error

    pub suberror Sm4Error {
    InvalidKeyLength(Int)
    InvalidIvLength(Int)
    InvalidBlockLength(Int)
    InvalidPadding
    AuthFailed
    } derive(Eq,
    Debug
    )

    Sm4Key

    pub struct Sm4Key {
    rk : FixedArray[UInt]
    }

    Expanded SM4 round keys (32 rounds).

    Sm4Key::cbc_decrypt_pkcs7

    fn Sm4Key::cbc_decrypt_pkcs7(self : Sm4Key, iv : Bytes, ciphertext : Bytes) -> Bytes raise Sm4Error

    SM4-CBC decryption with constant-time PKCS#7 padding verification.

    Sm4Key::cbc_decrypt_raw

    fn Sm4Key::cbc_decrypt_raw(self : Sm4Key, iv : Bytes, data : Bytes) -> Bytes raise Sm4Error

    Raw SM4-CBC decryption (no padding stripped; data.length() must be a multiple of 16).

    Sm4Key::cbc_encrypt_pkcs7

    fn Sm4Key::cbc_encrypt_pkcs7(self : Sm4Key, iv : Bytes, plaintext : Bytes) -> Bytes raise Sm4Error

    SM4-CBC encryption with PKCS#7 padding.

    Sm4Key::cbc_encrypt_raw

    fn Sm4Key::cbc_encrypt_raw(self : Sm4Key, iv : Bytes, data : Bytes) -> Bytes raise Sm4Error

    Raw SM4-CBC encryption (no padding added; data.length() must be a multiple of 16).

    Sm4Key::ctr_crypt

    fn Sm4Key::ctr_crypt(self : Sm4Key, iv : Bytes, data : Bytes) -> Bytes raise Sm4Error

    SM4-CTR encryption/decryption (big-endian 128-bit counter increment).

    Sm4Key::decrypt_block

    fn Sm4Key::decrypt_block(self : Sm4Key, block : Bytes) -> Bytes raise Sm4Error

    Decrypts a single 16-byte block.

    Sm4Key::decrypt_block_inplace

    fn Sm4Key::decrypt_block_inplace(self : Sm4Key, buf : FixedArray[Byte], off : Int) -> Unit

    Decrypts a single 16-byte block in place.

    Sm4Key::ecb_decrypt_pkcs7

    fn Sm4Key::ecb_decrypt_pkcs7(self : Sm4Key, ciphertext : Bytes) -> Bytes raise Sm4Error

    SM4-ECB decryption with constant-time PKCS#7 padding verification (GB/T 32907-2016 / GB/T 38635.4).

    Sm4Key::ecb_encrypt_pkcs7

    fn Sm4Key::ecb_encrypt_pkcs7(self : Sm4Key, plaintext : Bytes) -> Bytes

    SM4-ECB encryption with PKCS#7 padding (1..16 bytes, GB/T 32907-2016 / GB/T 38635.4).

    Sm4Key::encrypt_block

    fn Sm4Key::encrypt_block(self : Sm4Key, block : Bytes) -> Bytes raise Sm4Error

    Encrypts a single 16-byte block.

    Sm4Key::encrypt_block_inplace

    fn Sm4Key::encrypt_block_inplace(self : Sm4Key, buf : FixedArray[Byte], off : Int) -> Unit

    Encrypts a single 16-byte block in place.

    Sm4Key::gcm_decrypt

    fn Sm4Key::gcm_decrypt(self : Sm4Key, iv : Bytes, aad : Bytes, ciphertext : Bytes, tag : Bytes) -> Bytes raise Sm4Error

    RFC 8998 / GM/T 0024-2023 SM4-GCM authenticated decryption. Verifies the 16-byte tag in constant time before releasing plaintext.

    Sm4Key::gcm_encrypt

    fn Sm4Key::gcm_encrypt(self : Sm4Key, iv : Bytes, aad : Bytes, plaintext : Bytes) -> (Bytes, Bytes) raise Sm4Error

    RFC 8998 / GM/T 0024-2023 SM4-GCM authenticated encryption. Returns (ciphertext, tag) where tag.length() == 16.

    Sm4Key::new

    fn Sm4Key::new(key : Bytes) -> Sm4Key raise Sm4Error

    Expands a 16-byte SM4 key into 32 round keys.

    SM4_BLOCK_SIZE

    let SM4_BLOCK_SIZE : Int

    SM4_GCM_TAG_SIZE

    let SM4_GCM_TAG_SIZE : Int

    SM4_KEY_SIZE

    let SM4_KEY_SIZE : Int

    Source Files