History

crypto: dh - allow for passing NULL to the ffdheXYZ(dh)s' ->set_secret()

Ephemeral key generation can be requested from any of the ffdheXYZ(dh) variants' common ->set_secret() by passing it an (encoded) struct dh with the key parameter being unset, i.e. with ->key_size == 0. As the whole purpose of the ffdheXYZ(dh) templates is to fill in the group parameters as appropriate, they expect ->p and ->g to be unset in any input struct dh as well. This means that a user would have to encode an all-zeroes struct dh instance via crypto_dh_encode_key() when requesting ephemeral key generation from a ffdheXYZ(dh) instance, which is kind of pointless. Make dh_safe_prime_set_secret() to decode a struct dh from the supplied buffer only if the latter is non-NULL and initialize it with all zeroes otherwise. That is, it is now possible to call crypto_kpp_set_secret(tfm, NULL, 0); on any ffdheXYZ(dh) tfm for requesting ephemeral key generation.

Nicolai Stange committed 4 years ago

Commit c8e82361 parent 209b7fc1 file · +8 −7Browse files

Unified · Split

crypto/dh.c+8−7
@@ -444,17 +444,18 @@ static int dh_safe_prime_set_secret(struct crypto_kpp *tfm, const void *buffer, · 443 unmodified lines
444 struct dh_safe_prime_instance_ctx *inst_ctx =444 struct dh_safe_prime_instance_ctx *inst_ctx =
445 dh_safe_prime_instance_ctx(tfm);445 dh_safe_prime_instance_ctx(tfm);
446 struct dh_safe_prime_tfm_ctx *tfm_ctx = kpp_tfm_ctx(tfm);446 struct dh_safe_prime_tfm_ctx *tfm_ctx = kpp_tfm_ctx(tfm);
447 struct dh params;447 struct dh params = {};
448 void *buf = NULL, *key = NULL;448 void *buf = NULL, *key = NULL;
449 unsigned int buf_size;449 unsigned int buf_size;
450 int err;450 int err;
451 451
452 err = __crypto_dh_decode_key(buffer, len, &params);452 if (buffer) {
453 if (err)453 err = __crypto_dh_decode_key(buffer, len, &params);
454 return err;454 if (err)
455 455 return err;
456 if (params.p_size || params.g_size)456 if (params.p_size || params.g_size)
457 return -EINVAL;457 return -EINVAL;
458 }
458 459
459 params.p = inst_ctx->safe_prime->p;460 params.p = inst_ctx->safe_prime->p;
460 params.p_size = inst_ctx->safe_prime->p_size;461 params.p_size = inst_ctx->safe_prime->p_size;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t