From 3f493770d4cdf2fa33ac659fe180bb955fe10efe Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 20 Sep 2017 15:00:24 -0700 Subject: [PATCH] Fixes bug with creation of the KeyUsage BitString which was always adding the optional second byte reguardless of len, which created invalid ASN if value provided was less than 256. Bug was introduced with ASN refactor in commit fd9e41dd993bf31207868dc63a49c2e8b5a3e102. --- wolfcrypt/src/asn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index d4b108461..3c4e5dcb1 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1060,7 +1060,8 @@ static word32 SetBitString16Bit(word16 val, byte* output) idx = SetBitString(len, unusedBits, output); output[idx++] = (byte)val; - output[idx++] = (byte)(val >> 8); + if (len > 1) + output[idx++] = (byte)(val >> 8); return idx; }