History log of /openbsd-current/lib/libssl/bs_cbs.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.25 25-May-2024 tb

sync inclusion of <stdlib.h> from libcrypto


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.24 15-Dec-2021 jsing

Provide various CBS_peek_* functions.

These will be used in libcrypto.

With input from and ok tb@


# 1.23 15-Dec-2021 jsing

Provide CBS_get_u64().

This will be used in the libcrypto certificate transparency code.

ok tb@


# 1.22 15-Dec-2021 jsing

Provide CBS_get_last_u8().

This will be used in the TLSv1.3 record layer.

From BoringSSL.

ok tb@


# 1.21 31-Oct-2021 jsing

Add explicit CBS_contains_zero_byte() check in CBS_strdup().

If the CBS data contains a zero byte, then CBS_strdup() is only going to
return part of the data - add an explicit CBS_contains_zero_byte() and
treat such data as an error case.

ok tb@


Revision tags: OPENBSD_7_0_BASE
# 1.20 16-May-2021 jsing

Fix formatting of multi-line license comment per style(9).


# 1.19 16-May-2021 jsing

Remove unnecessary includes from the bytestring APIs.

The bytestring APIs are self contained, hence including openssl headers
here is unnecessary.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


# 1.24 15-Dec-2021 jsing

Provide various CBS_peek_* functions.

These will be used in libcrypto.

With input from and ok tb@


# 1.23 15-Dec-2021 jsing

Provide CBS_get_u64().

This will be used in the libcrypto certificate transparency code.

ok tb@


# 1.22 15-Dec-2021 jsing

Provide CBS_get_last_u8().

This will be used in the TLSv1.3 record layer.

From BoringSSL.

ok tb@


# 1.21 31-Oct-2021 jsing

Add explicit CBS_contains_zero_byte() check in CBS_strdup().

If the CBS data contains a zero byte, then CBS_strdup() is only going to
return part of the data - add an explicit CBS_contains_zero_byte() and
treat such data as an error case.

ok tb@


Revision tags: OPENBSD_7_0_BASE
# 1.20 16-May-2021 jsing

Fix formatting of multi-line license comment per style(9).


# 1.19 16-May-2021 jsing

Remove unnecessary includes from the bytestring APIs.

The bytestring APIs are self contained, hence including openssl headers
here is unnecessary.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


# 1.21 31-Oct-2021 jsing

Add explicit CBS_contains_zero_byte() check in CBS_strdup().

If the CBS data contains a zero byte, then CBS_strdup() is only going to
return part of the data - add an explicit CBS_contains_zero_byte() and
treat such data as an error case.

ok tb@


Revision tags: OPENBSD_7_0_BASE
# 1.20 16-May-2021 jsing

Fix formatting of multi-line license comment per style(9).


# 1.19 16-May-2021 jsing

Remove unnecessary includes from the bytestring APIs.

The bytestring APIs are self contained, hence including openssl headers
here is unnecessary.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


# 1.20 16-May-2021 jsing

Fix formatting of multi-line license comment per style(9).


# 1.19 16-May-2021 jsing

Remove unnecessary includes from the bytestring APIs.

The bytestring APIs are self contained, hence including openssl headers
here is unnecessary.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


# 1.20 16-May-2021 jsing

Fix formatting of multi-line license comment per style(9).


# 1.19 16-May-2021 jsing

Remove unnecessary includes from the bytestring APIs.

The bytestring APIs are self contained, hence including openssl headers
here is unnecessary.


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


# 1.18 23-Jan-2019 beck

assert.h is often misused. It should not be used in a library
ok bcook@ jsing@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.17 24-Jun-2015 jsing

Stop using BUF_memdup() within the LibreSSL code base - it is correctly
spelt malloc+memcpy, which is what is used in all except two places.

ok deraadt@ doug@


# 1.16 23-Jun-2015 doug

Change CBS_dup() to also sync the offset.

Previously, CBS_dup() had its own offset. However, it is more consistent
to copy everything.

ok miod@ jsing@


# 1.15 20-Jun-2015 doug

Replace internal call to CRYPTO_memcmp with timingsafe_memcmp.

Suggested by jsing@.

ok jsing@ miod@


# 1.14 19-Jun-2015 doug

Add CBS_dup() to initialize a new CBS with the same values.

This is useful for when you need to check the data ahead and then continue
on from the same spot.

input + ok jsing@ miod@


# 1.13 17-Jun-2015 doug

Use explicit int in bs_cbs.c.

ok miod@ jsing@


# 1.12 17-Jun-2015 doug

Add CBS_write_bytes() to copy the remaining CBS bytes to the caller.

This is a common operation when dealing with CBS.

ok miod@ jsing@


# 1.11 17-Jun-2015 doug

Add a new function CBS_offset() to report the current offset in the data.

"why not" miod@, sure jsing@


# 1.10 16-Jun-2015 doug

Simplify cbs_get_any_asn1_element_internal based on comments from jsing@


# 1.9 15-Jun-2015 doug

Make CBS_get_any_asn1_element() more compliant with DER encoding.

CBS_get_any_asn1_element violates DER encoding by allowing indefinite
form. All callers except bs_ber.c expect DER encoding. The callers
must check to see if it was indefinite or not.

Rather than exposing all callers to this behavior,
cbs_get_any_asn1_element_internal() allows specifying whether you want to
allow the normally forbidden indefinite form. This is used by
CBS_get_any_asn1_element() for strict DER encoding and by a new static
function in bs_ber.c for the relaxed version.

While I was here, I added comments to differentiate between ASN.1
restrictions and CBS limitations.

ok miod@


# 1.8 13-Jun-2015 doug

Reject long-form tags in CBS_peek_asn1_tag.

Currently, CBS only handles short-form tags.

ok miod@ jsing@


# 1.7 29-Apr-2015 doug

Add whitespace and replace OPENSSL_free with free in documentation.

ok jsing@


# 1.6 29-Apr-2015 doug

Avoid NULL deref in CBS_get_any_asn1_element().

This function is documented as allowing NULL for out_header_len.

ok jsing@


# 1.5 29-Apr-2015 doug

Added error checking for len argument in cbs_get_u().

tweak + ok jsing@


# 1.4 29-Apr-2015 doug

free() can handle NULL.

ok jsing@


# 1.3 25-Apr-2015 doug

Check for invalid leading zeros in CBS_get_asn1_uint64.

ASN.1 integers cannot have all zeros or all ones for the first 9 bits.
This rule ensures the numbers are encoded with the smallest number of
content octets (see ITU-T Rec X.690 section 8.3.2).

Based on BoringSSL commit 5933723b7b592e9914f703d630b596e140c93e16

ok deraadt@ jsing@


# 1.2 06-Feb-2015 doug

KNF bytestring files.

I checked that this doesn't change anything. Compiled with clang using
-Wno-pointer-sign -g0 to reduce the differences. Only difference in the
asm is due to assert(0) line number changes in bs_cbs.c and bs_cbb.c.

miod is ok with the general process.


# 1.1 06-Feb-2015 doug

Import BoringSSL's crypto bytestring and crypto bytebuilder APIs.

This is imported with as few changes as possible for the initial commit.
I removed OPENSSL_EXPORT, replaced OPENSSL_malloc() etc with malloc()
and changed a few header includes.

BoringSSL has this as part of their public API. We're leaving it internal
to libssl for now.

Based on BoringSSL's CBB/CBS API as of commit
c5cc15b4f5b1d6e9b9112cb8d30205a638aa2c54.

input + ok jsing@, miod@