Crates.io | sframe |
lib.rs | sframe |
version | 0.7.1 |
source | src |
created_at | 2022-12-16 13:07:50.943625 |
updated_at | 2024-06-21 06:22:48.27912 |
description | pure rust implementation of SFrame draft-ietf-sframe-enc-09 |
homepage | |
repository | https://github.com/TobTheRock/sframe-rs |
max_upload_size | |
id | 738807 |
size | 269,506 |
This library is an implementation of draft-ietf-sframe-enc-09 and provides and end-to-end encryption mechanism for media frames that is suited for WebRTC conferences. It was forked from the original goto-opensource/secure-frame-rs and is continued here.
Currently two crypto libraries are supported:
ring
openssl
cargo build --features openssl --no-default-features
perl
(and perl-core
), and make
. For further options see the openssl crate documentation.Both cannot be enabled at the same time, thus on conflict sframe
issues a compiler error.
Depending on your use case, this library offers two distinct APIs.
This API provides an easy to use interface to the Sframe
implementation. The Sender
/ Receiver
:
Sframe
key(s)...
let key_id = 123;
let key_material = "pw123";
let skipped_payload = 1; // payload bytes which are skipped for encryption
let media_frame = b"SOME DATA";
let mut sender = Sender::new(key_id);
sender.set_encryption_key(key_material).unwrap();
let encrypted_frame = sender
.encrypt(media_frame, skipped_payload)
.unwrap();
let mut receiver = Receiver::default();
receiver
.set_encryption_key(key_id, key_material)
.unwrap();
let decrypted_frame = receiver.decrypt(encrypted_frame, skipped_payload).unwrap();
assert_eq!(media_frame, decrypted_frame);
For more options see the encrypt_decrypt example.
This API provides low-level access to encryption and decryption at the frame level, offering granular control. It allows the use of arbitrary buffers, enabling the creation of views to avoid unnecessary copies:
MediaFrameView
for unencrypted dataEncryptedFrameView
for encrypted dataFor encryption and decryption, a buffer must be provided implementing the FrameBuffer
trait to allocate the necessary memory. For convenience, this trait has already been implemented for Vec<u8>
.
For example:
...
let key_id = 42u64;
let enc_key = EncryptionKey::derive_from(CipherSuiteVariant::AesGcm256Sha512, key_id, "pw123").unwrap();
let dec_key = DecryptionKey::derive_from(CipherSuiteVariant::AesGcm256Sha512, key_id, "pw123").unwrap();
let frame_count = 1u8;
let payload = "Something secret";
let mut encrypt_buffer = Vec::new();
let mut decrypt_buffer = Vec::new();
let media_frame = MediaFrameView::new(frame_count, payload);
let encrypted_frame = media_frame.encrypt_into(&enc_key, &mut encrypt_buffer).unwrap();
let decrypted_media_frame = encrypted_frame
.decrypt_into(&mut dec_key, &mut decrypt_buffer)
.unwrap();
assert_eq!(decrypted_media_frame, media_frame);
MediaFrame
for unencrypted dataEncryptedFrame
for encrypted dataTo see how the API is used with another buffer type, you can check out the bip_frame_buffer example.
The criterion
benchmarks located at ./benches currently test
They are tracked continously with a Bencher Perf Page:
Any help in form of descriptive and friendly issues or comprehensive pull requests are welcome!
The Changelog of this library is generated from its commit log, there any commit message must conform with https://www.conventionalcommits.org/en/v1.0.0/. For simplicity you could make your commits with convco.