A computer-implemented method of protecting execution of a cryptographic hash function in a computing environment where inputs, outputs and intermediate values can be observed, the method comprising: encoding an input message to provide an encoded input message having an original message length λ in bytes; padding the encoded input message with one or more padding bytes to provide a padded message, wherein the one or more padding bytes include one or more un-encoded padding bytes whereby the encoded input message is padded to a padded message length λ' bytes, wherein: a) if λ mod ω is equal to 0, one 0x80 un-encoded padding byte and, if necessary, subsequent 0x00 un-encoded padding bytes are added until λ' mod B equals B-L, b) if λ mod ω is not equal to 0 a first 0x80 encoded padding byte is added and, if necessary, subsequent 0x00 encoded padding bytes are added until λ' mod ω equals zero and then if λ' mod B is not equal to B-L 0x00 un-encoded padding bytes are added until λ' mod B is equal to B-L; wherein B is the block length of the cryptographic hash function in bytes, ω is the size in bytes of a word of the cryptographic hash function and L is the size in bytes of an integer indicating the message length λ; adding the integer indicating the original message length λ to the padded message to thereby result in a total message length that corresponds to the cryptographic hash function; and applying a transformed cryptographic hash function to the padded message to provide an output digest, wherein the transformed cryptographic hash function comprises a modified version of the cryptographic hash function such that a digest generated by applying the transformed cryptographic hash function to an encoded message is equivalent to a digest that would be generated by applying the cryptographic hash function to an un-encoded message. encoding an input message to provide an encoded input message having an original message length λ in bytes; padding the encoded input message with one or more padding bytes to provide a padded message, wherein the one or more padding bytes include one or more un-encoded padding bytes whereby the encoded input message is padded to a padded message length λ' bytes, wherein: a) if λ mod ω is equal to 0, one 0x80 un-encoded padding byte and, if necessary, subsequent 0x00 un-encoded padding bytes are added until λ' mod B equals B-L, b) if λ mod ω is not equal to 0 a first 0x80 encoded padding byte is added and, if necessary, subsequent 0x00 encoded padding bytes are added until λ' mod ω equals zero and then if λ' mod B is not equal to B-L 0x00 un-encoded padding bytes are added until λ' mod B is equal to B-L; a) if λ mod ω is equal to 0, one 0x80 un-encoded padding byte and, if necessary, subsequent 0x00 un-encoded padding bytes are added until λ' mod B equals B-L, b) if λ mod ω is not equal to 0 a first 0x80 encoded padding byte is added and, if necessary, subsequent 0x00 encoded padding bytes are added until λ' mod ω equals zero and then if λ' mod B is not equal to B-L 0x00 un-encoded padding bytes are added until λ' mod B is equal to B-L; wherein B is the block length of the cryptographic hash function in bytes, ω is the size in bytes of a word of the cryptographic hash function and L is the size in bytes of an integer indicating the message length λ; adding the integer indicating the original message length λ to the padded message to thereby result in a total message length that corresponds to the cryptographic hash function; and applying a transformed cryptographic hash function to the padded message to provide an output digest, wherein the transformed cryptographic hash function comprises a modified version of the cryptographic hash function such that a digest generated by applying the transformed cryptographic hash function to an encoded message is equivalent to a digest that would be generated by applying the cryptographic hash function to an un-encoded message.