AESDecoder - input and output buffer can be the same!?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

AESDecoder - input and output buffer can be the same!?

Post by Andre »

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)
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: AESDecoder - input and output buffer can be the same!?

Post by Andre »

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: Select all

; 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)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: AESDecoder - input and output buffer can be the same!?

Post by mk-soft »

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 / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: AESDecoder - input and output buffer can be the same!?

Post by Andre »

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)
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] AESDecoder - input and output buffer can be the same!?

Post by Fred »

I don't know exactly how it behave with the same buffers and it can change in a future version, so to be on the safe side use different buffers.
Post Reply