11/*
22 * talitos - Freescale Integrated Security Engine (SEC) device driver
33 *
4- * Copyright (c) 2008 Freescale Semiconductor, Inc.
4+ * Copyright (c) 2008-2010 Freescale Semiconductor, Inc.
55 *
66 * Scatterlist Crypto API glue code copied from files with the following:
77 * Copyright (c) 2006-2007 Herbert Xu <herbert@gondor.apana.org.au>
@@ -156,6 +156,7 @@ struct talitos_private {
156156/* .features flag */
157157#define TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT 0x00000001
158158#define TALITOS_FTR_HW_AUTH_CHECK 0x00000002
159+ #define TALITOS_FTR_SHA224_HWINIT 0x00000004
159160
160161static void to_talitos_ptr (struct talitos_ptr * talitos_ptr , dma_addr_t dma_addr )
161162{
@@ -720,10 +721,11 @@ struct talitos_ctx {
720721
721722struct talitos_ahash_req_ctx {
722723 u64 count ;
723- u8 hw_context [TALITOS_MDEU_MAX_CONTEXT_SIZE ];
724+ u32 hw_context [TALITOS_MDEU_MAX_CONTEXT_SIZE / sizeof ( u32 ) ];
724725 unsigned int hw_context_size ;
725726 u8 buf [HASH_MAX_BLOCK_SIZE ];
726727 u8 bufnext [HASH_MAX_BLOCK_SIZE ];
728+ unsigned int swinit ;
727729 unsigned int first ;
728730 unsigned int last ;
729731 unsigned int to_hash_later ;
@@ -1631,12 +1633,13 @@ static int common_nonsnoop_hash(struct talitos_edesc *edesc,
16311633 /* first DWORD empty */
16321634 desc -> ptr [0 ] = zero_entry ;
16331635
1634- /* hash context in (if not first) */
1635- if (!req_ctx -> first ) {
1636+ /* hash context in */
1637+ if (!req_ctx -> first || req_ctx -> swinit ) {
16361638 map_single_talitos_ptr (dev , & desc -> ptr [1 ],
16371639 req_ctx -> hw_context_size ,
16381640 (char * )req_ctx -> hw_context , 0 ,
16391641 DMA_TO_DEVICE );
1642+ req_ctx -> swinit = 0 ;
16401643 } else {
16411644 desc -> ptr [1 ] = zero_entry ;
16421645 /* Indicate next op is not the first. */
@@ -1722,7 +1725,8 @@ static int ahash_init(struct ahash_request *areq)
17221725
17231726 /* Initialize the context */
17241727 req_ctx -> count = 0 ;
1725- req_ctx -> first = 1 ; /* first indicates h/w must init it's context */
1728+ req_ctx -> first = 1 ; /* first indicates h/w must init its context */
1729+ req_ctx -> swinit = 0 ; /* assume h/w init of context */
17261730 req_ctx -> hw_context_size =
17271731 (crypto_ahash_digestsize (tfm ) <= SHA256_DIGEST_SIZE )
17281732 ? TALITOS_MDEU_CONTEXT_SIZE_MD5_SHA1_SHA256
@@ -1731,6 +1735,33 @@ static int ahash_init(struct ahash_request *areq)
17311735 return 0 ;
17321736}
17331737
1738+ /*
1739+ * on h/w without explicit sha224 support, we initialize h/w context
1740+ * manually with sha224 constants, and tell it to run sha256.
1741+ */
1742+ static int ahash_init_sha224_swinit (struct ahash_request * areq )
1743+ {
1744+ struct talitos_ahash_req_ctx * req_ctx = ahash_request_ctx (areq );
1745+
1746+ ahash_init (areq );
1747+ req_ctx -> swinit = 1 ;/* prevent h/w initting context with sha256 values*/
1748+
1749+ req_ctx -> hw_context [0 ] = cpu_to_be32 (SHA224_H0 );
1750+ req_ctx -> hw_context [1 ] = cpu_to_be32 (SHA224_H1 );
1751+ req_ctx -> hw_context [2 ] = cpu_to_be32 (SHA224_H2 );
1752+ req_ctx -> hw_context [3 ] = cpu_to_be32 (SHA224_H3 );
1753+ req_ctx -> hw_context [4 ] = cpu_to_be32 (SHA224_H4 );
1754+ req_ctx -> hw_context [5 ] = cpu_to_be32 (SHA224_H5 );
1755+ req_ctx -> hw_context [6 ] = cpu_to_be32 (SHA224_H6 );
1756+ req_ctx -> hw_context [7 ] = cpu_to_be32 (SHA224_H7 );
1757+
1758+ /* init 64-bit count */
1759+ req_ctx -> hw_context [8 ] = 0 ;
1760+ req_ctx -> hw_context [9 ] = 0 ;
1761+
1762+ return 0 ;
1763+ }
1764+
17341765static int ahash_process_req (struct ahash_request * areq , unsigned int nbytes )
17351766{
17361767 struct crypto_ahash * tfm = crypto_ahash_reqtfm (areq );
@@ -1799,8 +1830,8 @@ static int ahash_process_req(struct ahash_request *areq, unsigned int nbytes)
17991830 else
18001831 edesc -> desc .hdr |= DESC_HDR_MODE0_MDEU_CONT ;
18011832
1802- /* On first one, request SEC to INIT hash. */
1803- if (req_ctx -> first )
1833+ /* request SEC to INIT hash. */
1834+ if (req_ctx -> first && ! req_ctx -> swinit )
18041835 edesc -> desc .hdr |= DESC_HDR_MODE0_MDEU_INIT ;
18051836
18061837 /* When the tfm context has a keylen, it's an HMAC.
@@ -1843,8 +1874,9 @@ static int ahash_finup(struct ahash_request *areq)
18431874static int ahash_digest (struct ahash_request * areq )
18441875{
18451876 struct talitos_ahash_req_ctx * req_ctx = ahash_request_ctx (areq );
1877+ struct crypto_ahash * ahash = crypto_ahash_reqtfm (areq );
18461878
1847- ahash_init (areq );
1879+ ahash -> init (areq );
18481880 req_ctx -> last = 1 ;
18491881
18501882 return ahash_process_req (areq , areq -> nbytes );
@@ -2109,6 +2141,27 @@ static struct talitos_alg_template driver_algs[] = {
21092141 DESC_HDR_SEL0_MDEUA |
21102142 DESC_HDR_MODE0_MDEU_SHA1 ,
21112143 },
2144+ { .type = CRYPTO_ALG_TYPE_AHASH ,
2145+ .alg .hash = {
2146+ .init = ahash_init ,
2147+ .update = ahash_update ,
2148+ .final = ahash_final ,
2149+ .finup = ahash_finup ,
2150+ .digest = ahash_digest ,
2151+ .halg .digestsize = SHA224_DIGEST_SIZE ,
2152+ .halg .base = {
2153+ .cra_name = "sha224" ,
2154+ .cra_driver_name = "sha224-talitos" ,
2155+ .cra_blocksize = SHA224_BLOCK_SIZE ,
2156+ .cra_flags = CRYPTO_ALG_TYPE_AHASH |
2157+ CRYPTO_ALG_ASYNC ,
2158+ .cra_type = & crypto_ahash_type
2159+ }
2160+ },
2161+ .desc_hdr_template = DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
2162+ DESC_HDR_SEL0_MDEUA |
2163+ DESC_HDR_MODE0_MDEU_SHA224 ,
2164+ },
21122165 { .type = CRYPTO_ALG_TYPE_AHASH ,
21132166 .alg .hash = {
21142167 .init = ahash_init ,
@@ -2298,6 +2351,7 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
22982351 struct talitos_alg_template
22992352 * template )
23002353{
2354+ struct talitos_private * priv = dev_get_drvdata (dev );
23012355 struct talitos_crypto_alg * t_alg ;
23022356 struct crypto_alg * alg ;
23032357
@@ -2319,6 +2373,14 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
23192373 case CRYPTO_ALG_TYPE_AHASH :
23202374 alg = & t_alg -> algt .alg .hash .halg .base ;
23212375 alg -> cra_init = talitos_cra_init_ahash ;
2376+ if (!(priv -> features & TALITOS_FTR_SHA224_HWINIT ) &&
2377+ !strcmp (alg -> cra_name , "sha224" )) {
2378+ t_alg -> algt .alg .hash .init = ahash_init_sha224_swinit ;
2379+ t_alg -> algt .desc_hdr_template =
2380+ DESC_HDR_TYPE_COMMON_NONSNOOP_NO_AFEU |
2381+ DESC_HDR_SEL0_MDEUA |
2382+ DESC_HDR_MODE0_MDEU_SHA256 ;
2383+ }
23222384 break ;
23232385 }
23242386
@@ -2406,7 +2468,8 @@ static int talitos_probe(struct of_device *ofdev,
24062468 priv -> features |= TALITOS_FTR_SRC_LINK_TBL_LEN_INCLUDES_EXTENT ;
24072469
24082470 if (of_device_is_compatible (np , "fsl,sec2.1" ))
2409- priv -> features |= TALITOS_FTR_HW_AUTH_CHECK ;
2471+ priv -> features |= TALITOS_FTR_HW_AUTH_CHECK |
2472+ TALITOS_FTR_SHA224_HWINIT ;
24102473
24112474 priv -> chan = kzalloc (sizeof (struct talitos_channel ) *
24122475 priv -> num_channels , GFP_KERNEL );
0 commit comments