cipher_aria_gcm_hw.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright 2019 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. * Generic support for ARIA GCM.
  11. */
  12. #include "cipher_aria_gcm.h"
  13. static int aria_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
  14. size_t keylen)
  15. {
  16. PROV_ARIA_GCM_CTX *actx = (PROV_ARIA_GCM_CTX *)ctx;
  17. ARIA_KEY *ks = &actx->ks.ks;
  18. GCM_HW_SET_KEY_CTR_FN(ks, aria_set_encrypt_key, aria_encrypt, NULL);
  19. return 1;
  20. }
  21. static int aria_cipher_update(PROV_GCM_CTX *ctx, const unsigned char *in,
  22. size_t len, unsigned char *out)
  23. {
  24. if (ctx->enc) {
  25. if (CRYPTO_gcm128_encrypt(&ctx->gcm, in, out, len))
  26. return 0;
  27. } else {
  28. if (CRYPTO_gcm128_decrypt(&ctx->gcm, in, out, len))
  29. return 0;
  30. }
  31. return 1;
  32. }
  33. static const PROV_GCM_HW aria_gcm = {
  34. aria_gcm_initkey,
  35. gcm_setiv,
  36. gcm_aad_update,
  37. aria_cipher_update,
  38. gcm_cipher_final,
  39. gcm_one_shot
  40. };
  41. const PROV_GCM_HW *PROV_ARIA_HW_gcm(size_t keybits)
  42. {
  43. return &aria_gcm;
  44. }