diff options
author | Ben Marshall <ben-marshall@users.noreply.github.com> | 2021-01-22 22:11:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-22 14:11:00 -0800 |
commit | d6238d9945d029be956ae7c3e10b532b542e6f36 (patch) | |
tree | 43221f50f74032add50498ac1d9c5da509f17c43 /riscv/insns/sm4ed.h | |
parent | ccdbfacc9f3eb84e2f2f6c6e3a8e9ee6160c8a15 (diff) | |
download | spike-d6238d9945d029be956ae7c3e10b532b542e6f36.zip spike-d6238d9945d029be956ae7c3e10b532b542e6f36.tar.gz spike-d6238d9945d029be956ae7c3e10b532b542e6f36.tar.bz2 |
scalar-crypto: Initial spike support for v0.8.1 (#635)
Brief:
- This commit adds spike support for the scalar cryptography extension.
See the riscv-crypto repository (https://github.com/riscv/riscv-crypto)
for more information on this extension.
- It is based on the experimental patch which has so far been kept in the
riscv-crypto repository. Now that scalar crypto is nearly at the "freeze"
stage and entering opcode consistency review, it makes sense to start
upstreaming our experimental version.
- In terms of compiler support - we are using an experimental patch in
the riscv-crypto repository at the moment, others are working on an
upstream appropriate version.
Details:
- Add support for dedicated scalar crypto instructions.
- Add very basic support for the entropy source (entropy_source.h).
Much of the behaviour of this is implementation specific. This model
aims to provide the bare minimum of functionality which can be used to
quickly develop software. It uses /dev/urandom as its entropy source for
now.
- Scalar crypto is unique in that it _borrows_ instructions from the
Bitmanipulation extension. This is currently _not_ encoded in the patch,
as I didn't want to damage anything in Bitmanip which is currently under
review. However, I've added a macro in riscv/decode.h called
"require_either_extension(A,B)", which allows instructions to be valid
opcodes iff they are in one or both extensions.
On branch scalar-crypto
Changes to be committed:
modified: README.md
modified: riscv/decode.h
modified: riscv/encoding.h
new file: riscv/entropy_source.h
new file: riscv/insns/aes64im.h
new file: riscv/insns/aes64ks1i.h
new file: riscv/insns/aes64ks2.h
new file: riscv/insns/aes_common.h
new file: riscv/insns/aesds.h
new file: riscv/insns/aesdsm.h
new file: riscv/insns/aeses.h
new file: riscv/insns/aesesm.h
new file: riscv/insns/sha256sig0.h
new file: riscv/insns/sha256sig1.h
new file: riscv/insns/sha256sum0.h
new file: riscv/insns/sha256sum1.h
new file: riscv/insns/sha512sig0.h
new file: riscv/insns/sha512sig0h.h
new file: riscv/insns/sha512sig0l.h
new file: riscv/insns/sha512sig1.h
new file: riscv/insns/sha512sig1h.h
new file: riscv/insns/sha512sig1l.h
new file: riscv/insns/sha512sum0.h
new file: riscv/insns/sha512sum0r.h
new file: riscv/insns/sha512sum1.h
new file: riscv/insns/sha512sum1r.h
new file: riscv/insns/sm3p0.h
new file: riscv/insns/sm3p1.h
new file: riscv/insns/sm4_common.h
new file: riscv/insns/sm4ed.h
new file: riscv/insns/sm4ks.h
modified: riscv/processor.cc
modified: riscv/processor.h
modified: riscv/riscv.mk.in
Diffstat (limited to 'riscv/insns/sm4ed.h')
-rw-r--r-- | riscv/insns/sm4ed.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/riscv/insns/sm4ed.h b/riscv/insns/sm4ed.h new file mode 100644 index 0000000..5583335 --- /dev/null +++ b/riscv/insns/sm4ed.h @@ -0,0 +1,23 @@ + +require_extension('K'); + +#include "sm4_common.h" + +uint8_t bs = insn.bs(); + +uint32_t sb_in = (RS2 >> (8*bs)) & 0xFF; +uint32_t sb_out = (uint32_t)sm4_sbox[sb_in]; + +uint32_t linear = sb_out ^ (sb_out << 8) ^ + (sb_out << 2) ^ + (sb_out << 18) ^ + ((sb_out & 0x3f) << 26) ^ + ((sb_out & 0xC0) << 10) ; + +uint32_t rotl = (linear << (8*bs)) | (linear >> (32-8*bs)); + +uint32_t result = rotl ^ RS1; +uint64_t rd = insn.rs1(); // RD sourced from RS1 field. + +WRITE_REG(rd, zext_xlen(result)); + |