flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Rijndael (and AES) macros for fasm

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


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Rijndael is the encryption scheme adopted by NIST for the AES. These macros support all the original Rijndael specification key and block sizes. ECB and CBC mode macros are included.

Encryption/decryption is not fast, about 350 bytes/second (using 128 bit key and block sizes) on my laptop.

Possible uses might be if you have small pieces of code and/or data that you want to encode within your executable. For larger sections I would recommend using an external program to do the work unless you are patient and don't mind waiting for assembly to complete.

The attachment contains 9 files:
Rijndael-fasm.inc - the core macros
Rijndael-fasm-verify.asm - verifying correct operation
test-vectors.inc - test vectors for sanity check
Rijndael-fasm-speed.asm - encrypts 100k, but be patient
ecb_vk.asm - generates ecb_vk.txt for comparison to Rijndael specification
ecb_vt.asm - generates ecb_vt.txt for comparison to Rijndael specification
test_run.bat - WIN-2K and WIN-XP batch doing verification and comparison
Reference\ecb_vk.txt - original Rijndael specification generated file
Reference\ecb_vt.txt - original Rijndael specification generated file


Description: Macros for Rijndael in fasm
Download
Filename: Rijndael-fasm.zip
Filesize: 36.77 KB
Downloaded: 436 Time(s)



Last edited by revolution on 14 Jun 2010, 04:12; edited 2 times in total
Post 23 Jul 2005, 02:33
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Oh yeah, you are a master. Just as with SHA macroses I didn't suspect that it is possible with current fasm macro capabilities. But you proved it. Congratulations Smile
Post 23 Jul 2005, 12:53
View user's profile Send private message Visit poster's website Reply with quote
skingston



Joined: 11 Dec 2004
Posts: 19
skingston
How easy would it be to convert the macros into a program? I would do this myself but I currently only have a limited knowledge of macros and I do not know how the algorithm works. Do you have info on the algorithm?
Post 10 Feb 2006, 01:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
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 authors site and download the original specifications. There is software available for many languages for free.
Post 10 Feb 2006, 02:54
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
On Witeg's page there are many algo implementations but in MASM. Here is AES implementation. It's always easier/faster to rewrite it than to make it whole new. And MASM->FASM isn't so hard to do.
Post 10 Feb 2006, 16:54
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Post 24 Aug 2006, 11:59
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
just for case you want neat AES implementation in C (also contains asm implementation for x86, written in YASM):
http://fp.gladman.plus.com/cryptography_technology/rijndael/
Post 30 Aug 2006, 08:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
ziral2088



Joined: 16 Aug 2009
Posts: 15
Location: Ukraine
ziral2088
Hi guys. I want to place encrypted strings in resource section, so i download these macroses, but i cant use them in right way(
I use 128 bit key and 128 block size. Macroses say ok, but they write zeroes instead of crypted data.
I try cbc and ecb - the result is the same.

Code:
..

UrlKey1                 =               845AF1F7h
UrlKey2                 =               863428ABh
UrlKey3                 =               845AF1F7h
UrlKey4                 =               863428ABh
UrlKey5                 =               845AF1F7h
UrlKey6                 =               863428ABh
UrlKey7                 =               845AF1F7h
UrlKey8                 =               863428ABh 

macro   simple_rijndael_fasm_encrypt key1 , key2 , key3 , key4 , key5 , key6 , key7 , key8 , pData , dwDataSize
{
    rijndael_fasm_init 128 , 128                                                                                                  ;key size 128, block size 128
    rijndael_fasm_key_schedule key1 , key2 , key3 , key4 , key5 , key6 , key7 , key8
    rijndael_fasm_encrypt_blocks_ecb pData , dwDataSize;cbc give the same result.
} 

macro PlaceInStringTableEncryptedString key1* , key2* , key3* , key4* , key5* , key6* , key7* , key8* , string*
{
    local size,s
    virtual at 0
        db string
        size = $
    end virtual
    dw size
    s = $
    du string
    simple_rijndael_fasm_encrypt key1 , key2 , key3 , key4 , key5 , key6 , key7 , key8 , s , size;(but here must be * 2, when i do so - error appear.)
}       
        PlaceInStringTableEncryptedString UrlKey1 , UrlKey2 , UrlKey3 , UrlKey4 , UrlKey5 , UrlKey6 , UrlKey7 , UrlKey8 ,\
                                          "teststring"               
    
Post 13 Jun 2010, 11:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
ziral2088: I have updated the attachment in the first post.

The previous attachment was for older versions of fasm.

The only change is that all double hashes ("##") have been changed to backslash-hash ("\#").
Post 14 Jun 2010, 04:15
View user's profile Send private message Visit poster's website Reply with quote
ziral2088



Joined: 16 Aug 2009
Posts: 15
Location: Ukraine
ziral2088
thank you Smile
Now all works.
Post 14 Jun 2010, 19:48
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Hi, I'm new with macros so, I don't understand it's algorithm.. Can someone tell me how to encrypt custom size of data ? for example "Hello World!" I've tried something like this but it fails.. Sad
Code:
include 'Rijndael-fasm.inc'

virtual at 0

;************************************************************
;CBC mode speed
;************************************************************

rijndael_test_data:
db "Hello World!",0

rijndael_fasm_init 128,128
rijndael_fasm_key_schedule 0,0,0,0,0,0,0,0
rijndael_fasm_encrypt_blocks_cbc rijndael_test_data,12

end virtual    
Post 29 Jun 2011, 09:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
Pad your data to the next block size (128 bits in your case):
Code:
db "Hello World!",4 dup 0 ;pad to 128 bits (16 bytes)    
Post 29 Jun 2011, 09:22
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Thank you.. Smile I though 128 was bytes not bits ^^
Post 29 Jun 2011, 10:00
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Now what I'm doing wrong here ?......
Code:
format PE CONSOLE 4.0
include 'WIN32AX.INC'
include 'ENCRYPTION\Rijndael.inc'
entry main
section '.data' data readable writeable
k1                 =               845AF1F7h
k2                 =               863428ABh
k3                 =               845AF1F7h
k4                 =               863428ABh
k5                 =               845AF1F7h
k6                 =               863428ABh
k7                 =               845AF1F7h
k8                 =               863428ABh
rijndael_data:
db "Hello World!",4 dup 0
section '.text' code readable executable
main:
        aes_128 rijndael_data,16,k1,k2,k3,k4,k5,k6,k7,k8
        invoke Sleep,-1
        ret    

aes_128 macro
Code:
macro aes_128 pData, size, key1, key2, key3, key4, key5, key6, key7, key8
{
   rijndael_fasm_init 128,128
  rijndael_fasm_key_schedule key1, key2, key3, key4, key5, key6, key7, key8
   rijndael_fasm_encrypt_blocks_ecb pData, size
}    

error = "value out of range."
Thanks.
Post 04 Jul 2011, 08:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
You won't be able to access data outside the current section. Move your encryption into the data section:
Code:
db "Hello World!",4 dup 0
        aes_128 rijndael_data,16,k1,k2,k3,k4,k5,k6,k7,k8
section '.text' code readable executable    
Post 06 Jul 2011, 05:18
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
ahh..... I don't understood for what macroses were and now I know.. Smile Thank you very much Smile
Post 06 Jul 2011, 06:13
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.