Inspired by Federicos posting about the footprint of his system [1] I downloaded the source-code of openssl and started poking around for places that should/could be marked as const.
I noticed a few and the attached patch addresses them (compile and make test tested) but this patch only moved 96 bytes from .data to .rodata so it feel like a bit of failure... But I guess it might be more with a older compiler. Feel free to apply if it looks ok. The patch applies cleanly to 0.9.8a and today's snapshot. The savings on my system come exclusively from the change in ocsp_ht.c but I figured that some const-sprinkling could not hurt. ;) /Henning [1] http://primates.ximian.com/~federico/news-2006-04.html#21
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/a_gentm.c openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/a_gentm.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/a_gentm.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/a_gentm.c 2006-04-24 10:44:58.000000000 +0200
@@ -117,8 +117,8 @@
int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
{
- static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
- static int max[9]={99, 99,12,31,23,59,59,12,59};
+ static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
+ static const int max[9]={99, 99,12,31,23,59,59,12,59};
char *a;
int n,i,l,o;
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/a_utctm.c openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/a_utctm.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/a_utctm.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/a_utctm.c 2006-04-24 10:44:58.000000000 +0200
@@ -114,8 +114,8 @@
int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
{
- static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
- static int max[8]={99,12,31,23,59,59,12,59};
+ static const int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
+ static const int max[8]={99,12,31,23,59,59,12,59};
char *a;
int n,i,l,o;
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/tasn_dec.c openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/tasn_dec.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/asn1/tasn_dec.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/asn1/tasn_dec.c 2006-04-24 10:52:49.000000000 +0200
@@ -93,7 +93,7 @@
int tag, int aclass, char opt, ASN1_TLC *ctx);
/* Table to convert tags to bit values, used for MSTRING type */
-static unsigned long tag2bit[32] = {
+static const unsigned long tag2bit[32] = {
0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/des/set_key.c openssl-0.9.8-stable-SNAP-20060424/crypto/des/set_key.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/des/set_key.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/des/set_key.c 2006-04-24 10:44:58.000000000 +0200
@@ -336,7 +336,7 @@
void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
{
- static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
+ static const int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
register DES_LONG c,d,t,s,t2;
register const unsigned char *in;
register DES_LONG *k;
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/des/xcbc_enc.c openssl-0.9.8-stable-SNAP-20060424/crypto/des/xcbc_enc.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/des/xcbc_enc.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/des/xcbc_enc.c 2006-04-24 10:44:58.000000000 +0200
@@ -60,7 +60,7 @@
/* RSA's DESX */
-static unsigned char desx_white_in2out[256]={
+static const unsigned char desx_white_in2out[256]={
0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36,
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/evp/encode.c openssl-0.9.8-stable-SNAP-20060424/crypto/evp/encode.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/evp/encode.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/evp/encode.c 2006-04-24 10:44:58.000000000 +0200
@@ -85,7 +85,7 @@
#define CHUNKS_PER_LINE (64/4)
#define CHAR_PER_LINE (64+1)
-static unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
+static const unsigned char data_bin2ascii[65]="ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz0123456789+/";
/* 0xF0 is a EOLN
@@ -102,7 +102,7 @@
#define B64_ERROR 0xFF
#define B64_NOT_BASE64(a) (((a)|0x13) == 0xF3)
-static unsigned char data_ascii2bin[128]={
+static const unsigned char data_ascii2bin[128]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xE0,0xF0,0xFF,0xFF,0xF1,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/ocsp/ocsp_ht.c openssl-0.9.8-stable-SNAP-20060424/crypto/ocsp/ocsp_ht.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/ocsp/ocsp_ht.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/ocsp/ocsp_ht.c 2006-04-24 10:44:58.000000000 +0200
@@ -81,7 +81,7 @@
OCSP_RESPONSE *resp = NULL;
char *p, *q, *r;
int len, retcode;
- static char req_txt[] =
+ static const char req_txt[] =
"POST %s HTTP/1.0\r\n\
Content-Type: application/ocsp-request\r\n\
Content-Length: %d\r\n\r\n";
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/rc2/rc2_skey.c openssl-0.9.8-stable-SNAP-20060424/crypto/rc2/rc2_skey.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/rc2/rc2_skey.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/rc2/rc2_skey.c 2006-04-24 10:44:58.000000000 +0200
@@ -59,7 +59,7 @@
#include <openssl/rc2.h>
#include "rc2_locl.h"
-static unsigned char key_table[256]={
+static const unsigned char key_table[256]={
0xd9,0x78,0xf9,0xc4,0x19,0xdd,0xb5,0xed,0x28,0xe9,0xfd,0x79,
0x4a,0xa0,0xd8,0x9d,0xc6,0x7e,0x37,0x83,0x2b,0x76,0x53,0x8e,
0x62,0x4c,0x64,0x88,0x44,0x8b,0xfb,0xa2,0x17,0x9a,0x59,0xf5,
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/x509/x509_obj.c openssl-0.9.8-stable-SNAP-20060424/crypto/x509/x509_obj.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/x509/x509_obj.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/x509/x509_obj.c 2006-04-24 10:44:58.000000000 +0200
@@ -72,7 +72,7 @@
char *p;
unsigned char *q;
BUF_MEM *b=NULL;
- static char hex[17]="0123456789ABCDEF";
+ static const char hex[17]="0123456789ABCDEF";
int gs_doit[4];
char tmp_buf[80];
#ifdef CHARSET_EBCDIC
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/crypto/x509v3/v3_utl.c openssl-0.9.8-stable-SNAP-20060424/crypto/x509v3/v3_utl.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/crypto/x509v3/v3_utl.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/crypto/x509v3/v3_utl.c 2006-04-24 10:44:58.000000000 +0200
@@ -366,7 +366,7 @@
char *tmp, *q;
unsigned char *p;
int i;
- static char hexdig[] = "0123456789ABCDEF";
+ static const char hexdig[] = "0123456789ABCDEF";
if(!buffer || !len) return NULL;
if(!(tmp = OPENSSL_malloc(len * 3 + 1))) {
X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
diff -ru openssl-0.9.8-stable-SNAP-20060424-orig/ssl/d1_both.c openssl-0.9.8-stable-SNAP-20060424/ssl/d1_both.c
--- openssl-0.9.8-stable-SNAP-20060424-orig/ssl/d1_both.c 2006-04-24 10:44:30.000000000 +0200
+++ openssl-0.9.8-stable-SNAP-20060424/ssl/d1_both.c 2006-04-24 10:44:58.000000000 +0200
@@ -125,7 +125,7 @@
/* XDTLS: figure out the right values */
-static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};
+static const unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};
static unsigned int dtls1_min_mtu(void);
static unsigned int dtls1_guess_mtu(unsigned int curr_mtu);
signature.asc
Description: This is a digitally signed message part
