Skip to content

Commit

Permalink
chore: add comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
anday013 committed Aug 15, 2024
1 parent ba82e53 commit 632ee46
Show file tree
Hide file tree
Showing 11 changed files with 1,012 additions and 90 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ Next-gen React Native library for Bcrypt hashing using pure C++ with Turbo Modul

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

## Features

- **50x faster than JS implementation** 🚀
- **Multithreaded for high performance without blocking the JS thread** 🧵
- **Seamless integration with Turbo Modules** 🔌
- **Native C++ hashing for maximum security** 🔒
- **Supports both asynchronous and synchronous operations** ⚡️
- **Optimized for React Native's New Architecture** 📱

## Performance

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:

![Comparisons](./assets/comparisons)

## Demo

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.

| JavaScript Demo | C++ Demo |
| :---------------------------------------: | :-----------------------------------------: |
| ![JS Demo](./assets/JS_GENERATE_HASH.gif) | ![C++ Demo](./assets/C++_GENERATE_HASH.gif) |
| **JavaScript Hashing** | **C++ Hashing** |

## Installation

```sh
Expand All @@ -16,6 +40,10 @@ or
yarn add react-native-bcrypt-cpp
```

### Linking

TBD

## Usage

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

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

## Bcrypt Algorithm Source

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.
This product includes software developed by Niels Provos.

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand Down
Binary file added assets/C++_GENERATE_HASH.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/JS_GENERATE_HASH.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/comparisons
Binary file not shown.
10 changes: 8 additions & 2 deletions example/ios/BcryptCppExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -664,7 +667,10 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = "$(inherited) ";
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
8 changes: 7 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,8 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-randombytes (3.6.1):
- React-Core
- React-nativeconfig (0.74.5)
- React-NativeModulesApple (0.74.5):
- glog
Expand Down Expand Up @@ -1222,6 +1224,7 @@ DEPENDENCIES:
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-bcrypt-cpp (from `../..`)
- react-native-randombytes (from `../node_modules/react-native-randombytes`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand Down Expand Up @@ -1315,6 +1318,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
react-native-bcrypt-cpp:
:path: "../.."
react-native-randombytes:
:path: "../node_modules/react-native-randombytes"
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1395,7 +1400,8 @@ SPEC CHECKSUMS:
React-jsitracing: 3b6060bbf5317663667e1dd93560c7943ab86ccc
React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c
React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f
react-native-bcrypt-cpp: 4e7cb1f3c64413bd84b3e8b13db0ce7bcb52b581
react-native-bcrypt-cpp: 3a7a9427b6aa068c1fa462ee0465eb05d3cd198c
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851
React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697
React-perflogger: ed4e0c65781521e0424f2e5e40b40cc7879d737e
Expand Down
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"react": "18.2.0",
"react-native": "0.74.5"
"react-native": "0.74.5",
"react-native-randombytes": "^3.6.1"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
Loading

0 comments on commit 632ee46

Please sign in to comment.