Skip to content

Commit 95ec01b

Browse files
jejbherbertx
authored andcommitted
crypto: ecdh - fix to allow multi segment scatterlists
Apparently the ecdh use case was in bluetooth which always has single element scatterlists, so the ecdh module was hard coded to expect them. Now we're using this in TPM, we need multi-element scatterlists, so remove this limitation. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a7d85e0 commit 95ec01b

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎crypto/ecdh.c‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ static int ecdh_compute_value(struct kpp_request *req)
8989
if (!shared_secret)
9090
goto free_pubkey;
9191

92-
copied = sg_copy_to_buffer(req->src, 1, public_key,
93-
public_key_sz);
94-
if (copied != public_key_sz) {
95-
ret = -EINVAL;
92+
/* from here on it's invalid parameters */
93+
ret = -EINVAL;
94+
95+
/* must have exactly two points to be on the curve */
96+
if (public_key_sz != req->src_len)
97+
goto free_all;
98+
99+
copied = sg_copy_to_buffer(req->src,
100+
sg_nents_for_len(req->src,
101+
public_key_sz),
102+
public_key, public_key_sz);
103+
if (copied != public_key_sz)
96104
goto free_all;
97-
}
98105

99106
ret = crypto_ecdh_shared_secret(ctx->curve_id, ctx->ndigits,
100107
ctx->private_key, public_key,
@@ -111,7 +118,11 @@ static int ecdh_compute_value(struct kpp_request *req)
111118
if (ret < 0)
112119
goto free_all;
113120

114-
copied = sg_copy_from_buffer(req->dst, 1, buf, nbytes);
121+
/* might want less than we've got */
122+
nbytes = min_t(size_t, nbytes, req->dst_len);
123+
copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst,
124+
nbytes),
125+
buf, nbytes);
115126
if (copied != nbytes)
116127
ret = -EINVAL;
117128

0 commit comments

Comments
 (0)