Home | History | Annotate | Line # | Download | only in opencrypto
xform.c revision 1.18
      1  1.18    darran /*	$NetBSD: xform.c,v 1.18 2009/03/25 01:26:13 darran 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.18    darran __KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.18 2009/03/25 01:26:13 darran 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.15   thorpej const u_int8_t hmac_ipad_buffer[64] = {
     54  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     55  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     56  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     57  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     58  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     59  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     60  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
     61  1.15   thorpej 	0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
     62  1.15   thorpej };
     63  1.15   thorpej 
     64  1.15   thorpej const u_int8_t hmac_opad_buffer[64] = {
     65  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     66  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     67  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     68  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     69  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     70  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     71  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
     72  1.15   thorpej 	0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
     73  1.15   thorpej };
     74   1.1  jonathan 
     75   1.1  jonathan /* Encryption instances */
     76   1.1  jonathan struct enc_xform enc_xform_null = {
     77   1.1  jonathan 	CRYPTO_NULL_CBC, "NULL",
     78   1.1  jonathan 	/* NB: blocksize of 4 is to generate a properly aligned ESP header */
     79  1.15   thorpej 	4, 0, 256 /* 2048 bits, max key */
     80   1.1  jonathan };
     81   1.1  jonathan 
     82   1.1  jonathan struct enc_xform enc_xform_des = {
     83   1.1  jonathan 	CRYPTO_DES_CBC, "DES",
     84  1.15   thorpej 	8, 8, 8
     85   1.1  jonathan };
     86   1.1  jonathan 
     87   1.1  jonathan struct enc_xform enc_xform_3des = {
     88   1.1  jonathan 	CRYPTO_3DES_CBC, "3DES",
     89  1.15   thorpej 	8, 24, 24
     90   1.1  jonathan };
     91   1.1  jonathan 
     92   1.1  jonathan struct enc_xform enc_xform_blf = {
     93   1.1  jonathan 	CRYPTO_BLF_CBC, "Blowfish",
     94  1.15   thorpej 	8, 5, 56 /* 448 bits, max key */
     95   1.1  jonathan };
     96   1.1  jonathan 
     97   1.1  jonathan struct enc_xform enc_xform_cast5 = {
     98   1.1  jonathan 	CRYPTO_CAST_CBC, "CAST-128",
     99  1.15   thorpej 	8, 5, 16
    100   1.1  jonathan };
    101   1.1  jonathan 
    102   1.1  jonathan struct enc_xform enc_xform_skipjack = {
    103   1.1  jonathan 	CRYPTO_SKIPJACK_CBC, "Skipjack",
    104  1.15   thorpej 	8, 10, 10
    105   1.1  jonathan };
    106   1.1  jonathan 
    107   1.1  jonathan struct enc_xform enc_xform_rijndael128 = {
    108   1.1  jonathan 	CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES",
    109  1.15   thorpej 	16, 8, 32
    110   1.1  jonathan };
    111   1.1  jonathan 
    112   1.1  jonathan struct enc_xform enc_xform_arc4 = {
    113   1.1  jonathan 	CRYPTO_ARC4, "ARC4",
    114  1.15   thorpej 	1, 1, 32
    115   1.1  jonathan };
    116   1.1  jonathan 
    117   1.1  jonathan /* Authentication instances */
    118   1.1  jonathan struct auth_hash auth_hash_null = {
    119   1.1  jonathan 	CRYPTO_NULL_HMAC, "NULL-HMAC",
    120  1.15   thorpej 	0, 0, 12, sizeof(int)			/* NB: context isn't used */
    121   1.1  jonathan };
    122   1.1  jonathan 
    123  1.16       tls struct auth_hash auth_hash_hmac_md5 = {
    124  1.16       tls 	CRYPTO_MD5_HMAC, "HMAC-MD5",
    125  1.16       tls 	16, 16, 16, sizeof(MD5_CTX)
    126  1.16       tls };
    127  1.16       tls 
    128  1.16       tls struct auth_hash auth_hash_hmac_sha1 = {
    129  1.16       tls 	CRYPTO_SHA1_HMAC, "HMAC-SHA1",
    130  1.16       tls 	20, 20, 20, sizeof(SHA1_CTX)
    131  1.16       tls };
    132  1.16       tls 
    133  1.16       tls struct auth_hash auth_hash_hmac_ripemd_160 = {
    134  1.16       tls 	CRYPTO_RIPEMD160_HMAC, "HMAC-RIPEMD-160",
    135  1.16       tls 	20, 20, 20, sizeof(RMD160_CTX)
    136  1.16       tls };
    137  1.16       tls 
    138   1.1  jonathan struct auth_hash auth_hash_hmac_md5_96 = {
    139  1.17       tls 	CRYPTO_MD5_HMAC_96, "HMAC-MD5-96",
    140  1.15   thorpej 	16, 16, 12, sizeof(MD5_CTX)
    141   1.1  jonathan };
    142   1.1  jonathan 
    143   1.1  jonathan struct auth_hash auth_hash_hmac_sha1_96 = {
    144  1.17       tls 	CRYPTO_SHA1_HMAC_96, "HMAC-SHA1-96",
    145  1.15   thorpej 	20, 20, 12, sizeof(SHA1_CTX)
    146   1.1  jonathan };
    147   1.1  jonathan 
    148   1.1  jonathan struct auth_hash auth_hash_hmac_ripemd_160_96 = {
    149  1.17       tls 	CRYPTO_RIPEMD160_HMAC_96, "HMAC-RIPEMD-160",
    150  1.15   thorpej 	20, 20, 12, sizeof(RMD160_CTX)
    151   1.1  jonathan };
    152   1.1  jonathan 
    153   1.1  jonathan struct auth_hash auth_hash_key_md5 = {
    154   1.1  jonathan 	CRYPTO_MD5_KPDK, "Keyed MD5",
    155  1.15   thorpej 	0, 16, 16, sizeof(MD5_CTX)
    156   1.1  jonathan };
    157   1.1  jonathan 
    158   1.1  jonathan struct auth_hash auth_hash_key_sha1 = {
    159   1.1  jonathan 	CRYPTO_SHA1_KPDK, "Keyed SHA1",
    160  1.15   thorpej 	0, 20, 20, sizeof(SHA1_CTX)
    161   1.1  jonathan };
    162   1.1  jonathan 
    163   1.1  jonathan struct auth_hash auth_hash_md5 = {
    164   1.1  jonathan 	CRYPTO_MD5, "MD5",
    165  1.15   thorpej 	0, 16, 16, sizeof(MD5_CTX)
    166   1.1  jonathan };
    167   1.1  jonathan 
    168   1.1  jonathan struct auth_hash auth_hash_sha1 = {
    169   1.1  jonathan 	CRYPTO_SHA1, "SHA1",
    170  1.15   thorpej 	0, 20, 20, sizeof(SHA1_CTX)
    171   1.1  jonathan };
    172   1.1  jonathan 
    173   1.1  jonathan struct auth_hash auth_hash_hmac_sha2_256 = {
    174   1.1  jonathan 	CRYPTO_SHA2_HMAC, "HMAC-SHA2",
    175  1.15   thorpej 	32, 32, 12, sizeof(SHA256_CTX)
    176   1.1  jonathan };
    177   1.1  jonathan 
    178   1.1  jonathan struct auth_hash auth_hash_hmac_sha2_384 = {
    179   1.1  jonathan 	CRYPTO_SHA2_HMAC, "HMAC-SHA2-384",
    180  1.15   thorpej 	48, 48, 12, sizeof(SHA384_CTX)
    181   1.1  jonathan };
    182   1.1  jonathan 
    183   1.1  jonathan struct auth_hash auth_hash_hmac_sha2_512 = {
    184   1.1  jonathan 	CRYPTO_SHA2_HMAC, "HMAC-SHA2-512",
    185  1.15   thorpej 	64, 64, 12, sizeof(SHA512_CTX)
    186   1.1  jonathan };
    187   1.1  jonathan 
    188   1.1  jonathan /* Compression instance */
    189   1.1  jonathan struct comp_algo comp_algo_deflate = {
    190   1.1  jonathan 	CRYPTO_DEFLATE_COMP, "Deflate",
    191  1.15   thorpej 	90
    192   1.1  jonathan };
    193  1.18    darran 
    194  1.18    darran struct comp_algo comp_algo_gzip = {
    195  1.18    darran 	CRYPTO_GZIP_COMP, "GZIP",
    196  1.18    darran 	90
    197  1.18    darran };
    198