Skip to content

Commit

Permalink
fixup! fixup! feat: Add an Elliptic Curve Encryption Scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed May 9, 2024
1 parent 044190c commit 4bdc765
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/ecies/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ use crate::Curve25519PublicKey;

mod messages;

const MATRIX_INFO_PREFIX: &str = "MATRIX_QR_CODE_LOGIN";
const MATRIX_QR_LOGIN_INFO_PREFIX: &str = "MATRIX_QR_CODE_LOGIN";

type ApplicationInfo = String;

fn get_check_code_info(info: &str) -> String {
format!("{info}_CHECKCODE")
}

fn get_encrytpion_key_g_info(info: &str) -> String {
fn get_encryption_key_g_info(info: &str) -> String {
format!("{info}_ENCKEY_G")
}

fn get_encrytpion_key_s_info(info: &str) -> String {
fn get_encryption_key_s_info(info: &str) -> String {
format!("{info}_ENCKEY_S")
}

Expand Down Expand Up @@ -229,11 +229,11 @@ impl Ecies {
/// Create a new, random, unestablished ECIES session.
///
/// This method will use the `MATRIX_QR_CODE_LOGIN` info. If you are using
/// this for a different purpose consider using the [`Ecies::with_info()`]
/// this for a different purpose, consider using the [`Ecies::with_info()`]
/// method.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self::with_info(MATRIX_INFO_PREFIX)
Self::with_info(MATRIX_QR_LOGIN_INFO_PREFIX)
}

/// Create a new, random, unestablished ECIES session with the given
Expand Down Expand Up @@ -432,10 +432,10 @@ impl EstablishedEcies {
) -> Box<[u8; 32]> {
let info = if initiator {
// we are Device G
get_encrytpion_key_g_info(info)
get_encryption_key_g_info(info)
} else {
// we are Device S
get_encrytpion_key_s_info(info)
get_encryption_key_s_info(info)
};

Self::create_key(&info, shared_secret, our_public_key, their_public_key, initiator)
Expand All @@ -450,10 +450,10 @@ impl EstablishedEcies {
) -> Box<[u8; 32]> {
let info = if initiator {
// we are Device G, they are Device S
get_encrytpion_key_s_info(info)
get_encryption_key_s_info(info)
} else {
// we are Device S, they are Device G
get_encrytpion_key_g_info(info)
get_encryption_key_g_info(info)
};

Self::create_key(&info, shared_secret, our_public_key, their_public_key, initiator)
Expand All @@ -463,7 +463,7 @@ impl EstablishedEcies {
shared_secret: &SharedSecret,
our_public_key: Curve25519PublicKey,
their_public_key: Curve25519PublicKey,
infos: ApplicationInfo,
info: ApplicationInfo,
initiator: bool,
) -> Self {
let (encryption_nonce, decryption_nonce) = (EciesNonce::new(), EciesNonce::new());
Expand All @@ -472,21 +472,21 @@ impl EstablishedEcies {
shared_secret,
our_public_key,
their_public_key,
&infos,
&info,
initiator,
);
let decryption_key = Self::create_decryption_key(
shared_secret,
our_public_key,
their_public_key,
&infos,
&info,
initiator,
);
let check_code = Self::create_check_code(
shared_secret,
our_public_key,
their_public_key,
&infos,
&info,
initiator,
);

Expand Down Expand Up @@ -664,13 +664,13 @@ mod test {

#[test]
fn info_expansion() {
let info = get_check_code_info(MATRIX_INFO_PREFIX);
let info = get_check_code_info(MATRIX_QR_LOGIN_INFO_PREFIX);
assert_eq!(info, "MATRIX_QR_CODE_LOGIN_CHECKCODE");

let info = get_encrytpion_key_g_info(MATRIX_INFO_PREFIX);
let info = get_encryption_key_g_info(MATRIX_QR_LOGIN_INFO_PREFIX);
assert_eq!(info, "MATRIX_QR_CODE_LOGIN_ENCKEY_G");

let info = get_encrytpion_key_s_info(MATRIX_INFO_PREFIX);
let info = get_encryption_key_s_info(MATRIX_QR_LOGIN_INFO_PREFIX);
assert_eq!(info, "MATRIX_QR_CODE_LOGIN_ENCKEY_S");
}

Expand Down

0 comments on commit 4bdc765

Please sign in to comment.