summaryrefslogtreecommitdiffstats
path: root/crypto/buffer
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2006-04-10 00:11:30 +0000
committerDr. Stephen Henson <steve@openssl.org>2006-04-10 00:11:30 +0000
commit9befdf1d2072f3366086583462332cf6f2bc1540 (patch)
tree75b7a912df90b997a0d4100a3ef786113b32a5dc /crypto/buffer
parent75d44c0452e8807dcd9dd126390dd8df35c57efa (diff)
New utility function to reverse a buffer, either by copying or in-place.
Diffstat (limited to 'crypto/buffer')
-rw-r--r--crypto/buffer/buffer.c23
-rw-r--r--crypto/buffer/buffer.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/crypto/buffer/buffer.c b/crypto/buffer/buffer.c
index 3bf03c7eff..a7fe5ba54f 100644
--- a/crypto/buffer/buffer.c
+++ b/crypto/buffer/buffer.c
@@ -219,3 +219,26 @@ size_t BUF_strlcat(char *dst, const char *src, size_t size)
l++;
return l + BUF_strlcpy(dst, src, size);
}
+
+void BUF_reverse(unsigned char *out, unsigned char *in, size_t size)
+ {
+ size_t i;
+ if (in)
+ {
+ out += size - 1;
+ for (i = 0; i < size; i++)
+ *in++ = *out--;
+ }
+ else
+ {
+ unsigned char *q;
+ char c;
+ q = out + size - 1;
+ for (i = 0; i < size/2; i++)
+ {
+ c = *q;
+ *q-- = *out;
+ *out++ = c;
+ }
+ }
+ }
diff --git a/crypto/buffer/buffer.h b/crypto/buffer/buffer.h
index 1db9607450..f7acca56ed 100644
--- a/crypto/buffer/buffer.h
+++ b/crypto/buffer/buffer.h
@@ -88,6 +88,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len);
char * BUF_strdup(const char *str);
char * BUF_strndup(const char *str, size_t siz);
void * BUF_memdup(const void *data, size_t siz);
+void BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
/* safe string functions */
size_t BUF_strlcpy(char *dst,const char *src,size_t siz);