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

Argon2 implementation #47

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1e4ccd9
argon2: Initial commit
Jujumba Oct 2, 2023
837e14e
readme: fix readme
Jujumba Oct 8, 2023
ca27439
argon2: impl `From` trait for Argon2 structs
Jujumba Nov 27, 2023
7152730
argon2: add switch
Jujumba Nov 27, 2023
0c04e35
argon2: impl `process_argon2`
Jujumba Jan 4, 2024
5e9059f
argon2: fix serialization
Jujumba Jan 31, 2024
b4e9157
argon2: Add rfc link
Jujumba Jan 31, 2024
3effbce
argon2: enable `Event` and `EventTarget` features
Jujumba Jan 31, 2024
1a83ee9
argon2: input: add `set_version` closure
Jujumba Jan 31, 2024
f197374
argon2: fix `[u8]` to `String` conversion
Jujumba Jan 31, 2024
3ac3dff
argon2: fixes
Jujumba Jan 31, 2024
e84a4e9
info: Add `Argon2` and `Bcrypt`
Jujumba Feb 1, 2024
69a62e9
Cargo: fix `base64` version
Jujumba Feb 1, 2024
7f03323
argon2: generate random salt if empty one is supplied
Jujumba Feb 24, 2024
da93b07
argon2: fix random salt generation
Jujumba Feb 25, 2024
dcf518f
argon2: impl `TryFrom<&str>` for `Argon2Variant`
Jujumba Feb 25, 2024
44b6f1f
argon2: add salt input
Jujumba Feb 25, 2024
e29d309
argon2: remove duplicate entries in the about page
Jujumba Feb 27, 2024
6cf783a
argon2: remove extra `data` field
Jujumba Feb 27, 2024
e881b2f
argon2: fix random salt generation and base64 padding character
Jujumba Feb 27, 2024
37f1cee
argon2: fix salt encoding & decoding
Jujumba Feb 27, 2024
eec95a5
argon2: fix hash computation
Jujumba Mar 16, 2024
7b537f4
argon2: fix `Default` impl for `Argon2HashAction`
Jujumba Mar 16, 2024
9a011bf
argon2: fix error types
Jujumba Mar 22, 2024
4ed099f
argon2: fix
Jujumba Mar 23, 2024
7e806ba
argon2: add hash verification
Jujumba Mar 23, 2024
f69a926
argon2: fix dependencies versions
Jujumba Mar 26, 2024
2c88007
argon2: run formatter
Jujumba Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ rsa = "0.7.2"
yew-hooks = "0.2.0"
bcrypt = "0.14.0"
flate2 = { version = "1.0.26", features = ["zlib"] }
argon2 = "0.5.2"
14 changes: 8 additions & 6 deletions README.md
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ Visit this tool at [crypto.qkation.com](https://crypto.qkation.com).

Table of content:

* [Features](#features)
* [Development](#development)
* [Meta](#meta)
* [Contributing](#contributing)
- [crypto-helper](#crypto-helper)
- [Features](#features)
- [Development](#development)
- [Meta](#meta)
- [Contributing](#contributing)

![](/public/img/example.png)
![](/public/img/sha.png)
![](/public/img/jwt.png)

The crypto-helper is an online app that helps to work with the different crypto algorithms. This app can hash/hmac, encrypt/decrypt, and sign/verify the data.
The crypto-helper is a web app that helps to work with the different crypto algorithms. This app can hash/hmac, encrypt/decrypt, and sign/verify the data.

All computations are performed on the client side. This tool never sends the data to any server.

### Features

* Written in [Rust](https://github.com/rust-lang/rust) :crab: using [yew](https://github.com/yewstack/yew) :sparkles:
* `MD5`
* `BCRYPT`
* `SHA1`/`SHA256`/`SHA384`/`SHA512`
* Kerberos ciphers: `AES128-CTS-HMAC-SHA1-96`/`AES256-CTS-HMAC-SHA1-96`
* Kerberos HMAC: `HMAC-SHA1-96-AES128`/`HMAC-SHA1-96-AES256`
Expand Down Expand Up @@ -55,7 +57,7 @@ export APP_HOST=<url>
# example:
# export APP_HOST=https://crypto-helper.qkation.com
```
This env variable is uses for the url generation when you click the *share by url* button.
This env variable is used for the url generation when you click the *share by url* button.

3. Run `trunk serve` in your terminal.
4. Go to http://127.0.0.1:8080 in your browser.
Expand Down
3 changes: 2 additions & 1 deletion src/crypto_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use yew::{function_component, html, use_effect_with_deps, use_state, Callback, H
use yew_hooks::{use_clipboard, use_location};
use yew_notifications::{use_notification, Notification, NotificationType};

use self::computations::{process_krb_cipher, process_krb_hmac, process_rsa, process_zlib};
use self::computations::{process_krb_cipher, process_krb_hmac, process_rsa, process_zlib, process_argon2};
use crate::crypto_helper::computations::process_bcrypt;
use crate::url_query_params::generate_crypto_helper_link;

Expand All @@ -39,6 +39,7 @@ fn convert(algrithm: &Algorithm) -> Result<Vec<u8>, String> {
Algorithm::Rsa(input) => process_rsa(input),
Algorithm::Bcrypt(input) => process_bcrypt(input),
Algorithm::Zlib(input) => process_zlib(input),
Algorithm::Argon2(input) => process_argon2(input),
}
}

Expand Down
65 changes: 63 additions & 2 deletions src/crypto_helper/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ pub const RSA: &str = "RSA";
pub const SHA384: &str = "SHA384";
pub const BCRYPT: &str = "BCRYPT";
pub const ZLIB: &str = "ZLIB";
pub const ARGON2: &str = "ARGON2";

pub const SUPPORTED_ALGORITHMS: [&str; 12] = [
pub const SUPPORTED_ALGORITHMS: [&str; 13] = [
MD5,
SHA1,
SHA256,
Expand All @@ -32,9 +33,10 @@ pub const SUPPORTED_ALGORITHMS: [&str; 12] = [
SHA384,
BCRYPT,
ZLIB,
ARGON2,
];

pub const HASHING_ALGOS: [&str; 6] = [MD5, SHA1, SHA256, SHA384, SHA512, BCRYPT];
pub const HASHING_ALGOS: [&str; 7] = [MD5, SHA1, SHA256, SHA384, SHA512, BCRYPT, ARGON2];

pub const ENCRYPTION_ALGOS: [&str; 3] = [AES128_CTS_HMAC_SHA1_96, AES256_CTS_HMAC_SHA1_96, RSA];

Expand Down Expand Up @@ -362,6 +364,61 @@ pub struct ZlibInput {
pub data: Vec<u8>,
}

#[derive(Eq, Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct Argon2HashAction {
memory: u32,
iters: u32,
paralelism: u32,
output_len: u32,
}

#[derive(Eq, Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum Argon2Action {
Hash(Argon2HashAction),
Verify(Vec<u8>),
}
#[derive(Eq, Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct Argon2Input {
pub action: Argon2Action,
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
pub data: Vec<u8>,
}

impl From<argon2::Params> for Argon2HashAction {
fn from(value: argon2::Params) -> Self {
let params = argon2::Params::DEFAULT;
Self {
memory: params.m_cost(),
iters: params.t_cost(),
paralelism: params.p_cost(),
output_len: 32
}
}
}

impl Default for Argon2HashAction {
fn default() -> Self {
argon2::Params::DEFAULT.into()
}
}

impl Default for Argon2Action {
fn default() -> Self {
Self::Hash(Argon2HashAction::default())
}
}
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved

impl Default for Argon2Input {
fn default() -> Self {
Self {
action: Argon2Action::default(),
data: Vec::new()
}
}
}



#[allow(clippy::large_enum_variant)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum Algorithm {
Expand All @@ -382,6 +439,7 @@ pub enum Algorithm {
Rsa(RsaInput),
Bcrypt(BcryptInput),
Zlib(ZlibInput),
Argon2(Argon2Input),
}

impl TryFrom<&str> for Algorithm {
Expand Down Expand Up @@ -412,6 +470,8 @@ impl TryFrom<&str> for Algorithm {
return Ok(Algorithm::Bcrypt(Default::default()));
} else if value == ZLIB {
return Ok(Algorithm::Zlib(Default::default()));
} else if value == ARGON2 {
return Ok(Algorithm::Argon2(Default::default()));
}

Err(format!(
Expand All @@ -436,6 +496,7 @@ impl From<&Algorithm> for &str {
Algorithm::Rsa(_) => RSA,
Algorithm::Bcrypt(_) => BCRYPT,
Algorithm::Zlib(_) => ZLIB,
Algorithm::Argon2(_) => ARGON2,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/crypto_helper/computations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rand_chacha::ChaCha8Rng;
use rsa::{PaddingScheme, PublicKey as PublicKeyTrait};

use super::algorithm::{
BcryptAction, BcryptInput, KrbInput, KrbInputData, KrbMode, RsaAction, RsaInput, ZlibInput, ZlibMode,
BcryptAction, BcryptInput, KrbInput, KrbInputData, KrbMode, RsaAction, RsaInput, ZlibInput, ZlibMode, Argon2Input, Argon2Action,
};

pub fn process_rsa(input: &RsaInput) -> Result<Vec<u8>, String> {
Expand Down Expand Up @@ -92,3 +92,7 @@ pub fn process_zlib(input: &ZlibInput) -> Result<Vec<u8>, String> {
}
}
}

pub fn process_argon2(input: &Argon2Input) -> Result<Vec<u8>, String> {
todo!()
}
3 changes: 3 additions & 0 deletions src/crypto_helper/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ fn get_algorithm_info(algorithm: &Algorithm) -> Html {
<a href="https://www.rfc-editor.org/rfc/rfc1950">{"RFC"}</a>
</span>
},
Algorithm::Argon2(_) => html! {
<span>{"Use Argon2 to encrypt/verify your data."}</span>
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
},
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/crypto_helper/input.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod argon2;
mod bcrypt;
mod krb;
mod rsa;
Expand All @@ -6,6 +7,7 @@ mod zlib;
use picky_krb::crypto::CipherSuite;
use yew::{function_component, html, Callback, Html, Properties, UseStateSetter};

use self::argon2::build_argon2_input;
use self::bcrypt::build_bcrypt_input;
use self::krb::build_krb_input;
use self::rsa::build_rsa_input;
Expand Down Expand Up @@ -93,6 +95,10 @@ fn get_input_components(algorithm: &Algorithm, setter: &UseStateSetter<Algorithm
input.clone(),
Callback::from(move |input| setter.set(Algorithm::Zlib(input))),
),
Algorithm::Argon2(input) => build_argon2_input(
input.clone(),
Callback::from(move |input| setter.set(Algorithm::Argon2(input))),
),
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/crypto_helper/input/argon2.rs
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use web_sys::HtmlInputElement;
use yew::{classes, function_component, html, Callback, Html, Properties, TargetCast};
use yew_notifications::{use_notification, Notification, NotificationType};

use crate::{crypto_helper::algorithm::Argon2Input as Argon2InputData, common::{build_byte_input, BytesFormat}};

#[derive(PartialEq, Properties, Clone)]
pub struct Argon2InputProps {
pub input: Argon2InputData,
pub argon2_input_setter: Callback<Argon2InputData>,
}

#[function_component(Argon2Input)]
pub fn argon2_input(props: &Argon2InputProps) -> Html {
let data = props.input.data.clone();
let input_setter = props.argon2_input_setter.clone();
let action = props.input.action.clone();
let setter = Callback::from(move |data| {
input_setter.emit(Argon2InputData {
action: action.clone(),
data,
})
});
html! {
<div class={classes!("wide-input", "vertical")}>
{build_byte_input(data, setter, Some(BytesFormat::Ascii), Some("argon2".into()))}
Jujumba marked this conversation as resolved.
Show resolved Hide resolved
</div>
}
}

pub fn build_argon2_input(input: Argon2InputData, setter: Callback<Argon2InputData>) -> Html {
html! {
<Argon2Input input={input} argon2_input_setter={setter}/>
}
}
1 change: 1 addition & 0 deletions src/crypto_helper/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn get_output_components(algorithm: &Algorithm, output: &[u8], add_notification:
add_notification,
),
Algorithm::Zlib(_) => build_simple_output(output.into(), BytesFormat::Hex, add_notification),
Algorithm::Argon2(_) => build_simple_output(output.into(), BytesFormat::Hex, add_notification),
}
}

Expand Down
Loading