The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/crypto/crypto_null.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* 
    2  * Cryptographic API.
    3  *
    4  * Null algorithms, aka Much Ado About Nothing.
    5  *
    6  * These are needed for IPsec, and may be useful in general for
    7  * testing & debugging.
    8  * 
    9  * The null cipher is compliant with RFC2410.
   10  *
   11  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
   12  *
   13  * This program is free software; you can redistribute it and/or modify
   14  * it under the terms of the GNU General Public License as published by
   15  * the Free Software Foundation; either version 2 of the License, or
   16  * (at your option) any later version.
   17  *
   18  */
   19 #include <linux/init.h>
   20 #include <linux/module.h>
   21 #include <linux/mm.h>
   22 #include <asm/scatterlist.h>
   23 #include <linux/crypto.h>
   24 
   25 #define NULL_KEY_SIZE           0
   26 #define NULL_BLOCK_SIZE         1
   27 #define NULL_DIGEST_SIZE        0
   28 
   29 static int null_compress(void *ctx, const u8 *src, unsigned int slen,
   30                          u8 *dst, unsigned int *dlen)
   31 { return 0; }
   32 
   33 static int null_decompress(void *ctx, const u8 *src, unsigned int slen,
   34                            u8 *dst, unsigned int *dlen)
   35 { return 0; }
   36 
   37 static void null_init(void *ctx)
   38 { }
   39 
   40 static void null_update(void *ctx, const u8 *data, unsigned int len)
   41 { }
   42 
   43 static void null_final(void *ctx, u8 *out)
   44 { }
   45 
   46 static int null_setkey(void *ctx, const u8 *key,
   47                        unsigned int keylen, u32 *flags)
   48 { return 0; }
   49 
   50 static void null_encrypt(void *ctx, u8 *dst, const u8 *src)
   51 { }
   52 
   53 static void null_decrypt(void *ctx, u8 *dst, const u8 *src)
   54 { }
   55 
   56 static struct crypto_alg compress_null = {
   57         .cra_name               =       "compress_null",
   58         .cra_flags              =       CRYPTO_ALG_TYPE_COMPRESS,
   59         .cra_blocksize          =       NULL_BLOCK_SIZE,
   60         .cra_ctxsize            =       0,
   61         .cra_module             =       THIS_MODULE,
   62         .cra_list               =       LIST_HEAD_INIT(compress_null.cra_list),
   63         .cra_u                  =       { .compress = {
   64         .coa_compress           =       null_compress,
   65         .coa_decompress         =       null_decompress } }
   66 };
   67 
   68 static struct crypto_alg digest_null = {
   69         .cra_name               =       "digest_null",
   70         .cra_flags              =       CRYPTO_ALG_TYPE_DIGEST,
   71         .cra_blocksize          =       NULL_BLOCK_SIZE,
   72         .cra_ctxsize            =       0,
   73         .cra_module             =       THIS_MODULE,
   74         .cra_list               =       LIST_HEAD_INIT(digest_null.cra_list),   
   75         .cra_u                  =       { .digest = {
   76         .dia_digestsize         =       NULL_DIGEST_SIZE,
   77         .dia_init               =       null_init,
   78         .dia_update             =       null_update,
   79         .dia_final              =       null_final } }
   80 };
   81 
   82 static struct crypto_alg cipher_null = {
   83         .cra_name               =       "cipher_null",
   84         .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
   85         .cra_blocksize          =       NULL_BLOCK_SIZE,
   86         .cra_ctxsize            =       0,
   87         .cra_module             =       THIS_MODULE,
   88         .cra_list               =       LIST_HEAD_INIT(cipher_null.cra_list),
   89         .cra_u                  =       { .cipher = {
   90         .cia_min_keysize        =       NULL_KEY_SIZE,
   91         .cia_max_keysize        =       NULL_KEY_SIZE,
   92         .cia_ivsize             =       0,
   93         .cia_setkey             =       null_setkey,
   94         .cia_encrypt            =       null_encrypt,
   95         .cia_decrypt            =       null_decrypt } }
   96 };
   97 
   98 static int __init init(void)
   99 {
  100         int ret = 0;
  101         
  102         ret = crypto_register_alg(&cipher_null);
  103         if (ret < 0)
  104                 goto out;
  105 
  106         ret = crypto_register_alg(&digest_null);
  107         if (ret < 0) {
  108                 crypto_unregister_alg(&cipher_null);
  109                 goto out;
  110         }
  111 
  112         ret = crypto_register_alg(&compress_null);
  113         if (ret < 0) {
  114                 crypto_unregister_alg(&digest_null);
  115                 crypto_unregister_alg(&cipher_null);
  116                 goto out;
  117         }
  118 
  119 out:    
  120         return ret;
  121 }
  122 
  123 static void __exit fini(void)
  124 {
  125         crypto_unregister_alg(&compress_null);
  126         crypto_unregister_alg(&digest_null);
  127         crypto_unregister_alg(&cipher_null);
  128 }
  129 
  130 module_init(init);
  131 module_exit(fini);
  132 
  133 MODULE_LICENSE("GPL");
  134 MODULE_DESCRIPTION("Null Cryptographic Algorithms");

Cache object: e4144ee93ce20f95266bbfac1139f5d4


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.