further benchmarking stuff
This commit is contained in:
@@ -2,7 +2,7 @@ import { UUID } from "uuidv7";
|
||||
|
||||
export enum ChallengeAlgorithm {
|
||||
SHA256 = "sha256",
|
||||
Argon2id = "argon2id",
|
||||
Argon2 = "argon2",
|
||||
kCTF = "kctf",
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export function algorithmToInt(algorithm: ChallengeAlgorithm): number {
|
||||
switch (algorithm) {
|
||||
case ChallengeAlgorithm.SHA256:
|
||||
return 0;
|
||||
case ChallengeAlgorithm.Argon2id:
|
||||
case ChallengeAlgorithm.Argon2:
|
||||
return 1;
|
||||
case ChallengeAlgorithm.kCTF:
|
||||
return 2;
|
||||
@@ -37,7 +37,7 @@ export function strategyToInt(strategy: ChallengeStrategy): number {
|
||||
// In this case, the client will repeatedly hash a number with has until it
|
||||
// finds a hash thaat starts with *difficulty* leading zeroes
|
||||
export interface ChallengeLeadingZeroes {
|
||||
algorithm: ChallengeAlgorithm.SHA256 | ChallengeAlgorithm.Argon2id;
|
||||
algorithm: ChallengeAlgorithm.SHA256 | ChallengeAlgorithm.Argon2;
|
||||
strategy: ChallengeStrategy.LeadingZeroes;
|
||||
salt: string; // random string
|
||||
difficulty: number;
|
||||
@@ -46,7 +46,7 @@ export interface ChallengeLeadingZeroes {
|
||||
// In this case, the server generates a random number, and the client will hash
|
||||
// the salt (a random string) + a random number until it finds a hash that is equal to challenge
|
||||
export interface ChallengeTargetNumber {
|
||||
algorithm: ChallengeAlgorithm.SHA256 | ChallengeAlgorithm.Argon2id;
|
||||
algorithm: ChallengeAlgorithm.SHA256 | ChallengeAlgorithm.Argon2;
|
||||
strategy: ChallengeStrategy.TargetNumber;
|
||||
salt: string; // random string
|
||||
target: string; // hash of salt + random number
|
||||
|
||||
@@ -31,14 +31,14 @@ export async function init_solver(env: SolverEnv, module: WebAssembly.Module): P
|
||||
}
|
||||
|
||||
type Argon2LeadingZeroesParams = {
|
||||
name: ChallengeAlgorithm.Argon2id;
|
||||
name: ChallengeAlgorithm.Argon2;
|
||||
strategy: ChallengeStrategy.LeadingZeroes;
|
||||
salt: string;
|
||||
difficulty: number;
|
||||
};
|
||||
|
||||
type Argon2TargetNumberParams = {
|
||||
name: ChallengeAlgorithm.Argon2id;
|
||||
name: ChallengeAlgorithm.Argon2;
|
||||
strategy: ChallengeStrategy.TargetNumber;
|
||||
salt: string;
|
||||
target: string;
|
||||
@@ -90,7 +90,7 @@ export function solve(solver: SolverModule, algorithm: SolveParams): string | nu
|
||||
let ret: string | number;
|
||||
switch (algorithm.name) {
|
||||
case ChallengeAlgorithm.SHA256:
|
||||
case ChallengeAlgorithm.Argon2id:
|
||||
case ChallengeAlgorithm.Argon2:
|
||||
switch (algorithm.strategy) {
|
||||
case ChallengeStrategy.LeadingZeroes: {
|
||||
ret = solver.exports.solve(algorithmToInt(algorithm.name), strategyToInt(ChallengeStrategy.LeadingZeroes), salt_ptr, salt_buf.length, algorithm.difficulty, 0, 0);
|
||||
|
||||
@@ -31,7 +31,7 @@ export interface SHA256ChallengeConfig {
|
||||
}
|
||||
|
||||
export interface Argon2ChallengeConfig {
|
||||
algorithm: ChallengeAlgorithm.Argon2id;
|
||||
algorithm: ChallengeAlgorithm.Argon2;
|
||||
strategy: ChallengeStrategy.LeadingZeroes | ChallengeStrategy.TargetNumber;
|
||||
difficulty: number;
|
||||
parameters: Object;
|
||||
@@ -69,8 +69,8 @@ async function encode_challenge(inner_challenge: InnerChallenge, parameters: Obj
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ChallengeAlgorithm.Argon2id: {
|
||||
challenge.algorithm = ChallengeAlgorithm.Argon2id;
|
||||
case ChallengeAlgorithm.Argon2: {
|
||||
challenge.algorithm = ChallengeAlgorithm.Argon2;
|
||||
challenge.salt = inner_challenge.salt;
|
||||
switch (inner_challenge.strategy) {
|
||||
case ChallengeStrategy.LeadingZeroes: {
|
||||
@@ -130,7 +130,7 @@ export async function generate_challenge(config: ChallengeConfig): Promise<Chall
|
||||
let parameters_str: string;
|
||||
switch (config.algorithm) {
|
||||
case ChallengeAlgorithm.SHA256:
|
||||
case ChallengeAlgorithm.Argon2id:
|
||||
case ChallengeAlgorithm.Argon2:
|
||||
switch (config.strategy) {
|
||||
case ChallengeStrategy.LeadingZeroes:
|
||||
if (config.difficulty < 1 || config.difficulty > 64) {
|
||||
@@ -235,7 +235,7 @@ export async function validate_challenge(challenge: Challenge, challenge_solutio
|
||||
switch (challenge.algorithm) {
|
||||
case ChallengeAlgorithm.SHA256:
|
||||
if (typeof challenge_solution === "string") {
|
||||
throw new Error("Argon2id challenges do not support a solution as a number");
|
||||
throw new Error("Argon2 challenges do not support a solution as a number");
|
||||
}
|
||||
|
||||
switch (challenge.strategy) {
|
||||
@@ -254,9 +254,9 @@ export async function validate_challenge(challenge: Challenge, challenge_solutio
|
||||
|
||||
return validator.exports.validate(algorithmToInt(challenge.algorithm), strategyToInt(challenge.strategy), challenge_ptr, challenge_buf.length, solution_ptr, solution_buf.length, challenge_solution, 0);
|
||||
}
|
||||
case ChallengeAlgorithm.Argon2id:
|
||||
case ChallengeAlgorithm.Argon2:
|
||||
if (typeof challenge_solution === "string") {
|
||||
throw new Error("Argon2id challenges do not support a solution as a number");
|
||||
throw new Error("Argon2 challenges do not support a solution as a number");
|
||||
}
|
||||
|
||||
switch (challenge.strategy) {
|
||||
|
||||
Reference in New Issue
Block a user