boringssl/ssl
David Benjamin a01deee96b Make CBB_len relative to its argument.
Rather than the length of the top-level CBB, which is kind of odd when ASN.1
length prefixes are not yet determined, return the number of bytes written to
the CBB so far. This can be computed without increasing the size of CBB at all.
Have offset and pending_*.

This means functions which take in a CBB as argument will not be sensitive to
whether the CBB is a top-level or child CBB. The extensions logic had to be
careful to only ever compare differences of lengths, which was awkward.

The reversal will also allow for the following pattern in the future, once
CBB_add_space is split into, say, CBB_reserve and CBB_did_write and we add a
CBB_data:

  uint8_t *signature;
  size_t signature_len = 0;
  if (!CBB_add_asn1(out, &cert, CBB_ASN1_SEQUENCE) ||
      /* Emit the TBSCertificate. */
      !CBB_add_asn1(&cert, &tbs_cert, CBS_ASN1_SEQUENCE) ||
      !CBB_add_tbs_cert_stuff(&tbs_cert, stuff) ||
      !CBB_flush(&cert) ||
      /* Feed it into md_ctx. */
      !EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
      !EVP_DigestSignUpdate(&md_ctx, CBB_data(&cert), CBB_len(&cert)) ||
      /* Emit the signature algorithm. */
      !CBB_add_asn1(&cert, &sig_alg, CBS_ASN1_SEQUENCE) ||
      !CBB_add_sigalg_stuff(&sig_alg, other_stuff) ||
      /* Emit the signature. */
      !EVP_DigestSignFinal(&md_ctx, NULL, &signature_len) ||
      !CBB_reserve(&cert, &signature, signature_len) ||
      !EVP_DigestSignFinal(&md_ctx, signature, &signature_len) ||
      !CBB_did_write(&cert, signature_len)) {
    goto err;
  }

(Were TBSCertificate not the first field, we'd still have to sample
CBB_len(&cert), but at least that's reasonable straight-forward. The
alternative would be if CBB_data and CBB_len somehow worked on
recently-invalidated CBBs, but that would go wrong once the invalidated CBB's
parent flushed and possibly shifts everything.)

And similar for signing ServerKeyExchange.

Change-Id: I7761e492ae472d7632875b5666b6088970261b14
Reviewed-on: https://boringssl-review.googlesource.com/6681
Reviewed-by: Adam Langley <agl@google.com>
2015-12-16 21:16:12 +00:00
..
pqueue Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
test Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
CMakeLists.txt Fix shared library build on OS X. 2015-10-26 23:39:47 +00:00
custom_extensions.c
d1_both.c Rewrite DTLS handshake message sending logic. 2015-11-06 21:43:32 +00:00
d1_clnt.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
d1_lib.c Separate CCS and handshake writing in DTLS. 2015-11-04 00:11:14 +00:00
d1_meth.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
d1_pkt.c Slightly simplify SSL3_RECORD. 2015-12-16 18:41:59 +00:00
d1_srtp.c Add defines for SRTP profiles using GCM ciphers from RFC 7714. 2015-12-10 23:18:16 +00:00
d1_srvr.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
dtls_record.c
internal.h Remove a dead prototype. 2015-12-16 20:03:53 +00:00
s3_both.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
s3_clnt.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
s3_enc.c
s3_lib.c Make SSL_(CTX_)?set_tmp_ecdh call SSL_(CTX_)?set1_curves. 2015-12-15 20:28:47 +00:00
s3_meth.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
s3_pkt.c Slightly simplify SSL3_RECORD. 2015-12-16 18:41:59 +00:00
s3_srvr.c Pull ChangeCipherSpec into the handshake state machine. 2015-12-16 18:36:57 +00:00
ssl_aead_ctx.c Revert most of "Refactor ChaCha20-Poly1305 AEAD nonce handling." 2015-10-29 18:40:33 +00:00
ssl_asn1.c Check for overflow when parsing a CBS with d2i_*. 2015-11-16 23:17:42 +00:00
ssl_buffer.c Remove SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER. 2015-12-15 19:14:00 +00:00
ssl_cert.c Make SSL_(CTX_)?set_tmp_ecdh call SSL_(CTX_)?set1_curves. 2015-12-15 20:28:47 +00:00
ssl_cipher.c Reformat the cipher suite table. 2015-11-19 01:32:55 +00:00
ssl_file.c More SSL_SESSION serialization functions. 2015-10-26 17:57:50 +00:00
ssl_lib.c Remove unused functions. 2015-12-15 21:32:44 +00:00
ssl_rsa.c Add get0 getters for EVP_PKEY. 2015-11-20 23:34:12 +00:00
ssl_session.c Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
ssl_stat.c
ssl_test.cc Remove algo_strength. 2015-11-19 01:30:44 +00:00
t1_enc.c *_Update of length zero is legal. 2015-12-16 19:46:57 +00:00
t1_lib.c Make CBB_len relative to its argument. 2015-12-16 21:16:12 +00:00
tls_record.c Remove |need_record_splitting| from |SSL3_STATE|. 2015-12-16 18:45:48 +00:00