Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a86360fef7 |
33
.circleci/build-wheel.sh
Executable file
33
.circleci/build-wheel.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash -ex
|
||||
|
||||
cd /test
|
||||
|
||||
echo "Building for ${PLATFORM}"
|
||||
|
||||
PYBIN="/opt/python/${PYTHON}/bin"
|
||||
|
||||
mkdir -p /test/wheelhouse.final
|
||||
|
||||
"${PYBIN}"/python -m venv .venv
|
||||
|
||||
.venv/bin/pip install -U pip wheel cffi
|
||||
|
||||
.venv/bin/python setup.py sdist
|
||||
cd dist
|
||||
tar zxf bcrypt*.tar.gz
|
||||
rm -rf bcrypt*.tar.gz
|
||||
cd bcrypt*
|
||||
|
||||
REGEX="cp3([0-9])*"
|
||||
if [[ "${PYBIN}" =~ $REGEX ]]; then
|
||||
PY_LIMITED_API="--py-limited-api=cp3${BASH_REMATCH[1]}"
|
||||
fi
|
||||
|
||||
../../.venv/bin/python setup.py bdist_wheel "$PY_LIMITED_API"
|
||||
|
||||
auditwheel repair --plat "${PLATFORM}" -w wheelhouse/ dist/bcrypt*.whl
|
||||
|
||||
../../.venv/bin/pip install bcrypt --no-index -f wheelhouse/
|
||||
../../.venv/bin/python -c "import bcrypt; password = b'super secret password';hashed = bcrypt.hashpw(password, bcrypt.gensalt());bcrypt.checkpw(password, hashed)"
|
||||
|
||||
mv wheelhouse/* /test/wheelhouse.final
|
||||
97
.circleci/config.yml
Normal file
97
.circleci/config.yml
Normal file
@ -0,0 +1,97 @@
|
||||
version: 2.1
|
||||
|
||||
commands:
|
||||
docker-pull:
|
||||
parameters:
|
||||
image:
|
||||
type: string
|
||||
steps:
|
||||
- run: docker pull <<parameters.image>>
|
||||
docker-run:
|
||||
parameters:
|
||||
image:
|
||||
type: string
|
||||
command:
|
||||
type: string
|
||||
steps:
|
||||
- run: docker run -e PLATFORM -e PYTHON -v $(pwd):/test <<parameters.image>> /bin/bash -c 'cd /test;<<parameters.command>>'
|
||||
|
||||
jobs:
|
||||
linux-arm64:
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
resource_class: arm.medium
|
||||
parameters:
|
||||
image:
|
||||
type: string
|
||||
toxenv:
|
||||
type: string
|
||||
steps:
|
||||
- checkout
|
||||
- docker-pull:
|
||||
image: <<parameters.image>>
|
||||
- docker-run:
|
||||
image: <<parameters.image>>
|
||||
command: /venv/bin/tox -e <<parameters.toxenv>>
|
||||
linux-arm64-wheel:
|
||||
machine:
|
||||
image: ubuntu-2004:current
|
||||
resource_class: arm.medium
|
||||
parameters:
|
||||
image:
|
||||
type: string
|
||||
platform:
|
||||
type: string
|
||||
python:
|
||||
type: string
|
||||
environment:
|
||||
PLATFORM: <<parameters.platform>>
|
||||
PYTHON: <<parameters.python>>
|
||||
steps:
|
||||
- checkout
|
||||
- docker-pull:
|
||||
image: <<parameters.image>>
|
||||
- docker-run:
|
||||
image: <<parameters.image>>
|
||||
command: /test/.circleci/build-wheel.sh
|
||||
- store_artifacts:
|
||||
path: wheelhouse.final
|
||||
|
||||
workflows:
|
||||
ci:
|
||||
jobs:
|
||||
- linux-arm64:
|
||||
# Changing this name should only be done in conjunction with updating
|
||||
# the required checks on GH
|
||||
name: linux-arm64-ci
|
||||
image: ghcr.io/pyca/cryptography-runner-ubuntu-focal:aarch64
|
||||
toxenv: py38
|
||||
# This makes sure it runs on all tags in addition to PRs/branches.
|
||||
# By default CircleCI ignores tags.
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
- linux-arm64-wheel:
|
||||
name: manylinux2014_aarch64-wheel
|
||||
image: ghcr.io/pyca/cryptography-manylinux2014_aarch64:latest
|
||||
python: cp36-cp36m
|
||||
platform: manylinux2014_aarch64
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
- linux-arm64-wheel:
|
||||
name: manylinux_2_24_aarch64-wheel
|
||||
image: ghcr.io/pyca/cryptography-manylinux_2_24:aarch64
|
||||
python: cp36-cp36m
|
||||
platform: manylinux_2_24_aarch64
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
- linux-arm64-wheel:
|
||||
name: musllinux_1_1_aarch64-wheel
|
||||
image: ghcr.io/pyca/cryptography-musllinux_1_1:aarch64
|
||||
python: cp36-cp36m
|
||||
platform: musllinux_1_1_aarch64
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array>
|
||||
<dict>
|
||||
<key>attributeSetting</key>
|
||||
<integer>1</integer>
|
||||
<key>choiceAttribute</key>
|
||||
<string>selected</string>
|
||||
<key>choiceIdentifier</key>
|
||||
<string>org.python.Python.PythonTFramework-3.13</string>
|
||||
</dict>
|
||||
</array>
|
||||
</plist>
|
||||
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array>
|
||||
<dict>
|
||||
<key>attributeSetting</key>
|
||||
<integer>1</integer>
|
||||
<key>choiceAttribute</key>
|
||||
<string>selected</string>
|
||||
<key>choiceIdentifier</key>
|
||||
<string>org.python.Python.PythonTFramework-3.14</string>
|
||||
</dict>
|
||||
</array>
|
||||
</plist>
|
||||
9
.github/dependabot.yml
vendored
9
.github/dependabot.yml
vendored
@ -4,12 +4,3 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
open-pull-requests-limit: 1024
|
||||
- package-ecosystem: cargo
|
||||
directory: "/src/_bcrypt/"
|
||||
schedule:
|
||||
interval: daily
|
||||
allow:
|
||||
# Also update indirect dependencies
|
||||
- dependency-type: all
|
||||
open-pull-requests-limit: 1024
|
||||
|
||||
192
.github/workflows/ci.yml
vendored
192
.github/workflows/ci.yml
vendored
@ -9,191 +9,87 @@ on:
|
||||
|
||||
jobs:
|
||||
macos:
|
||||
runs-on: ${{ matrix.MACOS }}
|
||||
runs-on: macos-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
PYTHON:
|
||||
- {VERSION: "3.8", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14t", NOXSESSION: "tests"}
|
||||
MACOS:
|
||||
- macos-15-intel
|
||||
- macos-latest
|
||||
name: "Python ${{ matrix.PYTHON.VERSION }} on ${{ matrix.MACOS }}"
|
||||
PYTHON:
|
||||
- {VERSION: "3.6", TOXENV: "py36"}
|
||||
- {VERSION: "3.10", TOXENV: "py310"}
|
||||
name: "Python ${{ matrix.PYTHON.VERSION }} on macOS"
|
||||
steps:
|
||||
- uses: actions/checkout@v6.0.2
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- name: Setup python
|
||||
id: setup-python
|
||||
uses: actions/setup-python@v6.2.0
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.PYTHON.VERSION }}
|
||||
- uses: actions/cache@v5.0.5
|
||||
timeout-minutes: 5
|
||||
with:
|
||||
path: |
|
||||
~/Library/Caches/pip/
|
||||
src/_bcrypt/target/
|
||||
key: ${{ runner.os }}-${{ matrix.PYTHON.VERSION }}-${{ steps.setup-python.outputs.python-version }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- run: pip install nox
|
||||
- run: nox -v
|
||||
|
||||
- run: pip install tox
|
||||
- run: tox
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.PYTHON.NOXSESSION }}
|
||||
CARGO_TARGET_DIR: ${{ format('{0}/src/_bcrypt/target/', github.workspace) }}
|
||||
TOXENV: ${{ matrix.PYTHON.TOXENV }}
|
||||
|
||||
windows:
|
||||
runs-on: ${{ matrix.WINDOWS.RUNNER }}
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
WINDOWS:
|
||||
- {ARCH: 'x86', WINDOWS: 'win32', RUST_TRIPLE: 'i686-pc-windows-msvc', RUNNER: 'windows-latest'}
|
||||
- {ARCH: 'x64', WINDOWS: 'win64', RUST_TRIPLE: 'x86_64-pc-windows-msvc', RUNNER: 'windows-latest'}
|
||||
- {ARCH: 'x86', WINDOWS: 'win32'}
|
||||
- {ARCH: 'x64', WINDOWS: 'win64'}
|
||||
PYTHON:
|
||||
- {VERSION: "3.8", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14t", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.6", TOXENV: "py36"}
|
||||
- {VERSION: "3.10", TOXENV: "py310"}
|
||||
name: "Python ${{ matrix.PYTHON.VERSION }} on ${{ matrix.WINDOWS.WINDOWS }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v6.0.2
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- name: Setup python
|
||||
id: setup-python
|
||||
uses: actions/setup-python@v6.2.0
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.PYTHON.VERSION }}
|
||||
architecture: ${{ matrix.WINDOWS.ARCH }}
|
||||
- uses: actions/cache@v5.0.5
|
||||
timeout-minutes: 5
|
||||
with:
|
||||
path: |
|
||||
~/AppData/Local/pip/Cache/
|
||||
src/_bcrypt/target/
|
||||
key: ${{ runner.os }}-${{ matrix.WINDOWS.ARCH }}-${{ matrix.PYTHON.VERSION }}-${{ steps.setup-python.outputs.python-version }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
|
||||
- run: pip install nox
|
||||
- run: nox -v
|
||||
- run: pip install tox
|
||||
- run: tox
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.PYTHON.NOXSESSION }}
|
||||
CARGO_TARGET_DIR: ${{ format('{0}/src/_bcrypt/target/', github.workspace) }}
|
||||
TOXENV: ${{ matrix.PYTHON.TOXENV }}
|
||||
linux:
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
PYTHON:
|
||||
- {VERSION: "3.13", NOXSESSION: "pep8,packaging"}
|
||||
- {VERSION: "3.13", NOXSESSION: "mypy"}
|
||||
- {VERSION: "3.8", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.9", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.10", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.11", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.12", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.13", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.13t", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14", NOXSESSION: "tests"}
|
||||
- {VERSION: "3.14t", NOXSESSION: "tests"}
|
||||
- {VERSION: "pypy-3.11", NOXSESSION: "tests"}
|
||||
|
||||
# MSRV
|
||||
- {VERSION: "3.13", NOXSESSION: "tests", RUST_VERSION: "1.85"}
|
||||
- {VERSION: "3.13", NOXSESSION: "tests", RUST_VERSION: "beta"}
|
||||
- {VERSION: "3.13", NOXSESSION: "tests", RUST_VERSION: "nightly"}
|
||||
name: "${{ matrix.PYTHON.VERSION }} on linux, Rust ${{ matrix.PYTHON.RUST_VERSION || 'stable' }}"
|
||||
- {VERSION: "3.9", TOXENV: "pep8,packaging"}
|
||||
- {VERSION: "3.9", TOXENV: "mypy"}
|
||||
- {VERSION: "3.6", TOXENV: "py36"}
|
||||
- {VERSION: "3.7", TOXENV: "py37"}
|
||||
- {VERSION: "3.8", TOXENV: "py38"}
|
||||
- {VERSION: "3.9", TOXENV: "py39"}
|
||||
- {VERSION: "3.10", TOXENV: "py310"}
|
||||
- {VERSION: "pypy-3.7", TOXENV: "pypy3"}
|
||||
- {VERSION: "pypy-3.8", TOXENV: "pypy3"}
|
||||
- {VERSION: "pypy-3.9", TOXENV: "pypy3"}
|
||||
name: "${{ matrix.PYTHON.TOXENV }} on linux"
|
||||
steps:
|
||||
- uses: actions/checkout@v6.0.2
|
||||
- uses: actions/checkout@v2.4.0
|
||||
- name: Setup python
|
||||
id: setup-python
|
||||
uses: actions/setup-python@v6.2.0
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.PYTHON.VERSION }}
|
||||
- uses: actions/cache@v5.0.5
|
||||
timeout-minutes: 5
|
||||
with:
|
||||
path: |
|
||||
~/.cache/pip/
|
||||
src/_bcrypt/target/
|
||||
key: ${{ runner.os }}-${{ matrix.PYTHON.VERSION }}-${{ steps.setup-python.outputs.python-version }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
|
||||
with:
|
||||
toolchain: ${{ matrix.PYTHON.RUST_VERSION || 'stable' }}
|
||||
|
||||
- run: pip install nox
|
||||
- run: nox -v
|
||||
- run: pip install tox
|
||||
- run: tox
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.PYTHON.NOXSESSION }}
|
||||
CARGO_TARGET_DIR: ${{ format('{0}/src/_bcrypt/target/', github.workspace) }}
|
||||
|
||||
alpine:
|
||||
runs-on: ${{ matrix.IMAGE.RUNNER }}
|
||||
container:
|
||||
image: ghcr.io/pyca/cryptography-runner-${{ matrix.IMAGE.IMAGE }}
|
||||
volumes:
|
||||
- /staticnodehost:/staticnodecontainer:rw,rshared
|
||||
- /staticnodehost/24:/__e/node24:ro,rshared
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
IMAGE:
|
||||
- {IMAGE: "alpine", NOXSESSION: "tests", RUNNER: "ubuntu-latest"}
|
||||
- {IMAGE: "alpine:aarch64", NOXSESSION: "tests", RUNNER: "ubuntu-24.04-arm"}
|
||||
name: "${{ matrix.IMAGE.NOXSESSION }} on ${{ matrix.IMAGE.IMAGE }}"
|
||||
steps:
|
||||
- name: Ridiculous-er workaround for static node
|
||||
run: |
|
||||
cp -R /staticnode/* /staticnodecontainer/
|
||||
- name: Ridiculous alpine workaround for actions support on arm64
|
||||
run: |
|
||||
# This modifies /etc/os-release so the JS actions
|
||||
# from GH can't detect that it's on alpine:aarch64. It will
|
||||
# then use a glibc nodejs, which works fine when gcompat
|
||||
# is installed in the container (which it is)
|
||||
sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release
|
||||
if: matrix.IMAGE.IMAGE == 'alpine:aarch64'
|
||||
- uses: actions/checkout@v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- run: /venv/bin/pip install nox
|
||||
- run: /venv/bin/nox -v
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.IMAGE.NOXSESSION }}
|
||||
RUSTUP_HOME: /root/.rustup
|
||||
CARGO_TARGET_DIR: ${{ format('{0}/src/_bcrypt/target/', github.workspace) }}
|
||||
TOXENV: ${{ matrix.PYTHON.TOXENV }}
|
||||
|
||||
linux-distros:
|
||||
runs-on: ${{ matrix.IMAGE.RUNNER }}
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/pyca/cryptography-runner-${{ matrix.IMAGE.IMAGE }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
IMAGE:
|
||||
- {IMAGE: "ubuntu-rolling:aarch64", NOXSESSION: "tests", RUNNER: "ubuntu-24.04-arm"}
|
||||
- {IMAGE: "ubuntu-rolling:armv7l", NOXSESSION: "tests", RUNNER: "ubuntu-24.04-arm"}
|
||||
name: "${{ matrix.IMAGE.NOXSESSION }} on ${{ matrix.IMAGE.IMAGE }}"
|
||||
- {IMAGE: "alpine", TOXENV: "py39"}
|
||||
name: "${{ matrix.IMAGE.TOXENV }} on ${{ matrix.IMAGE.IMAGE }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v6.0.2
|
||||
- uses: actions/checkout@v3.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
- run: /venv/bin/pip install nox
|
||||
- run: /venv/bin/nox -v
|
||||
- run: '/venv/bin/tox'
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.IMAGE.NOXSESSION }}
|
||||
RUSTUP_HOME: /root/.rustup
|
||||
CARGO_TARGET_DIR: ${{ format('{0}/src/_bcrypt/target/', github.workspace) }}
|
||||
|
||||
all-green: # This job does nothing and is only used for the branch protection
|
||||
if: always()
|
||||
|
||||
needs:
|
||||
- macos
|
||||
- windows
|
||||
- linux
|
||||
- alpine
|
||||
- linux-distros
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Decide whether the needed jobs succeeded or failed
|
||||
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe
|
||||
with:
|
||||
jobs: ${{ toJSON(needs) }}
|
||||
TOXENV: ${{ matrix.IMAGE.TOXENV }}
|
||||
|
||||
5
.github/workflows/lock.yml
vendored
5
.github/workflows/lock.yml
vendored
@ -3,14 +3,11 @@ on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
permissions:
|
||||
issues: "write"
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v6
|
||||
- uses: dessant/lock-threads@v3
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issue-inactive-days: 90
|
||||
|
||||
60
.github/workflows/pypi-publish.yml
vendored
60
.github/workflows/pypi-publish.yml
vendored
@ -1,60 +0,0 @@
|
||||
name: Publish to PyPI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
run_id:
|
||||
description: The run of wheel-builder to use for finding artifacts.
|
||||
required: true
|
||||
environment:
|
||||
description: Which PyPI environment to upload to
|
||||
required: true
|
||||
type: choice
|
||||
options: ["testpypi", "pypi"]
|
||||
workflow_run:
|
||||
workflows: ["Wheel Builder"]
|
||||
types: [completed]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
# We're not actually verifying that the triggering push event was for a
|
||||
# tag, because github doesn't expose enough information to do so.
|
||||
# wheel-builder.yml currently only has push events for tags.
|
||||
if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.event == 'push' && github.event.workflow_run.conclusion == 'success')
|
||||
permissions:
|
||||
id-token: "write"
|
||||
attestations: "write"
|
||||
steps:
|
||||
- run: echo "$EVENT_CONTEXT"
|
||||
env:
|
||||
EVENT_CONTEXT: ${{ toJson(github.event) }}
|
||||
|
||||
- run: |
|
||||
echo "PYPI_URL=https://upload.pypi.org/legacy/" >> $GITHUB_ENV
|
||||
if: github.event_name == 'workflow_run' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi')
|
||||
- run: |
|
||||
echo "PYPI_URL=https://test.pypi.org/legacy/" >> $GITHUB_ENV
|
||||
if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'testpypi'
|
||||
|
||||
- uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
|
||||
with:
|
||||
path: tmpdist/
|
||||
run_id: ${{ github.event.inputs.run_id || github.event.workflow_run.id }}
|
||||
- run: mkdir dist/
|
||||
- run: |
|
||||
find tmpdist/ -type f -name 'bcrypt*' -exec mv {} dist/ \;
|
||||
|
||||
- name: Publish package distributions to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
||||
with:
|
||||
repository-url: ${{ env.PYPI_URL }}
|
||||
skip-existing: true
|
||||
# Do not perform attestation for things for TestPyPI. This is
|
||||
# because there's nothing that would prevent a malicious PyPI from
|
||||
# serving a signed TestPyPI asset in place of a release intended for
|
||||
# PyPI.
|
||||
attestations: ${{ env.PYPI_URL == 'https://upload.pypi.org/legacy/' }}
|
||||
233
.github/workflows/wheel-builder.yml
vendored
233
.github/workflows/wheel-builder.yml
vendored
@ -7,113 +7,34 @@ on:
|
||||
version:
|
||||
description: The version to build
|
||||
required: false
|
||||
# Do not add any non-tag push events without updating pypi-publish.yml. If
|
||||
# you do, it'll upload wheels to PyPI.
|
||||
push:
|
||||
tags:
|
||||
- '*.*'
|
||||
- '*.*.*'
|
||||
pull_request:
|
||||
paths:
|
||||
- .github/workflows/wheel-builder.yml
|
||||
- setup.py
|
||||
- pyproject.toml
|
||||
|
||||
|
||||
jobs:
|
||||
sdist:
|
||||
manylinux:
|
||||
runs-on: ubuntu-latest
|
||||
name: sdists
|
||||
strategy:
|
||||
matrix:
|
||||
PYTHON:
|
||||
- {VERSION: "cp36-cp36m", ABI_VERSION: 'cp36'}
|
||||
CONTAINER:
|
||||
- {IMAGE: "cryptography-manylinux2010:x86_64", NAME: "manylinux2010"}
|
||||
- {IMAGE: "cryptography-manylinux2014:x86_64", NAME: "manylinux2014"}
|
||||
- {IMAGE: "cryptography-manylinux_2_24:x86_64", NAME: "manylinux_2_24"}
|
||||
- {IMAGE: "cryptography-musllinux_1_1:x86_64", NAME: "musllinux_1_1"}
|
||||
name: "${{ matrix.PYTHON.ABI_VERSION }} ${{ matrix.CONTAINER.NAME }}"
|
||||
container: ghcr.io/pyca/${{ matrix.CONTAINER.IMAGE }}
|
||||
steps:
|
||||
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v4.2.2
|
||||
- uses: actions/checkout@v1 # Need v1 because manylinux2010 can't run node from v2
|
||||
with:
|
||||
# The tag to build or the tag received by the tag event
|
||||
ref: ${{ github.event.inputs.version || github.ref }}
|
||||
persist-credentials: false
|
||||
|
||||
- run: python -m venv .venv
|
||||
- name: Install Python dependencies
|
||||
run: .venv/bin/pip install -U pip build
|
||||
- name: Make sdist
|
||||
run: .venv/bin/python -m build --sdist
|
||||
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: "bcrypt-sdist"
|
||||
path: dist/bcrypt*
|
||||
manylinux:
|
||||
needs: [sdist]
|
||||
runs-on: ${{ matrix.MANYLINUX.RUNNER }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
PYTHON:
|
||||
- { VERSION: "cp38-cp38", ABI_VERSION: 'cp38' }
|
||||
- { VERSION: "cp39-cp39", ABI_VERSION: 'cp39' }
|
||||
- { VERSION: "pp311-pypy311_pp73" }
|
||||
- { VERSION: "cp313-cp313t" }
|
||||
- { VERSION: "cp314-cp314t" }
|
||||
MANYLINUX:
|
||||
- { NAME: "manylinux2014_x86_64", CONTAINER: "cryptography-manylinux2014:x86_64", RUNNER: "ubuntu-latest" }
|
||||
- { NAME: "manylinux_2_28_x86_64", CONTAINER: "cryptography-manylinux_2_28:x86_64", RUNNER: "ubuntu-latest"}
|
||||
- { NAME: "manylinux_2_34_x86_64", CONTAINER: "cryptography-manylinux_2_34:x86_64", RUNNER: "ubuntu-latest"}
|
||||
- { NAME: "musllinux_1_2_x86_64", CONTAINER: "cryptography-musllinux_1_2:x86_64", RUNNER: "ubuntu-latest"}
|
||||
|
||||
- { NAME: "manylinux2014_aarch64", CONTAINER: "cryptography-manylinux2014_aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
- { NAME: "manylinux_2_28_aarch64", CONTAINER: "cryptography-manylinux_2_28:aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
- { NAME: "manylinux_2_34_aarch64", CONTAINER: "cryptography-manylinux_2_34:aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
- { NAME: "musllinux_1_2_aarch64", CONTAINER: "cryptography-musllinux_1_2:aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
|
||||
- { NAME: "manylinux_2_31_armv7l", CONTAINER: "cryptography-manylinux_2_31:armv7l", RUNNER: "ubuntu-24.04-arm" }
|
||||
exclude:
|
||||
# There are no readily available musllinux PyPy distributions
|
||||
- PYTHON: { VERSION: "pp311-pypy311_pp73" }
|
||||
MANYLINUX: { NAME: "musllinux_1_2_x86_64", CONTAINER: "cryptography-musllinux_1_2:x86_64", RUNNER: "ubuntu-latest"}
|
||||
- PYTHON: { VERSION: "pp311-pypy311_pp73" }
|
||||
MANYLINUX: { NAME: "musllinux_1_2_aarch64", CONTAINER: "cryptography-musllinux_1_2:aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
|
||||
# We also don't build pypy wheels for anything except the latest manylinux
|
||||
- PYTHON: { VERSION: "pp311-pypy311_pp73" }
|
||||
MANYLINUX: { NAME: "manylinux2014_x86_64", CONTAINER: "cryptography-manylinux2014:x86_64", RUNNER: "ubuntu-latest"}
|
||||
- PYTHON: { VERSION: "pp311-pypy311_pp73" }
|
||||
MANYLINUX: { NAME: "manylinux2014_aarch64", CONTAINER: "cryptography-manylinux2014_aarch64", RUNNER: "ubuntu-24.04-arm" }
|
||||
|
||||
# No PyPy on armv7l either
|
||||
- PYTHON: { VERSION: "pp311-pypy311_pp73" }
|
||||
MANYLINUX: { NAME: "manylinux_2_31_armv7l", CONTAINER: "cryptography-manylinux_2_31:armv7l", RUNNER: "ubuntu-24.04-arm" }
|
||||
|
||||
name: "${{ matrix.PYTHON.VERSION }} for ${{ matrix.MANYLINUX.NAME }}"
|
||||
container:
|
||||
image: ghcr.io/pyca/${{ matrix.MANYLINUX.CONTAINER }}
|
||||
volumes:
|
||||
- /staticnodehost:/staticnodecontainer:rw,rshared
|
||||
- /staticnodehost/24:/__e/node24:ro,rshared
|
||||
steps:
|
||||
- name: Ridiculous-er workaround for static node
|
||||
run: |
|
||||
cp -R /staticnode/* /staticnodecontainer/
|
||||
- name: Ridiculous alpine workaround for actions support on arm64
|
||||
run: |
|
||||
# This modifies /etc/os-release so the JS actions
|
||||
# from GH can't detect that it's on alpine:aarch64. It will
|
||||
# then use a glibc nodejs, which works fine when gcompat
|
||||
# is installed in the container (which it is)
|
||||
sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release
|
||||
if: startsWith(matrix.MANYLINUX.NAME, 'musllinux') && endsWith(matrix.MANYLINUX.NAME, 'aarch64')
|
||||
- run: /opt/python/${{ matrix.PYTHON.VERSION }}/bin/python -m venv .venv
|
||||
- name: Install python dependencies
|
||||
run: .venv/bin/pip install -U pip wheel setuptools-rust
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: bcrypt-sdist
|
||||
- run: mkdir tmpwheelhouse
|
||||
- name: Build the wheel
|
||||
run: |
|
||||
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
|
||||
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
|
||||
fi
|
||||
.venv/bin/python -m pip wheel -v $PY_LIMITED_API bcrypt*.tar.gz -w dist/ && mv dist/bcrypt*.whl tmpwheelhouse
|
||||
env:
|
||||
RUSTUP_HOME: /root/.rustup
|
||||
run: .venv/bin/pip install -U pip wheel cffi six
|
||||
- name: Make sdist
|
||||
run: .venv/bin/python setup.py sdist
|
||||
- run: tar zxvf dist/bcrypt*.tar.gz && mkdir tmpwheelhouse
|
||||
- run: cd bcrypt* && ../.venv/bin/python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/bcrypt*.whl ../tmpwheelhouse
|
||||
- run: auditwheel repair tmpwheelhouse/bcrypt*.whl -w wheelhouse/
|
||||
- run: .venv/bin/pip install bcrypt --no-index -f wheelhouse/
|
||||
- run: |
|
||||
@ -121,73 +42,41 @@ jobs:
|
||||
|
||||
- run: mkdir bcrypt-wheelhouse
|
||||
- run: mv wheelhouse/bcrypt*.whl bcrypt-wheelhouse/
|
||||
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-${{ matrix.MANYLINUX.NAME }}-${{ matrix.PYTHON.VERSION }}${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-${{ matrix.CONTAINER.NAME }} -${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
path: bcrypt-wheelhouse/
|
||||
|
||||
macos:
|
||||
needs: [sdist]
|
||||
runs-on: macos-15
|
||||
runs-on: macos-11
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
PYTHON:
|
||||
- VERSION: '3.11'
|
||||
ABI_VERSION: 'cp38'
|
||||
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.11.9/python-3.11.9-macos11.pkg'
|
||||
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
|
||||
- VERSION: '3.11'
|
||||
ABI_VERSION: 'cp39'
|
||||
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.11.9/python-3.11.9-macos11.pkg'
|
||||
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.11/bin/python3'
|
||||
- VERSION: '3.13t'
|
||||
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.13.7/python-3.13.7-macos11.pkg'
|
||||
BIN_PATH: '/Library/Frameworks/PythonT.framework/Versions/3.13/bin/python3.13t'
|
||||
- VERSION: '3.14t'
|
||||
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.14.0/python-3.14.0-macos11.pkg'
|
||||
BIN_PATH: '/Library/Frameworks/PythonT.framework/Versions/3.14/bin/python3.14t'
|
||||
name: "Python ${{ matrix.PYTHON.VERSION }} ${{ matrix.PYTHON.ABI_VERSION }} on macOS"
|
||||
- VERSION: '3.10'
|
||||
ABI_VERSION: 'cp36'
|
||||
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.10.1/python-3.10.1-macos11.pkg'
|
||||
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3'
|
||||
name: "Python ${{ matrix.PYTHON.VERSION }} for ABI ${{ matrix.PYTHON.ABI_VERSION }} on macOS"
|
||||
steps:
|
||||
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v4.2.2
|
||||
- uses: actions/checkout@v2.4.0
|
||||
with:
|
||||
# The tag to build or the tag received by the tag event
|
||||
ref: ${{ github.event.inputs.version || github.ref }}
|
||||
sparse-checkout: |
|
||||
.github/config/macos-pkg-choices-freethreaded-3.13t.xml
|
||||
.github/config/macos-pkg-choices-freethreaded-3.14t.xml
|
||||
persist-credentials: false
|
||||
- name: Install Python
|
||||
if: ${{ !endsWith(matrix.PYTHON.VERSION, 't') }}
|
||||
run: |
|
||||
- run: |
|
||||
curl "${{ matrix.PYTHON.DOWNLOAD_URL }}" -o python.pkg
|
||||
sudo installer -pkg python.pkg -target /
|
||||
- name: Install Python (free-threaded)
|
||||
if: ${{ endsWith(matrix.PYTHON.VERSION, 't') }}
|
||||
run: |
|
||||
curl "${{ matrix.PYTHON.DOWNLOAD_URL }}" -o python.pkg
|
||||
sudo installer -pkg python.pkg -applyChoiceChangesXML .github/config/macos-pkg-choices-freethreaded-${{ matrix.PYTHON.VERSION }}.xml -target /
|
||||
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
|
||||
with:
|
||||
toolchain: stable
|
||||
# Add the x86-64 target in addition to the native arch (arm64)
|
||||
target: x86_64-apple-darwin
|
||||
|
||||
- run: ${{ matrix.PYTHON.BIN_PATH }} -m venv venv
|
||||
- run: venv/bin/pip install -U pip wheel setuptools-rust
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: bcrypt-sdist
|
||||
- run: mkdir wheelhouse
|
||||
- run: venv/bin/pip install -U pip wheel cffi six
|
||||
- name: Make sdist
|
||||
run: venv/bin/python setup.py sdist
|
||||
- run: tar zxvf dist/bcrypt*.tar.gz && mkdir wheelhouse
|
||||
- name: Build the wheel
|
||||
run: |
|
||||
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
|
||||
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
|
||||
fi
|
||||
venv/bin/python -m pip wheel -v $PY_LIMITED_API bcrypt*.tar.gz -w dist/ && mv dist/bcrypt*.whl wheelhouse
|
||||
run: cd bcrypt* && ../venv/bin/python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/bcrypt*.whl ../wheelhouse
|
||||
env:
|
||||
PYTHON_VERSION: ${{ matrix.PYTHON.ABI_VERSION }}
|
||||
MACOSX_DEPLOYMENT_TARGET: '10.12'
|
||||
MACOSX_DEPLOYMENT_TARGET: '10.10'
|
||||
CFLAGS: '-arch arm64 -arch x86_64'
|
||||
ARCHFLAGS: '-arch arm64 -arch x86_64'
|
||||
_PYTHON_HOST_PLATFORM: 'macosx-10.9-universal2'
|
||||
- run: venv/bin/pip install -f wheelhouse --no-index bcrypt
|
||||
@ -196,50 +85,38 @@ jobs:
|
||||
|
||||
- run: mkdir bcrypt-wheelhouse
|
||||
- run: mv wheelhouse/bcrypt*.whl bcrypt-wheelhouse/
|
||||
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-macOS-${{ matrix.PYTHON.VERSION }}${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-macOS-${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
path: bcrypt-wheelhouse/
|
||||
|
||||
windows:
|
||||
needs: [sdist]
|
||||
runs-on: ${{ matrix.WINDOWS.RUNNER }}
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
WINDOWS:
|
||||
- {ARCH: 'x86', RUST_TRIPLE: 'i686-pc-windows-msvc', RUNNER: 'windows-latest'}
|
||||
- {ARCH: 'x64', RUST_TRIPLE: 'x86_64-pc-windows-msvc', RUNNER: 'windows-latest'}
|
||||
- 'x86'
|
||||
- 'x64'
|
||||
PYTHON:
|
||||
- {VERSION: "3.11", ABI_VERSION: "cp38"}
|
||||
- {VERSION: "3.11", ABI_VERSION: "cp39"}
|
||||
- {VERSION: "3.13t"}
|
||||
- {VERSION: "3.14t"}
|
||||
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.PYTHON.ABI_VERSION }} ${{ matrix.WINDOWS.ARCH }}"
|
||||
- {VERSION: "3.6", ABI_VERSION: "cp36"}
|
||||
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.PYTHON.ABI_VERSION }} ${{ matrix.WINDOWS}}"
|
||||
steps:
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
- uses: actions/checkout@v2.4.0
|
||||
with:
|
||||
name: bcrypt-sdist
|
||||
# The tag to build or the tag received by the tag event
|
||||
ref: ${{ github.event.inputs.version || github.ref }}
|
||||
persist-credentials: false
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v6.2.0
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.PYTHON.VERSION }}
|
||||
architecture: ${{ matrix.WINDOWS.ARCH }}
|
||||
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
|
||||
with:
|
||||
toolchain: stable
|
||||
target: ${{ matrix.WINDOWS.RUST_TRIPLE }}
|
||||
|
||||
- run: python -m pip install -U pip wheel setuptools-rust
|
||||
- run: mkdir wheelhouse
|
||||
shell: bash
|
||||
- name: Build the wheel
|
||||
run: |
|
||||
if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
|
||||
PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
|
||||
fi
|
||||
python -m pip wheel -v $PY_LIMITED_API bcrypt*.tar.gz -w dist/ && mv dist/bcrypt*.whl wheelhouse
|
||||
architecture: ${{ matrix.WINDOWS }}
|
||||
- run: python -m pip install -U pip wheel cffi six
|
||||
- name: Make sdist
|
||||
run: python setup.py sdist
|
||||
- run: tar zxvf dist/bcrypt*.tar.gz && mkdir wheelhouse
|
||||
shell: bash
|
||||
- run: cd bcrypt* && python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/bcrypt*.whl ../wheelhouse
|
||||
- run: pip install -f wheelhouse --no-index bcrypt
|
||||
- run: |
|
||||
python -c "import bcrypt; password = b'super secret password';hashed = bcrypt.hashpw(password, bcrypt.gensalt());bcrypt.checkpw(password, hashed)"
|
||||
@ -247,7 +124,7 @@ jobs:
|
||||
# TODO: can we setup another python and test in the same job? this would catch bad linking problems (e.g. build and test on py36, but then install py38 and see if it works
|
||||
- run: mkdir bcrypt-wheelhouse
|
||||
- run: move wheelhouse\bcrypt*.whl bcrypt-wheelhouse\
|
||||
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-${{ matrix.WINDOWS.ARCH }}-${{ matrix.PYTHON.VERSION }}${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
name: "bcrypt-${{ github.event.inputs.version }}-${{ matrix.WINDOWS }}-${{ matrix.PYTHON.ABI_VERSION }}"
|
||||
path: bcrypt-wheelhouse\
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
||||
__pycache__/
|
||||
*.py[co]
|
||||
*.so
|
||||
target/
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
|
||||
167
CHANGELOG.rst
167
CHANGELOG.rst
@ -1,167 +0,0 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
Unreleased
|
||||
----------
|
||||
|
||||
* Bumped MSRV to 1.85.
|
||||
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
* Bumped MSRV to 1.74.
|
||||
* Added support for Python 3.14 and free-threaded Python 3.14.
|
||||
* Added support for Windows on ARM.
|
||||
* Passing ``hashpw`` a password longer than 72 bytes now raises a
|
||||
``ValueError``. Previously the password was silently truncated, following the
|
||||
behavior of the original OpenBSD ``bcrypt`` implementation.
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* Dropped support for Python 3.7.
|
||||
* We now support free-threaded Python 3.13.
|
||||
* We now support PyPy 3.11.
|
||||
* We now publish wheels for free-threaded Python 3.13, for PyPy 3.11 on
|
||||
``manylinux``, and for ARMv7l on ``manylinux``.
|
||||
|
||||
4.2.1
|
||||
-----
|
||||
|
||||
* Bump Rust dependency versions - this should resolve crashes on Python 3.13
|
||||
free-threaded builds.
|
||||
* We no longer build ``manylinux`` wheels for PyPy 3.9.
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
* Bump Rust dependency versions
|
||||
* Removed the ``BCRYPT_ALLOW_RUST_163`` environment variable.
|
||||
|
||||
4.1.3
|
||||
-----
|
||||
|
||||
* Bump Rust dependency versions
|
||||
|
||||
4.1.2
|
||||
-----
|
||||
|
||||
* Publish both ``py37`` and ``py39`` wheels. This should resolve some errors
|
||||
relating to initializing a module multiple times per process.
|
||||
|
||||
4.1.1
|
||||
-----
|
||||
|
||||
* Fixed the type signature on the ``kdf`` method.
|
||||
* Fixed packaging bug on Windows.
|
||||
* Fixed incompatibility with passlib package detection assumptions.
|
||||
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
* Dropped support for Python 3.6.
|
||||
* Bumped MSRV to 1.64. (Note: Rust 1.63 can be used by setting the ``BCRYPT_ALLOW_RUST_163`` environment variable)
|
||||
|
||||
4.0.1
|
||||
-----
|
||||
|
||||
* We now build PyPy ``manylinux`` wheels.
|
||||
* Fixed a bug where passing an invalid ``salt`` to ``checkpw`` could result in
|
||||
a ``pyo3_runtime.PanicException``. It now correctly raises a ``ValueError``.
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* ``bcrypt`` is now implemented in Rust. Users building from source will need
|
||||
to have a Rust compiler available. Nothing will change for users downloading
|
||||
wheels.
|
||||
* We no longer ship ``manylinux2010`` wheels. Users should upgrade to the latest
|
||||
``pip`` to ensure this doesn’t cause issues downloading wheels on their
|
||||
platform. We now ship ``manylinux_2_28`` wheels for users on new enough platforms.
|
||||
* ``NUL`` bytes are now allowed in inputs.
|
||||
|
||||
|
||||
3.2.2
|
||||
-----
|
||||
|
||||
* Fixed packaging of ``py.typed`` files in wheels so that ``mypy`` works.
|
||||
|
||||
3.2.1
|
||||
-----
|
||||
|
||||
* Added support for compilation on z/OS
|
||||
* The next release of ``bcrypt`` with be 4.0 and it will require Rust at
|
||||
compile time, for users building from source. There will be no additional
|
||||
requirement for users who are installing from wheels. Users on most
|
||||
platforms will be able to obtain a wheel by making sure they have an up to
|
||||
date ``pip``. The minimum supported Rust version will be 1.56.0.
|
||||
* This will be the final release for which we ship ``manylinux2010`` wheels.
|
||||
Going forward the minimum supported manylinux ABI for our wheels will be
|
||||
``manylinux2014``. The vast majority of users will continue to receive
|
||||
``manylinux`` wheels provided they have an up to date ``pip``.
|
||||
|
||||
|
||||
3.2.0
|
||||
-----
|
||||
|
||||
* Added typehints for library functions.
|
||||
* Dropped support for Python versions less than 3.6 (2.7, 3.4, 3.5).
|
||||
* Shipped ``abi3`` Windows wheels (requires pip >= 20).
|
||||
|
||||
3.1.7
|
||||
-----
|
||||
|
||||
* Set a ``setuptools`` lower bound for PEP517 wheel building.
|
||||
* We no longer distribute 32-bit ``manylinux1`` wheels. Continuing to produce
|
||||
them was a maintenance burden.
|
||||
|
||||
3.1.6
|
||||
-----
|
||||
|
||||
* Added support for compilation on Haiku.
|
||||
|
||||
3.1.5
|
||||
-----
|
||||
|
||||
* Added support for compilation on AIX.
|
||||
* Dropped Python 2.6 and 3.3 support.
|
||||
* Switched to using ``abi3`` wheels for Python 3. If you are not getting a
|
||||
wheel on a compatible platform please upgrade your ``pip`` version.
|
||||
|
||||
3.1.4
|
||||
-----
|
||||
|
||||
* Fixed compilation with mingw and on illumos.
|
||||
|
||||
3.1.3
|
||||
-----
|
||||
* Fixed a compilation issue on Solaris.
|
||||
* Added a warning when using too few rounds with ``kdf``.
|
||||
|
||||
3.1.2
|
||||
-----
|
||||
* Fixed a compile issue affecting big endian platforms.
|
||||
* Fixed invalid escape sequence warnings on Python 3.6.
|
||||
* Fixed building in non-UTF8 environments on Python 2.
|
||||
|
||||
3.1.1
|
||||
-----
|
||||
* Resolved a ``UserWarning`` when used with ``cffi`` 1.8.3.
|
||||
|
||||
3.1.0
|
||||
-----
|
||||
* Added support for ``checkpw``, a convenience method for verifying a password.
|
||||
* Ensure that you get a ``$2y$`` hash when you input a ``$2y$`` salt.
|
||||
* Fixed a regression where ``$2a`` hashes were vulnerable to a wraparound bug.
|
||||
* Fixed compilation under Alpine Linux.
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
* Switched the C backend to code obtained from the OpenBSD project rather than
|
||||
openwall.
|
||||
* Added support for ``bcrypt_pbkdf`` via the ``kdf`` function.
|
||||
|
||||
2.0.0
|
||||
-----
|
||||
* Added support for an adjustible prefix when calling ``gensalt``.
|
||||
* Switched to CFFI 1.0+
|
||||
11
MANIFEST.in
11
MANIFEST.in
@ -1,16 +1,15 @@
|
||||
include LICENSE README.rst CHANGELOG.rst
|
||||
include LICENSE README.rst
|
||||
|
||||
include pyproject.toml
|
||||
|
||||
include noxfile.py .coveragerc
|
||||
include tox.ini .coveragerc
|
||||
include src/build_bcrypt.py
|
||||
|
||||
recursive-include src py.typed *.pyi
|
||||
recursive-include src/_bcrypt Cargo.toml Cargo.lock *.rs
|
||||
recursive-include src/_csrc *
|
||||
recursive-include tests *.py
|
||||
|
||||
exclude requirements.txt release.py mypy.ini
|
||||
|
||||
recursive-exclude .github *
|
||||
|
||||
exclude src/_bcrypt/target
|
||||
recursive-exclude src/_bcrypt/target *
|
||||
recursive-exclude .circleci *
|
||||
|
||||
121
README.rst
121
README.rst
@ -8,8 +8,7 @@ bcrypt
|
||||
.. image:: https://github.com/pyca/bcrypt/workflows/CI/badge.svg?branch=main
|
||||
:target: https://github.com/pyca/bcrypt/actions?query=workflow%3ACI+branch%3Amain
|
||||
|
||||
Acceptable password hashing for your software and your servers (but you should
|
||||
really use argon2id or scrypt)
|
||||
Good password hashing for your software and your servers
|
||||
|
||||
|
||||
Installation
|
||||
@ -17,44 +16,126 @@ Installation
|
||||
|
||||
To install bcrypt, simply:
|
||||
|
||||
.. code:: console
|
||||
.. code:: bash
|
||||
|
||||
$ pip install bcrypt
|
||||
|
||||
Note that bcrypt should build very easily on Linux provided you have a C
|
||||
compiler and a Rust compiler (the minimum supported Rust version is 1.74.0).
|
||||
Note that bcrypt should build very easily on Linux provided you have a C compiler, headers for Python (if you're not using pypy), and headers for the libffi libraries available on your system.
|
||||
|
||||
For Debian and Ubuntu, the following command will ensure that the required dependencies are installed:
|
||||
|
||||
.. code:: console
|
||||
.. code:: bash
|
||||
|
||||
$ sudo apt-get install build-essential cargo
|
||||
$ sudo apt-get install build-essential libffi-dev python-dev
|
||||
|
||||
For Fedora and RHEL-derivatives, the following command will ensure that the required dependencies are installed:
|
||||
|
||||
.. code:: console
|
||||
.. code:: bash
|
||||
|
||||
$ sudo yum install gcc cargo
|
||||
$ sudo yum install gcc libffi-devel python-devel
|
||||
|
||||
For Alpine, the following command will ensure that the required dependencies are installed:
|
||||
|
||||
.. code:: console
|
||||
.. code:: bash
|
||||
|
||||
$ apk add --update musl-dev gcc cargo
|
||||
$ apk add --update musl-dev gcc libffi-dev
|
||||
|
||||
|
||||
Alternatives
|
||||
============
|
||||
|
||||
While bcrypt remains an acceptable choice for password storage, depending on your specific use case you may also want to consider using scrypt (either via `standard library`_ or `cryptography`_) or argon2id via `argon2_cffi`_.
|
||||
While bcrypt remains a good choice for password storage depending on your specific use case you may also want to consider using scrypt (either via `standard library`_ or `cryptography`_) or argon2id via `argon2_cffi`_.
|
||||
|
||||
Changelog
|
||||
=========
|
||||
|
||||
The changelog is maintained in `CHANGELOG.rst <https://github.com/pyca/bcrypt/blob/main/CHANGELOG.rst>`_
|
||||
3.2.2
|
||||
-----
|
||||
|
||||
* Fixed packaging of ``py.typed`` files in wheels so that ``mypy`` works.
|
||||
|
||||
3.2.1
|
||||
-----
|
||||
|
||||
* Added support for compilation on z/OS
|
||||
* The next release of ``bcrypt`` with be 4.0 and it will require Rust at
|
||||
compile time, for users building from source. There will be no additional
|
||||
requirement for users who are installing from wheels. Users on most
|
||||
platforms will be able to obtain a wheel by making sure they have an up to
|
||||
date ``pip``. The minimum supported Rust version will be 1.56.0.
|
||||
* This will be the final release for which we ship ``manylinux2010`` wheels.
|
||||
Going forward the minimum supported manylinux ABI for our wheels will be
|
||||
``manylinux2014``. The vast majority of users will continue to receive
|
||||
``manylinux`` wheels provided they have an up to date ``pip``.
|
||||
|
||||
|
||||
3.2.0
|
||||
-----
|
||||
|
||||
* Added typehints for library functions.
|
||||
* Dropped support for Python versions less than 3.6 (2.7, 3.4, 3.5).
|
||||
* Shipped ``abi3`` Windows wheels (requires pip >= 20).
|
||||
|
||||
3.1.7
|
||||
-----
|
||||
|
||||
* Set a ``setuptools`` lower bound for PEP517 wheel building.
|
||||
* We no longer distribute 32-bit ``manylinux1`` wheels. Continuing to produce
|
||||
them was a maintenance burden.
|
||||
|
||||
3.1.6
|
||||
-----
|
||||
|
||||
* Added support for compilation on Haiku.
|
||||
|
||||
3.1.5
|
||||
-----
|
||||
|
||||
* Added support for compilation on AIX.
|
||||
* Dropped Python 2.6 and 3.3 support.
|
||||
* Switched to using ``abi3`` wheels for Python 3. If you are not getting a
|
||||
wheel on a compatible platform please upgrade your ``pip`` version.
|
||||
|
||||
3.1.4
|
||||
-----
|
||||
|
||||
* Fixed compilation with mingw and on illumos.
|
||||
|
||||
3.1.3
|
||||
-----
|
||||
* Fixed a compilation issue on Solaris.
|
||||
* Added a warning when using too few rounds with ``kdf``.
|
||||
|
||||
3.1.2
|
||||
-----
|
||||
* Fixed a compile issue affecting big endian platforms.
|
||||
* Fixed invalid escape sequence warnings on Python 3.6.
|
||||
* Fixed building in non-UTF8 environments on Python 2.
|
||||
|
||||
3.1.1
|
||||
-----
|
||||
* Resolved a ``UserWarning`` when used with ``cffi`` 1.8.3.
|
||||
|
||||
3.1.0
|
||||
-----
|
||||
* Added support for ``checkpw``, a convenience method for verifying a password.
|
||||
* Ensure that you get a ``$2y$`` hash when you input a ``$2y$`` salt.
|
||||
* Fixed a regression where ``$2a`` hashes were vulnerable to a wraparound bug.
|
||||
* Fixed compilation under Alpine Linux.
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
* Switched the C backend to code obtained from the OpenBSD project rather than
|
||||
openwall.
|
||||
* Added support for ``bcrypt_pbkdf`` via the ``kdf`` function.
|
||||
|
||||
2.0.0
|
||||
-----
|
||||
* Added support for an adjustible prefix when calling ``gensalt``.
|
||||
* Switched to CFFI 1.0+
|
||||
|
||||
Usage
|
||||
=====
|
||||
-----
|
||||
|
||||
Password Hashing
|
||||
~~~~~~~~~~~~~~~~
|
||||
@ -123,9 +204,8 @@ As of 3.0.0 the ``$2y$`` prefix is still supported in ``hashpw`` but deprecated.
|
||||
Maximum Password Length
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Passing ``hashpw`` a password longer than 72 bytes now raises a ``ValueError``.
|
||||
Previously the password was silently truncated, following the behavior of the
|
||||
original OpenBSD ``bcrypt`` implementation. To work around this, a common approach is to hash a
|
||||
The bcrypt algorithm only handles passwords up to 72 characters, any characters
|
||||
beyond that are ignored. To work around this, a common approach is to hash a
|
||||
password with a cryptographic hash (such as ``sha256``) and then base64
|
||||
encode it to prevent NULL byte problems before hashing the result with
|
||||
``bcrypt``:
|
||||
@ -142,7 +222,12 @@ Compatibility
|
||||
-------------
|
||||
|
||||
This library should be compatible with py-bcrypt and it will run on Python
|
||||
3.8+ (including free-threaded builds), and PyPy 3.
|
||||
3.6+, and PyPy 3.
|
||||
|
||||
C Code
|
||||
------
|
||||
|
||||
This library uses code from OpenBSD.
|
||||
|
||||
Security
|
||||
--------
|
||||
|
||||
36
mypy.ini
Normal file
36
mypy.ini
Normal file
@ -0,0 +1,36 @@
|
||||
[mypy]
|
||||
show_column_numbers=True
|
||||
pretty=True
|
||||
|
||||
disallow_any_unimported=True
|
||||
# _bcrypt usage will result in any exprs
|
||||
disallow_any_expr=False
|
||||
disallow_any_decorated=True
|
||||
disallow_any_explicit=True
|
||||
disallow_any_generics=True
|
||||
disallow_subclassing_any=True
|
||||
|
||||
disallow_untyped_calls=True
|
||||
disallow_untyped_defs=True
|
||||
disallow_incomplete_defs=True
|
||||
check_untyped_defs=True
|
||||
disallow_untyped_decorators=True
|
||||
|
||||
no_implicit_optional=True
|
||||
strict_optional=True
|
||||
|
||||
warn_redundant_casts=True
|
||||
warn_unused_ignores=True
|
||||
warn_no_return=True
|
||||
# _bcrypt is untyped so all calls involving it will be Any
|
||||
warn_return_any=False
|
||||
# keep backwards compatibility for users not using static type checking
|
||||
warn_unreachable=False
|
||||
|
||||
strict_equality=True
|
||||
|
||||
ignore_missing_imports=False
|
||||
|
||||
[mypy-bcrypt._bcrypt]
|
||||
ignore_missing_imports = True
|
||||
disallow_any_explicit = False
|
||||
42
noxfile.py
42
noxfile.py
@ -1,42 +0,0 @@
|
||||
import nox
|
||||
|
||||
nox.options.reuse_existing_virtualenvs = True
|
||||
nox.options.default_venv_backend = "uv|virtualenv"
|
||||
|
||||
|
||||
@nox.session
|
||||
def tests(session: nox.Session) -> None:
|
||||
session.install("coverage")
|
||||
session.install(".[tests]")
|
||||
|
||||
session.run(
|
||||
"coverage", "run", "-m", "pytest", "--strict-markers", *session.posargs
|
||||
)
|
||||
session.run("coverage", "combine")
|
||||
session.run("coverage", "report", "-m", "--fail-under", "100")
|
||||
|
||||
|
||||
@nox.session
|
||||
def pep8(session: nox.Session) -> None:
|
||||
session.install("ruff")
|
||||
|
||||
session.run("ruff", "check", ".")
|
||||
session.run("ruff", "format", "--check", ".")
|
||||
|
||||
|
||||
@nox.session
|
||||
def mypy(session: nox.Session) -> None:
|
||||
session.install("mypy")
|
||||
session.install(".[tests]")
|
||||
|
||||
session.run("mypy", "tests/")
|
||||
|
||||
|
||||
@nox.session
|
||||
def packaging(session: nox.Session) -> None:
|
||||
session.install("setuptools-rust", "check-manifest", "readme_renderer")
|
||||
|
||||
session.run("check-manifest")
|
||||
session.run(
|
||||
"python3", "-m", "readme_renderer", "README.rst", "-o", "/dev/null"
|
||||
)
|
||||
@ -1,80 +1,14 @@
|
||||
[build-system]
|
||||
# Must be kept in sync with `setup_requirements` in `setup.py`
|
||||
requires = [
|
||||
"setuptools>=42.0.0",
|
||||
"setuptools>=40.8.0",
|
||||
"wheel",
|
||||
"setuptools-rust>=1.7.0",
|
||||
"cffi>=1.1; python_implementation != 'PyPy'",
|
||||
]
|
||||
# Point to the setuptools' PEP517 build backend explicitly to
|
||||
# disable Pip's fallback guessing
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "bcrypt"
|
||||
# When updating this, also update lib.rs
|
||||
version = "5.0.0"
|
||||
authors = [
|
||||
{name = "The Python Cryptographic Authority developers", email = "cryptography-dev@python.org"}
|
||||
]
|
||||
description = "Modern password hashing for your software and your servers"
|
||||
license = {text = "Apache-2.0"}
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"License :: OSI Approved :: Apache Software License",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
"Programming Language :: Python :: 3.14",
|
||||
"Programming Language :: Python :: Free Threading :: 3 - Stable",
|
||||
]
|
||||
requires-python = ">= 3.8"
|
||||
dynamic = ["readme"]
|
||||
|
||||
[project.urls]
|
||||
homepage = "https://github.com/pyca/bcrypt/"
|
||||
changelog = "https://github.com/pyca/bcrypt/blob/main/CHANGELOG.rst"
|
||||
|
||||
[tool.setuptools]
|
||||
zip-safe = false
|
||||
package-dir = {"" = "src"}
|
||||
packages = ["bcrypt"]
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
readme = {file = "README.rst", content-type = "text/x-rst"}
|
||||
|
||||
[project.optional-dependencies]
|
||||
tests = ["pytest>=3.2.1,!=3.3.0"]
|
||||
typecheck = ["mypy"]
|
||||
|
||||
[[tool.setuptools-rust.ext-modules]]
|
||||
target = "bcrypt._bcrypt"
|
||||
path = "src/_bcrypt/Cargo.toml"
|
||||
py-limited-api = "auto"
|
||||
rust-version = ">=1.64.0"
|
||||
|
||||
[tool.ruff]
|
||||
[tool.black]
|
||||
line-length = 79
|
||||
|
||||
lint.ignore = ['N818']
|
||||
lint.select = ['E', 'F', 'I', 'N', 'W', 'UP', 'RUF']
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
known-first-party = ["bcrypt", "tests"]
|
||||
|
||||
[tool.mypy]
|
||||
show_error_codes = true
|
||||
check_untyped_defs = true
|
||||
no_implicit_reexport = true
|
||||
warn_redundant_casts = true
|
||||
warn_unused_ignores = true
|
||||
warn_unused_configs = true
|
||||
strict_equality = true
|
||||
|
||||
[tool.check-manifest]
|
||||
ignore = ["tests/reference/*"]
|
||||
target-version = ["py36"]
|
||||
|
||||
134
release.py
134
release.py
@ -1,33 +1,139 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# This file is dual licensed under the terms of the Apache License, Version
|
||||
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
||||
# for complete details.
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import getpass
|
||||
import glob
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import zipfile
|
||||
|
||||
import click
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def run(*args, **kwargs):
|
||||
print(f"[running] {list(args)}")
|
||||
print("[running] {0}".format(list(args)))
|
||||
subprocess.check_call(list(args), **kwargs)
|
||||
|
||||
|
||||
def wait_for_build_complete_github_actions(session, token, run_url):
|
||||
while True:
|
||||
response = session.get(
|
||||
run_url,
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
if response.json()["conclusion"] is not None:
|
||||
break
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
def download_artifacts_github_actions(session, token, run_url):
|
||||
response = session.get(
|
||||
run_url,
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
response = session.get(
|
||||
response.json()["artifacts_url"],
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
paths = []
|
||||
for artifact in response.json()["artifacts"]:
|
||||
response = session.get(
|
||||
artifact["archive_download_url"],
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
)
|
||||
with zipfile.ZipFile(io.BytesIO(response.content)) as z:
|
||||
for name in z.namelist():
|
||||
if not name.endswith(".whl"):
|
||||
continue
|
||||
p = z.open(name)
|
||||
out_path = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
"dist",
|
||||
os.path.basename(name),
|
||||
)
|
||||
with open(out_path, "wb") as f:
|
||||
f.write(p.read())
|
||||
paths.append(out_path)
|
||||
return paths
|
||||
|
||||
|
||||
def build_github_actions_wheels(token, version):
|
||||
session = requests.Session()
|
||||
|
||||
response = session.post(
|
||||
"https://api.github.com/repos/pyca/bcrypt/actions/workflows/"
|
||||
"wheel-builder.yml/dispatches",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/vnd.github.v3+json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
data=json.dumps({"ref": "main", "inputs": {"version": version}}),
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
# Give it a few seconds for the run to kick off.
|
||||
time.sleep(5)
|
||||
response = session.get(
|
||||
(
|
||||
"https://api.github.com/repos/pyca/bcrypt/actions/workflows/"
|
||||
"wheel-builder.yml/runs?event=workflow_dispatch"
|
||||
),
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "token {}".format(token),
|
||||
},
|
||||
)
|
||||
response.raise_for_status()
|
||||
run_url = response.json()["workflow_runs"][0]["url"]
|
||||
wait_for_build_complete_github_actions(session, token, run_url)
|
||||
return download_artifacts_github_actions(session, token, run_url)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("version")
|
||||
def release(version):
|
||||
"""
|
||||
``version`` should be a string like '0.4' or '1.0'.
|
||||
"""
|
||||
run("git", "tag", "-s", version, "-m", f"{version} release")
|
||||
run("git", "push", "--tags", "git@github.com:pyca/bcrypt.git")
|
||||
github_token = getpass.getpass("Github person access token: ")
|
||||
|
||||
run("git", "tag", "-s", version, "-m", "{0} release".format(version))
|
||||
run("git", "push", "--tags")
|
||||
|
||||
run("python", "setup.py", "sdist")
|
||||
|
||||
packages = glob.glob("dist/bcrypt-{0}*".format(version))
|
||||
github_actions_wheel_paths = build_github_actions_wheels(
|
||||
github_token, version
|
||||
)
|
||||
|
||||
run("twine", "upload", "-s", *packages)
|
||||
run("twine", "upload", *github_actions_wheel_paths)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
42
setup.cfg
Normal file
42
setup.cfg
Normal file
@ -0,0 +1,42 @@
|
||||
[metadata]
|
||||
name = bcrypt
|
||||
version = attr: bcrypt.__about__.__version__
|
||||
description = Modern password hashing for your software and your servers
|
||||
long_description = file: README.rst
|
||||
long_description_content_type = text/x-rst
|
||||
license = Apache License, Version 2.0
|
||||
license_file = LICENSE
|
||||
url = https://github.com/pyca/bcrypt/
|
||||
author = The Python Cryptographic Authority developers
|
||||
author_email = cryptography-dev@python.org
|
||||
classifiers =
|
||||
Development Status :: 5 - Production/Stable
|
||||
License :: OSI Approved :: Apache Software License
|
||||
Programming Language :: Python :: Implementation :: CPython
|
||||
Programming Language :: Python :: Implementation :: PyPy
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3 :: Only
|
||||
Programming Language :: Python :: 3.6
|
||||
Programming Language :: Python :: 3.7
|
||||
Programming Language :: Python :: 3.8
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
|
||||
[options]
|
||||
python_requires = >=3.6
|
||||
include_package_data = True
|
||||
zip_safe = False
|
||||
package_dir =
|
||||
=src
|
||||
packages =
|
||||
bcrypt
|
||||
ext_package = bcrypt
|
||||
# `install_requires` must be kept in sync with `pyproject.toml`
|
||||
install_requires =
|
||||
cffi>=1.1
|
||||
|
||||
[options.extras_require]
|
||||
tests =
|
||||
pytest>=3.2.1,!=3.3.0
|
||||
typecheck =
|
||||
mypy
|
||||
23
setup.py
Normal file
23
setup.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
import platform
|
||||
import sys
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
CFFI_MODULES = [
|
||||
"src/build_bcrypt.py:ffi",
|
||||
]
|
||||
|
||||
|
||||
if platform.python_implementation() == "PyPy":
|
||||
if sys.pypy_version_info < (2, 6):
|
||||
raise RuntimeError(
|
||||
"bcrypt is not compatible with PyPy < 2.6. Please upgrade PyPy to "
|
||||
"use this library."
|
||||
)
|
||||
|
||||
|
||||
setup(
|
||||
cffi_modules=CFFI_MODULES,
|
||||
)
|
||||
625
src/_bcrypt/Cargo.lock
generated
625
src/_bcrypt/Cargo.lock
generated
@ -1,625 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bcrypt"
|
||||
version = "0.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24ae5479c93d3720e4c1dbd6b945b97457c50cb672781104768190371df1a905"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"blowfish",
|
||||
"getrandom",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bcrypt-pbkdf"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144e573728da132683b9488acd528274c790e07fc06ff81ee29f9d8f8b1041e0"
|
||||
dependencies = [
|
||||
"blowfish",
|
||||
"pbkdf2",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bcrypt-rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bcrypt",
|
||||
"bcrypt-pbkdf",
|
||||
"getrandom",
|
||||
"pyo3",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blowfish"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62ce3946557b35e71d1bbe07ec385073ce9eda05043f95de134eb578fcf1a298"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
|
||||
dependencies = [
|
||||
"crypto-common",
|
||||
"inout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmov"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctutils"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e"
|
||||
dependencies = [
|
||||
"cmov",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"ctutils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasip2",
|
||||
"wasip3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hybrid-array"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.17.0",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||
|
||||
[[package]]
|
||||
name = "leb128fmt"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.186"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629"
|
||||
dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"once_cell",
|
||||
"portable-atomic",
|
||||
"pyo3-build-config",
|
||||
"pyo3-ffi",
|
||||
"pyo3-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-build-config"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
||||
dependencies = [
|
||||
"target-lexicon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-ffi"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pyo3-build-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-macros"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"pyo3-macros-backend",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pyo3-macros-backend"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"pyo3-build-config",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-lexicon"
|
||||
version = "0.13.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.1+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
|
||||
dependencies = [
|
||||
"wit-bindgen 0.46.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasip3"
|
||||
version = "0.4.0+wasi-0.3.0-rc-2026-01-06"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"
|
||||
dependencies = [
|
||||
"wit-bindgen 0.51.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
|
||||
dependencies = [
|
||||
"leb128fmt",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"hashbrown 0.15.5",
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||
dependencies = [
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"prettyplease",
|
||||
"syn",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
@ -1,28 +0,0 @@
|
||||
[package]
|
||||
name = "bcrypt-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["The bcrypt developers <cryptography-dev@python.org>"]
|
||||
edition = "2024"
|
||||
# This specifies the MSRV
|
||||
rust-version = "1.85"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
pyo3 = { version = "0.28", features = ["abi3"] }
|
||||
bcrypt = "0.19.1"
|
||||
bcrypt-pbkdf = "0.11.0"
|
||||
base64 = "0.22.1"
|
||||
subtle = "2.6"
|
||||
getrandom = "0.4"
|
||||
|
||||
[features]
|
||||
extension-module = ["pyo3/extension-module"]
|
||||
default = ["extension-module"]
|
||||
|
||||
[lib]
|
||||
name = "bcrypt_rust"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
overflow-checks = true
|
||||
@ -1,226 +0,0 @@
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
|
||||
use base64::Engine;
|
||||
use pyo3::types::PyBytesMethods;
|
||||
use pyo3::PyTypeInfo;
|
||||
use std::convert::TryInto;
|
||||
use std::ffi::CString;
|
||||
use std::io::Write;
|
||||
use subtle::ConstantTimeEq;
|
||||
|
||||
pub const BASE64_ENGINE: base64::engine::GeneralPurpose = base64::engine::GeneralPurpose::new(
|
||||
&base64::alphabet::BCRYPT,
|
||||
base64::engine::general_purpose::NO_PAD,
|
||||
);
|
||||
|
||||
#[pyo3::pyfunction]
|
||||
#[pyo3(signature = (rounds=12, prefix=None), text_signature = "(rounds=12, prefix=b'2b')")]
|
||||
fn gensalt<'p>(
|
||||
py: pyo3::Python<'p>,
|
||||
rounds: u16,
|
||||
prefix: Option<&[u8]>,
|
||||
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
|
||||
let prefix = prefix.unwrap_or(b"2b");
|
||||
|
||||
if prefix != b"2a" && prefix != b"2b" {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err(
|
||||
"Supported prefixes are b'2a' or b'2b'",
|
||||
));
|
||||
}
|
||||
|
||||
if !(4..=31).contains(&rounds) {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err("Invalid rounds"));
|
||||
}
|
||||
|
||||
let mut salt = [0; 16];
|
||||
getrandom::fill(&mut salt).unwrap();
|
||||
|
||||
let encoded_salt = BASE64_ENGINE.encode(salt);
|
||||
|
||||
pyo3::types::PyBytes::new_with(
|
||||
py,
|
||||
1 + prefix.len() + 1 + 2 + 1 + encoded_salt.len(),
|
||||
|mut b| {
|
||||
write!(b, "$").unwrap();
|
||||
b.write_all(prefix).unwrap();
|
||||
write!(b, "$").unwrap();
|
||||
write!(b, "{:02.2}", rounds).unwrap();
|
||||
write!(b, "$").unwrap();
|
||||
b.write_all(encoded_salt.as_bytes()).unwrap();
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[pyo3::pyfunction]
|
||||
fn hashpw<'p>(
|
||||
py: pyo3::Python<'p>,
|
||||
password: &[u8],
|
||||
salt: &[u8],
|
||||
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
|
||||
// bcrypt originally suffered from a wraparound bug:
|
||||
// http://www.openwall.com/lists/oss-security/2012/01/02/4
|
||||
// This bug was corrected in the OpenBSD source by truncating inputs to 72
|
||||
// bytes on the updated prefix $2b$, but leaving $2a$ unchanged for
|
||||
// compatibility. However, pyca/bcrypt 2.0.0 *did* correctly truncate inputs
|
||||
// on $2a$, so we do it here to preserve compatibility with 2.0.0
|
||||
// Silent truncation is _probably_ not the best idea, even if the "original"
|
||||
// OpenBSD implementation did/does this.
|
||||
// We prefer to raise a ValueError in this case - if the user _wants_ to truncate,
|
||||
// they can always do so manually by passing s[:72] instead of s into hashpw().
|
||||
|
||||
if password.len() > 72 {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err(
|
||||
"password cannot be longer than 72 bytes, truncate manually if necessary (e.g. my_password[:72])",
|
||||
));
|
||||
}
|
||||
|
||||
// salt here is not just the salt bytes, but rather an encoded value
|
||||
// containing a version number, number of rounds, and the salt.
|
||||
// Should be [prefix, cost, hash]. This logic is copied from `bcrypt`
|
||||
let invalid_salt = || pyo3::exceptions::PyValueError::new_err("Invalid salt");
|
||||
let mut parts = salt.split(|&b| b == b'$').filter(|s| !s.is_empty());
|
||||
let raw_version = parts.next().ok_or_else(invalid_salt)?;
|
||||
let raw_cost = parts.next().ok_or_else(invalid_salt)?;
|
||||
let remainder = parts.next().ok_or_else(invalid_salt)?;
|
||||
if parts.next().is_some() {
|
||||
return Err(invalid_salt());
|
||||
}
|
||||
|
||||
let version = match raw_version {
|
||||
b"2y" => bcrypt::Version::TwoY,
|
||||
b"2b" => bcrypt::Version::TwoB,
|
||||
b"2a" => bcrypt::Version::TwoA,
|
||||
b"2x" => bcrypt::Version::TwoX,
|
||||
_ => {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err("Invalid salt"));
|
||||
}
|
||||
};
|
||||
let cost = std::str::from_utf8(raw_cost)
|
||||
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?
|
||||
.parse::<u32>()
|
||||
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
|
||||
|
||||
if remainder.len() < 22 {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err("Invalid salt"));
|
||||
}
|
||||
|
||||
// The last component can contain either just the salt, or the salt and
|
||||
// the result hash, depending on if the `salt` value come from `hashpw` or
|
||||
// `gensalt`.
|
||||
let raw_salt = BASE64_ENGINE
|
||||
.decode(&remainder[..22])
|
||||
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?
|
||||
.try_into()
|
||||
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
|
||||
|
||||
let hashed = py
|
||||
.detach(|| bcrypt::hash_with_salt(password, cost, raw_salt))
|
||||
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid salt"))?;
|
||||
Ok(pyo3::types::PyBytes::new(
|
||||
py,
|
||||
hashed.format_for_version(version).as_bytes(),
|
||||
))
|
||||
}
|
||||
|
||||
#[pyo3::pyfunction]
|
||||
fn checkpw(py: pyo3::Python<'_>, password: &[u8], hashed_password: &[u8]) -> pyo3::PyResult<bool> {
|
||||
Ok(hashpw(py, password, hashed_password)?
|
||||
.as_bytes()
|
||||
.ct_eq(hashed_password)
|
||||
.into())
|
||||
}
|
||||
|
||||
#[pyo3::pyfunction]
|
||||
#[pyo3(signature = (password, salt, desired_key_bytes, rounds, ignore_few_rounds=false))]
|
||||
fn kdf<'p>(
|
||||
py: pyo3::Python<'p>,
|
||||
password: &[u8],
|
||||
salt: &[u8],
|
||||
desired_key_bytes: usize,
|
||||
rounds: u32,
|
||||
ignore_few_rounds: bool,
|
||||
) -> pyo3::PyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
|
||||
if password.is_empty() || salt.is_empty() {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err(
|
||||
"password and salt must not be empty",
|
||||
));
|
||||
}
|
||||
|
||||
if desired_key_bytes == 0 || desired_key_bytes > 512 {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err(
|
||||
"desired_key_bytes must be 1-512",
|
||||
));
|
||||
}
|
||||
|
||||
if rounds < 1 {
|
||||
return Err(pyo3::exceptions::PyValueError::new_err(
|
||||
"rounds must be 1 or more",
|
||||
));
|
||||
}
|
||||
|
||||
if rounds < 50 && !ignore_few_rounds {
|
||||
// They probably think bcrypt.kdf()'s rounds parameter is logarithmic,
|
||||
// expecting this value to be slow enough (it probably would be if this
|
||||
// were bcrypt). Emit a warning.
|
||||
pyo3::PyErr::warn(
|
||||
py,
|
||||
&pyo3::exceptions::PyUserWarning::type_object(py),
|
||||
&CString::new(format!("Warning: bcrypt.kdf() called with only {rounds} round(s). This few is not secure: the parameter is linear, like PBKDF2.")).unwrap(),
|
||||
3
|
||||
)?;
|
||||
}
|
||||
|
||||
pyo3::types::PyBytes::new_with(py, desired_key_bytes, |output| {
|
||||
py.detach(|| {
|
||||
bcrypt_pbkdf::bcrypt_pbkdf(password, salt, rounds, output).unwrap();
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[pyo3::pymodule(gil_used = false)]
|
||||
mod _bcrypt {
|
||||
use pyo3::types::PyModuleMethods;
|
||||
|
||||
#[pymodule_export]
|
||||
use super::{checkpw, gensalt, hashpw, kdf};
|
||||
|
||||
// Not yet possible to add constants declaratively.
|
||||
#[pymodule_init]
|
||||
fn init(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {
|
||||
m.add("__title__", "bcrypt")?;
|
||||
m.add(
|
||||
"__summary__",
|
||||
"Modern(-ish) password hashing for your software and your servers",
|
||||
)?;
|
||||
m.add("__uri__", "https://github.com/pyca/bcrypt/")?;
|
||||
|
||||
// When updating this, also update pyproject.toml
|
||||
// This isn't named __version__ because passlib treats the existence of
|
||||
// that attribute as proof that we're a different module
|
||||
m.add("__version_ex__", "5.0.0")?;
|
||||
|
||||
let author = "The Python Cryptographic Authority developers";
|
||||
m.add("__author__", author)?;
|
||||
m.add("__email__", "cryptography-dev@python.org")?;
|
||||
|
||||
m.add("__license__", "Apache License, Version 2.0")?;
|
||||
m.add("__copyright__", format!("Copyright 2013-2025 {author}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
274
src/_csrc/bcrypt.c
Normal file
274
src/_csrc/bcrypt.c
Normal file
@ -0,0 +1,274 @@
|
||||
/* $OpenBSD: bcrypt.c,v 1.55 2015/09/13 15:33:48 guenther Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
|
||||
* Copyright (c) 1997 Niels Provos <provos@umich.edu>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
/* This password hashing algorithm was designed by David Mazieres
|
||||
* <dm@lcs.mit.edu> and works as follows:
|
||||
*
|
||||
* 1. state := InitState ()
|
||||
* 2. state := ExpandKey (state, salt, password)
|
||||
* 3. REPEAT rounds:
|
||||
* state := ExpandKey (state, 0, password)
|
||||
* state := ExpandKey (state, 0, salt)
|
||||
* 4. ctext := "OrpheanBeholderScryDoubt"
|
||||
* 5. REPEAT 64:
|
||||
* ctext := Encrypt_ECB (state, ctext);
|
||||
* 6. RETURN Concatenate (salt, ctext);
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <blf.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "pycabcrypt.h"
|
||||
|
||||
/* This implementation is adaptable to current computing power.
|
||||
* You can have up to 2^31 rounds which should be enough for some
|
||||
* time to come.
|
||||
*/
|
||||
|
||||
#define BCRYPT_VERSION '2'
|
||||
#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */
|
||||
#define BCRYPT_WORDS 6 /* Ciphertext words */
|
||||
#define BCRYPT_MINLOGROUNDS 4 /* we have log2(rounds) in salt */
|
||||
|
||||
#define BCRYPT_SALTSPACE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1)
|
||||
#define BCRYPT_HASHSPACE 61
|
||||
|
||||
char *bcrypt_gensalt(u_int8_t);
|
||||
|
||||
int encode_base64(char *, const u_int8_t *, size_t);
|
||||
static int decode_base64(u_int8_t *, size_t, const char *);
|
||||
|
||||
/*
|
||||
* the core bcrypt function
|
||||
*/
|
||||
int
|
||||
bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
|
||||
size_t encryptedlen)
|
||||
{
|
||||
blf_ctx state;
|
||||
u_int32_t rounds, i, k;
|
||||
u_int16_t j;
|
||||
size_t key_len;
|
||||
u_int8_t salt_len, logr, minor;
|
||||
u_int8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt";
|
||||
u_int8_t csalt[BCRYPT_MAXSALT];
|
||||
u_int32_t cdata[BCRYPT_WORDS];
|
||||
|
||||
if (encryptedlen < BCRYPT_HASHSPACE)
|
||||
goto inval;
|
||||
|
||||
/* Check and discard "$" identifier */
|
||||
if (salt[0] != '$')
|
||||
goto inval;
|
||||
salt += 1;
|
||||
|
||||
if (salt[0] != BCRYPT_VERSION)
|
||||
goto inval;
|
||||
|
||||
/* Check for minor versions */
|
||||
switch ((minor = salt[1])) {
|
||||
case 'a':
|
||||
key_len = (u_int8_t)(strlen(key) + 1);
|
||||
break;
|
||||
case 'b':
|
||||
/* strlen() returns a size_t, but the function calls
|
||||
* below result in implicit casts to a narrower integer
|
||||
* type, so cap key_len at the actual maximum supported
|
||||
* length here to avoid integer wraparound */
|
||||
key_len = strlen(key);
|
||||
if (key_len > 72)
|
||||
key_len = 72;
|
||||
key_len++; /* include the NUL */
|
||||
break;
|
||||
default:
|
||||
goto inval;
|
||||
}
|
||||
if (salt[2] != '$')
|
||||
goto inval;
|
||||
/* Discard version + "$" identifier */
|
||||
salt += 3;
|
||||
|
||||
/* Check and parse num rounds */
|
||||
if (!isdigit((unsigned char)salt[0]) ||
|
||||
!isdigit((unsigned char)salt[1]) || salt[2] != '$')
|
||||
goto inval;
|
||||
logr = (salt[1] - '0') + ((salt[0] - '0') * 10);
|
||||
if (logr < BCRYPT_MINLOGROUNDS || logr > 31)
|
||||
goto inval;
|
||||
/* Computer power doesn't increase linearly, 2^x should be fine */
|
||||
rounds = 1U << logr;
|
||||
|
||||
/* Discard num rounds + "$" identifier */
|
||||
salt += 3;
|
||||
|
||||
if (strlen(salt) * 3 / 4 < BCRYPT_MAXSALT)
|
||||
goto inval;
|
||||
|
||||
/* We dont want the base64 salt but the raw data */
|
||||
if (decode_base64(csalt, BCRYPT_MAXSALT, salt))
|
||||
goto inval;
|
||||
salt_len = BCRYPT_MAXSALT;
|
||||
|
||||
/* Setting up S-Boxes and Subkeys */
|
||||
Blowfish_initstate(&state);
|
||||
Blowfish_expandstate(&state, csalt, salt_len,
|
||||
(u_int8_t *) key, key_len);
|
||||
for (k = 0; k < rounds; k++) {
|
||||
Blowfish_expand0state(&state, (u_int8_t *) key, key_len);
|
||||
Blowfish_expand0state(&state, csalt, salt_len);
|
||||
}
|
||||
|
||||
/* This can be precomputed later */
|
||||
j = 0;
|
||||
for (i = 0; i < BCRYPT_WORDS; i++)
|
||||
cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);
|
||||
|
||||
/* Now do the encryption */
|
||||
for (k = 0; k < 64; k++)
|
||||
blf_enc(&state, cdata, BCRYPT_WORDS / 2);
|
||||
|
||||
for (i = 0; i < BCRYPT_WORDS; i++) {
|
||||
ciphertext[4 * i + 3] = cdata[i] & 0xff;
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 2] = cdata[i] & 0xff;
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 1] = cdata[i] & 0xff;
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 0] = cdata[i] & 0xff;
|
||||
}
|
||||
|
||||
|
||||
snprintf(encrypted, 8, "$2%c$%2.2u$", minor, logr);
|
||||
encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT);
|
||||
encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1);
|
||||
explicit_bzero(&state, sizeof(state));
|
||||
explicit_bzero(ciphertext, sizeof(ciphertext));
|
||||
explicit_bzero(csalt, sizeof(csalt));
|
||||
explicit_bzero(cdata, sizeof(cdata));
|
||||
return 0;
|
||||
|
||||
inval:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* internal utilities
|
||||
*/
|
||||
static const u_int8_t Base64Code[] =
|
||||
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
static const u_int8_t index_64[128] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 0, 1, 54, 55,
|
||||
56, 57, 58, 59, 60, 61, 62, 63, 255, 255,
|
||||
255, 255, 255, 255, 255, 2, 3, 4, 5, 6,
|
||||
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
||||
255, 255, 255, 255, 255, 255, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
51, 52, 53, 255, 255, 255, 255, 255
|
||||
};
|
||||
#define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)])
|
||||
|
||||
/*
|
||||
* read buflen (after decoding) bytes of data from b64data
|
||||
*/
|
||||
static int
|
||||
decode_base64(u_int8_t *buffer, size_t len, const char *b64data)
|
||||
{
|
||||
u_int8_t *bp = buffer;
|
||||
const u_int8_t *p = b64data;
|
||||
u_int8_t c1, c2, c3, c4;
|
||||
|
||||
while (bp < buffer + len) {
|
||||
c1 = CHAR64(*p);
|
||||
/* Invalid data */
|
||||
if (c1 == 255)
|
||||
return -1;
|
||||
|
||||
c2 = CHAR64(*(p + 1));
|
||||
if (c2 == 255)
|
||||
return -1;
|
||||
|
||||
*bp++ = (c1 << 2) | ((c2 & 0x30) >> 4);
|
||||
if (bp >= buffer + len)
|
||||
break;
|
||||
|
||||
c3 = CHAR64(*(p + 2));
|
||||
if (c3 == 255)
|
||||
return -1;
|
||||
|
||||
*bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2);
|
||||
if (bp >= buffer + len)
|
||||
break;
|
||||
|
||||
c4 = CHAR64(*(p + 3));
|
||||
if (c4 == 255)
|
||||
return -1;
|
||||
*bp++ = ((c3 & 0x03) << 6) | c4;
|
||||
|
||||
p += 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn len bytes of data into base64 encoded data.
|
||||
* This works without = padding.
|
||||
*/
|
||||
int
|
||||
encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
|
||||
{
|
||||
u_int8_t *bp = b64buffer;
|
||||
const u_int8_t *p = data;
|
||||
u_int8_t c1, c2;
|
||||
|
||||
while (p < data + len) {
|
||||
c1 = *p++;
|
||||
*bp++ = Base64Code[(c1 >> 2)];
|
||||
c1 = (c1 & 0x03) << 4;
|
||||
if (p >= data + len) {
|
||||
*bp++ = Base64Code[c1];
|
||||
break;
|
||||
}
|
||||
c2 = *p++;
|
||||
c1 |= (c2 >> 4) & 0x0f;
|
||||
*bp++ = Base64Code[c1];
|
||||
c1 = (c2 & 0x0f) << 2;
|
||||
if (p >= data + len) {
|
||||
*bp++ = Base64Code[c1];
|
||||
break;
|
||||
}
|
||||
c2 = *p++;
|
||||
c1 |= (c2 >> 6) & 0x03;
|
||||
*bp++ = Base64Code[c1];
|
||||
*bp++ = Base64Code[c2 & 0x3f];
|
||||
}
|
||||
*bp = '\0';
|
||||
return 0;
|
||||
}
|
||||
168
src/_csrc/bcrypt_pbkdf.c
Normal file
168
src/_csrc/bcrypt_pbkdf.c
Normal file
@ -0,0 +1,168 @@
|
||||
/* $OpenBSD: bcrypt_pbkdf.c,v 1.13 2015/01/12 03:20:04 tedu Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pycabcrypt.h"
|
||||
#include "blf.h"
|
||||
#include "sha2.h"
|
||||
|
||||
#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
/*
|
||||
* pkcs #5 pbkdf2 implementation using the "bcrypt" hash
|
||||
*
|
||||
* The bcrypt hash function is derived from the bcrypt password hashing
|
||||
* function with the following modifications:
|
||||
* 1. The input password and salt are preprocessed with SHA512.
|
||||
* 2. The output length is expanded to 256 bits.
|
||||
* 3. Subsequently the magic string to be encrypted is lengthened and modifed
|
||||
* to "OxychromaticBlowfishSwatDynamite"
|
||||
* 4. The hash function is defined to perform 64 rounds of initial state
|
||||
* expansion. (More rounds are performed by iterating the hash.)
|
||||
*
|
||||
* Note that this implementation pulls the SHA512 operations into the caller
|
||||
* as a performance optimization.
|
||||
*
|
||||
* One modification from official pbkdf2. Instead of outputting key material
|
||||
* linearly, we mix it. pbkdf2 has a known weakness where if one uses it to
|
||||
* generate (e.g.) 512 bits of key material for use as two 256 bit keys, an
|
||||
* attacker can merely run once through the outer loop, but the user
|
||||
* always runs it twice. Shuffling output bytes requires computing the
|
||||
* entirety of the key material to assemble any subkey. This is something a
|
||||
* wise caller could do; we just do it for you.
|
||||
*/
|
||||
|
||||
#define BCRYPT_WORDS 8
|
||||
#define BCRYPT_HASHSIZE (BCRYPT_WORDS * 4)
|
||||
|
||||
static void
|
||||
bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
|
||||
{
|
||||
blf_ctx state;
|
||||
uint8_t ciphertext[BCRYPT_HASHSIZE] =
|
||||
"OxychromaticBlowfishSwatDynamite";
|
||||
uint32_t cdata[BCRYPT_WORDS];
|
||||
int i;
|
||||
uint16_t j;
|
||||
size_t shalen = SHA512_DIGEST_LENGTH;
|
||||
|
||||
/* key expansion */
|
||||
Blowfish_initstate(&state);
|
||||
Blowfish_expandstate(&state, sha2salt, shalen, sha2pass, shalen);
|
||||
for (i = 0; i < 64; i++) {
|
||||
Blowfish_expand0state(&state, sha2salt, shalen);
|
||||
Blowfish_expand0state(&state, sha2pass, shalen);
|
||||
}
|
||||
|
||||
/* encryption */
|
||||
j = 0;
|
||||
for (i = 0; i < BCRYPT_WORDS; i++)
|
||||
cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext),
|
||||
&j);
|
||||
for (i = 0; i < 64; i++)
|
||||
blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
|
||||
|
||||
/* copy out */
|
||||
for (i = 0; i < BCRYPT_WORDS; i++) {
|
||||
out[4 * i + 3] = (cdata[i] >> 24) & 0xff;
|
||||
out[4 * i + 2] = (cdata[i] >> 16) & 0xff;
|
||||
out[4 * i + 1] = (cdata[i] >> 8) & 0xff;
|
||||
out[4 * i + 0] = cdata[i] & 0xff;
|
||||
}
|
||||
|
||||
/* zap */
|
||||
explicit_bzero(ciphertext, sizeof(ciphertext));
|
||||
explicit_bzero(cdata, sizeof(cdata));
|
||||
explicit_bzero(&state, sizeof(state));
|
||||
}
|
||||
|
||||
int
|
||||
bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, size_t saltlen,
|
||||
uint8_t *key, size_t keylen, unsigned int rounds)
|
||||
{
|
||||
SHA2_CTX ctx;
|
||||
uint8_t sha2pass[SHA512_DIGEST_LENGTH];
|
||||
uint8_t sha2salt[SHA512_DIGEST_LENGTH];
|
||||
uint8_t out[BCRYPT_HASHSIZE];
|
||||
uint8_t tmpout[BCRYPT_HASHSIZE];
|
||||
uint8_t countsalt[4];
|
||||
size_t i, j, amt, stride;
|
||||
uint32_t count;
|
||||
size_t origkeylen = keylen;
|
||||
|
||||
/* nothing crazy */
|
||||
if (rounds < 1)
|
||||
return -1;
|
||||
if (passlen == 0 || saltlen == 0 || keylen == 0 ||
|
||||
keylen > sizeof(out) * sizeof(out))
|
||||
return -1;
|
||||
stride = (keylen + sizeof(out) - 1) / sizeof(out);
|
||||
amt = (keylen + stride - 1) / stride;
|
||||
|
||||
/* collapse password */
|
||||
SHA512Init(&ctx);
|
||||
SHA512Update(&ctx, pass, passlen);
|
||||
SHA512Final(sha2pass, &ctx);
|
||||
|
||||
|
||||
/* generate key, sizeof(out) at a time */
|
||||
for (count = 1; keylen > 0; count++) {
|
||||
countsalt[0] = (count >> 24) & 0xff;
|
||||
countsalt[1] = (count >> 16) & 0xff;
|
||||
countsalt[2] = (count >> 8) & 0xff;
|
||||
countsalt[3] = count & 0xff;
|
||||
|
||||
/* first round, salt is salt */
|
||||
SHA512Init(&ctx);
|
||||
SHA512Update(&ctx, salt, saltlen);
|
||||
SHA512Update(&ctx, countsalt, sizeof(countsalt));
|
||||
SHA512Final(sha2salt, &ctx);
|
||||
bcrypt_hash(sha2pass, sha2salt, tmpout);
|
||||
memcpy(out, tmpout, sizeof(out));
|
||||
|
||||
for (i = 1; i < rounds; i++) {
|
||||
/* subsequent rounds, salt is previous output */
|
||||
SHA512Init(&ctx);
|
||||
SHA512Update(&ctx, tmpout, sizeof(tmpout));
|
||||
SHA512Final(sha2salt, &ctx);
|
||||
bcrypt_hash(sha2pass, sha2salt, tmpout);
|
||||
for (j = 0; j < sizeof(out); j++)
|
||||
out[j] ^= tmpout[j];
|
||||
}
|
||||
|
||||
/*
|
||||
* pbkdf2 deviation: output the key material non-linearly.
|
||||
*/
|
||||
amt = MINIMUM(amt, keylen);
|
||||
for (i = 0; i < amt; i++) {
|
||||
size_t dest = i * stride + (count - 1);
|
||||
if (dest >= origkeylen)
|
||||
break;
|
||||
key[dest] = out[i];
|
||||
}
|
||||
keylen -= i;
|
||||
}
|
||||
|
||||
/* zap */
|
||||
explicit_bzero(&ctx, sizeof(ctx));
|
||||
explicit_bzero(out, sizeof(out));
|
||||
|
||||
return 0;
|
||||
}
|
||||
654
src/_csrc/blf.c
Normal file
654
src/_csrc/blf.c
Normal file
@ -0,0 +1,654 @@
|
||||
/* $OpenBSD: blf.c,v 1.7 2007/11/26 09:28:34 martynas Exp $ */
|
||||
|
||||
/*
|
||||
* Blowfish block cipher for OpenBSD
|
||||
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Implementation advice by David Mazieres <dm@lcs.mit.edu>.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is derived from section 14.3 and the given source
|
||||
* in section V of Applied Cryptography, second edition.
|
||||
* Blowfish is an unpatented fast block cipher designed by
|
||||
* Bruce Schneier.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "blf.h"
|
||||
|
||||
#undef inline
|
||||
#ifdef __GNUC__
|
||||
#define inline __inline
|
||||
#else /* !__GNUC__ */
|
||||
#define inline
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
/* Function for Feistel Networks */
|
||||
|
||||
#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \
|
||||
+ (s)[0x100 + (((x)>>16)&0xFF)]) \
|
||||
^ (s)[0x200 + (((x)>> 8)&0xFF)]) \
|
||||
+ (s)[0x300 + ( (x) &0xFF)])
|
||||
|
||||
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
|
||||
|
||||
void
|
||||
Blowfish_encipher(blf_ctx *c, u_int32_t *x)
|
||||
{
|
||||
u_int32_t Xl;
|
||||
u_int32_t Xr;
|
||||
u_int32_t *s = c->S[0];
|
||||
u_int32_t *p = c->P;
|
||||
|
||||
Xl = x[0];
|
||||
Xr = x[1];
|
||||
|
||||
Xl ^= p[0];
|
||||
BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2);
|
||||
BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4);
|
||||
BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6);
|
||||
BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8);
|
||||
BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10);
|
||||
BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12);
|
||||
BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14);
|
||||
BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16);
|
||||
|
||||
x[0] = Xr ^ p[17];
|
||||
x[1] = Xl;
|
||||
}
|
||||
|
||||
void
|
||||
Blowfish_decipher(blf_ctx *c, u_int32_t *x)
|
||||
{
|
||||
u_int32_t Xl;
|
||||
u_int32_t Xr;
|
||||
u_int32_t *s = c->S[0];
|
||||
u_int32_t *p = c->P;
|
||||
|
||||
Xl = x[0];
|
||||
Xr = x[1];
|
||||
|
||||
Xl ^= p[17];
|
||||
BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15);
|
||||
BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13);
|
||||
BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11);
|
||||
BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9);
|
||||
BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7);
|
||||
BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5);
|
||||
BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3);
|
||||
BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1);
|
||||
|
||||
x[0] = Xr ^ p[0];
|
||||
x[1] = Xl;
|
||||
}
|
||||
|
||||
void
|
||||
Blowfish_initstate(blf_ctx *c)
|
||||
{
|
||||
/* P-box and S-box tables initialized with digits of Pi */
|
||||
|
||||
static const blf_ctx initstate =
|
||||
|
||||
{ {
|
||||
{
|
||||
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
|
||||
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
||||
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
|
||||
0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
||||
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
|
||||
0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
||||
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
|
||||
0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
||||
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
|
||||
0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
||||
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
|
||||
0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
||||
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
|
||||
0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
||||
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
|
||||
0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
||||
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
|
||||
0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
||||
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
|
||||
0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
||||
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
|
||||
0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
||||
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
|
||||
0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
||||
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
|
||||
0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
||||
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
|
||||
0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
||||
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
|
||||
0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
||||
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
|
||||
0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
||||
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
|
||||
0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
||||
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
|
||||
0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
||||
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
|
||||
0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
||||
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
|
||||
0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
||||
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
|
||||
0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
||||
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
|
||||
0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
||||
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
|
||||
0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
||||
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
|
||||
0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
||||
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
|
||||
0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
||||
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
|
||||
0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
||||
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
|
||||
0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
||||
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
|
||||
0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
||||
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
|
||||
0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
||||
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
|
||||
0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
||||
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
|
||||
0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
||||
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
|
||||
0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
|
||||
{
|
||||
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
|
||||
0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
||||
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
|
||||
0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
||||
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
|
||||
0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
||||
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
|
||||
0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
||||
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
|
||||
0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
||||
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
|
||||
0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
||||
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
|
||||
0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
||||
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
|
||||
0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
||||
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
|
||||
0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
||||
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
|
||||
0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
||||
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
|
||||
0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
||||
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
|
||||
0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
||||
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
|
||||
0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
||||
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
|
||||
0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
||||
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
|
||||
0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
||||
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
|
||||
0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
||||
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
|
||||
0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
||||
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
|
||||
0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
||||
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
|
||||
0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
||||
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
|
||||
0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
||||
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
|
||||
0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
||||
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
|
||||
0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
||||
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
|
||||
0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
||||
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
|
||||
0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
||||
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
|
||||
0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
||||
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
|
||||
0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
||||
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
|
||||
0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
||||
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
|
||||
0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
||||
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
|
||||
0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
||||
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
|
||||
0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
||||
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
|
||||
0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
||||
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
|
||||
0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
|
||||
{
|
||||
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
|
||||
0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
||||
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
|
||||
0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
||||
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
|
||||
0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
||||
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
|
||||
0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
||||
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
|
||||
0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
||||
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
|
||||
0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
||||
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
|
||||
0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
||||
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
|
||||
0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
||||
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
|
||||
0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
||||
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
|
||||
0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
||||
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
|
||||
0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
||||
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
|
||||
0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
||||
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
|
||||
0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
||||
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
|
||||
0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
||||
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
|
||||
0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
||||
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
|
||||
0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
||||
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
|
||||
0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
||||
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
|
||||
0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
||||
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
|
||||
0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
||||
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
|
||||
0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
||||
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
|
||||
0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
||||
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
|
||||
0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
||||
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
|
||||
0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
||||
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
|
||||
0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
||||
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
|
||||
0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
||||
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
|
||||
0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
||||
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
|
||||
0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
||||
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
|
||||
0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
||||
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
|
||||
0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
||||
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
|
||||
0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
||||
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
|
||||
0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
||||
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
|
||||
0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
|
||||
{
|
||||
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
|
||||
0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
||||
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
|
||||
0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
||||
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
|
||||
0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
||||
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
|
||||
0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
||||
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
|
||||
0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
||||
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
|
||||
0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
||||
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
|
||||
0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
||||
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
|
||||
0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
||||
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
|
||||
0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
||||
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
|
||||
0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
||||
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
|
||||
0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
||||
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
|
||||
0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
||||
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
|
||||
0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
||||
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
|
||||
0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
||||
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
|
||||
0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
||||
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
|
||||
0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
||||
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
|
||||
0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
||||
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
|
||||
0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
||||
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
|
||||
0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
||||
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
|
||||
0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
||||
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
|
||||
0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
||||
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
|
||||
0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
||||
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
|
||||
0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
||||
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
|
||||
0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
||||
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
|
||||
0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
||||
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
|
||||
0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
||||
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
|
||||
0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
||||
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
|
||||
0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
||||
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
|
||||
0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
||||
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
|
||||
0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
||||
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
|
||||
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
||||
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
|
||||
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}
|
||||
},
|
||||
{
|
||||
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
|
||||
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
|
||||
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
||||
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
|
||||
0x9216d5d9, 0x8979fb1b
|
||||
} };
|
||||
|
||||
*c = initstate;
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
|
||||
u_int16_t *current)
|
||||
{
|
||||
u_int8_t i;
|
||||
u_int16_t j;
|
||||
u_int32_t temp;
|
||||
|
||||
temp = 0x00000000;
|
||||
j = *current;
|
||||
|
||||
for (i = 0; i < 4; i++, j++) {
|
||||
if (j >= databytes)
|
||||
j = 0;
|
||||
temp = (temp << 8) | data[j];
|
||||
}
|
||||
|
||||
*current = j;
|
||||
return temp;
|
||||
}
|
||||
|
||||
void
|
||||
Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
|
||||
{
|
||||
u_int16_t i;
|
||||
u_int16_t j;
|
||||
u_int16_t k;
|
||||
u_int32_t temp;
|
||||
u_int32_t data[2];
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < BLF_N + 2; i++) {
|
||||
/* Extract 4 int8 to 1 int32 from keystream */
|
||||
temp = Blowfish_stream2word(key, keybytes, &j);
|
||||
c->P[i] = c->P[i] ^ temp;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
data[0] = 0x00000000;
|
||||
data[1] = 0x00000000;
|
||||
for (i = 0; i < BLF_N + 2; i += 2) {
|
||||
Blowfish_encipher(c, data);
|
||||
|
||||
c->P[i] = data[0];
|
||||
c->P[i + 1] = data[1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (k = 0; k < 256; k += 2) {
|
||||
Blowfish_encipher(c, data);
|
||||
|
||||
c->S[i][k] = data[0];
|
||||
c->S[i][k + 1] = data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
|
||||
const u_int8_t *key, u_int16_t keybytes)
|
||||
{
|
||||
u_int16_t i;
|
||||
u_int16_t j;
|
||||
u_int16_t k;
|
||||
u_int32_t temp;
|
||||
u_int32_t d[2];
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < BLF_N + 2; i++) {
|
||||
/* Extract 4 int8 to 1 int32 from keystream */
|
||||
temp = Blowfish_stream2word(key, keybytes, &j);
|
||||
c->P[i] = c->P[i] ^ temp;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
d[0] = 0x00000000;
|
||||
d[1] = 0x00000000;
|
||||
for (i = 0; i < BLF_N + 2; i += 2) {
|
||||
d[0] ^= Blowfish_stream2word(data, databytes, &j);
|
||||
d[1] ^= Blowfish_stream2word(data, databytes, &j);
|
||||
Blowfish_encipher(c, d);
|
||||
|
||||
c->P[i] = d[0];
|
||||
c->P[i + 1] = d[1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (k = 0; k < 256; k += 2) {
|
||||
d[0]^= Blowfish_stream2word(data, databytes, &j);
|
||||
d[1] ^= Blowfish_stream2word(data, databytes, &j);
|
||||
Blowfish_encipher(c, d);
|
||||
|
||||
c->S[i][k] = d[0];
|
||||
c->S[i][k + 1] = d[1];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
|
||||
{
|
||||
/* Initialize S-boxes and subkeys with Pi */
|
||||
Blowfish_initstate(c);
|
||||
|
||||
/* Transform S-boxes and subkeys with key */
|
||||
Blowfish_expand0state(c, k, len);
|
||||
}
|
||||
|
||||
void
|
||||
blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
{
|
||||
u_int32_t *d;
|
||||
u_int16_t i;
|
||||
|
||||
d = data;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
Blowfish_encipher(c, d);
|
||||
d += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
{
|
||||
u_int32_t *d;
|
||||
u_int16_t i;
|
||||
|
||||
d = data;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
Blowfish_decipher(c, d);
|
||||
d += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r, d[2];
|
||||
u_int32_t i;
|
||||
|
||||
for (i = 0; i < len; i += 8) {
|
||||
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
d[0] = l;
|
||||
d[1] = r;
|
||||
Blowfish_encipher(c, d);
|
||||
l = d[0];
|
||||
r = d[1];
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
data += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r, d[2];
|
||||
u_int32_t i;
|
||||
|
||||
for (i = 0; i < len; i += 8) {
|
||||
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
d[0] = l;
|
||||
d[1] = r;
|
||||
Blowfish_decipher(c, d);
|
||||
l = d[0];
|
||||
r = d[1];
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
data += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r, d[2];
|
||||
u_int32_t i, j;
|
||||
|
||||
for (i = 0; i < len; i += 8) {
|
||||
for (j = 0; j < 8; j++)
|
||||
data[j] ^= iv[j];
|
||||
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
d[0] = l;
|
||||
d[1] = r;
|
||||
Blowfish_encipher(c, d);
|
||||
l = d[0];
|
||||
r = d[1];
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
iv = data;
|
||||
data += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r, d[2];
|
||||
u_int8_t *iv;
|
||||
u_int32_t i, j;
|
||||
|
||||
iv = data + len - 16;
|
||||
data = data + len - 8;
|
||||
for (i = len - 8; i >= 8; i -= 8) {
|
||||
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
d[0] = l;
|
||||
d[1] = r;
|
||||
Blowfish_decipher(c, d);
|
||||
l = d[0];
|
||||
r = d[1];
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
for (j = 0; j < 8; j++)
|
||||
data[j] ^= iv[j];
|
||||
iv -= 8;
|
||||
data -= 8;
|
||||
}
|
||||
l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
|
||||
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
|
||||
d[0] = l;
|
||||
d[1] = r;
|
||||
Blowfish_decipher(c, d);
|
||||
l = d[0];
|
||||
r = d[1];
|
||||
data[0] = l >> 24 & 0xff;
|
||||
data[1] = l >> 16 & 0xff;
|
||||
data[2] = l >> 8 & 0xff;
|
||||
data[3] = l & 0xff;
|
||||
data[4] = r >> 24 & 0xff;
|
||||
data[5] = r >> 16 & 0xff;
|
||||
data[6] = r >> 8 & 0xff;
|
||||
data[7] = r & 0xff;
|
||||
for (j = 0; j < 8; j++)
|
||||
data[j] ^= iva[j];
|
||||
}
|
||||
81
src/_csrc/blf.h
Normal file
81
src/_csrc/blf.h
Normal file
@ -0,0 +1,81 @@
|
||||
/* $OpenBSD: blf.h,v 1.6 2007/02/21 19:25:40 grunk Exp $ */
|
||||
|
||||
/*
|
||||
* Blowfish - a fast block cipher designed by Bruce Schneier
|
||||
*
|
||||
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLF_H_
|
||||
#define _BLF_H_
|
||||
|
||||
#include "pycabcrypt.h"
|
||||
|
||||
/* Schneier states the maximum key length to be 56 bytes.
|
||||
* The way how the subkeys are initialized by the key up
|
||||
* to (N+2)*4 i.e. 72 bytes are utilized.
|
||||
* Warning: For normal blowfish encryption only 56 bytes
|
||||
* of the key affect all cipherbits.
|
||||
*/
|
||||
|
||||
#define BLF_N 16 /* Number of Subkeys */
|
||||
#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
|
||||
#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */
|
||||
|
||||
/* Blowfish context */
|
||||
typedef struct BlowfishContext {
|
||||
u_int32_t S[4][256]; /* S-Boxes */
|
||||
u_int32_t P[BLF_N + 2]; /* Subkeys */
|
||||
} blf_ctx;
|
||||
|
||||
/* Raw access to customized Blowfish
|
||||
* blf_key is just:
|
||||
* Blowfish_initstate( state )
|
||||
* Blowfish_expand0state( state, key, keylen )
|
||||
*/
|
||||
|
||||
void Blowfish_encipher(blf_ctx *, u_int32_t *);
|
||||
void Blowfish_decipher(blf_ctx *, u_int32_t *);
|
||||
void Blowfish_initstate(blf_ctx *);
|
||||
void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
|
||||
void Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
|
||||
|
||||
/* Standard Blowfish */
|
||||
|
||||
void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
|
||||
void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
|
||||
void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
|
||||
|
||||
/* Converts u_int8_t to u_int32_t */
|
||||
u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t ,
|
||||
u_int16_t *);
|
||||
|
||||
void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
|
||||
void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
|
||||
|
||||
void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
|
||||
void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
|
||||
#endif
|
||||
238
src/_csrc/portable_endian.h
Normal file
238
src/_csrc/portable_endian.h
Normal file
@ -0,0 +1,238 @@
|
||||
// "License": Public Domain
|
||||
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
|
||||
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
|
||||
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
|
||||
// an example on how to get the endian conversion functions on different platforms.
|
||||
|
||||
#ifndef PORTABLE_ENDIAN_H__
|
||||
#define PORTABLE_ENDIAN_H__
|
||||
|
||||
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
|
||||
|
||||
# define __WINDOWS__
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
/* Define necessary macros for the header to expose all fields. */
|
||||
# if !defined(_BSD_SOURCE)
|
||||
# define _BSD_SOURCE
|
||||
# endif
|
||||
# if !defined(__USE_BSD)
|
||||
# define __USE_BSD
|
||||
# endif
|
||||
# if !defined(_DEFAULT_SOURCE)
|
||||
# define _DEFAULT_SOURCE
|
||||
# endif
|
||||
# include <endian.h>
|
||||
# include <features.h>
|
||||
/* See http://linux.die.net/man/3/endian */
|
||||
# if defined(htobe16) && defined(htole16) && defined(be16toh) && defined(le16toh) && defined(htobe32) && defined(htole32) && defined(be32toh) && defined(htole32) && defined(htobe64) && defined(htole64) && defined(be64) && defined(le64)
|
||||
/* Do nothing. The macros we need already exist. */
|
||||
# elif !defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9)))
|
||||
# include <arpa/inet.h>
|
||||
# if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
# define htobe16(x) htons(x)
|
||||
# define htole16(x) (x)
|
||||
# define be16toh(x) ntohs(x)
|
||||
# define le16toh(x) (x)
|
||||
|
||||
# define htobe32(x) htonl(x)
|
||||
# define htole32(x) (x)
|
||||
# define be32toh(x) ntohl(x)
|
||||
# define le32toh(x) (x)
|
||||
|
||||
# define htobe64(x) (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htonl(((uint32_t)(x)))) << 32))
|
||||
# define htole64(x) (x)
|
||||
# define be64toh(x) (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)ntohl(((uint32_t)(x)))) << 32))
|
||||
# define le64toh(x) (x)
|
||||
# elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
# define htobe16(x) (x)
|
||||
# define htole16(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
# define be16toh(x) (x)
|
||||
# define le16toh(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
|
||||
# define htobe32(x) (x)
|
||||
# define htole32(x) (((uint32_t)htole16(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)htole16(((uint16_t)(x)))) << 16))
|
||||
# define be32toh(x) (x)
|
||||
# define le32toh(x) (((uint32_t)le16toh(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)le16toh(((uint16_t)(x)))) << 16))
|
||||
|
||||
# define htobe64(x) (x)
|
||||
# define htole64(x) (((uint64_t)htole32(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htole32(((uint32_t)(x)))) << 32))
|
||||
# define be64toh(x) (x)
|
||||
# define le64toh(x) (((uint64_t)le32toh(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)le32toh(((uint32_t)(x)))) << 32))
|
||||
# else
|
||||
# error Byte Order not supported or not defined.
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
# include <libkern/OSByteOrder.h>
|
||||
|
||||
# define htobe16(x) OSSwapHostToBigInt16(x)
|
||||
# define htole16(x) OSSwapHostToLittleInt16(x)
|
||||
# define be16toh(x) OSSwapBigToHostInt16(x)
|
||||
# define le16toh(x) OSSwapLittleToHostInt16(x)
|
||||
|
||||
# define htobe32(x) OSSwapHostToBigInt32(x)
|
||||
# define htole32(x) OSSwapHostToLittleInt32(x)
|
||||
# define be32toh(x) OSSwapBigToHostInt32(x)
|
||||
# define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
|
||||
# define htobe64(x) OSSwapHostToBigInt64(x)
|
||||
# define htole64(x) OSSwapHostToLittleInt64(x)
|
||||
# define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
# define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||
|
||||
# define __BYTE_ORDER BYTE_ORDER
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
# define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
# include <sys/endian.h>
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
# include <endian.h>
|
||||
|
||||
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
||||
# include <sys/endian.h>
|
||||
|
||||
# if !defined(be16toh)
|
||||
# define be16toh(x) betoh16(x)
|
||||
# define le16toh(x) letoh16(x)
|
||||
# endif
|
||||
|
||||
# if !defined(be32toh)
|
||||
# define be32toh(x) betoh32(x)
|
||||
# define le32toh(x) letoh32(x)
|
||||
# endif
|
||||
|
||||
# if !defined(be64toh)
|
||||
# define be64toh(x) betoh64(x)
|
||||
# define le64toh(x) letoh64(x)
|
||||
# endif
|
||||
|
||||
#elif defined(__WINDOWS__)
|
||||
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
|
||||
# define htobe16(x) _byteswap_ushort(x)
|
||||
# define htole16(x) (x)
|
||||
# define be16toh(x) _byteswap_ushort(x)
|
||||
# define le16toh(x) (x)
|
||||
|
||||
# define htobe32(x) _byteswap_ulong(x)
|
||||
# define htole32(x) (x)
|
||||
# define be32toh(x) _byteswap_ulong(x)
|
||||
# define le32toh(x) (x)
|
||||
|
||||
# define htobe64(x) _byteswap_uint64(x)
|
||||
# define be64toh(x) _byteswap_uint64(x)
|
||||
# define htole64(x) (x)
|
||||
# define le64toh(x) (x)
|
||||
|
||||
# elif BYTE_ORDER == BIG_ENDIAN
|
||||
|
||||
/* that would be xbox 360 */
|
||||
# define htobe16(x) (x)
|
||||
# define htole16(x) __builtin_bswap16(x)
|
||||
# define be16toh(x) (x)
|
||||
# define le16toh(x) __builtin_bswap16(x)
|
||||
|
||||
# define htobe32(x) (x)
|
||||
# define htole32(x) __builtin_bswap32(x)
|
||||
# define be32toh(x) (x)
|
||||
# define le32toh(x) __builtin_bswap32(x)
|
||||
|
||||
# define htobe64(x) (x)
|
||||
# define htole64(x) __builtin_bswap64(x)
|
||||
# define be64toh(x) (x)
|
||||
# define le64toh(x) __builtin_bswap64(x)
|
||||
|
||||
# else
|
||||
|
||||
# error byte order not supported
|
||||
|
||||
# endif
|
||||
|
||||
# define __BYTE_ORDER BYTE_ORDER
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
# define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
#elif defined(__sun)
|
||||
|
||||
# include <sys/byteorder.h>
|
||||
|
||||
# define htobe16(x) BE_16(x)
|
||||
# define htole16(x) LE_16(x)
|
||||
# define be16toh(x) BE_16(x)
|
||||
# define le16toh(x) LE_16(x)
|
||||
|
||||
# define htobe32(x) BE_32(x)
|
||||
# define htole32(x) LE_32(x)
|
||||
# define be32toh(x) BE_32(x)
|
||||
# define le32toh(x) LE_32(x)
|
||||
|
||||
# define htobe64(x) BE_64(x)
|
||||
# define htole64(x) LE_64(x)
|
||||
# define be64toh(x) BE_64(x)
|
||||
# define le64toh(x) LE_64(x)
|
||||
|
||||
#elif defined _AIX /* AIX is always big endian */
|
||||
# define be64toh(x) (x)
|
||||
# define be32toh(x) (x)
|
||||
# define be16toh(x) (x)
|
||||
# define le32toh(x) \
|
||||
((((x) & 0xff) << 24) | \
|
||||
(((x) & 0xff00) << 8) | \
|
||||
(((x) & 0xff0000) >> 8) | \
|
||||
(((x) & 0xff000000) >> 24))
|
||||
# define le64toh(x) \
|
||||
((((x) & 0x00000000000000ffL) << 56) | \
|
||||
(((x) & 0x000000000000ff00L) << 40) | \
|
||||
(((x) & 0x0000000000ff0000L) << 24) | \
|
||||
(((x) & 0x00000000ff000000L) << 8) | \
|
||||
(((x) & 0x000000ff00000000L) >> 8) | \
|
||||
(((x) & 0x0000ff0000000000L) >> 24) | \
|
||||
(((x) & 0x00ff000000000000L) >> 40) | \
|
||||
(((x) & 0xff00000000000000L) >> 56))
|
||||
# ifndef htobe64
|
||||
# define htobe64(x) be64toh(x)
|
||||
# endif
|
||||
# ifndef htobe32
|
||||
# define htobe32(x) be32toh(x)
|
||||
# endif
|
||||
# ifndef htobe16
|
||||
# define htobe16(x) be16toh(x)
|
||||
# endif
|
||||
|
||||
#elif defined(__MVS__)
|
||||
|
||||
# define htobe16(x) (x)
|
||||
# define htole16(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
# define be16toh(x) (x)
|
||||
# define le16toh(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
|
||||
# define htobe32(x) (x)
|
||||
# define htole32(x) (((uint32_t)htole16(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)htole16(((uint16_t)(x)))) << 16))
|
||||
# define be32toh(x) (x)
|
||||
# define le32toh(x) (((uint32_t)le16toh(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)le16toh(((uint16_t)(x)))) << 16))
|
||||
|
||||
# define htobe64(x) (x)
|
||||
# define htole64(x) (((uint64_t)htole32(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htole32(((uint32_t)(x)))) << 32))
|
||||
# define be64toh(x) (x)
|
||||
# define le64toh(x) (((uint64_t)le32toh(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)le32toh(((uint32_t)(x)))) << 32))
|
||||
|
||||
#else
|
||||
|
||||
# error platform not supported
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
44
src/_csrc/pycabcrypt.h
Normal file
44
src/_csrc/pycabcrypt.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef PYCABCRYPT
|
||||
#define PYCABCRYPT
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "portable_endian.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
typedef unsigned char uint8_t;
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
typedef unsigned uint32_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
#define snprintf _snprintf
|
||||
#define __attribute__(unused)
|
||||
#elif defined(__sun)
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
#elif defined(__MVS__)
|
||||
#include <stdint.h>
|
||||
typedef uint8_t u_int8_t;
|
||||
typedef uint16_t u_int16_t;
|
||||
typedef uint32_t u_int32_t;
|
||||
typedef uint64_t u_int64_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#define explicit_bzero(s,n) memset(s, 0, n)
|
||||
#define DEF_WEAK(f)
|
||||
|
||||
int bcrypt_hashpass(const char *key, const char *salt, char *encrypted, size_t encryptedlen);
|
||||
int encode_base64(char *, const u_int8_t *, size_t);
|
||||
int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
|
||||
int bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint8_t *key, size_t keylen, unsigned int rounds);
|
||||
|
||||
#endif
|
||||
|
||||
812
src/_csrc/sha2.c
Normal file
812
src/_csrc/sha2.c
Normal file
@ -0,0 +1,812 @@
|
||||
/* $OpenBSD: sha2.c,v 1.18 2015/03/14 03:38:46 jsg Exp $ */
|
||||
|
||||
/*
|
||||
* FILE: sha2.c
|
||||
* AUTHOR: Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright (c) 2000-2001, Aaron D. Gifford
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
|
||||
*/
|
||||
|
||||
#include "pycabcrypt.h"
|
||||
#include "sha2.h"
|
||||
|
||||
/*
|
||||
* UNROLLED TRANSFORM LOOP NOTE:
|
||||
* You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
|
||||
* loop version for the hash transform rounds (defined using macros
|
||||
* later in this file). Either define on the command line, for example:
|
||||
*
|
||||
* cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
|
||||
*
|
||||
* or define below:
|
||||
*
|
||||
* #define SHA2_UNROLL_TRANSFORM
|
||||
*
|
||||
*/
|
||||
#ifndef SMALL_KERNEL
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
#define SHA2_UNROLL_TRANSFORM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*** SHA-256/384/512 Various Length Definitions ***********************/
|
||||
/* NOTE: Most of these are in sha2.h */
|
||||
#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
|
||||
#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
|
||||
#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
|
||||
|
||||
/*
|
||||
* Macro for incrementally adding the unsigned 64-bit integer n to the
|
||||
* unsigned 128-bit integer (represented using a two-element array of
|
||||
* 64-bit words):
|
||||
*/
|
||||
#define ADDINC128(w,n) { \
|
||||
(w)[0] += (u_int64_t)(n); \
|
||||
if ((w)[0] < (n)) { \
|
||||
(w)[1]++; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*** THE SIX LOGICAL FUNCTIONS ****************************************/
|
||||
/*
|
||||
* Bit shifting and rotation (used by the six SHA-XYZ logical functions:
|
||||
*
|
||||
* NOTE: The naming of R and S appears backwards here (R is a SHIFT and
|
||||
* S is a ROTATION) because the SHA-256/384/512 description document
|
||||
* (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this
|
||||
* same "backwards" definition.
|
||||
*/
|
||||
/* Shift-right (used in SHA-256, SHA-384, and SHA-512): */
|
||||
#define R(b,x) ((x) >> (b))
|
||||
/* 32-bit Rotate-right (used in SHA-256): */
|
||||
#define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
|
||||
/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
|
||||
#define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
|
||||
|
||||
/* Two of six logical functions used in SHA-256, SHA-384, and SHA-512: */
|
||||
#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
|
||||
|
||||
/* Four of six logical functions used in SHA-256: */
|
||||
#define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x)))
|
||||
#define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x)))
|
||||
#define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x)))
|
||||
#define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x)))
|
||||
|
||||
/* Four of six logical functions used in SHA-384 and SHA-512: */
|
||||
#define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x)))
|
||||
#define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x)))
|
||||
#define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x)))
|
||||
#define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x)))
|
||||
|
||||
/*** INTERNAL FUNCTION PROTOTYPES *************************************/
|
||||
/* NOTE: These should not be accessed directly from outside this
|
||||
* library -- they are intended for private internal visibility/use
|
||||
* only.
|
||||
*/
|
||||
void SHA512Last(SHA2_CTX *);
|
||||
void SHA256Transform(u_int32_t *, const u_int8_t *);
|
||||
void SHA512Transform(u_int64_t *, const u_int8_t *);
|
||||
|
||||
|
||||
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
|
||||
/* Hash constant words K for SHA-256: */
|
||||
const static u_int32_t K256[64] = {
|
||||
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
|
||||
0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
|
||||
0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
|
||||
0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
|
||||
0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
|
||||
0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
|
||||
0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
|
||||
0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
|
||||
0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
|
||||
0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
|
||||
0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
|
||||
0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
|
||||
0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
|
||||
0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
|
||||
0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
|
||||
0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-256: */
|
||||
const static u_int32_t sha256_initial_hash_value[8] = {
|
||||
0x6a09e667UL,
|
||||
0xbb67ae85UL,
|
||||
0x3c6ef372UL,
|
||||
0xa54ff53aUL,
|
||||
0x510e527fUL,
|
||||
0x9b05688cUL,
|
||||
0x1f83d9abUL,
|
||||
0x5be0cd19UL
|
||||
};
|
||||
|
||||
/* Hash constant words K for SHA-384 and SHA-512: */
|
||||
const static u_int64_t K512[80] = {
|
||||
0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
|
||||
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
|
||||
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
|
||||
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
|
||||
0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
|
||||
0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
|
||||
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
|
||||
0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
|
||||
0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
|
||||
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
|
||||
0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
|
||||
0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
|
||||
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
|
||||
0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
|
||||
0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
|
||||
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
|
||||
0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
|
||||
0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
|
||||
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
|
||||
0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
|
||||
0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
|
||||
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
|
||||
0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
|
||||
0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
|
||||
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
|
||||
0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
|
||||
0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
|
||||
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
|
||||
0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
|
||||
0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
|
||||
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
|
||||
0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
|
||||
0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
|
||||
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
|
||||
0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
|
||||
0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
|
||||
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
|
||||
0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
|
||||
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
|
||||
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-384 */
|
||||
const static u_int64_t sha384_initial_hash_value[8] = {
|
||||
0xcbbb9d5dc1059ed8ULL,
|
||||
0x629a292a367cd507ULL,
|
||||
0x9159015a3070dd17ULL,
|
||||
0x152fecd8f70e5939ULL,
|
||||
0x67332667ffc00b31ULL,
|
||||
0x8eb44a8768581511ULL,
|
||||
0xdb0c2e0d64f98fa7ULL,
|
||||
0x47b5481dbefa4fa4ULL
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-512 */
|
||||
const static u_int64_t sha512_initial_hash_value[8] = {
|
||||
0x6a09e667f3bcc908ULL,
|
||||
0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL,
|
||||
0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL,
|
||||
0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL,
|
||||
0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
|
||||
/*** SHA-256: *********************************************************/
|
||||
void
|
||||
SHA256Init(SHA2_CTX *context)
|
||||
{
|
||||
memcpy(context->state.st32, sha256_initial_hash_value,
|
||||
SHA256_DIGEST_LENGTH);
|
||||
memset(context->buffer, 0, SHA256_BLOCK_LENGTH);
|
||||
context->bitcount[0] = 0;
|
||||
}
|
||||
|
||||
#ifdef SHA2_UNROLL_TRANSFORM
|
||||
|
||||
/* Unrolled SHA-256 round macros: */
|
||||
|
||||
#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) do { \
|
||||
W256[j] = (u_int32_t)data[3] | ((u_int32_t)data[2] << 8) | \
|
||||
((u_int32_t)data[1] << 16) | ((u_int32_t)data[0] << 24); \
|
||||
data += 4; \
|
||||
T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + W256[j]; \
|
||||
(d) += T1; \
|
||||
(h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \
|
||||
j++; \
|
||||
} while(0)
|
||||
|
||||
#define ROUND256(a,b,c,d,e,f,g,h) do { \
|
||||
s0 = W256[(j+1)&0x0f]; \
|
||||
s0 = sigma0_256(s0); \
|
||||
s1 = W256[(j+14)&0x0f]; \
|
||||
s1 = sigma1_256(s1); \
|
||||
T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + \
|
||||
(W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
|
||||
(d) += T1; \
|
||||
(h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \
|
||||
j++; \
|
||||
} while(0)
|
||||
|
||||
void
|
||||
SHA256Transform(u_int32_t *state, const u_int8_t *data)
|
||||
{
|
||||
u_int32_t a, b, c, d, e, f, g, h, s0, s1;
|
||||
u_int32_t T1, W256[16];
|
||||
int j;
|
||||
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
|
||||
j = 0;
|
||||
do {
|
||||
/* Rounds 0 to 15 (unrolled): */
|
||||
ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
|
||||
ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
|
||||
ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
|
||||
ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
|
||||
ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
|
||||
ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
|
||||
ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
|
||||
ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
|
||||
} while (j < 16);
|
||||
|
||||
/* Now for the remaining rounds to 64: */
|
||||
do {
|
||||
ROUND256(a,b,c,d,e,f,g,h);
|
||||
ROUND256(h,a,b,c,d,e,f,g);
|
||||
ROUND256(g,h,a,b,c,d,e,f);
|
||||
ROUND256(f,g,h,a,b,c,d,e);
|
||||
ROUND256(e,f,g,h,a,b,c,d);
|
||||
ROUND256(d,e,f,g,h,a,b,c);
|
||||
ROUND256(c,d,e,f,g,h,a,b);
|
||||
ROUND256(b,c,d,e,f,g,h,a);
|
||||
} while (j < 64);
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
|
||||
/* Clean up */
|
||||
a = b = c = d = e = f = g = h = T1 = 0;
|
||||
}
|
||||
|
||||
#else /* SHA2_UNROLL_TRANSFORM */
|
||||
|
||||
void
|
||||
SHA256Transform(u_int32_t *state, const u_int8_t *data)
|
||||
{
|
||||
u_int32_t a, b, c, d, e, f, g, h, s0, s1;
|
||||
u_int32_t T1, T2, W256[16];
|
||||
int j;
|
||||
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
|
||||
j = 0;
|
||||
do {
|
||||
W256[j] = (u_int32_t)data[3] | ((u_int32_t)data[2] << 8) |
|
||||
((u_int32_t)data[1] << 16) | ((u_int32_t)data[0] << 24);
|
||||
data += 4;
|
||||
/* Apply the SHA-256 compression function to update a..h */
|
||||
T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
|
||||
T2 = Sigma0_256(a) + Maj(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + T1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = T1 + T2;
|
||||
|
||||
j++;
|
||||
} while (j < 16);
|
||||
|
||||
do {
|
||||
/* Part of the message block expansion: */
|
||||
s0 = W256[(j+1)&0x0f];
|
||||
s0 = sigma0_256(s0);
|
||||
s1 = W256[(j+14)&0x0f];
|
||||
s1 = sigma1_256(s1);
|
||||
|
||||
/* Apply the SHA-256 compression function to update a..h */
|
||||
T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
|
||||
(W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
|
||||
T2 = Sigma0_256(a) + Maj(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + T1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = T1 + T2;
|
||||
|
||||
j++;
|
||||
} while (j < 64);
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
|
||||
/* Clean up */
|
||||
a = b = c = d = e = f = g = h = T1 = T2 = 0;
|
||||
}
|
||||
|
||||
#endif /* SHA2_UNROLL_TRANSFORM */
|
||||
|
||||
void
|
||||
SHA256Update(SHA2_CTX *context, const void *dataptr, size_t len)
|
||||
{
|
||||
const uint8_t *data = dataptr;
|
||||
size_t freespace, usedspace;
|
||||
|
||||
/* Calling with no data is valid (we do nothing) */
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
|
||||
if (usedspace > 0) {
|
||||
/* Calculate how much free space is available in the buffer */
|
||||
freespace = SHA256_BLOCK_LENGTH - usedspace;
|
||||
|
||||
if (len >= freespace) {
|
||||
/* Fill the buffer completely and process it */
|
||||
memcpy(&context->buffer[usedspace], data, freespace);
|
||||
context->bitcount[0] += freespace << 3;
|
||||
len -= freespace;
|
||||
data += freespace;
|
||||
SHA256Transform(context->state.st32, context->buffer);
|
||||
} else {
|
||||
/* The buffer is not yet full */
|
||||
memcpy(&context->buffer[usedspace], data, len);
|
||||
context->bitcount[0] += len << 3;
|
||||
/* Clean up: */
|
||||
usedspace = freespace = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (len >= SHA256_BLOCK_LENGTH) {
|
||||
/* Process as many complete blocks as we can */
|
||||
SHA256Transform(context->state.st32, data);
|
||||
context->bitcount[0] += SHA256_BLOCK_LENGTH << 3;
|
||||
len -= SHA256_BLOCK_LENGTH;
|
||||
data += SHA256_BLOCK_LENGTH;
|
||||
}
|
||||
if (len > 0) {
|
||||
/* There's left-overs, so save 'em */
|
||||
memcpy(context->buffer, data, len);
|
||||
context->bitcount[0] += len << 3;
|
||||
}
|
||||
/* Clean up: */
|
||||
usedspace = freespace = 0;
|
||||
}
|
||||
|
||||
void
|
||||
SHA256Final(u_int8_t digest[], SHA2_CTX *context)
|
||||
{
|
||||
unsigned int usedspace;
|
||||
|
||||
usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
|
||||
/* Convert FROM host byte order */
|
||||
context->bitcount[0] = htobe64(context->bitcount[0]);
|
||||
if (usedspace > 0) {
|
||||
/* Begin padding with a 1 bit: */
|
||||
context->buffer[usedspace++] = 0x80;
|
||||
|
||||
if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) {
|
||||
/* Set-up for the last transform: */
|
||||
memset(&context->buffer[usedspace], 0,
|
||||
SHA256_SHORT_BLOCK_LENGTH - usedspace);
|
||||
} else {
|
||||
if (usedspace < SHA256_BLOCK_LENGTH) {
|
||||
memset(&context->buffer[usedspace], 0,
|
||||
SHA256_BLOCK_LENGTH - usedspace);
|
||||
}
|
||||
/* Do second-to-last transform: */
|
||||
SHA256Transform(context->state.st32, context->buffer);
|
||||
|
||||
/* And set-up for the last transform: */
|
||||
memset(context->buffer, 0,
|
||||
SHA256_SHORT_BLOCK_LENGTH);
|
||||
}
|
||||
} else {
|
||||
/* Set-up for the last transform: */
|
||||
memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH);
|
||||
|
||||
/* Begin padding with a 1 bit: */
|
||||
*context->buffer = 0x80;
|
||||
}
|
||||
/* Set the bit count: */
|
||||
*(u_int64_t *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount[0];
|
||||
|
||||
/* Final transform: */
|
||||
SHA256Transform(context->state.st32, context->buffer);
|
||||
|
||||
{
|
||||
/* Convert TO host byte order */
|
||||
int j;
|
||||
for (j = 0; j < 8; j++) {
|
||||
context->state.st32[j] = le32toh(context->state.st32[j]);
|
||||
}
|
||||
}
|
||||
memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
|
||||
/* Clean up state data: */
|
||||
explicit_bzero(context, sizeof(*context));
|
||||
usedspace = 0;
|
||||
}
|
||||
|
||||
|
||||
/*** SHA-512: *********************************************************/
|
||||
void
|
||||
SHA512Init(SHA2_CTX *context)
|
||||
{
|
||||
memcpy(context->state.st64, sha512_initial_hash_value,
|
||||
SHA512_DIGEST_LENGTH);
|
||||
memset(context->buffer, 0, SHA512_BLOCK_LENGTH);
|
||||
context->bitcount[0] = context->bitcount[1] = 0;
|
||||
}
|
||||
|
||||
#ifdef SHA2_UNROLL_TRANSFORM
|
||||
|
||||
/* Unrolled SHA-512 round macros: */
|
||||
|
||||
#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) do { \
|
||||
W512[j] = (u_int64_t)data[7] | ((u_int64_t)data[6] << 8) | \
|
||||
((u_int64_t)data[5] << 16) | ((u_int64_t)data[4] << 24) | \
|
||||
((u_int64_t)data[3] << 32) | ((u_int64_t)data[2] << 40) | \
|
||||
((u_int64_t)data[1] << 48) | ((u_int64_t)data[0] << 56); \
|
||||
data += 8; \
|
||||
T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + W512[j]; \
|
||||
(d) += T1; \
|
||||
(h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \
|
||||
j++; \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define ROUND512(a,b,c,d,e,f,g,h) do { \
|
||||
s0 = W512[(j+1)&0x0f]; \
|
||||
s0 = sigma0_512(s0); \
|
||||
s1 = W512[(j+14)&0x0f]; \
|
||||
s1 = sigma1_512(s1); \
|
||||
T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + \
|
||||
(W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
|
||||
(d) += T1; \
|
||||
(h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \
|
||||
j++; \
|
||||
} while(0)
|
||||
|
||||
void
|
||||
SHA512Transform(u_int64_t *state, const u_int8_t *data)
|
||||
{
|
||||
u_int64_t a, b, c, d, e, f, g, h, s0, s1;
|
||||
u_int64_t T1, W512[16];
|
||||
int j;
|
||||
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
|
||||
j = 0;
|
||||
do {
|
||||
ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
|
||||
ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
|
||||
ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
|
||||
ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
|
||||
ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
|
||||
ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
|
||||
ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
|
||||
ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
|
||||
} while (j < 16);
|
||||
|
||||
/* Now for the remaining rounds up to 79: */
|
||||
do {
|
||||
ROUND512(a,b,c,d,e,f,g,h);
|
||||
ROUND512(h,a,b,c,d,e,f,g);
|
||||
ROUND512(g,h,a,b,c,d,e,f);
|
||||
ROUND512(f,g,h,a,b,c,d,e);
|
||||
ROUND512(e,f,g,h,a,b,c,d);
|
||||
ROUND512(d,e,f,g,h,a,b,c);
|
||||
ROUND512(c,d,e,f,g,h,a,b);
|
||||
ROUND512(b,c,d,e,f,g,h,a);
|
||||
} while (j < 80);
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
|
||||
/* Clean up */
|
||||
a = b = c = d = e = f = g = h = T1 = 0;
|
||||
}
|
||||
|
||||
#else /* SHA2_UNROLL_TRANSFORM */
|
||||
|
||||
void
|
||||
SHA512Transform(u_int64_t *state, const u_int8_t *data)
|
||||
{
|
||||
u_int64_t a, b, c, d, e, f, g, h, s0, s1;
|
||||
u_int64_t T1, T2, W512[16];
|
||||
int j;
|
||||
|
||||
/* Initialize registers with the prev. intermediate value */
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
|
||||
j = 0;
|
||||
do {
|
||||
W512[j] = (u_int64_t)data[7] | ((u_int64_t)data[6] << 8) |
|
||||
((u_int64_t)data[5] << 16) | ((u_int64_t)data[4] << 24) |
|
||||
((u_int64_t)data[3] << 32) | ((u_int64_t)data[2] << 40) |
|
||||
((u_int64_t)data[1] << 48) | ((u_int64_t)data[0] << 56);
|
||||
data += 8;
|
||||
/* Apply the SHA-512 compression function to update a..h */
|
||||
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
|
||||
T2 = Sigma0_512(a) + Maj(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + T1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = T1 + T2;
|
||||
|
||||
j++;
|
||||
} while (j < 16);
|
||||
|
||||
do {
|
||||
/* Part of the message block expansion: */
|
||||
s0 = W512[(j+1)&0x0f];
|
||||
s0 = sigma0_512(s0);
|
||||
s1 = W512[(j+14)&0x0f];
|
||||
s1 = sigma1_512(s1);
|
||||
|
||||
/* Apply the SHA-512 compression function to update a..h */
|
||||
T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
|
||||
(W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
|
||||
T2 = Sigma0_512(a) + Maj(a, b, c);
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + T1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = T1 + T2;
|
||||
|
||||
j++;
|
||||
} while (j < 80);
|
||||
|
||||
/* Compute the current intermediate hash value */
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
|
||||
/* Clean up */
|
||||
a = b = c = d = e = f = g = h = T1 = T2 = 0;
|
||||
}
|
||||
|
||||
#endif /* SHA2_UNROLL_TRANSFORM */
|
||||
|
||||
void
|
||||
SHA512Update(SHA2_CTX *context, const void *dataptr, size_t len)
|
||||
{
|
||||
const uint8_t *data = dataptr;
|
||||
size_t freespace, usedspace;
|
||||
|
||||
/* Calling with no data is valid (we do nothing) */
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
|
||||
if (usedspace > 0) {
|
||||
/* Calculate how much free space is available in the buffer */
|
||||
freespace = SHA512_BLOCK_LENGTH - usedspace;
|
||||
|
||||
if (len >= freespace) {
|
||||
/* Fill the buffer completely and process it */
|
||||
memcpy(&context->buffer[usedspace], data, freespace);
|
||||
ADDINC128(context->bitcount, freespace << 3);
|
||||
len -= freespace;
|
||||
data += freespace;
|
||||
SHA512Transform(context->state.st64, context->buffer);
|
||||
} else {
|
||||
/* The buffer is not yet full */
|
||||
memcpy(&context->buffer[usedspace], data, len);
|
||||
ADDINC128(context->bitcount, len << 3);
|
||||
/* Clean up: */
|
||||
usedspace = freespace = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
while (len >= SHA512_BLOCK_LENGTH) {
|
||||
/* Process as many complete blocks as we can */
|
||||
SHA512Transform(context->state.st64, data);
|
||||
ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
|
||||
len -= SHA512_BLOCK_LENGTH;
|
||||
data += SHA512_BLOCK_LENGTH;
|
||||
}
|
||||
if (len > 0) {
|
||||
/* There's left-overs, so save 'em */
|
||||
memcpy(context->buffer, data, len);
|
||||
ADDINC128(context->bitcount, len << 3);
|
||||
}
|
||||
/* Clean up: */
|
||||
usedspace = freespace = 0;
|
||||
}
|
||||
|
||||
void
|
||||
SHA512Last(SHA2_CTX *context)
|
||||
{
|
||||
unsigned int usedspace;
|
||||
|
||||
usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
|
||||
/* Convert FROM host byte order */
|
||||
context->bitcount[0] = htobe64(context->bitcount[0]);
|
||||
context->bitcount[1] = htobe64(context->bitcount[1]);
|
||||
if (usedspace > 0) {
|
||||
/* Begin padding with a 1 bit: */
|
||||
context->buffer[usedspace++] = 0x80;
|
||||
|
||||
if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) {
|
||||
/* Set-up for the last transform: */
|
||||
memset(&context->buffer[usedspace], 0,
|
||||
SHA512_SHORT_BLOCK_LENGTH - usedspace);
|
||||
} else {
|
||||
if (usedspace < SHA512_BLOCK_LENGTH) {
|
||||
memset(&context->buffer[usedspace], 0,
|
||||
SHA512_BLOCK_LENGTH - usedspace);
|
||||
}
|
||||
/* Do second-to-last transform: */
|
||||
SHA512Transform(context->state.st64, context->buffer);
|
||||
|
||||
/* And set-up for the last transform: */
|
||||
memset(context->buffer, 0, SHA512_BLOCK_LENGTH - 2);
|
||||
}
|
||||
} else {
|
||||
/* Prepare for final transform: */
|
||||
memset(context->buffer, 0, SHA512_SHORT_BLOCK_LENGTH);
|
||||
|
||||
/* Begin padding with a 1 bit: */
|
||||
*context->buffer = 0x80;
|
||||
}
|
||||
/* Store the length of input data (in bits): */
|
||||
*(u_int64_t *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
|
||||
*(u_int64_t *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
|
||||
|
||||
/* Final transform: */
|
||||
SHA512Transform(context->state.st64, context->buffer);
|
||||
}
|
||||
|
||||
void
|
||||
SHA512Final(u_int8_t digest[], SHA2_CTX *context)
|
||||
{
|
||||
|
||||
SHA512Last(context);
|
||||
|
||||
/* Save the hash data for output: */
|
||||
{
|
||||
/* Convert TO host byte order */
|
||||
int j;
|
||||
for (j = 0; j < 8; j++) {
|
||||
context->state.st64[j] = be64toh(context->state.st64[j]);
|
||||
}
|
||||
}
|
||||
memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
|
||||
|
||||
/* Zero out state data */
|
||||
explicit_bzero(context, sizeof(*context));
|
||||
}
|
||||
|
||||
|
||||
/*** SHA-384: *********************************************************/
|
||||
void
|
||||
SHA384Init(SHA2_CTX *context)
|
||||
{
|
||||
memcpy(context->state.st64, sha384_initial_hash_value,
|
||||
SHA512_DIGEST_LENGTH);
|
||||
memset(context->buffer, 0, SHA384_BLOCK_LENGTH);
|
||||
context->bitcount[0] = context->bitcount[1] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
SHA384Update(SHA2_CTX *context, const void *data, size_t len)
|
||||
{
|
||||
SHA512Update(context, data, len);
|
||||
}
|
||||
|
||||
void
|
||||
SHA384Final(u_int8_t digest[], SHA2_CTX *context)
|
||||
{
|
||||
|
||||
SHA512Last(context);
|
||||
|
||||
/* Save the hash data for output: */
|
||||
{
|
||||
/* Convert TO host byte order */
|
||||
int j;
|
||||
for (j = 0; j < 6; j++) {
|
||||
context->state.st64[j] = be64toh(context->state.st64[j]);
|
||||
}
|
||||
}
|
||||
memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
|
||||
/* Zero out state data */
|
||||
explicit_bzero(context, sizeof(*context));
|
||||
}
|
||||
87
src/_csrc/sha2.h
Normal file
87
src/_csrc/sha2.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* $OpenBSD: sha2.h,v 1.5 2014/11/16 17:39:09 tedu Exp $ */
|
||||
|
||||
/*
|
||||
* FILE: sha2.h
|
||||
* AUTHOR: Aaron D. Gifford <me@aarongifford.com>
|
||||
*
|
||||
* Copyright (c) 2000-2001, Aaron D. Gifford
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
|
||||
*/
|
||||
|
||||
#ifndef _SHA2_H
|
||||
#define _SHA2_H
|
||||
|
||||
|
||||
/*** SHA-256/384/512 Various Length Definitions ***********************/
|
||||
#define SHA256_BLOCK_LENGTH 64
|
||||
#define SHA256_DIGEST_LENGTH 32
|
||||
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA384_BLOCK_LENGTH 128
|
||||
#define SHA384_DIGEST_LENGTH 48
|
||||
#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
|
||||
#define SHA512_BLOCK_LENGTH 128
|
||||
#define SHA512_DIGEST_LENGTH 64
|
||||
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
||||
|
||||
|
||||
/*** SHA-256/384/512 Context Structure *******************************/
|
||||
typedef struct _SHA2_CTX {
|
||||
union {
|
||||
u_int32_t st32[8];
|
||||
u_int64_t st64[8];
|
||||
} state;
|
||||
u_int64_t bitcount[2];
|
||||
u_int8_t buffer[SHA512_BLOCK_LENGTH];
|
||||
} SHA2_CTX;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void SHA256Init(SHA2_CTX *);
|
||||
void SHA256Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA256Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
|
||||
|
||||
void SHA384Init(SHA2_CTX *);
|
||||
void SHA384Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA384Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
|
||||
|
||||
void SHA512Init(SHA2_CTX *);
|
||||
void SHA512Update(SHA2_CTX *, const void *, size_t)
|
||||
__attribute__((__bounded__(__string__,2,3)));
|
||||
void SHA512Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA2_CTX *)
|
||||
__attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SHA2_H */
|
||||
29
src/_csrc/timingsafe_bcmp.c
Normal file
29
src/_csrc/timingsafe_bcmp.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* $OpenBSD: timingsafe_bcmp.c,v 1.1 2010/09/24 13:33:00 matthew Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2010 Damien Miller. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "pycabcrypt.h"
|
||||
|
||||
int
|
||||
timingsafe_bcmp(const void *b1, const void *b2, size_t n)
|
||||
{
|
||||
const unsigned char *p1 = b1, *p2 = b2;
|
||||
int ret = 0;
|
||||
|
||||
for (; n > 0; n--)
|
||||
ret |= *p1++ ^ *p2++;
|
||||
return (ret != 0);
|
||||
}
|
||||
41
src/bcrypt/__about__.py
Normal file
41
src/bcrypt/__about__.py
Normal file
@ -0,0 +1,41 @@
|
||||
# Author:: Donald Stufft (<donald@stufft.io>)
|
||||
# Copyright:: Copyright (c) 2013 Donald Stufft
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
|
||||
__all__ = [
|
||||
"__title__",
|
||||
"__summary__",
|
||||
"__uri__",
|
||||
"__version__",
|
||||
"__author__",
|
||||
"__email__",
|
||||
"__license__",
|
||||
"__copyright__",
|
||||
]
|
||||
|
||||
__title__ = "bcrypt"
|
||||
__summary__ = "Modern password hashing for your software and your servers"
|
||||
__uri__ = "https://github.com/pyca/bcrypt/"
|
||||
|
||||
__version__ = "3.2.2"
|
||||
|
||||
__author__ = "The Python Cryptographic Authority developers"
|
||||
__email__ = "cryptography-dev@python.org"
|
||||
|
||||
__license__ = "Apache License, Version 2.0"
|
||||
__copyright__ = "Copyright 2013-2022 {0}".format(__author__)
|
||||
@ -1,3 +1,7 @@
|
||||
# Author:: Donald Stufft (<donald@stufft.io>)
|
||||
# Copyright:: Copyright (c) 2013 Donald Stufft
|
||||
# License:: Apache License, Version 2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -9,8 +13,15 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
|
||||
from ._bcrypt import (
|
||||
import hmac
|
||||
import os
|
||||
import re
|
||||
import warnings
|
||||
|
||||
from .__about__ import (
|
||||
__author__,
|
||||
__copyright__,
|
||||
__email__,
|
||||
@ -18,26 +29,143 @@ from ._bcrypt import (
|
||||
__summary__,
|
||||
__title__,
|
||||
__uri__,
|
||||
checkpw,
|
||||
gensalt,
|
||||
hashpw,
|
||||
kdf,
|
||||
)
|
||||
from ._bcrypt import (
|
||||
__version_ex__ as __version__,
|
||||
__version__,
|
||||
)
|
||||
from . import _bcrypt # noqa: I100
|
||||
|
||||
|
||||
__all__ = [
|
||||
"__author__",
|
||||
"__copyright__",
|
||||
"__email__",
|
||||
"__license__",
|
||||
"__summary__",
|
||||
"__title__",
|
||||
"__summary__",
|
||||
"__uri__",
|
||||
"__version__",
|
||||
"checkpw",
|
||||
"__author__",
|
||||
"__email__",
|
||||
"__license__",
|
||||
"__copyright__",
|
||||
"gensalt",
|
||||
"hashpw",
|
||||
"kdf",
|
||||
"checkpw",
|
||||
]
|
||||
|
||||
|
||||
_normalize_re = re.compile(rb"^\$2y\$")
|
||||
|
||||
|
||||
def gensalt(rounds: int = 12, prefix: bytes = b"2b") -> bytes:
|
||||
if prefix not in (b"2a", b"2b"):
|
||||
raise ValueError("Supported prefixes are b'2a' or b'2b'")
|
||||
|
||||
if rounds < 4 or rounds > 31:
|
||||
raise ValueError("Invalid rounds")
|
||||
|
||||
salt = os.urandom(16)
|
||||
output = _bcrypt.ffi.new("char[]", 30)
|
||||
_bcrypt.lib.encode_base64(output, salt, len(salt))
|
||||
|
||||
return (
|
||||
b"$"
|
||||
+ prefix
|
||||
+ b"$"
|
||||
+ ("%2.2u" % rounds).encode("ascii")
|
||||
+ b"$"
|
||||
+ _bcrypt.ffi.string(output)
|
||||
)
|
||||
|
||||
|
||||
def hashpw(password: bytes, salt: bytes) -> bytes:
|
||||
if isinstance(password, str) or isinstance(salt, str):
|
||||
raise TypeError("Strings must be encoded before hashing")
|
||||
|
||||
if b"\x00" in password:
|
||||
raise ValueError("password may not contain NUL bytes")
|
||||
|
||||
# bcrypt originally suffered from a wraparound bug:
|
||||
# http://www.openwall.com/lists/oss-security/2012/01/02/4
|
||||
# This bug was corrected in the OpenBSD source by truncating inputs to 72
|
||||
# bytes on the updated prefix $2b$, but leaving $2a$ unchanged for
|
||||
# compatibility. However, pyca/bcrypt 2.0.0 *did* correctly truncate inputs
|
||||
# on $2a$, so we do it here to preserve compatibility with 2.0.0
|
||||
password = password[:72]
|
||||
|
||||
# When the original 8bit bug was found the original library we supported
|
||||
# added a new prefix, $2y$, that fixes it. This prefix is exactly the same
|
||||
# as the $2b$ prefix added by OpenBSD other than the name. Since the
|
||||
# OpenBSD library does not support the $2y$ prefix, if the salt given to us
|
||||
# is for the $2y$ prefix, we'll just mugne it so that it's a $2b$ prior to
|
||||
# passing it into the C library.
|
||||
original_salt, salt = salt, _normalize_re.sub(b"$2b$", salt)
|
||||
|
||||
hashed = _bcrypt.ffi.new("char[]", 128)
|
||||
retval = _bcrypt.lib.bcrypt_hashpass(password, salt, hashed, len(hashed))
|
||||
|
||||
if retval != 0:
|
||||
raise ValueError("Invalid salt")
|
||||
|
||||
# Now that we've gotten our hashed password, we want to ensure that the
|
||||
# prefix we return is the one that was passed in, so we'll use the prefix
|
||||
# from the original salt and concatenate that with the return value (minus
|
||||
# the return value's prefix). This will ensure that if someone passed in a
|
||||
# salt with a $2y$ prefix, that they get back a hash with a $2y$ prefix
|
||||
# even though we munged it to $2b$.
|
||||
return original_salt[:4] + _bcrypt.ffi.string(hashed)[4:]
|
||||
|
||||
|
||||
def checkpw(password: bytes, hashed_password: bytes) -> bool:
|
||||
if isinstance(password, str) or isinstance(hashed_password, str):
|
||||
raise TypeError("Strings must be encoded before checking")
|
||||
|
||||
if b"\x00" in password or b"\x00" in hashed_password:
|
||||
raise ValueError(
|
||||
"password and hashed_password may not contain NUL bytes"
|
||||
)
|
||||
|
||||
ret = hashpw(password, hashed_password)
|
||||
return hmac.compare_digest(ret, hashed_password)
|
||||
|
||||
|
||||
def kdf(
|
||||
password: bytes,
|
||||
salt: bytes,
|
||||
desired_key_bytes: int,
|
||||
rounds: int,
|
||||
ignore_few_rounds: bool = False,
|
||||
) -> bytes:
|
||||
if isinstance(password, str) or isinstance(salt, str):
|
||||
raise TypeError("Strings must be encoded before hashing")
|
||||
|
||||
if len(password) == 0 or len(salt) == 0:
|
||||
raise ValueError("password and salt must not be empty")
|
||||
|
||||
if desired_key_bytes <= 0 or desired_key_bytes > 512:
|
||||
raise ValueError("desired_key_bytes must be 1-512")
|
||||
|
||||
if rounds < 1:
|
||||
raise ValueError("rounds must be 1 or more")
|
||||
|
||||
if rounds < 50 and not ignore_few_rounds:
|
||||
# They probably think bcrypt.kdf()'s rounds parameter is logarithmic,
|
||||
# expecting this value to be slow enough (it probably would be if this
|
||||
# were bcrypt). Emit a warning.
|
||||
warnings.warn(
|
||||
(
|
||||
"Warning: bcrypt.kdf() called with only {0} round(s). "
|
||||
"This few is not secure: the parameter is linear, like PBKDF2."
|
||||
).format(rounds),
|
||||
UserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
key = _bcrypt.ffi.new("uint8_t[]", desired_key_bytes)
|
||||
res = _bcrypt.lib.bcrypt_pbkdf(
|
||||
password, len(password), salt, len(salt), key, len(key), rounds
|
||||
)
|
||||
_bcrypt_assert(res == 0)
|
||||
|
||||
return _bcrypt.ffi.buffer(key, desired_key_bytes)[:]
|
||||
|
||||
|
||||
def _bcrypt_assert(ok: bool) -> None:
|
||||
if not ok:
|
||||
raise SystemError("bcrypt assertion failed")
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
def gensalt(rounds: int = 12, prefix: bytes = b"2b") -> bytes: ...
|
||||
def hashpw(password: bytes, salt: bytes) -> bytes: ...
|
||||
def checkpw(password: bytes, hashed_password: bytes) -> bool: ...
|
||||
def kdf(
|
||||
password: bytes,
|
||||
salt: bytes,
|
||||
desired_key_bytes: int,
|
||||
rounds: int,
|
||||
ignore_few_rounds: bool = False,
|
||||
) -> bytes: ...
|
||||
4
src/bcrypt/_bcrypt.pyi
Normal file
4
src/bcrypt/_bcrypt.pyi
Normal file
@ -0,0 +1,4 @@
|
||||
import typing
|
||||
|
||||
ffi: typing.Any
|
||||
lib: typing.Any
|
||||
46
src/build_bcrypt.py
Normal file
46
src/build_bcrypt.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os.path
|
||||
|
||||
from cffi import FFI
|
||||
|
||||
|
||||
BLOWFISH_DIR = os.path.join(os.path.dirname(__file__), "_csrc")
|
||||
|
||||
|
||||
ffi = FFI()
|
||||
|
||||
ffi.cdef(
|
||||
"""
|
||||
int bcrypt_hashpass(const char *, const char *, char *, size_t);
|
||||
int encode_base64(char *, const uint8_t *, size_t);
|
||||
int bcrypt_pbkdf(const char *, size_t, const uint8_t *, size_t,
|
||||
uint8_t *, size_t, unsigned int);
|
||||
int timingsafe_bcmp(const void *, const void *, size_t);
|
||||
"""
|
||||
)
|
||||
|
||||
ffi.set_source(
|
||||
"_bcrypt",
|
||||
"""
|
||||
#include "pycabcrypt.h"
|
||||
""",
|
||||
sources=[
|
||||
os.path.join(BLOWFISH_DIR, "blf.c"),
|
||||
os.path.join(BLOWFISH_DIR, "bcrypt.c"),
|
||||
os.path.join(BLOWFISH_DIR, "bcrypt_pbkdf.c"),
|
||||
os.path.join(BLOWFISH_DIR, "sha2.c"),
|
||||
os.path.join(BLOWFISH_DIR, "timingsafe_bcmp.c"),
|
||||
],
|
||||
include_dirs=[BLOWFISH_DIR],
|
||||
)
|
||||
@ -1,10 +1,10 @@
|
||||
import uuid
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
import bcrypt
|
||||
|
||||
|
||||
_test_vectors = [
|
||||
(
|
||||
b"Kk4DQuMMfZL9o",
|
||||
@ -121,25 +121,29 @@ _test_vectors = [
|
||||
b"$2a$05$XXXXXXXXXXXXXXXXXXXXXO",
|
||||
b"$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a",
|
||||
),
|
||||
(
|
||||
b"0123456789abcdefghijklmnopqrstuvwxyz"
|
||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b"chars after 72 are ignored",
|
||||
b"$2a$05$abcdefghijklmnopqrstuu",
|
||||
b"$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui",
|
||||
),
|
||||
(
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
|
||||
b"chars after 72 are ignored as usual",
|
||||
b"$2a$05$/OK.fbVrR/bpIqNJ5ianF.",
|
||||
b"$2a$05$/OK.fbVrR/bpIqNJ5ianF.swQOIzjOiJ9GHEPuhEkvqrUyvWhEMx6",
|
||||
),
|
||||
(
|
||||
b"\xa3",
|
||||
b"$2a$05$/OK.fbVrR/bpIqNJ5ianF.",
|
||||
b"$2a$05$/OK.fbVrR/bpIqNJ5ianF.Sa7shbm4.OzKpvFnX1pQLmQW96oUlCq",
|
||||
),
|
||||
(
|
||||
b"}>\xb3\xfe\xf1\x8b\xa0\xe6(\xa2Lzq\xc3P\x7f\xcc\xc8b{\xf9\x14\xf6"
|
||||
b"\xf6`\x81G5\xec\x1d\x87\x10\xbf\xa7\xe1}I7 \x96\xdfc\xf2\xbf\xb3Vh"
|
||||
b"\xdfM\x88q\xf7\xff\x1b\x82~z\x13\xdd\xe9\x84\x00\xdd4",
|
||||
b"$2b$10$keO.ZZs22YtygVF6BLfhGO",
|
||||
b"$2b$10$keO.ZZs22YtygVF6BLfhGOI/JjshJYPp8DZsUtym6mJV2Eha2Hdd.",
|
||||
),
|
||||
(
|
||||
b"g7\r\x01\xf3\xd4\xd0\xa9JB^\x18\x007P\xb2N\xc7\x1c\xee\x87&\x83C"
|
||||
b"\x8b\xe8\x18\xc5>\x86\x14/\xd6\xcc\x1cJ\xde\xd7ix\xeb\xdeO\xef"
|
||||
b"\xe1i\xac\xcb\x03\x96v1' \xd6@.m\xa5!\xa0\xef\xc0(",
|
||||
b"$2a$04$tecY.9ylRInW/rAAzXCXPO",
|
||||
b"$2a$04$tecY.9ylRInW/rAAzXCXPOOlyYeCNzmNTzPDNSIFztFMKbvs/s5XG",
|
||||
),
|
||||
]
|
||||
|
||||
_2y_test_vectors = [
|
||||
@ -156,41 +160,40 @@ _2y_test_vectors = [
|
||||
]
|
||||
|
||||
|
||||
def test_gensalt_basic():
|
||||
salt = bcrypt.gensalt()
|
||||
assert salt.startswith(b"$2b$12$")
|
||||
def test_gensalt_basic(monkeypatch):
|
||||
monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
|
||||
assert bcrypt.gensalt() == b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("rounds", "expected_prefix"),
|
||||
("rounds", "expected"),
|
||||
[
|
||||
(4, b"$2b$04$"),
|
||||
(5, b"$2b$05$"),
|
||||
(6, b"$2b$06$"),
|
||||
(7, b"$2b$07$"),
|
||||
(8, b"$2b$08$"),
|
||||
(9, b"$2b$09$"),
|
||||
(10, b"$2b$10$"),
|
||||
(11, b"$2b$11$"),
|
||||
(12, b"$2b$12$"),
|
||||
(13, b"$2b$13$"),
|
||||
(14, b"$2b$14$"),
|
||||
(15, b"$2b$15$"),
|
||||
(16, b"$2b$16$"),
|
||||
(17, b"$2b$17$"),
|
||||
(18, b"$2b$18$"),
|
||||
(19, b"$2b$19$"),
|
||||
(20, b"$2b$20$"),
|
||||
(21, b"$2b$21$"),
|
||||
(22, b"$2b$22$"),
|
||||
(23, b"$2b$23$"),
|
||||
(24, b"$2b$24$"),
|
||||
(4, b"$2b$04$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(5, b"$2b$05$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(6, b"$2b$06$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(7, b"$2b$07$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(8, b"$2b$08$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(9, b"$2b$09$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(10, b"$2b$10$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(11, b"$2b$11$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(12, b"$2b$12$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(13, b"$2b$13$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(14, b"$2b$14$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(15, b"$2b$15$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(16, b"$2b$16$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(17, b"$2b$17$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(18, b"$2b$18$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(19, b"$2b$19$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(20, b"$2b$20$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(21, b"$2b$21$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(22, b"$2b$22$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(23, b"$2b$23$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
(24, b"$2b$24$KB.uKB.uKB.uKB.uKB.uK."),
|
||||
],
|
||||
)
|
||||
def test_gensalt_rounds_valid(rounds, expected_prefix):
|
||||
salt = bcrypt.gensalt(rounds)
|
||||
|
||||
assert salt.startswith(expected_prefix)
|
||||
def test_gensalt_rounds_valid(rounds, expected, monkeypatch):
|
||||
monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
|
||||
assert bcrypt.gensalt(rounds) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rounds", list(range(1, 4)))
|
||||
@ -201,12 +204,12 @@ def test_gensalt_rounds_invalid(rounds):
|
||||
|
||||
def test_gensalt_bad_prefix():
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.gensalt(prefix=b"bad")
|
||||
bcrypt.gensalt(prefix="bad")
|
||||
|
||||
|
||||
def test_gensalt_2a_prefix():
|
||||
salt = bcrypt.gensalt(prefix=b"2a")
|
||||
assert salt.startswith(b"$2a$12$")
|
||||
def test_gensalt_2a_prefix(monkeypatch):
|
||||
monkeypatch.setattr(os, "urandom", lambda n: b"0000000000000000")
|
||||
assert bcrypt.gensalt(prefix=b"2a") == b"$2a$12$KB.uKB.uKB.uKB.uKB.uK."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("password", "salt", "hashed"), _test_vectors)
|
||||
@ -234,25 +237,6 @@ def test_checkpw_2y_prefix(password, hashed, expected):
|
||||
assert bcrypt.checkpw(password, hashed) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("pw_length", "should_raise"),
|
||||
[
|
||||
(71, False),
|
||||
(72, False),
|
||||
(73, True),
|
||||
],
|
||||
)
|
||||
def test_hashpw_raises_correctly_for_long_passwords(pw_length, should_raise):
|
||||
password = b"\xaa" * pw_length
|
||||
salt = b"$2b$04$xnFVhJsTzsFBTeP3PpgbMe"
|
||||
|
||||
if should_raise:
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.hashpw(password, salt)
|
||||
else:
|
||||
bcrypt.hashpw(password, salt)
|
||||
|
||||
|
||||
def test_hashpw_invalid():
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.hashpw(b"password", b"$2z$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
@ -274,40 +258,34 @@ def test_checkpw_bad_salt():
|
||||
b"badpass",
|
||||
b"$2b$04$?Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe",
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.checkpw(
|
||||
b"password",
|
||||
b"$2b$3$mdEQPMOtfPX.WGZNXgF66OhmBlOGKEd66SQ7DyJPGucYYmvTJYviy",
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.checkpw(b"password", b"$2b$12$incorrect")
|
||||
|
||||
|
||||
def test_checkpw_str_password():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.checkpw("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO") # type: ignore[arg-type]
|
||||
bcrypt.checkpw("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
|
||||
|
||||
def test_checkpw_str_salt():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.checkpw(b"password", "$2b$04$cVWp4XaNU8a4v1uMRum2SO") # type: ignore[arg-type]
|
||||
bcrypt.checkpw(b"password", "$2b$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
|
||||
|
||||
def test_hashpw_str_password():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.hashpw("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO") # type: ignore[arg-type]
|
||||
bcrypt.hashpw("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
|
||||
|
||||
def test_hashpw_str_salt():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.hashpw(b"password", "$2b$04$cVWp4XaNU8a4v1uMRum2SO") # type: ignore[arg-type]
|
||||
bcrypt.hashpw(b"password", "$2b$04$cVWp4XaNU8a4v1uMRum2SO")
|
||||
|
||||
|
||||
def test_checkpw_nul_byte():
|
||||
bcrypt.checkpw(
|
||||
b"abc\0def",
|
||||
b"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe",
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.checkpw(
|
||||
b"abc\0def",
|
||||
b"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe",
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.checkpw(
|
||||
@ -318,13 +296,8 @@ def test_checkpw_nul_byte():
|
||||
|
||||
def test_hashpw_nul_byte():
|
||||
salt = bcrypt.gensalt(4)
|
||||
hashed = bcrypt.hashpw(b"abc\0def", salt)
|
||||
assert bcrypt.checkpw(b"abc\0def", hashed)
|
||||
# assert that we are sensitive to changes in the password after the first
|
||||
# null byte:
|
||||
assert not bcrypt.checkpw(b"abc\0deg", hashed)
|
||||
assert not bcrypt.checkpw(b"abc\0def\0", hashed)
|
||||
assert not bcrypt.checkpw(b"abc\0def\0\0", hashed)
|
||||
with pytest.raises(ValueError):
|
||||
bcrypt.hashpw(b"abc\0def", salt)
|
||||
|
||||
|
||||
def test_checkpw_extra_data():
|
||||
@ -398,13 +371,13 @@ def test_checkpw_extra_data():
|
||||
[
|
||||
# longer password
|
||||
8,
|
||||
b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do"
|
||||
b" eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
|
||||
b"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
|
||||
b"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
|
||||
b"enim ad minim veniam, quis nostrud exercitation ullamco laboris "
|
||||
b"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor "
|
||||
b"in reprehenderit in voluptate velit esse cillum dolore eu fugiat"
|
||||
b" nulla pariatur. Excepteur sint occaecat cupidatat non proident,"
|
||||
b" sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
b"in reprehenderit in voluptate velit esse cillum dolore eu fugiat "
|
||||
b"nulla pariatur. Excepteur sint occaecat cupidatat non proident, "
|
||||
b"sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||
b"salis\x00",
|
||||
b"\x10\x97\x8b\x07\x25\x3d\xf5\x7f\x71\xa1\x62\xeb\x0e\x8a\xd3\x0a",
|
||||
],
|
||||
@ -440,7 +413,8 @@ def test_checkpw_extra_data():
|
||||
[
|
||||
# UTF-8 Greek characters "odysseus" / "telemachos"
|
||||
8,
|
||||
b"\xe1\xbd\x88\xce\xb4\xcf\x85\xcf\x83\xcf\x83\xce\xb5\xcf\x8d\xcf\x82",
|
||||
b"\xe1\xbd\x88\xce\xb4\xcf\x85\xcf\x83\xcf\x83\xce\xb5\xcf\x8d\xcf"
|
||||
b"\x82",
|
||||
b"\xce\xa4\xce\xb7\xce\xbb\xce\xad\xce\xbc\xce\xb1\xcf\x87\xce\xbf"
|
||||
b"\xcf\x82",
|
||||
b"\x43\x66\x6c\x9b\x09\xef\x33\xed\x8c\x27\xe8\xe8\xf3\xe2\xd8\xe6",
|
||||
@ -456,12 +430,12 @@ def test_kdf(rounds, password, salt, expected):
|
||||
|
||||
def test_kdf_str_password():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.kdf("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 10, 10) # type: ignore[arg-type]
|
||||
bcrypt.kdf("password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 10, 10)
|
||||
|
||||
|
||||
def test_kdf_str_salt():
|
||||
with pytest.raises(TypeError):
|
||||
bcrypt.kdf(b"password", "salt", 10, 10) # type: ignore[arg-type]
|
||||
bcrypt.kdf(b"password", "salt", 10, 10)
|
||||
|
||||
|
||||
def test_kdf_no_warn_rounds():
|
||||
@ -481,7 +455,7 @@ def test_kdf_warn_rounds():
|
||||
(b"", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 10, 10, ValueError),
|
||||
(b"password", b"", 10, 10, ValueError),
|
||||
(b"password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 0, 10, ValueError),
|
||||
(b"password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", -3, 10, OverflowError),
|
||||
(b"password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", -3, 10, ValueError),
|
||||
(b"password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 513, 10, ValueError),
|
||||
(b"password", b"$2b$04$cVWp4XaNU8a4v1uMRum2SO", 20, 0, ValueError),
|
||||
],
|
||||
@ -491,22 +465,15 @@ def test_invalid_params(password, salt, desired_key_bytes, rounds, error):
|
||||
bcrypt.kdf(password, salt, desired_key_bytes, rounds)
|
||||
|
||||
|
||||
def test_multithreading():
|
||||
def create_user(pw):
|
||||
salt = bcrypt.gensalt(4)
|
||||
hash_ = bcrypt.hashpw(pw, salt)
|
||||
key = bcrypt.kdf(pw, salt, 32, 50)
|
||||
assert bcrypt.checkpw(pw, hash_)
|
||||
return (salt, hash_, key)
|
||||
def test_bcrypt_assert():
|
||||
with pytest.raises(SystemError):
|
||||
bcrypt._bcrypt_assert(False)
|
||||
|
||||
user_creator = ThreadPoolExecutor(max_workers=4)
|
||||
pws = [uuid.uuid4().bytes for _ in range(50)]
|
||||
|
||||
futures = [user_creator.submit(create_user, pw) for pw in pws]
|
||||
|
||||
users = [future.result() for future in futures]
|
||||
|
||||
for pw, (salt, hash_, key) in zip(pws, users):
|
||||
assert bcrypt.hashpw(pw, salt) == hash_
|
||||
assert bcrypt.checkpw(pw, hash_)
|
||||
assert bcrypt.kdf(pw, salt, 32, 50) == key
|
||||
def test_2a_wraparound_bug():
|
||||
assert (
|
||||
bcrypt.hashpw(
|
||||
(b"0123456789" * 26)[:255], b"$2a$04$R1lJ2gkNaoPGdafE.H.16."
|
||||
)
|
||||
== b"$2a$04$R1lJ2gkNaoPGdafE.H.16.1MKHPvmKwryeulRe225LKProWYwt9Oi"
|
||||
)
|
||||
|
||||
43
tox.ini
Normal file
43
tox.ini
Normal file
@ -0,0 +1,43 @@
|
||||
[tox]
|
||||
isolated_build = True
|
||||
|
||||
[testenv]
|
||||
extras =
|
||||
tests
|
||||
deps =
|
||||
coverage
|
||||
commands =
|
||||
coverage run -m pytest --strict-markers {posargs}
|
||||
coverage combine
|
||||
coverage report -m --fail-under 100
|
||||
|
||||
[testenv:pep8]
|
||||
deps =
|
||||
black
|
||||
flake8
|
||||
flake8-import-order
|
||||
pep8-naming
|
||||
commands =
|
||||
flake8 .
|
||||
black --check .
|
||||
|
||||
[testenv:mypy]
|
||||
deps =
|
||||
mypy
|
||||
commands =
|
||||
mypy src/bcrypt
|
||||
|
||||
[testenv:packaging]
|
||||
deps =
|
||||
check-manifest
|
||||
readme_renderer
|
||||
commands =
|
||||
check-manifest
|
||||
python setup.py check --metadata --restructuredtext --strict
|
||||
|
||||
|
||||
[flake8]
|
||||
ignore = E203,E211,E501,W503,W504
|
||||
exclude = .tox,*.egg
|
||||
select = E,W,F,N,I
|
||||
application-import-names = bcrypt,tests
|
||||
Loading…
Reference in New Issue
Block a user