Lines Matching refs:SSL
15 #include <openssl/ssl.h>
42 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
53 OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
86 uint8_t *ssl_read_buffer(SSL *ssl) {
87 return ssl->s3->read_buffer.buf + ssl->s3->read_buffer.offset;
90 size_t ssl_read_buffer_len(const SSL *ssl) {
91 return ssl->s3->read_buffer.len;
94 static int dtls_read_buffer_next_packet(SSL *ssl) {
95 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
100 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
104 /* Read a single packet from |ssl->rbio|. |buf->cap| must fit in an int. */
105 int ret = BIO_read(ssl->rbio, buf->buf + buf->offset, (int)buf->cap);
107 ssl->rwstate = SSL_READING;
115 static int tls_read_buffer_extend_to(SSL *ssl, size_t len) {
116 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
119 OPENSSL_PUT_ERROR(SSL, SSL_R_BUFFER_TOO_SMALL);
127 int ret = BIO_read(ssl->rbio, buf->buf + buf->offset + buf->len,
130 ssl->rwstate = SSL_READING;
141 int ssl_read_buffer_extend_to(SSL *ssl, size_t len) {
143 ssl_read_buffer_discard(ssl);
145 if (SSL_is_dtls(ssl)) {
154 if (!ensure_buffer(&ssl->s3->read_buffer, ssl_record_prefix_len(ssl), len)) {
158 if (ssl->rbio == NULL) {
159 OPENSSL_PUT_ERROR(SSL, SSL_R_BIO_NOT_SET);
164 if (SSL_is_dtls(ssl)) {
166 ret = dtls_read_buffer_next_packet(ssl);
168 ret = tls_read_buffer_extend_to(ssl, len);
174 ssl_read_buffer_discard(ssl);
179 void ssl_read_buffer_consume(SSL *ssl, size_t len) {
180 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
189 assert(SSL_is_dtls(ssl) || len == 0 || buf->len == 0);
192 void ssl_read_buffer_discard(SSL *ssl) {
193 if (ssl->s3->read_buffer.len == 0) {
194 ssl_read_buffer_clear(ssl);
198 void ssl_read_buffer_clear(SSL *ssl) {
199 clear_buffer(&ssl->s3->read_buffer);
203 int ssl_write_buffer_is_pending(const SSL *ssl) {
204 return ssl->s3->write_buffer.len > 0;
218 int ssl_write_buffer_init(SSL *ssl, uint8_t **out_ptr, size_t max_len) {
219 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
222 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
226 if (!ensure_buffer(buf, ssl_seal_align_prefix_len(ssl), max_len)) {
233 void ssl_write_buffer_set_len(SSL *ssl, size_t len) {
234 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
242 static int tls_write_buffer_flush(SSL *ssl) {
243 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
246 int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);
248 ssl->rwstate = SSL_WRITING;
253 ssl_write_buffer_clear(ssl);
257 static int dtls_write_buffer_flush(SSL *ssl) {
258 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
263 int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);
265 ssl->rwstate = SSL_WRITING;
269 ssl_write_buffer_clear(ssl);
272 ssl_write_buffer_clear(ssl);
276 int ssl_write_buffer_flush(SSL *ssl) {
277 if (ssl->wbio == NULL) {
278 OPENSSL_PUT_ERROR(SSL, SSL_R_BIO_NOT_SET);
282 if (SSL_is_dtls(ssl)) {
283 return dtls_write_buffer_flush(ssl);
285 return tls_write_buffer_flush(ssl);
289 void ssl_write_buffer_clear(SSL *ssl) {
290 clear_buffer(&ssl->s3->write_buffer);