Re: linking errors on linux........!

2008-06-16 Thread karim Bendadda
Could you post the message given you by the compiler??

On Mon, Jun 16, 2008 at 9:51 AM, vinni rathore <[EMAIL PROTECTED]> wrote:

> hi
> i m getting undefined symbol for my sample server program that is on linux.
> my program is using openssl apis.
>  i have installed the openssl 0.9.8g version on the red hat machine
> everything got sucess but still getting the linking errors.
> steps that i followed:
> 1- config
> 2. make
> 3. make install
>
> finally when i tried my sample with gcc compiler it gives the undefined
> symbol errors.
> like : undefined reference to SSL_library_init.
>
> plz reply as soon as possible.
> thnx in advance.
>
> --
> regards,
> Vineeta Kumari
> Software engg
> Mobera Systems
> Chandigarh




-- 
Karim


Re: AES CTR128

2008-05-27 Thread karim Bendadda
http://fixunix.com/openssl/249591-evp_decryptfinal_ex-bad-decrypt.html


On Tue, May 27, 2008 at 10:58 AM, karim Bendadda <[EMAIL PROTECTED]> wrote:

> Try this: http://www.grandville.net/pmwiki.php/OpenSSL/AES-CBC-EVP
>
> Openssl  EVP API makes AES encryption/decryption.
>
>
> On Mon, May 26, 2008 at 5:54 PM, Mohamed Amine Ourmech <
> [EMAIL PROTECTED]> wrote:
>
>>   Good morning,
>> I want to test the AES CTR128 encryption of openSSL but infortunately i
>> could not find one. I have tested one but still i got errors in the output
>> of the program. here is the code i tested (i found it on the internet), plz
>> can anyone provide a really simple test program for the counter mode of AES
>> in openSSL, or simply see what s the problem in that source code. Thank you
>> very much for consideration.
>>
>> #include 
>> #include 
>> #include < openssl
>> <http://osdir.com/ml/encryption.openssl.devel/2002-07/msg00358.html#>/aes.h>
>>
>>
>> #define KEY_LENGTH 16
>> #define TEXT_LENGTH 36
>> #define COUNTER_LENGTH 16
>>
>> void mirror(const unsigned char *in, unsigned char *out,
>> const unsigned long length, const AES_KEY *key,
>> unsigned char *counter, unsigned int *num) {
>>
>> unsigned int n;
>> unsigned long l=length;
>> unsigned char tmp[AES_BLOCK_SIZE];
>>
>> memset(tmp, 0xFF, AES_BLOCK_SIZE);
>> }
>>
>> int main(void)
>> {
>> unsigned char key[KEY_LENGTH + 1] = "9dfe5ea4c3f84ae3";
>> unsigned char plaintext1[(TEXT_LENGTH / 2) + 1] =
>> "123456789012345678";
>> unsigned char plaintext2[(TEXT_LENGTH / 2) + 1] =
>> "876543210987654321";
>> unsigned char ciphertext[TEXT_LENGTH + 1];
>> unsigned char plaintext[TEXT_LENGTH + 1];
>> unsigned char ecounter[COUNTER_LENGTH + 1] = "6543210987654321";
>> unsigned char dcounter[COUNTER_LENGTH + 1] = "6543210987654321";
>> AES_KEY k;
>> int num;
>> int retval;
>>
>>
>> retval = AES_set_encrypt_key(key, strlen(key) * 8, &k);
>> if (retval < 0) {
>> printf("couldn't set encrypt key: %d\n", retval);
>> return -1;
>> }
>>
>> num = 0;
>> AES_ctr128_encrypt(plaintext1, ciphertext, strlen(plaintext1),
>>&k, ecounter, &num);
>>
>> mirror(NULL, NULL, 0, NULL, NULL, NULL);
>>
>> AES_ctr128_encrypt(plaintext2, ciphertext + strlen(plaintext1),
>>strlen(plaintext2), &k, ecounter, &num);
>>
>> num = 0;
>> AES_ctr128_encrypt(ciphertext, plaintext,
>>strlen(plaintext1) + strlen(plaintext2),
>>&k, dcounter, &num);
>>
>> retval = strncmp(plaintext, plaintext1, strlen(plaintext1));
>> if (retval != 0) {
>> printf("error\n");
>> return -1;
>> }
>> retval = strncmp(plaintext + strlen(plaintext1), plaintext2,
>>  strlen(plaintext2));
>> if (retval != 0) {
>> printf("error\n");
>> return -1;
>> }
>>
>> printf("success\n");
>>
>> return 0;
>> }
>>
>>
>
>
> --
> Karim




-- 
Karim


Re: AES CTR128

2008-05-27 Thread karim Bendadda
Try this: http://www.grandville.net/pmwiki.php/OpenSSL/AES-CBC-EVP

Openssl  EVP API makes AES encryption/decryption.

On Mon, May 26, 2008 at 5:54 PM, Mohamed Amine Ourmech <[EMAIL PROTECTED]>
wrote:

>   Good morning,
> I want to test the AES CTR128 encryption of openSSL but infortunately i
> could not find one. I have tested one but still i got errors in the output
> of the program. here is the code i tested (i found it on the internet), plz
> can anyone provide a really simple test program for the counter mode of AES
> in openSSL, or simply see what s the problem in that source code. Thank you
> very much for consideration.
>
> #include 
> #include 
> #include < openssl
> /aes.h>
>
>
> #define KEY_LENGTH 16
> #define TEXT_LENGTH 36
> #define COUNTER_LENGTH 16
>
> void mirror(const unsigned char *in, unsigned char *out,
> const unsigned long length, const AES_KEY *key,
> unsigned char *counter, unsigned int *num) {
>
> unsigned int n;
> unsigned long l=length;
> unsigned char tmp[AES_BLOCK_SIZE];
>
> memset(tmp, 0xFF, AES_BLOCK_SIZE);
> }
>
> int main(void)
> {
> unsigned char key[KEY_LENGTH + 1] = "9dfe5ea4c3f84ae3";
> unsigned char plaintext1[(TEXT_LENGTH / 2) + 1] =
> "123456789012345678";
> unsigned char plaintext2[(TEXT_LENGTH / 2) + 1] =
> "876543210987654321";
> unsigned char ciphertext[TEXT_LENGTH + 1];
> unsigned char plaintext[TEXT_LENGTH + 1];
> unsigned char ecounter[COUNTER_LENGTH + 1] = "6543210987654321";
> unsigned char dcounter[COUNTER_LENGTH + 1] = "6543210987654321";
> AES_KEY k;
> int num;
> int retval;
>
>
> retval = AES_set_encrypt_key(key, strlen(key) * 8, &k);
> if (retval < 0) {
> printf("couldn't set encrypt key: %d\n", retval);
> return -1;
> }
>
> num = 0;
> AES_ctr128_encrypt(plaintext1, ciphertext, strlen(plaintext1),
>&k, ecounter, &num);
>
> mirror(NULL, NULL, 0, NULL, NULL, NULL);
>
> AES_ctr128_encrypt(plaintext2, ciphertext + strlen(plaintext1),
>strlen(plaintext2), &k, ecounter, &num);
>
> num = 0;
> AES_ctr128_encrypt(ciphertext, plaintext,
>strlen(plaintext1) + strlen(plaintext2),
>&k, dcounter, &num);
>
> retval = strncmp(plaintext, plaintext1, strlen(plaintext1));
> if (retval != 0) {
> printf("error\n");
> return -1;
> }
> retval = strncmp(plaintext + strlen(plaintext1), plaintext2,
>  strlen(plaintext2));
> if (retval != 0) {
> printf("error\n");
> return -1;
> }
>
> printf("success\n");
>
> return 0;
> }
>
>


-- 
Karim


Re: [Base64 Decoding] Bug when decoding??

2008-05-24 Thread karim Bendadda
Thank you Steve for help. I tried to use the BIO_FLAGS_BASE64_NO_NL flag in
my code. This works fine.

Thank you everybody again for help.

On Fri, May 23, 2008 at 12:24 PM, Dr. Stephen Henson <[EMAIL PROTECTED]>
wrote:

> On Fri, May 23, 2008, karim Bendadda wrote:
>
> > Hi Stephen,
> >
> >I just try it! it works fine! it doesn't appear when lunching
> openssl
> > command: $openssl enc ?
> >  How can I implement it using the openssl's EVP API???
> >
>
> It is mentioned in the documentation and the BIO equivalent is to set the
> flag
> BIO_FLAGS_BASE64_NO_NL. See enc and BIO_f_base64() documents. I don't
> normally
> use EVP for base64 encoding, I use a bio chain so don't know about that.
>
> Steve.
> --
> Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
> OpenSSL project core developer and freelance consultant.
> Homepage: http://www.drh-consultancy.demon.co.uk
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>



-- 
Karim


Re: [Base64 Decoding] Bug when decoding??

2008-05-23 Thread karim Bendadda
Hi Stephen,

   I just try it! it works fine! it doesn't appear when lunching openssl
command: $openssl enc ?
 How can I implement it using the openssl's EVP API???

Thank you.

On Thu, May 22, 2008 at 8:12 PM, Dr. Stephen Henson <[EMAIL PROTECTED]>
wrote:

> On Thu, May 22, 2008, karim Bendadda wrote:
>
> > Hi All,
> >
> >I'm trying to decode a Base64 encoded string. Using the openssl
> decoding
> > command:*
> >
> > echo
> >
> "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPqnSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXljRolfrSX6bNjcMvfy7k5J+2xo451u="
> > | openssl enc -base64 -d
> >
> > *I got no result! nothing!!!  I tried to decode this string on an online
> > base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl  and it's
> ok!!
> > I have the correct string
> > ( wich is an encrypted string). What's wrong with openssl command???
> >
>
> Did you try the -A option?
>
> Steve.
> --
> Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
> OpenSSL project core developer and freelance consultant.
> Homepage: http://www.drh-consultancy.demon.co.uk
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>



-- 
Karim


Re: [Base64 Decoding] Bug when decoding??

2008-05-23 Thread karim Bendadda
Thanks for examples Victor.

  As Dominique suggests I tried to split the base64 encoded string to blocs.
The decoding works fine now! but I still have some decrypting
problems...I'll post my problem on a new topic; it concerning decrypting
now!.

Thank you for your help!

On Thu, May 22, 2008 at 8:14 PM, Victor Duchovni <
[EMAIL PROTECTED]> wrote:

> On Thu, May 22, 2008 at 02:20:07PM +0200, karim Bendadda wrote:
>
> > Hi All,
> >
> >I'm trying to decode a Base64 encoded string. Using the openssl
> decoding
> > command:*
> >
> > echo
> >
> "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPqnSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXljRolfrSX6bNjcMvfy7k5J+2xo451u="
> > | openssl enc -base64 -d
>
> The string is too long to fit on one line. The "openssl base64" decoder
> requires long strings to be split over multiple lines. As you can see, the
> limit is 80 characters per-line:
>
>$ let i=15; while (( i < 25))
>do
>echo $i $(perl -e "printf qq{%s\n}, q{} x $i" |
>openssl base64 -d | wc -c)
>let i=i+1
>done
>15 45
>16 48
>17 51
>18 54
>19 57
>20 0
>21 0
>22 0
>23 0
>24 0
>
> Also each line MUST end with "\n" or "\r\n", incomplete last lines don't
> work:
>
>$ let i=15; while (( i < 25))
>do
>echo $i $(perl -e "printf qq{%s}, q{} x $i" |
>openssl base64 -d | wc -c)
>let i=i+1
>done
>15 0
>16 0
>17 0
>18 0
>19 0
>20 0
>21 0
>22 0
>23 0
>24 0
>
> --
>Viktor.
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>



-- 
Karim


Re: [Base64 Decoding] Bug when decoding??

2008-05-22 Thread karim Bendadda
Hi Dominique,


First I'd like to thank you for your quick answer. You're right, it
works well when spliting. I'd like now to do it using the openssl API
(I found the function above on the web). This function works well for input
at most 64 bytes .May I have to do a manual split where input is at least 64
bytes long? Is there any methods (an Openssl function for example) to do it
automatically???.

Thank you for your efforts.

*char *unbase64(unsigned char *input, int length)
{
  BIO *b64, *bmem;

  char *buffer = (char *)malloc(length);
  memset(buffer, 0, length);

  b64 = BIO_new(BIO_f_base64());
  bmem = BIO_new_mem_buf(input, length);
  bmem = BIO_push(b64, bmem);

  BIO_read(bmem, buffer, length);

  BIO_free_all(bmem);

  return buffer;
}
*
--
On Thu, May 22, 2008 at 3:57 PM, Dominique Lohez <[EMAIL PROTECTED]>
wrote:

> Hello karim
> The line must be at most 64 octets long
> using the file  essai.pem where the unique has been splited in three
> the command
>
> openssl enc -base64 -d -in essai.pem
> works.
>
> but be carefull most of the characterare not printables
>
> karim Bendadda a écrit :
>
>  Hi All,
>>
>>   I'm trying to decode a Base64 encoded string. Using the openssl decoding
>> command:/
>> echo
>> "nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPqnSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXljRolfrSX6bNjcMvfy7k5J+2xo451u="
>> | openssl enc -base64 -d
>>
>> /I got no result! nothing!!!  I tried to decode this string on an online
>> base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl  and it's
>> ok!! I have the correct string
>> ( wich is an encrypted string). What's wrong with openssl command???
>>
>> Thank you for help.
>>
>> --
>> Karim
>>
>
>
> --
> Dr Dominique LOHEZ
> ISEN
> 41, Bd Vauban
> F59046 LILLE
> France
>
> Phone : +33 (0)3 20 30 40 71
> Email: [EMAIL PROTECTED]
>
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>



-- 
Karim


[Base64 Decoding] Bug when decoding??

2008-05-22 Thread karim Bendadda
Hi All,

   I'm trying to decode a Base64 encoded string. Using the openssl decoding
command:*

echo
"nnnKZdKOQMmVpLEOBqNU3L07ELMSoQxW0z7SvgZBmwXpjvMYPqnSMaWy9vu6NFUHGc40nhLbaFe8vI159nZHHdMOssHyfI6kzXljRolfrSX6bNjcMvfy7k5J+2xo451u="
| openssl enc -base64 -d

*I got no result! nothing!!!  I tried to decode this string on an online
base64 decoder http://webnet77.com/cgi-bin/helpers/base-64.pl  and it's ok!!
I have the correct string
( wich is an encrypted string). What's wrong with openssl command???

Thank you for help.

-- 
Karim


Re: Update: !!! [AEC CBC decryption] Decrypted data Length problem (AES_cbc_encrypt)...

2008-05-19 Thread karim Bendadda
Thank you for your quick answer!

   I see what you mean... that's the problem: How can I guarantee this?? I
will receive an encrypted data, I have the key and the vector. How can I
decrypted the data ??

Thanks!


On Mon, May 19, 2008 at 4:53 PM, Michael S. Zick <[EMAIL PROTECTED]>
wrote:

> On Mon May 19 2008 09:35, karim Bendadda wrote:
> > *Sorry for the first mail!!*
> >
>
> Unless you can guarantee that the strings do not contain embedded zeros;
> strlen() will not give the expected results.
>
> Mike
> > Hi all,
> >
> >I'm new on openssl development, so I'm sorry if that a "beginner's"
> > question . I'm trying to decrypt a *base64 AES CBC* encrypted data (using
> > the *AES_cbc_encrypt*). The base64 encoding/decoding works fine. the code
> > below works depending on data length:
> >
> >-  The example with :
> >
> >
> > data ="*This is a long very long test*" works fine, I have the good
> > decrypted data.
> >
> >- The second one  "*This is a test*" doesn't work... I read somewhere
> >that's depending of data padding... Have you any idea??
> >
> >
> > ..
> > int main(int argc, char *argv[])
> > {
> > unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> > unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> > unsigned char iv1[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
> >
> >
> >
> > unsigned char* data ="This is a test";
> > //unsigned char* data ="This is a long very long test";
> >
> > unsigned char* buffer = (char *) malloc(60);
> > unsigned char* buffer1 = (char *) malloc(60);
> >
> >
> > unsigned long bufferLength= (ceil(strlen(data)/16)+1)*16;
> >
> > AES_KEY aeskeyEnc, aeskeyDec;
> >
> >
> > AES_set_encrypt_key (key, KeyLength*8, &aeskeyEnc);
> > AES_set_decrypt_key (key, KeyLength*8, &aeskeyDec);
> >
> > /*Encrypting...*/
> > AES_cbc_encrypt(data, buffer, bufferLength, &aeskeyEnc, iv,
> > AES_ENCRYPT);
> > //AES_cbc_encrypt(data, buffer, strlen(data), &aeskeyEnc, iv,
> > AES_ENCRYPT);
> > printf("Encrypted data: %s\n",buffer);
> >
> >
> > /*To Base64 encrypted data  */
> > char *base64Buffer = base64(buffer, strlen(buffer));
> > printf("Base64 Encrypted data: %s\n",base64Buffer);
> >
> >
> > /* Unbase64 of encrypted data*/
> > char* test_1 = strcat(base64Buffer,"\n\0");
> > char* unBase64 = unbase64(base64Buffer, strlen(base64Buffer));
> >
> >
> > /*Decypting unBase64...*/
> > AES_cbc_encrypt(unBase64, buffer1,bufferLength, &aeskeyDec, iv1,
> > AES_DECRYPT);
> > //AES_cbc_encrypt(unBase64, buffer1, strlen(unBase64), &aeskeyDec,
> iv1,
> > AES_DECRYPT);
> > printf("Decrypted data: %s \n",buffer1);
> >
> >
> >
> > return(0);
> > }
> >
> >
> >
> __
> OpenSSL Project http://www.openssl.org
> User Support Mailing Listopenssl-users@openssl.org
> Automated List Manager   [EMAIL PROTECTED]
>



-- 
Karim


Update: !!! [AEC CBC decryption] Decrypted data Length problem (AES_cbc_encrypt)...

2008-05-19 Thread karim Bendadda
*Sorry for the first mail!!*

Hi all,

   I'm new on openssl development, so I'm sorry if that a "beginner's"
question . I'm trying to decrypt a *base64 AES CBC* encrypted data (using
the *AES_cbc_encrypt*). The base64 encoding/decoding works fine. the code
below works depending on data length:

   -  The example with :


data ="*This is a long very long test*" works fine, I have the good
decrypted data.

   - The second one  "*This is a test*" doesn't work... I read somewhere
   that's depending of data padding... Have you any idea??


..
int main(int argc, char *argv[])
{
unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
unsigned char iv1[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};



unsigned char* data ="This is a test";
//unsigned char* data ="This is a long very long test";

unsigned char* buffer = (char *) malloc(60);
unsigned char* buffer1 = (char *) malloc(60);


unsigned long bufferLength= (ceil(strlen(data)/16)+1)*16;

AES_KEY aeskeyEnc, aeskeyDec;


AES_set_encrypt_key (key, KeyLength*8, &aeskeyEnc);
AES_set_decrypt_key (key, KeyLength*8, &aeskeyDec);

/*Encrypting...*/
AES_cbc_encrypt(data, buffer, bufferLength, &aeskeyEnc, iv,
AES_ENCRYPT);
//AES_cbc_encrypt(data, buffer, strlen(data), &aeskeyEnc, iv,
AES_ENCRYPT);
printf("Encrypted data: %s\n",buffer);


/*To Base64 encrypted data  */
char *base64Buffer = base64(buffer, strlen(buffer));
printf("Base64 Encrypted data: %s\n",base64Buffer);


/* Unbase64 of encrypted data*/
char* test_1 = strcat(base64Buffer,"\n\0");
char* unBase64 = unbase64(base64Buffer, strlen(base64Buffer));


/*Decypting unBase64...*/
AES_cbc_encrypt(unBase64, buffer1,bufferLength, &aeskeyDec, iv1,
AES_DECRYPT);
//AES_cbc_encrypt(unBase64, buffer1, strlen(unBase64), &aeskeyDec, iv1,
AES_DECRYPT);
printf("Decrypted data: %s \n",buffer1);



return(0);
}



-- 
Karim Bendadda


[AEC CBC decryption] Decrypted data Length problem (AES_cbc_encrypt)...

2008-05-19 Thread karim Bendadda
Hi all,

   I'm new on openssl development, so I'm sorry if that a "beginner's"
question . I'm trying to decrypt a *base64 AES CBC* encrypted data (using
the *AES_cbc_encrypt*). The base64 encoding/decoding works fine. the code
below works depending on data length:

   -  The example with :


data ="This is a long very long test" works fine, I have the good decrypted
data.

   - The second one doesn't work... I read somewhere that's depending of
   data padding... Can you


..
int main(int argc, char *argv[])
{
unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};
unsigned char iv1[] = {0,1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e'};



int KeyLength=16;
int BufferLength=60;


unsigned char* data ="This is a test";
//unsigned char* data ="This is a long very long test";

unsigned char* buffer = (char *) malloc(BufferLength);
unsigned char* buffer1 = (char *) malloc(BufferLength);



AES_KEY aeskeyEnc, aeskeyDec;


AES_set_encrypt_key (key, KeyLength*8, &aeskeyEnc);
AES_set_decrypt_key (key, KeyLength*8, &aeskeyDec);

/*Encrypting...*/
AES_cbc_encrypt(data, buffer, 16, &aeskeyEnc, iv, AES_ENCRYPT);
//AES_cbc_encrypt(data, buffer, strlen(data), &aeskeyEnc, iv,
AES_ENCRYPT);
printf("Encrypted data: %s\n",buffer);


/*To Base64 encrypted data  */
char *base64Buffer = base64(buffer, strlen(buffer));
printf("Base64 Encrypted data: %s\n",base64Buffer);


/* Unbase64 of encrypted data*/
char* test_1 = strcat(base64Buffer,"\n\0");
char* unBase64 = unbase64(base64Buffer, strlen(base64Buffer));


/*Decypting unBase64...*/
AES_cbc_encrypt(unBase64, buffer1,16, &aeskeyDec, iv1, AES_DECRYPT);
//AES_cbc_encrypt(unBase64, buffer1, strlen(unBase64), &aeskeyDec, iv1,
AES_DECRYPT);
printf("Decrypted data: %s \n",buffer1);



return(0);
}



-- 
Karim Bendadda