5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
23 * Revision 1.1 2000/06/27 11:36:55 priikone
32 #include "rijndael_internal.h"
35 * SILC Crypto API for Rijndael
38 /* Sets the key for the cipher. */
40 SILC_CIPHER_API_SET_KEY(rijndael)
42 rijndael_set_key((RijndaelContext *)context, (unsigned int *)key, keylen);
46 /* Sets the string as a new key for the cipher. The string is first
47 hashed and then used as a new key. */
49 SILC_CIPHER_API_SET_KEY_WITH_STRING(rijndael)
51 /* unsigned char key[md5_hash_len];
52 SilcMarsContext *ctx = (SilcMarsContext *)context;
54 make_md5_hash(string, &key);
55 memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
56 memset(&key, 'F', sizeoof(key));
62 /* Returns the size of the cipher context. */
64 SILC_CIPHER_API_CONTEXT_LEN(rijnadel)
66 return sizeof(RijndaelContext);
69 /* Encrypts with the cipher in CBC mode. Source and destination buffers
70 maybe one and same. */
72 SILC_CIPHER_API_ENCRYPT_CBC(rijndael)
74 unsigned int *in, *out, *tiv;
78 in = (unsigned int *)src;
79 out = (unsigned int *)dst;
80 tiv = (unsigned int *)iv;
82 tmp[0] = in[0] ^ tiv[0];
83 tmp[1] = in[1] ^ tiv[1];
84 tmp[2] = in[2] ^ tiv[2];
85 tmp[3] = in[3] ^ tiv[3];
86 rijndael_encrypt((RijndaelContext *)context, tmp, out);
90 for (i = 16; i < len; i += 16) {
91 tmp[0] = in[0] ^ out[0 - 4];
92 tmp[1] = in[1] ^ out[1 - 4];
93 tmp[2] = in[2] ^ out[2 - 4];
94 tmp[3] = in[3] ^ out[3 - 4];
95 rijndael_encrypt((RijndaelContext *)context, tmp, out);
103 /* Decrypts with the cipher in CBC mode. Source and destination buffers
104 maybe one and same. */
106 SILC_CIPHER_API_DECRYPT_CBC(rijndael)
108 unsigned int *in, *out, *tiv;
109 unsigned int tmp[4], tmp2[4];
112 in = (unsigned int *)src;
113 out = (unsigned int *)dst;
114 tiv = (unsigned int *)iv;
120 rijndael_decrypt((RijndaelContext *)context, in, out);
128 for (i = 16; i < len; i += 16) {
137 rijndael_decrypt((RijndaelContext *)context, in, out);