summaryrefslogtreecommitdiff
path: root/chip/g/dcrypto/internal.h
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2015-12-08 21:07:54 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-01-11 22:03:13 -0800
commit7a254e9851e37a5473efb8e61059d47b52bcee76 (patch)
treef37e151d293b26962f79234b6103d5245e4f4d0b /chip/g/dcrypto/internal.h
parent4368dcfb32942740dd11188de6a8658cdd448a5a (diff)
downloadchrome-ec-stabilize-7821.B.tar.gz
Initial RSA implementation.stabilize-7821.B
Includes support for encrypt / decrypt, and sign / verify; padding schemes OAEP / PKCS1; supporting bignum library. RSA key sizes must be a multiple of 32-bits (with the top bit set). Keying material, input and output buffers are required to be word-aligned. BRANCH=none TEST=added encrypt/decrypt sign/verify tests, compatibility with openssl tested BUG=chrome-os-partner:43025,chrome-os-partner:47524 Change-Id: I6bc324c651e3178bb45bb75ab5935d9bc07efbce Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/316942 Commit-Ready: Marius Schilder <mschilder@chromium.org> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org>
Diffstat (limited to 'chip/g/dcrypto/internal.h')
-rw-r--r--chip/g/dcrypto/internal.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/chip/g/dcrypto/internal.h b/chip/g/dcrypto/internal.h
index 3be8a406a7..8757ab5e86 100644
--- a/chip/g/dcrypto/internal.h
+++ b/chip/g/dcrypto/internal.h
@@ -12,6 +12,9 @@
#include "sha1.h"
#include "sha256.h"
+/*
+ * SHA.
+ */
#define CTRL_CTR_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define CTRL_ENABLE 1
#define CTRL_ENCRYPT 1
@@ -79,4 +82,27 @@ void dcrypto_sha_update(struct HASH_CTX *unused,
const uint8_t *data, uint32_t n);
void dcrypto_sha_wait(enum sha_mode mode, uint32_t *digest);
+/*
+ * BIGNUM.
+ */
+#define BN_BITS2 32
+#define BN_BYTES 4
+
+struct BIGNUM {
+ uint32_t dmax; /* Size of d, in 32-bit words. */
+ uint32_t *d; /* Word array, little endian format ... */
+};
+
+void bn_init(struct BIGNUM *bn, void *buf, size_t len);
+#define bn_size(b) ((b)->dmax * BN_BYTES)
+int bn_check_topbit(const struct BIGNUM *N);
+void bn_mont_modexp(struct BIGNUM *output, const struct BIGNUM *input,
+ const struct BIGNUM *exp, const struct BIGNUM *N);
+
+/*
+ * Utility functions.
+ */
+/* TODO(ngm): memset that doesn't get optimized out. */
+#define dcrypto_memset(p, b, len) memset((p), (b), (len))
+
#endif /* ! __EC_CHIP_G_DCRYPTO_INTERNAL_H */