Commit f036dd56 authored by Herbert Xu's avatar Herbert Xu

crypto: spacc - Use crypto_authenc_extractkeys

Use the crypto_authenc_extractkeys helper rather than ad-hoc parsing.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent c76c9ec3
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <crypto/gcm.h> #include <crypto/gcm.h>
#include <crypto/aead.h> #include <crypto/aead.h>
#include <crypto/authenc.h> #include <crypto/authenc.h>
#include <linux/rtnetlink.h>
#include <crypto/scatterwalk.h> #include <crypto/scatterwalk.h>
#include <crypto/internal/aead.h> #include <crypto/internal/aead.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -540,15 +539,13 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, const u8 *key, ...@@ -540,15 +539,13 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
{ {
struct spacc_crypto_ctx *ctx = crypto_aead_ctx(tfm); struct spacc_crypto_ctx *ctx = crypto_aead_ctx(tfm);
const struct spacc_alg *salg = spacc_tfm_aead(&tfm->base); const struct spacc_alg *salg = spacc_tfm_aead(&tfm->base);
struct crypto_authenc_keys authenc_keys;
struct spacc_priv *priv; struct spacc_priv *priv;
struct rtattr *rta = (void *)key;
struct crypto_authenc_key_param *param;
unsigned int authkeylen, enckeylen; unsigned int authkeylen, enckeylen;
const unsigned char *authkey, *enckey; const unsigned char *authkey, *enckey;
unsigned char xcbc[64]; unsigned char xcbc[64];
int err = -EINVAL;
int singlekey = 0; int singlekey = 0;
int err;
/* are keylens valid? */ /* are keylens valid? */
ctx->ctx_valid = false; ctx->ctx_valid = false;
...@@ -569,26 +566,14 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, const u8 *key, ...@@ -569,26 +566,14 @@ static int spacc_aead_setkey(struct crypto_aead *tfm, const u8 *key,
goto skipover; goto skipover;
} }
if (!RTA_OK(rta, keylen) || err = crypto_authenc_extractkeys(&authenc_keys, key, keylen);
rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM || if (err)
RTA_PAYLOAD(rta) < sizeof(*param)) return err;
return -EINVAL;
param = RTA_DATA(rta);
enckeylen = be32_to_cpu(param->enckeylen);
key += RTA_ALIGN(rta->rta_len);
keylen -= RTA_ALIGN(rta->rta_len);
if (keylen < enckeylen)
return -EINVAL;
authkeylen = keylen - enckeylen;
/* enckey is at &key[authkeylen] and authkeylen = authenc_keys.authkeylen;
* authkey is at &key[0] authkey = authenc_keys.authkey;
*/ enckeylen = authenc_keys.enckeylen;
authkey = &key[0]; enckey = authenc_keys.enckey;
enckey = &key[authkeylen];
skipover: skipover:
/* detect RFC3686/4106 and trim from enckeylen(and copy salt..) */ /* detect RFC3686/4106 and trim from enckeylen(and copy salt..) */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment