Enable SHA-256 ARM NEON acceleration on aarch64 Linux

未关闭
#1,478 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
cpp, linux

调研方向

Start with sha256.cpp:22 and read through sha_256_arm_v8() and the Linux runtime detection at lines 683–684. Check how the compiler handles the SHA2 intrinsics and target attribute for aarch64 Linux, then run the existing SHA-256 tests. Done means Linux aarch64 builds can use the accelerated implementation when SHA2 is detected, without calling it on unsupported hardware.

由索引模型根据 Issue 内容生成。

描述

The hardware-accelerated SHA-256 implementation (sha_256_arm_v8 using ARM SHA2 crypto extensions) is currently restricted to Apple platforms by the preprocessor guard at sha256.cpp:22:

#elif defined(__aarch64__) && defined(__APPLE__)

The Linux runtime detection code (getauxval(AT_HWCAP) & HWCAP_SHA2 at line 683) already exists inside this block but is dead code since the outer guard requires __APPLE__.

Why Apple-only

All Apple Silicon chips guarantee SHA2 extensions, so compiling the intrinsics is always safe. On Linux aarch64, older cores (e.g., Cortex-A53) may lack SHA2 support, and compiling the intrinsics without -march=armv8-a+crypto could fail.

Proposed fix
  1. Widen the outer guard to #elif defined(__aarch64__)
  2. Add __attribute__((target("sha2"))) (or +sha2 target) to sha_256_arm_v8() so the compiler emits SHA instructions only for that function, regardless of the global -march
  3. The existing getauxval runtime detection at line 683-684 already correctly gates whether sha_256_arm_v8 is actually called at runtime

This would enable hardware SHA-256 acceleration on Linux ARM servers (AWS Graviton, Ampere Altra, etc.).

Found during security audit of cryptographic precompile code.

主要语言
C++
星标
979
派生
340
平均合并
12 小时 16 分钟
30 天内合并 PR
25

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ipsilon/evmone 的其他 Issue

查看 ipsilon/evmone 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。