Since somebody asked me via PM for my implementation of the RC6 algorithm, I figured I might as well post it here...
The attached archive includes the source code (TASM ideal mode, should be easy to convert to MASM syntax) as well as a minimalistic example program illustrating its usage.
I'm getting a throughput of around 57MB/sec on my machine, so this code should be fast enough for most applications ;)
Attachments:
Posted on 2005-05-13 11:34:45 by Tola
RC6 is a nice algorithm, since it's relatively fast and small (lack of s-boxes).

How are the current patent/licensing issues with RC6? When I looked a couple of years ago, it seemed RSA wanted royalties if you used the algorithm commercially (probably because they were annoyed Rijndael was chosen for AES, instead of RC6).
Posted on 2005-05-13 11:59:11 by f0dder
Hey tola, sorry I didn't respond to your pm sooner, I didn't see it. Here's your code rewritten in masm, as requested. Great implementation btw, I really appreciated it sir.
Attachments:
Posted on 2005-05-19 08:32:59 by Webring
Hello, all about interesting rc6.

here is a test code about rc6.
when rc6 encrypt or decrypt a disk file. it can't work fine. That's why?

please modify output file name when you are testing.


regards

Attachments:
Posted on 2005-06-01 01:40:16 by dcskm4200

when rc6 encrypt or decrypt a disk file. it can't work fine. That's why?

That's somewhat vague - what goes wrong? Is it a GPF, or do you get garbage when decrypting, or... what?
Posted on 2005-06-01 04:25:41 by f0dder
Hello, f0dder.

I explain more clear about it can't work fine.
the tested file is 10.txt.
the encrypted file is 11.txt.
the decrypted file is 12.txt.

here is testing result:
;===========
10.txt
this is rc6 tested.
;===========
11.txt
??
;===========
12.txt
? (it should be "this is rc6 tested.")
;===========


regards
Posted on 2005-06-01 04:43:27 by dcskm4200
Hey dcskm4200, the problem with your code is Rc6 only encrypts data that's up to the length of the key. Meaning if your key is 16 bytes long, 16 bytes of plain data is encrypted, and anything left over is untouched... So for files since they're usually alot larger than 16 bytes you need to read and encrypt in 16 byte increments, or really anything 16 and below. You could read 8 bytes at a time for instance. And you can also change the key length to say 32 bytes. I would have responded sooner but I was put on a very reasonable 5 day posting ban by SpooK because of my attitude problem. I have openly broken the rules of this community and I don't know how to act. I believe these forums are here for my personal use and I don't care if I undermind the moderators/admins or the rules. I do not wish to be be perm banned, but it will happen eventually because I don't know how to follow the rules or keep my mouth shut when it would best serve me. So if you need help fixing your code dcskm4200, email me. ;)
Posted on 2005-06-01 05:19:41 by Webring
Hello, Code Warrior Webring

Thanks you for reply.
before you guided me, I didn't actually understand the rc6. I'll try to fix the tested code. if I can't figure out, I'll ask for you with a email.
;==================================
I always appreciated the following words.

the other viewpoint is as a landscape. if you like it , then stay there for sightseeing; if you disgust it, then depart from it. and the landscape is staying there, could not track you.

life is bitter and short. enjoy everyday.

;==================================

regards.
Posted on 2005-06-01 06:47:41 by dcskm4200
Sounds like a blocksize problem, then.

First of all, the RC6_encrypt primitive works on a 'block' of data, like all block ciphers. Iirc the RC6 blocksize is 128bit/16byte. So, you have to process files in blocks.

Also, files with a final block of less than blockfile size needs to be padded, otherwise the final block will be decrypted wrong! You should pad the buffer with random data, not zeroes.

And finally, you should use a chaining method between the blocks, to a void encrypting, say, multiple 16-byte blocks of zeroes to the same encrypted value. The simplest chaining method is probably CBC: http://en.wikipedia.org/wiki/Cipher_Block_Chaining
Posted on 2005-06-01 08:22:34 by f0dder
Hello,F0dder.

Thanks you for help.

it is very important that you guided me. after i read Webring's post. I try to modify the code. but I didn't wake up to that:
1. fill lack bytes with random char.
2. better method is the CBC or CFB or OFB or CTR, not ECB.

thanks again.   
Posted on 2005-06-01 09:32:43 by dcskm4200
dcskm4200,
invoke WriteFile,hFile,lpBufferSource,Sizeof lpBufferSource,ADDR dwBytesTouched,0

find the mistake ;)
Posted on 2005-06-01 10:12:29 by Tola
Hey,Tola
there is no mistake. attachment include the front code which i modified a little for testing.
the 11.txt and 12.txt which created by rc6_7.exe are fine.


error is where f0dder and Webring told me.

regards.

Attachments:
Posted on 2005-06-02 08:06:34 by dcskm4200
I don't have masm installed so I cannot test this. Still, the test program you posted before always creates 'encrypted' files that are only 4 bytes in length, regardless of the size of the target file.
Posted on 2005-06-02 10:06:49 by Tola
Also, stop the .bat == .asm madness... it breaks syntax highlighting and double-click == open...
Posted on 2005-06-02 18:10:50 by f0dder
hey,f0dder
;===============================================
yes, I'm madness. This is the reality which I must accept. But if you said the source code style is madness, Most of famous coder
like EliCZ,y0da,Four-F....will chide you.
;===============================================
you may config your setFile of .bat as same as setFile of .asm in your IDE. for making syntax highlighting .
double-click == make exe
open== right-click,open with...
;===============================================
the source code written by ECB may work, but it is ugly.
do you want to know the content of << The Frist Dialogue of New World>> ?

let's go...

Key=passme

regards
Attachments:
Posted on 2005-06-23 02:26:00 by dcskm4200
HAHAHA
jokes
u are most famous MAD insane coder
Posted on 2005-06-24 07:31:00 by comrade
LOOKLY VERY NICE.
if I was a coder, I must ask for MARRY with you.
Posted on 2005-06-24 08:37:35 by dcskm4200
Now now, children ^_^
Posted on 2005-06-24 12:06:42 by f0dder
hey,Tola

Your implementation of the RC6 algorithm runs faster.
in Intel(R) Pentium(r) 1.4GHz, 25.3M encrypted file has been finished less 3s.

regards
Posted on 2005-06-26 10:52:34 by dcskm4200

hey,Tola

Your implementation of the RC6 algorithm runs faster.
in Intel(R) Pentium(r) 1.4GHz, 25.3M encrypted file has been finished less 3s.

it runs faster than what? :mrgreen:
Posted on 2005-06-27 06:04:50 by Tola