Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/crypto: Add new subfunctions to the cpacf PRNO function.

There is a new TRNG extension in the subcodes for the cpacf
PRNO function. This patch introduces new defines and a new
cpacf_trng inline function to provide these new features for
other kernel code parts.

Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Harald Freudenberger and committed by
Martin Schwidefsky
f75fa65d 985a9d20

+29 -2
+29 -2
arch/s390/include/asm/cpacf.h
··· 129 129 #define CPACF_PRNO_QUERY 0x00 130 130 #define CPACF_PRNO_SHA512_DRNG_GEN 0x03 131 131 #define CPACF_PRNO_SHA512_DRNG_SEED 0x83 132 + #define CPACF_PRNO_TRNG_Q_R2C_RATIO 0x70 133 + #define CPACF_PRNO_TRNG 0x72 132 134 133 135 typedef struct { unsigned char bytes[16]; } cpacf_mask_t; 134 136 ··· 385 383 * @seed_len: size of seed data in bytes 386 384 */ 387 385 static inline void cpacf_prno(unsigned long func, void *param, 388 - u8 *dest, long dest_len, 389 - const u8 *seed, long seed_len) 386 + u8 *dest, unsigned long dest_len, 387 + const u8 *seed, unsigned long seed_len) 390 388 { 391 389 register unsigned long r0 asm("0") = (unsigned long) func; 392 390 register unsigned long r1 asm("1") = (unsigned long) param; ··· 401 399 : [dst] "+a" (r2), [dlen] "+d" (r3) 402 400 : [fc] "d" (r0), [pba] "a" (r1), 403 401 [seed] "a" (r4), [slen] "d" (r5), [opc] "i" (CPACF_PRNO) 402 + : "cc", "memory"); 403 + } 404 + 405 + /** 406 + * cpacf_trng() - executes the TRNG subfunction of the PRNO instruction 407 + * @ucbuf: buffer for unconditioned data 408 + * @ucbuf_len: amount of unconditioned data to fetch in bytes 409 + * @cbuf: buffer for conditioned data 410 + * @cbuf_len: amount of conditioned data to fetch in bytes 411 + */ 412 + static inline void cpacf_trng(u8 *ucbuf, unsigned long ucbuf_len, 413 + u8 *cbuf, unsigned long cbuf_len) 414 + { 415 + register unsigned long r0 asm("0") = (unsigned long) CPACF_PRNO_TRNG; 416 + register unsigned long r2 asm("2") = (unsigned long) ucbuf; 417 + register unsigned long r3 asm("3") = (unsigned long) ucbuf_len; 418 + register unsigned long r4 asm("4") = (unsigned long) cbuf; 419 + register unsigned long r5 asm("5") = (unsigned long) cbuf_len; 420 + 421 + asm volatile ( 422 + "0: .insn rre,%[opc] << 16,%[ucbuf],%[cbuf]\n" 423 + " brc 1,0b\n" /* handle partial completion */ 424 + : [ucbuf] "+a" (r2), [ucbuflen] "+d" (r3), 425 + [cbuf] "+a" (r4), [cbuflen] "+d" (r5) 426 + : [fc] "d" (r0), [opc] "i" (CPACF_PRNO) 404 427 : "cc", "memory"); 405 428 } 406 429