sha2_prov.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/evp.h>
  12. #include <openssl/sha.h>
  13. #include <openssl/evp.h>
  14. #include <openssl/params.h>
  15. #include <openssl/core_names.h>
  16. #include "internal/digestcommon.h"
  17. #include "internal/provider_algs.h"
  18. #include "crypto/sha.h"
  19. static OSSL_OP_digest_set_ctx_params_fn sha1_set_ctx_params;
  20. static OSSL_OP_digest_settable_ctx_params_fn sha1_settable_ctx_params;
  21. static const OSSL_PARAM known_sha1_settable_ctx_params[] = {
  22. {OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
  23. OSSL_PARAM_END
  24. };
  25. static const OSSL_PARAM *sha1_settable_ctx_params(void)
  26. {
  27. return known_sha1_settable_ctx_params;
  28. }
  29. /* Special set_params method for SSL3 */
  30. static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
  31. {
  32. const OSSL_PARAM *p;
  33. SHA_CTX *ctx = (SHA_CTX *)vctx;
  34. if (ctx != NULL && params != NULL) {
  35. p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
  36. if (p != NULL && p->data_type == OSSL_PARAM_OCTET_STRING)
  37. return sha1_ctrl(ctx, EVP_CTRL_SSL3_MASTER_SECRET, p->data_size,
  38. p->data);
  39. }
  40. return 0;
  41. }
  42. /* sha1_functions */
  43. IMPLEMENT_digest_functions_with_settable_ctx(
  44. sha1, SHA_CTX, SHA_CBLOCK, SHA_DIGEST_LENGTH, EVP_MD_FLAG_DIGALGID_ABSENT,
  45. SHA1_Init, SHA1_Update, SHA1_Final,
  46. sha1_settable_ctx_params, sha1_set_ctx_params)
  47. /* sha224_functions */
  48. IMPLEMENT_digest_functions(sha224, SHA256_CTX,
  49. SHA256_CBLOCK, SHA224_DIGEST_LENGTH,
  50. EVP_MD_FLAG_DIGALGID_ABSENT,
  51. SHA224_Init, SHA224_Update, SHA224_Final)
  52. /* sha256_functions */
  53. IMPLEMENT_digest_functions(sha256, SHA256_CTX,
  54. SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
  55. EVP_MD_FLAG_DIGALGID_ABSENT,
  56. SHA256_Init, SHA256_Update, SHA256_Final)
  57. /* sha384_functions */
  58. IMPLEMENT_digest_functions(sha384, SHA512_CTX,
  59. SHA512_CBLOCK, SHA384_DIGEST_LENGTH,
  60. EVP_MD_FLAG_DIGALGID_ABSENT,
  61. SHA384_Init, SHA384_Update, SHA384_Final)
  62. /* sha512_functions */
  63. IMPLEMENT_digest_functions(sha512, SHA512_CTX,
  64. SHA512_CBLOCK, SHA512_DIGEST_LENGTH,
  65. EVP_MD_FLAG_DIGALGID_ABSENT,
  66. SHA512_Init, SHA512_Update, SHA512_Final)
  67. /* sha512_224_functions */
  68. IMPLEMENT_digest_functions(sha512_224, SHA512_CTX,
  69. SHA512_CBLOCK, SHA224_DIGEST_LENGTH,
  70. EVP_MD_FLAG_DIGALGID_ABSENT,
  71. sha512_224_init, SHA512_Update, SHA512_Final)
  72. /* sha512_256_functions */
  73. IMPLEMENT_digest_functions(sha512_256, SHA512_CTX,
  74. SHA512_CBLOCK, SHA256_DIGEST_LENGTH,
  75. EVP_MD_FLAG_DIGALGID_ABSENT,
  76. sha512_256_init, SHA512_Update, SHA512_Final)