cipher_aria_hw.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2001-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. #include <openssl/proverr.h>
  10. #include "cipher_aria.h"
  11. static int cipher_hw_aria_initkey(PROV_CIPHER_CTX *dat,
  12. const unsigned char *key, size_t keylen)
  13. {
  14. int ret, mode = dat->mode;
  15. PROV_ARIA_CTX *adat = (PROV_ARIA_CTX *)dat;
  16. ARIA_KEY *ks = &adat->ks.ks;
  17. if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE))
  18. ret = ossl_aria_set_encrypt_key(key, keylen * 8, ks);
  19. else
  20. ret = ossl_aria_set_decrypt_key(key, keylen * 8, ks);
  21. if (ret < 0) {
  22. ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
  23. return 0;
  24. }
  25. dat->ks = ks;
  26. dat->block = (block128_f)ossl_aria_encrypt;
  27. return 1;
  28. }
  29. IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_aria_copyctx, PROV_ARIA_CTX)
  30. # define PROV_CIPHER_HW_aria_mode(mode) \
  31. static const PROV_CIPHER_HW aria_##mode = { \
  32. cipher_hw_aria_initkey, \
  33. ossl_cipher_hw_chunked_##mode, \
  34. cipher_hw_aria_copyctx \
  35. }; \
  36. const PROV_CIPHER_HW *ossl_prov_cipher_hw_aria_##mode(size_t keybits) \
  37. { \
  38. return &aria_##mode; \
  39. }
  40. PROV_CIPHER_HW_aria_mode(cbc)
  41. PROV_CIPHER_HW_aria_mode(ecb)
  42. PROV_CIPHER_HW_aria_mode(ofb128)
  43. PROV_CIPHER_HW_aria_mode(cfb128)
  44. PROV_CIPHER_HW_aria_mode(cfb1)
  45. PROV_CIPHER_HW_aria_mode(cfb8)
  46. PROV_CIPHER_HW_aria_mode(ctr)