tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sslencode.h (4532B)


      1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
      2 /*
      3 * This file is PRIVATE to SSL.
      4 *
      5 * This Source Code Form is subject to the terms of the Mozilla Public
      6 * License, v. 2.0. If a copy of the MPL was not distributed with this
      7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      8 
      9 #ifndef __sslencode_h_
     10 #define __sslencode_h_
     11 
     12 /* A buffer object, used for assembling messages. */
     13 typedef struct sslBufferStr {
     14    PRUint8 *buf;
     15    unsigned int len;
     16    unsigned int space;
     17    /* Set to true if the storage for the buffer is fixed, such as a stack
     18     * variable or a view on another buffer. Growing a fixed buffer fails. */
     19    PRBool fixed;
     20 } sslBuffer;
     21 
     22 #define SSL_BUFFER_EMPTY     \
     23    {                        \
     24        NULL, 0, 0, PR_FALSE \
     25    }
     26 #define SSL_BUFFER_FIXED(b, maxlen) \
     27    {                               \
     28        b, 0, maxlen, PR_TRUE       \
     29    }
     30 #define SSL_BUFFER_FIXED_LEN(b, len) \
     31    {                                \
     32        b, len, 0, PR_TRUE           \
     33    }
     34 #define SSL_BUFFER(b) SSL_BUFFER_FIXED(b, sizeof(b))
     35 #define SSL_BUFFER_BASE(b) ((b)->buf)
     36 #define SSL_BUFFER_LEN(b) ((b)->len)
     37 #define SSL_BUFFER_NEXT(b) ((b)->buf + (b)->len)
     38 #define SSL_BUFFER_SPACE(b) ((b)->space - (b)->len)
     39 
     40 SECStatus sslBuffer_Grow(sslBuffer *b, unsigned int newLen);
     41 SECStatus sslBuffer_Fill(sslBuffer *b, PRUint8 c, size_t len);
     42 SECStatus sslBuffer_Append(sslBuffer *b, const void *data, unsigned int len);
     43 SECStatus sslBuffer_AppendNumber(sslBuffer *b, PRUint64 v, unsigned int size);
     44 SECStatus sslBuffer_AppendVariable(sslBuffer *b, const PRUint8 *data,
     45                                   unsigned int len, unsigned int size);
     46 SECStatus sslBuffer_AppendBuffer(sslBuffer *b, const sslBuffer *append);
     47 SECStatus sslBuffer_AppendBufferVariable(sslBuffer *b, const sslBuffer *append,
     48                                         unsigned int size);
     49 SECStatus sslBuffer_Skip(sslBuffer *b, unsigned int size,
     50                         unsigned int *savedOffset);
     51 SECStatus sslBuffer_InsertLength(sslBuffer *b, unsigned int at,
     52                                 unsigned int size);
     53 SECStatus sslBuffer_InsertNumber(sslBuffer *b, unsigned int at,
     54                                 PRUint64 v, unsigned int size);
     55 void sslBuffer_Clear(sslBuffer *b);
     56 
     57 SECStatus ssl3_AppendHandshake(sslSocket *ss, const void *void_src,
     58                               unsigned int bytes);
     59 SECStatus ssl3_AppendHandshakeSuppressHash(sslSocket *ss, const void *void_src,
     60                                           unsigned int bytes);
     61 SECStatus ssl3_AppendHandshakeHeader(sslSocket *ss,
     62                                     SSLHandshakeType t, unsigned int length);
     63 SECStatus ssl3_AppendHandshakeHeaderAndStashSeqNum(sslSocket *ss,
     64                                                   SSLHandshakeType t, unsigned int length, PRUint64 *b);
     65 SECStatus ssl3_AppendHandshakeNumber(sslSocket *ss, PRUint64 num,
     66                                     unsigned int lenSize);
     67 SECStatus ssl3_AppendHandshakeNumberSuppressHash(sslSocket *ss, PRUint64 num,
     68                                                 unsigned int lenSize, PRBool suppressHash);
     69 SECStatus ssl3_AppendHandshakeVariable(sslSocket *ss, const PRUint8 *src,
     70                                       unsigned int bytes, unsigned int lenSize);
     71 SECStatus ssl3_AppendBufferToHandshake(sslSocket *ss, sslBuffer *buf);
     72 SECStatus ssl3_AppendBufferToHandshakeVariable(sslSocket *ss, sslBuffer *buf,
     73                                               unsigned int lenSize);
     74 SECStatus ssl3_CopyToSECItem(sslBuffer *b, SECItem *i);
     75 
     76 typedef struct {
     77    const PRUint8 *buf;
     78    unsigned int len;
     79 } sslReadBuffer;
     80 typedef struct {
     81    sslReadBuffer buf;
     82    unsigned int offset;
     83 } sslReader;
     84 #define SSL_READER(b, l) \
     85    {                    \
     86        { b, l }, 0      \
     87    }
     88 #define SSL_READER_CURRENT(r) \
     89    ((r)->buf.buf + (r)->offset)
     90 #define SSL_READER_REMAINING(r) \
     91    ((r)->buf.len - (r)->offset)
     92 SECStatus sslRead_Read(sslReader *reader, unsigned int count,
     93                       sslReadBuffer *out);
     94 SECStatus sslRead_ReadVariable(sslReader *reader, unsigned int sizeLen,
     95                               sslReadBuffer *out);
     96 SECStatus sslRead_ReadNumber(sslReader *reader, unsigned int bytes,
     97                             PRUint64 *val);
     98 
     99 /* Remove message_seq, fragment_offset and fragment_length values
    100 * from the savedMessage buffer. Used for DTLS1.3 */
    101 SECStatus ssl3_MaybeUpdateHashWithSavedRecord(sslSocket *ss);
    102 
    103 #endif /* __sslencode_h_ */