{"id":28392039,"url":"https://github.com/kokke/tiny-ecdh-c","last_synced_at":"2025-06-26T01:32:43.117Z","repository":{"id":26687580,"uuid":"109536932","full_name":"kokke/tiny-ECDH-c","owner":"kokke","description":"Small portable Elliptic-Curve Diffie-Hellman in C","archived":false,"fork":false,"pushed_at":"2022-05-27T00:13:01.000Z","size":59,"stargazers_count":276,"open_issues_count":16,"forks_count":69,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-31T22:10:16.333Z","etag":null,"topics":["c","ecdh","elliptic-curve-diffie-hellman","key-exchange-protocol","public-key-cryptography"],"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":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-04T23:12:49.000Z","updated_at":"2025-05-29T20:30:07.000Z","dependencies_parsed_at":"2022-07-31T23:09:55.457Z","dependency_job_id":null,"html_url":"https://github.com/kokke/tiny-ECDH-c","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kokke/tiny-ECDH-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-ECDH-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-ECDH-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-ECDH-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-ECDH-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kokke","download_url":"https://codeload.github.com/kokke/tiny-ECDH-c/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kokke%2Ftiny-ECDH-c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261982780,"owners_count":23240139,"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":["c","ecdh","elliptic-curve-diffie-hellman","key-exchange-protocol","public-key-cryptography"],"created_at":"2025-05-31T11:14:13.538Z","updated_at":"2025-06-26T01:32:42.654Z","avatar_url":"https://github.com/kokke.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Tiny ECDH / ECC in C\n\nThis is a small and portable implementation of the [Elliptic-Curve Diffie-Hellman key agreement algorithm](https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman) written in C.\n\nDescription from Wikipedia:\n\n\u003e Elliptic-curve Diffie–Hellman (ECDH) is an anonymous key agreement protocol that allows two parties, each having an elliptic-curve public–private key pair, to establish a shared secret over an insecure channel. This shared secret may be directly used as a key, or to derive another key. The key, or the derived key, can then be used to encrypt subsequent communications using a symmetric-key cipher. It is a variant of the Diffie–Hellman protocol using elliptic-curve cryptography.\n`\n\nYou can choose between 10 standard NIST curves of different sizes. 5 pseudo-random curves and 5 Koblitz curves providing from 80 to 256 bits symmetrically equivalent security.  See [ecdh.h](https://github.com/kokke/tiny-ECDH-c/blob/master/ecdh.h) for clarification.\n\nYou can define the macro `ECDH_COFACTOR_VARIANT` in [ecdh.c](https://github.com/kokke/tiny-ECDH-c/blob/master/ecdh.c) to enable the [co-factor variant of ECDH](https://crypto.stackexchange.com/questions/18222/difference-between-ecdh-with-cofactor-key-and-ecdh-without-cofactor-key) for safe non-ephemeral use.\n\n\nThe API is very simple and looks like this (I am using C99 `\u003cstdint.h\u003e`-style annotated types):\n\n```C\n/* NOTE: assumes private is filled with random data before calling */\nint ecdh_generate_keys(uint8_t* public, uint8_t* private);\n\n/* input: own private key + other party's public key, output: shared secret */\nint ecdh_shared_secret(const uint8_t* private, const uint8_t* others_pub, uint8_t* output);\n```\n\nYou need to provide random data for the private key yourself, for the key generation process.\nSee [ecdh_example.c](https://github.com/kokke/tiny-ECDH-c/blob/master/ecdh_example.c) for an example of how to use the library.\n\nThere is no built-in protection from out-of-bounds memory access errors as a result of malicious input. The two functions ecdh_shared_secret() and ecdh_generate_keys() expect inputs of a certain length. See [ecdh.h](https://github.com/kokke/tiny-ECDH-c/blob/master/ecdh.h) for clarification.\n\n\nThe module allocates no RAM internally and takes up 2.1K ROM when compiled for ARM (1.4K for Thumb but YMMV).\nA keypair requires between 72 and 216 bytes of RAM depending on which curve you choose (i.e. how big the underlying base field is).\n\n\nIt is the smallest implementation of ECC in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). \n\n\n```C\n$ arm-none-eabi-gcc -Os -c ecdh.c -mthumb\n$ size ecdh.o\n   text    data     bss     dec     hex filename\n   1413       0       0    1413     585 ecdh.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\nAll material in this repository is in the public domain.\n\n\n### TODO:\n\n- Implement ECDSA signing and verifification.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokke%2Ftiny-ecdh-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkokke%2Ftiny-ecdh-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkokke%2Ftiny-ecdh-c/lists"}