简体   繁体   English

AES-256-GCM 在 M1 Macbook 上的 PHP ext-sodium 中不可用

[英]AES-256-GCM unavailable in PHP ext-sodium on M1 Macbook

Recently at work we've had a new hire to work on a project of ours that utilizes AES-256-GCM encryption and decryption via PHP's sodium extension.最近在工作中,我们有一个新员工来处理我们的一个项目,该项目通过 PHP 的钠扩展利用 AES-256-GCM 加密和解密。 Since we all use Macbooks, the new employee received a 2020 Macbook Pro with M1 chip.由于我们都使用 Macbook,新员工收到了 2020 款配备 M1 芯片的 Macbook Pro。

The first attempt at getting the aforementioned project up and running was using a HomeBrew setup, which runs the following components:启动和运行上述项目的第一次尝试是使用 HomeBrew 设置,它运行以下组件:

  • Apache 2.4 Apache 2.4
  • PHP 7.4 PHP 7.4
  • MySQL 5.7 MySQL 5.7

We quickly noticed that sodium_crypto_aead_aes256gcm_is_available() was returning false in our code, indicating that AES-256-GCM was not supported by the hardware of the Macbook.我们很快注意到代码中的sodium_crypto_aead_aes256gcm_is_available()返回 false,表明 Macbook 的硬件不支持 AES-256-GCM。 Running openssl list-cipher-algorithms | grep "GCM"运行openssl list-cipher-algorithms | grep "GCM" openssl list-cipher-algorithms | grep "GCM" on the other hand gave us this list:另一方面, openssl list-cipher-algorithms | grep "GCM"给了我们这个列表:

id-aes128-GCM
id-aes192-GCM
id-aes256-GCM
id-aes128-GCM
id-aes192-GCM
id-aes256-GCM

Running openssl speed -elapsed -evp aes-256-gcm also returned the expected output, so openssl seems to have access/is able to use it.运行openssl speed -elapsed -evp aes-256-gcm也返回了预期的 output,所以 openssl 似乎可以访问/能够使用它。

You have chosen to measure elapsed time instead of user CPU time.
Doing aes-256-gcm for 3s on 16 size blocks: 26616041 aes-256-gcm's in 3.00s
Doing aes-256-gcm for 3s on 64 size blocks: 6757776 aes-256-gcm's in 3.00s
Doing aes-256-gcm for 3s on 256 size blocks: 1647975 aes-256-gcm's in 3.00s
Doing aes-256-gcm for 3s on 1024 size blocks: 411604 aes-256-gcm's in 3.00s
Doing aes-256-gcm for 3s on 8192 size blocks: 51239 aes-256-gcm's in 3.00s
LibreSSL 2.8.3
built on: date not available
options:bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) aes(partial) blowfish(idx)
compiler: information not available

The second attempt using the dockerized version of the project yields the same results and also claims AES-256-GCM with AEAD is unsupported by the hardware, which was to be expected since it runs on the same host hardware.使用该项目的 dockerized 版本的第二次尝试产生了相同的结果,并且还声称带有 AEAD 的 AES-256-GCM 不受硬件支持,这是意料之中的,因为它在相同的主机硬件上运行。 This was done using the official PHP 7.4 image from Dockerhub.这是使用来自 Dockerhub 的官方 PHP 7.4 映像完成的。

Are there any known issues regarding the combination of M1 chips, AES-256-GCM using (lib)sodium and PHP?关于 M1 芯片、使用 (lib)sodium 的 AES-256-GCM 和 PHP 的组合是否存在任何已知问题? We've spent several days scouring here and on the support boards, but this combination seems to be quite niche.我们花了几天时间在这里和支持板上搜索,但这种组合似乎非常小众。 For now I've recommended that every developer remains on Intel based Macbooks, since everything works out of the box on that platform.目前,我建议每个开发人员都使用基于 Intel 的 Macbook,因为在该平台上一切都可以开箱即用。

So far we already checked the following:到目前为止,我们已经检查了以下内容:

  • ext-sodium enabled in PHP?在 PHP 中启用了 ext-sodium? yes是的
  • does it work on Intel based Macbook Pro using HomeBrew?它可以在使用 HomeBrew 的基于英特尔的 Macbook Pro 上运行吗? yes是的
  • does it work on Intel based Macbook Pro using Docker (compose)?它是否适用于使用 Docker(撰写)的基于英特尔的 Macbook Pro? yes是的
  • does OpenSSL support AES-256-GCM? OpenSSL 是否支持 AES-256-GCM? yes是的

After further inquiry on the Apple support forums, they pointed me into the direction of ARM hardware acceleration support not fully being present in libsodium.在 Apple 支持论坛上进一步询问后,他们向我指出了 ARM 硬件加速支持未完全存在于 libsodium 中的方向。 A GitHub issue titled Support for AES and GCM instructions on ARM processors #363 further indicates that there do not seem immediate plans to do this any time soon, seeing as the issue was opened in 2016 and abruptly closed in 2018.题为“支持 ARM 处理器#363 上的 AES 和 GCM 指令”的 GitHub 问题进一步表明,似乎短期内没有立即计划这样做,因为该问题于 2016 年打开并于 2018 年突然关闭。

For the time being I recommend using OpenSSL for AES-256-GCM if anywhere down the line your project will be developed or will run on ARM architecture.目前我建议使用 OpenSSL 用于AES-256-GCM ,如果您的项目将在任何地方开发或将在 ARM 架构上运行。 They seem to have implemented hardware acceleration for ARM environments.他们似乎已经为 ARM 环境实现了硬件加速。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM