xemu/backends
zhenwei pi 0e660a6f90 crypto: Introduce RSA algorithm
There are two parts in this patch:
1, support akcipher service by cryptodev-builtin driver
2, virtio-crypto driver supports akcipher service

In principle, we should separate this into two patches, to avoid
compiling error, merge them into one.

Then virtio-crypto gets request from guest side, and forwards the
request to builtin driver to handle it.

Test with a guest linux:
1, The self-test framework of crypto layer works fine in guest kernel
2, Test with Linux guest(with asym support), the following script
test(note that pkey_XXX is supported only in a newer version of keyutils):
  - both public key & private key
  - create/close session
  - encrypt/decrypt/sign/verify basic driver operation
  - also test with kernel crypto layer(pkey add/query)

All the cases work fine.

Run script in guest:
rm -rf *.der *.pem *.pfx
modprobe pkcs8_key_parser # if CONFIG_PKCS8_PRIVATE_KEY_PARSER=m
rm -rf /tmp/data
dd if=/dev/random of=/tmp/data count=1 bs=20

openssl req -nodes -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/C=CN/ST=BJ/L=HD/O=qemu/OU=dev/CN=qemu/emailAddress=qemu@qemu.org"
openssl pkcs8 -in key.pem -topk8 -nocrypt -outform DER -out key.der
openssl x509 -in cert.pem -inform PEM -outform DER -out cert.der

PRIV_KEY_ID=`cat key.der | keyctl padd asymmetric test_priv_key @s`
echo "priv key id = "$PRIV_KEY_ID
PUB_KEY_ID=`cat cert.der | keyctl padd asymmetric test_pub_key @s`
echo "pub key id = "$PUB_KEY_ID

keyctl pkey_query $PRIV_KEY_ID 0
keyctl pkey_query $PUB_KEY_ID 0

echo "Enc with priv key..."
keyctl pkey_encrypt $PRIV_KEY_ID 0 /tmp/data enc=pkcs1 >/tmp/enc.priv
echo "Dec with pub key..."
keyctl pkey_decrypt $PRIV_KEY_ID 0 /tmp/enc.priv enc=pkcs1 >/tmp/dec
cmp /tmp/data /tmp/dec

echo "Sign with priv key..."
keyctl pkey_sign $PRIV_KEY_ID 0 /tmp/data enc=pkcs1 hash=sha1 > /tmp/sig
echo "Verify with pub key..."
keyctl pkey_verify $PRIV_KEY_ID 0 /tmp/data /tmp/sig enc=pkcs1 hash=sha1

echo "Enc with pub key..."
keyctl pkey_encrypt $PUB_KEY_ID 0 /tmp/data enc=pkcs1 >/tmp/enc.pub
echo "Dec with priv key..."
keyctl pkey_decrypt $PRIV_KEY_ID 0 /tmp/enc.pub enc=pkcs1 >/tmp/dec
cmp /tmp/data /tmp/dec

echo "Verify with pub key..."
keyctl pkey_verify $PUB_KEY_ID 0 /tmp/data /tmp/sig enc=pkcs1 hash=sha1

Reviewed-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: lei he <helei.sig11@bytedance.com
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Message-Id: <20220611064243.24535-2-pizhenwei@bytedance.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2022-06-16 12:54:58 -04:00
..
tpm Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
confidential-guest-support.c confidential guest support: Introduce new confidential guest support class 2021-02-08 16:57:37 +11:00
cryptodev-builtin.c crypto: Introduce RSA algorithm 2022-06-16 12:54:58 -04:00
cryptodev-vhost-user.c crypto: Introduce RSA algorithm 2022-06-16 12:54:58 -04:00
cryptodev-vhost.c vhost: Add Error parameter to vhost_dev_init() 2021-06-30 13:15:44 +02:00
cryptodev.c crypto: Introduce RSA algorithm 2022-06-16 12:54:58 -04:00
dbus-vmstate.c dbus-vmstate: Increase the size of input stream buffer used during load 2021-04-01 15:27:44 +04:00
dbus-vmstate1.xml docs: move D-Bus VMState documentation to source XML 2021-12-21 10:50:21 +04:00
hostmem-epc.c Remove qemu-common.h include from most units 2022-04-06 14:31:55 +02:00
hostmem-file.c include: Move qemu_madvise() and related #defines to new qemu/madvise.h 2022-02-21 13:30:20 +00:00
hostmem-memfd.c hostmem: Wire up RAM_NORESERVE via "reserve" property 2021-06-15 20:27:38 +02:00
hostmem-ram.c hostmem: Wire up RAM_NORESERVE via "reserve" property 2021-06-15 20:27:38 +02:00
hostmem.c hostmem: default the amount of prealloc-threads to smp-cpus 2022-05-23 10:56:01 +02:00
Kconfig tpm: Move backend code under the 'backends/' directory 2020-06-19 07:25:55 -04:00
meson.build meson: use have_vhost_* variables to pick sources 2022-05-07 07:46:58 +02:00
rng-builtin.c replay: rng-builtin support 2021-02-08 15:15:32 +01:00
rng-egd.c rng-egd: Register "chardev" as class property 2020-10-13 15:56:30 -04:00
rng-random.c rng-random: register "filename" as class property 2020-10-13 15:56:30 -04:00
rng.c rng: make opened property read-only 2022-05-14 12:33:44 +02:00
trace-events docs: fix references to docs/devel/tracing.rst 2021-06-02 06:51:09 +02:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vhost-user.c vhost: Add Error parameter to vhost_dev_init() 2021-06-30 13:15:44 +02:00