1*e7be843bSPierre Pronchery /* 2*e7be843bSPierre Pronchery * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. 3*e7be843bSPierre Pronchery * 4*e7be843bSPierre Pronchery * Licensed under the Apache License 2.0 (the "License"). You may not use 5*e7be843bSPierre Pronchery * this file except in compliance with the License. You can obtain a copy 6*e7be843bSPierre Pronchery * in the file LICENSE in the source distribution or at 7*e7be843bSPierre Pronchery * https://www.openssl.org/source/license.html 8*e7be843bSPierre Pronchery */ 9*e7be843bSPierre Pronchery 10*e7be843bSPierre Pronchery #include <openssl/crypto.h> 11*e7be843bSPierre Pronchery #include <openssl/comp.h> 12*e7be843bSPierre Pronchery #include <openssl/obj_mac.h> 13*e7be843bSPierre Pronchery 14*e7be843bSPierre Pronchery #include "internal/cryptlib.h" 15*e7be843bSPierre Pronchery #include "internal/comp.h" 16*e7be843bSPierre Pronchery 17*e7be843bSPierre Pronchery #define SSL_COMP_NULL_IDX 0 18*e7be843bSPierre Pronchery #define SSL_COMP_ZLIB_IDX 1 19*e7be843bSPierre Pronchery #define SSL_COMP_NUM_IDX 2 20*e7be843bSPierre Pronchery 21*e7be843bSPierre Pronchery #ifndef OPENSSL_NO_COMP sk_comp_cmp(const SSL_COMP * const * a,const SSL_COMP * const * b)22*e7be843bSPierre Proncherystatic int sk_comp_cmp(const SSL_COMP *const *a, const SSL_COMP *const *b) 23*e7be843bSPierre Pronchery { 24*e7be843bSPierre Pronchery return ((*a)->id - (*b)->id); 25*e7be843bSPierre Pronchery } 26*e7be843bSPierre Pronchery #endif 27*e7be843bSPierre Pronchery STACK_OF(SSL_COMP)28*e7be843bSPierre ProncherySTACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void) 29*e7be843bSPierre Pronchery { 30*e7be843bSPierre Pronchery STACK_OF(SSL_COMP) *comp_methods = NULL; 31*e7be843bSPierre Pronchery #ifndef OPENSSL_NO_COMP 32*e7be843bSPierre Pronchery SSL_COMP *comp = NULL; 33*e7be843bSPierre Pronchery COMP_METHOD *method = COMP_zlib(); 34*e7be843bSPierre Pronchery 35*e7be843bSPierre Pronchery comp_methods = sk_SSL_COMP_new(sk_comp_cmp); 36*e7be843bSPierre Pronchery 37*e7be843bSPierre Pronchery if (COMP_get_type(method) != NID_undef && comp_methods != NULL) { 38*e7be843bSPierre Pronchery comp = OPENSSL_malloc(sizeof(*comp)); 39*e7be843bSPierre Pronchery if (comp != NULL) { 40*e7be843bSPierre Pronchery comp->method = method; 41*e7be843bSPierre Pronchery comp->id = SSL_COMP_ZLIB_IDX; 42*e7be843bSPierre Pronchery comp->name = COMP_get_name(method); 43*e7be843bSPierre Pronchery if (!sk_SSL_COMP_push(comp_methods, comp)) 44*e7be843bSPierre Pronchery OPENSSL_free(comp); 45*e7be843bSPierre Pronchery } 46*e7be843bSPierre Pronchery } 47*e7be843bSPierre Pronchery #endif 48*e7be843bSPierre Pronchery return comp_methods; 49*e7be843bSPierre Pronchery } 50*e7be843bSPierre Pronchery cmeth_free(SSL_COMP * cm)51*e7be843bSPierre Proncherystatic void cmeth_free(SSL_COMP *cm) 52*e7be843bSPierre Pronchery { 53*e7be843bSPierre Pronchery OPENSSL_free(cm); 54*e7be843bSPierre Pronchery } 55*e7be843bSPierre Pronchery ossl_free_compression_methods_int(STACK_OF (SSL_COMP)* methods)56*e7be843bSPierre Proncheryvoid ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods) 57*e7be843bSPierre Pronchery { 58*e7be843bSPierre Pronchery sk_SSL_COMP_pop_free(methods, cmeth_free); 59*e7be843bSPierre Pronchery } 60