It is currently Mon Oct 21, 2019 12:25 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: AESDecoder - input and output buffer can be the same!?
PostPosted: Thu Sep 27, 2018 10:43 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1704
Location: Germany (Saxony, Deutscheinsiedel)
Other than written in the PB docs (see here and here) it seems that something like "in-place" encrypting/decrypting is possible, which means the input and output buffer can be the same.

I myself use some code (originally written by walbus, see this example with self-overwriting function) successfully, which don't need different buffers.

So it should be proofed/checked, if the current limitation written in the docs is really valid.
Otherwise the docs should be adapted. Thank you!

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: AESDecoder - input and output buffer can be the same!?
PostPosted: Sat Sep 29, 2018 8:39 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1704
Location: Germany (Saxony, Deutscheinsiedel)
To be more specific, here is a short example which shows the possible 'in-place' encryption.
So the manual should be probably extended, showing this and mentioning that only CBC mode really need different buffers. The example code could be added as well...

Code:
; The bare AES function don't need two different buffers.
; Only for using CBC mode you need different input and output buffers - This is due to the way the CBC mode works.

; Caution! However, encrypting a string can create null bytes, which undesiretely terminate the string!

test$="ABCDEFG1234567" ; The length is at least 16 bytes, a further padding on a size divisible by 16 is not necessary

bytelength_string=StringByteLength(test$)

Debug test$

AESEncoder(@test$, @test$, bytelength_string, ?key, 128, 0, #PB_Cipher_ECB) ; No IV required for ECB mode

ShowMemoryViewer(@test$, bytelength_string+SizeOf(character)) ; You see, the encoder overwrite not the zero byte string termination,
                                                              ; although the string length is not divisible by 16

AESDecoder(@test$, @test$, bytelength_string, ?key, 128, 0, #PB_Cipher_ECB)

Debug test$

DataSection
  key:
  Data .b $06 , $a9 , $21 , $40 , $36 , $b8 , $a1 , $5b , $51 , $2e , $03 ,$d5 ,$34 , $12 , $00 , $06
EndDataSection

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: AESDecoder - input and output buffer can be the same!?
PostPosted: Sun Sep 30, 2018 10:49 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1969
Location: Germany
Have tested the ECB mode on large amounts of data and goes into in-place mode.

Maybe you can write that it goes into this mode in-place. But not recommended.
Just how you should take the standard mode CBC better.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: AESDecoder - input and output buffer can be the same!?
PostPosted: Sun Sep 30, 2018 7:23 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1704
Location: Germany (Saxony, Deutscheinsiedel)
As far as I know:
The CBC mode is one of various modes, which are base on the native AES ECB modues.
But it isn't the optimal solution and is therefore increasingly being replaced by other modes.


What's possible to do with all variants of AES encryption/decryption is shown here:
QAES AES256 KFB mode special coder for string, binary, text

But it's up to Fred / freak to change or better extend the PB docs with more notes and examples, as I don't have any special knowledge about encryption...

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye