28 #if defined(POLARSSL_DEBUG_C)
35 #if defined(EFIX64) || defined(EFI32)
39 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
41 #define snprintf _snprintf
44 #if !defined vsnprintf
45 #define vsnprintf _vsnprintf
49 char *
debug_fmt(
const char *format, ... )
53 int maxlen =
sizeof( str ) - 1;
55 va_start( argp, format );
56 vsnprintf( str, maxlen, format, argp );
64 const char *file,
int line,
const char *text )
67 int maxlen =
sizeof( str ) - 1;
69 if( ssl->
f_dbg == NULL )
72 snprintf( str, maxlen,
"%s(%04d): %s\n", file, line, text );
78 const char *file,
int line,
79 const char *text,
int ret )
82 int maxlen =
sizeof( str ) - 1;
84 if( ssl->
f_dbg == NULL )
87 snprintf( str, maxlen,
"%s(%04d): %s() returned %d (0x%x)\n",
88 file, line, text, ret, ret );
95 const char *file,
int line,
const char *text,
96 unsigned char *buf,
size_t len )
99 size_t i, maxlen =
sizeof( str ) - 1;
101 if( ssl->
f_dbg == NULL )
104 snprintf( str, maxlen,
"%s(%04d): dumping '%s' (%d bytes)\n",
105 file, line, text, (
unsigned int) len );
110 for( i = 0; i < len; i++ )
120 snprintf( str, maxlen,
"%s(%04d): %04x: ", file, line,
127 snprintf( str, maxlen,
" %02x", (
unsigned int) buf[i] );
137 #if defined(POLARSSL_ECP_C)
139 const char *file,
int line,
143 int maxlen =
sizeof( str ) - 1;
145 snprintf( str, maxlen,
"%s(X)", text );
149 snprintf( str, maxlen,
"%s(Y)", text );
153 snprintf( str, maxlen,
"%s(Z)", text );
159 #if defined(POLARSSL_BIGNUM_C)
161 const char *file,
int line,
162 const char *text,
const mpi *X )
165 int j, k, maxlen =
sizeof( str ) - 1, zeros = 1;
168 if( ssl->
f_dbg == NULL || X == NULL )
171 for( n = X->
n - 1; n > 0; n-- )
175 for( j = (
sizeof(
t_uint) << 3 ) - 1; j >= 0; j-- )
176 if( ( ( X->
p[n] >> j ) & 1 ) != 0 )
179 snprintf( str, maxlen,
"%s(%04d): value of '%s' (%d bits) is:\n",
181 (
int) ( ( n * (
sizeof(
t_uint) << 3 ) ) + j + 1 ) );
186 for( i = n + 1, j = 0; i > 0; i-- )
188 if( zeros && X->
p[i - 1] == 0 )
191 for( k =
sizeof(
t_uint ) - 1; k >= 0; k-- )
193 if( zeros && ( ( X->
p[i - 1] >> (k << 3) ) & 0xFF ) == 0 )
203 snprintf( str, maxlen,
"%s(%04d): ", file, line );
209 snprintf( str, maxlen,
" %02x", (
unsigned int)
210 ( X->
p[i - 1] >> (k << 3) ) & 0xFF );
222 snprintf( str, maxlen,
"%s(%04d): ", file, line );
233 #if defined(POLARSSL_X509_CRT_PARSE_C)
234 static void debug_print_pk(
const ssl_context *ssl,
int level,
235 const char *file,
int line,
242 memset( items, 0,
sizeof( items ) );
250 for( i = 0; i <
sizeof( items ); i++ )
255 snprintf( name,
sizeof( name ),
"%s%s", text, items[i].name );
256 name[
sizeof( name ) - 1] =
'\0';
261 #if defined(POLARSSL_ECP_C)
271 const char *file,
int line,
272 const char *text,
const x509_crt *crt )
274 char str[1024], prefix[64];
275 int i = 0, maxlen =
sizeof( prefix ) - 1;
277 if( ssl->
f_dbg == NULL || crt == NULL )
280 snprintf( prefix, maxlen,
"%s(%04d): ", file, line );
281 prefix[maxlen] =
'\0';
282 maxlen =
sizeof( str ) - 1;
289 snprintf( str, maxlen,
"%s(%04d): %s #%d:\n%s",
290 file, line, text, ++i, buf );
295 debug_print_pk( ssl, level, file, line,
"crt->", &crt->
pk );
void debug_print_crt(const ssl_context *ssl, int level, const char *file, int line, const char *text, const x509_crt *crt)
void(* f_dbg)(void *, int, const char *)
void debug_print_msg(const ssl_context *ssl, int level, const char *file, int line, const char *text)
int pk_debug(const pk_context *ctx, pk_debug_item *items)
Export debug information.
Configuration options (set of defines)
void debug_print_ecp(const ssl_context *ssl, int level, const char *file, int line, const char *text, const ecp_point *X)
struct _x509_crt * next
Next certificate in the CA-chain.
Container for an X.509 certificate.
Item to send to the debug module.
ECP point structure (jacobian coordinates)
void debug_print_mpi(const ssl_context *ssl, int level, const char *file, int line, const char *text, const mpi *X)
void debug_print_buf(const ssl_context *ssl, int level, const char *file, int line, const char *text, unsigned char *buf, size_t len)
void debug_print_ret(const ssl_context *ssl, int level, const char *file, int line, const char *text, int ret)
pk_context pk
Container for the public key context.
char * debug_fmt(const char *format,...)
#define POLARSSL_PK_DEBUG_MAX_ITEMS
Maximum number of item send for debugging, plus 1.
int x509_crt_info(char *buf, size_t size, const char *prefix, const x509_crt *crt)
Returns an informational string about the certificate.