066-0005-EAP-pwd-Run-through-prf-result-processing-even-if-it.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 00a6cc73da61b03c146b6c341d0d1e572bcef432 Mon Sep 17 00:00:00 2001
  2. From: Jouni Malinen <[email protected]>
  3. Date: Mon, 24 Jun 2019 23:02:51 +0300
  4. Subject: [PATCH 5/6] EAP-pwd: Run through prf result processing even if it >=
  5. prime
  6. This reduces differences in timing and memory access within the
  7. hunting-and-pecking loop for ECC groups that have a prime that is not
  8. close to a power of two (e.g., Brainpool curves).
  9. Signed-off-by: Jouni Malinen <[email protected]>
  10. (cherry picked from commit cd803299ca485eb857e37c88f973fccfbb8600e5)
  11. ---
  12. src/eap_common/eap_pwd_common.c | 13 ++++++++++---
  13. 1 file changed, 10 insertions(+), 3 deletions(-)
  14. --- a/src/eap_common/eap_pwd_common.c
  15. +++ b/src/eap_common/eap_pwd_common.c
  16. @@ -155,6 +155,8 @@ int compute_password_element(EAP_PWD_gro
  17. struct crypto_bignum *x_candidate = NULL, *cofactor = NULL;
  18. const struct crypto_bignum *prime;
  19. u8 mask, found_ctr = 0, is_odd = 0;
  20. + int cmp_prime;
  21. + unsigned int in_range;
  22. if (grp->pwe)
  23. return -1;
  24. @@ -247,8 +249,13 @@ int compute_password_element(EAP_PWD_gro
  25. if (primebitlen % 8)
  26. buf_shift_right(prfbuf, primebytelen,
  27. 8 - primebitlen % 8);
  28. - if (const_time_memcmp(prfbuf, prime_bin, primebytelen) >= 0)
  29. - continue;
  30. + cmp_prime = const_time_memcmp(prfbuf, prime_bin, primebytelen);
  31. + /* Create a const_time mask for selection based on prf result
  32. + * being smaller than prime. */
  33. + in_range = const_time_fill_msb((unsigned int) cmp_prime);
  34. + /* The algorithm description would skip the next steps if
  35. + * cmp_prime >= 0, but go through them regardless to minimize
  36. + * externally observable differences in behavior. */
  37. crypto_bignum_deinit(x_candidate, 1);
  38. x_candidate = crypto_bignum_init_set(prfbuf, primebytelen);
  39. @@ -311,7 +318,7 @@ int compute_password_element(EAP_PWD_gro
  40. goto fail;
  41. mask = const_time_eq(res, check);
  42. found_ctr = const_time_select_u8(found, found_ctr, ctr);
  43. - found |= mask;
  44. + found |= mask & in_range;
  45. }
  46. if (found == 0) {
  47. wpa_printf(MSG_INFO,