Skip to main content

Implementation of a Generalized-Feistel Cipher for generating random permutations.

Project description

🎲 gfc — fast & lazy random permutations

PyPI Status Tests Status PyPI

gfc is a C implementation of a Generalized-Feistel Cipher [1, alg. 3] for generating random permutations.
It uses Speck 64/128 as the random function, and can generate permutations with up to 2^64 elements.
The permutation is computed, and reversed, on-the-fly, without any mutable state and by using very little memory.

Usage

C / C++

API

#include <gfc/gfc.h>
GFC* gfc_init(uint64_t range, uint64_t rounds, uint64_t seed);
void gfc_destroy(GFC* gfc);
uint64_t gfc_decrypt(const GFC* gfc, uint64_t m);
uint64_t gfc_encrypt(const GFC* gfc, uint64_t m);

Example

// main.c
// gcc -Iinclude/ src/gfc.c main.c -o main
#include <assert.h>
#include <gfc/gfc.h>

int main() {
  GFC* gfc = gfc_init(65536, 6, 42);
  
  for (uint64_t i = 0; i < 65536; i++) {
    uint64_t enc = gfc_encrypt(gfc, i);
    uint64_t dec = gfc_decrypt(gfc, enc);
    assert(enc != i);
    assert(dec == i);
  }

  gfc_destroy(gfc);
  return 0;
}

CMake Integration

cmake_minimum_required(VERSION 3.12)
project(example)
add_subdirectory(gfc)
add_executable(main main.c)
target_link_libraries(main PRIVATE gfc)
git submodule add https://github.com/maxmouchet/gfc.git
mkdir build && cd build
cmake .. && cmake --build .
./main

Python

pip install pygfc
from pygfc import Permutation
# Permutation(range, rounds, seed)
perm = Permutation(2 ** 16, 8, 42)
assert set(perm) == set(range(2 ** 16))
assert all(perm.inv(perm[i]) == i for i in range(2 ** 16))

Dependencies

The Speck implementation is from madmo/speck and is licensed under the ISC license (MIT-compatible).

References

[1] Black, John, and Phillip Rogaway. "Ciphers with arbitrary finite domains." Cryptographers’ track at the RSA conference. Springer, Berlin, Heidelberg, 2002. https://web.cs.ucdavis.edu/~rogaway/papers/subset.pdf

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygfc-1.0.5.tar.gz (47.1 kB view hashes)

Uploaded Source

Built Distributions

pygfc-1.0.5-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (150.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (154.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (41.9 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pygfc-1.0.5-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (146.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (19.4 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

pygfc-1.0.5-cp310-cp310-musllinux_1_1_x86_64.whl (138.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

pygfc-1.0.5-cp310-cp310-musllinux_1_1_i686.whl (139.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

pygfc-1.0.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (132.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (133.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-cp310-cp310-macosx_11_0_arm64.whl (25.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pygfc-1.0.5-cp310-cp310-macosx_10_9_x86_64.whl (26.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pygfc-1.0.5-cp39-cp39-musllinux_1_1_x86_64.whl (136.8 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

pygfc-1.0.5-cp39-cp39-musllinux_1_1_i686.whl (138.2 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

pygfc-1.0.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (130.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (132.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-cp39-cp39-macosx_11_0_arm64.whl (24.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pygfc-1.0.5-cp39-cp39-macosx_10_9_x86_64.whl (25.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pygfc-1.0.5-cp38-cp38-musllinux_1_1_x86_64.whl (135.5 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

pygfc-1.0.5-cp38-cp38-musllinux_1_1_i686.whl (138.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

pygfc-1.0.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (129.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (131.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-cp38-cp38-macosx_11_0_arm64.whl (24.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pygfc-1.0.5-cp38-cp38-macosx_10_9_x86_64.whl (25.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pygfc-1.0.5-cp37-cp37m-musllinux_1_1_x86_64.whl (125.3 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

pygfc-1.0.5-cp37-cp37m-musllinux_1_1_i686.whl (127.2 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

pygfc-1.0.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (121.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (122.7 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-cp37-cp37m-macosx_10_9_x86_64.whl (25.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

pygfc-1.0.5-cp36-cp36m-musllinux_1_1_x86_64.whl (126.2 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

pygfc-1.0.5-cp36-cp36m-musllinux_1_1_i686.whl (127.9 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

pygfc-1.0.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (122.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pygfc-1.0.5-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (123.3 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pygfc-1.0.5-cp36-cp36m-macosx_10_9_x86_64.whl (25.5 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page