summaryrefslogtreecommitdiff
path: root/src/crypto/bytestring/cbs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/bytestring/cbs.c')
-rw-r--r--src/crypto/bytestring/cbs.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/crypto/bytestring/cbs.c b/src/crypto/bytestring/cbs.c
index 8328b7fe..ec495d21 100644
--- a/src/crypto/bytestring/cbs.c
+++ b/src/crypto/bytestring/cbs.c
@@ -190,13 +190,13 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
return 0;
}
- /* ITU-T X.690 section 8.1.2.3 specifies the format for identifiers with a tag
- * number no greater than 30.
- *
- * If the number portion is 31 (0x1f, the largest value that fits in the
- * allotted bits), then the tag is more than one byte long and the
- * continuation bytes contain the tag number. This parser only supports tag
- * numbers less than 31 (and thus single-byte tags). */
+ // ITU-T X.690 section 8.1.2.3 specifies the format for identifiers with a tag
+ // number no greater than 30.
+ //
+ // If the number portion is 31 (0x1f, the largest value that fits in the
+ // allotted bits), then the tag is more than one byte long and the
+ // continuation bytes contain the tag number. This parser only supports tag
+ // numbers less than 31 (and thus single-byte tags).
if ((tag & 0x1f) == 0x1f) {
return 0;
}
@@ -206,52 +206,51 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
}
size_t len;
- /* The format for the length encoding is specified in ITU-T X.690 section
- * 8.1.3. */
+ // The format for the length encoding is specified in ITU-T X.690 section
+ // 8.1.3.
if ((length_byte & 0x80) == 0) {
- /* Short form length. */
+ // Short form length.
len = ((size_t) length_byte) + 2;
if (out_header_len != NULL) {
*out_header_len = 2;
}
} else {
- /* The high bit indicate that this is the long form, while the next 7 bits
- * encode the number of subsequent octets used to encode the length (ITU-T
- * X.690 clause 8.1.3.5.b). */
+ // The high bit indicate that this is the long form, while the next 7 bits
+ // encode the number of subsequent octets used to encode the length (ITU-T
+ // X.690 clause 8.1.3.5.b).
const size_t num_bytes = length_byte & 0x7f;
uint32_t len32;
if (ber_ok && (tag & CBS_ASN1_CONSTRUCTED) != 0 && num_bytes == 0) {
- /* indefinite length */
+ // indefinite length
if (out_header_len != NULL) {
*out_header_len = 2;
}
return CBS_get_bytes(cbs, out, 2);
}
- /* ITU-T X.690 clause 8.1.3.5.c specifies that the value 0xff shall not be
- * used as the first byte of the length. If this parser encounters that
- * value, num_bytes will be parsed as 127, which will fail the check below.
- */
+ // ITU-T X.690 clause 8.1.3.5.c specifies that the value 0xff shall not be
+ // used as the first byte of the length. If this parser encounters that
+ // value, num_bytes will be parsed as 127, which will fail the check below.
if (num_bytes == 0 || num_bytes > 4) {
return 0;
}
if (!cbs_get_u(&header, &len32, num_bytes)) {
return 0;
}
- /* ITU-T X.690 section 10.1 (DER length forms) requires encoding the length
- * with the minimum number of octets. */
+ // ITU-T X.690 section 10.1 (DER length forms) requires encoding the length
+ // with the minimum number of octets.
if (len32 < 128) {
- /* Length should have used short-form encoding. */
+ // Length should have used short-form encoding.
return 0;
}
if ((len32 >> ((num_bytes-1)*8)) == 0) {
- /* Length should have been at least one byte shorter. */
+ // Length should have been at least one byte shorter.
return 0;
}
len = len32;
if (len + 2 + num_bytes < len) {
- /* Overflow. */
+ // Overflow.
return 0;
}
len += 2 + num_bytes;
@@ -338,23 +337,23 @@ int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out) {
size_t len = CBS_len(&bytes);
if (len == 0) {
- /* An INTEGER is encoded with at least one octet. */
+ // An INTEGER is encoded with at least one octet.
return 0;
}
if ((data[0] & 0x80) != 0) {
- /* Negative number. */
+ // Negative number.
return 0;
}
if (data[0] == 0 && len > 1 && (data[1] & 0x80) == 0) {
- /* Extra leading zeros. */
+ // Extra leading zeros.
return 0;
}
for (size_t i = 0; i < len; i++) {
if ((*out >> 56) != 0) {
- /* Too large to represent as a uint64_t. */
+ // Too large to represent as a uint64_t.
return 0;
}
*out <<= 8;
@@ -462,7 +461,7 @@ int CBS_is_valid_asn1_bitstring(const CBS *cbs) {
return 1;
}
- /* All num_unused_bits bits must exist and be zeros. */
+ // All num_unused_bits bits must exist and be zeros.
uint8_t last;
if (!CBS_get_last_u8(&in, &last) ||
(last & ((1 << num_unused_bits) - 1)) != 0) {
@@ -480,9 +479,9 @@ int CBS_asn1_bitstring_has_bit(const CBS *cbs, unsigned bit) {
const unsigned byte_num = (bit >> 3) + 1;
const unsigned bit_num = 7 - (bit & 7);
- /* Unused bits are zero, and this function does not distinguish between
- * missing and unset bits. Thus it is sufficient to do a byte-level length
- * check. */
+ // Unused bits are zero, and this function does not distinguish between
+ // missing and unset bits. Thus it is sufficient to do a byte-level length
+ // check.
return byte_num < CBS_len(cbs) &&
(CBS_data(cbs)[byte_num] & (1 << bit_num)) != 0;
}