sha2_prov.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2019 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. #include <openssl/crypto.h>
  10. #include <openssl/core_numbers.h>
  11. #include <openssl/sha.h>
  12. #include <openssl/evp.h>
  13. #include <openssl/params.h>
  14. #include <openssl/core_names.h>
  15. #include "internal/core_mkdigest.h"
  16. #include "internal/provider_algs.h"
  17. #include "internal/sha.h"
  18. static OSSL_OP_digest_set_params_fn sha1_set_params;
  19. /* Special set_params method for SSL3 */
  20. static int sha1_set_params(void *vctx, const OSSL_PARAM params[])
  21. {
  22. const OSSL_PARAM *p;
  23. SHA_CTX *ctx = (SHA_CTX *)vctx;
  24. if (ctx != NULL && params != NULL) {
  25. p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SSL3_MS);
  26. if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
  27. return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
  28. p->data);
  29. }
  30. return 0;
  31. }
  32. OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(sha1, SHA_CTX,
  33. SHA_CBLOCK, SHA_DIGEST_LENGTH,
  34. SHA1_Init, SHA1_Update, SHA1_Final,
  35. sha1_set_params)
  36. OSSL_FUNC_DIGEST_CONSTRUCT(sha224, SHA256_CTX,
  37. SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
  38. SHA224_Init, SHA224_Update, SHA224_Final)
  39. OSSL_FUNC_DIGEST_CONSTRUCT(sha256, SHA256_CTX,
  40. SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
  41. SHA256_Init, SHA256_Update, SHA256_Final)
  42. OSSL_FUNC_DIGEST_CONSTRUCT(sha384, SHA512_CTX,
  43. SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
  44. SHA384_Init, SHA384_Update, SHA384_Final)
  45. OSSL_FUNC_DIGEST_CONSTRUCT(sha512, SHA512_CTX,
  46. SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
  47. SHA512_Init, SHA512_Update, SHA512_Final)
  48. OSSL_FUNC_DIGEST_CONSTRUCT(sha512_224, SHA512_CTX,
  49. SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
  50. sha512_224_init, SHA512_Update, SHA512_Final)
  51. OSSL_FUNC_DIGEST_CONSTRUCT(sha512_256, SHA512_CTX,
  52. SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
  53. sha512_256_init, SHA512_Update, SHA512_Final)