Skip to content

Question regarding random raw hash #509

@cisoun

Description

@cisoun

Hello,

I'm testing this package against the node implementation. I don't quite understand how this one works.
For instance this code:

const argon2 = require('argon2');
const crypto = require('node:crypto');
const { Buffer } = require('buffer');

const pw = 'mygreatpassword123';
const salt = Buffer.from('mygreatstupidsalt');

async function main () {

	// argon2

	try {
		const hash = await argon2.hash(pw, {
			type: argon2.argon2id,
			memoryCost: 2 ** 16,
			timeCost: 3,
			hashLength: 64,
			secret: salt,
			parallelism: 4,
			raw: true
		});
		console.log(`argon2: ${hash.toString('hex')}`);
	} catch (err) {
		console.error(err);
	}

	// node

	const hash = crypto.argon2('argon2id', {
		message: pw,
		memory: 2 ** 16,
		passes: 3,
		tagLength: 64,
		nonce: salt,
		parallelism: 4,
	}, (err, derivedKey) => {
		if (!err) {
			console.log(`node:   ${derivedKey.toString('hex')}`);
		} else {
			console.error(err);
		}
	});

}

main();

Results:

➜  argon2 node test.js
argon2: 3f04a297601a0c0395fc58c7fa435ba1d98ee7113ee6f805b0354856aa3a3e6ab4baa3c5bb4dbbf47a48834d3ebb279896bc8299f4863e75f6d2aa8b20c1441a
node:   ce3713cf69f7c52d64a78884ad21c8efadf9aa0350142d3dc98ab93ea39f0d4f291c3c5ee012302e4b329c8b3686d5a315771d1a381bbf943c46b768990f1d95
➜  argon2 node test.js
argon2: d7ce6d47d9a1d539b64ec34bc2388d84cc7de821595ca8d486c0a67ba695eb6ab04c08d47fd0652725178b2f6fa25b52e296d88f9c357c7706450222bc30d22e
node:   ce3713cf69f7c52d64a78884ad21c8efadf9aa0350142d3dc98ab93ea39f0d4f291c3c5ee012302e4b329c8b3686d5a315771d1a381bbf943c46b768990f1d95
➜  argon2 node test.js
argon2: 72239b38e28f7b6957eae47db84a699356497a16228438cff000474517d233ddba74d231c457ccb3d1d17200af1f554fadb16ba5e186ae771884eab1e38c8e64
node:   ce3713cf69f7c52d64a78884ad21c8efadf9aa0350142d3dc98ab93ea39f0d4f291c3c5ee012302e4b329c8b3686d5a315771d1a381bbf943c46b768990f1d95

Why the raw hash is always random while the derived key from node is always the same?

Please excuse me if I don't understand the algorithm correctly. I've tested the same parameters on https://argon2.online/ and it provided the same results as node over and over while the ones from this module always change.

Is the raw hash different than the derived key of node?

Thanks for your help and your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions