Skip to content

Commit dcd8b94

Browse files
authored
feat: blake3 support (#809)
1 parent 6426a76 commit dcd8b94

File tree

29 files changed

+1060
-21
lines changed

29 files changed

+1060
-21
lines changed

.github/actions/post-maestro-screenshot/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ runs:
103103
104104
### 📸 Final Test Screenshot
105105
106-
![Maestro Test Results - ${{ inputs.platform }}](${{ steps.upload-screenshot.outputs.url }})
106+
<img src="${{ steps.upload-screenshot.outputs.url }}" alt="Maestro Test Results - ${{ inputs.platform }}" width="400" />
107107
108108
*Screenshot automatically captured from End-to-End tests and will expire in 30 days*
109109

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "packages/react-native-quick-crypto/deps/blake3"]
2+
path = packages/react-native-quick-crypto/deps/blake3
3+
url = https://github.com/BLAKE3-team/BLAKE3.git

example/android/app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ android {
8484
targetSdkVersion rootProject.ext.targetSdkVersion
8585
versionCode 1
8686
versionName "1.0"
87+
externalNativeBuild {
88+
cmake {
89+
arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
90+
}
91+
}
92+
}
93+
packaging {
94+
jniLibs {
95+
pickFirsts += ["**/libNitroModules.so", "**/libc++_shared.so", "**/libfbjni.so"]
96+
}
8797
}
8898
signingConfigs {
8999
debug {

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
minSdkVersion = 24
55
compileSdkVersion = 36
66
targetSdkVersion = 36
7-
ndkVersion = "27.1.12297006"
7+
ndkVersion = "28.2.13676358"
88
kotlinVersion = "2.1.20"
99
}
1010
repositories {

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,7 @@ SPEC CHECKSUMS:
27462746
hermes-engine: 4f8246b1f6d79f625e0d99472d1f3a71da4d28ca
27472747
NitroModules: 1715fe0e22defd9e2cdd48fb5e0dbfd01af54bec
27482748
OpenSSL-Universal: 6082b0bf950e5636fe0d78def171184e2b3899c2
2749-
QuickCrypto: 0e223a6fd5f3bf5841592a3aa9e0471078912ee8
2749+
QuickCrypto: 18cce2f53208e965986216aaa6d6bff0839618b0
27502750
RCT-Folly: 846fda9475e61ec7bcbf8a3fe81edfcaeb090669
27512751
RCTDeprecation: c4b9e2fd0ab200e3af72b013ed6113187c607077
27522752
RCTRequired: e97dd5dafc1db8094e63bc5031e0371f092ae92a
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import rnqc from 'react-native-quick-crypto';
2+
import { blake3 as nobleBlake3 } from '@noble/hashes/blake3';
3+
import type { BenchFn } from '../../types/benchmarks';
4+
import { Bench } from 'tinybench';
5+
6+
const TIME_MS = 1000;
7+
8+
const blake3_32b: BenchFn = () => {
9+
const data = rnqc.randomBytes(32);
10+
11+
const bench = new Bench({
12+
name: 'blake3 32b input',
13+
time: TIME_MS,
14+
});
15+
16+
bench
17+
.add('rnqc', () => {
18+
rnqc.blake3(data);
19+
})
20+
.add('@noble/hashes/blake3', () => {
21+
nobleBlake3(data);
22+
});
23+
24+
bench.warmupTime = 100;
25+
return bench;
26+
};
27+
28+
const blake3_1kb: BenchFn = () => {
29+
const data = rnqc.randomBytes(1024);
30+
31+
const bench = new Bench({
32+
name: 'blake3 1KB input',
33+
time: TIME_MS,
34+
});
35+
36+
bench
37+
.add('rnqc', () => {
38+
rnqc.blake3(data);
39+
})
40+
.add('@noble/hashes/blake3', () => {
41+
nobleBlake3(data);
42+
});
43+
44+
bench.warmupTime = 100;
45+
return bench;
46+
};
47+
48+
const blake3_64kb: BenchFn = () => {
49+
const data = rnqc.randomBytes(64 * 1024);
50+
51+
const bench = new Bench({
52+
name: 'blake3 64KB input',
53+
time: TIME_MS,
54+
});
55+
56+
bench
57+
.add('rnqc', () => {
58+
rnqc.blake3(data);
59+
})
60+
.add('@noble/hashes/blake3', () => {
61+
nobleBlake3(data);
62+
});
63+
64+
bench.warmupTime = 100;
65+
return bench;
66+
};
67+
68+
const blake3_xof_256b: BenchFn = () => {
69+
const data = rnqc.randomBytes(32);
70+
71+
const bench = new Bench({
72+
name: 'blake3 XOF 256b output',
73+
time: TIME_MS,
74+
});
75+
76+
bench
77+
.add('rnqc', () => {
78+
rnqc.blake3(data, { dkLen: 256 });
79+
})
80+
.add('@noble/hashes/blake3', () => {
81+
nobleBlake3(data, { dkLen: 256 });
82+
});
83+
84+
bench.warmupTime = 100;
85+
return bench;
86+
};
87+
88+
const blake3_keyed: BenchFn = () => {
89+
const data = rnqc.randomBytes(64);
90+
const key = rnqc.randomBytes(32);
91+
92+
const bench = new Bench({
93+
name: 'blake3 keyed MAC',
94+
time: TIME_MS,
95+
});
96+
97+
bench
98+
.add('rnqc', () => {
99+
rnqc.blake3(data, { key });
100+
})
101+
.add('@noble/hashes/blake3', () => {
102+
nobleBlake3(data, { key });
103+
});
104+
105+
bench.warmupTime = 100;
106+
return bench;
107+
};
108+
109+
const blake3_streaming: BenchFn = () => {
110+
const chunk1 = rnqc.randomBytes(512);
111+
const chunk2 = rnqc.randomBytes(512);
112+
113+
const bench = new Bench({
114+
name: 'blake3 streaming (2x 512b)',
115+
time: TIME_MS,
116+
});
117+
118+
bench
119+
.add('rnqc', () => {
120+
const h = rnqc.createBlake3();
121+
h.update(chunk1);
122+
h.update(chunk2);
123+
h.digest();
124+
})
125+
.add('@noble/hashes/blake3', () => {
126+
const h = nobleBlake3.create({});
127+
h.update(chunk1);
128+
h.update(chunk2);
129+
h.digest();
130+
});
131+
132+
bench.warmupTime = 100;
133+
return bench;
134+
};
135+
136+
export default [
137+
blake3_32b,
138+
blake3_1kb,
139+
blake3_64kb,
140+
blake3_xof_256b,
141+
blake3_keyed,
142+
blake3_streaming,
143+
];

example/src/hooks/useBenchmarks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import { BenchmarkSuite } from '../benchmarks/benchmarks';
3+
import blake3 from '../benchmarks/blake3/blake3';
34
import ed from '../benchmarks/ed/ed25519';
45
import pbkdf2 from '../benchmarks/pbkdf2/pbkdf2';
56
import random from '../benchmarks/random/randomBytes';
@@ -19,6 +20,7 @@ export const useBenchmarks = (): [
1920
// initial load of benchmark suites
2021
useEffect(() => {
2122
const newSuites: BenchmarkSuite[] = [];
23+
newSuites.push(new BenchmarkSuite('blake3', blake3));
2224
newSuites.push(new BenchmarkSuite('ed', ed));
2325
newSuites.push(new BenchmarkSuite('pbkdf2', pbkdf2));
2426
newSuites.push(

example/src/hooks/useTestsList.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState, useCallback } from 'react';
22
import type { TestSuites } from '../types/tests';
33
import { TestsContext } from '../tests/util';
44

5+
import '../tests/blake3/blake3_tests';
56
import '../tests/cipher/cipher_tests';
67
import '../tests/cipher/chacha_tests';
78
import '../tests/cipher/xsalsa20_tests';
@@ -13,9 +14,9 @@ import '../tests/pbkdf2/pbkdf2_tests';
1314
import '../tests/random/random_tests';
1415
import '../tests/subtle/deriveBits';
1516
import '../tests/subtle/digest';
16-
import '../tests/subtle/encrypt_decrypt';
17+
// import '../tests/subtle/encrypt_decrypt';
1718
import '../tests/subtle/generateKey';
18-
import '../tests/subtle/import_export';
19+
// import '../tests/subtle/import_export';
1920
import '../tests/subtle/sign_verify';
2021

2122
export const useTestsList = (): [

example/src/navigators/children/TestDetailsScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const TestDetailsScreen = ({ route }) => {
3131
disableText={true}
3232
fillColor="red"
3333
style={styles.checkbox}
34+
testID="show-failed-checkbox"
3435
/>
3536
<Text style={styles.showMenuLabel}>Show Failed</Text>
3637
</View>
@@ -41,6 +42,7 @@ export const TestDetailsScreen = ({ route }) => {
4142
disableText={true}
4243
fillColor={colors.green}
4344
style={styles.checkbox}
45+
testID="show-passed-checkbox"
4446
/>
4547
<Text style={styles.showMenuLabel}>Show Passed</Text>
4648
</View>

example/src/navigators/children/TestSuitesScreen.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const TestSuitesScreen = () => {
4545
0,
4646
)}
4747
</Text>
48-
<Text style={[styles.fail, styles.statNumber]}>
48+
<Text
49+
style={[styles.fail, styles.statNumber]}
50+
testID="total-fail-count"
51+
>
4952
{Object.values(results).reduce(
5053
(sum, suite) =>
5154
sum + suite.results.filter(r => r.type === 'incorrect').length,

0 commit comments

Comments
 (0)