From dce63c8bfc0eb0d389aa3a7836ac03df9438a527 Mon Sep 17 00:00:00 2001 From: vtarasov Date: Sun, 29 May 2011 17:47:54 +0000 Subject: [PATCH] libopensc: new exported function to reverse memory buffer git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5516 c6295689-39f2-0310-b995-f0e70906c6a9 --- src/libopensc/libopensc.exports | 1 + src/libopensc/opensc.h | 1 + src/libopensc/sc.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/libopensc/libopensc.exports b/src/libopensc/libopensc.exports index 8449c67f..28143df9 100644 --- a/src/libopensc/libopensc.exports +++ b/src/libopensc/libopensc.exports @@ -117,6 +117,7 @@ sc_lock sc_logout sc_make_cache_dir sc_mem_clear +sc_mem_reverse sc_path_print sc_path_set sc_pin_cmd diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index f208c06d..7a81b756 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -1149,6 +1149,7 @@ int sc_base64_decode(const char *in, u8 *out, size_t outlen); */ void sc_mem_clear(void *ptr, size_t len); void *sc_mem_alloc_secure(size_t len); +int sc_mem_reverse(unsigned char *buf, size_t len); int sc_get_cache_dir(sc_context_t *ctx, char *buf, size_t bufsize); int sc_make_cache_dir(sc_context_t *ctx); diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index bd10007f..12565339 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -727,6 +727,23 @@ void sc_mem_clear(void *ptr, size_t len) #endif } +int sc_mem_reverse(unsigned char *buf, size_t len) +{ + unsigned char ch; + size_t ii; + + if (!buf || !len) + return SC_ERROR_INVALID_ARGUMENTS; + + for (ii = 0; ii < len / 2; ii++) { + ch = *(buf + ii); + *(buf + ii) = *(buf + len - 1 - ii); + *(buf + len - 1 - ii) = ch; + } + + return 0; +} + static int sc_remote_apdu_allocate(struct sc_remote_data *rdata, struct sc_remote_apdu **new_rapdu)