diff options
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/deflate.c | 61 | ||||
| -rw-r--r-- | crypto/testmgr.c | 10 | ||||
| -rw-r--r-- | crypto/testmgr.h | 75 |
3 files changed, 129 insertions, 17 deletions
diff --git a/crypto/deflate.c b/crypto/deflate.c index f942cb391890..94ec3b36a8e8 100644 --- a/crypto/deflate.c +++ b/crypto/deflate.c | |||
| @@ -43,20 +43,24 @@ struct deflate_ctx { | |||
| 43 | struct z_stream_s decomp_stream; | 43 | struct z_stream_s decomp_stream; |
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | static int deflate_comp_init(struct deflate_ctx *ctx) | 46 | static int deflate_comp_init(struct deflate_ctx *ctx, int format) |
| 47 | { | 47 | { |
| 48 | int ret = 0; | 48 | int ret = 0; |
| 49 | struct z_stream_s *stream = &ctx->comp_stream; | 49 | struct z_stream_s *stream = &ctx->comp_stream; |
| 50 | 50 | ||
| 51 | stream->workspace = vzalloc(zlib_deflate_workspacesize( | 51 | stream->workspace = vzalloc(zlib_deflate_workspacesize( |
| 52 | -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL)); | 52 | MAX_WBITS, MAX_MEM_LEVEL)); |
| 53 | if (!stream->workspace) { | 53 | if (!stream->workspace) { |
| 54 | ret = -ENOMEM; | 54 | ret = -ENOMEM; |
| 55 | goto out; | 55 | goto out; |
| 56 | } | 56 | } |
| 57 | ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED, | 57 | if (format) |
| 58 | -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL, | 58 | ret = zlib_deflateInit(stream, 3); |
| 59 | Z_DEFAULT_STRATEGY); | 59 | else |
| 60 | ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED, | ||
| 61 | -DEFLATE_DEF_WINBITS, | ||
| 62 | DEFLATE_DEF_MEMLEVEL, | ||
| 63 | Z_DEFAULT_STRATEGY); | ||
| 60 | if (ret != Z_OK) { | 64 | if (ret != Z_OK) { |
| 61 | ret = -EINVAL; | 65 | ret = -EINVAL; |
| 62 | goto out_free; | 66 | goto out_free; |
| @@ -68,7 +72,7 @@ out_free: | |||
| 68 | goto out; | 72 | goto out; |
| 69 | } | 73 | } |
| 70 | 74 | ||
| 71 | static int deflate_decomp_init(struct deflate_ctx *ctx) | 75 | static int deflate_decomp_init(struct deflate_ctx *ctx, int format) |
| 72 | { | 76 | { |
| 73 | int ret = 0; | 77 | int ret = 0; |
| 74 | struct z_stream_s *stream = &ctx->decomp_stream; | 78 | struct z_stream_s *stream = &ctx->decomp_stream; |
| @@ -78,7 +82,10 @@ static int deflate_decomp_init(struct deflate_ctx *ctx) | |||
| 78 | ret = -ENOMEM; | 82 | ret = -ENOMEM; |
| 79 | goto out; | 83 | goto out; |
| 80 | } | 84 | } |
| 81 | ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS); | 85 | if (format) |
| 86 | ret = zlib_inflateInit(stream); | ||
| 87 | else | ||
| 88 | ret = zlib_inflateInit2(stream, -DEFLATE_DEF_WINBITS); | ||
| 82 | if (ret != Z_OK) { | 89 | if (ret != Z_OK) { |
| 83 | ret = -EINVAL; | 90 | ret = -EINVAL; |
| 84 | goto out_free; | 91 | goto out_free; |
| @@ -102,21 +109,21 @@ static void deflate_decomp_exit(struct deflate_ctx *ctx) | |||
| 102 | vfree(ctx->decomp_stream.workspace); | 109 | vfree(ctx->decomp_stream.workspace); |
| 103 | } | 110 | } |
| 104 | 111 | ||
| 105 | static int __deflate_init(void *ctx) | 112 | static int __deflate_init(void *ctx, int format) |
| 106 | { | 113 | { |
| 107 | int ret; | 114 | int ret; |
| 108 | 115 | ||
| 109 | ret = deflate_comp_init(ctx); | 116 | ret = deflate_comp_init(ctx, format); |
| 110 | if (ret) | 117 | if (ret) |
| 111 | goto out; | 118 | goto out; |
| 112 | ret = deflate_decomp_init(ctx); | 119 | ret = deflate_decomp_init(ctx, format); |
| 113 | if (ret) | 120 | if (ret) |
| 114 | deflate_comp_exit(ctx); | 121 | deflate_comp_exit(ctx); |
| 115 | out: | 122 | out: |
| 116 | return ret; | 123 | return ret; |
| 117 | } | 124 | } |
| 118 | 125 | ||
| 119 | static void *deflate_alloc_ctx(struct crypto_scomp *tfm) | 126 | static void *gen_deflate_alloc_ctx(struct crypto_scomp *tfm, int format) |
| 120 | { | 127 | { |
| 121 | struct deflate_ctx *ctx; | 128 | struct deflate_ctx *ctx; |
| 122 | int ret; | 129 | int ret; |
| @@ -125,7 +132,7 @@ static void *deflate_alloc_ctx(struct crypto_scomp *tfm) | |||
| 125 | if (!ctx) | 132 | if (!ctx) |
| 126 | return ERR_PTR(-ENOMEM); | 133 | return ERR_PTR(-ENOMEM); |
| 127 | 134 | ||
| 128 | ret = __deflate_init(ctx); | 135 | ret = __deflate_init(ctx, format); |
| 129 | if (ret) { | 136 | if (ret) { |
| 130 | kfree(ctx); | 137 | kfree(ctx); |
| 131 | return ERR_PTR(ret); | 138 | return ERR_PTR(ret); |
| @@ -134,11 +141,21 @@ static void *deflate_alloc_ctx(struct crypto_scomp *tfm) | |||
| 134 | return ctx; | 141 | return ctx; |
| 135 | } | 142 | } |
| 136 | 143 | ||
| 144 | static void *deflate_alloc_ctx(struct crypto_scomp *tfm) | ||
| 145 | { | ||
| 146 | return gen_deflate_alloc_ctx(tfm, 0); | ||
| 147 | } | ||
| 148 | |||
| 149 | static void *zlib_deflate_alloc_ctx(struct crypto_scomp *tfm) | ||
| 150 | { | ||
| 151 | return gen_deflate_alloc_ctx(tfm, 1); | ||
| 152 | } | ||
| 153 | |||
| 137 | static int deflate_init(struct crypto_tfm *tfm) | 154 | static int deflate_init(struct crypto_tfm *tfm) |
| 138 | { | 155 | { |
| 139 | struct deflate_ctx *ctx = crypto_tfm_ctx(tfm); | 156 | struct deflate_ctx *ctx = crypto_tfm_ctx(tfm); |
| 140 | 157 | ||
| 141 | return __deflate_init(ctx); | 158 | return __deflate_init(ctx, 0); |
| 142 | } | 159 | } |
| 143 | 160 | ||
| 144 | static void __deflate_exit(void *ctx) | 161 | static void __deflate_exit(void *ctx) |
| @@ -272,7 +289,7 @@ static struct crypto_alg alg = { | |||
| 272 | .coa_decompress = deflate_decompress } } | 289 | .coa_decompress = deflate_decompress } } |
| 273 | }; | 290 | }; |
| 274 | 291 | ||
| 275 | static struct scomp_alg scomp = { | 292 | static struct scomp_alg scomp[] = { { |
| 276 | .alloc_ctx = deflate_alloc_ctx, | 293 | .alloc_ctx = deflate_alloc_ctx, |
| 277 | .free_ctx = deflate_free_ctx, | 294 | .free_ctx = deflate_free_ctx, |
| 278 | .compress = deflate_scompress, | 295 | .compress = deflate_scompress, |
| @@ -282,7 +299,17 @@ static struct scomp_alg scomp = { | |||
| 282 | .cra_driver_name = "deflate-scomp", | 299 | .cra_driver_name = "deflate-scomp", |
| 283 | .cra_module = THIS_MODULE, | 300 | .cra_module = THIS_MODULE, |
| 284 | } | 301 | } |
| 285 | }; | 302 | }, { |
| 303 | .alloc_ctx = zlib_deflate_alloc_ctx, | ||
| 304 | .free_ctx = deflate_free_ctx, | ||
| 305 | .compress = deflate_scompress, | ||
| 306 | .decompress = deflate_sdecompress, | ||
| 307 | .base = { | ||
| 308 | .cra_name = "zlib-deflate", | ||
| 309 | .cra_driver_name = "zlib-deflate-scomp", | ||
| 310 | .cra_module = THIS_MODULE, | ||
| 311 | } | ||
| 312 | } }; | ||
| 286 | 313 | ||
| 287 | static int __init deflate_mod_init(void) | 314 | static int __init deflate_mod_init(void) |
| 288 | { | 315 | { |
| @@ -292,7 +319,7 @@ static int __init deflate_mod_init(void) | |||
| 292 | if (ret) | 319 | if (ret) |
| 293 | return ret; | 320 | return ret; |
| 294 | 321 | ||
| 295 | ret = crypto_register_scomp(&scomp); | 322 | ret = crypto_register_scomps(scomp, ARRAY_SIZE(scomp)); |
| 296 | if (ret) { | 323 | if (ret) { |
| 297 | crypto_unregister_alg(&alg); | 324 | crypto_unregister_alg(&alg); |
| 298 | return ret; | 325 | return ret; |
| @@ -304,7 +331,7 @@ static int __init deflate_mod_init(void) | |||
| 304 | static void __exit deflate_mod_fini(void) | 331 | static void __exit deflate_mod_fini(void) |
| 305 | { | 332 | { |
| 306 | crypto_unregister_alg(&alg); | 333 | crypto_unregister_alg(&alg); |
| 307 | crypto_unregister_scomp(&scomp); | 334 | crypto_unregister_scomps(scomp, ARRAY_SIZE(scomp)); |
| 308 | } | 335 | } |
| 309 | 336 | ||
| 310 | module_init(deflate_mod_init); | 337 | module_init(deflate_mod_init); |
diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 6b8661ee8dc0..6f5f3ed8376c 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c | |||
| @@ -3513,6 +3513,16 @@ static const struct alg_test_desc alg_test_descs[] = { | |||
| 3513 | .dec = __VECS(tf_xts_dec_tv_template) | 3513 | .dec = __VECS(tf_xts_dec_tv_template) |
| 3514 | } | 3514 | } |
| 3515 | } | 3515 | } |
| 3516 | }, { | ||
| 3517 | .alg = "zlib-deflate", | ||
| 3518 | .test = alg_test_comp, | ||
| 3519 | .fips_allowed = 1, | ||
| 3520 | .suite = { | ||
| 3521 | .comp = { | ||
| 3522 | .comp = __VECS(zlib_deflate_comp_tv_template), | ||
| 3523 | .decomp = __VECS(zlib_deflate_decomp_tv_template) | ||
| 3524 | } | ||
| 3525 | } | ||
| 3516 | } | 3526 | } |
| 3517 | }; | 3527 | }; |
| 3518 | 3528 | ||
diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 15c043f74b18..429357339dcc 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h | |||
| @@ -33204,6 +33204,81 @@ static const struct comp_testvec deflate_decomp_tv_template[] = { | |||
| 33204 | }, | 33204 | }, |
| 33205 | }; | 33205 | }; |
| 33206 | 33206 | ||
| 33207 | static const struct comp_testvec zlib_deflate_comp_tv_template[] = { | ||
| 33208 | { | ||
| 33209 | .inlen = 70, | ||
| 33210 | .outlen = 44, | ||
| 33211 | .input = "Join us now and share the software " | ||
| 33212 | "Join us now and share the software ", | ||
| 33213 | .output = "\x78\x5e\xf3\xca\xcf\xcc\x53\x28" | ||
| 33214 | "\x2d\x56\xc8\xcb\x2f\x57\x48\xcc" | ||
| 33215 | "\x4b\x51\x28\xce\x48\x2c\x4a\x55" | ||
| 33216 | "\x28\xc9\x48\x55\x28\xce\x4f\x2b" | ||
| 33217 | "\x29\x07\x71\xbc\x08\x2b\x01\x00" | ||
| 33218 | "\x7c\x65\x19\x3d", | ||
| 33219 | }, { | ||
| 33220 | .inlen = 191, | ||
| 33221 | .outlen = 129, | ||
| 33222 | .input = "This document describes a compression method based on the DEFLATE" | ||
| 33223 | "compression algorithm. This document defines the application of " | ||
| 33224 | "the DEFLATE algorithm to the IP Payload Compression Protocol.", | ||
| 33225 | .output = "\x78\x5e\x5d\xce\x41\x0a\xc3\x30" | ||
| 33226 | "\x0c\x04\xc0\xaf\xec\x0b\xf2\x87" | ||
| 33227 | "\xd2\xa6\x50\xe8\xc1\x07\x7f\x40" | ||
| 33228 | "\xb1\x95\x5a\x60\x5b\xc6\x56\x0f" | ||
| 33229 | "\xfd\x7d\x93\x1e\x42\xe8\x51\xec" | ||
| 33230 | "\xee\x20\x9f\x64\x20\x6a\x78\x17" | ||
| 33231 | "\xae\x86\xc8\x23\x74\x59\x78\x80" | ||
| 33232 | "\x10\xb4\xb4\xce\x63\x88\x56\x14" | ||
| 33233 | "\xb6\xa4\x11\x0b\x0d\x8e\xd8\x6e" | ||
| 33234 | "\x4b\x8c\xdb\x7c\x7f\x5e\xfc\x7c" | ||
| 33235 | "\xae\x51\x7e\x69\x17\x4b\x65\x02" | ||
| 33236 | "\xfc\x1f\xbc\x4a\xdd\xd8\x7d\x48" | ||
| 33237 | "\xad\x65\x09\x64\x3b\xac\xeb\xd9" | ||
| 33238 | "\xc2\x01\xc0\xf4\x17\x3c\x1c\x1c" | ||
| 33239 | "\x7d\xb2\x52\xc4\xf5\xf4\x8f\xeb" | ||
| 33240 | "\x6a\x1a\x34\x4f\x5f\x2e\x32\x45" | ||
| 33241 | "\x4e", | ||
| 33242 | }, | ||
| 33243 | }; | ||
| 33244 | |||
| 33245 | static const struct comp_testvec zlib_deflate_decomp_tv_template[] = { | ||
| 33246 | { | ||
| 33247 | .inlen = 128, | ||
| 33248 | .outlen = 191, | ||
| 33249 | .input = "\x78\x9c\x5d\x8d\x31\x0e\xc2\x30" | ||
| 33250 | "\x10\x04\xbf\xb2\x2f\xc8\x1f\x10" | ||
| 33251 | "\x04\x09\x89\xc2\x85\x3f\x70\xb1" | ||
| 33252 | "\x2f\xf8\x24\xdb\x67\xd9\x47\xc1" | ||
| 33253 | "\xef\x49\x68\x12\x51\xae\x76\x67" | ||
| 33254 | "\xd6\x27\x19\x88\x1a\xde\x85\xab" | ||
| 33255 | "\x21\xf2\x08\x5d\x16\x1e\x20\x04" | ||
| 33256 | "\x2d\xad\xf3\x18\xa2\x15\x85\x2d" | ||
| 33257 | "\x69\xc4\x42\x83\x23\xb6\x6c\x89" | ||
| 33258 | "\x71\x9b\xef\xcf\x8b\x9f\xcf\x33" | ||
| 33259 | "\xca\x2f\xed\x62\xa9\x4c\x80\xff" | ||
| 33260 | "\x13\xaf\x52\x37\xed\x0e\x52\x6b" | ||
| 33261 | "\x59\x02\xd9\x4e\xe8\x7a\x76\x1d" | ||
| 33262 | "\x02\x98\xfe\x8a\x87\x83\xa3\x4f" | ||
| 33263 | "\x56\x8a\xb8\x9e\x8e\x5c\x57\xd3" | ||
| 33264 | "\xa0\x79\xfa\x02\x2e\x32\x45\x4e", | ||
| 33265 | .output = "This document describes a compression method based on the DEFLATE" | ||
| 33266 | "compression algorithm. This document defines the application of " | ||
| 33267 | "the DEFLATE algorithm to the IP Payload Compression Protocol.", | ||
| 33268 | }, { | ||
| 33269 | .inlen = 44, | ||
| 33270 | .outlen = 70, | ||
| 33271 | .input = "\x78\x9c\xf3\xca\xcf\xcc\x53\x28" | ||
| 33272 | "\x2d\x56\xc8\xcb\x2f\x57\x48\xcc" | ||
| 33273 | "\x4b\x51\x28\xce\x48\x2c\x4a\x55" | ||
| 33274 | "\x28\xc9\x48\x55\x28\xce\x4f\x2b" | ||
| 33275 | "\x29\x07\x71\xbc\x08\x2b\x01\x00" | ||
| 33276 | "\x7c\x65\x19\x3d", | ||
| 33277 | .output = "Join us now and share the software " | ||
| 33278 | "Join us now and share the software ", | ||
| 33279 | }, | ||
| 33280 | }; | ||
| 33281 | |||
| 33207 | /* | 33282 | /* |
| 33208 | * LZO test vectors (null-terminated strings). | 33283 | * LZO test vectors (null-terminated strings). |
| 33209 | */ | 33284 | */ |
