@@ -13,7 +13,7 @@ use parsec_interface::operations::ping::Operation as Ping;
1313use parsec_interface:: operations:: psa_aead_decrypt:: Operation as PsaAeadDecrypt ;
1414use parsec_interface:: operations:: psa_aead_encrypt:: Operation as PsaAeadEncrypt ;
1515use parsec_interface:: operations:: psa_algorithm:: {
16- Aead , AsymmetricEncryption , AsymmetricSignature ,
16+ Aead , AsymmetricEncryption , AsymmetricSignature , Hash
1717} ;
1818use parsec_interface:: operations:: psa_asymmetric_decrypt:: Operation as PsaAsymDecrypt ;
1919use parsec_interface:: operations:: psa_asymmetric_encrypt:: Operation as PsaAsymEncrypt ;
@@ -22,6 +22,8 @@ use parsec_interface::operations::psa_export_key::Operation as PsaExportKey;
2222use parsec_interface:: operations:: psa_export_public_key:: Operation as PsaExportPublicKey ;
2323use parsec_interface:: operations:: psa_generate_key:: Operation as PsaGenerateKey ;
2424use parsec_interface:: operations:: psa_generate_random:: Operation as PsaGenerateRandom ;
25+ use parsec_interface:: operations:: psa_hash_compare:: Operation as PsaHashCompare ;
26+ use parsec_interface:: operations:: psa_hash_compute:: Operation as PsaHashCompute ;
2527use parsec_interface:: operations:: psa_import_key:: Operation as PsaImportKey ;
2628use parsec_interface:: operations:: psa_key_attributes:: Attributes ;
2729use parsec_interface:: operations:: psa_sign_hash:: Operation as PsaSignHash ;
@@ -696,6 +698,70 @@ impl BasicClient {
696698 Err ( Error :: Client ( ClientErrorKind :: InvalidServiceResponseType ) )
697699 }
698700 }
701+ /// **[Cryptographic Operation]** Compute hash of a message.
702+ ///
703+ /// The hash computation will be performed with the algorithm defined in `alg`.
704+ ///
705+ /// # Errors
706+ ///
707+ /// If the implicit client provider is `ProviderID::Core`, a client error
708+ /// of `InvalidProvider` type is returned.
709+ ///
710+ /// If the implicit client provider has not been set, a client error of
711+ /// `NoProvider` type is returned.
712+ ///
713+ /// See the operation-specific response codes returned by the service
714+ /// [here](https://parallaxsecond.github.io/parsec-book/parsec_client/operations/psa_hash_compute.html#specific-response-status-codes).
715+ pub fn psa_hash_compute ( & self , alg : Hash , input : & [ u8 ] ) -> Result < Vec < u8 > > {
716+ let crypto_provider = self . can_provide_crypto ( ) ?;
717+ let op = PsaHashCompute {
718+ alg,
719+ input : input. to_vec ( ) . into ( ) ,
720+ } ;
721+ let hash_compute_res = self . op_client . process_operation (
722+ NativeOperation :: PsaHashCompute ( op) ,
723+ crypto_provider,
724+ & self . auth_data ,
725+ ) ?;
726+ if let NativeResult :: PsaHashCompute ( res) = hash_compute_res {
727+ Ok ( res. hash . to_vec ( ) )
728+ } else {
729+ // Should really not be reached given the checks we do, but it's not impossible if some
730+ // changes happen in the interface
731+ Err ( Error :: Client ( ClientErrorKind :: InvalidServiceResponseType ) )
732+ }
733+ }
734+
735+ /// **[Cryptographic Operation]** Compute hash of a message and compare it with a reference value.
736+ ///
737+ /// The hash computation will be performed with the algorithm defined in `alg`.
738+ ///
739+ /// If this operation returns no error, the hash was computed successfully and it matches the reference value.
740+ ///
741+ /// # Errors
742+ ///
743+ /// If the implicit client provider is `ProviderID::Core`, a client error
744+ /// of `InvalidProvider` type is returned.
745+ ///
746+ /// If the implicit client provider has not been set, a client error of
747+ /// `NoProvider` type is returned.
748+ ///
749+ /// See the operation-specific response codes returned by the service
750+ /// [here](https://parallaxsecond.github.io/parsec-book/parsec_client/operations/psa_hash_compare.html#specific-response-status-codes).
751+ pub fn psa_hash_compare ( & self , alg : Hash , input : & [ u8 ] , hash : & [ u8 ] ) -> Result < ( ) > {
752+ let crypto_provider = self . can_provide_crypto ( ) ?;
753+ let op = PsaHashCompare {
754+ alg,
755+ input : input. to_vec ( ) . into ( ) ,
756+ hash : hash. to_vec ( ) . into ( ) ,
757+ } ;
758+ let _ = self . op_client . process_operation (
759+ NativeOperation :: PsaHashCompare ( op) ,
760+ crypto_provider,
761+ & self . auth_data ,
762+ ) ?;
763+ Ok ( ( ) )
764+ }
699765
700766 /// **[Cryptographic Operation]** Authenticate and encrypt a short message.
701767 ///
0 commit comments