A method for generating a signature for a message by a processor of a security token, wherein the method comprises the steps of: - providing () parts (T1-T7) of the message sequentially by the processor; - whilst said parts of the message are being provided sequentially, applying, by the processor, an intermediate value function or a termination function 302 of a hash function to each of the parts of the message directly after said part has been provided so as to calculate a first hash value (#H1) step by step, wherein the first hash value (#H1) is identical to a value that would have been obtained if the hash function had been applied to the entire message; - providing one or more data values (D1-D4) by the processor; - once the first hash value (#H1) has been calculated, generating a concatenated value by the processor by concatenating the one or more data values (D1-D4) and the calculated first hash value (#H1), wherein the message is excluded from the concatenation; - applying, by the processor, the hash function or a further hash function to the concatenated value to calculate a second hash value (#H2); - outputting the second hash value (#H2) by the processor to use the second hash value as the signature of the message or as part of this signature; and also comprises the step of: - freeing main memory of the security token that was occupied by each of the parts of the message, directly following the application of the intermediate value function or the termination function to this part of the message; or - freeing main memory of the security token that was occupied by each of the parts of the message, following the application of the intermediate value function or the termination function to this part of the message and directly after this part of the message has been output via an interface (119.1) of the security token. - providing () parts (T1-T7) of the message sequentially by the processor; - whilst said parts of the message are being provided sequentially, applying, by the processor, an intermediate value function or a termination function 302 of a hash function to each of the parts of the message directly after said part has been provided so as to calculate a first hash value (#H1) step by step, wherein the first hash value (#H1) is identical to a value that would have been obtained if the hash function had been applied to the entire message; - providing one or more data values (D1-D4) by the processor; - once the first hash value (#H1) has been calculated, generating a concatenated value by the processor by concatenating the one or more data values (D1-D4) and the calculated first hash value (#H1), wherein the message is excluded from the concatenation; - applying, by the processor, the hash function or a further hash function to the concatenated value to calculate a second hash value (#H2); - outputting the second hash value (#H2) by the processor to use the second hash value as the signature of the message or as part of this signature; - freeing main memory of the security token that was occupied by each of the parts of the message, directly following the application of the intermediate value function or the termination function to this part of the message; or - freeing main memory of the security token that was occupied by each of the parts of the message, following the application of the intermediate value function or the termination function to this part of the message and directly after this part of the message has been output via an interface (119.1) of the security token.