Skip to content
Snippets Groups Projects
Select Git revision
  • master
  • sso-support
  • async-rewrite
  • docker
  • discord_api_integration
5 results

campus.py

Blame
  • deflate.c 5.38 KiB
    /*
     * Cryptographic API.
     *
     * Deflate algorithm (RFC 1951), implemented here primarily for use
     * by IPCOMP (RFC 3173 & RFC 2394).
     *
     * Copyright (c) 2003 James Morris <jmorris@intercode.com.au>
     *
     * 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; either version 2 of the License, or (at your option)
     * any later version.
     *
     * FIXME: deflate transforms will require up to a total of about 436k of kernel
     * memory on i386 (390k for compression, the rest for decompression), as the
     * current zlib kernel code uses a worst case pre-allocation system by default.
     * This needs to be fixed so that the amount of memory required is properly
     * related to the  winbits and memlevel parameters.
     *
     * The default winbits of 11 should suit most packets, and it may be something
     * to configure on a per-tfm basis in the future.
     *
     * Currently, compression history is not maintained between tfm calls, as
     * it is not needed for IPCOMP and keeps the code simpler.  It can be
     * implemented if someone wants it.
     */
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/crypto.h>
    #include <linux/zlib.h>
    #include <linux/vmalloc.h>
    #include <linux/interrupt.h>
    #include <linux/mm.h>
    #include <linux/net.h>
    
    #define DEFLATE_DEF_LEVEL		Z_DEFAULT_COMPRESSION
    #define DEFLATE_DEF_WINBITS		11
    #define DEFLATE_DEF_MEMLEVEL		MAX_MEM_LEVEL
    
    struct deflate_ctx {
    	struct z_stream_s comp_stream;
    	struct z_stream_s decomp_stream;
    };
    
    static int deflate_comp_init(struct deflate_ctx *ctx)
    {
    	int ret = 0;
    	struct z_stream_s *stream = &ctx->comp_stream;
    
    	stream->workspace = vzalloc(zlib_deflate_workspacesize(
    				-DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL));
    	if (!stream->workspace) {
    		ret = -ENOMEM;
    		goto out;
    	}
    	ret = zlib_deflateInit2(stream, DEFLATE_DEF_LEVEL, Z_DEFLATED,
    	                        -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL,
    	                        Z_DEFAULT_STRATEGY);
    	if (ret != Z_OK) {
    		ret = -EINVAL;
    		goto out_free;
    	}
    out:
    	return ret;
    out_free:
    	vfree(stream->workspace);
    	goto out;
    }
    
    static int deflate_decomp_init(struct deflate_ctx *ctx)