Skip to content

Instantly share code, notes, and snippets.

View firaja's full-sized avatar
💭
Do or do not. There is no try.

David Bertoldi firaja

💭
Do or do not. There is no try.
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <mpi.h>
#include "config.h"
#define ROOT 0
void showDistances(int matrix[], int n);
void populateMatrix(int matrix[], int n, int density, int rank, int processes);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "config.h"
void showDistances(int matrix[], int n);
void populateMatrix(int* matrix, int n, int density);
void floydWarshall(int* matrix, int n);
int main(int argc, char** argv)
@firaja
firaja / benchmark.java
Created October 6, 2022 09:49
Password4j - determine bcrypt parameters
int minimumTime = 1500;
BenchmarkResult<BcryptFunction> benchmark = SystemChecker.benchmarkBcrypt(minimumTime);
benchmark.getElapsed(); // 929ms
benchmark.getPrototype(); // BcryptFunction object with 14 rounds
@firaja
firaja / update-bcrypt-to-argon2.java
Created October 6, 2022 09:38
Password4j - migrate from bcrypt to Argon2
String userPassword = "my password";
String oldHash = "$2y$06$pWbj0v7UGWgOp1mXWfCt1OUAibk5luL758NoVndquXnXfH79zFTRG";
BcryptFunction bcrypt = BcryptFunction.getInstanceFromHash(oldHash);
Argon2Function argon2 = Argon2Function.getInstance(14, 20, 1, 32, Argon2.ID);
HashUpdate update = Password.check(userPassword, oldHash)
.andUpdate()
.with(bcrypt, argon2);
@firaja
firaja / verify-argon2-implicit.java
Created October 6, 2022 09:26
Password4j - verify Argon2 hash without specifying parameters
String hash = "$argon2id$v=19$m=14,t=20,p=1$cHJpdmF0ZS1zYWx0$mxKlVBKpr3lNXHdaBKnuvjl/IsESYkYPCFAsb7VaIGs";
Argon2Function argon2 = Argon2Function.getInstanceFromHash(hash);
boolean verified = Password.check("my password", hash)
.addPepper("shared-secret")
.with(argon2);
// true
@firaja
firaja / verify-argon2.java
Created October 6, 2022 09:24
Password4j - Verify Argon2 hash
Argon2Function argon2 = Argon2Function.getInstance(14, 20, 1, 32, Argon2.ID);
boolean verified = Password.check("my password", "$argon2id$v=19$m=14,t=20,p=1$cHJpdmF0ZS1zYWx0$mxKlVBKpr3lNXHdaBKnuvjl/IsESYkYPCFAsb7VaIGs")
.addPepper("shared-secret")
.with(argon2);
// true
@firaja
firaja / hash-argon2.java
Last active October 6, 2022 09:37
Password4j - Hash password with Argon2
Argon2Function argon2 = Argon2Function.getInstance(14, 20, 1, 32, Argon2.ID);
Hash hash = Password.hash("my password")
.addPepper("shared-secret")
.addSalt("private-salt")
.with(argon2);
hash.getResult(); // $argon2id$v=19$m=14,t=20,p=1$cHJpdmF0ZS1zYWx0$mxKlVBKpr3lNXHdaBKnuvjl/IsESYkYPCFAsb7VaIGs
@firaja
firaja / verify-scrypt-implicit.java
Last active October 6, 2022 11:50
Password4j - Verify scrypt hash without specifying parameters
String hash = "$100801$cHJpdmF0ZS1zYWx0$ibAGantBIzk0Zcpl11VLaywBOdVA4mgrwTkIxWbNYBsIDROtTIMGULxMS9AJj7MOs74D/fQk6WtodZ1115i5wg==";
ScryptFunction scrypt = ScryptFunction.getInstanceFromHash(hash);
boolean verified = Password.check("my password", hash)
.addPepper("shared-secret")
.with(scrypt);
// true
@firaja
firaja / verify-scrypt.java
Last active October 6, 2022 11:51
Password4j - Verify scrypt hash
ScryptFunction scrypt = ScryptFunction.getInstance(1<<16, 8, 1);
boolean verified = Password.check("my password", "$100801$cHJpdmF0ZS1zYWx0$ibAGantBIzk0Zcpl11VLaywBOdVA4mgrwTkIxWbNYBsIDROtTIMGULxMS9AJj7MOs74D/fQk6WtodZ1115i5wg==")
.addPepper("shared-secret")
.with(scrypt);
// true
@firaja
firaja / hash-scrypt.java
Last active October 6, 2022 11:51
Password4j - Hash password with scrypt
ScryptFunction scrypt = ScryptFunction.getInstance(32768, 8, 1);
Hash hash = Password.hash("my password")
.addPepper("shared-secret")
.addSalt("private-salt")
.with(scrypt);
hash.getResult(); //$f0801$cHJpdmF0ZS1zYWx0$zrgVuAP6ndmAOZpA/FI3LpRWYjl0f+9gxHlNIGzTbJ9+ER41i6zwkorvTc0GO4WgSe6FBxrHbLEiw5P9ev4q2w==