]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/crypto: Add Support for Query Authentication Information
authorFinn Callies <fcallies@linux.ibm.com>
Wed, 11 Sep 2024 07:21:08 +0000 (09:21 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Thu, 12 Sep 2024 12:13:27 +0000 (14:13 +0200)
Introduce functions __cpacf_qai() and wrapper cpacf_qai() to the
respective existing functions __cpacf_query() and cpacf_query() are
introduced to support the Query Authentication Information feature of
MSA 13.

Suggested-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Harald Freudenberger <freude@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Finn Callies <fcallies@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/include/asm/cpacf.h

index 52652f0acfcea5bb109414a00398ea75bd42e278..1d3a4b0c650fc12ae8f32292fdd967f59fe6dc37 100644 (file)
 #define CPACF_KDSA_ENC_EDDSA_SIGN_ED448 0x34
 
 #define CPACF_FC_QUERY 0x00
+#define CPACF_FC_QUERY_AUTH_INFO 0x7F
 
 typedef struct { unsigned char bytes[16]; } cpacf_mask_t;
+typedef struct { unsigned char bytes[256]; } cpacf_qai_t;
 
 /*
  * Prototype for a not existing function to produce a link
@@ -349,7 +351,8 @@ static inline int cpacf_test_func(cpacf_mask_t *mask, unsigned int func)
        return (mask->bytes[func >> 3] & (0x80 >> (func & 7))) != 0;
 }
 
-static __always_inline int cpacf_query_func(unsigned int opcode, unsigned int func)
+static __always_inline int cpacf_query_func(unsigned int opcode,
+                                           unsigned int func)
 {
        cpacf_mask_t mask;
 
@@ -358,6 +361,32 @@ static __always_inline int cpacf_query_func(unsigned int opcode, unsigned int fu
        return 0;
 }
 
+static __always_inline void __cpacf_qai(unsigned int opcode, cpacf_qai_t *qai)
+{
+       __cpacf_query_insn(opcode, qai, CPACF_FC_QUERY_AUTH_INFO);
+}
+
+/**
+ * cpacf_qai() - Get the query authentication information for a CPACF opcode
+ * @opcode: the opcode of the crypto instruction
+ * @mask: ptr to struct cpacf_qai_t
+ *
+ * Executes the query authentication information function for the given crypto
+ * instruction @opcode and checks if @func is available
+ *
+ * On success 1 is returned and the mask is filled with the query authentication
+ * information for this CPACF opcode, otherwise 0 is returned.
+ */
+static __always_inline int cpacf_qai(unsigned int opcode, cpacf_qai_t *qai)
+{
+       if (cpacf_query_func(opcode, CPACF_FC_QUERY_AUTH_INFO)) {
+               __cpacf_qai(opcode, qai);
+               return 1;
+       }
+       memset(qai, 0, sizeof(*qai));
+       return 0;
+}
+
 /**
  * cpacf_km() - executes the KM (CIPHER MESSAGE) instruction
  * @func: the function code passed to KM; see CPACF_KM_xxx defines