{"id":26935804,"url":"https://github.com/kokke/tiny-AES128-C","last_synced_at":"2025-04-02T12:01:50.626Z","repository":{"id":3386035,"uuid":"4434428","full_name":"kokke/tiny-AES-c","owner":"kokke","description":"Small portable AES128/192/256 in C","archived":false,"fork":false,"pushed_at":"2024-10-04T09:45:23.000Z","size":178,"stargazers_count":4258,"open_issues_count":25,"forks_count":1294,"subscribers_count":143,"default_branch":"master","last_synced_at":"2024-10-29T15:28:43.731Z","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":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kokke.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,"publiccode":null,"codemeta":null}},"created_at":"2012-05-24T15:27:24.000Z","updated_at":"2024-10-29T13:02:28.000Z","dependencies_parsed_at":"2024-05-01T23:11:33.922Z","dependency_job_id":"a231de48-523b-4abb-9525-e82b98ec710a","html_url":"https://github.com/kokke/tiny-AES-c","commit_stats":{"total_commits":245,"total_committers":22,"mean_commits":"11.136363636363637","dds":"0.17142857142857137","last_synced_commit":"f06ac37fc31dfdaca2e0d9bec83f90d5663c319b"},"previous_names":["kokke/tiny-aes128-c"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-AES-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-AES-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-AES-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-AES-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kokke","download_url":"https://codeload.github.com/kokke/tiny-AES-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246811289,"owners_count":20837749,"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":"2025-04-02T12:01:39.559Z","updated_at":"2025-04-02T12:01:50.607Z","avatar_url":"https://github.com/kokke.png","language":"C","readme":"![CI](https://github.com/kokke/tiny-AES-c/actions/workflows/c-cpp.yml/badge.svg)\n### Tiny AES in C\n\nThis is a small and portable implementation of the AES [ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_.28ECB.29), [CTR](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29) and [CBC](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29) encryption algorithms written in C.\n\nYou can override the default key-size of 128 bit with 192 or 256 bit by defining the symbols AES192 or AES256 in [`aes.h`](https://github.com/kokke/tiny-AES-c/blob/master/aes.h).\n\nThe API is very simple and looks like this (I am using C99 `\u003cstdint.h\u003e`-style annotated types):\n\n```C\n/* Initialize context calling one of: */\nvoid AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);\nvoid AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);\n\n/* ... or reset IV at random point: */\nvoid AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);\n\n/* Then start encrypting and decrypting with the functions below: */\nvoid AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);\nvoid AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);\n\nvoid AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);\nvoid AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);\n\n/* Same function for encrypting as for decrypting in CTR mode */\nvoid AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);\n```\n\nImportant notes: \n * No padding is provided so for CBC and ECB all buffers should be multiples of 16 bytes. For padding [PKCS7](https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7) is recommendable.\n * ECB mode is considered unsafe for most uses and is not implemented in streaming mode. If you need this mode, call the function for every block of 16 bytes you need encrypted. See [wikipedia's article on ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_Codebook_(ECB)) for more details.\n * This library is designed for small code size and simplicity, intended for cases where small binary size, low memory footprint and portability is more important than high performance. If speed is a concern, you can try more complex libraries, e.g. [Mbed TLS](https://tls.mbed.org/), [OpenSSL](https://www.openssl.org/) etc.\n\nYou can choose to use any or all of the modes-of-operations, by defining the symbols CBC, CTR or ECB in [`aes.h`](https://github.com/kokke/tiny-AES-c/blob/master/aes.h) (read the comments for clarification).\n\nC++ users should `#include` [aes.hpp](https://github.com/kokke/tiny-AES-c/blob/master/aes.hpp) instead of [aes.h](https://github.com/kokke/tiny-AES-c/blob/master/aes.h)\n\nThere is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input.\n\nThe module uses less than 200 bytes of RAM and 1-2K ROM when compiled for ARM, but YMMV depending on which modes are enabled.\n\nIt is one of the smallest implementations in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). \n\nI've successfully used the code on 64bit x86, 32bit ARM and 8 bit AVR platforms.\n\n\nGCC size output when only CTR mode is compiled for ARM:\n\n    $ arm-none-eabi-gcc -Os -DCBC=0 -DECB=0 -DCTR=1 -c aes.c\n    $ size aes.o\n       text    data     bss     dec     hex filename\n       1171       0       0    1171     493 aes.o\n\n.. and when compiling for the THUMB instruction set, we end up well below 1K in code size.\n\n    $ arm-none-eabi-gcc -Os -mthumb -DCBC=0 -DECB=0 -DCTR=1 -c aes.c\n    $ size aes.o\n       text    data     bss     dec     hex filename\n        903       0       0     903     387 aes.o\n\n\nI am using the Free Software Foundation, ARM GCC compiler:\n\n    $ arm-none-eabi-gcc --version\n    arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release)\n    Copyright (C) 2013 Free Software Foundation, Inc.\n    This is free software; see the source for copying conditions.  There is NO\n    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n\n\n\nThis implementation is verified against the data in:\n\n[National Institute of Standards and Technology Special Publication 800-38A 2001 ED](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf) Appendix F: Example Vectors for Modes of Operation of the AES.\n\nThe other appendices in the document are valuable for implementation details on e.g. padding, generation of IVs and nonces in CTR-mode etc.\n\n\nA heartfelt thank-you to [all the nice people](https://github.com/kokke/tiny-AES-c/graphs/contributors) out there who have contributed to this project.\n\n\nAll material in this repository is in the public domain.\n","funding_links":[],"categories":["Cryptography","密码学","C","Frameworks and Libs"],"sub_categories":["C"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokke%2Ftiny-AES128-C","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkokke%2Ftiny-AES128-C","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokke%2Ftiny-AES128-C/lists"}