diff options
Diffstat (limited to 'src/lib/libssl/bs_cbb.c')
| -rw-r--r-- | src/lib/libssl/bs_cbb.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c index eed8091698..5546fac97f 100644 --- a/src/lib/libssl/bs_cbb.c +++ b/src/lib/libssl/bs_cbb.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bs_cbb.c,v 1.4 2015/02/07 04:37:35 doug Exp $ */ | 1 | /* $OpenBSD: bs_cbb.c,v 1.5 2015/02/07 06:10:32 doug Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014, Google Inc. | 3 | * Copyright (c) 2014, Google Inc. |
| 4 | * | 4 | * |
| @@ -28,9 +28,8 @@ cbb_init(CBB *cbb, uint8_t *buf, size_t cap) | |||
| 28 | struct cbb_buffer_st *base; | 28 | struct cbb_buffer_st *base; |
| 29 | 29 | ||
| 30 | base = malloc(sizeof(struct cbb_buffer_st)); | 30 | base = malloc(sizeof(struct cbb_buffer_st)); |
| 31 | if (base == NULL) { | 31 | if (base == NULL) |
| 32 | return 0; | 32 | return 0; |
| 33 | } | ||
| 34 | 33 | ||
| 35 | base->buf = buf; | 34 | base->buf = buf; |
| 36 | base->len = 0; | 35 | base->len = 0; |
| @@ -148,7 +147,10 @@ CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) | |||
| 148 | return 0; | 147 | return 0; |
| 149 | 148 | ||
| 150 | if (cbb->base->can_resize && (out_data == NULL || out_len == NULL)) | 149 | if (cbb->base->can_resize && (out_data == NULL || out_len == NULL)) |
| 151 | /* |out_data| and |out_len| can only be NULL if the CBB is fixed. */ | 150 | /* |
| 151 | * |out_data| and |out_len| can only be NULL if the CBB is | ||
| 152 | * fixed. | ||
| 153 | */ | ||
| 152 | return 0; | 154 | return 0; |
| 153 | 155 | ||
| 154 | if (out_data != NULL) | 156 | if (out_data != NULL) |
| @@ -187,9 +189,11 @@ CBB_flush(CBB *cbb) | |||
| 187 | len = cbb->base->len - child_start; | 189 | len = cbb->base->len - child_start; |
| 188 | 190 | ||
| 189 | if (cbb->pending_is_asn1) { | 191 | if (cbb->pending_is_asn1) { |
| 190 | /* For ASN.1 we assume that we'll only need a single byte for the length. | 192 | /* |
| 191 | * If that turned out to be incorrect, we have to move the contents along | 193 | * For ASN.1 we assume that we'll only need a single byte for |
| 192 | * in order to make space. */ | 194 | * the length. If that turned out to be incorrect, we have to |
| 195 | * move the contents along in order to make space. | ||
| 196 | */ | ||
| 193 | size_t len_len; | 197 | size_t len_len; |
| 194 | uint8_t initial_length_byte; | 198 | uint8_t initial_length_byte; |
| 195 | 199 | ||
| @@ -217,7 +221,10 @@ CBB_flush(CBB *cbb) | |||
| 217 | } | 221 | } |
| 218 | 222 | ||
| 219 | if (len_len != 1) { | 223 | if (len_len != 1) { |
| 220 | /* We need to move the contents along in order to make space. */ | 224 | /* |
| 225 | * We need to move the contents along in order to make | ||
| 226 | * space. | ||
| 227 | */ | ||
| 221 | size_t extra_bytes = len_len - 1; | 228 | size_t extra_bytes = len_len - 1; |
| 222 | if (!cbb_buffer_add(cbb->base, NULL, extra_bytes)) | 229 | if (!cbb_buffer_add(cbb->base, NULL, extra_bytes)) |
| 223 | return 0; | 230 | return 0; |
| @@ -289,6 +296,10 @@ CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents) | |||
| 289 | int | 296 | int |
| 290 | CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag) | 297 | CBB_add_asn1(CBB *cbb, CBB *out_contents, uint8_t tag) |
| 291 | { | 298 | { |
| 299 | /* Long form identifier octets are not supported. */ | ||
| 300 | if ((tag & 0x1f) == 0x1f) | ||
| 301 | return 0; | ||
| 302 | |||
| 292 | if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag)) | 303 | if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag)) |
| 293 | return 0; | 304 | return 0; |
| 294 | 305 | ||
| @@ -370,8 +381,10 @@ CBB_add_asn1_uint64(CBB *cbb, uint64_t value) | |||
| 370 | /* Don't encode leading zeros. */ | 381 | /* Don't encode leading zeros. */ |
| 371 | continue; | 382 | continue; |
| 372 | 383 | ||
| 373 | /* If the high bit is set, add a padding byte to make it | 384 | /* |
| 374 | * unsigned. */ | 385 | * If the high bit is set, add a padding byte to make it |
| 386 | * unsigned. | ||
| 387 | */ | ||
| 375 | if ((byte & 0x80) && !CBB_add_u8(&child, 0)) | 388 | if ((byte & 0x80) && !CBB_add_u8(&child, 0)) |
| 376 | return 0; | 389 | return 0; |
| 377 | 390 | ||
