Hi Martin,
Thanks for the speedy response. I have been attempting to use the
EVP interface, but the cipher text produced is wrong (and I am fairly new to
this). As a simple test, I have hard-coded an 8 byte block for the key (in
hexadecimal), and also an 8 byte block (also in hex) for the plaintext. Can you
kindly take a look and provide feedback?
int main()
{
EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX*)malloc(sizeof(EVP_CIPHER_CTX));
EVP_CIPHER_CTX_init(ctx);
unsigned char key[]={0x01, 0x91, 0xd0, 0xad, 0x79, 0x4c, 0xae, 0x9b};
//64-bit KEY
unsigned char plaintext[]={0x61, 0x62, 0x63, 0x64, 0x61, 0x62, 0x63, 0x64};
//64-bit Plaintext to be encrypted
int ret;
ret = EVP_EncryptInit_ex(ctx, EVP_des_ecb(), NULL, key, NULL); //USE DES ECB
mode
assert(ret == 1);
ret = EVP_CIPHER_CTX_set_padding(ctx, 0); //No padding
assert(ret == 1);
int val, num_bytes_in(8),num_bytes_out(8); //8 bytes of plaintext, 8 bytes
of ciphertext
unsigned char out[8]; //Store ciphertext in "out"
val=EVP_EncryptUpdate(ctx, out, &num_bytes_out, plaintext, num_bytes_in );
//Encrypt plaintext
for (int i=0; i<8; i++) //Print ciphertext
{
printf("%02x",out[i]);
}
cout<<endl;
}
Best Regards,
- Ali
----- Original Message -----
From: "Martin Kaiser" <[email protected]>
To: [email protected]
Sent: Friday, April 9, 2010 10:52:07 AM GMT -06:00 US/Canada Central
Subject: Re: How to configure DES ECB encryption without the "no padding" mode?
Hi Ali,
Thus wrote Ali Sydney ([email protected]):
> I am attempting to implement DES (in C++ with the OpenSSL
> libraries) in ECB mode without padding. I am using the following
> function for encryption:
> void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
> DES_key_schedule *ks, int enc);
> However, this function does not have any parameters to specify the "no
> padding" option. How do I configure "no padding"? Thank you.
you should use the EVP interface instead of the low-level functions
ret = EVP_DecryptInit_ex(&ctx, EVP_des_ecb(), NULL, myKey, NULL);
assert(ret == 1);
ret = EVP_CIPHER_CTX_set_padding(&ctx, 0);
assert(ret == 1);
and then EVP_Decrypt_Update(), EVP_DecryptFinal(). Similar for
encryption.
Hope this helps,
Martin
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]