pax_global_header00006660000000000000000000000064133553676650014535gustar00rootroot0000000000000052 comment=45b8b1d5926c9cee83a2f5db4973fb9820c68796 siphashc-1.2/000077500000000000000000000000001335536766500132015ustar00rootroot00000000000000siphashc-1.2/.github/000077500000000000000000000000001335536766500145415ustar00rootroot00000000000000siphashc-1.2/.github/stale.yml000066400000000000000000000026011335536766500163730ustar00rootroot00000000000000# Configuration for probot-stale - https://github.com/probot/stale # Number of days of inactivity before an Issue or Pull Request becomes stale daysUntilStale: 60 # 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: 14 daysUntilClose: 7 exemptLabels: - bug - enhancement - documentation - security siphashc-1.2/.gitignore000066400000000000000000000001041335536766500151640ustar00rootroot00000000000000__pycache__ *egg-info /build /dist /MANIFEST /siphashc*.so *.py[co] siphashc-1.2/.travis.yml000066400000000000000000000005431335536766500153140ustar00rootroot00000000000000dist: trusty sudo: false language: python python: - "2.7" - "3.3" - "3.4" - "3.5" - "3.6" matrix: include: - os: osx language: generic - python: 3.7 dist: xenial sudo: true script: - CFLAGS="-Wall -Wextra -Wno-unused-parameter" python setup.py build - python setup.py test - python benchmark.py siphashc-1.2/CHANGES.rst000066400000000000000000000004521335536766500150040ustar00rootroot00000000000000Changes ======= 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-1.2/LICENSE.md000066400000000000000000000022121335536766500146020ustar00rootroot00000000000000Copyright (c) 2013 Eli Janssen Copyright (c) 2014 Carlo Pires (python3 support) Copyright (c) 2017 Michal Čihař (additional cleanups) 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. siphashc-1.2/MANIFEST.in000066400000000000000000000001471335536766500147410ustar00rootroot00000000000000include siphash/*.h include test_siphashc.py include LICENSE.md include README.rst include CHANGES.rst siphashc-1.2/README.rst000066400000000000000000000030171335536766500146710ustar00rootroot00000000000000siphashc ======== .. image:: https://travis-ci.org/WeblateOrg/siphashc.svg?branch=master :target: https://travis-ci.org/WeblateOrg/siphashc .. image:: https://ci.appveyor.com/api/projects/status/kgeohtb6as3xd9b7/branch/master?svg=true :target: https://ci.appveyor.com/project/nijel/siphashc-merge/branch/master .. image:: https://api.codacy.com/project/badge/Grade/33758f86fbf44e929d85f47390093771 :target: https://www.codacy.com/app/Weblate/siphashc .. 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 ~~~~~ Python 2 ^^^^^^^^ .. code:: python >>> from siphashc import siphash >>> siphash('sixteencharstrng', 'i need a hash of this') 10796923698683394048L Python 3 ^^^^^^^^ .. code:: python >>> from siphashc import siphash >>> siphash('sixteencharstrng', 'i need a hash of this') 10796923698683394048 License ~~~~~~~ Released under the `MIT license `__. See ``LICENSE.md`` file for details. siphashc-1.2/appveyor.yml000066400000000000000000000012551335536766500155740ustar00rootroot00000000000000version: "{build}" clone_depth: 100 environment: matrix: - PYTHON: "C:\\Python27" - PYTHON: "C:\\Python33" - PYTHON: "C:\\Python34" - PYTHON: "C:\\Python35" - PYTHON: "C:\\Python36" - PYTHON: "C:\\Python36-x64" install: - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" # We need wheel installed to build wheels - "python.exe -m pip install wheel" build_script: # Build the compiled extension - "python setup.py build" test_script: # Run the project tests - "python setup.py test" - "python benchmark.py" after_test: - "python.exe setup.py bdist_wheel" artifacts: # bdist_wheel puts your built wheel in the dist directory - path: dist\* siphashc-1.2/benchmark.py000077500000000000000000000006511335536766500155120ustar00rootroot00000000000000#!/usr/bin/env python """Simple timing benchmark. Used for testing possible regressions when changing code.""" from __future__ import print_function 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-1.2/setup.py000077500000000000000000000023731335536766500147230ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- import io import os.path from setuptools import setup, Extension 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='1.2', author='Michal Čihař', author_email='michal@cihar.com', description='Python module (in c) for siphash-2-4', long_description=LONG_DESCRIPTION, keywords='siphash siphash-2-4', url='https://github.com/WeblateOrg/siphashc', bugtrack_url='https://github.com/WeblateOrg/siphashc/issues', license="MIT", 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 :: 2.7', 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Libraries :: Python Modules', 'License :: OSI Approved :: MIT License', ], test_suite='test_siphashc', zip_safe=True, ) siphashc-1.2/siphash/000077500000000000000000000000001335536766500146405ustar00rootroot00000000000000siphashc-1.2/siphash/README.md000066400000000000000000000000651335536766500161200ustar00rootroot00000000000000siphash from https://github.com/floodyberry/siphash siphashc-1.2/siphash/siphash.c000066400000000000000000000035521335536766500164500ustar00rootroot00000000000000#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-1.2/siphash/siphash.h000066400000000000000000000007051335536766500164520ustar00rootroot00000000000000#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-1.2/siphash/siphash_impl.h000066400000000000000000000025321335536766500174730ustar00rootroot00000000000000#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-1.2/siphashc.c000066400000000000000000000056231335536766500151550ustar00rootroot00000000000000/* * Copyright (c) 2013 Eli Janssen * Copyright (c) 2014 Carlo Pires * Copyright (c) 2017 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. **/ #include #include #include #include "siphash/siphash.h" static PyObject *pysiphash(PyObject *self, PyObject *args) { const char *key = NULL; int key_sz; const char *plaintext = NULL; int 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 */ }; #if PY_MAJOR_VERSION >= 3 static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "siphashc", NULL, -1, siphashc_methods, NULL, NULL, NULL, NULL }; #define INITERROR return NULL PyObject * PyInit_siphashc(void) #else #define INITERROR return void initsiphashc(void) #endif { PyObject *module; #if PY_MAJOR_VERSION >= 3 module = PyModule_Create(&moduledef); #else module = Py_InitModule("siphashc", siphashc_methods); #endif if (module == NULL) INITERROR; #if PY_MAJOR_VERSION >= 3 return module; #endif } siphashc-1.2/test_siphashc.py000066400000000000000000000051231335536766500164150ustar00rootroot00000000000000"""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)