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