Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * \file aes.h |
| 3 | */ |
| 4 | #ifndef XYSSL_AES_H |
| 5 | #define XYSSL_AES_H |
| 6 | |
| 7 | #define AES_ENCRYPT 1 |
| 8 | #define AES_DECRYPT 0 |
| 9 | |
| 10 | /** |
| 11 | * \brief AES context structure |
| 12 | */ |
| 13 | typedef struct |
| 14 | { |
| 15 | int nr; /*!< number of rounds */ |
| 16 | unsigned long *rk; /*!< AES round keys */ |
| 17 | unsigned long buf[68]; /*!< unaligned data */ |
| 18 | } |
| 19 | aes_context; |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | /** |
| 26 | * \brief AES key schedule (encryption) |
| 27 | * |
| 28 | * \param ctx AES context to be initialized |
| 29 | * \param key encryption key |
| 30 | * \param keysize must be 128, 192 or 256 |
| 31 | */ |
| 32 | void aes_setkey_enc( aes_context *ctx, unsigned char *key, int keysize ); |
| 33 | |
| 34 | /** |
| 35 | * \brief AES key schedule (decryption) |
| 36 | * |
| 37 | * \param ctx AES context to be initialized |
| 38 | * \param key decryption key |
| 39 | * \param keysize must be 128, 192 or 256 |
| 40 | */ |
| 41 | void aes_setkey_dec( aes_context *ctx, unsigned char *key, int keysize ); |
| 42 | |
| 43 | /** |
| 44 | * \brief AES-ECB block encryption/decryption |
| 45 | * |
| 46 | * \param ctx AES context |
| 47 | * \param mode AES_ENCRYPT or AES_DECRYPT |
| 48 | * \param input 16-byte input block |
| 49 | * \param output 16-byte output block |
| 50 | */ |
| 51 | void aes_crypt_ecb( aes_context *ctx, |
| 52 | int mode, |
| 53 | unsigned char input[16], |
| 54 | unsigned char output[16] ); |
| 55 | |
| 56 | /** |
| 57 | * \brief AES-CBC buffer encryption/decryption |
| 58 | * |
| 59 | * \param ctx AES context |
| 60 | * \param mode AES_ENCRYPT or AES_DECRYPT |
| 61 | * \param length length of the input data |
| 62 | * \param iv initialization vector (updated after use) |
| 63 | * \param input buffer holding the input data |
| 64 | * \param output buffer holding the output data |
| 65 | */ |
| 66 | void aes_crypt_cbc( aes_context *ctx, |
| 67 | int mode, |
| 68 | int length, |
| 69 | unsigned char iv[16], |
| 70 | unsigned char *input, |
| 71 | unsigned char *output ); |
| 72 | |
| 73 | /** |
| 74 | * \brief AES-CFB128 buffer encryption/decryption |
| 75 | * |
| 76 | * \param ctx AES context |
| 77 | * \param mode AES_ENCRYPT or AES_DECRYPT |
| 78 | * \param length length of the input data |
| 79 | * \param iv_off offset in IV (updated after use) |
| 80 | * \param iv initialization vector (updated after use) |
| 81 | * \param input buffer holding the input data |
| 82 | * \param output buffer holding the output data |
| 83 | */ |
| 84 | void aes_crypt_cfb128( aes_context *ctx, |
| 85 | int mode, |
| 86 | int length, |
| 87 | int *iv_off, |
| 88 | unsigned char iv[16], |
| 89 | unsigned char *input, |
| 90 | unsigned char *output ); |
| 91 | |
| 92 | /** |
| 93 | * \brief Checkup routine |
| 94 | * |
| 95 | * \return 0 if successful, or 1 if the test failed |
| 96 | */ |
| 97 | int aes_self_test( int verbose ); |
| 98 | |
| 99 | #ifdef __cplusplus |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | #endif /* aes.h */ |