├── .editorconfig ├── .gitattributes ├── .github ├── actions │ └── setup │ │ └── action.yml └── workflows │ └── ci.yml ├── .gitignore ├── .nvmrc ├── .watchmanconfig ├── .yarn ├── plugins │ └── @yarnpkg │ │ ├── plugin-interactive-tools.cjs │ │ └── plugin-workspace-tools.cjs └── releases │ └── yarn-3.6.1.cjs ├── .yarnrc.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── CMakeLists.txt ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── com │ └── bcryptcpp │ └── BcryptCppPackage.kt ├── assets ├── C++_GENERATE_HASH.gif ├── JS_GENERATE_HASH.gif └── comparisons ├── babel.config.js ├── cpp ├── NativeBcryptCppTurboModule.cpp ├── NativeBcryptCppTurboModule.h └── bcrypt │ ├── bcrypt.cpp │ ├── bcrypt.h │ ├── blowfish.cpp │ ├── node_blf.h │ └── openbsd.h ├── example ├── .bundle │ └── config ├── .watchmanconfig ├── Gemfile ├── README.md ├── android │ ├── app │ │ ├── build.gradle │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── bcryptcpp │ │ │ │ └── example │ │ │ │ ├── MainActivity.kt │ │ │ │ └── MainApplication.kt │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── .xcode.env │ ├── BcryptCppExample-Bridging-Header.h │ ├── BcryptCppExample.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── BcryptCppExample.xcscheme │ ├── BcryptCppExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── BcryptCppExample │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ ├── PrivacyInfo.xcprivacy │ │ └── main.m │ ├── BcryptCppExampleTests │ │ ├── BcryptCppExampleTests.m │ │ └── Info.plist │ ├── File.swift │ ├── Podfile │ └── Podfile.lock ├── jest.config.js ├── metro.config.js ├── package.json ├── react-native.config.js └── src │ ├── App.tsx │ ├── MovingRectangle.tsx │ └── bcryptjs.ts ├── ios └── onLoad.mm ├── lefthook.yml ├── package.json ├── react-native-bcrypt-cpp.podspec ├── react-native.config.js ├── src ├── NativeBcryptCpp.ts ├── __tests__ │ └── index.test.tsx └── index.tsx ├── tsconfig.build.json ├── tsconfig.json ├── turbo.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup Node.js and install dependencies 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Setup Node.js 8 | uses: actions/setup-node@v3 9 | with: 10 | node-version-file: .nvmrc 11 | 12 | - name: Cache dependencies 13 | id: yarn-cache 14 | uses: actions/cache@v3 15 | with: 16 | path: | 17 | **/node_modules 18 | .yarn/install-state.gz 19 | key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }} 20 | restore-keys: | 21 | ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} 22 | ${{ runner.os }}-yarn- 23 | 24 | - name: Install dependencies 25 | if: steps.yarn-cache.outputs.cache-hit != 'true' 26 | run: yarn install --immutable 27 | shell: bash 28 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - main 9 | merge_group: 10 | types: 11 | - checks_requested 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | 20 | - name: Setup 21 | uses: ./.github/actions/setup 22 | 23 | - name: Lint files 24 | run: yarn lint 25 | 26 | - name: Typecheck files 27 | run: yarn typecheck 28 | 29 | test: 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v3 34 | 35 | - name: Setup 36 | uses: ./.github/actions/setup 37 | 38 | - name: Run unit tests 39 | run: yarn test --maxWorkers=2 --coverage 40 | 41 | build-library: 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Checkout 45 | uses: actions/checkout@v3 46 | 47 | - name: Setup 48 | uses: ./.github/actions/setup 49 | 50 | - name: Build package 51 | run: yarn prepare 52 | 53 | build-android: 54 | runs-on: ubuntu-latest 55 | env: 56 | TURBO_CACHE_DIR: .turbo/android 57 | steps: 58 | - name: Checkout 59 | uses: actions/checkout@v3 60 | 61 | - name: Setup 62 | uses: ./.github/actions/setup 63 | 64 | - name: Cache turborepo for Android 65 | uses: actions/cache@v3 66 | with: 67 | path: ${{ env.TURBO_CACHE_DIR }} 68 | key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }} 69 | restore-keys: | 70 | ${{ runner.os }}-turborepo-android- 71 | 72 | - name: Check turborepo cache for Android 73 | run: | 74 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status") 75 | 76 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then 77 | echo "turbo_cache_hit=1" >> $GITHUB_ENV 78 | fi 79 | 80 | - name: Install JDK 81 | if: env.turbo_cache_hit != 1 82 | uses: actions/setup-java@v3 83 | with: 84 | distribution: 'zulu' 85 | java-version: '17' 86 | 87 | - name: Finalize Android SDK 88 | if: env.turbo_cache_hit != 1 89 | run: | 90 | /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null" 91 | 92 | - name: Cache Gradle 93 | if: env.turbo_cache_hit != 1 94 | uses: actions/cache@v3 95 | with: 96 | path: | 97 | ~/.gradle/wrapper 98 | ~/.gradle/caches 99 | key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }} 100 | restore-keys: | 101 | ${{ runner.os }}-gradle- 102 | 103 | - name: Build example for Android 104 | env: 105 | JAVA_OPTS: "-XX:MaxHeapSize=6g" 106 | run: | 107 | yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" 108 | 109 | build-ios: 110 | runs-on: macos-14 111 | env: 112 | TURBO_CACHE_DIR: .turbo/ios 113 | steps: 114 | - name: Checkout 115 | uses: actions/checkout@v3 116 | 117 | - name: Setup 118 | uses: ./.github/actions/setup 119 | 120 | - name: Cache turborepo for iOS 121 | uses: actions/cache@v3 122 | with: 123 | path: ${{ env.TURBO_CACHE_DIR }} 124 | key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }} 125 | restore-keys: | 126 | ${{ runner.os }}-turborepo-ios- 127 | 128 | - name: Check turborepo cache for iOS 129 | run: | 130 | TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status") 131 | 132 | if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then 133 | echo "turbo_cache_hit=1" >> $GITHUB_ENV 134 | fi 135 | 136 | - name: Cache cocoapods 137 | if: env.turbo_cache_hit != 1 138 | id: cocoapods-cache 139 | uses: actions/cache@v3 140 | with: 141 | path: | 142 | **/ios/Pods 143 | key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }} 144 | restore-keys: | 145 | ${{ runner.os }}-cocoapods- 146 | 147 | - name: Install cocoapods 148 | if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true' 149 | run: | 150 | cd example/ios 151 | pod install 152 | env: 153 | NO_FLIPPER: 1 154 | 155 | - name: Build example for iOS 156 | run: | 157 | yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" 158 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # Ruby 48 | example/vendor/ 49 | 50 | # node.js 51 | # 52 | node_modules/ 53 | npm-debug.log 54 | yarn-debug.log 55 | yarn-error.log 56 | 57 | # BUCK 58 | buck-out/ 59 | \.buckd/ 60 | android/app/libs 61 | android/keystores/debug.keystore 62 | 63 | # Yarn 64 | .yarn/* 65 | !.yarn/patches 66 | !.yarn/plugins 67 | !.yarn/releases 68 | !.yarn/sdks 69 | !.yarn/versions 70 | 71 | # Expo 72 | .expo/ 73 | 74 | # Turborepo 75 | .turbo/ 76 | 77 | # generated by bob 78 | lib/ 79 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | nmHoistingLimits: workspaces 3 | 4 | plugins: 5 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 6 | spec: "@yarnpkg/plugin-interactive-tools" 7 | - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs 8 | spec: "@yarnpkg/plugin-workspace-tools" 9 | 10 | yarnPath: .yarn/releases/yarn-3.6.1.cjs 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, caste, color, religion, or sexual 11 | identity and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the overall 27 | community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or advances of 32 | any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email address, 36 | without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [INSERT CONTACT METHOD]. 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series of 87 | actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or permanent 94 | ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within the 114 | community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.1, available at 120 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 121 | 122 | Community Impact Guidelines were inspired by 123 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. 124 | 125 | For answers to common questions about this code of conduct, see the FAQ at 126 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at 127 | [https://www.contributor-covenant.org/translations][translations]. 128 | 129 | [homepage]: https://www.contributor-covenant.org 130 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 131 | [Mozilla CoC]: https://github.com/mozilla/diversity 132 | [FAQ]: https://www.contributor-covenant.org/faq 133 | [translations]: https://www.contributor-covenant.org/translations 134 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are always welcome, no matter how large or small! 4 | 5 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the [code of conduct](./CODE_OF_CONDUCT.md). 6 | 7 | ## Development workflow 8 | 9 | This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages: 10 | 11 | - The library package in the root directory. 12 | - An example app in the `example/` directory. 13 | 14 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 15 | 16 | ```sh 17 | yarn 18 | ``` 19 | 20 | > Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development. 21 | 22 | The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make. 23 | 24 | It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app. 25 | 26 | If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/BcryptCppExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-bcrypt-cpp`. 27 | 28 | To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-bcrypt-cpp` under `Android`. 29 | 30 | You can use various commands from the root directory to work with the project. 31 | 32 | To start the packager: 33 | 34 | ```sh 35 | yarn example start 36 | ``` 37 | 38 | To run the example app on Android: 39 | 40 | ```sh 41 | yarn example android 42 | ``` 43 | 44 | To run the example app on iOS: 45 | 46 | ```sh 47 | yarn example ios 48 | ``` 49 | 50 | To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this: 51 | 52 | ```sh 53 | Running "BcryptCppExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1} 54 | ``` 55 | 56 | Note the `"fabric":true` and `"concurrentRoot":true` properties. 57 | 58 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 59 | 60 | ```sh 61 | yarn typecheck 62 | yarn lint 63 | ``` 64 | 65 | To fix formatting errors, run the following: 66 | 67 | ```sh 68 | yarn lint --fix 69 | ``` 70 | 71 | Remember to add tests for your change if possible. Run the unit tests by: 72 | 73 | ```sh 74 | yarn test 75 | ``` 76 | 77 | ### Commit message convention 78 | 79 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 80 | 81 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 82 | - `feat`: new features, e.g. add new method to the module. 83 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 84 | - `docs`: changes into documentation, e.g. add usage example for the module.. 85 | - `test`: adding or updating tests, e.g. add integration tests using detox. 86 | - `chore`: tooling changes, e.g. change CI config. 87 | 88 | Our pre-commit hooks verify that your commit message matches this format when committing. 89 | 90 | ### Linting and tests 91 | 92 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 93 | 94 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 95 | 96 | Our pre-commit hooks verify that the linter and tests pass when committing. 97 | 98 | ### Publishing to npm 99 | 100 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 101 | 102 | To publish new versions, run the following: 103 | 104 | ```sh 105 | yarn release 106 | ``` 107 | 108 | ### Scripts 109 | 110 | The `package.json` file contains various scripts for common tasks: 111 | 112 | - `yarn`: setup project by installing dependencies. 113 | - `yarn typecheck`: type-check files with TypeScript. 114 | - `yarn lint`: lint files with ESLint. 115 | - `yarn test`: run unit tests with Jest. 116 | - `yarn example start`: start the Metro server for the example app. 117 | - `yarn example android`: run the example app on Android. 118 | - `yarn example ios`: run the example app on iOS. 119 | 120 | ### Sending a pull request 121 | 122 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 123 | 124 | When you're sending a pull request: 125 | 126 | - Prefer small pull requests focused on one change. 127 | - Verify that linters and tests are passing. 128 | - Review the documentation to make sure it looks good. 129 | - Follow the pull request template when opening a pull request. 130 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 131 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 anday013 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-bcrypt-cpp 2 | 3 | Next-gen React Native library for Bcrypt hashing using pure C++ with Turbo Modules and multithreading for superior performance. 4 | 5 | **_NOTE:_** This library can be used only with New Architecture (more information about New Architecture [here](https://github.com/reactwg/react-native-new-architecture)) 6 | 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 | 31 | ## Installation 32 | 33 | ```sh 34 | npm install react-native-bcrypt-cpp 35 | ``` 36 | 37 | or 38 | 39 | ```sh 40 | yarn add react-native-bcrypt-cpp 41 | ``` 42 | 43 | ### Linking 44 | 45 | ```sh 46 | cd ios && bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install 47 | ``` 48 | 49 | ## Usage 50 | 51 | ### Asynchronous Hashing (Multithreaded) 52 | 53 | ```js 54 | import { generateHash, validatePassword } from 'react-native-bcrypt-cpp'; 55 | 56 | // Generate a hash asynchronously 57 | const hash = await generateHash('password', 12); 58 | 59 | // Validate a password against a hash 60 | const isValid = await validatePassword('password', hash); 61 | ``` 62 | 63 | ### Synchronous Hashing (Single-threaded) 64 | 65 | ```js 66 | import { 67 | generateHashSync, 68 | validatePasswordSync, 69 | } from 'react-native-bcrypt-cpp'; 70 | 71 | // Generate a hash synchronously 72 | const hash = generateHashSync('password', 12); 73 | 74 | // Validate a password against a hash synchronously 75 | const isValid = validatePasswordSync('password', hash); 76 | ``` 77 | 78 | ## API Reference 79 | 80 | ## API Reference 81 | 82 | ### `generateHash(password: string, workload: number): Promise` 83 | 84 | Asynchronously generates a Bcrypt hash for the given password with the specified workload factor. 85 | 86 | **Parameters:** 87 | 88 | - `password` (string): The password to hash. 89 | - `workload` (number): The cost factor for the hashing algorithm (e.g., 12). 90 | 91 | **Returns:** 92 | 93 | - A `Promise` that resolves to a `string` containing the generated hash. 94 | 95 | ### `validatePassword(password: string, hash: string): Promise` 96 | 97 | Asynchronously validates the given password against the Bcrypt hash. 98 | 99 | **Parameters:** 100 | 101 | - `password` (string): The password to validate. 102 | - `hash` (string): The Bcrypt hash to validate against. 103 | 104 | **Returns:** 105 | 106 | - A `Promise` that resolves to a `boolean` indicating whether the password is valid. 107 | 108 | ### `generateHashSync(password: string, workload: number): string` 109 | 110 | Synchronously generates a Bcrypt hash for the given password with the specified workload factor. 111 | 112 | **Parameters:** 113 | 114 | - `password` (string): The password to hash. 115 | - `workload` (number): The cost factor for the hashing algorithm (e.g., 12). 116 | 117 | **Returns:** 118 | 119 | - A `string` containing the generated hash. 120 | 121 | ### `validatePasswordSync(password: string, hash: string): boolean` 122 | 123 | Synchronously validates the given password against the Bcrypt hash. 124 | 125 | **Parameters:** 126 | 127 | - `password` (string): The password to validate. 128 | - `hash` (string): The Bcrypt hash to validate against. 129 | 130 | **Returns:** 131 | 132 | - A `boolean` indicating whether the password is valid. 133 | 134 | ## Bcrypt Algorithm Source 135 | 136 | 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. 137 | This product includes software developed by Niels Provos. 138 | 139 | ## Contributing 140 | 141 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 142 | 143 | ## License 144 | 145 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 146 | 147 | --- 148 | 149 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 150 | -------------------------------------------------------------------------------- /android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | project(BcryptCpp) 3 | 4 | set(CMAKE_VERBOSE_MAKEFILE ON) 5 | 6 | add_compile_options( 7 | -fexceptions 8 | -frtti 9 | -std=c++17 10 | ) 11 | 12 | # Add bcrypt library 13 | add_library(bcrypt STATIC 14 | ../cpp/bcrypt/bcrypt.cpp 15 | ../cpp/bcrypt/blowfish.cpp 16 | ../cpp/bcrypt/node_blf.h 17 | ../cpp/bcrypt/openbsd.h) 18 | 19 | add_library(react-native-bcrypt-cpp STATIC 20 | ../cpp/NativeBcryptCppTurboModule.cpp) 21 | 22 | target_include_directories(bcrypt 23 | PUBLIC 24 | ../cpp/bcrypt) 25 | 26 | target_include_directories(react-native-bcrypt-cpp 27 | PUBLIC 28 | ../cpp 29 | ) 30 | 31 | target_link_libraries(react-native-bcrypt-cpp 32 | bcrypt 33 | jsi 34 | react_nativemodule_core 35 | react_codegen_RNBcryptCppSpec 36 | ) 37 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | // Buildscript is evaluated before everything else so we can't use getExtOrDefault 3 | def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["BcryptCpp_kotlinVersion"] 4 | 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | 10 | dependencies { 11 | classpath "com.android.tools.build:gradle:7.2.1" 12 | // noinspection DifferentKotlinGradleVersion 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | } 15 | } 16 | 17 | def reactNativeArchitectures() { 18 | def value = rootProject.getProperties().get("reactNativeArchitectures") 19 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 20 | } 21 | 22 | def isNewArchitectureEnabled() { 23 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" 24 | } 25 | 26 | apply plugin: "com.android.library" 27 | apply plugin: "kotlin-android" 28 | 29 | if (isNewArchitectureEnabled()) { 30 | apply plugin: "com.facebook.react" 31 | } 32 | 33 | def getExtOrDefault(name) { 34 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["BcryptCpp_" + name] 35 | } 36 | 37 | def getExtOrIntegerDefault(name) { 38 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["BcryptCpp_" + name]).toInteger() 39 | } 40 | 41 | def supportsNamespace() { 42 | def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') 43 | def major = parsed[0].toInteger() 44 | def minor = parsed[1].toInteger() 45 | 46 | // Namespace support was added in 7.3.0 47 | return (major == 7 && minor >= 3) || major >= 8 48 | } 49 | 50 | android { 51 | if (supportsNamespace()) { 52 | namespace "com.bcryptcpp" 53 | 54 | sourceSets { 55 | main { 56 | manifest.srcFile "src/main/AndroidManifestNew.xml" 57 | } 58 | } 59 | } 60 | 61 | ndkVersion getExtOrDefault("ndkVersion") 62 | compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") 63 | 64 | defaultConfig { 65 | minSdkVersion getExtOrIntegerDefault("minSdkVersion") 66 | targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") 67 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 68 | 69 | externalNativeBuild { 70 | cmake { 71 | cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all" 72 | abiFilters (*reactNativeArchitectures()) 73 | } 74 | } 75 | } 76 | 77 | externalNativeBuild { 78 | cmake { 79 | path "CMakeLists.txt" 80 | } 81 | } 82 | 83 | buildFeatures { 84 | buildConfig true 85 | } 86 | 87 | buildTypes { 88 | release { 89 | minifyEnabled false 90 | } 91 | } 92 | 93 | lintOptions { 94 | disable "GradleCompatible" 95 | } 96 | 97 | compileOptions { 98 | sourceCompatibility JavaVersion.VERSION_1_8 99 | targetCompatibility JavaVersion.VERSION_1_8 100 | } 101 | 102 | sourceSets { 103 | main { 104 | if (isNewArchitectureEnabled()) { 105 | java.srcDirs += [ 106 | // This is needed to build Kotlin project with NewArch enabled 107 | "${project.buildDir}/generated/source/codegen/java" 108 | ] 109 | } 110 | } 111 | } 112 | } 113 | 114 | repositories { 115 | mavenCentral() 116 | google() 117 | } 118 | 119 | def kotlin_version = getExtOrDefault("kotlinVersion") 120 | 121 | dependencies { 122 | // For < 0.71, this will be from the local maven repo 123 | // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin 124 | //noinspection GradleDynamicVersion 125 | implementation "com.facebook.react:react-native:+" 126 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 127 | } 128 | 129 | if (isNewArchitectureEnabled()) { 130 | react { 131 | jsRootDir = file("../src/") 132 | libraryName = "BcryptCpp" 133 | codegenJavaPackageName = "com.bcryptcpp" 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | BcryptCpp_kotlinVersion=1.7.0 2 | BcryptCpp_minSdkVersion=21 3 | BcryptCpp_targetSdkVersion=31 4 | BcryptCpp_compileSdkVersion=31 5 | BcryptCpp_ndkversion=21.4.7075529 6 | -------------------------------------------------------------------------------- /android/src/main/java/com/bcryptcpp/BcryptCppPackage.kt: -------------------------------------------------------------------------------- 1 | package com.bcryptcpp 2 | 3 | import com.facebook.react.TurboReactPackage 4 | import com.facebook.react.bridge.NativeModule 5 | import com.facebook.react.bridge.ReactApplicationContext 6 | import com.facebook.react.module.model.ReactModuleInfo 7 | import com.facebook.react.module.model.ReactModuleInfoProvider 8 | import java.util.Collections 9 | import java.util.HashMap 10 | 11 | class CryptoCppPackage : TurboReactPackage() { 12 | override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { 13 | return null; 14 | } 15 | 16 | override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { 17 | return ReactModuleInfoProvider { 18 | val moduleInfos: MutableMap = HashMap() 19 | moduleInfos 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /assets/C++_GENERATE_HASH.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/assets/C++_GENERATE_HASH.gif -------------------------------------------------------------------------------- /assets/JS_GENERATE_HASH.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/assets/JS_GENERATE_HASH.gif -------------------------------------------------------------------------------- /assets/comparisons: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/assets/comparisons -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['module:react-native-builder-bob/babel-preset', { modules: 'commonjs' }], 4 | ], 5 | }; 6 | -------------------------------------------------------------------------------- /cpp/NativeBcryptCppTurboModule.cpp: -------------------------------------------------------------------------------- 1 | #include "NativeBcryptCppTurboModule.h" 2 | #include 3 | 4 | namespace facebook::react 5 | { 6 | NativeBcryptCppTurboModule::NativeBcryptCppTurboModule(std::shared_ptr jsinvoker) : NativeBcryptCppCxxSpec(std::move(jsinvoker)) {} 7 | 8 | jsi::Value NativeBcryptCppTurboModule::generateHash(jsi::Runtime &rt, std::string password, double workload) 9 | { 10 | jsi::Function promiseConstructor = rt.global().getPropertyAsFunction(rt, "Promise"); 11 | 12 | return promiseConstructor.callAsConstructor(rt, 13 | jsi::Function::createFromHostFunction( 14 | rt, 15 | jsi::PropNameID::forAscii(rt, "promiseArg"), 16 | 2, 17 | [password, workload, jsInvoker = jsInvoker_]( 18 | jsi::Runtime &runtime, 19 | const jsi::Value &thisValue, 20 | const jsi::Value *arguments, 21 | std::size_t count) -> jsi::Value 22 | { 23 | auto resolverValue = std::make_shared((arguments[0].asObject(runtime))); 24 | 25 | std::thread([password, workload, resolverValue = std::move(resolverValue), jsInvoker, &runtime]() 26 | { 27 | std::string hash = bcrypt::generateHash(password, workload); 28 | // Post back to JS thread 29 | jsInvoker->invokeAsync([resolverValue, hash, &runtime]() { 30 | resolverValue->asObject(runtime).asFunction(runtime).call(runtime, hash); 31 | }); }) 32 | .detach(); 33 | return jsi::Value::undefined(); 34 | }) 35 | 36 | ); 37 | } 38 | 39 | jsi::Value NativeBcryptCppTurboModule::validatePassword(jsi::Runtime &rt, std::string password, std::string hash) 40 | { 41 | jsi::Function promiseConstructor = rt.global().getPropertyAsFunction(rt, "Promise"); 42 | 43 | return promiseConstructor.callAsConstructor(rt, 44 | jsi::Function::createFromHostFunction( 45 | rt, 46 | jsi::PropNameID::forAscii(rt, "promiseArg"), 47 | 2, 48 | [password, hash, jsInvoker = jsInvoker_]( 49 | jsi::Runtime &runtime, 50 | const jsi::Value &thisValue, 51 | const jsi::Value *arguments, 52 | std::size_t count) -> jsi::Value 53 | { 54 | auto resolverValue = std::make_shared((arguments[0].asObject(runtime))); 55 | 56 | std::thread([password, hash, resolverValue = std::move(resolverValue), jsInvoker, &runtime]() 57 | { 58 | bool isValid = bcrypt::validatePassword(password, hash); 59 | // Post back to JS thread 60 | jsInvoker->invokeAsync([resolverValue, isValid, &runtime]() { 61 | resolverValue->asObject(runtime).asFunction(runtime).call(runtime, isValid); 62 | }); }) 63 | .detach(); 64 | return jsi::Value::undefined(); 65 | }) 66 | 67 | ); 68 | } 69 | std::string NativeBcryptCppTurboModule::generateHashSync(jsi::Runtime &rt, std::string password, double workload) 70 | { 71 | return bcrypt::generateHash(password, workload); 72 | } 73 | bool NativeBcryptCppTurboModule::validatePasswordSync(jsi::Runtime &rt, std::string password, std::string hash) 74 | { 75 | return bcrypt::validatePassword(password, hash); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /cpp/NativeBcryptCppTurboModule.h: -------------------------------------------------------------------------------- 1 | #if __has_include() 2 | #include 3 | #elif __has_include("RNBcryptCppSpecJSI.h") 4 | #include "RNBcryptCppSpecJSI.h" 5 | #endif 6 | 7 | #if __has_include("bcrypt/bcrypt.h") 8 | #include "bcrypt/bcrypt.h" 9 | #elif __has_include("bcrypt.h") 10 | #include "bcrypt.h" 11 | #endif 12 | #include 13 | #include 14 | 15 | namespace facebook::react { 16 | class NativeBcryptCppTurboModule: public NativeBcryptCppCxxSpec { 17 | public: 18 | NativeBcryptCppTurboModule(std::shared_ptr jsInvoker); 19 | 20 | jsi::Value generateHash(jsi::Runtime &rt, std::string password, double workload); 21 | jsi::Value validatePassword(jsi::Runtime &rt, std::string password, std::string hash); 22 | std::string generateHashSync(jsi::Runtime &rt, std::string password, double workload); 23 | bool validatePasswordSync(jsi::Runtime &rt, std::string password, std::string hash); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /cpp/bcrypt/bcrypt.cpp: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: bcrypt.c,v 1.31 2014/03/22 23:02:03 tedu Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1997 Niels Provos 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | /* This password hashing algorithm was designed by David Mazieres 20 | * and works as follows: 21 | * 22 | * 1. state := InitState () 23 | * 2. state := ExpandKey (state, salt, password) 24 | * 3. REPEAT rounds: 25 | * state := ExpandKey (state, 0, password) 26 | * state := ExpandKey (state, 0, salt) 27 | * 4. ctext := "OrpheanBeholderScryDoubt" 28 | * 5. REPEAT 64: 29 | * ctext := Encrypt_ECB (state, ctext); 30 | * 6. RETURN Concatenate (salt, ctext); 31 | * 32 | */ 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "node_blf.h" 41 | 42 | #include "bcrypt.h" 43 | #include "openbsd.h" 44 | 45 | #ifdef _WIN32 46 | #define snprintf _snprintf 47 | #endif 48 | 49 | //#if !defined(__APPLE__) && !defined(__MACH__) 50 | //#include "bsd/stdlib.h" 51 | //#endif 52 | 53 | /* This implementation is adaptable to current computing power. 54 | * You can have up to 2^31 rounds which should be enough for some 55 | * time to come. 56 | */ 57 | 58 | static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); 59 | static void decode_base64(u_int8_t *, u_int16_t, u_int8_t *); 60 | 61 | const static char* error = ":"; 62 | 63 | const static u_int8_t Base64Code[] = 64 | "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 65 | 66 | const static u_int8_t index_64[128] = { 67 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 68 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 69 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 70 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 71 | 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, 72 | 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, 73 | 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, 74 | 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 75 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 76 | 255, 255, 255, 255, 255, 255, 28, 29, 30, 77 | 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 78 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 79 | 51, 52, 53, 255, 255, 255, 255, 255 80 | }; 81 | #define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)]) 82 | 83 | static void 84 | decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data) 85 | { 86 | u_int8_t *bp = buffer; 87 | u_int8_t *p = data; 88 | u_int8_t c1, c2, c3, c4; 89 | while (bp < buffer + len) { 90 | c1 = CHAR64(*p); 91 | c2 = CHAR64(*(p + 1)); 92 | 93 | /* Invalid data */ 94 | if (c1 == 255 || c2 == 255) 95 | break; 96 | 97 | *bp++ = (c1 << 2) | ((c2 & 0x30) >> 4); 98 | if (bp >= buffer + len) 99 | break; 100 | 101 | c3 = CHAR64(*(p + 2)); 102 | if (c3 == 255) 103 | break; 104 | 105 | *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); 106 | if (bp >= buffer + len) 107 | break; 108 | 109 | c4 = CHAR64(*(p + 3)); 110 | if (c4 == 255) 111 | break; 112 | *bp++ = ((c3 & 0x03) << 6) | c4; 113 | 114 | p += 4; 115 | } 116 | } 117 | 118 | void 119 | encode_salt(char *salt, u_int8_t *csalt, char minor, u_int16_t clen, u_int8_t logr) 120 | { 121 | salt[0] = '$'; 122 | salt[1] = BCRYPT_VERSION; 123 | salt[2] = minor; 124 | salt[3] = '$'; 125 | 126 | // Max rounds are 31 127 | snprintf(salt + 4, 4, "%2.2u$", logr & 0x001F); 128 | 129 | encode_base64((u_int8_t *) salt + 7, csalt, clen); 130 | } 131 | 132 | 133 | /* Generates a salt for this version of crypt. 134 | Since versions may change. Keeping this here 135 | seems sensible. 136 | from: http://mail-index.netbsd.org/tech-crypto/2002/05/24/msg000204.html 137 | */ 138 | void 139 | bcrypt_gensalt(char minor, u_int8_t log_rounds, u_int8_t *seed, char *gsalt) 140 | { 141 | if (log_rounds < 4) 142 | log_rounds = 4; 143 | else if (log_rounds > 31) 144 | log_rounds = 31; 145 | 146 | encode_salt(gsalt, seed, minor, BCRYPT_MAXSALT, log_rounds); 147 | } 148 | 149 | /* We handle $Vers$log2(NumRounds)$salt+passwd$ 150 | i.e. $2$04$iwouldntknowwhattosayetKdJ6iFtacBqJdKe6aW7ou */ 151 | 152 | void 153 | node_bcrypt(const char *key, size_t key_len, const char *salt, char *encrypted) 154 | { 155 | blf_ctx state; 156 | u_int32_t rounds, i, k; 157 | u_int16_t j; 158 | u_int8_t salt_len, logr, minor; 159 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS+1] = "OrpheanBeholderScryDoubt"; 160 | u_int8_t csalt[BCRYPT_MAXSALT]; 161 | u_int32_t cdata[BCRYPT_BLOCKS]; 162 | int n; 163 | 164 | /* Discard "$" identifier */ 165 | salt++; 166 | 167 | if (*salt > BCRYPT_VERSION) { 168 | /* How do I handle errors ? Return ':' */ 169 | strcpy(encrypted, error); 170 | return; 171 | } 172 | 173 | /* Check for minor versions */ 174 | if (salt[1] != '$') { 175 | switch (salt[1]) { 176 | case 'a': /* 'ab' should not yield the same as 'abab' */ 177 | case 'b': /* cap input length at 72 bytes */ 178 | minor = salt[1]; 179 | salt++; 180 | break; 181 | default: 182 | strcpy(encrypted, error); 183 | return; 184 | } 185 | } else 186 | minor = 0; 187 | 188 | /* Discard version + "$" identifier */ 189 | salt += 2; 190 | 191 | if (salt[2] != '$') { 192 | /* Out of sync with passwd entry */ 193 | strcpy(encrypted, error); 194 | return; 195 | } 196 | 197 | /* Computer power doesn't increase linear, 2^x should be fine */ 198 | n = atoi(salt); 199 | if (n > 31 || n < 0) { 200 | strcpy(encrypted, error); 201 | return; 202 | } 203 | logr = (u_int8_t)n; 204 | if ((rounds = (u_int32_t) 1 << logr) < BCRYPT_MINROUNDS) { 205 | strcpy(encrypted, error); 206 | return; 207 | } 208 | 209 | /* Discard num rounds + "$" identifier */ 210 | salt += 3; 211 | 212 | if (strlen(salt) * 3 / 4 < BCRYPT_MAXSALT) { 213 | strcpy(encrypted, error); 214 | return; 215 | } 216 | 217 | /* We dont want the base64 salt but the raw data */ 218 | decode_base64(csalt, BCRYPT_MAXSALT, (u_int8_t *) salt); 219 | salt_len = BCRYPT_MAXSALT; 220 | if (minor <= 'a') 221 | key_len = (u_int8_t)(key_len + (minor >= 'a' ? 1 : 0)); 222 | else 223 | { 224 | /* cap key_len at the actual maximum supported 225 | * length here to avoid integer wraparound */ 226 | if (key_len > 72) 227 | key_len = 72; 228 | key_len++; /* include the NUL */ 229 | } 230 | 231 | 232 | /* Setting up S-Boxes and Subkeys */ 233 | Blowfish_initstate(&state); 234 | Blowfish_expandstate(&state, csalt, salt_len, 235 | (u_int8_t *) key, key_len); 236 | for (k = 0; k < rounds; k++) { 237 | Blowfish_expand0state(&state, (u_int8_t *) key, key_len); 238 | Blowfish_expand0state(&state, csalt, salt_len); 239 | } 240 | 241 | /* This can be precomputed later */ 242 | j = 0; 243 | for (i = 0; i < BCRYPT_BLOCKS; i++) 244 | cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); 245 | 246 | /* Now do the encryption */ 247 | for (k = 0; k < 64; k++) 248 | blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); 249 | 250 | for (i = 0; i < BCRYPT_BLOCKS; i++) { 251 | ciphertext[4 * i + 3] = cdata[i] & 0xff; 252 | cdata[i] = cdata[i] >> 8; 253 | ciphertext[4 * i + 2] = cdata[i] & 0xff; 254 | cdata[i] = cdata[i] >> 8; 255 | ciphertext[4 * i + 1] = cdata[i] & 0xff; 256 | cdata[i] = cdata[i] >> 8; 257 | ciphertext[4 * i + 0] = cdata[i] & 0xff; 258 | } 259 | 260 | i = 0; 261 | encrypted[i++] = '$'; 262 | encrypted[i++] = BCRYPT_VERSION; 263 | if (minor) 264 | encrypted[i++] = minor; 265 | encrypted[i++] = '$'; 266 | 267 | snprintf(encrypted + i, 4, "%2.2u$", logr & 0x001F); 268 | 269 | encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); 270 | encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext, 271 | 4 * BCRYPT_BLOCKS - 1); 272 | memset(&state, 0, sizeof(state)); 273 | memset(ciphertext, 0, sizeof(ciphertext)); 274 | memset(csalt, 0, sizeof(csalt)); 275 | memset(cdata, 0, sizeof(cdata)); 276 | } 277 | 278 | u_int32_t bcrypt_get_rounds(const char * hash) 279 | { 280 | /* skip past the leading "$" */ 281 | if (!hash || *(hash++) != '$') return 0; 282 | 283 | /* skip past version */ 284 | if (0 == (*hash++)) return 0; 285 | if (*hash && *hash != '$') hash++; 286 | if (*hash++ != '$') return 0; 287 | 288 | return atoi(hash); 289 | } 290 | 291 | static void 292 | encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len) 293 | { 294 | u_int8_t *bp = buffer; 295 | u_int8_t *p = data; 296 | u_int8_t c1, c2; 297 | while (p < data + len) { 298 | c1 = *p++; 299 | *bp++ = Base64Code[(c1 >> 2)]; 300 | c1 = (c1 & 0x03) << 4; 301 | if (p >= data + len) { 302 | *bp++ = Base64Code[c1]; 303 | break; 304 | } 305 | c2 = *p++; 306 | c1 |= (c2 >> 4) & 0x0f; 307 | *bp++ = Base64Code[c1]; 308 | c1 = (c2 & 0x0f) << 2; 309 | if (p >= data + len) { 310 | *bp++ = Base64Code[c1]; 311 | break; 312 | } 313 | c2 = *p++; 314 | c1 |= (c2 >> 6) & 0x03; 315 | *bp++ = Base64Code[c1]; 316 | *bp++ = Base64Code[c2 & 0x3f]; 317 | } 318 | *bp = '\0'; 319 | } 320 | 321 | std::string bcrypt::generateHash(const std::string &password, unsigned int rounds) { 322 | char salt[_SALT_LEN]; 323 | 324 | unsigned char seed[17]{}; 325 | arc4random_init(); 326 | 327 | arc4random_buf(seed, 16); 328 | 329 | bcrypt_gensalt('b', rounds, seed, salt); 330 | 331 | std::string hash(61, '\0'); 332 | node_bcrypt(password.c_str(), password.size(), salt, &hash[0]); 333 | hash.resize(60); 334 | return hash; 335 | } 336 | 337 | bool bcrypt::validatePassword(const std::string &password, const std::string &hash) { 338 | std::string got(61, '\0'); 339 | node_bcrypt(password.c_str(), password.size(), hash.c_str(), &got[0]); 340 | got.resize(60); 341 | return hash == got; 342 | } 343 | -------------------------------------------------------------------------------- /cpp/bcrypt/bcrypt.h: -------------------------------------------------------------------------------- 1 | #ifndef BCRYPT_H 2 | #define BCRYPT_H 3 | 4 | #include 5 | 6 | namespace bcrypt { 7 | 8 | std::string generateHash(const std::string & password , unsigned rounds = 10 ); 9 | 10 | bool validatePassword(const std::string & password, const std::string & hash); 11 | 12 | } 13 | 14 | #endif // BCRYPT_H 15 | -------------------------------------------------------------------------------- /cpp/bcrypt/blowfish.cpp: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: blowfish.c,v 1.18 2004/11/02 17:23:26 hshoexer Exp $ */ 2 | /* 3 | * Blowfish block cipher for OpenBSD 4 | * Copyright 1997 Niels Provos 5 | * All rights reserved. 6 | * 7 | * Implementation advice by David Mazieres . 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by Niels Provos. 20 | * 4. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | /* 36 | * This code is derived from section 14.3 and the given source 37 | * in section V of Applied Cryptography, second edition. 38 | * Blowfish is an unpatented fast block cipher designed by 39 | * Bruce Schneier. 40 | */ 41 | 42 | #include "node_blf.h" 43 | 44 | #undef inline 45 | #ifdef __GNUC__ 46 | #define inline __inline 47 | #else /* !__GNUC__ */ 48 | #define inline 49 | #endif /* !__GNUC__ */ 50 | 51 | /* Function for Feistel Networks */ 52 | 53 | #define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ 54 | + (s)[0x100 + (((x)>>16)&0xFF)]) \ 55 | ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ 56 | + (s)[0x300 + ( (x) &0xFF)]) 57 | 58 | #define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) 59 | 60 | void 61 | Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) 62 | { 63 | u_int32_t Xl; 64 | u_int32_t Xr; 65 | u_int32_t *s = c->S[0]; 66 | u_int32_t *p = c->P; 67 | 68 | Xl = *xl; 69 | Xr = *xr; 70 | 71 | Xl ^= p[0]; 72 | BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); 73 | BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); 74 | BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); 75 | BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); 76 | BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); 77 | BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); 78 | BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); 79 | BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); 80 | 81 | *xl = Xr ^ p[17]; 82 | *xr = Xl; 83 | } 84 | 85 | void 86 | Blowfish_decipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) 87 | { 88 | u_int32_t Xl; 89 | u_int32_t Xr; 90 | u_int32_t *s = c->S[0]; 91 | u_int32_t *p = c->P; 92 | 93 | Xl = *xl; 94 | Xr = *xr; 95 | 96 | Xl ^= p[17]; 97 | BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15); 98 | BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13); 99 | BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11); 100 | BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9); 101 | BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7); 102 | BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5); 103 | BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3); 104 | BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1); 105 | 106 | *xl = Xr ^ p[0]; 107 | *xr = Xl; 108 | } 109 | 110 | void 111 | Blowfish_initstate(blf_ctx *c) 112 | { 113 | /* P-box and S-box tables initialized with digits of Pi */ 114 | 115 | static const blf_ctx initstate = 116 | { { 117 | { 118 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 119 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 120 | 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 121 | 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 122 | 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 123 | 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 124 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 125 | 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 126 | 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 127 | 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 128 | 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 129 | 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 130 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 131 | 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 132 | 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 133 | 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 134 | 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 135 | 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 136 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 137 | 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 138 | 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 139 | 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 140 | 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 141 | 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 142 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 143 | 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 144 | 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 145 | 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 146 | 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 147 | 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 148 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 149 | 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 150 | 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 151 | 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 152 | 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 153 | 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 154 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 155 | 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 156 | 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 157 | 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 158 | 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 159 | 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 160 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 161 | 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 162 | 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 163 | 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 164 | 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 165 | 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 166 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 167 | 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 168 | 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 169 | 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 170 | 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 171 | 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 172 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 173 | 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 174 | 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 175 | 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 176 | 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 177 | 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 178 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 179 | 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 180 | 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 181 | 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, 182 | { 183 | 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 184 | 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 185 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 186 | 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 187 | 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 188 | 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 189 | 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 190 | 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 191 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 192 | 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 193 | 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 194 | 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 195 | 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 196 | 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 197 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 198 | 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 199 | 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 200 | 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 201 | 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 202 | 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 203 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 204 | 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 205 | 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 206 | 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 207 | 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 208 | 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 209 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 210 | 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 211 | 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 212 | 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 213 | 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 214 | 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 215 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 216 | 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 217 | 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 218 | 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 219 | 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 220 | 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 221 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 222 | 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 223 | 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 224 | 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 225 | 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 226 | 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 227 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 228 | 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 229 | 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 230 | 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 231 | 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 232 | 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 233 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 234 | 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 235 | 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 236 | 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 237 | 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 238 | 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 239 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 240 | 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 241 | 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 242 | 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 243 | 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 244 | 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 245 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 246 | 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, 247 | { 248 | 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 249 | 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 250 | 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 251 | 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 252 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 253 | 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 254 | 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 255 | 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 256 | 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 257 | 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 258 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 259 | 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 260 | 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 261 | 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 262 | 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 263 | 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 264 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 265 | 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 266 | 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 267 | 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 268 | 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 269 | 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 270 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 271 | 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 272 | 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 273 | 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 274 | 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 275 | 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 276 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 277 | 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 278 | 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 279 | 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 280 | 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 281 | 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 282 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 283 | 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 284 | 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 285 | 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 286 | 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 287 | 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 288 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 289 | 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 290 | 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 291 | 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 292 | 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 293 | 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 294 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 295 | 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 296 | 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 297 | 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 298 | 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 299 | 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 300 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 301 | 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 302 | 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 303 | 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 304 | 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 305 | 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 306 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 307 | 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 308 | 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 309 | 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 310 | 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 311 | 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, 312 | { 313 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 314 | 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 315 | 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 316 | 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 317 | 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 318 | 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 319 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 320 | 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 321 | 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 322 | 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 323 | 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 324 | 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 325 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 326 | 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 327 | 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 328 | 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 329 | 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 330 | 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 331 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 332 | 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 333 | 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 334 | 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 335 | 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 336 | 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 337 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 338 | 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 339 | 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 340 | 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 341 | 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 342 | 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 343 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 344 | 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 345 | 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 346 | 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 347 | 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 348 | 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 349 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 350 | 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 351 | 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 352 | 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 353 | 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 354 | 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 355 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 356 | 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 357 | 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 358 | 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 359 | 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 360 | 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 361 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 362 | 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 363 | 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 364 | 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 365 | 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 366 | 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 367 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 368 | 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 369 | 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 370 | 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 371 | 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 372 | 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 373 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 374 | 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 375 | 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 376 | 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} 377 | }, 378 | { 379 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 380 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 381 | 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 382 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 383 | 0x9216d5d9, 0x8979fb1b 384 | } }; 385 | 386 | *c = initstate; 387 | } 388 | 389 | u_int32_t 390 | Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes, 391 | u_int16_t *current) 392 | { 393 | u_int8_t i; 394 | u_int16_t j; 395 | u_int32_t temp; 396 | 397 | temp = 0x00000000; 398 | j = *current; 399 | 400 | for (i = 0; i < 4; i++, j++) { 401 | if (j >= databytes) 402 | j = 0; 403 | temp = (temp << 8) | data[j]; 404 | } 405 | 406 | *current = j; 407 | return temp; 408 | } 409 | 410 | void 411 | Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes) 412 | { 413 | u_int16_t i; 414 | u_int16_t j; 415 | u_int16_t k; 416 | u_int32_t temp; 417 | u_int32_t datal; 418 | u_int32_t datar; 419 | 420 | j = 0; 421 | for (i = 0; i < BLF_N + 2; i++) { 422 | /* Extract 4 int8 to 1 int32 from keystream */ 423 | temp = Blowfish_stream2word(key, keybytes, &j); 424 | c->P[i] = c->P[i] ^ temp; 425 | } 426 | 427 | j = 0; 428 | datal = 0x00000000; 429 | datar = 0x00000000; 430 | for (i = 0; i < BLF_N + 2; i += 2) { 431 | Blowfish_encipher(c, &datal, &datar); 432 | 433 | c->P[i] = datal; 434 | c->P[i + 1] = datar; 435 | } 436 | 437 | for (i = 0; i < 4; i++) { 438 | for (k = 0; k < 256; k += 2) { 439 | Blowfish_encipher(c, &datal, &datar); 440 | 441 | c->S[i][k] = datal; 442 | c->S[i][k + 1] = datar; 443 | } 444 | } 445 | } 446 | 447 | 448 | void 449 | Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes, 450 | const u_int8_t *key, u_int16_t keybytes) 451 | { 452 | u_int16_t i; 453 | u_int16_t j; 454 | u_int16_t k; 455 | u_int32_t temp; 456 | u_int32_t datal; 457 | u_int32_t datar; 458 | 459 | j = 0; 460 | for (i = 0; i < BLF_N + 2; i++) { 461 | /* Extract 4 int8 to 1 int32 from keystream */ 462 | temp = Blowfish_stream2word(key, keybytes, &j); 463 | c->P[i] = c->P[i] ^ temp; 464 | } 465 | 466 | j = 0; 467 | datal = 0x00000000; 468 | datar = 0x00000000; 469 | for (i = 0; i < BLF_N + 2; i += 2) { 470 | datal ^= Blowfish_stream2word(data, databytes, &j); 471 | datar ^= Blowfish_stream2word(data, databytes, &j); 472 | Blowfish_encipher(c, &datal, &datar); 473 | 474 | c->P[i] = datal; 475 | c->P[i + 1] = datar; 476 | } 477 | 478 | for (i = 0; i < 4; i++) { 479 | for (k = 0; k < 256; k += 2) { 480 | datal ^= Blowfish_stream2word(data, databytes, &j); 481 | datar ^= Blowfish_stream2word(data, databytes, &j); 482 | Blowfish_encipher(c, &datal, &datar); 483 | 484 | c->S[i][k] = datal; 485 | c->S[i][k + 1] = datar; 486 | } 487 | } 488 | 489 | } 490 | 491 | void 492 | blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len) 493 | { 494 | /* Initialize S-boxes and subkeys with Pi */ 495 | Blowfish_initstate(c); 496 | 497 | /* Transform S-boxes and subkeys with key */ 498 | Blowfish_expand0state(c, k, len); 499 | } 500 | 501 | void 502 | blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks) 503 | { 504 | u_int32_t *d; 505 | u_int16_t i; 506 | 507 | d = data; 508 | for (i = 0; i < blocks; i++) { 509 | Blowfish_encipher(c, d, d + 1); 510 | d += 2; 511 | } 512 | } 513 | 514 | void 515 | blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks) 516 | { 517 | u_int32_t *d; 518 | u_int16_t i; 519 | 520 | d = data; 521 | for (i = 0; i < blocks; i++) { 522 | Blowfish_decipher(c, d, d + 1); 523 | d += 2; 524 | } 525 | } 526 | 527 | void 528 | blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) 529 | { 530 | u_int32_t l, r; 531 | u_int32_t i; 532 | 533 | for (i = 0; i < len; i += 8) { 534 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; 535 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; 536 | Blowfish_encipher(c, &l, &r); 537 | data[0] = l >> 24 & 0xff; 538 | data[1] = l >> 16 & 0xff; 539 | data[2] = l >> 8 & 0xff; 540 | data[3] = l & 0xff; 541 | data[4] = r >> 24 & 0xff; 542 | data[5] = r >> 16 & 0xff; 543 | data[6] = r >> 8 & 0xff; 544 | data[7] = r & 0xff; 545 | data += 8; 546 | } 547 | } 548 | 549 | void 550 | blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) 551 | { 552 | u_int32_t l, r; 553 | u_int32_t i; 554 | 555 | for (i = 0; i < len; i += 8) { 556 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; 557 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; 558 | Blowfish_decipher(c, &l, &r); 559 | data[0] = l >> 24 & 0xff; 560 | data[1] = l >> 16 & 0xff; 561 | data[2] = l >> 8 & 0xff; 562 | data[3] = l & 0xff; 563 | data[4] = r >> 24 & 0xff; 564 | data[5] = r >> 16 & 0xff; 565 | data[6] = r >> 8 & 0xff; 566 | data[7] = r & 0xff; 567 | data += 8; 568 | } 569 | } 570 | 571 | void 572 | blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len) 573 | { 574 | u_int32_t l, r; 575 | u_int32_t i, j; 576 | 577 | for (i = 0; i < len; i += 8) { 578 | for (j = 0; j < 8; j++) 579 | data[j] ^= iv[j]; 580 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; 581 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; 582 | Blowfish_encipher(c, &l, &r); 583 | data[0] = l >> 24 & 0xff; 584 | data[1] = l >> 16 & 0xff; 585 | data[2] = l >> 8 & 0xff; 586 | data[3] = l & 0xff; 587 | data[4] = r >> 24 & 0xff; 588 | data[5] = r >> 16 & 0xff; 589 | data[6] = r >> 8 & 0xff; 590 | data[7] = r & 0xff; 591 | iv = data; 592 | data += 8; 593 | } 594 | } 595 | 596 | void 597 | blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len) 598 | { 599 | u_int32_t l, r; 600 | u_int8_t *iv; 601 | u_int32_t i, j; 602 | 603 | iv = data + len - 16; 604 | data = data + len - 8; 605 | for (i = len - 8; i >= 8; i -= 8) { 606 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; 607 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; 608 | Blowfish_decipher(c, &l, &r); 609 | data[0] = l >> 24 & 0xff; 610 | data[1] = l >> 16 & 0xff; 611 | data[2] = l >> 8 & 0xff; 612 | data[3] = l & 0xff; 613 | data[4] = r >> 24 & 0xff; 614 | data[5] = r >> 16 & 0xff; 615 | data[6] = r >> 8 & 0xff; 616 | data[7] = r & 0xff; 617 | for (j = 0; j < 8; j++) 618 | data[j] ^= iv[j]; 619 | iv -= 8; 620 | data -= 8; 621 | } 622 | l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; 623 | r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; 624 | Blowfish_decipher(c, &l, &r); 625 | data[0] = l >> 24 & 0xff; 626 | data[1] = l >> 16 & 0xff; 627 | data[2] = l >> 8 & 0xff; 628 | data[3] = l & 0xff; 629 | data[4] = r >> 24 & 0xff; 630 | data[5] = r >> 16 & 0xff; 631 | data[6] = r >> 8 & 0xff; 632 | data[7] = r & 0xff; 633 | for (j = 0; j < 8; j++) 634 | data[j] ^= iva[j]; 635 | } 636 | 637 | #if 0 638 | void 639 | report(u_int32_t data[], u_int16_t len) 640 | { 641 | u_int16_t i; 642 | for (i = 0; i < len; i += 2) 643 | printf("Block %0hd: %08lx %08lx.\n", 644 | i / 2, data[i], data[i + 1]); 645 | } 646 | void 647 | main(void) 648 | { 649 | 650 | blf_ctx c; 651 | char key[] = "AAAAA"; 652 | char key2[] = "abcdefghijklmnopqrstuvwxyz"; 653 | 654 | u_int32_t data[10]; 655 | u_int32_t data2[] = 656 | {0x424c4f57l, 0x46495348l}; 657 | 658 | u_int16_t i; 659 | 660 | /* First test */ 661 | for (i = 0; i < 10; i++) 662 | data[i] = i; 663 | 664 | blf_key(&c, (u_int8_t *) key, 5); 665 | blf_enc(&c, data, 5); 666 | blf_dec(&c, data, 1); 667 | blf_dec(&c, data + 2, 4); 668 | printf("Should read as 0 - 9.\n"); 669 | report(data, 10); 670 | 671 | /* Second test */ 672 | blf_key(&c, (u_int8_t *) key2, strlen(key2)); 673 | blf_enc(&c, data2, 1); 674 | printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); 675 | report(data2, 2); 676 | blf_dec(&c, data2, 1); 677 | report(data2, 2); 678 | } 679 | #endif -------------------------------------------------------------------------------- /cpp/bcrypt/node_blf.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */ 2 | /* 3 | * Blowfish - a fast block cipher designed by Bruce Schneier 4 | * 5 | * Copyright 1997 Niels Provos 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. All advertising materials mentioning features or use of this software 17 | * must display the following acknowledgement: 18 | * This product includes software developed by Niels Provos. 19 | * 4. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _NODE_BLF_H_ 35 | #define _NODE_BLF_H_ 36 | 37 | #include 38 | 39 | /* Solaris compatibility */ 40 | #ifdef __sun 41 | #define u_int8_t uint8_t 42 | #define u_int16_t uint16_t 43 | #define u_int32_t uint32_t 44 | #define u_int64_t uint64_t 45 | #endif 46 | 47 | #ifdef _WIN32 48 | #define u_int8_t unsigned __int8 49 | #define u_int16_t unsigned __int16 50 | #define u_int32_t unsigned __int32 51 | #define u_int64_t unsigned __int64 52 | #endif 53 | 54 | /* Windows ssize_t compatibility */ 55 | #if defined(_WIN32) || defined(_WIN64) 56 | # if defined(_WIN64) 57 | typedef __int64 LONG_PTR; 58 | # else 59 | typedef long LONG_PTR; 60 | # endif 61 | typedef LONG_PTR SSIZE_T; 62 | typedef SSIZE_T ssize_t; 63 | #endif 64 | 65 | /* z/OS compatibility */ 66 | #ifdef __MVS__ 67 | typedef unsigned char u_int8_t; 68 | typedef unsigned short u_int16_t; 69 | typedef unsigned int u_int32_t; 70 | typedef unsigned long long u_int64_t; 71 | #endif 72 | 73 | #define BCRYPT_VERSION '2' 74 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ 75 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ 76 | #define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ 77 | 78 | /* Schneier specifies a maximum key length of 56 bytes. 79 | * This ensures that every key bit affects every cipher 80 | * bit. However, the subkeys can hold up to 72 bytes. 81 | * Warning: For normal blowfish encryption only 56 bytes 82 | * of the key affect all cipherbits. 83 | */ 84 | 85 | #define BLF_N 16 /* Number of Subkeys */ 86 | #define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ 87 | #define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */ 88 | 89 | #define _PASSWORD_LEN 128 /* max length, not counting NUL */ 90 | #define _SALT_LEN 32 /* max length */ 91 | 92 | /* Blowfish context */ 93 | typedef struct BlowfishContext { 94 | u_int32_t S[4][256]; /* S-Boxes */ 95 | u_int32_t P[BLF_N + 2]; /* Subkeys */ 96 | } blf_ctx; 97 | 98 | /* Raw access to customized Blowfish 99 | * blf_key is just: 100 | * Blowfish_initstate( state ) 101 | * Blowfish_expand0state( state, key, keylen ) 102 | */ 103 | 104 | void Blowfish_encipher(blf_ctx *, u_int32_t *, u_int32_t *); 105 | void Blowfish_decipher(blf_ctx *, u_int32_t *, u_int32_t *); 106 | void Blowfish_initstate(blf_ctx *); 107 | void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t); 108 | void Blowfish_expandstate 109 | (blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t); 110 | 111 | /* Standard Blowfish */ 112 | 113 | void blf_key(blf_ctx *, const u_int8_t *, u_int16_t); 114 | void blf_enc(blf_ctx *, u_int32_t *, u_int16_t); 115 | void blf_dec(blf_ctx *, u_int32_t *, u_int16_t); 116 | 117 | void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t); 118 | void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t); 119 | 120 | void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); 121 | void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); 122 | 123 | /* Converts u_int8_t to u_int32_t */ 124 | u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *); 125 | 126 | /* bcrypt functions*/ 127 | void bcrypt_gensalt(char, u_int8_t, u_int8_t*, char *); 128 | void node_bcrypt(const char *, size_t key_len, const char *, char *); 129 | void encode_salt(char *, u_int8_t *, char, u_int16_t, u_int8_t); 130 | u_int32_t bcrypt_get_rounds(const char *); 131 | 132 | #endif -------------------------------------------------------------------------------- /cpp/bcrypt/openbsd.h: -------------------------------------------------------------------------------- 1 | #ifndef ARC4RANDOM_H_INCLUDED 2 | #define ARC4RANDOM_H_INCLUDED 3 | 4 | #include /* srand, rand */ 5 | #include 6 | #include 7 | #include 8 | 9 | inline 10 | void arc4random_buf(void *buf, size_t nbytes) 11 | { 12 | 13 | for( size_t n = 0; n < nbytes; ++ n) 14 | ((char*)(buf))[n] = rand() %256; 15 | } 16 | 17 | inline 18 | void arc4random_init(void) 19 | { 20 | srand( (unsigned int) time(NULL)); 21 | } 22 | 23 | 24 | #endif // ARC4RANDOM_H_INCLUDED 25 | -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | # Cocoapods 1.15 introduced a bug which break the build. We will remove the upper 7 | # bound in the template on Cocoapods with next React Native release. 8 | gem 'cocoapods', '>= 1.13', '< 1.15' 9 | gem 'activesupport', '>= 6.1.7.5', '< 7.1.0' 10 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). 2 | 3 | # Getting Started 4 | 5 | >**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. 6 | 7 | ## Step 1: Start the Metro Server 8 | 9 | First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. 10 | 11 | To start Metro, run the following command from the _root_ of your React Native project: 12 | 13 | ```bash 14 | # using npm 15 | npm start 16 | 17 | # OR using Yarn 18 | yarn start 19 | ``` 20 | 21 | ## Step 2: Start your Application 22 | 23 | Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: 24 | 25 | ### For Android 26 | 27 | ```bash 28 | # using npm 29 | npm run android 30 | 31 | # OR using Yarn 32 | yarn android 33 | ``` 34 | 35 | ### For iOS 36 | 37 | ```bash 38 | # using npm 39 | npm run ios 40 | 41 | # OR using Yarn 42 | yarn ios 43 | ``` 44 | 45 | If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. 46 | 47 | This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. 48 | 49 | ## Step 3: Modifying your App 50 | 51 | Now that you have successfully run the app, let's modify it. 52 | 53 | 1. Open `App.tsx` in your text editor of choice and edit some lines. 54 | 2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! 55 | 56 | For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! 57 | 58 | ## Congratulations! :tada: 59 | 60 | You've successfully run and modified your React Native App. :partying_face: 61 | 62 | ### Now what? 63 | 64 | - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). 65 | - If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). 66 | 67 | # Troubleshooting 68 | 69 | If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. 70 | 71 | # Learn More 72 | 73 | To learn more about React Native, take a look at the following resources: 74 | 75 | - [React Native Website](https://reactnative.dev) - learn more about React Native. 76 | - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. 77 | - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. 78 | - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. 79 | - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. 80 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "org.jetbrains.kotlin.android" 3 | apply plugin: "com.facebook.react" 4 | 5 | /** 6 | * This is the configuration block to customize your React Native Android app. 7 | * By default you don't need to apply any configuration, just uncomment the lines you need. 8 | */ 9 | react { 10 | /* Folders */ 11 | // The root of your project, i.e. where "package.json" lives. Default is '..' 12 | // root = file("../") 13 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 14 | // reactNativeDir = file("../node_modules/react-native") 15 | // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen 16 | // codegenDir = file("../node_modules/@react-native/codegen") 17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 18 | // cliFile = file("../node_modules/react-native/cli.js") 19 | 20 | /* Variants */ 21 | // The list of variants to that are debuggable. For those we're going to 22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 24 | // debuggableVariants = ["liteDebug", "prodDebug"] 25 | 26 | /* Bundling */ 27 | // A list containing the node command and its flags. Default is just 'node'. 28 | // nodeExecutableAndArgs = ["node"] 29 | // 30 | // The command to run when bundling. By default is 'bundle' 31 | // bundleCommand = "ram-bundle" 32 | // 33 | // The path to the CLI configuration file. Default is empty. 34 | // bundleConfig = file(../rn-cli.config.js) 35 | // 36 | // The name of the generated asset file containing your JS bundle 37 | // bundleAssetName = "MyApplication.android.bundle" 38 | // 39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 40 | // entryFile = file("../js/MyApplication.android.js") 41 | // 42 | // A list of extra flags to pass to the 'bundle' commands. 43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 44 | // extraPackagerArgs = [] 45 | 46 | /* Hermes Commands */ 47 | // The hermes compiler command to run. By default it is 'hermesc' 48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 49 | // 50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 51 | // hermesFlags = ["-O", "-output-source-map"] 52 | } 53 | 54 | /** 55 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 56 | */ 57 | def enableProguardInReleaseBuilds = false 58 | 59 | /** 60 | * The preferred build flavor of JavaScriptCore (JSC) 61 | * 62 | * For example, to use the international variant, you can use: 63 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 64 | * 65 | * The international variant includes ICU i18n library and necessary data 66 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 67 | * give correct results when using with locales other than en-US. Note that 68 | * this variant is about 6MiB larger per architecture than default. 69 | */ 70 | def jscFlavor = 'org.webkit:android-jsc:+' 71 | 72 | android { 73 | ndkVersion rootProject.ext.ndkVersion 74 | buildToolsVersion rootProject.ext.buildToolsVersion 75 | compileSdk rootProject.ext.compileSdkVersion 76 | 77 | namespace "bcryptcpp.example" 78 | defaultConfig { 79 | applicationId "bcryptcpp.example" 80 | minSdkVersion rootProject.ext.minSdkVersion 81 | targetSdkVersion rootProject.ext.targetSdkVersion 82 | versionCode 1 83 | versionName "1.0" 84 | } 85 | signingConfigs { 86 | debug { 87 | storeFile file('debug.keystore') 88 | storePassword 'android' 89 | keyAlias 'androiddebugkey' 90 | keyPassword 'android' 91 | } 92 | } 93 | buildTypes { 94 | debug { 95 | signingConfig signingConfigs.debug 96 | } 97 | release { 98 | // Caution! In production, you need to generate your own keystore file. 99 | // see https://reactnative.dev/docs/signed-apk-android. 100 | signingConfig signingConfigs.debug 101 | minifyEnabled enableProguardInReleaseBuilds 102 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 103 | } 104 | } 105 | } 106 | 107 | dependencies { 108 | // The version of react-native is set by the React Native Gradle Plugin 109 | implementation("com.facebook.react:react-android") 110 | 111 | if (hermesEnabled.toBoolean()) { 112 | implementation("com.facebook.react:hermes-android") 113 | } else { 114 | implementation jscFlavor 115 | } 116 | } 117 | 118 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 119 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/bcryptcpp/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package bcryptcpp.example 2 | 3 | import com.facebook.react.ReactActivity 4 | import com.facebook.react.ReactActivityDelegate 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate 7 | 8 | class MainActivity : ReactActivity() { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | override fun getMainComponentName(): String = "BcryptCppExample" 15 | 16 | /** 17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] 18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] 19 | */ 20 | override fun createReactActivityDelegate(): ReactActivityDelegate = 21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) 22 | } 23 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/bcryptcpp/example/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package bcryptcpp.example 2 | 3 | import android.app.Application 4 | import com.facebook.react.PackageList 5 | import com.facebook.react.ReactApplication 6 | import com.facebook.react.ReactHost 7 | import com.facebook.react.ReactNativeHost 8 | import com.facebook.react.ReactPackage 9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load 10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost 11 | import com.facebook.react.defaults.DefaultReactNativeHost 12 | import com.facebook.soloader.SoLoader 13 | 14 | class MainApplication : Application(), ReactApplication { 15 | 16 | override val reactNativeHost: ReactNativeHost = 17 | object : DefaultReactNativeHost(this) { 18 | override fun getPackages(): List = 19 | PackageList(this).packages.apply { 20 | // Packages that cannot be autolinked yet can be added manually here, for example: 21 | // add(MyReactNativePackage()) 22 | } 23 | 24 | override fun getJSMainModuleName(): String = "index" 25 | 26 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG 27 | 28 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED 29 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED 30 | } 31 | 32 | override val reactHost: ReactHost 33 | get() = getDefaultReactHost(applicationContext, reactNativeHost) 34 | 35 | override fun onCreate() { 36 | super.onCreate() 37 | SoLoader.init(this, false) 38 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 39 | // If you opted-in for the New Architecture, we load the native entry point for this app. 40 | load() 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 22 | 23 | 24 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | BcryptCppExample 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | buildToolsVersion = "34.0.0" 4 | minSdkVersion = 23 5 | compileSdkVersion = 34 6 | targetSdkVersion = 34 7 | ndkVersion = "26.1.10909125" 8 | kotlinVersion = "1.9.22" 9 | } 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | dependencies { 15 | classpath("com.android.tools.build:gradle") 16 | classpath("com.facebook.react:react-native-gradle-plugin") 17 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") 18 | } 19 | } 20 | 21 | apply plugin: "com.facebook.react.rootproject" 22 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=false 26 | 27 | # Use this property to specify which architecture you want to build. 28 | # You can also override it from the CLI using 29 | # ./gradlew -PreactNativeArchitectures=x86_64 30 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 31 | 32 | # Use this property to enable support to the new architecture. 33 | # This will allow you to use TurboModules and the Fabric render in 34 | # your application. You should enable this flag either if you want 35 | # to write custom TurboModules/Fabric components OR use libraries that 36 | # are providing them. 37 | newArchEnabled=true 38 | 39 | # Use this property to enable or disable the Hermes JS engine. 40 | # If set to false, you will be using JSC instead. 41 | hermesEnabled=true 42 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anday013/react-native-bcrypt-cpp/b99e0c9bb4ae47699248200e51db3d8d3aebeafe/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'bcryptcpp.example' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/@react-native/gradle-plugin') 5 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BcryptCppExample", 3 | "displayName": "BcryptCppExample" 4 | } 5 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { getConfig } = require('react-native-builder-bob/babel-config'); 3 | const pkg = require('../package.json'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | 7 | module.exports = getConfig( 8 | { 9 | presets: ['module:@react-native/babel-preset'], 10 | }, 11 | { root, pkg } 12 | ); 13 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import App from './src/App'; 3 | import { name as appName } from './app.json'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample.xcodeproj/xcshareddata/xcschemes/BcryptCppExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"BcryptCppExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | return [self bundleURL]; 20 | } 21 | 22 | - (NSURL *)bundleURL 23 | { 24 | #if DEBUG 25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 26 | #else 27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 28 | #endif 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | BcryptCppExample 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | 30 | NSAllowsArbitraryLoads 31 | 32 | NSAllowsLocalNetworking 33 | 34 | 35 | NSLocationWhenInUseUsageDescription 36 | 37 | UILaunchStoryboardName 38 | LaunchScreen 39 | UIRequiredDeviceCapabilities 40 | 41 | arm64 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | UIViewControllerBasedStatusBarAppearance 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyAccessedAPITypes 6 | 7 | 8 | NSPrivacyAccessedAPIType 9 | NSPrivacyAccessedAPICategoryFileTimestamp 10 | NSPrivacyAccessedAPITypeReasons 11 | 12 | C617.1 13 | 14 | 15 | 16 | NSPrivacyAccessedAPIType 17 | NSPrivacyAccessedAPICategoryUserDefaults 18 | NSPrivacyAccessedAPITypeReasons 19 | 20 | CA92.1 21 | 22 | 23 | 24 | NSPrivacyAccessedAPIType 25 | NSPrivacyAccessedAPICategorySystemBootTime 26 | NSPrivacyAccessedAPITypeReasons 27 | 28 | 35F9.1 29 | 30 | 31 | 32 | NSPrivacyCollectedDataTypes 33 | 34 | NSPrivacyTracking 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExampleTests/BcryptCppExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface BcryptCppExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation BcryptCppExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /example/ios/BcryptCppExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/File.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // BcryptCppExample 4 | // 5 | 6 | import Foundation 7 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | ENV['RCT_NEW_ARCH_ENABLED'] = '1' 2 | 3 | # Resolve react_native_pods.rb with node to allow for hoisting 4 | require Pod::Executable.execute_command('node', ['-p', 5 | 'require.resolve( 6 | "react-native/scripts/react_native_pods.rb", 7 | {paths: [process.argv[1]]}, 8 | )', __dir__]).strip 9 | 10 | platform :ios, min_ios_version_supported 11 | prepare_react_native_project! 12 | 13 | linkage = ENV['USE_FRAMEWORKS'] 14 | if linkage != nil 15 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 16 | use_frameworks! :linkage => linkage.to_sym 17 | end 18 | 19 | target 'BcryptCppExample' do 20 | config = use_native_modules! 21 | 22 | use_react_native!( 23 | :path => config[:reactNativePath], 24 | # An absolute path to your application root. 25 | :app_path => "#{Pod::Config.instance.installation_root}/.." 26 | ) 27 | 28 | target 'BcryptCppExampleTests' do 29 | inherit! :complete 30 | # Pods for testing 31 | end 32 | 33 | post_install do |installer| 34 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 35 | react_native_post_install( 36 | installer, 37 | config[:reactNativePath], 38 | :mac_catalyst_enabled => false, 39 | # :ccache_enabled => true 40 | ) 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /example/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'react-native', 3 | }; 4 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { getDefaultConfig } = require('@react-native/metro-config'); 3 | const { getConfig } = require('react-native-builder-bob/metro-config'); 4 | const pkg = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | /** 9 | * Metro configuration 10 | * https://facebook.github.io/metro/docs/configuration 11 | * 12 | * @type {import('metro-config').MetroConfig} 13 | */ 14 | module.exports = getConfig(getDefaultConfig(__dirname), { 15 | root, 16 | pkg, 17 | project: __dirname, 18 | }); 19 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-bcrypt-cpp-example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "build:android": "react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"", 10 | "build:ios": "react-native build-ios --scheme BcryptCppExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\"" 11 | }, 12 | "dependencies": { 13 | "react": "18.2.0", 14 | "react-native": "0.74.5", 15 | "react-native-randombytes": "^3.6.1" 16 | }, 17 | "devDependencies": { 18 | "@babel/core": "^7.20.0", 19 | "@babel/preset-env": "^7.20.0", 20 | "@babel/runtime": "^7.20.0", 21 | "@react-native/babel-preset": "0.74.87", 22 | "@react-native/metro-config": "0.74.87", 23 | "@react-native/typescript-config": "0.74.87", 24 | "react-native-builder-bob": "^0.29.0" 25 | }, 26 | "engines": { 27 | "node": ">=18" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pkg = require('../package.json'); 3 | 4 | module.exports = { 5 | project: { 6 | ios: { 7 | automaticPodsInstallation: true, 8 | }, 9 | }, 10 | dependencies: { 11 | [pkg.name]: { 12 | root: path.join(__dirname, '..'), 13 | }, 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useState } from 'react'; 2 | import { 3 | ActivityIndicator, 4 | SafeAreaView, 5 | StyleSheet, 6 | Text, 7 | TouchableOpacity, 8 | View, 9 | } from 'react-native'; 10 | import { generateHash, validatePassword } from 'react-native-bcrypt-cpp'; 11 | import { MovingRectangle } from './MovingRectangle'; 12 | import { 13 | genSaltSync, 14 | hashSync as generateHashJS, 15 | compareSync as validatePasswordJS, 16 | } from './bcryptjs'; 17 | 18 | const workload = 12; 19 | const password = 'asdcds-sdjakl12313841skdnanczdeioaj'; 20 | 21 | export default function App() { 22 | const [hash, setHash] = useState( 23 | '$2a$12$a7aUL27hsWw0x2V8pJfK4eUNeANOCtAEOxJA6V4N3FIOfgoZuJz2W' 24 | ); 25 | const [timeTaken, setTimeTaken] = useState(0); 26 | const [isValid, setIsValid] = useState(); 27 | const [loading, setLoading] = useState(false); 28 | 29 | const measureTime = useCallback(async function (fn: () => T): Promise { 30 | setLoading(true); 31 | const start = performance.now(); 32 | const res = await fn(); 33 | const end = performance.now(); 34 | const _timeTaken = end - start; 35 | console.log('Time taken :', _timeTaken, 'ms'); 36 | setTimeTaken(_timeTaken); 37 | setLoading(false); 38 | return res; 39 | }, []); 40 | 41 | return ( 42 | 43 | 44 | Bcrypt Performance Test 45 | 46 | Password: 47 | {password} 48 | Generated Hash: 49 | {hash} 50 | Time taken: 51 | 52 | {Math.round((timeTaken / 1000) * 100) / 100} s 53 | 54 | Is Valid: 55 | 56 | {isValid === undefined 57 | ? 'Not checked' 58 | : isValid 59 | ? '✅ Yes' 60 | : '❌ No'} 61 | 62 | 63 | 64 | 65 | 66 | 67 | {loading && ( 68 | 69 | )} 70 | 71 | 72 | 73 | JavaScript 74 | { 77 | const generatedHash = await measureTime(() => 78 | generateHashJS(password, genSaltSync(workload)) 79 | ); 80 | console.log('Generated hash JS:', generatedHash); 81 | setHash(generatedHash); 82 | }} 83 | > 84 | Generate Hash 85 | 86 | { 89 | const _isValid = await measureTime(() => 90 | validatePasswordJS(password, hash) 91 | ); 92 | console.log('is Valid JS:', _isValid); 93 | setIsValid(_isValid); 94 | }} 95 | > 96 | Validate Password 97 | 98 | 99 | 100 | 101 | C++ 102 | { 105 | const generatedHash = await measureTime(() => 106 | generateHash(password, workload) 107 | ); 108 | console.log('Generated hash:', generatedHash); 109 | setHash(generatedHash); 110 | }} 111 | > 112 | Generate Hash 113 | 114 | { 117 | const _isValid = await measureTime(() => 118 | validatePassword(password, hash) 119 | ); 120 | console.log('isValid', _isValid); 121 | setIsValid(_isValid); 122 | }} 123 | > 124 | Validate Password 125 | 126 | 127 | 128 | 129 | ); 130 | } 131 | 132 | const styles = StyleSheet.create({ 133 | container: { 134 | flex: 1, 135 | padding: 20, 136 | justifyContent: 'space-around', 137 | backgroundColor: '#f0f4f7', 138 | }, 139 | header: { 140 | fontSize: 28, 141 | fontWeight: 'bold', 142 | textAlign: 'center', 143 | marginBottom: 30, 144 | color: '#333', 145 | }, 146 | resultContainer: { 147 | marginBottom: 20, 148 | padding: 15, 149 | borderRadius: 10, 150 | backgroundColor: '#fff', 151 | shadowColor: '#000', 152 | shadowOpacity: 0.1, 153 | shadowRadius: 10, 154 | shadowOffset: { width: 0, height: 4 }, 155 | elevation: 5, 156 | }, 157 | resultText: { 158 | fontSize: 18, 159 | fontWeight: '600', 160 | marginVertical: 5, 161 | color: '#555', 162 | }, 163 | hashText: { 164 | fontSize: 16, 165 | color: '#6200ee', 166 | fontWeight: '500', 167 | marginVertical: 5, 168 | }, 169 | timeText: { 170 | fontSize: 20, 171 | fontWeight: '700', 172 | color: '#6200ee', 173 | marginVertical: 5, 174 | }, 175 | validText: { 176 | fontSize: 20, 177 | fontWeight: '700', 178 | marginVertical: 5, 179 | }, 180 | buttonContainer: { 181 | flexDirection: 'row', 182 | justifyContent: 'space-between', 183 | }, 184 | column: { 185 | flex: 1, 186 | marginHorizontal: 10, 187 | }, 188 | columnHeader: { 189 | fontSize: 20, 190 | fontWeight: 'bold', 191 | textAlign: 'center', 192 | marginBottom: 15, 193 | color: '#6200ee', 194 | }, 195 | button: { 196 | backgroundColor: '#6200ee', 197 | paddingVertical: 12, 198 | paddingHorizontal: 20, 199 | borderRadius: 30, 200 | marginBottom: 10, 201 | alignItems: 'center', 202 | shadowColor: '#6200ee', 203 | shadowOpacity: 0.3, 204 | shadowRadius: 10, 205 | shadowOffset: { width: 0, height: 4 }, 206 | elevation: 5, 207 | }, 208 | buttonText: { 209 | color: '#fff', 210 | fontSize: 16, 211 | fontWeight: '600', 212 | textAlign: 'center', 213 | }, 214 | loader: { 215 | marginVertical: 20, 216 | }, 217 | }); 218 | -------------------------------------------------------------------------------- /example/src/MovingRectangle.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useRef } from 'react'; 2 | import { 3 | Animated, 4 | Dimensions, 5 | Easing, 6 | StyleSheet, 7 | Text, 8 | View, 9 | } from 'react-native'; 10 | 11 | export const MovingRectangle = () => { 12 | const animationValue = useRef(new Animated.Value(0)).current; 13 | const colorAnimation = useRef(new Animated.Value(0)).current; 14 | 15 | // Get the full width of the screen 16 | const screenWidth = Dimensions.get('window').width; 17 | 18 | useEffect(() => { 19 | const animate = () => { 20 | Animated.loop( 21 | Animated.parallel([ 22 | Animated.sequence([ 23 | Animated.timing(animationValue, { 24 | toValue: -200, 25 | duration: 600, 26 | easing: Easing.inOut(Easing.quad), 27 | useNativeDriver: false, 28 | }), 29 | Animated.timing(animationValue, { 30 | toValue: 0, 31 | duration: 600, 32 | easing: Easing.inOut(Easing.quad), 33 | useNativeDriver: false, 34 | }), 35 | ]), 36 | Animated.sequence([ 37 | Animated.timing(colorAnimation, { 38 | toValue: 1, 39 | duration: 600, 40 | easing: Easing.inOut(Easing.quad), 41 | useNativeDriver: false, 42 | }), 43 | Animated.timing(colorAnimation, { 44 | toValue: 0, 45 | duration: 600, 46 | easing: Easing.inOut(Easing.quad), 47 | useNativeDriver: false, 48 | }), 49 | ]), 50 | ]) 51 | ).start(); 52 | }; 53 | 54 | animate(); 55 | }, [animationValue, colorAnimation, screenWidth]); 56 | 57 | const backgroundColor = colorAnimation.interpolate({ 58 | inputRange: [0, 1], 59 | outputRange: ['blue', 'green'], 60 | }); 61 | 62 | return ( 63 | 64 | 70 | It stops when JS Thread blocked 71 | 72 | 73 | ); 74 | }; 75 | 76 | const styles = StyleSheet.create({ 77 | container: { 78 | justifyContent: 'center', 79 | alignItems: 'center', 80 | marginVertical: 20, 81 | width: '100%', 82 | }, 83 | rectangle: { 84 | width: 150, 85 | height: 150, 86 | backgroundColor: 'blue', 87 | borderRadius: 10, 88 | marginLeft: 200, 89 | justifyContent: 'center', 90 | alignItems: 'center', 91 | }, 92 | text: { 93 | color: 'white', 94 | fontSize: 16, 95 | fontWeight: 'bold', 96 | textAlign: 'center', 97 | }, 98 | }); 99 | -------------------------------------------------------------------------------- /example/src/bcryptjs.ts: -------------------------------------------------------------------------------- 1 | // Taken from https://github.com/shaneMangudi/bcrypt-nodejs/blob/master/bCrypt.js 2 | // Only for benchmarking purposes 3 | // @ts-nocheck 4 | /* eslint-disable */ 5 | 6 | import { randomBytes } from 'react-native-randombytes'; 7 | 8 | var BCRYPT_SALT_LEN = 16; 9 | 10 | var GENSALT_DEFAULT_LOG2_ROUNDS = 10; 11 | var BLOWFISH_NUM_ROUNDS = 16; 12 | 13 | var MAX_EXECUTION_TIME = 100; 14 | var P_orig = [ 15 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 16 | 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 17 | 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b, 18 | ]; 19 | var S_orig = [ 20 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 21 | 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 22 | 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 23 | 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 24 | 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 25 | 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 26 | 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 27 | 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 28 | 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 29 | 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 30 | 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1, 31 | 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 32 | 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 33 | 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 34 | 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, 35 | 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 36 | 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 37 | 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 38 | 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, 39 | 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 40 | 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 41 | 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 42 | 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, 43 | 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 44 | 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 45 | 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 46 | 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8, 47 | 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 48 | 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 49 | 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 50 | 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0, 51 | 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 52 | 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 53 | 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 54 | 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, 55 | 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 56 | 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 57 | 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 58 | 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, 59 | 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 60 | 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 61 | 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 62 | 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a, 0x4b7a70e9, 0xb5b32944, 63 | 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 64 | 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 65 | 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 66 | 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 0x4cdd2086, 0x8470eb26, 67 | 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 68 | 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 69 | 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 70 | 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 0xd19113f9, 0x7ca92ff6, 71 | 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 72 | 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 73 | 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 74 | 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 0xde9a771f, 0xd9930810, 75 | 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 76 | 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 77 | 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 78 | 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 0x71dff89e, 0x10314e55, 79 | 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 80 | 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 81 | 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 82 | 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 0xc6150eba, 0x94e2ea78, 83 | 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 84 | 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 85 | 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 86 | 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 0x1521b628, 0x29076170, 87 | 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 88 | 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 89 | 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 90 | 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 0x9b540b19, 0x875fa099, 91 | 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 92 | 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 93 | 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 94 | 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 0x5d4a14d9, 0xe864b7e3, 95 | 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 96 | 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 97 | 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 98 | 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 0x095bbf00, 0xad19489d, 99 | 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 100 | 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 101 | 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 102 | 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 0x9e447a2e, 0xc3453484, 103 | 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 104 | 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 105 | 0xe6e39f2b, 0xdb83adf7, 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 106 | 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 107 | 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 108 | 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 109 | 0x7fac6dd0, 0x31cb8504, 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 110 | 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 111 | 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 112 | 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 113 | 0xee39d7ab, 0x3b124e8b, 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 114 | 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 115 | 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 116 | 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 117 | 0x5ef47e1c, 0x9029317c, 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 118 | 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 119 | 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 120 | 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 121 | 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 122 | 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 123 | 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 124 | 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 125 | 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 126 | 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 127 | 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 128 | 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 129 | 0x12754ccc, 0x782ef11c, 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 130 | 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 131 | 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 132 | 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 133 | 0x7745ae04, 0xd736fccc, 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 134 | 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 135 | 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 136 | 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 137 | 0x8cd55591, 0xc902de4c, 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 138 | 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 139 | 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 140 | 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 141 | 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 142 | 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 143 | 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 144 | 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 145 | 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 146 | 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 147 | 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0, 148 | 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 149 | 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 150 | 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, 151 | 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 152 | 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 153 | 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 154 | 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, 155 | 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 156 | 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 157 | 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 158 | 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, 159 | 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 160 | 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 161 | 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 162 | 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5, 163 | 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 164 | 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 165 | 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 166 | 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd, 167 | 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 168 | 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 169 | 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 170 | 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc, 171 | 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 172 | 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 173 | 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 174 | 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, 175 | 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 176 | 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 177 | 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 178 | 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, 179 | 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 180 | 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 181 | 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 182 | 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 183 | 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 184 | 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 185 | 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 186 | 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 187 | 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 188 | 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 189 | 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 190 | 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6, 191 | ]; 192 | var bf_crypt_ciphertext = [ 193 | 0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274, 194 | ]; 195 | var base64_code = [ 196 | '.', 197 | '/', 198 | 'A', 199 | 'B', 200 | 'C', 201 | 'D', 202 | 'E', 203 | 'F', 204 | 'G', 205 | 'H', 206 | 'I', 207 | 'J', 208 | 'K', 209 | 'L', 210 | 'M', 211 | 'N', 212 | 'O', 213 | 'P', 214 | 'Q', 215 | 'R', 216 | 'S', 217 | 'T', 218 | 'U', 219 | 'V', 220 | 'W', 221 | 'X', 222 | 'Y', 223 | 'Z', 224 | 'a', 225 | 'b', 226 | 'c', 227 | 'd', 228 | 'e', 229 | 'f', 230 | 'g', 231 | 'h', 232 | 'i', 233 | 'j', 234 | 'k', 235 | 'l', 236 | 'm', 237 | 'n', 238 | 'o', 239 | 'p', 240 | 'q', 241 | 'r', 242 | 's', 243 | 't', 244 | 'u', 245 | 'v', 246 | 'w', 247 | 'x', 248 | 'y', 249 | 'z', 250 | '0', 251 | '1', 252 | '2', 253 | '3', 254 | '4', 255 | '5', 256 | '6', 257 | '7', 258 | '8', 259 | '9', 260 | ]; 261 | var index_64 = [ 262 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 263 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 264 | -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 265 | -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 266 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 267 | 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 268 | 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1, 269 | ]; 270 | 271 | function getByte(c) { 272 | var ret = 0; 273 | try { 274 | var b = c.charCodeAt(0); 275 | } catch (err) { 276 | b = c; 277 | } 278 | if (b > 127) { 279 | return -128 + (b % 128); 280 | } else { 281 | return b; 282 | } 283 | } 284 | 285 | function encode_base64(d, len) { 286 | var off = 0; 287 | var rs = []; 288 | var c1; 289 | var c2; 290 | if (len <= 0 || len > d.length) throw 'Invalid len'; 291 | while (off < len) { 292 | c1 = d[off++] & 0xff; 293 | rs.push(base64_code[(c1 >> 2) & 0x3f]); 294 | c1 = (c1 & 0x03) << 4; 295 | if (off >= len) { 296 | rs.push(base64_code[c1 & 0x3f]); 297 | break; 298 | } 299 | c2 = d[off++] & 0xff; 300 | c1 |= (c2 >> 4) & 0x0f; 301 | rs.push(base64_code[c1 & 0x3f]); 302 | c1 = (c2 & 0x0f) << 2; 303 | if (off >= len) { 304 | rs.push(base64_code[c1 & 0x3f]); 305 | break; 306 | } 307 | c2 = d[off++] & 0xff; 308 | c1 |= (c2 >> 6) & 0x03; 309 | rs.push(base64_code[c1 & 0x3f]); 310 | rs.push(base64_code[c2 & 0x3f]); 311 | } 312 | return rs.join(''); 313 | } 314 | 315 | function char64(x) { 316 | var code = x.charCodeAt(0); 317 | if (code < 0 || code > index_64.length) { 318 | return -1; 319 | } 320 | return index_64[code]; 321 | } 322 | 323 | function decode_base64(s, maxolen) { 324 | var off = 0; 325 | var slen = s.length; 326 | var olen = 0; 327 | var rs = []; 328 | var c1, c2, c3, c4, o; 329 | if (maxolen <= 0) throw 'Invalid maxolen'; 330 | while (off < slen - 1 && olen < maxolen) { 331 | c1 = char64(s.charAt(off++)); 332 | c2 = char64(s.charAt(off++)); 333 | if (c1 == -1 || c2 == -1) { 334 | break; 335 | } 336 | o = getByte(c1 << 2); 337 | o |= (c2 & 0x30) >> 4; 338 | rs.push(String.fromCharCode(o)); 339 | if (++olen >= maxolen || off >= slen) { 340 | break; 341 | } 342 | c3 = char64(s.charAt(off++)); 343 | if (c3 == -1) { 344 | break; 345 | } 346 | o = getByte((c2 & 0x0f) << 4); 347 | o |= (c3 & 0x3c) >> 2; 348 | rs.push(String.fromCharCode(o)); 349 | if (++olen >= maxolen || off >= slen) { 350 | break; 351 | } 352 | c4 = char64(s.charAt(off++)); 353 | o = getByte((c3 & 0x03) << 6); 354 | o |= c4; 355 | rs.push(String.fromCharCode(o)); 356 | ++olen; 357 | } 358 | var ret = []; 359 | for (off = 0; off < olen; off++) { 360 | ret.push(getByte(rs[off])); 361 | } 362 | return ret; 363 | } 364 | 365 | function encipher(lr, off, P, S) { 366 | var i; 367 | var n; 368 | var l = lr[off]; 369 | var r = lr[off + 1]; 370 | 371 | l ^= P[0]; 372 | for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) { 373 | // Feistel substitution on left word 374 | n = S[(l >> 24) & 0xff]; 375 | n += S[0x100 | ((l >> 16) & 0xff)]; 376 | n ^= S[0x200 | ((l >> 8) & 0xff)]; 377 | n += S[0x300 | (l & 0xff)]; 378 | r ^= n ^ P[++i]; 379 | 380 | // Feistel substitution on right word 381 | n = S[(r >> 24) & 0xff]; 382 | n += S[0x100 | ((r >> 16) & 0xff)]; 383 | n ^= S[0x200 | ((r >> 8) & 0xff)]; 384 | n += S[0x300 | (r & 0xff)]; 385 | l ^= n ^ P[++i]; 386 | } 387 | lr[off] = r ^ P[BLOWFISH_NUM_ROUNDS + 1]; 388 | lr[off + 1] = l; 389 | return lr; 390 | } 391 | 392 | function streamtoword(data, offp) { 393 | var i; 394 | var word = 0; 395 | for (i = 0; i < 4; i++) { 396 | word = (word << 8) | (data[offp] & 0xff); 397 | offp = (offp + 1) % data.length; 398 | } 399 | return { key: word, offp: offp }; 400 | } 401 | 402 | function key(key, P, S) { 403 | var i; 404 | var offp = 0; 405 | var lr = new Array(0x00000000, 0x00000000); 406 | var plen = P.length; 407 | var slen = S.length; 408 | 409 | for (i = 0; i < plen; i++) { 410 | var sw = streamtoword(key, offp); 411 | offp = sw.offp; 412 | P[i] = P[i] ^ sw.key; 413 | } 414 | for (i = 0; i < plen; i += 2) { 415 | lr = encipher(lr, 0, P, S); 416 | P[i] = lr[0]; 417 | P[i + 1] = lr[1]; 418 | } 419 | 420 | for (i = 0; i < slen; i += 2) { 421 | lr = encipher(lr, 0, P, S); 422 | S[i] = lr[0]; 423 | S[i + 1] = lr[1]; 424 | } 425 | } 426 | 427 | function ekskey(data, key, P, S) { 428 | var i; 429 | var offp = 0; 430 | var lr = new Array(0x00000000, 0x00000000); 431 | var plen = P.length; 432 | var slen = S.length; 433 | var sw; 434 | 435 | for (i = 0; i < plen; i++) { 436 | sw = streamtoword(key, offp); 437 | offp = sw.offp; 438 | P[i] = P[i] ^ sw.key; 439 | } 440 | offp = 0; 441 | for (i = 0; i < plen; i += 2) { 442 | sw = streamtoword(data, offp); 443 | offp = sw.offp; 444 | lr[0] ^= sw.key; 445 | 446 | sw = streamtoword(data, offp); 447 | offp = sw.offp; 448 | lr[1] ^= sw.key; 449 | 450 | lr = encipher(lr, 0, P, S); 451 | P[i] = lr[0]; 452 | P[i + 1] = lr[1]; 453 | } 454 | for (i = 0; i < slen; i += 2) { 455 | sw = streamtoword(data, offp); 456 | offp = sw.offp; 457 | lr[0] ^= sw.key; 458 | 459 | sw = streamtoword(data, offp); 460 | offp = sw.offp; 461 | lr[1] ^= sw.key; 462 | 463 | lr = encipher(lr, 0, P, S); 464 | S[i] = lr[0]; 465 | S[i + 1] = lr[1]; 466 | } 467 | } 468 | 469 | function crypt_raw( 470 | password: any, 471 | salt: any, 472 | log_rounds: number, 473 | progress?: (progress: number) => void 474 | ) { 475 | var rounds; 476 | var j; 477 | var cdata = bf_crypt_ciphertext.slice(); 478 | var clen = cdata.length; 479 | var one_percent; 480 | 481 | if (log_rounds < 4 || log_rounds > 31) throw 'Bad number of rounds'; 482 | if (salt.length !== BCRYPT_SALT_LEN) throw 'Bad salt length'; 483 | 484 | rounds = 1 << log_rounds; 485 | one_percent = Math.floor(rounds / 100) + 1; 486 | 487 | var P = P_orig.slice(); 488 | var S = S_orig.slice(); 489 | 490 | ekskey(salt, password, P, S); 491 | 492 | var i = 0; 493 | 494 | while (true) { 495 | if (i < rounds) { 496 | var start = new Date(); 497 | for (; i < rounds; ) { 498 | i = i + 1; 499 | key(password, P, S); 500 | key(salt, P, S); 501 | if (i % one_percent === 0 && progress) { 502 | progress(i / one_percent); 503 | } 504 | if (new Date() - start > MAX_EXECUTION_TIME) { 505 | break; 506 | } 507 | } 508 | } else { 509 | for (i = 0; i < 64; i++) { 510 | for (j = 0; j < clen >> 1; j++) { 511 | var lr = encipher(cdata, j << 1, P, S); 512 | } 513 | } 514 | var ret = []; 515 | for (i = 0; i < clen; i++) { 516 | ret.push(getByte((cdata[i] >> 24) & 0xff)); 517 | ret.push(getByte((cdata[i] >> 16) & 0xff)); 518 | ret.push(getByte((cdata[i] >> 8) & 0xff)); 519 | ret.push(getByte(cdata[i] & 0xff)); 520 | } 521 | return ret; 522 | } 523 | } 524 | } 525 | 526 | function hashpw( 527 | password: string, 528 | salt: string, 529 | progress?: (progress: number) => void 530 | ) { 531 | var real_salt; 532 | var passwordb = []; 533 | var saltb = []; 534 | var hashed = []; 535 | var minor = String.fromCharCode(0); 536 | var rounds = 0; 537 | var off = 0; 538 | 539 | if (salt.charAt(0) != '$' || salt.charAt(1) != '2') 540 | throw 'Invalid salt version'; 541 | if (salt.charAt(2) == '$') off = 3; 542 | else { 543 | minor = salt.charAt(2); 544 | if (minor != 'a' || salt.charAt(3) != '$') throw 'Invalid salt revision'; 545 | off = 4; 546 | } 547 | 548 | // Extract number of rounds 549 | if (salt.charAt(off + 2) > '$') throw 'Missing salt rounds'; 550 | var r1 = parseInt(salt.substring(off, off + 1)) * 10; 551 | var r2 = parseInt(salt.substring(off + 1, off + 2)); 552 | rounds = r1 + r2; 553 | real_salt = salt.substring(off + 3, off + 25); 554 | password = password + (minor >= 'a' ? '\x00' : ''); 555 | 556 | var buf = new Buffer(password); 557 | for (var r = 0; r < buf.length; r++) { 558 | passwordb.push(buf[r]); 559 | } 560 | saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); 561 | hashed = crypt_raw(passwordb, saltb, rounds, progress); 562 | 563 | var rs = []; 564 | rs.push('$2'); 565 | if (minor >= 'a') rs.push(minor); 566 | rs.push('$'); 567 | if (rounds < 10) rs.push('0'); 568 | rs.push(rounds.toString()); 569 | rs.push('$'); 570 | rs.push(encode_base64(saltb, saltb.length)); 571 | rs.push(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1)); 572 | 573 | return rs.join(''); 574 | } 575 | 576 | function gensalt(rounds: number) { 577 | var iteration_count = rounds; 578 | if (iteration_count < 4 || iteration_count > 31) { 579 | iteration_count = GENSALT_DEFAULT_LOG2_ROUNDS; 580 | } 581 | var output = []; 582 | output.push('$2a$'); 583 | if (iteration_count < 10) output.push('0'); 584 | output.push(iteration_count.toString()); 585 | output.push('$'); 586 | 587 | var rand_buf; 588 | try { 589 | rand_buf = randomBytes(BCRYPT_SALT_LEN); 590 | } catch (ex) { 591 | throw ex; 592 | } 593 | 594 | output.push(encode_base64(rand_buf, BCRYPT_SALT_LEN)); 595 | return output.join(''); 596 | } 597 | 598 | function genSaltSync(rounds: number) { 599 | /* 600 | rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10) 601 | seed_length - [OPTIONAL] - RAND_bytes wants a length. to make that a bit flexible, you can specify a seed_length. (default - 20) 602 | */ 603 | if (!rounds) { 604 | rounds = GENSALT_DEFAULT_LOG2_ROUNDS; 605 | } 606 | return gensalt(rounds); 607 | } 608 | 609 | function hashSync( 610 | data: string, 611 | salt: string, 612 | progress?: (progress: number) => void 613 | ) { 614 | /* 615 | data - [REQUIRED] - the data to be encrypted. 616 | salt - [REQUIRED] - the salt to be used in encryption. 617 | */ 618 | return hashpw(data, salt, progress); 619 | } 620 | 621 | function compareSync(data: string, encrypted: string) { 622 | /* 623 | data - [REQUIRED] - data to compare. 624 | encrypted - [REQUIRED] - data to be compared to. 625 | */ 626 | 627 | var encrypted_length = encrypted.length; 628 | 629 | if (encrypted_length !== 60) { 630 | return false; 631 | } 632 | 633 | var same = true; 634 | var hash_data = hashSync(data, encrypted.substr(0, encrypted_length - 31)); 635 | var hash_data_length = hash_data.length; 636 | 637 | same = hash_data_length === encrypted_length; 638 | 639 | var max_length = 640 | hash_data_length < encrypted_length ? hash_data_length : encrypted_length; 641 | 642 | // to prevent timing attacks, should check entire string 643 | // don't exit after found to be false 644 | for (var i = 0; i < max_length; ++i) { 645 | if ( 646 | hash_data_length >= i && 647 | encrypted_length >= i && 648 | hash_data[i] !== encrypted[i] 649 | ) { 650 | same = false; 651 | } 652 | } 653 | 654 | return same; 655 | } 656 | 657 | function getRounds(encrypted: string) { 658 | //encrypted - [REQUIRED] - hash from which the number of rounds used should be extracted. 659 | return Number(encrypted.split('$')[2]); 660 | } 661 | 662 | export { compareSync, genSaltSync, getRounds, hashSync }; 663 | -------------------------------------------------------------------------------- /ios/onLoad.mm: -------------------------------------------------------------------------------- 1 | #import "NativeBcryptCppTurboModule.h" 2 | #import 3 | #import 4 | 5 | @interface OnLoad: NSObject 6 | @end 7 | 8 | @implementation OnLoad 9 | 10 | +(void) load { 11 | facebook::react::registerCxxModuleToGlobalModuleMap( 12 | std::string(facebook::react::NativeBcryptCppTurboModule::kModuleName), 13 | [](std::shared_ptr jsInvoker) { 14 | return std::make_shared(jsInvoker); 15 | } 16 | ); 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /lefthook.yml: -------------------------------------------------------------------------------- 1 | pre-commit: 2 | parallel: true 3 | commands: 4 | lint: 5 | glob: "*.{js,ts,jsx,tsx}" 6 | run: npx eslint {staged_files} 7 | types: 8 | glob: "*.{js,ts, jsx, tsx}" 9 | run: npx tsc 10 | commit-msg: 11 | parallel: true 12 | commands: 13 | commitlint: 14 | run: npx commitlint --edit 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-bcrypt-cpp", 3 | "version": "0.2.3", 4 | "description": "Next-gen React Native library for Bcrypt hashing, using pure C++ with Turbo Modules and multithreading for superior performance", 5 | "source": "./src/index.tsx", 6 | "main": "./lib/commonjs/index.js", 7 | "types": "./lib/typescript/commonjs/src/index.d.ts", 8 | "module": "./lib/module/index.js", 9 | "files": [ 10 | "src", 11 | "lib", 12 | "android", 13 | "ios", 14 | "cpp", 15 | "*.podspec", 16 | "!ios/build", 17 | "!android/build", 18 | "!android/gradle", 19 | "!android/gradlew", 20 | "!android/gradlew.bat", 21 | "!android/local.properties", 22 | "!**/__tests__", 23 | "!**/__fixtures__", 24 | "!**/__mocks__", 25 | "!**/.*" 26 | ], 27 | "scripts": { 28 | "example": "yarn workspace react-native-bcrypt-cpp-example", 29 | "test": "jest", 30 | "typecheck": "tsc", 31 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 32 | "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib", 33 | "prepare": "bob build", 34 | "release": "release-it" 35 | }, 36 | "keywords": [ 37 | "react-native", 38 | "ios", 39 | "android", 40 | "bcrypt", 41 | "hashing", 42 | "cpp", 43 | "jsi", 44 | "new", 45 | "architecture", 46 | "new-architecture", 47 | "turbo", 48 | "modules", 49 | "multithreading", 50 | "performance", 51 | "security", 52 | "password", 53 | "hash", 54 | "hasher", 55 | "turbo-modules", 56 | "react-native-jsi", 57 | "react-native-new-architecture", 58 | "react-native-library", 59 | "react-native-module", 60 | "react-native-turbo", 61 | "react-native-turbo-modules", 62 | "react-native-multithreading", 63 | "react-native-performance", 64 | "react-native-security", 65 | "react-native-password", 66 | "react-native-hashing", 67 | "react-native-bcrypt", 68 | "react-native-cpp", 69 | "react-native-turbo-cpp", 70 | "react-native-turbo-modules-cpp", 71 | "react-native-multithreading-cpp", 72 | "react-native-performance-cpp", 73 | "react-native-security-cpp", 74 | "react-native-password-cpp", 75 | "react-native-hashing-cpp", 76 | "react-native-bcrypt-cpp", 77 | "react-native-bcrypt-cpp-library", 78 | "react-native-bcrypt-cpp-module", 79 | "react-native-bcrypt-cpp-turbo", 80 | "react-native-bcrypt-cpp-turbo-modules", 81 | "react-native-bcrypt-cpp-multithreading", 82 | "react-native-bcrypt-cpp-performance", 83 | "react-native-bcrypt-cpp-security", 84 | "react-native-bcrypt-cpp-password", 85 | "react-native-bcrypt-cpp-hashing" 86 | ], 87 | "repository": { 88 | "type": "git", 89 | "url": "https://github.com/anday013/react-native-bcrypt-cpp.git" 90 | }, 91 | "author": "anday013 (https://github.com/anday013)", 92 | "license": "MIT", 93 | "bugs": { 94 | "url": "https://github.com/anday013/react-native-bcrypt-cpp/issues" 95 | }, 96 | "homepage": "https://github.com/anday013/react-native-bcrypt-cpp#readme", 97 | "publishConfig": { 98 | "registry": "https://registry.npmjs.org/" 99 | }, 100 | "devDependencies": { 101 | "@commitlint/config-conventional": "^17.0.2", 102 | "@evilmartians/lefthook": "^1.5.0", 103 | "@react-native/eslint-config": "^0.73.1", 104 | "@release-it/conventional-changelog": "^5.0.0", 105 | "@types/jest": "^29.5.5", 106 | "@types/react": "^18.2.44", 107 | "commitlint": "^17.0.2", 108 | "del-cli": "^5.1.0", 109 | "eslint": "^8.51.0", 110 | "eslint-config-prettier": "^9.0.0", 111 | "eslint-plugin-prettier": "^5.0.1", 112 | "jest": "^29.7.0", 113 | "prettier": "^3.0.3", 114 | "react": "18.2.0", 115 | "react-native": "0.74.5", 116 | "react-native-builder-bob": "^0.29.0", 117 | "release-it": "^15.0.0", 118 | "turbo": "^1.10.7", 119 | "typescript": "^5.2.2" 120 | }, 121 | "resolutions": { 122 | "@types/react": "^18.2.44" 123 | }, 124 | "peerDependencies": { 125 | "react": "*", 126 | "react-native": "*" 127 | }, 128 | "workspaces": [ 129 | "example" 130 | ], 131 | "packageManager": "yarn@3.6.1", 132 | "jest": { 133 | "preset": "react-native", 134 | "modulePathIgnorePatterns": [ 135 | "/example/node_modules", 136 | "/lib/" 137 | ] 138 | }, 139 | "commitlint": { 140 | "extends": [ 141 | "@commitlint/config-conventional" 142 | ] 143 | }, 144 | "release-it": { 145 | "git": { 146 | "commitMessage": "chore: release ${version}", 147 | "tagName": "v${version}" 148 | }, 149 | "npm": { 150 | "publish": true 151 | }, 152 | "github": { 153 | "release": true 154 | }, 155 | "plugins": { 156 | "@release-it/conventional-changelog": { 157 | "preset": "angular" 158 | } 159 | } 160 | }, 161 | "eslintConfig": { 162 | "root": true, 163 | "extends": [ 164 | "@react-native", 165 | "prettier" 166 | ], 167 | "rules": { 168 | "react/react-in-jsx-scope": "off", 169 | "prettier/prettier": [ 170 | "error", 171 | { 172 | "quoteProps": "consistent", 173 | "singleQuote": true, 174 | "tabWidth": 2, 175 | "trailingComma": "es5", 176 | "useTabs": false 177 | } 178 | ] 179 | } 180 | }, 181 | "eslintIgnore": [ 182 | "node_modules/", 183 | "lib/" 184 | ], 185 | "prettier": { 186 | "quoteProps": "consistent", 187 | "singleQuote": true, 188 | "tabWidth": 2, 189 | "trailingComma": "es5", 190 | "useTabs": false 191 | }, 192 | "react-native-builder-bob": { 193 | "source": "src", 194 | "output": "lib", 195 | "targets": [ 196 | [ 197 | "commonjs", 198 | { 199 | "esm": true 200 | } 201 | ], 202 | [ 203 | "module", 204 | { 205 | "esm": true 206 | } 207 | ], 208 | [ 209 | "typescript", 210 | { 211 | "project": "tsconfig.build.json", 212 | "esm": true 213 | } 214 | ] 215 | ] 216 | }, 217 | "codegenConfig": { 218 | "name": "RNBcryptCppSpec", 219 | "type": "modules", 220 | "jsSrcsDir": "src" 221 | }, 222 | "create-react-native-library": { 223 | "type": "module-new", 224 | "languages": "cpp", 225 | "version": "0.40.0" 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /react-native-bcrypt-cpp.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' 5 | 6 | Pod::Spec.new do |s| 7 | s.name = "react-native-bcrypt-cpp" 8 | s.version = package["version"] 9 | s.summary = package["description"] 10 | s.homepage = package["homepage"] 11 | s.license = package["license"] 12 | s.authors = package["author"] 13 | 14 | s.platforms = { :ios => min_ios_version_supported } 15 | s.source = { :git => "https://github.com/anday013/react-native-bcrypt-cpp.git", :tag => "#{s.version}" } 16 | 17 | s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}" 18 | 19 | # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. 20 | # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. 21 | if respond_to?(:install_modules_dependencies, true) 22 | install_modules_dependencies(s) 23 | else 24 | s.dependency "React-Core" 25 | 26 | # Don't install the dependencies when we run `pod install` in the old architecture. 27 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then 28 | s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" 29 | s.pod_target_xcconfig = { 30 | "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", 31 | "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1", 32 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" 33 | } 34 | s.dependency "React-Codegen" 35 | s.dependency "RCT-Folly" 36 | s.dependency "RCTRequired" 37 | s.dependency "RCTTypeSafety" 38 | s.dependency "ReactCommon/turbomodule/core" 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependency: { 3 | platforms: { 4 | android: { 5 | cxxModuleCMakeListsModuleName: 'react-native-bcrypt-cpp', 6 | cxxModuleCMakeListsPath: 'CMakeLists.txt', 7 | cxxModuleHeaderName: 'NativeBcryptCppTurboModule', 8 | }, 9 | }, 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /src/NativeBcryptCpp.ts: -------------------------------------------------------------------------------- 1 | import type { TurboModule } from 'react-native'; 2 | import { TurboModuleRegistry } from 'react-native'; 3 | 4 | export interface Spec extends TurboModule { 5 | generateHash: (password: string, workload: number) => Promise; 6 | validatePassword: (password: string, hash: string) => Promise; 7 | generateHashSync: (password: string, workload: number) => string; 8 | validatePasswordSync: (password: string, hash: string) => boolean; 9 | } 10 | 11 | export default TurboModuleRegistry.getEnforcing('BcryptCpp'); 12 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import BcryptCpp from './NativeBcryptCpp'; 2 | 3 | export function generateHashSync(password: string, workload: number): string { 4 | return BcryptCpp.generateHashSync(password, workload); 5 | } 6 | 7 | export function validatePasswordSync(password: string, hash: string): boolean { 8 | return BcryptCpp.validatePasswordSync(password, hash); 9 | } 10 | 11 | export function generateHash( 12 | password: string, 13 | workload: number 14 | ): Promise { 15 | return BcryptCpp.generateHash(password, workload); 16 | } 17 | 18 | export function validatePassword( 19 | password: string, 20 | hash: string 21 | ): Promise { 22 | return BcryptCpp.validatePassword(password, hash); 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "exclude": ["example", "lib"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": ".", 4 | "paths": { 5 | "react-native-bcrypt-cpp": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react-jsx", 12 | "lib": ["ESNext"], 13 | "module": "ESNext", 14 | "moduleResolution": "Bundler", 15 | "noEmit": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUncheckedIndexedAccess": true, 21 | "noUnusedLocals": true, 22 | "noUnusedParameters": true, 23 | "resolveJsonModule": true, 24 | "skipLibCheck": true, 25 | "strict": true, 26 | "target": "ESNext", 27 | "verbatimModuleSyntax": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "pipeline": { 4 | "build:android": { 5 | "inputs": [ 6 | "package.json", 7 | "android", 8 | "!android/build", 9 | "src/*.ts", 10 | "src/*.tsx", 11 | "example/package.json", 12 | "example/android", 13 | "!example/android/.gradle", 14 | "!example/android/build", 15 | "!example/android/app/build" 16 | ], 17 | "outputs": [] 18 | }, 19 | "build:ios": { 20 | "inputs": [ 21 | "package.json", 22 | "*.podspec", 23 | "ios", 24 | "src/*.ts", 25 | "src/*.tsx", 26 | "example/package.json", 27 | "example/ios", 28 | "!example/ios/build", 29 | "!example/ios/Pods" 30 | ], 31 | "outputs": [] 32 | } 33 | } 34 | } 35 | --------------------------------------------------------------------------------