1*e7be843bSPierre ProncheryHandling Some MAX Defines in Future 2*e7be843bSPierre Pronchery=================================== 3*e7be843bSPierre Pronchery 4*e7be843bSPierre ProncheryProblem Definition 5*e7be843bSPierre Pronchery------------------ 6*e7be843bSPierre Pronchery 7*e7be843bSPierre ProncheryThe public headers contain multiple `#define` macros that limit sizes or 8*e7be843bSPierre Proncherynumbers of various kinds. In some cases they are uncontroversial so they 9*e7be843bSPierre Proncherydo not require any changes or workarounds for these limits. Such values 10*e7be843bSPierre Proncheryare not discussed further in this document. This document discusses only 11*e7be843bSPierre Proncherysome particularly problematic values and proposes some ways how to 12*e7be843bSPierre Proncherychange or overcome these particular limits. 13*e7be843bSPierre Pronchery 14*e7be843bSPierre ProncheryIndividual Values 15*e7be843bSPierre Pronchery----------------- 16*e7be843bSPierre Pronchery 17*e7be843bSPierre Pronchery### HMAC_MAX_MD_CBLOCK 18*e7be843bSPierre Pronchery 19*e7be843bSPierre Pronchery**Current value:** 200 20*e7be843bSPierre Pronchery 21*e7be843bSPierre ProncheryThis is a deprecated define which is useless. It is not used anywhere. 22*e7be843bSPierre Pronchery 23*e7be843bSPierre Pronchery#### Proposed solution: 24*e7be843bSPierre Pronchery 25*e7be843bSPierre ProncheryIt should be just removed with 4.0. 26*e7be843bSPierre Pronchery 27*e7be843bSPierre Pronchery### EVP_MAX_MD_SIZE 28*e7be843bSPierre Pronchery 29*e7be843bSPierre Pronchery**Current value:** 64 30*e7be843bSPierre Pronchery 31*e7be843bSPierre ProncheryIt is unlikely we will see longer than 512 bit hashes any time soon. 32*e7be843bSPierre ProncheryXOF functions do not count and the XOF output length is not and should 33*e7be843bSPierre Proncherynot be limited by this value. 34*e7be843bSPierre Pronchery 35*e7be843bSPierre ProncheryIt is widely used throughout the codebase and by 3rd party applications. 36*e7be843bSPierre Pronchery 37*e7be843bSPierre Pronchery#### API calls depending on this: 38*e7be843bSPierre Pronchery 39*e7be843bSPierre ProncheryHMAC() - no way to specify the length of the output buffer 40*e7be843bSPierre Pronchery 41*e7be843bSPierre ProncheryX509_pubkey_digest() - no way to specify the length of the output buffer 42*e7be843bSPierre Pronchery 43*e7be843bSPierre ProncheryEVP_Q_digest() - no way to specify the length of the output buffer 44*e7be843bSPierre Pronchery 45*e7be843bSPierre ProncheryEVP_Digest() - no way to specify the length of the output buffer 46*e7be843bSPierre Pronchery 47*e7be843bSPierre ProncheryEVP_DigestFinal_ex() - this is actually documented to allow larger output 48*e7be843bSPierre Proncheryif set explicitly by some application call that sets the output size 49*e7be843bSPierre Pronchery 50*e7be843bSPierre Pronchery#### Proposed solution: 51*e7be843bSPierre Pronchery 52*e7be843bSPierre ProncheryKeep the value as is, do not deprecate. Review the codebase if it isn't 53*e7be843bSPierre Proncheryused in places where XOF might be used with arbitrary output length. 54*e7be843bSPierre Pronchery 55*e7be843bSPierre ProncheryPerhaps introduce API calls replacing the calls above that would have 56*e7be843bSPierre Proncheryan input parameter indicating the size of the output buffer. 57*e7be843bSPierre Pronchery 58*e7be843bSPierre Pronchery### EVP_MAX_KEY_LENGTH 59*e7be843bSPierre Pronchery 60*e7be843bSPierre Pronchery**Current value:** 64 61*e7be843bSPierre Pronchery 62*e7be843bSPierre ProncheryThis is used throughout the code and depended on in a subtle way. It can 63*e7be843bSPierre Proncherybe assumed that 3rd party applications use this value to allocate fixed 64*e7be843bSPierre Proncherybuffers for keys. It is unlikely that symmetric ciphers with keys longer 65*e7be843bSPierre Proncherythan 512 bits will be used any time soon. 66*e7be843bSPierre Pronchery 67*e7be843bSPierre Pronchery#### API calls depending on this: 68*e7be843bSPierre Pronchery 69*e7be843bSPierre ProncheryEVP_KDF_CTX_get_kdf_size() returns EVP_MAX_KEY_LENGTH for KRB5KDF until 70*e7be843bSPierre Proncherythe cipher is set. 71*e7be843bSPierre Pronchery 72*e7be843bSPierre ProncheryEVP_CIPHER_CTX_rand_key() - no way to specify the length of the output 73*e7be843bSPierre Proncherybuffer. 74*e7be843bSPierre Pronchery 75*e7be843bSPierre Pronchery#### Proposed solution: 76*e7be843bSPierre Pronchery 77*e7be843bSPierre ProncheryKeep the value as is, do not deprecate. Possibly review the codebase 78*e7be843bSPierre Proncheryto not depend on this value but there are many such cases. Avoid adding 79*e7be843bSPierre Proncheryfurther APIs depending on this value. 80*e7be843bSPierre Pronchery 81*e7be843bSPierre Pronchery### EVP_MAX_IV_LENGTH 82*e7be843bSPierre Pronchery 83*e7be843bSPierre Pronchery**Current value:** 16 84*e7be843bSPierre Pronchery 85*e7be843bSPierre ProncheryThis value is the most problematic one as in case there are ciphers with 86*e7be843bSPierre Proncherylonger block size than 128 bits it could be potentially useful to have 87*e7be843bSPierre Proncherylonger IVs than just 16 bytes. There are many cases throughout the code 88*e7be843bSPierre Proncherywhere fixed size arrays of EVP_MAX_IV_LENGTH are used. 89*e7be843bSPierre Pronchery 90*e7be843bSPierre Pronchery#### API calls depending on this: 91*e7be843bSPierre Pronchery 92*e7be843bSPierre ProncherySSL_CTX_set_tlsext_ticket_key_evp_cb() explicitly uses EVP_MAX_IV_LENGTH 93*e7be843bSPierre Proncheryin the callback function signature. 94*e7be843bSPierre Pronchery 95*e7be843bSPierre ProncherySSL_CTX_set_tlsext_ticket_key_cb() is a deprecated version of the same 96*e7be843bSPierre Proncheryand has the same problem. 97*e7be843bSPierre Pronchery 98*e7be843bSPierre Pronchery#### Proposed solution: 99*e7be843bSPierre Pronchery 100*e7be843bSPierre ProncheryDeprecate the above API call and add a replacement which explicitly 101*e7be843bSPierre Proncherypasses the length of the _iv_ parameter. 102*e7be843bSPierre Pronchery 103*e7be843bSPierre ProncheryReview and modify the codebase to not depend on and use EVP_MAX_IV_LENGTH. 104*e7be843bSPierre Pronchery 105*e7be843bSPierre ProncheryDeprecate the EVP_MAX_IV_LENGTH macro. Avoid adding further APIs depending 106*e7be843bSPierre Proncheryon this value. 107*e7be843bSPierre Pronchery 108*e7be843bSPierre Pronchery### EVP_MAX_BLOCK_LENGTH 109*e7be843bSPierre Pronchery 110*e7be843bSPierre Pronchery**Current value:** 32 111*e7be843bSPierre Pronchery 112*e7be843bSPierre ProncheryThis is used in a few places in the code. It is possible that this is 113*e7be843bSPierre Proncheryused by 3rd party applications to allocate some fixed buffers for single 114*e7be843bSPierre Proncheryor multiple blocks. It is unlikely that symmetric ciphers with block sizes 115*e7be843bSPierre Pronchery longer than 256 bits will be used any time soon. 116*e7be843bSPierre Pronchery 117*e7be843bSPierre Pronchery#### API calls depending on this: 118*e7be843bSPierre Pronchery 119*e7be843bSPierre ProncheryNone 120*e7be843bSPierre Pronchery 121*e7be843bSPierre Pronchery#### Proposed solution: 122*e7be843bSPierre Pronchery 123*e7be843bSPierre ProncheryKeep the value as is, do not deprecate. Possibly review the codebase 124*e7be843bSPierre Proncheryto not depend on this value but there are many such cases. Avoid adding 125*e7be843bSPierre ProncheryAPIs depending on this value. 126*e7be843bSPierre Pronchery 127*e7be843bSPierre Pronchery### EVP_MAX_AEAD_TAG_LENGTH 128*e7be843bSPierre Pronchery 129*e7be843bSPierre Pronchery**Current value:** 16 130*e7be843bSPierre Pronchery 131*e7be843bSPierre ProncheryThis macro is used in a single place in hpke to allocate a fixed buffer. 132*e7be843bSPierre ProncheryThe EVP_EncryptInit(3) manual page mentions the tag size being at most 133*e7be843bSPierre Pronchery16 bytes for EVP_CIPHER_CTX_ctrl(EVP_CTRL_AEAD_SET_TAG). The value is 134*e7be843bSPierre Proncheryproblematic as for HMAC/KMAC based AEAD ciphers the tag length can be 135*e7be843bSPierre Proncherylarger than block size. Even in case we would have block ciphers with 136*e7be843bSPierre Pronchery256 block size the maximum tag length value of 16 is limiting. 137*e7be843bSPierre Pronchery 138*e7be843bSPierre Pronchery#### API calls depending on this: 139*e7be843bSPierre Pronchery 140*e7be843bSPierre ProncheryNone (except the documentation in 141*e7be843bSPierre ProncheryEVP_CIPHER_CTX_ctrl(EVP_CTRL_AEAD_SET/GET_TAG)) 142*e7be843bSPierre Pronchery 143*e7be843bSPierre Pronchery#### Proposed solution: 144*e7be843bSPierre Pronchery 145*e7be843bSPierre ProncheryReview and modify the codebase to not depend on and use 146*e7be843bSPierre ProncheryEVP_MAX_AEAD_TAG_LENGTH. 147*e7be843bSPierre Pronchery 148*e7be843bSPierre ProncheryDeprecate the EVP_MAX_AEAD_TAG_LENGTH macro. Avoid adding APIs depending 149*e7be843bSPierre Proncheryon this value. 150