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:54 priikone
32 #include "rc5_internal.h"
35 * SILC Crypto API for RC5
38 /* Sets the key for the cipher. */
40 SILC_CIPHER_API_SET_KEY(rc5)
42 rc5_set_key((RC5Context *)context, (unsigned char *)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(rc5)
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(rc5)
66 return sizeof(RC5Context);
69 /* Encrypts with the cipher in CBC mode. */
71 SILC_CIPHER_API_ENCRYPT_CBC(rc5)
73 unsigned int *in, *out, *tiv;
77 in = (unsigned int *)src;
78 out = (unsigned int *)dst;
79 tiv = (unsigned int *)iv;
81 tmp[0] = in[0] ^ tiv[0];
82 tmp[1] = in[1] ^ tiv[1];
83 rc5_encrypt((RC5Context *)context, tmp, out);
87 for (i = 8; i < len; i += 8) {
88 tmp[0] = in[0] ^ out[0 - 2];
89 tmp[1] = in[1] ^ out[1 - 2];
90 rc5_encrypt((RC5Context *)context, tmp, out);
98 /* Decrypts with the cipher in CBC mode. */
100 SILC_CIPHER_API_DECRYPT_CBC(rc5)
102 unsigned int *in, *out, *tiv;
103 unsigned int tmp[2], tmp2[2];
106 in = (unsigned int *)src;
107 out = (unsigned int *)dst;
108 tiv = (unsigned int *)iv;
113 rc5_decrypt((RC5Context *)context, in, out);
119 for (i = 8; i < len; i += 8) {
124 rc5_decrypt((RC5Context *)context, in, out);