Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #8585 > unrolled thread

AES256-ICM

Started byFranz Rachbauer <office@rachbauer.org>
First post2015-10-29 15:18 +0100
Last post2016-01-01 18:16 +0100
Articles 20 on this page of 33 — 7 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-10-29 15:18 +0100
    Re: AES256-ICM "Willie Moore" <williem@wmconsulting.com> - 2015-10-29 09:46 -0500
    Re: AES256-ICM Carlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com> - 2015-10-29 15:45 +0000
    Re: AES256-ICM Carlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com> - 2015-10-29 23:44 +0000
      Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-02 10:38 +0100
        Re: AES256-ICM Carlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com> - 2015-11-02 20:00 +0000
          Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-10 09:21 +0100
    Re: AES256-ICM sherlocksoftware@gmail.com - 2015-10-30 17:19 -0700
      Re: AES256-ICM Carlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com> - 2015-10-31 01:43 +0000
      Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-02 10:35 +0100
        Re: AES256-ICM sherlocksoftware@gmail.com - 2015-11-02 03:46 -0800
          Re: AES256-ICM sherlocksoftware@gmail.com - 2015-11-02 05:32 -0800
          Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-02 15:13 +0100
            Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-11-03 03:54 -0800
              Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-03 14:14 +0100
                Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-11-03 05:35 -0800
    Re: AES256-ICM "Jean Raymond" <jean_ray67@hotmail.com> - 2015-10-31 23:29 -0400
    Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-11-04 17:24 -0800
      Re: AES256-ICM "Wolfgang Riedmann" <wriedmann@gmail.com> - 2015-11-05 08:22 +0100
        Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-11-05 14:49 -0800
        Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-10 07:47 +0100
          Re: AES256-ICM "Wolfgang Riedmann" <wriedmann@gmail.com> - 2015-11-10 10:58 +0100
      Re: AES256-ICM "Willie Moore" <williem@wmconsulting.com> - 2015-11-05 06:58 -0600
    Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-11-04 19:47 -0800
      Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-11-10 08:19 +0100
      Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-12-29 09:11 +0100
        Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-12-29 19:49 -0800
          Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-12-30 09:36 +0100
            Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-12-30 13:53 -0800
              Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2015-12-31 09:32 +0100
                Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2015-12-31 01:11 -0800
                  Re: AES256-ICM Sherlock <sherlock@sherlock.com.au> - 2016-01-01 04:32 -0800
                  Re: AES256-ICM Franz Rachbauer <office@rachbauer.org> - 2016-01-01 18:16 +0100

Page 1 of 2  [1] 2  Next page →


#8585 — AES256-ICM

FromFranz Rachbauer <office@rachbauer.org>
Date2015-10-29 15:18 +0100
SubjectAES256-ICM
Message-ID<n0t9r2$us3$1@speranza.aioe.org>
Hi there,
I need an AES256-ICM decryption/encryption routine for VO, does anyone 
know one?

Regards, Franz

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

[toc] | [next] | [standalone]


#8586

From"Willie Moore" <williem@wmconsulting.com>
Date2015-10-29 09:46 -0500
Message-ID<n0tbga$3a1$1@speranza.aioe.org>
In reply to#8585
Franz,

Personally I would use the Crypto API from the dotNet framework and expose 
it as a com object that you can use in VO.

Regards,
Willie
Grafx Development Team

"Franz Rachbauer"  wrote in message news:n0t9r2$us3$1@speranza.aioe.org...

Hi there,
I need an AES256-ICM decryption/encryption routine for VO, does anyone
know one?

Regards, Franz

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus 

[toc] | [prev] | [next] | [standalone]


#8587

FromCarlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com>
Date2015-10-29 15:45 +0000
Message-ID<n0ter2$th1$1@dont-email.me>
In reply to#8585
After serious thinking Franz Rachbauer wrote :
> Hi there,
> I need an AES256-ICM decryption/encryption routine for VO, does anyone know 
> one?
>
Hello Franz,

Google pointed me to 
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28383566.html

It's VB6 but you can't translate it to VO because it uses bytearrays.
I can try to make an ActiveX DLL with VB6 if you are interested.

Or you can try Willie's suggestion and make that ActiveX DLL using 
WhereIsIt.IThoughtItWasHere.ItWasButNotAnymore.MaybeHere.Nope.CryptWhat.This.OhOk.ThankYou 
along with trillions of TB of dependencies. The advantage is that you 
have time take a coffee between calling the function and getting the 
result :')

-- 
Carlos Rocha

---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

[toc] | [prev] | [next] | [standalone]


#8590

FromCarlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com>
Date2015-10-29 23:44 +0000
Message-ID<n0ub0t$l0s$1@news.albasani.net>
In reply to#8585
I found that a (free) ActiveX DLL that I use since 2007 also has a 
Crypt class. It comes without documentation but method names are self 
explanatory.

I'm sure you can use it for what you want. Please post here if you have 
any doubt about it's usage (no "contact me in private BS")

http://www.vbrichclient.com/#/en/About/

-- 
Carlos Rocha

---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

[toc] | [prev] | [next] | [standalone]


#8598

FromFranz Rachbauer <office@rachbauer.org>
Date2015-11-02 10:38 +0100
Message-ID<n17avt$914$1@speranza.aioe.org>
In reply to#8590
Hi Carlos,
do you mean the AESEncrypt and AESDecrypt Methods in vbRichClient5? Can 
you tell me how to integrate these dll into my VO app, can I find an 
example to integrate a VB6 dll somewhere?

Regards, Franz

Am 30.10.2015 um 00:44 schrieb Carlos Rocha:
> I found that a (free) ActiveX DLL that I use since 2007 also has a Crypt
> class. It comes without documentation but method names are self
> explanatory.
>
> I'm sure you can use it for what you want. Please post here if you have
> any doubt about it's usage (no "contact me in private BS")
>
> http://www.vbrichclient.com/#/en/About/
>

[toc] | [prev] | [next] | [standalone]


#8602

FromCarlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com>
Date2015-11-02 20:00 +0000
Message-ID<n18f9i$vbs$1@dont-email.me>
In reply to#8598
Franz Rachbauer wrote :
> Hi Carlos,
> do you mean the AESEncrypt and AESDecrypt Methods in vbRichClient5? Can you 
> tell me how to integrate these dll into my VO app, can I find an example to 
> integrate a VB6 dll somewhere?
>
It might be AESEncrypt/AESDecrypt, but there are also other methods 
that seem related, and a few DiffieHellman properties. I'm not an 
expert in the matter.
A VB6 dll is an ActiveX dll. You can generate VO wrappers using 
"Tools/Atomation Server..." in the IDE.
With your project selected, create a new empty library with right click 
(New application/Basic/Empty Library) and select the new create 
library. As a start just select cCrypt in the rigth listbox, check 
"Include containing objects" and "Remove Underscores", and click in the 
button "Generate source". If you want to generate code for every class 
in vbRichClient5 select cFactory instead of cCrypt. There are lots of 
useful stuff in the library.


-- 
Carlos Rocha

---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

[toc] | [prev] | [next] | [standalone]


#8632

FromFranz Rachbauer <office@rachbauer.org>
Date2015-11-10 09:21 +0100
Message-ID<n1s9f0$a4k$1@speranza.aioe.org>
In reply to#8602
Hi Carlos,
thank you for informations! Do you know which params I have to use for 
Init(), AESEncrypt() and AESDecrypt?

hLib := LoadLibrary( PSZ(_CAST,"vbRichClient5.DLL" ) )
ocCrypt := cCrypt{
	ObjID,			// What is ObjID?
	fROTCHECK		// What is fROTCHECK?
		 }
cEnc := ocCrypt:AESEncrypt(
	B,			// array of byte => string
	KeyStringOrByteArray,	// ref usual => key
	AESStrength,		// usertype (long) => 256
	InitVector16,		// usual => What is this?
	KeyHashingSHA256	// logic => What is this?
			  }

cDecr:= ocCrypt:AESDecrypt(
	B,			// => cEnc
	KeyStringOrByteArray,
	AESStrength,
	InitVector16,
	KeyHashingSHA256
			  }

Franz

Am 02.11.2015 um 21:00 schrieb Carlos Rocha:
> Franz Rachbauer wrote :
>> Hi Carlos,
>> do you mean the AESEncrypt and AESDecrypt Methods in vbRichClient5?
>> Can you tell me how to integrate these dll into my VO app, can I find
>> an example to integrate a VB6 dll somewhere?
>>
> It might be AESEncrypt/AESDecrypt, but there are also other methods that
> seem related, and a few DiffieHellman properties. I'm not an expert in
> the matter.
> A VB6 dll is an ActiveX dll. You can generate VO wrappers using
> "Tools/Atomation Server..." in the IDE.
> With your project selected, create a new empty library with right click
> (New application/Basic/Empty Library) and select the new create library.
> As a start just select cCrypt in the rigth listbox, check "Include
> containing objects" and "Remove Underscores", and click in the button
> "Generate source". If you want to generate code for every class in
> vbRichClient5 select cFactory instead of cCrypt. There are lots of
> useful stuff in the library.
>
>

[toc] | [prev] | [next] | [standalone]


#8593

Fromsherlocksoftware@gmail.com
Date2015-10-30 17:19 -0700
Message-ID<1eb5e93b-d2d4-41df-8804-8487a0fa6b5a@googlegroups.com>
In reply to#8585
Frans.
snip[ I need an AES256-ICM decryption/encryption routine for VO, does anyone 
 know one? ]

Phil McGuinness
---------------

CLASS SHA256  

	// DESCRIPTION:
	// This class is used to generate a SHA-256 //digest// or //signature// of a string.
	// The SHA-256 algorithm is one of the industry standard methods for generating
	// digital signatures. It is generically known as a digest, digital signature,
	// one-way encryption, hash or checksum algorithm. A common use for SHA-256 is
	// for password encryption as it is one-way in nature, that does not mean that
	// your passwords are not free from a dictionary attack. If you are using the
	// routine for passwords, you can make it a little more secure by concatenating
	// some known random characters to the password before you generate the signature
	// and on subsequent tests, so even if a hacker knows you are using SHA-256 for
	// your passwords, the random characters will make it harder to dictionary attack.
	
	PROTECT DIM m_lOnBits[31] 	AS DWORD 
	PROTECT DIM m_l2Power[31] 	AS DWORD
	PROTECT DIM K[64] 						AS DWORD
	//
	DECLARE METHOD LShift                            // Left Shift
	DECLARE METHOD RShift                           	// Right Shift
	DECLARE METHOD AddUnsigned						//
	DECLARE METHOD Ch                            		// _XOR and _NOT	
	DECLARE METHOD Maj                             	// _XOR and _AND
	DECLARE METHOD S                                	// Right/Left Shift _AND
	DECLARE METHOD R                                 	// RightShift _AND
	DECLARE METHOD Sigma0                         // Sigma ZERO
	DECLARE METHOD Sigma1                         // Sigma ONE
	DECLARE METHOD Gamma0                       // Gamma ZERO
	DECLARE METHOD Gamma1                       // Gamma ONE
	DECLARE METHOD ConvertToWordArray     // Convert, padding according to the SHA-256 rules (similar to MD5 routine)
	DECLARE METHOD Cnv2Hex                       // Hex conversion     
	DECLARE METHOD GetSHA256            			// The only public method       
	//
METHOD Init() CLASS SHA256 

	m_lOnBits[1] := 1            // 00000000000000000000000000000001
	m_lOnBits[2] := 3            // 00000000000000000000000000000011
	m_lOnBits[3] := 7            // 00000000000000000000000000000111
	m_lOnBits[4] := 15           // 00000000000000000000000000001111
	m_lOnBits[5] := 31           // 00000000000000000000000000011111
	m_lOnBits[6] := 63           // 00000000000000000000000000111111
	m_lOnBits[7] := 127          // 00000000000000000000000001111111
	m_lOnBits[8] := 255          // 00000000000000000000000011111111
	m_lOnBits[9] := 511          // 00000000000000000000000111111111
	m_lOnBits[10] := 1023        // 00000000000000000000001111111111
	m_lOnBits[11] := 2047        // 00000000000000000000011111111111
	m_lOnBits[12] := 4095        // 00000000000000000000111111111111
	m_lOnBits[13] := 8191        // 00000000000000000001111111111111
	m_lOnBits[14] := 16383       // 00000000000000000011111111111111
	m_lOnBits[15] := 32767       // 00000000000000000111111111111111
	m_lOnBits[16] := 65535       // 00000000000000001111111111111111
	m_lOnBits[17] := 131071      // 00000000000000011111111111111111
	m_lOnBits[18] := 262143      // 00000000000000111111111111111111
	m_lOnBits[19] := 524287      // 00000000000001111111111111111111
	m_lOnBits[20] := 1048575     // 00000000000011111111111111111111
	m_lOnBits[21] := 2097151     // 00000000000111111111111111111111
	m_lOnBits[22] := 4194303     // 00000000001111111111111111111111
	m_lOnBits[23] := 8388607     // 00000000011111111111111111111111
	m_lOnBits[24] := 16777215    // 00000000111111111111111111111111
	m_lOnBits[25] := 33554431    // 00000001111111111111111111111111
	m_lOnBits[26] := 67108863    // 00000011111111111111111111111111
	m_lOnBits[27] := 134217727   // 00000111111111111111111111111111
	m_lOnBits[28] := 268435455   // 00001111111111111111111111111111
	m_lOnBits[29] := 536870911   // 00011111111111111111111111111111
	m_lOnBits[30] := 1073741823  // 00111111111111111111111111111111
	m_lOnBits[31] := 2147483647  // 01111111111111111111111111111111
	
	m_l2Power[1] := 1            // 00000000000000000000000000000001
	m_l2Power[2] := 2            // 00000000000000000000000000000010
	m_l2Power[3] := 4            // 00000000000000000000000000000100
	m_l2Power[4] := 8            // 00000000000000000000000000001000
	m_l2Power[5] := 16           // 00000000000000000000000000010000
	m_l2Power[6] := 32           // 00000000000000000000000000100000
	m_l2Power[7] := 64           // 00000000000000000000000001000000
	m_l2Power[8] := 128          // 00000000000000000000000010000000
	m_l2Power[9] := 256          // 00000000000000000000000100000000
	m_l2Power[10] := 512         // 00000000000000000000001000000000
	m_l2Power[11] := 1024        // 00000000000000000000010000000000
	m_l2Power[12] := 2048        // 00000000000000000000100000000000
	m_l2Power[13] := 4096        // 00000000000000000001000000000000
	m_l2Power[14] := 8192        // 00000000000000000010000000000000
	m_l2Power[15] := 16384       // 00000000000000000100000000000000
	m_l2Power[16] := 32768       // 00000000000000001000000000000000
	m_l2Power[17] := 65536       // 00000000000000010000000000000000
	m_l2Power[18] := 131072      // 00000000000000100000000000000000
	m_l2Power[19] := 262144      // 00000000000001000000000000000000
	m_l2Power[20] := 524288      // 00000000000010000000000000000000
	m_l2Power[21] := 1048576     // 00000000000100000000000000000000
	m_l2Power[22] := 2097152     // 00000000001000000000000000000000
	m_l2Power[23] := 4194304     // 00000000010000000000000000000000
	m_l2Power[24] := 8388608     // 00000000100000000000000000000000
	m_l2Power[25] := 16777216    // 00000001000000000000000000000000
	m_l2Power[26] := 33554432    // 00000010000000000000000000000000
	m_l2Power[27] := 67108864    // 00000100000000000000000000000000
	m_l2Power[28] := 134217728   // 00001000000000000000000000000000
	m_l2Power[29] := 268435456   // 00010000000000000000000000000000
	m_l2Power[30] := 536870912   // 00100000000000000000000000000000
	m_l2Power[31] := 1073741824  // 01000000000000000000000000000000
	
	// Just put together the K array once
	K[1] := 0x428A2F98
	K[2] := 0x71374491
	K[3] := 0xB5C0FBCF
	K[4] := 0xE9B5DBA5
	K[5] := 0x3956C25B
	K[6] := 0x59F111F1
	K[7] := 0x923F82A4
	K[8] := 0xAB1C5ED5
	K[9] := 0xD807AA98
	K[10] := 0x12835B01
	K[11] := 0x243185BE
	K[12] := 0x550C7DC3
	K[13] := 0x72BE5D74
	K[14] := 0x80DEB1FE
	K[15] := 0x9BDC06A7
	K[16] := 0xC19BF174
	K[17] := 0xE49B69C1
	K[18] := 0xEFBE4786
	K[19] := 0xFC19DC6
	K[20] := 0x240CA1CC
	K[21] := 0x2DE92C6F
	K[22] := 0x4A7484AA
	K[23] := 0x5CB0A9DC
	K[24] := 0x76F988DA
	K[25] := 0x983E5152
	K[26] := 0xA831C66D
	K[27] := 0xB00327C8
	K[28] := 0xBF597FC7
	K[29] := 0xC6E00BF3
	K[30] := 0xD5A79147
	K[31] := 0x6CA6351
	K[32] := 0x14292967
	K[33] := 0x27B70A85
	K[34] := 0x2E1B2138
	K[35] := 0x4D2C6DFC
	K[36] := 0x53380D13
	K[37] := 0x650A7354
	K[38] := 0x766A0ABB
	K[39] := 0x81C2C92E
	K[40] := 0x92722C85
	K[41] := 0xA2BFE8A1
	K[42] := 0xA81A664B
	K[43] := 0xC24B8B70
	K[44] := 0xC76C51A3
	K[45] := 0xD192E819
	K[46] := 0xD6990624
	K[47] := 0xF40E3585
	K[48] := 0x106AA070
	K[49] := 0x19A4C116
	K[50] := 0x1E376C08
	K[51] := 0x2748774C
	K[52] := 0x34B0BCB5
	K[53] := 0x391C0CB3
	K[54] := 0x4ED8AA4A
	K[55] := 0x5B9CCA4F
	K[56] := 0x682E6FF3
	K[57] := 0x748F82EE
	K[58] := 0x78A5636F
	K[59] := 0x84C87814
	K[60] := 0x8CC70208
	K[61] := 0x90BEFFFA
	K[62] := 0xA4506CEB
	K[63] := 0xBEF9A3F7
	K[64] := 0xC67178F2
	//
	RETURN SELF 

PROTECT METHOD LShift( dwValue AS DWORD, dwBits AS DWORD ) AS DWORD PASCAL CLASS SHA256
	RETURN dwValue << dwBits

PROTECT METHOD RShift( dwValue AS DWORD, dwBits AS DWORD ) AS DWORD PASCAL CLASS SHA256
	RETURN dwValue >> dwBits

PROTECT METHOD AddUnsigned( dwX AS DWORD, dwY AS DWORD ) AS DWORD PASCAL CLASS SHA256    

	LOCAL dwX4     AS DWORD
	LOCAL dwY4     AS DWORD
	LOCAL dwX8     AS DWORD
	LOCAL dwY8     AS DWORD
	LOCAL dwResult AS DWORD

	dwX8 := _AND(dwX, 0x80000000)
	dwY8 := _AND(dwY, 0x80000000)
	dwX4 := _AND(dwX, 0x40000000)
	dwY4 := _AND(dwY, 0x40000000)

	dwResult := _AND(dwX, 0x3FFFFFFF) + _AND(dwY, 0x3FFFFFFF)

	IF _AND(dwX4, dwY4) > 0
		dwResult := _XOR(dwResult, 0x80000000, dwX8, dwY8)
	ELSEIF _OR(dwX4, dwY4) > 0
		IF _AND(dwResult, 0x40000000) > 0
			dwResult := _XOR(dwResult, 0xC0000000, dwX8, dwY8)
		ELSE
			dwResult := _XOR(dwResult, 0x40000000, dwX8, dwY8)
		ENDIF
	ELSE
		dwResult := _XOR(dwResult, dwX8, dwY8)
	ENDIF  
	//
	RETURN dwResult

PROTECT METHOD Ch(X AS DWORD, Y AS DWORD, Z AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(_AND(X, Y), _AND(_NOT(X), Z)) 

PROTECT METHOD Maj(X AS DWORD, Y AS DWORD, Z AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(_AND(X, Y), _AND(X, Z), _AND(Y, Z))

PROTECT METHOD S(X AS DWORD, N AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _OR(SELF:RShift(X, _AND(N, m_lOnBits[5])), SELF:LShift(X, (32 - _AND(N, m_lOnBits[5]))))

PROTECT METHOD R(X AS DWORD, N AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN SELF:RShift(X, _AND(N, m_lOnBits[5]))

PROTECT METHOD Sigma0(X AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(SELF:S(X, 2), SELF:S(X, 13), SELF:S(X, 22))

PROTECT METHOD Sigma1(X AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(SELF:S(X, 6), SELF:S(X, 11), SELF:S(X, 25))

PROTECT METHOD Gamma0(X AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(SELF:S(X, 7), SELF:S(X, 18), SELF:R(X, 3))

PROTECT METHOD Gamma1(X AS DWORD) AS DWORD PASCAL CLASS SHA256
	RETURN _XOR(SELF:S(X, 17), SELF:S(X, 19), SELF:R(X, 10))

PROTECT METHOD ConvertToWordArray( cMessage AS STRING ) AS ARRAY PASCAL CLASS SHA256
	// Takes the string message and puts it in a long array with padding according to
	// the SHA-256 rules (similar to MD5 routine).
	LOCAL dwMessageLength   AS DWORD
	LOCAL dwNumberOfWords   AS DWORD
	LOCAL dwBytePosition    AS DWORD
	LOCAL dwByteCount       AS DWORD
	LOCAL dwWordCount       AS DWORD
	LOCAL dwByte            AS DWORD 
	LOCAL dwTmp             AS DWORD
	LOCAL dwWordArray      AS ARRAY 
	LOCAL MODULUS_BITS := 512 AS DWORD 
	LOCAL CONGRUENT_BITS := 448 AS DWORD
	
	dwMessageLength := SLen(CMessage)
	// Get padded number of words. Message needs to be congruent to 448 bits,
	// modulo 512 bits. If it is exactly congruent to 448 bits, modulo 512 bits
	// it must still have another 512 bits added. 512 bits = 64 bytes
	// (or 16 * 4 byte words), 448 bits = 56 bytes. This means lNumberOfWords must
	// be a multiple of 16 (i.e. 16 * 4 (bytes) * 8 (bits))
	dwNumberOfWords := (((dwMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) / 8)) / (MODULUS_BITS / 8)) + 1) * (MODULUS_BITS / 32)
	dwWordArray := ArrayCreate(dwNumberOfWords) 
	//
	FOR dwByte := 1 UPTO dwNumberOfWords 
		dwWordArray[dwByte] := 0
	NEXT
	
	// Combine each block of 4 bytes (ascii code of character) into one long
	// value and store in the message. The high-order (most significant) bit of
	// each byte is listed first. However, unlike MD5 we put the high-order
	// (most significant) byte first in each word.
	dwBytePosition := 0
	dwByteCount := 0
	//
	DO WHILE dwByteCount < dwMessageLength
		dwWordCount := dwByteCount / 4
		dwBytePosition := (3 - (dwByteCount % 4)) * 8
		dwByte := Asc(SubStr(cMessage, dwByteCount + 1, 1))
		//	
		dwTmp := dwWordArray[dwWordCount + 1]
		dwTmp := _OR(dwTmp, SELF:LShift(dwByte, dwBytePosition))
		dwWordArray[dwWordCount + 1] := dwTmp
		dwByteCount := dwByteCount + 1
	ENDDO 
	
	// Terminate according to SHA-256 rules with a 1 bit, zeros and the length in
	// bits stored in the last two words
	dwWordCount := dwByteCount / 4
	dwBytePosition := (3 - (dwByteCount % 4)) * 8
	// Add a terminating 1 bit, all the rest of the bits to the end of the
	// word array will default to zero
	dwTmp := dwWordArray[dwWordCount + 1]
	dwTmp := _OR(dwTmp, SELF:LShift(0x80, dwBytePosition))
	dwWordArray[dwWordCount + 1] := dwTmp
	
	// We put the length of the message in bits into the last two words, to get
	// the length in bits we need to multiply by 8 (or left shift 3). This left
	// shifted value is put in the last word. Any bits shifted off the left edge
	// need to be put in the penultimate word, we can work out which bits by shifting
	// right the length by 29 bits.  
	dwWordArray[dwNumberOfWords] := SELF:LShift(dwMessageLength, 3)
	dwWordArray[dwNumberOfWords - 2] := SELF:RShift(dwMessageLength, 29)
	//	
	RETURN dwWordArray 

METHOD GetSHA256( cMessage AS STRING ) AS STRING PASCAL CLASS SHA256  
	// Takes a string and uses the SHA-256 digest to produce a signature for it.
	LOCAL DIM HASH[8] AS DWORD
	LOCAL M AS ARRAY
	LOCAL DIM W[64] AS DWORD   
	LOCAL a, b, c, d, e, f, g, h, i, j, T1, T2 AS DWORD 
	LOCAL cOut AS STRING
	
	// Initial hash values
	HASH[1] := 0x6A09E667
	HASH[2] := 0xBB67AE85
	HASH[3] := 0x3C6EF372
	HASH[4] := 0xA54FF53A
	HASH[5] := 0x510E527F
	HASH[6] := 0x9B05688C
	HASH[7] := 0x1F83D9AB
	HASH[8] := 0x5BE0CD19
	
	// Preprocessing. Append padding bits and length and convert to words
	M := SELF:ConvertToWordArray(CMessage) 
	
	FOR j := 1 UPTO 64
		W[j] := 0
	NEXT

	// Main loop
	FOR i := 0 UPTO ALen(M) - 1 STEP 16
		a := HASH[1]
		b := HASH[2]
		c := HASH[3]
		d := HASH[4]
		e := HASH[5]
		f := HASH[6]
		g := HASH[7]
		h := HASH[8]
		//
		FOR j := 0 UPTO 63
			IF j < 16
				W[j + 1] := M[j + i + 1]
			ELSE
				W[j + 1] := SELF:AddUnsigned(SELF:AddUnsigned(SELF:AddUnsigned(SELF:Gamma1(W[j - 1]), W[j - 6]), SELF:Gamma0(W[j - 14])), W[j - 15])
			END IF
			//
			T1 := SELF:AddUnsigned(SELF:AddUnsigned(SELF:AddUnsigned(SELF:AddUnsigned(h, SELF:Sigma1(e)), SELF:Ch(e, f, g)), K[j + 1]), W[j + 1])
			T2 := SELF:AddUnsigned(SELF:Sigma0(a), SELF:Maj(a, b, c))
			//
			h := g
			g := f
			f := e
			e := SELF:AddUnsigned(d, T1)
			d := c
			c := b
			b := a
			a := SELF:AddUnsigned(T1, T2)
		NEXT
		//
		HASH[1] := SELF:AddUnsigned(a, HASH[1])
		HASH[2] := SELF:AddUnsigned(b, HASH[2])
		HASH[3] := SELF:AddUnsigned(c, HASH[3])
		HASH[4] := SELF:AddUnsigned(d, HASH[4])
		HASH[5] := SELF:AddUnsigned(e, HASH[5])
		HASH[6] := SELF:AddUnsigned(f, HASH[6])
		HASH[7] := SELF:AddUnsigned(g, HASH[7])
		HASH[8] := SELF:AddUnsigned(h, HASH[8])
	NEXT
	
	// Output the 256 bit digest
	cOut := SELF:Cnv2Hex(HASH[1]) + SELF:Cnv2Hex(HASH[2]) + SELF:Cnv2Hex(HASH[3]) + SELF:Cnv2Hex(HASH[4])
	cOut := cOut + SELF:Cnv2Hex(HASH[5]) + SELF:Cnv2Hex(HASH[6]) + SELF:Cnv2Hex(HASH[7]) + SELF:Cnv2Hex(HASH[8])
	//
	RETURN cOut
	
PROTECT METHOD Cnv2Hex(dwNum AS DWORD) AS STRING PASCAL CLASS SHA256
	RETURN Lower(Right("00000000" + AsHexString(dwNum), 8))

[toc] | [prev] | [next] | [standalone]


#8594

FromCarlos Rocha <JDOTCarlosDOTRochaDOT1@SpiedBy.gmail.com>
Date2015-10-31 01:43 +0000
Message-ID<n116cd$5id$1@news.albasani.net>
In reply to#8593
Phil,

Nice one. Thank you for sharing

-- 
Carlos Rocha

---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

[toc] | [prev] | [next] | [standalone]


#8597

FromFranz Rachbauer <office@rachbauer.org>
Date2015-11-02 10:35 +0100
Message-ID<n17ap3$87c$1@speranza.aioe.org>
In reply to#8593
Hi Phil,
is SHA256 the same as AES256? I think AES256 is a two-way crypt and 
SHA256 is one-way similar to MD5 Hash?

Regards Franz

Am 31.10.2015 um 01:19 schrieb sherlocksoftware@gmail.com:
> Frans.
> snip[ I need an AES256-ICM decryption/encryption routine for VO, does anyone
>   know one? ]
>
> Phil McGuinness
> ---------------
>
> CLASS SHA256
>
> 	// DESCRIPTION:
> 	// This class is used to generate a SHA-256 //digest// or //signature// of a string.
> 	// The SHA-256 algorithm is one of the industry standard methods for generating
> 	// digital signatures. It is generically known as a digest, digital signature,
> 	// one-way encryption, hash or checksum algorithm. A common use for SHA-256 is
> 	// for password encryption as it is one-way in nature, that does not mean that
> 	// your passwords are not free from a dictionary attack. If you are using the
> 	// routine for passwords, you can make it a little more secure by concatenating
> 	// some known random characters to the password before you generate the signature
> 	// and on subsequent tests, so even if a hacker knows you are using SHA-256 for
> 	// your passwords, the random characters will make it harder to dictionary attack.
> 	

[toc] | [prev] | [next] | [standalone]


#8599

Fromsherlocksoftware@gmail.com
Date2015-11-02 03:46 -0800
Message-ID<d3f463b0-2406-4c2b-87dd-e38aae2b8882@googlegroups.com>
In reply to#8597
Franz

Yes this is not what you are after. Used like MD5 that the data is the data matched the key.

SHA stands for Secure Hash Algorithm while AES stands for Advanced Encryption Standard. So SHA is a suite of hashing algorithms. AES on the other hand is a cipher which is used to encrypt. SHA algorithms (SHA-1, SHA-256 etc...) will take an input and produce a digest (hash), this is typically used in a digital signing process (produce a hash of some bytes and sign with a private key). 


Phil

[toc] | [prev] | [next] | [standalone]


#8600

Fromsherlocksoftware@gmail.com
Date2015-11-02 05:32 -0800
Message-ID<58bcd33f-ba11-45d4-ae06-e50891bc95a4@googlegroups.com>
In reply to#8599
Franz

I did find the source code for AES256... let one of guys look if it is an easy port to VO..

Phil

[toc] | [prev] | [next] | [standalone]


#8601

FromFranz Rachbauer <office@rachbauer.org>
Date2015-11-02 15:13 +0100
Message-ID<n17r26$jrp$1@speranza.aioe.org>
In reply to#8599
Hi Phil,

Am 02.11.2015 um 12:46 schrieb sherlocksoftware@gmail.com:
  AES on the other hand is a cipher which is used to encrypt. SHA
  algorithms (SHA-1, SHA-256 etc...) will take an input and produce a 
digest (hash), this is typically used
  in a digital signing process (produce a hash of some bytes and sign 
with a private key).

I have to sign financal data for the tax office in my POS software, 
that's why AES256 is needed!

Regards, Franz

[toc] | [prev] | [next] | [standalone]


#8604

FromSherlock <sherlock@sherlock.com.au>
Date2015-11-03 03:54 -0800
Message-ID<e31800ed-0334-43d2-8cec-85435e9ce5e5@googlegroups.com>
In reply to#8601
Franz

Found the AES256 code in C and tested it today against other web testing tools for input / output and it works.

Code is not that much bigger than the other code.
My guy time permitting will have it ported to VO in next day or so.


Phil

[toc] | [prev] | [next] | [standalone]


#8605

FromFranz Rachbauer <office@rachbauer.org>
Date2015-11-03 14:14 +0100
Message-ID<n1abvl$tsc$1@speranza.aioe.org>
In reply to#8604
Hi Phil.
this are wonderful news!
Franz

Am 03.11.2015 um 12:54 schrieb Sherlock:
> Franz
>
> Found the AES256 code in C and tested it today against other web testing tools for input / output and it works.
>
> Code is not that much bigger than the other code.
> My guy time permitting will have it ported to VO in next day or so.
>
>
> Phil
>

[toc] | [prev] | [next] | [standalone]


#8606

FromSherlock <sherlock@sherlock.com.au>
Date2015-11-03 05:35 -0800
Message-ID<aa17c478-1cd8-424c-840b-ff2e0b2f2975@googlegroups.com>
In reply to#8605
Franz

Interesting.. almost reassuring..

A 256bit encryption is the mathematical equivalent of 2256 key possibilities. To put that into perspective, 232 is about 4.3 billion, and it keeps growing exponentially after that. What does this mean though? Well simply put, let's say hypothetically all the super computers in the world (the ultimate brute force attack) decided to group up and tasked themselves to decrypt your AES-256 key so they could access your data. Assume they could look at 250 keys per second (which is approximately one quadrillion keys/second - a very generous assumption). A year is approximately 31,557,600 seconds. This means that by using the one billion super computers required to do this, they could check about 275 keys per year. At this rate it would take these computers 234 years (the age of our universe) to look at less than .01% of the entire key possibilities. The bottom line? No one will be breaking your encrypted data

Phil

[toc] | [prev] | [next] | [standalone]


#8595

From"Jean Raymond" <jean_ray67@hotmail.com>
Date2015-10-31 23:29 -0400
Message-ID<n140q2$lo7$2@dont-email.me>
In reply to#8585

[Multipart message — attachments visible in raw view] — view raw

Franz...

See:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908(v=vs.85).aspx

See AES256 ID (CALG_AES_256):
https://msdn.microsoft.com/en-us/library/windows/desktop/aa375549(v=vs.85).aspx

See .mef module (RegKeyFile - Free Functions - MD5-SHA1.MEF) attached, for
functions to crypt MD5 and SHA1, they can be modified to
include your AES256.
/-----------------------------------------------------------------------------------------
REF:
/*
De:Ginny Caughey (70714.1741@compuserve.com)
Assunto:Re: MD5 in VO?STATIC FUNCTION __Crypt_MD5_SHA1(cdata AS
STRING,cHashValue REF STRING, lMDA AS LOGIC) AS LOGIC
LOCAL lresult AS LOGIC

/*
De:Ginny Caughey (70714.1741@compuserve.com)
Assunto:Re: MD5 in VO?

Newsgroups:comp.lang.clipper.visual-objects
Data:2000-09-19 12:35:03 PST

Sligthly adapted by Adriano Rui Gominho // v1.5b  30-Set-2004 17:51:48

*/
/-----------------------------------------------------------------------------------------
Hope this will help

Best regards
Jean Raymond
Publisher of cmVodbx32 DBF manager
http://www.rayonline.com


/------------------------------------------------------------------------------------------------

"Franz Rachbauer"  wrote in message news:n0t9r2$us3$1@speranza.aioe.org...

Hi there,
I need an AES256-ICM decryption/encryption routine for VO, does anyone
know one?

Regards, Franz

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus 

[toc] | [prev] | [next] | [standalone]


#8608

FromSherlock <sherlock@sherlock.com.au>
Date2015-11-04 17:24 -0800
Message-ID<fd5057ae-7641-4bc0-9e84-ed3e2675e90c@googlegroups.com>
In reply to#8585
Franz

Here it is... please report any issues you may have.. but good old VO code does it again.

CLASS AES256 
//   Byte-oriented AES-256 implementation.
//   All lookup tables replaced with 'on the fly' calculations. 
//
//   Originally written in C.. Copyright (c) 2007-2009 Ilya O. Levin, 
//   http://www.literatecode.com / Other contributors: Hal Finney
//  
//   Implemented in VO (c) 2015 Sherlock Software http://www.sherlock.com.au 
//   Good work.. Ales Suchac.. 
//
//   Permission to use, copy, modify, and distribute this software for any
//   purpose with or without fee is hereby granted, provided that the above
//   copyright notice and this permission notice appear in all copies.
//
//   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
//   WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
//   MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
//   ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
//   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
//   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
//   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// ONLINE validation routine: http://aes.online-domain-tools.com/

    
    DECLARE METHOD Init             // Initalize class - it also initializes internal keys from 32-character encryption key
    DECLARE METHOD Encrypt          // Encrypts string of any length (it is internally filled up by NULL characters (ASCII code 0) up to next multiple of 16 
    DECLARE METHOD Decrypt          // Decrypts string of any length as returned by function Encrypt so the string's length must be multiple of 16
    
    // ------------------------------------- Private stuff -------------------------------------------
    PROTECT key AS BYTE PTR  
    PROTECT enckey AS BYTE PTR  
    PROTECT deckey AS BYTE PTR
   
    PROTECT sbox AS BYTE PTR  
    PROTECT sboxinv AS BYTE PTR
    PROTECT lInitialised := FALSE AS LOGIC      // Encryption/Decryption works only if this is true. This is set to true only when the encryption key is 32-char long
      
    // --------------------------------------- Protect methods ----------------------------------------
    DECLARE METHOD EncryptEcbArray  // Encrypts 16-chaaracter long part of byte array from given offset
    DECLARE METHOD DecryptEcbArray  // Decrypts 16-chaaracter long part of byte array from given offset
    
    DECLARE METHOD InitArrays
    DECLARE METHOD Str2ByteArray
    DECLARE METHOD ByteArray2Str   
    DECLARE METHOD rj_xtime
    DECLARE METHOD FD
    DECLARE METHOD aes_subBytes 
    DECLARE METHOD aes_subBytes_inv
    DECLARE METHOD aes_addRoundKeyX
    DECLARE METHOD aes_addRoundKey_cpy
    DECLARE METHOD aes_shiftRows
    DECLARE METHOD aes_shiftRows_inv
    DECLARE METHOD aes_mixColumns
    DECLARE METHOD aes_mixColumns_inv
    DECLARE METHOD aes_expandEncKey
    DECLARE METHOD aes_expandDecKey
    
    DECLARE METHOD ByteAnd
    DECLARE METHOD ByteOr
    DECLARE METHOD ByteXor
    DECLARE METHOD ByteNot
    DECLARE METHOD ByteShiftL
    DECLARE METHOD ByteShiftR
    
    DECLARE METHOD FreeArrays
    
METHOD Init(cKey AS STRING) CLASS AES256
    LOCAL k AS BYTE PTR
    LOCAL rcon AS BYTE
    LOCAL i AS DWORD
    
    IF SLen(cKey) == 32
        k := SELF:Str2ByteArray(cKey, 32)
        
        SELF:key := MemAlloc(32)
        SELF:enckey := MemAlloc(32)
        SELF:deckey := MemAlloc(32)
        SELF:sbox := MemAlloc(256)
        SELF:sboxinv := MemAlloc(256)
        
        IF (k == NULL_PTR) .OR. (SELF:key == NULL_PTR) .OR. (SELF:enckey == NULL_PTR) .OR. (SELF:deckey == NULL_PTR) .OR. (SELF:sbox == NULL_PTR) .OR. (SELF:sboxinv == NULL_PTR)
            SELF:FreeArrays()
            IF k != NULL_PTR
                MemFree(k)
            ENDIF
        ELSE 
            SELF:InitArrays()
            
            FOR i := 1 TO 32    
                SELF:key[i] := 0
                SELF:enckey[i] := k[i]
                SELF:deckey[i] := k[i]            
            NEXT
            
            rcon := 1
            
            FOR i := 1 TO 7
                SELF:aes_expandEncKey(SELF:deckey, @rcon)
            NEXT  
            
            MemFree(k)
            SELF:lInitialised := TRUE
        ENDIF
    ENDIF
    RegisterAxit(SELF)
    
RETURN SELF

PROTECT METHOD InitArrays() AS VOID PASCAL CLASS AES256
    LOCAL a AS ARRAY
   LOCAL i AS DWORD 
     
    a := { 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0 , ;
    0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15 , ;
    0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, ;
    0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, ;
    0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, ;
    0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, ;
    0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, ;
    0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, ;
    0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, ;
    0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, ;
    0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB }      // You can initialise an array with only up to 255 members
    AAdd(a, 0x16)
    
    FOR i := 1 TO 256
        SELF:sbox[i] := a[i]
    NEXT
    
    a := { 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, ;
    0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, ;
    0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, ;
    0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, ;
    0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, ;
    0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, ;
    0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, ;
    0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, ;
    0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, ;
    0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, ;
    0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C }      // You can initialise an array with only up to 255 members
    AAdd(a, 0x7D)
    
    FOR i := 1 TO 256
        SELF:sboxinv[i] := a[i]
    NEXT
    
RETURN  

PROTECT METHOD Str2ByteArray(cStr AS STRING, dwLen AS DWORD) AS BYTE PTR PASCAL CLASS AES256
    LOCAL buf AS BYTE PTR
    LOCAL i AS DWORD
    
    buf := MemAlloc(dwLen)
    IF buf != NULL_PTR
        FOR i := 1 TO dwLen
            buf[i] := BYTE(Asc(SubStr(cStr, i, 1)))
        NEXT
    ENDIF
RETURN buf     

PROTECT METHOD aes_expandEncKey(k AS BYTE PTR, rc REF BYTE) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD
    
    k[1] := SELF:ByteXor(SELF:ByteXor(k[1], sbox[k[30] + 1]), rc)  
    k[2] := SELF:ByteXor(k[2], sbox[k[31] + 1]) 
    k[3] := SELF:ByteXor(k[3], sbox[k[32] + 1]) 
    k[4] := SELF:ByteXor(k[4], sbox[k[29] + 1]) 
    rc := SELF:rj_xtime(rc)
    
    i := 5
    DO WHILE i < 17
        k[i] := SELF:ByteXor(k[i], k[i - 4])
        k[i + 1] := SELF:ByteXor(k[i + 1], k[i - 3])
        k[i + 2] := SELF:ByteXor(k[i + 2], k[i - 2])
        k[i + 3] := SELF:ByteXor(k[i + 3], k[i - 1])
        i += 4
    ENDDO 
    
    k[17] := SELF:ByteXor(k[17], sbox[k[13] + 1]) 
    k[18] := SELF:ByteXor(k[18], sbox[k[14] + 1]) 
    k[19] := SELF:ByteXor(k[19], sbox[k[15] + 1]) 
    k[20] := SELF:ByteXor(k[20], sbox[k[16] + 1])
    
    i := 21
    DO WHILE i < 33
        k[i] := SELF:ByteXor(k[i], k[i - 4])
        k[i + 1] := SELF:ByteXor(k[i + 1], k[i - 3])
        k[i + 2] := SELF:ByteXor(k[i + 2], k[i - 2])
        k[i + 3] := SELF:ByteXor(k[i + 3], k[i - 1])
        i += 4
    ENDDO 
RETURN 
      
PROTECT METHOD rj_xtime(x AS BYTE) AS BYTE PASCAL CLASS AES256 
    LOCAL y AS BYTE
    
    y := SELF:ByteShiftL(x, 1)
RETURN IIF(_AND(x, 0x80) > 0, _XOR(y, 0x1B), y)

PROTECT METHOD aes_subBytes(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD 
    
    FOR i := 16 DOWNTO 1
        buf[i] := SELF:sbox[buf[i] + 1]
    NEXT
RETURN

PROTECT METHOD aes_subBytes_inv(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD 
    
    FOR i := 16 DOWNTO 1
        buf[i] := SELF:sboxinv[buf[i] + 1]
    NEXT
RETURN

PROTECT METHOD aes_addRoundKey_cpy(buf AS BYTE PTR, key AS BYTE PTR, cpk AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD 
    
    FOR i := 16 DOWNTO 1                      
        cpk[i] := key[i]
        buf[i] := SELF:ByteXor(buf[i], cpk[i])
        cpk[16 + i] := key[16 + i]
    NEXT
RETURN

PROTECT METHOD aes_shiftRows(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256  
    LOCAL i, j AS BYTE 
    
    i := buf[2]
    buf[2] := buf[6]
    buf[6] := buf[10]
    buf[10] := buf[14]
    buf[14] := i
    
    i := buf[11]
    buf[11] := buf[3]
    buf[3] := i
    
    j := buf[4]
    buf[4] := buf[16]
    buf[16] := buf[12]
    buf[12] := buf[8]
    buf[8] := j
    
    j := buf[15]
    buf[15] := buf[7]
    buf[7] := j
RETURN

PROTECT METHOD aes_shiftRows_inv(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i, j AS BYTE 
    
    i := buf[2]
    buf[2] := buf[14]
    buf[14] := buf[10]
    buf[10] := buf[6]
    buf[6] := i
    
    i := buf[3]
    buf[3] := buf[11]
    buf[11] := i
    
    j := buf[4]
    buf[4] := buf[8]
    buf[8] := buf[12]
    buf[12] := buf[16]
    buf[16] := j
    
    j := buf[7]
    buf[7] := buf[15]
    buf[15] := j
RETURN

PROTECT METHOD aes_mixColumns(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD
    LOCAL a, b, c, d, e AS BYTE 
                                
    i := 1
    DO WHILE i < 17
        a := buf[i]
        b := buf[i + 1]
        c := buf[i + 2]
        d := buf[i + 3] 
        e := SELF:ByteXor(SELF:ByteXor(SELF:ByteXor(a, b), c), d)
        buf[i] := SELF:ByteXor(SELF:ByteXor(buf[i], e), SELF:rj_xtime(SELF:ByteXor(a, b)))
        buf[i + 1] := SELF:ByteXor(SELF:ByteXor(buf[i + 1], e), SELF:rj_xtime(SELF:ByteXor(b, c)))
        buf[i + 2] := SELF:ByteXor(SELF:ByteXor(buf[i + 2], e), SELF:rj_xtime(SELF:ByteXor(c, d)))
        buf[i + 3] := SELF:ByteXor(SELF:ByteXor(buf[i + 3], e), SELF:rj_xtime(SELF:ByteXor(d, a)))
        i += 4
    ENDDO                                
RETURN

PROTECT METHOD aes_mixColumns_inv(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD
    LOCAL a, b, c, d, e, x, y, z AS BYTE 
                                
    i := 1
    DO WHILE i < 17
        a := buf[i]
        b := buf[i + 1]
        c := buf[i + 2]
        d := buf[i + 3]         
        e := SELF:ByteXor(SELF:ByteXor(SELF:ByteXor(a, b), c), d)
        z := SELF:rj_xtime(e)  
        x := SELF:ByteXor(e, SELF:rj_xtime(SELF:rj_xtime(SELF:ByteXor(SELF:ByteXor(z, a), c))))
        y := SELF:ByteXor(e, SELF:rj_xtime(SELF:rj_xtime(SELF:ByteXor(SELF:ByteXor(z, b), d))))
        buf[i] := SELF:ByteXor(SELF:ByteXor(buf[i], x), SELF:rj_xtime(SELF:ByteXor(a, b)))
        buf[i + 1] := SELF:ByteXor(SELF:ByteXor(buf[i + 1], y), SELF:rj_xtime(SELF:ByteXor(b, c)))
        buf[i + 2] := SELF:ByteXor(SELF:ByteXor(buf[i + 2], x), SELF:rj_xtime(SELF:ByteXor(c, d)))
        buf[i + 3] := SELF:ByteXor(SELF:ByteXor(buf[i + 3], y), SELF:rj_xtime(SELF:ByteXor(d, a)))
        i += 4
    ENDDO                                
RETURN

PROTECT METHOD aes_expandDecKey(k AS BYTE PTR, rc REF BYTE) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD
    
    i := 29
    DO WHILE i > 17
        k[i] := SELF:ByteXor(k[i], k[i - 4])
        k[i + 1] := SELF:ByteXor(k[i + 1], k[i - 3])
        k[i + 2] := SELF:ByteXor(k[i + 2], k[i - 2])
        k[i + 3] := SELF:ByteXor(k[i + 3], k[i - 1])
        i -= 4
    ENDDO
    
    k[17] := SELF:ByteXor(k[17], sbox[k[13] + 1]) 
    k[18] := SELF:ByteXor(k[18], sbox[k[14] + 1]) 
    k[19] := SELF:ByteXor(k[19], sbox[k[15] + 1]) 
    k[20] := SELF:ByteXor(k[20], sbox[k[16] + 1])
    
    i := 13
    DO WHILE i > 1
        k[i] := SELF:ByteXor(k[i], k[i - 4])
        k[i + 1] := SELF:ByteXor(k[i + 1], k[i - 3])
        k[i + 2] := SELF:ByteXor(k[i + 2], k[i - 2])
        k[i + 3] := SELF:ByteXor(k[i + 3], k[i - 1])
        i -= 4
    ENDDO
    
    rc := SELF:FD(rc)
    k[1] := SELF:ByteXor(SELF:ByteXor(k[1], sbox[k[30] + 1]), rc)  
    k[2] := SELF:ByteXor(k[2], sbox[k[31] + 1]) 
    k[3] := SELF:ByteXor(k[3], sbox[k[32] + 1]) 
    k[4] := SELF:ByteXor(k[4], sbox[k[29] + 1]) 
RETURN 

PROTECT METHOD ByteAnd(b1 AS BYTE, b2 AS BYTE) AS BYTE PASCAL CLASS AES256
RETURN LoByte(_AND(DWORD(b1), DWORD(b2)))

PROTECT METHOD ByteOr(b1 AS BYTE, b2 AS BYTE) AS BYTE PASCAL CLASS AES256
RETURN LoByte(_OR(DWORD(b1), DWORD(b2)))

PROTECT METHOD ByteXor(b1 AS BYTE, b2 AS BYTE) AS BYTE PASCAL CLASS AES256
RETURN LoByte(_XOR(DWORD(b1), DWORD(b2)))

PROTECT METHOD ByteNot(b1 AS BYTE) AS BYTE PASCAL CLASS AES256
RETURN LoByte(_NOT(DWORD(b1)))

PROTECT METHOD FD(x AS BYTE) AS BYTE PASCAL CLASS AES256
    LOCAL y, w AS BYTE 
    
    y := SELF:ByteShiftR(x, 1)
    w := SELF:ByteAnd(x, 1)
RETURN SELF:ByteXor(y, IIF(w > 0, 0x8D, 0)) 

PROTECT METHOD aes_addRoundKeyX(buf AS BYTE PTR, key AS BYTE PTR, x AS DWORD) AS VOID PASCAL CLASS AES256
    LOCAL i AS DWORD 
    
    FOR i := 16 DOWNTO 1
        buf[i] := SELF:ByteXor(buf[i], key[i + x])
    NEXT
RETURN

PROTECT METHOD ByteArray2Str(buf AS BYTE PTR, dwLen AS DWORD, lRemoveTrailingNulls := FALSE AS LOGIC) AS STRING PASCAL CLASS AES256
    LOCAL cOut AS STRING
    
    IF lRemoveTrailingNulls
        DO WHILE dwLen >= 1
            IF buf[dwLen] == 0
                dwLen -= 1
            ELSE
                EXIT
            ENDIF
        ENDDO
    ENDIF
    
    cOut := Mem2String(buf, dwLen)
RETURN cOut

PROTECT METHOD ByteShiftL(b1 AS BYTE, b2 AS BYTE) AS BYTE PASCAL CLASS AES256
    LOCAL w1, w2 AS DWORD
    
    w1 := b1
    w2 := b2
RETURN LoByte(w1 << w2)

PROTECT METHOD ByteShiftR(b1 AS BYTE, b2 AS BYTE) AS BYTE PASCAL CLASS AES256
    LOCAL w1, w2 AS DWORD
    
    w1 := b1
    w2 := b2
RETURN LoByte(w1 >> w2) 

//PROCEDURE prbuf(label AS STRING, buf AS ARRAY, maxlen AS INT)
//    LOCAL s := "" AS STRING 
//    LOCAL i AS INT
//    
//     IF maxlen == 0
//         FOR i := 1 TO ALen(buf)
//             s += AsString(buf[i]) + " "
//         NEXT
//     ELSE
//         FOR i := 1 TO maxlen
//             s += AsString(buf[i]) + " "
//         NEXT
//     ENDIF
//     
//     ? "VO " + label
//     ? s
//     _Wait()
//RETURN
    
PROTECT METHOD EncryptEcbArray(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL rcon AS BYTE        
    LOCAL i AS DWORD
    
    IF  SELF:lInitialised
        SELF:aes_addRoundKey_cpy(buf, SELF:enckey, SELF:key) 
        rcon := 1
        i := 1
        
        DO WHILE i < 14
            SELF:aes_subBytes(buf) 
            SELF:aes_shiftRows(buf) 
            SELF:aes_mixColumns(buf)
            IF SELF:ByteAnd(i, 1) > 0
                SELF:aes_addRoundKeyX(buf, SELF:key, 16)
            ELSE
                SELF:aes_expandEncKey(SELF:key, @rcon)
                SELF:aes_addRoundKeyX(buf, SELF:key, 0)
            ENDIF
            i += 1
        ENDDO
        
        SELF:aes_subBytes(buf)
        SELF:aes_shiftRows(buf)
        SELF:aes_expandEncKey(SELF:key, @rcon)
        SELF:aes_addRoundKeyX(buf, SELF:key, 0)
    ENDIF    
RETURN 

PROTECT METHOD DecryptEcbArray(buf AS BYTE PTR) AS VOID PASCAL CLASS AES256
    LOCAL rcon AS BYTE        
    LOCAL i AS DWORD
    
    IF  SELF:lInitialised
        SELF:aes_addRoundKey_cpy(buf, SELF:deckey, SELF:key)
        SELF:aes_shiftRows_inv(buf)
        SELF:aes_subBytes_inv(buf)
        
        rcon := 0x80
        i := 13         
        
        DO WHILE i >= 1  
            IF SELF:ByteAnd(i, 1) > 0
                SELF:aes_expandDecKey(SELF:key, @rcon)
                SELF:aes_addRoundKeyX(buf, SELF:key, 16)
            ELSE
                SELF:aes_addRoundKeyX(buf, SELF:key, 0)
            ENDIF
            SELF:aes_mixColumns_inv(buf)
            SELF:aes_shiftRows_inv(buf)
            SELF:aes_subBytes_inv(buf)
            i -= 1
        ENDDO
        
        SELF:aes_addRoundKeyX(buf, SELF:key, 0)
    ENDIF
RETURN

METHOD Encrypt(cPlainText AS STRING) AS STRING PASCAL CLASS AES256
    LOCAL cOut := "" AS STRING
    LOCAL buf AS BYTE PTR
    LOCAL dwLen, dwExtra, dwOffset AS DWORD
    
    dwLen := SLen(cPlainText)
    IF (dwLen > 0) .AND. SELF:lInitialised
        dwExtra := dwLen % 16
        
        IF dwExtra > 0
            dwExtra := 16 - dwExtra
            cPlainText += Replicate(CHR(0), dwExtra)
            dwLen += dwExtra
        ENDIF
        
        buf := SELF:Str2ByteArray(cPlainText, dwLen)
        
        IF buf != NULL_PTR
            dwOffset := 0
            DO WHILE dwOffset <= (dwLen - 16)
                SELF:EncryptEcbArray(buf + dwOffset)
                dwOffset += 16
            ENDDO  
            
            cOut := SELF:ByteArray2Str(buf, dwLen)
            MemFree(buf)
        ENDIF
    ENDIF
    
RETURN cOut

METHOD Decrypt(cCipherText AS STRING, lRemoveTrailingNulls := FALSE AS LOGIC) AS STRING PASCAL CLASS AES256
    LOCAL cOut := "" AS STRING 
    LOCAL buf AS BYTE PTR
    LOCAL dwLen, dwOffset AS DWORD
    
    dwLen := SLen(cCipherText)
    IF (dwLen > 0) .AND. ((dwLen % 16) == 0) .AND. SELF:lInitialised
        buf := SELF:Str2ByteArray(cCipherText, dwLen)
        
        IF buf != NULL_PTR
            dwOffset := 0
            DO WHILE dwOffset <= (dwLen - 16)
                SELF:DecryptEcbArray(buf + dwOffset)
                dwOffset += 16
            ENDDO  
            
            cOut := SELF:ByteArray2Str(buf, dwLen, lRemoveTrailingNulls)
            MemFree(buf)
        ENDIF
    ENDIF
RETURN cOut 

METHOD Axit() CLASS AES256
    IF SELF:lInitialised 
        SELF:FreeArrays()
    ENDIF             
    UnRegisterAxit(SELF)
RETURN NIL

PROTECT METHOD FreeArrays() AS VOID PASCAL CLASS AES256
    IF SELF:sboxinv != NULL_PTR 
        MemFree(SELF:sboxinv)  
    ENDIF
    IF SELF:sbox != NULL_PTR 
        MemFree(SELF:sbox)
    ENDIF
    IF SELF:deckey != NULL_PTR 
        MemFree(SELF:deckey)
    ENDIF
    IF SELF:enckey != NULL_PTR 
        MemFree(SELF:enckey)
    ENDIF
    IF SELF:key != NULL_PTR 
        MemFree(SELF:key)
    ENDIF
RETURN

[toc] | [prev] | [next] | [standalone]


#8610

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2015-11-05 08:22 +0100
Message-ID<da0ee6Frjf0U1@mid.individual.net>
In reply to#8608
Hi Phil,

> Here it is... please report any issues you may have.. but good old VO
> code does it again.

thank you very much for sharing.

To compile in VO 2.8 SP4 without warnings I had to add some word()
castings in lowbyte calls.

I'll try to investgate the DLL issue. Do you are loading DLLs
dynamically (LoadLibrary) or statically (using VO libs)?

Wolfgang


-- 

[toc] | [prev] | [next] | [standalone]


#8612

FromSherlock <sherlock@sherlock.com.au>
Date2015-11-05 14:49 -0800
Message-ID<84b9fa27-c5fe-4afa-8853-e6eb1503de85@googlegroups.com>
In reply to#8610
Wolfgang
 
snip[I'll try to investgate the DLL issue. Do you are loading DLLs dynamically (LoadLibrary) or statically (using VO libs)? ]

Standard VO dll..   nothing special.

If you use the Start() sample code.. with code in the source.. no problems.
Have code in a library - no problems.
Make a DLL from library..  and include it.. crashes on some calls in that code.

Calling this and in that method I put some debug code but it does not get this far.. interesting.

        k := SELF:Str2ByteArray(cKey, 32)

Phil McGuinness
Phil

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web