cipher_camellia.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2019-2020 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. /* Dispatch functions for CAMELLIA cipher modes ecb, cbc, ofb, cfb, ctr */
  15. #include "cipher_camellia.h"
  16. #include "prov/implementations.h"
  17. #include "prov/providercommon.h"
  18. static OSSL_FUNC_cipher_freectx_fn camellia_freectx;
  19. static OSSL_FUNC_cipher_dupctx_fn camellia_dupctx;
  20. static void camellia_freectx(void *vctx)
  21. {
  22. PROV_CAMELLIA_CTX *ctx = (PROV_CAMELLIA_CTX *)vctx;
  23. ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
  24. OPENSSL_clear_free(ctx, sizeof(*ctx));
  25. }
  26. static void *camellia_dupctx(void *ctx)
  27. {
  28. PROV_CAMELLIA_CTX *in = (PROV_CAMELLIA_CTX *)ctx;
  29. PROV_CAMELLIA_CTX *ret;
  30. if (!ossl_prov_is_running())
  31. return NULL;
  32. ret = OPENSSL_malloc(sizeof(*ret));
  33. if (ret == NULL) {
  34. ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
  35. return NULL;
  36. }
  37. in->base.hw->copyctx(&ret->base, &in->base);
  38. return ret;
  39. }
  40. /* ossl_camellia256ecb_functions */
  41. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 256, 128, 0, block)
  42. /* ossl_camellia192ecb_functions */
  43. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 192, 128, 0, block)
  44. /* ossl_camellia128ecb_functions */
  45. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ecb, ECB, 0, 128, 128, 0, block)
  46. /* ossl_camellia256cbc_functions */
  47. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 256, 128, 128, block)
  48. /* ossl_camellia192cbc_functions */
  49. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 192, 128, 128, block)
  50. /* ossl_camellia128cbc_functions */
  51. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cbc, CBC, 0, 128, 128, 128, block)
  52. /* ossl_camellia256ofb_functions */
  53. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 256, 8, 128, stream)
  54. /* ossl_camellia192ofb_functions */
  55. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 192, 8, 128, stream)
  56. /* ossl_camellia128ofb_functions */
  57. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ofb, OFB, 0, 128, 8, 128, stream)
  58. /* ossl_camellia256cfb_functions */
  59. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb, CFB, 0, 256, 8, 128, stream)
  60. /* ossl_camellia192cfb_functions */
  61. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb, CFB, 0, 192, 8, 128, stream)
  62. /* ossl_camellia128cfb_functions */
  63. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb, CFB, 0, 128, 8, 128, stream)
  64. /* ossl_camellia256cfb1_functions */
  65. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 256, 8, 128, stream)
  66. /* ossl_camellia192cfb1_functions */
  67. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 192, 8, 128, stream)
  68. /* ossl_camellia128cfb1_functions */
  69. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb1, CFB, 0, 128, 8, 128, stream)
  70. /* ossl_camellia256cfb8_functions */
  71. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 256, 8, 128, stream)
  72. /* ossl_camellia192cfb8_functions */
  73. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 192, 8, 128, stream)
  74. /* ossl_camellia128cfb8_functions */
  75. IMPLEMENT_generic_cipher(camellia, CAMELLIA, cfb8, CFB, 0, 128, 8, 128, stream)
  76. /* ossl_camellia256ctr_functions */
  77. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 256, 8, 128, stream)
  78. /* ossl_camellia192ctr_functions */
  79. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 192, 8, 128, stream)
  80. /* ossl_camellia128ctr_functions */
  81. IMPLEMENT_generic_cipher(camellia, CAMELLIA, ctr, CTR, 0, 128, 8, 128, stream)