我正在嘗試為 Linux 編譯我的專案,在 ElAES.pas 中有這樣的代碼:
type
TAESKey256 = array [0..31] of byte;
TAESExpandedKey256 = array [0..63] of longword;
PLongWord = ^LongWord;
procedure ExpandAESKeyForEncryption(const Key: TAESKey256; var ExpandedKey: TAESExpandedKey256); overload;
begin
ExpandedKey[0] := PLongWord(@Key[0])^;
ExpandedKey[1] := PLongWord(@Key[4])^;
ExpandedKey[2] := PLongWord(@Key[8])^;
ExpandedKey[3] := PLongWord(@Key[12])^;
ExpandedKey[4] := PLongWord(@Key[16])^;
ExpandedKey[5] := PLongWord(@Key[20])^;
ExpandedKey[6] := PLongWord(@Key[24])^;
ExpandedKey[7] := PLongWord(@Key[28])^;
我在 Windows(32/64 位)上的 ExpandedKey 有一個結果,而在 Linux 和 MacOS 上有不同的結果。兩個平臺上的鍵值相同。我應該改變什么才能在 Linux/MAC 上像在 Windows 上一樣獲得相同的結果?
uj5u.com熱心網友回復:
通常,如果代碼在 Win32 中正常作業,我會在 Win64 中對其進行測驗。這有助于捕獲與 32 位和 64 位的某些型別的不同長度相關的錯誤。這一直對我有用,但只在這種情況下。上面的代碼在 Win64 中正常作業。但在 MacOS 中使用時出現錯誤。我想到的最后一件事是字體大小的差異。事實證明 - 徒勞。LongWord 原來是一種非常奇怪的型別,它的大小對于 Windows 32/64 位是相同的,而對于 Linux/MacOS 則更大。更改模塊中的型別后,一切都可以在任何位深度的所有平臺上運行。
type
TAESKey256 = array [0..31] of byte;
TAESExpandedKey256 = array [0..63] of UInt32;
PUInt32 = ^UInt32;
procedure ExpandAESKeyForEncryption(const Key: TAESKey256; var ExpandedKey: TAESExpandedKey256); overload;
begin
ExpandedKey[0] := PUInt32(@Key[0])^;
ExpandedKey[1] := PUInt32(@Key[4])^;
ExpandedKey[2] := PUInt32(@Key[8])^;
ExpandedKey[3] := PUInt32(@Key[12])^;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/460929.html
