Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Add some RSA PSS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Lippai committed Jun 27, 2018
1 parent 0c90d3a commit 1da3d88
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ describe('RSA-PSS-SHA256', () => {
rsaPssVerify.verify(signature, asmCrypto.string_to_bytes(text));
});

it('asmCrypto.RSA_PSS_SHA256 sign/verify with non-default salt length', function() {
const text = 'HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!';
const rsaPssSign = new asmCrypto.RSA_PSS(privkey, new asmCrypto.Sha256(), 32);
const rsaPssVerify = new asmCrypto.RSA_PSS(pubKey, new asmCrypto.Sha256(), 32);

const signature = rsaPssSign.sign(asmCrypto.string_to_bytes(text));
rsaPssVerify.verify(signature, asmCrypto.string_to_bytes(text));
});

it('asmCrypto.RSA_PSS_SHA256 sign/verify with salt length mismatch', function() {
const text = 'HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!';
const rsaPssSign = new asmCrypto.RSA_PSS(privkey, new asmCrypto.Sha256(), 4);
const rsaPssVerify = new asmCrypto.RSA_PSS(pubKey, new asmCrypto.Sha256(), 32);

const signature = rsaPssSign.sign(asmCrypto.string_to_bytes(text));
expect(() => rsaPssVerify.verify(signature, asmCrypto.string_to_bytes(text))).to.throw;
});

it('asmCrypto.RSA_PSS_SHA512 sign/verify', function() {
const text = 'HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!';
const rsaPssSign = new asmCrypto.RSA_PSS(privkey, new asmCrypto.Sha512());
const rsaPssVerify = new asmCrypto.RSA_PSS(pubKey, new asmCrypto.Sha512());

const signature = rsaPssSign.sign(asmCrypto.string_to_bytes(text));
rsaPssVerify.verify(signature, asmCrypto.string_to_bytes(text));
});

// This requires a RSA2048 key instead of RSA1024
it.skip('asmCrypto.RSA_PSS_SHA512 sign/verify with non-default salt length', function() {
const text = 'HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!HelloWorld!';
const rsaPssSign = new asmCrypto.RSA_PSS(privkey, new asmCrypto.Sha512(), 64);
const rsaPssVerify = new asmCrypto.RSA_PSS(pubKey, new asmCrypto.Sha512(), 64);

const signature = rsaPssSign.sign(asmCrypto.string_to_bytes(text));
rsaPssVerify.verify(signature, asmCrypto.string_to_bytes(text));
});

it('asmCrypto.RSA_PSS_SHA256 verify OpenSSL-signed-data', function() {
const key = [
asmCrypto.hex_to_bytes(
Expand Down

0 comments on commit 1da3d88

Please sign in to comment.