{"id":19442952,"url":"https://github.com/syncom/tinyp256","last_synced_at":"2025-04-25T00:32:13.776Z","repository":{"id":177716556,"uuid":"660028304","full_name":"syncom/tinyp256","owner":"syncom","description":"A minimum implementation of ECDSA-P256 signature verification with tinycrypt","archived":false,"fork":false,"pushed_at":"2024-07-01T04:43:21.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-05T16:07:43.815Z","etag":null,"topics":["curve-p256","ecdsa","ecdsa-signature","openssl","signature-verification"],"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/syncom.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,"dei":null}},"created_at":"2023-06-29T04:56:28.000Z","updated_at":"2024-07-01T04:43:24.000Z","dependencies_parsed_at":"2024-02-06T08:47:00.745Z","dependency_job_id":null,"html_url":"https://github.com/syncom/tinyp256","commit_stats":null,"previous_names":["syncom/tinyp256"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syncom%2Ftinyp256","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syncom%2Ftinyp256/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syncom%2Ftinyp256/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syncom%2Ftinyp256/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syncom","download_url":"https://codeload.github.com/syncom/tinyp256/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223975330,"owners_count":17234736,"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":["curve-p256","ecdsa","ecdsa-signature","openssl","signature-verification"],"created_at":"2024-11-10T15:41:30.828Z","updated_at":"2024-11-10T15:41:31.844Z","avatar_url":"https://github.com/syncom.png","language":"C","readme":"# A minimum implementation of ECDSA-P256 signature verification with tinycrypt\n\nThis is an implementation of ECDSA signature verification with Curve\n[P-256](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-186.pdf),\nbased on a minimum subset of source files from the [TinyCrypt cryptographic\nlibrary](https://github.com/intel/tinycrypt), with nearly no modification (cf.,\n[diffs](./diffs.txt)). It verifies the signature against a 256-bit hash digest\nof the payload message: a natural choice of the hash algorithm is SHA-256, and\nwe will assume it.\n\nThe API contains only one function\n\n```c\n/**\n * @brief Verify an ECDSA-P256 signature on a SHA-256 digest\n * @return returns TINYP256_OK if the signature is valid\n *         returns TINYP256_FAIL if an error occurred or the signature is\n *         invalid\n *\n * @param pubkey IN -- ECDSA-P256 public key. Must point to a 64-byte buffer\n * containing an uncompressed point in affine coordinates (Qx, Qy)\n * @param pubkey_len IN -- Size of public key buffer in bytes. Must be 64.\n * @param digest IN -- The SHA-256 digest of the message to verify. Must point to a 32-byte buffer.\n * @param digest_len IN -- Size of SHA-256 digest buffer in bytes. Must be 32.\n * @param signature IN -- ECDSA-P256 signature value. Must point to a 64-byte buffer\n * containing the raw (r, s) value\n * @param signature_len IN -- Size of sig buffer in bytes. Must be 64.\n *\n */\ntinyp256_t tinyp256_verify(\n    const uint8_t *pubkey, uint16_t pubkey_len,\n    uint8_t *digest, uint16_t digest_len,\n    uint8_t *signature, uint16_t signature_len);\n```\n\n## Interoperate with OpenSSL\n\nTested with \"OpenSSL 3.1.1 30 May 2023\" (Homebrew) on macOS and \"OpenSSL 1.1.1\n11 Sep 2018\" on Ubuntu/Linux.\n\n### Key generation and message signing with OpenSSL\n\n- Generate key pair\n\n  Generate private key `private.pem`\n\n  ```bash\n  openssl ecparam -name prime256v1 -genkey -noout -out private.pem\n  ```\n\n  Get public key `public.pem` from private key\n\n  ```bash\n  openssl ec -in private.pem -pubout -out public.pem\n  ```\n\n- Sign payload message, using SHA-256 as message digest\n\n  Suppose the payload message to sign is `msg.bin`. Get ECDSA-P256-SHA256\n  signature `msg.sig.bin`\n\n  ```bash\n  openssl dgst -sha256 -sign private.pem -out msg.sig.bin msg.bin\n  ```\n\n  Signature can be verified with OpenSSL using command\n\n  ```bash\n  # See \"Verification OK\" upon success, \"Verification Failure\" otherwise\n  openssl dgst -verify public.pem -keyform PEM -sha256 \\\n    -signature msg.sig.bin -binary msg.bin\n  ```\n\n  Sample files `private.pem`, `public.pem`, `msg.bin` and `msg.sig.bin` can be\n  found in [testdata/](./testdata/).\n\n### Signature verification with tinyp256\n\nObtain C-styled bytes arrays pointed to by `pubkey`, `digest` and `signature` as\nfollows.  Feed `tinyp256_verify()` with them for signature verification.\n\n- Public key (`pubkey`)\n\n  ```bash\n  openssl ec -pubin -in public.pem -outform DER  2\u003e/dev/null | xxd -i -s 27\n  ```\n\n- SHA-256 hash digest (`digest`) of message to verify\n\n  ```bash\n  openssl dgst -sha256 -binary msg.bin | xxd -i\n  ```\n\n- Signature (`signature`)\n\n  ```bash\n  openssl asn1parse -in msg.sig.bin -inform DER \\\n    | awk -F':' '{print $4}' \\\n    | awk 'NF \u003e 0' \\\n    | awk '{printf \"%064s\", $0}' \\\n    | tr ' ' 0 \\\n    | xxd -r -p \\\n    | xxd -i\n  ```\n\n  Note that we need to pad the `r`, `s` values in hex with leading zeros so that\n  they are 32-byte long, if needed - that's what `awk '{printf \"%064s\", $0} | tr\n  ' ' 0` is for.\n\nSample byte arrays `pubkey`, `digest` and `signature` can be found in\n[test_tinyp256.c](./test_tinyp256.c). To test, in repository's directory root\n\n```bash\nmake\n./test_tinyp256\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncom%2Ftinyp256","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyncom%2Ftinyp256","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyncom%2Ftinyp256/lists"}