+static int rme_parse_rpv(uint8_t *out, const char *in, Error **errp)
+{
+ int ret;
+ size_t in_len = strlen(in);
+
+ /* Two chars per byte */
+ if (in_len > KVM_CAP_ARM_RME_RPV_SIZE * 2) {
+ error_setg(errp, "Realm Personalization Value is too large");
+ return -E2BIG;
+ }
+
+ /*
+ * Parse as big-endian hexadecimal number (most significant byte on the
+ * left), store little-endian, zero-padded on the right.
+ */
+ while (in_len) {
+ /*
+ * Do the lower nibble first to catch invalid inputs such as '2z', and
+ * to handle the last char.
+ */
+ in_len--;
+ ret = sscanf(in + in_len, "%1hhx", out);
+ if (ret != 1) {
+ error_setg(errp, "Invalid Realm Personalization Value");
+ return -EINVAL;
+ }
+ if (!in_len) {
+ break;
+ }
+ in_len--;
+ ret = sscanf(in + in_len, "%2hhx", out++);
+ if (ret != 1) {
+ error_setg(errp, "Invalid Realm Personalization Value");
+ return -EINVAL;
+ }
+ }