From source bn_exp.c:
0634 #ifdef alloca 0635 if (powerbufLen < 3072) 0636 powerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH); 0637 else 0638 #endif 0639 if ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) 0640 goto err;
Note that 0xbff is 3071. On systems that support it, alloca performs stack allocation. This refers to the GNU version used by Linux, and the BSD implementation copied this API from 32V UNIX from AT & T ( according to FreeBSD ).
You only looked at line 639. But if alloca defined, then the C code matches your assembly.
Optimization itself is often used to avoid the cost of using malloc for a temporary buffer if the distribution is relatively small. For C.1999, VLA can be used instead (since C.2011, VLA is an optional function).
Sometimes optimization just uses a fixed size buffer with some reasonably small size. For instance:
char tmp_buf[1024]; char *tmp = tmp_buf; if (bytes_needed > 1024) { tmp = malloc(bytes_needed); } if (tmp != tmp_buf) { free(tmp); }
source share