Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Cryptographic API. |
| 3 | * |
| 4 | * Partial (de)compression operations. |
| 5 | * |
| 6 | * Copyright 2008 Sony Corporation |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. |
| 19 | * If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/crypto.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/seq_file.h> |
| 26 | #include <linux/string.h> |
Steffen Klassert | a55465d | 2011-09-27 07:46:32 +0200 | [diff] [blame] | 27 | #include <linux/cryptouser.h> |
| 28 | #include <net/netlink.h> |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 29 | |
| 30 | #include <crypto/compress.h> |
Geert Uytterhoeven | 2f6ceb7 | 2009-03-29 15:45:30 +0800 | [diff] [blame] | 31 | #include <crypto/internal/compress.h> |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 32 | |
| 33 | #include "internal.h" |
| 34 | |
| 35 | |
| 36 | static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
Herbert Xu | 2ca33da | 2009-07-13 20:46:25 +0800 | [diff] [blame] | 41 | static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm) |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
Herbert Xu | 3acc847 | 2011-11-03 23:46:07 +1100 | [diff] [blame] | 46 | #ifdef CONFIG_NET |
Steffen Klassert | a55465d | 2011-09-27 07:46:32 +0200 | [diff] [blame] | 47 | static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg) |
| 48 | { |
| 49 | struct crypto_report_comp rpcomp; |
| 50 | |
Mathias Krause | 9a5467b | 2013-02-05 18:19:13 +0100 | [diff] [blame] | 51 | strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type)); |
David S. Miller | 6662df3 | 2012-04-01 20:19:05 -0400 | [diff] [blame] | 52 | if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS, |
| 53 | sizeof(struct crypto_report_comp), &rpcomp)) |
| 54 | goto nla_put_failure; |
Steffen Klassert | a55465d | 2011-09-27 07:46:32 +0200 | [diff] [blame] | 55 | return 0; |
| 56 | |
| 57 | nla_put_failure: |
| 58 | return -EMSGSIZE; |
| 59 | } |
Herbert Xu | 3acc847 | 2011-11-03 23:46:07 +1100 | [diff] [blame] | 60 | #else |
| 61 | static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg) |
| 62 | { |
| 63 | return -ENOSYS; |
| 64 | } |
| 65 | #endif |
Steffen Klassert | a55465d | 2011-09-27 07:46:32 +0200 | [diff] [blame] | 66 | |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 67 | static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg) |
| 68 | __attribute__ ((unused)); |
| 69 | static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg) |
| 70 | { |
| 71 | seq_printf(m, "type : pcomp\n"); |
| 72 | } |
| 73 | |
| 74 | static const struct crypto_type crypto_pcomp_type = { |
Herbert Xu | f7c9beb | 2015-04-20 13:39:02 +0800 | [diff] [blame] | 75 | .extsize = crypto_alg_extsize, |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 76 | .init = crypto_pcomp_init, |
| 77 | .init_tfm = crypto_pcomp_init_tfm, |
| 78 | #ifdef CONFIG_PROC_FS |
| 79 | .show = crypto_pcomp_show, |
| 80 | #endif |
Steffen Klassert | a55465d | 2011-09-27 07:46:32 +0200 | [diff] [blame] | 81 | .report = crypto_pcomp_report, |
Geert Uytterhoeven | a1d2f09 | 2009-03-04 15:05:33 +0800 | [diff] [blame] | 82 | .maskclear = ~CRYPTO_ALG_TYPE_MASK, |
| 83 | .maskset = CRYPTO_ALG_TYPE_MASK, |
| 84 | .type = CRYPTO_ALG_TYPE_PCOMPRESS, |
| 85 | .tfmsize = offsetof(struct crypto_pcomp, base), |
| 86 | }; |
| 87 | |
| 88 | struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type, |
| 89 | u32 mask) |
| 90 | { |
| 91 | return crypto_alloc_tfm(alg_name, &crypto_pcomp_type, type, mask); |
| 92 | } |
| 93 | EXPORT_SYMBOL_GPL(crypto_alloc_pcomp); |
| 94 | |
| 95 | int crypto_register_pcomp(struct pcomp_alg *alg) |
| 96 | { |
| 97 | struct crypto_alg *base = &alg->base; |
| 98 | |
| 99 | base->cra_type = &crypto_pcomp_type; |
| 100 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; |
| 101 | base->cra_flags |= CRYPTO_ALG_TYPE_PCOMPRESS; |
| 102 | |
| 103 | return crypto_register_alg(base); |
| 104 | } |
| 105 | EXPORT_SYMBOL_GPL(crypto_register_pcomp); |
| 106 | |
| 107 | int crypto_unregister_pcomp(struct pcomp_alg *alg) |
| 108 | { |
| 109 | return crypto_unregister_alg(&alg->base); |
| 110 | } |
| 111 | EXPORT_SYMBOL_GPL(crypto_unregister_pcomp); |
| 112 | |
| 113 | MODULE_LICENSE("GPL"); |
| 114 | MODULE_DESCRIPTION("Partial (de)compression type"); |
| 115 | MODULE_AUTHOR("Sony Corporation"); |