Skip to content

Commit

Permalink
riscv: sha256: Provide a Zvknha-based implementation
Browse files Browse the repository at this point in the history
The upcoming RISC-V vector crypto extensions feature
a Zvknha extension, that provides sha256-specific instructions.
This patch provides an implementation that utilizes this
extension if available.

Tested on QEMU and no regressions observed.

Signed-off-by: Charalampos Mitrodimas <charalampos.mitrodimas@vrull.eu>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #21923)
  • Loading branch information
Charalampos Mitrodimas authored and hlandau committed Oct 26, 2023
1 parent 204a1c9 commit 1707306
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 0 deletions.
81 changes: 81 additions & 0 deletions crypto/perlasm/riscv.pm
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ sub rev8 {

# Vector instructions

sub vadd_vv {
# vadd.vv vd, vs2, vs1
my $template = 0b0000001_00000_00000_000_00000_1010111;
my $vd = read_vreg shift;
my $vs2 = read_vreg shift;
my $vs1 = read_vreg shift;
return ".word ".($template | ($vs2 << 20) | ($vs1 << 15) | ($vd << 7));
}

sub vid_v {
# vid.v vd
my $template = 0b0101001_00000_10001_010_00000_1010111;
my $vd = read_vreg shift;
return ".word ".($template | ($vd << 7));
}

sub vle32_v {
# vle32.v vd, (rs1)
my $template = 0b0000001_00000_00000_110_00000_0000111;
Expand All @@ -297,6 +313,15 @@ sub vle64_v {
return ".word ".($template | ($rs1 << 15) | ($vd << 7));
}

sub vlse32_v {
# vlse32.v vd, (rs1), rs2
my $template = 0b0000101_00000_00000_110_00000_0000111;
my $vd = read_vreg shift;
my $rs1 = read_reg shift;
my $rs2 = read_reg shift;
return ".word ".($template | ($rs2 << 20) | ($rs1 << 15) | ($vd << 7));
}

sub vlse64_v {
# vlse64.v vd, (rs1), rs2
my $template = 0b0000101_00000_00000_111_00000_0000111;
Expand All @@ -315,6 +340,24 @@ sub vmerge_vim {
return ".word ".($template | ($vs2 << 20) | ($imm << 15) | ($vd << 7));
}

sub vmerge_vvm {
# vmerge.vvm vd vs2 vs1
my $template = 0b0101110_00000_00000_000_00000_1010111;
my $vd = read_vreg shift;
my $vs2 = read_vreg shift;
my $vs1 = read_vreg shift;
return ".word ".($template | ($vs2 << 20) | ($vs1 << 15) | ($vd << 7))
}

sub vmseq_vi {
# vmseq vd vs1, imm
my $template = 0b0110001_00000_00000_011_00000_1010111;
my $vd = read_vreg shift;
my $vs1 = read_vreg shift;
my $imm = shift;
return ".word ".($template | ($vs1 << 20) | ($imm << 15) | ($vd << 7))
}

sub vmv_v_i {
# vmv.v.i vd, imm
my $template = 0b0101111_00000_00000_011_00000_1010111;
Expand Down Expand Up @@ -411,6 +454,15 @@ sub vsrl_vx {
return ".word ".($template | ($vs2 << 20) | ($rs1 << 15) | ($vd << 7));
}

sub vsse32_v {
# vse32.v vs3, (rs1), rs2
my $template = 0b0000101_00000_00000_110_00000_0100111;
my $vs3 = read_vreg shift;
my $rs1 = read_reg shift;
my $rs2 = read_reg shift;
return ".word ".($template | ($rs2 << 20) | ($rs1 << 15) | ($vs3 << 7));
}

sub vsse64_v {
# vsse64.v vs3, (rs1), rs2
my $template = 0b0000101_00000_00000_111_00000_0100111;
Expand Down Expand Up @@ -558,4 +610,33 @@ sub vaesz_vs {
return ".word ".($template | ($vs2 << 20) | ($vd << 7));
}

## Zvknha instructions

sub vsha2ms_vv {
# vsha2ms.vv vd, vs2, vs1
my $template = 0b1011011_00000_00000_010_00000_1110111;
my $vd = read_vreg shift;
my $vs2 = read_vreg shift;
my $vs1 = read_vreg shift;
return ".word ".($template | ($vs2 << 20)| ($vs1 << 15 )| ($vd << 7));
}

sub vsha2ch_vv {
# vsha2ch.vv vd, vs2, vs1
my $template = 0b101110_10000_00000_001_00000_01110111;
my $vd = read_vreg shift;
my $vs2 = read_vreg shift;
my $vs1 = read_vreg shift;
return ".word ".($template | ($vs2 << 20)| ($vs1 << 15 )| ($vd << 7));
}

sub vsha2cl_vv {
# vsha2cl.vv vd, vs2, vs1
my $template = 0b101111_10000_00000_001_00000_01110111;
my $vd = read_vreg shift;
my $vs2 = read_vreg shift;
my $vs1 = read_vreg shift;
return ".word ".($template | ($vs2 << 20)| ($vs1 << 15 )| ($vd << 7));
}

1;

0 comments on commit 1707306

Please sign in to comment.