On 3/27/2012 1:33 PM, pkumarn wrote:>
I am trying to write a sample program to do AES encryption using Openssl. I
tried going through Openssl documentation( it's a pain), could not figure
out much. I went through the code and found the API's using which i wrote a
small program as below (please omit the line numbers). I don't see any
encryption happening... am i missing something?
On 3/27/2012 10:42 PM, Jeffrey Walton wrote:
On Tue, Mar 27, 2012 at 4:26 PM, Ken Goldman<kgol...@us.ibm.com> wrote:
On 3/27/2012 3:51 PM, Jakob Bohm wrote:
On 3/27/2012 9:37 PM, Dr. Stephen Henson wrote:
You should really be using EVP instead of the low level routines.Where, precisely?
They are well documented with examples.
I didn't find it either when I was looking a few years ago, so I
settled on the obvious low level APIs too.
In fact, neither the low level or the EVP APIs are documented. I don't see
--
Jakob Bohm, CIO, partner, WiseMo A/S. http://www.wisemo.com
Transformervej 29, 2730 Herlev, Denmark. direct: +45 31 13 16 10 <call:+4531131610>
This message is only for its intended recipient, delete if misaddressed.
WiseMo - Remote Service Management for PCs, Phones and Embedded
On 3/27/2012 3:51 PM, Jakob Bohm wrote:
On 3/27/2012 9:37 PM, Dr. Stephen Henson wrote:
You should really be using EVP instead of the low level routines.Where, precisely?
They are well documented with examples.
I didn't find it either when I was looking a few years ago, so I
settled on the obvious low level APIs too.
In fact, neither the low level or the EVP APIs are documented. I don't see any AES documentation at all.
I also use the low level APIs, just because they were easier to find and understand in the source.
On 3/28/2012 3:01 AM, Prashanth kumar N wrote:
Here is the modified program[snip]
18 AES_KEY ectx;
19 AES_KEY dectx;
20
21 AES_set_encrypt_key(key, 256, &ectx);
22 AES_encrypt(text, out, &ectx);
23
24 printf("encryp data = %s\n", out);
25
26 AES_set_encrypt_key(key, 256, &dectx);
AES_set_decrypt_key()
27 AES_decrypt(out, decout, &dectx);
If you want to use low-level AES functions to encrypt more then 16 bytes
you
should use AES in CBC mode. You can implement this mode using AES_encrypt
()
or better use AES_cbc_encrypt().
Using AES_encrypt() block-by-block is called ECB mode.
Look at: http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
Example of using AES_cbc_encrypt() attached (pay attension of block
padding).
Best regards,
--
Marek Marcola <Marek....@malkom.pl>
owner-ope...@openssl.org wrote on 03/28/2012 09:01:25 AM:
> Prashanth kumar N <prashant...@gmail.com>
> Sent by: owner-ope...@openssl.org
>
> 03/28/2012 09:03 AM
>
> Please respond to
> openss...@openssl.org
>
> To
>
> openss...@openssl.org
>
> cc
>
> Subject
>
> Re: How to do encryption using AES in Openssl
>
> Here is the modified program
>
> #include <stdio.h>
> 2 #include <openssl/aes.h>
> 3
> 4 static const unsigned char key[] = {
> 5 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
> 6 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
> 7 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
> 8 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
> 9 };
> 10
> 11 void main()
> 12 {
> 13 unsigned char text[]="test12345678abcf";
> 14 unsigned char out[16];
> 15 unsigned char decout[16];
> 16 int i;
> 17
> 18 AES_KEY ectx;
> 19 AES_KEY dectx;
> 20
> 21 AES_set_encrypt_key(key, 256, &ectx);
> 22 AES_encrypt(text, out, &ectx);
> 23
> 24 printf("encryp data = %s\n", out);
> 25
> 26 AES_set_encrypt_key(key, 256, &dectx);
> 27 AES_decrypt(out, decout, &dectx);
> 28 printf(" Decrypted o/p: %s \n", decout);
> 29
> 30 for (i = 0;i < 16; i++)
> 31 printf(" %02x", decout[i]);
> 32 }
> 33
>
> As i read min AES block size is 128 bits which can go up to 256 bits in
multiples of 32-
> bits. Is this correct?
> I do know encrypted data is binary but when i pass the same data to
AES_decrypt()
> fucntion and print using %s, i get non-readable characters. What i
notice is when i
> change the input plain text, i do see o/p vaires.
>
On Thu, Mar 29, 2012, Prashanth kumar N wrote:The IV should be random and must be set to the same value on encrypt and
> Thanks Marek. I will try the attached code in the attached files.
> In many of the examples i have come across, i see IV is always being. Is it
> not possible to use this API by setting IV to NULL? (As i understand for
> CBC IV is a must) . In AES_Encrypt(), we don't use IV. Does this mean this
> does stream ciphering (byte by byte)?
>
decrypt. The information isn't security sensitive and can be sent in plain text.
If you use AES_encrypt you're effectively using ECB mode.
> Does any one know if Openssl supports AES-XTS? Reason is we are exploring
> to see if we can employ this.
> When i Googled, i did see some change request log which said AES-XTS has
> been added to Openssl in v1.1.0 which i am not able to find for download...
> Any idea on this?
>
XTS mode is very new and only supported in OpenSSL 1.0.1 and later. You use
EVP_CIPHER functions EVP_aes_128_xts() and EVP_aes_256_xts().
Note that the key length is double that for nomal AES. You can get the key
length of any cipher (provided you use EVP) using EVP_CIPHER_key_length().
Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
On 3/29/2012 1:40 AM, Prashanth kumar N wrote:That's what happens in C if you try to printf an array that's not NUL terminated. The printf just keeps going, right past the end of the buffer, until it either hits a \0 or segfaults.
Thanks Ken for pointing out the mistake... after changing to
AES_Decrypt(), it worked but i still see issue when i print the
decrypted output as it has extra non-ascii characters in it.
You encrypted 16 bytes, not nul terminated, decrypted to the same 16 bytes, then pretended that it was nul terminated and tried to printf.It depends on the mode and padding scheme. Some (CTR, OFB) don't pad, some (CFC) do pad.
Below is the input
unsigned char text[]="test12345678abc2";
After decryption, i get the following string: Decrypted o/p:
test12345678abc2Ȳu�z�B��� ��A��S�� Few questions...
1. If we use AES, will decrypted files have same number of bytes as
encrypted file? (I assume it should be same)
If you're just playing, fine. But if this is a real product you're designing, you shouldn't be asking this question. It's time to hire a crypto expert. Otherwise, your product will be insecure.
My requirement is mainly to support AES XTS but the reason for asking the above question was to understand if their is addition of extra bytes to encrypted data as it might consume more space when written to a drive... does my question make sense?
Hello,
If your data to encrypt is not exactly 16 bytes (AES block length), you
should add block
padding before encryption and remove padding after decryption.
In your case you have string "virident" (8bytes), you should add 16-8=8
bytes
of padding before encryption (fill last 8 bytes with value 8).
After decryption "remove" last 8 bytes (filed with value 8).
For printf() you may fill this last 8 bytes to 0.
owner-ope...@openssl.org wrote on 03/29/2012 04:02:17 PM:
> 03/29/2012 04:03 PM
>
> Please respond to
> openss...@openssl.org
>
> To
>
> openss...@openssl.org
>
> cc
>
> Subject
>
> Re: How to do encryption using AES in Openssl
>
Thanks Ken for pointing out the mistake... after changing to AES_Decrypt(), it worked but i still see issue when i print the decrypted output as it has extra non-ascii characters in it.
Below is the input
unsigned char text[]="test12345678abc2";
After decryption, i get the following string: Decrypted o/p: test12345678abc2Ȳu�z�B��� ��A��S��
Few questions...1. If we use AES, will decrypted files have same number of bytes as encrypted file? (I assume it should be same)
-PrashanthOn Wed, Mar 28, 2012 at 7:29 PM, Ken Goldman <kgol...@us.ibm.com> wrote:
On 3/28/2012 3:01 AM, Prashanth kumar N wrote:
Here is the modified program
[snip]
18 AES_KEY ectx;
19 AES_KEY dectx;
20
21 AES_set_encrypt_key(key, 256, &ectx);
22 AES_encrypt(text, out, &ectx);
23
24 printf("encryp data = %s\n", out);
25
26 AES_set_encrypt_key(key, 256, &dectx);
AES_set_decrypt_key()
27 AES_decrypt(out, decout, &dectx);