Skip to content

Commit d80e437

Browse files
real-or-randomsipa
authored andcommitted
bip340: Add subsection on Domain Separation
1 parent 200f9b2 commit d80e437

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bip-0340.mediawiki

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,26 @@ In particular, the signing algorithm needs two sequential hashing passes over th
237237
which means that the full message must necessarily be kept in memory during signing,
238238
and large messages entail a runtime penalty.<ref>Typically, messages of 56 bytes or longer enjoy a performance benefit from pre-hashing, assuming the speed of SHA256 inside the signing algorithm matches that of the pre-hashing done by the calling application.</ref>
239239

240+
==== Domain Separation ====
241+
242+
It is good cryptographic practice to use a key pair only for a single purpose.
243+
Nevertheless, there may be situations in which it may be desirable to use the same key pair in multiple contexts,
244+
i.e., to sign different types of messages within the same application
245+
or even messages in entirely different applications
246+
(e.g., a secret key may be used to sign Bitcoin transactions as well plain text messages).
247+
248+
As a consequence, applications should ensure that a signed application message intended for one context is never deemed valid in a different context
249+
(e.g., a signed plain text message should never be misinterpreted as a signed Bitcoin transaction, because this could cause unintended loss of funds).
250+
This is called "domain separation" and it is typically realized by partitioning the message space.
251+
Even if key pairs are intended to be used only within a single context,
252+
domain separation is a good idea because it makes it easy to add more contexts later.
253+
254+
As a best practice, we recommend applications to use exactly one of the following methods to pre-process application messages before passing it to the signature scheme:
255+
* Either, pre-hash the application message using ''hash<sub>name</sub>'', where ''name'' identifies the context uniquely (e.g., "foo-app/signed-bar"),
256+
* or prefix the actual message with a 33-byte string that identifies the context uniquely (e.g., the UTF-8 encoding of "foo-app/signed-bar", padded with null bytes to 33 bytes).
257+
258+
As the two pre-processing methods yield different message sizes (32 bytes vs. at least 33 bytes), there is no risk of collision between them.
259+
240260
== Applications ==
241261

242262
There are several interesting applications beyond simple signatures.

0 commit comments

Comments
 (0)