Index: openssl-0.9.7c/crypto/evp/bio_crlf.c
===================================================================
--- openssl-0.9.7c/crypto/evp/bio_crlf.c	(revision 0)
+++ openssl-0.9.7c/crypto/evp/bio_crlf.c	(revision 0)
@@ -0,0 +1,153 @@
+#include <stdio.h>
+#include <errno.h>
+#include "cryptlib.h"
+#include <openssl/buffer.h>
+#include <openssl/evp.h>
+
+static int crlf_write(BIO *h, const char *buf, int num);
+static int crlf_read(BIO *h, char *buf, int size);
+static int crlf_gets(BIO *h, char *buf, int size);
+static long crlf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
+static int crlf_new(BIO *h);
+static int crlf_free(BIO *data);
+static long crlf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp);
+
+static BIO_METHOD methods_crlf=
+	{
+	BIO_TYPE_CRLF_FILTER,
+	"CRLF Filter",
+	crlf_write,
+	crlf_read,
+	NULL,
+	crlf_gets,
+	crlf_ctrl,
+	crlf_new,
+	crlf_free,
+	crlf_callback_ctrl,
+	};
+
+
+
+
+BIO_METHOD *BIO_f_crlf(void)
+{
+	return(&methods_crlf);
+}
+
+static int crlf_new(BIO *bi)
+{
+	bi->init=1;
+	bi->flags=0;
+	bi->ptr = NULL;
+	
+	return(1);
+}
+
+static int crlf_free(BIO *a)
+{
+	if (a == NULL) return(0);
+/*      a->ptr=NULL;
+        a->init=0;
+        a->flags=0;*/
+	return(1);
+	}
+
+static int crlf_read(BIO *b, char *out, int outl)
+{
+	int ret=0;
+
+	if (out == NULL) return(0);
+	if (b->next_bio == NULL) return(0);
+	ret=BIO_read(b->next_bio,out,outl);
+	BIO_clear_retry_flags(b);
+	BIO_copy_next_retry(b);
+	return(ret);
+}	
+
+static int crlf_write(BIO *b, const char *in, int inl)
+{
+	int ret=inl, i;
+	char *start, *end;
+	int left;
+	char cr = '\r', lf = '\n';
+
+	if ((in == NULL) || (inl <= 0)) return(0);
+	if (b->next_bio == NULL) return(0);
+	
+	BIO_clear_retry_flags(b);
+	start = in;
+	left = inl;
+	while (end = memchr(start, lf, left))
+	{
+		i = BIO_write(b->next_bio, start, end - start);
+		if (i <= 0) {
+			BIO_copy_next_retry(b);
+			return(i);
+        }
+		i = BIO_write(b->next_bio, &cr, 1);
+		if (i <= 0) {
+			BIO_copy_next_retry(b);
+			return(i);
+        }
+		i = BIO_write(b->next_bio, &lf, 1);
+		if (i <= 0) {
+			BIO_copy_next_retry(b);
+			return(i);
+        }
+
+		left -= end - start + 1;
+		start = end + 1;
+	}
+
+	if (left > 0) {
+		i = BIO_write(b->next_bio, start, left);
+		if (i <= 0) {
+			BIO_copy_next_retry(b);
+			return(i);
+		}
+	}
+	return(ret);
+}
+
+static long crlf_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+	long ret;
+
+	if (b->next_bio == NULL) return(0);
+	switch(cmd)
+			{
+	case BIO_C_DO_STATE_MACHINE:
+			BIO_clear_retry_flags(b);
+			ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+			BIO_copy_next_retry(b);
+			break;
+	case BIO_CTRL_DUP:
+			ret=0L;
+			break;
+	default:
+			ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+			}
+	return(ret);
+}
+
+static long crlf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+	long ret=1;
+
+	if (b->next_bio == NULL) return(0);
+	switch (cmd)
+	{
+		default:
+			ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+		break;
+	}
+	return(ret);
+}
+
+static int crlf_gets(BIO *bp, char *buf, int size)
+{
+	if (bp->next_bio == NULL) return(0);
+	return(BIO_gets(bp->next_bio,buf,size));
+}
+
+
Index: openssl-0.9.7c/crypto/evp/Makefile.ssl
===================================================================
--- openssl-0.9.7c/crypto/evp/Makefile.ssl	(revision 2349)
+++ openssl-0.9.7c/crypto/evp/Makefile.ssl	(working copy)
@@ -31,7 +31,7 @@
 	m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
 	m_dss.c m_dss1.c m_mdc2.c m_ripemd.c \
 	p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
-	bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
+	bio_md.c bio_b64.c bio_crlf.c bio_enc.c evp_err.c e_null.c \
 	c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
 	evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c
 
@@ -42,7 +42,7 @@
 	m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
 	m_dss.o m_dss1.o m_mdc2.o m_ripemd.o \
 	p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
-	bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
+	bio_md.o bio_b64.o bio_crlf.o bio_enc.o evp_err.o e_null.o \
 	c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
 	evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o
 
@@ -120,6 +120,7 @@
 bio_b64.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
 bio_b64.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
 bio_b64.o: ../cryptlib.h bio_b64.c
+bio_crlf.o: ../cryptlib.h bio_crlf.c
 bio_enc.o: ../../e_os.h ../../include/openssl/aes.h
 bio_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
 bio_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
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)
@@ -93,6 +93,7 @@
 #define BIO_TYPE_BER		(18|0x0200)		/* BER -> bin filter */
 #define BIO_TYPE_BIO		(19|0x0400)		/* (half a) BIO pair */
 #define BIO_TYPE_LINEBUFFER	(20|0x0200)		/* filter */
+#define BIO_TYPE_CRLF_FILTER	(21|0x0200)		/* filter */
 
 #define BIO_TYPE_DESCRIPTOR	0x0100	/* socket, fd, connect or accept */
 #define BIO_TYPE_FILTER		0x0200
