Skip to content
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

Port OpenSSL assembly routines to Morello #2120

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from

Conversation

bsdjhb
Copy link
Collaborator

@bsdjhb bsdjhb commented Jun 15, 2024

  • OpenSSL arm_arch.h: Add helper macros for purecap support
  • OpenSSL arm64cpuid.pl: Add purecap support
  • OpenSSL aesv8-armx.pl: Add purecap support
  • OpenSSL vpaes-armv8.pl: Add purecap support
  • OpenSSL armv8-mont.pl: Add purecap support
  • OpenSSL chacha-armv8.pl: Add purecap support
  • OpenSSL ecp_nistz256-armv8.pl: Add purecap support
  • OpenSSL ghashv8-armx.pl: Add purecap support
  • OpenSSL aes-gcm-armv8_64.pl: Add purecap support
  • OpenSSL poly1305-armv8.pl: Add purecap support
  • OpenSSL keccak1600-armv8.pl: Add purecap support
  • OpenSSL sha1-armv8.pl: Add purecap support
  • OpenSSL sha512-armv8.pl: Add purecap support
  • OpenSSL: Regen aarch64 assembly for Morello
  • libcrypto: Enable build of assembly routines for Morello purecap
  • armv8crypto,ossl: Use correct -march for Morello
  • armv8crypto,ossl: Enable build for Morello purecap
  • cryptocheck: Don't test Chacha20-Poly1305 with an IV size of 8
  • ktls: Use SOPT_SETCAP to fix KTLS socket options for CHERI kernels
  • sys: Replace SOPT_SET/GETCAP with sooptcopyincap

So far I've been able to validate the following routines in userspace:

  • aes-gcm-armv8_64.s
    • aes_gcm_dec_128_kernel (ktls_test:ktls_transmit_aes128_gcm_1_2_long)
    • aes_gcm_dec_192_kernel
    • aes_gcm_dec_256_kernel (ktls_test:ktls_transmit_aes256_gcm_1_2_long)
    • aes_gcm_enc_128_kernel (cryptocheck)
    • aes_gcm_enc_192_kernel (cryptocheck)
    • aes_gcm_enc_256_kernel (cryptocheck)
  • aesv8-armx.s
    • aes_v8_cbc_encrypt (cryptocheck)
    • aes_v8_ctr32_encrypt_blocks (cryptocheck)
    • aes_v8_decrypt
    • aes_v8_ecb_encrypt (ssh-keygen)
    • aes_v8_encrypt (cryptocheck)
    • aes_v8_set_decrypt_key (cryptocheck)
    • aes_v8_set_encrypt_key (cryptocheck)
    • aes_v8_xts_decrypt (cryptocheck)
    • aes_v8_xts_encrypt (cryptocheck)
  • arm64cpuid.s
    • CRYPTO_memcmp (cryptocheck)
    • OPENSSL_cleanse (cryptocheck)
    • _armv7_neon_probe
    • _armv7_tick
    • _armv8_aes_probe
    • _armv8_cpuid_probe (cryptocheck)
    • _armv8_pmull_probe
    • _armv8_sha1_probe
    • _armv8_sha256_probe
    • _armv8_sha512_probe
  • armv8-mont.s
    • bn_mul_mont (ssh-keygen ecdsa)
  • chacha-armv8.s
    • ChaCha20_ctr32 (cryptocheck)
  • ecp_nistz256-armv8.s
    • ecp_nistz256_add
    • ecp_nistz256_div_by_2
    • ecp_nistz256_from_mont
    • ecp_nistz256_gather_w5
    • ecp_nistz256_gather_w7 (sshd)
    • ecp_nistz256_mul_by_2
    • ecp_nistz256_mul_by_3
    • ecp_nistz256_mul_mont
    • ecp_nistz256_neg
    • ecp_nistz256_ord_mul_mont
    • ecp_nistz256_ord_sqr_mont
    • ecp_nistz256_point_add
    • ecp_nistz256_point_add_affine
    • ecp_nistz256_point_double
    • ecp_nistz256_precomputed
    • ecp_nistz256_scatter_w5
    • ecp_nistz256_scatter_w7
    • ecp_nistz256_sqr_mont
    • ecp_nistz256_sub
    • ecp_nistz256_to_mont
  • ghashv8-armx.s
    • gcm_ghash_v8 (cryptocheck)
    • gcm_gmult_v8 (cryptocheck)
    • gcm_init_v8 (cryptocheck)
  • keccak1600-armv8.s
    • SHA3_absorb
    • SHA3_absorb_cext
    • SHA3_squeeze
    • SHA3_squeeze_cext
  • poly1305-armv8.s
    • poly1305_blocks (cryptocheck)
    • poly1305_emit (cryptocheck)
    • poly1305_init (cryptocheck)
  • sha1-armv8.s
    • sha1_block_data_order (cryptocheck)
  • sha256-armv8.s
    • sha256_block_data_order (cryptocheck)
  • sha512-armv8.s
    • sha512_block_data_order (cryptocheck)
  • vpaes-armv8.s (hard to test as only used if AESNI is not present)
    • vpaes_cbc_encrypt
    • vpaes_decrypt
    • vpaes_ecb_decrypt
    • vpaes_ecb_encrypt
    • vpaes_encrypt
    • vpaes_set_decrypt_key
    • vpaes_set_encrypt_key

For kernel testing will do the following on a purecap kernel:

  • cryptocheck armv8_crypto0
  • cryptocheck ossl0
  • ktls_test

@bsdjhb
Copy link
Collaborator Author

bsdjhb commented Jun 15, 2024

Currently the default host keys for sshd (ed25519) do not work. sshd doesn't crash, the keys just fail to validate, and ssh-keygen can't read them. I'm sure this is a bug in one of the files I've not been able to test yet.

@bsdjhb
Copy link
Collaborator Author

bsdjhb commented Jul 3, 2024

Currently the default host keys for sshd (ed25519) do not work. sshd doesn't crash, the keys just fail to validate, and ssh-keygen can't read them. I'm sure this is a bug in one of the files I've not been able to test yet.

ed25519 keys should now work, my attempt to clear carry was setting carry instead.

@bsdjhb
Copy link
Collaborator Author

bsdjhb commented Jul 3, 2024

Want to merge the patches at the end to fix cryptocheck and kernel TLS separately before this, but am marking as ready to that CI can run.

@bsdjhb bsdjhb marked this pull request as ready for review July 3, 2024 19:37
@@ -1115,13 +1127,13 @@
rev64 $acc_lb, $acc_lb
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A few lines above this is the potential out of bounds store referenced in the commit log. In practice, calling code stores the 16 byte tag after the end of the plain/cipher text, so the extra preserved bytes happen to always be in bounds as they are part of the tag in existing code. The tail sections of all of the enc/dec routines in this file follow the same pattern.

@bsdjhb
Copy link
Collaborator Author

bsdjhb commented Jul 5, 2024

More of the ecp_nistz256_* routines are probably exercised by sshd than I've marked so far.

bsdjhb added 19 commits July 17, 2024 16:00
OpenSSL 3.0+ doesn't support an IV size of 8 either for the Chacha20
stream cipher or the AEAD combination with Poly1305.  This did work
previously with OpenSSL 1.1.

Reviewed by:	markj
Sponsored by:	AFRL, DARPA
Differential Revision:	https://reviews.freebsd.org/D45280

(cherry picked from commit 4ebf794)
- PTR(n) can be used to select either x0-x30 or c0-c30.
- PTRN(n) can be used for to select either sp or csp.
- PTR_WIDTH is the size of a pointer in bytes.
NB: This just fixes pointers operands to be capability registers, it
does not yet address out of bounds stores at the end of a buffer when
the length is not a multiple of the block size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant