/* * Prototype for a not existing function to produce a link * error if __cpacf_query() or __cpacf_check_opcode() is used * with an invalid compile time const opcode.
*/ void __cpacf_bad_opcode(void);
static __always_inline int __cpacf_check_opcode(unsignedint opcode)
{ switch (opcode) { case CPACF_KMAC: case CPACF_KM: case CPACF_KMC: case CPACF_KIMD: case CPACF_KLMD: return test_facility(17); /* check for MSA */ case CPACF_PCKMO: return test_facility(76); /* check for MSA3 */ case CPACF_KMF: case CPACF_KMO: case CPACF_PCC: case CPACF_KMCTR: return test_facility(77); /* check for MSA4 */ case CPACF_PRNO: return test_facility(57); /* check for MSA5 */ case CPACF_KMA: return test_facility(146); /* check for MSA8 */ case CPACF_KDSA: return test_facility(155); /* check for MSA9 */ default:
__cpacf_bad_opcode(); return 0;
}
}
/** * cpacf_query() - Query the function code mask for this CPACF opcode * @opcode: the opcode of the crypto instruction * @mask: ptr to struct cpacf_mask_t * * Executes the query 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 function * code mask for this CPACF opcode, otherwise 0 is returned.
*/ static __always_inline int cpacf_query(unsignedint opcode, cpacf_mask_t *mask)
{ if (__cpacf_check_opcode(opcode)) {
__cpacf_query(opcode, mask); return 1;
}
memset(mask, 0, sizeof(*mask)); return 0;
}
/** * 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(unsignedint 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 * @param: address of parameter block; see POP for details on each func * @dest: address of destination memory area * @src: address of source memory area * @src_len: length of src operand in bytes * * Returns 0 for the query func, number of processed bytes for * encryption/decryption funcs
*/ staticinlineint cpacf_km(unsignedlong func, void *param,
u8 *dest, const u8 *src, long src_len)
{ union register_pair d, s;
/** * cpacf_kmc() - executes the KMC (CIPHER MESSAGE WITH CHAINING) instruction * @func: the function code passed to KM; see CPACF_KMC_xxx defines * @param: address of parameter block; see POP for details on each func * @dest: address of destination memory area * @src: address of source memory area * @src_len: length of src operand in bytes * * Returns 0 for the query func, number of processed bytes for * encryption/decryption funcs
*/ staticinlineint cpacf_kmc(unsignedlong func, void *param,
u8 *dest, const u8 *src, long src_len)
{ union register_pair d, s;
/** * cpacf_kimd() - executes the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) * instruction * @func: the function code passed to KM; see CPACF_KIMD_xxx defines * @param: address of parameter block; see POP for details on each func * @src: address of source memory area * @src_len: length of src operand in bytes
*/ staticinlinevoid cpacf_kimd(unsignedlong func, void *param, const u8 *src, long src_len)
{ union register_pair s;
/** * cpacf_klmd() - executes the KLMD (COMPUTE LAST MESSAGE DIGEST) instruction * @func: the function code passed to KM; see CPACF_KLMD_xxx defines * @param: address of parameter block; see POP for details on each func * @src: address of source memory area * @src_len: length of src operand in bytes
*/ staticinlinevoid cpacf_klmd(unsignedlong func, void *param, const u8 *src, long src_len)
{ union register_pair s;
/** * _cpacf_kmac() - executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) * instruction and updates flags in gr0 * @gr0: pointer to gr0 (fc and flags) passed to KMAC; see CPACF_KMAC_xxx defines * @param: address of parameter block; see POP for details on each func * @src: address of source memory area * @src_len: length of src operand in bytes * * Returns 0 for the query func, number of processed bytes for digest funcs
*/ staticinlineint _cpacf_kmac(unsignedlong *gr0, void *param, const u8 *src, long src_len)
{ union register_pair s;
/** * cpacf_kmac() - executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) * instruction * @func: function code passed to KMAC; see CPACF_KMAC_xxx defines * @param: address of parameter block; see POP for details on each func * @src: address of source memory area * @src_len: length of src operand in bytes * * Returns 0 for the query func, number of processed bytes for digest funcs
*/ staticinlineint cpacf_kmac(unsignedlong func, void *param, const u8 *src, long src_len)
{ return _cpacf_kmac(&func, param, src, src_len);
}
/** * cpacf_kmctr() - executes the KMCTR (CIPHER MESSAGE WITH COUNTER) instruction * @func: the function code passed to KMCTR; see CPACF_KMCTR_xxx defines * @param: address of parameter block; see POP for details on each func * @dest: address of destination memory area * @src: address of source memory area * @src_len: length of src operand in bytes * @counter: address of counter value * * Returns 0 for the query func, number of processed bytes for * encryption/decryption funcs
*/ staticinlineint cpacf_kmctr(unsignedlong func, void *param, u8 *dest, const u8 *src, long src_len, u8 *counter)
{ union register_pair d, s, c;
/** * cpacf_prno() - executes the PRNO (PERFORM RANDOM NUMBER OPERATION) * instruction * @func: the function code passed to PRNO; see CPACF_PRNO_xxx defines * @param: address of parameter block; see POP for details on each func * @dest: address of destination memory area * @dest_len: size of destination memory area in bytes * @seed: address of seed data * @seed_len: size of seed data in bytes
*/ staticinlinevoid cpacf_prno(unsignedlong func, void *param,
u8 *dest, unsignedlong dest_len, const u8 *seed, unsignedlong seed_len)
{ union register_pair d, s;
/** * cpacf_trng() - executes the TRNG subfunction of the PRNO instruction * @ucbuf: buffer for unconditioned data * @ucbuf_len: amount of unconditioned data to fetch in bytes * @cbuf: buffer for conditioned data * @cbuf_len: amount of conditioned data to fetch in bytes
*/ staticinlinevoid cpacf_trng(u8 *ucbuf, unsignedlong ucbuf_len,
u8 *cbuf, unsignedlong cbuf_len)
{ union register_pair u, c;
/** * cpacf_pcc() - executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION) * instruction * @func: the function code passed to PCC; see CPACF_KM_xxx defines * @param: address of parameter block; see POP for details on each func * * Returns the condition code, this is * 0 - cc code 0 (normal completion) * 1 - cc code 1 (protected key wkvp mismatch or src operand out of range) * 2 - cc code 2 (something invalid, scalar multiply infinity, ...) * Condition code 3 (partial completion) is handled within the asm code * and never returned.
*/ staticinlineint cpacf_pcc(unsignedlong func, void *param)
{ int cc;
/** * cpacf_pckmo() - executes the PCKMO (PERFORM CRYPTOGRAPHIC KEY * MANAGEMENT) instruction * @func: the function code passed to PCKMO; see CPACF_PCKMO_xxx defines * @param: address of parameter block; see POP for details on each func * * Returns 0.
*/ staticinlinevoid cpacf_pckmo(long func, void *param)
{ asmvolatile( " lgr 0,%[fc]\n" " lgr 1,%[pba]\n" " .insn rre,%[opc] << 16,0,0\n"/* PCKMO opcode */
:
: [fc] "d" (func), [pba] "d" ((unsignedlong)param),
[opc] "i" (CPACF_PCKMO)
: "cc", "memory", "0", "1");
}
/** * cpacf_kma() - executes the KMA (CIPHER MESSAGE WITH AUTHENTICATION) * instruction * @func: the function code passed to KMA; see CPACF_KMA_xxx defines * @param: address of parameter block; see POP for details on each func * @dest: address of destination memory area * @src: address of source memory area * @src_len: length of src operand in bytes * @aad: address of additional authenticated data memory area * @aad_len: length of aad operand in bytes
*/ staticinlinevoid cpacf_kma(unsignedlong func, void *param, u8 *dest, const u8 *src, unsignedlong src_len, const u8 *aad, unsignedlong aad_len)
{ union register_pair d, s, a;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.