From patchwork Mon Jan 4 04:46:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7945441 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A76C0BEEE5 for ; Mon, 4 Jan 2016 04:50:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BDD920382 for ; Mon, 4 Jan 2016 04:50:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B89820361 for ; Mon, 4 Jan 2016 04:50:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752733AbcADEsE (ORCPT ); Sun, 3 Jan 2016 23:48:04 -0500 Received: from mail-pf0-f179.google.com ([209.85.192.179]:33454 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752701AbcADErY (ORCPT ); Sun, 3 Jan 2016 23:47:24 -0500 Received: by mail-pf0-f179.google.com with SMTP id q63so159874199pfb.0; Sun, 03 Jan 2016 20:47:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nbBOn7AdkL1KzYZq9kxUd/c3QubdA++3yQ9Hg+tLfVE=; b=gR177Laj3dAWjAfGd2XCrBXGBTTfQ1lF+ET3HeEVIMAhvqFBOrG576fdu+2svPv7fp pTquD2O0Vs8tJF1fcg4ohLCcnOiow2ddxIgGayaV1QCBc2LOYS49kIWVNdGeSECycNRa wIw339AFFR1K66apARQk1pjF2X+aFxWEpbvaoTVJTPD/HL8GqeBzRAWAs9qAqeY4jiuL Diya4pKl/6Tp3gOk3sOiObu4//iX5zLmfDCn4fJYVSciTpZJcZ5bb6Kw0MhjznKOrUt/ /efc1ip+MONHmzzAFwOBPQrPZO0bx+xjoN6AKjCipqubpoS2AHUJ2idXvuc7WPkubvnv giaQ== X-Received: by 10.98.13.155 with SMTP id 27mr66806848pfn.40.1451882843786; Sun, 03 Jan 2016 20:47:23 -0800 (PST) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id tu9sm122503374pac.0.2016.01.03.20.47.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Jan 2016 20:47:22 -0800 (PST) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Herbert Xu Cc: "David S. Miller" , Weigang Li , Sergey Senozhatsky , Minchan Kim , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Joonsoo Kim Subject: [PATCH RFC 2/7] crypto/compress: introduce sychronuous compression API Date: Mon, 4 Jan 2016 13:46:53 +0900 Message-Id: <1451882819-2810-3-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451882819-2810-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1451882819-2810-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This introduces new compression APIs. Major change is that APIs are stateless. Instead of previous implementation, tfm objects doesn't embedded any context so we can de/compress concurrently with one tfm object. Instead, thsi de/compression context is coupled with the request. This architecture change will make APIs more flexible. Signed-off-by: Joonsoo Kim --- crypto/Kconfig | 5 ++ crypto/Makefile | 1 + crypto/scompress.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ include/crypto/compress.h | 76 +++++++++++++++++++++++++++++++ include/linux/crypto.h | 1 + 5 files changed, 197 insertions(+) create mode 100644 crypto/scompress.c create mode 100644 include/crypto/compress.h diff --git a/crypto/Kconfig b/crypto/Kconfig index c80d34f..7159520 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig @@ -84,6 +84,10 @@ config CRYPTO_RNG_DEFAULT tristate select CRYPTO_DRBG_MENU +config CRYPTO_SCOMPRESS + tristate + select CRYPTO_ALGAPI2 + config CRYPTO_AKCIPHER2 tristate select CRYPTO_ALGAPI2 @@ -1499,6 +1503,7 @@ config CRYPTO_LZO select CRYPTO_ALGAPI select LZO_COMPRESS select LZO_DECOMPRESS + select SCOMPRESS help This is the LZO algorithm. diff --git a/crypto/Makefile b/crypto/Makefile index ffe18c9..16ef796 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -28,6 +28,7 @@ crypto_hash-y += ahash.o crypto_hash-y += shash.o obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o +obj-$(CONFIG_CRYPTO_SCOMPRESS) += scompress.o obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o $(obj)/rsapubkey-asn1.o: $(obj)/rsapubkey-asn1.c $(obj)/rsapubkey-asn1.h diff --git a/crypto/scompress.c b/crypto/scompress.c new file mode 100644 index 0000000..7c9955b --- /dev/null +++ b/crypto/scompress.c @@ -0,0 +1,114 @@ +/* + * Cryptographic API. + * + * Synchronous compression operations. + * + * Copyright 2015 LG Electronics Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. + * If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "internal.h" + + +static int crypto_scomp_init(struct crypto_tfm *tfm, u32 type, u32 mask) +{ + return 0; +} + +static int crypto_scomp_init_tfm(struct crypto_tfm *tfm) +{ + return 0; +} + +#ifdef CONFIG_NET +static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + struct crypto_report_comp rcomp; + + strncpy(rcomp.type, "scomp", sizeof(rcomp.type)); + if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, + sizeof(struct crypto_report_comp), &rcomp)) + goto nla_put_failure; + return 0; + +nla_put_failure: + return -EMSGSIZE; +} +#else +static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg) +{ + return -ENOSYS; +} +#endif + +static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg) + __attribute__ ((unused)); +static void crypto_scomp_show(struct seq_file *m, struct crypto_alg *alg) +{ + seq_puts(m, "type : scomp\n"); +} + +static const struct crypto_type crypto_scomp_type = { + .extsize = crypto_alg_extsize, + .init = crypto_scomp_init, + .init_tfm = crypto_scomp_init_tfm, +#ifdef CONFIG_PROC_FS + .show = crypto_scomp_show, +#endif + .report = crypto_scomp_report, + .maskclear = ~CRYPTO_ALG_TYPE_MASK, + .maskset = CRYPTO_ALG_TYPE_MASK, + .type = CRYPTO_ALG_TYPE_SCOMPRESS, + .tfmsize = offsetof(struct crypto_scomp, base), +}; + +struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type, + u32 mask) +{ + return crypto_alloc_tfm(alg_name, &crypto_scomp_type, type, mask); +} +EXPORT_SYMBOL_GPL(crypto_alloc_scomp); + +int crypto_register_scomp(struct scomp_alg *alg) +{ + struct crypto_alg *base = &alg->base; + + base->cra_type = &crypto_scomp_type; + base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; + base->cra_flags |= CRYPTO_ALG_TYPE_SCOMPRESS; + + return crypto_register_alg(base); +} +EXPORT_SYMBOL_GPL(crypto_register_scomp); + +int crypto_unregister_scomp(struct scomp_alg *alg) +{ + return crypto_unregister_alg(&alg->base); +} +EXPORT_SYMBOL_GPL(crypto_unregister_scomp); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Synchronous compression operations"); +MODULE_AUTHOR("LG Electronics Inc."); + diff --git a/include/crypto/compress.h b/include/crypto/compress.h new file mode 100644 index 0000000..4d89a68 --- /dev/null +++ b/include/crypto/compress.h @@ -0,0 +1,76 @@ +#ifndef _CRYPTO_COMPRESS_H +#define _CRYPTO_COMPRESS_H +#include + +struct crypto_scomp { + struct crypto_tfm base; +}; + +struct scomp_alg { + void *(*alloc_ctx)(struct crypto_scomp *tfm); + void (*free_ctx)(struct crypto_scomp *tfm, void *ctx); + int (*compress)(struct crypto_scomp *tfm, const u8 *src, + unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx); + int (*decompress)(struct crypto_scomp *tfm, const u8 *src, + unsigned int slen, u8 *dst, unsigned int *dlen, void *ctx); + + struct crypto_alg base; +}; + +extern struct crypto_scomp *crypto_alloc_scomp(const char *alg_name, u32 type, + u32 mask); + +static inline struct crypto_tfm *crypto_scomp_tfm(struct crypto_scomp *tfm) +{ + return &tfm->base; +} + +static inline struct crypto_scomp *crypto_scomp_cast(struct crypto_tfm *tfm) +{ + return (struct crypto_scomp *)tfm; +} + +static inline void crypto_free_scomp(struct crypto_scomp *tfm) +{ + crypto_destroy_tfm(tfm, crypto_scomp_tfm(tfm)); +} + +static inline struct scomp_alg *__crypto_scomp_alg(struct crypto_alg *alg) +{ + return container_of(alg, struct scomp_alg, base); +} + +static inline struct scomp_alg *crypto_scomp_alg(struct crypto_scomp *tfm) +{ + return __crypto_scomp_alg(crypto_scomp_tfm(tfm)->__crt_alg); +} + +static inline void *crypto_scomp_alloc_ctx(struct crypto_scomp *tfm) +{ + return crypto_scomp_alg(tfm)->alloc_ctx(tfm); +} + +static inline void crypto_scomp_free_ctx(struct crypto_scomp *tfm, + void *ctx) +{ + return crypto_scomp_alg(tfm)->free_ctx(tfm, ctx); +} + +static inline int crypto_scomp_compress(struct crypto_scomp *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen, void *ctx) +{ + return crypto_scomp_alg(tfm)->compress(tfm, src, slen, dst, dlen, ctx); +} + +static inline int crypto_scomp_decompress(struct crypto_scomp *tfm, + const u8 *src, unsigned int slen, + u8 *dst, unsigned int *dlen, void *ctx) +{ + return crypto_scomp_alg(tfm)->decompress(tfm, src, slen, + dst, dlen, ctx); +} + +extern int crypto_register_scomp(struct scomp_alg *alg); +extern int crypto_unregister_scomp(struct scomp_alg *alg); +#endif diff --git a/include/linux/crypto.h b/include/linux/crypto.h index ab2a745..726df9b 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -54,6 +54,7 @@ #define CRYPTO_ALG_TYPE_AHASH 0x0000000a #define CRYPTO_ALG_TYPE_RNG 0x0000000c #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d +#define CRYPTO_ALG_TYPE_SCOMPRESS 0x0000000e #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e #define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c