1 /* $OpenBSD: xform.h,v 1.8 2001/08/28 12:20:43 ben Exp $ */
4 * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
6 * This code was written by Angelos D. Keromytis in Athens, Greece, in
7 * February 2000. Network Security Technologies Inc. (NSTI) kindly
8 * supported the development of this code.
10 * Copyright (c) 2000 Angelos D. Keromytis
11 * Copyright (c) 2014 The FreeBSD Foundation
12 * All rights reserved.
14 * Portions of this software were developed by John-Mark Gurney
15 * under sponsorship of the FreeBSD Foundation and
16 * Rubicon Communications, LLC (Netgate).
18 * Permission to use, copy, and modify this software without fee
19 * is hereby granted, provided that this entire notice is included in
20 * all source code copies of any software which is or includes a copy or
21 * modification of this software.
23 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
24 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
25 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
26 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
30 #ifndef _CRYPTO_XFORM_ENC_H_
31 #define _CRYPTO_XFORM_ENC_H_
33 #include <sys/types.h>
35 #include <crypto/rijndael/rijndael.h>
36 #include <crypto/camellia/camellia.h>
37 #include <opencrypto/cryptodev.h>
42 #define AESICM_BLOCKSIZE AES_BLOCK_LEN
43 #define AES_XTS_BLOCKSIZE 16
44 #define AES_XTS_IVSIZE 8
45 #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */
52 uint16_t blocksize; /* Required input block size -- 1 for stream ciphers. */
53 uint16_t native_blocksize; /* Used for stream ciphers. */
55 uint16_t minkey, maxkey;
56 uint16_t macsize; /* For AEAD ciphers. */
58 /* Initialize context and set key. */
59 int (*setkey) (void *, const uint8_t *, int len);
61 /* Supply context with nonce/IV. */
62 void (*reinit) (void *, const uint8_t *, size_t);
65 * Encrypt/decrypt a single block. For stream ciphers this
66 * encrypts/decrypts a single "native" block.
68 void (*encrypt) (void *, const uint8_t *, uint8_t *);
69 void (*decrypt) (void *, const uint8_t *, uint8_t *);
72 * Encrypt/decrypt multiple blocks. For stream ciphers this
73 * encrypts/decrypts multiple "native" blocks. The fourth
74 * argument is a count of bytes.
76 void (*encrypt_multi) (void *, const uint8_t *, uint8_t *, size_t);
77 void (*decrypt_multi) (void *, const uint8_t *, uint8_t *, size_t);
80 * For stream ciphers, encrypt/decrypt the final partial block
83 void (*encrypt_last) (void *, const uint8_t *, uint8_t *, size_t len);
84 void (*decrypt_last) (void *, const uint8_t *, uint8_t *, size_t len);
87 * For AEAD ciphers, update and generate MAC/tag.
89 int (*update) (void *, const void *, u_int);
90 void (*final) (uint8_t *, void *);
94 extern const struct enc_xform enc_xform_null;
95 extern const struct enc_xform enc_xform_aes_cbc;
96 extern const struct enc_xform enc_xform_aes_icm;
97 extern const struct enc_xform enc_xform_aes_nist_gcm;
98 extern const struct enc_xform enc_xform_aes_nist_gmac;
99 extern const struct enc_xform enc_xform_aes_xts;
100 extern const struct enc_xform enc_xform_camellia;
101 extern const struct enc_xform enc_xform_chacha20;
102 extern const struct enc_xform enc_xform_chacha20_poly1305;
103 extern const struct enc_xform enc_xform_xchacha20_poly1305;
104 extern const struct enc_xform enc_xform_ccm;
107 uint32_t ac_ek[4*(RIJNDAEL_MAXNR + 1)];
108 /* ac_block is initialized to IV */
109 uint8_t ac_block[AESICM_BLOCKSIZE];
116 uint8_t tweak[AES_XTS_BLOCKSIZE];
119 #endif /* _CRYPTO_XFORM_ENC_H_ */