cipher_seed.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /* Dispatch functions for Seed cipher modes ecb, cbc, ofb, cfb */
  10. /*
  11. * SEED low level APIs are deprecated for public use, but still ok for
  12. * internal use.
  13. */
  14. #include "internal/deprecated.h"
  15. #include "cipher_seed.h"
  16. #include "prov/implementations.h"
  17. #include "prov/providercommon.h"
  18. static OSSL_FUNC_cipher_freectx_fn seed_freectx;
  19. static OSSL_FUNC_cipher_dupctx_fn seed_dupctx;
  20. static void seed_freectx(void *vctx)
  21. {
  22. PROV_SEED_CTX *ctx = (PROV_SEED_CTX *)vctx;
  23. ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
  24. OPENSSL_clear_free(ctx, sizeof(*ctx));
  25. }
  26. static void *seed_dupctx(void *ctx)
  27. {
  28. PROV_SEED_CTX *in = (PROV_SEED_CTX *)ctx;
  29. PROV_SEED_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. *ret = *in;
  38. return ret;
  39. }
  40. /* ossl_seed128ecb_functions */
  41. IMPLEMENT_generic_cipher(seed, SEED, ecb, ECB, 0, 128, 128, 0, block)
  42. /* ossl_seed128cbc_functions */
  43. IMPLEMENT_generic_cipher(seed, SEED, cbc, CBC, 0, 128, 128, 128, block)
  44. /* ossl_seed128ofb128_functions */
  45. IMPLEMENT_generic_cipher(seed, SEED, ofb128, OFB, 0, 128, 8, 128, stream)
  46. /* ossl_seed128cfb128_functions */
  47. IMPLEMENT_generic_cipher(seed, SEED, cfb128, CFB, 0, 128, 8, 128, stream)