{"id":16876901,"url":"https://github.com/nsubiron/crypto","last_synced_at":"2025-03-20T04:48:21.391Z","repository":{"id":69753770,"uuid":"107863744","full_name":"nsubiron/crypto","owner":"nsubiron","description":"Few handy wrappers around OpenSSL's libcrypto.","archived":false,"fork":false,"pushed_at":"2017-11-03T10:37:05.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T06:41:14.642Z","etag":null,"topics":["crypto","crypto-library","cryptography","cryptography-library","openssl","password-digest","random-number-generators","secure-string"],"latest_commit_sha":null,"homepage":null,"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/nsubiron.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":"2017-10-22T12:26:48.000Z","updated_at":"2017-11-03T10:42:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcc536d4-7d0f-435f-8c44-8071adeb6964","html_url":"https://github.com/nsubiron/crypto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsubiron%2Fcrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsubiron%2Fcrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsubiron%2Fcrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsubiron%2Fcrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsubiron","download_url":"https://codeload.github.com/nsubiron/crypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554135,"owners_count":20471173,"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":["crypto","crypto-library","cryptography","cryptography-library","openssl","password-digest","random-number-generators","secure-string"],"created_at":"2024-10-13T15:40:51.920Z","updated_at":"2025-03-20T04:48:21.362Z","avatar_url":"https://github.com/nsubiron.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"crypto\n======\n\nFew handy wrappers around [OpenSSL](https://www.openssl.org/)'s libcrypto.\n\nIncludes\n\n  * Simple secure string\n  * Password digest class\n  * Random number generator adaptor\n\nBuild\n-----\n\nBuild with cmake. For default cmake configuration use the provided Makefile.\nRequires C++14 or later.\n\nUnit tests\n----------\n\nThe unit tests require [Google Test](https://github.com/google/googletest), the\nsetup script downloads and compiles GTest to use with the provided Makefile\n\n    $ ./Setup.sh\n    $ make check\n\nUsage\n-----\n\nAll the include files are installed under `$installdir/includes`. Static\nlibraries are installed under `$installdir/includes`. Link against\n`wcrypto` (`wcryptod` for debug) and OpenSSL's crypto. E.g.\n\n    $ clang++ -I$installdir/include -L$installdir/lib ... -lwcrypto -lcrypto\n\n#### Secure string\n\nA super basic secure string. Its contents are zeroized on destruction. It is\nimplemented from scratch to avoid small string optimizations, therefore most of\nthe functionality of std::string is lost. It just provides basic functionality\nto move the string around and append two strings.\n\nIt cannot be constructed directly, but through its static methods\n`clean_buffer_and_make` and `unsafe_make`. This is meant to avoid unsafe usage\nof the string go unnoticed.\n\n```cpp\n#include \"crypto/secure_string.h\"\n\n#include \u003cunistd.h\u003e\n\nint main() {\n  using namespace crypto;\n\n  char *buffer = getpass(\"Password: \");\n  auto str0 = secure_string::clean_buffer_and_make(buffer);\n\n  auto str1 = secure_string::unsafe_make(\" with some not so secret text\");\n\n  auto str = str0 + str1;\n}\n```\n\n#### Password digest\n\nA password digest object to store digested passwords. Allows comparison with\nother password digests and clear passwords.\n\nThis object can be copied around without copying the holding data. A single\nconst copy of the data is shared among all the copies of the password_digest\nusing shared_ptr.\n\n```cpp\n#include \"crypto/password_digest.h\"\n\n#include \u003ciostream\u003e\n#include \u003cunistd.h\u003e\n\nint main() {\n  using namespace crypto;\n\n  char *unsafe_buffer = getpass(\"Password: \");\n  auto password = secure_string::clean_buffer_and_make(unsafe_buffer);\n\n  auto digest = password_digest\u003csha256_digest\u003e(password);\n\n  unsafe_buffer = getpass(\"Confirm password: \");\n  auto confirm_password = secure_string::clean_buffer_and_make(unsafe_buffer);\n\n  if (digest != confirm_password)\n    std::cerr \u003c\u003c \"Passwords do not match!\" \u003c\u003c std::endl;\n}\n```\n\n#### Random engine adaptor\n\nThe `random_engine_adaptor` implements most of the standard random utilities as\nmember functions of the random engine. Two default random engines are provided\n(`crypto::default_random_engine` and `crypto::mt19937`) based on\n[_randutils.hpp_](https://gist.github.com/imneme/540829265469e673d045). When\ndefault constructed, these two are seeded with a random seed.\n\n```cpp\n#include \"crypto/random.h\"\n\n#include \u003ciostream\u003e\n#include \u003cvector\u003e\n\nint main() {\n  crypto::mt19937 rng0;\n\n  std::cout \u003c\u003c rng0.uniform\u003cdouble\u003e()     \u003c\u003c '\\n'\n            \u003c\u003c rng0.uniform\u003cint\u003e(-10, 10) \u003c\u003c '\\n'\n            \u003c\u003c rng0.bernoulli(0.6)        \u003c\u003c '\\n';\n\n  std::seed_seq seed{1, 2, 3, 4, 5, 6, 7, 8, 9};\n  crypto::default_random_engine rng1(seed);\n\n  std::vector\u003cint\u003e v{1, 2, 3, 4, 5};\n  rng1.shuffle(v);\n\n  // Using directly with std random engines.\n  crypto::random_engine_adaptor\u003cstd::minstd_rand\u003e rng2;\n\n  std::cout \u003c\u003c rng2.choice(v) \u003c\u003c '\\n';\n}\n```\n\nLicense\n-------\n\n_crypto_ is distributed under MIT License.\n\n[_randutils.h_](https://gist.github.com/imneme/540829265469e673d045) Copyright\n(c) 2015 Melissa E. O'Neill, distributed under MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsubiron%2Fcrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsubiron%2Fcrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsubiron%2Fcrypto/lists"}