mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-08 15:39:22 +01:00
Merge branch 'development' into dtls
* development: (46 commits) Fix url again Fix small bug in base64_encode() Fix depend that was checked but not documented Fix dependency that was not checked Minor gitginore fixes Move some ignore patterns to subdirectories Ignore CMake/MSVC-related build files. Re-categorize changelog entry Fix misattribution Minor nits with stdout/stderr. Add cmake compatibility targets Add script for polarssl symlink creation Fix more stdio inclusion issues Add debug info for cert/suite selection Fix possible portability issue Fix bug in ssl_get_verify_result() aescrypt2.c local char array not initial Update Changelog Fix mips64 bignum implementation Fix usage string of ssl_client2 ... Conflicts: include/polarssl/ssl.h library/CMakeLists.txt library/Makefile programs/Makefile programs/ssl/ssl_client2.c programs/ssl/ssl_server2.c visualc/VS2010/PolarSSL.sln visualc/VS2010/mbedTLS.vcxproj visualc/VS6/mbedtls.dsp visualc/VS6/mbedtls.dsw
This commit is contained in:
commit
2a0718d947
267 changed files with 5475 additions and 3350 deletions
|
|
@ -1,59 +1,59 @@
|
|||
add_executable(dh_client dh_client.c)
|
||||
target_link_libraries(dh_client polarssl)
|
||||
target_link_libraries(dh_client mbedtls)
|
||||
|
||||
add_executable(dh_genprime dh_genprime.c)
|
||||
target_link_libraries(dh_genprime polarssl)
|
||||
target_link_libraries(dh_genprime mbedtls)
|
||||
|
||||
add_executable(dh_server dh_server.c)
|
||||
target_link_libraries(dh_server polarssl)
|
||||
target_link_libraries(dh_server mbedtls)
|
||||
|
||||
add_executable(ecdsa ecdsa.c)
|
||||
target_link_libraries(ecdsa polarssl)
|
||||
target_link_libraries(ecdsa mbedtls)
|
||||
|
||||
add_executable(gen_key gen_key.c)
|
||||
target_link_libraries(gen_key polarssl)
|
||||
target_link_libraries(gen_key mbedtls)
|
||||
|
||||
add_executable(key_app key_app.c)
|
||||
target_link_libraries(key_app polarssl)
|
||||
target_link_libraries(key_app mbedtls)
|
||||
|
||||
add_executable(key_app_writer key_app_writer.c)
|
||||
target_link_libraries(key_app_writer polarssl)
|
||||
target_link_libraries(key_app_writer mbedtls)
|
||||
|
||||
add_executable(mpi_demo mpi_demo.c)
|
||||
target_link_libraries(mpi_demo polarssl)
|
||||
target_link_libraries(mpi_demo mbedtls)
|
||||
|
||||
add_executable(rsa_genkey rsa_genkey.c)
|
||||
target_link_libraries(rsa_genkey polarssl)
|
||||
target_link_libraries(rsa_genkey mbedtls)
|
||||
|
||||
add_executable(rsa_sign rsa_sign.c)
|
||||
target_link_libraries(rsa_sign polarssl)
|
||||
target_link_libraries(rsa_sign mbedtls)
|
||||
|
||||
add_executable(rsa_verify rsa_verify.c)
|
||||
target_link_libraries(rsa_verify polarssl)
|
||||
target_link_libraries(rsa_verify mbedtls)
|
||||
|
||||
add_executable(rsa_sign_pss rsa_sign_pss.c)
|
||||
target_link_libraries(rsa_sign_pss polarssl)
|
||||
target_link_libraries(rsa_sign_pss mbedtls)
|
||||
|
||||
add_executable(rsa_verify_pss rsa_verify_pss.c)
|
||||
target_link_libraries(rsa_verify_pss polarssl)
|
||||
target_link_libraries(rsa_verify_pss mbedtls)
|
||||
|
||||
add_executable(rsa_encrypt rsa_encrypt.c)
|
||||
target_link_libraries(rsa_encrypt polarssl)
|
||||
target_link_libraries(rsa_encrypt mbedtls)
|
||||
|
||||
add_executable(rsa_decrypt rsa_decrypt.c)
|
||||
target_link_libraries(rsa_decrypt polarssl)
|
||||
target_link_libraries(rsa_decrypt mbedtls)
|
||||
|
||||
add_executable(pk_sign pk_sign.c)
|
||||
target_link_libraries(pk_sign polarssl)
|
||||
target_link_libraries(pk_sign mbedtls)
|
||||
|
||||
add_executable(pk_verify pk_verify.c)
|
||||
target_link_libraries(pk_verify polarssl)
|
||||
target_link_libraries(pk_verify mbedtls)
|
||||
|
||||
add_executable(pk_encrypt pk_encrypt.c)
|
||||
target_link_libraries(pk_encrypt polarssl)
|
||||
target_link_libraries(pk_encrypt mbedtls)
|
||||
|
||||
add_executable(pk_decrypt pk_decrypt.c)
|
||||
target_link_libraries(pk_decrypt polarssl)
|
||||
target_link_libraries(pk_decrypt mbedtls)
|
||||
|
||||
install(TARGETS dh_client dh_genprime dh_server key_app mpi_demo rsa_genkey rsa_sign rsa_verify rsa_encrypt rsa_decrypt pk_encrypt pk_decrypt pk_sign pk_verify gen_key
|
||||
DESTINATION "bin"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -49,7 +55,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
|
||||
polarssl_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 and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
|
|
@ -85,7 +91,7 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1. Setup the RNG
|
||||
*/
|
||||
printf( "\n . Seeding the random number generator" );
|
||||
polarssl_printf( "\n . Seeding the random number generator" );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -93,20 +99,20 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 2. Read the server's public RSA key
|
||||
*/
|
||||
printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
polarssl_printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -116,7 +122,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -127,35 +133,35 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 3. Initiate the connection
|
||||
*/
|
||||
printf( "\n . Connecting to tcp/%s/%d", SERVER_NAME,
|
||||
polarssl_printf( "\n . Connecting to tcp/%s/%d", SERVER_NAME,
|
||||
SERVER_PORT );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = net_connect( &server_fd, SERVER_NAME,
|
||||
SERVER_PORT, NET_PROTO_TCP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_connect returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_connect returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 4a. First get the buffer length
|
||||
*/
|
||||
printf( "\n . Receiving the server's DH parameters" );
|
||||
polarssl_printf( "\n . Receiving the server's DH parameters" );
|
||||
fflush( stdout );
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
if( ( ret = net_recv( &server_fd, buf, 2 ) ) != 2 )
|
||||
{
|
||||
printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
n = buflen = ( buf[0] << 8 ) | buf[1];
|
||||
if( buflen < 1 || buflen > sizeof( buf ) )
|
||||
{
|
||||
printf( " failed\n ! Got an invalid buffer length\n\n" );
|
||||
polarssl_printf( " failed\n ! Got an invalid buffer length\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +172,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = net_recv( &server_fd, buf, n ) ) != (int) n )
|
||||
{
|
||||
printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -174,14 +180,14 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = dhm_read_params( &dhm, &p, end ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_read_params returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_read_params returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( dhm.len < 64 || dhm.len > 512 )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Invalid DHM modulus size\n\n" );
|
||||
polarssl_printf( " failed\n ! Invalid DHM modulus size\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +195,7 @@ int main( int argc, char *argv[] )
|
|||
* 5. Check that the server's RSA signature matches
|
||||
* the SHA-1 hash of (P,G,Ys)
|
||||
*/
|
||||
printf( "\n . Verifying the server's RSA signature" );
|
||||
polarssl_printf( "\n . Verifying the server's RSA signature" );
|
||||
fflush( stdout );
|
||||
|
||||
p += 2;
|
||||
|
|
@ -197,7 +203,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( n = (size_t) ( end - p ) ) != rsa.len )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Invalid RSA signature size\n\n" );
|
||||
polarssl_printf( " failed\n ! Invalid RSA signature size\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -206,46 +212,46 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC,
|
||||
POLARSSL_MD_SHA1, 0, hash, p ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_verify returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_verify returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 6. Send our public value: Yc = G ^ Xc mod P
|
||||
*/
|
||||
printf( "\n . Sending own public value to server" );
|
||||
polarssl_printf( "\n . Sending own public value to server" );
|
||||
fflush( stdout );
|
||||
|
||||
n = dhm.len;
|
||||
if( ( ret = dhm_make_public( &dhm, (int) dhm.len, buf, n,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_make_public returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_make_public returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = net_send( &server_fd, buf, n ) ) != (int) n )
|
||||
{
|
||||
printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 7. Derive the shared secret: K = Ys ^ Xc mod P
|
||||
*/
|
||||
printf( "\n . Shared secret: " );
|
||||
polarssl_printf( "\n . Shared secret: " );
|
||||
fflush( stdout );
|
||||
|
||||
n = dhm.len;
|
||||
if( ( ret = dhm_calc_secret( &dhm, buf, &n,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_calc_secret returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_calc_secret returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( n = 0; n < 16; n++ )
|
||||
printf( "%02x", buf[n] );
|
||||
polarssl_printf( "%02x", buf[n] );
|
||||
|
||||
/*
|
||||
* 8. Setup the AES-256 decryption key
|
||||
|
|
@ -255,7 +261,7 @@ int main( int argc, char *argv[] )
|
|||
* the keying material for the encryption/decryption keys,
|
||||
* IVs and MACs.
|
||||
*/
|
||||
printf( "...\n . Receiving and decrypting the ciphertext" );
|
||||
polarssl_printf( "...\n . Receiving and decrypting the ciphertext" );
|
||||
fflush( stdout );
|
||||
|
||||
aes_setkey_dec( &aes, buf, 256 );
|
||||
|
|
@ -264,13 +270,13 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = net_recv( &server_fd, buf, 16 ) ) != 16 )
|
||||
{
|
||||
printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
aes_crypt_ecb( &aes, AES_DECRYPT, buf, buf );
|
||||
buf[16] = '\0';
|
||||
printf( "\n . Plaintext is \"%s\"\n\n", (char *) buf );
|
||||
polarssl_printf( "\n . Plaintext is \"%s\"\n\n", (char *) buf );
|
||||
|
||||
exit:
|
||||
|
||||
|
|
@ -284,7 +290,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2012, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "polarssl/bignum.h"
|
||||
|
|
@ -47,7 +53,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C and/or "
|
||||
"POLARSSL_GENPRIME not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -70,31 +76,31 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = mpi_read_string( &G, 10, GENERATOR ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_string returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_string returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\nWARNING: You should not generate and use your own DHM primes\n" );
|
||||
printf( " unless you are very certain of what you are doing!\n" );
|
||||
printf( " Failing to follow this instruction may result in\n" );
|
||||
printf( " weak security for your connections! Use the\n" );
|
||||
printf( " predefined DHM parameters from dhm.h instead!\n\n" );
|
||||
printf( "============================================================\n\n" );
|
||||
polarssl_printf( "\nWARNING: You should not generate and use your own DHM primes\n" );
|
||||
polarssl_printf( " unless you are very certain of what you are doing!\n" );
|
||||
polarssl_printf( " Failing to follow this instruction may result in\n" );
|
||||
polarssl_printf( " weak security for your connections! Use the\n" );
|
||||
polarssl_printf( " predefined DHM parameters from dhm.h instead!\n\n" );
|
||||
polarssl_printf( "============================================================\n\n" );
|
||||
|
||||
printf( " ! Generating large primes may take minutes!\n" );
|
||||
polarssl_printf( " ! Generating large primes may take minutes!\n" );
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Generating the modulus, please wait..." );
|
||||
polarssl_printf( " ok\n . Generating the modulus, please wait..." );
|
||||
fflush( stdout );
|
||||
|
||||
/*
|
||||
|
|
@ -103,49 +109,49 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = mpi_gen_prime( &P, DH_P_SIZE, 1,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_gen_prime returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_gen_prime returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Verifying that Q = (P-1)/2 is prime..." );
|
||||
polarssl_printf( " ok\n . Verifying that Q = (P-1)/2 is prime..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = mpi_sub_int( &Q, &P, 1 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_sub_int returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_sub_int returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mpi_div_int( &Q, NULL, &Q, 2 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_div_int returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_div_int returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mpi_is_prime( &Q, ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_is_prime returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_is_prime returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Exporting the value in dh_prime.txt..." );
|
||||
polarssl_printf( " ok\n . Exporting the value in dh_prime.txt..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( fout = fopen( "dh_prime.txt", "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create dh_prime.txt\n\n" );
|
||||
polarssl_printf( " failed\n ! Could not create dh_prime.txt\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = mpi_write_file( "P = ", &P, 16, fout ) != 0 ) ||
|
||||
( ret = mpi_write_file( "G = ", &G, 16, fout ) != 0 ) )
|
||||
{
|
||||
printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n\n" );
|
||||
polarssl_printf( " ok\n\n" );
|
||||
fclose( fout );
|
||||
|
||||
exit:
|
||||
|
|
@ -155,7 +161,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -49,7 +55,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_AES_C and/or POLARSSL_DHM_C and/or POLARSSL_ENTROPY_C "
|
||||
polarssl_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 and/or "
|
||||
"POLARSSL_CTR_DBRG_C not defined.\n");
|
||||
|
|
@ -86,7 +92,7 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1. Setup the RNG
|
||||
*/
|
||||
printf( "\n . Seeding the random number generator" );
|
||||
polarssl_printf( "\n . Seeding the random number generator" );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -94,20 +100,20 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 2a. Read the server's private RSA key
|
||||
*/
|
||||
printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
polarssl_printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -123,7 +129,7 @@ int main( int argc, char *argv[] )
|
|||
( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -134,13 +140,13 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 2b. Get the DHM modulus and generator
|
||||
*/
|
||||
printf( "\n . Reading DH parameters from dh_prime.txt" );
|
||||
polarssl_printf( "\n . Reading DH parameters from dh_prime.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "dh_prime.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open dh_prime.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open dh_prime.txt\n" \
|
||||
" ! Please run dh_genprime first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -148,7 +154,7 @@ int main( int argc, char *argv[] )
|
|||
if( mpi_read_file( &dhm.P, 16, f ) != 0 ||
|
||||
mpi_read_file( &dhm.G, 16, f ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Invalid DH parameter file\n\n" );
|
||||
polarssl_printf( " failed\n ! Invalid DH parameter file\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -157,25 +163,25 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 3. Wait for a client to connect
|
||||
*/
|
||||
printf( "\n . Waiting for a remote connection" );
|
||||
polarssl_printf( "\n . Waiting for a remote connection" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = net_bind( &listen_fd, NULL, SERVER_PORT, NET_PROTO_TCP ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_bind returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! net_accept returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_accept returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 4. Setup the DH parameters (P,G,Ys)
|
||||
*/
|
||||
printf( "\n . Sending the server's DH parameters" );
|
||||
polarssl_printf( "\n . Sending the server's DH parameters" );
|
||||
fflush( stdout );
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
|
@ -183,7 +189,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = dhm_make_params( &dhm, (int) mpi_size( &dhm.P ), buf, &n,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_make_params returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_make_params returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +204,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = rsa_pkcs1_sign( &rsa, NULL, NULL, RSA_PRIVATE, POLARSSL_MD_SHA1,
|
||||
0, hash, buf + n + 2 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_sign returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_sign returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -209,14 +215,14 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = net_send( &client_fd, buf2, 2 ) ) != 2 ||
|
||||
( ret = net_send( &client_fd, buf, buflen ) ) != (int) buflen )
|
||||
{
|
||||
printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 6. Get the client's public value: Yc = G ^ Xc mod P
|
||||
*/
|
||||
printf( "\n . Receiving the client's public value" );
|
||||
polarssl_printf( "\n . Receiving the client's public value" );
|
||||
fflush( stdout );
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
|
@ -224,31 +230,31 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = net_recv( &client_fd, buf, n ) ) != (int) n )
|
||||
{
|
||||
printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_recv returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = dhm_read_public( &dhm, buf, dhm.len ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_read_public returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_read_public returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 7. Derive the shared secret: K = Ys ^ Xc mod P
|
||||
*/
|
||||
printf( "\n . Shared secret: " );
|
||||
polarssl_printf( "\n . Shared secret: " );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = dhm_calc_secret( &dhm, buf, &n,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! dhm_calc_secret returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! dhm_calc_secret returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( n = 0; n < 16; n++ )
|
||||
printf( "%02x", buf[n] );
|
||||
polarssl_printf( "%02x", buf[n] );
|
||||
|
||||
/*
|
||||
* 8. Setup the AES-256 encryption key
|
||||
|
|
@ -258,7 +264,7 @@ int main( int argc, char *argv[] )
|
|||
* the keying material for the encryption/decryption keys
|
||||
* and MACs.
|
||||
*/
|
||||
printf( "...\n . Encrypting and sending the ciphertext" );
|
||||
polarssl_printf( "...\n . Encrypting and sending the ciphertext" );
|
||||
fflush( stdout );
|
||||
|
||||
aes_setkey_enc( &aes, buf, 256 );
|
||||
|
|
@ -267,11 +273,11 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( ret = net_send( &client_fd, buf, 16 ) ) != 16 )
|
||||
{
|
||||
printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! net_send returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n\n" );
|
||||
polarssl_printf( "\n\n" );
|
||||
|
||||
exit:
|
||||
|
||||
|
|
@ -285,7 +291,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include "polarssl/entropy.h"
|
||||
#include "polarssl/ctr_drbg.h"
|
||||
#include "polarssl/ecdsa.h"
|
||||
|
|
@ -54,7 +60,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_ECDSA_C and/or "
|
||||
polarssl_printf("POLARSSL_ECDSA_C and/or "
|
||||
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C not defined\n");
|
||||
return( 0 );
|
||||
}
|
||||
|
|
@ -65,11 +71,11 @@ static void dump_buf( const char *title, unsigned char *buf, size_t len )
|
|||
{
|
||||
size_t i;
|
||||
|
||||
printf( "%s", title );
|
||||
polarssl_printf( "%s", title );
|
||||
for( i = 0; i < len; i++ )
|
||||
printf("%c%c", "0123456789ABCDEF" [buf[i] / 16],
|
||||
polarssl_printf("%c%c", "0123456789ABCDEF" [buf[i] / 16],
|
||||
"0123456789ABCDEF" [buf[i] % 16] );
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
}
|
||||
|
||||
static void dump_pubkey( const char *title, ecdsa_context *key )
|
||||
|
|
@ -80,7 +86,7 @@ static void dump_pubkey( const char *title, ecdsa_context *key )
|
|||
if( ecp_point_write_binary( &key->grp, &key->Q,
|
||||
POLARSSL_ECP_PF_UNCOMPRESSED, &len, buf, sizeof buf ) != 0 )
|
||||
{
|
||||
printf("internal error\n");
|
||||
polarssl_printf("internal error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -111,10 +117,10 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 1 )
|
||||
{
|
||||
printf( "usage: ecdsa\n" );
|
||||
polarssl_printf( "usage: ecdsa\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
|
|
@ -123,7 +129,7 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* Generate a key pair for signing
|
||||
*/
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -131,28 +137,28 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Generating key pair..." );
|
||||
polarssl_printf( " ok\n . Generating key pair..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ecdsa_genkey( &ctx_sign, ECPARAMS,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ecdsa_genkey returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ecdsa_genkey returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok (key size: %d bits)\n", (int) ctx_sign.grp.pbits );
|
||||
polarssl_printf( " ok (key size: %d bits)\n", (int) ctx_sign.grp.pbits );
|
||||
|
||||
dump_pubkey( " + Public key: ", &ctx_sign );
|
||||
|
||||
/*
|
||||
* Sign some message hash
|
||||
*/
|
||||
printf( " . Signing message..." );
|
||||
polarssl_printf( " . Signing message..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ecdsa_write_signature( &ctx_sign,
|
||||
|
|
@ -160,10 +166,10 @@ int main( int argc, char *argv[] )
|
|||
sig, &sig_len,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ecdsa_genkey returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ecdsa_genkey returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
printf( " ok (signature length = %u)\n", (unsigned int) sig_len );
|
||||
polarssl_printf( " ok (signature length = %u)\n", (unsigned int) sig_len );
|
||||
|
||||
dump_buf( " + Hash: ", hash, sizeof hash );
|
||||
dump_buf( " + Signature: ", sig, sig_len );
|
||||
|
|
@ -184,18 +190,18 @@ int main( int argc, char *argv[] )
|
|||
* chose to use a new one in order to make it clear that the verifying
|
||||
* context only needs the public key (Q), and not the private key (d).
|
||||
*/
|
||||
printf( " . Preparing verification context..." );
|
||||
polarssl_printf( " . Preparing verification context..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ecp_group_copy( &ctx_verify.grp, &ctx_sign.grp ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ecp_group_copy returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ecp_group_copy returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = ecp_copy( &ctx_verify.Q, &ctx_sign.Q ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ecp_copy returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ecp_copy returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -204,23 +210,23 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* Verify signature
|
||||
*/
|
||||
printf( " ok\n . Verifying signature..." );
|
||||
polarssl_printf( " ok\n . Verifying signature..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ecdsa_read_signature( &ctx_verify,
|
||||
hash, sizeof( hash ),
|
||||
sig, sig_len ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ecdsa_read_signature returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ecdsa_read_signature returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
exit:
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -49,7 +55,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
|
||||
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_ENTROPY_C and/or POLARSSL_CTR_DRBG_C "
|
||||
"not defined.\n" );
|
||||
return( 0 );
|
||||
|
|
@ -204,13 +210,13 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
usage:
|
||||
ret = 1;
|
||||
printf( USAGE );
|
||||
polarssl_printf( USAGE );
|
||||
#if defined(POLARSSL_ECP_C)
|
||||
printf( " availabled ec_curve values:\n" );
|
||||
polarssl_printf( " availabled ec_curve values:\n" );
|
||||
curve_info = ecp_curve_list();
|
||||
printf( " %s (default)\n", curve_info->name );
|
||||
polarssl_printf( " %s (default)\n", curve_info->name );
|
||||
while( ( ++curve_info )->name != NULL )
|
||||
printf( " %s\n", curve_info->name );
|
||||
polarssl_printf( " %s\n", curve_info->name );
|
||||
#endif
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -274,7 +280,7 @@ int main( int argc, char *argv[] )
|
|||
goto usage;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -284,11 +290,11 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = entropy_add_source( &entropy, dev_random_entropy_poll,
|
||||
NULL, DEV_RANDOM_THRESHOLD ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! entropy_add_source returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! entropy_add_source returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf("\n Using /dev/random, so can take a long time! " );
|
||||
polarssl_printf("\n Using /dev/random, so can take a long time! " );
|
||||
fflush( stdout );
|
||||
}
|
||||
#endif /* !_WIN32 && POLARSSL_FS_IO */
|
||||
|
|
@ -297,19 +303,19 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1.1. Generate the key
|
||||
*/
|
||||
printf( "\n . Generating the private key ..." );
|
||||
polarssl_printf( "\n . Generating the private key ..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_init_ctx( &key, pk_info_from_type( opt.type ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_init_ctx returned -0x%04x", -ret );
|
||||
polarssl_printf( " failed\n ! pk_init_ctx returned -0x%04x", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -320,7 +326,7 @@ int main( int argc, char *argv[] )
|
|||
opt.rsa_keysize, 65537 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_gen_key returned -0x%04x", -ret );
|
||||
polarssl_printf( " failed\n ! rsa_gen_key returned -0x%04x", -ret );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -333,21 +339,21 @@ int main( int argc, char *argv[] )
|
|||
ctr_drbg_random, &ctr_drbg );
|
||||
if( ret != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_gen_key returned -0x%04x", -ret );
|
||||
polarssl_printf( " failed\n ! rsa_gen_key returned -0x%04x", -ret );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* POLARSSL_ECP_C */
|
||||
{
|
||||
printf( " failed\n ! key type not supported\n" );
|
||||
polarssl_printf( " failed\n ! key type not supported\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1.2 Print the key
|
||||
*/
|
||||
printf( " ok\n . Key information:\n" );
|
||||
polarssl_printf( " ok\n . Key information:\n" );
|
||||
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
if( pk_get_type( &key ) == POLARSSL_PK_RSA )
|
||||
|
|
@ -368,7 +374,7 @@ int main( int argc, char *argv[] )
|
|||
if( pk_get_type( &key ) == POLARSSL_PK_ECKEY )
|
||||
{
|
||||
ecp_keypair *ecp = pk_ec( key );
|
||||
printf( "curve: %s\n",
|
||||
polarssl_printf( "curve: %s\n",
|
||||
ecp_curve_info_from_grp_id( ecp->grp.id )->name );
|
||||
mpi_write_file( "X_Q: ", &ecp->Q.X, 16, NULL );
|
||||
mpi_write_file( "Y_Q: ", &ecp->Q.Y, 16, NULL );
|
||||
|
|
@ -376,20 +382,20 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
#endif
|
||||
printf(" ! key type not supported\n");
|
||||
polarssl_printf(" ! key type not supported\n");
|
||||
|
||||
/*
|
||||
* 1.3 Export key
|
||||
*/
|
||||
printf( " . Writing key to file..." );
|
||||
polarssl_printf( " . Writing key to file..." );
|
||||
|
||||
if( ( ret = write_private_key( &key, opt.filename ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n" );
|
||||
polarssl_printf( " failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
exit:
|
||||
|
||||
|
|
@ -397,9 +403,9 @@ exit:
|
|||
{
|
||||
#ifdef POLARSSL_ERROR_C
|
||||
polarssl_strerror( ret, buf, sizeof( buf ) );
|
||||
printf( " - %s\n", buf );
|
||||
polarssl_printf( " - %s\n", buf );
|
||||
#else
|
||||
printf("\n");
|
||||
polarssl_printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -408,7 +414,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -41,7 +47,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or "
|
||||
"POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
|
|
@ -94,7 +100,7 @@ int main( int argc, char *argv[] )
|
|||
if( argc == 0 )
|
||||
{
|
||||
usage:
|
||||
printf( USAGE );
|
||||
polarssl_printf( USAGE );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +139,7 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
if( strlen( opt.password ) && strlen( opt.password_file ) )
|
||||
{
|
||||
printf( "Error: cannot have both password and password_file\n" );
|
||||
polarssl_printf( "Error: cannot have both password and password_file\n" );
|
||||
goto usage;
|
||||
}
|
||||
|
||||
|
|
@ -141,16 +147,16 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
FILE *f;
|
||||
|
||||
printf( "\n . Loading the password file ..." );
|
||||
polarssl_printf( "\n . Loading the password file ..." );
|
||||
if( ( f = fopen( opt.password_file, "rb" ) ) == NULL )
|
||||
{
|
||||
printf( " failed\n ! fopen returned NULL\n" );
|
||||
polarssl_printf( " failed\n ! fopen returned NULL\n" );
|
||||
goto exit;
|
||||
}
|
||||
if( fgets( buf, sizeof(buf), f ) == NULL )
|
||||
{
|
||||
fclose( f );
|
||||
printf( "Error: fgets() failed to retrieve password\n" );
|
||||
polarssl_printf( "Error: fgets() failed to retrieve password\n" );
|
||||
goto exit;
|
||||
}
|
||||
fclose( f );
|
||||
|
|
@ -164,23 +170,23 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1.1. Load the key
|
||||
*/
|
||||
printf( "\n . Loading the private key ..." );
|
||||
polarssl_printf( "\n . Loading the private key ..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = pk_parse_keyfile( &pk, opt.filename, opt.password );
|
||||
|
||||
if( ret != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.2 Print the key
|
||||
*/
|
||||
printf( " . Key information ...\n" );
|
||||
polarssl_printf( " . Key information ...\n" );
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
|
||||
{
|
||||
|
|
@ -208,7 +214,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
{
|
||||
printf("Do not know how to print key information for this type\n" );
|
||||
polarssl_printf("Do not know how to print key information for this type\n" );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -217,20 +223,20 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1.1. Load the key
|
||||
*/
|
||||
printf( "\n . Loading the public key ..." );
|
||||
polarssl_printf( "\n . Loading the public key ..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = pk_parse_public_keyfile( &pk, opt.filename );
|
||||
|
||||
if( ret != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
printf( " . Key information ...\n" );
|
||||
polarssl_printf( " . Key information ...\n" );
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
|
||||
{
|
||||
|
|
@ -251,7 +257,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
{
|
||||
printf("Do not know how to print key information for this type\n" );
|
||||
polarssl_printf("Do not know how to print key information for this type\n" );
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
|
@ -262,13 +268,13 @@ exit:
|
|||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
pk_free( &pk );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -40,7 +46,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
|
||||
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
|
@ -201,7 +207,7 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
usage:
|
||||
ret = 1;
|
||||
printf( USAGE );
|
||||
polarssl_printf( USAGE );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -258,13 +264,13 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( opt.mode == MODE_NONE && opt.output_mode != OUTPUT_MODE_NONE )
|
||||
{
|
||||
printf( "\nCannot output a key without reading one.\n");
|
||||
polarssl_printf( "\nCannot output a key without reading one.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( opt.mode == MODE_PUBLIC && opt.output_mode == OUTPUT_MODE_PRIVATE )
|
||||
{
|
||||
printf( "\nCannot output a private key from a public key.\n");
|
||||
polarssl_printf( "\nCannot output a private key from a public key.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +279,7 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1.1. Load the key
|
||||
*/
|
||||
printf( "\n . Loading the private key ..." );
|
||||
polarssl_printf( "\n . Loading the private key ..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = pk_parse_keyfile( &key, opt.filename, NULL );
|
||||
|
|
@ -281,16 +287,16 @@ int main( int argc, char *argv[] )
|
|||
if( ret != 0 )
|
||||
{
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.2 Print the key
|
||||
*/
|
||||
printf( " . Key information ...\n" );
|
||||
polarssl_printf( " . Key information ...\n" );
|
||||
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
if( pk_get_type( &key ) == POLARSSL_PK_RSA )
|
||||
|
|
@ -318,7 +324,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
#endif
|
||||
printf("key type not supported yet\n");
|
||||
polarssl_printf("key type not supported yet\n");
|
||||
|
||||
}
|
||||
else if( opt.mode == MODE_PUBLIC )
|
||||
|
|
@ -326,7 +332,7 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* 1.1. Load the key
|
||||
*/
|
||||
printf( "\n . Loading the public key ..." );
|
||||
polarssl_printf( "\n . Loading the public key ..." );
|
||||
fflush( stdout );
|
||||
|
||||
ret = pk_parse_public_keyfile( &key, opt.filename );
|
||||
|
|
@ -334,16 +340,16 @@ int main( int argc, char *argv[] )
|
|||
if( ret != 0 )
|
||||
{
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
|
||||
polarssl_printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n" );
|
||||
polarssl_printf( " ok\n" );
|
||||
|
||||
/*
|
||||
* 1.2 Print the key
|
||||
*/
|
||||
printf( " . Key information ...\n" );
|
||||
polarssl_printf( " . Key information ...\n" );
|
||||
|
||||
#if defined(POLARSSL_RSA_C)
|
||||
if( pk_get_type( &key ) == POLARSSL_PK_RSA )
|
||||
|
|
@ -364,7 +370,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
#endif
|
||||
printf("key type not supported yet\n");
|
||||
polarssl_printf("key type not supported yet\n");
|
||||
}
|
||||
else
|
||||
goto usage;
|
||||
|
|
@ -384,16 +390,16 @@ exit:
|
|||
{
|
||||
#ifdef POLARSSL_ERROR_C
|
||||
polarssl_strerror( ret, buf, sizeof( buf ) );
|
||||
printf( " - %s\n", buf );
|
||||
polarssl_printf( " - %s\n", buf );
|
||||
#else
|
||||
printf("\n");
|
||||
polarssl_printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
pk_free( &key );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "polarssl/bignum.h"
|
||||
|
|
@ -36,7 +42,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
|
@ -56,11 +62,11 @@ int main( int argc, char *argv[] )
|
|||
mpi_read_string( &E, 10, "257" );
|
||||
mpi_mul_mpi( &N, &P, &Q );
|
||||
|
||||
printf( "\n Public key:\n\n" );
|
||||
polarssl_printf( "\n Public key:\n\n" );
|
||||
mpi_write_file( " N = ", &N, 10, NULL );
|
||||
mpi_write_file( " E = ", &E, 10, NULL );
|
||||
|
||||
printf( "\n Private key:\n\n" );
|
||||
polarssl_printf( "\n Private key:\n\n" );
|
||||
mpi_write_file( " P = ", &P, 10, NULL );
|
||||
mpi_write_file( " Q = ", &Q, 10, NULL );
|
||||
|
||||
|
|
@ -73,24 +79,24 @@ int main( int argc, char *argv[] )
|
|||
mpi_write_file( " D = E^-1 mod (P-1)*(Q-1) = ",
|
||||
&D, 10, NULL );
|
||||
#else
|
||||
printf("\nTest skipped (POLARSSL_GENPRIME not defined).\n\n");
|
||||
polarssl_printf("\nTest skipped (POLARSSL_GENPRIME not defined).\n\n");
|
||||
#endif
|
||||
mpi_read_string( &X, 10, "55555" );
|
||||
mpi_exp_mod( &Y, &X, &E, &N, NULL );
|
||||
mpi_exp_mod( &Z, &Y, &D, &N, NULL );
|
||||
|
||||
printf( "\n RSA operation:\n\n" );
|
||||
polarssl_printf( "\n RSA operation:\n\n" );
|
||||
mpi_write_file( " X (plaintext) = ", &X, 10, NULL );
|
||||
mpi_write_file( " Y (ciphertext) = X^E mod N = ", &Y, 10, NULL );
|
||||
mpi_write_file( " Z (decrypted) = Y^D mod N = ", &Z, 10, NULL );
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
mpi_free( &E ); mpi_free( &P ); mpi_free( &Q ); mpi_free( &N );
|
||||
mpi_free( &H ); mpi_free( &D ); mpi_free( &X ); mpi_free( &Y );
|
||||
mpi_free( &Z );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -42,7 +48,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
"POLARSSL_FS_IO and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -66,16 +72,16 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 2 )
|
||||
{
|
||||
printf( "usage: pk_decrypt <key_file>\n" );
|
||||
polarssl_printf( "usage: pk_decrypt <key_file>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -83,18 +89,18 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
pk_init( &pk );
|
||||
|
||||
if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +111,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -120,19 +126,19 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* Decrypt the encrypted RSA data and print the result.
|
||||
*/
|
||||
printf( "\n . Decrypting the encrypted data" );
|
||||
polarssl_printf( "\n . Decrypting the encrypted data" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_decrypt( &pk, buf, i, result, &olen, sizeof(result),
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_decrypt returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_decrypt returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK\n\n" );
|
||||
polarssl_printf( "\n . OK\n\n" );
|
||||
|
||||
printf( "The decrypted result is: '%s'\n\n", result );
|
||||
polarssl_printf( "The decrypted result is: '%s'\n\n", result );
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
|
@ -142,11 +148,11 @@ exit:
|
|||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,13 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -42,7 +49,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
"POLARSSL_ENTROPY_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -64,16 +71,16 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: pk_encrypt <key_file> <string of max 100 characters>\n" );
|
||||
polarssl_printf( "usage: pk_encrypt <key_file> <string of max 100 characters>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -81,24 +88,24 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
pk_init( &pk );
|
||||
|
||||
if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( strlen( argv[2] ) > 100 )
|
||||
{
|
||||
printf( " Input data larger than 100 characters.\n\n" );
|
||||
polarssl_printf( " Input data larger than 100 characters.\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -107,14 +114,14 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* Calculate the RSA encryption of the hash.
|
||||
*/
|
||||
printf( "\n . Generating the encrypted value" );
|
||||
polarssl_printf( "\n . Generating the encrypted value" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_encrypt( &pk, input, strlen( argv[2] ),
|
||||
buf, &olen, sizeof(buf),
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_encrypt returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_encrypt returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -124,17 +131,17 @@ int main( int argc, char *argv[] )
|
|||
if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
||||
polarssl_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( i = 0; i < olen; i++ )
|
||||
fprintf( f, "%02X%s", buf[i],
|
||||
polarssl_fprintf( f, "%02X%s", buf[i],
|
||||
( i + 1 ) % 16 == 0 ? "\r\n" : " " );
|
||||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
polarssl_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
|
|
@ -142,11 +149,11 @@ exit:
|
|||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -49,7 +55,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_SHA1_C and/or "
|
||||
"POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
|
|
@ -74,33 +80,33 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: pk_sign <key_file> <filename>\n" );
|
||||
polarssl_printf( "usage: pk_sign <key_file> <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open '%s'\n", argv[1] );
|
||||
polarssl_printf( " failed\n ! Could not open '%s'\n", argv[1] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -108,19 +114,19 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file,
|
||||
* then calculate the signature of the hash.
|
||||
*/
|
||||
printf( "\n . Generating the SHA-1 signature" );
|
||||
polarssl_printf( "\n . Generating the SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_sign returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_sign returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -132,19 +138,19 @@ int main( int argc, char *argv[] )
|
|||
if( ( f = fopen( filename, "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create %s\n\n", filename );
|
||||
polarssl_printf( " failed\n ! Could not create %s\n\n", filename );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( fwrite( buf, 1, olen, f ) != olen )
|
||||
{
|
||||
printf( "failed\n ! fwrite failed\n\n" );
|
||||
polarssl_printf( "failed\n ! fwrite failed\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Done (created \"%s\")\n\n", filename );
|
||||
polarssl_printf( "\n . Done (created \"%s\")\n\n", filename );
|
||||
|
||||
exit:
|
||||
pk_free( &pk );
|
||||
|
|
@ -153,11 +159,11 @@ exit:
|
|||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -46,7 +52,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or "
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
"POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -66,21 +72,21 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: pk_verify <key_file> <filename>\n" );
|
||||
polarssl_printf( "usage: pk_verify <key_file> <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -92,7 +98,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( f = fopen( filename, "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", filename );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", filename );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -105,23 +111,23 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file and compare
|
||||
* it with the hash decrypted from the signature.
|
||||
*/
|
||||
printf( "\n . Verifying the SHA-1 signature" );
|
||||
polarssl_printf( "\n . Verifying the SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = pk_verify( &pk, POLARSSL_MD_SHA1, hash, 0,
|
||||
buf, i ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_verify returned -0x%04x\n", -ret );
|
||||
polarssl_printf( " failed\n ! pk_verify returned -0x%04x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
polarssl_printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
|
@ -130,11 +136,11 @@ exit:
|
|||
|
||||
#if defined(POLARSSL_ERROR_C)
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " ! Last error was: %s\n", buf );
|
||||
polarssl_printf( " ! Last error was: %s\n", buf );
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -41,7 +47,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_FS_IO and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -65,16 +71,16 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 1 )
|
||||
{
|
||||
printf( "usage: rsa_decrypt\n" );
|
||||
polarssl_printf( "usage: rsa_decrypt\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -82,16 +88,16 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
polarssl_printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -107,7 +113,7 @@ int main( int argc, char *argv[] )
|
|||
( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +128,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", "result-enc.txt" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -136,27 +142,27 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( i != rsa.len )
|
||||
{
|
||||
printf( "\n ! Invalid RSA signature format\n\n" );
|
||||
polarssl_printf( "\n ! Invalid RSA signature format\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decrypt the encrypted RSA data and print the result.
|
||||
*/
|
||||
printf( "\n . Decrypting the encrypted data" );
|
||||
polarssl_printf( "\n . Decrypting the encrypted data" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_decrypt( &rsa, ctr_drbg_random, &ctr_drbg,
|
||||
RSA_PRIVATE, &i, buf, result,
|
||||
1024 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_decrypt returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK\n\n" );
|
||||
polarssl_printf( "\n . OK\n\n" );
|
||||
|
||||
printf( "The decrypted result is: '%s'\n\n", result );
|
||||
polarssl_printf( "The decrypted result is: '%s'\n\n", result );
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
|
@ -165,7 +171,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,13 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -41,7 +48,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_ENTROPY_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -63,16 +70,16 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 2 )
|
||||
{
|
||||
printf( "usage: rsa_encrypt <string of max 100 characters>\n" );
|
||||
polarssl_printf( "usage: rsa_encrypt <string of max 100 characters>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -80,17 +87,17 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
polarssl_printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -100,7 +107,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +117,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( strlen( argv[1] ) > 100 )
|
||||
{
|
||||
printf( " Input data larger than 100 characters.\n\n" );
|
||||
polarssl_printf( " Input data larger than 100 characters.\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -119,14 +126,14 @@ int main( int argc, char *argv[] )
|
|||
/*
|
||||
* Calculate the RSA encryption of the hash.
|
||||
*/
|
||||
printf( "\n . Generating the RSA encrypted value" );
|
||||
polarssl_printf( "\n . Generating the RSA encrypted value" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = rsa_pkcs1_encrypt( &rsa, ctr_drbg_random, &ctr_drbg,
|
||||
RSA_PUBLIC, strlen( argv[1] ),
|
||||
input, buf ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_encrypt returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -136,24 +143,24 @@ int main( int argc, char *argv[] )
|
|||
if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
||||
polarssl_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( i = 0; i < rsa.len; i++ )
|
||||
fprintf( f, "%02X%s", buf[i],
|
||||
polarssl_fprintf( f, "%02X%s", buf[i],
|
||||
( i + 1 ) % 16 == 0 ? "\r\n" : " " );
|
||||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
polarssl_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||
|
||||
exit:
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "polarssl/entropy.h"
|
||||
|
|
@ -45,7 +51,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_RSA_C and/or POLARSSL_GENPRIME and/or "
|
||||
"POLARSSL_FS_IO and/or POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -64,7 +70,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
entropy_init( &entropy );
|
||||
|
|
@ -72,11 +78,11 @@ int main( int argc, char *argv[] )
|
|||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
|
||||
polarssl_printf( " ok\n . Generating the RSA key [ %d-bit ]...", KEY_SIZE );
|
||||
fflush( stdout );
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
|
|
@ -84,16 +90,16 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = rsa_gen_key( &rsa, ctr_drbg_random, &ctr_drbg, KEY_SIZE,
|
||||
EXPONENT ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_gen_key returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! rsa_gen_key returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Exporting the public key in rsa_pub.txt...." );
|
||||
polarssl_printf( " ok\n . Exporting the public key in rsa_pub.txt...." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( fpub = fopen( "rsa_pub.txt", "wb+" ) ) == NULL )
|
||||
{
|
||||
printf( " failed\n ! could not open rsa_pub.txt for writing\n\n" );
|
||||
polarssl_printf( " failed\n ! could not open rsa_pub.txt for writing\n\n" );
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -101,16 +107,16 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = mpi_write_file( "N = ", &rsa.N, 16, fpub ) ) != 0 ||
|
||||
( ret = mpi_write_file( "E = ", &rsa.E, 16, fpub ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( " ok\n . Exporting the private key in rsa_priv.txt..." );
|
||||
polarssl_printf( " ok\n . Exporting the private key in rsa_priv.txt..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( fpriv = fopen( "rsa_priv.txt", "wb+" ) ) == NULL )
|
||||
{
|
||||
printf( " failed\n ! could not open rsa_priv.txt for writing\n" );
|
||||
polarssl_printf( " failed\n ! could not open rsa_priv.txt for writing\n" );
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -124,11 +130,11 @@ int main( int argc, char *argv[] )
|
|||
( ret = mpi_write_file( "DQ = ", &rsa.DQ, 16, fpriv ) ) != 0 ||
|
||||
( ret = mpi_write_file( "QP = ", &rsa.QP, 16, fpriv ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_write_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
/*
|
||||
printf( " ok\n . Generating the certificate..." );
|
||||
polarssl_printf( " ok\n . Generating the certificate..." );
|
||||
|
||||
x509write_init_raw( &cert );
|
||||
x509write_add_pubkey( &cert, &rsa );
|
||||
|
|
@ -140,7 +146,7 @@ int main( int argc, char *argv[] )
|
|||
x509write_crtfile( &cert, "cert.pem", X509_OUTPUT_PEM );
|
||||
x509write_free_raw( &cert );
|
||||
*/
|
||||
printf( " ok\n\n" );
|
||||
polarssl_printf( " ok\n\n" );
|
||||
|
||||
exit:
|
||||
|
||||
|
|
@ -155,7 +161,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,13 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -39,7 +46,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
|
|
@ -57,22 +64,22 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 2 )
|
||||
{
|
||||
printf( "usage: rsa_sign <filename>\n" );
|
||||
polarssl_printf( "usage: rsa_sign <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
polarssl_printf( "\n . Reading private key from rsa_priv.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -88,7 +95,7 @@ int main( int argc, char *argv[] )
|
|||
( ret = mpi_read_file( &rsa.DQ, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.QP, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -96,11 +103,11 @@ int main( int argc, char *argv[] )
|
|||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Checking the private key" );
|
||||
polarssl_printf( "\n . Checking the private key" );
|
||||
fflush( stdout );
|
||||
if( ( ret = rsa_check_privkey( &rsa ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_check_privkey failed with -0x%0x\n", -ret );
|
||||
polarssl_printf( " failed\n ! rsa_check_privkey failed with -0x%0x\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -108,19 +115,19 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file,
|
||||
* then calculate the RSA signature of the hash.
|
||||
*/
|
||||
printf( "\n . Generating the RSA/SHA-1 signature" );
|
||||
polarssl_printf( "\n . Generating the RSA/SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[1], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[1] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[1] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = rsa_pkcs1_sign( &rsa, NULL, NULL, RSA_PRIVATE, POLARSSL_MD_SHA1,
|
||||
20, hash, buf ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_sign returned -0x%0x\n\n", -ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_sign returned -0x%0x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -132,22 +139,22 @@ int main( int argc, char *argv[] )
|
|||
if( ( f = fopen( argv[1], "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create %s\n\n", argv[1] );
|
||||
polarssl_printf( " failed\n ! Could not create %s\n\n", argv[1] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for( i = 0; i < rsa.len; i++ )
|
||||
fprintf( f, "%02X%s", buf[i],
|
||||
polarssl_fprintf( f, "%02X%s", buf[i],
|
||||
( i + 1 ) % 16 == 0 ? "\r\n" : " " );
|
||||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Done (created \"%s\")\n\n", argv[1] );
|
||||
polarssl_printf( "\n . Done (created \"%s\")\n\n", argv[1] );
|
||||
|
||||
exit:
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -49,7 +55,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_ENTROPY_C and/or "
|
||||
"POLARSSL_RSA_C and/or POLARSSL_SHA1_C and/or "
|
||||
"POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO and/or "
|
||||
"POLARSSL_CTR_DRBG_C not defined.\n");
|
||||
|
|
@ -74,41 +80,41 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: rsa_sign_pss <key_file> <filename>\n" );
|
||||
polarssl_printf( "usage: rsa_sign_pss <key_file> <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Seeding the random number generator..." );
|
||||
polarssl_printf( "\n . Seeding the random number generator..." );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
polarssl_printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading private key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not read key from '%s'\n", argv[1] );
|
||||
printf( " ! pk_parse_public_keyfile returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! Could not read key from '%s'\n", argv[1] );
|
||||
polarssl_printf( " ! pk_parse_public_keyfile returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( !pk_can_do( &pk, POLARSSL_PK_RSA ) )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Key is not an RSA key\n" );
|
||||
polarssl_printf( " failed\n ! Key is not an RSA key\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -118,19 +124,19 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file,
|
||||
* then calculate the RSA signature of the hash.
|
||||
*/
|
||||
printf( "\n . Generating the RSA/SHA-1 signature" );
|
||||
polarssl_printf( "\n . Generating the RSA/SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = pk_sign( &pk, POLARSSL_MD_SHA1, hash, 0, buf, &olen,
|
||||
ctr_drbg_random, &ctr_drbg ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_sign returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! pk_sign returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -142,19 +148,19 @@ int main( int argc, char *argv[] )
|
|||
if( ( f = fopen( filename, "wb+" ) ) == NULL )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Could not create %s\n\n", filename );
|
||||
polarssl_printf( " failed\n ! Could not create %s\n\n", filename );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( fwrite( buf, 1, olen, f ) != olen )
|
||||
{
|
||||
printf( "failed\n ! fwrite failed\n\n" );
|
||||
polarssl_printf( "failed\n ! fwrite failed\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fclose( f );
|
||||
|
||||
printf( "\n . Done (created \"%s\")\n\n", filename );
|
||||
polarssl_printf( "\n . Done (created \"%s\")\n\n", filename );
|
||||
|
||||
exit:
|
||||
pk_free( &pk );
|
||||
|
|
@ -162,7 +168,7 @@ exit:
|
|||
entropy_free( &entropy );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -39,7 +45,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
}
|
||||
|
|
@ -56,21 +62,21 @@ int main( int argc, char *argv[] )
|
|||
ret = 1;
|
||||
if( argc != 2 )
|
||||
{
|
||||
printf( "usage: rsa_verify <filename>\n" );
|
||||
polarssl_printf( "usage: rsa_verify <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
polarssl_printf( "\n . Reading public key from rsa_pub.txt" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
|
||||
{
|
||||
printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
polarssl_printf( " failed\n ! Could not open rsa_pub.txt\n" \
|
||||
" ! Please run rsa_genkey first\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -80,7 +86,7 @@ int main( int argc, char *argv[] )
|
|||
if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
|
||||
( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! mpi_read_file returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +103,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( f = fopen( argv[1], "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", argv[1] );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", argv[1] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +117,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( i != rsa.len )
|
||||
{
|
||||
printf( "\n ! Invalid RSA signature format\n\n" );
|
||||
polarssl_printf( "\n ! Invalid RSA signature format\n\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -119,30 +125,30 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file and compare
|
||||
* it with the hash decrypted from the RSA signature.
|
||||
*/
|
||||
printf( "\n . Verifying the RSA/SHA-1 signature" );
|
||||
polarssl_printf( "\n . Verifying the RSA/SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[1], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[1] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[1] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = rsa_pkcs1_verify( &rsa, NULL, NULL, RSA_PUBLIC,
|
||||
POLARSSL_MD_SHA1, 20, hash, buf ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! rsa_pkcs1_verify returned -0x%0x\n\n", -ret );
|
||||
polarssl_printf( " failed\n ! rsa_pkcs1_verify returned -0x%0x\n\n", -ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
polarssl_printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
|
||||
*
|
||||
* This file is part of mbed TLS (https://www.polarssl.org)
|
||||
* This file is part of mbed TLS (https://polarssl.org)
|
||||
*
|
||||
* 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
|
||||
|
|
@ -26,6 +26,12 @@
|
|||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -47,7 +53,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
polarssl_printf("POLARSSL_BIGNUM_C and/or POLARSSL_RSA_C and/or "
|
||||
"POLARSSL_SHA1_C and/or POLARSSL_PK_PARSE_C and/or "
|
||||
"POLARSSL_FS_IO not defined.\n");
|
||||
return( 0 );
|
||||
|
|
@ -67,29 +73,29 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( argc != 3 )
|
||||
{
|
||||
printf( "usage: rsa_verify_pss <key_file> <filename>\n" );
|
||||
polarssl_printf( "usage: rsa_verify_pss <key_file> <filename>\n" );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( "\n" );
|
||||
polarssl_printf( "\n" );
|
||||
#endif
|
||||
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
polarssl_printf( "\n . Reading public key from '%s'", argv[1] );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not read key from '%s'\n", argv[1] );
|
||||
printf( " ! pk_parse_public_keyfile returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! Could not read key from '%s'\n", argv[1] );
|
||||
polarssl_printf( " ! pk_parse_public_keyfile returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( !pk_can_do( &pk, POLARSSL_PK_RSA ) )
|
||||
{
|
||||
ret = 1;
|
||||
printf( " failed\n ! Key is not an RSA key\n" );
|
||||
polarssl_printf( " failed\n ! Key is not an RSA key\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +109,7 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( ( f = fopen( filename, "rb" ) ) == NULL )
|
||||
{
|
||||
printf( "\n ! Could not open %s\n\n", filename );
|
||||
polarssl_printf( "\n ! Could not open %s\n\n", filename );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -116,23 +122,23 @@ int main( int argc, char *argv[] )
|
|||
* Compute the SHA-1 hash of the input file and compare
|
||||
* it with the hash decrypted from the RSA signature.
|
||||
*/
|
||||
printf( "\n . Verifying the RSA/SHA-1 signature" );
|
||||
polarssl_printf( "\n . Verifying the RSA/SHA-1 signature" );
|
||||
fflush( stdout );
|
||||
|
||||
if( ( ret = sha1_file( argv[2], hash ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
polarssl_printf( " failed\n ! Could not open or read %s\n\n", argv[2] );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( ret = pk_verify( &pk, POLARSSL_MD_SHA1, hash, 0,
|
||||
buf, i ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! pk_verify returned %d\n\n", ret );
|
||||
polarssl_printf( " failed\n ! pk_verify returned %d\n\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
polarssl_printf( "\n . OK (the decrypted SHA-1 hash matches)\n\n" );
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
|
@ -140,7 +146,7 @@ exit:
|
|||
pk_free( &pk );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue