than the new one. For now, the client keys are saved with the
new filename format. The affected file silc/client_ops.c.
+ * Implemented the Cipher API for the rest of the ciphers that
+ did not implement it or implemented it the wrong way.
+
Wed May 2 13:31:26 EEST 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
* Register default ciphers and stuff when using the -S option
TODO/bugs In SILC Libraries
===========================
- o Some of the ciphers in lib/silccrypt does not implement the SILC
- Crypto API correctly.
+ o IPv6 support for ID's and into the code.
o Compression routines are missing. The protocol supports packet
compression thus it must be implemented. SILC Comp API must be
not in distribution), but it is not used yet, and it requires some
tweaking on the Makefiles (we want static lib not shared).
- o IPv6 support for ID's and into the code.
+ o The CAST cipher is not compiled currently due to compilation errors;
+ check those. Cast is in lib/silccrypt/cast.c.
TODO After 1.0
"server" : "client");
if (pk_type != SILC_SKE_PK_TYPE_SILC) {
- silc_say(client, conn, "We don't support %s key type %d",
+ silc_say(client, conn, "We don't support %s public key type %d",
entity, pk_type);
return FALSE;
}
if (!pw)
return FALSE;
- /* Replace all whitespaces with `_'. */
- fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
- for (i = 0; i < strlen(fingerprint); i++)
- if (fingerprint[i] == ' ')
- fingerprint[i] = '_';
-
memset(filename, 0, sizeof(filename));
memset(file, 0, sizeof(file));
- snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
- snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
- pw->pw_dir, entity, file);
- silc_free(fingerprint);
+ if (conn_type == SILC_SOCKET_TYPE_SERVER ||
+ conn_type == SILC_SOCKET_TYPE_ROUTER) {
+ snprintf(file, sizeof(file) - 1, "%skey_%s_%d.pub", entity,
+ conn->sock->hostname, conn->sock->port);
+ snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
+ pw->pw_dir, entity, file);
+ } else {
+ /* Replace all whitespaces with `_'. */
+ fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
+ for (i = 0; i < strlen(fingerprint); i++)
+ if (fingerprint[i] == ' ')
+ fingerprint[i] = '_';
+
+ snprintf(file, sizeof(file) - 1, "%skey_%s.pub", entity, fingerprint);
+ snprintf(filename, sizeof(filename) - 1, "%s/.silc/%skeys/%s",
+ pw->pw_dir, entity, file);
+ silc_free(fingerprint);
+ }
+
+ /* Take fingerprint of the public key */
fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
/* Check whether this key already exists */
}
if (!silc_pkcs_is_supported(pkcs_name)) {
- fprintf(stderr, "Unsupported PKCS `%s'", pkcs_name);
+ fprintf(stderr, "Unknown PKCS `%s'", pkcs_name);
return FALSE;
}
if (opt_create_keypair == TRUE) {
/* Create new key pair and exit */
+ silc_cipher_register_default();
+ silc_pkcs_register_default();
+ silc_hash_register_default();
+ silc_hmac_register_default();
silc_server_create_key_pair(opt_pkcs, opt_bits, opt_keypath,
NULL, NULL, NULL);
exit(0);
libsilccrypt_a_SOURCES = \
none.c \
- blowfish.c \
rc5.c \
rc6.c \
mars.c \
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.1 2001/02/26 17:32:08 priikone
- * updates.
- *
- * Revision 1.2 2000/10/02 18:31:46 priikone
- * Added rijndael (AES) to cipher list.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:55 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
#ifndef RIJNDAEL_H
#define RIJNDAEL_H
SILC_CIPHER_API_ENCRYPT_CBC(aes);
SILC_CIPHER_API_DECRYPT_CBC(aes);
-
#endif
#include "silcincludes.h"
#include "blowfish.h"
+/*
+ * SILC Crypto API for Blowfish
+ */
+
+/* Sets the key for the cipher. */
+
+SILC_CIPHER_API_SET_KEY(blowfish)
+{
+ blowfish_set_key((BlowfishContext *)context, (unsigned char *)key, keylen);
+ return TRUE;
+}
+
+/* Sets the string as a new key for the cipher. The string is first
+ hashed and then used as a new key. */
+
+SILC_CIPHER_API_SET_KEY_WITH_STRING(blowfish)
+{
+ /* unsigned char key[md5_hash_len];
+ SilcMarsContext *ctx = (SilcMarsContext *)context;
+
+ make_md5_hash(string, &key);
+ memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
+ memset(&key, 'F', sizeoof(key));
+ */
+
+ return 1;
+}
+
+/* Returns the size of the cipher context. */
+
+SILC_CIPHER_API_CONTEXT_LEN(blowfish)
+{
+ return sizeof(BlowfishContext);
+}
+
+/* Encrypts with the cipher in CBC mode. Source and destination buffers
+ maybe one and same. */
+
+SILC_CIPHER_API_ENCRYPT_CBC(blowfish)
+{
+ uint32 tiv[4];
+ int i;
+
+ SILC_CBC_GET_IV(tiv, iv);
+
+ SILC_CBC_ENC_PRE(tiv, src);
+ blowfish_encrypt((BlowfishContext *)context, tiv, tiv, 16);
+ SILC_CBC_ENC_POST(tiv, dst, src);
+
+ for (i = 16; i < len; i += 16) {
+ SILC_CBC_ENC_PRE(tiv, src);
+ blowfish_encrypt((BlowfishContext *)context, tiv, tiv, 16);
+ SILC_CBC_ENC_POST(tiv, dst, src);
+ }
+
+ SILC_CBC_PUT_IV(tiv, iv);
+
+ return TRUE;
+}
+
+/* Decrypts with the cipher in CBC mode. Source and destination buffers
+ maybe one and same. */
+
+SILC_CIPHER_API_DECRYPT_CBC(blowfish)
+{
+ uint32 tmp[4], tmp2[4], tiv[4];
+ int i;
+
+ SILC_CBC_GET_IV(tiv, iv);
+
+ SILC_CBC_DEC_PRE(tmp, src);
+ blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+
+ for (i = 16; i < len; i += 16) {
+ SILC_CBC_DEC_PRE(tmp, src);
+ blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+ }
+
+ SILC_CBC_PUT_IV(tiv, iv);
+
+ return TRUE;
+}
+
static u32 bf_pbox[16 + 2] =
{
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.2 2001/04/03 19:54:10 priikone
- * updates. New data types.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:54 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
#ifndef BLOWFISH_H
#define BLOWFISH_H
* SILC Crypto API for Blowfish
*/
-/* Sets the key for the cipher. */
-
-SILC_CIPHER_API_SET_KEY(blowfish)
-{
- blowfish_set_key((BlowfishContext *)context,
- (unsigned char *)key, keylen);
- return TRUE;
-}
-
-/* Sets the string as a new key for the cipher. The string is first
- hashed and then used as a new key. */
-
-SILC_CIPHER_API_SET_KEY_WITH_STRING(blowfish)
-{
- SilcHash hash;
- unsigned char key[16];
-
- silc_hash_alloc("md5", &hash);
- hash->make_hash(hash, string, stringlen, key);
-
- blowfish_set_key((BlowfishContext *)context, key, sizeof(key));
-
- silc_hash_free(hash);
- memset(&key, 'F', sizeof(key));
-
- return TRUE;
-}
-
-/* Returns the size of the cipher context. */
-
-SILC_CIPHER_API_CONTEXT_LEN(blowfish)
-{
- return sizeof(BlowfishContext);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_ENCRYPT_CBC(blowfish)
-{
- uint32 *in, *out, *tiv;
- uint32 tmp[4];
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- tmp[0] = in[0] ^ tiv[0];
- tmp[1] = in[1] ^ tiv[1];
- tmp[2] = in[2] ^ tiv[2];
- tmp[3] = in[3] ^ tiv[3];
- blowfish_encrypt((BlowfishContext *)context, tmp, out, 16);
- in += 4;
- out += 4;
-
- for (i = 16; i < len; i += 16) {
- tmp[0] = in[0] ^ out[0 - 4];
- tmp[1] = in[1] ^ out[1 - 4];
- tmp[2] = in[2] ^ out[2 - 4];
- tmp[3] = in[3] ^ out[3 - 4];
- blowfish_encrypt((BlowfishContext *)context, tmp, out, 16);
- in += 4;
- out += 4;
- }
-
- return 1;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_DECRYPT_CBC(blowfish)
-{
- uint32 *in, *out, *tiv;
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- blowfish_decrypt((BlowfishContext *)context, in, out, 16);
- out[0] ^= tiv[0];
- out[1] ^= tiv[1];
- out[2] ^= tiv[2];
- out[3] ^= tiv[3];
- in += 4;
- out += 4;
-
- for (i = 16; i < len; i += 16) {
- blowfish_decrypt((BlowfishContext *)context, in, out, 16);
- out[0] ^= in[0 - 4];
- out[1] ^= in[1 - 4];
- out[2] ^= in[2 - 4];
- out[3] ^= in[3 - 4];
- in += 4;
- out += 4;
- }
-
- return 1;
-}
+SILC_CIPHER_API_SET_KEY(blowfish);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(blowfish);
+SILC_CIPHER_API_CONTEXT_LEN(blowfish);
+SILC_CIPHER_API_ENCRYPT_CBC(blowfish);
+SILC_CIPHER_API_DECRYPT_CBC(blowfish);
#endif
\r
#include "silcincludes.h"\r
#include "cast.h"\r
+\r
+#define io_swap\r
\r
+/* \r
+ * SILC Crypto API for Cast-256\r
+ */\r
+\r
+/* Sets the key for the cipher. */\r
+\r
+SILC_CIPHER_API_SET_KEY(cast)\r
+{\r
+ uint32 k[8];\r
+\r
+ SILC_GET_WORD_KEY(key, k, keylen);\r
+ cast_set_key((CastContext *)context, k, keylen);\r
+\r
+ return TRUE;\r
+}\r
+\r
+/* Sets the string as a new key for the cipher. The string is first\r
+ hashed and then used as a new key. */\r
+\r
+SILC_CIPHER_API_SET_KEY_WITH_STRING(cast)\r
+{\r
+ /* unsigned char key[md5_hash_len];\r
+ SilcMarsContext *ctx = (SilcMarsContext *)context;\r
+\r
+ make_md5_hash(string, &key);\r
+ memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);\r
+ memset(&key, 'F', sizeoof(key));\r
+ */\r
+\r
+ return 1;\r
+}\r
+\r
+/* Returns the size of the cipher context. */\r
+\r
+SILC_CIPHER_API_CONTEXT_LEN(cast)\r
+{\r
+ return sizeof(CastContext);\r
+}\r
+\r
+/* Encrypts with the cipher in CBC mode. Source and destination buffers\r
+ maybe one and same. */\r
+\r
+SILC_CIPHER_API_ENCRYPT_CBC(cast)\r
+{\r
+ uint32 tiv[4];\r
+ int i;\r
+\r
+ SILC_CBC_GET_IV(tiv, iv);\r
+\r
+ SILC_CBC_ENC_PRE(tiv, src);\r
+ cast_encrypt((CastContext *)context, tiv, tiv);\r
+ SILC_CBC_ENC_POST(tiv, dst, src);\r
+\r
+ for (i = 16; i < len; i += 16) {\r
+ SILC_CBC_ENC_PRE(tiv, src);\r
+ cast_encrypt((CastContext *)context, tiv, tiv);\r
+ SILC_CBC_ENC_POST(tiv, dst, src);\r
+ }\r
+\r
+ SILC_CBC_PUT_IV(tiv, iv);\r
+\r
+ return TRUE;\r
+}\r
+\r
+/* Decrypts with the cipher in CBC mode. Source and destination buffers\r
+ maybe one and same. */\r
+\r
+SILC_CIPHER_API_DECRYPT_CBC(cast)\r
+{\r
+ uint32 tmp[4], tmp2[4], tiv[4];\r
+ int i;\r
+\r
+ SILC_CBC_GET_IV(tiv, iv);\r
+\r
+ SILC_CBC_DEC_PRE(tmp, src);\r
+ cast_decrypt((CastContext *)context, tmp, tmp2);\r
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);\r
+\r
+ for (i = 16; i < len; i += 16) {\r
+ SILC_CBC_DEC_PRE(tmp, src);\r
+ cast_decrypt((CastContext *)context, tmp, tmp2); \r
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);\r
+ }\r
+ \r
+ SILC_CBC_PUT_IV(tiv, iv);\r
+ \r
+ return TRUE;\r
+}\r
+\r
u4byte s_box[4][256] = \r
{ {\r
0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9C004dd3, \r
}\r
};\r
\r
-#define f1(y,x,kr,km) \\r
- t = rotl(km + x, kr); \\r
- u = s_box[0][byte(t,3)]; \\r
- u ^= s_box[1][byte(t,2)]; \\r
- u -= s_box[2][byte(t,1)]; \\r
- u += s_box[3][byte(t,0)]; \\r
+#define f1(y,x,kr,km) \\r
+ t = rotl(km + x, kr); \\r
+ u = s_box[0][byte(t,3)]; \\r
+ u ^= s_box[1][byte(t,2)]; \\r
+ u -= s_box[2][byte(t,1)]; \\r
+ u += s_box[3][byte(t,0)]; \\r
y ^= u\r
\r
-#define f2(y,x,kr,km) \\r
- t = rotl(km ^ x, kr); \\r
- u = s_box[0][byte(t,3)]; \\r
- u -= s_box[1][byte(t,2)]; \\r
- u += s_box[2][byte(t,1)]; \\r
- u ^= s_box[3][byte(t,0)]; \\r
+#define f2(y,x,kr,km) \\r
+ t = rotl(km ^ x, kr); \\r
+ u = s_box[0][byte(t,3)]; \\r
+ u -= s_box[1][byte(t,2)]; \\r
+ u += s_box[2][byte(t,1)]; \\r
+ u ^= s_box[3][byte(t,0)]; \\r
y ^= u\r
\r
-#define f3(y,x,kr,km) \\r
- t = rotl(km - x, kr); \\r
- u = s_box[0][byte(t,3)]; \\r
- u += s_box[1][byte(t,2)]; \\r
- u ^= s_box[2][byte(t,1)]; \\r
- u -= s_box[3][byte(t,0)]; \\r
+#define f3(y,x,kr,km) \\r
+ t = rotl(km - x, kr); \\r
+ u = s_box[0][byte(t,3)]; \\r
+ u += s_box[1][byte(t,2)]; \\r
+ u ^= s_box[2][byte(t,1)]; \\r
+ u -= s_box[3][byte(t,0)]; \\r
y ^= u\r
\r
-#define f_rnd(x,n) \\r
- f1(x[2],x[3],l_key[n], l_key[n + 4]); \\r
- f2(x[1],x[2],l_key[n + 1],l_key[n + 5]); \\r
- f3(x[0],x[1],l_key[n + 2],l_key[n + 6]); \\r
+#define f_rnd(x,n) \\r
+ f1(x[2],x[3],l_key[n], l_key[n + 4]); \\r
+ f2(x[1],x[2],l_key[n + 1],l_key[n + 5]); \\r
+ f3(x[0],x[1],l_key[n + 2],l_key[n + 6]); \\r
f1(x[3],x[0],l_key[n + 3],l_key[n + 7])\r
\r
-#define i_rnd(x, n) \\r
- f1(x[3],x[0],l_key[n + 3],l_key[n + 7]); \\r
- f3(x[0],x[1],l_key[n + 2],l_key[n + 6]); \\r
- f2(x[1],x[2],l_key[n + 1],l_key[n + 5]); \\r
+#define i_rnd(x, n) \\r
+ f1(x[3],x[0],l_key[n + 3],l_key[n + 7]); \\r
+ f3(x[0],x[1],l_key[n + 2],l_key[n + 6]); \\r
+ f2(x[1],x[2],l_key[n + 1],l_key[n + 5]); \\r
f1(x[2],x[3],l_key[n], l_key[n + 4])\r
\r
-#define k_rnd(k,tr,tm) \\r
- f1(k[6],k[7],tr[0],tm[0]); \\r
- f2(k[5],k[6],tr[1],tm[1]); \\r
- f3(k[4],k[5],tr[2],tm[2]); \\r
- f1(k[3],k[4],tr[3],tm[3]); \\r
- f2(k[2],k[3],tr[4],tm[4]); \\r
- f3(k[1],k[2],tr[5],tm[5]); \\r
- f1(k[0],k[1],tr[6],tm[6]); \\r
+#define k_rnd(k,tr,tm) \\r
+ f1(k[6],k[7],tr[0],tm[0]); \\r
+ f2(k[5],k[6],tr[1],tm[1]); \\r
+ f3(k[4],k[5],tr[2],tm[2]); \\r
+ f1(k[3],k[4],tr[3],tm[3]); \\r
+ f2(k[2],k[3],tr[4],tm[4]); \\r
+ f3(k[1],k[2],tr[5],tm[5]); \\r
+ f1(k[0],k[1],tr[6],tm[6]); \\r
f2(k[7],k[0],tr[7],tm[7])\r
\r
/* initialise the key schedule from the user supplied key */\r
}\r
\r
return l_key;\r
-};\r
+}\r
\r
/* encrypt a block of text */\r
\r
\r
out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
-};\r
+}\r
\r
/* decrypt a block of text */\r
\r
\r
out_blk[0] = io_swap(blk[0]); out_blk[1] = io_swap(blk[1]);\r
out_blk[2] = io_swap(blk[2]); out_blk[3] = io_swap(blk[3]);\r
-};\r
-\r
+}\r
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.2 2001/04/03 19:54:10 priikone
- * updates. New data types.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:54 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
#ifndef CAST_H
#define CAST_H
#include "cast_internal.h"
/*
- * SILC Crypto API for Cast
+ * SILC Crypto API for Cast-256
*/
-/* Sets the key for the cipher. */
-
-inline int silc_cast_init(void *context,
- const unsigned char *key,
- uint32 keylen)
-{
- cast_set_key((CastContext *)context, (uint32 *)key, keylen);
- return 1;
-}
-
-/* Sets the string as a new key for the cipher. The string is first
- hashed and then used as a new key. */
-
-inline int silc_cast_set_string_as_key(void *context,
- const unsigned char *string,
- uint32 stringlen)
-{
- /* SilcHash hash;
- unsigned char key[16];
-
- silc_hash_alloc("md5", &hash);
- hash->make_hash(hash, string, stringlen, key);
-
- cast_set_key((CastContext *)context, (const u4byte *)key, sizeof(key));
-
- silc_hash_free(hash);
- memset(&key, 'F', sizeof(key));
- */
- return TRUE;
-}
-
-/* Returns the size of the cipher context. */
-
-inline uint32 silc_cast_context_len()
-{
- return sizeof(CastContext);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-inline int silc_cast_encrypt_cbc(void *context,
- const unsigned char *src,
- unsigned char *dst,
- uint32 len,
- unsigned char *iv)
-{
- uint32 *in, *out, *tiv;
- uint32 tmp[4];
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- tmp[0] = in[0] ^ tiv[0];
- tmp[1] = in[1] ^ tiv[1];
- tmp[2] = in[2] ^ tiv[2];
- tmp[3] = in[3] ^ tiv[3];
- cast_encrypt((CastContext *)context, tmp, out);
- in += 4;
- out += 4;
-
- for (i = 16; i < len; i += 16) {
- tmp[0] = in[0] ^ out[0 - 4];
- tmp[1] = in[1] ^ out[1 - 4];
- tmp[2] = in[2] ^ out[2 - 4];
- tmp[3] = in[3] ^ out[3 - 4];
- cast_encrypt((CastContext *)context, tmp, out);
- in += 4;
- out += 4;
- }
-
- return 1;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-inline int silc_cast_decrypt_cbc(void *context,
- const unsigned char *src,
- unsigned char *dst,
- uint32 len,
- unsigned char *iv)
-{
- uint32 *in, *out, *tiv;
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- cast_decrypt((CastContext *)context, in, out);
- out[0] ^= tiv[0];
- out[1] ^= tiv[1];
- out[2] ^= tiv[2];
- out[3] ^= tiv[3];
- in += 4;
- out += 4;
-
- for (i = 16; i < len; i += 16) {
- cast_decrypt((CastContext *)context, in, out);
- out[0] ^= in[0 - 4];
- out[1] ^= in[1 - 4];
- out[2] ^= in[2 - 4];
- out[3] ^= in[3 - 4];
- in += 4;
- out += 4;
- }
-
- return 1;
-}
+SILC_CIPHER_API_SET_KEY(cast);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(cast);
+SILC_CIPHER_API_CONTEXT_LEN(cast);
+SILC_CIPHER_API_ENCRYPT_CBC(cast);
+SILC_CIPHER_API_DECRYPT_CBC(cast);
#endif
#include "none.h"
#include "mars.h"
+#include "rc5.h"
#include "rc6.h"
#include "twofish.h"
#include "aes.h"
+#include "blowfish.h"
#endif
#include "silcincludes.h"
#include "rc5.h"
+/*
+ * SILC Crypto API for RC5
+ */
+
+/* Sets the key for the cipher. */
+
+SILC_CIPHER_API_SET_KEY(aes)
+{
+ uint32 k[8];
+
+ SILC_GET_WORD_KEY(key, k, keylen);
+ rc5_set_key((RC5Context *)context, k, keylen);
+
+ return TRUE;
+}
+
+/* Sets the string as a new key for the cipher. The string is first
+ hashed and then used as a new key. */
+
+SILC_CIPHER_API_SET_KEY_WITH_STRING(aes)
+{
+ /* unsigned char key[md5_hash_len];
+ SilcMarsContext *ctx = (SilcMarsContext *)context;
+
+ make_md5_hash(string, &key);
+ memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
+ memset(&key, 'F', sizeoof(key));
+ */
+
+ return 1;
+}
+
+/* Returns the size of the cipher context. */
+
+SILC_CIPHER_API_CONTEXT_LEN(aes)
+{
+ return sizeof(RC5Context);
+}
+
+/* Encrypts with the cipher in CBC mode. Source and destination buffers
+ maybe one and same. */
+
+SILC_CIPHER_API_ENCRYPT_CBC(aes)
+{
+ uint32 tiv[4];
+ int i;
+
+ SILC_CBC_GET_IV(tiv, iv);
+
+ SILC_CBC_ENC_PRE(tiv, src);
+ rc5_encrypt((RC5Context *)context, tiv, tiv);
+ SILC_CBC_ENC_POST(tiv, dst, src);
+
+ for (i = 16; i < len; i += 16) {
+ SILC_CBC_ENC_PRE(tiv, src);
+ rc5_encrypt((RC5Context *)context, tiv, tiv);
+ SILC_CBC_ENC_POST(tiv, dst, src);
+ }
+
+ SILC_CBC_PUT_IV(tiv, iv);
+
+ return TRUE;
+}
+
+/* Decrypts with the cipher in CBC mode. Source and destination buffers
+ maybe one and same. */
+
+SILC_CIPHER_API_DECRYPT_CBC(aes)
+{
+ uint32 tmp[4], tmp2[4], tiv[4];
+ int i;
+
+ SILC_CBC_GET_IV(tiv, iv);
+
+ SILC_CBC_DEC_PRE(tmp, src);
+ rc5_decrypt((RC5Context *)context, tmp, tmp2);
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+
+ for (i = 16; i < len; i += 16) {
+ SILC_CBC_DEC_PRE(tmp, src);
+ rc5_decrypt((RC5Context *)context, tmp, tmp2);
+ SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
+ }
+
+ SILC_CBC_PUT_IV(tiv, iv);
+
+ return TRUE;
+}
+
/* RC5 encryption */
#define RC5E(i, A, B) \
A = A ^ B; \
/* Sets RC5 key */
-int rc5_set_key(RC5Context *ctx, char *key, int key_len)
+int rc5_set_key(RC5Context *ctx, const uint32 in_key[], int key_len)
{
- u32 *in_key = (u32 *)key;
u32 i, j, k, A, B, L[c];
u32 *out_key = ctx->out_key;
if (key_len < b || key_len > (2 * b))
return -1;
- // key_len *= 8;
-
/* init L */
for (i = 0; i < key_len / w; i++)
L[i] = in_key[i];
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.2 2001/04/03 19:54:10 priikone
- * updates. New data types.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:54 priikone
- * Importet from internal CVS/Added Log headers.
- *
- *
- */
#ifndef RC5_H
#define RC5_H
* SILC Crypto API for RC5
*/
-/* Sets the key for the cipher. */
-
-SILC_CIPHER_API_SET_KEY(rc5)
-{
- rc5_set_key((RC5Context *)context, (unsigned char *)key, keylen);
- return 1;
-}
-
-/* Sets the string as a new key for the cipher. The string is first
- hashed and then used as a new key. */
-
-SILC_CIPHER_API_SET_KEY_WITH_STRING(rc5)
-{
- /* unsigned char key[md5_hash_len];
- SilcMarsContext *ctx = (SilcMarsContext *)context;
-
- make_md5_hash(string, &key);
- memcpy(&ctx->key, mars_set_key(&key, keylen), keylen);
- memset(&key, 'F', sizeoof(key));
- */
-
- return 1;
-}
-
-/* Returns the size of the cipher context. */
-
-SILC_CIPHER_API_CONTEXT_LEN(rc5)
-{
- return sizeof(RC5Context);
-}
-
-/* Encrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_ENCRYPT_CBC(rc5)
-{
- uint32 *in, *out, *tiv;
- uint32 tmp[2];
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- tmp[0] = in[0] ^ tiv[0];
- tmp[1] = in[1] ^ tiv[1];
- rc5_encrypt((RC5Context *)context, tmp, out);
- in += 2;
- out += 2;
-
- for (i = 8; i < len; i += 8) {
- tmp[0] = in[0] ^ out[0 - 2];
- tmp[1] = in[1] ^ out[1 - 2];
- rc5_encrypt((RC5Context *)context, tmp, out);
- in += 2;
- out += 2;
- }
-
- return TRUE;
-}
-
-/* Decrypts with the cipher in CBC mode. */
-
-SILC_CIPHER_API_DECRYPT_CBC(rc5)
-{
- uint32 *in, *out, *tiv;
- uint32 tmp[2], tmp2[2];
- int i;
-
- in = (uint32 *)src;
- out = (uint32 *)dst;
- tiv = (uint32 *)iv;
-
- tmp[0] = in[0];
- tmp[1] = in[1];
- tmp[3] = in[3];
- rc5_decrypt((RC5Context *)context, in, out);
- out[0] ^= tiv[0];
- out[1] ^= tiv[1];
- in += 2;
- out += 2;
-
- for (i = 8; i < len; i += 8) {
- tmp2[0] = tmp[0];
- tmp2[1] = tmp[1];
- tmp[0] = in[0];
- tmp[1] = in[1];
- rc5_decrypt((RC5Context *)context, in, out);
- out[0] ^= tmp2[0];
- out[1] ^= tmp2[1];
- in += 2;
- out += 2;
- }
-
- return TRUE;
-}
+SILC_CIPHER_API_SET_KEY(rc5);
+SILC_CIPHER_API_SET_KEY_WITH_STRING(rc5);
+SILC_CIPHER_API_CONTEXT_LEN(rc5);
+SILC_CIPHER_API_ENCRYPT_CBC(rc5);
+SILC_CIPHER_API_DECRYPT_CBC(rc5);
#endif
} RC5Context;
/* Prototypes */
-int rc5_set_key(RC5Context *ctx, char *key, int key_len);
+int rc5_set_key(RC5Context *ctx, const uint32 in_key[], int key_len);
int rc5_encrypt(RC5Context *ctx, u32 *in, u32 *out);
int rc5_decrypt(RC5Context *ctx, u32 *in, u32 *out);