Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

AES Encryption (software based)?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
techknight

Bascom Member



Joined: 21 Apr 2008
Posts: 230

usa.gif
PostPosted: Thu Jul 27, 2017 8:22 pm    Post subject: AES Encryption (software based)? Reply with quote

I know the xMega can do AES Encryption natively and I use it well.

but I got a couple of standard Mega ICs that I need to be able to work in the same environment as the xMegas, and that is AES.

I was wondering if someone has developed an AES software routine as well?

I found ASM code for AVR online for AES, but no idea how to implement it into BASCOM.

it is located here:

http://point-at-infinity.org/avraes/

Any ideas? Thanks.

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2470
Location: Queensland

australia.gif
PostPosted: Fri Jul 28, 2017 12:19 am    Post subject: Reply with quote

Bascom supports inline ASM. You should be able to just insert the code, and interface to the input and output, probably as byte arrays. Whether you have enough space left in mem to hold the arrays, plus what you want to do with them, is another question.

I now had a ( very ) brief look at the code, and see it uses ( naturally ) all of the registers, so you would have to do a pushall, popall around the code block so you dont clobber registers used by Bascom ( also most of them ). But after that, its only a matter of getting your data to the input and output text and key blocks.

_________________
Adrian Jansen
Computer language is a framework for creativity


Last edited by AdrianJ on Fri Jul 28, 2017 12:31 am; edited 1 time in total
Back to top
View user's profile Visit poster's website
techknight

Bascom Member



Joined: 21 Apr 2008
Posts: 230

usa.gif
PostPosted: Fri Jul 28, 2017 12:23 am    Post subject: Reply with quote

Well I kinda remember that.

But, what I was wanting to do, is take the existing XTEA LIB and just modify it with the code in that link and call it SOFTAES or something along those lines. Problem is, I dont know how the key and data is passed in and out of that library.

I am rusty on my ASM as its been years since I used it, But, The biggest problem is I am unsure how the compiler passes things in and out of libraries. I know with that particular library you can do xteaencode or xteadecode and the arguments are two byte arrays as you had mentioned to use.

But I don't know how the library "knows" where those are and how to use them. I was going to do a pushall/popall so I dont destroy any critical registers that could cause things to crash, but again I dunno which registers contain what. It would be nice if there was a tutorial or manual on how to write libraries for BASCOM-AVR.

as far as RAM, thats not an issue since I am using an ATMega1284P DIP.

Thanks for any input.
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2470
Location: Queensland

australia.gif
PostPosted: Fri Jul 28, 2017 12:36 am    Post subject: Reply with quote

The pushall/popall saves all the regs, so you should not clobber anything.

Should be possible just to load the address ( varptr gives you that ) of the strings you want, and send them to the appropriate registers in the AES code.

You dont need a library to do that. Once you have it working, you could of course convert it into a library, but I dont see much point if only you are going to use it. An #include file does essentially the same thing.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 260
Location: Berlin

germany.gif
PostPosted: Sat Jul 29, 2017 3:00 pm    Post subject: Reply with quote

PUSHALL and POPALL are not sufficient when you use "foreign" assembler code blocks. These commands will NOT save some of the "holy" BASCOM registers (see help).
Bascom uses following register exclusivly: r4, r5, r6, r8, r9 and Y (r28,r29) - see help "mixing ASM and BASIC" - the content of this register must not be altered between statements/subs/lib-routines/asm-blocks and these are the register you have to save! All other can be freely used in a programm.

PUSHALL/POPALL are created for interrupt routines.

I did a quick look to the "furios" code you have linked to and it is using r0-r18, r21,Y,Z. But r0-r18,r21 are defined with .def statments, so there are easily changeable. When you also change Y to X you shoud be able to use the code block without destroying bascom at all. You have to adapt the syntax anyway. Don't forget, if neccessary, to change lpm -> elpm and RAMPZ support for the ATMeag1284. See ADR2 and LOADADR to learn how to load X and Z with var- and labeladresses.

I agree with AdrianJ that you don't need to build a lib, just make a normal subroutine with embedded asm.
Back to top
View user's profile
uga237

Bascom Member



Joined: 15 May 2012
Posts: 32

blank.gif
PostPosted: Mon Mar 12, 2018 4:20 pm    Post subject: Reply with quote

AES-128 funtastic Bascom atxmega16e5(not have HW AES)
http://point-at-infinity.org/avraes/

Encrypt and decrypt one 128 bit block by 128 bit key.


Thank to Bascom for:
.align Wink

Dont forget JMP:

!jmp start
$include "aes_funtastic.inc"
Start:

And When i see:
$ORG and .org in Bascom? Smile
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5027
Location: Holland

blank.gif
PostPosted: Fri Mar 16, 2018 10:26 am    Post subject: Reply with quote

well done ! Thanks for sharing.

Of course there is the ! .org $someaddress

_________________
Mark
Back to top
View user's profile Visit poster's website
uga237

Bascom Member



Joined: 15 May 2012
Posts: 32

blank.gif
PostPosted: Fri Mar 16, 2018 2:24 pm    Post subject: Reply with quote

albertsm wrote:
Of course there is the ! .org $someaddress


Please Add this to Help. Thank You!
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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 cannot download files in this forum