Index: openssl-0.9.7c/crypto/evp/evp.h
===================================================================
--- openssl-0.9.7c/crypto/evp/evp.h	(revision 2349)
+++ openssl-0.9.7c/crypto/evp/evp.h	(working copy)
@@ -441,6 +441,7 @@
 	unsigned char enc_data[80];	/* data to encode */
 	int line_num;	/* number read on current line */
 	int expect_nl;
+	int crlf_eol;	/* Terminate lines with \r\n sequence instead of \n */
 	} EVP_ENCODE_CTX;
 
 /* Password based encryption function */
Index: openssl-0.9.7c/crypto/evp/bio_b64.c
===================================================================
--- openssl-0.9.7c/crypto/evp/bio_b64.c	(revision 2349)
+++ openssl-0.9.7c/crypto/evp/bio_b64.c	(working copy)
@@ -356,6 +356,8 @@
 		ctx->buf_off=0;
 		ctx->tmp_len=0;
 		EVP_EncodeInit(&(ctx->base64));
+		if (BIO_get_flags(b) & BIO_FLAGS_BASE64_CRLF)
+			ctx->base64.crlf_eol=1;
 		}
 
 	n=ctx->buf_len-ctx->buf_off;
Index: openssl-0.9.7c/crypto/evp/encode.c
===================================================================
--- openssl-0.9.7c/crypto/evp/encode.c	(revision 2349)
+++ openssl-0.9.7c/crypto/evp/encode.c	(working copy)
@@ -126,6 +126,7 @@
 	ctx->length=48;
 	ctx->num=0;
 	ctx->line_num=0;
+	ctx->crlf_eol=0;
 	}
 
 void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
@@ -152,6 +153,11 @@
 		j=EVP_EncodeBlock(out,ctx->enc_data,ctx->length);
 		ctx->num=0;
 		out+=j;
+		if (ctx->crlf_eol)
+			{
+			*(out++)='\r';
+			j++;
+			}
 		*(out++)='\n';
 		*out='\0';
 		total=j+1;
@@ -162,6 +168,11 @@
 		in+=ctx->length;
 		inl-=ctx->length;
 		out+=j;
+		if (ctx->crlf_eol)
+			{
+			*(out++)='\r';
+			j++;
+			}
 		*(out++)='\n';
 		*out='\0';
 		total+=j+1;
@@ -179,6 +190,8 @@
 	if (ctx->num != 0)
 		{
 		ret=EVP_EncodeBlock(out,ctx->enc_data,ctx->num);
+		if (ctx->crlf_eol)
+			out[ret++]='\r';
 		out[ret++]='\n';
 		out[ret]='\0';
 		ctx->num=0;
@@ -226,6 +239,7 @@
 	ctx->num=0;
 	ctx->line_num=0;
 	ctx->expect_nl=0;
+	ctx->crlf_eol=0;
 	}
 
 /* -1 for error
Index: openssl-0.9.7c/crypto/bio/bio.h
===================================================================
--- openssl-0.9.7c/crypto/bio/bio.h	(revision 2349)
+++ openssl-0.9.7c/crypto/bio/bio.h	(working copy)
@@ -157,6 +157,9 @@
  */
 #define BIO_FLAGS_MEM_RDONLY	0x200
 
+/* This causes lines to be terminated with \r\n sequence */
+#define BIO_FLAGS_BASE64_CRLF	0x400
+
 #define BIO_set_flags(b,f) ((b)->flags|=(f))
 #define BIO_get_flags(b) ((b)->flags)
 #define BIO_set_retry_special(b) \
@@ -203,7 +206,7 @@
 /* The callback is called before and after the underling operation,
  * The BIO_CB_RETURN flag indicates if it is after the call */
 #define BIO_CB_RETURN	0x80
-#define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
+#define BIO_CB_return(a) ((a)|BIO_CB_RETURN)
 #define BIO_cb_pre(a)	(!((a)&BIO_CB_RETURN))
 #define BIO_cb_post(a)	((a)&BIO_CB_RETURN)
 
