cipher_camellia_hw.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /*
  10. * Camellia low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include <openssl/camellia.h>
  15. #include <openssl/proverr.h>
  16. #include "cipher_camellia.h"
  17. static int cipher_hw_camellia_initkey(PROV_CIPHER_CTX *dat,
  18. const unsigned char *key, size_t keylen)
  19. {
  20. int ret, mode = dat->mode;
  21. PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
  22. CAMELLIA_KEY *ks = &adat->ks.ks;
  23. dat->ks = ks;
  24. ret = Camellia_set_key(key, keylen * 8, ks);
  25. if (ret < 0) {
  26. ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
  27. return 0;
  28. }
  29. if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) {
  30. dat->block = (block128_f) Camellia_encrypt;
  31. dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
  32. (cbc128_f) Camellia_cbc_encrypt : NULL;
  33. } else {
  34. dat->block = (block128_f) Camellia_decrypt;
  35. dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
  36. (cbc128_f) Camellia_cbc_encrypt : NULL;
  37. }
  38. return 1;
  39. }
  40. IMPLEMENT_CIPHER_HW_COPYCTX(cipher_hw_camellia_copyctx, PROV_CAMELLIA_CTX)
  41. # if defined(SPARC_CMLL_CAPABLE)
  42. # include "cipher_camellia_hw_t4.inc"
  43. # else
  44. /* The generic case */
  45. # define PROV_CIPHER_HW_declare(mode)
  46. # define PROV_CIPHER_HW_select(mode)
  47. # endif /* SPARC_CMLL_CAPABLE */
  48. #define PROV_CIPHER_HW_camellia_mode(mode) \
  49. static const PROV_CIPHER_HW camellia_##mode = { \
  50. cipher_hw_camellia_initkey, \
  51. ossl_cipher_hw_generic_##mode, \
  52. cipher_hw_camellia_copyctx \
  53. }; \
  54. PROV_CIPHER_HW_declare(mode) \
  55. const PROV_CIPHER_HW *ossl_prov_cipher_hw_camellia_##mode(size_t keybits) \
  56. { \
  57. PROV_CIPHER_HW_select(mode) \
  58. return &camellia_##mode; \
  59. }
  60. PROV_CIPHER_HW_camellia_mode(cbc)
  61. PROV_CIPHER_HW_camellia_mode(ecb)
  62. PROV_CIPHER_HW_camellia_mode(ofb128)
  63. PROV_CIPHER_HW_camellia_mode(cfb128)
  64. PROV_CIPHER_HW_camellia_mode(cfb1)
  65. PROV_CIPHER_HW_camellia_mode(cfb8)
  66. PROV_CIPHER_HW_camellia_mode(ctr)