Skip to content

Commit 632ee46

Browse files
committed
chore: add comparisons
1 parent ba82e53 commit 632ee46

File tree

11 files changed

+1012
-90
lines changed

11 files changed

+1012
-90
lines changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ Next-gen React Native library for Bcrypt hashing using pure C++ with Turbo Modul
44

55
**_NOTE:_** This library can be used only with New Architecture (more information about New Architecture [here](https://github.com/reactwg/react-native-new-architecture))
66

7+
## Features
8+
9+
- **50x faster than JS implementation** 🚀
10+
- **Multithreaded for high performance without blocking the JS thread** 🧵
11+
- **Seamless integration with Turbo Modules** 🔌
12+
- **Native C++ hashing for maximum security** 🔒
13+
- **Supports both asynchronous and synchronous operations** ⚡️
14+
- **Optimized for React Native's New Architecture** 📱
15+
16+
## Performance
17+
18+
The C++ implementation of Bcrypt hashing is significantly faster than the JavaScript implementation, especially for high-cost factors. Here are some benchmarks comparing the two implementations:
19+
20+
![Comparisons](./assets/comparisons)
21+
22+
## Demo
23+
24+
After running "Generate Hash" function on JS side, it blocks JS Thread while the function runs (approximately 14 seconds). On the other hand, the C++ implementation runs the same function in a separate thread, allowing the JS thread to continue executing other tasks without blocking (approximately 0.3 seconds). This demonstrates the superior performance of the C++ implementation over the JavaScript implementation.
25+
26+
| JavaScript Demo | C++ Demo |
27+
| :---------------------------------------: | :-----------------------------------------: |
28+
| ![JS Demo](./assets/JS_GENERATE_HASH.gif) | ![C++ Demo](./assets/C++_GENERATE_HASH.gif) |
29+
| **JavaScript Hashing** | **C++ Hashing** |
30+
731
## Installation
832

933
```sh
@@ -16,6 +40,10 @@ or
1640
yarn add react-native-bcrypt-cpp
1741
```
1842

43+
### Linking
44+
45+
TBD
46+
1947
## Usage
2048

2149
### Asynchronous Hashing (Multithreaded)
@@ -101,6 +129,11 @@ Synchronously validates the given password against the Bcrypt hash.
101129

102130
- A `boolean` indicating whether the password is valid.
103131

132+
## Bcrypt Algorithm Source
133+
134+
This library implements the Bcrypt hashing algorithm in C++, adapted from the [Bcrypt.cpp project](https://github.com/hilch/Bcrypt.cpp?tab=License-1-ov-file) by Hilko Bengen.
135+
This product includes software developed by Niels Provos.
136+
104137
## Contributing
105138

106139
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

assets/C++_GENERATE_HASH.gif

10.8 MB
Loading

assets/JS_GENERATE_HASH.gif

10.2 MB
Loading

assets/comparisons

102 KB
Binary file not shown.

example/ios/BcryptCppExample.xcodeproj/project.pbxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,10 @@
592592
"-DFOLLY_CFG_NO_COROUTINES=1",
593593
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
594594
);
595-
OTHER_LDFLAGS = "$(inherited) ";
595+
OTHER_LDFLAGS = (
596+
"$(inherited)",
597+
" ",
598+
);
596599
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
597600
SDKROOT = iphoneos;
598601
USE_HERMES = true;
@@ -664,7 +667,10 @@
664667
"-DFOLLY_CFG_NO_COROUTINES=1",
665668
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
666669
);
667-
OTHER_LDFLAGS = "$(inherited) ";
670+
OTHER_LDFLAGS = (
671+
"$(inherited)",
672+
" ",
673+
);
668674
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
669675
SDKROOT = iphoneos;
670676
USE_HERMES = true;

example/ios/Podfile.lock

+7-1
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ PODS:
956956
- ReactCommon/turbomodule/bridging
957957
- ReactCommon/turbomodule/core
958958
- Yoga
959+
- react-native-randombytes (3.6.1):
960+
- React-Core
959961
- React-nativeconfig (0.74.5)
960962
- React-NativeModulesApple (0.74.5):
961963
- glog
@@ -1222,6 +1224,7 @@ DEPENDENCIES:
12221224
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
12231225
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
12241226
- react-native-bcrypt-cpp (from `../..`)
1227+
- react-native-randombytes (from `../node_modules/react-native-randombytes`)
12251228
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
12261229
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
12271230
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -1315,6 +1318,8 @@ EXTERNAL SOURCES:
13151318
:path: "../node_modules/react-native/ReactCommon"
13161319
react-native-bcrypt-cpp:
13171320
:path: "../.."
1321+
react-native-randombytes:
1322+
:path: "../node_modules/react-native-randombytes"
13181323
React-nativeconfig:
13191324
:path: "../node_modules/react-native/ReactCommon"
13201325
React-NativeModulesApple:
@@ -1395,7 +1400,8 @@ SPEC CHECKSUMS:
13951400
React-jsitracing: 3b6060bbf5317663667e1dd93560c7943ab86ccc
13961401
React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c
13971402
React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f
1398-
react-native-bcrypt-cpp: 4e7cb1f3c64413bd84b3e8b13db0ce7bcb52b581
1403+
react-native-bcrypt-cpp: 3a7a9427b6aa068c1fa462ee0465eb05d3cd198c
1404+
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
13991405
React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851
14001406
React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697
14011407
React-perflogger: ed4e0c65781521e0424f2e5e40b40cc7879d737e

example/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"react": "18.2.0",
14-
"react-native": "0.74.5"
14+
"react-native": "0.74.5",
15+
"react-native-randombytes": "^3.6.1"
1516
},
1617
"devDependencies": {
1718
"@babel/core": "^7.20.0",

0 commit comments

Comments
 (0)