Wienhold, Kathy wrote:
>
> This is a question regarding the correct ASN.1 encoding for bitstrings.
>
> #define ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
>
> This does not set the a->flags parameter as (for instance) ASN1_sign does:
>
> signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
> signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
>
> Hence, a subsequent call to i2d_ASN1_BIT_STRING to encode the bitstring can
> lose
> the last N bytes, if those bytes happen to be all zeroes.
>
> In a perfect world, shouldn't ASN1_BIT_STRING_set have a fourth parameter to
> hold
> the number-of-padding-bits value? Or am I not grokking the programming
> model here?
>
The DER encoding of a BIT STRING forbids trailing zeros, except where it
is used to wrap another structure.
When a bit string is used as it was intended, as a sequence of flags,
deleting trailing zeroes doesn't matter at all. This is now the default
behaviour.
However in a few legacy cases a BIT STRING is used to wrap another
structure and in this case trailing zeroes must be permitted or the
wrapped structure could be truncated. Examples of this are certificate
public keys and signatures.
It should be noted that several ASN1 implementations (including earlier
versions of SSLeay) do not correctly encode bit strings. Several CAs
for example include BIT STRINGs with trailing zeroes in things like the
keyUsage extension.
Steve.
--
Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED]
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]