Skip to content

Commit 2d7e5fe

Browse files
authored
Merge pull request #46 from Patater/fix-windows-initializers
psa: Test fresh contexts have default behavior
2 parents 1fb011f + 5229bbb commit 2d7e5fe

File tree

1 file changed

+34
-45
lines changed

1 file changed

+34
-45
lines changed

tests/suites/test_suite_psa_crypto.function

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,15 +1441,15 @@ void key_policy_init( )
14411441

14421442
memset( &zero, 0, sizeof( zero ) );
14431443

1444-
/* Although not technically guaranteed by the C standard nor the PSA Crypto
1445-
* specification, we test that all valid ways of initializing the object
1446-
* have the same bit pattern. This is a stronger requirement that may not
1447-
* be valid on all platforms or PSA Crypto implementations, but implies the
1448-
* weaker actual requirement is met: that a freshly initialized object, no
1449-
* matter how it was initialized, acts the same as any other valid
1450-
* initialization. */
1451-
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
1452-
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
1444+
/* A default key policy should not permit any usage. */
1445+
TEST_EQUAL( psa_key_policy_get_usage( &func ), 0 );
1446+
TEST_EQUAL( psa_key_policy_get_usage( &init ), 0 );
1447+
TEST_EQUAL( psa_key_policy_get_usage( &zero ), 0 );
1448+
1449+
/* A default key policy should not permit any algorithm. */
1450+
TEST_EQUAL( psa_key_policy_get_algorithm( &func ), 0 );
1451+
TEST_EQUAL( psa_key_policy_get_algorithm( &init ), 0 );
1452+
TEST_EQUAL( psa_key_policy_get_algorithm( &zero ), 0 );
14531453
}
14541454
/* END_CASE */
14551455

@@ -1960,15 +1960,10 @@ void hash_operation_init( )
19601960

19611961
memset( &zero, 0, sizeof( zero ) );
19621962

1963-
/* Although not technically guaranteed by the C standard nor the PSA Crypto
1964-
* specification, we test that all valid ways of initializing the object
1965-
* have the same bit pattern. This is a stronger requirement that may not
1966-
* be valid on all platforms or PSA Crypto implementations, but implies the
1967-
* weaker actual requirement is met: that a freshly initialized object, no
1968-
* matter how it was initialized, acts the same as any other valid
1969-
* initialization. */
1970-
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
1971-
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
1963+
/* A default hash operation should be abortable without error. */
1964+
PSA_ASSERT( psa_hash_abort( &func ) );
1965+
PSA_ASSERT( psa_hash_abort( &init ) );
1966+
PSA_ASSERT( psa_hash_abort( &zero ) );
19721967
}
19731968
/* END_CASE */
19741969

@@ -2183,15 +2178,10 @@ void mac_operation_init( )
21832178

21842179
memset( &zero, 0, sizeof( zero ) );
21852180

2186-
/* Although not technically guaranteed by the C standard nor the PSA Crypto
2187-
* specification, we test that all valid ways of initializing the object
2188-
* have the same bit pattern. This is a stronger requirement that may not
2189-
* be valid on all platforms or PSA Crypto implementations, but implies the
2190-
* weaker actual requirement is met: that a freshly initialized object, no
2191-
* matter how it was initialized, acts the same as any other valid
2192-
* initialization. */
2193-
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
2194-
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
2181+
/* A default MAC operation should be abortable without error. */
2182+
PSA_ASSERT( psa_mac_abort( &func ) );
2183+
PSA_ASSERT( psa_mac_abort( &init ) );
2184+
PSA_ASSERT( psa_mac_abort( &zero ) );
21952185
}
21962186
/* END_CASE */
21972187

@@ -2338,15 +2328,10 @@ void cipher_operation_init( )
23382328

23392329
memset( &zero, 0, sizeof( zero ) );
23402330

2341-
/* Although not technically guaranteed by the C standard nor the PSA Crypto
2342-
* specification, we test that all valid ways of initializing the object
2343-
* have the same bit pattern. This is a stronger requirement that may not
2344-
* be valid on all platforms or PSA Crypto implementations, but implies the
2345-
* weaker actual requirement is met: that a freshly initialized object, no
2346-
* matter how it was initialized, acts the same as any other valid
2347-
* initialization. */
2348-
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
2349-
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
2331+
/* A default cipher operation should be abortable without error. */
2332+
PSA_ASSERT( psa_cipher_abort( &func ) );
2333+
PSA_ASSERT( psa_cipher_abort( &init ) );
2334+
PSA_ASSERT( psa_cipher_abort( &zero ) );
23502335
}
23512336
/* END_CASE */
23522337

@@ -3527,21 +3512,25 @@ void crypto_generator_init( )
35273512
* Clang 5 complains when `-Wmissing-field-initializers` is used, even
35283513
* though it's OK by the C standard. We could test for this, but we'd need
35293514
* to supress the Clang warning for the test. */
3515+
size_t capacity;
35303516
psa_crypto_generator_t func = psa_crypto_generator_init( );
35313517
psa_crypto_generator_t init = PSA_CRYPTO_GENERATOR_INIT;
35323518
psa_crypto_generator_t zero;
35333519

35343520
memset( &zero, 0, sizeof( zero ) );
35353521

3536-
/* Although not technically guaranteed by the C standard nor the PSA Crypto
3537-
* specification, we test that all valid ways of initializing the object
3538-
* have the same bit pattern. This is a stronger requirement that may not
3539-
* be valid on all platforms or PSA Crypto implementations, but implies the
3540-
* weaker actual requirement is met: that a freshly initialized object, no
3541-
* matter how it was initialized, acts the same as any other valid
3542-
* initialization. */
3543-
TEST_EQUAL( memcmp( &func, &zero, sizeof( zero ) ), 0 );
3544-
TEST_EQUAL( memcmp( &init, &zero, sizeof( zero ) ), 0 );
3522+
/* A default generator should have no capacity. */
3523+
PSA_ASSERT( psa_get_generator_capacity( &func, &capacity ) );
3524+
TEST_EQUAL( capacity, 0 );
3525+
PSA_ASSERT( psa_get_generator_capacity( &init, &capacity ) );
3526+
TEST_EQUAL( capacity, 0 );
3527+
PSA_ASSERT( psa_get_generator_capacity( &zero, &capacity ) );
3528+
TEST_EQUAL( capacity, 0 );
3529+
3530+
/* A default generator should be abortable without error. */
3531+
PSA_ASSERT( psa_generator_abort(&func) );
3532+
PSA_ASSERT( psa_generator_abort(&init) );
3533+
PSA_ASSERT( psa_generator_abort(&zero) );
35453534
}
35463535
/* END_CASE */
35473536

0 commit comments

Comments
 (0)