Re: [PATCH] crypto: ccp - Check for CCP before registering crypto algs

2014-09-05 Thread Scot Doyle

On Fri, 5 Sep 2014, Tom Lendacky wrote:

> If the ccp is built as a built-in module, then ccp-crypto (whether
> built as a module or a built-in module) will be able to load and
> it will register its crypto algorithms.  If the system does not have
> a CCP this will result in -ENODEV being returned whenever a command
> is attempted to be queued by the registered crypto algorithms.
>
> Add an API, ccp_present(), that checks for the presence of a CCP
> on the system.  The ccp-crypto module can use this to determine if it
> should register it's crypto alogorithms.
>
> Reported-by: Scot Doyle 
> Signed-off-by: Tom Lendacky 
> ---
> drivers/crypto/ccp/ccp-crypto-main.c |4 
> drivers/crypto/ccp/ccp-dev.c |   14 ++
> include/linux/ccp.h  |   12 
> 3 files changed, 30 insertions(+)
>
> diff --git a/drivers/crypto/ccp/ccp-crypto-main.c 
> b/drivers/crypto/ccp/ccp-crypto-main.c
> index 20dc848..4d4e016 100644
> --- a/drivers/crypto/ccp/ccp-crypto-main.c
> +++ b/drivers/crypto/ccp/ccp-crypto-main.c
> @@ -367,6 +367,10 @@ static int ccp_crypto_init(void)
> {
>   int ret;
>
> + ret = ccp_present();
> + if (ret)
> + return ret;
> +
>   spin_lock_init(&req_queue_lock);
>   INIT_LIST_HEAD(&req_queue.cmds);
>   req_queue.backlog = &req_queue.cmds;
> diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
> index a7d1106..c6e6171 100644
> --- a/drivers/crypto/ccp/ccp-dev.c
> +++ b/drivers/crypto/ccp/ccp-dev.c
> @@ -55,6 +55,20 @@ static inline void ccp_del_device(struct ccp_device *ccp)
> }
>
> /**
> + * ccp_present - check if a CCP device is present
> + *
> + * Returns zero if a CCP device is present, -ENODEV otherwise.
> + */
> +int ccp_present(void)
> +{
> + if (ccp_get_device())
> + return 0;
> +
> + return -ENODEV;
> +}
> +EXPORT_SYMBOL_GPL(ccp_present);
> +
> +/**
>  * ccp_enqueue_cmd - queue an operation for processing by the CCP
>  *
>  * @cmd: ccp_cmd struct to be processed
> diff --git a/include/linux/ccp.h b/include/linux/ccp.h
> index ebcc9d1..7f43703 100644
> --- a/include/linux/ccp.h
> +++ b/include/linux/ccp.h
> @@ -27,6 +27,13 @@ struct ccp_cmd;
>   defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE)
>
> /**
> + * ccp_present - check if a CCP device is present
> + *
> + * Returns zero if a CCP device is present, -ENODEV otherwise.
> + */
> +int ccp_present(void);
> +
> +/**
>  * ccp_enqueue_cmd - queue an operation for processing by the CCP
>  *
>  * @cmd: ccp_cmd struct to be processed
> @@ -53,6 +60,11 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd);
>
> #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */
>
> +static inline int ccp_present(void)
> +{
> + return -ENODEV;
> +}
> +
> static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
> {
>   return -ENODEV;

Thanks Tom!

Tested-by: Scot Doyle 

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] crypto: LLVMLinux: Remove VLAIS usage from crypto/testmgr.c

2014-09-05 Thread behanw
From: Jan-Simon Möller 

The use of variable length arrays in structs (VLAIS) in the Linux Kernel code
precludes the use of compilers which don't implement VLAIS (for instance the
Clang compiler). This patch instead allocates the appropriate amount of memory
using an char array.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Jan-Simon Möller 
Signed-off-by: Behan Webster 
Cc: pagee...@freemail.hu
---
 crypto/testmgr.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index ac2b631..34f5a32 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1714,16 +1714,16 @@ static int alg_test_crc32c(const struct alg_test_desc 
*desc,
}
 
do {
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(tfm)];
-   } sdesc;
+   char sdesc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(tfm)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)sdesc;
+   u32 *ctx = (u32 *)shash_desc_ctx(shash);
 
-   sdesc.shash.tfm = tfm;
-   sdesc.shash.flags = 0;
+   shash->tfm = tfm;
+   shash->flags = 0;
 
-   *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
-   err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
+   *ctx = le32_to_cpu(420553207);
+   err = crypto_shash_final(shash, (u8 *)&val);
if (err) {
printk(KERN_ERR "alg: crc32c: Operation failed for "
   "%s: %d\n", driver, err);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] crypto: LLVMLinux: Remove VLAIS usage from crypto/hmac.c

2014-09-05 Thread behanw
From: Jan-Simon Möller 

The use of variable length arrays in structs (VLAIS) in the Linux Kernel code
precludes the use of compilers which don't implement VLAIS (for instance the
Clang compiler). This patch instead allocates the appropriate amount of memory
using an char array.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Jan-Simon Möller 
Signed-off-by: Behan Webster 
Cc: pagee...@freemail.hu
---
 crypto/hmac.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/crypto/hmac.c b/crypto/hmac.c
index 8d9544c..f2da806 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -52,20 +52,19 @@ static int hmac_setkey(struct crypto_shash *parent,
struct hmac_ctx *ctx = align_ptr(opad + ss,
 crypto_tfm_ctx_alignment());
struct crypto_shash *hash = ctx->hash;
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(hash)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(hash)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
unsigned int i;
 
-   desc.shash.tfm = hash;
-   desc.shash.flags = crypto_shash_get_flags(parent) &
-   CRYPTO_TFM_REQ_MAY_SLEEP;
+   shash->tfm = hash;
+   shash->flags = crypto_shash_get_flags(parent)
+   & CRYPTO_TFM_REQ_MAY_SLEEP;
 
if (keylen > bs) {
int err;
 
-   err = crypto_shash_digest(&desc.shash, inkey, keylen, ipad);
+   err = crypto_shash_digest(shash, inkey, keylen, ipad);
if (err)
return err;
 
@@ -81,12 +80,12 @@ static int hmac_setkey(struct crypto_shash *parent,
opad[i] ^= 0x5c;
}
 
-   return crypto_shash_init(&desc.shash) ?:
-  crypto_shash_update(&desc.shash, ipad, bs) ?:
-  crypto_shash_export(&desc.shash, ipad) ?:
-  crypto_shash_init(&desc.shash) ?:
-  crypto_shash_update(&desc.shash, opad, bs) ?:
-  crypto_shash_export(&desc.shash, opad);
+   return crypto_shash_init(shash) ?:
+  crypto_shash_update(shash, ipad, bs) ?:
+  crypto_shash_export(shash, ipad) ?:
+  crypto_shash_init(shash) ?:
+  crypto_shash_update(shash, opad, bs) ?:
+  crypto_shash_export(shash, opad);
 }
 
 static int hmac_export(struct shash_desc *pdesc, void *out)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: LLVMLinux: Remove VLAIS from crypto/omap_sham.c

2014-09-05 Thread behanw
From: Behan Webster 

Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using an char array.

The new code can be compiled with both gcc and clang.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Behan Webster 
Signed-off-by: Mark Charlebois 
Signed-off-by: Jan-Simon Möller 
---
 drivers/crypto/omap-sham.c | 32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
index 710d863..dcbfd35 100644
--- a/drivers/crypto/omap-sham.c
+++ b/drivers/crypto/omap-sham.c
@@ -949,17 +949,16 @@ static int omap_sham_finish_hmac(struct ahash_request 
*req)
struct omap_sham_hmac_ctx *bctx = tctx->base;
int bs = crypto_shash_blocksize(bctx->shash);
int ds = crypto_shash_digestsize(bctx->shash);
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(bctx->shash)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(bctx->shash)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
 
-   desc.shash.tfm = bctx->shash;
-   desc.shash.flags = 0; /* not CRYPTO_TFM_REQ_MAY_SLEEP */
+   shash->tfm = bctx->shash;
+   shash->flags = 0; /* not CRYPTO_TFM_REQ_MAY_SLEEP */
 
-   return crypto_shash_init(&desc.shash) ?:
-  crypto_shash_update(&desc.shash, bctx->opad, bs) ?:
-  crypto_shash_finup(&desc.shash, req->result, ds, req->result);
+   return crypto_shash_init(shash) ?:
+  crypto_shash_update(shash, bctx->opad, bs) ?:
+  crypto_shash_finup(shash, req->result, ds, req->result);
 }
 
 static int omap_sham_finish(struct ahash_request *req)
@@ -1118,18 +1117,17 @@ static int omap_sham_update(struct ahash_request *req)
return omap_sham_enqueue(req, OP_UPDATE);
 }
 
-static int omap_sham_shash_digest(struct crypto_shash *shash, u32 flags,
+static int omap_sham_shash_digest(struct crypto_shash *tfm, u32 flags,
  const u8 *data, unsigned int len, u8 *out)
 {
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(shash)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(shash)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
 
-   desc.shash.tfm = shash;
-   desc.shash.flags = flags & CRYPTO_TFM_REQ_MAY_SLEEP;
+   shash->tfm = tfm;
+   shash->flags = flags & CRYPTO_TFM_REQ_MAY_SLEEP;
 
-   return crypto_shash_digest(&desc.shash, data, len, out);
+   return crypto_shash_digest(shash, data, len, out);
 }
 
 static int omap_sham_final_shash(struct ahash_request *req)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: LLVMLinux: Remove VLAIS from crypto/.../qat_algs.c

2014-09-05 Thread behanw
From: Behan Webster 

Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using an char array.

The new code can be compiled with both gcc and clang.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Behan Webster 
Signed-off-by: Mark Charlebois 
Signed-off-by: Jan-Simon Möller 
---
 drivers/crypto/qat/qat_common/qat_algs.c | 33 
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/drivers/crypto/qat/qat_common/qat_algs.c 
b/drivers/crypto/qat/qat_common/qat_algs.c
index 59df488..3090333 100644
--- a/drivers/crypto/qat/qat_common/qat_algs.c
+++ b/drivers/crypto/qat/qat_common/qat_algs.c
@@ -152,10 +152,9 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
  const uint8_t *auth_key,
  unsigned int auth_keylen, uint8_t *auth_state)
 {
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(ctx->hash_tfm)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(ctx->hash_tfm)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
struct sha1_state sha1;
struct sha256_state sha256;
struct sha512_state sha512;
@@ -167,12 +166,12 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
__be64 *hash512_state_out;
int i, offset;
 
-   desc.shash.tfm = ctx->hash_tfm;
-   desc.shash.flags = 0x0;
+   shash->tfm = ctx->hash_tfm;
+   shash->flags = 0x0;
 
if (auth_keylen > block_size) {
char buff[SHA512_BLOCK_SIZE];
-   int ret = crypto_shash_digest(&desc.shash, auth_key,
+   int ret = crypto_shash_digest(shash, auth_key,
  auth_keylen, buff);
if (ret)
return ret;
@@ -195,10 +194,10 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
*opad_ptr ^= 0x5C;
}
 
-   if (crypto_shash_init(&desc.shash))
+   if (crypto_shash_init(shash))
return -EFAULT;
 
-   if (crypto_shash_update(&desc.shash, ipad, block_size))
+   if (crypto_shash_update(shash, ipad, block_size))
return -EFAULT;
 
hash_state_out = (__be32 *)hash->sha.state1;
@@ -206,19 +205,19 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
 
switch (ctx->qat_hash_alg) {
case ICP_QAT_HW_AUTH_ALGO_SHA1:
-   if (crypto_shash_export(&desc.shash, &sha1))
+   if (crypto_shash_export(shash, &sha1))
return -EFAULT;
for (i = 0; i < digest_size >> 2; i++, hash_state_out++)
*hash_state_out = cpu_to_be32(*(sha1.state + i));
break;
case ICP_QAT_HW_AUTH_ALGO_SHA256:
-   if (crypto_shash_export(&desc.shash, &sha256))
+   if (crypto_shash_export(shash, &sha256))
return -EFAULT;
for (i = 0; i < digest_size >> 2; i++, hash_state_out++)
*hash_state_out = cpu_to_be32(*(sha256.state + i));
break;
case ICP_QAT_HW_AUTH_ALGO_SHA512:
-   if (crypto_shash_export(&desc.shash, &sha512))
+   if (crypto_shash_export(shash, &sha512))
return -EFAULT;
for (i = 0; i < digest_size >> 3; i++, hash512_state_out++)
*hash512_state_out = cpu_to_be64(*(sha512.state + i));
@@ -227,10 +226,10 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
return -EFAULT;
}
 
-   if (crypto_shash_init(&desc.shash))
+   if (crypto_shash_init(shash))
return -EFAULT;
 
-   if (crypto_shash_update(&desc.shash, opad, block_size))
+   if (crypto_shash_update(shash, opad, block_size))
return -EFAULT;
 
offset = round_up(qat_get_inter_state_size(ctx->qat_hash_alg), 8);
@@ -239,19 +238,19 @@ static int qat_alg_do_precomputes(struct 
icp_qat_hw_auth_algo_blk *hash,
 
switch (ctx->qat_hash_alg) {
case ICP_QAT_HW_AUTH_ALGO_SHA1:
-   if (crypto_shash_export(&desc.shash, &sha1))
+   if (crypto_shash_export(shash, &sha1))
return -EFAULT;
 

[PATCH] crypto: LLVMLinux: Remove VLAIS from crypto/n2_core.c

2014-09-05 Thread behanw
From: Behan Webster 

Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using an char array.

The new code can be compiled with both gcc and clang.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Behan Webster 
Signed-off-by: Mark Charlebois 
Signed-off-by: Jan-Simon Möller 
---
 drivers/crypto/n2_core.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index 7263c10..ed142d1 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -445,10 +445,9 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, 
const u8 *key,
struct n2_hmac_ctx *ctx = crypto_ahash_ctx(tfm);
struct crypto_shash *child_shash = ctx->child_shash;
struct crypto_ahash *fallback_tfm;
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(child_shash)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(child_shash)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
int err, bs, ds;
 
fallback_tfm = ctx->base.fallback_tfm;
@@ -456,15 +455,15 @@ static int n2_hmac_async_setkey(struct crypto_ahash *tfm, 
const u8 *key,
if (err)
return err;
 
-   desc.shash.tfm = child_shash;
-   desc.shash.flags = crypto_ahash_get_flags(tfm) &
+   shash->tfm = child_shash;
+   shash->flags = crypto_ahash_get_flags(tfm) &
CRYPTO_TFM_REQ_MAY_SLEEP;
 
bs = crypto_shash_blocksize(child_shash);
ds = crypto_shash_digestsize(child_shash);
BUG_ON(ds > N2_HASH_KEY_MAX);
if (keylen > bs) {
-   err = crypto_shash_digest(&desc.shash, key, keylen,
+   err = crypto_shash_digest(shash, key, keylen,
  ctx->hash_key);
if (err)
return err;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] crypto: LLVMLinux: Remove VLAIS from crypto/mv_cesa.c

2014-09-05 Thread behanw
From: Behan Webster 

Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using an char array.

The new code can be compiled with both gcc and clang.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Behan Webster 
Signed-off-by: Mark Charlebois 
Signed-off-by: Jan-Simon Möller 
---
 drivers/crypto/mv_cesa.c | 46 +++---
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index 29d0ee5..0d92c85 100644
--- a/drivers/crypto/mv_cesa.c
+++ b/drivers/crypto/mv_cesa.c
@@ -402,26 +402,25 @@ static int mv_hash_final_fallback(struct ahash_request 
*req)
 {
const struct mv_tfm_hash_ctx *tfm_ctx = crypto_tfm_ctx(req->base.tfm);
struct mv_req_hash_ctx *req_ctx = ahash_request_ctx(req);
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(tfm_ctx->fallback)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(tfm_ctx->fallback)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
int rc;
 
-   desc.shash.tfm = tfm_ctx->fallback;
-   desc.shash.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+   shash->tfm = tfm_ctx->fallback;
+   shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
if (unlikely(req_ctx->first_hash)) {
-   crypto_shash_init(&desc.shash);
-   crypto_shash_update(&desc.shash, req_ctx->buffer,
+   crypto_shash_init(shash);
+   crypto_shash_update(shash, req_ctx->buffer,
req_ctx->extra_bytes);
} else {
/* only SHA1 for now
 */
-   rc = mv_hash_import_sha1_ctx(req_ctx, &desc.shash);
+   rc = mv_hash_import_sha1_ctx(req_ctx, shash);
if (rc)
goto out;
}
-   rc = crypto_shash_final(&desc.shash, req->result);
+   rc = crypto_shash_final(shash, req->result);
 out:
return rc;
 }
@@ -794,23 +793,24 @@ static int mv_hash_setkey(struct crypto_ahash *tfm, const 
u8 * key,
ss = crypto_shash_statesize(ctx->base_hash);
 
{
-   struct {
-   struct shash_desc shash;
-   char ctx[crypto_shash_descsize(ctx->base_hash)];
-   } desc;
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(ctx->base_hash)]
+   CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *shash = (struct shash_desc *)desc;
+
unsigned int i;
char ipad[ss];
char opad[ss];
 
-   desc.shash.tfm = ctx->base_hash;
-   desc.shash.flags = crypto_shash_get_flags(ctx->base_hash) &
+   shash->tfm = ctx->base_hash;
+   shash->flags = crypto_shash_get_flags(ctx->base_hash) &
CRYPTO_TFM_REQ_MAY_SLEEP;
 
if (keylen > bs) {
int err;
 
err =
-   crypto_shash_digest(&desc.shash, key, keylen, ipad);
+   crypto_shash_digest(shash, key, keylen, ipad);
if (err)
return err;
 
@@ -826,12 +826,12 @@ static int mv_hash_setkey(struct crypto_ahash *tfm, const 
u8 * key,
opad[i] ^= 0x5c;
}
 
-   rc = crypto_shash_init(&desc.shash) ? :
-   crypto_shash_update(&desc.shash, ipad, bs) ? :
-   crypto_shash_export(&desc.shash, ipad) ? :
-   crypto_shash_init(&desc.shash) ? :
-   crypto_shash_update(&desc.shash, opad, bs) ? :
-   crypto_shash_export(&desc.shash, opad);
+   rc = crypto_shash_init(shash) ? :
+   crypto_shash_update(shash, ipad, bs) ? :
+   crypto_shash_export(shash, ipad) ? :
+   crypto_shash_init(shash) ? :
+   crypto_shash_update(shash, opad, bs) ? :
+   crypto_shash_export(shash, opad);
 
if (rc == 0)
mv_hash_init_ivs(ctx, ipad, opad);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vge

[PATCH] crypto: LLVMLinux: Remove VLAIS from crypto/ccp/ccp-crypto-sha.c

2014-09-05 Thread behanw
From: Jan-Simon Möller 

Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
compliant equivalent. This patch allocates the appropriate amount of memory
using an char array.

The new code can be compiled with both gcc and clang.

struct shash_desc contains a flexible array member member ctx declared with
CRYPTO_MINALIGN_ATTR, so sizeof(struct shash_desc) aligns the beginning
of the array declared after struct shash_desc with long long.

No trailing padding is required because it is not a struct type that can
be used in an array.

The CRYPTO_MINALIGN_ATTR is required so that desc is aligned with long long
as would be the case for a struct containing a member with
CRYPTO_MINALIGN_ATTR.

Signed-off-by: Jan-Simon Möller 
Signed-off-by: Behan Webster 
---
 drivers/crypto/ccp/ccp-crypto-sha.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-crypto-sha.c 
b/drivers/crypto/ccp/ccp-crypto-sha.c
index 873f234..29f9fda 100644
--- a/drivers/crypto/ccp/ccp-crypto-sha.c
+++ b/drivers/crypto/ccp/ccp-crypto-sha.c
@@ -198,10 +198,11 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const 
u8 *key,
 {
struct ccp_ctx *ctx = crypto_tfm_ctx(crypto_ahash_tfm(tfm));
struct crypto_shash *shash = ctx->u.sha.hmac_tfm;
-   struct {
-   struct shash_desc sdesc;
-   char ctx[crypto_shash_descsize(shash)];
-   } desc;
+
+   char desc[sizeof(struct shash_desc) +
+   crypto_shash_descsize(shash)] CRYPTO_MINALIGN_ATTR;
+   struct shash_desc *sdesc = (struct shash_desc *)desc;
+
unsigned int block_size = crypto_shash_blocksize(shash);
unsigned int digest_size = crypto_shash_digestsize(shash);
int i, ret;
@@ -216,11 +217,11 @@ static int ccp_sha_setkey(struct crypto_ahash *tfm, const 
u8 *key,
 
if (key_len > block_size) {
/* Must hash the input key */
-   desc.sdesc.tfm = shash;
-   desc.sdesc.flags = crypto_ahash_get_flags(tfm) &
+   sdesc->tfm = shash;
+   sdesc->flags = crypto_ahash_get_flags(tfm) &
CRYPTO_TFM_REQ_MAY_SLEEP;
 
-   ret = crypto_shash_digest(&desc.sdesc, key, key_len,
+   ret = crypto_shash_digest(sdesc, key, key_len,
  ctx->u.sha.key);
if (ret) {
crypto_ahash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Inkjet Printer ink

2014-09-05 Thread John
Dear Sir, 

  Glad to hear you're on the market for CIJ inks.
  This is Kingsfang(Xiamen)Import&Export Co.,Ltd in China.We specialized in the 
production of replacement of inkjet printer ink,such as Imaje, Domino, 
Videojet, Linx, Willet, Hitachi, KGK and so on, we have our own factory.
   For all the ink products got the SGS approval every year. Some have passed 
non-halogen request.
  
  Hope to find a way to cooperate with you!

Saleskingsfang
Kingsfang(Xiamen)Import&Export Co.,Ltd
Tel: +86-592-6058718
Email:sm...@kingsfang.com
Website: www.kingsfang.com

[PATCH] crypto: ccp - Check for CCP before registering crypto algs

2014-09-05 Thread Tom Lendacky
If the ccp is built as a built-in module, then ccp-crypto (whether
built as a module or a built-in module) will be able to load and
it will register its crypto algorithms.  If the system does not have
a CCP this will result in -ENODEV being returned whenever a command
is attempted to be queued by the registered crypto algorithms.

Add an API, ccp_present(), that checks for the presence of a CCP
on the system.  The ccp-crypto module can use this to determine if it
should register it's crypto alogorithms.

Reported-by: Scot Doyle 
Signed-off-by: Tom Lendacky 
---
 drivers/crypto/ccp/ccp-crypto-main.c |4 
 drivers/crypto/ccp/ccp-dev.c |   14 ++
 include/linux/ccp.h  |   12 
 3 files changed, 30 insertions(+)

diff --git a/drivers/crypto/ccp/ccp-crypto-main.c 
b/drivers/crypto/ccp/ccp-crypto-main.c
index 20dc848..4d4e016 100644
--- a/drivers/crypto/ccp/ccp-crypto-main.c
+++ b/drivers/crypto/ccp/ccp-crypto-main.c
@@ -367,6 +367,10 @@ static int ccp_crypto_init(void)
 {
int ret;
 
+   ret = ccp_present();
+   if (ret)
+   return ret;
+
spin_lock_init(&req_queue_lock);
INIT_LIST_HEAD(&req_queue.cmds);
req_queue.backlog = &req_queue.cmds;
diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
index a7d1106..c6e6171 100644
--- a/drivers/crypto/ccp/ccp-dev.c
+++ b/drivers/crypto/ccp/ccp-dev.c
@@ -55,6 +55,20 @@ static inline void ccp_del_device(struct ccp_device *ccp)
 }
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void)
+{
+   if (ccp_get_device())
+   return 0;
+
+   return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(ccp_present);
+
+/**
  * ccp_enqueue_cmd - queue an operation for processing by the CCP
  *
  * @cmd: ccp_cmd struct to be processed
diff --git a/include/linux/ccp.h b/include/linux/ccp.h
index ebcc9d1..7f43703 100644
--- a/include/linux/ccp.h
+++ b/include/linux/ccp.h
@@ -27,6 +27,13 @@ struct ccp_cmd;
defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE)
 
 /**
+ * ccp_present - check if a CCP device is present
+ *
+ * Returns zero if a CCP device is present, -ENODEV otherwise.
+ */
+int ccp_present(void);
+
+/**
  * ccp_enqueue_cmd - queue an operation for processing by the CCP
  *
  * @cmd: ccp_cmd struct to be processed
@@ -53,6 +60,11 @@ int ccp_enqueue_cmd(struct ccp_cmd *cmd);
 
 #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */
 
+static inline int ccp_present(void)
+{
+   return -ENODEV;
+}
+
 static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
 {
return -ENODEV;

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: AF_ALG inadvertently disabled

2014-09-05 Thread Tom Lendacky

On 09/04/2014 07:43 PM, Scot Doyle wrote:

On a laptop without AMD's CCP, compiling 3.17-rc3 with
   # CONFIG_MODULES is not set
   CONFIG_CRYPTO_MANAGER_DISABLE_TESTS=y
   CONFIG_CRYPTO_DEV_CCP=y
   CONFIG_CRYPTO_DEV_CCP_DD=y
   # CONFIG_CRYPTO_DEV_CCP_CRYPTO is not set
the strace from a test program is
   socket(PF_ALG, SOCK_SEQPACKET, 0)   = 3
   bind(3, {sa_family=AF_ALG, sa_data="skcipher\0\0\0\0\0\0"}, 88) = 0
   setsockopt(3, 0x117 /* SOL_?? */, 1, "n) 
\21\220\25-\364\356\5\2019\336\366\20\273", 16) = 0
   accept(3, 0, NULL)  = 4
   sendmsg(4, {msg_name(0)=NULL, 
msg_iov(1)=[{"\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27"...,
 512}], msg_controllen=64, {cmsg_len=20, cmsg_level=0x117 /* SOL_??? */, cmsg_type=, 
...}, msg_flags=0}, 0) = 512
   read(4, 
"\322\322\22\25\3\3159\2052Q\356\256lA<\336\245\230a\36!\343\366\26=J\231\254\211x>G"...,
 512) = 512


However, when compiling with
   # CONFIG_MODULES is not set
   CONFIG_CRYPTO_MANAGER_DISABLE_TESTS=y
   CONFIG_CRYPTO_DEV_CCP=y
   CONFIG_CRYPTO_DEV_CCP_DD=y
   CONFIG_CRYPTO_DEV_CCP_CRYPTO=y
the strace from the same test program is
   socket(PF_ALG, SOCK_SEQPACKET, 0)   = 3
   bind(3, {sa_family=AF_ALG, sa_data="skcipher\0\0\0\0\0\0"}, 88) = 0
   setsockopt(3, 0x117 /* SOL_?? */, 1, "n) 
\21\220\25-\364\356\5\2019\336\366\20\273", 16) = 0
   accept(3, 0, NULL)  = 4
   sendmsg(4, {msg_name(0)=NULL, 
msg_iov(1)=[{"\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27\27"...,
 512}], msg_controllen=64, {cmsg_len=20, cmsg_level=0x117 /* SOL_??? */, cmsg_type=, 
...}, msg_flags=0}, 0) = 512
   read(4, 0x1f48000, 512) = -1 ENODEV (No such device)



Because ccp-crypto isn't built as a module it will register the
algorithms even if a CCP device isn't there. I'll work up a patch
that checks for the presence of the CCP and only register the
algorithms if a CCP is there.

Thanks,
Tom



cryptsetup exhibits the same behavior as the test program.


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html