mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-24 00:06:32 +01:00
- Moved all examples programs to use the new entropy and CTR_DRBG
This commit is contained in:
parent
4dc6457274
commit
508ad5ab6d
15 changed files with 343 additions and 143 deletions
|
|
@ -37,23 +37,25 @@
|
|||
#include "polarssl/dhm.h"
|
||||
#include "polarssl/rsa.h"
|
||||
#include "polarssl/sha1.h"
|
||||
#include "polarssl/havege.h"
|
||||
#include "polarssl/entropy.h"
|
||||
#include "polarssl/ctr_drbg.h"
|
||||
|
||||
#define SERVER_NAME "localhost"
|
||||
#define SERVER_PORT 11999
|
||||
|
||||
#if !defined(POLARSSL_AES_C) || !defined(POLARSSL_DHM_C) || \
|
||||
!defined(POLARSSL_HAVEGE_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_ENTROPY_C) || !defined(POLARSSL_NET_C) || \
|
||||
!defined(POLARSSL_RSA_C) || !defined(POLARSSL_SHA1_C) || \
|
||||
!defined(POLARSSL_FS_IO)
|
||||
!defined(POLARSSL_FS_IO) || !defined(POLARSSL_CTR_DRBG_C)
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_HAVEGE_C "
|
||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
|
||||
"and/or POLARSSL_NET_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
|
@ -68,8 +70,10 @@ int main( int argc, char *argv[] )
|
|||
unsigned char *p, *end;
|
||||
unsigned char buf[1024];
|
||||
unsigned char hash[20];
|
||||
char *pers = "dh_client";
|
||||
|
||||
havege_state hs;
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
rsa_context rsa;
|
||||
dhm_context dhm;
|
||||
aes_context aes;
|
||||
|
|
@ -86,7 +90,13 @@ int main( int argc, char *argv[] )
|
|||
printf( "\n . Seeding the random number generator" );
|
||||
fflush( stdout );
|
||||
|
||||
havege_init( &hs );
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 2. Read the server's public RSA key
|
||||
|
|
@ -207,7 +217,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
n = dhm.len;
|
||||
if( ( ret = dhm_make_public( &dhm, 256, buf, n,
|
||||
havege_random, &hs ) ) != 0 )
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_make_public returned %d\n\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -273,6 +283,6 @@ exit:
|
|||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_HAVEGE_C &&
|
||||
#endif /* POLARSSL_AES_C && POLARSSL_DHM_C && POLARSSL_ENTROPY_C &&
|
||||
POLARSSL_NET_C && POLARSSL_RSA_C && POLARSSL_SHA1_C &&
|
||||
POLARSSL_FS_IO */
|
||||
POLARSSL_FS_IO && POLARSSL_CTR_DRBG_C */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue