cipher_aes_gcm_hw_armv8.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * Crypto extention support for AES GCM.
  11. * This file is included by cipher_aes_gcm_hw.c
  12. */
  13. size_t armv8_aes_gcm_encrypt(const unsigned char *in, unsigned char *out, size_t len,
  14. const void *key, unsigned char ivec[16], u64 *Xi)
  15. {
  16. size_t align_bytes = 0;
  17. align_bytes = len - len % 16;
  18. AES_KEY *aes_key = (AES_KEY *)key;
  19. switch(aes_key->rounds) {
  20. case 10:
  21. aes_gcm_enc_128_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  22. break;
  23. case 12:
  24. aes_gcm_enc_192_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  25. break;
  26. case 14:
  27. aes_gcm_enc_256_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  28. break;
  29. }
  30. return align_bytes;
  31. }
  32. size_t armv8_aes_gcm_decrypt(const unsigned char *in, unsigned char *out, size_t len,
  33. const void *key, unsigned char ivec[16], u64 *Xi)
  34. {
  35. size_t align_bytes = 0;
  36. align_bytes = len - len % 16;
  37. AES_KEY *aes_key = (AES_KEY *)key;
  38. switch(aes_key->rounds) {
  39. case 10:
  40. aes_gcm_dec_128_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  41. break;
  42. case 12:
  43. aes_gcm_dec_192_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  44. break;
  45. case 14:
  46. aes_gcm_dec_256_kernel(in, align_bytes * 8, out, (uint64_t *)Xi, ivec, key);
  47. break;
  48. }
  49. return align_bytes;
  50. }
  51. static int armv8_aes_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
  52. size_t keylen)
  53. {
  54. PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
  55. AES_KEY *ks = &actx->ks.ks;
  56. GCM_HW_SET_KEY_CTR_FN(ks, aes_v8_set_encrypt_key, aes_v8_encrypt,
  57. aes_v8_ctr32_encrypt_blocks);
  58. return 1;
  59. }
  60. static const PROV_GCM_HW armv8_aes_gcm = {
  61. armv8_aes_gcm_initkey,
  62. ossl_gcm_setiv,
  63. ossl_gcm_aad_update,
  64. generic_aes_gcm_cipher_update,
  65. ossl_gcm_cipher_final,
  66. ossl_gcm_one_shot
  67. };
  68. const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits)
  69. {
  70. return AES_PMULL_CAPABLE ? &armv8_aes_gcm : &aes_gcm;
  71. }