]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/opencrypto/xform_enc.h
MFC r344140,r344141,r344142,r344143,r344388,r344547
[FreeBSD/FreeBSD.git] / sys / opencrypto / xform_enc.h
1 /*      $FreeBSD$       */
2 /*      $OpenBSD: xform.h,v 1.8 2001/08/28 12:20:43 ben Exp $   */
3
4 /*-
5  * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
6  *
7  * This code was written by Angelos D. Keromytis in Athens, Greece, in
8  * February 2000. Network Security Technologies Inc. (NSTI) kindly
9  * supported the development of this code.
10  *
11  * Copyright (c) 2000 Angelos D. Keromytis
12  * Copyright (c) 2014 The FreeBSD Foundation
13  * All rights reserved.
14  *
15  * Portions of this software were developed by John-Mark Gurney
16  * under sponsorship of the FreeBSD Foundation and
17  * Rubicon Communications, LLC (Netgate).
18  *
19  * Permission to use, copy, and modify this software without fee
20  * is hereby granted, provided that this entire notice is included in
21  * all source code copies of any software which is or includes a copy or
22  * modification of this software. 
23  *
24  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
25  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
26  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
27  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
28  * PURPOSE.
29  */
30
31 #ifndef _CRYPTO_XFORM_ENC_H_
32 #define _CRYPTO_XFORM_ENC_H_
33
34 #include <sys/malloc.h>
35 #include <sys/errno.h>
36 #include <crypto/blowfish/blowfish.h>
37 #include <crypto/des/des.h>
38 #include <crypto/rijndael/rijndael.h>
39 #include <crypto/camellia/camellia.h>
40 #include <opencrypto/cast.h>
41 #include <opencrypto/skipjack.h>
42 #include <opencrypto/cryptodev.h>
43 #include <opencrypto/xform_userland.h>
44
45 #define AESICM_BLOCKSIZE        AES_BLOCK_LEN
46 #define AES_XTS_BLOCKSIZE       16
47 #define AES_XTS_IVSIZE          8
48 #define AES_XTS_ALPHA           0x87    /* GF(2^128) generator polynomial */
49
50 /* Declarations */
51 struct enc_xform {
52         int type;
53         char *name;
54         u_int16_t blocksize;    /* Required input block size -- 1 for stream ciphers. */
55         u_int16_t ivsize;
56         u_int16_t minkey, maxkey;
57         void (*encrypt) (caddr_t, u_int8_t *);
58         void (*decrypt) (caddr_t, u_int8_t *);
59         int (*setkey) (u_int8_t **, u_int8_t *, int len);
60         void (*zerokey) (u_int8_t **);
61         void (*reinit) (caddr_t, u_int8_t *);
62         /*
63          * Encrypt/decrypt 1+ blocks of input -- total size is 'len' bytes.
64          * Len is guaranteed to be a multiple of the defined 'blocksize'.
65          * Optional interface -- most useful for stream ciphers with a small
66          * blocksize (1).
67          */
68         void (*encrypt_multi) (void *, uint8_t *, size_t len);
69         void (*decrypt_multi) (void *, uint8_t *, size_t len);
70 };
71
72
73 extern struct enc_xform enc_xform_null;
74 extern struct enc_xform enc_xform_des;
75 extern struct enc_xform enc_xform_3des;
76 extern struct enc_xform enc_xform_blf;
77 extern struct enc_xform enc_xform_cast5;
78 extern struct enc_xform enc_xform_skipjack;
79 extern struct enc_xform enc_xform_rijndael128;
80 extern struct enc_xform enc_xform_aes_icm;
81 extern struct enc_xform enc_xform_aes_nist_gcm;
82 extern struct enc_xform enc_xform_aes_nist_gmac;
83 extern struct enc_xform enc_xform_aes_xts;
84 extern struct enc_xform enc_xform_arc4;
85 extern struct enc_xform enc_xform_camellia;
86 extern struct enc_xform enc_xform_chacha20;
87 extern struct enc_xform enc_xform_ccm;
88
89 struct aes_icm_ctx {
90         u_int32_t       ac_ek[4*(RIJNDAEL_MAXNR + 1)];
91         /* ac_block is initalized to IV */
92         u_int8_t        ac_block[AESICM_BLOCKSIZE];
93         int             ac_nr;
94 };
95
96 struct aes_xts_ctx {
97         rijndael_ctx key1;
98         rijndael_ctx key2;
99         u_int8_t tweak[AES_XTS_BLOCKSIZE];
100 };
101
102 #endif /* _CRYPTO_XFORM_ENC_H_ */