1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#ifndef __LSQUIC_CRT_COMPRESS_H__
350aadb33SDmitri Tikhonov#define __LSQUIC_CRT_COMPRESS_H__
450aadb33SDmitri Tikhonov
550aadb33SDmitri Tikhonov#include <stdint.h>
650aadb33SDmitri Tikhonov
750aadb33SDmitri Tikhonovstruct lsquic_str;
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#ifdef __cplusplus
1050aadb33SDmitri Tikhonovextern "C" {
1150aadb33SDmitri Tikhonov#endif
1250aadb33SDmitri Tikhonov
135392f7a3SLiteSpeed Tech
1450aadb33SDmitri Tikhonovenum entry_type {
1550aadb33SDmitri Tikhonov    END_OF_LIST = 0,
1650aadb33SDmitri Tikhonov    ENTRY_COMPRESSED = 1,
1750aadb33SDmitri Tikhonov    ENTRY_CACHED = 2,
1850aadb33SDmitri Tikhonov    ENTRY_COMMON = 3,
1950aadb33SDmitri Tikhonov};
2050aadb33SDmitri Tikhonov
2150aadb33SDmitri Tikhonovtypedef struct cert_entry_st {
2250aadb33SDmitri Tikhonov    enum entry_type type;
2350aadb33SDmitri Tikhonov    uint32_t index;
2450aadb33SDmitri Tikhonov    uint64_t hash;
2550aadb33SDmitri Tikhonov    uint64_t set_hash;
2650aadb33SDmitri Tikhonov} cert_entry_t;
2750aadb33SDmitri Tikhonov
285392f7a3SLiteSpeed Tech
2950aadb33SDmitri Tikhonovtypedef struct common_cert_st
3050aadb33SDmitri Tikhonov{
3150aadb33SDmitri Tikhonov    size_t num_certs;
3250aadb33SDmitri Tikhonov    const unsigned char* const* certs;
3350aadb33SDmitri Tikhonov    const size_t* lens;
3450aadb33SDmitri Tikhonov    uint64_t hash;
3550aadb33SDmitri Tikhonov} common_cert_t;
3650aadb33SDmitri Tikhonov
372f4629f2SDmitri Tikhonovint
382f4629f2SDmitri Tikhonovlsquic_crt_init (void);
392f4629f2SDmitri Tikhonov
40a5fa05f9SDmitri Tikhonovstruct lsquic_str * lsquic_get_common_certs_hash();
4150aadb33SDmitri Tikhonov
425392f7a3SLiteSpeed Tech
43a5fa05f9SDmitri Tikhonovint lsquic_get_common_cert(uint64_t hash, uint32_t index, struct lsquic_str *buf);
445392f7a3SLiteSpeed Tech
45fbc6cc04SDmitri Tikhonovstruct compressed_cert
46fbc6cc04SDmitri Tikhonov{
47fbc6cc04SDmitri Tikhonov    size_t          len;
48fbc6cc04SDmitri Tikhonov    unsigned        refcnt;
49fbc6cc04SDmitri Tikhonov    unsigned char   buf[0]; /* len bytes */
50fbc6cc04SDmitri Tikhonov};
51fbc6cc04SDmitri Tikhonov
52fbc6cc04SDmitri Tikhonov/* Returns newly allocated structure or NULL on error */
53fbc6cc04SDmitri Tikhonovstruct compressed_cert *
54fbc6cc04SDmitri Tikhonovlsquic_compress_certs(struct lsquic_str **certs, size_t certs_count,
555392f7a3SLiteSpeed Tech                   struct lsquic_str *client_common_set_hashes,
56fbc6cc04SDmitri Tikhonov                   struct lsquic_str *client_cached_cert_hashes);
57fbc6cc04SDmitri Tikhonov
58fbc6cc04SDmitri Tikhonovint
59fbc6cc04SDmitri Tikhonovlsquic_get_certs_count (const struct compressed_cert *);
605392f7a3SLiteSpeed Tech
61a5fa05f9SDmitri Tikhonovint lsquic_decompress_certs(const unsigned char *in, const unsigned char *in_end,
6250aadb33SDmitri Tikhonov                     struct lsquic_str *cached_certs, size_t cached_certs_count,
6350aadb33SDmitri Tikhonov                     struct lsquic_str **out_certs,
6450aadb33SDmitri Tikhonov                     size_t *out_certs_count);
6550aadb33SDmitri Tikhonov
6650aadb33SDmitri Tikhonovvoid
6750aadb33SDmitri Tikhonovlsquic_crt_cleanup (void);
6850aadb33SDmitri Tikhonov
695392f7a3SLiteSpeed Tech
7050aadb33SDmitri Tikhonov#ifdef __cplusplus
7150aadb33SDmitri Tikhonov}
7250aadb33SDmitri Tikhonov#endif
7350aadb33SDmitri Tikhonov
745392f7a3SLiteSpeed Tech
7550aadb33SDmitri Tikhonov#endif //__LSQUIC_CRT_COMPRESS_H__
76