ExCEP. Crypto. SM4
(ex_cep v0.1.1)
Copy Markdown
Pure Elixir implementation of the Chinese national block cipher SM4 (GB/T 32907-2016).
Supports:
- Raw 128-bit ECB block encryption/decryption (
encrypt_block/2,decrypt_block/2) - SM4-CBC with PKCS#7 padding (
encrypt_cbc/3,decrypt_cbc/3) - SM4-CTR stream mode (
crypt_ctr/3)
Implements ExCEP.Transport.Cipher for CSG CEP TS6.3 encrypted channels.
Summary
Functions
Encrypts or decrypts binary data using SM4-CTR mode.
Decrypts a single 16-byte block with a 16-byte SM4 key.
Decrypts SM4-CBC ciphertext with PKCS#7 unpadding.
Encrypts plaintext with SM4.
Encrypts a single 16-byte block with a 16-byte SM4 key.
Encrypts binary plaintext using SM4-CBC with PKCS#7 padding.
Functions
Encrypts or decrypts binary data using SM4-CTR mode.
@spec decrypt_block(<<_::128>>, <<_::128>>) :: <<_::128>>
Decrypts a single 16-byte block with a 16-byte SM4 key.
Decrypts SM4-CBC ciphertext with PKCS#7 unpadding.
Encrypts plaintext with SM4.
Options
:key- 16-byte SM4 key (required):mode-:cbc(default, prepends 16-byte random IV) or:ctr(prepends 16-byte random nonce)
@spec encrypt_block(<<_::128>>, <<_::128>>) :: <<_::128>>
Encrypts a single 16-byte block with a 16-byte SM4 key.
Encrypts binary plaintext using SM4-CBC with PKCS#7 padding.