2 * Copyright 2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
14 #define CRYPTO_MAX_ALG_NAME 80
15 #define SHA1_DIGEST_SIZE 20
16 #define SHA256_DIGEST_SIZE 32
18 struct caam_hash_template {
19 char name[CRYPTO_MAX_ALG_NAME];
20 unsigned int digestsize;
24 enum caam_hash_algos {
29 static struct caam_hash_template driver_hash[] = {
32 .digestsize = SHA1_DIGEST_SIZE,
33 .alg_type = OP_ALG_ALGSEL_SHA1,
37 .digestsize = SHA256_DIGEST_SIZE,
38 .alg_type = OP_ALG_ALGSEL_SHA256,
42 int caam_hash(const unsigned char *pbuf, unsigned int buf_len,
43 unsigned char *pout, enum caam_hash_algos algo)
48 desc = malloc(sizeof(int) * MAX_CAAM_DESCSIZE);
50 debug("Not enough memory for descriptor allocation\n");
54 inline_cnstr_jobdesc_hash(desc, pbuf, buf_len, pout,
55 driver_hash[algo].alg_type,
56 driver_hash[algo].digestsize,
59 ret = run_descriptor_jr(desc);
65 void hw_sha256(const unsigned char *pbuf, unsigned int buf_len,
66 unsigned char *pout, unsigned int chunk_size)
68 if (caam_hash(pbuf, buf_len, pout, SHA256))
69 printf("CAAM was not setup properly or it is faulty\n");
72 void hw_sha1(const unsigned char *pbuf, unsigned int buf_len,
73 unsigned char *pout, unsigned int chunk_size)
75 if (caam_hash(pbuf, buf_len, pout, SHA1))
76 printf("CAAM was not setup properly or it is faulty\n");