0007-SAE-Mask-timing-of-MODP-groups-22-23-24.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From 90839597cc4016b33f00055b12d59174c62770a3 Mon Sep 17 00:00:00 2001
  2. From: Jouni Malinen <jouni@codeaurora.org>
  3. Date: Sat, 2 Mar 2019 12:24:09 +0200
  4. Subject: [PATCH 07/14] SAE: Mask timing of MODP groups 22, 23, 24
  5. These groups have significant probability of coming up with pwd-value
  6. that is equal or greater than the prime and as such, need for going
  7. through the PWE derivation loop multiple times. This can result in
  8. sufficient timing different to allow an external observer to determine
  9. how many rounds are needed and that can leak information about the used
  10. password.
  11. Force at least 40 loop rounds for these MODP groups similarly to the ECC
  12. group design to mask timing. This behavior is not described in IEEE Std
  13. 802.11-2016 for SAE, but it does not result in different values (i.e.,
  14. only different timing), so such implementation specific countermeasures
  15. can be done without breaking interoperability with other implementation.
  16. Note: These MODP groups 22, 23, and 24 are not considered sufficiently
  17. strong to be used with SAE (or more or less anything else). As such,
  18. they should never be enabled in runtime configuration for any production
  19. use cases. These changes to introduce additional protection to mask
  20. timing is only for completeness of implementation and not an indication
  21. that these groups should be used.
  22. This is related to CVE-2019-9494.
  23. Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
  24. ---
  25. src/common/sae.c | 38 ++++++++++++++++++++++++++++----------
  26. 1 file changed, 28 insertions(+), 10 deletions(-)
  27. diff --git a/src/common/sae.c b/src/common/sae.c
  28. index 5df9b95..75b1b4a 100644
  29. --- a/src/common/sae.c
  30. +++ b/src/common/sae.c
  31. @@ -601,22 +601,27 @@ fail:
  32. }
  33. +static int sae_modp_group_require_masking(int group)
  34. +{
  35. + /* Groups for which pwd-value is likely to be >= p frequently */
  36. + return group == 22 || group == 23 || group == 24;
  37. +}
  38. +
  39. +
  40. static int sae_derive_pwe_ffc(struct sae_data *sae, const u8 *addr1,
  41. const u8 *addr2, const u8 *password,
  42. size_t password_len, const char *identifier)
  43. {
  44. - u8 counter;
  45. + u8 counter, k;
  46. u8 addrs[2 * ETH_ALEN];
  47. const u8 *addr[3];
  48. size_t len[3];
  49. size_t num_elem;
  50. int found = 0;
  51. + struct crypto_bignum *pwe = NULL;
  52. - if (sae->tmp->pwe_ffc == NULL) {
  53. - sae->tmp->pwe_ffc = crypto_bignum_init();
  54. - if (sae->tmp->pwe_ffc == NULL)
  55. - return -1;
  56. - }
  57. + crypto_bignum_deinit(sae->tmp->pwe_ffc, 1);
  58. + sae->tmp->pwe_ffc = NULL;
  59. wpa_hexdump_ascii_key(MSG_DEBUG, "SAE: password",
  60. password, password_len);
  61. @@ -640,7 +645,9 @@ static int sae_derive_pwe_ffc(struct sae_data *sae, const u8 *addr1,
  62. len[num_elem] = sizeof(counter);
  63. num_elem++;
  64. - for (counter = 1; !found; counter++) {
  65. + k = sae_modp_group_require_masking(sae->group) ? 40 : 1;
  66. +
  67. + for (counter = 1; counter <= k || !found; counter++) {
  68. u8 pwd_seed[SHA256_MAC_LEN];
  69. int res;
  70. @@ -650,19 +657,30 @@ static int sae_derive_pwe_ffc(struct sae_data *sae, const u8 *addr1,
  71. break;
  72. }
  73. - wpa_printf(MSG_DEBUG, "SAE: counter = %u", counter);
  74. + wpa_printf(MSG_DEBUG, "SAE: counter = %02u", counter);
  75. if (hmac_sha256_vector(addrs, sizeof(addrs), num_elem,
  76. addr, len, pwd_seed) < 0)
  77. break;
  78. - res = sae_test_pwd_seed_ffc(sae, pwd_seed, sae->tmp->pwe_ffc);
  79. + if (!pwe) {
  80. + pwe = crypto_bignum_init();
  81. + if (!pwe)
  82. + break;
  83. + }
  84. + res = sae_test_pwd_seed_ffc(sae, pwd_seed, pwe);
  85. if (res < 0)
  86. break;
  87. if (res > 0) {
  88. - wpa_printf(MSG_DEBUG, "SAE: Use this PWE");
  89. found = 1;
  90. + if (!sae->tmp->pwe_ffc) {
  91. + wpa_printf(MSG_DEBUG, "SAE: Use this PWE");
  92. + sae->tmp->pwe_ffc = pwe;
  93. + pwe = NULL;
  94. + }
  95. }
  96. }
  97. + crypto_bignum_deinit(pwe, 1);
  98. +
  99. return found ? 0 : -1;
  100. }
  101. --
  102. 2.7.4