[gnutls-devel] libtasn1 | BIT STRING input to asn1_der_coding producing incorrect result (#47)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Mon Aug 21 16:51:09 CEST 2023



marquitos0119 created an issue: https://gitlab.com/gnutls/libtasn1/-/issues/47



## Description of problem: BIT STRING encoding producing incorrect result

## Version of libtasn1 used: 4.19.0.12-3f7a

## Distributor of libtasn1 (e.g., Ubuntu, Fedora, RHEL) - built from source

## How reproducible:

Steps to Reproduce:

* Using the asn1Coding executable which makes calls to asn1_der_coding, I attempt to encode a single element SEQUENCE with a BIT STRING element.
* definition file:

  ```plaintext
  MYEXAMPLE { }
  
  DEFINITIONS IMPLICIT TAGS ::=
  
  BEGIN
  
  mySeq ::= SEQUENCE {
  	myBit BIT STRING
  }
  
  END
  ```
* assignment file:

  ```plaintext
  dp MYEXAMPLE.mySeq
  
  myBit abc123
  ```

## Actual results:

```plaintext
30 04 03 02 02 60
```

When I set the input characters to multiples of 8, it will encode the first char in the set per 8 input chars. e.g. if the input for myBit is `a1234567`, the output encode `a` as the bit string:

```plaintext
30 04 03 02 00 61
```

where 61 is the ascii encoding of `a`. However, less than 8 characters (like the above example `abc123`) ends up with different results.

## Expected results:

```plaintext
30 09 03 07 00 61 62 63 31 32 33
```

I expected the same results as with an OCTET STRING, with the additional "unused bits" prefix byte. OCTET STRING encoding is below:

```plaintext
30 08 04 06 61 62 63 31 32 33
```

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/libtasn1/-/issues/47
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20230821/29b54cd4/attachment-0001.html>


More information about the Gnutls-devel mailing list