Coder Social home page Coder Social logo

Comments (5)

decentralgabe avatar decentralgabe commented on September 27, 2024 1

Thanks @bwesterb I'll close this issue. I did not notice that you're in compliance with existing test vectors.

from circl.

decentralgabe avatar decentralgabe commented on September 27, 2024

To throw another wrench into the mix I've also tried verifying signatures generated from this java implementation which appears on the official Dilithium site.

The code this snippet outputs could not be verified by either this library or the JS one 😕 .

	public void vectors() throws Exception {
		DilithiumProvider pv = new DilithiumProvider();
		KeyPairGenerator kpg = KeyPairGenerator.getInstance("Dilithium", pv);
		kpg.initialize(DilithiumParameterSpec.LEVEL5);
		KeyPair kp = kpg.generateKeyPair();

		Signature signature = Signature.getInstance("Dilithium", pv);
		signature.initSign(kp.getPrivate());
		byte[] text = new byte[]{0,1,2,3,4,5};
		signature.update(text);
		byte[] sig = signature.sign();

		// Check we can verify with the correct public key
		signature.initVerify(kp.getPublic());
		signature.update(text);
		assertTrue(signature.verify(sig));

		System.out.printf("Public Key: %s\n", bytesToHex(kp.getPublic().getEncoded()));
		System.out.printf("Signature: %s", bytesToHex(sig));
	}
	
	public static String bytesToHex(byte[] bytes) {
		StringBuilder hex = new StringBuilder();
		for (byte b : bytes) {
			hex.append(String.format("%02X", b));
		}
		return hex.toString();
	}

from circl.

bwesterb avatar bwesterb commented on September 27, 2024

Here is a clue: the signature generated by javascript is 4602 bytes, whereas the one generated by CIRCL is 4595 bytes. The Dilithium spec lists the correct signature size to be 4595. We check test vectors against the reference implementation.

from circl.

bwesterb avatar bwesterb commented on September 27, 2024

Looking at the source code of the JS package you are using:

long dilithiumjs_sign (
	uint8_t *sig,
	const uint8_t *m,
	unsigned long mlen,
	const uint8_t *sk
) {
	size_t siglen;

	int status	= PQCLEAN_DILITHIUM5_CLEAN_crypto_sign_signature(
		sig + sizeof(unsigned short),
		&siglen,
		m,
		mlen,
		sk
	);

	if (status == 0) {
		*((unsigned short*) sig)	= (unsigned short) siglen;
	}

	return status;
}

long dilithiumjs_verify (
	const uint8_t *m,
	unsigned long mlen,
	const uint8_t *sig,
	const uint8_t *pk
) {
	size_t siglen	= (size_t) *((unsigned short*) sig);

	return PQCLEAN_DILITHIUM5_CLEAN_crypto_sign_verify(
		sig + sizeof(unsigned short),
		siglen,
		m,
		mlen,
		pk
	);
}

I would not use that package.

from circl.

armfazh avatar armfazh commented on September 27, 2024

maybe this is something to raise to the back-end library to check whether that implementation is compliant with the latest test vectors.

from circl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.