X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Fcast.c;h=ac8aa770b50d60daff1474a079c66ee258335102;hb=9f20f0382b6229eca740925a73f96294f6dcedc6;hp=522078871f7b06adb4aa23aa8895a636d33f52c3;hpb=97ca3ffe0ce65ac0c5fa3274284825537e996c78;p=crypto.git diff --git a/lib/silccrypt/cast.c b/lib/silccrypt/cast.c index 52207887..ac8aa770 100644 --- a/lib/silccrypt/cast.c +++ b/lib/silccrypt/cast.c @@ -58,7 +58,7 @@ Mean: 674 cycles = 38.0 mbits/sec */ -#include "silc.h" +#include "silccrypto.h" #include "cast_internal.h" #include "cast.h" @@ -70,7 +70,7 @@ Mean: 674 cycles = 38.0 mbits/sec /* Sets the key for the cipher. */ -SILC_CIPHER_API_SET_KEY(cast) +SILC_CIPHER_API_SET_KEY(cast_cbc) { SilcUInt32 k[8]; @@ -80,21 +80,41 @@ SILC_CIPHER_API_SET_KEY(cast) return TRUE; } -/* Returns the size of the cipher context. */ +/* Sets IV for the cipher. */ -SILC_CIPHER_API_CONTEXT_LEN(cast) +SILC_CIPHER_API_SET_IV(cast_cbc) { - return sizeof(CastContext); + +} + +/* Initialize */ + +SILC_CIPHER_API_INIT(cast_cbc) +{ + return silc_calloc(1, sizeof(CastContext)); +} + +/* Uninitialize */ + +SILC_CIPHER_API_UNINIT(cast_cbc) +{ + CastContext *cast = context; + memset(cast, 0, sizeof(*cast)); + silc_free(cast); } /* Encrypts with the cipher in CBC mode. Source and destination buffers maybe one and same. */ -SILC_CIPHER_API_ENCRYPT_CBC(cast) +SILC_CIPHER_API_ENCRYPT(cast_cbc) { SilcUInt32 tiv[4]; int i; + SILC_ASSERT((len & (16 - 1)) == 0); + if (len & (16 - 1)) + return FALSE; + SILC_CBC_GET_IV(tiv, iv); SILC_CBC_ENC_PRE(tiv, src); @@ -115,11 +135,14 @@ SILC_CIPHER_API_ENCRYPT_CBC(cast) /* Decrypts with the cipher in CBC mode. Source and destination buffers maybe one and same. */ -SILC_CIPHER_API_DECRYPT_CBC(cast) +SILC_CIPHER_API_DECRYPT(cast_cbc) { SilcUInt32 tmp[4], tmp2[4], tiv[4]; int i; + if (len & (16 - 1)) + return FALSE; + SILC_CBC_GET_IV(tiv, iv); SILC_CBC_DEC_PRE(tmp, src);