{"id":18564854,"url":"https://github.com/marcoplaitano/c-cipher","last_synced_at":"2025-05-15T18:34:49.916Z","repository":{"id":177293394,"uuid":"495570345","full_name":"marcoplaitano/c-cipher","owner":"marcoplaitano","description":"A program to encrypt/decrypt files using the AES-CTR-256 cipher.","archived":false,"fork":false,"pushed_at":"2024-01-04T12:50:35.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-26T12:09:44.127Z","etag":null,"topics":["aes","aes-256","aes-256-ctr","aes-ctr","aes-encryption","c","cipher","cipher-algorithms","encryption","encryption-algorithms","encryption-decryption","password-manager"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcoplaitano.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-05-23T20:54:04.000Z","updated_at":"2024-01-04T12:49:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"94387723-ca0d-49a8-8214-2de09e6a61c3","html_url":"https://github.com/marcoplaitano/c-cipher","commit_stats":null,"previous_names":["marcoplaitano/c-cipher"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fc-cipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fc-cipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fc-cipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcoplaitano%2Fc-cipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcoplaitano","download_url":"https://codeload.github.com/marcoplaitano/c-cipher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239293948,"owners_count":19615043,"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":["aes","aes-256","aes-256-ctr","aes-ctr","aes-encryption","c","cipher","cipher-algorithms","encryption","encryption-algorithms","encryption-decryption","password-manager"],"created_at":"2024-11-06T22:16:31.857Z","updated_at":"2025-02-17T13:14:32.001Z","avatar_url":"https://github.com/marcoplaitano.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C-CIPHER\n\nA program to encrypt/decrypt a file using the **AES-CTR-256** cipher.\n\nIt can be used to store passwords (or any other kind of sensible information) \nlocally, in a private way.  \nThe user only needs one password to both encrypt and decrypt the information.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Details on Security\n\nThe algorithm is implemented in C, using the [OpenSSL]'s Encryption [API].\n\nThe **Encryption Key** has to be 256-bits long; it is generated by computing\n`SHA256(p)`, with `p` being the user's password.\u003csup\u003e[1](#f1)\u003c/sup\u003e  \nThe same key is used for both encryption and decryption.\n\nThe _Initialization Vector IV_ is a string of `16` bytes.  \nThe last (**LSB**)\u003csup\u003e[2](#f2)\u003c/sup\u003e `8` bytes contain a counter which will be\nincremented at every new encrypted block.  \nThe first (**MSB**) `8` bytes contain the \"_nonce_\": a random sequence of bits.  \nWhen encrypting, the _nonce_ is filled with random bytes; these will be\nprepended to the ciphertext in order to read them during the decryption\nprocedure.\n\nThe _block length n_, is an important parameter for determining the concrete\nsecurity of the cipher.  \nBeing the **IV** a uniform string of _n-bits_, it is expected to repeat after\nhaving performed \"only\" `2`\u003csup\u003e`n/2`\u003c/sup\u003e encryptions.\u003csup\u003e[3](#f3)\u003c/sup\u003e  \nIn our case `n` is `128` bits; this means that only `2`\u003csup\u003e`64`\u003c/sup\u003e blocks -\nor `2*10`\u003csup\u003e`5`\u003c/sup\u003e **Petabytes** - can be safely encrypted without ever\nchanging the `IV`.  \nThis is more than safe for a regular text file.\n\n### Tampering\n\nIt must be noted that this mode of encryption provides no security against data\ntampering.  \nIf the ciphertext were to be modified even by just one bit, the *integrity* of\nthe information would be lost.\n\nThe scope of this project however is to provide a trivial example of encryption,\nto be used for simpler \"protection\" against *adversaries* who know little to\nnothing about cryptography.\n\n\u003cbr\u003e\n\n\u003csup id=\"f1\"\u003e**1**\u003c/sup\u003e The usage of a **PBKDF** (Password-Based Key\nDerivation Function) would further improve security.  \n\u003csup id=\"f2\"\u003e**2**\u003c/sup\u003e In **big-endian** order.  \n\u003csup id=\"f3\"\u003e**3**\u003c/sup\u003e Similar concept to '[The Birthday Problem]'.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Installation\n\nTake a look at the [dependencies] listed below.\n\nTo download and compile the program:\n\n```sh\ngit clone https://github.com/marcoplaitano/c-cipher\ncd c-cipher\nmake\n```\n\nThe executable file is `ccipher`.  \nTo install it globally:\n\n```sh\nsudo make install\n```\n\nThis will simply copy the executable to `/usr/local/bin/` and the manpage to\n`usr/local/man/`.  \nUninstall with:\n\n```sh\nsudo make uninstall\n```\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Usage\n\n```sh\nccipher in-file out-file mode password\n```\n\nThe program needs the following 4 command line arguments, in order:\n\n+ `in-file`  \n    Input file on which the cipher will be applied\n+ `out-file`  \n    Output file storing the result\n+ `mode`  \n    A string: either **encrypt**, **e**, **decrypt** or **d**\n+ `password`  \n    A string chosen by the user\n\n_**Note:** using this approach means that anyone with access to the computer\ncan learn the password since it is stored in the shell's history.\nA workaround might be requesting the 4 arguments **inside** the program, at\nruntime._\n\n### Example\n\nThe first time you run the program, the `in-file` should be the plain text file\ncontaining the private information.  \nThe output file will store the encrypted version of it.  \nIt is at this point that you must choose the **password** to use. It can contain\nany ASCII character and can be of any (reasonable) length.\n\n```sh\nccipher input.txt private.dat e Password123\n```\n\nThe following times, the plaintext version can be recreated with the command:\n\n```sh\nccipher private.dat output.txt d Password123\n```\n\nNotice how the two paths have been swapped, the mode is now **d**ecrypt and the\npassword remains the same.\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Dependencies\n\n+ gcc\n+ make\n+ libssl3\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## Author\n\nMarco Plaitano\n\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n\n## License\n\nDistributed under the [MIT] license.\n\n\n\u003c!-- Links --\u003e\n\n[OpenSSL]:\nhttps://www.openssl.org/\n\"Main Website\"\n\n[API]:\nhttps://www.openssl.org/docs/man3.0/man3/EVP_aes_256_ctr.html\n\"Online Documentation\"\n\n[The Birthday Problem]:\nhttps://en.wikipedia.org/wiki/Birthday_problem\n\"Wikipedia Article\"\n\n[dependencies]:\n#dependencies\n\"Anchor to header\"\n\n[MIT]:\nLICENSE\n\"Repository file\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoplaitano%2Fc-cipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcoplaitano%2Fc-cipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcoplaitano%2Fc-cipher/lists"}