platform: msm_shared: Add support for sha1 crypto algo in LK

CRs-Fixed: 574457
Change-Id: I86a4b1466d3d36d4d49ff04b238a18bf89e4413d
diff --git a/platform/msm_shared/crypto5_eng.c b/platform/msm_shared/crypto5_eng.c
index 17fbf88..3f21845 100644
--- a/platform/msm_shared/crypto5_eng.c
+++ b/platform/msm_shared/crypto5_eng.c
@@ -321,12 +321,22 @@
 
 static uint32_t crypto5_get_sha_cfg(void *ctx_ptr, crypto_auth_alg_type auth_alg)
 {
-   crypto_SHA256_ctx *sha256_ctx = (crypto_SHA256_ctx *) ctx_ptr;
-   uint32_t seg_cfg_val;
+	crypto_SHA256_ctx *sha256_ctx = (crypto_SHA256_ctx *) ctx_ptr;
+	crypto_SHA1_ctx *sha1_ctx = (crypto_SHA1_ctx *) ctx_ptr;
+	uint32_t seg_cfg_val;
 
-   seg_cfg_val = SEG_CFG_AUTH_ALG_SHA;
+	seg_cfg_val = SEG_CFG_AUTH_ALG_SHA;
 
-	if (auth_alg == CRYPTO_AUTH_ALG_SHA256)
+	if (auth_alg == CRYPTO_AUTH_ALG_SHA1)
+	{
+		seg_cfg_val |= SEG_CFG_AUTH_SIZE_SHA1;
+
+		if (sha1_ctx->flags & CRYPTO_LAST_CHUNK)
+		{
+			seg_cfg_val |= SEG_CFG_LAST;
+		}
+	}
+	else if (auth_alg == CRYPTO_AUTH_ALG_SHA256)
 	{
 		seg_cfg_val |= SEG_CFG_AUTH_SIZE_SHA256;
 
@@ -364,13 +374,13 @@
 		iv_len = SHA256_INIT_VECTOR_SIZE;
 	}
 
-    seg_cfg_val = crypto5_get_sha_cfg(ctx_ptr, auth_alg);
+	seg_cfg_val = crypto5_get_sha_cfg(ctx_ptr, auth_alg);
 
-    if (!seg_cfg_val)
-    {
+	if (!seg_cfg_val)
+	{
 		dprintf(CRITICAL, "Authentication alg config failed.\n");
 		return;
-    }
+	}
 
 	/* Initialize CE pointers. */
 	REG_WRITE_QUEUE_INIT(dev);
@@ -379,13 +389,13 @@
 	REG_WRITE_QUEUE(dev, CRYPTO_ENCR_SEG_CFG(dev->base), 0);
 	REG_WRITE_QUEUE(dev, CRYPTO_AUTH_SEG_CFG(dev->base), seg_cfg_val);
 
-    for (i = 0; i < iv_len; i++)
-    {
+	for (i = 0; i < iv_len; i++)
+	{
 		if (sha256_ctx->flags & CRYPTO_FIRST_CHUNK)
 			REG_WRITE_QUEUE(dev, CRYPTO_AUTH_IVn(dev->base, i), BE32(*(auth_iv + i)));
 		else
 			REG_WRITE_QUEUE(dev, CRYPTO_AUTH_IVn(dev->base, i), (*(auth_iv + i)));
-    }
+	}
 
 	/* Typecast with crypto_SHA1_ctx because offset of auth_bytecnt
 	 * in both crypto_SHA1_ctx and crypto_SHA256_ctx are same.
@@ -393,7 +403,6 @@
 	REG_WRITE_QUEUE(dev, CRYPTO_AUTH_BYTECNTn(dev->base, 0), ((crypto_SHA1_ctx *) ctx_ptr)->auth_bytecnt[0]);
 	REG_WRITE_QUEUE(dev, CRYPTO_AUTH_BYTECNTn(dev->base, 1), ((crypto_SHA1_ctx *) ctx_ptr)->auth_bytecnt[1]);
 }
-
 /* Function: crypto5_set_auth_cfg
  * Arg     : dev, ptr to data buffer, buffer_size, burst_mask for alignment
  * Return  : aligned buffer incase of unaligned data_ptr and total no. of bytes
diff --git a/platform/msm_shared/crypto_hash.c b/platform/msm_shared/crypto_hash.c
index 50d4a17..0d3cce8 100644
--- a/platform/msm_shared/crypto_hash.c
+++ b/platform/msm_shared/crypto_hash.c
@@ -50,7 +50,7 @@
 	crypto_result_type ret_val = CRYPTO_SHA_ERR_NONE;
 	crypto_engine_type platform_ce_type = board_ce_type();
 
-	if (auth_alg == 1) {
+	if (auth_alg == CRYPTO_AUTH_ALG_SHA1) {
 		if(platform_ce_type == CRYPTO_ENGINE_TYPE_SW)
 			/* Hardware CE is not present , use software hashing */
 			digest = SHA1(addr, size, digest);
@@ -58,7 +58,7 @@
 			ret_val = crypto_sha1(addr, size, digest);
 		else
 			ret_val = CRYPTO_SHA_ERR_FAIL;
-	} else if (auth_alg == 2) {
+	} else if (auth_alg == CRYPTO_AUTH_ALG_SHA256) {
 		if(platform_ce_type == CRYPTO_ENGINE_TYPE_SW)
 			/* Hardware CE is not present , use software hashing */
 			digest = SHA256(addr, size, digest);
@@ -67,6 +67,8 @@
 		else
 		ret_val = CRYPTO_SHA_ERR_FAIL;
 	}
+	else
+		ret_val = CRYPTO_SHA_ERR_FAIL;
 
 	if (ret_val != CRYPTO_SHA_ERR_NONE) {
 		dprintf(CRITICAL, "crypto_sha256 returns error %d\n", ret_val);
diff --git a/platform/msm_shared/include/crypto_hash.h b/platform/msm_shared/include/crypto_hash.h
index 800ebaf..bdcf7e0 100644
--- a/platform/msm_shared/include/crypto_hash.h
+++ b/platform/msm_shared/include/crypto_hash.h
@@ -71,17 +71,18 @@
 	unsigned int auth_bytecnt[2];
 	unsigned char saved_buff[64];
 	unsigned char saved_buff_indx;
-	unsigned int auth_iv[5];
+	uint32_t bytes_to_write;
 	uint32_t flags;
+	unsigned int auth_iv[5];
 } crypto_SHA1_ctx;
 
 typedef struct {
 	unsigned int auth_bytecnt[2];
 	unsigned char saved_buff[64];
 	unsigned char saved_buff_indx;
-	unsigned int auth_iv[8];
 	uint32_t bytes_to_write;
 	uint32_t flags;
+	unsigned int auth_iv[8];
 } crypto_SHA256_ctx;
 
 extern void crypto_eng_reset(void);