Implementation of a Generalized-Feistel Cipher for generating random permutations.
Project description
🎲 gfc — fast & lazy random permutations
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pygfc-1.0.2-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bcdbd94df8e94b738801260e43beac26729a092c8b5d1c636871906a4e8c214 |
|
MD5 | 896e329b455c2c1e77bcd3d78c2534bd |
|
BLAKE2b-256 | 828e1e25dc952c5adfe1d29ba20d29736a6fcda9e843fa59221c8e0b480ed3b0 |
Hashes for pygfc-1.0.2-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e42b56a393c7a7bfe509dec2a142efb9886257395d397aaadcd18748cc23535 |
|
MD5 | 2eef19ebec2a04111b2e27e3e1e29aba |
|
BLAKE2b-256 | b5dd51f9b8da91fcc3e77eefffbd3f14097b5b19e3e8141a1cd36bef4703ed4d |
Hashes for pygfc-1.0.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6531a5c76093420dfcaaa114d5026abdde702ca54476de68c7576b5ad36a7e7e |
|
MD5 | a6ec0a70a8be2831c445f3103b709dad |
|
BLAKE2b-256 | e1727c92e02f90a19ad1b455fdabc678fcbbbd270fb9036964b7097573520529 |
Hashes for pygfc-1.0.2-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ba96fa2fecd65ac96da3fb757cdd17d0c6940d17559b08f2361b529f4876a4 |
|
MD5 | 4388e9fd5b3afaeadd915a4098d74b97 |
|
BLAKE2b-256 | 1dd236a18b4e50c9bedfa0f5280c12a70d037396f336b7b0834efa0ebc46df15 |
Hashes for pygfc-1.0.2-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f68c26204e0aa8f85efe1a4d85711f679be16945a2fd4af9fea5e3d53401958f |
|
MD5 | 15595ae8f5aabe71ad37e4308aa9490b |
|
BLAKE2b-256 | af2a58533175fbed506285e448aa8e7143593efffde66d582f403c2109acab0e |
Hashes for pygfc-1.0.2-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 279e28d05cf4d9b1d459383faaeaed1a3f378e42dc1e01ef555bce54ee623ee9 |
|
MD5 | 007b5266bf62f51e39b3caf2139d6fc5 |
|
BLAKE2b-256 | 829db360e6a62cbf1cf7e413a3902e943ea306f0d43b464d4ade9f6a245637c3 |
Hashes for pygfc-1.0.2-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dda79f498856388248a1329512249b0ae525a077308242eed45e1bf29d66a925 |
|
MD5 | 8392bb12ebce0a732b982a134ba4fc12 |
|
BLAKE2b-256 | 75f30c5d8874b348e26cec5a075116d590bf6daaec988fe23e327c0bcd548c40 |
Hashes for pygfc-1.0.2-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68ca21fa3efa4780fe554ac5b2a2179ac2091cce1c35fb1cd43035aa85e3e291 |
|
MD5 | 8cc5e72637b47b7dec20a11f9fb70a67 |
|
BLAKE2b-256 | f2ec775ff008535fa0937c66251b66fc81c74c1a452902189892f02ade3f3b63 |
Hashes for pygfc-1.0.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dafbfac7520fdb04d47fd39f968afb5f04dc21c8c38e14728ab8bef302d31c04 |
|
MD5 | 8e31cc368f5e573a441351a4cf344f99 |
|
BLAKE2b-256 | 9e3066e816174aa4974a4235f0ea1dcdd974451094a9ab28814819384eecb7a3 |
Hashes for pygfc-1.0.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6120f26a1a7e09056275f945b579c9e5a03b0971062fae142e43cbc52ec036d |
|
MD5 | ddd09b68cf89e7bb88317a308038027f |
|
BLAKE2b-256 | f6ac11f805879db68db95e0dd704db07a4c6ded6dc21e7c765255cfa0eed263c |
Hashes for pygfc-1.0.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e37b81550a7ebb317d747702ccd894f3e2453ab932ff04551f6de0bf3437037 |
|
MD5 | f9db0a85a45823887b41997a212af578 |
|
BLAKE2b-256 | a638721be4ac9fba62dcc63a03b0e03714660c96e69ab9e8f5db3ae1bbb9e912 |
Hashes for pygfc-1.0.2-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f14a6174e3921449ed509f11dda98d26df51afce855104a56930134506fa9691 |
|
MD5 | df5f97524fba17fcae951614cbd23675 |
|
BLAKE2b-256 | 9fde53b92a82589252bd5c9f8d29b212ceabe6a9d9ca7d203d26e48ff40f498b |
Hashes for pygfc-1.0.2-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b19627344227c944e40c67a89d49a43bbfab47172d7e8d5c627ccbd3a21bc41e |
|
MD5 | ced4a2d3e71a3a254230955809ec3343 |
|
BLAKE2b-256 | 637724d394678eef137de9321d34eb4250c6007be9e0acb82903fec83dabb9fe |
Hashes for pygfc-1.0.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c5da4d73dd8aae6119a65de30550bf0338f0079db2c2e853a67f8b57d272c8 |
|
MD5 | 89e8160df4bedde18f1f19001ea825e8 |
|
BLAKE2b-256 | 43cad2391eed151d1a6c51be4bdc27fe77fdb3a5e2d7cf57e790e39ce69387c9 |
Hashes for pygfc-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5acb1a80bf23821403ad976ee2ef7934a0f2ecab020ae8e2e2ee93a10a73ecca |
|
MD5 | d92d7224c0389786511530c6da7c8f85 |
|
BLAKE2b-256 | 5361071d047fb178fae340fe4a974bf70088b2a73b8086246d7e5d5e9e413306 |
Hashes for pygfc-1.0.2-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b0a2bcb1c9b344a59691c1bf896d0b39e904d03e5f393bdb052ea75d814c0b |
|
MD5 | fa159db4190581c92dc67707f457f435 |
|
BLAKE2b-256 | ae0fbdd2036d1f2ebbd21f8e53f501bdc4a649df49df81622d96a5296025b83e |
Hashes for pygfc-1.0.2-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2471d2f0d77465d5e0a1702abe61d09e0fa5942ff73259985409968637bf5142 |
|
MD5 | f969a544aaf2cf12ce8132f76f4f8357 |
|
BLAKE2b-256 | d969d34ffa5e4856ac76170f0c2c6f5f056986821af42e16d74c3fc4653aad36 |
Hashes for pygfc-1.0.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eab17445d16f0f8dd1d5d3f29be51cb9ee6708e21a538d9d6807b6ac7ba870a |
|
MD5 | f9e14c16918b4ee666e6bb67d1fb4f76 |
|
BLAKE2b-256 | f59a6d7942a69190b715f8b1ccaca6b0589873ce65a7849f4fb87a822e57a4a6 |
Hashes for pygfc-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d07bdf8c7d8c654c508c7c1ebc774fa789a9a88e92d43504fe7b3e30be3bca |
|
MD5 | d221cc849f44f792e941d89b27b734bb |
|
BLAKE2b-256 | b5746ef32ad7a6e5c1cc3a7beff75fd153397ba4d74730f999f031f561d77284 |
Hashes for pygfc-1.0.2-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b86518c687656b15fdb2adfc37d69ab4c8fc2b1decc8c99595fede0868ea325 |
|
MD5 | 63dddf55ff17ff26827f5da8ab7bfdfb |
|
BLAKE2b-256 | fe469119f546d46d4e66d9d6a3d4fbca69ca42b3f797b12cf8b4eb3d4cbadbf7 |
Hashes for pygfc-1.0.2-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7427dd503c8f43c7051da5ec31311a5d6690fd4b341d1946fb159f51f63ba2e8 |
|
MD5 | 5dbeda5b96e03b658ba55729a2e763dd |
|
BLAKE2b-256 | 9d80df4681d573184ce43b9e339a19a852400aa720cd59b9d6c27dad811f5f6c |
Hashes for pygfc-1.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c9177efbdc3a5cbc990807e52d839accb8f1a19e6dcff7f976f010f7006a6b |
|
MD5 | cdab22e48e85e4371b9a25a77a8b174a |
|
BLAKE2b-256 | bf29dbf1e19c6cb6f9daa6c59fb43349365a623c5c159842f400538c69610314 |
Hashes for pygfc-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aea30d1c6ec4b18368f42f1fece7b63fc5a22b742bab904ea50c15b47441b28 |
|
MD5 | 053b2fbcdc2a4f4c068f25a42332db2c |
|
BLAKE2b-256 | 140c989ed8f430bbb0e22bc298855488134307bb93c31da6bc6919194878e2f7 |