| 1 |
/* |
| 2 |
* Copyright 2023-2025 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_zbb(void *ctx, const void *in, size_t num); |
| 20 |
void sha256_block_data_order_riscv64(void *ctx, const void *in, size_t num); |
| 21 |
void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num); |
| 22 |
|
| 23 |
void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num) |
| 24 |
{ |
| 25 |
if (RISCV_HAS_ZVKB() && (RISCV_HAS_ZVKNHA() || RISCV_HAS_ZVKNHB()) && riscv_vlen() >= 128) { |
| 26 |
sha256_block_data_order_zvkb_zvknha_or_zvknhb(ctx, in, num); |
| 27 |
} else if (RISCV_HAS_ZBB()) { |
| 28 |
sha256_block_data_order_zbb(ctx, in, num); |
| 29 |
} else { |
| 30 |
sha256_block_data_order_riscv64(ctx, in, num); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
void sha512_block_data_order_zvkb_zvknhb(void *ctx, const void *in, size_t num); |
| 35 |
void sha512_block_data_order_zbb(void *ctx, const void *in, size_t num); |
| 36 |
void sha512_block_data_order_c(void *ctx, const void *in, size_t num); |
| 37 |
void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num); |
| 38 |
|
| 39 |
void sha512_block_data_order(SHA512_CTX *ctx, const void *in, size_t num) |
| 40 |
{ |
| 41 |
if (RISCV_HAS_ZVKB_AND_ZVKNHB() && riscv_vlen() >= 128) { |
| 42 |
sha512_block_data_order_zvkb_zvknhb(ctx, in, num); |
| 43 |
} else if (RISCV_HAS_ZBB()) { |
| 44 |
sha512_block_data_order_zbb(ctx, in, num); |
| 45 |
} else { |
| 46 |
sha512_block_data_order_c(ctx, in, num); |
| 47 |
} |
| 48 |
} |