4 * A simple abstraction for the basic functionality of a block cipher engine.
\r
6 * @author Paulo S. L. M. Barreto
\r
10 * This software is hereby placed in the public domain.
\r
12 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
\r
13 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
15 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
\r
16 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
17 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
18 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
\r
19 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
\r
21 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
22 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
24 #ifndef __BLOCKCIPHER_H
\r
25 #define __BLOCKCIPHER_H
\r
27 #include <freeradius-devel/ident.h>
\r
28 RCSIDH(BlockCipher_h, "$Id$")
\r
30 #include "/usr/include/sys/types.h"
\r
34 typedef unsigned char byte;
\r
35 //typedef unsigned long uint; /* assuming sizeof(uint) == 4 */
\r
36 #endif /* USUAL_TYPES */
\r
39 #define DIR_ENCRYPT 1
\r
40 #define DIR_DECRYPT 2
\r
41 #define DIR_BOTH (DIR_ENCRYPT | DIR_DECRYPT) /* both directions */
\r
47 * Cipher's block size in bits.
\r
49 virtual uint blockBits() const = 0;
\r
52 * Cipher's block size in bytes.
\r
54 virtual uint blockSize() const = 0;
\r
57 * Cipher's key size in bits.
\r
59 virtual uint keyBits() const = 0;
\r
62 * Cipher's key size in bytes.
\r
64 virtual uint keySize() const = 0;
\r
67 * Setup the key schedule for encryption, decryption, or both.
\r
69 * @param cipherKey the cipher key.
\r
70 * @param keyBits size of the cipher key in bits.
\r
71 * @param direction cipher direction (DIR_ENCRYPT, DIR_DECRYPT, or DIR_BOTH).
\r
73 virtual void makeKey(const byte *cipherKey, uint keyBits, uint dir) = 0;
\r
76 * Encrypt exactly one block of plaintext.
\r
78 * @param pt plaintext block.
\r
79 * @param ct ciphertext block.
\r
81 virtual void encrypt(const byte *pt, byte *ct) = 0;
\r
84 * Decrypt exactly one block of ciphertext.
\r
86 * @param ct ciphertext block.
\r
87 * @param pt plaintext block.
\r
89 virtual void decrypt(const byte *ct, byte *pt) = 0;
\r
93 #endif /* __BLOCKCIPHER_H */
\r