@@ -732,9 +732,9 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
732
732
}
733
733
PSA_ASSERT (status );
734
734
735
- status = psa_raw_key_agreement (alg , key ,
736
- public_key , public_key_length ,
737
- output , sizeof (output ), & output_length );
735
+ status = psa_raw_key_agreement (
736
+ alg , key , public_key , public_key_length ,
737
+ output , sizeof (output ), & output_length );
738
738
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE ) {
739
739
/* The key has been destroyed. */
740
740
status = PSA_SUCCESS ;
@@ -749,8 +749,11 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
749
749
}
750
750
751
751
#if MBEDTLS_VERSION_MAJOR >= 4
752
+ psa_status_t raw_status = status ;
753
+
752
754
psa_set_key_type (& shared_secret_attributes , PSA_KEY_TYPE_DERIVE );
753
- psa_set_key_usage_flags (& shared_secret_attributes , PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT );
755
+ psa_set_key_usage_flags (& shared_secret_attributes ,
756
+ PSA_KEY_USAGE_DERIVE | PSA_KEY_USAGE_EXPORT );
754
757
755
758
status = psa_key_agreement (key , public_key , public_key_length , alg ,
756
759
& shared_secret_attributes , & shared_secret_id );
@@ -759,27 +762,37 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
759
762
/* The key has been destroyed. */
760
763
status = PSA_SUCCESS ;
761
764
goto exit ;
762
- } else if (status == PSA_SUCCESS ) {
765
+ }
766
+
767
+ /* In this function, we expect either success or a validation failure,
768
+ * which should be identical for raw output and key output. So flag any
769
+ * discrepancy between the two (in particular a key creation failure)
770
+ * as a test failure. */
771
+ TEST_EQUAL (raw_status , status );
763
772
773
+ if (status == PSA_SUCCESS ) {
764
774
status = psa_get_key_attributes (shared_secret_id , & export_attributes );
765
775
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE ) {
766
776
/* The key
8000
has been destroyed. */
767
777
status = PSA_SUCCESS ;
768
778
goto exit ;
769
779
}
770
780
771
- exported_size = PSA_EXPORT_KEY_OUTPUT_SIZE (psa_get_key_type (& export_attributes ),
772
- psa_get_key_bits (& export_attributes ));
781
+ exported_size =
782
+ PSA_EXPORT_KEY_OUTPUT_SIZE (psa_get_key_type (& export_attributes ),
783
+ psa_get_key_bits (& export_attributes ));
773
784
TEST_CALLOC (exported , exported_size );
774
785
775
- status = psa_export_key (shared_secret_id , exported , exported_size , & exported_length );
776
-
786
+ status = psa_export_key (shared_secret_id ,
787
+ exported , exported_size , & exported_length );
777
788
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE ) {
778
789
/* The key has been destroyed. */
779
790
status = PSA_SUCCESS ;
791
+ } else {
792
+ PSA_ASSERT (status );
793
+ TEST_MEMORY_COMPARE (exported , exported_length ,
794
+ output , output_length );
780
795
}
781
-
782
- PSA_ASSERT (status );
783
796
}
784
797
785
798
#if defined(MBEDTLS_ECP_RESTARTABLE ) && defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH )
@@ -798,18 +811,39 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
798
811
/* The key has been destroyed. */
799
812
status = PSA_SUCCESS ;
800
813
goto exit ;
801
- } else if (status == PSA_SUCCESS ) {
814
+ }
815
+
816
+ /* In this function, we expect either success or a validation failure,
817
+ * which should be identical for one-shot and interruptible. For an
818
+ * interruptible operation, we insist on detecting error conditions
819
+ * early, in setup() rather than complete(). So flag any discrepancy
820
+ * between one-shot and interruptible-setup as a test failure. */
821
+ TEST_EQUAL (raw_status , status );
822
+
823
+ if (status == PSA_SUCCESS ) {
802
824
803
825
do {
804
- status = psa_key_agreement_iop_complete (& iop_operation , & shared_secret_id );
826
+ status = psa_key_agreement_iop_complete (& iop_operation ,
827
+ & shared_secret_id );
805
828
} while (status == PSA_OPERATION_INCOMPLETE );
806
829
807
830
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE ) {
808
831
/* The key has been destroyed. */
809
832
status = PSA_SUCCESS ;
833
+ } else {
834
+ PSA_ASSERT (status );
835
+ status = psa_export_key (shared_secret_id ,
836
+ exported , exported_size ,
837
+ & exported_length );
838
+ if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE ) {
839
+ /* The key has been destroyed. */
840
+ status = PSA_SUCCESS ;
841
+ } else {
842
+ PSA_ASSERT (status );
843
+ TEST_MEMORY_COMPARE (exported , exported_length ,
844
+ output , output_length );
845
+ }
810
846
}
811
-
812
- PSA_ASSERT (status );
813
847
}
814
848
} else {
815
849
TEST_EQUAL (psa_key_agreement_iop_setup (& iop_operation , key , public_key ,
0 commit comments