({ name,
context,
publicKeyPem,
privateKeyPem,
signature,
data })
| 17 | const vectors = require('../fixtures/crypto/ml-dsa')(); |
| 18 | |
| 19 | async function testVerify({ name, |
| 20 | context, |
| 21 | publicKeyPem, |
| 22 | privateKeyPem, |
| 23 | signature, |
| 24 | data }) { |
| 25 | const [ |
| 26 | publicKey, |
| 27 | noVerifyPublicKey, |
| 28 | privateKey, |
| 29 | hmacKey, |
| 30 | rsaKeys, |
| 31 | ecKeys, |
| 32 | ] = await Promise.all([ |
| 33 | crypto.createPublicKey(publicKeyPem) |
| 34 | .toCryptoKey(name, false, ['verify']), |
| 35 | crypto.createPublicKey(publicKeyPem) |
| 36 | .toCryptoKey(name, false, [ /* No usages */ ]), |
| 37 | crypto.createPrivateKey(privateKeyPem) |
| 38 | .toCryptoKey(name, false, ['sign']), |
| 39 | subtle.generateKey( |
| 40 | { name: 'HMAC', hash: 'SHA-256' }, |
| 41 | false, |
| 42 | ['sign']), |
| 43 | subtle.generateKey( |
| 44 | { |
| 45 | name: 'RSA-PSS', |
| 46 | modulusLength: 1024, |
| 47 | publicExponent: new Uint8Array([1, 0, 1]), |
| 48 | hash: 'SHA-256', |
| 49 | }, |
| 50 | false, |
| 51 | ['sign']), |
| 52 | subtle.generateKey( |
| 53 | { |
| 54 | name: 'ECDSA', |
| 55 | namedCurve: 'P-256' |
| 56 | }, |
| 57 | false, |
| 58 | ['sign']), |
| 59 | ]); |
| 60 | |
| 61 | assert(await subtle.verify({ name, context }, publicKey, signature, data)); |
| 62 | assert(!(await subtle.verify({ name, context: crypto.randomBytes(30) }, publicKey, signature, data))); |
| 63 | if (context.byteLength === 0) { |
| 64 | assert(await subtle.verify({ name }, publicKey, signature, data)); |
| 65 | } |
| 66 | |
| 67 | // Test verification with altered buffers |
| 68 | const copy = Buffer.from(data); |
| 69 | const sigcopy = Buffer.from(signature); |
| 70 | const p = subtle.verify({ name, context }, publicKey, sigcopy, copy); |
| 71 | copy[0] = 255 - copy[0]; |
| 72 | sigcopy[0] = 255 - sigcopy[0]; |
| 73 | assert(await p); |
| 74 | |
| 75 | // Test failure when using wrong key |
| 76 | await assert.rejects( |
no test coverage detected