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.2 2001/04/03 19:54:10 priikone
24 * updates. New data types.
26 * Revision 1.1.1.1 2000/06/27 11:36:54 priikone
27 * Importet from internal CVS/Added Log headers.
35 #include "rc5_internal.h"
38 * SILC Crypto API for RC5
41 /* Sets the key for the cipher. */
43 SILC_CIPHER_API_SET_KEY(rc5)
45 rc5_set_key((RC5Context *)context, (unsigned char *)key, keylen);
49 /* Sets the string as a new key for the cipher. The string is first
50 hashed and then used as a new key. */
52 SILC_CIPHER_API_SET_KEY_WITH_STRING(rc5)
54 /* unsigned char key[md5_hash_len];
55 SilcMarsContext *ctx = (SilcMarsContext *)context;
57 make_md5_hash(string, &key);
58 memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
59 memset(&key, 'F', sizeoof(key));
65 /* Returns the size of the cipher context. */
67 SILC_CIPHER_API_CONTEXT_LEN(rc5)
69 return sizeof(RC5Context);
72 /* Encrypts with the cipher in CBC mode. */
74 SILC_CIPHER_API_ENCRYPT_CBC(rc5)
76 uint32 *in, *out, *tiv;
84 tmp[0] = in[0] ^ tiv[0];
85 tmp[1] = in[1] ^ tiv[1];
86 rc5_encrypt((RC5Context *)context, tmp, out);
90 for (i = 8; i < len; i += 8) {
91 tmp[0] = in[0] ^ out[0 - 2];
92 tmp[1] = in[1] ^ out[1 - 2];
93 rc5_encrypt((RC5Context *)context, tmp, out);
101 /* Decrypts with the cipher in CBC mode. */
103 SILC_CIPHER_API_DECRYPT_CBC(rc5)
105 uint32 *in, *out, *tiv;
106 uint32 tmp[2], tmp2[2];
116 rc5_decrypt((RC5Context *)context, in, out);
122 for (i = 8; i < len; i += 8) {
127 rc5_decrypt((RC5Context *)context, in, out);