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 13 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
47 changes: 40 additions & 7 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ yew-notifications = { git = "https://github.com/TheBestTvarynka/yew-notification
# wasm
js-sys = "0.3.60"
wasm-bindgen = "0.2.83"
web-sys = { version = "0.3.60", features = ["Window"] }
web-sys = { version = "0.3.60", features = ["Window", "Event", "EventTarget"] }

# logging
wasm-logger = "0.2.0"
Expand Down 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"
15 changes: 9 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,26 @@ 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`
* `Argon2`
* `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 +58,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
4 changes: 4 additions & 0 deletions src/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ pub fn about() -> Html {
<span>{"Crypto-helper"}</span>
<span>{"The crypto-helper is an online app that helps to work with the diferent crypto algorithms:"}</span>
<ul>
<li>{"Argon2"}</li>
<li>{"BCrypt"}</li>
<li>{"MD5"}</li>
<li>{"Argon2"}</li>
<li>{"BCRYPT"}</li>
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
<li>{"SHA1/SHA256/SHA384/SHA512"}</li>
<li>{"Kerberos ciphers: AES128-CTS-HMAC-SHA1-96/AES256-CTS-HMAC-SHA1-96"}</li>
<li>{"Kerberos HMAC: HMAC-SHA1-96-AES128/HMAC-SHA1-96-AES256"}</li>
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
147 changes: 145 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 @@ -361,6 +363,143 @@ pub struct ZlibInput {
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
pub data: Vec<u8>,
}
#[derive(Eq, Clone, Copy, PartialEq, Debug, Serialize, Deserialize, Default)]
pub enum Argon2Variant {
Argon2i,
Argon2d,
#[default]
Argon2id,
}
#[derive(Eq, Clone, Copy, PartialEq, Debug, Serialize, Deserialize, Default)]
pub enum Argon2Version {
Jujumba marked this conversation as resolved.
Show resolved Hide resolved
Version10,
#[default]
Version13,
}
#[derive(Eq, Clone, PartialEq, Debug, Serialize, Deserialize)]
pub struct Argon2HashAction {
pub memory: u32,
pub iters: u32,
pub paralelism: u32,
pub output_len: usize,
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
pub salt: Vec<u8>,
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
pub data: Vec<u8>,
#[serde(serialize_with = "serialize_bytes", deserialize_with = "deserialize_bytes")]
pub secret: Vec<u8>,
pub variant: Argon2Variant,
pub version: Argon2Version,
}

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

impl Argon2Input {
pub fn set_variant(&self, variant: Argon2Variant) -> Self {
let mut input = self.clone();
if let Argon2Action::Hash(ref mut action) = input.action {
action.variant = variant;
}
input
}
pub fn set_version(&self, version: Argon2Version) -> Self {
Jujumba marked this conversation as resolved.
Show resolved Hide resolved
Jujumba marked this conversation as resolved.
Show resolved Hide resolved
let mut input = self.clone();
if let Argon2Action::Hash(ref mut action) = input.action {
action.version = version;
}
input
}
}
impl<'a> TryFrom<&'a str> for Argon2Version {
type Error = (); // todo: proper error type
Jujumba marked this conversation as resolved.
Show resolved Hide resolved

fn try_from(value: &'a str) -> Result<Self, Self::Error> {
match value {
"Argon13" => Ok(Self::Version13),
"Argon10" => Ok(Self::Version10),
_ => Err(()),
}
}
}
impl From<Argon2Variant> for argon2::Algorithm {
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
fn from(value: Argon2Variant) -> Self {
match value {
Argon2Variant::Argon2d => argon2::Algorithm::Argon2d,
Argon2Variant::Argon2i => argon2::Algorithm::Argon2i,
Argon2Variant::Argon2id => argon2::Algorithm::Argon2id,
}
}
}

impl From<Argon2Version> for argon2::Version {
fn from(value: Argon2Version) -> Self {
match value {
Argon2Version::Version10 => argon2::Version::V0x10,
Argon2Version::Version13 => argon2::Version::V0x13,
}
}
}

impl From<&Argon2HashAction> for argon2::Params {
fn from(value: &Argon2HashAction) -> Self {
argon2::ParamsBuilder::new()
.m_cost(value.memory)
.p_cost(value.paralelism)
.t_cost(value.iters)
.build()
.unwrap()
TheBestTvarynka marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl Default for Argon2HashAction {
fn default() -> Self {
Self {
memory: 19456u32,
iters: 2u32,
paralelism: 1u32,
output_len: 32usize,
salt: Default::default(),
data: Default::default(),
secret: Default::default(),
variant: Default::default(),
version: Default::default(),
}
}
}

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

impl From<bool> for Argon2Action {
fn from(value: bool) -> Self {
match value {
true => Argon2Action::Verify(Default::default()),
false => Argon2Action::Hash(Default::default()),
}
}
}

impl From<&Argon2Action> for bool {
fn from(value: &Argon2Action) -> Self {
match value {
Argon2Action::Verify(_) => true,
Argon2Action::Hash(_) => false,
}
}
}

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

impl TryFrom<&str> for Algorithm {
Expand Down Expand Up @@ -412,6 +552,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 +578,7 @@ impl From<&Algorithm> for &str {
Algorithm::Rsa(_) => RSA,
Algorithm::Bcrypt(_) => BCRYPT,
Algorithm::Zlib(_) => ZLIB,
Algorithm::Argon2(_) => ARGON2,
}
}
}
Expand Down
Loading