From patchwork Mon Oct 7 12:12:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 20855 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97B5424697 for ; Mon, 7 Oct 2013 12:14:14 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id db12sf15651742veb.6 for ; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=7/nHFLSawwNTk7t/IKnIoh7Z1ehxx9WF8/sGVcEnaIw=; b=musXQI26HR2CcbuyVxJJI6llPufNmzupRNk08rfkmE1+PFpnL3x7zgmjb/32l7Vf9E AArI924PlrgjOXF62X4bHHWCooPG1pZ4MiCQ2NEK9qNnjBk8BDkMjdWdLXo6LDI7DIPF 639fZtFJ0jvFKjdcbGpGnvqUq0CYdGG9ogf14QSZ9tbLyQiYnhkMN/nwC22bGQh7cxtw sPepRmuWceBzCRHDMqWelPN6ZJvYnzMDP8pbzoLWJB0rCZm6kYlhsDFePmcF5UdYCmEY jHnFofA7YUci+CzoYnRx2j2SoBNISxAFsC31T3Csdw5k300LyYMlbtqIxvypWqVvkGcn TckA== X-Received: by 10.236.69.35 with SMTP id m23mr25568878yhd.6.1381148054407; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.35.194 with SMTP id k2ls842728qej.45.gmail; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) X-Received: by 10.220.94.206 with SMTP id a14mr1458766vcn.19.1381148054273; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by mx.google.com with ESMTPS id qf5si7721491vec.68.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Oct 2013 05:14:14 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.46; Received: by mail-vb0-f46.google.com with SMTP id p13so3310211vbe.5 for ; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) X-Gm-Message-State: ALoCoQnr2TB9U9UfZet+u2UI05LaW40OFDhyQB0ONS4P50ydutzB57omZhaSAxsKQlKtjYblA7Jq X-Received: by 10.52.32.37 with SMTP id f5mr21678469vdi.17.1381148054143; Mon, 07 Oct 2013 05:14:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp120358vcz; Mon, 7 Oct 2013 05:14:13 -0700 (PDT) X-Received: by 10.180.73.134 with SMTP id l6mr18939007wiv.16.1381148052522; Mon, 07 Oct 2013 05:14:12 -0700 (PDT) Received: from mail-we0-f174.google.com (mail-we0-f174.google.com [74.125.82.174]) by mx.google.com with ESMTPS id a5si11097930wjb.10.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Oct 2013 05:14:12 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.174 is neither permitted nor denied by best guess record for domain of ard.biesheuvel@linaro.org) client-ip=74.125.82.174; Received: by mail-we0-f174.google.com with SMTP id u56so3582445wes.33 for ; Mon, 07 Oct 2013 05:14:12 -0700 (PDT) X-Received: by 10.194.104.42 with SMTP id gb10mr24190324wjb.16.1381148052096; Mon, 07 Oct 2013 05:14:12 -0700 (PDT) Received: from ards-mac-mini.local ([83.153.85.71]) by mx.google.com with ESMTPSA id ma3sm38759714wic.1.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Oct 2013 05:14:11 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, nico@linaro.org, patches@linaro.org, Ard Biesheuvel Subject: [RFC PATCH 3/5] ARM64: add Crypto Extensions based synchronous core AES cipher Date: Mon, 7 Oct 2013 14:12:29 +0200 Message-Id: <1381147951-7609-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1381147951-7609-1-git-send-email-ard.biesheuvel@linaro.org> References: <1381147951-7609-1-git-send-email-ard.biesheuvel@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This implements the core AES cipher using the Crypto Extensions, using only NEON register q0 and q1. Signed-off-by: Ard Biesheuvel --- arch/arm64/crypto/Makefile | 5 +++ arch/arm64/crypto/aes-sync.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 arch/arm64/crypto/aes-sync.c diff --git a/arch/arm64/crypto/Makefile b/arch/arm64/crypto/Makefile index f87ec80..e598c0a 100644 --- a/arch/arm64/crypto/Makefile +++ b/arch/arm64/crypto/Makefile @@ -9,3 +9,8 @@ # obj-y += aesce-emu.o + +ifeq ($(CONFIG_KERNEL_MODE_SYNC_CE_CRYPTO),y) +aesce-sync-y := aes-sync.o +obj-m += aesce-sync.o +endif diff --git a/arch/arm64/crypto/aes-sync.c b/arch/arm64/crypto/aes-sync.c new file mode 100644 index 0000000..5c5d641 --- /dev/null +++ b/arch/arm64/crypto/aes-sync.c @@ -0,0 +1,95 @@ +/* + * linux/arch/arm64/crypto/aes-sync.c + * + * Copyright (C) 2013 Linaro Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include + +static void aes_cipher_encrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[]) +{ + struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); + int rounds = 6 + ctx->key_length / 4; + + __asm__(" .arch armv8-a+crypto \n\t" + " ld1 {v0.16b}, [%[in]] \n\t" + " ld1 {v1.16b}, [%[key]], #16 \n\t" + "0: aese v0.16b, v1.16b \n\t" + " subs %[rounds], %[rounds], #1 \n\t" + " ld1 {v1.16b}, [%[key]], #16 \n\t" + " beq 1f \n\t" + " aesmc v0.16b, v0.16b \n\t" + " b 0b \n\t" + "1: eor v0.16b, v0.16b, v1.16b \n\t" + " st1 {v0.16b}, [%[out]] \n\t" + : : + [out] "r"(dst), + [in] "r"(src), + [rounds] "r"(rounds), + [key] "r"(ctx->key_enc)); +} + +static void aes_cipher_decrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[]) +{ + struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm); + int rounds = 6 + ctx->key_length / 4; + + __asm__(" .arch armv8-a+crypto \n\t" + " ld1 {v0.16b}, [%[in]] \n\t" + " ld1 {v1.16b}, [%[key]], #16 \n\t" + "0: aesd v0.16b, v1.16b \n\t" + " ld1 {v1.16b}, [%[key]], #16 \n\t" + " subs %[rounds], %[rounds], #1 \n\t" + " beq 1f \n\t" + " aesimc v0.16b, v0.16b \n\t" + " b 0b \n\t" + "1: eor v0.16b, v0.16b, v1.16b \n\t" + " st1 {v0.16b}, [%[out]] \n\t" + : : + [out] "r"(dst), + [in] "r"(src), + [rounds] "r"(rounds), + [key] "r"(ctx->key_dec)); +} + +static struct crypto_alg aes_alg = { + .cra_name = "aes", + .cra_driver_name = "aes-ce", + .cra_priority = 300, + .cra_flags = CRYPTO_ALG_TYPE_CIPHER, + .cra_blocksize = AES_BLOCK_SIZE, + .cra_ctxsize = sizeof(struct crypto_aes_ctx), + .cra_module = THIS_MODULE, + .cra_cipher = { + .cia_min_keysize = AES_MIN_KEY_SIZE, + .cia_max_keysize = AES_MAX_KEY_SIZE, + .cia_setkey = crypto_aes_set_key, + .cia_encrypt = aes_cipher_encrypt, + .cia_decrypt = aes_cipher_decrypt + } +}; + +static int __init aes_mod_init(void) +{ + if (0) // TODO check for crypto extensions + return -ENODEV; + return crypto_register_alg(&aes_alg); +} + +static void __exit aes_mod_exit(void) +{ + crypto_unregister_alg(&aes_alg); +} + +module_init(aes_mod_init); +module_exit(aes_mod_exit); + +MODULE_DESCRIPTION("Synchronous AES using ARMv8 Crypto Extensions"); +MODULE_AUTHOR("Ard Biesheuvel "); +MODULE_LICENSE("GPL");