Skip to content

Commit fd1c787

Browse files
committed
Integrating Zvkgs specification inside Zvkg chapter
1 parent 3e0efea commit fd1c787

File tree

1 file changed

+78
-32
lines changed

1 file changed

+78
-32
lines changed

src/vector-crypto.adoc

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ Note: If `Zve32x` is supported then `Zvkb` or `Zvbb` provide support for EEW of
491491

492492

493493
All _cryptography-specific_ instructions defined in this Vector Crypto specification (i.e., those
494-
in <<zvkned>>, <<zvknh,Zvknh[ab]>>, <<Zvkg>>, <<Zvksed>> and <<zvksh>> but _not_ <<zvbb>>, <<zvkb>>, <<zvbc>> or <<zvbc,Zvbc32e>>) shall
494+
in <<zvkned>>, <<zvknh,Zvknh[ab]>>, <<Zvkg>>, <<Zvkg,Zvkgs>>, <<Zvksed>> and <<zvksh>> but _not_ <<zvbb>>, <<zvkb>>, <<zvbc>> or <<zvbc,Zvbc32e>>) shall
495495
be executed with data-independent execution latency as defined in the
496496
<<#crypto_scalar_instructions,RISC-V Scalar Cryptography Extensions specification>>.
497497
It is important to note that the Vector Crypto instructions are independent of the
@@ -600,11 +600,15 @@ in the Zvbb extension: vbrev.v, vclz.v, vctz.v, vcpop.v, and vwsll.[vv,vx,vi].
600600
<<<
601601

602602
[[zvkg,Zvkg]]
603-
==== `Zvkg` - Vector GCM/GMAC
603+
==== `Zvkg` and `Zvkgs` - Vector GCM/GMAC
604604

605605
Instructions to enable the efficient implementation of GHASH~H~ which is used in Galois/Counter Mode (GCM) and
606606
Galois Message Authentication Code (GMAC).
607607

608+
Zvkg defines the vector-vector (.vv) versions of the instructions.
609+
Zvkgs defines the vector-scalar (.vs) versions of the instructions.
610+
Zvkgs depends on Zvkg.
611+
608612
All of these instructions work on 128-bit element groups comprised of four 32-bit elements.
609613

610614
GHASH~H~ is defined in the
@@ -635,8 +639,8 @@ Likewise, `vstart` must be a multiple of `EGS=4`.
635639
|EGW
636640
|Mnemonic
637641
|Instruction
638-
| 32 | 128 | vghsh.vv | <<insns-vghsh>>
639-
| 32 | 128 | vgmul.vv | <<insns-vgmul>>
642+
| 32 | 128 | vghsh.[vv,vs] | <<insns-vghsh>>
643+
| 32 | 128 | vgmul.[vv,vs] | <<insns-vgmul>>
640644

641645
|===
642646

@@ -880,7 +884,7 @@ This extension is shorthand for the following set of other extensions:
880884

881885
[NOTE]
882886
====
883-
While Zvkg and Zvbc are not part of this extension, it is recommended that at least one of them is implemented with this extension to enable efficient AES-GCM.
887+
While Zvkg, Zvkgs and Zvbc are not part of this extension, it is recommended that at least one of them is implemented with this extension to enable efficient AES-GCM.
884888
====
885889

886890
<<<
@@ -955,7 +959,7 @@ This extension is shorthand for the following set of other extensions:
955959

956960
[NOTE]
957961
====
958-
While Zvkg and Zvbc are not part of this extension, it is recommended that at least one of them is implemented with this extension to enable efficient SM4-GCM.
962+
While Zvkg, Zvkgs and Zvbc are not part of this extension, it is recommended that at least one of them is implemented with this extension to enable efficient SM4-GCM.
959963
====
960964

961965
<<<
@@ -2559,15 +2563,16 @@ Included in::
25592563
<<<
25602564

25612565
[[insns-vghsh, Vector GHASH Add-Multiply]]
2562-
==== vghsh.vv
2566+
==== vghsh.[vv,vs]
25632567

25642568
Synopsis::
25652569
Vector Add-Multiply over GHASH Galois-Field
25662570

25672571
Mnemonic::
2568-
vghsh.vv vd, vs2, vs1
2572+
vghsh.vv vd, vs2, vs1 +
2573+
vghsh.vs vd, vs2, vs1
25692574

2570-
Encoding::
2575+
Encoding (Vector-Vector)::
25712576
[wavedrom, , svg]
25722577
....
25732578
{reg:[
@@ -2580,8 +2585,26 @@ Encoding::
25802585
{bits: 6, name: '101100'},
25812586
]}
25822587
....
2588+
2589+
Encoding (Vector-Scalar)::
2590+
[wavedrom, , svg]
2591+
....
2592+
{reg:[
2593+
{bits: 7, name: 'OP-VE'},
2594+
{bits: 5, name: 'vd'},
2595+
{bits: 3, name: 'OPMVV'},
2596+
{bits: 5, name: 'vs1'},
2597+
{bits: 5, name: 'vs2'},
2598+
{bits: 1, name: '1'},
2599+
{bits: 6, name: '100011'},
2600+
]}
2601+
....
2602+
2603+
2604+
25832605
Reserved Encodings::
25842606
* `SEW` is any value other than 32
2607+
* Only for the `.vs` form: the `vd` register group overlaps the `vs2` scalar element group
25852608

25862609
Arguments::
25872610

@@ -2604,6 +2627,11 @@ Arguments::
26042627
Description::
26052628
A single "iteration" of the GHASH~H~ algorithm is performed.
26062629

2630+
The previous partial hashes are read as 4-element groups from `vd`,
2631+
the cipher texts are read as 4-element groups from `vs1`
2632+
and the hash subkey is read either as 4-element groups from `vs2` (`vghsh.vv`) or from the scalar 4-element group in `vs2` (`vghsh.vs`).
2633+
The resulting partial hashes are written as 4-element groups into `vd`.
2634+
26072635
This instruction treats all of the inputs and outputs as 128-bit polynomials and
26082636
performs operations over GF[2].
26092637
It produces the next partial hash (Y~i+1~) by adding the current partial
@@ -2634,12 +2662,6 @@ with the NIST specification. These reversals are inexpensive to implement as the
26342662
swap bit positions and therefore do not require any logic.
26352663
====
26362664

2637-
[NOTE]
2638-
====
2639-
Since the same hash subkey `H` will typically be used repeatedly on a given message,
2640-
a future extension might define a vector-scalar version of this instruction where
2641-
`vs2` is the scalar element group. This would help reduce register pressure when `LMUL` > 1.
2642-
====
26432665

26442666
Operation::
26452667
[source,pseudocode]
@@ -2655,9 +2677,10 @@ function clause execute (VGHSH(vs2, vs1, vd)) = {
26552677
eg_start = (vstart/EGS)
26562678

26572679
foreach (i from eg_start to eg_len-1) {
2680+
let hindex = if suffix=="vv" then i else 0;
26582681
let Y = (get_velem(vd,EGW=128,i)); // current partial-hash
26592682
let X = get_velem(vs1,EGW=128,i); // block cipher output
2660-
let H = brev8(get_velem(vs2,EGW=128,i)); // Hash subkey
2683+
let H = brev8(get_velem(vs2,EGW=128,hindex)); // Hash subkey
26612684

26622685
let Z : bits(128) = 0;
26632686

@@ -2681,21 +2704,25 @@ function clause execute (VGHSH(vs2, vs1, vd)) = {
26812704
}
26822705
--
26832706

2684-
Included in::
2707+
`vghsh.vv` is included in::
26852708
<<zvkg>>, <<zvkng>>, <<zvksg>>
26862709

2710+
`vghsh.vs` is included in::
2711+
<<zvkg,Zvkgs>>
2712+
26872713
<<<
26882714

26892715
[[insns-vgmul, Vector GHASH Multiply]]
2690-
==== vgmul.vv
2716+
==== vgmul.[vv,vs]
26912717

26922718
Synopsis::
26932719
Vector Multiply over GHASH Galois-Field
26942720

26952721
Mnemonic::
2696-
vgmul.vv vd, vs2
2722+
vgmul.vv vd, vs2 +
2723+
vgmul.vs vd, vs2
26972724

2698-
Encoding::
2725+
Encoding (Vector-Vector)::
26992726
[wavedrom, , svg]
27002727
....
27012728
{reg:[
@@ -2708,8 +2735,24 @@ Encoding::
27082735
{bits: 6, name: '101000'},
27092736
]}
27102737
....
2738+
2739+
Encoding (Vector-Scalar)::
2740+
[wavedrom, , svg]
2741+
....
2742+
{reg:[
2743+
{bits: 7, name: 'OP-VE'},
2744+
{bits: 5, name: 'vd'},
2745+
{bits: 3, name: 'OPMVV'},
2746+
{bits: 5, name: '10001'},
2747+
{bits: 5, name: 'vs2'},
2748+
{bits: 1, name: '1'},
2749+
{bits: 6, name: '101001'},
2750+
]}
2751+
....
2752+
27112753
Reserved Encodings::
27122754
* `SEW` is any value other than 32
2755+
* Only for the `.vs` form: the `vd` register group overlaps the `vs2` scalar element group
27132756

27142757
Arguments::
27152758

@@ -2731,6 +2774,11 @@ Arguments::
27312774
Description::
27322775
A GHASH~H~ multiply is performed.
27332776

2777+
2778+
The multipliers are read as 4-element groups from `vd`,
2779+
the multiplicand subkey is read either as 4-element groups from `vs2` (`vgmul.vv`) or from the scalar element group in `vs2` (`vgmul.vs`).
2780+
The resulting products are written as 4-element groups into `vd`.
2781+
27342782
This instruction treats all of the inputs and outputs as 128-bit polynomials and
27352783
performs operations over GF[2].
27362784
It produces the product over GF(2^128^) of the two 128-bit inputs.
@@ -2755,20 +2803,14 @@ with the NIST specification. These reversals are inexpensive to implement as the
27552803
swap bit positions and therefore do not require any logic.
27562804
====
27572805

2758-
[NOTE]
2759-
====
2760-
Since the same multiplicand will typically be used repeatedly on a given message,
2761-
a future extension might define a vector-scalar version of this instruction where
2762-
`vs2` is the scalar element group. This would help reduce register pressure when `LMUL` > 1.
2763-
====
27642806

27652807
[NOTE]
27662808
====
2767-
This instruction is identical to `vghsh.vv` with vs1=0.
2809+
This instruction is identical to `vghsh.vv` (respectively `vghsh.vs`) with vs1=0.
27682810
This instruction is often used in GHASH code. In some cases it is followed
27692811
by an XOR to perform a multiply-add. Implementations may choose to fuse these
27702812
two instructions to improve performance on GHASH code that
2771-
doesn't use the add-multiply form of the `vghsh.vv` instruction.
2813+
doesn't use the add-multiply form of the `vghsh.[vv,vs]` instruction.
27722814
====
27732815

27742816

@@ -2786,8 +2828,9 @@ function clause execute (VGMUL(vs2, vs1, vd)) = {
27862828
eg_start = (vstart/EGS)
27872829

27882830
foreach (i from eg_start to eg_len-1) {
2831+
let hindex = if suffix=="vv" then i else 0;
27892832
let Y = brev8(get_velem(vd,EGW=128,i)); // Multiplier
2790-
let H = brev8(get_velem(vs2,EGW=128,i)); // Multiplicand
2833+
let H = brev8(get_velem(vs2,EGW=128,hindex)); // Multiplicand
27912834
let Z : bits(128) = 0;
27922835

27932836
for (int bit = 0; bit < 128; bit++) {
@@ -2809,9 +2852,12 @@ function clause execute (VGMUL(vs2, vs1, vd)) = {
28092852
}
28102853
--
28112854

2812-
Included in::
2855+
`vgmul.vv` included in::
28132856
<<zvkg>>, <<zvkng>>, <<zvksg>>
28142857

2858+
`vgmul.vs` included in::
2859+
<<zvkg, Zvkgs>>
2860+
28152861
<<<
28162862

28172863
[[insns-vrev8, Vector Reverse Bytes]]
@@ -4402,7 +4448,7 @@ Crypto Vector instructions except Zvbb and Zvbc
44024448
|100000||||| 100000 |V| | vsm3me | 100000 | | |
44034449
| 100001 | | | | | 100001 |V| | vsm4k.vi | 100001 | | |
44044450
| 100010 | | | | | 100010 |V| | vaeskf1.vi | 100010 | | |
4405-
| 100011 | | | | | 100011 | | | | 100011 | | |
4451+
| 100011 | | | | | 100011 | | | vghsh.vs | 100011 | | |
44064452
| 100100 | | | | | 100100 | | | | 100100 | | |
44074453
| 100101 | | | | | 100101 | | | | 100101 | | |
44084454
| 100110 | | | | | 100110 | | | | 100110 | | |
@@ -4412,7 +4458,7 @@ Crypto Vector instructions except Zvbb and Zvbc
44124458
| 101001 | | | | | 101001 |V| | *VAES.vs* | 101001 | | |
44134459
| 101010 | | | | | 101010 |V| | vaeskf2.vi | 101010 | | |
44144460
| 101011 | | | | | 101011 |V| | vsm3c.vi | 101011 | | |
4415-
| 101100 | | | | | 101100 |V| | vghsh | 101100 | | |
4461+
| 101100 | | | | | 101100 |V| | vghsh.vv | 101100 | | |
44164462
| 101101 | | | | | 101101 |V| | vsha2ms | 101101 | | |
44174463
| 101110 | | | | | 101110 |V| | vsha2ch | 101110 | | |
44184464
| 101111 | | | | | 101111 |V| | vsha2cl | 101111 | | |

0 commit comments

Comments
 (0)