Skip to content

Commit a56973a

Browse files
committed
Merge remote-tracking branch 'remotes/origin/at91-4.14-trunk/base_crypto' into linux-4.14-at91
2 parents 7cd21a0 + ee8ac71 commit a56973a

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

Documentation/crypto/api-samples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Code Example For Use of Operational State Memory With SHASH
194194
char *hash_alg_name = "sha1-padlock-nano";
195195
int ret;
196196

197-
alg = crypto_alloc_shash(hash_alg_name, CRYPTO_ALG_TYPE_SHASH, 0);
197+
alg = crypto_alloc_shash(hash_alg_name, 0, 0);
198198
if (IS_ERR(alg)) {
199199
pr_info("can't alloc alg %s\n", hash_alg_name);
200200
return PTR_ERR(alg);

drivers/crypto/atmel-ecc.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ static int atmel_ecc_init_ecdh_cmd(struct atmel_ecc_cmd *cmd,
186186
* always be the same. Use a macro for the key size to avoid unnecessary
187187
* computations.
188188
*/
189-
copied = sg_copy_to_buffer(pubkey, 1, cmd->data, ATMEL_ECC_PUBKEY_SIZE);
189+
copied = sg_copy_to_buffer(pubkey,
190+
sg_nents_for_len(pubkey,
191+
ATMEL_ECC_PUBKEY_SIZE),
192+
cmd->data, ATMEL_ECC_PUBKEY_SIZE);
190193
if (copied != ATMEL_ECC_PUBKEY_SIZE)
191194
return -EINVAL;
192195

@@ -268,15 +271,17 @@ static void atmel_ecdh_done(struct atmel_ecc_work_data *work_data, void *areq,
268271
struct kpp_request *req = areq;
269272
struct atmel_ecdh_ctx *ctx = work_data->ctx;
270273
struct atmel_ecc_cmd *cmd = &work_data->cmd;
271-
size_t copied;
272-
size_t n_sz = ctx->n_sz;
274+
size_t copied, n_sz;
273275

274276
if (status)
275277
goto free_work_data;
276278

279+
/* might want less than we've got */
280+
n_sz = min_t(size_t, ctx->n_sz, req->dst_len);
281+
277282
/* copy the shared secret */
278-
copied = sg_copy_from_buffer(req->dst, 1, &cmd->data[RSP_DATA_IDX],
279-
n_sz);
283+
copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst, n_sz),
284+
&cmd->data[RSP_DATA_IDX], n_sz);
280285
if (copied != n_sz)
281286
status = -EINVAL;
282287

@@ -440,18 +445,22 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)
440445
{
441446
struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
442447
struct atmel_ecdh_ctx *ctx = kpp_tfm_ctx(tfm);
443-
size_t copied;
448+
size_t copied, nbytes;
444449
int ret = 0;
445450

446451
if (ctx->do_fallback) {
447452
kpp_request_set_tfm(req, ctx->fallback);
448453
return crypto_kpp_generate_public_key(req);
449454
}
450455

456+
/* might want less than we've got */
457+
nbytes = min_t(size_t, ATMEL_ECC_PUBKEY_SIZE, req->dst_len);
458+
451459
/* public key was saved at private key generation */
452-
copied = sg_copy_from_buffer(req->dst, 1, ctx->public_key,
453-
ATMEL_ECC_PUBKEY_SIZE);
454-
if (copied != ATMEL_ECC_PUBKEY_SIZE)
460+
copied = sg_copy_from_buffer(req->dst,
461+
sg_nents_for_len(req->dst, nbytes),
462+
ctx->public_key, nbytes);
463+
if (copied != nbytes)
455464
ret = -EINVAL;
456465

457466
return ret;
@@ -470,6 +479,10 @@ static int atmel_ecdh_compute_shared_secret(struct kpp_request *req)
470479
return crypto_kpp_compute_shared_secret(req);
471480
}
472481

482+
/* must have exactly two points to be on the curve */
483+
if (req->src_len != ATMEL_ECC_PUBKEY_SIZE)
484+
return -EINVAL;
485+
473486
gfp = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL :
474487
GFP_ATOMIC;
475488

@@ -554,10 +567,6 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm)
554567
}
555568

556569
crypto_kpp_set_flags(fallback, crypto_kpp_get_flags(tfm));
557-
558-
dev_info(&ctx->client->dev, "Using '%s' as fallback implementation.\n",
559-
crypto_tfm_alg_driver_name(crypto_kpp_tfm(fallback)));
560-
561570
ctx->fallback = fallback;
562571

563572
return 0;

drivers/crypto/atmel-sha.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,9 +2316,7 @@ struct atmel_sha_authenc_ctx *atmel_sha_authenc_spawn(unsigned long mode)
23162316
goto error;
23172317
}
23182318

2319-
tfm = crypto_alloc_ahash(name,
2320-
CRYPTO_ALG_TYPE_AHASH,
2321-
CRYPTO_ALG_TYPE_AHASH_MASK);
2319+
tfm = crypto_alloc_ahash(name, 0, 0);
23222320
if (IS_ERR(tfm)) {
23232321
err = PTR_ERR(tfm);
23242322
goto error;

drivers/crypto/inside-secure/safexcel_hash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,7 @@ static int safexcel_hmac_setkey(const char *alg, const u8 *key,
887887
u8 *ipad, *opad;
888888
int ret;
889889

890-
tfm = crypto_alloc_ahash(alg, CRYPTO_ALG_TYPE_AHASH,
891-
CRYPTO_ALG_TYPE_AHASH_MASK);
890+
tfm = crypto_alloc_ahash(alg, 0, 0);
892891
if (IS_ERR(tfm))
893892
return PTR_ERR(tfm);
894893

drivers/crypto/marvell/hash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,7 @@ static int mv_cesa_ahmac_setkey(const char *hash_alg_name,
11831183
u8 *opad;
11841184
int ret;
11851185

1186-
tfm = crypto_alloc_ahash(hash_alg_name, CRYPTO_ALG_TYPE_AHASH,
1187-
CRYPTO_ALG_TYPE_AHASH_MASK);
1186+
tfm = crypto_alloc_ahash(hash_alg_name, 0, 0);
11881187
if (IS_ERR(tfm))
11891188
return PTR_ERR(tfm);
11901189

drivers/crypto/qce/sha.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ static int qce_ahash_hmac_setkey(struct crypto_ahash *tfm, const u8 *key,
394394
else
395395
return -EINVAL;
396396

397-
ahash_tfm = crypto_alloc_ahash(alg_name, CRYPTO_ALG_TYPE_AHASH,
398-
CRYPTO_ALG_TYPE_AHASH_MASK);
397+
ahash_tfm = crypto_alloc_ahash(alg_name, 0, 0);
399398
if (IS_ERR(ahash_tfm))
400399
return PTR_ERR(ahash_tfm);
401400

security/keys/dh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ long __keyctl_dh_compute(struct keyctl_dh_params __user *params,
324324
if (ret)
325325
goto out3;
326326

327-
tfm = crypto_alloc_kpp("dh", CRYPTO_ALG_TYPE_KPP, 0);
327+
tfm = crypto_alloc_kpp("dh", 0, 0);
328328
if (IS_ERR(tfm)) {
329329
ret = PTR_ERR(tfm);
330330
goto out3;

0 commit comments

Comments
 (0)