mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-24 14:35:51 +00:00
Move away from BN.js in tests
This commit is contained in:
parent
b92c2e0114
commit
b2570bb960
@ -1,9 +1,9 @@
|
|||||||
import BN from 'bn.js';
|
|
||||||
import { use as chaiUse, expect } from 'chai';
|
import { use as chaiUse, expect } from 'chai';
|
||||||
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
import chaiAsPromised from 'chai-as-promised'; // eslint-disable-line import/newline-after-import
|
||||||
chaiUse(chaiAsPromised);
|
chaiUse(chaiAsPromised);
|
||||||
|
|
||||||
import openpgp from '../initOpenpgp.js';
|
import openpgp from '../initOpenpgp.js';
|
||||||
|
import util from '../../src/util.js';
|
||||||
|
|
||||||
const armoredDSAKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
const armoredDSAKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||||
|
|
||||||
@ -387,15 +387,16 @@ export default () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('detect g with small order', async function() {
|
it('detect g with small order', async function() {
|
||||||
const keyPacket = await cloneKeyPacket(egKey);
|
const BigInteger = await util.getBigInteger();
|
||||||
const p = keyPacket.publicParams.p;
|
|
||||||
const g = keyPacket.publicParams.g;
|
|
||||||
|
|
||||||
const pBN = new BN(p);
|
const keyPacket = await cloneKeyPacket(egKey);
|
||||||
const gModP = new BN(g).toRed(new BN.red(pBN));
|
const { p, g } = keyPacket.publicParams;
|
||||||
|
|
||||||
|
const pBN = new BigInteger(p);
|
||||||
|
const gBN = new BigInteger(g);
|
||||||
// g**(p-1)/2 has order 2
|
// g**(p-1)/2 has order 2
|
||||||
const gOrd2 = gModP.redPow(pBN.subn(1).shrn(1));
|
const gOrd2 = gBN.modExp(pBN.dec().irightShift(new BigInteger(1)), pBN);
|
||||||
keyPacket.publicParams.g = gOrd2.toArrayLike(Uint8Array, 'be');
|
keyPacket.publicParams.g = gOrd2.toUint8Array();
|
||||||
await expect(keyPacket.validate()).to.be.rejectedWith('Key is invalid');
|
await expect(keyPacket.validate()).to.be.rejectedWith('Key is invalid');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user