Commit 38119b18 authored by Paul Bakker's avatar Paul Bakker
Browse files

- Added first version of Camellia

parent 7a7c78fd
......@@ -3,7 +3,8 @@ PolarSSL ChangeLog
= Version 0.x released on 2009-01-??
* Migrated XySSL to PolarSSL
* Added XTEA symmetric cipher
? * Added Camellia symmetric cipher
* Added Camellia symmetric cipher
? * Added SSL Support for Camellia
? * Fixed dangerous bug that can cause a heap overflow in
rsa_pkcs1_decrypt
......
/**
* \file camellia.h
*
* Copyright (C) 2009 Paul Bakker
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef POLARSSL_CAMELLIA_H
#define POLARSSL_CAMELLIA_H
#define CAMELLIA_ENCRYPT 1
#define CAMELLIA_DECRYPT 0
/**
* \brief CAMELLIA context structure
*/
typedef struct
{
int nr; /*!< number of rounds */
unsigned long rk[68]; /*!< CAMELLIA round keys */
}
camellia_context;
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief CAMELLIA key schedule (encryption)
*
* \param ctx CAMELLIA context to be initialized
* \param key encryption key
* \param keysize must be 128, 192 or 256
*/
void camellia_setkey_enc( camellia_context *ctx, unsigned char *key, int keysize );
/**
* \brief CAMELLIA key schedule (decryption)
*
* \param ctx CAMELLIA context to be initialized
* \param key decryption key
* \param keysize must be 128, 192 or 256
*/
void camellia_setkey_dec( camellia_context *ctx, unsigned char *key, int keysize );
/**
* \brief CAMELLIA-ECB block encryption/decryption
*
* \param ctx CAMELLIA context
* \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
* \param input 16-byte input block
* \param output 16-byte output block
*/
void camellia_crypt_ecb( camellia_context *ctx,
int mode,
unsigned char input[16],
unsigned char output[16] );
/**
* \brief CAMELLIA-CBC buffer encryption/decryption
*
* \param ctx CAMELLIA context
* \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
* \param length length of the input data
* \param iv initialization vector (updated after use)
* \param input buffer holding the input data
* \param output buffer holding the output data
*/
void camellia_crypt_cbc( camellia_context *ctx,
int mode,
int length,
unsigned char iv[16],
unsigned char *input,
unsigned char *output );
/**
* \brief CAMELLIA-CFB128 buffer encryption/decryption
*
* \param ctx CAMELLIA context
* \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
* \param length length of the input data
* \param iv_off offset in IV (updated after use)
* \param iv initialization vector (updated after use)
* \param input buffer holding the input data
* \param output buffer holding the output data
*/
void camellia_crypt_cfb128( camellia_context *ctx,
int mode,
int length,
int *iv_off,
unsigned char iv[16],
unsigned char *input,
unsigned char *output );
/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int camellia_self_test( int verbose );
#ifdef __cplusplus
}
#endif
#endif /* camellia.h */
......@@ -120,6 +120,14 @@
*/
#define POLARSSL_BIGNUM_C
/*
* Module: library/camellia.c
* Caller:
*
* This module enabled the following cipher suites:
*/
#define POLARSSL_CAMELLIA_C
/*
* Module: library/certs.c
* Caller:
......
......@@ -24,7 +24,8 @@ OBJS= aes.o arc4.o base64.o \
net.o padlock.o rsa.o \
sha1.o sha2.o sha4.o \
ssl_cli.o ssl_srv.o ssl_tls.o \
timing.o x509parse.o xtea.o
timing.o x509parse.o xtea.o \
camellia.o
.SILENT:
......
This diff is collapsed.
......@@ -37,6 +37,7 @@
#include "polarssl/arc4.h"
#include "polarssl/des.h"
#include "polarssl/aes.h"
#include "polarssl/camellia.h"
#include "polarssl/rsa.h"
#include "polarssl/timing.h"
......@@ -67,6 +68,9 @@ int main( void )
#if defined(POLARSSL_AES_C)
aes_context aes;
#endif
#if defined(POLARSSL_CAMELLIA_C)
camellia_context camellia;
#endif
#if defined(POLARSSL_RSA_C)
rsa_context rsa;
#endif
......@@ -215,6 +219,30 @@ int main( void )
}
#endif
#if defined(POLARSSL_CAMELLIA_C)
for( keysize = 128; keysize <= 256; keysize += 64 )
{
printf( " CAMELLIA-%d : ", keysize );
fflush( stdout );
memset( buf, 0, sizeof( buf ) );
memset( tmp, 0, sizeof( tmp ) );
camellia_setkey_enc( &camellia, tmp, keysize );
set_alarm( 1 );
for( i = 1; ! alarmed; i++ )
camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
tsc = hardclock();
for( j = 0; j < 4096; j++ )
camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
( hardclock() - tsc ) / ( j * BUFSIZE ) );
}
#endif
#if defined(POLARSSL_RSA_C)
rsa_init( &rsa, RSA_PKCS_V15, 0, myrand, NULL );
rsa_gen_key( &rsa, 1024, 65537 );
......
......@@ -126,6 +126,11 @@ int main( int argc, char *argv[] )
return( ret );
#endif
#if defined(POLARSSL_CAMELLIA_C)
if( ( ret = camellia_self_test( v ) ) != 0 )
return( ret );
#endif
if( v != 0 )
{
printf( " [ All tests passed ]\n\n" );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment