Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pickling logic to pk_encryption #173

Closed
wants to merge 15 commits into from
Closed
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- uses: Swatinem/rust-cache@v2

- name: Clippy
run: cargo clippy --all-targets -- -D warnings
run: cargo clippy --all-targets --all-features -- -D warnings

test:
name: ${{ matrix.target.name }} ${{ matrix.channel }}
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ default = ["libolm-compat"]
js = ["getrandom/js"]
strict-signatures = []
libolm-compat = []
insecure-pk-encryption = []
# The low-level-api feature exposes extra APIs that are only useful in advanced
# use cases and require extra care to use.
low-level-api = []
Expand Down
8 changes: 4 additions & 4 deletions src/cipher/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Aes256Iv = GenericArray<u8, <Aes256CbcEnc as IvSizeUser>::IvSize>;
type HmacSha256Key = [u8; 32];

#[derive(Zeroize, ZeroizeOnDrop)]
struct ExpandedKeys(Box<[u8; 80]>);
pub(crate) struct ExpandedKeys(Box<[u8; 80]>);

impl ExpandedKeys {
const OLM_HKDF_INFO: &'static [u8] = b"OLM_KEYS";
Expand All @@ -47,7 +47,7 @@ impl ExpandedKeys {
Self::new_helper(pickle_key, b"Pickle")
}

fn new_helper(message_key: &[u8], info: &[u8]) -> Self {
pub(crate) fn new_helper(message_key: &[u8], info: &[u8]) -> Self {
let mut expanded_keys = [0u8; 80];

let hkdf: Hkdf<Sha256> = Hkdf::new(Some(&[0]), message_key);
Expand All @@ -59,7 +59,7 @@ impl ExpandedKeys {
}

#[derive(Zeroize, ZeroizeOnDrop)]
pub(super) struct CipherKeys {
pub(crate) struct CipherKeys {
aes_key: Box<[u8; 32]>,
aes_iv: Box<[u8; 16]>,
mac_key: Box<[u8; 32]>,
Expand All @@ -85,7 +85,7 @@ impl CipherKeys {
Self::from_expanded_keys(expanded_keys)
}

fn from_expanded_keys(expanded_keys: ExpandedKeys) -> Self {
pub(crate) fn from_expanded_keys(expanded_keys: ExpandedKeys) -> Self {
let mut aes_key = Box::new([0u8; 32]);
let mut mac_key = Box::new([0u8; 32]);
let mut aes_iv = Box::new([0u8; 16]);
Expand Down
8 changes: 4 additions & 4 deletions src/cipher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod key;
pub(crate) mod key;

use aes::{
cipher::{
Expand All @@ -27,9 +27,9 @@ use key::CipherKeys;
use sha2::Sha256;
use thiserror::Error;

type Aes256CbcEnc = cbc::Encryptor<Aes256>;
type Aes256CbcDec = cbc::Decryptor<Aes256>;
type HmacSha256 = Hmac<Sha256>;
pub(crate) type Aes256CbcEnc = cbc::Encryptor<Aes256>;
pub(crate) type Aes256CbcDec = cbc::Decryptor<Aes256>;
pub(crate) type HmacSha256 = Hmac<Sha256>;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Mac(pub(crate) [u8; Self::LENGTH]);
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ pub mod ecies;
pub mod hazmat;
pub mod megolm;
pub mod olm;
#[cfg(feature = "insecure-pk-encryption")]
pub mod pk_encryption;
pub mod sas;

pub use base64::DecodeError as Base64DecodeError;
Expand Down
2 changes: 1 addition & 1 deletion src/olm/messages/pre_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl PreKeyMessage {

/// Create a new pre-key message from the session keys and standard message.
#[cfg(feature = "low-level-api")]
pub fn wrap(session_keys: SessionKeys, message: Message) -> Self {
pub const fn wrap(session_keys: SessionKeys, message: Message) -> Self {
PreKeyMessage::new(session_keys, message)
}

Expand Down
4 changes: 2 additions & 2 deletions src/olm/session/message_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ impl MessageKey {

/// Get the message key's ratchet key.
#[cfg(feature = "low-level-api")]
pub fn ratchet_key(&self) -> RatchetPublicKey {
pub const fn ratchet_key(&self) -> RatchetPublicKey {
self.ratchet_key
}

/// Get the message key's index.
#[cfg(feature = "low-level-api")]
pub fn index(&self) -> u64 {
pub const fn index(&self) -> u64 {
self.index
}
}
Expand Down
Loading