{"id":15047636,"url":"https://github.com/justasmasiulis/xorstr","last_synced_at":"2025-04-09T04:06:54.482Z","repository":{"id":41530676,"uuid":"123487831","full_name":"JustasMasiulis/xorstr","owner":"JustasMasiulis","description":"heavily vectorized c++17 compile time string encryption.","archived":false,"fork":false,"pushed_at":"2021-11-19T16:59:01.000Z","size":74,"stargazers_count":1288,"open_issues_count":4,"forks_count":198,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-09T04:06:36.271Z","etag":null,"topics":["compile-time","cpp","cpp17","encryption","string","template","vectorized","xor"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JustasMasiulis.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":"2018-03-01T20:20:01.000Z","updated_at":"2025-04-06T11:59:55.000Z","dependencies_parsed_at":"2022-07-22T08:53:08.324Z","dependency_job_id":null,"html_url":"https://github.com/JustasMasiulis/xorstr","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/JustasMasiulis%2Fxorstr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustasMasiulis%2Fxorstr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustasMasiulis%2Fxorstr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustasMasiulis%2Fxorstr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JustasMasiulis","download_url":"https://codeload.github.com/JustasMasiulis/xorstr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974732,"owners_count":21026742,"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":["compile-time","cpp","cpp17","encryption","string","template","vectorized","xor"],"created_at":"2024-09-24T21:01:57.236Z","updated_at":"2025-04-09T04:06:54.452Z","avatar_url":"https://github.com/JustasMasiulis.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## xorstr\nA heavily vectorized c++17 compile time string encryption.\n\n# quick example\n```cpp\nint main() {\n    std::puts(xorstr_(\"an extra long hello_world\"));\n}\n```\n\n# API\n```cpp\n// This macro creates an encrypted xor_string string instance.\n#define xorstr(string) xor_string\u003c...\u003e{string}\n\n// For convenience sake there is also a macro to instantly decrypt the string\n#define xorstr_(string) xorstr(string).crypt_get()\n\nstruct xor_string\u003cCharType, ...\u003e {\n    using size_type     = std::size_t;\n    using value_type    = CharT;\n    using pointer       = value_type*;\n    using const_pointer = const value_type*;\n    \n    // Returns string size in characters, not including null terminator.\n    constexpr size_type size() const;\n    \n    // Runs the encryption/decryption algorithm on the internal storage.\n    void crypt() noexcept;\n    \n    // Returns const pointer to the storage, without doing any modifications to it.\n    const_pointer get() const;\n    \n    // Returns non const pointer to the storage, without doing any modifications to it.\n    pointer get();\n\n    // Runs crypt() and returns the pointer to the internal storage.\n    pointer crypt_get();\n}\n```\n\n# noteworthy things\n* All keys are 64bit and generated during compile time.\n* Data blocks go in increments of 16 bytes so some space may be wasted.\n* The code has been crafted so that all the data would be embedded directly into code and not stored on .rdata and such.\n* The entirety of string encryption and decryption will be inlined.\n\n# supported compilers and platforms\nTested to be working on clang 5.0+, gcc 7.1+ and MSVC v141.\nIf your CPU does not support AVX define JM_XORSTR_DISABLE_AVX_INTRINSICS to only use SSE.\n\n# example assembly output\nOutput of gcc (trunk) from the quick example\n```asm\nmain:\n  movabs rax, -4762152789334367252\n  push rbp\n  mov rbp, rsp\n  and rsp, -32\n  sub rsp, 64\n  mov QWORD PTR [rsp], rax\n  mov rdi, rsp\n  movabs rax, -6534519754492314190\n  mov QWORD PTR [rsp+8], rax\n  movabs rax, -2862143164529545214\n  mov QWORD PTR [rsp+16], rax\n  movabs rax, -4140208776682645948\n  mov QWORD PTR [rsp+24], rax\n  vmovdqa ymm1, YMMWORD PTR [rsp]\n  movabs rax, -2550414817236710003\n  mov QWORD PTR [rsp+32], rax\n  movabs rax, -4595755740016602734\n  mov QWORD PTR [rsp+40], rax\n  movabs rax, -5461194525092864914\n  mov QWORD PTR [rsp+48], rax\n  movabs rax, -4140208776682645984\n  mov QWORD PTR [rsp+56], rax\n  vpxor ymm0, ymm1, YMMWORD PTR [rsp+32]\n  vmovdqa YMMWORD PTR [rsp], ymm0\n  vzeroupper\n  call puts\n  xor eax, eax\n  leave\n  ret\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustasmasiulis%2Fxorstr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustasmasiulis%2Fxorstr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustasmasiulis%2Fxorstr/lists"}