use getrandom::SysRng;
use gmcrypto_core::sm2::{DEFAULT_SIGNER_ID, Sm2PrivateKey, sign_raw_with_id};
use gmcrypto_core::sm4::{Sm4CbcDecryptor, Sm4CbcEncryptor};
#[test]
fn sign_raw_with_id_exists() {
let key = Sm2PrivateKey::from_bytes_be(&[0x11; 32])
.into_option()
.expect("0x11..11 is a valid SM2 scalar");
let mut rng = SysRng;
let pair = sign_raw_with_id(&key, DEFAULT_SIGNER_ID, b"v0.21 existence probe", &mut rng);
assert!(pair.is_ok());
}
#[test]
fn cbc_take_output_drains_exist() {
let key = [0x22u8; 16];
let iv = [0x33u8; 16];
let mut enc = Sm4CbcEncryptor::new(&key, &iv);
enc.update(&[0u8; 32]);
let emitted = enc.take_output();
assert_eq!(emitted.len() % 16, 0);
let mut dec = Sm4CbcDecryptor::new(&key, &iv);
dec.update(&emitted);
let _so_far = dec.take_output();
}
#[test]
fn group_a_low_level_curve_surface_exists() {
use gmcrypto_core::sm2::curve::{Fn, Fp};
use gmcrypto_core::sm2::point::ProjectivePoint;
const _: fn() -> Fp = gmcrypto_core::sm2::curve::b;
const _: fn() -> Fp = gmcrypto_core::sm2::curve::b3;
const _: fn(&Fn) -> ProjectivePoint = gmcrypto_core::sm2::scalar_mul::mul_g;
const _: fn(&Fn, &ProjectivePoint) -> ProjectivePoint = gmcrypto_core::sm2::scalar_mul::mul_var;
const _: fn(&gmcrypto_core::sm2::Fn) -> ProjectivePoint = gmcrypto_core::sm2::mul_g;
const _: fn(&gmcrypto_core::sm2::Fn, &ProjectivePoint) -> ProjectivePoint =
gmcrypto_core::sm2::mul_var;
const _: fn() -> gmcrypto_core::sm2::Fp = gmcrypto_core::sm2::curve::b;
const _: fn(&ProjectivePoint) -> Option<(Fp, Fp)> = ProjectivePoint::to_affine;
let affine = ProjectivePoint::generator().to_affine();
assert!(affine.is_some(), "generator is finite");
}
#[test]
#[allow(clippy::type_complexity)]
fn group_w1_reshaped_surface_exists() {
use gmcrypto_core::sm2::Sm2PublicKey;
use gmcrypto_core::sm2::point::ProjectivePoint;
use gmcrypto_core::traits::BlockCipher;
const _: fn(ProjectivePoint) -> Sm2PublicKey = Sm2PublicKey::from_point;
const _: fn(&Sm2PublicKey) -> ProjectivePoint = Sm2PublicKey::point;
const _: fn(&[u8]) -> Option<(&[u8], &[u8])> = gmcrypto_core::asn1::reader::read_sequence;
const _: fn(&mut Vec<u8>, &[u8]) = gmcrypto_core::asn1::writer::write_sequence;
const _: fn(&[u32]) -> [u8; 3] = gmcrypto_core::asn1::oid::encode::<3>;
fn _assert_block_cipher<T: BlockCipher>() {}
let _ = _assert_block_cipher::<gmcrypto_core::sm4::Sm4Cipher>;
let key = Sm2PrivateKey::from_bytes_be(&[0x11; 32])
.into_option()
.expect("0x11..11 is a valid SM2 scalar");
let pk: Sm2PublicKey = key.public_key();
let _: ProjectivePoint = pk.point();
}