diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2002-07-21 06:59:54 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-07-18 11:17:32 -0700 |
commit | cdf8fed1d002465246fa2029a3a2614fc3f9c22a (patch) | |
tree | 1aba356b781dbbc0c7735e03506f9f51a7fffb72 /rijndael.h | |
parent | c706936054da559cd8bd12425a07a4fdb2c9a17a (diff) | |
download | rijndael-cdf8fed1d002465246fa2029a3a2614fc3f9c22a.tar.gz rijndael-cdf8fed1d002465246fa2029a3a2614fc3f9c22a.tar.bz2 rijndael-cdf8fed1d002465246fa2029a3a2614fc3f9c22a.zip |
Initial implementation.
Diffstat (limited to 'rijndael.h')
-rw-r--r-- | rijndael.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/rijndael.h b/rijndael.h new file mode 100644 index 0000000..a1694d2 --- /dev/null +++ b/rijndael.h @@ -0,0 +1,74 @@ +/* + * Highly portable ANSI C implementation of Rijndael cipher. + * Written by Kaz Kylheku. + */ + +#ifndef RIJNDAEL_H +#define RIJNDAEL_H + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define RIJN_MAX_ROUNDS 14 + +/* + * Constants representing choice of Rijndael key or block size, + * either of which can be 128 bits, 192 bits or 256 bits. + */ + +typedef enum { + rijn_128 = 4, /* number of rows */ + rijn_192 = 6, + rijn_256 = 8 +} rijn_size_t; + +/* + * Rijndael parameters. + */ + +typedef struct { + rijn_size_t rijn_blockrows; + rijn_size_t rijn_keyrows; +} rijn_param_t; + +#define RIJN_PARAM_DEFAULT_INITIALIZER { rijn_128, rijn_256 } +#define RIJN_PARAM_INITIALIZER(BLOCKSZ, KEYSZ) { (BLOCKSZ), (KEYSZ) } + +void rijn_param_init(rijn_param_t *, rijn_size_t blocksz, rijn_size_t keysz); + +/* + * Rijndael keys are 128, 192 or 256 bits wide. There are up to + * RIJN_MAX_ROUNDS + 1 round keys needed, so the schedule is that big. + */ + +typedef unsigned char rijn_unit_t[4]; +typedef rijn_unit_t rijn_key_t[8]; +typedef rijn_unit_t rijn_block_t[8]; +typedef unsigned char rijn_flatblock_t[sizeof (rijn_block_t)]; + +typedef struct { + rijn_param_t rijn_param; + int rijn_nrounds; + rijn_block_t rijn_roundkey[RIJN_MAX_ROUNDS]; +} rijn_keysched_t; + +void rijn_sched_key(rijn_keysched_t *, rijn_key_t *, const rijn_param_t *); +void rijn_encrypt(rijn_keysched_t *, unsigned char *, const unsigned char *); +void rijn_decrypt(rijn_keysched_t *, unsigned char *, const unsigned char *); +void rijn_cbc_encrypt(rijn_keysched_t *, unsigned char *iv, unsigned char *out, + const unsigned char *in, size_t nblocks); +void rijn_cbc_decrypt(rijn_keysched_t *, unsigned char *iv, unsigned char *out, + const unsigned char *in, size_t nblocks); +void rijn_cfb_encrypt(rijn_keysched_t *, unsigned char *iv, unsigned char *out, + const unsigned char *pt, size_t nbytes); +void rijn_cfb_decrypt(rijn_keysched_t *, unsigned char *iv, unsigned char *out, + const unsigned char *in, size_t nbytes); + +#ifdef __cplusplus +} +#endif + +#endif |