473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

DES Algorithm padding problem??

Hello,

I am making an implementation of DES using 56bit key and 64 bit block.
Now the problem is that when the last set of bytes are read from the file, and say it comes out to be 2bytes remaining, then I have to pad remaining 6 bytes to get my 8 bytes of block for encryption.

So when I decrypt the file, these padded bytes also gets decrypted(which should not happen), resulting in corruption of the file after decryption.

So, please tell me how can I overcome this problem.

I am using OpenSSL libraries for DES.

Also, can I increase the input block size from 64bit to some higher value, because it takes a lot of time during encryption/decryption.

Pawan
Feb 21 '07 #1
13 2490
RedSon
5,000 Expert 4TB
The problem with block ciphers is that they must operate on multiples of their block size. You are running into an issue with a poor block cipher mode of operation. Simply padding the block might not work unless you can find the original size of the file to begin with. You should choose a better mode of operation.

Link: http://en.wikipedia.org/wiki/Block_c...s_of_operation
Feb 21 '07 #2
The problem with block ciphers is that they must operate on multiples of their block size. You are running into an issue with a poor block cipher mode of operation. Simply padding the block might not work unless you can find the original size of the file to begin with. You should choose a better mode of operation.

Link: http://en.wikipedia.org/wiki/Block_c...s_of_operation
The Wiki link is great, thanks.
Also I think I will have to store the original file length at the beginning of the file and use it to get the file length during decryption.

Also can you tell me, how to rate a post.
Pawan
Feb 21 '07 #3
RedSon
5,000 Expert 4TB
Good luck, let me know how it turns out.
Feb 21 '07 #4
Good luck, let me know how it turns out.
OK, I will, also can you tell me how to rate a post.
Pawan
Feb 21 '07 #5
Ganon11
3,652 Expert 2GB
As of right now, we don't implement a post-rating system.
Feb 21 '07 #6
RedSon
5,000 Expert 4TB
We currently don't have that facility but if you make another post in this thread about what you would like to rate it and what you think of if I will let the administrators know about it.
Feb 21 '07 #7
RedSon
5,000 Expert 4TB
Oops, Ganon, you beat me to the punch.
Feb 21 '07 #8
Ganon11
3,652 Expert 2GB
XD No matter - I must have faster fingers :P.
Feb 21 '07 #9
RedSon
5,000 Expert 4TB
XD No matter - I must have faster fingers :P.
Actually I think my post is twice as long as yours, so I posted twice as much in about the same time so double :P :P
Feb 21 '07 #10
I just wanted to say that the reply to my original post was really quick and I think is really good, and I will surely use the concept in my DES code.
Thats why I thought that there should be post rating system, anyway, I have posted many problems at TSDN and have always benefited from the reply. Great job, keep it up!

Pawan
Feb 21 '07 #11
Ganon11
3,652 Expert 2GB
Well, thanks for the kind feelings. I'm just glad we were able to help, and I hope you'll be willing to stop by and help people too!

And you can argue however much you want, RedSon, the fact is that my reply was in before yours. Thus, I win. XD
Feb 21 '07 #12
I am posting a reply just to tell what I actually did to overcome the padding problem. I searched a lot on net but almost everywhere I got the answer that I should store the original filelength somewhere, but I thought that as I am opening the file in binary mode, it would be difficult for me to store the filelength. So I created my own mathod. What I did is, initially I found the file's length, and then took filelength%8. Then if say filelength is 66bytes, then I got 2 bytes extra, so after encrypting say 5 blocks(= 5*8bytes) I read 2 bytes and stored them unencrypted. Then continued my encryption process on rest of the file. So during decryption, I decrypted 5 block and copied 2bytes directly and decrypted remaining blocks.

Thus, in this way I achieved a simple solution to my problem. Some might say that the unencrypted 2bytes are a security flaw, but I dont believe, as it is almost impossible and usless to get the knowledge of which 2 bytes are unencrypted.

If any comments on my method, please reply
Pawan
Feb 28 '07 #13
DeMan
1,806 1GB
Presumably the two bytes are in some fixed position (so you know where/how to find them - In this case 5 blocks....).
HOWEVER, The two bytes being unencrypted is no security concern, unless they themselves contain secure data.
As they give nothing away about the encryption, and so long as they give as little away as possible about the original plaintext, they are virtually useless even to people who know that exactly those bytes are unencrypted.

As a thought to the problem of storing a file length.....If you have to pad the code out to the nearest 8 blocks anyway, you can make sure that you ALWAYS pad it out (that is even if size%8 = 0, always add 8 bytes). In the last of these you could store the size.....
Feb 28 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: delerious | last post by:
Could someone please take a look at this page: http://home.comcast.net/~delerious1/index11.html The set of links on the left should not have any whitespace between them, and the set of links...
2
by: Knoxy | last post by:
Hello, I've noticed one or two people post on this before but nobody seems to have replied so raising the issue again... is this a known IE6 CSS bug? I have placed the following in my...
4
by: Wilhelm Kutting | last post by:
hi, when i use the padding-left attribut, i like to overwrite a default value like that ..padding30 {margin-left: 30px;} ..padding0 {margin-left: 0px;} <div class="padding30"> Padding 30...
2
by: Remi Villatel | last post by:
Hi there, I have following CSS definitions: div.limits { margin: 0 20px 0 20px; } div.halfleft { float: left; left: 0; width: 50%;
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
12
by: wjb131 | last post by:
hi all, below you find my simple python version of MD2 algorithm as described in RFC1319 (http://rfc1319.x42.com/MD2). It produces correct results for strings shorter than 16 Bytes and wrong...
3
by: ThomasH | last post by:
Hi: being a relatively inexperienced HTML user I would like to ask you if you know of any macro(?), css style(?) or any other convenient method which would allow to quote pieces of code with...
36
by: phil-news-nospam | last post by:
Here is a simpler (no drop shadows) example of the padding bug I see: http://phil.ipal.org/usenet/ciwas/2006-05-08/buttons-1.html So far I find nothing in the CSS2 document that says I should...
5
by: Tom | last post by:
I am having a problem where an extra gap (whitespace, padding) appears in a table cell where I don't want it. The data fed in the table is via dynamic HTML, so the amount in the middle cell may...
5
by: Mike | last post by:
I am having a problem with padding. I have three boxes and I want them all to be the same width. In IE it looks like the outside of the DIV stays put and the padding is placed on the inside, so the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.