summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2016-07-09 15:09:16 -0400
committerFranklin Wei <frankhwei536@gmail.com>2016-07-09 15:09:52 -0400
commit5fc1b86d596778cf65c844eac2d36f607c870598 (patch)
treecb72fcad3e86732217e4162afc540aaa6f68d543 /apps/plugins/lib
parent2716c64cba0c0772ff9b0064a04710d999b95610 (diff)
downloadrockbox-5fc1b86d596778cf65c844eac2d36f607c870598.zip
rockbox-5fc1b86d596778cf65c844eac2d36f607c870598.tar.gz
rockbox-5fc1b86d596778cf65c844eac2d36f607c870598.tar.bz2
rockbox-5fc1b86d596778cf65c844eac2d36f607c870598.tar.xz
support static passwords, hardware-accelerated AES, SHA1
Change-Id: Iacb1ac768741f40a7b3ed39eb820bb228bbabd0a
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/sha1.c53
-rw-r--r--apps/plugins/lib/sha1.h14
2 files changed, 62 insertions, 5 deletions
diff --git a/apps/plugins/lib/sha1.c b/apps/plugins/lib/sha1.c
index fc0a136..2457716 100644
--- a/apps/plugins/lib/sha1.c
+++ b/apps/plugins/lib/sha1.c
@@ -111,6 +111,10 @@ sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
digest. */
void *sha1_buffer (const char *buffer, size_t len, void *resblock)
{
+#if CONFIG_CPU == S5L8702 && !defined(SIMULATOR)
+ rb->s5l8702_sha1((char*)buffer, len, resblock);
+ return resblock;
+#else
struct sha1_ctx ctx;
/* Initialize the computation context. */
@@ -121,6 +125,7 @@ void *sha1_buffer (const char *buffer, size_t len, void *resblock)
/* Put result in desired memory area. */
return sha1_finish_ctx (&ctx, resblock);
+#endif
}
void
@@ -396,11 +401,7 @@ hmac_sha1 (const void *key, size_t keylen,
if (keylen > 64)
{
- struct sha1_ctx keyhash;
-
- sha1_init_ctx (&keyhash);
- sha1_process_bytes (key, keylen, &keyhash);
- sha1_finish_ctx (&keyhash, optkeybuf);
+ sha1_buffer(key, keylen, optkeybuf);
key = optkeybuf;
keylen = 20;
@@ -484,3 +485,45 @@ void hmac_sha1_finish_ctx(struct hmac_ctx *ctx, void *resbuf)
sha1_finish_ctx (&ctx->outer, resbuf);
}
+
+#if CONFIG_CPU == S5L8702 && !defined(SIMULATOR)
+
+/* HACK ALERT!!! */
+/* in must point to 64 bytes into region of at least 64 + MAX(inlen, 20) bytes */
+/* trades logic for speed */
+/* will overwrite in */
+/* can operate in-place (in = resbuf) */
+int
+hmac_sha1_hwaccel (const void *key, size_t keylen,
+ void *in, size_t inlen, void *resbuf)
+{
+ char optkeybuf[20];
+ char *block = in - 64;
+
+ /* Reduce the key's size, so that it becomes <= 64 bytes large. */
+
+ if (keylen > 64)
+ {
+ rb->s5l8702_sha1((void*)key, keylen, optkeybuf);
+
+ key = optkeybuf;
+ keylen = 20;
+ }
+
+ /* Compute INNERHASH from KEY and IN. */
+
+ memset (block, IPAD, 64);
+ memxor (block, key, keylen);
+
+ rb->s5l8702_sha1(block, 64 + inlen, in); // 64 bytes past block is `in'
+
+ /* Compute result from KEY and INNERHASH. */
+
+ memset (block, OPAD, 64);
+ memxor (block, key, keylen);
+
+ rb->s5l8702_sha1(block, 64 + 20, resbuf);
+
+ return 0;
+}
+#endif
diff --git a/apps/plugins/lib/sha1.h b/apps/plugins/lib/sha1.h
index b98b2d3..2d066fa 100644
--- a/apps/plugins/lib/sha1.h
+++ b/apps/plugins/lib/sha1.h
@@ -76,6 +76,9 @@ void *sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf);
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
+
+// Rockbox-specific: on S5L8702, uses internal SHA1 accelerator
+
void *sha1_buffer (const char *buffer, size_t len, void *resblock);
#endif
@@ -127,4 +130,15 @@ void hmac_sha1_init(struct hmac_ctx *ctx, const void *key, size_t keylen);
void hmac_sha1_process_bytes(struct hmac_ctx *ctx, const void *in, size_t inlen);
void hmac_sha1_finish_ctx(struct hmac_ctx *ctx, void *resbuf);
+/* HACK ALERT!!! */
+/* in must point to 64 bytes into region of at least 64 + MAX(inlen, 20) bytes */
+/* trades logic for speed */
+/* will overwrite in */
+/* can operate in-place (in = resbuf) */
+#if CONFIG_CPU == S5L8702 && !defined(SIMULATOR)
+int
+hmac_sha1_hwaccel (const void *key, size_t keylen,
+ void *in, size_t inlen, void *resbuf);
+#endif
+
#endif /* HMAC_H */