static struct crypto_engine *phmac_crypto_engine;
#define MAX_QLEN 10
+static bool pkey_clrkey_allowed;
+module_param_named(clrkey, pkey_clrkey_allowed, bool, 0444);
+MODULE_PARM_DESC(clrkey, "Allow clear key material (default N)");
+
/*
* A simple hash walk helper
*/
* This function may sleep - don't call in non-sleeping context.
*/
static inline int convert_key(const u8 *key, unsigned int keylen,
- struct phmac_protkey *pk)
+ struct phmac_protkey *pk, bool tested)
{
+ u32 xflags = PKEY_XFLAG_NOMEMALLOC;
int rc, i;
+ if (tested && !pkey_clrkey_allowed)
+ xflags |= PKEY_XFLAG_NOCLEARKEY;
+
pk->len = sizeof(pk->protkey);
/*
}
rc = pkey_key2protkey(key, keylen,
pk->protkey, &pk->len, &pk->type,
- PKEY_XFLAG_NOMEMALLOC);
+ xflags);
}
out:
* unnecessary additional conversion but never to invalid data on the
* hash operation.
*/
-static int phmac_convert_key(struct phmac_tfm_ctx *tfm_ctx)
+static int phmac_convert_key(struct phmac_tfm_ctx *tfm_ctx, bool tested)
{
struct phmac_protkey pk;
int rc;
tfm_ctx->pk_state = PK_STATE_CONVERT_IN_PROGRESS;
spin_unlock_bh(&tfm_ctx->pk_lock);
- rc = convert_key(tfm_ctx->keybuf, tfm_ctx->keylen, &pk);
+ rc = convert_key(tfm_ctx->keybuf, tfm_ctx->keylen, &pk, tested);
/* update context */
spin_lock_bh(&tfm_ctx->pk_lock);
struct kmac_sha2_ctx *ctx = &req_ctx->kmac_ctx;
struct hash_walk_helper *hwh = &req_ctx->hwh;
unsigned int bs = crypto_ahash_blocksize(tfm);
+ bool tested = crypto_ahash_tested(tfm);
unsigned int offset, k, n;
int rc = 0;
rc = -EKEYEXPIRED;
goto out;
}
- rc = phmac_convert_key(tfm_ctx);
+ rc = phmac_convert_key(tfm_ctx, tested);
if (rc)
goto out;
spin_lock_bh(&tfm_ctx->pk_lock);
rc = -EKEYEXPIRED;
goto out;
}
- rc = phmac_convert_key(tfm_ctx);
+ rc = phmac_convert_key(tfm_ctx, tested);
if (rc)
goto out;
spin_lock_bh(&tfm_ctx->pk_lock);
struct kmac_sha2_ctx *ctx = &req_ctx->kmac_ctx;
unsigned int ds = crypto_ahash_digestsize(tfm);
unsigned int bs = crypto_ahash_blocksize(tfm);
+ bool tested = crypto_ahash_tested(tfm);
unsigned int k, n;
int rc = 0;
rc = -EKEYEXPIRED;
goto out;
}
- rc = phmac_convert_key(tfm_ctx);
+ rc = phmac_convert_key(tfm_ctx, tested);
if (rc)
goto out;
spin_lock_bh(&tfm_ctx->pk_lock);
struct phmac_tfm_ctx *tfm_ctx = crypto_ahash_ctx(tfm);
unsigned int ds = crypto_ahash_digestsize(tfm);
unsigned int bs = crypto_ahash_blocksize(tfm);
+ bool tested = crypto_ahash_tested(tfm);
unsigned int tmpkeylen;
u8 *tmpkey = NULL;
int rc = 0;
- if (!crypto_ahash_tested(tfm)) {
+ if (!tested) {
/*
* selftest running: key is a raw hmac clear key and needs
* to get embedded into a 'clear key token' in order to have
goto out;
/* convert raw key into protected key */
- rc = phmac_convert_key(tfm_ctx);
+ rc = phmac_convert_key(tfm_ctx, tested);
if (rc)
goto out;