+/* \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