summaryrefslogtreecommitdiff
path: root/include/rsa.h
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2014-11-11 10:19:38 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-15 06:00:02 +0000
commitb63b0d70f53ac1e6f500da0b10ac66d96299a22b (patch)
tree2544d109f1a8d954aad70782c17bb7777b0c8c3d /include/rsa.h
parent9de2ef515fd8c534e6ff4dddee0c2b9f5ec012f2 (diff)
downloadchrome-ec-b63b0d70f53ac1e6f500da0b10ac66d96299a22b.tar.gz
rsa: add support for 4096 and 8192 bit keys
Allow to use larger RSA keys by setting CONFIG_RSA_KEY_SIZE to 4096 or 8192 rather than using the default 2048-bit size. It's mainly for benchmarking purpose right now as we don't have the RAM to store the 3x key size buffer and the flash space for the public key structure. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=samus BUG=none TEST=build Zinger with CONFIG_RSA_KEY_SIZE equals to 4096 and run it. Change-Id: I9839121bf158d0a30dde1e48d875f345191bfec2 Reviewed-on: https://chromium-review.googlesource.com/228925 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/rsa.h')
-rw-r--r--include/rsa.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/include/rsa.h b/include/rsa.h
index 95e17450c6..dbf00fa13f 100644
--- a/include/rsa.h
+++ b/include/rsa.h
@@ -6,12 +6,38 @@
#ifndef _INCLUDE_RSA_H
#define _INCLUDE_RSA_H
-#include "common.h"
+#include "config.h"
+
+#ifndef CONFIG_RSA_KEY_SIZE
+#define CONFIG_RSA_KEY_SIZE 2048 /* default to 2048-bit key length */
+#endif
-#define RSANUMBYTES 256 /* 2048 bit key length */
+#define RSANUMBYTES ((CONFIG_RSA_KEY_SIZE)/8)
#define RSANUMWORDS (RSANUMBYTES / sizeof(uint32_t))
-/* 2048-bit RSA public key definition */
+#ifdef CONFIG_RSA /* reserve space for public key only if used */
+/*
+ * The size of the public key structure is
+ * 2 x RSANUMBYTES for n and rr fields
+ * plus 4 for n0inv, aligned on a multiple of 16
+ * Put numerical constants here to please the linker script.
+ */
+#if CONFIG_RSA_KEY_SIZE == 2048
+#define RSA_PUBLIC_KEY_SIZE 528
+#elif CONFIG_RSA_KEY_SIZE == 4096
+#define RSA_PUBLIC_KEY_SIZE 1040
+#elif CONFIG_RSA_KEY_SIZE == 8192
+#define RSA_PUBLIC_KEY_SIZE 2064
+#else
+#error Unsupported RSA key size
+#endif
+#endif /* CONFIG_RSA */
+
+#ifndef __ASSEMBLER__
+
+#include "common.h"
+
+/* RSA public key definition */
struct rsa_public_key {
uint32_t n[RSANUMWORDS]; /* modulus as little endian array */
uint32_t rr[RSANUMWORDS]; /* R^2 as little endian array */
@@ -23,4 +49,6 @@ int rsa_verify(const struct rsa_public_key *key,
const uint8_t *sha,
uint32_t *workbuf32);
+#endif /* !__ASSEMBLER__ */
+
#endif /* _INCLUDE_RSA_H */