{"id":13617742,"url":"https://github.com/conduition/secp","last_synced_at":"2025-04-22T22:41:24.264Z","repository":{"id":203664462,"uuid":"710116971","full_name":"conduition/secp","owner":"conduition","description":"Flexible secp256k1 curve math library. ","archived":false,"fork":false,"pushed_at":"2025-02-02T03:21:44.000Z","size":73,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T19:34:31.914Z","etag":null,"topics":["cryptography","digital-signature","elliptic-curve-cryptography","secp256k1"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/conduition.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,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T03:50:44.000Z","updated_at":"2025-03-29T13:28:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"f04b7ed8-7f3e-4dc5-bb61-49e1bcfb3080","html_url":"https://github.com/conduition/secp","commit_stats":null,"previous_names":["conduition/secp"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fsecp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fsecp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fsecp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fsecp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conduition","download_url":"https://codeload.github.com/conduition/secp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337276,"owners_count":21414092,"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":["cryptography","digital-signature","elliptic-curve-cryptography","secp256k1"],"created_at":"2024-08-01T20:01:47.207Z","updated_at":"2025-04-22T22:41:24.249Z","avatar_url":"https://github.com/conduition.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# `secp`\n\nA flexible and secure secp256k1 elliptic curve math library, with constant-time support, and superb ergonomics.\n\n`secp` takes full advantage of Rust's `std::ops` traits to make elliptic curve cryptography code easy to read, easy to write, succinct, readable, and secure.\n\n## Example\n\nHere's an implementation of simple Schnorr signatures using the `secp` crate.\n\n```rust\nuse secp::{MaybeScalar, Point, Scalar};\nuse sha2::{Digest, Sha256};\n\nfn compute_challenge(nonce_point: \u0026Point, pubkey: \u0026Point, msg: \u0026[u8]) -\u003e MaybeScalar {\n    let hash: [u8; 32] = Sha256::new()\n        .chain_update(\u0026nonce_point.serialize())\n        .chain_update(\u0026pubkey.serialize())\n        .chain_update(msg)\n        .finalize()\n        .into();\n    MaybeScalar::reduce_from(\u0026hash)\n}\n\nfn random_scalar() -\u003e Scalar {\n    // In an actual implementation this would produce a scalar value\n    // sampled from a CSPRNG.\n    Scalar::two()\n}\n\nfn schnorr_sign(secret_key: Scalar, message: \u0026[u8]) -\u003e (Point, MaybeScalar) {\n    let nonce = random_scalar();\n    let nonce_point = nonce.base_point_mul();\n    let pubkey = secret_key.base_point_mul();\n\n    let e = compute_challenge(\u0026nonce_point, \u0026pubkey, message);\n    let s = nonce + secret_key * e;\n    (nonce_point, s)\n}\n\nfn schnorr_verify(public_key: Point, signature: (Point, MaybeScalar), message: \u0026[u8]) -\u003e bool {\n    let (r, s) = signature;\n    let e = compute_challenge(\u0026r, \u0026public_key, message);\n    s.base_point_mul() == r + e * public_key\n}\n\nlet secret_key: Scalar = \"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\"\n    .parse()\n    .unwrap();\nlet public_key = secret_key.base_point_mul();\n\nlet message = b\"I am the dragon!\";\n\nlet signature = schnorr_sign(secret_key, message);\nassert!(schnorr_verify(public_key, signature, message));\n```\n\n## Choice of Backbone\n\nThis crate does not implement elliptic curve point math directly. Instead we depend on one of two reputable elliptic curve cryptography libraries:\n\n- C bindings to [`libsecp256k1`](https://github.com/bitcoin-core/secp256k1), via [the `secp256k1` crate](https://crates.io/crates/secp256k1), maintained by the Bitcoin Core team.\n- A pure-rust implementation via [the `k256` crate](https://crates.io/crates/k256), maintained by the [RustCrypto](https://github.com/RustCrypto) team.\n\n**One or the other can be used.** By default, this crate prefers to rely on `libsecp256k1`, as this is the most vetted and publicly trusted implementation of secp256k1 curve math available anywhere. However, if you need a pure-rust implementation, you can install this crate without it, and use the pure-rust `k256` crate instead.\n\n```notrust\ncargo add secp --no-default-features --features k256\n```\n\nIf both `k256` and `secp256k1` features are enabled, then we default to using `libsecp256k1` bindings for the actual math, but still provide trait implementations to make this crate interoperable with `k256`.\n\n## Documentation\n\nTo see the API documentation, [head on over to docs.rs](https://docs.rs/secp).\n\n## CLI\n\nThis crate also offers a CLI tool for computing secp256k1 curve operations in your shell. Build it with `make cli`. A binary will be built at `target/release/secp`.\n\n```not_rust\nUsage:\n\n-- Scalar operations --\n  secp scalar gen                           Generate a random scalar.\n  secp scalar add \u003cscalar\u003e [\u003cscalar\u003e...]    Sum two or more scalars.\n  secp scalar mul \u003cscalar\u003e [\u003cscalar\u003e...]    Multiply two or more scalars.\n  secp scalar inv \u003cscalar\u003e                  Multiplicative inverse of a scalar mod n.\n\n-- Point operations --\n  secp scalar gen                           Generate a random point.\n  secp point add \u003cpoint\u003e [\u003cpoint\u003e...]       Sum two or more points.\n  secp point mul \u003cpoint\u003e [\u003cscalar\u003e...]      Multiply a point by one or more scalars.\n\n-- Formats --\n\nPoints are represented in 65-byte compressed hex format. Example:\n\n  02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n\nScalars are represented in 32-byte hex format. Example:\n\n  e8c23ee3c98e040adea5dc92c5c381d6be93615f289ec2d505909657368a0c8f\n\nPrepending a minus sign '-' in front of a point or scalar will negate it. Example:\n\n  -02eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n\n-- Special values --\n\n- The values '0', '1', or '-1' may be substituted for any scalar.\n- The value 'G' may be substituted for any point to represent the secp256k1 base point.\n- The value '0' may be substituted for any point to represent the additive identity point (infinity).\n```\n\nExample usage:\n\n```console\ns1=`secp scalar gen`\ns2=`secp scalar gen`\np1=`secp point mul G $s1`\np2=`secp point mul G $s2`\np3=`secp point add $p1 $p2`\np4=`secp point add $p1 -$p2`\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fsecp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconduition%2Fsecp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fsecp/lists"}