summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/g/dcrypto/rsa.c13
-rw-r--r--common/util.c15
-rw-r--r--include/util.h5
3 files changed, 20 insertions, 13 deletions
diff --git a/chip/g/dcrypto/rsa.c b/chip/g/dcrypto/rsa.c
index 9d854e7533..5107773a30 100644
--- a/chip/g/dcrypto/rsa.c
+++ b/chip/g/dcrypto/rsa.c
@@ -297,19 +297,6 @@ static int check_pkcs1_type1_pad(const uint8_t *msg, uint32_t msg_len,
return memcmp(msg, &padded[i], hash_size) == 0;
}
-static void reverse(uint8_t *start, size_t len)
-{
- int i;
- uint8_t *end = start + len;
-
- for (i = 0; i < len / 2; ++i) {
- uint8_t tmp = *start;
-
- *start++ = *--end;
- *end = tmp;
- }
-}
-
static int check_modulus_params(const struct BIGNUM *N, uint32_t *out_len)
{
if (bn_size(N) > RSA_MAX_BYTES)
diff --git a/common/util.c b/common/util.c
index 2b745e8621..9df5b5596f 100644
--- a/common/util.c
+++ b/common/util.c
@@ -305,6 +305,21 @@ void *memmove(void *dest, const void *src, size_t len)
}
+void reverse(void *dest, size_t len)
+{
+ int i;
+ uint8_t *start = dest;
+ uint8_t *end = start + len;
+
+ for (i = 0; i < len / 2; ++i) {
+ uint8_t tmp = *start;
+
+ *start++ = *--end;
+ *end = tmp;
+ }
+}
+
+
char *strzcpy(char *dest, const char *src, int len)
{
char *d = dest;
diff --git a/include/util.h b/include/util.h
index d8967ec0c0..fd8f5d40c9 100644
--- a/include/util.h
+++ b/include/util.h
@@ -146,6 +146,11 @@ int uint64divmod(uint64_t *v, int by);
*/
int get_next_bit(uint32_t *mask);
+/**
+ * Reverse's the byte-order of the provided buffer.
+ */
+void reverse(void *dest, size_t len);
+
/****************************************************************************/
/* Conditional stuff.