# HG changeset patch # User Sergey Kandaurov # Date 1623855813 -10800 # Node ID 2029a30863e2287847cf7abe2d8e2248b88be658 # Parent e617d0ba387a7b0e5ad46ecc87f9f51ee1e90953 QUIC: using compile time block/iv length for tokens. Reference values can be found in RFC 3602, 2.1, 2.4. diff --git a/src/event/quic/ngx_event_quic_tokens.c b/src/event/quic/ngx_event_quic_tokens.c --- a/src/event/quic/ngx_event_quic_tokens.c +++ b/src/event/quic/ngx_event_quic_tokens.c @@ -14,6 +14,10 @@ #define NGX_QUIC_MAX_TOKEN_SIZE 64 /* SHA-1(addr)=20 + sizeof(time_t) + retry(1) + odcid.len(1) + odcid */ +/* RFC 3602, 2.1 and 2.4 for AES-CBC block size and IV length */ +#define NGX_QUIC_AES_256_CBC_IV_LEN 16 +#define NGX_QUIC_AES_256_CBC_BLOCK_SIZE 16 + static void ngx_quic_address_hash(struct sockaddr *sockaddr, socklen_t socklen, ngx_uint_t no_port, u_char buf[20]); @@ -76,9 +80,9 @@ ngx_quic_new_token(ngx_connection_t *c, len = p - in; cipher = EVP_aes_256_cbc(); - iv_len = EVP_CIPHER_iv_length(cipher); + iv_len = NGX_QUIC_AES_256_CBC_IV_LEN; - token->len = iv_len + len + EVP_CIPHER_block_size(cipher); + token->len = iv_len + len + NGX_QUIC_AES_256_CBC_BLOCK_SIZE; token->data = ngx_pnalloc(c->pool, token->len); if (token->data == NULL) { return NGX_ERROR; @@ -188,11 +192,11 @@ ngx_quic_validate_token(ngx_connection_t cipher = EVP_aes_256_cbc(); iv = pkt->token.data; - iv_len = EVP_CIPHER_iv_length(cipher); + iv_len = NGX_QUIC_AES_256_CBC_IV_LEN; /* sanity checks */ - if (pkt->token.len < (size_t) iv_len + EVP_CIPHER_block_size(cipher)) { + if (pkt->token.len < (size_t) iv_len + NGX_QUIC_AES_256_CBC_BLOCK_SIZE) { goto garbage; }