CR50: Include NUL byte from label for OAEP pad calculation

If a label is specified, then the NUL terminating
character is considered part of the label per the
TPM2 implementation.

BRANCH=none
BUG=chrome-os-partner:43025,chrome-os-partner:47524
TEST=tests under test/tpm2/ pass.

Change-Id: If5fccc293f7ab52fd6c33e2f3c38695c2921d919
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/326910
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Marius Schilder <mschilder@chromium.org>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
This commit is contained in:
nagendra modadugu
2016-02-08 21:49:25 -08:00
committed by chrome-bot
parent 5dca5807bd
commit cd5745f99c

View File

@@ -91,7 +91,7 @@ static int oaep_pad(uint8_t *output, uint32_t output_len,
else
DCRYPTO_SHA256_init(&ctx, 0);
DCRYPTO_HASH_update(&ctx, label, label ? strlen(label) : 0);
DCRYPTO_HASH_update(&ctx, label, label ? strlen(label) + 1 : 0);
memcpy(phash, DCRYPTO_HASH_final(&ctx), hash_size);
*one = 1;
memcpy(one + 1, msg, msg_len);
@@ -131,7 +131,7 @@ static int check_oaep_pad(uint8_t *out, uint32_t *out_len,
DCRYPTO_SHA1_init(&ctx, 0);
else
DCRYPTO_SHA256_init(&ctx, 0);
DCRYPTO_HASH_update(&ctx, label, label ? strlen(label) : 0);
DCRYPTO_HASH_update(&ctx, label, label ? strlen(label) + 1 : 0);
bad = memcmp(phash, DCRYPTO_HASH_final(&ctx), hash_size);
bad |= padded[0];