From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 461B7C31E51 for ; Tue, 18 Jun 2019 12:09:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B863208E4 for ; Tue, 18 Jun 2019 12:09:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="LDzajFXW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729346AbfFRMI5 (ORCPT ); Tue, 18 Jun 2019 08:08:57 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:53382 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729242AbfFRMIu (ORCPT ); Tue, 18 Jun 2019 08:08:50 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x5IC8a9h077759; Tue, 18 Jun 2019 07:08:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1560859716; bh=/ijk8DpdTXuEeYYGPNYsSxzYzytlXm+I5jpGlL0+qTk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LDzajFXWXfu3zToEFf0AD9ILaK44jvMl0hVz6HGEZ7eGjIAd9DOLMLuvGRTqH4aGg ntvw+ifK3Du+HTkcxH0fzZi4O/SR2ocb9mlFZ5LXJl7RIj0OH4qeUvSwJc4/T1cOAS jwLWbrTU9Zid6Dmhd244cmiazREK8VhqHPgHHLHQ= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x5IC8a6E118769 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 18 Jun 2019 07:08:36 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 18 Jun 2019 07:08:35 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 18 Jun 2019 07:08:35 -0500 Received: from a0393675ula.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x5IC89Gg080327; Tue, 18 Jun 2019 07:08:33 -0500 From: Keerthy To: , , CC: , , , , , Subject: [PATCH 08/10] crypto: sa2ul: Add hmac(sha256) HMAC algorithm support Date: Tue, 18 Jun 2019 17:38:41 +0530 Message-ID: <20190618120843.18777-9-j-keerthy@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190618120843.18777-1-j-keerthy@ti.com> References: <20190618120843.18777-1-j-keerthy@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org HMAC hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC. Add hmac(sha256) HMAC algorithm support and the message digest size is 32 bytes. Signed-off-by: Keerthy --- drivers/crypto/sa2ul.c | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c index e3a1321f0666..74211cd21c62 100644 --- a/drivers/crypto/sa2ul.c +++ b/drivers/crypto/sa2ul.c @@ -1673,11 +1673,38 @@ static int sa_sham_sha1_setkey(struct crypto_ahash *tfm, const u8 *key, return sa_sham_setkey(tfm, key, keylen, ad); } +static int sa_sham_sha256_setkey(struct crypto_ahash *tfm, const u8 *key, + unsigned int keylen) +{ + struct algo_data *ad = kzalloc(sizeof(*ad), GFP_KERNEL); + + ad->enc_eng.eng_id = SA_ENG_ID_NONE; + ad->enc_eng.sc_size = SA_CTX_ENC_TYPE1_SZ; + ad->auth_eng.eng_id = SA_ENG_ID_AM1; + ad->auth_eng.sc_size = SA_CTX_AUTH_TYPE2_SZ; + ad->mci_enc = NULL; + ad->mci_dec = NULL; + ad->inv_key = false; + ad->keyed_mac = true; + ad->ealg_id = SA_EALG_ID_NONE; + ad->aalg_id = SA_AALG_ID_HMAC_SHA2_256; + ad->hash_size = SHA256_DIGEST_SIZE; + ad->auth_ctrl = 0x4; + ad->prep_iopad = sa_hmac_sha256_get_pad; + + return sa_sham_setkey(tfm, key, keylen, ad); +} + static int sa_sham_cra_sha1_init(struct crypto_tfm *tfm) { return sa_sham_cra_init_alg(tfm, "sha1"); } +static int sa_sham_cra_sha256_init(struct crypto_tfm *tfm) +{ + return sa_sham_cra_init_alg(tfm, "sha256"); +} + static void sa_sham_cra_exit(struct crypto_tfm *tfm) { struct crypto_alg *alg = tfm->__crt_alg; @@ -1839,6 +1866,31 @@ static struct ahash_alg algs_sha[] = { .cra_exit = sa_sham_cra_exit, } }, +{ + .init = sa_sham_init, + .update = sa_sham_update, + .final = sa_sham_final, + .finup = sa_sham_finup, + .digest = sa_sham_digest, + .setkey = sa_sham_sha256_setkey, + .halg.digestsize = SHA256_DIGEST_SIZE, + .halg.statesize = 128, + .halg.base = { + .cra_name = "hmac(sha256)", + .cra_driver_name = "sa-hmac-sha256", + .cra_priority = 400, + .cra_flags = CRYPTO_ALG_TYPE_AHASH | + CRYPTO_ALG_ASYNC | + CRYPTO_ALG_KERN_DRIVER_ONLY | + CRYPTO_ALG_NEED_FALLBACK, + .cra_blocksize = SHA256_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct sa_tfm_ctx), + .cra_alignmask = SA_ALIGN_MASK, + .cra_module = THIS_MODULE, + .cra_init = sa_sham_cra_sha256_init, + .cra_exit = sa_sham_cra_exit, + } +}, }; /* Register the algorithms in crypto framework */ -- 2.17.1