mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 11:05:40 +01:00
- Added generic cipher wrapper for integration with OpenVPN (donated by Fox-IT)
This commit is contained in:
parent
6d46812123
commit
8123e9d8f1
@ -6,6 +6,8 @@ Features
|
||||
by Fox-IT)
|
||||
* Added generic message digest wrapper for integration
|
||||
with OpenVPN (donated by Fox-IT)
|
||||
* Added generic cipher wrapper for integration
|
||||
with OpenVPN (donated by Fox-IT)
|
||||
|
||||
= Version 0.14.0 released on 2010-08-16
|
||||
Features
|
||||
|
351
include/polarssl/cipher.h
Normal file
351
include/polarssl/cipher.h
Normal file
@ -0,0 +1,351 @@
|
||||
/**
|
||||
* \file cipher.h
|
||||
*
|
||||
* \brief Generic cipher wrapper.
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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_CIPHER_H
|
||||
#define POLARSSL_CIPHER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef enum {
|
||||
POLARSSL_CIPHER_ID_NONE = 0,
|
||||
POLARSSL_CIPHER_ID_AES,
|
||||
POLARSSL_CIPHER_ID_DES,
|
||||
POLARSSL_CIPHER_ID_3DES,
|
||||
POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
} cipher_id_t;
|
||||
|
||||
typedef enum {
|
||||
POLARSSL_CIPHER_NONE = 0,
|
||||
POLARSSL_CIPHER_CAMELLIA_128_CBC = 0,
|
||||
POLARSSL_CIPHER_CAMELLIA_192_CBC,
|
||||
POLARSSL_CIPHER_CAMELLIA_256_CBC,
|
||||
POLARSSL_CIPHER_AES_128_CBC,
|
||||
POLARSSL_CIPHER_AES_192_CBC,
|
||||
POLARSSL_CIPHER_AES_256_CBC,
|
||||
POLARSSL_CIPHER_DES_CBC,
|
||||
POLARSSL_CIPHER_DES_EDE_CBC,
|
||||
POLARSSL_CIPHER_DES_EDE3_CBC
|
||||
} cipher_type_t;
|
||||
|
||||
typedef enum {
|
||||
POLARSSL_MODE_NONE = 0,
|
||||
POLARSSL_MODE_CBC,
|
||||
POLARSSL_MODE_CFB,
|
||||
POLARSSL_MODE_OFB,
|
||||
} cipher_mode_t;
|
||||
|
||||
typedef enum {
|
||||
POLARSSL_DECRYPT = 0,
|
||||
POLARSSL_ENCRYPT,
|
||||
} operation_t;
|
||||
|
||||
enum {
|
||||
/** Undefined key length */
|
||||
POLARSSL_KEY_LENGTH_NONE = 0,
|
||||
/** Key length, in bits, for DES keys */
|
||||
POLARSSL_KEY_LENGTH_DES = 56,
|
||||
/** Key length, in bits, for DES in two key EDE */
|
||||
POLARSSL_KEY_LENGTH_DES_EDE = 112,
|
||||
/** Key length, in bits, for DES in three-key EDE */
|
||||
POLARSSL_KEY_LENGTH_DES_EDE3 = 168,
|
||||
/** Maximum length of any IV, in bytes */
|
||||
POLARSSL_MAX_IV_LENGTH = 16,
|
||||
};
|
||||
|
||||
/**
|
||||
* Cipher information. Allows cipher functions to be called in a generic way.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Full cipher identifier (e.g. POLARSSL_CIPHER_AES_256_CBC) */
|
||||
cipher_type_t type;
|
||||
|
||||
/** Base Cipher type (e.g. POLARSSL_CIPHER_ID_AES) */
|
||||
cipher_id_t cipher;
|
||||
|
||||
/** Cipher mode (e.g. POLARSSL_CIPHER_MODE_CBC) */
|
||||
cipher_mode_t mode;
|
||||
|
||||
/** Cipher key length, in bits (default length for variable sized ciphers) */
|
||||
int key_length;
|
||||
|
||||
/** Name of the message digest */
|
||||
const char * name;
|
||||
|
||||
/** IV size, in bytes */
|
||||
int iv_size;
|
||||
|
||||
/** block size, in bytes */
|
||||
int block_size;
|
||||
|
||||
/** Encrypt using CBC */
|
||||
int (*cbc_func)( void *ctx, operation_t mode, int length, unsigned char *iv,
|
||||
const unsigned char *input, unsigned char *output );
|
||||
|
||||
/** Set key for encryption purposes */
|
||||
int (*setkey_enc_func)( void *ctx, const unsigned char *key, int key_length);
|
||||
|
||||
/** Set key for decryption purposes */
|
||||
int (*setkey_dec_func)( void *ctx, const unsigned char *key, int key_length);
|
||||
|
||||
/** Allocate a new context */
|
||||
void * (*ctx_alloc_func)( void );
|
||||
|
||||
/** Free the given context */
|
||||
void (*ctx_free_func)( void *ctx );
|
||||
|
||||
} cipher_info_t;
|
||||
|
||||
/**
|
||||
* Generic message digest context.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Information about the associated cipher */
|
||||
const cipher_info_t *cipher_info;
|
||||
|
||||
/** Key length to use */
|
||||
int key_length;
|
||||
|
||||
/** Operation that the context's key has been initialised for */
|
||||
operation_t operation;
|
||||
|
||||
/** Buffer for data that hasn't been encrypted yet */
|
||||
unsigned char unprocessed_data[POLARSSL_MAX_IV_LENGTH];
|
||||
|
||||
/** Number of bytes that still need processing */
|
||||
int unprocessed_len;
|
||||
|
||||
/** Current IV */
|
||||
unsigned char iv[POLARSSL_MAX_IV_LENGTH];
|
||||
|
||||
/** Cipher-specific context */
|
||||
void *cipher_ctx;
|
||||
} cipher_context_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Returns the cipher information structure associated
|
||||
* with the given cipher name.
|
||||
*
|
||||
* \param cipher_name Name of the cipher to search for.
|
||||
*
|
||||
* \return the cipher information structure associated with the
|
||||
* given cipher_name, or NULL if not found.
|
||||
*/
|
||||
const cipher_info_t *cipher_info_from_string( const char *cipher_name );
|
||||
|
||||
/**
|
||||
* \brief Returns the cipher information structure associated
|
||||
* with the given cipher type.
|
||||
*
|
||||
* \param cipher_type Type of the cipher to search for.
|
||||
*
|
||||
* \return the cipher information structure associated with the
|
||||
* given cipher_type, or NULL if not found.
|
||||
*/
|
||||
const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type );
|
||||
|
||||
/**
|
||||
* \brief Initialises and fills the cipher context structure with
|
||||
* the appropriate values.
|
||||
*
|
||||
* \param ctx context to initialise. May not be NULL.
|
||||
* \param cipher_info cipher to use.
|
||||
*
|
||||
* \return \c 0 on success, \c 1 on parameter failure, \c 2 if
|
||||
* allocation of the cipher-specific context failed.
|
||||
*/
|
||||
int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info );
|
||||
|
||||
/**
|
||||
* \brief Free the cipher-specific context of ctx. Freeing ctx
|
||||
* itself remains the responsibility of the caller.
|
||||
*
|
||||
* \param ctx Free the cipher-specific context
|
||||
*
|
||||
* \returns 0 on success, 1 if parameter verification fails.
|
||||
*/
|
||||
int cipher_free_ctx( cipher_context_t *ctx );
|
||||
|
||||
/**
|
||||
* \brief Returns the block size of the given cipher.
|
||||
*
|
||||
* \param ctx cipher's context. Must have been initialised.
|
||||
*
|
||||
* \return size of the cipher's blocks, or 0 if ctx has not been
|
||||
* initialised.
|
||||
*/
|
||||
static inline int cipher_get_block_size( const cipher_context_t *ctx )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->block_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the size of the cipher's IV.
|
||||
*
|
||||
* \param ctx cipher's context. Must have been initialised.
|
||||
*
|
||||
* \return size of the cipher's IV, or 0 if ctx has not been
|
||||
* initialised.
|
||||
*/
|
||||
static inline int cipher_get_iv_size( const cipher_context_t *ctx )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->iv_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the type of the given cipher.
|
||||
*
|
||||
* \param ctx cipher's context. Must have been initialised.
|
||||
*
|
||||
* \return type of the cipher, or POLARSSL_CIPHER_NONE if ctx has
|
||||
* not been initialised.
|
||||
*/
|
||||
static inline cipher_type_t cipher_get_type( const cipher_context_t *ctx )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the name of the given cipher, as a string.
|
||||
*
|
||||
* \param ctx cipher's context. Must have been initialised.
|
||||
*
|
||||
* \return name of the cipher, or NULL if ctx was not initialised.
|
||||
*/
|
||||
static inline const char *cipher_get_name( const cipher_context_t *ctx )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return 0;
|
||||
|
||||
return ctx->cipher_info->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the key length of the cipher.
|
||||
*
|
||||
* \param ctx cipher's context. Must have been initialised.
|
||||
*
|
||||
* \return cipher's key length, in bits, or
|
||||
* POLARSSL_KEY_LENGTH_NONE if ctx has not been
|
||||
* initialised.
|
||||
*/
|
||||
static inline int cipher_get_key_size ( const cipher_context_t *ctx )
|
||||
{
|
||||
if( NULL == ctx )
|
||||
return POLARSSL_KEY_LENGTH_NONE;
|
||||
|
||||
return ctx->key_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set the key to use with the given context.
|
||||
*
|
||||
* \param ctx generic cipher context. May not be NULL. Must have been
|
||||
* initialised using cipher_context_from_type or
|
||||
* cipher_context_from_name.
|
||||
* \param key The key to use.
|
||||
* \param key_length key length to use, in bits.
|
||||
* \param operation Operation that the key will be used for, either
|
||||
* POLARSSL_ENCRYPT or POLARSSL_DECRYPT.
|
||||
*
|
||||
* \returns 0 on success, 1 if parameter verification fails.
|
||||
*/
|
||||
int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, int key_len,
|
||||
const operation_t operation );
|
||||
|
||||
/**
|
||||
* \brief Reset the given context, setting the IV to iv
|
||||
*
|
||||
* \param ctx generic cipher context
|
||||
* \param iv IV to use
|
||||
*
|
||||
* \returns 0 on success, 1 if parameter verification fails.
|
||||
*/
|
||||
int cipher_reset( cipher_context_t *ctx, const unsigned char *iv );
|
||||
|
||||
/**
|
||||
* \brief Generic cipher update function. Encrypts/decrypts
|
||||
* using the given cipher context. Writes as many block
|
||||
* size'd blocks of data as possible to output. Any data
|
||||
* that cannot be written immediately will either be added
|
||||
* to the next block, or flushed when cipher_final is
|
||||
* called.
|
||||
*
|
||||
* \param ctx generic cipher context
|
||||
* \param input buffer holding the input data
|
||||
* \param ilen length of the input data
|
||||
* \param output buffer for the output data. Should be able to hold at
|
||||
* least ilen + block_size
|
||||
* \param olen length of the output data, will be filled with the
|
||||
* actual number of bytes written.
|
||||
*
|
||||
* \returns 0 on success, 1 if parameter verification fails.
|
||||
*/
|
||||
int cipher_update( cipher_context_t *ctx, const unsigned char *input, int ilen,
|
||||
unsigned char *output, int *olen );
|
||||
|
||||
/**
|
||||
* \brief Generic cipher finalisation function. If data still
|
||||
* needs to be flushed from an incomplete block, data
|
||||
* contained within it will be padded with the size of
|
||||
* the last block, and written to the output buffer.
|
||||
*
|
||||
* \param ctx Generic message digest context
|
||||
* \param output buffer to write data to. Needs block_size data available.
|
||||
* \param olen length of the data written to the output buffer.
|
||||
*
|
||||
* \returns 0 on success, 1 if parameter verification fails.
|
||||
*/
|
||||
int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int cipher_self_test( int verbose );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* POLARSSL_MD_H */
|
68
include/polarssl/cipher_wrap.h
Normal file
68
include/polarssl/cipher_wrap.h
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* \file cipher_wrap.h
|
||||
*
|
||||
* \brief Cipher wrappers.
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "polarssl/config.h"
|
||||
#include "polarssl/cipher.h"
|
||||
|
||||
#ifndef POLARSSL_CIPHER_WRAP_H
|
||||
#define POLARSSL_CIPHER_WRAP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_AES_C)
|
||||
|
||||
extern const cipher_info_t aes_128_cbc_info;
|
||||
extern const cipher_info_t aes_192_cbc_info;
|
||||
extern const cipher_info_t aes_256_cbc_info;
|
||||
|
||||
#endif /* defined(POLARSSL_AES_C) */
|
||||
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
|
||||
extern const cipher_info_t camellia_128_cbc_info;
|
||||
extern const cipher_info_t camellia_192_cbc_info;
|
||||
extern const cipher_info_t camellia_256_cbc_info;
|
||||
|
||||
#endif /* defined(POLARSSL_CAMELLIA_C) */
|
||||
|
||||
#if defined(POLARSSL_DES_C)
|
||||
|
||||
extern const cipher_info_t des_cbc_info;
|
||||
extern const cipher_info_t des_ede_cbc_info;
|
||||
extern const cipher_info_t des_ede3_cbc_info;
|
||||
|
||||
#endif /* defined(POLARSSL_DES_C) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* POLARSSL_CIPHER_WRAP_H */
|
@ -157,6 +157,14 @@
|
||||
*/
|
||||
#define POLARSSL_CERTS_C
|
||||
|
||||
/*
|
||||
* Module: library/cipher.c
|
||||
* Caller:
|
||||
*
|
||||
* Uncomment to enable generic cipher wrappers.
|
||||
*/
|
||||
#define POLARSSL_CIPHER_C
|
||||
|
||||
/*
|
||||
* Module: library/debug.c
|
||||
* Caller: library/ssl_cli.c
|
||||
|
@ -61,48 +61,60 @@ extern "C" {
|
||||
*
|
||||
* \param ctx DES context to be initialized
|
||||
* \param key 8-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, const unsigned char key[8] );
|
||||
int des_setkey_enc( des_context *ctx, const unsigned char key[8] );
|
||||
|
||||
/**
|
||||
* \brief DES key schedule (56-bit, decryption)
|
||||
*
|
||||
* \param ctx DES context to be initialized
|
||||
* \param key 8-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, const unsigned char key[8] );
|
||||
int des_setkey_dec( des_context *ctx, const unsigned char key[8] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, encryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 16-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des3_set2key_enc( des3_context *ctx, const unsigned char key[16] );
|
||||
int des3_set2key_enc( des3_context *ctx, const unsigned char key[16] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (112-bit, decryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 16-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des3_set2key_dec( des3_context *ctx, const unsigned char key[16] );
|
||||
int des3_set2key_dec( des3_context *ctx, const unsigned char key[16] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, encryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 24-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des3_set3key_enc( des3_context *ctx, const unsigned char key[24] );
|
||||
int des3_set3key_enc( des3_context *ctx, const unsigned char key[24] );
|
||||
|
||||
/**
|
||||
* \brief Triple-DES key schedule (168-bit, decryption)
|
||||
*
|
||||
* \param ctx 3DES context to be initialized
|
||||
* \param key 24-byte secret key
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
void des3_set3key_dec( des3_context *ctx, const unsigned char key[24] );
|
||||
int des3_set3key_dec( des3_context *ctx, const unsigned char key[24] );
|
||||
|
||||
/**
|
||||
* \brief DES-ECB block encryption/decryption
|
||||
|
@ -7,6 +7,8 @@ set(src
|
||||
bignum.c
|
||||
camellia.c
|
||||
certs.c
|
||||
cipher.c
|
||||
cipher_wrap.c
|
||||
debug.c
|
||||
des.c
|
||||
dhm.c
|
||||
|
@ -26,7 +26,8 @@ OBJS= aes.o arc4.o base64.o \
|
||||
ssl_cli.o ssl_srv.o ssl_tls.o \
|
||||
timing.o x509parse.o xtea.o \
|
||||
camellia.o version.o md.o \
|
||||
md_wrap.o
|
||||
md_wrap.o cipher.o cipher_wrap.o
|
||||
|
||||
|
||||
.SILENT:
|
||||
|
||||
|
346
library/cipher.c
Normal file
346
library/cipher.c
Normal file
@ -0,0 +1,346 @@
|
||||
/**
|
||||
* \file cipher.c
|
||||
*
|
||||
* \brief Generic cipher wrapper for PolarSSL
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "polarssl/config.h"
|
||||
|
||||
#if defined(POLARSSL_CIPHER_C)
|
||||
|
||||
#include "polarssl/cipher.h"
|
||||
#include "polarssl/cipher_wrap.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const cipher_info_t *cipher_info_from_type( cipher_type_t cipher_type )
|
||||
{
|
||||
/* Find static cipher information */
|
||||
switch ( cipher_type )
|
||||
{
|
||||
#if defined(POLARSSL_AES_C)
|
||||
case POLARSSL_CIPHER_AES_128_CBC:
|
||||
return &aes_128_cbc_info;
|
||||
case POLARSSL_CIPHER_AES_192_CBC:
|
||||
return &aes_192_cbc_info;
|
||||
case POLARSSL_CIPHER_AES_256_CBC:
|
||||
return &aes_256_cbc_info;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
|
||||
return &camellia_128_cbc_info;
|
||||
case POLARSSL_CIPHER_CAMELLIA_192_CBC:
|
||||
return &camellia_192_cbc_info;
|
||||
case POLARSSL_CIPHER_CAMELLIA_256_CBC:
|
||||
return &camellia_256_cbc_info;
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_DES_C)
|
||||
case POLARSSL_CIPHER_DES_CBC:
|
||||
return &des_cbc_info;
|
||||
case POLARSSL_CIPHER_DES_EDE_CBC:
|
||||
return &des_ede_cbc_info;
|
||||
case POLARSSL_CIPHER_DES_EDE3_CBC:
|
||||
return &des_ede3_cbc_info;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const cipher_info_t *cipher_info_from_string( const char *cipher_name )
|
||||
{
|
||||
if( NULL == cipher_name )
|
||||
return NULL;
|
||||
|
||||
/* Get the appropriate digest information */
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
if( !strcasecmp( "CAMELLIA-128-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_128_CBC );
|
||||
if( !strcasecmp( "CAMELLIA-192-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_192_CBC );
|
||||
if( !strcasecmp( "CAMELLIA-256-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_256_CBC );
|
||||
#endif
|
||||
#if defined(POLARSSL_AES_C)
|
||||
if( !strcasecmp( "AES-128-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_AES_128_CBC );
|
||||
if( !strcasecmp( "AES-192-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_AES_192_CBC );
|
||||
if( !strcasecmp( "AES-256-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_AES_256_CBC );
|
||||
#endif
|
||||
#if defined(POLARSSL_DES_C)
|
||||
if( !strcasecmp( "DES-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_DES_CBC );
|
||||
if( !strcasecmp( "DES-EDE-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE_CBC );
|
||||
if( !strcasecmp( "DES-EDE3-CBC", cipher_name ) )
|
||||
return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE3_CBC );
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info )
|
||||
{
|
||||
if( NULL == cipher_info || NULL == ctx )
|
||||
return 1;
|
||||
|
||||
memset( ctx, 0, sizeof( ctx ) );
|
||||
|
||||
if( NULL == ( ctx->cipher_ctx = cipher_info->ctx_alloc_func() ) )
|
||||
return 2;
|
||||
|
||||
ctx->cipher_info = cipher_info;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cipher_free_ctx( cipher_context_t *ctx )
|
||||
{
|
||||
if( ctx == NULL || ctx->cipher_info == NULL )
|
||||
return 1;
|
||||
|
||||
ctx->cipher_info->ctx_free_func( ctx->cipher_ctx );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cipher_setkey( cipher_context_t *ctx, const unsigned char *key,
|
||||
int key_length, const operation_t operation )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return 1;
|
||||
|
||||
ctx->key_length = key_length;
|
||||
ctx->operation = operation;
|
||||
|
||||
if (POLARSSL_ENCRYPT == operation)
|
||||
return ctx->cipher_info->setkey_enc_func( ctx->cipher_ctx, key,
|
||||
ctx->key_length );
|
||||
|
||||
if (POLARSSL_DECRYPT == operation)
|
||||
return ctx->cipher_info->setkey_dec_func( ctx->cipher_ctx, key,
|
||||
ctx->key_length );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cipher_reset( cipher_context_t *ctx, const unsigned char *iv )
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info || NULL == iv )
|
||||
return 1;
|
||||
|
||||
ctx->unprocessed_len = 0;
|
||||
|
||||
memcpy( ctx->iv, iv, cipher_get_iv_size( ctx ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cipher_update( cipher_context_t *ctx, const unsigned char *input, int ilen,
|
||||
unsigned char *output, int *olen )
|
||||
{
|
||||
int copy_len = 0;
|
||||
|
||||
if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen )
|
||||
return 1;
|
||||
|
||||
*olen = 0;
|
||||
|
||||
if( ctx->cipher_info->mode == POLARSSL_MODE_CBC )
|
||||
{
|
||||
/*
|
||||
* If there is not enough data for a full block, cache it.
|
||||
*/
|
||||
if( ( ctx->operation == POLARSSL_DECRYPT &&
|
||||
ilen + ctx->unprocessed_len <= cipher_get_block_size( ctx ) ) ||
|
||||
( ctx->operation == POLARSSL_ENCRYPT &&
|
||||
ilen + ctx->unprocessed_len < cipher_get_block_size( ctx ) ) )
|
||||
{
|
||||
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
||||
ilen );
|
||||
|
||||
ctx->unprocessed_len += ilen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process cached data first
|
||||
*/
|
||||
if( ctx->unprocessed_len != 0 )
|
||||
{
|
||||
copy_len = cipher_get_block_size( ctx ) - ctx->unprocessed_len;
|
||||
|
||||
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
||||
copy_len );
|
||||
|
||||
if( 0 != ctx->cipher_info->cbc_func( ctx->cipher_ctx,
|
||||
ctx->operation, cipher_get_block_size( ctx ), ctx->iv,
|
||||
ctx->unprocessed_data, output) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
*olen += cipher_get_block_size( ctx );
|
||||
output += cipher_get_block_size( ctx );
|
||||
ctx->unprocessed_len = 0;
|
||||
|
||||
input += copy_len;
|
||||
ilen -= copy_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cache final, incomplete block
|
||||
*/
|
||||
if( 0 != ilen )
|
||||
{
|
||||
copy_len = ilen % cipher_get_block_size( ctx );
|
||||
if( copy_len == 0 && ctx->operation == POLARSSL_DECRYPT )
|
||||
copy_len = cipher_get_block_size(ctx);
|
||||
|
||||
memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ),
|
||||
copy_len );
|
||||
|
||||
ctx->unprocessed_len += copy_len;
|
||||
ilen -= copy_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process remaining full blocks
|
||||
*/
|
||||
if( ilen )
|
||||
{
|
||||
if( 0 != ctx->cipher_info->cbc_func( ctx->cipher_ctx,
|
||||
ctx->operation, ilen, ctx->iv, input, output ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
*olen += ilen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void add_pkcs_padding( unsigned char *output, unsigned char output_len,
|
||||
int data_len )
|
||||
{
|
||||
unsigned char padding_len = output_len - data_len;
|
||||
unsigned char i = 0;
|
||||
|
||||
for( i = 0; i < padding_len; i++ )
|
||||
output[data_len + i] = padding_len;
|
||||
}
|
||||
|
||||
static int get_pkcs_padding( unsigned char *input, unsigned char input_len,
|
||||
int *data_len)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned char padding_len = 0;
|
||||
|
||||
if ( NULL == input || NULL == data_len )
|
||||
return 1;
|
||||
|
||||
padding_len = input[input_len - 1];
|
||||
|
||||
if ( padding_len > input_len )
|
||||
return 2;
|
||||
|
||||
for ( i = input_len - padding_len; i < input_len; i++ )
|
||||
if ( input[i] != padding_len )
|
||||
return 2;
|
||||
|
||||
*data_len = input_len - padding_len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cipher_finish( cipher_context_t *ctx, unsigned char *output, int *olen)
|
||||
{
|
||||
if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen )
|
||||
return 1;
|
||||
|
||||
*olen = 0;
|
||||
|
||||
if( POLARSSL_MODE_CBC == ctx->cipher_info->mode )
|
||||
{
|
||||
if( POLARSSL_ENCRYPT == ctx->operation )
|
||||
{
|
||||
add_pkcs_padding( ctx->unprocessed_data, cipher_get_iv_size( ctx ),
|
||||
ctx->unprocessed_len );
|
||||
}
|
||||
else if ( cipher_get_block_size( ctx ) != ctx->unprocessed_len )
|
||||
{
|
||||
/* For decrypt operations, expect a full block */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cipher block */
|
||||
if( 0 != ctx->cipher_info->cbc_func( ctx->cipher_ctx, ctx->operation,
|
||||
cipher_get_block_size( ctx ), ctx->iv, ctx->unprocessed_data,
|
||||
output ) )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set output size for decryption */
|
||||
if( POLARSSL_DECRYPT == ctx->operation )
|
||||
return get_pkcs_padding( output, cipher_get_block_size( ctx ), olen );
|
||||
|
||||
/* Set output size for encryption */
|
||||
*olen = cipher_get_block_size( ctx );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define ASSERT(x) if (!(x)) { \
|
||||
printf( "failed with %i at %s\n", value, (#x) ); \
|
||||
return( 1 ); \
|
||||
}
|
||||
/*
|
||||
* Checkup routine
|
||||
*/
|
||||
|
||||
int cipher_self_test( int verbose )
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
295
library/cipher_wrap.c
Normal file
295
library/cipher_wrap.c
Normal file
@ -0,0 +1,295 @@
|
||||
/**
|
||||
* \file md_wrap.c
|
||||
*
|
||||
* \brief Generic message digest wrapper for PolarSSL
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "polarssl/config.h"
|
||||
|
||||
#if defined(POLARSSL_CIPHER_C)
|
||||
|
||||
#include "polarssl/cipher_wrap.h"
|
||||
#include "polarssl/aes.h"
|
||||
#include "polarssl/camellia.h"
|
||||
#include "polarssl/des.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(POLARSSL_AES_C)
|
||||
|
||||
int aes_crypt_cbc_wrap( void *ctx, operation_t operation, int length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
|
||||
}
|
||||
|
||||
int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return aes_setkey_dec( (aes_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return aes_setkey_enc( (aes_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static void * aes_ctx_alloc( void )
|
||||
{
|
||||
return malloc( sizeof( aes_context ) );
|
||||
}
|
||||
|
||||
static void aes_ctx_free( void *ctx )
|
||||
{
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
const cipher_info_t aes_128_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_AES_128_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_AES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 128,
|
||||
.name = "AES-128-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = aes_crypt_cbc_wrap,
|
||||
.setkey_enc_func = aes_setkey_enc_wrap,
|
||||
.setkey_dec_func = aes_setkey_dec_wrap,
|
||||
.ctx_alloc_func = aes_ctx_alloc,
|
||||
.ctx_free_func = aes_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t aes_192_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_AES_192_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_AES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 192,
|
||||
.name = "AES-192-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = aes_crypt_cbc_wrap,
|
||||
.setkey_enc_func = aes_setkey_enc_wrap,
|
||||
.setkey_dec_func = aes_setkey_dec_wrap,
|
||||
.ctx_alloc_func = aes_ctx_alloc,
|
||||
.ctx_free_func = aes_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t aes_256_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_AES_256_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_AES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 256,
|
||||
.name = "AES-256-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = aes_crypt_cbc_wrap,
|
||||
.setkey_enc_func = aes_setkey_enc_wrap,
|
||||
.setkey_dec_func = aes_setkey_dec_wrap,
|
||||
.ctx_alloc_func = aes_ctx_alloc,
|
||||
.ctx_free_func = aes_ctx_free
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
|
||||
int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, int length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
|
||||
}
|
||||
|
||||
int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static void * camellia_ctx_alloc( void )
|
||||
{
|
||||
return malloc( sizeof( camellia_context ) );
|
||||
}
|
||||
|
||||
static void camellia_ctx_free( void *ctx )
|
||||
{
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
const cipher_info_t camellia_128_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_CAMELLIA_128_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 128,
|
||||
.name = "CAMELLIA-128-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = camellia_crypt_cbc_wrap,
|
||||
.setkey_enc_func = camellia_setkey_enc_wrap,
|
||||
.setkey_dec_func = camellia_setkey_dec_wrap,
|
||||
.ctx_alloc_func = camellia_ctx_alloc,
|
||||
.ctx_free_func = camellia_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t camellia_192_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_CAMELLIA_192_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 192,
|
||||
.name = "CAMELLIA-192-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = camellia_crypt_cbc_wrap,
|
||||
.setkey_enc_func = camellia_setkey_enc_wrap,
|
||||
.setkey_dec_func = camellia_setkey_dec_wrap,
|
||||
.ctx_alloc_func = camellia_ctx_alloc,
|
||||
.ctx_free_func = camellia_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t camellia_256_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_CAMELLIA_256_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = 256,
|
||||
.name = "CAMELLIA-256-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = camellia_crypt_cbc_wrap,
|
||||
.setkey_enc_func = camellia_setkey_enc_wrap,
|
||||
.setkey_dec_func = camellia_setkey_dec_wrap,
|
||||
.ctx_alloc_func = camellia_ctx_alloc,
|
||||
.ctx_free_func = camellia_ctx_free
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_DES_C)
|
||||
|
||||
int des_crypt_cbc_wrap( void *ctx, operation_t operation, int length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
|
||||
}
|
||||
|
||||
int des3_crypt_cbc_wrap( void *ctx, operation_t operation, int length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
|
||||
}
|
||||
|
||||
int des_setkey_dec_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des_setkey_dec( (des_context *) ctx, key );
|
||||
}
|
||||
|
||||
int des_setkey_enc_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des_setkey_enc( (des_context *) ctx, key );
|
||||
}
|
||||
|
||||
int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des3_set2key_dec( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des3_set2key_enc( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des3_set3key_dec( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, int key_length )
|
||||
{
|
||||
return des3_set3key_enc( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static void * des_ctx_alloc( void )
|
||||
{
|
||||
return malloc( sizeof( des_context ) );
|
||||
}
|
||||
|
||||
static void * des3_ctx_alloc( void )
|
||||
{
|
||||
return malloc( sizeof( des3_context ) );
|
||||
}
|
||||
|
||||
static void des_ctx_free( void *ctx )
|
||||
{
|
||||
free( ctx );
|
||||
}
|
||||
|
||||
const cipher_info_t des_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_DES_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_DES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = POLARSSL_KEY_LENGTH_DES,
|
||||
.name = "DES-CBC",
|
||||
.iv_size = 8,
|
||||
.block_size = 8,
|
||||
.cbc_func = des_crypt_cbc_wrap,
|
||||
.setkey_enc_func = des_setkey_enc_wrap,
|
||||
.setkey_dec_func = des_setkey_dec_wrap,
|
||||
.ctx_alloc_func = des_ctx_alloc,
|
||||
.ctx_free_func = des_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t des_ede_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_DES_EDE_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_DES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = POLARSSL_KEY_LENGTH_DES_EDE,
|
||||
.name = "DES-EDE-CBC",
|
||||
.iv_size = 16,
|
||||
.block_size = 16,
|
||||
.cbc_func = des3_crypt_cbc_wrap,
|
||||
.setkey_enc_func = des3_set2key_enc_wrap,
|
||||
.setkey_dec_func = des3_set2key_dec_wrap,
|
||||
.ctx_alloc_func = des3_ctx_alloc,
|
||||
.ctx_free_func = des_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t des_ede3_cbc_info = {
|
||||
.type = POLARSSL_CIPHER_DES_EDE3_CBC,
|
||||
.cipher = POLARSSL_CIPHER_ID_DES,
|
||||
.mode = POLARSSL_MODE_CBC,
|
||||
.key_length = POLARSSL_KEY_LENGTH_DES_EDE3,
|
||||
.name = "DES-EDE3-CBC",
|
||||
.iv_size = 8,
|
||||
.block_size = 8,
|
||||
.cbc_func = des3_crypt_cbc_wrap,
|
||||
.setkey_enc_func = des3_set3key_enc_wrap,
|
||||
.setkey_dec_func = des3_set3key_dec_wrap,
|
||||
.ctx_alloc_func = des3_ctx_alloc,
|
||||
.ctx_free_func = des_ctx_free
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
@ -362,15 +362,17 @@ static void des_setkey( unsigned long SK[32], const unsigned char key[8] )
|
||||
/*
|
||||
* DES key schedule (56-bit, encryption)
|
||||
*/
|
||||
void des_setkey_enc( des_context *ctx, const unsigned char key[8] )
|
||||
int des_setkey_enc( des_context *ctx, const unsigned char key[8] )
|
||||
{
|
||||
des_setkey( ctx->sk, key );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* DES key schedule (56-bit, decryption)
|
||||
*/
|
||||
void des_setkey_dec( des_context *ctx, const unsigned char key[8] )
|
||||
int des_setkey_dec( des_context *ctx, const unsigned char key[8] )
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -381,6 +383,8 @@ void des_setkey_dec( des_context *ctx, const unsigned char key[8] )
|
||||
SWAP( ctx->sk[i ], ctx->sk[30 - i] );
|
||||
SWAP( ctx->sk[i + 1], ctx->sk[31 - i] );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void des3_set2key( unsigned long esk[96],
|
||||
@ -411,23 +415,27 @@ static void des3_set2key( unsigned long esk[96],
|
||||
/*
|
||||
* Triple-DES key schedule (112-bit, encryption)
|
||||
*/
|
||||
void des3_set2key_enc( des3_context *ctx, const unsigned char key[16] )
|
||||
int des3_set2key_enc( des3_context *ctx, const unsigned char key[16] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set2key( ctx->sk, sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (112-bit, decryption)
|
||||
*/
|
||||
void des3_set2key_dec( des3_context *ctx, const unsigned char key[16] )
|
||||
int des3_set2key_dec( des3_context *ctx, const unsigned char key[16] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set2key( sk, ctx->sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void des3_set3key( unsigned long esk[96],
|
||||
@ -456,23 +464,27 @@ static void des3_set3key( unsigned long esk[96],
|
||||
/*
|
||||
* Triple-DES key schedule (168-bit, encryption)
|
||||
*/
|
||||
void des3_set3key_enc( des3_context *ctx, const unsigned char key[24] )
|
||||
int des3_set3key_enc( des3_context *ctx, const unsigned char key[24] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set3key( ctx->sk, sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Triple-DES key schedule (168-bit, decryption)
|
||||
*/
|
||||
void des3_set3key_dec( des3_context *ctx, const unsigned char key[24] )
|
||||
int des3_set3key_dec( des3_context *ctx, const unsigned char key[24] )
|
||||
{
|
||||
unsigned long sk[96];
|
||||
|
||||
des3_set3key( sk, ctx->sk, key );
|
||||
memset( sk, 0, sizeof( sk ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -23,6 +23,7 @@ add_test_suite(md)
|
||||
add_test_suite(aes)
|
||||
add_test_suite(camellia)
|
||||
add_test_suite(des)
|
||||
add_test_suite(cipher)
|
||||
add_test_suite(rsa)
|
||||
add_test_suite(xtea)
|
||||
add_test_suite(dhm)
|
||||
|
@ -15,7 +15,8 @@ APPS = test_suite_aes test_suite_arc4 \
|
||||
test_suite_mpi test_suite_rsa \
|
||||
test_suite_shax test_suite_x509parse\
|
||||
test_suite_xtea test_suite_debug \
|
||||
test_suite_version test_suite_md
|
||||
test_suite_version test_suite_md \
|
||||
test_suite_cipher
|
||||
|
||||
.SILENT:
|
||||
|
||||
@ -41,6 +42,10 @@ test_suite_camellia: test_suite_camellia.c ../library/libpolarssl.a
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_cipher: test_suite_cipher.c ../library/libpolarssl.a
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_des: test_suite_des.c ../library/libpolarssl.a
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
707
tests/suites/test_suite_cipher.data
Normal file
707
tests/suites/test_suite_cipher.data
Normal file
@ -0,0 +1,707 @@
|
||||
Cipher Selftest
|
||||
cipher_selftest:
|
||||
|
||||
Decrypt empty buffer
|
||||
dec_empty_buf:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_128_CBC:AES-128-CBC:128:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_CBC:128:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_192_CBC:AES-192-CBC:192:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_192_CBC:192:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_AES_256_CBC:AES-256-CBC:256:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_128_CBC:CAMELLIA-128-CBC:128:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_128_CBC:128:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_192_CBC:CAMELLIA-192-CBC:192:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_192_CBC:192:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_CAMELLIA_256_CBC:CAMELLIA-256-CBC:256:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_CAMELLIA_256_CBC:256:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_CBC:DES-CBC:56:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_CBC:56:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE_CBC:DES-EDE-CBC:112:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE_CBC:112:16:16:
|
||||
|
||||
Encrypt and decrypt 0 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:0
|
||||
|
||||
Encrypt and decrypt 1 byte
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:1
|
||||
|
||||
Encrypt and decrypt 2 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:2
|
||||
|
||||
Encrypt and decrypt 7 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:7
|
||||
|
||||
Encrypt and decrypt 8 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:8
|
||||
|
||||
Encrypt and decrypt 9 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:9
|
||||
|
||||
Encrypt and decrypt 15 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:15
|
||||
|
||||
Encrypt and decrypt 16 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:16
|
||||
|
||||
Encrypt and decrypt 17 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:17
|
||||
|
||||
Encrypt and decrypt 31 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:31
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:32
|
||||
|
||||
Encrypt and decrypt 32 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:33
|
||||
|
||||
Encrypt and decrypt 47 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:47
|
||||
|
||||
Encrypt and decrypt 48 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:48
|
||||
|
||||
Encrypt and decrypt 49 bytes
|
||||
enc_dec_buf:POLARSSL_CIPHER_DES_EDE3_CBC:DES-EDE3-CBC:168:49
|
||||
|
||||
Encrypt and decrypt 0 bytes in multiple parts
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:0:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:1:0:
|
||||
|
||||
Encrypt and decrypt 1 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:0:1:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:16:0:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 2
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:0:16:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 3
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:1:15:
|
||||
|
||||
Encrypt and decrypt 16 bytes in multiple parts 4
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:15:1:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:15:7:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:16:6:
|
||||
|
||||
Encrypt and decrypt 22 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:17:6:
|
||||
|
||||
Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_DES_EDE3_CBC:168:16:16:
|
184
tests/suites/test_suite_cipher.function
Normal file
184
tests/suites/test_suite_cipher.function
Normal file
@ -0,0 +1,184 @@
|
||||
BEGIN_HEADER
|
||||
#include <polarssl/config.h>
|
||||
#include <polarssl/cipher.h>
|
||||
END_HEADER
|
||||
|
||||
BEGIN_CASE
|
||||
enc_dec_buf:cipher_id:cipher_string:key_len:length:
|
||||
int length = {length};
|
||||
unsigned char key[32];
|
||||
unsigned char iv[16];
|
||||
|
||||
const cipher_info_t *cipher_info;
|
||||
cipher_context_t ctx_dec;
|
||||
cipher_context_t ctx_enc;
|
||||
|
||||
unsigned char inbuf[64];
|
||||
unsigned char encbuf[64];
|
||||
unsigned char decbuf[64];
|
||||
|
||||
int outlen = 0;
|
||||
int enclen = 0;
|
||||
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
memset( &ctx_enc, 0, sizeof( ctx_enc ) );
|
||||
|
||||
memset( inbuf, 5, 64 );
|
||||
memset( encbuf, 0, 64 );
|
||||
memset( decbuf, 0, 64 );
|
||||
|
||||
/* Check and get info structures */
|
||||
cipher_info = cipher_info_from_type( {cipher_id} );
|
||||
TEST_ASSERT( NULL != cipher_info );
|
||||
TEST_ASSERT( cipher_info_from_string( "{cipher_string}" ) == cipher_info );
|
||||
|
||||
/* Initialise enc and dec contexts */
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, {key_len}, POLARSSL_DECRYPT ) );
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, {key_len}, POLARSSL_ENCRYPT ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx_dec, iv ) );
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx_enc, iv ) );
|
||||
|
||||
enclen = cipher_get_block_size( &ctx_enc )
|
||||
* ( 1 + length / cipher_get_block_size( &ctx_enc ) );
|
||||
|
||||
/* encode length number of bytes from inbuf */
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
|
||||
TEST_ASSERT( outlen == enclen - cipher_get_block_size ( &ctx_enc ) );
|
||||
TEST_ASSERT( 0 == cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
|
||||
TEST_ASSERT( outlen == cipher_get_block_size ( &ctx_enc ) );
|
||||
|
||||
/* decode the previously encoded string */
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
|
||||
TEST_ASSERT( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
|
||||
TEST_ASSERT( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
|
||||
TEST_ASSERT( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
|
||||
|
||||
TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
dec_empty_buf:
|
||||
unsigned char key[32];
|
||||
unsigned char iv[16];
|
||||
|
||||
cipher_context_t ctx_dec;
|
||||
const cipher_info_t *cipher_info;
|
||||
|
||||
unsigned char encbuf[64];
|
||||
unsigned char decbuf[64];
|
||||
|
||||
int outlen = 0;
|
||||
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
|
||||
memset( encbuf, 0, 64 );
|
||||
memset( decbuf, 0, 64 );
|
||||
|
||||
/* Initialise enc and dec contexts */
|
||||
cipher_info = cipher_info_from_type( POLARSSL_CIPHER_AES_128_CBC );
|
||||
TEST_ASSERT( NULL != cipher_info);
|
||||
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, 128, POLARSSL_DECRYPT ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx_dec, iv ) );
|
||||
|
||||
/* decode 0-byte string */
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, 0, decbuf, &outlen ) );
|
||||
TEST_ASSERT( 0 == outlen );
|
||||
TEST_ASSERT( 1 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
|
||||
TEST_ASSERT( 0 == outlen );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
enc_dec_buf_multipart:cipher_id:key_len:first_length:second_length:
|
||||
int first_length = {first_length};
|
||||
int second_length = {second_length};
|
||||
int length = first_length + second_length;
|
||||
unsigned char key[32];
|
||||
unsigned char iv[16];
|
||||
|
||||
cipher_context_t ctx_dec;
|
||||
cipher_context_t ctx_enc;
|
||||
const cipher_info_t *cipher_info;
|
||||
|
||||
unsigned char inbuf[64];
|
||||
unsigned char encbuf[64];
|
||||
unsigned char decbuf[64];
|
||||
|
||||
int outlen = 0;
|
||||
int totaloutlen = 0;
|
||||
int enclen = 0;
|
||||
|
||||
memset( key, 0, 32 );
|
||||
memset( iv , 0, 16 );
|
||||
|
||||
memset( &ctx_dec, 0, sizeof( ctx_dec ) );
|
||||
memset( &ctx_enc, 0, sizeof( ctx_enc ) );
|
||||
|
||||
memset( inbuf, 5, 64 );
|
||||
memset( encbuf, 0, 64 );
|
||||
memset( decbuf, 0, 64 );
|
||||
|
||||
/* Initialise enc and dec contexts */
|
||||
cipher_info = cipher_info_from_type( {cipher_id} );
|
||||
TEST_ASSERT( NULL != cipher_info);
|
||||
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_dec, cipher_info ) );
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx_enc, cipher_info ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx_dec, key, {key_len}, POLARSSL_DECRYPT ) );
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx_enc, key, {key_len}, POLARSSL_ENCRYPT ) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx_dec, iv ) );
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx_enc, iv ) );
|
||||
|
||||
enclen = cipher_get_block_size(&ctx_enc )
|
||||
* ( 1 + length / cipher_get_block_size( &ctx_enc ) );
|
||||
|
||||
/* encode length number of bytes from inbuf */
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
|
||||
totaloutlen = outlen;
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
|
||||
totaloutlen += outlen;
|
||||
TEST_ASSERT( totaloutlen == enclen - cipher_get_block_size ( &ctx_enc ) );
|
||||
TEST_ASSERT( 0 == cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
|
||||
totaloutlen += outlen;
|
||||
TEST_ASSERT( outlen == cipher_get_block_size ( &ctx_enc ) );
|
||||
|
||||
/* decode the previously encoded string */
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx_dec, encbuf, enclen, decbuf, &outlen ) );
|
||||
TEST_ASSERT( enclen - cipher_get_block_size ( &ctx_enc ) == outlen );
|
||||
TEST_ASSERT( 0 == cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
|
||||
TEST_ASSERT( length - enclen + cipher_get_block_size ( &ctx_enc ) == outlen );
|
||||
|
||||
|
||||
TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
|
||||
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_dec ) );
|
||||
TEST_ASSERT( 0 == cipher_free_ctx( &ctx_enc ) );
|
||||
END_CASE
|
||||
|
||||
|
||||
BEGIN_CASE
|
||||
cipher_selftest:
|
||||
{
|
||||
TEST_ASSERT( cipher_self_test( 0 ) == 0 );
|
||||
}
|
||||
END_CASE
|
Loading…
Reference in New Issue
Block a user