Crates.io | enard |
lib.rs | enard |
version | 0.1.1 |
source | src |
created_at | 2022-06-18 16:22:53.626746 |
updated_at | 2022-06-18 17:23:21.430953 |
description | Implementation of the enard container format |
homepage | |
repository | https://github.com/bindernews/enard |
max_upload_size | |
id | 608598 |
size | 44,169 |
Enard is an encrypted container format, intended to allow on-the-fly decryption of game assets
stored in a different format (e.g. a zip file). Enard encrypts the "wrapped" file and provides
a reader which implements Rust's std::io::Read
and std::io::Seek
traits, allowing users
to treat it similarly to a file. In practice this means it's very easy to wrap the
zip library around an EnardReader
and it just works.
Here's an example
let key = [0x42u8; 32];
let file = File::open("example.zip.enard")?;
let e_reader = EnardReader::new(BufReader::new(file), RuntimeCipherFactory, &key)?;
let archive = ZipArchive::new(e_reader)?;
for names in archive.file_names() {
println!("{}", name);
}
Enard files can be created either using the library directly, or with the CLI.
Enard uses a stream cipher for encryption to be able to jump to any point in the file when
decrypting, allowing the reader to implement std::io::Seek
and thus act like a file.
Enard also uses a SHA2-256 Message Authentication Code to verify that the file hasn't
been modified.
For more details about the file format see format.md.
The default cipher is ChaCha12 instead of ChaCha20 because the intent of this library is to load encrypted assets from disk for games, and ChaCha12 is a good mix of security and performance. Enard is not meant to make game assets impossible to steal, it's a deterrent.
Those fields are both unencrypted and not part of the MAC, meaning an attacker can easily change both. The problem is that doing so would change what data is fed into the MAC, meaning it would fail to authenticate and the decryption would fail.
First, you might not want to use ZIP files. Second, ZIP file encryption is relatively weak, doesn't apply to the whole file, requires that the file be decrypted all at once, and many zip implementations simply don't support it.
There are many reasonable archive formats out there that are well-specified and have well-tested implementations. Enard isn't trying to reinvent the wheel, just put a bike-lock on it.