-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathcipher.ts
More file actions
45 lines (38 loc) · 1.23 KB
/
cipher.ts
File metadata and controls
45 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import rnqc from 'react-native-quick-crypto';
// @ts-expect-error - crypto-browserify is not typed
import browserify from 'crypto-browserify';
import { gcm } from '@noble/ciphers/aes.js';
import type { BenchFn } from '../../types/benchmarks';
import { Bench } from 'tinybench';
import { buffer1MB } from '../testData';
// Generate a key for AES-256-GCM
const key = rnqc.randomBytes(32);
const iv = rnqc.randomBytes(12);
// @noble requires Uint8Array
const nobleKey = new Uint8Array(key);
const nobleIv = new Uint8Array(iv);
const cipher_aes256gcm_1mb_buffer: BenchFn = () => {
const bench = new Bench({
name: 'cipher aes256gcm 1MB Buffer',
iterations: 1,
warmupIterations: 0,
});
const nobleData = new Uint8Array(buffer1MB);
bench
.add('rnqc', () => {
const cipher = rnqc.createCipheriv('aes-256-gcm', key, iv);
cipher.update(buffer1MB);
cipher.final();
})
.add('@noble/ciphers/aes', () => {
const cipher = gcm(nobleKey, nobleIv);
cipher.encrypt(nobleData);
})
.add('browserify', () => {
const cipher = browserify.createCipheriv('aes-256-gcm', key, iv);
cipher.update(buffer1MB);
cipher.final();
});
return bench;
};
export default [cipher_aes256gcm_1mb_buffer];