summaryrefslogtreecommitdiff
path: root/chip/g/dcrypto/internal.h
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2015-11-19 16:15:35 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-25 11:17:13 -0800
commitae89bb6f49f30186e300e0b60c6384b37da8c72f (patch)
treefccdd5ba91b0481f06f68b81a26c7fd33ce1f76b /chip/g/dcrypto/internal.h
parentf01d71eb5b0ee8f15e2c85e9302c24bc5fe3ebcd (diff)
downloadchrome-ec-ae89bb6f49f30186e300e0b60c6384b37da8c72f.tar.gz
cr50: SHA1 and SHA256 implementation with hardware support
This change includes hardware and software support for SHA1/256 on CR50. When running in the RO image, only hardware sha256 support is included. When running in the RW image, the code auto-selects between the software and hardware implementation. Software implementation path is taken if the hardware is currently in use by some other context. Refactor the CR50 loader to use this abstraction. The existing software implementation for SHA1 and SHA256 is used for the software path. CQ-DEPEND=CL:*239385 BRANCH=none TEST=EC shell boots fine (implies that SHA256 works) BUG=chrome-os-partner:43025 Change-Id: I7bcefc12fcef869dac2e48793bd0cb5ce8e80d5b Signed-off-by: nagendra modadugu <ngm@google.com> Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313011
Diffstat (limited to 'chip/g/dcrypto/internal.h')
-rw-r--r--chip/g/dcrypto/internal.h47
1 files changed, 41 insertions, 6 deletions
diff --git a/chip/g/dcrypto/internal.h b/chip/g/dcrypto/internal.h
index 5eb76ecc8a..279b2798e7 100644
--- a/chip/g/dcrypto/internal.h
+++ b/chip/g/dcrypto/internal.h
@@ -3,19 +3,43 @@
* found in the LICENSE file.
*/
-/*
- * Crypto wrapper library for CR50.
- */
-#ifndef EC_BOARD_CR50_DCRYPTO_INTERNAL_H_
-#define EC_BOARD_CR50_DCRYPTO_INTERNAL_H_
+#ifndef __EC_CHIP_G_DCRYPTO_INTERNAL_H
+#define __EC_CHIP_G_DCRYPTO_INTERNAL_H
+
+#include <inttypes.h>
#include "common.h"
+#include "sha1.h"
+#include "sha256.h"
#define CTRL_CTR_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define CTRL_ENABLE 1
#define CTRL_ENCRYPT 1
#define CTRL_NO_SOFT_RESET 0
+struct HASH_CTX; /* Forward declaration. */
+
+struct HASH_VTAB {
+ void (* const update)(struct HASH_CTX *, const uint8_t *, uint32_t);
+ const uint8_t *(* const final)(struct HASH_CTX *);
+ const uint8_t *(* const hash)(const uint8_t *, uint32_t, uint8_t *);
+ uint32_t size;
+};
+
+struct HASH_CTX {
+ const struct HASH_VTAB *vtab;
+ union {
+ uint8_t buf[64];
+ struct sha1_ctx sw_sha1;
+ struct sha256_ctx sw_sha256;
+ } u;
+};
+
+enum sha_mode {
+ SHA1_MODE = 0,
+ SHA256_MODE = 1
+};
+
/*
* Use this structure to avoid alignment problems with input and output
* pointers.
@@ -24,4 +48,15 @@ struct access_helper {
uint32_t udata;
} __packed;
-#endif /* ! EC_BOARD_CR50_DCRYPTO_INTERNAL_H_ */
+#ifndef SECTION_IS_RO
+int dcrypto_grab_sha_hw(void);
+void dcrypto_release_sha_hw(void);
+#endif
+void dcrypto_sha_hash(enum sha_mode mode, const uint8_t *data,
+ uint32_t n, uint8_t *digest);
+void dcrypto_sha_init(enum sha_mode mode);
+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);
+
+#endif /* ! __EC_CHIP_G_DCRYPTO_INTERNAL_H */