8000 Provide CPU RNG Support for 64 Bit Arm CPUs by otoledan · Pull Request #15361 · openssl/openssl · GitHub
[go: up one dir, main page]

Skip to content

Provide CPU RNG Support for 64 Bit Arm CPUs #15361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed

Provide CPU RNG Support for 64 Bit Arm CPUs #15361

wants to merge 11 commits into from

Conversation

otoledan
Copy link
Contributor

Provide support in a new engine and provider for aarch64 random number generation. The engine and provider make use of the RNDR and RNDRRS Arm assembly instructions.

Checklist
  • documentation is added or updated
  • tests are added or updated

@slontis
Copy link
Member
slontis commented May 19, 2021

Engines are deprecated.
Adding new engine code into master may not be a good path forward.

crypto/armcap.c Outdated
size_t OPENSSL_rndr_asm(unsigned char *buf, size_t len);
size_t OPENSSL_rndrrs_asm(unsigned char *buf, size_t len);

size_t OPENSSL_rndr_wrapper(size_t (*func)(unsigned char *, size_t), unsigned char *buf, size_t len)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that any of these functions should be public, so openssl_rndr_wrapper(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marked as static. fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_armv8_rng_probe, OPENSSL_rndr_asm, OPENSSL_rndrrs_asm(unsigned char *buf, size_t len) were made global again since the assembly function definition was not being picked up by the compiler with strict warnings enabled.

static size_t OPENSSL_rndr_wrapper has remained static since all contents definitions and references exist within this file.

@paulidale
Copy link
Contributor

Adding an engine to 1.1.1 would be considered a new feature and I doubt it would be accepted. It could still be distributed separately.

For 3.0, an engine is undesirable. The provider implementation is much cleaner too.

@ozbenh
Copy link
ozbenh commented May 20, 2021

Adding an engine to 1.1.1 would be considered a new feature and I doubt it would be accepted. It could still be distributed separately.

For 3.0, an engine is undesirable. The provider implementation is much cleaner too.

Oops, sorry, I accidentally deleted my message, as I was going to reply to your other comment above.

I agree for 3.0 the provider is the way to go. But it will take years for 3.0 to be sufficiently widespread and we would like this to be backport'able to existing enterprise distros to exploit the HW rng. But we can indeed distribute it separately if necessary.

@paulidale
Copy link
Contributor

The way to go would be to submit the provider code to master and raise a separate PR for 1.1.1 for the engine.

Perhaps start with an issue for the new feature in 1.1.1 and the OTC can decide to include or not.

@ozbenh
Copy link
ozbenh commented May 20, 2021

The way to go would be to submit the provider code to master and raise a separate PR for 1.1.1 for the engine.

Perhaps start with an issue for the new feature in 1.1.1 and the OTC can decide to include or not.

Yup, sounds good. Thanks !

@mattcaswell
Copy link
Member

Perhaps start with an issue for the new feature in 1.1.1 and the OTC can decide to include or not.

I very much doubt that OTC will approve this.

Unfortunately I think this is probably too late for inclusion in 3.0 too.

@ozbenh
Copy link
ozbenh commented May 20, 2021

Perhaps start with an issue for the new feature in 1.1.1 and the OTC can decide to include or not.

I very much doubt that OTC will approve this.

Unfortunately I think this is probably too late for inclusion in 3.0 too.

I suppose it depends if you consider it a "new feature" or just ARM support for the existing "rdcpu" one :-)

@otoledan otoledan requested a review from paulidale May 20, 2021 23:24
@otoledan otoledan requested a review from paulidale May 21, 2021 05:25
Copy link
Contributor
@paulidale paulidale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easier for the reviewers if you used fixup commits (git --fixup ).
They get squashed as part of the merge process and they help us see what has changed.

@paulidale paulidale added approval: review pending This pull request needs review by a committer branch: master Merge to master branch labels May 21, 2021
@paulidale paulidale self-assigned this May 21, 2021
@otoledan
Copy link
Contributor Author

They get squashed as part of the merge process and they help us see what has changed.

will keep that in mind for future changes.

@otoledan
Copy link
Contributor Author

Is there anything else required on my end as the developer in terms of merging this change?

I see there is now a conflict for CHANGES.md, should I wait until the status is set to approval:done or rebase periodically?

@paulidale
Copy link
Contributor

A second reviewer's approval is required.

@otoledan otoledan requested a review from slontis May 29, 2021 01:07
b.eq .${rdop}_done
mov x3,xzr
mrs x3,$rand_reg
b.eq .${rdop}_done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt zero a possible valid value here?

The documentation for
https://developer.arm.com/documentation/ddi0595/2021-03/AArch64-Registers/RNDR--Random-Number?lang=en

says this

If the hardware returns a genuine random number, PSTATE.NZCV is set to 0b0000.
If the instruction cannot return a genuine random number in a reasonable period of time, PSTATE.NZCV is set to 0b0100 and the data value returned is 0.

Should it be doing
mrs x4, nzcv

Copy link
Contributor Author
@otoledan otoledan May 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a zero value is possible in the x3 register, though only in a failure situation.

The mrs x3,xzr is used to clear out the register used for rng (which is not strictly necessary and used to ensure previous values were not in the register) prior to running the command for rng (mrs x3,$rand_reg). The check for the failure is done by b.eq .${rdop}_done which checks if the Zero flag is set. As quoted from the documentation "If the instruction cannot return a genuine random number in a reasonable period of time, PSTATE.NZCV is set to 0b0100". So the check for the Zero flag would be enough to validate that rng has occurred.

From my understanding of the documentation there is no need to run mrs x4, nzcv, prior to rng.

@slontis slontis added the hold: committer discussion The committers need to establish a consensus how to move forward with the issue or PR label May 31, 2021
@slontis
Copy link
Member
slontis commented May 31, 2021

OTC: Should this be added to 3.0?

@paulidale paulidale added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Dec 15, 2021
@openssl-machine openssl-machine removed the approval: done This pull request has the required number of approvals label Dec 16, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@openssl-machine openssl-machine added the approval: ready to merge The 24 hour grace period has passed, ready to merge label Dec 16, 2021
openssl-machine pushed a commit that referenced this pull request Dec 16, 2021
Include aarch64 asm instructions for random number generation using the
RNDR and RNDRRS instructions. Provide detection functions for RNDR and
RNDRRS getauxval.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)
openssl-machine pushed a commit that referenced this pull request Dec 16, 2021
Create new provider for RNDRRS. Modify support for rand_cpu to default to
RDRAND/RDSEED on x86 and RNDRRS on aarch64.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)
openssl-machine pushed a commit that referenced this pull request Dec 16, 2021
Add test cases for RNDR and RNDRRS. Combine tests for RDRAND and RNDR to
share common logic.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)
openssl-machine pushed a commit that referenced this pull request Dec 16, 2021
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)
@t8m
Copy link
Member
t8m commented Dec 16, 2021

Merged. Thank you for your contribution!

@t8m t8m closed this Dec 16, 2021
t8m pushed a commit to t8m/openssl that referenced this pull request Nov 2, 2022
Include aarch64 asm instructions for random number generation using the
RNDR and RNDRRS instructions. Provide detection functions for RNDR and
RNDRRS getauxval.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#15361)

(cherry picked from commit efa1f22)
t8m pushed a commit to t8m/openssl that referenced this pull request Nov 2, 2022
Create new provider for RNDRRS. Modify support for rand_cpu to default to
RDRAND/RDSEED on x86 and RNDRRS on aarch64.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#15361)

(cherry picked from commit eb28fda)
t8m pushed a commit to t8m/openssl that referenced this pull request Nov 2, 2022
Add test cases for RNDR and RNDRRS. Combine tests for RDRAND and RNDR to
share common logic.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#15361)

(cherry picked from commit 1f8ce0c)
t8m pushed a commit to t8m/openssl that referenced this pull request Nov 2, 2022
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#15361)

(cherry picked from commit e8b597f)
openssl-machine pushed a commit that referenced this pull request Nov 9, 2022
Include aarch64 asm instructions for random number generation using the
RNDR and RNDRRS instructions. Provide detection functions for RNDR and
RNDRRS getauxval.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)

(cherry picked from commit efa1f22)
openssl-machine pushed a commit that referenced this pull request Nov 9, 2022
Create new provider for RNDRRS. Modify support for rand_cpu to default to
RDRAND/RDSEED on x86 and RNDRRS on aarch64.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)

(cherry picked from commit eb28fda)
openssl-machine pushed a commit that referenced this pull request Nov 9, 2022
Add test cases for RNDR and RNDRRS. Combine tests for RDRAND and RNDR to
share common logic.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)

(cherry picked from commit 1f8ce0c)
openssl-machine pushed a commit that referenced this pull request Nov 9, 2022
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #15361)

(cherry picked from commit e8b597f)
achow101 added a commit to bitcoin-core/gui that referenced this pull request Nov 7, 2023
…on Linux

aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes #26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 24, 2024
aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes bitcoin#26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 24, 2024
aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes bitcoin#26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 24, 2024
aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes bitcoin#26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 24, 2024
aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes bitcoin#26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 24, 2024
aee5404 Add support for RNDR/RNDRRS for aarch64 on Linux (John Moffett)

Pull request description:

  This checks whether the ARMv8.5-A optional TRNG extensions [RNDR](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDR--Random-Number) and [RNDRRS](https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number) are available and, if they are, uses them for random entropy purposes.

  They are nearly functionally identical to the x86 RDRAND/RDSEED extensions and are used in a similar manner.

  Currently, there [appears to be](https://marcin.juszkiewicz.com.pl/download/tables/arm-socs.html) only one actual hardware implementation -- the Amazon Graviton 3. (See the `rnd` column in the link.) However, future hardware implementations may become available.

  It's not possible to directly query for the capability in userspace, but the Linux kernel [added support](torvalds/linux@1a50ec0) for querying the extension via `getauxval` in version 5.6 (in 2020), so this is limited to Linux-only for now.

  Reviewers may want to launch any of the `c7g` instances from AWS to test the Graviton 3 hardware. Alternatively, QEMU emulates these opcodes for `aarch64` with CPU setting `max`.

  Output from Graviton 3 hardware:

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:01:48Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:01:48Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:01:48Z Using RNDR and RNDRRS as additional entropy sources
  2023-01-06T20:01:48Z Default data directory /home/ubuntu/.bitcoin
  ```

  Graviton 2 (doesn't support extensions):

  ```
  ubuntu@ip:~/bitcoin$ src/bitcoind -regtest
  2023-01-06T20:05:04Z Bitcoin Core version v24.99.0-3670266ce89a (release build)
  2023-01-06T20:05:04Z Using the 'arm_shani(1way,2way)' SHA256 implementation
  2023-01-06T20:05:04Z Default data directory /home/ubuntu/.bitcoin
  ```

  This partially closes bitcoin#26796. As noted in that issue, OpenSSL [added support](openssl/openssl#15361) for these extensions a little over a year ago.

ACKs for top commit:
  achow101:
    ACK aee5404
  laanwj:
    Tested ACK aee5404

Tree-SHA512: 1c1eb345d6690f5307a87e9bac8f06a0d1fdc7ca35db38fa22192510a44289a03252e4677dc7cbf731a27e6e3a9a4e42b6eb4149fe063bc1c905eb2536cdb1d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch triaged: feature The issue/pr requests/adds a feature triaged: OTC evaluated This issue/pr was triaged by OTC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0