From patchwork Thu Jun 1 08:22:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Eremin-Solenikov X-Patchwork-Id: 100828 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp697160qge; Thu, 1 Jun 2017 01:32:53 -0700 (PDT) X-Received: by 10.55.77.208 with SMTP id a199mr247162qkb.251.1496305973881; Thu, 01 Jun 2017 01:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496305973; cv=none; d=google.com; s=arc-20160816; b=dcuFWB/jK35XAOeIR9IqAgCt8rxf5aE/USpjMja1H1Z6Kh3fEJO76VlmLMdhQLErba sZkGW6REcjNppJGYzxuIO58pOcOMnGGyMzYpGWdKXykT4IRdp7SDJ/7kpDT8n8k+CCJb y/pO5m/FwsLfh4kKmoqBRxGgwOwferXwyCQ9MoMXr/RqOfaNP0UNbf88OFvjlaAb/LZ0 DTHNn61KKa29o5yecevvC1jSDVlnvaH0rEvhVYWcgvTymvNjacol3qj7+YsqdhxkPfiQ Ab0unkbjT6k0HTpwMNuxB6ncdEvPxP5rZlZzQ21L/gawj4Op8UQtcnr7dfdvjslMZq+I SeeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=RpqaW/Z3jJoNerz+esYO/HNQh1sky5GPpoYQrFQ9YoQ=; b=ybTvU+c3+ggzxS4GLHEgpeEZE/0zLbQzIBsj3nnetbn1qYdP/lfxTyqxDTVtUTd8SA yF/qKhMFJZ/QdHicUi6IuxjzlrBetxwzkla3TXZJcPq32xAxqBwA/5HVS1MNRVyZljy4 0UNCEPDgQ/dWUlHcJmUwZnZFLvqpwvZHG6MowMyptARFJKZ1SS59nqy+Eor4LsyT6SAR GxkBgt8JhGAQk5ZCS9KXzU0m4HDe/4zNunEzgf83L77H6PVB69+Rr+3XYx//AnRZvTBw NZk5h4qAIWu4cS6NGzIEJCTrqpK40+bGUXXYn4w2JUgjs2I7zl6VJ5qvKi8yIU0+Swfl liTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e1si18537277qkf.42.2017.06.01.01.32.53; Thu, 01 Jun 2017 01:32:53 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 8D86660670; Thu, 1 Jun 2017 08:32:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 96B3B60D7F; Thu, 1 Jun 2017 08:25:28 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D152D60C0C; Thu, 1 Jun 2017 08:25:23 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id F186460D3A for ; Thu, 1 Jun 2017 08:23:35 +0000 (UTC) Received: by mail-lf0-f50.google.com with SMTP id 99so22040428lfu.1 for ; Thu, 01 Jun 2017 01:23:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RpqaW/Z3jJoNerz+esYO/HNQh1sky5GPpoYQrFQ9YoQ=; b=f12PSHfKcrTKA+F9d7KtxLI+X8Q7z1aNnL7qflQuwbJf2+KE1MB94tjO1yhAQLE0mH OdoNTVLB0ZorifCtiPY/NI6xlXRbr52Gv3Px7cnyVQS/9PrG40u13G8Kvqrq3BTfIwve Oniw63RPOXcJMOjB6z6JAc1+vm5FavK0dLTDudh+boX9gZuLuM83gcxheeAQ43s/br9U g1TyNM9qYH5ZLbMT2kfAgda6OteOHAsZGER+4CdQNj7Av959+v60mriYUDB0SaTOR4SK rxlcsyNAfOQ6oUI26xrx3lGj59qgH5V/OnOKdbsyhCr2/ckycwxnLRoJx39Ww2THTn02 Kidg== X-Gm-Message-State: AODbwcAdnbv6dAmkl4Bkr0fp2stGTxHgQjWiKQ5yYVOTW2JFN2epZ1Wz 40q7qoXYLYCSxojxi2sB5yMP X-Received: by 10.25.15.30 with SMTP id e30mr131787lfi.10.1496305414604; Thu, 01 Jun 2017 01:23:34 -0700 (PDT) Received: from forlindon.lumag.auriga.ru ([188.162.64.12]) by smtp.gmail.com with ESMTPSA id c78sm4185837lfh.25.2017.06.01.01.23.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 01:23:33 -0700 (PDT) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Thu, 1 Jun 2017 11:22:51 +0300 Message-Id: <20170601082320.4673-12-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601082320.4673-1-dmitry.ereminsolenikov@linaro.org> References: <20170601082320.4673-1-dmitry.ereminsolenikov@linaro.org> Subject: [lng-odp] [PATCH 07/23] linux: crypto: update AES-GCM support to reflect aad and auth_digest_len X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Make AES-GCM use recently introduced aad and auth_digest_len fields. Signed-off-by: Dmitry Eremin-Solenikov --- platform/linux-generic/odp_crypto.c | 58 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 43 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 91ef05aebadf..352cfa536268 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -267,10 +267,8 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, { uint8_t *data = odp_packet_data(param->out_pkt); uint32_t plain_len = param->cipher_range.length; - uint8_t *aad_head = data + param->auth_range.offset; - uint8_t *aad_tail = data + param->cipher_range.offset + - param->cipher_range.length; - uint32_t auth_len = param->auth_range.length; + const uint8_t *aad_head = param->aad.ptr; + uint32_t aad_len = param->aad.length; unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -282,12 +280,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID; - /* All cipher data must be part of the authentication */ - if (param->auth_range.offset > param->cipher_range.offset || - param->auth_range.offset + auth_len < - param->cipher_range.offset + plain_len) - return ODP_CRYPTO_ALG_ERR_DATA_SIZE; - /* * Create a copy of the IV. The DES library modifies IV * and if we are processing packets on parallel threads @@ -305,23 +297,16 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); /* Authenticate header data (if any) without encrypting them */ - if (aad_head < plaindata) { + if (aad_len > 0) EVP_EncryptUpdate(ctx, NULL, &cipher_len, - aad_head, plaindata - aad_head); - } + aad_head, aad_len); EVP_EncryptUpdate(ctx, plaindata, &cipher_len, plaindata, plain_len); - cipher_len = plain_len; - - /* Authenticate footer data (if any) without encrypting them */ - if (aad_head + auth_len > plaindata + plain_len) { - EVP_EncryptUpdate(ctx, NULL, NULL, aad_tail, - auth_len - (aad_tail - aad_head)); - } EVP_EncryptFinal_ex(ctx, plaindata + cipher_len, &cipher_len); - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, + session->p.auth_digest_len, tag); return ODP_CRYPTO_ALG_ERR_NONE; } @@ -332,10 +317,8 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, { uint8_t *data = odp_packet_data(param->out_pkt); uint32_t cipher_len = param->cipher_range.length; - uint8_t *aad_head = data + param->auth_range.offset; - uint8_t *aad_tail = data + param->cipher_range.offset + - param->cipher_range.length; - uint32_t auth_len = param->auth_range.length; + const uint8_t *aad_head = param->aad.ptr; + uint32_t aad_len = param->aad.length; unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -347,12 +330,6 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID; - /* All cipher data must be part of the authentication */ - if (param->auth_range.offset > param->cipher_range.offset || - param->auth_range.offset + auth_len < - param->cipher_range.offset + cipher_len) - return ODP_CRYPTO_ALG_ERR_DATA_SIZE; - /* * Create a copy of the IV. The DES library modifies IV * and if we are processing packets on parallel threads @@ -368,25 +345,18 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, + session->p.auth_digest_len, tag); /* Authenticate header data (if any) without encrypting them */ - if (aad_head < cipherdata) { + if (aad_len > 0) EVP_DecryptUpdate(ctx, NULL, &plain_len, - aad_head, cipherdata - aad_head); - } + aad_head, aad_len); EVP_DecryptUpdate(ctx, cipherdata, &plain_len, cipherdata, cipher_len); - plain_len = cipher_len; - - /* Authenticate footer data (if any) without encrypting them */ - if (aad_head + auth_len > cipherdata + cipher_len) { - EVP_DecryptUpdate(ctx, NULL, NULL, aad_tail, - auth_len - (aad_tail - aad_head)); - } - if (EVP_DecryptFinal_ex(ctx, cipherdata + cipher_len, &plain_len) <= 0) + if (EVP_DecryptFinal_ex(ctx, cipherdata + plain_len, &plain_len) <= 0) return ODP_CRYPTO_ALG_ERR_ICV_CHECK; return ODP_CRYPTO_ALG_ERR_NONE; @@ -770,6 +740,8 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_AES128_GCM: if (param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM) aes_gcm = 1; + /* Fixed digest tag length with deprecated algo */ + session->p.auth_digest_len = 16; /* Fallthrough */ #endif case ODP_AUTH_ALG_AES_GCM: