From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko =?ISO-8859-1?Q?St=FCbner?= Date: Mon, 25 May 2020 19:18:08 +0200 Subject: [PATCH v5 4/8] lib: rsa: fix allocated size for rr and rrtmp in rsa_gen_key_prop() In-Reply-To: <20200522141937.3523692-4-heiko@sntech.de> References: <20200522141937.3523692-1-heiko@sntech.de> <20200522141937.3523692-4-heiko@sntech.de> Message-ID: <14768968.1T0FKZa6J5@diego> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Am Freitag, 22. Mai 2020, 16:19:33 CEST schrieb Heiko Stuebner: > From: Heiko Stuebner > > When calculating rrtmp/rr rsa_gen_key_prop() tries to make > (((rlen + 31) >> 5) + 1) steps in the rr uint32_t array and > (((rlen + 7) >> 3) + 1) / 4 steps in uint32_t rrtmp[] > with rlen being num_bits * 2 > > On a 4096bit key this comes down to to 257 uint32_t elements > in rr and 256 elements in rrtmp but with the current allocation > rr and rrtmp only have 129 uint32_t elements. > > On 2048bit keys this works by chance as the defined max_rsa_size=4096 > allocates a suitable number of elements, but with an actual 4096bit key > this results in other memory parts getting overwritten. > > so double the number of elements in rr and rrtmp so that it matches > the needed number and should increase nicely if max_rsa_size gets > increased in the future. > > Signed-off-by: Heiko Stuebner transplanting a tag from v4: Reviewed-by: Simon Glass