bitcoin/bitcoin — pull request #1039 by sipa (2012-04-05 00:10:36+00:00)
Title: Fix #955: Verify status of encrypt/decrypt calls to detect failed padding

Issue #955 was discovered to be caused by users entering an *incorrect* password that accidentally (with a chance of 1/255) resulted in valid AES-CBC padding, which causes a decrypted secret of 45-47 bytes, causing a failed CKey::SetSecret call. In the normal case, a bad password causes an incorrect padding which is detected by the decrypt function. As the return code is not checked, the previously (incorrectly) decrypted 32 bytes are used anyway, leading to a succesful CKey::SetSecret call.

So in summary: we didn't know we were padding by default, and hence forgot to check for the case of a failed padding, which apparently resulted in something of the expected size.