Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c
index a3fa6d7..9c08435 100644
--- a/programs/pkey/rsa_verify.c
+++ b/programs/pkey/rsa_verify.c
@@ -24,12 +24,12 @@
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
!defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \
!defined(MBEDTLS_FS_IO)
-int main( void )
+int main(void)
{
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_RSA_C and/or "
- "MBEDTLS_MD_C and/or "
- "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n");
- mbedtls_exit( 0 );
+ "MBEDTLS_MD_C and/or "
+ "MBEDTLS_SHA256_C and/or MBEDTLS_FS_IO not defined.\n");
+ mbedtls_exit(0);
}
#else
@@ -40,7 +40,7 @@
#include <string.h>
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
FILE *f;
int ret = 1;
@@ -52,62 +52,58 @@
unsigned char buf[MBEDTLS_MPI_MAX_SIZE];
char filename[512];
- mbedtls_rsa_init( &rsa );
+ mbedtls_rsa_init(&rsa);
- if( argc != 2 )
- {
- mbedtls_printf( "usage: rsa_verify <filename>\n" );
+ if (argc != 2) {
+ mbedtls_printf("usage: rsa_verify <filename>\n");
#if defined(_WIN32)
- mbedtls_printf( "\n" );
+ mbedtls_printf("\n");
#endif
goto exit;
}
- mbedtls_printf( "\n . Reading public key from rsa_pub.txt" );
- fflush( stdout );
+ mbedtls_printf("\n . Reading public key from rsa_pub.txt");
+ fflush(stdout);
- if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL )
- {
- mbedtls_printf( " failed\n ! Could not open rsa_pub.txt\n" \
- " ! Please run rsa_genkey first\n\n" );
+ if ((f = fopen("rsa_pub.txt", "rb")) == NULL) {
+ mbedtls_printf(" failed\n ! Could not open rsa_pub.txt\n" \
+ " ! Please run rsa_genkey first\n\n");
goto exit;
}
- if( ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(N), 16, f ) ) != 0 ||
- ( ret = mbedtls_mpi_read_file( &rsa.MBEDTLS_PRIVATE(E), 16, f ) ) != 0 )
- {
- mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret );
- fclose( f );
+ if ((ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(N), 16, f)) != 0 ||
+ (ret = mbedtls_mpi_read_file(&rsa.MBEDTLS_PRIVATE(E), 16, f)) != 0) {
+ mbedtls_printf(" failed\n ! mbedtls_mpi_read_file returned %d\n\n", ret);
+ fclose(f);
goto exit;
}
- rsa.MBEDTLS_PRIVATE(len) = ( mbedtls_mpi_bitlen( &rsa.MBEDTLS_PRIVATE(N) ) + 7 ) >> 3;
+ rsa.MBEDTLS_PRIVATE(len) = (mbedtls_mpi_bitlen(&rsa.MBEDTLS_PRIVATE(N)) + 7) >> 3;
- fclose( f );
+ fclose(f);
/*
* Extract the RSA signature from the text file
*/
- mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[1] );
+ mbedtls_snprintf(filename, sizeof(filename), "%s.sig", argv[1]);
- if( ( f = fopen( filename, "rb" ) ) == NULL )
- {
- mbedtls_printf( "\n ! Could not open %s\n\n", filename );
+ if ((f = fopen(filename, "rb")) == NULL) {
+ mbedtls_printf("\n ! Could not open %s\n\n", filename);
goto exit;
}
i = 0;
- while( fscanf( f, "%02X", (unsigned int*) &c ) > 0 &&
- i < (int) sizeof( buf ) )
+ while (fscanf(f, "%02X", (unsigned int *) &c) > 0 &&
+ i < (int) sizeof(buf)) {
buf[i++] = (unsigned char) c;
+ }
- fclose( f );
+ fclose(f);
- if( i != rsa.MBEDTLS_PRIVATE(len) )
- {
- mbedtls_printf( "\n ! Invalid RSA signature format\n\n" );
+ if (i != rsa.MBEDTLS_PRIVATE(len)) {
+ mbedtls_printf("\n ! Invalid RSA signature format\n\n");
goto exit;
}
@@ -115,33 +111,32 @@
* Compute the SHA-256 hash of the input file and
* verify the signature
*/
- mbedtls_printf( "\n . Verifying the RSA/SHA-256 signature" );
- fflush( stdout );
+ mbedtls_printf("\n . Verifying the RSA/SHA-256 signature");
+ fflush(stdout);
- if( ( ret = mbedtls_md_file(
- mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ),
- argv[1], hash ) ) != 0 )
- {
- mbedtls_printf( " failed\n ! Could not open or read %s\n\n", argv[1] );
+ if ((ret = mbedtls_md_file(
+ mbedtls_md_info_from_type(MBEDTLS_MD_SHA256),
+ argv[1], hash)) != 0) {
+ mbedtls_printf(" failed\n ! Could not open or read %s\n\n", argv[1]);
goto exit;
}
- if( ( ret = mbedtls_rsa_pkcs1_verify( &rsa, MBEDTLS_MD_SHA256,
- 32, hash, buf ) ) != 0 )
- {
- mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_verify returned -0x%0x\n\n", (unsigned int) -ret );
+ if ((ret = mbedtls_rsa_pkcs1_verify(&rsa, MBEDTLS_MD_SHA256,
+ 32, hash, buf)) != 0) {
+ mbedtls_printf(" failed\n ! mbedtls_rsa_pkcs1_verify returned -0x%0x\n\n",
+ (unsigned int) -ret);
goto exit;
}
- mbedtls_printf( "\n . OK (the signature is valid)\n\n" );
+ mbedtls_printf("\n . OK (the signature is valid)\n\n");
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
- mbedtls_rsa_free( &rsa );
+ mbedtls_rsa_free(&rsa);
- mbedtls_exit( exit_code );
+ mbedtls_exit(exit_code);
}
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C &&
MBEDTLS_FS_IO */