SSL_CTX_SET_...DING_CALLBACK(3ossl)
π SSL_CTX_SET_...DING_CALLBACK β the OpenSSL fam (manual section 3ossl)
okay bestie, sit down, grab a boba, because we're talking about TLS 1.3 record padding and honestly? it's giving β¨control freak in the best wayβ¨. this is the <openssl/ssl.h> girlies.
πΈ NAME πΈ
SSL_CTX_set_record_padding_callback, SSL_set_record_padding_callback, SSL_CTX_set_record_padding_callback_arg, SSL_set_record_padding_callback_arg, SSL_CTX_get_record_padding_callback_arg, SSL_get_record_padding_callback_arg, SSL_CTX_set_block_padding, SSL_CTX_set_block_padding_ex, SSL_set_block_padding, SSL_set_block_padding_ex β install a callback to specify TLS 1.3 record padding π
β¨ SYNOPSIS β¨
#include <openssl/ssl.h>
void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx, size_t (*cb)(SSL *s, int type, size_t len, void *arg));
int SSL_set_record_padding_callback(SSL *ssl, size_t (*cb)(SSL *s, int type, size_t len, void *arg));
void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg);
void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx);
void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg);
void *SSL_get_record_padding_callback_arg(const SSL *ssl);
int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size);
int SSL_set_block_padding(SSL *ssl, size_t block_size);
int SSL_CTX_set_block_padding_ex(SSL_CTX *ctx, size_t app_block_size, size_t hs_block_size);
int SSL_set_block_padding_ex(SSL *ssl, size_t app_block_size, size_t hs_block_size);
π¦ DESCRIPTION π¦
so SSL_CTX_set_record_padding_callback() and SSL_set_record_padding_callback() let you hand over a callback function cb that decides the padding for your TLS 1.3 records. main character energy, truly. the value you set on ctx gets copied into a new SSL by SSL_new() π«Ά
β οΈ heads up: Kernel TLS is not possible if the record padding callback is set, and you also can't set the callback function if Kernel TLS is already configured for the current SSL object. pick a lane bestie, you cannot have both π
SSL_CTX_set_record_padding_callback_arg() and SSL_set_record_padding_callback_arg() assign a value arg that gets passed to the callback whenever it's invoked. and yes, the value set in ctx is copied to a new SSL by SSL_new() too. consistency queen π
SSL_CTX_get_record_padding_callback_arg() and SSL_get_record_padding_callback_arg() retrieve that arg value that's passed to the callback. getters, we love to see it.
SSL_CTX_set_block_padding() and SSL_set_block_padding() pad the record up to a multiple of block_size. a block_size of 0 or 1 disables block padding (so unserious). the limit of block_size is SSL3_RT_MAX_PLAIN_LENGTH.
SSL_CTX_set_block_padding_ex() and SSL_set_block_padding_ex() do the same lil thing but let the caller separately specify the padding block size to apply to handshake messages and to application data messages. fancy π
okay now the callback deets, because this is where it gets good:
- the callback is invoked for every record before encryption
typeβ the TLS record type being processed; it may be one ofSSL3_RT_APPLICATION_DATA,SSL3_RT_HANDSHAKE, orSSL3_RT_ALERTlenβ the current plaintext length of the record before encryptionargβ the value set viaSSL_CTX_set_record_padding_callback_arg()orSSL_set_record_padding_callback_arg()
π¨ and now the buzzkill: these functions cannot be used with QUIC SSL objects.SSL_set_record_padding_callback()andSSL_set_block_padding()fail if called on a QUIC SSL object. no QUIC for you, sorry babe π
π RETURN VALUES π
SSL_CTX_get_record_padding_callback_arg() and SSL_get_record_padding_callback_arg() return the arg value you assigned in the corresponding set functions. straightforward, iconic.
SSL_CTX_set_block_padding() and SSL_set_block_padding() return 1 on success, or 0 if block_size is too large. (rude, but okay.)
cb returns the number of padding bytes to add to the record. a return of 0 means no padding gets added β clean, minimal, no notes. and if your return value would make the record exceed the maximum record size (SSL3_RT_MAX_PLAIN_LENGTH), it'll pad out to the maximum record size instead. it simply will not let you overshoot π
SSL_CTX_get_record_padding_callback_arg() returns 1 on success or 0 if the callback function is not set because Kernel TLS is configured for the SSL object. yes that's what it says, keep it in your notes bestie π
π NOTES π
- the default behavior is to add no padding to the record. au naturel π§
- a user-supplied padding callback function will override the behavior set by
SSL_set_block_padding()orSSL_CTX_set_block_padding(). setting the user-supplied callback toNULLwill restore the configured block padding behavior. it's giving toggles β¨ - these functions only apply to TLS 1.3 records being written. read that again. TLS 1.3. written. okay? π«Ά
- > π padding bytes are not added in constant-time. just so you know. that's a real caveat, not a vibe.
π₯ SEE ALSO π₯
β HISTORY β
- the record padding API was added for TLS 1.3 support in OpenSSL 1.1.1
- the return type of
SSL_CTX_set_record_padding_callback()was changed tointin OpenSSL 3.0 SSL_set_block_padding_ex()andSSL_CTX_set_block_padding_ex()were added in OpenSSL 3.4
π COPYRIGHT π
Copyright 2017-2024 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie π this was OpenSSL 3.5.9, dated 2026-09-2, section 3ossl β slay, stay padded, and remember: no constant-time, no QUIC, no cap β¨ππ¦
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms