From 809e7948168ae2696e8a0f59d84dcbabbdbb99ff Mon Sep 17 00:00:00 2001 From: Alina Sireneva Date: Thu, 8 Feb 2024 04:10:09 +0300 Subject: [PATCH] test: added factorization tests --- .../src/utils/crypto/factorization.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/core/src/utils/crypto/factorization.test.ts diff --git a/packages/core/src/utils/crypto/factorization.test.ts b/packages/core/src/utils/crypto/factorization.test.ts new file mode 100644 index 00000000..aec3c8f2 --- /dev/null +++ b/packages/core/src/utils/crypto/factorization.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it } from 'vitest' + +import { bigIntToBuffer, bufferToBigInt } from '../bigint-utils.js' +import { factorizePQSync } from './factorization.js' +import { defaultCryptoProviderFactory } from './index.js' + +describe('prime factorization', () => { + const testFactorization = (pq: bigint, p: bigint, q: bigint) => { + const [p_, q_] = factorizePQSync(defaultCryptoProviderFactory(), bigIntToBuffer(pq)) + expect(bufferToBigInt(p_)).toBe(p) + expect(bufferToBigInt(q_)).toBe(q) + } + + it('should factorize', () => { + testFactorization(2090522174869285481n, 1112973847n, 1878321023n) + testFactorization(1470626929934143021n, 1206429347n, 1218991343n) + testFactorization(2804275833720261793n, 1555252417n, 1803100129n) + }) +})