diff options
author | Patrick Steuer <patrick.steuer@de.ibm.com> | 2018-03-28 12:54:50 +0100 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2018-03-28 23:30:56 +0200 |
commit | dacd2a87b550923524e80554b3a4869ea0351f66 (patch) | |
tree | 40821f67689e4f8d24c26567c7bea9aab65e8b9b /crypto/evp/e_aes.c | |
parent | 55bd169fd874f65fa15b20ce4feae2e8ed5e77f1 (diff) | |
download | openssl-dacd2a87b550923524e80554b3a4869ea0351f66.zip openssl-dacd2a87b550923524e80554b3a4869ea0351f66.tar.gz openssl-dacd2a87b550923524e80554b3a4869ea0351f66.tar.bz2 |
s390x assembly pack: add KMO code path for aes-ofb
Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5250)
Diffstat (limited to 'crypto/evp/e_aes.c')
-rw-r--r-- | crypto/evp/e_aes.c | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index c595f55..9309ec9 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -975,6 +975,24 @@ typedef struct { union { double align; /*- + * KMO-AES parameter block - begin + * (see z/Architecture Principles of Operation >= SA22-7832-08) + */ + struct { + unsigned char cv[16]; + unsigned char k[32]; + } param; + /* KMO-AES parameter block - end */ + } kmo; + unsigned int fc; + + int res; +} S390X_AES_OFB_CTX; + +typedef struct { + union { + double align; + /*- * KMA-GCM-AES parameter block - begin * (see z/Architecture Principles of Operation >= SA22-7832-11) */ @@ -1125,16 +1143,70 @@ static int s390x_aes_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, return 1; } -# define S390X_aes_128_ofb_CAPABLE 0 -# define S390X_aes_192_ofb_CAPABLE 0 -# define S390X_aes_256_ofb_CAPABLE 0 -# define S390X_AES_OFB_CTX EVP_AES_KEY +# define S390X_aes_128_ofb_CAPABLE (S390X_aes_128_CAPABLE && \ + (OPENSSL_s390xcap_P.kmo[0] & \ + S390X_CAPBIT(S390X_AES_128))) +# define S390X_aes_192_ofb_CAPABLE (S390X_aes_192_CAPABLE && \ + (OPENSSL_s390xcap_P.kmo[0] & \ + S390X_CAPBIT(S390X_AES_192))) +# define S390X_aes_256_ofb_CAPABLE (S390X_aes_256_CAPABLE && \ + (OPENSSL_s390xcap_P.kmo[0] & \ + S390X_CAPBIT(S390X_AES_256))) + +static int s390x_aes_ofb_init_key(EVP_CIPHER_CTX *ctx, + const unsigned char *key, + const unsigned char *ivec, int enc) +{ + S390X_AES_OFB_CTX *cctx = EVP_C_DATA(S390X_AES_OFB_CTX, ctx); + const unsigned char *iv = EVP_CIPHER_CTX_original_iv(ctx); + const int keylen = EVP_CIPHER_CTX_key_length(ctx); + const int ivlen = EVP_CIPHER_CTX_iv_length(ctx); -# define s390x_aes_ofb_init_key aes_init_key + memcpy(cctx->kmo.param.cv, iv, ivlen); + memcpy(cctx->kmo.param.k, key, keylen); + cctx->fc = S390X_AES_FC(keylen); + cctx->res = 0; + return 1; +} -# define s390x_aes_ofb_cipher aes_ofb_cipher static int s390x_aes_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t len); + const unsigned char *in, size_t len) +{ + S390X_AES_OFB_CTX *cctx = EVP_C_DATA(S390X_AES_OFB_CTX, ctx); + int n = cctx->res; + int rem; + + while (n && len) { + *out = *in ^ cctx->kmo.param.cv[n]; + n = (n + 1) & 0xf; + --len; + ++in; + ++out; + } + + rem = len & 0xf; + + len &= ~(size_t)0xf; + if (len) { + s390x_kmo(in, len, out, cctx->fc, &cctx->kmo.param); + + out += len; + in += len; + } + + if (rem) { + s390x_km(cctx->kmo.param.cv, 16, cctx->kmo.param.cv, cctx->fc, + cctx->kmo.param.k); + + while (rem--) { + out[n] = in[n] ^ cctx->kmo.param.cv[n]; + ++n; + } + } + + cctx->res = n; + return 1; +} # define S390X_aes_128_cfb_CAPABLE 0 # define S390X_aes_192_cfb_CAPABLE 0 |