Skip to content

Instantly share code, notes, and snippets.

@blackle
Created September 7, 2021 20:02
Show Gist options
  • Save blackle/a94e4a50803261c6dee6de3a20928e39 to your computer and use it in GitHub Desktop.
Save blackle/a94e4a50803261c6dee6de3a20928e39 to your computer and use it in GitHub Desktop.
I was thinking of what it would take to have a function like:
decrypt_if_input_valid(encrypted_data, input)
this function checks if the input satisfies some criteria, and if it does it will decrypt the data.
suppose our input is a list of numbers, and our criteria is "each number has to be at most 2 away from the number 378." writing this is fairly straightforward
however, if we want to distribute this function, it is trivial for someone to decompile it and see what it's checking for. is it possible to use cryptography to hide our validation criteria so we can run our code on insecure systems?
my thought is, we could hash the entire input and use this as the encryption key. but because our validation criteria is "loose", we need to account for every slightly different input that is still valid. if we enumerated over every valid input and computed it's hash value, and allowed for that value to decrypt our data as well, then this could be a solution
unfortunately this solution requires iterating over combinatorically many "valid" solutions, and including encrypted keys for each alongside the cyphertext.
@chucnorrisful
Copy link

Here are my thoughts in no particular order:

  1. it would propably leak part of the validation code by giving the number of possible correct answers to a problem
  2. the part of a loose criteria seems unintuitive to me: if there exist many possible solutions, it will be more easy to brute-force, and if the choosen validation program is relatively strict, why not make it a little bit more strict by having only one possible solution? [anyways you propably have a reason for that]
  3. your initial idea of encrypting data with a masterkey, and encrypting the masterkey multiple times for each correct solution doesn't look too bad in terms of runtime, if the number of possible answers is not in the millions (that would be weak in terms of securtiy anyhow), problem 1) remains though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment