file from a bio or fp. Added some more constification to the BN library.
Changes between 0.9.3a and 0.9.4
+ *) New functions CONF_load_bio() and CONF_load_fp() to allow a config
+ file to be loaded from a BIO or FILE pointer. The BIO version will
+ for example allow memory BIOs to contain config info.
+ [Steve Henson]
+
*) New function "CRYPTO_num_locks" that returns CRYPTO_NUM_LOCKS.
Whoever hopes to achieve shared-library compatibility across versions
must use this, not the compile-time macro.
void BN_clear_free(BIGNUM *a);
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
-int BN_bn2bin(BIGNUM *a, unsigned char *to);
+int BN_bn2bin(const BIGNUM *a, unsigned char *to);
BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
-int BN_bn2mpi(BIGNUM *a, unsigned char *to);
+int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
int BN_set_bit(BIGNUM *a, int n);
int BN_clear_bit(BIGNUM *a, int n);
-char * BN_bn2hex(BIGNUM *a);
-char * BN_bn2dec(BIGNUM *a);
-int BN_hex2bn(BIGNUM **a,char *str);
-int BN_dec2bn(BIGNUM **a,char *str);
+char * BN_bn2hex(const BIGNUM *a);
+char * BN_bn2dec(const BIGNUM *a);
+int BN_hex2bn(BIGNUM **a, const char *str);
+int BN_dec2bn(BIGNUM **a, const char *str);
int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add,
}
/* ignore negative */
-int BN_bn2bin(BIGNUM *a, unsigned char *to)
+int BN_bn2bin(const BIGNUM *a, unsigned char *to)
{
int n,i;
BN_ULONG l;
#include "cryptlib.h"
#include "bn_lcl.h"
-int BN_bn2mpi(BIGNUM *a, unsigned char *d)
+int BN_bn2mpi(const BIGNUM *a, unsigned char *d)
{
int bits;
int num=0;
static const char *Hex="0123456789ABCDEF";
/* Must 'Free' the returned data */
-char *BN_bn2hex(BIGNUM *a)
+char *BN_bn2hex(const BIGNUM *a)
{
int i,j,v,z=0;
char *buf;
}
/* Must 'Free' the returned data */
-char *BN_bn2dec(BIGNUM *a)
+char *BN_bn2dec(const BIGNUM *a)
{
int i=0,num;
char *buf=NULL;
return(buf);
}
-int BN_hex2bn(BIGNUM **bn, char *a)
+int BN_hex2bn(BIGNUM **bn, const char *a)
{
BIGNUM *ret=NULL;
BN_ULONG l=0;
return(0);
}
-int BN_dec2bn(BIGNUM **bn, char *a)
+int BN_dec2bn(BIGNUM **bn, const char *a)
{
BIGNUM *ret=NULL;
BN_ULONG l=0;
conf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
conf.o: ../../include/openssl/stack.h ../cryptlib.h conf_lcl.h
-conf_err.o: ../../include/openssl/conf.h ../../include/openssl/err.h
-conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/stack.h
+conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
+conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h
+conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h
+conf_err.o: ../../include/openssl/stack.h
const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
-LHASH *CONF_load(LHASH *h, char *file, long *line)
+
+LHASH *CONF_load(LHASH *h, const char *file, long *line)
{
- LHASH *ret=NULL;
+ LHASH *ltmp;
FILE *in=NULL;
+
+#ifdef VMS
+ in=fopen(file,"r");
+#else
+ in=fopen(file,"rb");
+#endif
+ if (in == NULL)
+ {
+ SYSerr(SYS_F_FOPEN,get_last_sys_error());
+ ERR_set_error_data(BUF_strdup(file),
+ ERR_TXT_MALLOCED|ERR_TXT_STRING);
+ CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+ return NULL;
+ }
+
+ ltmp = CONF_load_fp(h, in, line);
+ fclose(in);
+
+ return ltmp;
+}
+
+LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
+{
+ BIO *btmp;
+ LHASH *ltmp;
+ if(!(btmp = BIO_new_fp(in, BIO_NOCLOSE))) {
+ CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
+ return NULL;
+ }
+ ltmp = CONF_load_bio(h, btmp, line);
+ BIO_free(btmp);
+ return ltmp;
+}
+
+LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line)
+ {
+ LHASH *ret=NULL;
#define BUFSIZE 512
char btmp[16];
int bufnum=0,i,ii;
if ((buff=BUF_MEM_new()) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);
- goto err;
- }
-
-#ifdef VMS
- in=fopen(file,"r");
-#else
- in=fopen(file,"rb");
-#endif
- if (in == NULL)
- {
- SYSerr(SYS_F_FOPEN,get_last_sys_error());
- ERR_set_error_data(BUF_strdup(file),
- ERR_TXT_MALLOCED|ERR_TXT_STRING);
- CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
goto err;
}
section=(char *)Malloc(10);
if (section == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
goto err;
}
strcpy(section,"default");
{
if ((ret=lh_new(hash,cmp)) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
goto err;
}
}
sv=new_section(ret,section);
if (sv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
section_sk=(STACK *)sv->value;
again=0;
if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);
+ CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
goto err;
}
p= &(buff->data[bufnum]);
*p='\0';
- fgets(p,BUFSIZE-1,in);
+ BIO_gets(in, p, BUFSIZE-1);
p[BUFSIZE-1]='\0';
ii=i=strlen(p);
if (i == 0) break;
ss=p;
goto again;
}
- CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
goto err;
}
*end='\0';
sv=new_section(ret,section);
if (sv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
section_sk=(STACK *)sv->value;
p=eat_ws(end);
if (*p != '=')
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_MISSING_EQUAL_SIGN);
goto err;
}
*end='\0';
if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
if (psection == NULL) psection=section;
v->value=NULL;
if (v->name == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
strcpy(v->name,pname);
tv=new_section(ret,psection);
if (tv == NULL)
{
- CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
goto err;
}
ts=(STACK *)tv->value;
v->section=tv->section;
if (!sk_push(ts,(char *)v))
{
- CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);
+ CONFerr(CONF_F_CONF_LOAD_BIO,
+ ERR_R_MALLOC_FAILURE);
goto err;
}
vv=(CONF_VALUE *)lh_insert(ret,(char *)v);
}
if (buff != NULL) BUF_MEM_free(buff);
if (section != NULL) Free(section);
- if (in != NULL) fclose(in);
return(ret);
err:
if (buff != NULL) BUF_MEM_free(buff);
if (line != NULL) *line=eline;
sprintf(btmp,"%ld",eline);
ERR_add_error_data(2,"line ",btmp);
- if (in != NULL) fclose(in);
if ((h != ret) && (ret != NULL)) CONF_free(ret);
if (v != NULL)
{
}
return(NULL);
}
-
+
char *CONF_get_string(LHASH *conf, char *section, char *name)
{
CONF_VALUE *v,vv;
extern "C" {
#endif
-#include <openssl/stack.h>
+#include <openssl/bio.h>
#include <openssl/lhash.h>
+#include <openssl/stack.h>
typedef struct
{
} CONF_VALUE;
-LHASH *CONF_load(LHASH *conf,char *file,long *eline);
+LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
+LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
+LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
STACK *CONF_get_section(LHASH *conf,char *section);
char *CONF_get_string(LHASH *conf,char *group,char *name);
long CONF_get_number(LHASH *conf,char *group,char *name);
/* Function codes. */
#define CONF_F_CONF_LOAD 100
+#define CONF_F_CONF_LOAD_BIO 102
+#define CONF_F_CONF_LOAD_FP 103
#define CONF_F_STR_COPY 101
/* Reason codes. */
static ERR_STRING_DATA CONF_str_functs[]=
{
{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
+{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
+{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
{0,NULL}
};
BIO_new_bio_pair 1802
BIO_ctrl_get_write_guarantee 1803
CRYPTO_num_locks 1804
+CONF_load_bio 1805
+CONF_load_fp 1806