-
Notifications
You must be signed in to change notification settings - Fork 75
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
Lockbox to replace existing aes_cbc:encrypt(payload) & aes_cbc:decrypt(payload) #35
Comments
Hi @nodecentral, At a glance your usage looks correct, but I think you may have a small error in your test code, it looks like
Otherwise your for loop will be iterating over the test fixture properties (cipher, decipher, key, etc...) |
Many thanks @somesocks Starting with encryption, If I was wrap this into a function, and call it with the 3 elements I have?
What exactly am I looking to return to get the ciphertext I need ? Then when it come to doing any decryption, what do I need to change/do differently ? (Sorry if these are basic questions) |
To build a working block cipher you need to know 6 things:
So, you're missing a few things in your function definition:
You have the block cipher (AES 128) and the mode (CBC), but you're missing the padding algorithm, the input format for the key/iv/plaintext, and the output format. If I assume you're using zero padding, and passing all the inputs and outputs as hex strings, then I'd probably write it like this:
You could also skip the function, and drop it in as a one-liner:
For deciphering, you need all the same parameters:
So, the decryption function would be something like:
|
Wow, thanks so much ! This is great stuff :-) My challenge now is put it into action with my TV, as found a Lua script online to help pair my Pi device with it (to then act as a remote control).
Any advise you can give on the above to help me get the required values in the necessary format, would be greatly appreciated.. |
I took a look through the forum post you linked and, and it seems like there's a lot of confusion in general about how this auth exchange actually works. I think this code from this github thread comment is a good starting point: florianholzapfel/panasonic-viera#9 (comment) Running through that code:
^ this is not an initialization vector, this is the encryption key. They're using the wrong term here, which adds a lot of confusion.
^ you don't "derive" a key from an initialization vector. There should never be any relationship between an IV and an encryption key, they should be two independent random numbers. And, to me, this doesn't look like a key derivation either, this looks much more like an endian conversion, converting bytes from network-order to machine-order (Though you don't use a
^ the HMAC key initialization seems fine, as far as I can tell
^ THIS is the IV. Those bytes should be randomized for every message sent, and in general, it very much matters that the IV is generated and used correctly. A null IV weakens the security of a CBC cipher, see https://en.wikipedia.org/wiki/Initialization_vector for more info
^ |
Thanks again @somesocks , i’m not sure I’ve been able to follow everything you’ve said, but it’s so good to have another pair of eyes look at this. Unfortunately I’m only familiar with Lua, so the language used for that other script, is not as easy to follow, but if I’ve understood you correctly, the And when it comes to the If you’ll indulge me, here’s a side by side with the code you linked to earlier showing what I’ve done so far, and I’m still grateful for any help.
Which then leads us into what we do with your code and the AES-CBC encryption…. |
Here's how I'd try to complete your code. I haven't tested it at all, so there may be some bugs in here:
|
@nodecentral I'm closing this issue due to inactivity, but if you did get it to work, it'd be great if you could post the code here for others to see |
Hi
I’ve finally found some time to focus on this, with the goal to use lockbox to replace some Lua functions/libraries I don’t have access to.
The commands are as follows.
Encrypt
Decrypt
I’m still learning Lua so this is a bit of a stretch to me, but looking at the test, would the encrypt be something like the following?.
The text was updated successfully, but these errors were encountered: