projects
/
crypto.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Major restructuring of the internals of SILC Cipher API
[crypto.git]
/
lib
/
silccrypt
/
blowfish.c
diff --git
a/lib/silccrypt/blowfish.c
b/lib/silccrypt/blowfish.c
index fb3d8c8b65a8830cfeb728952225ad2f70bd27e1..862f1c2015f0ac980b90998d542bbaf92a1bdf44 100644
(file)
--- a/
lib/silccrypt/blowfish.c
+++ b/
lib/silccrypt/blowfish.c
@@
-33,49
+33,49
@@
*
*/
*
*/
-#include "silc
includes
.h"
+#include "silc
crypto
.h"
#include "blowfish_internal.h"
#include "blowfish.h"
#include "blowfish_internal.h"
#include "blowfish.h"
-/*
+/*
* SILC Crypto API for Blowfish
*/
/* Sets the key for the cipher. */
* SILC Crypto API for Blowfish
*/
/* Sets the key for the cipher. */
-SILC_CIPHER_API_SET_KEY(blowfish)
+SILC_CIPHER_API_SET_KEY(blowfish
_cbc
)
{
blowfish_set_key((BlowfishContext *)context, (unsigned char *)key, keylen);
return TRUE;
}
{
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. */
+/* Sets IV for the cipher. */
-SILC_CIPHER_API_SET_
KEY_WITH_STRING(blowfish
)
+SILC_CIPHER_API_SET_
IV(blowfish_cbc
)
{
{
- /* 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));
- */
+}
+
+/* Initialize */
- return 1;
+SILC_CIPHER_API_INIT(blowfish_cbc)
+{
+ return silc_calloc(1, sizeof(BlowfishContext));
}
}
-/*
Returns the size of the cipher context.
*/
+/*
Unnitialize
*/
-SILC_CIPHER_API_
CONTEXT_LEN(blowfish
)
+SILC_CIPHER_API_
UNINIT(blowfish_cbc
)
{
{
- return sizeof(BlowfishContext);
+ BlowfishContext *b = context;
+ memset(b, 0, sizeof(*b));
+ silc_free(b);
}
/* Encrypts with the cipher in CBC mode. Source and destination buffers
maybe one and same. */
}
/* Encrypts with the cipher in CBC mode. Source and destination buffers
maybe one and same. */
-SILC_CIPHER_API_ENCRYPT
_CBC(blowfish
)
+SILC_CIPHER_API_ENCRYPT
(blowfish_cbc
)
{
SilcUInt32 tiv[4];
int i;
{
SilcUInt32 tiv[4];
int i;
@@
-100,7
+100,7
@@
SILC_CIPHER_API_ENCRYPT_CBC(blowfish)
/* Decrypts with the cipher in CBC mode. Source and destination buffers
maybe one and same. */
/* Decrypts with the cipher in CBC mode. Source and destination buffers
maybe one and same. */
-SILC_CIPHER_API_DECRYPT
_CBC(blowfish
)
+SILC_CIPHER_API_DECRYPT
(blowfish_cbc
)
{
SilcUInt32 tmp[4], tmp2[4], tiv[4];
int i;
{
SilcUInt32 tmp[4], tmp2[4], tiv[4];
int i;
@@
-116,9
+116,9
@@
SILC_CIPHER_API_DECRYPT_CBC(blowfish)
blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
}
blowfish_decrypt((BlowfishContext *)context, tmp, tmp2, 16);
SILC_CBC_DEC_POST(tmp2, dst, src, tmp, tiv);
}
-
+
SILC_CBC_PUT_IV(tiv, iv);
SILC_CBC_PUT_IV(tiv, iv);
-
+
return TRUE;
}
return TRUE;
}
@@
-391,7
+391,7
@@
static u32 bf_sbox[256 * 4] =
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
};
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
};
-/*
+/*
* Round loop unrolling macros, S is a pointer to a S-Box array
* organized in 4 SilcUInt32s at a row.
*/
* Round loop unrolling macros, S is a pointer to a S-Box array
* organized in 4 SilcUInt32s at a row.
*/
@@
-408,7
+408,7
@@
static u32 bf_sbox[256 * 4] =
/*
* The blowfish encipher, processes 64-bit blocks.
/*
* The blowfish encipher, processes 64-bit blocks.
- * NOTE: This function MUSTN'T respect endianess
+ * NOTE: This function MUSTN'T respect endianess
*/
int blowfish_encrypt(BlowfishContext *ctx,
*/
int blowfish_encrypt(BlowfishContext *ctx,
@@
-534,7
+534,7
@@
int blowfish_set_key(BlowfishContext *ctx,
for (i = 0; i < 16 + 2; i += 2)
{
blowfish_encrypt(ctx, data, data, 8);
for (i = 0; i < 16 + 2; i += 2)
{
blowfish_encrypt(ctx, data, data, 8);
-
+
P[i] = data[0];
P[i + 1] = data[1];
}
P[i] = data[0];
P[i + 1] = data[1];
}