Home | History | Annotate | Line # | Download | only in opencrypto
xform.c revision 1.22
      1  1.22  drochner /*	$NetBSD: xform.c,v 1.22 2011/05/05 17:42:17 drochner Exp $ */
      2   1.1  jonathan /*	$FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $	*/
      3   1.1  jonathan /*	$OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $	*/
      4   1.1  jonathan 
      5   1.1  jonathan /*
      6   1.1  jonathan  * The authors of this code are John Ioannidis (ji (at) tla.org),
      7   1.1  jonathan  * Angelos D. Keromytis (kermit (at) csd.uch.gr) and
      8   1.1  jonathan  * Niels Provos (provos (at) physnet.uni-hamburg.de).
      9   1.1  jonathan  *
     10   1.1  jonathan  * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
     11   1.1  jonathan  * in November 1995.
     12   1.1  jonathan  *
     13   1.1  jonathan  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
     14   1.1  jonathan  * by Angelos D. Keromytis.
     15   1.1  jonathan  *
     16   1.1  jonathan  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
     17   1.1  jonathan  * and Niels Provos.
     18   1.1  jonathan  *
     19   1.1  jonathan  * Additional features in 1999 by Angelos D. Keromytis.
     20   1.1  jonathan  *
     21   1.1  jonathan  * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
     22   1.1  jonathan  * Angelos D. Keromytis and Niels Provos.
     23   1.1  jonathan  *
     24   1.1  jonathan  * Copyright (C) 2001, Angelos D. Keromytis.
     25   1.1  jonathan  *
     26   1.1  jonathan  * Permission to use, copy, and modify this software with or without fee
     27   1.1  jonathan  * is hereby granted, provided that this entire notice is included in
     28   1.1  jonathan  * all copies of any software which is or includes a copy or
     29   1.1  jonathan  * modification of this software.
     30   1.1  jonathan  * You may use this code under the GNU public license if you so wish. Please
     31   1.1  jonathan  * contribute changes back to the authors under this freer than GPL license
     32   1.1  jonathan  * so that we may further the use of strong encryption without limitations to
     33   1.1  jonathan  * all.
     34   1.1  jonathan  *
     35   1.1  jonathan  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
     36   1.1  jonathan  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
     37   1.1  jonathan  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
     38   1.1  jonathan  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
     39   1.1  jonathan  * PURPOSE.
     40   1.1  jonathan  */
     41   1.1  jonathan 
     42   1.1  jonathan #include <sys/cdefs.h>
     43  1.22  drochner __KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.22 2011/05/05 17:42:17 drochner Exp $");
     44   1.1  jonathan 
     45   1.1  jonathan #include <sys/param.h>
     46   1.1  jonathan #include <sys/malloc.h>
     47   1.1  jonathan 
     48   1.1  jonathan #include <opencrypto/cryptodev.h>
     49   1.1  jonathan #include <opencrypto/xform.h>
     50   1.1  jonathan 
     51  1.15   thorpej MALLOC_DEFINE(M_XDATA, "xform", "xform data buffers");
     52   1.1  jonathan 
     53  1.20  drochner const u_int8_t hmac_ipad_buffer[128] = {
     54  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     55  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     56  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     57  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     58  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     59  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     60  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     61  1.20  drochner 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     62  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     63  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     64  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     65  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     66  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     67  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     68  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     69  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
     70  1.15   thorpej };
     71  1.15   thorpej 
     72  1.20  drochner const u_int8_t hmac_opad_buffer[128] = {
     73  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     74  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     75  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     76  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     77  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     78  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     79  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     80  1.20  drochner 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     81  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     82  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     83  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     84  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     85  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     86  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     87  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     88  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
     89  1.15   thorpej };
     90   1.1  jonathan 
     91   1.1  jonathan /* Encryption instances */
     92  1.21  drochner const struct enc_xform enc_xform_null = {
     93   1.1  jonathan 	CRYPTO_NULL_CBC, "NULL",
     94   1.1  jonathan 	/* NB: blocksize of 4 is to generate a properly aligned ESP header */
     95  1.15   thorpej 	4, 0, 256 /* 2048 bits, max key */
     96   1.1  jonathan };
     97   1.1  jonathan 
     98  1.21  drochner const struct enc_xform enc_xform_des = {
     99   1.1  jonathan 	CRYPTO_DES_CBC, "DES",
    100  1.15   thorpej 	8, 8, 8
    101   1.1  jonathan };
    102   1.1  jonathan 
    103  1.21  drochner const struct enc_xform enc_xform_3des = {
    104   1.1  jonathan 	CRYPTO_3DES_CBC, "3DES",
    105  1.15   thorpej 	8, 24, 24
    106   1.1  jonathan };
    107   1.1  jonathan 
    108  1.21  drochner const struct enc_xform enc_xform_blf = {
    109   1.1  jonathan 	CRYPTO_BLF_CBC, "Blowfish",
    110  1.15   thorpej 	8, 5, 56 /* 448 bits, max key */
    111   1.1  jonathan };
    112   1.1  jonathan 
    113  1.21  drochner const struct enc_xform enc_xform_cast5 = {
    114   1.1  jonathan 	CRYPTO_CAST_CBC, "CAST-128",
    115  1.15   thorpej 	8, 5, 16
    116   1.1  jonathan };
    117   1.1  jonathan 
    118  1.21  drochner const struct enc_xform enc_xform_skipjack = {
    119   1.1  jonathan 	CRYPTO_SKIPJACK_CBC, "Skipjack",
    120  1.15   thorpej 	8, 10, 10
    121   1.1  jonathan };
    122   1.1  jonathan 
    123  1.21  drochner const struct enc_xform enc_xform_rijndael128 = {
    124   1.1  jonathan 	CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES",
    125  1.15   thorpej 	16, 8, 32
    126   1.1  jonathan };
    127   1.1  jonathan 
    128  1.21  drochner const struct enc_xform enc_xform_arc4 = {
    129   1.1  jonathan 	CRYPTO_ARC4, "ARC4",
    130  1.15   thorpej 	1, 1, 32
    131   1.1  jonathan };
    132   1.1  jonathan 
    133  1.22  drochner const struct enc_xform enc_xform_camellia = {
    134  1.22  drochner 	CRYPTO_CAMELLIA_CBC, "Camellia",
    135  1.22  drochner 	16, 8, 32
    136  1.22  drochner };
    137  1.22  drochner 
    138   1.1  jonathan /* Authentication instances */
    139  1.21  drochner const struct auth_hash auth_hash_null = {
    140   1.1  jonathan 	CRYPTO_NULL_HMAC, "NULL-HMAC",
    141  1.20  drochner 	0, 0, 12, 64, sizeof(int)		/* NB: context isn't used */
    142   1.1  jonathan };
    143   1.1  jonathan 
    144  1.21  drochner const struct auth_hash auth_hash_hmac_md5 = {
    145  1.16       tls 	CRYPTO_MD5_HMAC, "HMAC-MD5",
    146  1.20  drochner 	16, 16, 16, 64, sizeof(MD5_CTX)
    147  1.16       tls };
    148  1.16       tls 
    149  1.21  drochner const struct auth_hash auth_hash_hmac_sha1 = {
    150  1.16       tls 	CRYPTO_SHA1_HMAC, "HMAC-SHA1",
    151  1.20  drochner 	20, 20, 20, 64, sizeof(SHA1_CTX)
    152  1.16       tls };
    153  1.16       tls 
    154  1.21  drochner const struct auth_hash auth_hash_hmac_ripemd_160 = {
    155  1.16       tls 	CRYPTO_RIPEMD160_HMAC, "HMAC-RIPEMD-160",
    156  1.20  drochner 	20, 20, 20, 64, sizeof(RMD160_CTX)
    157  1.16       tls };
    158  1.16       tls 
    159  1.21  drochner const struct auth_hash auth_hash_hmac_md5_96 = {
    160  1.17       tls 	CRYPTO_MD5_HMAC_96, "HMAC-MD5-96",
    161  1.20  drochner 	16, 16, 12, 64, sizeof(MD5_CTX)
    162   1.1  jonathan };
    163   1.1  jonathan 
    164  1.21  drochner const struct auth_hash auth_hash_hmac_sha1_96 = {
    165  1.17       tls 	CRYPTO_SHA1_HMAC_96, "HMAC-SHA1-96",
    166  1.20  drochner 	20, 20, 12, 64, sizeof(SHA1_CTX)
    167   1.1  jonathan };
    168   1.1  jonathan 
    169  1.21  drochner const struct auth_hash auth_hash_hmac_ripemd_160_96 = {
    170  1.17       tls 	CRYPTO_RIPEMD160_HMAC_96, "HMAC-RIPEMD-160",
    171  1.20  drochner 	20, 20, 12, 64, sizeof(RMD160_CTX)
    172   1.1  jonathan };
    173   1.1  jonathan 
    174  1.21  drochner const struct auth_hash auth_hash_key_md5 = {
    175   1.1  jonathan 	CRYPTO_MD5_KPDK, "Keyed MD5",
    176  1.20  drochner 	0, 16, 16, 0, sizeof(MD5_CTX)
    177   1.1  jonathan };
    178   1.1  jonathan 
    179  1.21  drochner const struct auth_hash auth_hash_key_sha1 = {
    180   1.1  jonathan 	CRYPTO_SHA1_KPDK, "Keyed SHA1",
    181  1.20  drochner 	0, 20, 20, 0, sizeof(SHA1_CTX)
    182   1.1  jonathan };
    183   1.1  jonathan 
    184  1.21  drochner const struct auth_hash auth_hash_md5 = {
    185   1.1  jonathan 	CRYPTO_MD5, "MD5",
    186  1.20  drochner 	0, 16, 16, 0, sizeof(MD5_CTX)
    187   1.1  jonathan };
    188   1.1  jonathan 
    189  1.21  drochner const struct auth_hash auth_hash_sha1 = {
    190   1.1  jonathan 	CRYPTO_SHA1, "SHA1",
    191  1.20  drochner 	0, 20, 20, 0, sizeof(SHA1_CTX)
    192   1.1  jonathan };
    193   1.1  jonathan 
    194  1.21  drochner const struct auth_hash auth_hash_hmac_sha2_256 = {
    195  1.20  drochner 	CRYPTO_SHA2_256_HMAC, "HMAC-SHA2",
    196  1.20  drochner 	32, 32, 16, 64, sizeof(SHA256_CTX)
    197   1.1  jonathan };
    198   1.1  jonathan 
    199  1.21  drochner const struct auth_hash auth_hash_hmac_sha2_384 = {
    200  1.20  drochner 	CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384",
    201  1.20  drochner 	48, 48, 24, 128, sizeof(SHA384_CTX)
    202   1.1  jonathan };
    203   1.1  jonathan 
    204  1.21  drochner const struct auth_hash auth_hash_hmac_sha2_512 = {
    205  1.20  drochner 	CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512",
    206  1.20  drochner 	64, 64, 32, 128, sizeof(SHA512_CTX)
    207   1.1  jonathan };
    208   1.1  jonathan 
    209   1.1  jonathan /* Compression instance */
    210  1.21  drochner const struct comp_algo comp_algo_deflate = {
    211   1.1  jonathan 	CRYPTO_DEFLATE_COMP, "Deflate",
    212  1.15   thorpej 	90
    213   1.1  jonathan };
    214  1.18    darran 
    215  1.21  drochner const struct comp_algo comp_algo_deflate_nogrow = {
    216  1.19  drochner 	CRYPTO_DEFLATE_COMP_NOGROW, "Deflate",
    217  1.19  drochner 	90
    218  1.19  drochner };
    219  1.19  drochner 
    220  1.21  drochner const struct comp_algo comp_algo_gzip = {
    221  1.18    darran 	CRYPTO_GZIP_COMP, "GZIP",
    222  1.18    darran 	90
    223  1.18    darran };
    224