Lines Matching refs:rc
287 br_ssl_engine_fail(br_ssl_engine_context *rc, int err)
289 if (rc->iomode != BR_IO_FAILED) {
290 rc->iomode = BR_IO_FAILED;
291 rc->err = err;
299 make_ready_in(br_ssl_engine_context *rc)
301 rc->ixa = rc->ixb = 0;
302 rc->ixc = 5;
303 if (rc->iomode == BR_IO_IN) {
304 rc->iomode = BR_IO_INOUT;
312 make_ready_out(br_ssl_engine_context *rc)
317 b = rc->obuf_len - a;
318 rc->out.vtable->max_plaintext(&rc->out.vtable, &a, &b);
319 if ((b - a) > rc->max_frag_len) {
320 b = a + rc->max_frag_len;
322 rc->oxa = a;
323 rc->oxb = b;
324 rc->oxc = a;
325 if (rc->iomode == BR_IO_OUT) {
326 rc->iomode = BR_IO_INOUT;
332 br_ssl_engine_new_max_frag_len(br_ssl_engine_context *rc, unsigned max_frag_len)
336 rc->max_frag_len = max_frag_len;
337 nxb = rc->oxc + max_frag_len;
338 if (rc->oxa < rc->oxb && rc->oxb > nxb && rc->oxa < nxb) {
339 rc->oxb = nxb;
345 br_ssl_engine_set_buffer(br_ssl_engine_context *rc,
349 br_ssl_engine_set_buffers_bidi(rc, NULL, 0, NULL, 0);
373 rc->iomode = BR_IO_FAILED;
374 rc->err = BR_ERR_BAD_PARAM;
383 br_ssl_engine_set_buffers_bidi(rc,
387 br_ssl_engine_set_buffers_bidi(rc,
395 br_ssl_engine_set_buffers_bidi(br_ssl_engine_context *rc,
398 rc->iomode = BR_IO_INOUT;
399 rc->incrypt = 0;
400 rc->err = BR_ERR_OK;
401 rc->version_in = 0;
402 rc->record_type_in = 0;
403 rc->version_out = 0;
404 rc->record_type_out = 0;
406 if (rc->ibuf == NULL) {
407 br_ssl_engine_fail(rc, BR_ERR_BAD_PARAM);
412 rc->ibuf = ibuf;
413 rc->ibuf_len = ibuf_len;
418 rc->obuf = obuf;
419 rc->obuf_len = obuf_len;
440 br_ssl_engine_fail(rc, BR_ERR_BAD_PARAM);
445 rc->max_frag_len = (size_t)1 << u;
446 rc->log_max_frag_len = u;
447 rc->peer_log_max_frag_len = 0;
449 rc->out.vtable = &br_sslrec_out_clear_vtable;
450 make_ready_in(rc);
451 make_ready_out(rc);
458 engine_clearbuf(br_ssl_engine_context *rc)
460 make_ready_in(rc);
461 make_ready_out(rc);
566 recvrec_buf(const br_ssl_engine_context *rc, size_t *len)
568 if (rc->shutdown_recv) {
583 switch (rc->iomode) {
586 if (rc->ixa == rc->ixb) {
589 z = rc->ixc;
590 if (z > rc->ibuf_len - rc->ixa) {
591 z = rc->ibuf_len - rc->ixa;
594 return rc->ibuf + rc->ixa;
603 recvrec_ack(br_ssl_engine_context *rc, size_t len)
613 if (rc->iomode == BR_IO_INOUT && rc->ibuf == rc->obuf) {
614 rc->iomode = BR_IO_IN;
620 rc->ixb = (rc->ixa += len);
621 rc->ixc -= len;
627 if (rc->ixa < 5) {
634 if (rc->ixa == 5) {
650 rc->record_type_in = rc->ibuf[0];
651 version = br_dec16be(rc->ibuf + 1);
653 br_ssl_engine_fail(rc, BR_ERR_UNSUPPORTED_VERSION);
663 if (rc->version_in != 0 && rc->version_in != version) {
664 br_ssl_engine_fail(rc, BR_ERR_BAD_VERSION);
667 rc->version_in = version;
679 rlen = br_dec16be(rc->ibuf + 3);
680 if (rc->incrypt) {
681 if (!rc->in.vtable->check_length(
682 &rc->in.vtable, rlen))
684 br_ssl_engine_fail(rc, BR_ERR_BAD_LENGTH);
687 if (rlen > (rc->ibuf_len - 5)) {
688 br_ssl_engine_fail(rc, BR_ERR_TOO_LARGE);
693 br_ssl_engine_fail(rc, BR_ERR_BAD_LENGTH);
712 make_ready_in(rc);
714 rc->ixa = rc->ixb = 5;
715 rc->ixc = rlen;
726 if (!rc->incrypt) {
727 rc->ixa = 5;
735 if (rc->ixc != 0) {
742 pbuf_len = rc->ixa - 5;
743 pbuf = rc->in.vtable->decrypt(&rc->in.vtable,
744 rc->record_type_in, rc->version_in, rc->ibuf + 5, &pbuf_len);
746 br_ssl_engine_fail(rc, BR_ERR_BAD_MAC);
749 rc->ixa = (size_t)(pbuf - rc->ibuf);
750 rc->ixb = rc->ixa + pbuf_len;
756 if (rc->ixa == rc->ixb) {
757 make_ready_in(rc);
763 br_ssl_engine_recvrec_finished(const br_ssl_engine_context *rc)
765 switch (rc->iomode) {
768 return rc->ixc == 0 || rc->ixa < 5;
775 recvpld_buf(const br_ssl_engine_context *rc, size_t *len)
781 switch (rc->iomode) {
784 *len = rc->ixb - rc->ixa;
785 return (*len == 0) ? NULL : (rc->ibuf + rc->ixa);
793 recvpld_ack(br_ssl_engine_context *rc, size_t len)
795 rc->ixa += len;
803 if (rc->ixa == rc->ixb) {
804 if (rc->ixc == 0) {
805 make_ready_in(rc);
807 rc->ixa = rc->ixb = 5;
813 sendpld_buf(const br_ssl_engine_context *rc, size_t *len)
819 switch (rc->iomode) {
822 *len = rc->oxb - rc->oxa;
823 return (*len == 0) ? NULL : (rc->obuf + rc->oxa);
839 sendpld_flush(br_ssl_engine_context *rc, int force)
844 if (rc->oxa == rc->oxb) {
847 xlen = rc->oxa - rc->oxc;
851 buf = rc->out.vtable->encrypt(&rc->out.vtable,
852 rc->record_type_out, rc->version_out,
853 rc->obuf + rc->oxc, &xlen);
854 rc->oxb = rc->oxa = (size_t)(buf - rc->obuf);
855 rc->oxc = rc->oxa + xlen;
859 sendpld_ack(br_ssl_engine_context *rc, size_t len)
865 if (rc->iomode == BR_IO_INOUT && rc->ibuf == rc->obuf) {
866 rc->iomode = BR_IO_OUT;
868 rc->oxa += len;
869 if (rc->oxa >= rc->oxb) {
875 rc->oxb = rc->oxa + 1;
876 sendpld_flush(rc, 0);
881 sendrec_buf(const br_ssl_engine_context *rc, size_t *len)
889 switch (rc->iomode) {
892 if (rc->oxc > rc->oxa) {
893 *len = rc->oxc - rc->oxa;
894 return rc->obuf + rc->oxa;
903 sendrec_ack(br_ssl_engine_context *rc, size_t len)
905 rc->oxb = (rc->oxa += len);
906 if (rc->oxa == rc->oxc) {
907 make_ready_out(rc);
916 has_rec_tosend(const br_ssl_engine_context *rc)
918 return rc->oxa == rc->oxb && rc->oxa != rc->oxc;