pax_global_header00006660000000000000000000000064137236510570014523gustar00rootroot0000000000000052 comment=081af975885dc8f65ddb7cec36914c5539d4a0d5 siphashc-2.1/000077500000000000000000000000001372365105700131675ustar00rootroot00000000000000siphashc-2.1/.github/000077500000000000000000000000001372365105700145275ustar00rootroot00000000000000siphashc-2.1/.github/.kodiak.toml000066400000000000000000000003121372365105700167400ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ # Configuration for https://kodiakhq.com/ version = 1 [merge] method = "rebase" [update] ignored_usernames = ["dependabot", "weblate"] siphashc-2.1/.github/FUNDING.yml000066400000000000000000000002101372365105700163350ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ github: [nijel] custom: https://weblate.org/donate/ liberapay: Weblate siphashc-2.1/.github/dependabot.yml000066400000000000000000000005451372365105700173630ustar00rootroot00000000000000# This file is generated in https://github.com/WeblateOrg/meta/ version: 2 updates: - package-ecosystem: github-actions directory: / schedule: interval: daily labels: - dependencies - automerge - package-ecosystem: pip directory: / schedule: interval: daily labels: - dependencies - automerge siphashc-2.1/.github/labels.yml000066400000000000000000000034561372365105700165240ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ # Default GitHub labels - color: d73a4a name: bug description: Something isn't working - color: cfd3d7 name: duplicate description: This issue or pull request already exists - color: a2eeef name: enhancement description: New feature or request - color: 7057ff name: good first issue description: Good for newcomers - color: 008672 name: help wanted description: Extra attention is needed - color: e4e669 name: invalid description: This doesn't seem right - color: d876e3 name: question description: Support question - color: ffffff name: wontfix description: This will not be worked on # Bountysource - color: 129e5e name: bounty description: There is a bounty on the issue # Dependabot - color: 0025ff name: dependencies description: Pull requests that update a dependency file # Kodiaq - color: 000000 name: automerge description: Automatically merge pull request once tests pass # Hacktoberfest - color: 129e5e name: hacktoberfest description: This is good for Hacktoberfest # Weblate specific - color: 87a2f2 name: backlog description: This is currently not on the roadmap - color: 0075ca name: documentation description: Improvements or additions to documentation - color: d4c5f9 name: hosted description: Issues affecting Hosted Weblate service - color: e3f49c name: naming description: Discussions about naming certain features - color: fef2c0 name: translate-toolkit description: Issues which need to be fixed in the translate-toolkit - color: 02d7e1 name: undecided description: These features might not be implemented at all - color: e3f49c name: ux description: User experience issues - color: b38ddd name: needinfo description: This needs additional information from the reporter siphashc-2.1/.github/matchers/000077500000000000000000000000001372365105700163355ustar00rootroot00000000000000siphashc-2.1/.github/matchers/flake8.json000066400000000000000000000004441372365105700204040ustar00rootroot00000000000000{ "problemMatcher": [ { "owner": "flake8", "pattern": [ { "code": 4, "column": 3, "file": 1, "line": 2, "message": 5, "regexp": "^([^:]*):(\\d+):(\\d+): (\\w+\\d\\d\\d) (.*)$" } ] } ] } siphashc-2.1/.github/stale.yml000066400000000000000000000027041372365105700163650ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ # # Configuration for probot-stale - https://github.com/probot/stale # Number of days of inactivity before an Issue or Pull Request becomes stale daysUntilStale: 30 # Number of days of inactivity before a stale Issue or Pull Request is closed daysUntilClose: 14 # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable exemptLabels: - pinned - security # Label to use when marking as stale staleLabel: wontfix # Comment to post when marking as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when removing the stale label. Set to `false` to disable unmarkComment: false # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable closeComment: false # Limit to only `issues` or `pulls` # only: issues # # Optionally, specify configuration settings that are specific to just 'issues' or 'pulls': pulls: markComment: > This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. issues: daysUntilStale: 10 daysUntilClose: 4 exemptLabels: - bug - enhancement - documentation - security siphashc-2.1/.github/workflows/000077500000000000000000000000001372365105700165645ustar00rootroot00000000000000siphashc-2.1/.github/workflows/closing.yml000066400000000000000000000035171372365105700207530ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Issue closed on: issues: types: [closed] jobs: issueClosed: runs-on: ubuntu-latest steps: - name: Add closed question comment uses: peter-evans/create-or-update-comment@v1 if: (contains(github.event.issue.labels.*.name, 'question') && ! contains(github.event.issue.labels.*.name, 'wontfix')) || join(github.event.issue.labels.*.name) == '' with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | The issue you have reported seems to be resolved now. * In case you see a similar problem, please open a separate issue. * If you are happy with the outcome, consider supporting Weblate by [donating](https://weblate.org/donate/). - name: Add closed issue comment uses: peter-evans/create-or-update-comment@v1 if: "! contains(github.event.issue.labels.*.name, 'invalid') && ! contains(github.event.issue.labels.*.name, 'question') && ! contains(github.event.issue.labels.*.name, 'wontfix') && ! contains(github.event.issue.labels.*.name, 'duplicate') && ! contains(github.event.issue.labels.*.name, 'undecided') && ! contains(github.event.issue.labels.*.name, 'needinfo') && join(github.event.issue.labels.*.name) != ''" with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | Thank you for your report, the issue you have reported has just been fixed. * In case you see a problem with the fix, please comment on this issue. * In case you see a similar problem, please open a separate issue. * If you are happy with the outcome, consider supporting Weblate by [donating](https://weblate.org/donate/). siphashc-2.1/.github/workflows/codeql-analysis.yml000066400000000000000000000030761372365105700224050ustar00rootroot00000000000000name: "CodeQL" on: push: branches: [master] pull_request: # The branches below must be a subset of the branches above branches: [master] schedule: - cron: "0 19 * * 0" jobs: analyze: name: Analyze runs-on: ubuntu-latest strategy: fail-fast: false matrix: # Override automatic language detection by changing the below list # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] language: ["cpp", "python"] # Learn more... # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection steps: - name: Checkout repository uses: actions/checkout@v2 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. fetch-depth: 2 # If this run was triggered by a pull request event, then checkout # the head of the pull request instead of the merge commit. - run: git checkout HEAD^2 if: ${{ github.event_name == 'pull_request' }} # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} - name: Set up Python uses: actions/setup-python@v2.1.2 with: python-version: 3.8 - run: python setup.py build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 siphashc-2.1/.github/workflows/flake8.yml000066400000000000000000000016561372365105700204710ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Flake8 on: push: branches-ignore: - "dependabot/**" pull_request: jobs: flake8: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/cache@v2.1.1 with: path: | ~/.cache/pip ~/.cache/pre-commit key: ${{ runner.os }}-pip-lint-${{ hashFiles('**/requirements*.txt') }}-${{ hashFiles('.pre-commit-config.yaml') }} - name: Setup Python uses: actions/setup-python@v2.1.2 with: python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip wheel pip install -r requirements-lint.txt - name: Run flake8 run: | echo "::add-matcher::.github/matchers/flake8.json" pre-commit run flake8 --all echo "::remove-matcher owner=flake8::" siphashc-2.1/.github/workflows/label-sync.yml000066400000000000000000000010261372365105700213370ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Sync labels on: push: branches: - master paths: - .github/labels.yml - .github/workflows/label-sync.yml jobs: build: name: Sync labels runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.1 - uses: micnncim/action-label-syncer@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} with: manifest: .github/labels.yml siphashc-2.1/.github/workflows/labels.yml000066400000000000000000000044671372365105700205640ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Issue labeled on: issues: types: [labeled] jobs: issueLabeled: runs-on: ubuntu-latest steps: - name: Add backlog comment uses: peter-evans/create-or-update-comment@v1 if: github.event.label.name == 'backlog' with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | This issue has been added to the backlog. It is not scheduled on our roadmap, but it eventually might be implemented. In case you desperately need this feature, please consider helping or [funding the development](https://weblate.org/support/). - name: Add undecided comment uses: peter-evans/create-or-update-comment@v1 if: github.event.label.name == 'undecided' with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | This issue has been put aside. Currently, it is unclear whether it will ever be implemented as it seems to cover too narrow of a use case or doesn't seem to fit into Weblate. Please try to clarify the use case or consider proposing something more generic to make it useful to more users. - name: Add question comment uses: peter-evans/create-or-update-comment@v1 if: github.event.label.name == 'question' with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | This issue looks like a support question. We try to answer these reasonably fast, but in case you are looking for faster resolution, please consider [purchasing support subscription](https://weblate.org/support/) and make Weblate stronger. - name: Add translate-toolkit comment uses: peter-evans/create-or-update-comment@v1 if: github.event.label.name == 'translate-toolkit' with: token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | The issue you've reported needs to be addressed in the [translate-toolkit](https://github.com/translate/translate/). Please file the issue there and do not forget to include links to any relevant specifications about the formats (if applicable). siphashc-2.1/.github/workflows/pre-commit.yml000066400000000000000000000015011372365105700213600ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Pre-commit check on: push: branches-ignore: - "dependabot/**" pull_request: jobs: pre-commit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.1 - uses: actions/cache@v2.1.1 with: path: | ~/.cache/pip ~/.cache/pre-commit key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/requirements*.txt') }}-${{ hashFiles('.pre-commit-config.yaml') }} - name: Setup Python uses: actions/setup-python@v2.1.2 with: python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip wheel pip install -r requirements-lint.txt - name: pre-commit run: pre-commit run --all siphashc-2.1/.github/workflows/pull_requests.yaml000066400000000000000000000006321372365105700223600ustar00rootroot00000000000000# This file is maintained in https://github.com/WeblateOrg/meta/ name: Pull request automation on: pull_request: types: opened jobs: weblate_automerge: runs-on: ubuntu-latest name: Weblate automerge if: github.actor == 'weblate' steps: - uses: actions-ecosystem/action-add-labels@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} labels: automerge siphashc-2.1/.github/workflows/pythonpackage.yml000066400000000000000000000012601372365105700221430ustar00rootroot00000000000000name: Python package on: push: branches-ignore: - "dependabot/**" pull_request: jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: [3.5, 3.6, 3.7, 3.8] steps: - uses: actions/checkout@v2.3.1 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2.1.2 with: python-version: ${{ matrix.python-version }} - name: Compile run: | CFLAGS="-Wall -Wextra -Wno-unused-parameter" python setup.py build - name: Test run: | python -W default setup.py test - name: Benchmark run: | python benchmark.py siphashc-2.1/.github/workflows/setup.yml000066400000000000000000000045721372365105700204570ustar00rootroot00000000000000name: Distribution on: [push, pull_request] jobs: manylinux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/cache@v2.1.1 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-setup-${{ hashFiles('**/requirements*.txt') }} - name: Set up Python uses: actions/setup-python@v2.1.2 with: python-version: 3.8 - name: Install dependencies run: | python -m pip install --upgrade pip wheel pip install twine - uses: RalfG/python-wheels-manylinux-build@v0.3.1 with: python-versions: "cp35-cp35m cp36-cp36m cp37-cp37m cp38-cp38" - name: twine run: twine check dist/* - name: Publish package if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.pypi_password }} run: twine upload --skip-existing dist/*-manylinux*.whl native: runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] python-version: [3.5, 3.6, 3.7, 3.8] steps: - uses: actions/checkout@v2 - uses: actions/cache@v2.1.1 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-setup-${{ hashFiles('**/requirements*.txt') }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2.1.2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip wheel pip install twine - name: build run: python ./setup.py sdist bdist_wheel - name: twine run: twine check dist/* - name: Publish wheel if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && matrix.os != 'ubuntu-latest' env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.pypi_password }} run: twine upload --skip-existing dist/*.whl - name: Publish source if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.pypi_password }} run: twine upload --skip-existing dist/*.tar.gz siphashc-2.1/.gitignore000066400000000000000000000001041372365105700151520ustar00rootroot00000000000000__pycache__ *egg-info /build /dist /MANIFEST /siphashc*.so *.py[co] siphashc-2.1/.pre-commit-config.yaml000066400000000000000000000027141372365105700174540ustar00rootroot00000000000000# See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/mirrors-isort rev: v5.4.2 hooks: - id: isort - repo: https://github.com/ambv/black rev: 20.8b1 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.3 hooks: - id: flake8 additional_dependencies: - flake8-breakpoint - flake8-black - flake8-bugbear - flake8-builtins - flake8-comprehensions - flake8-docstrings - flake8-eradicate - flake8-executable - flake8-isort - flake8-logging-format - flake8-mutable - flake8-no-u-prefixed-strings - flake8-print - flake8-return - flake8-self - flake8-string-format - pep8-naming - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.2.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: requirements-txt-fixer - id: check-merge-conflict - id: mixed-line-ending args: [--fix=lf] - repo: https://github.com/adrienverge/yamllint rev: v1.24.2 hooks: - id: yamllint - repo: meta hooks: - id: check-hooks-apply - id: check-useless-excludes - repo: https://github.com/prettier/prettier rev: 2.1.1 hooks: - id: prettier siphashc-2.1/.yamllint.yml000066400000000000000000000001401372365105700156140ustar00rootroot00000000000000extends: default rules: line-length: max: 500 level: error document-start: disable siphashc-2.1/CHANGES.rst000066400000000000000000000007251372365105700147750ustar00rootroot00000000000000Changes ======= 2.1 --- * Fixed publishing wheels in pypi.org. 2.0 --- * Dropped support for Python 2. 1.3 --- * Changed license to ISC. * Fixed depreciation warning on Python 3.8. 1.2 --- * Included tests in the pypi package. 1.1 --- * Fixed README enconding. * Included documentation in the pypi package. 1.0 --- * Stable release. * Documentation improvements. 0.8 --- * First release under new maintainer. * Merged two siphashc module implementations. siphashc-2.1/LICENSE.md000066400000000000000000000015131372365105700145730ustar00rootroot00000000000000Copyright (c) 2013 Eli Janssen Copyright (c) 2014 Carlo Pires (python3 support) Copyright (c) 2017 - 2019 Michal Čihař (additional cleanups) Permission to use, copy, modify, and/or 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. siphashc-2.1/MANIFEST.in000066400000000000000000000001471372365105700147270ustar00rootroot00000000000000include siphash/*.h include test_siphashc.py include LICENSE.md include README.rst include CHANGES.rst siphashc-2.1/README.rst000066400000000000000000000023211372365105700146540ustar00rootroot00000000000000.. image:: https://s.weblate.org/cdn/Logo-Darktext-borders.png :alt: Weblate :target: https://weblate.org/ :height: 80px **Weblate is a copylefted libre software web-based continuous localization system, used by over 1150 libre projects and companies in more than 115 countries.** siphashc is a Python module (in c) for siphash-2-4 .. image:: https://img.shields.io/pypi/v/siphashc.svg :target: https://pypi.python.org/pypi/siphashc :alt: PyPI package Installation ~~~~~~~~~~~~ Install using pip: .. code-block:: sh pip install siphashc Sources are available at . Introduction ~~~~~~~~~~~~ siphashc is a python c-module for `siphash `__, based on `floodberry's version `__. It was merged from two versions of the module: - https://github.com/cactus/siphashc - https://github.com/carlopires/siphashc3 Usage ~~~~~ .. code:: python >>> from siphashc import siphash >>> siphash('sixteencharstrng', 'i need a hash of this') 10796923698683394048 License ~~~~~~~ Released under the `ISC license `__. See ``LICENSE.md`` file for details. siphashc-2.1/benchmark.py000077500000000000000000000006061372365105700155000ustar00rootroot00000000000000#!/usr/bin/env python """ Simple timing benchmark. Used for testing possible regressions when changing code. """ import timeit print("Benchmark (short):") print(timeit.timeit("siphash('0123456789ABCDEF', 'a')", "from siphashc import siphash")) print("Benchmark (long):") print( timeit.timeit( "siphash('0123456789ABCDEF', 'a' * 1000)", "from siphashc import siphash" ) ) siphashc-2.1/requirements-lint.txt000066400000000000000000000000301372365105700174100ustar00rootroot00000000000000pre-commit==2.7.1 twine siphashc-2.1/setup.cfg000066400000000000000000000001061372365105700150050ustar00rootroot00000000000000[flake8] per-file-ignores = benchmark.py:T001 max-line-length = 88 siphashc-2.1/setup.py000077500000000000000000000031651372365105700147110ustar00rootroot00000000000000#!/usr/bin/env python """Setup for the siphashc module.""" import io import os.path from setuptools import Extension, setup with io.open( os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf-8" ) as readme: LONG_DESCRIPTION = readme.read() setup( name="siphashc", version="2.1", author="Michal Čihař", author_email="michal@cihar.com", description="Python module (in c) for siphash-2-4", long_description=LONG_DESCRIPTION, long_description_content_type="text/x-rst", keywords="siphash siphash-2-4", url="https://github.com/WeblateOrg/siphashc", project_urls={ "Issue Tracker": "https://github.com/WeblateOrg/siphashc/issues", "Source Code": "https://github.com/WeblateOrg/siphashc", "Twitter": "https://twitter.com/WeblateOrg", }, license="ISC", python_requires=">=3.5", ext_modules=[ Extension( name="siphashc", sources=["siphashc.c", "siphash/siphash.c"], language="c" ) ], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries :: Python Modules", "License :: OSI Approved :: ISC License (ISCL)", ], test_suite="test_siphashc", zip_safe=True, ) siphashc-2.1/siphash/000077500000000000000000000000001372365105700146265ustar00rootroot00000000000000siphashc-2.1/siphash/README.md000066400000000000000000000000641372365105700161050ustar00rootroot00000000000000siphash from https://github.com/floodyberry/siphash siphashc-2.1/siphash/siphash.c000066400000000000000000000035521372365105700164360ustar00rootroot00000000000000#include "siphash.h" #include "siphash_impl.h" INLINE static uint64_t U8TO64_LE(const unsigned char *p) { return *(const uint64_t *)p; } uint64_t siphash(const unsigned char key[16], const unsigned char *m, size_t len) { uint64_t v0, v1, v2, v3; uint64_t mi, k0, k1; uint64_t last7; size_t i, blocks; k0 = U8TO64_LE(key + 0); k1 = U8TO64_LE(key + 8); v0 = k0 ^ 0x736f6d6570736575ull; v1 = k1 ^ 0x646f72616e646f6dull; v2 = k0 ^ 0x6c7967656e657261ull; v3 = k1 ^ 0x7465646279746573ull; last7 = (uint64_t)(len & 0xff) << 56; #define sipcompress() \ v0 += v1; v2 += v3; \ v1 = ROTL64(v1,13); v3 = ROTL64(v3,16); \ v1 ^= v0; v3 ^= v2; \ v0 = ROTL64(v0,32); \ v2 += v1; v0 += v3; \ v1 = ROTL64(v1,17); v3 = ROTL64(v3,21); \ v1 ^= v2; v3 ^= v0; \ v2 = ROTL64(v2,32); for (i = 0, blocks = (len & ~7); i < blocks; i += 8) { mi = U8TO64_LE(m + i); v3 ^= mi; sipcompress() sipcompress() v0 ^= mi; } switch (len - blocks) { case 7: last7 |= (uint64_t)m[i + 6] << 48; FALLTHROUGH; case 6: last7 |= (uint64_t)m[i + 5] << 40; FALLTHROUGH; case 5: last7 |= (uint64_t)m[i + 4] << 32; FALLTHROUGH; case 4: last7 |= (uint64_t)m[i + 3] << 24; FALLTHROUGH; case 3: last7 |= (uint64_t)m[i + 2] << 16; FALLTHROUGH; case 2: last7 |= (uint64_t)m[i + 1] << 8; FALLTHROUGH; case 1: last7 |= (uint64_t)m[i + 0] ; FALLTHROUGH; case 0: default:; }; v3 ^= last7; sipcompress() sipcompress() v0 ^= last7; v2 ^= 0xff; sipcompress() sipcompress() sipcompress() sipcompress() return v0 ^ v1 ^ v2 ^ v3; } siphashc-2.1/siphash/siphash.h000066400000000000000000000007031372365105700164360ustar00rootroot00000000000000#ifndef SIPHASH_H #define SIPHASH_H #if defined(_MSC_VER) #include typedef unsigned __int64 uint64_t; #else #include #include #endif #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ extern "C" { #endif uint64_t siphash(const unsigned char key[16], const unsigned char *m, size_t len); #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ } #endif #endif // SIPHASH_H siphashc-2.1/siphash/siphash_impl.h000066400000000000000000000025321372365105700174610ustar00rootroot00000000000000#ifndef SIPHASH_IMPL_H #define SIPHASH_IMPL_H #include "siphash.h" #if defined(_MSC_VER) #include #define INLINE __forceinline #define NOINLINE __declspec(noinline) #define ROTL64(a,b) _rotl64(a,b) #define MM16 __declspec(align(16)) typedef unsigned int uint32_t; #if (_MSC_VER >= 1500) #define __SSSE3__ #endif #if (_MSC_VER > 1200) || defined(_mm_free) #define __SSE2__ #endif #else #define INLINE inline __attribute__((always_inline)) #define NOINLINE __attribute__((noinline)) #define ROTL64(a,b) (((a)<<(b))|((a)>>(64-b))) #define MM16 __attribute__((aligned(16))) #endif #define FALLTHROUGH #if defined(__clang__) # if defined(__has_cpp_attribute) # if __has_cpp_attribute(clang::fallthrough) # undef FALLTHROUGH # define FALLTHROUGH [[clang::fallthrough]] # endif # endif #elif defined(__GNUC__) #undef FALLTHROUGH #define FALLTHROUGH __attribute__ ((fallthrough)) #endif #if defined(__SSE2__) #include typedef __m128i xmmi; typedef __m64 qmm; typedef union packedelem64_t { uint64_t u[2]; xmmi v; } packedelem64; typedef union packedelem8_t { unsigned char u[16]; xmmi v; } packedelem8; #endif #if defined(__SSSE3__) #include #endif #endif // SIPHASH_IMPL_H siphashc-2.1/siphashc.c000066400000000000000000000051171372365105700151410ustar00rootroot00000000000000/* * Copyright (c) 2013 Eli Janssen * Copyright (c) 2014 Carlo Pires * Copyright (c) 2017 - 2020 Michal Čihař * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. **/ #define PY_SSIZE_T_CLEAN #include #include #include #include "siphash/siphash.h" static PyObject *pysiphash(PyObject *self, PyObject *args) { const char *key = NULL; Py_ssize_t key_sz; const char *plaintext = NULL; Py_ssize_t plain_sz; uint64_t hash; if (!PyArg_ParseTuple( args, "s#s#:siphash", &key, &key_sz, &plaintext, &plain_sz)) { return NULL; } if (key_sz != 16) { PyErr_SetString( PyExc_ValueError, "key must be exactly 128 bits long (16 chars)"); return NULL; } hash = siphash( (const unsigned char*)key, (const unsigned char*)plaintext, plain_sz); return PyLong_FromUnsignedLongLong(hash); } static char siphash_docstring[] = "" "Computes Siphash-2-4 of the given string and key\n\n" "siphash(key, plaintext) -> hash\n" " - key: must be 128 bit long (16 chars at 8 bit each)\n" " - plaintext: text\n" "returns 64-bit output (python Long)\n"; static PyMethodDef siphashc_methods[] = { {"siphash", pysiphash, METH_VARARGS, siphash_docstring}, {NULL, NULL, 0, NULL} /* sentinel */ }; static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "siphashc", NULL, -1, siphashc_methods, NULL, NULL, NULL, NULL }; PyObject * PyInit_siphashc(void) { return PyModule_Create(&moduledef); } siphashc-2.1/test_siphashc.py000066400000000000000000000061151372365105700164050ustar00rootroot00000000000000"""Test for siphashc module.""" import unittest from siphashc import siphash class TestSiphashC(unittest.TestCase): """Test for siphashc module.""" def test_hash(self): """Test simple hashing.""" result = siphash("sixteencharstrng", "i need a hash of this") self.assertEqual(10796923698683394048, result) result = siphash("0123456789ABCDEF", "a") self.assertEqual(12398370950267227270, result) def test_errors(self): """Test error handling.""" with self.assertRaises(ValueError): siphash("not long enough", "a") with self.assertRaises(ValueError): siphash("toooooooooooooooooooooooo long", "a") with self.assertRaises(ValueError): siphash("", "a") def test_reference_vectors(self): """Test reference vectors.""" vectors = [ 0x726FDB47DD0E0E31, 0x74F839C593DC67FD, 0x0D6C8009D9A94F5A, 0x85676696D7FB7E2D, 0xCF2794E0277187B7, 0x18765564CD99A68D, 0xCBC9466E58FEE3CE, 0xAB0200F58B01D137, 0x93F5F5799A932462, 0x9E0082DF0BA9E4B0, 0x7A5DBBC594DDB9F3, 0xF4B32F46226BADA7, 0x751E8FBC860EE5FB, 0x14EA5627C0843D90, 0xF723CA908E7AF2EE, 0xA129CA6149BE45E5, 0x3F2ACC7F57C29BDB, 0x699AE9F52CBE4794, 0x4BC1B3F0968DD39C, 0xBB6DC91DA77961BD, 0xBED65CF21AA2EE98, 0xD0F2CBB02E3B67C7, 0x93536795E3A33E88, 0xA80C038CCD5CCEC8, 0xB8AD50C6F649AF94, 0xBCE192DE8A85B8EA, 0x17D835B85BBB15F3, 0x2F2E6163076BCFAD, 0xDE4DAAACA71DC9A5, 0xA6A2506687956571, 0xAD87A3535C49EF28, 0x32D892FAD841C342, 0x7127512F72F27CCE, 0xA7F32346F95978E3, 0x12E0B01ABB051238, 0x15E034D40FA197AE, 0x314DFFBE0815A3B4, 0x027990F029623981, 0xCADCD4E59EF40C4D, 0x9ABFD8766A33735C, 0x0E3EA96B5304A7D0, 0xAD0C42D6FC585992, 0x187306C89BC215A9, 0xD4A60ABCF3792B95, 0xF935451DE4F21DF2, 0xA9538F0419755787, 0xDB9ACDDFF56CA510, 0xD06C98CD5C0975EB, 0xE612A3CB9ECBA951, 0xC766E62CFCADAF96, 0xEE64435A9752FE72, 0xA192D576B245165A, 0x0A8787BF8ECB74B2, 0x81B3E73D20B49B6F, 0x7FA8220BA3B2ECEA, 0x245731C13CA42499, 0xB78DBFAF3A8D83BD, 0xEA1AD565322A1A0B, 0x60E61C23A3795013, 0x6606D7E446282B93, 0x6CA4ECB15C5F91E1, 0x9F626DA15C9625F3, 0xE51B38608EF25F57, 0x958A324CEB064572, ] k = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" message = "" for i in range(64): self.assertEqual(siphash(k, message), vectors[i]) message += chr(i)