2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/net/sunrpc/gss_krb5_crypto.c
|
|
|
|
*
|
2010-03-18 01:02:51 +08:00
|
|
|
* Copyright (c) 2000-2008 The Regents of the University of Michigan.
|
2005-04-17 06:20:36 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Andy Adamson <andros@umich.edu>
|
|
|
|
* Bruce Fields <bfields@umich.edu>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1998 by the FundsXpress, INC.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Export of this software from the United States of America may require
|
|
|
|
* a specific license from the United States Government. It is the
|
|
|
|
* responsibility of any person or organization contemplating export to
|
|
|
|
* obtain such a license before exporting.
|
|
|
|
*
|
|
|
|
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
|
|
|
|
* distribute this software and its documentation for any purpose and
|
|
|
|
* without fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies and that both that copyright notice and
|
|
|
|
* this permission notice appear in supporting documentation, and that
|
|
|
|
* the name of FundsXpress. not be used in advertising or publicity pertaining
|
|
|
|
* to distribution of the software without specific, written prior
|
|
|
|
* permission. FundsXpress makes no representations about the suitability of
|
|
|
|
* this software for any purpose. It is provided "as is" without express
|
|
|
|
* or implied warranty.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2017-06-10 10:59:07 +08:00
|
|
|
#include <crypto/algapi.h>
|
2016-01-24 21:17:59 +08:00
|
|
|
#include <crypto/hash.h>
|
|
|
|
#include <crypto/skcipher.h>
|
2006-08-24 17:10:20 +08:00
|
|
|
#include <linux/err.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/mm.h>
|
2005-09-17 15:55:31 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/pagemap.h>
|
2010-03-18 01:03:00 +08:00
|
|
|
#include <linux/random.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/sunrpc/gss_krb5.h>
|
2006-12-05 09:22:33 +08:00
|
|
|
#include <linux/sunrpc/xdr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-11-18 05:58:04 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
|
2005-04-17 06:20:36 +08:00
|
|
|
# define RPCDBG_FACILITY RPCDBG_AUTH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
u32
|
|
|
|
krb5_encrypt(
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *tfm,
|
2005-04-17 06:20:36 +08:00
|
|
|
void * iv,
|
|
|
|
void * in,
|
|
|
|
void * out,
|
|
|
|
int length)
|
|
|
|
{
|
|
|
|
u32 ret = -EINVAL;
|
2007-02-10 07:38:13 +08:00
|
|
|
struct scatterlist sg[1];
|
2010-03-18 01:02:51 +08:00
|
|
|
u8 local_iv[GSS_KRB5_MAX_BLOCKSIZE] = {0};
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
if (length % crypto_sync_skcipher_blocksize(tfm) != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
if (crypto_sync_skcipher_ivsize(tfm) > GSS_KRB5_MAX_BLOCKSIZE) {
|
2008-02-22 02:44:12 +08:00
|
|
|
dprintk("RPC: gss_k5encrypt: tfm iv size too large %d\n",
|
2018-09-19 10:10:39 +08:00
|
|
|
crypto_sync_skcipher_ivsize(tfm));
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iv)
|
2018-09-19 10:10:39 +08:00
|
|
|
memcpy(local_iv, iv, crypto_sync_skcipher_ivsize(tfm));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memcpy(out, in, length);
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_init_one(sg, out, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, tfm);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
skcipher_request_set_crypt(req, sg, sg, length, local_iv);
|
|
|
|
|
|
|
|
ret = crypto_skcipher_encrypt(req);
|
|
|
|
skcipher_request_zero(req);
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
2007-02-01 01:14:05 +08:00
|
|
|
dprintk("RPC: krb5_encrypt returns %d\n", ret);
|
2006-12-05 09:22:31 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u32
|
|
|
|
krb5_decrypt(
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *tfm,
|
2005-04-17 06:20:36 +08:00
|
|
|
void * iv,
|
|
|
|
void * in,
|
|
|
|
void * out,
|
|
|
|
int length)
|
|
|
|
{
|
|
|
|
u32 ret = -EINVAL;
|
|
|
|
struct scatterlist sg[1];
|
2010-03-18 01:02:51 +08:00
|
|
|
u8 local_iv[GSS_KRB5_MAX_BLOCKSIZE] = {0};
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
if (length % crypto_sync_skcipher_blocksize(tfm) != 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
if (crypto_sync_skcipher_ivsize(tfm) > GSS_KRB5_MAX_BLOCKSIZE) {
|
2008-02-22 02:44:12 +08:00
|
|
|
dprintk("RPC: gss_k5decrypt: tfm iv size too large %d\n",
|
2018-09-19 10:10:39 +08:00
|
|
|
crypto_sync_skcipher_ivsize(tfm));
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (iv)
|
2018-09-19 10:10:39 +08:00
|
|
|
memcpy(local_iv, iv, crypto_sync_skcipher_ivsize(tfm));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memcpy(out, in, length);
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_init_one(sg, out, length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, tfm);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
skcipher_request_set_crypt(req, sg, sg, length, local_iv);
|
|
|
|
|
|
|
|
ret = crypto_skcipher_decrypt(req);
|
|
|
|
skcipher_request_zero(req);
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
2007-02-01 01:14:05 +08:00
|
|
|
dprintk("RPC: gss_k5decrypt returns %d\n",ret);
|
2006-12-05 09:22:31 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-10-14 04:55:03 +08:00
|
|
|
static int
|
|
|
|
checksummer(struct scatterlist *sg, void *data)
|
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
struct ahash_request *req = data;
|
|
|
|
|
|
|
|
ahash_request_set_crypt(req, sg, NULL, sg->length);
|
2005-10-14 04:55:03 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
return crypto_ahash_update(req);
|
2005-10-14 04:55:03 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 01:03:06 +08:00
|
|
|
static int
|
|
|
|
arcfour_hmac_md5_usage_to_salt(unsigned int usage, u8 salt[4])
|
|
|
|
{
|
|
|
|
unsigned int ms_usage;
|
|
|
|
|
|
|
|
switch (usage) {
|
|
|
|
case KG_USAGE_SIGN:
|
|
|
|
ms_usage = 15;
|
|
|
|
break;
|
|
|
|
case KG_USAGE_SEAL:
|
|
|
|
ms_usage = 13;
|
|
|
|
break;
|
|
|
|
default:
|
2010-11-15 10:08:11 +08:00
|
|
|
return -EINVAL;
|
2010-03-18 01:03:06 +08:00
|
|
|
}
|
|
|
|
salt[0] = (ms_usage >> 0) & 0xff;
|
|
|
|
salt[1] = (ms_usage >> 8) & 0xff;
|
|
|
|
salt[2] = (ms_usage >> 16) & 0xff;
|
|
|
|
salt[3] = (ms_usage >> 24) & 0xff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
|
|
|
make_checksum_hmac_md5(struct krb5_ctx *kctx, char *header, int hdrlen,
|
|
|
|
struct xdr_buf *body, int body_offset, u8 *cksumkey,
|
|
|
|
unsigned int usage, struct xdr_netobj *cksumout)
|
|
|
|
{
|
|
|
|
struct scatterlist sg[1];
|
2016-10-19 04:30:09 +08:00
|
|
|
int err = -1;
|
|
|
|
u8 *checksumdata;
|
2018-08-18 05:43:54 +08:00
|
|
|
u8 *rc4salt;
|
2016-01-24 21:17:59 +08:00
|
|
|
struct crypto_ahash *md5;
|
|
|
|
struct crypto_ahash *hmac_md5;
|
|
|
|
struct ahash_request *req;
|
2010-03-18 01:03:06 +08:00
|
|
|
|
|
|
|
if (cksumkey == NULL)
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
|
|
|
|
if (cksumout->len < kctx->gk5e->cksumlength) {
|
|
|
|
dprintk("%s: checksum buffer length, %u, too small for %s\n",
|
|
|
|
__func__, cksumout->len, kctx->gk5e->name);
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-08-18 05:43:54 +08:00
|
|
|
rc4salt = kmalloc_array(4, sizeof(*rc4salt), GFP_NOFS);
|
|
|
|
if (!rc4salt)
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
|
2010-03-18 01:03:06 +08:00
|
|
|
if (arcfour_hmac_md5_usage_to_salt(usage, rc4salt)) {
|
|
|
|
dprintk("%s: invalid usage value %u\n", __func__, usage);
|
2018-08-18 05:43:54 +08:00
|
|
|
goto out_free_rc4salt;
|
2010-03-18 01:03:06 +08:00
|
|
|
}
|
|
|
|
|
2016-10-19 04:30:09 +08:00
|
|
|
checksumdata = kmalloc(GSS_KRB5_MAX_CKSUM_LEN, GFP_NOFS);
|
|
|
|
if (!checksumdata)
|
2018-08-18 05:43:54 +08:00
|
|
|
goto out_free_rc4salt;
|
2016-10-19 04:30:09 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
md5 = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (IS_ERR(md5))
|
2016-10-19 04:30:09 +08:00
|
|
|
goto out_free_cksum;
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
hmac_md5 = crypto_alloc_ahash(kctx->gk5e->cksum_name, 0,
|
|
|
|
CRYPTO_ALG_ASYNC);
|
2016-10-19 04:30:09 +08:00
|
|
|
if (IS_ERR(hmac_md5))
|
|
|
|
goto out_free_md5;
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2016-10-27 04:03:00 +08:00
|
|
|
req = ahash_request_alloc(md5, GFP_NOFS);
|
2016-10-19 04:30:09 +08:00
|
|
|
if (!req)
|
|
|
|
goto out_free_hmac_md5;
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_ahash_init(req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
sg_init_one(sg, rc4salt, 4);
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, sg, NULL, 4);
|
|
|
|
err = crypto_ahash_update(req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sg_init_one(sg, header, hdrlen);
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, sg, NULL, hdrlen);
|
|
|
|
err = crypto_ahash_update(req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = xdr_process_buf(body, body_offset, body->len - body_offset,
|
2016-01-24 21:17:59 +08:00
|
|
|
checksummer, req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, NULL, checksumdata, 0);
|
|
|
|
err = crypto_ahash_final(req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_free(req);
|
2016-10-27 04:03:00 +08:00
|
|
|
req = ahash_request_alloc(hmac_md5, GFP_NOFS);
|
2016-10-19 04:30:09 +08:00
|
|
|
if (!req)
|
|
|
|
goto out_free_hmac_md5;
|
2016-01-24 21:17:59 +08:00
|
|
|
|
|
|
|
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_ahash_setkey(hmac_md5, cksumkey, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
sg_init_one(sg, checksumdata, crypto_ahash_digestsize(md5));
|
|
|
|
ahash_request_set_crypt(req, sg, checksumdata,
|
|
|
|
crypto_ahash_digestsize(md5));
|
|
|
|
err = crypto_ahash_digest(req);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
|
|
|
|
cksumout->len = kctx->gk5e->cksumlength;
|
|
|
|
out:
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_free(req);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_hmac_md5:
|
2016-01-24 21:17:59 +08:00
|
|
|
crypto_free_ahash(hmac_md5);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_md5:
|
|
|
|
crypto_free_ahash(md5);
|
|
|
|
out_free_cksum:
|
|
|
|
kfree(checksumdata);
|
2018-08-18 05:43:54 +08:00
|
|
|
out_free_rc4salt:
|
|
|
|
kfree(rc4salt);
|
2010-03-18 01:03:06 +08:00
|
|
|
return err ? GSS_S_FAILURE : 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 01:02:52 +08:00
|
|
|
/*
|
|
|
|
* checksum the plaintext data and hdrlen bytes of the token header
|
|
|
|
* The checksum is performed over the first 8 bytes of the
|
|
|
|
* gss token header and then over the data body
|
|
|
|
*/
|
|
|
|
u32
|
|
|
|
make_checksum(struct krb5_ctx *kctx, char *header, int hdrlen,
|
|
|
|
struct xdr_buf *body, int body_offset, u8 *cksumkey,
|
2010-03-18 01:03:02 +08:00
|
|
|
unsigned int usage, struct xdr_netobj *cksumout)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
struct crypto_ahash *tfm;
|
|
|
|
struct ahash_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct scatterlist sg[1];
|
2016-10-19 04:30:09 +08:00
|
|
|
int err = -1;
|
|
|
|
u8 *checksumdata;
|
2010-03-18 01:02:52 +08:00
|
|
|
unsigned int checksumlen;
|
|
|
|
|
2010-03-18 01:03:06 +08:00
|
|
|
if (kctx->gk5e->ctype == CKSUMTYPE_HMAC_MD5_ARCFOUR)
|
|
|
|
return make_checksum_hmac_md5(kctx, header, hdrlen,
|
|
|
|
body, body_offset,
|
|
|
|
cksumkey, usage, cksumout);
|
|
|
|
|
2010-03-18 01:02:52 +08:00
|
|
|
if (cksumout->len < kctx->gk5e->cksumlength) {
|
|
|
|
dprintk("%s: checksum buffer length, %u, too small for %s\n",
|
|
|
|
__func__, cksumout->len, kctx->gk5e->name);
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-19 04:30:09 +08:00
|
|
|
checksumdata = kmalloc(GSS_KRB5_MAX_CKSUM_LEN, GFP_NOFS);
|
|
|
|
if (checksumdata == NULL)
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
tfm = crypto_alloc_ahash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
|
|
|
|
if (IS_ERR(tfm))
|
2016-10-19 04:30:09 +08:00
|
|
|
goto out_free_cksum;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-10-27 04:03:00 +08:00
|
|
|
req = ahash_request_alloc(tfm, GFP_NOFS);
|
2016-10-19 04:30:09 +08:00
|
|
|
if (!req)
|
|
|
|
goto out_free_ahash;
|
2016-01-24 21:17:59 +08:00
|
|
|
|
|
|
|
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
|
|
|
|
|
|
|
|
checksumlen = crypto_ahash_digestsize(tfm);
|
2010-03-18 01:02:52 +08:00
|
|
|
|
|
|
|
if (cksumkey != NULL) {
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_ahash_setkey(tfm, cksumkey,
|
|
|
|
kctx->gk5e->keylength);
|
2010-03-18 01:02:52 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_ahash_init(req);
|
2006-08-24 17:10:20 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_init_one(sg, header, hdrlen);
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, sg, NULL, hdrlen);
|
|
|
|
err = crypto_ahash_update(req);
|
2006-08-24 17:10:20 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2006-12-05 09:22:33 +08:00
|
|
|
err = xdr_process_buf(body, body_offset, body->len - body_offset,
|
2016-01-24 21:17:59 +08:00
|
|
|
checksummer, req);
|
2006-08-24 17:10:20 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, NULL, checksumdata, 0);
|
|
|
|
err = crypto_ahash_final(req);
|
2010-03-18 01:02:52 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
2006-08-24 17:10:20 +08:00
|
|
|
|
2010-03-18 01:02:52 +08:00
|
|
|
switch (kctx->gk5e->ctype) {
|
|
|
|
case CKSUMTYPE_RSA_MD5:
|
|
|
|
err = kctx->gk5e->encrypt(kctx->seq, NULL, checksumdata,
|
|
|
|
checksumdata, checksumlen);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
memcpy(cksumout->data,
|
|
|
|
checksumdata + checksumlen - kctx->gk5e->cksumlength,
|
|
|
|
kctx->gk5e->cksumlength);
|
|
|
|
break;
|
2010-03-18 01:02:55 +08:00
|
|
|
case CKSUMTYPE_HMAC_SHA1_DES3:
|
|
|
|
memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
|
|
|
|
break;
|
2010-03-18 01:02:52 +08:00
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cksumout->len = kctx->gk5e->cksumlength;
|
2006-08-24 17:10:20 +08:00
|
|
|
out:
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_free(req);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_ahash:
|
2016-01-24 21:17:59 +08:00
|
|
|
crypto_free_ahash(tfm);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_cksum:
|
|
|
|
kfree(checksumdata);
|
2006-08-24 17:10:20 +08:00
|
|
|
return err ? GSS_S_FAILURE : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 01:02:59 +08:00
|
|
|
/*
|
|
|
|
* checksum the plaintext data and hdrlen bytes of the token header
|
|
|
|
* Per rfc4121, sec. 4.2.4, the checksum is performed over the data
|
|
|
|
* body then over the first 16 octets of the MIC token
|
|
|
|
* Inclusion of the header data in the calculation of the
|
|
|
|
* checksum is optional.
|
|
|
|
*/
|
|
|
|
u32
|
|
|
|
make_checksum_v2(struct krb5_ctx *kctx, char *header, int hdrlen,
|
|
|
|
struct xdr_buf *body, int body_offset, u8 *cksumkey,
|
2010-03-18 01:03:02 +08:00
|
|
|
unsigned int usage, struct xdr_netobj *cksumout)
|
2010-03-18 01:02:59 +08:00
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
struct crypto_ahash *tfm;
|
|
|
|
struct ahash_request *req;
|
2010-03-18 01:02:59 +08:00
|
|
|
struct scatterlist sg[1];
|
2016-10-19 04:30:09 +08:00
|
|
|
int err = -1;
|
|
|
|
u8 *checksumdata;
|
2010-03-18 01:02:59 +08:00
|
|
|
|
|
|
|
if (kctx->gk5e->keyed_cksum == 0) {
|
|
|
|
dprintk("%s: expected keyed hash for %s\n",
|
|
|
|
__func__, kctx->gk5e->name);
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
}
|
|
|
|
if (cksumkey == NULL) {
|
|
|
|
dprintk("%s: no key supplied for %s\n",
|
|
|
|
__func__, kctx->gk5e->name);
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-10-19 04:30:09 +08:00
|
|
|
checksumdata = kmalloc(GSS_KRB5_MAX_CKSUM_LEN, GFP_NOFS);
|
|
|
|
if (!checksumdata)
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
tfm = crypto_alloc_ahash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
|
|
|
|
if (IS_ERR(tfm))
|
2016-10-19 04:30:09 +08:00
|
|
|
goto out_free_cksum;
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2016-10-27 04:03:00 +08:00
|
|
|
req = ahash_request_alloc(tfm, GFP_NOFS);
|
2016-10-19 04:30:09 +08:00
|
|
|
if (!req)
|
|
|
|
goto out_free_ahash;
|
2010-03-18 01:02:59 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
|
|
|
|
|
|
|
|
err = crypto_ahash_setkey(tfm, cksumkey, kctx->gk5e->keylength);
|
2010-03-18 01:02:59 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_ahash_init(req);
|
2010-03-18 01:02:59 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
err = xdr_process_buf(body, body_offset, body->len - body_offset,
|
2016-01-24 21:17:59 +08:00
|
|
|
checksummer, req);
|
2010-03-18 01:02:59 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
if (header != NULL) {
|
|
|
|
sg_init_one(sg, header, hdrlen);
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, sg, NULL, hdrlen);
|
|
|
|
err = crypto_ahash_update(req);
|
2010-03-18 01:02:59 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_set_crypt(req, NULL, checksumdata, 0);
|
|
|
|
err = crypto_ahash_final(req);
|
2010-03-18 01:02:59 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
cksumout->len = kctx->gk5e->cksumlength;
|
|
|
|
|
|
|
|
switch (kctx->gk5e->ctype) {
|
|
|
|
case CKSUMTYPE_HMAC_SHA1_96_AES128:
|
|
|
|
case CKSUMTYPE_HMAC_SHA1_96_AES256:
|
|
|
|
/* note that this truncates the hash */
|
|
|
|
memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
2016-01-24 21:17:59 +08:00
|
|
|
ahash_request_free(req);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_ahash:
|
2016-01-24 21:17:59 +08:00
|
|
|
crypto_free_ahash(tfm);
|
2016-10-19 04:30:09 +08:00
|
|
|
out_free_cksum:
|
|
|
|
kfree(checksumdata);
|
2010-03-18 01:02:59 +08:00
|
|
|
return err ? GSS_S_FAILURE : 0;
|
|
|
|
}
|
|
|
|
|
2005-10-14 04:55:13 +08:00
|
|
|
struct encryptor_desc {
|
2010-03-18 01:02:51 +08:00
|
|
|
u8 iv[GSS_KRB5_MAX_BLOCKSIZE];
|
2016-01-24 21:17:59 +08:00
|
|
|
struct skcipher_request *req;
|
2005-10-14 04:55:13 +08:00
|
|
|
int pos;
|
|
|
|
struct xdr_buf *outbuf;
|
|
|
|
struct page **pages;
|
|
|
|
struct scatterlist infrags[4];
|
|
|
|
struct scatterlist outfrags[4];
|
|
|
|
int fragno;
|
|
|
|
int fraglen;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
encryptor(struct scatterlist *sg, void *data)
|
|
|
|
{
|
|
|
|
struct encryptor_desc *desc = data;
|
|
|
|
struct xdr_buf *outbuf = desc->outbuf;
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *tfm =
|
|
|
|
crypto_sync_skcipher_reqtfm(desc->req);
|
2005-10-14 04:55:13 +08:00
|
|
|
struct page *in_page;
|
|
|
|
int thislen = desc->fraglen + sg->length;
|
|
|
|
int fraglen, ret;
|
|
|
|
int page_pos;
|
|
|
|
|
|
|
|
/* Worst case is 4 fragments: head, end of page 1, start
|
|
|
|
* of page 2, tail. Anything more is a bug. */
|
|
|
|
BUG_ON(desc->fragno > 3);
|
|
|
|
|
|
|
|
page_pos = desc->pos - outbuf->head[0].iov_len;
|
|
|
|
if (page_pos >= 0 && page_pos < outbuf->page_len) {
|
|
|
|
/* pages are not in place: */
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
int i = (page_pos + outbuf->page_base) >> PAGE_SHIFT;
|
2005-10-14 04:55:13 +08:00
|
|
|
in_page = desc->pages[i];
|
|
|
|
} else {
|
2007-10-23 01:44:26 +08:00
|
|
|
in_page = sg_page(sg);
|
2005-10-14 04:55:13 +08:00
|
|
|
}
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_set_page(&desc->infrags[desc->fragno], in_page, sg->length,
|
|
|
|
sg->offset);
|
|
|
|
sg_set_page(&desc->outfrags[desc->fragno], sg_page(sg), sg->length,
|
|
|
|
sg->offset);
|
2005-10-14 04:55:13 +08:00
|
|
|
desc->fragno++;
|
|
|
|
desc->fraglen += sg->length;
|
|
|
|
desc->pos += sg->length;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
fraglen = thislen & (crypto_sync_skcipher_blocksize(tfm) - 1);
|
2005-10-14 04:55:13 +08:00
|
|
|
thislen -= fraglen;
|
|
|
|
|
|
|
|
if (thislen == 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-10-31 19:06:37 +08:00
|
|
|
sg_mark_end(&desc->infrags[desc->fragno - 1]);
|
|
|
|
sg_mark_end(&desc->outfrags[desc->fragno - 1]);
|
2007-10-27 15:52:07 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_crypt(desc->req, desc->infrags, desc->outfrags,
|
|
|
|
thislen, desc->iv);
|
|
|
|
|
|
|
|
ret = crypto_skcipher_encrypt(desc->req);
|
2005-10-14 04:55:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2007-10-27 15:52:07 +08:00
|
|
|
|
|
|
|
sg_init_table(desc->infrags, 4);
|
|
|
|
sg_init_table(desc->outfrags, 4);
|
|
|
|
|
2005-10-14 04:55:13 +08:00
|
|
|
if (fraglen) {
|
2007-10-24 17:20:47 +08:00
|
|
|
sg_set_page(&desc->outfrags[0], sg_page(sg), fraglen,
|
|
|
|
sg->offset + sg->length - fraglen);
|
2005-10-14 04:55:13 +08:00
|
|
|
desc->infrags[0] = desc->outfrags[0];
|
2007-10-24 17:20:47 +08:00
|
|
|
sg_assign_page(&desc->infrags[0], in_page);
|
2005-10-14 04:55:13 +08:00
|
|
|
desc->fragno = 1;
|
|
|
|
desc->fraglen = fraglen;
|
|
|
|
} else {
|
|
|
|
desc->fragno = 0;
|
|
|
|
desc->fraglen = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-09-19 10:10:39 +08:00
|
|
|
gss_encrypt_xdr_buf(struct crypto_sync_skcipher *tfm, struct xdr_buf *buf,
|
2006-08-22 18:33:54 +08:00
|
|
|
int offset, struct page **pages)
|
2005-10-14 04:55:13 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct encryptor_desc desc;
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
BUG_ON((buf->len - offset) % crypto_sync_skcipher_blocksize(tfm) != 0);
|
2005-10-14 04:55:13 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, tfm);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
2005-10-14 04:55:13 +08:00
|
|
|
|
|
|
|
memset(desc.iv, 0, sizeof(desc.iv));
|
2016-01-24 21:17:59 +08:00
|
|
|
desc.req = req;
|
2005-10-14 04:55:13 +08:00
|
|
|
desc.pos = offset;
|
|
|
|
desc.outbuf = buf;
|
|
|
|
desc.pages = pages;
|
|
|
|
desc.fragno = 0;
|
|
|
|
desc.fraglen = 0;
|
|
|
|
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_init_table(desc.infrags, 4);
|
|
|
|
sg_init_table(desc.outfrags, 4);
|
|
|
|
|
2006-12-05 09:22:33 +08:00
|
|
|
ret = xdr_process_buf(buf, offset, buf->len - offset, encryptor, &desc);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_zero(req);
|
2005-10-14 04:55:13 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct decryptor_desc {
|
2010-03-18 01:02:51 +08:00
|
|
|
u8 iv[GSS_KRB5_MAX_BLOCKSIZE];
|
2016-01-24 21:17:59 +08:00
|
|
|
struct skcipher_request *req;
|
2005-10-14 04:55:13 +08:00
|
|
|
struct scatterlist frags[4];
|
|
|
|
int fragno;
|
|
|
|
int fraglen;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decryptor(struct scatterlist *sg, void *data)
|
|
|
|
{
|
|
|
|
struct decryptor_desc *desc = data;
|
|
|
|
int thislen = desc->fraglen + sg->length;
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *tfm =
|
|
|
|
crypto_sync_skcipher_reqtfm(desc->req);
|
2005-10-14 04:55:13 +08:00
|
|
|
int fraglen, ret;
|
|
|
|
|
|
|
|
/* Worst case is 4 fragments: head, end of page 1, start
|
|
|
|
* of page 2, tail. Anything more is a bug. */
|
|
|
|
BUG_ON(desc->fragno > 3);
|
2007-10-27 15:52:07 +08:00
|
|
|
sg_set_page(&desc->frags[desc->fragno], sg_page(sg), sg->length,
|
|
|
|
sg->offset);
|
2005-10-14 04:55:13 +08:00
|
|
|
desc->fragno++;
|
|
|
|
desc->fraglen += sg->length;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
fraglen = thislen & (crypto_sync_skcipher_blocksize(tfm) - 1);
|
2005-10-14 04:55:13 +08:00
|
|
|
thislen -= fraglen;
|
|
|
|
|
|
|
|
if (thislen == 0)
|
|
|
|
return 0;
|
|
|
|
|
2007-10-31 19:06:37 +08:00
|
|
|
sg_mark_end(&desc->frags[desc->fragno - 1]);
|
2007-10-27 15:52:07 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_crypt(desc->req, desc->frags, desc->frags,
|
|
|
|
thislen, desc->iv);
|
|
|
|
|
|
|
|
ret = crypto_skcipher_decrypt(desc->req);
|
2005-10-14 04:55:13 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2007-10-27 15:52:07 +08:00
|
|
|
|
|
|
|
sg_init_table(desc->frags, 4);
|
|
|
|
|
2005-10-14 04:55:13 +08:00
|
|
|
if (fraglen) {
|
2007-10-24 17:20:47 +08:00
|
|
|
sg_set_page(&desc->frags[0], sg_page(sg), fraglen,
|
|
|
|
sg->offset + sg->length - fraglen);
|
2005-10-14 04:55:13 +08:00
|
|
|
desc->fragno = 1;
|
|
|
|
desc->fraglen = fraglen;
|
|
|
|
} else {
|
|
|
|
desc->fragno = 0;
|
|
|
|
desc->fraglen = 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-09-19 10:10:39 +08:00
|
|
|
gss_decrypt_xdr_buf(struct crypto_sync_skcipher *tfm, struct xdr_buf *buf,
|
2006-08-22 18:33:54 +08:00
|
|
|
int offset)
|
2005-10-14 04:55:13 +08:00
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
int ret;
|
2005-10-14 04:55:13 +08:00
|
|
|
struct decryptor_desc desc;
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
|
2005-10-14 04:55:13 +08:00
|
|
|
|
|
|
|
/* XXXJBF: */
|
2018-09-19 10:10:39 +08:00
|
|
|
BUG_ON((buf->len - offset) % crypto_sync_skcipher_blocksize(tfm) != 0);
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, tfm);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
2005-10-14 04:55:13 +08:00
|
|
|
|
|
|
|
memset(desc.iv, 0, sizeof(desc.iv));
|
2016-01-24 21:17:59 +08:00
|
|
|
desc.req = req;
|
2005-10-14 04:55:13 +08:00
|
|
|
desc.fragno = 0;
|
|
|
|
desc.fraglen = 0;
|
2007-10-27 15:52:07 +08:00
|
|
|
|
|
|
|
sg_init_table(desc.frags, 4);
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
ret = xdr_process_buf(buf, offset, buf->len - offset, decryptor, &desc);
|
|
|
|
skcipher_request_zero(req);
|
|
|
|
return ret;
|
2005-10-14 04:55:13 +08:00
|
|
|
}
|
2010-03-18 01:02:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function makes the assumption that it was ultimately called
|
|
|
|
* from gss_wrap().
|
|
|
|
*
|
|
|
|
* The client auth_gss code moves any existing tail data into a
|
|
|
|
* separate page before calling gss_wrap.
|
|
|
|
* The server svcauth_gss code ensures that both the head and the
|
|
|
|
* tail have slack space of RPC_MAX_AUTH_SIZE before calling gss_wrap.
|
|
|
|
*
|
|
|
|
* Even with that guarantee, this function may be called more than
|
|
|
|
* once in the processing of gss_wrap(). The best we can do is
|
|
|
|
* verify at compile-time (see GSS_KRB5_SLACK_CHECK) that the
|
|
|
|
* largest expected shift will fit within RPC_MAX_AUTH_SIZE.
|
|
|
|
* At run-time we can verify that a single invocation of this
|
|
|
|
* function doesn't attempt to use more the RPC_MAX_AUTH_SIZE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
xdr_extend_head(struct xdr_buf *buf, unsigned int base, unsigned int shiftlen)
|
|
|
|
{
|
|
|
|
u8 *p;
|
|
|
|
|
|
|
|
if (shiftlen == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(GSS_KRB5_MAX_SLACK_NEEDED > RPC_MAX_AUTH_SIZE);
|
|
|
|
BUG_ON(shiftlen > RPC_MAX_AUTH_SIZE);
|
|
|
|
|
|
|
|
p = buf->head[0].iov_base + base;
|
|
|
|
|
|
|
|
memmove(p + shiftlen, p, buf->head[0].iov_len - base);
|
|
|
|
|
|
|
|
buf->head[0].iov_len += shiftlen;
|
|
|
|
buf->len += shiftlen;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
static u32
|
2018-09-19 10:10:39 +08:00
|
|
|
gss_krb5_cts_crypt(struct crypto_sync_skcipher *cipher, struct xdr_buf *buf,
|
2010-03-18 01:03:00 +08:00
|
|
|
u32 offset, u8 *iv, struct page **pages, int encrypt)
|
|
|
|
{
|
|
|
|
u32 ret;
|
|
|
|
struct scatterlist sg[1];
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, cipher);
|
2016-10-19 04:30:09 +08:00
|
|
|
u8 *data;
|
2010-03-18 01:03:00 +08:00
|
|
|
struct page **save_pages;
|
|
|
|
u32 len = buf->len - offset;
|
|
|
|
|
2016-10-19 04:30:09 +08:00
|
|
|
if (len > GSS_KRB5_MAX_BLOCKSIZE * 2) {
|
2012-03-13 01:29:05 +08:00
|
|
|
WARN_ON(0);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2016-10-19 04:30:09 +08:00
|
|
|
data = kmalloc(GSS_KRB5_MAX_BLOCKSIZE * 2, GFP_NOFS);
|
|
|
|
if (!data)
|
|
|
|
return -ENOMEM;
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For encryption, we want to read from the cleartext
|
|
|
|
* page cache pages, and write the encrypted data to
|
|
|
|
* the supplied xdr_buf pages.
|
|
|
|
*/
|
|
|
|
save_pages = buf->pages;
|
|
|
|
if (encrypt)
|
|
|
|
buf->pages = pages;
|
|
|
|
|
|
|
|
ret = read_bytes_from_xdr_buf(buf, offset, data, len);
|
|
|
|
buf->pages = save_pages;
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
sg_init_one(sg, data, len);
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, cipher);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
|
|
|
skcipher_request_set_crypt(req, sg, sg, len, iv);
|
|
|
|
|
2010-03-18 01:03:00 +08:00
|
|
|
if (encrypt)
|
2016-01-24 21:17:59 +08:00
|
|
|
ret = crypto_skcipher_encrypt(req);
|
2010-03-18 01:03:00 +08:00
|
|
|
else
|
2016-01-24 21:17:59 +08:00
|
|
|
ret = crypto_skcipher_decrypt(req);
|
|
|
|
|
|
|
|
skcipher_request_zero(req);
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = write_bytes_to_xdr_buf(buf, offset, data, len);
|
|
|
|
|
|
|
|
out:
|
2016-10-19 04:30:09 +08:00
|
|
|
kfree(data);
|
2010-03-18 01:03:00 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32
|
|
|
|
gss_krb5_aes_encrypt(struct krb5_ctx *kctx, u32 offset,
|
2014-07-16 18:52:22 +08:00
|
|
|
struct xdr_buf *buf, struct page **pages)
|
2010-03-18 01:03:00 +08:00
|
|
|
{
|
|
|
|
u32 err;
|
|
|
|
struct xdr_netobj hmac;
|
|
|
|
u8 *cksumkey;
|
|
|
|
u8 *ecptr;
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *cipher, *aux_cipher;
|
2010-03-18 01:03:00 +08:00
|
|
|
int blocksize;
|
|
|
|
struct page **save_pages;
|
|
|
|
int nblocks, nbytes;
|
|
|
|
struct encryptor_desc desc;
|
|
|
|
u32 cbcbytes;
|
2010-03-18 01:03:02 +08:00
|
|
|
unsigned int usage;
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
if (kctx->initiate) {
|
|
|
|
cipher = kctx->initiator_enc;
|
|
|
|
aux_cipher = kctx->initiator_enc_aux;
|
|
|
|
cksumkey = kctx->initiator_integ;
|
2010-03-18 01:03:02 +08:00
|
|
|
usage = KG_USAGE_INITIATOR_SEAL;
|
2010-03-18 01:03:00 +08:00
|
|
|
} else {
|
|
|
|
cipher = kctx->acceptor_enc;
|
|
|
|
aux_cipher = kctx->acceptor_enc_aux;
|
|
|
|
cksumkey = kctx->acceptor_integ;
|
2010-03-18 01:03:02 +08:00
|
|
|
usage = KG_USAGE_ACCEPTOR_SEAL;
|
2010-03-18 01:03:00 +08:00
|
|
|
}
|
2018-09-19 10:10:39 +08:00
|
|
|
blocksize = crypto_sync_skcipher_blocksize(cipher);
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
/* hide the gss token header and insert the confounder */
|
|
|
|
offset += GSS_KRB5_TOK_HDR_LEN;
|
2010-03-18 01:03:05 +08:00
|
|
|
if (xdr_extend_head(buf, offset, kctx->gk5e->conflen))
|
2010-03-18 01:03:00 +08:00
|
|
|
return GSS_S_FAILURE;
|
2010-03-18 01:03:05 +08:00
|
|
|
gss_krb5_make_confounder(buf->head[0].iov_base + offset, kctx->gk5e->conflen);
|
2010-03-18 01:03:00 +08:00
|
|
|
offset -= GSS_KRB5_TOK_HDR_LEN;
|
|
|
|
|
|
|
|
if (buf->tail[0].iov_base != NULL) {
|
|
|
|
ecptr = buf->tail[0].iov_base + buf->tail[0].iov_len;
|
|
|
|
} else {
|
|
|
|
buf->tail[0].iov_base = buf->head[0].iov_base
|
|
|
|
+ buf->head[0].iov_len;
|
|
|
|
buf->tail[0].iov_len = 0;
|
|
|
|
ecptr = buf->tail[0].iov_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy plaintext gss token header after filler (if any) */
|
2014-07-16 18:52:22 +08:00
|
|
|
memcpy(ecptr, buf->head[0].iov_base + offset, GSS_KRB5_TOK_HDR_LEN);
|
2010-03-18 01:03:00 +08:00
|
|
|
buf->tail[0].iov_len += GSS_KRB5_TOK_HDR_LEN;
|
|
|
|
buf->len += GSS_KRB5_TOK_HDR_LEN;
|
|
|
|
|
|
|
|
/* Do the HMAC */
|
|
|
|
hmac.len = GSS_KRB5_MAX_CKSUM_LEN;
|
|
|
|
hmac.data = buf->tail[0].iov_base + buf->tail[0].iov_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When we are called, pages points to the real page cache
|
|
|
|
* data -- which we can't go and encrypt! buf->pages points
|
|
|
|
* to scratch pages which we are going to send off to the
|
|
|
|
* client/server. Swap in the plaintext pages to calculate
|
|
|
|
* the hmac.
|
|
|
|
*/
|
|
|
|
save_pages = buf->pages;
|
|
|
|
buf->pages = pages;
|
|
|
|
|
|
|
|
err = make_checksum_v2(kctx, NULL, 0, buf,
|
2010-03-18 01:03:02 +08:00
|
|
|
offset + GSS_KRB5_TOK_HDR_LEN,
|
|
|
|
cksumkey, usage, &hmac);
|
2010-03-18 01:03:00 +08:00
|
|
|
buf->pages = save_pages;
|
|
|
|
if (err)
|
|
|
|
return GSS_S_FAILURE;
|
|
|
|
|
|
|
|
nbytes = buf->len - offset - GSS_KRB5_TOK_HDR_LEN;
|
|
|
|
nblocks = (nbytes + blocksize - 1) / blocksize;
|
|
|
|
cbcbytes = 0;
|
|
|
|
if (nblocks > 2)
|
|
|
|
cbcbytes = (nblocks - 2) * blocksize;
|
|
|
|
|
|
|
|
memset(desc.iv, 0, sizeof(desc.iv));
|
|
|
|
|
|
|
|
if (cbcbytes) {
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, aux_cipher);
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2010-03-18 01:03:00 +08:00
|
|
|
desc.pos = offset + GSS_KRB5_TOK_HDR_LEN;
|
|
|
|
desc.fragno = 0;
|
|
|
|
desc.fraglen = 0;
|
|
|
|
desc.pages = pages;
|
|
|
|
desc.outbuf = buf;
|
2016-01-24 21:17:59 +08:00
|
|
|
desc.req = req;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, aux_cipher);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
sg_init_table(desc.infrags, 4);
|
|
|
|
sg_init_table(desc.outfrags, 4);
|
|
|
|
|
|
|
|
err = xdr_process_buf(buf, offset + GSS_KRB5_TOK_HDR_LEN,
|
|
|
|
cbcbytes, encryptor, &desc);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_zero(req);
|
2010-03-18 01:03:00 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure IV carries forward from any CBC results. */
|
|
|
|
err = gss_krb5_cts_crypt(cipher, buf,
|
|
|
|
offset + GSS_KRB5_TOK_HDR_LEN + cbcbytes,
|
|
|
|
desc.iv, pages, 1);
|
|
|
|
if (err) {
|
|
|
|
err = GSS_S_FAILURE;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now update buf to account for HMAC */
|
|
|
|
buf->tail[0].iov_len += kctx->gk5e->cksumlength;
|
|
|
|
buf->len += kctx->gk5e->cksumlength;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
if (err)
|
|
|
|
err = GSS_S_FAILURE;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32
|
|
|
|
gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf,
|
|
|
|
u32 *headskip, u32 *tailskip)
|
|
|
|
{
|
|
|
|
struct xdr_buf subbuf;
|
|
|
|
u32 ret = 0;
|
|
|
|
u8 *cksum_key;
|
2018-09-19 10:10:39 +08:00
|
|
|
struct crypto_sync_skcipher *cipher, *aux_cipher;
|
2010-03-18 01:03:00 +08:00
|
|
|
struct xdr_netobj our_hmac_obj;
|
|
|
|
u8 our_hmac[GSS_KRB5_MAX_CKSUM_LEN];
|
|
|
|
u8 pkt_hmac[GSS_KRB5_MAX_CKSUM_LEN];
|
|
|
|
int nblocks, blocksize, cbcbytes;
|
|
|
|
struct decryptor_desc desc;
|
2010-03-18 01:03:02 +08:00
|
|
|
unsigned int usage;
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
if (kctx->initiate) {
|
|
|
|
cipher = kctx->acceptor_enc;
|
|
|
|
aux_cipher = kctx->acceptor_enc_aux;
|
|
|
|
cksum_key = kctx->acceptor_integ;
|
2010-03-18 01:03:02 +08:00
|
|
|
usage = KG_USAGE_ACCEPTOR_SEAL;
|
2010-03-18 01:03:00 +08:00
|
|
|
} else {
|
|
|
|
cipher = kctx->initiator_enc;
|
|
|
|
aux_cipher = kctx->initiator_enc_aux;
|
|
|
|
cksum_key = kctx->initiator_integ;
|
2010-03-18 01:03:02 +08:00
|
|
|
usage = KG_USAGE_INITIATOR_SEAL;
|
2010-03-18 01:03:00 +08:00
|
|
|
}
|
2018-09-19 10:10:39 +08:00
|
|
|
blocksize = crypto_sync_skcipher_blocksize(cipher);
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* create a segment skipping the header and leaving out the checksum */
|
|
|
|
xdr_buf_subsegment(buf, &subbuf, offset + GSS_KRB5_TOK_HDR_LEN,
|
|
|
|
(buf->len - offset - GSS_KRB5_TOK_HDR_LEN -
|
|
|
|
kctx->gk5e->cksumlength));
|
|
|
|
|
|
|
|
nblocks = (subbuf.len + blocksize - 1) / blocksize;
|
|
|
|
|
|
|
|
cbcbytes = 0;
|
|
|
|
if (nblocks > 2)
|
|
|
|
cbcbytes = (nblocks - 2) * blocksize;
|
|
|
|
|
|
|
|
memset(desc.iv, 0, sizeof(desc.iv));
|
|
|
|
|
|
|
|
if (cbcbytes) {
|
2018-09-19 10:10:39 +08:00
|
|
|
SYNC_SKCIPHER_REQUEST_ON_STACK(req, aux_cipher);
|
2016-01-24 21:17:59 +08:00
|
|
|
|
2010-03-18 01:03:00 +08:00
|
|
|
desc.fragno = 0;
|
|
|
|
desc.fraglen = 0;
|
2016-01-24 21:17:59 +08:00
|
|
|
desc.req = req;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
skcipher_request_set_sync_tfm(req, aux_cipher);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
2010-03-18 01:03:00 +08:00
|
|
|
|
|
|
|
sg_init_table(desc.frags, 4);
|
|
|
|
|
|
|
|
ret = xdr_process_buf(&subbuf, 0, cbcbytes, decryptor, &desc);
|
2016-01-24 21:17:59 +08:00
|
|
|
skcipher_request_zero(req);
|
2010-03-18 01:03:00 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure IV carries forward from any CBC results. */
|
|
|
|
ret = gss_krb5_cts_crypt(cipher, &subbuf, cbcbytes, desc.iv, NULL, 0);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
|
|
|
|
/* Calculate our hmac over the plaintext data */
|
|
|
|
our_hmac_obj.len = sizeof(our_hmac);
|
|
|
|
our_hmac_obj.data = our_hmac;
|
|
|
|
|
|
|
|
ret = make_checksum_v2(kctx, NULL, 0, &subbuf, 0,
|
2010-03-18 01:03:02 +08:00
|
|
|
cksum_key, usage, &our_hmac_obj);
|
2010-03-18 01:03:00 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Get the packet's hmac value */
|
|
|
|
ret = read_bytes_from_xdr_buf(buf, buf->len - kctx->gk5e->cksumlength,
|
|
|
|
pkt_hmac, kctx->gk5e->cksumlength);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
|
2017-06-10 10:59:07 +08:00
|
|
|
if (crypto_memneq(pkt_hmac, our_hmac, kctx->gk5e->cksumlength) != 0) {
|
2010-03-18 01:03:00 +08:00
|
|
|
ret = GSS_S_BAD_SIG;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2010-03-18 01:03:05 +08:00
|
|
|
*headskip = kctx->gk5e->conflen;
|
2010-03-18 01:03:00 +08:00
|
|
|
*tailskip = kctx->gk5e->cksumlength;
|
|
|
|
out_err:
|
|
|
|
if (ret && ret != GSS_S_BAD_SIG)
|
|
|
|
ret = GSS_S_FAILURE;
|
|
|
|
return ret;
|
|
|
|
}
|
2010-03-18 01:03:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute Kseq given the initial session key and the checksum.
|
|
|
|
* Set the key of the given cipher.
|
|
|
|
*/
|
|
|
|
int
|
2018-09-19 10:10:39 +08:00
|
|
|
krb5_rc4_setup_seq_key(struct krb5_ctx *kctx,
|
|
|
|
struct crypto_sync_skcipher *cipher,
|
2010-03-18 01:03:06 +08:00
|
|
|
unsigned char *cksum)
|
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
struct crypto_shash *hmac;
|
|
|
|
struct shash_desc *desc;
|
2010-03-18 01:03:06 +08:00
|
|
|
u8 Kseq[GSS_KRB5_MAX_KEYLEN];
|
|
|
|
u32 zeroconstant = 0;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
dprintk("%s: entered\n", __func__);
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
hmac = crypto_alloc_shash(kctx->gk5e->cksum_name, 0, 0);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (IS_ERR(hmac)) {
|
|
|
|
dprintk("%s: error %ld, allocating hash '%s'\n",
|
|
|
|
__func__, PTR_ERR(hmac), kctx->gk5e->cksum_name);
|
|
|
|
return PTR_ERR(hmac);
|
|
|
|
}
|
|
|
|
|
2016-04-03 12:37:15 +08:00
|
|
|
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac),
|
2016-10-27 04:03:00 +08:00
|
|
|
GFP_NOFS);
|
2016-01-24 21:17:59 +08:00
|
|
|
if (!desc) {
|
|
|
|
dprintk("%s: failed to allocate shash descriptor for '%s'\n",
|
|
|
|
__func__, kctx->gk5e->cksum_name);
|
|
|
|
crypto_free_shash(hmac);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
desc->tfm = hmac;
|
|
|
|
desc->flags = 0;
|
2010-03-18 01:03:06 +08:00
|
|
|
|
|
|
|
/* Compute intermediate Kseq from session key */
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_setkey(hmac, kctx->Ksess, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_digest(desc, (u8 *)&zeroconstant, 4, Kseq);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Compute final Kseq from the checksum and intermediate Kseq */
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_setkey(hmac, Kseq, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_digest(desc, cksum, 8, Kseq);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
err = crypto_sync_skcipher_setkey(cipher, Kseq, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out_err:
|
2016-01-24 21:17:59 +08:00
|
|
|
kzfree(desc);
|
|
|
|
crypto_free_shash(hmac);
|
2010-03-18 01:03:06 +08:00
|
|
|
dprintk("%s: returning %d\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute Kcrypt given the initial session key and the plaintext seqnum.
|
|
|
|
* Set the key of cipher kctx->enc.
|
|
|
|
*/
|
|
|
|
int
|
2018-09-19 10:10:39 +08:00
|
|
|
krb5_rc4_setup_enc_key(struct krb5_ctx *kctx,
|
|
|
|
struct crypto_sync_skcipher *cipher,
|
2010-03-18 01:03:06 +08:00
|
|
|
s32 seqnum)
|
|
|
|
{
|
2016-01-24 21:17:59 +08:00
|
|
|
struct crypto_shash *hmac;
|
|
|
|
struct shash_desc *desc;
|
2010-03-18 01:03:06 +08:00
|
|
|
u8 Kcrypt[GSS_KRB5_MAX_KEYLEN];
|
|
|
|
u8 zeroconstant[4] = {0};
|
|
|
|
u8 seqnumarray[4];
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
dprintk("%s: entered, seqnum %u\n", __func__, seqnum);
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
hmac = crypto_alloc_shash(kctx->gk5e->cksum_name, 0, 0);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (IS_ERR(hmac)) {
|
|
|
|
dprintk("%s: error %ld, allocating hash '%s'\n",
|
|
|
|
__func__, PTR_ERR(hmac), kctx->gk5e->cksum_name);
|
|
|
|
return PTR_ERR(hmac);
|
|
|
|
}
|
|
|
|
|
2016-04-03 12:37:15 +08:00
|
|
|
desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(hmac),
|
2016-10-27 04:03:00 +08:00
|
|
|
GFP_NOFS);
|
2016-01-24 21:17:59 +08:00
|
|
|
if (!desc) {
|
|
|
|
dprintk("%s: failed to allocate shash descriptor for '%s'\n",
|
|
|
|
__func__, kctx->gk5e->cksum_name);
|
|
|
|
crypto_free_shash(hmac);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2010-03-18 01:03:06 +08:00
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
desc->tfm = hmac;
|
|
|
|
desc->flags = 0;
|
2010-03-18 01:03:06 +08:00
|
|
|
|
|
|
|
/* Compute intermediate Kcrypt from session key */
|
|
|
|
for (i = 0; i < kctx->gk5e->keylength; i++)
|
|
|
|
Kcrypt[i] = kctx->Ksess[i] ^ 0xf0;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_setkey(hmac, Kcrypt, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_digest(desc, zeroconstant, 4, Kcrypt);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
/* Compute final Kcrypt from the seqnum and intermediate Kcrypt */
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_setkey(hmac, Kcrypt, kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
seqnumarray[0] = (unsigned char) ((seqnum >> 24) & 0xff);
|
|
|
|
seqnumarray[1] = (unsigned char) ((seqnum >> 16) & 0xff);
|
|
|
|
seqnumarray[2] = (unsigned char) ((seqnum >> 8) & 0xff);
|
|
|
|
seqnumarray[3] = (unsigned char) ((seqnum >> 0) & 0xff);
|
|
|
|
|
2016-01-24 21:17:59 +08:00
|
|
|
err = crypto_shash_digest(desc, seqnumarray, 4, Kcrypt);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2018-09-19 10:10:39 +08:00
|
|
|
err = crypto_sync_skcipher_setkey(cipher, Kcrypt,
|
|
|
|
kctx->gk5e->keylength);
|
2010-03-18 01:03:06 +08:00
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out_err:
|
2016-01-24 21:17:59 +08:00
|
|
|
kzfree(desc);
|
|
|
|
crypto_free_shash(hmac);
|
2010-03-18 01:03:06 +08:00
|
|
|
dprintk("%s: returning %d\n", __func__, err);
|
|
|
|
return err;
|
|
|
|
}
|