Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .docs/implementation-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ These algorithms provide quantum-resistant cryptography.
* ❌ `crypto.encapsulate(key[, callback])`
* `-` `crypto.fips` deprecated, not applicable to RN
* ✅ `crypto.generateKey(type, options, callback)`
* 🚧 `crypto.generateKeyPair(type, options, callback)`
* 🚧 `crypto.generateKeyPairSync(type, options)`
* 🚧 `crypto.generateKeySync(type, options)`
* `crypto.generateKeyPair(type, options, callback)`
* `crypto.generateKeyPairSync(type, options)`
* `crypto.generateKeySync(type, options)`
* ✅ `crypto.generatePrime(size[, options[, callback]])`
* ✅ `crypto.generatePrimeSync(size[, options])`
* ✅ `crypto.getCipherInfo(nameOrNid[, options])`
Expand Down Expand Up @@ -182,26 +182,26 @@ These algorithms provide quantum-resistant cryptography.
| --------- | :----: |
| `rsa` | ✅ |
| `rsa-pss` | ✅ |
| `dsa` | |
| `dsa` | |
| `ec` | ✅ |
| `ed25519` | ✅ |
| `ed448` | ✅ |
| `x25519` | ✅ |
| `x448` | ✅ |
| `dh` | |
| `dh` | |

## `crypto.generateKeyPairSync`
| type | Status |
| --------- | :----: |
| `rsa` | ✅ |
| `rsa-pss` | ✅ |
| `dsa` | |
| `dsa` | |
| `ec` | ✅ |
| `ed25519` | ✅ |
| `ed448` | ✅ |
| `x25519` | ✅ |
| `x448` | ✅ |
| `dh` | |
| `dh` | |

## `crypto.generateKeySync`
| type | Status |
Expand Down
199 changes: 199 additions & 0 deletions example/src/tests/keys/generate_keypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,202 @@ test(SUITE, 'generateKeyPairSync EC with DER encoding', () => {
expect((privateKey as ArrayBuffer).byteLength).to.be.greaterThan(0);
expect((publicKey as ArrayBuffer).byteLength).to.be.greaterThan(0);
});

// --- DSA Key Generation Tests ---

test(SUITE, 'generateKeyPair DSA 2048-bit with PEM encoding', async () => {
const { privateKey, publicKey } = await new Promise<{
privateKey: string;
publicKey: string;
}>((resolve, reject) => {
generateKeyPair(
'dsa',
{
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
},
(err, pubKey, privKey) => {
if (err) reject(err);
else
resolve({
privateKey: privKey as string,
publicKey: pubKey as string,
});
},
);
});

expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPair DSA with custom divisorLength', async () => {
const { privateKey, publicKey } = await new Promise<{
privateKey: string;
publicKey: string;
}>((resolve, reject) => {
generateKeyPair(
'dsa',
{
modulusLength: 2048,
divisorLength: 256,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
},
(err, pubKey, privKey) => {
if (err) reject(err);
else
resolve({
privateKey: privKey as string,
publicKey: pubKey as string,
});
},
);
});

expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPair DSA with DER encoding', async () => {
const { privateKey, publicKey } = await new Promise<{
privateKey: ArrayBuffer;
publicKey: ArrayBuffer;
}>((resolve, reject) => {
generateKeyPair(
'dsa',
{
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'der' },
privateKeyEncoding: { type: 'pkcs8', format: 'der' },
},
(err, pubKey, privKey) => {
if (err) reject(err);
else
resolve({
privateKey: privKey as ArrayBuffer,
publicKey: pubKey as ArrayBuffer,
});
},
);
});

expect(privateKey instanceof ArrayBuffer).to.equal(true);
expect(publicKey instanceof ArrayBuffer).to.equal(true);
expect(privateKey.byteLength).to.be.greaterThan(0);
expect(publicKey.byteLength).to.be.greaterThan(0);
});

test(SUITE, 'generateKeyPairSync DSA 2048-bit', () => {
const { privateKey, publicKey } = generateKeyPairSync('dsa', {
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});

expect(typeof privateKey).to.equal('string');
expect(typeof publicKey).to.equal('string');
expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPairSync DSA keys work for signing', () => {
const { privateKey, publicKey } = generateKeyPairSync('dsa', {
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});

const testData = 'Test data for DSA signing';
const signature = createSign('SHA256')
.update(testData)
.sign(privateKey as string);
const isValid = createVerify('SHA256')
.update(testData)
.verify(publicKey as string, signature);

expect(isValid).to.equal(true);
});

// --- DH Key Generation Tests ---

test(SUITE, 'generateKeyPair DH with named group modp14', async () => {
const { privateKey, publicKey } = await new Promise<{
privateKey: string;
publicKey: string;
}>((resolve, reject) => {
generateKeyPair(
'dh',
{
groupName: 'modp14',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
},
(err, pubKey, privKey) => {
if (err) reject(err);
else
resolve({
privateKey: privKey as string,
publicKey: pubKey as string,
});
},
);
});

expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPair DH with primeLength', async () => {
const { privateKey, publicKey } = await new Promise<{
privateKey: string;
publicKey: string;
}>((resolve, reject) => {
generateKeyPair(
'dh',
{
primeLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
},
(err, pubKey, privKey) => {
if (err) reject(err);
else
resolve({
privateKey: privKey as string,
publicKey: pubKey as string,
});
},
);
});

expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPairSync DH with named group', () => {
const { privateKey, publicKey } = generateKeyPairSync('dh', {
groupName: 'modp14',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});

expect(typeof privateKey).to.equal('string');
expect(typeof publicKey).to.equal('string');
expect(privateKey).to.match(/^-----BEGIN PRIVATE KEY-----/);
expect(publicKey).to.match(/^-----BEGIN PUBLIC KEY-----/);
});

test(SUITE, 'generateKeyPairSync DH with DER encoding', () => {
const { privateKey, publicKey } = generateKeyPairSync('dh', {
groupName: 'modp14',
publicKeyEncoding: { type: 'spki', format: 'der' },
privateKeyEncoding: { type: 'pkcs8', format: 'der' },
});

expect(privateKey instanceof ArrayBuffer).to.equal(true);
expect(publicKey instanceof ArrayBuffer).to.equal(true);
expect((privateKey as ArrayBuffer).byteLength).to.be.greaterThan(0);
expect((publicKey as ArrayBuffer).byteLength).to.be.greaterThan(0);
});
3 changes: 3 additions & 0 deletions packages/react-native-quick-crypto/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_library(
../cpp/cipher/ChaCha20Cipher.cpp
../cpp/cipher/ChaCha20Poly1305Cipher.cpp
../cpp/dh/HybridDiffieHellman.cpp
../cpp/dh/HybridDhKeyPair.cpp
../cpp/dsa/HybridDsaKeyPair.cpp
../cpp/ec/HybridEcKeyPair.cpp
../cpp/ecdh/HybridECDH.cpp
../cpp/ed25519/HybridEdKeyPair.cpp
Expand Down Expand Up @@ -74,6 +76,7 @@ include_directories(
"../cpp/certificate"
"../cpp/cipher"
"../cpp/dh"
"../cpp/dsa"
"../cpp/ec"
"../cpp/ecdh"
"../cpp/ed25519"
Expand Down
Loading
Loading