sha_riscv.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2023 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 <stdlib.h>
  10. #include <string.h>
  11. #include <openssl/opensslconf.h>
  12. #include <openssl/sha.h>
  13. #include "crypto/riscv_arch.h"
  14. void sha256_block_data_order_zvkb_zvknha_or_zvknhb(void *ctx, const void *in,
  15. size_t num);
  16. void sha256_block_data_order_c(void *ctx, const void *in, size_t num);
  17. void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num);
  18. void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num)
  19. {
  20. if (RISCV_HAS_ZVKB() && (RISCV_HAS_ZVKNHA() || RISCV_HAS_ZVKNHB()) &&
  21. riscv_vlen() >= 128) {
  22. sha256_block_data_order_zvkb_zvknha_or_zvknhb(ctx, in, num);
  23. } else {
  24. sha256_block_data_order_c(ctx, in, num);
  25. }
  26. }
  27. void sha512_block_data_order_zvkb_zvknhb(void *ctx, const void *in, size_t num);
  28. void sha512_block_data_order_c(void *ctx, const void *in, size_t num);
  29. void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num);
  30. void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num)
  31. {
  32. if (RISCV_HAS_ZVKB_AND_ZVKNHB() && riscv_vlen() >= 128) {
  33. sha512_block_data_order_zvkb_zvknhb(ctx, in, num);
  34. } else {
  35. sha512_block_data_order_c(ctx, in, num);
  36. }
  37. }