summaryrefslogtreecommitdiff
path: root/library/cipher_wrap.c
diff options
context:
space:
mode:
authorPaul Bakker <p.j.bakker@polarssl.org>2012-07-04 17:10:40 +0000
committerPaul Bakker <p.j.bakker@polarssl.org>2012-07-04 17:10:40 +0000
commit6132d0aa9387e9a23ac7608d269eed7c4f5424e9 (patch)
tree228c5db47e5c004066f28fe9ebf17769e832c795 /library/cipher_wrap.c
parent26c4e3cb0bb6547de0d94de4c41c838b09ee08bb (diff)
- Added Blowfish to generic cipher layer
- Renamed POLARSSL_MODE_CFB128 to POLARSSL_MODE_CFB
Diffstat (limited to 'library/cipher_wrap.c')
-rw-r--r--library/cipher_wrap.c128
1 files changed, 122 insertions, 6 deletions
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index 99e50928..6b85903f 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -45,6 +45,10 @@
#include "polarssl/des.h"
#endif
+#if defined(POLARSSL_BLOWFISH_C)
+#include "polarssl/blowfish.h"
+#endif
+
#include <stdlib.h>
#if defined(POLARSSL_AES_C)
@@ -157,7 +161,7 @@ const cipher_info_t aes_256_cbc_info = {
#if defined(POLARSSL_CIPHER_MODE_CFB)
const cipher_info_t aes_128_cfb128_info = {
POLARSSL_CIPHER_AES_128_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
128,
"AES-128-CFB128",
16,
@@ -167,7 +171,7 @@ const cipher_info_t aes_128_cfb128_info = {
const cipher_info_t aes_192_cfb128_info = {
POLARSSL_CIPHER_AES_192_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
192,
"AES-192-CFB128",
16,
@@ -177,7 +181,7 @@ const cipher_info_t aes_192_cfb128_info = {
const cipher_info_t aes_256_cfb128_info = {
POLARSSL_CIPHER_AES_256_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
256,
"AES-256-CFB128",
16,
@@ -330,7 +334,7 @@ const cipher_info_t camellia_256_cbc_info = {
#if defined(POLARSSL_CIPHER_MODE_CFB)
const cipher_info_t camellia_128_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_128_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
128,
"CAMELLIA-128-CFB128",
16,
@@ -340,7 +344,7 @@ const cipher_info_t camellia_128_cfb128_info = {
const cipher_info_t camellia_192_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_192_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
192,
"CAMELLIA-192-CFB128",
16,
@@ -350,7 +354,7 @@ const cipher_info_t camellia_192_cfb128_info = {
const cipher_info_t camellia_256_cfb128_info = {
POLARSSL_CIPHER_CAMELLIA_256_CFB128,
- POLARSSL_MODE_CFB128,
+ POLARSSL_MODE_CFB,
256,
"CAMELLIA-256-CFB128",
16,
@@ -558,6 +562,118 @@ const cipher_info_t des_ede3_cbc_info = {
};
#endif
+#if defined(POLARSSL_BLOWFISH_C)
+
+int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
+ unsigned char *iv, const unsigned char *input, unsigned char *output )
+{
+ return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
+}
+
+int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
+ size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
+{
+#if defined(POLARSSL_CIPHER_MODE_CFB)
+ return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
+#else
+ ((void) ctx);
+ ((void) operation);
+ ((void) length);
+ ((void) iv_off);
+ ((void) iv);
+ ((void) input);
+ ((void) output);
+
+ return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
+#endif
+}
+
+int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
+ size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
+ const unsigned char *input, unsigned char *output )
+{
+#if defined(POLARSSL_CIPHER_MODE_CTR)
+ return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
+ stream_block, input, output );
+#else
+ ((void) ctx);
+ ((void) length);
+ ((void) nc_off);
+ ((void) nonce_counter);
+ ((void) stream_block);
+ ((void) input);
+ ((void) output);
+
+ return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
+#endif
+}
+
+int blowfish_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
+{
+ return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
+}
+
+int blowfish_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
+{
+ return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
+}
+
+static void * blowfish_ctx_alloc( void )
+{
+ return malloc( sizeof( blowfish_context ) );
+}
+
+static void blowfish_ctx_free( void *ctx )
+{
+ free( ctx );
+}
+
+const cipher_base_t blowfish_info = {
+ POLARSSL_CIPHER_ID_BLOWFISH,
+ blowfish_crypt_cbc_wrap,
+ blowfish_crypt_cfb64_wrap,
+ blowfish_crypt_ctr_wrap,
+ blowfish_setkey_enc_wrap,
+ blowfish_setkey_dec_wrap,
+ blowfish_ctx_alloc,
+ blowfish_ctx_free
+};
+
+const cipher_info_t blowfish_cbc_info = {
+ POLARSSL_CIPHER_BLOWFISH_CBC,
+ POLARSSL_MODE_CBC,
+ 32,
+ "BLOWFISH-CBC",
+ 8,
+ 8,
+ &blowfish_info
+};
+
+#if defined(POLARSSL_CIPHER_MODE_CFB)
+const cipher_info_t blowfish_cfb64_info = {
+ POLARSSL_CIPHER_BLOWFISH_CFB64,
+ POLARSSL_MODE_CFB,
+ 32,
+ "BLOWFISH-CFB64",
+ 8,
+ 8,
+ &blowfish_info
+};
+#endif /* POLARSSL_CIPHER_MODE_CFB */
+
+#if defined(POLARSSL_CIPHER_MODE_CTR)
+const cipher_info_t blowfish_ctr_info = {
+ POLARSSL_CIPHER_BLOWFISH_CTR,
+ POLARSSL_MODE_CTR,
+ 32,
+ "BLOWFISH-CTR",
+ 8,
+ 8,
+ &blowfish_info
+};
+#endif /* POLARSSL_CIPHER_MODE_CTR */
+#endif /* POLARSSL_BLOWFISH_C */
+
#if defined(POLARSSL_CIPHER_NULL_CIPHER)
static void * null_ctx_alloc( void )
{