{"id":21166363,"url":"https://github.com/markamdev/klein","last_synced_at":"2025-03-14T16:46:42.607Z","repository":{"id":219813461,"uuid":"258538205","full_name":"markamdev/klein","owner":"markamdev","description":"Simple implementation of KLEIN - the lightweight block cipher","archived":false,"fork":false,"pushed_at":"2020-05-07T19:21:58.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T10:11:34.872Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markamdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-24T14:40:07.000Z","updated_at":"2020-05-07T19:22:01.000Z","dependencies_parsed_at":"2024-01-29T22:59:20.340Z","dependency_job_id":null,"html_url":"https://github.com/markamdev/klein","commit_stats":null,"previous_names":["markamdev/klein"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fklein","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fklein/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fklein/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fklein/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markamdev","download_url":"https://codeload.github.com/markamdev/klein/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243615556,"owners_count":20319728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T14:49:36.034Z","updated_at":"2025-03-14T16:46:42.585Z","avatar_url":"https://github.com/markamdev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SKLEIN - a Simple KLEIN implementation\n\nThis repository contains an implementation of KLEIN lightweight block cipher block cipher written in C language. For information about this cipher please read authors' paper: [KLEIN: A New Family of Lightweight Block Ciphers](https://research.utwente.nl/files/5095831/The_KLEIN_Block_Cipher.pdf).\n\n## Source code compilation\n\n### Library compilation\n\nKLEIN implementation can be compiled into both static and dynamic library. To build (S)KLEIN libraries call:\n\n```shell\nmake library\n```\n\nHeader file (*sklein.h*) and two versions of library (*libsklein.a* and *libsklein.so*) will be placed in output directory (*./build*).\n\n### Demo app compilation\n\nSimple demo application that shows how to use this implementation can be found in *./demo/demo.c*. To build demo application call:\n\n```bash\nmake demo\n```\n\nExecutable file will be stored in *./build/sklein-demo*. Currently demo presents only usage of *KLEIN-64*.\n\n### Tests compilation and launching\n\nTo validate implemented encryption and decryption test vectors from KLEIN specification (Appendix A.) are used. All test related files are stored in *./test* directory. Test vectors are declared and defined in *test-vectors.h* and *test-vectors.c* respectively. Simple \"test engine\" implementation can be found in *main.c*.\n\nTo build and launch tests one has to call:\n\n```bash\nmake tests\n```\n\nTest binary will be created in *./build/sklein-tests* directory and executed.\n\n## SKLEIN library usage\n\n### Header file and API\n\nAll necessary SKLEIN data types and functions are defined in *sklein.h\" header file. SKLEIN API is mainly composed of following 5 functions:\n\n```C\nsklein_t sklein_create(int km);\n\nint sklein_set_key(sklein_t crypter, const uint8_t *mkey, uint8\\_t k\\_length);\n\nint sklein\\_encrypt\\_block(sklein\\_t crypter, uint8\\_t *block);\n\nint sklein_decrypt_block(sklein_t crypter, uint8_t *block);\n\nvoid sklein\\_destroy(sklein\\_t crypter);\n```\n\nPlease see mentioned header for more details.\n\n### Examples\n\nThis library provides only implementation of KLEIN block cipher with support of one block only encryption/decryption based on algorith specification. To encrypt 8B (one block) of data using KLEIN-64 following steps are needed:\n\n```C\n    sklein_t crypter = sklein_create(KLEIN_MODE_64);\n    if (crypter == NULL)\n    {\n        printf(\"ERROR: Failed to create KLEIN-64\\n\");\n        return 1;\n    }\n\n    uint8_t data64[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\n    uint8_t key64[] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};\n\n    int result = 0;\n    result = sklein_set_key(crypter, key64, sizeof(key64));\n    if (result != KLEIN_RESULT_OK)\n    {\n        printf(\"ERROR: Failed to set key: %d\\n\", result);\n        return 1;\n    }\n\n    result = sklein_encrypt_block(crypter, data64);\n    if (result != KLEIN_RESULT_OK)\n    {\n        printf(\"ERROR: Failed to crypt\\n\");\n        return 1;\n    }\n```\n\nIn similar way encrypted data can be decrypted with use of provided implementation:\n\n```C\n    sklein_t crypter = sklein_create(KLEIN_MODE_64);\n    if (crypter == NULL)\n    {\n        printf(\"ERROR: Failed to create KLEIN-64\\n\");\n        return 1;\n    }\n\n    uint8_t data64[] = {0x59, 0x23, 0x56, 0xC4, 0x99, 0x71, 0x76, 0xC8};\n    uint8_t key64[] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};\n\n    int result = 0;\n    result = sklein_set_key(crypter, key64, sizeof(key64));\n    if (result != KLEIN_RESULT_OK)\n    {\n        printf(\"ERROR: Failed to set key: %d\\n\", result);\n        return 1;\n    }\n\n    result = sklein_decrypt_block(crypter, data64);\n    if (result != KLEIN_RESULT_OK)\n    {\n        printf(\"ERROR: Failed to decrypt\\n\");\n        return 1;\n    }\n\n```\n\nPlease see provided *demo/demo.c* file for full encryption/decryption example.\n\n### KLEIN in CBC (Cipher BLock Chaining) mode\n\nFor encrypting data sets larger than one block (8B) KLEIN cipher has been enclosed in Cipher Block Chaining algorithm. It uses 8B Initialization Vector and encrypts blocks of N*8B length.\n\nFunctions below have been added specificaly for CBC mode:\n\n```C\nint sklein_set_iv(sklein_t crypter, const uint8_t *iv);\n\nint sklein_cbc_encrypt_data(sklein_t crypter, uint8_t *data, size_t len);\n\nint sklein_cbc_decrypt_data(sklein_t crypter, uint8_t *data, size_t len);\n```\n\nBoth *encrypt* and *decrypt* functions are placing encryption result in input data buffer.\n\n## Disclaimer\n\nThis implementation has been written \"just for fun\" and is published \"AS IS\". It is not optimized neither analyzed for security weakness.\n\nCode form this repository can be included in other projects in parts or as a whole but it is not recommended to use it in production environment.\n\n## Author / contact\n\nIf you need to contact me feel free to write me an email:\n[markamdev.84#dontwantSPAM#gmail.com](mailto:)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkamdev%2Fklein","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkamdev%2Fklein","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkamdev%2Fklein/lists"}