mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 18:05:42 +01:00
Merged platform compatibility layer
This commit is contained in:
commit
6a28e722c9
@ -9,6 +9,10 @@ Features
|
||||
* Option to set the Curve preference order
|
||||
* Support for RSASSA-PSS keys and signatures in certificates, CSRs
|
||||
and CRLs
|
||||
* Single Platform compatilibity layer (for memory / printf / fprintf)
|
||||
|
||||
Changes
|
||||
* Deprecated the Memory layer
|
||||
|
||||
Bugfix
|
||||
* ecp_gen_keypair() does more tries to prevent failure because of
|
||||
|
@ -3,7 +3,7 @@
|
||||
*
|
||||
* \brief Configuration options (set of defines)
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -113,6 +113,42 @@
|
||||
* Comment if your system does not support the IPv6 socket interface
|
||||
*/
|
||||
#define POLARSSL_HAVE_IPV6
|
||||
|
||||
/**
|
||||
* \def POLARSSL_PLATFORM_MEMORY
|
||||
*
|
||||
* Enable the memory allocation layer.
|
||||
*
|
||||
* By default PolarSSL uses the system-provided malloc() and free().
|
||||
* This allows different allocators (self-implemented or provided) to be
|
||||
* provided to the platform abstraction layer.
|
||||
*
|
||||
* Enabling POLARSSL_PLATFORM_MEMORY will provide "platform_set_malloc_free()"
|
||||
* to allow you to set an alternative malloc() and free() function pointer.
|
||||
*
|
||||
* Requires: POLARSSL_PLATFORM_C
|
||||
*
|
||||
* Enable this layer to allow use of alternative memory allocators.
|
||||
*/
|
||||
//#define POLARSSL_PLATFORM_MEMORY
|
||||
|
||||
/**
|
||||
* \def POLARSSL_PLATFORM_XXX_ALT
|
||||
*
|
||||
* Uncomment a macro to let PolarSSL support the function in the platform
|
||||
* abstraction layer.
|
||||
*
|
||||
* Example: In case you uncomment POLARSSL_PLATFORM_PRINTF_ALT, PolarSSL will
|
||||
* provide a function "platform_set_printf()" that allows you to set an
|
||||
* alternative printf function pointer.
|
||||
*
|
||||
* All these define require POLARSSL_PLATFORM_C to be defined!
|
||||
*
|
||||
* Uncomment a macro to enable alternate implementation of specific base
|
||||
* platform function
|
||||
*/
|
||||
//#define POLARSSL_PLATFORM_PRINTF_ALT
|
||||
//#define POLARSSL_PLATFORM_FPRINTF_ALT
|
||||
/* \} name SECTION: System support */
|
||||
|
||||
/**
|
||||
@ -624,7 +660,6 @@
|
||||
* function for 'debug output' of allocated memory.
|
||||
*
|
||||
* Requires: POLARSSL_MEMORY_BUFFER_ALLOC_C
|
||||
* fprintf()
|
||||
*
|
||||
* Uncomment this macro to let the buffer allocator print out error messages.
|
||||
*/
|
||||
@ -1408,15 +1443,7 @@
|
||||
|
||||
/**
|
||||
* \def POLARSSL_MEMORY_C
|
||||
*
|
||||
* Enable the memory allocation layer.
|
||||
* By default PolarSSL uses the system-provided malloc() and free().
|
||||
* (As long as POLARSSL_MEMORY_STDMALLOC and POLARSSL_MEMORY_STDFREE
|
||||
* are defined and unmodified)
|
||||
*
|
||||
* This allows different allocators (self-implemented or provided)
|
||||
*
|
||||
* Enable this layer to allow use of alternative memory allocators.
|
||||
* Deprecated since 1.3.5. Please use POLARSSL_PLATFORM_MEMORY instead.
|
||||
*/
|
||||
//#define POLARSSL_MEMORY_C
|
||||
|
||||
@ -1429,7 +1456,8 @@
|
||||
*
|
||||
* Module: library/memory_buffer_alloc.c
|
||||
*
|
||||
* Requires: POLARSSL_MEMORY_C
|
||||
* Requires: POLARSSL_PLATFORM_C
|
||||
* POLARSSL_PLATFORM_MEMORY (to use it within PolarSSL)
|
||||
*
|
||||
* Enable this module to enable the buffer memory allocator.
|
||||
*/
|
||||
@ -1620,6 +1648,19 @@
|
||||
*/
|
||||
#define POLARSSL_PKCS12_C
|
||||
|
||||
/**
|
||||
* \def POLARSSL_PLATFORM_C
|
||||
*
|
||||
* Enable the platform abstraction layer that allows you to re-assign
|
||||
* functions like malloc(), free(), printf(), fprintf()
|
||||
*
|
||||
* Module: library/platform.c
|
||||
* Caller: Most other .c files
|
||||
*
|
||||
* This module enables abstraction of common (libc) functions.
|
||||
*/
|
||||
#define POLARSSL_PLATFORM_C
|
||||
|
||||
/**
|
||||
* \def POLARSSL_RIPEMD160_C
|
||||
*
|
||||
@ -1964,10 +2005,14 @@
|
||||
#define ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
|
||||
#define ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
|
||||
|
||||
// Memory options
|
||||
// Memory buffer allocator options
|
||||
#define MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
|
||||
#define POLARSSL_MEMORY_STDMALLOC malloc /**< Default allocator to use, can be undefined */
|
||||
#define POLARSSL_MEMORY_STDFREE free /**< Default free to use, can be undefined */
|
||||
|
||||
// Platform options
|
||||
#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use, can be undefined */
|
||||
#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
|
||||
#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
|
||||
#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
|
||||
|
||||
// SSL Cache options
|
||||
//
|
||||
@ -2108,7 +2153,8 @@
|
||||
#error "POLARSSL_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && !defined(POLARSSL_MEMORY_C)
|
||||
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && \
|
||||
( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
|
||||
#error "POLARSSL_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/**
|
||||
* \file memory.h
|
||||
*
|
||||
* \brief Memory allocation layer
|
||||
* \brief Memory allocation layer (Deprecated to platform layer)
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -31,101 +31,18 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_OPTIONS)
|
||||
#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
|
||||
|
||||
#define POLARSSL_MEMORY_STDMALLOC malloc /**< Default allocator to use, can be undefined */
|
||||
#define POLARSSL_MEMORY_STDFREE free /**< Default free to use, can be undefined */
|
||||
#endif /* POLARSSL_CONFIG_OPTIONS */
|
||||
|
||||
#define MEMORY_VERIFY_NONE 0
|
||||
#define MEMORY_VERIFY_ALLOC (1 << 0)
|
||||
#define MEMORY_VERIFY_FREE (1 << 1)
|
||||
#define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
|
||||
#define POLARSSL_PLATFORM_MEMORY
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The function pointers for malloc and free
|
||||
*/
|
||||
extern void * (*polarssl_malloc)( size_t len );
|
||||
extern void (*polarssl_free)( void *ptr );
|
||||
#include "platform.h"
|
||||
#include "memory_buffer_alloc.h"
|
||||
|
||||
/**
|
||||
* \brief Set your own memory implementation function pointers
|
||||
*
|
||||
* \param malloc_func the malloc function implementation
|
||||
* \param free_func the free function implementation
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int memory_set_own( void * (*malloc_func)( size_t ),
|
||||
void (*free_func)( void * ) );
|
||||
|
||||
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
|
||||
/**
|
||||
* \brief Initialize use of stack-based memory allocator.
|
||||
* The stack-based allocator does memory management inside the
|
||||
* presented buffer and does not call malloc() and free().
|
||||
* It sets the global polarssl_malloc() and polarssl_free() pointers
|
||||
* to its own functions.
|
||||
* (Provided polarssl_malloc() and polarssl_free() are thread-safe if
|
||||
* POLARSSL_THREADING_C is defined)
|
||||
*
|
||||
* \note This code is not optimized and provides a straight-forward
|
||||
* implementation of a stack-based memory allocator.
|
||||
*
|
||||
* \param buf buffer to use as heap
|
||||
* \param len size of the buffer
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int memory_buffer_alloc_init( unsigned char *buf, size_t len );
|
||||
|
||||
/**
|
||||
* \brief Free the mutex for thread-safety and clear remaining memory
|
||||
*/
|
||||
void memory_buffer_alloc_free();
|
||||
|
||||
/**
|
||||
* \brief Determine when the allocator should automatically verify the state
|
||||
* of the entire chain of headers / meta-data.
|
||||
* (Default: MEMORY_VERIFY_NONE)
|
||||
*
|
||||
* \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC,
|
||||
* MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS
|
||||
*/
|
||||
void memory_buffer_set_verify( int verify );
|
||||
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
/**
|
||||
* \brief Print out the status of the allocated memory (primarily for use
|
||||
* after a program should have de-allocated all memory)
|
||||
* Prints out a list of 'still allocated' blocks and their stack
|
||||
* trace if POLARSSL_MEMORY_BACKTRACE is defined.
|
||||
*/
|
||||
void memory_buffer_alloc_status();
|
||||
#endif /* POLARSSL_MEMORY_DEBUG */
|
||||
|
||||
/**
|
||||
* \brief Verifies that all headers in the memory buffer are correct
|
||||
* and contain sane values. Helps debug buffer-overflow errors.
|
||||
*
|
||||
* Prints out first failure if POLARSSL_MEMORY_DEBUG is defined.
|
||||
* Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS
|
||||
* is defined. (Includes stack trace information for each block if
|
||||
* POLARSSL_MEMORY_BACKTRACE is defined as well).
|
||||
*
|
||||
* \returns 0 if verified, 1 otherwise
|
||||
*/
|
||||
int memory_buffer_alloc_verify();
|
||||
|
||||
#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
return platform_set_malloc_free( malloc_func, free_func );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* memory.h */
|
||||
|
108
include/polarssl/memory_buffer_alloc.h
Normal file
108
include/polarssl/memory_buffer_alloc.h
Normal file
@ -0,0 +1,108 @@
|
||||
/**
|
||||
* \file memory_buffer_alloc.h
|
||||
*
|
||||
* \brief Buffer-based memory allocator
|
||||
*
|
||||
* Copyright (C) 2006-2014, 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_MEMORY_BUFFER_ALLOC_H
|
||||
#define POLARSSL_MEMORY_BUFFER_ALLOC_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_OPTIONS)
|
||||
#define POLARSSL_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
|
||||
#endif /* POLARSSL_CONFIG_OPTIONS */
|
||||
|
||||
#define MEMORY_VERIFY_NONE 0
|
||||
#define MEMORY_VERIFY_ALLOC (1 << 0)
|
||||
#define MEMORY_VERIFY_FREE (1 << 1)
|
||||
#define MEMORY_VERIFY_ALWAYS (MEMORY_VERIFY_ALLOC | MEMORY_VERIFY_FREE)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Initialize use of stack-based memory allocator.
|
||||
* The stack-based allocator does memory management inside the
|
||||
* presented buffer and does not call malloc() and free().
|
||||
* It sets the global polarssl_malloc() and polarssl_free() pointers
|
||||
* to its own functions.
|
||||
* (Provided polarssl_malloc() and polarssl_free() are thread-safe if
|
||||
* POLARSSL_THREADING_C is defined)
|
||||
*
|
||||
* \note This code is not optimized and provides a straight-forward
|
||||
* implementation of a stack-based memory allocator.
|
||||
*
|
||||
* \param buf buffer to use as heap
|
||||
* \param len size of the buffer
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int memory_buffer_alloc_init( unsigned char *buf, size_t len );
|
||||
|
||||
/**
|
||||
* \brief Free the mutex for thread-safety and clear remaining memory
|
||||
*/
|
||||
void memory_buffer_alloc_free( void );
|
||||
|
||||
/**
|
||||
* \brief Determine when the allocator should automatically verify the state
|
||||
* of the entire chain of headers / meta-data.
|
||||
* (Default: MEMORY_VERIFY_NONE)
|
||||
*
|
||||
* \param verify One of MEMORY_VERIFY_NONE, MEMORY_VERIFY_ALLOC,
|
||||
* MEMORY_VERIFY_FREE or MEMORY_VERIFY_ALWAYS
|
||||
*/
|
||||
void memory_buffer_set_verify( int verify );
|
||||
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
/**
|
||||
* \brief Print out the status of the allocated memory (primarily for use
|
||||
* after a program should have de-allocated all memory)
|
||||
* Prints out a list of 'still allocated' blocks and their stack
|
||||
* trace if POLARSSL_MEMORY_BACKTRACE is defined.
|
||||
*/
|
||||
void memory_buffer_alloc_status( void );
|
||||
#endif /* POLARSSL_MEMORY_DEBUG */
|
||||
|
||||
/**
|
||||
* \brief Verifies that all headers in the memory buffer are correct
|
||||
* and contain sane values. Helps debug buffer-overflow errors.
|
||||
*
|
||||
* Prints out first failure if POLARSSL_MEMORY_DEBUG is defined.
|
||||
* Prints out full header information if POLARSSL_MEMORY_DEBUG_HEADERS
|
||||
* is defined. (Includes stack trace information for each block if
|
||||
* POLARSSL_MEMORY_BACKTRACE is defined as well).
|
||||
*
|
||||
* \returns 0 if verified, 1 otherwise
|
||||
*/
|
||||
int memory_buffer_alloc_verify( void );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* memory_buffer_alloc.h */
|
102
include/polarssl/platform.h
Normal file
102
include/polarssl/platform.h
Normal file
@ -0,0 +1,102 @@
|
||||
/**
|
||||
* \file platform.h
|
||||
*
|
||||
* \brief PolarSSL Platform abstraction layer
|
||||
*
|
||||
* Copyright (C) 2006-2014, 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_PLATFORM_H
|
||||
#define POLARSSL_PLATFORM_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_OPTIONS)
|
||||
#include <stdlib.h>
|
||||
#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
|
||||
#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
|
||||
#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
|
||||
#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
|
||||
#endif /* POLARSSL_CONFIG_OPTIONS */
|
||||
|
||||
/*
|
||||
* The function pointers for malloc and free
|
||||
*/
|
||||
#if defined(POLARSSL_PLATFORM_MEMORY)
|
||||
extern void * (*polarssl_malloc)( size_t len );
|
||||
extern void (*polarssl_free)( void *ptr );
|
||||
|
||||
/**
|
||||
* \brief Set your own memory implementation function pointers
|
||||
*
|
||||
* \param malloc_func the malloc function implementation
|
||||
* \param free_func the free function implementation
|
||||
*
|
||||
* \return 0 if successful
|
||||
*/
|
||||
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
|
||||
void (*free_func)( void * ) );
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The function pointers for printf
|
||||
*/
|
||||
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
|
||||
extern int (*polarssl_printf)( const char *format, ... );
|
||||
|
||||
/**
|
||||
* \brief Set your own printf function pointer
|
||||
*
|
||||
* \param printf_func the printf function implementation
|
||||
*
|
||||
* \return 0
|
||||
*/
|
||||
int platform_set_printf( int (*printf_func)( const char *, ... ) );
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The function pointers for fprintf
|
||||
*/
|
||||
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
|
||||
extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
|
||||
|
||||
int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
|
||||
... ) );
|
||||
#else
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* platform.h */
|
@ -32,7 +32,6 @@ set(src
|
||||
md2.c
|
||||
md4.c
|
||||
md5.c
|
||||
memory.c
|
||||
memory_buffer_alloc.c
|
||||
net.c
|
||||
oid.c
|
||||
@ -46,6 +45,7 @@ set(src
|
||||
pk_wrap.c
|
||||
pkparse.c
|
||||
pkwrite.c
|
||||
platform.c
|
||||
ripemd160.c
|
||||
rsa.c
|
||||
sha1.c
|
||||
|
@ -46,13 +46,13 @@ OBJS= aes.o aesni.o arc4.o \
|
||||
error.o gcm.o havege.o \
|
||||
hmac_drbg.o \
|
||||
md.o md_wrap.o md2.o \
|
||||
md4.o md5.o memory.o \
|
||||
md4.o md5.o \
|
||||
memory_buffer_alloc.o net.o \
|
||||
oid.o \
|
||||
padlock.o pbkdf2.o pem.o \
|
||||
pkcs5.o pkcs11.o pkcs12.o \
|
||||
pk.o pk_wrap.o pkparse.o \
|
||||
pkwrite.o ripemd160.o \
|
||||
pkwrite.o platform.o ripemd160.o \
|
||||
rsa.o sha1.o sha256.o \
|
||||
sha512.o ssl_cache.o ssl_cli.o \
|
||||
ssl_srv.o ssl_ciphersuites.o \
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS-197 compliant AES implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -41,6 +41,12 @@
|
||||
#include "polarssl/aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_AES_ALT)
|
||||
|
||||
/*
|
||||
@ -1191,8 +1197,8 @@ int aes_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-ECB-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " AES-ECB-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memset( buf, 0, 16 );
|
||||
|
||||
@ -1206,7 +1212,7 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_ecb_dec[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1221,18 +1227,18 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_ecb_enc[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
/*
|
||||
@ -1244,8 +1250,8 @@ int aes_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " AES-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memset( iv , 0, 16 );
|
||||
memset( prv, 0, 16 );
|
||||
@ -1261,7 +1267,7 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_cbc_dec[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1284,18 +1290,18 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( prv, aes_test_cbc_enc[u], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CFB)
|
||||
@ -1308,8 +1314,8 @@ int aes_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-CFB128-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " AES-CFB128-%3d (%s): ", 128 + u * 64,
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( iv, aes_test_cfb128_iv, 16 );
|
||||
memcpy( key, aes_test_cfb128_key[u], 16 + u * 8 );
|
||||
@ -1325,7 +1331,7 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_cfb128_pt, 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1338,18 +1344,18 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_cfb128_ct[u], 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CFB */
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CTR)
|
||||
@ -1362,8 +1368,8 @@ int aes_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-CTR-128 (%s): ",
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " AES-CTR-128 (%s): ",
|
||||
( v == AES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 );
|
||||
memcpy( key, aes_test_ctr_key[u], 16 );
|
||||
@ -1381,7 +1387,7 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_ctr_pt[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1396,18 +1402,18 @@ int aes_self_test( int verbose )
|
||||
if( memcmp( buf, aes_test_ctr_ct[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
|
||||
return( 0 );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* An implementation of the ARCFOUR algorithm
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -34,6 +34,12 @@
|
||||
|
||||
#include "polarssl/arc4.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_ARC4_ALT)
|
||||
|
||||
/*
|
||||
@ -143,7 +149,7 @@ int arc4_self_test( int verbose )
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " ARC4 test #%d: ", i + 1 );
|
||||
polarssl_printf( " ARC4 test #%d: ", i + 1 );
|
||||
|
||||
memcpy( ibuf, arc4_test_pt[i], 8 );
|
||||
|
||||
@ -153,17 +159,17 @@ int arc4_self_test( int verbose )
|
||||
if( memcmp( obuf, arc4_test_ct[i], 8 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Generic ASN.1 parsing
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -33,8 +33,8 @@
|
||||
#include "polarssl/bignum.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* ASN.1 buffer writing functionality
|
||||
*
|
||||
* Copyright (C) 2006-2012, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -29,8 +29,8 @@
|
||||
|
||||
#include "polarssl/asn1write.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_malloc malloc
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* RFC 1521 base64 encoding/decoding
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -36,6 +36,12 @@ typedef UINT32 uint32_t;
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
static const unsigned char base64_enc_map[64] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
@ -222,7 +228,7 @@ int base64_self_test( int verbose )
|
||||
unsigned char buffer[128];
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " Base64 encoding test: " );
|
||||
polarssl_printf( " Base64 encoding test: " );
|
||||
|
||||
len = sizeof( buffer );
|
||||
src = base64_test_dec;
|
||||
@ -231,13 +237,13 @@ int base64_self_test( int verbose )
|
||||
memcmp( base64_test_enc, buffer, 88 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n Base64 decoding test: " );
|
||||
polarssl_printf( "passed\n Base64 decoding test: " );
|
||||
|
||||
len = sizeof( buffer );
|
||||
src = base64_test_enc;
|
||||
@ -246,13 +252,13 @@ int base64_self_test( int verbose )
|
||||
memcmp( base64_test_dec, buffer, 64 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n\n" );
|
||||
polarssl_printf( "passed\n\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Multi-precision integer library
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -37,9 +37,10 @@
|
||||
#include "polarssl/bignum.h"
|
||||
#include "polarssl/bn_mul.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
@ -616,7 +617,7 @@ int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout )
|
||||
return( POLARSSL_ERR_MPI_FILE_IO_ERROR );
|
||||
}
|
||||
else
|
||||
printf( "%s%s", p, s );
|
||||
polarssl_printf( "%s%s", p, s );
|
||||
|
||||
cleanup:
|
||||
|
||||
@ -2189,19 +2190,19 @@ int mpi_self_test( int verbose )
|
||||
"30879B56C61DE584A0F53A2447A51E" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " MPI test #1 (mul_mpi): " );
|
||||
polarssl_printf( " MPI test #1 (mul_mpi): " );
|
||||
|
||||
if( mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
MPI_CHK( mpi_div_mpi( &X, &Y, &A, &N ) );
|
||||
|
||||
@ -2214,20 +2215,20 @@ int mpi_self_test( int verbose )
|
||||
"9EE50D0657C77F374E903CDFA4C642" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " MPI test #2 (div_mpi): " );
|
||||
polarssl_printf( " MPI test #2 (div_mpi): " );
|
||||
|
||||
if( mpi_cmp_mpi( &X, &U ) != 0 ||
|
||||
mpi_cmp_mpi( &Y, &V ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
MPI_CHK( mpi_exp_mod( &X, &A, &E, &N, NULL ) );
|
||||
|
||||
@ -2237,19 +2238,19 @@ int mpi_self_test( int verbose )
|
||||
"325D24D6A3C12710F10A09FA08AB87" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " MPI test #3 (exp_mod): " );
|
||||
polarssl_printf( " MPI test #3 (exp_mod): " );
|
||||
|
||||
if( mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
MPI_CHK( mpi_inv_mod( &X, &A, &N ) );
|
||||
|
||||
@ -2259,22 +2260,22 @@ int mpi_self_test( int verbose )
|
||||
"C5B8A74DAC4D09E03B5E0BE779F2DF61" ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " MPI test #4 (inv_mod): " );
|
||||
polarssl_printf( " MPI test #4 (inv_mod): " );
|
||||
|
||||
if( mpi_cmp_mpi( &X, &U ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " MPI test #5 (simple gcd): " );
|
||||
polarssl_printf( " MPI test #5 (simple gcd): " );
|
||||
|
||||
for ( i = 0; i < GCD_PAIR_COUNT; i++)
|
||||
{
|
||||
@ -2286,7 +2287,7 @@ int mpi_self_test( int verbose )
|
||||
if( mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed at %d\n", i );
|
||||
polarssl_printf( "failed at %d\n", i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
@ -2294,18 +2295,18 @@ int mpi_self_test( int verbose )
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
|
||||
if( ret != 0 && verbose != 0 )
|
||||
printf( "Unexpected error, return code = %08X\n", ret );
|
||||
polarssl_printf( "Unexpected error, return code = %08X\n", ret );
|
||||
|
||||
mpi_free( &A ); mpi_free( &E ); mpi_free( &N ); mpi_free( &X );
|
||||
mpi_free( &Y ); mpi_free( &U ); mpi_free( &V );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Camellia implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -35,6 +35,12 @@
|
||||
|
||||
#include "polarssl/camellia.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_CAMELLIA_ALT)
|
||||
|
||||
/*
|
||||
@ -889,8 +895,8 @@ int camellia_self_test( int verbose )
|
||||
v = j & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
|
||||
(v == CAMELLIA_DECRYPT) ? "dec" : "enc");
|
||||
polarssl_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64,
|
||||
(v == CAMELLIA_DECRYPT) ? "dec" : "enc");
|
||||
|
||||
for (i = 0; i < CAMELLIA_TESTS_ECB; i++ ) {
|
||||
memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u);
|
||||
@ -910,18 +916,18 @@ int camellia_self_test( int verbose )
|
||||
if( memcmp( buf, dst, 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
/*
|
||||
@ -933,8 +939,8 @@ int camellia_self_test( int verbose )
|
||||
v = j & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64,
|
||||
( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( src, camellia_test_cbc_iv, 16);
|
||||
memcpy( dst, camellia_test_cbc_iv, 16);
|
||||
@ -963,19 +969,19 @@ int camellia_self_test( int verbose )
|
||||
if( memcmp( buf, dst, 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CTR)
|
||||
/*
|
||||
@ -987,8 +993,8 @@ int camellia_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " CAMELLIA-CTR-128 (%s): ",
|
||||
( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " CAMELLIA-CTR-128 (%s): ",
|
||||
( v == CAMELLIA_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 );
|
||||
memcpy( key, camellia_test_ctr_key[u], 16 );
|
||||
@ -1006,7 +1012,7 @@ int camellia_self_test( int verbose )
|
||||
if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1021,18 +1027,18 @@ int camellia_self_test( int verbose )
|
||||
if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
|
||||
return ( 0 );
|
||||
|
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* \file cipher.c
|
||||
*
|
||||
*
|
||||
* \brief Generic cipher wrapper for PolarSSL
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -769,16 +769,9 @@ int cipher_check_tag( cipher_context_t *ctx,
|
||||
|
||||
#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 )
|
||||
{
|
||||
((void) verbose);
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -57,8 +57,8 @@
|
||||
#include "polarssl/gcm.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* CTR_DRBG implementation based on AES-256 (NIST SP 800-90)
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,6 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Non-public function wrapped by ctr_crbg_init(). Necessary to allow NIST
|
||||
* tests to succeed (which require known length fixed entropy)
|
||||
@ -460,11 +466,11 @@ static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
polarssl_printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
@ -479,7 +485,7 @@ int ctr_drbg_self_test( int verbose )
|
||||
* Based on a NIST CTR_DRBG test vector (PR = True)
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
printf( " CTR_DRBG (PR = TRUE) : " );
|
||||
polarssl_printf( " CTR_DRBG (PR = TRUE) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
@ -490,13 +496,13 @@ int ctr_drbg_self_test( int verbose )
|
||||
CHK( memcmp( buf, result_pr, CTR_DRBG_BLOCKSIZE ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
/*
|
||||
* Based on a NIST CTR_DRBG test vector (PR = FALSE)
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
printf( " CTR_DRBG (PR = FALSE): " );
|
||||
polarssl_printf( " CTR_DRBG (PR = FALSE): " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( ctr_drbg_init_entropy_len( &ctx, ctr_drbg_self_test_entropy,
|
||||
@ -507,10 +513,10 @@ int ctr_drbg_self_test( int verbose )
|
||||
CHK( memcmp( buf, result_nopr, 16 ) );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS-46-3 compliant Triple-DES implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -35,6 +35,12 @@
|
||||
|
||||
#include "polarssl/des.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_DES_ALT)
|
||||
|
||||
/*
|
||||
@ -839,9 +845,9 @@ int des_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " DES%c-ECB-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == DES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " DES%c-ECB-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == DES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( buf, des3_test_buf, 8 );
|
||||
|
||||
@ -889,17 +895,17 @@ int des_self_test( int verbose )
|
||||
memcmp( buf, des3_test_ecb_enc[u], 8 ) != 0 ) )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
/*
|
||||
@ -911,9 +917,9 @@ int des_self_test( int verbose )
|
||||
v = i & 1;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " DES%c-CBC-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == DES_DECRYPT ) ? "dec" : "enc" );
|
||||
polarssl_printf( " DES%c-CBC-%3d (%s): ",
|
||||
( u == 0 ) ? ' ' : '3', 56 + u * 56,
|
||||
( v == DES_DECRYPT ) ? "dec" : "enc" );
|
||||
|
||||
memcpy( iv, des3_test_iv, 8 );
|
||||
memcpy( prv, des3_test_iv, 8 );
|
||||
@ -984,18 +990,18 @@ int des_self_test( int verbose )
|
||||
memcmp( buf, des3_test_cbc_enc[u], 8 ) != 0 ) )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Diffie-Hellman-Merkle key exchange
|
||||
*
|
||||
* Copyright (C) 2006-2010, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -42,10 +42,11 @@
|
||||
#include "polarssl/asn1.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
@ -548,19 +549,19 @@ int dhm_self_test( int verbose )
|
||||
dhm_context dhm;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " DHM parameter load: " );
|
||||
polarssl_printf( " DHM parameter load: " );
|
||||
|
||||
if( ( ret = dhm_parse_dhm( &dhm, (const unsigned char *) test_dhm_params,
|
||||
strlen( test_dhm_params ) ) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n\n" );
|
||||
polarssl_printf( "passed\n\n" );
|
||||
|
||||
dhm_free( &dhm );
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Elliptic curves over GF(p): generic functions
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -50,9 +50,10 @@
|
||||
|
||||
#include "polarssl/ecp.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
@ -1904,7 +1905,7 @@ int ecp_self_test( int verbose )
|
||||
#endif
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " ECP test #1 (constant op_count, base point G): " );
|
||||
polarssl_printf( " ECP test #1 (constant op_count, base point G): " );
|
||||
|
||||
/* Do a dummy multiplication first to trigger precomputation */
|
||||
MPI_CHK( mpi_lset( &m, 2 ) );
|
||||
@ -1933,7 +1934,7 @@ int ecp_self_test( int verbose )
|
||||
mul_count != mul_c_prev )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed (%u)\n", (unsigned int) i );
|
||||
polarssl_printf( "failed (%u)\n", (unsigned int) i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
@ -1941,10 +1942,10 @@ int ecp_self_test( int verbose )
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " ECP test #2 (constant op_count, other point): " );
|
||||
polarssl_printf( " ECP test #2 (constant op_count, other point): " );
|
||||
/* We computed P = 2G last time, use it */
|
||||
|
||||
add_count = 0;
|
||||
@ -1970,7 +1971,7 @@ int ecp_self_test( int verbose )
|
||||
mul_count != mul_c_prev )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed (%u)\n", (unsigned int) i );
|
||||
polarssl_printf( "failed (%u)\n", (unsigned int) i );
|
||||
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
@ -1978,12 +1979,12 @@ int ecp_self_test( int verbose )
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
cleanup:
|
||||
|
||||
if( ret < 0 && verbose != 0 )
|
||||
printf( "Unexpected error, return code = %08X\n", ret );
|
||||
polarssl_printf( "Unexpected error, return code = %08X\n", ret );
|
||||
|
||||
ecp_group_free( &grp );
|
||||
ecp_point_free( &R );
|
||||
@ -1991,7 +1992,7 @@ cleanup:
|
||||
mpi_free( &m );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* NIST SP800-38D compliant GCM implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -43,6 +43,12 @@
|
||||
#include "polarssl/aesni.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (big endian)
|
||||
*/
|
||||
@ -716,7 +722,8 @@ int gcm_self_test( int verbose )
|
||||
for( i = 0; i < MAX_TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " AES-GCM-%3d #%d (%s): ", key_len, i, "enc" );
|
||||
polarssl_printf( " AES-GCM-%3d #%d (%s): ",
|
||||
key_len, i, "enc" );
|
||||
|
||||
gcm_init( &ctx, cipher, key[key_index[i]], key_len );
|
||||
|
||||
@ -731,7 +738,7 @@ int gcm_self_test( int verbose )
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -739,10 +746,11 @@ int gcm_self_test( int verbose )
|
||||
gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-GCM-%3d #%d (%s): ", key_len, i, "dec" );
|
||||
polarssl_printf( " AES-GCM-%3d #%d (%s): ",
|
||||
key_len, i, "dec" );
|
||||
|
||||
gcm_init( &ctx, cipher, key[key_index[i]], key_len );
|
||||
|
||||
@ -757,7 +765,7 @@ int gcm_self_test( int verbose )
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -765,10 +773,11 @@ int gcm_self_test( int verbose )
|
||||
gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-GCM-%3d #%d split (%s): ", key_len, i, "enc" );
|
||||
polarssl_printf( " AES-GCM-%3d #%d split (%s): ",
|
||||
key_len, i, "enc" );
|
||||
|
||||
gcm_init( &ctx, cipher, key[key_index[i]], key_len );
|
||||
|
||||
@ -778,7 +787,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -790,7 +799,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -799,7 +808,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -810,7 +819,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -822,7 +831,7 @@ int gcm_self_test( int verbose )
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -830,10 +839,11 @@ int gcm_self_test( int verbose )
|
||||
gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " AES-GCM-%3d #%d split (%s): ", key_len, i, "dec" );
|
||||
polarssl_printf( " AES-GCM-%3d #%d split (%s): ",
|
||||
key_len, i, "dec" );
|
||||
|
||||
gcm_init( &ctx, cipher, key[key_index[i]], key_len );
|
||||
|
||||
@ -843,7 +853,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -855,7 +865,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -864,7 +874,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -875,7 +885,7 @@ int gcm_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -887,7 +897,7 @@ int gcm_self_test( int verbose )
|
||||
memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -895,13 +905,13 @@ int gcm_self_test( int verbose )
|
||||
gcm_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -39,6 +39,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* HMAC_DRBG update, using optional additional data (10.1.2.2)
|
||||
*/
|
||||
@ -368,7 +374,7 @@ int hmac_drbg_self_test( int verbose )
|
||||
{
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -418,11 +424,11 @@ static int hmac_drbg_self_test_entropy( void *data,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
#define CHK( c ) if( (c) != 0 ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
polarssl_printf( "failed\n" ); \
|
||||
return( 1 ); \
|
||||
}
|
||||
|
||||
/*
|
||||
@ -438,7 +444,7 @@ int hmac_drbg_self_test( int verbose )
|
||||
* PR = True
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC_DRBG (PR = True) : " );
|
||||
polarssl_printf( " HMAC_DRBG (PR = True) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( hmac_drbg_init( &ctx, md_info,
|
||||
@ -451,13 +457,13 @@ int hmac_drbg_self_test( int verbose )
|
||||
hmac_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
/*
|
||||
* PR = False
|
||||
*/
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC_DRBG (PR = False) : " );
|
||||
polarssl_printf( " HMAC_DRBG (PR = False) : " );
|
||||
|
||||
test_offset = 0;
|
||||
CHK( hmac_drbg_init( &ctx, md_info,
|
||||
@ -470,10 +476,10 @@ int hmac_drbg_self_test( int verbose )
|
||||
hmac_drbg_free( &ctx );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* RFC 1115/1319 compliant MD2 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -39,6 +39,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_MD2_ALT)
|
||||
|
||||
static const unsigned char PI_SUBST[256] =
|
||||
@ -340,7 +346,7 @@ int md2_self_test( int verbose )
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " MD2 test #%d: ", i + 1 );
|
||||
polarssl_printf( " MD2 test #%d: ", i + 1 );
|
||||
|
||||
md2( (unsigned char *) md2_test_str[i],
|
||||
strlen( md2_test_str[i] ), md2sum );
|
||||
@ -348,17 +354,17 @@ int md2_self_test( int verbose )
|
||||
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* RFC 1186/1320 compliant MD4 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -39,6 +39,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_MD4_ALT)
|
||||
|
||||
/*
|
||||
@ -436,7 +442,7 @@ int md4_self_test( int verbose )
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " MD4 test #%d: ", i + 1 );
|
||||
polarssl_printf( " MD4 test #%d: ", i + 1 );
|
||||
|
||||
md4( (unsigned char *) md4_test_str[i],
|
||||
strlen( md4_test_str[i] ), md4sum );
|
||||
@ -444,17 +450,17 @@ int md4_self_test( int verbose )
|
||||
if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* RFC 1321 compliant MD5 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,6 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_MD5_ALT)
|
||||
|
||||
/*
|
||||
@ -522,29 +528,29 @@ int md5_self_test( int verbose )
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " MD5 test #%d: ", i + 1 );
|
||||
polarssl_printf( " MD5 test #%d: ", i + 1 );
|
||||
|
||||
md5( md5_test_buf[i], md5_test_buflen[i], md5sum );
|
||||
|
||||
if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC-MD5 test #%d: ", i + 1 );
|
||||
polarssl_printf( " HMAC-MD5 test #%d: ", i + 1 );
|
||||
|
||||
if( i == 5 || i == 6 )
|
||||
{
|
||||
@ -565,17 +571,17 @@ int md5_self_test( int verbose )
|
||||
if( memcmp( md5sum, md5_hmac_test_sum[i], buflen ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -61,8 +61,8 @@
|
||||
#include "polarssl/sha512.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Memory allocation layer
|
||||
*
|
||||
* Copyright (C) 2006-2013, 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_MEMORY_C)
|
||||
|
||||
#include "polarssl/memory.h"
|
||||
|
||||
#if !defined(POLARSSL_MEMORY_STDMALLOC)
|
||||
static void *memory_malloc_uninit( size_t len )
|
||||
{
|
||||
((void) len);
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#define POLARSSL_MEMORY_STDMALLOC memory_malloc_uninit
|
||||
#endif /* !POLARSSL_MEMORY_STDMALLOC */
|
||||
|
||||
#if !defined(POLARSSL_MEMORY_STDFREE)
|
||||
static void memory_free_uninit( void *ptr )
|
||||
{
|
||||
((void) ptr);
|
||||
}
|
||||
|
||||
#define POLARSSL_MEMORY_STDFREE memory_free_uninit
|
||||
#endif /* !POLARSSL_MEMORY_STDFREE */
|
||||
|
||||
void * (*polarssl_malloc)( size_t ) = POLARSSL_MEMORY_STDMALLOC;
|
||||
void (*polarssl_free)( void * ) = POLARSSL_MEMORY_STDFREE;
|
||||
|
||||
int memory_set_own( void * (*malloc_func)( size_t ),
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
polarssl_malloc = malloc_func;
|
||||
polarssl_free = free_func;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* POLARSSL_MEMORY_C */
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Buffer-based memory allocator
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -25,9 +25,9 @@
|
||||
|
||||
#include "polarssl/config.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C) && defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
|
||||
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
|
||||
|
||||
#include "polarssl/memory.h"
|
||||
#include "polarssl/memory_buffer_alloc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -42,6 +42,12 @@
|
||||
#include "polarssl/threading.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif
|
||||
|
||||
#define MAGIC1 0xFF00AA55
|
||||
#define MAGIC2 0xEE119966
|
||||
#define MAX_BT 20
|
||||
@ -94,17 +100,18 @@ static void debug_header( memory_header *hdr )
|
||||
size_t i;
|
||||
#endif
|
||||
|
||||
fprintf( stderr, "HDR: PTR(%10u), PREV(%10u), NEXT(%10u), ALLOC(%u), SIZE(%10u)\n",
|
||||
(size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next,
|
||||
hdr->alloc, hdr->size );
|
||||
fprintf( stderr, " FPREV(%10u), FNEXT(%10u)\n",
|
||||
(size_t) hdr->prev_free, (size_t) hdr->next_free );
|
||||
polarssl_fprintf( stderr, "HDR: PTR(%10u), PREV(%10u), NEXT(%10u), "
|
||||
"ALLOC(%u), SIZE(%10u)\n",
|
||||
(size_t) hdr, (size_t) hdr->prev, (size_t) hdr->next,
|
||||
hdr->alloc, hdr->size );
|
||||
polarssl_fprintf( stderr, " FPREV(%10u), FNEXT(%10u)\n",
|
||||
(size_t) hdr->prev_free, (size_t) hdr->next_free );
|
||||
|
||||
#if defined(POLARSSL_MEMORY_BACKTRACE)
|
||||
fprintf( stderr, "TRACE: \n" );
|
||||
polarssl_fprintf( stderr, "TRACE: \n" );
|
||||
for( i = 0; i < hdr->trace_count; i++ )
|
||||
fprintf( stderr, "%s\n", hdr->trace[i] );
|
||||
fprintf( stderr, "\n" );
|
||||
polarssl_fprintf( stderr, "%s\n", hdr->trace[i] );
|
||||
polarssl_fprintf( stderr, "\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -112,14 +119,14 @@ static void debug_chain()
|
||||
{
|
||||
memory_header *cur = heap.first;
|
||||
|
||||
fprintf( stderr, "\nBlock list\n" );
|
||||
polarssl_fprintf( stderr, "\nBlock list\n" );
|
||||
while( cur != NULL )
|
||||
{
|
||||
debug_header( cur );
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
fprintf( stderr, "Free list\n" );
|
||||
polarssl_fprintf( stderr, "Free list\n" );
|
||||
cur = heap.first_free;
|
||||
|
||||
while( cur != NULL )
|
||||
@ -135,7 +142,7 @@ static int verify_header( memory_header *hdr )
|
||||
if( hdr->magic1 != MAGIC1 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: MAGIC1 mismatch\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: MAGIC1 mismatch\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -143,7 +150,7 @@ static int verify_header( memory_header *hdr )
|
||||
if( hdr->magic2 != MAGIC2 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: MAGIC2 mismatch\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: MAGIC2 mismatch\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -151,7 +158,7 @@ static int verify_header( memory_header *hdr )
|
||||
if( hdr->alloc > 1 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: alloc has illegal value\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: alloc has illegal value\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -159,7 +166,7 @@ static int verify_header( memory_header *hdr )
|
||||
if( hdr->prev != NULL && hdr->prev == hdr->next )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: prev == next\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: prev == next\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -167,7 +174,7 @@ static int verify_header( memory_header *hdr )
|
||||
if( hdr->prev_free != NULL && hdr->prev_free == hdr->next_free )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: prev_free == next_free\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: prev_free == next_free\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -182,7 +189,8 @@ static int verify_chain()
|
||||
if( verify_header( heap.first ) != 0 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: verification of first header failed\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: verification of first header "
|
||||
"failed\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -190,7 +198,8 @@ static int verify_chain()
|
||||
if( heap.first->prev != NULL )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: verification failed: first->prev != NULL\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: verification failed: "
|
||||
"first->prev != NULL\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -200,7 +209,8 @@ static int verify_chain()
|
||||
if( verify_header( cur ) != 0 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: verification of header failed\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: verification of header "
|
||||
"failed\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -208,7 +218,8 @@ static int verify_chain()
|
||||
if( cur->prev != prv )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: verification failed: cur->prev != prv\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: verification failed: "
|
||||
"cur->prev != prv\n" );
|
||||
#endif
|
||||
return( 1 );
|
||||
}
|
||||
@ -254,7 +265,8 @@ static void *buffer_alloc_malloc( size_t len )
|
||||
if( cur->alloc != 0 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: block in free_list but allocated data\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: block in free_list but allocated "
|
||||
"data\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
}
|
||||
@ -365,7 +377,8 @@ static void buffer_alloc_free( void *ptr )
|
||||
if( p < heap.buf || p > heap.buf + heap.len )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: polarssl_free() outside of managed space\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: polarssl_free() outside of managed "
|
||||
"space\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
}
|
||||
@ -379,7 +392,8 @@ static void buffer_alloc_free( void *ptr )
|
||||
if( hdr->alloc != 1 )
|
||||
{
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
fprintf( stderr, "FATAL: polarssl_free() on unallocated data\n" );
|
||||
polarssl_fprintf( stderr, "FATAL: polarssl_free() on unallocated "
|
||||
"data\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
}
|
||||
@ -486,23 +500,24 @@ int memory_buffer_alloc_verify()
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
void memory_buffer_alloc_status()
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Current use: %u blocks / %u bytes, max: %u blocks / %u bytes (total %u bytes), malloc / free: %u / %u\n",
|
||||
heap.header_count, heap.total_used,
|
||||
heap.maximum_header_count, heap.maximum_used,
|
||||
heap.maximum_header_count * sizeof( memory_header )
|
||||
+ heap.maximum_used,
|
||||
heap.malloc_count, heap.free_count );
|
||||
polarssl_fprintf( stderr,
|
||||
"Current use: %u blocks / %u bytes, max: %u blocks / "
|
||||
"%u bytes (total %u bytes), malloc / free: %u / %u\n",
|
||||
heap.header_count, heap.total_used,
|
||||
heap.maximum_header_count, heap.maximum_used,
|
||||
heap.maximum_header_count * sizeof( memory_header )
|
||||
+ heap.maximum_used,
|
||||
heap.malloc_count, heap.free_count );
|
||||
|
||||
if( heap.first->next == NULL )
|
||||
fprintf( stderr, "All memory de-allocated in stack buffer\n" );
|
||||
polarssl_fprintf( stderr, "All memory de-allocated in stack buffer\n" );
|
||||
else
|
||||
{
|
||||
fprintf( stderr, "Memory currently allocated:\n" );
|
||||
polarssl_fprintf( stderr, "Memory currently allocated:\n" );
|
||||
debug_chain();
|
||||
}
|
||||
}
|
||||
#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_DEBUG */
|
||||
#endif /* POLARSSL_MEMORY_DEBUG */
|
||||
|
||||
#if defined(POLARSSL_THREADING_C)
|
||||
static void *buffer_alloc_malloc_mutexed( size_t len )
|
||||
@ -529,11 +544,10 @@ int memory_buffer_alloc_init( unsigned char *buf, size_t len )
|
||||
|
||||
#if defined(POLARSSL_THREADING_C)
|
||||
polarssl_mutex_init( &heap.mutex );
|
||||
polarssl_malloc = buffer_alloc_malloc_mutexed;
|
||||
polarssl_free = buffer_alloc_free_mutexed;
|
||||
platform_set_malloc_free( buffer_alloc_malloc_mutexed,
|
||||
buffer_alloc_free_mutexed );
|
||||
#else
|
||||
polarssl_malloc = buffer_alloc_malloc;
|
||||
polarssl_free = buffer_alloc_free;
|
||||
platform_set_malloc_free( buffer_alloc_malloc, buffer_alloc_free );
|
||||
#endif
|
||||
|
||||
heap.buf = buf;
|
||||
@ -555,4 +569,4 @@ void memory_buffer_alloc_free()
|
||||
memset( &heap, 0, sizeof(buffer_alloc_ctx) );
|
||||
}
|
||||
|
||||
#endif /* POLARSSL_MEMORY_C && POLARSSL_MEMORY_BUFFER_ALLOC_C */
|
||||
#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Privacy Enhanced Mail (PEM) decoding
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -33,8 +33,8 @@
|
||||
#include "polarssl/md5.h"
|
||||
#include "polarssl/cipher.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Public Key abstraction layer: wrapper functions
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -40,8 +40,8 @@
|
||||
#include "polarssl/ecdsa.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_malloc malloc
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -34,15 +34,14 @@
|
||||
#include "polarssl/oid.h"
|
||||
#include "polarssl/x509_crt.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11_cert )
|
||||
{
|
||||
int ret = 1;
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
* \author Mathias Olsson <mathias@kompetensum.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -42,6 +42,12 @@
|
||||
#include "polarssl/cipher.h"
|
||||
#include "polarssl/oid.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
static int pkcs5_parse_pbkdf2_params( asn1_buf *params,
|
||||
asn1_buf *salt, int *iterations,
|
||||
int *keylen, md_type_t *md_type )
|
||||
@ -357,7 +363,7 @@ int pkcs5_self_test( int verbose )
|
||||
|
||||
for( i = 0; i < MAX_TESTS; i++ )
|
||||
{
|
||||
printf( " PBKDF2 (SHA1) #%d: ", i );
|
||||
polarssl_printf( " PBKDF2 (SHA1) #%d: ", i );
|
||||
|
||||
ret = pkcs5_pbkdf2_hmac( &sha1_ctx, password[i], plen[i], salt[i],
|
||||
slen[i], it_cnt[i], key_len[i], key );
|
||||
@ -365,16 +371,16 @@ int pkcs5_self_test( int verbose )
|
||||
memcmp( result_key[i], key, key_len[i] ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
if( ( ret = md_free_ctx( &sha1_ctx ) ) != 0 )
|
||||
return( 1 );
|
||||
|
@ -50,8 +50,8 @@
|
||||
#include "polarssl/pkcs12.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_malloc malloc
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Public Key layer for writing key files and structures
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -44,8 +44,8 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define polarssl_malloc malloc
|
||||
|
112
library/platform.c
Normal file
112
library/platform.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Platform abstraction layer
|
||||
*
|
||||
* Copyright (C) 2006-2014, 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_PLATFORM_C)
|
||||
|
||||
#include "polarssl/platform.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_MEMORY)
|
||||
#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
|
||||
static void *platform_malloc_uninit( size_t len )
|
||||
{
|
||||
((void) len);
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#define POLARSSL_PLATFORM_STD_MALLOC memory_malloc_uninit
|
||||
#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
|
||||
|
||||
#if !defined(POLARSSL_PLATFORM_STD_FREE)
|
||||
static void platform_free_uninit( void *ptr )
|
||||
{
|
||||
((void) ptr);
|
||||
}
|
||||
|
||||
#define POLARSSL_PLATFORM_STD_FREE memory_free_uninit
|
||||
#endif /* !POLARSSL_PLATFORM_STD_FREE */
|
||||
|
||||
void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
|
||||
void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
|
||||
|
||||
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
polarssl_malloc = malloc_func;
|
||||
polarssl_free = free_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_PLATFORM_MEMORY */
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
|
||||
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_printf_uninit( const char *format, ... )
|
||||
{
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
|
||||
#endif /* !POLARSSL_PLATFORM_STD_PRINTF */
|
||||
|
||||
int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
|
||||
|
||||
int platform_set_printf( int (*printf_func)( const char *, ... ) )
|
||||
{
|
||||
polarssl_printf = printf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
|
||||
#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
|
||||
{
|
||||
((void) stream);
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define POLARSSL_PLATFORM_STD_fPRINTF platform_fprintf_uninit
|
||||
#endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
|
||||
|
||||
int (*polarssl_fprintf)( FILE *, const char *, ... ) =
|
||||
POLARSSL_PLATFORM_STD_FPRINTF;
|
||||
|
||||
int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
|
||||
{
|
||||
polarssl_fprintf = fprintf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
|
||||
|
||||
#endif /* POLARSSL_PLATFORM_C */
|
@ -43,6 +43,12 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 32-bit integer manipulation macros (little endian)
|
||||
*/
|
||||
@ -573,7 +579,7 @@ int ripemd160_self_test( int verbose )
|
||||
for( i = 0; i < TESTS; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " RIPEMD-160 test #%d: ", i + 1 );
|
||||
polarssl_printf( " RIPEMD-160 test #%d: ", i + 1 );
|
||||
|
||||
ripemd160( (const unsigned char *) ripemd160_test_input[i],
|
||||
strlen( ripemd160_test_input[i] ),
|
||||
@ -582,18 +588,19 @@ int ripemd160_self_test( int verbose )
|
||||
if( memcmp( output, ripemd160_test_md[i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
for( j = 0; j < KEYS; j++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC-RIPEMD-160 test #%d, key #%d: ", i + 1, j + 1 );
|
||||
polarssl_printf( " HMAC-RIPEMD-160 test #%d, key #%d: ",
|
||||
i + 1, j + 1 );
|
||||
|
||||
ripemd160_hmac( ripemd160_test_key[j], 20,
|
||||
(const unsigned char *) ripemd160_test_input[i],
|
||||
@ -603,17 +610,17 @@ int ripemd160_self_test( int verbose )
|
||||
if( memcmp( output, ripemd160_test_hmac[j][i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* The RSA public-key cryptosystem
|
||||
*
|
||||
* Copyright (C) 2006-2011, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -43,6 +43,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize an RSA context
|
||||
*/
|
||||
@ -1495,19 +1501,19 @@ int rsa_self_test( int verbose )
|
||||
mpi_read_string( &rsa.QP, 16, RSA_QP );
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " RSA key validation: " );
|
||||
polarssl_printf( " RSA key validation: " );
|
||||
|
||||
if( rsa_check_pubkey( &rsa ) != 0 ||
|
||||
rsa_check_privkey( &rsa ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n PKCS#1 encryption : " );
|
||||
polarssl_printf( "passed\n PKCS#1 encryption : " );
|
||||
|
||||
memcpy( rsa_plaintext, RSA_PT, PT_LEN );
|
||||
|
||||
@ -1515,20 +1521,20 @@ int rsa_self_test( int verbose )
|
||||
rsa_plaintext, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n PKCS#1 decryption : " );
|
||||
polarssl_printf( "passed\n PKCS#1 decryption : " );
|
||||
|
||||
if( rsa_pkcs1_decrypt( &rsa, myrand, NULL, RSA_PRIVATE, &len,
|
||||
rsa_ciphertext, rsa_decrypted,
|
||||
sizeof(rsa_decrypted) ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
@ -1536,14 +1542,14 @@ int rsa_self_test( int verbose )
|
||||
if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n PKCS#1 data sign : " );
|
||||
polarssl_printf( "passed\n PKCS#1 data sign : " );
|
||||
|
||||
sha1( rsa_plaintext, PT_LEN, sha1sum );
|
||||
|
||||
@ -1551,25 +1557,25 @@ int rsa_self_test( int verbose )
|
||||
sha1sum, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n PKCS#1 sig. verify: " );
|
||||
polarssl_printf( "passed\n PKCS#1 sig. verify: " );
|
||||
|
||||
if( rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC, POLARSSL_MD_SHA1, 0,
|
||||
sha1sum, rsa_ciphertext ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n\n" );
|
||||
polarssl_printf( "passed\n\n" );
|
||||
#endif /* POLARSSL_SHA1_C */
|
||||
|
||||
rsa_free( &rsa );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS-180-1 compliant SHA-1 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,6 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_SHA1_ALT)
|
||||
|
||||
/*
|
||||
@ -548,7 +554,7 @@ int sha1_self_test( int verbose )
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " SHA-1 test #%d: ", i + 1 );
|
||||
polarssl_printf( " SHA-1 test #%d: ", i + 1 );
|
||||
|
||||
sha1_starts( &ctx );
|
||||
|
||||
@ -568,22 +574,22 @@ int sha1_self_test( int verbose )
|
||||
if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC-SHA-1 test #%d: ", i + 1 );
|
||||
polarssl_printf( " HMAC-SHA-1 test #%d: ", i + 1 );
|
||||
|
||||
if( i == 5 || i == 6 )
|
||||
{
|
||||
@ -604,17 +610,17 @@ int sha1_self_test( int verbose )
|
||||
if( memcmp( sha1sum, sha1_hmac_test_sum[i], buflen ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS-180-2 compliant SHA-256 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,6 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_SHA256_ALT)
|
||||
|
||||
/*
|
||||
@ -626,7 +632,7 @@ int sha256_self_test( int verbose )
|
||||
k = i < 3;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
polarssl_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
|
||||
sha256_starts( &ctx, k );
|
||||
|
||||
@ -646,17 +652,17 @@ int sha256_self_test( int verbose )
|
||||
if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
for( i = 0; i < 14; i++ )
|
||||
{
|
||||
@ -664,7 +670,7 @@ int sha256_self_test( int verbose )
|
||||
k = i < 7;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
polarssl_printf( " HMAC-SHA-%d test #%d: ", 256 - k * 32, j + 1 );
|
||||
|
||||
if( j == 5 || j == 6 )
|
||||
{
|
||||
@ -685,17 +691,17 @@ int sha256_self_test( int verbose )
|
||||
if( memcmp( sha256sum, sha256_hmac_test_sum[i], buflen ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* FIPS-180-2 compliant SHA-384/512 implementation
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,6 +38,12 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_SHA512_ALT)
|
||||
|
||||
/*
|
||||
@ -681,7 +687,7 @@ int sha512_self_test( int verbose )
|
||||
k = i < 3;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 );
|
||||
polarssl_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 );
|
||||
|
||||
sha512_starts( &ctx, k );
|
||||
|
||||
@ -701,17 +707,17 @@ int sha512_self_test( int verbose )
|
||||
if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
for( i = 0; i < 14; i++ )
|
||||
{
|
||||
@ -719,7 +725,7 @@ int sha512_self_test( int verbose )
|
||||
k = i < 7;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " HMAC-SHA-%d test #%d: ", 512 - k * 128, j + 1 );
|
||||
polarssl_printf( " HMAC-SHA-%d test #%d: ", 512 - k * 128, j + 1 );
|
||||
|
||||
if( j == 5 || j == 6 )
|
||||
{
|
||||
@ -740,17 +746,17 @@ int sha512_self_test( int verbose )
|
||||
if( memcmp( sha512sum, sha512_hmac_test_sum[i], buflen ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SSL session cache implementation
|
||||
*
|
||||
* Copyright (C) 2006-2012, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -33,8 +33,8 @@
|
||||
|
||||
#include "polarssl/ssl_cache.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SSLv3/TLSv1 client-side functions
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -30,8 +30,8 @@
|
||||
#include "polarssl/debug.h"
|
||||
#include "polarssl/ssl.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SSLv3/TLSv1 server-side functions
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -33,8 +33,8 @@
|
||||
#include "polarssl/ecp.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SSLv3/TLSv1 shared functions
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -38,8 +38,8 @@
|
||||
#include "polarssl/debug.h"
|
||||
#include "polarssl/ssl.h"
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 certificate and private key decoding
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -45,9 +45,10 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
#endif
|
||||
@ -991,7 +992,7 @@ int x509_self_test( int verbose )
|
||||
x509_crt clicert;
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( " X.509 certificate load: " );
|
||||
polarssl_printf( " X.509 certificate load: " );
|
||||
|
||||
x509_crt_init( &clicert );
|
||||
|
||||
@ -1000,7 +1001,7 @@ int x509_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
@ -1012,27 +1013,27 @@ int x509_self_test( int verbose )
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n X.509 signature verify: ");
|
||||
polarssl_printf( "passed\n X.509 signature verify: ");
|
||||
|
||||
ret = x509_crt_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
|
||||
if( ret != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
printf("ret = %d, &flags = %04x\n", ret, flags);
|
||||
polarssl_printf("ret = %d, &flags = %04x\n", ret, flags);
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n\n");
|
||||
polarssl_printf( "passed\n\n");
|
||||
|
||||
x509_crt_free( &cacert );
|
||||
x509_crt_free( &clicert );
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 certificate and private key decoding
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -44,8 +44,8 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 certificate and private key decoding
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -44,8 +44,8 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* X.509 Certificate Signing Request (CSR) parsing
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -44,8 +44,8 @@
|
||||
#include "polarssl/pem.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
|
@ -29,6 +29,12 @@
|
||||
|
||||
#include "polarssl/xtea.h"
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if !defined(POLARSSL_XTEA_ALT)
|
||||
|
||||
/*
|
||||
@ -220,7 +226,7 @@ int xtea_self_test( int verbose )
|
||||
for( i = 0; i < 6; i++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( " XTEA test #%d: ", i + 1 );
|
||||
polarssl_printf( " XTEA test #%d: ", i + 1 );
|
||||
|
||||
memcpy( buf, xtea_test_pt[i], 8 );
|
||||
|
||||
@ -230,17 +236,17 @@ int xtea_self_test( int verbose )
|
||||
if( memcmp( buf, xtea_test_ct[i], 8 ) != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
printf( "failed\n" );
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "passed\n" );
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user