ElAES.pas 在 Windows 和 Linux 上的不同结果

发布于 2025-01-20 20:44:08 字数 735 浏览 1 评论 0原文

我正在尝试编译我的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位),以及Linux和MacOS上的不同结果。两个平台上的钥匙值相同。我应该更改什么以在Windows上的Linux/Mac上获得相同的结果?

I'm trying compile my project for Linux, have such code in 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])^;

And I have one result in ExpandedKey on Windows (32/64bit) and different result on Linux and MacOS. Key value is the same on both platforms. What I should change to get the same result on Linux/MAC like on Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晌融 2025-01-27 20:44:08

通常,如果代码在 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])^;

Usually, if the code works correctly in Win32, I test it in Win64. This helps catch errors related to different lengths of some types for 32 and 64 bits. This has always worked for me, but only until this case. The above code worked correctly in Win64. But there were errors when using in MacOS. The last thing I thought about was the difference in type sizes. And as it turned out - in vain. LongWord turned out to be a very strange type, the size of which is the same for Windows 32/64 bits and larger for Linux/MacOS. After changing the types in the module, everything worked on all platforms with any bit depth.

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])^;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文