[sw, rom_exts] Add development keys and reference signature artifacts
The idea for this change stemmed from:
https://docs.opentitan.org/sw/device/rom_exts/docs/manifest/#development-versions-subject-to-change
This change however goes beyond development key pair and adds some useful
reference files (binary to sign, SHA-256 hash of this binary, and
signatures in DER and base64 representations).
Signed-off-by: Silvestrs Timofejevs <silvestrst@lowrisc.org>
diff --git a/sw/device/rom_exts/keys/README.md b/sw/device/rom_exts/keys/README.md
new file mode 100644
index 0000000..f193421
--- /dev/null
+++ b/sw/device/rom_exts/keys/README.md
@@ -0,0 +1,112 @@
+# Introduction
+
+The main idea of the development key pair and other signing artefacts is to
+make cross-development of on device and host side components for ROM_EXT
+signing easier.
+
+It is also useful when starting new development, as it is easier to make sure
+that signing process is correct by matching the produced hashes and signatures
+against the reference files provided.
+
+Typical use-case would be - signing ROM_EXT image via host side tooling, and
+then using the same key pair on device to validate the signature.
+
+Files breakdown:
+- `test_key_private.pem` : private key (DER encoded binary) in PEM
+ representation.
+- `test_key_public.pem` : public key (DER encoded binary) in PEM
+ representation.
+`testing` sub-directory:
+- `hello_world.bin` : reference file containing "Hello World!".
+- `hello_world_digest.base64` : SHA-256 digest in base64 representation.
+- `hello_world.sign.base64` : RSASSA-PKCS1-V1_5-SIGN signature (DER encoded
+ binary) in base64 representation.
+
+** Please note that some tools/libraries require files in DER binary encoding.
+Instructions below include commands to generate DER keys and signature
+artifacts. **
+
+# Keys
+
+This guide assumes that commands are run from within `sw/device/rom_exts/keys`
+directory.
+
+`cd sw/device/rom_exts/keys`
+
+## How the key pair was generated?
+
+```
+// Private RSA key in `.pem` and `.der` representations.
+openssl genrsa -3 -out test_key_private.pem 3072
+openssl rsa -in test_key_private.pem -outform DER -out test_key_private.der
+```
+
+```
+// Public RSA key in `.pem` and `.der` representations.
+openssl rsa -in test_key_private.pem -pubout -out test_key_public.pem
+openssl rsa \
+ -in test_key_private.pem \
+ -outform DER -pubout \
+ -out test_key_public.der
+```
+
+# Hash, signature generation and verification.
+
+This guide assumes that commands are run from within
+`sw/device/rom_exts/keys/testing` directory.
+
+`cd sw/device/rom_exts/keys/testing`
+
+## How the reference file was signed?
+
+```
+// Hash generation.
+openssl dgst -sha256 -binary -out hello_world_digest.bin hello_world.bin
+
+// Convert hash from binary to base64.
+openssl base64 -in hello_world_digest.bin -out hello_world_digest.base64
+
+// Convert hash from base64 to binary.
+openssl base64 -d -in hello_world_digest.base64 -out hello_world_digest.bin
+```
+
+```
+// RSASSA-PKCS1-V1_5-SIGN.
+// For DER use `-keyform DER` and `-inkey ../test_key_private.der`.
+openssl pkeyutl \
+ -keyform PEM \
+ -inkey ../test_key_private.pem \
+ -pkeyopt rsa_padding_mode:pkcs1 \
+ -pkeyopt digest:sha256 \
+ -in hello_world_digest.bin \
+ -out hello_world.sign -sign
+```
+
+```
+// Convert the signature from binary to base64.
+openssl base64 -in hello_world.sign -out hello_world.sign.base64
+
+// Convert the signature from base64 to binary.
+openssl base64 -d -in hello_world.sign.base64 -out hello_world.sign
+```
+
+## Signature verification.
+
+```
+// From source.
+openssl dgst \
+ -sha256 \
+ -verify ../test_key_public.pem \
+ -signature hello_world.sign \
+ hello_world.bin
+```
+
+```
+// From hash.
+openssl pkeyutl \
+ -verify \
+ -in hello_world_digest.bin \
+ -sigfile hello_world.sign \
+ -pkeyopt digest:sha256 \
+ -inkey ../test_key_private.pem
+```
diff --git a/sw/device/rom_exts/keys/test_key_private.pem b/sw/device/rom_exts/keys/test_key_private.pem
new file mode 100644
index 0000000..d24715a
--- /dev/null
+++ b/sw/device/rom_exts/keys/test_key_private.pem
@@ -0,0 +1,39 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIG5AIBAAKCAYEA1UaqkxKjjxVY1TnvkaIQJGZoMky1sAVmbWmu8U6Yh/HIRfwo
+HOI7ZU6oYP2MZrC9DvGIsGAS3sjnbwmEont683dYj1ZIXGorwfozYP8ZdWXO/ADf
+spoVPCyztaJPgXM4ZKF9fOXQalW1MLd0/3hTtDbufbSCgyXSsf9oAhpQPMcIETUX
+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nI2vOPivrYeXcpapg4rEk0n70+nMZ80LFU+PrmiOMIUjx1TUdmchjOsf7rChq
+Fl2qnn9RdZCqzHZuYpEA5uOVVRzN2TZgrS9J5keQtfsMGVKUL64Tig==
+-----END RSA PRIVATE KEY-----
diff --git a/sw/device/rom_exts/keys/test_key_public.pem b/sw/device/rom_exts/keys/test_key_public.pem
new file mode 100644
index 0000000..fa708e4
--- /dev/null
+++ b/sw/device/rom_exts/keys/test_key_public.pem
@@ -0,0 +1,11 @@
+-----BEGIN PUBLIC KEY-----
+MIIBoDANBgkqhkiG9w0BAQEFAAOCAY0AMIIBiAKCAYEA1UaqkxKjjxVY1TnvkaIQ
+JGZoMky1sAVmbWmu8U6Yh/HIRfwoHOI7ZU6oYP2MZrC9DvGIsGAS3sjnbwmEont6
+83dYj1ZIXGorwfozYP8ZdWXO/ADfspoVPCyztaJPgXM4ZKF9fOXQalW1MLd0/3hT
+tDbufbSCgyXSsf9oAhpQPMcIETUXd3RuLl6frHXxpdZjLsE31mY6XxtH/VVd4nYO
+9JW8Rvx6mgv5hG/hRTw/oD+v4Px6pE6dXIPSEBElRvOiE4/MO2O01Vb4n1WgVO8g
+k5V++VB6lCGHLgEcV9NRwnIxuBr7SNAA321sSvEin9Nh7SwqK1ZK/uEBl3Y5l+JQ
+ReZD7tcJMdRqrtXspMYanyDm3JTE7zAhrbp1Q7C6CBnT8QqXKL61xIE5cb1k2/Bu
+1cZjh70uBcHz2zKntAe43Tp35kWWDEZrJkSLYZcLMmK3P6O3VzL6gJvWSu/wMs8q
+rQB1kmthD/2c2X+VCrsMarabKLmIEkWBvTtMSZRpWT5fAgED
+-----END PUBLIC KEY-----
diff --git a/sw/device/rom_exts/keys/testing/hello_world.bin b/sw/device/rom_exts/keys/testing/hello_world.bin
new file mode 100644
index 0000000..c57eff5
--- /dev/null
+++ b/sw/device/rom_exts/keys/testing/hello_world.bin
@@ -0,0 +1 @@
+Hello World!
\ No newline at end of file
diff --git a/sw/device/rom_exts/keys/testing/hello_world.sign.base64 b/sw/device/rom_exts/keys/testing/hello_world.sign.base64
new file mode 100644
index 0000000..2d3cc3d
--- /dev/null
+++ b/sw/device/rom_exts/keys/testing/hello_world.sign.base64
@@ -0,0 +1,8 @@
+X11NVgfrm7cE5zWg3ExDTZ/kQuohY2Z2xvLzhOXIXbA4Z6p6cAyslFL3CfLUyFlt
+RgO/1pKZG8ix0l86d5oKccS7+HYPJOuigEN02saQGa4pLqKD5RQ7eA036CdyLhld
+uUFECpt+jlSGS/XCtbxuMxdCqTRQ9S+a90gcxv/T1O3ZZHss9EOPMCXVF4MP6itw
+8QsDCTMCZLZP61i13RJZyUBnreR98FLCT1P6V7wFk093pgYQNHwE7trEGsAi8qxh
+/k+2AOoG79qKfxeYsctWYl+bZPLSIlnBHm6rW8zb27McHxpodVQaJS3Kvw9E4Off
+xBGqKciyIWIol9MPamYnxufV+VmHgPdLrfs7DwsW35Ep5RKuk4MOagwP6366I/6w
+re0Muaqb9hKQ6lWxyRhaBFELu1KaOphpJ6jcjjhb90WF4JzCcRpPg5jKcDoDmX2m
+oVmU/TQYsMw6c549RkIud8KykRVfFzab/AMoo1k7fUMP3Ejpg3lJa7838C6NFAKT
diff --git a/sw/device/rom_exts/keys/testing/hello_world_digest.base64 b/sw/device/rom_exts/keys/testing/hello_world_digest.base64
new file mode 100644
index 0000000..79c4de5
--- /dev/null
+++ b/sw/device/rom_exts/keys/testing/hello_world_digest.base64
@@ -0,0 +1 @@
+f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=