#block-cipher #sm3 #hashing #mac #sm4 #shang-mi

neuedu-cryptos

包含国密算法的密码库。 A library include SM3, SM4 (Chinese ShangMi) crypto algos

10 releases (4 breaking)

0.5.3 Dec 14, 2023
0.5.2 Dec 7, 2023
0.4.0 Dec 5, 2023
0.3.0 Dec 4, 2023
0.1.6 Dec 2, 2023

#1566 in Cryptography

Download history 5/week @ 2024-02-10 97/week @ 2024-02-17 14/week @ 2024-02-24 18/week @ 2024-03-09 83/week @ 2024-03-30 17/week @ 2024-04-06

100 downloads per month
Used in neuedu-cryptos-wasm

MIT/Apache

125KB
1.5K SLoC

Neuedu-Cryptos

Crates.io: neuedu-cryptos Documentation


lib.rs:

此密码库实现了中华人民共和国国家密码管理局发布的商用密码算法。
This cryptographic library implements the ShangMi algorithms which issued by the State Cryptography Administration of the People's Republic of China.

支持算法列表(Available Algoruthms)

  • 密码杂凑算法(Cryptographic Hash Algoruthms)

    • SM3 - SM3密码杂凑算法(ShangMi 3 Cryptographic Hash Algoruthm)
    • SHA-1 - 安全散列算法1(Secure Hash Algorithm 1)
    • SHA-2 - 安全散列算法2(Secure Hash Algorithm 2)
    • 了解更多(Learn More)
  • 分组密码算法(Block Cipher Algoruthms)

  • 消息鉴别码算法(Message Authentication Code Algoruthms)

支持分组工作模式列表(Available Operation Modes for Block Cipher)

  • ECB - 电码本(Electronic Codebook)
  • CBC - 密文分组链接(Cipher Block Chaining)
  • CFB - 密文反馈(Cipher Feedback)
  • OFB - 输出反馈(Output Feedback)
  • 了解更多(Learn More)

示例(Examples)

  • 使用密文分组链接工作模式的SM4分组密码算法的流式加密计算(SM4-CBC Encryption Stream Mode Calculate)
use neuedu_cryptos::common::PaddingMethod;
use neuedu_cryptos::block_ciphers::{BlockCipherImpl, Operation, OperationMode, SM4};

#
let mut instance = SM4::new(
    KEY,
    Operation::Encrypt,
    Some(OperationMode::CBC(IV.into())),
    Some(PaddingMethod::Method1),
)?;

let mut cipher = Vec::<u8>::new();
cipher.append(&mut instance.update(&PLAIN_MESSAGE)?);
cipher.append(&mut instance.r#final()?);
#
#
  • 基于SM3密码杂凑算法的密钥杂凑消息鉴别码的块式计算(HMAC-SM3 Block Mode Calculate)
use neuedu_cryptos::mac::hmac_sm3;

let mac = hmac_sm3(b"key", b"message")?;
#
#

No runtime deps