mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-09 10:14:11 +00:00
Bring code-style up-to-date
This PR was originally created before the code style was changed. This commit updates the style. Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
This commit is contained in:
parent
f8b9ebf297
commit
209c9c9492
@ -33,26 +33,26 @@
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
#define TEST_SHA256_HASH { \
|
||||
0x5a, 0x09, 0xe8, 0xfa, 0x9c, 0x77, 0x80, 0x7b, 0x24, 0xe9, 0x9c, 0x9c, \
|
||||
0xf9, 0x99, 0xde, 0xbf, 0xad, 0x84, 0x41, 0xe2, 0x69, 0xeb, 0x96, 0x0e, \
|
||||
0x20, 0x1f, 0x61, 0xfc, 0x3d, 0xe2, 0x0d, 0x5a \
|
||||
0x5a, 0x09, 0xe8, 0xfa, 0x9c, 0x77, 0x80, 0x7b, 0x24, 0xe9, 0x9c, 0x9c, \
|
||||
0xf9, 0x99, 0xde, 0xbf, 0xad, 0x84, 0x41, 0xe2, 0x69, 0xeb, 0x96, 0x0e, \
|
||||
0x20, 0x1f, 0x61, 0xfc, 0x3d, 0xe2, 0x0d, 0x5a \
|
||||
}
|
||||
|
||||
const uint8_t mbedtls_test_sha256_hash[] = TEST_SHA256_HASH;
|
||||
|
||||
const size_t mbedtls_test_sha256_hash_len =
|
||||
sizeof( mbedtls_test_sha256_hash );
|
||||
sizeof(mbedtls_test_sha256_hash);
|
||||
|
||||
#if !defined(MBEDTLS_PSA_CRYPTO_C) || !defined(MBEDTLS_SHA256_C)
|
||||
int main( void )
|
||||
int main(void)
|
||||
{
|
||||
printf( "MBEDTLS_PSA_CRYPTO_C and MBEDTLS_SHA256_C"
|
||||
"not defined.\r\n" );
|
||||
return( EXIT_SUCCESS );
|
||||
printf("MBEDTLS_PSA_CRYPTO_C and MBEDTLS_SHA256_C"
|
||||
"not defined.\r\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#else
|
||||
|
||||
int main( void )
|
||||
int main(void)
|
||||
{
|
||||
uint8_t buf[] = "Hello World!";
|
||||
psa_status_t status;
|
||||
@ -61,92 +61,84 @@ int main( void )
|
||||
psa_hash_operation_t sha256_psa = PSA_HASH_OPERATION_INIT;
|
||||
psa_hash_operation_t cloned_sha256 = PSA_HASH_OPERATION_INIT;
|
||||
|
||||
printf( "PSA Crypto API: SHA-256 example\n\n" );
|
||||
printf("PSA Crypto API: SHA-256 example\n\n");
|
||||
|
||||
status = psa_crypto_init( );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_crypto_init failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_crypto_init failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* Compute hash using multi-part operation */
|
||||
|
||||
status = psa_hash_setup( &sha256_psa, PSA_ALG_SHA_256 );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_hash_setup failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_hash_setup(&sha256_psa, PSA_ALG_SHA_256);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_hash_setup failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status = psa_hash_update( &sha256_psa, buf, sizeof( buf ) );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_hash_update failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_hash_update(&sha256_psa, buf, sizeof(buf));
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_hash_update failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status = psa_hash_clone( &sha256_psa, &cloned_sha256 );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "PSA hash clone failed" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_hash_clone(&sha256_psa, &cloned_sha256);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("PSA hash clone failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status = psa_hash_finish( &sha256_psa, hash, sizeof( hash ), &hash_size );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_hash_finish failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_hash_finish(&sha256_psa, hash, sizeof(hash), &hash_size);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_hash_finish failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
status = psa_hash_verify( &cloned_sha256, mbedtls_test_sha256_hash, mbedtls_test_sha256_hash_len );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_hash_verify failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
} else
|
||||
{
|
||||
printf( "Multi-part hash operation successful!\n");
|
||||
status =
|
||||
psa_hash_verify(&cloned_sha256, mbedtls_test_sha256_hash, mbedtls_test_sha256_hash_len);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_hash_verify failed\n");
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
printf("Multi-part hash operation successful!\n");
|
||||
}
|
||||
|
||||
/* Compute hash using one-shot function call */
|
||||
memset( hash,0,sizeof( hash ) );
|
||||
memset(hash, 0, sizeof(hash));
|
||||
hash_size = 0;
|
||||
|
||||
status = psa_hash_compute( PSA_ALG_SHA_256,
|
||||
buf, sizeof( buf ),
|
||||
hash, sizeof( hash ),
|
||||
&hash_size );
|
||||
if( status != PSA_SUCCESS )
|
||||
{
|
||||
printf( "psa_hash_compute failed\n" );
|
||||
return( EXIT_FAILURE );
|
||||
status = psa_hash_compute(PSA_ALG_SHA_256,
|
||||
buf, sizeof(buf),
|
||||
hash, sizeof(hash),
|
||||
&hash_size);
|
||||
if (status != PSA_SUCCESS) {
|
||||
printf("psa_hash_compute failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for( size_t j = 0; j < mbedtls_test_sha256_hash_len; j++ )
|
||||
{
|
||||
if( hash[j] != mbedtls_test_sha256_hash[j] )
|
||||
{
|
||||
printf( "One-shot hash operation failed!\n\n");
|
||||
return( EXIT_FAILURE );
|
||||
for (size_t j = 0; j < mbedtls_test_sha256_hash_len; j++) {
|
||||
if (hash[j] != mbedtls_test_sha256_hash[j]) {
|
||||
printf("One-shot hash operation failed!\n\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
printf( "One-shot hash operation successful!\n\n");
|
||||
printf("One-shot hash operation successful!\n\n");
|
||||
|
||||
printf( "The SHA-256( '%s' ) is:\n", buf );
|
||||
printf("The SHA-256( '%s' ) is:\n", buf);
|
||||
|
||||
for( size_t j = 0; j < mbedtls_test_sha256_hash_len; j++ )
|
||||
{
|
||||
if( j % 8 == 0 ) printf( "\n " );
|
||||
printf( "%02x ", hash[j] );
|
||||
for (size_t j = 0; j < mbedtls_test_sha256_hash_len; j++) {
|
||||
if (j % 8 == 0) {
|
||||
printf("\n ");
|
||||
}
|
||||
printf("%02x ", hash[j]);
|
||||
}
|
||||
|
||||
printf( "\n" );
|
||||
printf("\n");
|
||||
|
||||
mbedtls_psa_crypto_free( );
|
||||
return( EXIT_SUCCESS );
|
||||
mbedtls_psa_crypto_free();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C && MBEDTLS_SHA256_C */
|
||||
|
Loading…
x
Reference in New Issue
Block a user