{"id":33933029,"url":"https://github.com/enquo/cretrit","last_synced_at":"2026-04-05T01:31:33.776Z","repository":{"id":62445066,"uuid":"542834485","full_name":"enquo/cretrit","owner":"enquo","description":"Comparison-Revealing Encryption primitives","archived":false,"fork":false,"pushed_at":"2024-04-28T23:06:41.000Z","size":101,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-13T23:41:26.322Z","etag":null,"topics":["cryptography","encryption","enquo","hacktoberfest","order-revealing-encryption","ore","rust","security"],"latest_commit_sha":null,"homepage":"https://enquo.org","language":"Rust","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/enquo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-09-28T23:36:21.000Z","updated_at":"2024-11-01T08:05:54.000Z","dependencies_parsed_at":"2024-04-28T01:27:55.835Z","dependency_job_id":null,"html_url":"https://github.com/enquo/cretrit","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"07bb5c62cac701a32addb9466106bde58b494e88"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/enquo/cretrit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquo%2Fcretrit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquo%2Fcretrit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquo%2Fcretrit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquo%2Fcretrit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enquo","download_url":"https://codeload.github.com/enquo/cretrit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enquo%2Fcretrit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31421869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T00:25:07.052Z","status":"ssl_error","status_checked_at":"2026-04-05T00:25:05.923Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","encryption","enquo","hacktoberfest","order-revealing-encryption","ore","rust","security"],"created_at":"2025-12-12T13:01:38.029Z","updated_at":"2026-04-05T01:31:33.766Z","avatar_url":"https://github.com/enquo.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is `cretrit` (pronounced \"cre-TRIT\"), a Rust library for performing comparison-revealing cryptographic operations (encryption, comparison) on arbitrary data.\nIt implements the two-value and three-value encrypted comparison algorithms described in the paper [Order-Revealing Encryption: New Constructions, Applications, and Lower Bounds](https://eprint.iacr.org/2016/612.pdf) by Kevin Lewi and David J. Wu, of Stanford University.\n\nWhat this library allows you to do is to take plaintext values, encrypt them, and then perform comparison operations on the encrypted forms that produce results identical to the equivalent comparison operations on the plaintexts.\nThis is typically useful for performing ordering (where the comparison is \"is this value less-than, equal-to, or greater-than that value?\") and equality (\"is this value equal-to or not-equal-to that value?\").\nHowever the library is designed to accommodate other comparison operators, in case the need arises.\nTo provide implementation examples, and satisfy common use cases, generic ordering and equality ciphertext types are also provided.\n\nIf the ideas in this library intrigue you, but the idea of fiddling around with these low-level primitives sounds a bit tedious, you may wish to check out the rest of [the Enquo Project](https://enquo.org).\nThe Enquo Project exists to provide encrypted, queryable datastores for everyone, which uses comparison-revealing cryptography extensively.\n\n\n# Security Status\n\nThis library has NOT been audited by any competent third party for implementation flaws.\nIf you would like to undertake, or sponsor, such an audit, please get in touch.\n\nIf you believe you have found a security flaw in this library, an e-mail to `security@enquo.org` would be appreciated.\n\n\n\n\n\n# Usage\n\nTo use the existing ordering and equality types, you just have to select a *cipher suite*, and then `use` the module in that cipher suite that corresponds to the operation you wish to perform.\nAt present, only one cipher suite is available, named `aes128v1`, and there are `ore` (order-revealing encryption) and `ere` (equality-revealing encryption) modules.\n\nFrom there, you instantiate a `Cipher` whose generic parameters represent the number of blocks (`N`) and the \"width\" of each block (the number of values representable by each block, `W`), giving it a key to use for encryption.\nFor example:\n\n```rust\n// Let's do some order-revealing encryption!\nuse cretrit::aes128v1::ore;\n# use rand::{Rng, SeedableRng};\n# use rand_chacha::ChaCha20Rng;\n\n# fn main() -\u003e Result\u003c(), cretrit::Error\u003e {\n// Always use cryptographically-secure random keys!\nlet key = ChaCha20Rng::from_entropy().gen::\u003c[u8; 32]\u003e();\n\n// This cipher has four blocks, the value of each is in the range\n// 0-255.  Hence, this cipher can represent the ordering of values\n// between 0 and 256^4-1 (aka 2**32-1), which corresponds to a 32-bit\n// unsigned integer.\nlet cipher = ore::Cipher::\u003c4, 256\u003e::new(\u0026key)?;\n# Ok(())\n# }\n```\n\nThis cipher is how you encrypt plaintexts.\nInternally, plaintexts are an array of the value of each block, and you can use that representation if you like.\nFor encrypting unsigned integers, there are implementations of the `TryFrom` trait that allow you to pass the integers in directly, like this:\n\n```rust\n# use cretrit::aes128v1::ore;\n# fn main() -\u003e Result\u003c(), cretrit::Error\u003e {\n# let cipher = ore::Cipher::\u003c4, 256\u003e::new(\u0026[0u8; 32])?;\nlet forty_two: u32 = 42;\nlet ore_forty_two = cipher.full_encrypt(\u0026forty_two.try_into()?)?;\nlet over_nine_thousand: u32 = 9001;\nlet ore_over_nine_thousand = cipher.full_encrypt(\u0026over_nine_thousand.try_into()?)?;\n# Ok(())\n# }\n```\n\nIf the value you're trying to turn into a plaintext can't be represented by the plaintext type you're using, a `cretrit::Error::RangeError` will be returned.\n\nCiphertexts for the order-revealing and equality-revealing encryption schemes implement `Ord`, `Eq`, and the `Partial*` variants as appropriate.\nThus, you can just compare the outputs of the `encrypt` function like they were any other value:\n\n```rust\n# use cretrit::aes128v1::ore;\n# fn main() -\u003e Result\u003c(), cretrit::Error\u003e {\n# let cipher = ore::Cipher::\u003c4, 256\u003e::new(\u0026[0u8; 32])?;\n# let ore_forty_two = cipher.full_encrypt(\u002642u32.try_into()?)?;\n# let ore_over_nine_thousand = cipher.full_encrypt(\u00269001u32.try_into()?)?;\nassert!(ore_forty_two != ore_over_nine_thousand);\nassert!(ore_forty_two \u003c ore_over_nine_thousand);\n# Ok(())\n# }\n```\n\nYou can also serialise and deserialise ciphertexts to/from `u8` vectors, which allows you to store them in files, databases, etc.\nA simple example of round-tripping a ciphertext:\n\n```rust\n// Pull in the necessary trait\nuse cretrit::SerializableCipherText;\n\n# use cretrit::aes128v1::ore;\n# fn main() -\u003e Result\u003c(), cretrit::Error\u003e {\n# let cipher = ore::Cipher::\u003c4, 256\u003e::new(\u0026[0u8; 32])?;\n# let ore_forty_two = cipher.full_encrypt(\u002642u32.try_into()?)?;\n# let ore_over_nine_thousand = cipher.full_encrypt(\u00269001u32.try_into()?)?;\nlet v = ore_forty_two.to_vec()?;\n\n// When deserialising a ciphertext, you need to specify the cipher parameters\n// so that the types line up.\nlet new_forty_two = ore::CipherText::\u003c4, 256\u003e::from_slice(\u0026v)?;\n\n// Once it's deserialised, it's back to its original form and ready to\n// go!\nassert!(new_forty_two == ore_forty_two);\nassert!(new_forty_two != ore_over_nine_thousand);\nassert!(new_forty_two \u003c ore_over_nine_thousand);\n# Ok(())\n# }\n```\n\n\n# Terminology\n\nTo help make sense of everything, here's some of the terms that we use in the codebase and documentation.\n\n* **Comparison-Revealing Encryption**: a generic encryption scheme which produces ciphertexts which can be compared against one another to determine a defined relationship between the plaintexts from which the ciphertexts were produced.\n  Ideally, the ciphertexts do not reveal any other information about the two plaintexts or their relationship to each other.\n\n* **Order-Revealing Encryption**: a form of comparison-revealing encryption, which produces ciphertexts which reveal the relative ordering of ciphertexts, without giving any indication of the actual value of the underlying plaintexts.\n  This is done by revealing whether a ciphertext is less-than, equal-to, or greater-than any other ciphertext, which is all that is necessary to order any collection of ciphertexts.\n\n* **Equality-Revealing Encryption**: a form or comparison-revealing encryption, which produces ciphertexts which reveal whether the plaintext value behind two ciphertexts are equal, or not.\n  While order-revealing encryption can also be used to reveal equality, this form is useful when there is no well-defined ordering of a set of values, or you specifically do not which to reveal that ordering.\n  The ciphertexts produced by equality-revealing encryption are also smaller than those produced by order-revealing encryption.\n\n* **Cipher Suite**: a collection of cryptographic primitives which, in combination, are needed to perform the complete set of comparison-revealing encryption operations.\n  Multiple cipher suites may be defined to upgrade security, or provide increased performance.\n\n* **Cipher**: a combination of a cipher suite and comparison operator which, together, provide the ability to encrypt a plaintext into a particular comparison-revealing form.\n\n* **Plaintext Block**: to keep ciphertext sizes under control, the Lewi-Wu scheme breaks a single large plaintext into smaller blocks.\n  Each block can represent values of a certain range, and a single plaintext has a certain number of blocks.\n  These parameters control the size and leakage of the corresponding ciphertext.\n\n\n# Contributing\n\nFor general guidelines for contributions, see [CONTRIBUTING.md](CONTRIBUTING.md).\n\n\n# Licence\n\nUnless otherwise stated, everything in this repo is covered by the following\nlicence statement (the MIT licence):\n\n```text\n    Copyright (C) 2022  Matt Palmer \u003cmatt@enquo.org\u003e\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenquo%2Fcretrit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenquo%2Fcretrit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenquo%2Fcretrit/lists"}