Merge pull request #46 from Patater/fix-windows-initializers

psa: Test fresh contexts have default behavior
This commit is contained in:
Jaeden Amero 2019-02-12 16:34:10 +00:00 committed by GitHub
commit 2d7e5fe31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1441,15 +1441,15 @@ void key_policy_init( )
memset( &zero, 0, sizeof( zero ) ); memset( &zero, 0, sizeof( zero ) );
/* Although not technically guaranteed by the C standard nor the PSA Crypto /* A default key policy should not permit any usage. */
* specification, we test that all valid ways of initializing the object TEST_EQUAL( psa_key_policy_get_usage( &func ), 0 );
* have the same bit pattern. This is a stronger requirement that may not TEST_EQUAL( psa_key_policy_get_usage( &init ), 0 );
* be valid on all platforms or PSA Crypto implementations, but implies the TEST_EQUAL( psa_key_policy_get_usage( &zero ), 0 );
* weaker actual requirement is met: that a freshly initialized object, no
* matter how it was initialized, acts the same as any other valid /* A default key policy should not permit any algorithm. */
* initialization. */ TEST_EQUAL( psa_key_policy_get_algorithm( &func ), 0 );
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 ); TEST_EQUAL( psa_key_policy_get_algorithm( &init ), 0 );
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 ); TEST_EQUAL( psa_key_policy_get_algorithm( &zero ), 0 );
} }
/* END_CASE */ /* END_CASE */
@ -1960,15 +1960,10 @@ void hash_operation_init( )
memset( &zero, 0, sizeof( zero ) ); memset( &zero, 0, sizeof( zero ) );
/* Although not technically guaranteed by the C standard nor the PSA Crypto /* A default hash operation should be abortable without error. */
* specification, we test that all valid ways of initializing the object PSA_ASSERT( psa_hash_abort( &func ) );
* have the same bit pattern. This is a stronger requirement that may not PSA_ASSERT( psa_hash_abort( &init ) );
* be valid on all platforms or PSA Crypto implementations, but implies the PSA_ASSERT( psa_hash_abort( &zero ) );
* weaker actual requirement is met: that a freshly initialized object, no
* matter how it was initialized, acts the same as any other valid
* initialization. */
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
} }
/* END_CASE */ /* END_CASE */
@ -2183,15 +2178,10 @@ void mac_operation_init( )
memset( &zero, 0, sizeof( zero ) ); memset( &zero, 0, sizeof( zero ) );
/* Although not technically guaranteed by the C standard nor the PSA Crypto /* A default MAC operation should be abortable without error. */
* specification, we test that all valid ways of initializing the object PSA_ASSERT( psa_mac_abort( &func ) );
* have the same bit pattern. This is a stronger requirement that may not PSA_ASSERT( psa_mac_abort( &init ) );
* be valid on all platforms or PSA Crypto implementations, but implies the PSA_ASSERT( psa_mac_abort( &zero ) );
* weaker actual requirement is met: that a freshly initialized object, no
* matter how it was initialized, acts the same as any other valid
* initialization. */
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
} }
/* END_CASE */ /* END_CASE */
@ -2338,15 +2328,10 @@ void cipher_operation_init( )
memset( &zero, 0, sizeof( zero ) ); memset( &zero, 0, sizeof( zero ) );
/* Although not technically guaranteed by the C standard nor the PSA Crypto /* A default cipher operation should be abortable without error. */
* specification, we test that all valid ways of initializing the object PSA_ASSERT( psa_cipher_abort( &func ) );
* have the same bit pattern. This is a stronger requirement that may not PSA_ASSERT( psa_cipher_abort( &init ) );
* be valid on all platforms or PSA Crypto implementations, but implies the PSA_ASSERT( psa_cipher_abort( &zero ) );
* weaker actual requirement is met: that a freshly initialized object, no
* matter how it was initialized, acts the same as any other valid
* initialization. */
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
} }
/* END_CASE */ /* END_CASE */
@ -3527,21 +3512,25 @@ void crypto_generator_init( )
* Clang 5 complains when `-Wmissing-field-initializers` is used, even * Clang 5 complains when `-Wmissing-field-initializers` is used, even
* though it's OK by the C standard. We could test for this, but we'd need * though it's OK by the C standard. We could test for this, but we'd need
* to supress the Clang warning for the test. */ * to supress the Clang warning for the test. */
size_t capacity;
psa_crypto_generator_t func = psa_crypto_generator_init( ); psa_crypto_generator_t func = psa_crypto_generator_init( );
psa_crypto_generator_t init = PSA_CRYPTO_GENERATOR_INIT; psa_crypto_generator_t init = PSA_CRYPTO_GENERATOR_INIT;
psa_crypto_generator_t zero; psa_crypto_generator_t zero;
memset( &zero, 0, sizeof( zero ) ); memset( &zero, 0, sizeof( zero ) );
/* Although not technically guaranteed by the C standard nor the PSA Crypto /* A default generator should have no capacity. */
* specification, we test that all valid ways of initializing the object PSA_ASSERT( psa_get_generator_capacity( &func, &capacity ) );
* have the same bit pattern. This is a stronger requirement that may not TEST_EQUAL( capacity, 0 );
* be valid on all platforms or PSA Crypto implementations, but implies the PSA_ASSERT( psa_get_generator_capacity( &init, &capacity ) );
* weaker actual requirement is met: that a freshly initialized object, no TEST_EQUAL( capacity, 0 );
* matter how it was initialized, acts the same as any other valid PSA_ASSERT( psa_get_generator_capacity( &zero, &capacity ) );
* initialization. */ TEST_EQUAL( capacity, 0 );
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 ); /* A default generator should be abortable without error. */
PSA_ASSERT( psa_generator_abort(&func) );
PSA_ASSERT( psa_generator_abort(&init) );
PSA_ASSERT( psa_generator_abort(&zero) );
} }
/* END_CASE */ /* END_CASE */