flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > RSA Public Key Encryption (PKE) macros for fasm

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20342
Location: In your JS exploiting you and your system
revolution 23 Jul 2005, 17:16
RSA Public Key Encryption (PKE) macros for fasm

RSA is the encryption method used with PGP. We publicise a modulus and key so that others can encrypt messages and send to us (or can decrypt messages we send to them). Once encrypted with one key a message cannot be decrypted with the same key. We can use either key to encrypt and after that we have to use the other key to decrypt.

I have attached macros to perform PKE. Once again, not fast but convenient. There is no restriction on key size except that is must be a multiple of 32 bits. You can set the length of the modulus to any multiple of 32 but the limiting factor will probably be your patience waiting for it to complete for the larger key sizes.

Obviously since I have published both private and public keys in the attachment you won't be able to use these for any serious encryption. You will have to generate your own key pairs and moduli to make proper use of these macros.

While testing these macros I discovered a small problem with the assembler, occasionally the run time will be double the usual if the source file is if the "wrong" length. This is because the generated code in memory within fasm is not aligned to any fixed boundary. I also submit a small change to the file 'PARSER.INC':
Code:
;between lines 40 and 41 I align the code to 16
        jne     invalid_value     ;<-- line 40
  add edi,15     ;<-- insert this line
  and edi,not 15 ;<-- and insert this line also
        mov     [code_start],edi  ;<-- line 41    


The attachment contains 3 files:
RSA-fasm.inc - The core macros
RSA-fasm-test.asm - Some basic tests to check functionality
RSA-fasm-example.asm - An example of possible use

This is the last of the three sets of macros I will post (SHA, Rijndael and RSA). I had originally intended to do a fourth with ECC encryption but since most of the interesting functions are similar to RSA I have decided not to do this. Feel free to add ECC to the set yourself, use the RSA macros as a starting point.

Why did I do this? I wanted to learn more about how to use the preprocessor and assembler and also how they interact. Making these macros has taught me many things that I will be able to apply to other projects. I hope you all can find good uses for these macros, and perhaps also learn how to do some tasks that you may have thought not possible. If you discover any new tricks and/or methods don't forget to post here.


Description: Macros for RSA in fasm
Download
Filename: RSA-fasm.zip
Filesize: 4.12 KB
Downloaded: 1030 Time(s)



Last edited by revolution on 23 Sep 2008, 08:43; edited 2 times in total
Post 23 Jul 2005, 17:16
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 23 Jul 2005, 17:41
Again great work. I also thought about learning the power of preprocessor 'in practice' and you gave me a great idea how to do this. Maybe if I will be able I will alse post something similar. Thanks
Post 23 Jul 2005, 17:41
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20342
Location: In your JS exploiting you and your system
revolution 31 Jul 2005, 01:34
I have updated the attachment above to fix the problem of multiply overflow with the new fasm version 1.63.3
Post 31 Jul 2005, 01:34
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 15 Sep 2005, 19:14
I tried using it and after it fnishes it.. The executable outputed is blank
Post 15 Sep 2005, 19:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20342
Location: In your JS exploiting you and your system
revolution 16 Sep 2005, 00:58
The code is not an executable, it is just an example of how it might be used. But you should get a small file with the encrypted signature and the public key and modulus included. Try using a hex editor to view the output.
Post 16 Sep 2005, 00:58
View user's profile Send private message Visit poster's website Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2 16 Sep 2005, 02:36
ya I figured that out after lol ... What a noob I am
Post 16 Sep 2005, 02:36
View user's profile Send private message Reply with quote
skingston



Joined: 11 Dec 2004
Posts: 19
skingston 10 Feb 2006, 01:24
How secure are these marcros? ie. how easy is it for someone to decrypt with the key?

I'm looking for some simple assembly routines that i can use to encrypt data between my program and a server, without having to use something like SSL, but still with as much security as possible.
Post 10 Feb 2006, 01:24
View user's profile Send private message Reply with quote
skingston



Joined: 11 Dec 2004
Posts: 19
skingston 10 Feb 2006, 01:31
How easy would it be to convert these macros to a program?

I only have limited knowledge on macros and do not know how RSA works. Is there a source (ie. info on RSA) you used to write the code?

I'm looking for some simple assembly routines that i can use to encrypt data between my program and a server, without having to use something like SSL, but still with as much security as possible.
Post 10 Feb 2006, 01:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20342
Location: In your JS exploiting you and your system
revolution 10 Feb 2006, 02:55
I don't have any direct links handy to post but there is plenty of information about this stuff on the WWW. Do a search for it in your favourite search engine. Visit the RSA site and download the original specifications. There is software available for many languages for free.
Post 10 Feb 2006, 02:55
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 10 Feb 2006, 17:00
To implement RSA download BigLib by fleur or other bignum library. In fact RSA is just a powmod function. So first read about RSA, understand how it works, then read BigLib's documentation on biglib_powmod() (or sth like this)
Post 10 Feb 2006, 17:00
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 10 Jan 2007, 17:50
It doesn't work with the latest release of FASM and I saw that parser already included these lines you included (though they are somewhere between lines 163..166). I got the same effect that its blank. It includes all the keys, but the encrypted message is blanked out (all zeroes).

The tests are even worse Sad they don't even compile - they only say that "halt-something went wrong" and I don't know how to debug it.

I want to get it working so I can convert it to PHP that doesn't have this function yet. The only problem then remains the 32-bit-ONLY PHP whereas FASM is 64-bit internally.
Post 10 Jan 2007, 17:50
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20342
Location: In your JS exploiting you and your system
revolution 10 Jan 2007, 23:14
Madis731 wrote:
It doesn't work with the latest release of FASM
The original macros I posted were for fasm 1.63. Since that time there have been some changes in fasm with regard to the handling of the hash (#) character.

I have replaced the attachment in the first post with the edited version that is compatible with fasm 1.67.18. I ran a quick verification test and it says "Okay" now.

BTW: the only change is that all double hashes (##) have become backslash-hash (\#).
Post 10 Jan 2007, 23:14
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 11 Jan 2007, 08:00
Wow, really thanks, now everything works as expected. I'll post the PHP somewhere if I ever get it finished.
Post 11 Jan 2007, 08:00
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
loki



Joined: 11 Feb 2011
Posts: 2
loki 11 Feb 2011, 16:34
Thank you very match, good job mmm!Wink
Post 11 Feb 2011, 16:34
View user's profile Send private message ICQ Number Reply with quote
loki



Joined: 11 Feb 2011
Posts: 2
loki 07 Sep 2011, 07:16
Good day, none of you did an example implementation of the client to the server FASM in PHP or similar to the key above 512, ideally 4096? sorry, my english is bad:(
Post 07 Sep 2011, 07:16
View user's profile Send private message ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.