-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encryption is not secure #17
Comments
Ciao @rspencer01 thank you so much for dedicating some time to hack this :) I see you assumptions implies:
How much harder would be without starting from those assumptions to get back the plaintext? Thank you so much for your support. |
I've also looked at the code here and it has a few rather concerning flaws... The whole salt and IV thing doesn't really make any sense (neither are what they say on the box, you could have called them The largest issue is the issue outlined by rspencer01. I say issue lightly here, it is a full break of the algorithm, really. I feel that it is misleading to potential viewers of this repository to not alert them to the fact that the code within doesn't actually provide any security. I second the idea of a banner. |
Ciao @rspencer01 @luke-park I am sincerely thankful to you for taking time to study the algorithm and even write some code to demonstrate its vulnerability. I had a real life issue in the last 2 hours, so I was not able to commit changes, I will for sure add the suggested statement in the README and relate it to this issue. This repository and its codebase are obviously in experimental state and its procedure for sure not in its definitive state, it is just an experiment. @rspencer01 I am also eager to finally run your gist and test on longer keys. Thank you again for sharing your experience. I am sure who is following Cape's development will be as happy as me to play with your example. @luke-park I am sorry, the 00000 string encryption flaw was already described in the reddit, but I have practically tested this afternoon using different keys and both hash and encrypt function but I am not able to get the key as you describe. Quoting myself on reddit:
@luke-park what you mean with
|
@gioblu The problem with encrypting a zero byte string is that this results in a direct correlation between known variables. srk = salt ^ reduced_key
// For encrypt/decrypt; 0 <= i < message length
key[(srk ^ i) % _key_length] = destination[i] ^ source[i] ^ iv ^ i;
// For hash; 0 <= i < message length
key[(srk ^ i) % _key_length] = destination[i] ^ source[i] ^ srk ^ i; This means that there is a fairly straightforward way to calculate the key if the source (or any properties of the source) are known. Brute forcing the unknowns allows a very quick calculation of all valid keys for a message.
Sure, the following prints that ciphertext: #include <iostream>
#include <string>
#include "Cape.h"
int main() {
char key[] = "e`mnijkd????kd??"; // Undetermined characters were replaced by ?
char src[] = {0,0,0,0,0,0,0,0,0,0};
char dst[255];
Cape cape(key, std::strlen(key));
cape.hash(src, dst, 10);
std::cout << std::string(dst, 10) << std::endl;
} |
Ciao @silkeh, thank you so much for your support. I have tried out the proposed calculation starting from hash using key 1234567890, plantext 0000000000 and salt 0 : calculated_key[(i ^ cape.salt ^ reduced_key) % 10] =
(destination[i] ^ source[i] ^ cape.salt ^ reduced_key ^ i); Results show effectively the key for plaintext 0000000000 and 1234567890, but thiskeynot and many others does not output the key, it seems an attack related not only to a finite set of plaintext (0000000000, 1111111111, 2222222222) but also a finite set of keys (0000000000, 1234567890, 2345678901) and salt values:
Then starting from the assumption that the plaintext is known to the attacker, I have used brute force to obtain the salt and I have noticed that more than one value of salt (also not the one is in use) outputs the correct key used for that ciphertext and also that the salt only scrambles the key in any case giving good hints about it. So absolutely, too few unkowns, weak algorithm and me not taking into consideration the known plaintext attack. 🥇 Thank you and my compliments again @silkeh and @rspencer01 . I will work on something less vulnerable :) |
Good luck! By the way, watch out for the use of the destination[i] = source[i] ^ iv ^ i ^ _key[(srk ^ i) % _key_length]; Additionally, I think the quality of the C++ code could be improved:
Following the features of a C++ standard (eg: C++11 or C++14) and matching guidelines (eg: http://cginternals.github.io/guidelines/) can help you with this. |
@silkeh I have fixed the sign issue, thank you. |
Sorry to drag this up again, but I missed it at the time because I forgot to watch the repo. @silkeh The reason C++ stdlib types aren't used is because this library is used on Arduino and Arduino programs don't have a version of the stdlib, and frankly some Arduino MCUs don't have enough RAM to support the dynamic allocation used by The @rspencer01 I'm glad you managed to make a proof of this. |
Ciao @Pharap I agree, I wasn't able to break it too, @rspencer01 gave a great contribution 👍 , extremely instructive. I agree with you @Pharap about |
See here: https://www.reddit.com/r/crypto/comments/7rpvur/cape_can_you_break_it/dsyx1w8/
I suggest a banner at the top of the readme explaining that this algorithm is for research and educational purposes only and that it shouldn't be used in production.
The text was updated successfully, but these errors were encountered: