sentc_crypto_core/
lib.rs

1//! # Sentclose crypto crate
2//! This create is non_std with alloc
3//!    
4//! used alg:
5//! - Password hashing
6//! 	- argon2
7//! - symmetric encryption:
8//! 	- aes gcm
9//! - asymmetric encryption:
10//! 	- ecies based on x25519
11//! - signing
12//! 	- ed25519
13//! - hmac
14//! 	- hmac sha256
15//!
16//! This create can be used as stand-alone version without the sentclose api
17
18#![no_std]
19#![allow(clippy::infallible_destructuring_match, clippy::tabs_in_doc_comments, clippy::from_over_into)]
20
21extern crate alloc;
22
23pub mod cryptomat;
24mod error;
25pub mod group;
26pub mod user;
27
28use rand_core::{CryptoRng, OsRng, RngCore};
29
30pub use self::error::Error;
31
32fn get_rand() -> impl CryptoRng + RngCore
33{
34	#[cfg(feature = "default_env")]
35	OsRng
36}
37
38pub fn generate_user_register_data() -> Result<([u8; 20], [u8; 40]), Error>
39{
40	let mut identifier = [0u8; 20];
41	let mut password = [0u8; 40];
42
43	let mut rng = get_rand();
44
45	rng.try_fill_bytes(&mut identifier)
46		.map_err(|_| Error::KeyCreationFailed)?;
47
48	rng.try_fill_bytes(&mut password)
49		.map_err(|_| Error::KeyCreationFailed)?;
50
51	Ok((identifier, password))
52}
53
54pub fn split_sig_and_data(data_with_sig: &[u8], len: usize) -> Result<(&[u8], &[u8]), Error>
55{
56	if data_with_sig.len() <= len {
57		return Err(Error::DataToSignTooShort);
58	}
59
60	//split sign and data
61	let sig = &data_with_sig[..len];
62	let data = &data_with_sig[len..];
63
64	Ok((sig, data))
65}