11//! Hashing with the [keccak] (SHA-3) hash function.
22//!
33//! [keccak]: https://keccak.team/keccak.html
4- #![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
54#![ no_std]
5+ #![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
66
7- #[ cfg( all( feature = "sha3" , not( target_os = "solana" ) ) ) ]
7+ #[ cfg( all( feature = "sha3" , not( any ( target_os = "solana" , target_arch = "bpf" ) ) ) ) ]
88use sha3:: { Digest , Keccak256 } ;
99pub use solana_hash:: { Hash , ParseHashError , HASH_BYTES , MAX_BASE58_LEN } ;
1010
1111#[ derive( Clone , Default ) ]
12- #[ cfg( all( feature = "sha3" , not( target_os = "solana" ) ) ) ]
12+ #[ cfg( all( feature = "sha3" , not( any ( target_os = "solana" , target_arch = "bpf" ) ) ) ) ]
1313pub struct Hasher {
1414 hasher : Keccak256 ,
1515}
1616
17- #[ cfg( all( feature = "sha3" , not( target_os = "solana" ) ) ) ]
17+ #[ cfg( all( feature = "sha3" , not( any ( target_os = "solana" , target_arch = "bpf" ) ) ) ) ]
1818impl Hasher {
1919 pub fn hash ( & mut self , val : & [ u8 ] ) {
2020 self . hasher . update ( val) ;
@@ -30,11 +30,11 @@ impl Hasher {
3030}
3131
3232/// Return a Keccak256 hash for the given data.
33- #[ cfg_attr( target_os = "solana" , inline( always) ) ]
33+ #[ cfg_attr( any ( target_os = "solana" , target_arch = "bpf" ) , inline( always) ) ]
3434pub fn hashv ( vals : & [ & [ u8 ] ] ) -> Hash {
3535 // Perform the calculation inline, calling this from within a program is
3636 // not supported
37- #[ cfg( not( target_os = "solana" ) ) ]
37+ #[ cfg( not( any ( target_os = "solana" , target_arch = "bpf" ) ) ) ]
3838 {
3939 #[ cfg( feature = "sha3" ) ]
4040 {
@@ -49,7 +49,7 @@ pub fn hashv(vals: &[&[u8]]) -> Hash {
4949 }
5050 }
5151 // Call via a system call to perform the calculation
52- #[ cfg( target_os = "solana" ) ]
52+ #[ cfg( any ( target_os = "solana" , target_arch = "bpf" ) ) ]
5353 {
5454 let mut hash_result = core:: mem:: MaybeUninit :: < [ u8 ; solana_hash:: HASH_BYTES ] > :: uninit ( ) ;
5555 // SAFETY: This is sound as sol_keccak256 always fills all 32 bytes of our hash
@@ -65,7 +65,7 @@ pub fn hashv(vals: &[&[u8]]) -> Hash {
6565}
6666
6767/// Return a Keccak256 hash for the given data.
68- #[ cfg_attr( target_os = "solana" , inline( always) ) ]
68+ #[ cfg_attr( any ( target_os = "solana" , target_arch = "bpf" ) , inline( always) ) ]
6969pub fn hash ( val : & [ u8 ] ) -> Hash {
7070 hashv ( & [ val] )
7171}
0 commit comments