cipher_camellia_hw_t4.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * Fujitsu SPARC64 X support for camellia modes.
  11. * This file is included by cipher_camellia_hw.c
  12. */
  13. static int cipher_hw_camellia_t4_initkey(PROV_CIPHER_CTX *dat,
  14. const unsigned char *key,
  15. size_t keylen)
  16. {
  17. int ret = 0, bits, mode = dat->mode;
  18. PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat;
  19. CAMELLIA_KEY *ks = &adat->ks.ks;
  20. dat->ks = ks;
  21. bits = keylen * 8;
  22. cmll_t4_set_key(key, bits, ks);
  23. if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) {
  24. dat->block = (block128_f) cmll_t4_encrypt;
  25. switch (bits) {
  26. case 128:
  27. if (mode == EVP_CIPH_CBC_MODE)
  28. dat->stream.cbc = (cbc128_f) cmll128_t4_cbc_encrypt;
  29. else if (mode == EVP_CIPH_CTR_MODE)
  30. dat->stream.ctr = (ctr128_f) cmll128_t4_ctr32_encrypt;
  31. else
  32. dat->stream.cbc = NULL;
  33. break;
  34. case 192:
  35. case 256:
  36. if (mode == EVP_CIPH_CBC_MODE)
  37. dat->stream.cbc = (cbc128_f) cmll256_t4_cbc_encrypt;
  38. else if (mode == EVP_CIPH_CTR_MODE)
  39. dat->stream.ctr = (ctr128_f) cmll256_t4_ctr32_encrypt;
  40. else
  41. dat->stream.cbc = NULL;
  42. break;
  43. default:
  44. ret = -1;
  45. break;
  46. }
  47. } else {
  48. dat->block = (block128_f) cmll_t4_decrypt;
  49. switch (bits) {
  50. case 128:
  51. dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
  52. (cbc128_f) cmll128_t4_cbc_decrypt : NULL;
  53. break;
  54. case 192:
  55. case 256:
  56. dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
  57. (cbc128_f) cmll256_t4_cbc_decrypt : NULL;
  58. break;
  59. default:
  60. ret = -1;
  61. break;
  62. }
  63. }
  64. if (ret < 0) {
  65. ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
  66. return 0;
  67. }
  68. return 1;
  69. }
  70. #define PROV_CIPHER_HW_declare(mode) \
  71. static const PROV_CIPHER_HW t4_camellia_##mode = { \
  72. cipher_hw_camellia_t4_initkey, \
  73. ossl_cipher_hw_generic_##mode, \
  74. cipher_hw_camellia_copyctx \
  75. };
  76. #define PROV_CIPHER_HW_select(mode) \
  77. if (SPARC_CMLL_CAPABLE) \
  78. return &t4_camellia_##mode;