2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Cryptographic API.
|
|
|
|
*
|
2006-01-06 16:19:17 +08:00
|
|
|
* Support for s390 cryptographic instructions.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-02-06 04:18:14 +08:00
|
|
|
* Copyright IBM Corp. 2003,2007
|
|
|
|
* Author(s): Thomas Spatzier
|
|
|
|
* Jan Glauber (jan.glauber@de.ibm.com)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
*/
|
2006-01-06 16:19:17 +08:00
|
|
|
#ifndef _CRYPTO_ARCH_S390_CRYPT_S390_H
|
|
|
|
#define _CRYPTO_ARCH_S390_CRYPT_S390_H
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/errno.h>
|
|
|
|
|
2006-01-06 16:19:17 +08:00
|
|
|
#define CRYPT_S390_OP_MASK 0xFF00
|
|
|
|
#define CRYPT_S390_FUNC_MASK 0x00FF
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-08-21 19:18:50 +08:00
|
|
|
#define CRYPT_S390_PRIORITY 300
|
2006-08-21 19:39:24 +08:00
|
|
|
#define CRYPT_S390_COMPOSITE_PRIORITY 400
|
2006-08-21 19:18:50 +08:00
|
|
|
|
2011-04-20 03:29:14 +08:00
|
|
|
#define CRYPT_S390_MSA 0x1
|
|
|
|
#define CRYPT_S390_MSA3 0x2
|
|
|
|
#define CRYPT_S390_MSA4 0x4
|
|
|
|
|
2007-07-10 17:24:08 +08:00
|
|
|
/* s390 cryptographic operations */
|
2006-01-06 16:19:17 +08:00
|
|
|
enum crypt_s390_operations {
|
|
|
|
CRYPT_S390_KM = 0x0100,
|
|
|
|
CRYPT_S390_KMC = 0x0200,
|
|
|
|
CRYPT_S390_KIMD = 0x0300,
|
|
|
|
CRYPT_S390_KLMD = 0x0400,
|
2011-05-04 13:09:44 +08:00
|
|
|
CRYPT_S390_KMAC = 0x0500,
|
|
|
|
CRYPT_S390_KMCTR = 0x0600
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/*
|
|
|
|
* function codes for KM (CIPHER MESSAGE) instruction
|
2006-01-06 16:19:17 +08:00
|
|
|
* 0x80 is the decipher modifier bit
|
|
|
|
*/
|
|
|
|
enum crypt_s390_km_func {
|
2006-01-06 16:19:18 +08:00
|
|
|
KM_QUERY = CRYPT_S390_KM | 0x0,
|
|
|
|
KM_DEA_ENCRYPT = CRYPT_S390_KM | 0x1,
|
|
|
|
KM_DEA_DECRYPT = CRYPT_S390_KM | 0x1 | 0x80,
|
|
|
|
KM_TDEA_128_ENCRYPT = CRYPT_S390_KM | 0x2,
|
|
|
|
KM_TDEA_128_DECRYPT = CRYPT_S390_KM | 0x2 | 0x80,
|
|
|
|
KM_TDEA_192_ENCRYPT = CRYPT_S390_KM | 0x3,
|
|
|
|
KM_TDEA_192_DECRYPT = CRYPT_S390_KM | 0x3 | 0x80,
|
|
|
|
KM_AES_128_ENCRYPT = CRYPT_S390_KM | 0x12,
|
|
|
|
KM_AES_128_DECRYPT = CRYPT_S390_KM | 0x12 | 0x80,
|
|
|
|
KM_AES_192_ENCRYPT = CRYPT_S390_KM | 0x13,
|
|
|
|
KM_AES_192_DECRYPT = CRYPT_S390_KM | 0x13 | 0x80,
|
|
|
|
KM_AES_256_ENCRYPT = CRYPT_S390_KM | 0x14,
|
|
|
|
KM_AES_256_DECRYPT = CRYPT_S390_KM | 0x14 | 0x80,
|
2011-04-26 14:12:42 +08:00
|
|
|
KM_XTS_128_ENCRYPT = CRYPT_S390_KM | 0x32,
|
|
|
|
KM_XTS_128_DECRYPT = CRYPT_S390_KM | 0x32 | 0x80,
|
|
|
|
KM_XTS_256_ENCRYPT = CRYPT_S390_KM | 0x34,
|
|
|
|
KM_XTS_256_DECRYPT = CRYPT_S390_KM | 0x34 | 0x80,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/*
|
|
|
|
* function codes for KMC (CIPHER MESSAGE WITH CHAINING)
|
2006-01-06 16:19:17 +08:00
|
|
|
* instruction
|
|
|
|
*/
|
|
|
|
enum crypt_s390_kmc_func {
|
2006-01-06 16:19:18 +08:00
|
|
|
KMC_QUERY = CRYPT_S390_KMC | 0x0,
|
|
|
|
KMC_DEA_ENCRYPT = CRYPT_S390_KMC | 0x1,
|
|
|
|
KMC_DEA_DECRYPT = CRYPT_S390_KMC | 0x1 | 0x80,
|
|
|
|
KMC_TDEA_128_ENCRYPT = CRYPT_S390_KMC | 0x2,
|
|
|
|
KMC_TDEA_128_DECRYPT = CRYPT_S390_KMC | 0x2 | 0x80,
|
|
|
|
KMC_TDEA_192_ENCRYPT = CRYPT_S390_KMC | 0x3,
|
|
|
|
KMC_TDEA_192_DECRYPT = CRYPT_S390_KMC | 0x3 | 0x80,
|
|
|
|
KMC_AES_128_ENCRYPT = CRYPT_S390_KMC | 0x12,
|
|
|
|
KMC_AES_128_DECRYPT = CRYPT_S390_KMC | 0x12 | 0x80,
|
|
|
|
KMC_AES_192_ENCRYPT = CRYPT_S390_KMC | 0x13,
|
|
|
|
KMC_AES_192_DECRYPT = CRYPT_S390_KMC | 0x13 | 0x80,
|
|
|
|
KMC_AES_256_ENCRYPT = CRYPT_S390_KMC | 0x14,
|
|
|
|
KMC_AES_256_DECRYPT = CRYPT_S390_KMC | 0x14 | 0x80,
|
2007-02-06 04:18:22 +08:00
|
|
|
KMC_PRNG = CRYPT_S390_KMC | 0x43,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2011-05-04 13:09:44 +08:00
|
|
|
/*
|
|
|
|
* function codes for KMCTR (CIPHER MESSAGE WITH COUNTER)
|
|
|
|
* instruction
|
|
|
|
*/
|
|
|
|
enum crypt_s390_kmctr_func {
|
|
|
|
KMCTR_QUERY = CRYPT_S390_KMCTR | 0x0,
|
|
|
|
KMCTR_DEA_ENCRYPT = CRYPT_S390_KMCTR | 0x1,
|
|
|
|
KMCTR_DEA_DECRYPT = CRYPT_S390_KMCTR | 0x1 | 0x80,
|
|
|
|
KMCTR_TDEA_128_ENCRYPT = CRYPT_S390_KMCTR | 0x2,
|
|
|
|
KMCTR_TDEA_128_DECRYPT = CRYPT_S390_KMCTR | 0x2 | 0x80,
|
|
|
|
KMCTR_TDEA_192_ENCRYPT = CRYPT_S390_KMCTR | 0x3,
|
|
|
|
KMCTR_TDEA_192_DECRYPT = CRYPT_S390_KMCTR | 0x3 | 0x80,
|
|
|
|
KMCTR_AES_128_ENCRYPT = CRYPT_S390_KMCTR | 0x12,
|
|
|
|
KMCTR_AES_128_DECRYPT = CRYPT_S390_KMCTR | 0x12 | 0x80,
|
|
|
|
KMCTR_AES_192_ENCRYPT = CRYPT_S390_KMCTR | 0x13,
|
|
|
|
KMCTR_AES_192_DECRYPT = CRYPT_S390_KMCTR | 0x13 | 0x80,
|
|
|
|
KMCTR_AES_256_ENCRYPT = CRYPT_S390_KMCTR | 0x14,
|
|
|
|
KMCTR_AES_256_DECRYPT = CRYPT_S390_KMCTR | 0x14 | 0x80,
|
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/*
|
|
|
|
* function codes for KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
|
2006-01-06 16:19:17 +08:00
|
|
|
* instruction
|
|
|
|
*/
|
|
|
|
enum crypt_s390_kimd_func {
|
|
|
|
KIMD_QUERY = CRYPT_S390_KIMD | 0,
|
|
|
|
KIMD_SHA_1 = CRYPT_S390_KIMD | 1,
|
2006-01-06 16:19:18 +08:00
|
|
|
KIMD_SHA_256 = CRYPT_S390_KIMD | 2,
|
2008-03-06 19:52:00 +08:00
|
|
|
KIMD_SHA_512 = CRYPT_S390_KIMD | 3,
|
2011-04-20 03:29:18 +08:00
|
|
|
KIMD_GHASH = CRYPT_S390_KIMD | 65,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/*
|
|
|
|
* function codes for KLMD (COMPUTE LAST MESSAGE DIGEST)
|
2006-01-06 16:19:17 +08:00
|
|
|
* instruction
|
|
|
|
*/
|
|
|
|
enum crypt_s390_klmd_func {
|
|
|
|
KLMD_QUERY = CRYPT_S390_KLMD | 0,
|
|
|
|
KLMD_SHA_1 = CRYPT_S390_KLMD | 1,
|
2006-01-06 16:19:18 +08:00
|
|
|
KLMD_SHA_256 = CRYPT_S390_KLMD | 2,
|
2008-03-06 19:52:00 +08:00
|
|
|
KLMD_SHA_512 = CRYPT_S390_KLMD | 3,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/*
|
|
|
|
* function codes for KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
|
2006-01-06 16:19:17 +08:00
|
|
|
* instruction
|
|
|
|
*/
|
|
|
|
enum crypt_s390_kmac_func {
|
|
|
|
KMAC_QUERY = CRYPT_S390_KMAC | 0,
|
|
|
|
KMAC_DEA = CRYPT_S390_KMAC | 1,
|
|
|
|
KMAC_TDEA_128 = CRYPT_S390_KMAC | 2,
|
|
|
|
KMAC_TDEA_192 = CRYPT_S390_KMAC | 3
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_km:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_km_func
|
|
|
|
* @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
|
|
|
|
*
|
2006-01-06 16:19:17 +08:00
|
|
|
* Executes the KM (CIPHER MESSAGE) operation of the CPU.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for encryption/decryption funcs
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-06 04:18:14 +08:00
|
|
|
static inline int crypt_s390_km(long func, void *param,
|
|
|
|
u8 *dest, const u8 *src, long src_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-06 16:19:17 +08:00
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
2007-02-06 04:18:14 +08:00
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
2005-04-17 06:20:36 +08:00
|
|
|
register long __src_len asm("3") = src_len;
|
2007-02-06 04:18:14 +08:00
|
|
|
register u8 *__dest asm("4") = dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb92e0000,%3,%1 \n" /* KM opcode */
|
2006-01-06 16:19:17 +08:00
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
2007-02-06 04:18:14 +08:00
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
2006-09-28 22:56:43 +08:00
|
|
|
: "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
|
2007-02-06 04:18:14 +08:00
|
|
|
: "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
|
2006-09-28 22:56:43 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_kmc:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_kmc_func
|
|
|
|
* @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
|
|
|
|
*
|
2006-01-06 16:19:17 +08:00
|
|
|
* Executes the KMC (CIPHER MESSAGE WITH CHAINING) operation of the CPU.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for encryption/decryption funcs
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-06 04:18:14 +08:00
|
|
|
static inline int crypt_s390_kmc(long func, void *param,
|
|
|
|
u8 *dest, const u8 *src, long src_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-06 16:19:17 +08:00
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
2007-02-06 04:18:14 +08:00
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
2005-04-17 06:20:36 +08:00
|
|
|
register long __src_len asm("3") = src_len;
|
2007-02-06 04:18:14 +08:00
|
|
|
register u8 *__dest asm("4") = dest;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb92f0000,%3,%1 \n" /* KMC opcode */
|
2006-01-06 16:19:17 +08:00
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
2007-02-06 04:18:14 +08:00
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
2006-09-28 22:56:43 +08:00
|
|
|
: "=d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest)
|
2007-02-06 04:18:14 +08:00
|
|
|
: "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
|
2006-09-28 22:56:43 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_kimd:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_kimd_func
|
|
|
|
* @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
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Executes the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST) operation
|
2006-01-06 16:19:17 +08:00
|
|
|
* of the CPU.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for digest funcs
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-06 04:18:14 +08:00
|
|
|
static inline int crypt_s390_kimd(long func, void *param,
|
|
|
|
const u8 *src, long src_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-06 16:19:17 +08:00
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
2007-02-06 04:18:14 +08:00
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
2005-04-17 06:20:36 +08:00
|
|
|
register long __src_len asm("3") = src_len;
|
|
|
|
int ret;
|
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb93e0000,%1,%1 \n" /* KIMD opcode */
|
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
2007-02-06 04:18:14 +08:00
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
2006-09-28 22:56:43 +08:00
|
|
|
: "=d" (ret), "+a" (__src), "+d" (__src_len)
|
2007-02-06 04:18:14 +08:00
|
|
|
: "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
|
2006-09-28 22:56:43 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_klmd:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_klmd_func
|
|
|
|
* @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
|
|
|
|
*
|
2006-01-06 16:19:17 +08:00
|
|
|
* Executes the KLMD (COMPUTE LAST MESSAGE DIGEST) operation of the CPU.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for digest funcs
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-06 04:18:14 +08:00
|
|
|
static inline int crypt_s390_klmd(long func, void *param,
|
|
|
|
const u8 *src, long src_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-06 16:19:17 +08:00
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
2007-02-06 04:18:14 +08:00
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
2005-04-17 06:20:36 +08:00
|
|
|
register long __src_len asm("3") = src_len;
|
|
|
|
int ret;
|
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb93f0000,%1,%1 \n" /* KLMD opcode */
|
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
2007-02-06 04:18:14 +08:00
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
2006-09-28 22:56:43 +08:00
|
|
|
: "=d" (ret), "+a" (__src), "+d" (__src_len)
|
2007-02-06 04:18:14 +08:00
|
|
|
: "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
|
2006-09-28 22:56:43 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_kmac:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_klmd_func
|
|
|
|
* @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
|
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE) operation
|
2006-01-06 16:19:17 +08:00
|
|
|
* of the CPU.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for digest funcs
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-06 04:18:14 +08:00
|
|
|
static inline int crypt_s390_kmac(long func, void *param,
|
|
|
|
const u8 *src, long src_len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-06 16:19:17 +08:00
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
2007-02-06 04:18:14 +08:00
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
2005-04-17 06:20:36 +08:00
|
|
|
register long __src_len asm("3") = src_len;
|
|
|
|
int ret;
|
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb91e0000,%1,%1 \n" /* KLAC opcode */
|
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
2007-02-06 04:18:14 +08:00
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
2006-09-28 22:56:43 +08:00
|
|
|
: "=d" (ret), "+a" (__src), "+d" (__src_len)
|
2007-02-06 04:18:14 +08:00
|
|
|
: "d" (__func), "a" (__param), "0" (-1) : "cc", "memory");
|
2006-09-28 22:56:43 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-05-04 13:09:44 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_kmctr:
|
|
|
|
* @func: the function code passed to KMCTR; see crypt_s390_kmctr_func
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* Executes the KMCTR (CIPHER MESSAGE WITH COUNTER) operation of the CPU.
|
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for the query func, number of processed
|
|
|
|
* bytes for encryption/decryption funcs
|
|
|
|
*/
|
|
|
|
static inline int crypt_s390_kmctr(long func, void *param, u8 *dest,
|
|
|
|
const u8 *src, long src_len, u8 *counter)
|
|
|
|
{
|
|
|
|
register long __func asm("0") = func & CRYPT_S390_FUNC_MASK;
|
|
|
|
register void *__param asm("1") = param;
|
|
|
|
register const u8 *__src asm("2") = src;
|
|
|
|
register long __src_len asm("3") = src_len;
|
|
|
|
register u8 *__dest asm("4") = dest;
|
|
|
|
register u8 *__ctr asm("6") = counter;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
"0: .insn rrf,0xb92d0000,%3,%1,%4,0 \n" /* KMCTR opcode */
|
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
|
|
|
: "+d" (ret), "+a" (__src), "+d" (__src_len), "+a" (__dest),
|
|
|
|
"+a" (__ctr)
|
|
|
|
: "d" (__func), "a" (__param) : "cc", "memory");
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
return (func & CRYPT_S390_FUNC_MASK) ? src_len - __src_len : __src_len;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
2007-02-06 04:18:14 +08:00
|
|
|
* crypt_s390_func_available:
|
|
|
|
* @func: the function code of the specific function; 0 if op in general
|
|
|
|
*
|
2006-01-06 16:19:17 +08:00
|
|
|
* Tests if a specific crypto function is implemented on the machine.
|
2007-02-06 04:18:14 +08:00
|
|
|
*
|
|
|
|
* Returns 1 if func available; 0 if func or op in general not available
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2011-04-20 03:29:14 +08:00
|
|
|
static inline int crypt_s390_func_available(int func,
|
|
|
|
unsigned int facility_mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-06 04:18:14 +08:00
|
|
|
unsigned char status[16];
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-04-20 03:29:14 +08:00
|
|
|
if (facility_mask & CRYPT_S390_MSA && !test_facility(17))
|
|
|
|
return 0;
|
2011-11-14 18:19:07 +08:00
|
|
|
|
|
|
|
if (facility_mask & CRYPT_S390_MSA3 &&
|
|
|
|
(!test_facility(2) || !test_facility(76)))
|
2011-04-20 03:29:14 +08:00
|
|
|
return 0;
|
2011-11-14 18:19:07 +08:00
|
|
|
if (facility_mask & CRYPT_S390_MSA4 &&
|
|
|
|
(!test_facility(2) || !test_facility(77)))
|
2008-07-12 15:42:11 +08:00
|
|
|
return 0;
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
switch (func & CRYPT_S390_OP_MASK) {
|
|
|
|
case CRYPT_S390_KM:
|
|
|
|
ret = crypt_s390_km(KM_QUERY, &status, NULL, NULL, 0);
|
|
|
|
break;
|
|
|
|
case CRYPT_S390_KMC:
|
|
|
|
ret = crypt_s390_kmc(KMC_QUERY, &status, NULL, NULL, 0);
|
|
|
|
break;
|
|
|
|
case CRYPT_S390_KIMD:
|
|
|
|
ret = crypt_s390_kimd(KIMD_QUERY, &status, NULL, 0);
|
|
|
|
break;
|
|
|
|
case CRYPT_S390_KLMD:
|
|
|
|
ret = crypt_s390_klmd(KLMD_QUERY, &status, NULL, 0);
|
|
|
|
break;
|
|
|
|
case CRYPT_S390_KMAC:
|
|
|
|
ret = crypt_s390_kmac(KMAC_QUERY, &status, NULL, 0);
|
|
|
|
break;
|
2011-05-04 13:09:44 +08:00
|
|
|
case CRYPT_S390_KMCTR:
|
|
|
|
ret = crypt_s390_kmctr(KMCTR_QUERY, &status, NULL, NULL, 0,
|
|
|
|
NULL);
|
|
|
|
break;
|
2007-02-06 04:18:14 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-06 04:18:14 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return 0;
|
|
|
|
func &= CRYPT_S390_FUNC_MASK;
|
|
|
|
func &= 0x7f; /* mask modifier bit */
|
|
|
|
return (status[func >> 3] & (0x80 >> (func & 7))) != 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-04-26 14:12:42 +08:00
|
|
|
/**
|
|
|
|
* crypt_s390_pcc:
|
|
|
|
* @func: the function code passed to KM; see crypt_s390_km_func
|
|
|
|
* @param: address of parameter block; see POP for details on each func
|
|
|
|
*
|
|
|
|
* Executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION) operation of the CPU.
|
|
|
|
*
|
|
|
|
* Returns -1 for failure, 0 for success.
|
|
|
|
*/
|
|
|
|
static inline int crypt_s390_pcc(long func, void *param)
|
|
|
|
{
|
|
|
|
register long __func asm("0") = func & 0x7f; /* encrypt or decrypt */
|
|
|
|
register void *__param asm("1") = param;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
"0: .insn rre,0xb92c0000,0,0 \n" /* PCC opcode */
|
|
|
|
"1: brc 1,0b \n" /* handle partial completion */
|
|
|
|
" la %0,0\n"
|
|
|
|
"2:\n"
|
|
|
|
EX_TABLE(0b,2b) EX_TABLE(1b,2b)
|
|
|
|
: "+d" (ret)
|
|
|
|
: "d" (__func), "a" (__param) : "cc", "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-06 04:18:14 +08:00
|
|
|
#endif /* _CRYPTO_ARCH_S390_CRYPT_S390_H */
|