The title just about says it.
The idea here is that I could disable encryption by choosing an appropriate key instead of disabling the encryption in the code.
No, XTEA does not have weak keys where the encryption or decryption functions separately behave like the identity functions. (Or at least such a class of keys is not known.)
No, no matter what key you use (even the key 0x00000000 + 0x00000000 + 0x00000000 + 0x00000000 ), xtea will encrypt the data.
BUT, if you don't want the encryption, just set rounds to 0, and your data won't be encrypted, which i guess is what you want :) only padding will be applied in that case. (when rounds is 0, it does not matter what your encryption key is, by the way. no encryption key will make any difference.)
Related
I am creating a program that is going to encrypt files in a folder and allow me to decrypt them later on.
I am using AES-GCM at the moment and I am wondering if using the same key but changing the IV for every encryption is the correct way to do this?
I am using mBedTLS to do this and I am able to successfully encrypt/decrypt a file using AES-GCM and hard coded key and IV. However for security reasons I want to make sure that I am changing what needs to be changed and for performance reasons, not changing something that doesn't need to be.
Yup,
Even a single AES-GCM nonce reuse can be catastrophic, with the same static key.
A single nonce reuse leaks the xor of plaintexts, so if one plaintext is known the adversary can completely decrypt the other.
So you can only use the same [nonce (IV), key] tuple once per message.
It's perfectly fine to use a new nonce/IV with the same static key.
AES-GCM operates with a 32-bit counter, so unfortunately with the same key, nonce (IV) pair you can only safely encrypt ~ 64GB of data (2^39-256 bits).
If you want to move to an even safer cipher, I recommend XSalsa20 or XChaCha20, which provide a 192-bit nonce size, effectively allowing a practically "unlimited" number of messages to be encrypted with the same key, nonce pair.
Firstly I'm new to cryptography.
Suppose I encrypt a plain test using AES 128 bit Encryption and passed to the receiver. The key is also passed to the receiver. At the receiver side how can I check the KEY is correct or not without fully decrypting the message.
What I mean is can we check like this
IF(KEY==something)
DECRYPT
ELSE
NOT a correct key.
Is there anything to do with IV?
I really Don't understand what the IV is.
Firstly, passing the ciphertext and key through an insecure channel is, as you can probably determine, insecure. Keeping the ciphertext and key together in the same place is the same as keeping the plaintext, so don't do that.
Rather than determine if a given key is correct for the ciphertext, cryptographic systems instead determine if the ciphertext is legitimate before they even decrypt. The most common way to do this is using a MAC, or Message Authentication Code. HMACs are a common way to do this, as are Authenticated block modes like GCM.
Lastly, an IV is used to ensure that duplicated blocks of plaintext don't result in repeated blocks of ciphertext. E.g. in ECB mode, which doesn't use an IV, each identical block of plaintext will encrypt to the same ciphertext under a given key. Applying an IV (in modes like CBC), will ensure that identical plaintext blocks look different due to a chained XOR operation that starts with the IV.
To solve your problem, either use GCM mode or use a KDF to derive a symmetric key and a key for an HMAC.
I have a tcl/tk based tool, which uses network password for authentication. Issue is that, it is saving password in the logs/history. So objective is to encrypt the password.
I tried to use aes package. But at the very beginning aes::init asks for keydata and initialization vector (16 byte). So how to generate IV and keydata. Is is some Random number? I am a novice in encryption algorithms.
If you have the password in the logs/history, why not fix the bug of logging/storing it in the first place?
Otherwise there are distinct things you might want:
A password hashing scheme like PBKDF2, bcrypt, argon2 etc. to store a password in a safe way and compare some user input to it. This is typically the case when you need to implement some kind of authentication with passwords on the server side.
A password encryption and protection scheme like AES. You need a password to authenticate to some service automatically, and it requires some form of cleartext password.
You have some secret data and need to securly store it to in non cleartext form.
If you have case 1, don't use the aespackage, it is the wrong tool for the job. If you have case 2, the aes package might help you, but you just exchanged the problem of keeping the password secret with the other problem of keeping the key secret (not a huge win). So the only viable case where aes is an option might be 3.
Lets assume you need to store some secret data in a reversible way, e.g. case 3 from above.
AES has a few possible modes of operation, common ones you might see are ECB, CBC, OFB, GCM, CTR. The Tcllib package just supports ECB and CBC, and only CBC (which is the default) is really an option to use.
Visit Wikipedia for an example why you should never use ECB mode.
Now back to your actual question:
Initialization Vector (IV)
This is a random value you pick for each encryption, it is not secret, you can just publish it together with the encrypted data. Picking a random IV helps to make two encrypted blocks differ, even if you use the same key and cleartext.
Secret Key
This is also a random value, but you must keep it secret, as it can be used for encryption and decryption. You often have the same key for multiple encryptions.
Where to get good randomness?
If you are on Linux, BSD or other unixoid systems just read bytes from /dev/urandom or use a wrapper for getrandom(). Do NOT use Tcls expr {rand()} or similar pseudorandom number generators (PRNG). On Windows TWAPI and the CryptGenRandom function would be the best idea, but sadly there is no Tcl high level wrapper included.
Is that enough?
Depends. If you just want to hide a bit of plaintext from cursory looks, maybe. If you have attackers manipulating your data or actively trying to hack your system, less so. Plain AES-CBC has a lot of things you can do wrong, and even experts did wrong (read about SSL/TLS 1.0 problems with AES-CBC).
Final words: If you are a novice in encryption algorithms, be sure you understand what you want and need to protect, there are a lot of pitfalls.
If I read the Tcler's Wiki page on aes, I see that I encrypt by doing this:
package require aes
set plaintext "Some super-secret bytes!"
set key "abcd1234dcba4321"; # 16 bytes
set encrypted [aes::aes -dir encrypt -key $key $plaintext]
and I decrypt by doing:
# Assuming the code above was run...
set decrypted [aes::aes -dir decrypt -key $key $encrypted]
Note that the decrypted text has NUL (zero) bytes added on the end (8 of them in this example) because the encryption algorithm always works on blocks of 16 bytes, and if you're working with non-ASCII text then encoding convertto and encoding convertfrom might be necessary.
You don't need to use aes::init directly unless you are doing large-scale streaming encryption. Your use case doesn't sound like it needs that sort of thing. (The key data is your “secret”, and the initialisation vector is something standardised that usually you don't need to set.)
I have two AES-enrypted tickets (see below) and the plaintexts to it.
Can I find the AES key from this information?
encryption type: AES CBC encryption with PKCS#5 padding
Two encrypted tickets:
CD46F0E2B829FBF75CA5A93D35CAF5FB3FFB997D7ADB606CD7F82DAE0D79859B84EA91D7D6A7F6FAF45C59DF370F1E31BEEF0000BEEF0000BEEF0000BEEF0000
Plaintext-value: 20101010
6B4CF1C63C819AA79437BEBF2189F672A40CB30AF1E8B2C7857A2C458DF8DFD286E898D4D6A7F6FAF66B67DD350D1C33BEEF0000BEEF0000BEEF0000BEEF0000
Plaintext-value: 20101209
The ability to determine the encryption key when one has access to one or more plaintexts and their associated ciphertexts is described as a "known-plaintext attack", to which (according to Wikipedia) AES is not (currently) known to be vulnerable.
No! This is why AES is so strong and widely used. It was designed against this kind of attack.
ASE has not known weaknesses on.
Known plaintext attack (that what you ask for)
Chosen plaintext attack (you can pick messages that you want to encrypt)
Related-key attack (you can arbitrary change key, lets say increase key by 1)
Not without an amazing amount of luck. Part of the purpose of strong cryptography like AES is to make doing what you propose mathematically infeasible.
Right now, this is what I am doing:
1. SHA-1 a password like "pass123", use the first 32 characters of the hexadecimal decoding for the key
2. Encrypt with AES-256 with just whatever the default parameters are
^Is that secure enough?
I need my application to encrypt data with a password, and securely. There are too many different things that come up when I google this and some things that I don't understand about it too. I am asking this as a general question, not any specific coding language (though I'm planning on using this with Java and with iOS).
So now that I am trying to do this more properly, please follow what I have in mind:
Input is a password such as "pass123" and the data is
what I want to encrypt such as "The bank account is 038414838 and the pin is 5931"
Use PBKDF2 to derive a key from the password. Parameters:
1000 iterations
length of 256bits
Salt - this one confuses me because I am not sure where to get the salt from, do I just make one up? As in, all my encryptions would always use the salt "F" for example (since apparently salts are 8bits which is just one character)
Now I take this key, and do I hash it?? Should I use something like SHA-256? Is that secure? And what is HMAC? Should I use that?
Note: Do I need to perform both steps 2 and 3 or is just one or the other okay?
Okay now I have the 256-bit key to do the encryption with. So I perform the encryption using AES, but here's yet another confusing part (the parameters).
I'm not really sure what are the different "modes" to use, apparently there's like CBC and EBC and a bunch of others
I also am not sure about the "Initialization Vector," do I just make one up and always use that one?
And then what about other options, what is PKCS7Padding?
For your initial points:
Using hexadecimals clearly splits the key size in half. Basically, you are using AES-128 security wise. Not that that is bad, but you might also go for AES-128 and use 16 bytes.
SHA-1 is relatively safe for key derivation, but it shouldn't be used directly because of the existence/creation of rainbow tables. For this you need a function like PBKDF2 which uses an iteration count and salt.
As for the solution:
You should not encrypt PIN's if that can be avoided. Please make sure your passwords are safe enough, allow pass phrases.
Create a random number per password and save the salt (16 bytes) with the output of PBKDF2. The salt does not have to be secret, although you might want to include a system secret to add some extra security. The salt and password are hashed, so they may have any length to be compatible with PBKDF2.
No, you just save the secret generated by the PBKDF2, let the PBKDF2 generate more data when required.
Never use ECB (not EBC). Use CBC as minimum. Note that CBC encryption does not provide integrity checking (somebody might change the cipher text and you might never know it) or authenticity. For that, you might want to add an additional MAC, HMAC or use an encryption mode such as GCM. PKCS7Padding (identical to PKCS5Padding in most occurences) is a simple method of adding bogus data to get N * [blocksize] bytes, required by block wise encryption.
Don't forget to prepend a (random) IV to your cipher text in case you reuse your encryption keys. An IV is similar to a salt, but should be exactly [blocksize] bytes (16 for AES).