Skip to content

Commit cdb3925

Browse files
committed
mh_sha256: add an mh_sha256 assembly implementation with vector extension for riscv64
Signed-off-by: Julian Zhu <[email protected]>
1 parent bc9e4a9 commit cdb3925

File tree

5 files changed

+665
-1
lines changed

5 files changed

+665
-1
lines changed

mh_sha256/Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ lsrc_aarch64 += $(lsrc_sha256) \
6363
mh_sha256/mh_sha256_block_base.c
6464

6565
lsrc_riscv64 += $(lsrc_sha256) \
66-
mh_sha256/mh_sha256_base_aliases.c \
66+
mh_sha256/riscv64/mh_sha256_multibinary.S \
67+
mh_sha256/riscv64/mh_sha256_riscv64_dispatcher.c \
68+
mh_sha256/riscv64/mh_sha256_block_rvv.S \
69+
mh_sha256/riscv64/mh_sha256_block.c \
6770
mh_sha256/mh_sha256.c \
6871
mh_sha256/mh_sha256_finalize_base.c \
6972
mh_sha256/mh_sha256_update_base.c \
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**********************************************************************
2+
Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of ISCAS nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
**********************************************************************/
29+
30+
#include <string.h>
31+
#include "mh_sha256_internal.h"
32+
33+
void
34+
mh_sha256_block_rvv(const uint8_t *input_data,
35+
uint32_t digests[ISAL_SHA256_DIGEST_WORDS][ISAL_HASH_SEGS],
36+
uint8_t frame_buffer[ISAL_MH_SHA256_BLOCK_SIZE], uint32_t num_blocks);
37+
/***************mh_sha256_update***********/
38+
// mh_sha256_update_rvv.c
39+
#define MH_SHA256_UPDATE_FUNCTION mh_sha256_update_rvv
40+
#define MH_SHA256_BLOCK_FUNCTION mh_sha256_block_rvv
41+
#include "mh_sha256_update_base.c"
42+
#undef MH_SHA256_UPDATE_FUNCTION
43+
#undef MH_SHA256_BLOCK_FUNCTION
44+
45+
/***************mh_sha256_finalize AND mh_sha256_tail***********/
46+
// mh_sha256_tail is used to calculate the last incomplete src data block
47+
// mh_sha256_finalize is a isal_mh_sha256_ctx wrapper of mh_sha256_tail
48+
// mh_sha256_finalize_rvv.c and mh_sha256_tail_rvv.c
49+
#define MH_SHA256_FINALIZE_FUNCTION mh_sha256_finalize_rvv
50+
#define MH_SHA256_TAIL_FUNCTION mh_sha256_tail_rvv
51+
#define MH_SHA256_BLOCK_FUNCTION mh_sha256_block_rvv
52+
#include "mh_sha256_finalize_base.c"
53+
#undef MH_SHA256_FINALIZE_FUNCTION
54+
#undef MH_SHA256_TAIL_FUNCTION
55+
#undef MH_SHA256_BLOCK_FUNCTION

0 commit comments

Comments
 (0)