cipher_seed.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. return NULL;
  35. *ret = *in;
  36. return ret;
  37. }
  38. /* ossl_seed128ecb_functions */
  39. IMPLEMENT_generic_cipher(seed, SEED, ecb, ECB, 0, 128, 128, 0, block)
  40. /* ossl_seed128cbc_functions */
  41. IMPLEMENT_generic_cipher(seed, SEED, cbc, CBC, 0, 128, 128, 128, block)
  42. /* ossl_seed128ofb128_functions */
  43. IMPLEMENT_generic_cipher(seed, SEED, ofb128, OFB, 0, 128, 8, 128, stream)
  44. /* ossl_seed128cfb128_functions */
  45. IMPLEMENT_generic_cipher(seed, SEED, cfb128, CFB, 0, 128, 8, 128, stream)