Repeated Nonces
Repeated Nonces
2020 1280
Copyright ⓒ 2020 KSII
Received September 30, 2019; revised December 4, 2019; accepted January 5, 2020;
published March 31, 2020
Abstract
In the modern financial sector, interest in providing financial services that employ blockchain
technology has increased. Blockchain technology is efficient and can operate without a trusted
party to store all transaction information; additionally, it provides transparency and prevents
the tampering of transaction information. However, new security threats can occur because
blockchain technology shares all the transaction information. Furthermore, studies have
reported that the private keys of users who use the same signature value two or more times can
be recovered. Because private keys of blockchain identify users, private key leaks can result in
attackers stealing the ownership rights to users’ property. Therefore, as more financial services
use blockchain technology, actions to counteract the threat of private key recovery must be
continually investigated. Private key recovery studies are presented here. Based on these
studies, duplicated signatures generated by blockchain users are defined. Additionally,
scenarios that generate and use duplicated signatures are applied in an actual bitcoin
environment to demonstrate that actual bitcoin users’ private keys can be recovered.
1. Introduction
2. Related Work
2.1 Digital Signature
Digital signatures are used to secure electronic transactions as attached values to guarantee
the data source, integrity, and non-repudiation. Fig. 1 shows the operation of a digital
signature. To view the message, the receiver decrypts the signature and then recalculates the
hash value. If the hash value matches, the authenticity of the message and the sender are
proven. The integrity of the message can be confirmed through the hash function, which
produces different results if the text has been changed if even slightly. The sender can be
confirmed because only the correct sender can generate a signature with the correct private key
[7].
2.2 ECDSA
ECDSA is an implementation of the DSA (the National Institute of Standards and
Technology’s signature algorithm) on an elliptic curve. The elliptic curve and domain
parameters for ECC calculations were predefined. In an ECDSA, a mathematically related
private and public key pair are used to generate and verify the digital signature [8]. This
section describes the process of generating and verifying ECDSA signatures.
Select a nonce: k (1 ≤ k ≤ n − 1)
(𝑥𝑥1 , 𝑦𝑦1 ) = 𝑘𝑘𝑘𝑘
r = 𝑥𝑥1 𝑚𝑚𝑚𝑚𝑚𝑚 𝑛𝑛
e = SHA256(message)
s = 𝑘𝑘 −1 (𝑒𝑒 + 𝑑𝑑𝑑𝑑)𝑚𝑚𝑚𝑚𝑚𝑚 𝑛𝑛
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1283
e = 𝑆𝑆𝑆𝑆𝑆𝑆256(𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚)
a = s −1 𝑒𝑒 𝑚𝑚𝑚𝑚𝑚𝑚 𝑛𝑛
b = s −1 𝑟𝑟 𝑚𝑚𝑚𝑚𝑚𝑚 𝑛𝑛
(𝑥𝑥2 , 𝑦𝑦2 ) = 𝑎𝑎𝑎𝑎 + 𝑏𝑏𝑏𝑏
t = 𝑥𝑥2 𝑚𝑚𝑚𝑚𝑚𝑚 𝑛𝑛
Result: if ‘t’ is equal to ‘r’, verification is successful
The hash function receives a message of random length as input and produces a hash value
of a fixed length. The hash function serves to generate unchangeable proof values for the
message to provide integrity such that it message errors or falsifications can be detected. When
long messages are signed, a short hash value is calculated for the entire message, and this value
is signed. For the hash function to be secure, it must be difficult to find collisions [11]. Table 2
shows the strength of the SHA-256 used in bitcoin.
2.4 Bitcoin
Bitcoin is a system designed such that users can trust each other without a trusted third
party, and it was proposed in 2009 by Satoshi Nakamoto [14]. Because all members have the
same ledger, tampering is not possible. When new transactions occur, new blocks are
1284 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
connected to the existing ledger block in the form of a chain [2]. Because bitcoin is an
electronic currency that only moves between transaction parties, it does not require a trusted
party, and P2P networks are used to prevent double payments. Furthermore, the anonymity of
members can be ensured by maintaining the anonymity of the public keys [14]. As of June 9,
2019, bitcoin contains 579,952 blocks in its chain [15]. All of the block data included in
bitcoin can be synchronized with the bitcoin core [16].
The header of a bitcoin block contains a magic number that distinguishes the block, block
size, block version, previous block’s hash, current block’s hash, time of block creation, target
that shows the block creation level of difficulty, and the nonce for proof-of-work. Furthermore,
the number of transactions and the transaction data are included after the header. Table 3
shows the structure of a bitcoin block [17].
Bitcoin transactions comprises the transaction’s version, input, and output. The input
includes the input number, previous transaction’s hash, previous output’s index, scriptSig
length, the scriptSig that contains the signature data, and a 4-byte sequence. The output
includes the output number, the value that is the coin amount in Satoshi units, scriptPubKey
length, scriptPubKey that contains the sender’s public key hash data, and locktime at which
the transaction was created. Table 4 shows the structure of a bitcoin transaction [17].
Shown below are two situations in which an attack can recover a user’s private key as well
as the recovery processes, as reported by Michael Brengel et al. [6]. Private key recovery is
accomplished by modifying the formula for the signature value as in Order 5 of Section 2.2.1.
Step 1. User A uses nonces 𝑘𝑘1 and 𝑘𝑘2 to generate two signatures
𝑠𝑠1,𝐴𝐴 = 𝑘𝑘1 −1 �𝑒𝑒1,𝐴𝐴 + 𝑟𝑟1 𝑑𝑑𝐴𝐴 �𝑚𝑚𝑚𝑚𝑚𝑚 n, 𝑠𝑠2,𝐴𝐴 = 𝑘𝑘2 −1 �𝑒𝑒2,𝐴𝐴 + 𝑟𝑟2 𝑑𝑑𝐴𝐴 �𝑚𝑚𝑚𝑚𝑚𝑚 n
Step 2. User B uses nonces 𝑘𝑘1 and 𝑘𝑘2 to generate two signatures
𝑠𝑠1,𝐵𝐵 = 𝑘𝑘1 −1 �𝑒𝑒1,𝐵𝐵 + 𝑟𝑟1 𝑑𝑑𝐵𝐵 �𝑚𝑚𝑚𝑚𝑚𝑚 n, 𝑠𝑠2,𝐵𝐵 = 𝑘𝑘2 −1 �𝑒𝑒2,𝐵𝐵 + 𝑟𝑟2 𝑑𝑑𝐵𝐵 �𝑚𝑚𝑚𝑚𝑚𝑚 n
Step 3. The four formulas used in Steps 1 and 2 are established for 𝑘𝑘1 and 𝑘𝑘2
𝑘𝑘1 = �𝑒𝑒1,𝐴𝐴 + 𝑟𝑟1 𝑑𝑑𝐴𝐴 �𝑠𝑠1,𝐴𝐴 −1 𝑚𝑚𝑚𝑚𝑚𝑚 n, 𝑘𝑘1 = �𝑒𝑒1,𝐵𝐵 + 𝑟𝑟1 𝑑𝑑𝐵𝐵 �𝑠𝑠1,𝐵𝐵 −1 𝑚𝑚𝑚𝑚𝑚𝑚 n
𝑘𝑘2 = �𝑒𝑒2,𝐴𝐴 + 𝑟𝑟2 𝑑𝑑𝐴𝐴 �𝑠𝑠2,𝐴𝐴 −1 𝑚𝑚𝑚𝑚𝑚𝑚 n, 𝑘𝑘2 = �𝑒𝑒2,𝐵𝐵 + 𝑟𝑟2 𝑑𝑑𝐵𝐵 �𝑠𝑠2,𝐵𝐵 −1 𝑚𝑚𝑚𝑚𝑚𝑚 n
Step 4. The two formulas in Step 3 are established for 𝑑𝑑𝐵𝐵
𝑑𝑑𝐵𝐵 = ��𝑒𝑒1,𝐴𝐴 + 𝑟𝑟1 𝑑𝑑𝐴𝐴 �𝑠𝑠1,𝐴𝐴 −1 𝑠𝑠1,𝐵𝐵 − 𝑒𝑒1,𝐵𝐵 � 𝑟𝑟1 −1 𝑚𝑚𝑚𝑚𝑚𝑚 n
The study reported that the same r values of signatures can occur not only in cases where
the same nonce was reused, but also in cases in which the used nonces have a complementary
relationship with previously used nonces. Owing to the properties of the elliptic curve, when
nonces k and -k (inverse of addition for n) are used in Order 1-2 of Section 2.2.1, kG =
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1287
(𝑥𝑥1 , 𝑦𝑦1 ) and −kG = (𝑥𝑥1 , −𝑦𝑦1 ). This yields the same r value of signature in Order 3 of Section
2.2.1.
In this threat, the private key recovery for when the user uses the same nonces, as
mentioned in Section 2.7.1, is changed into a private key recovery for when the user uses
nonces that complement each other. Fig. 2 shows the private key recovery process when the
duplicate nonce k that was used in Section 2.7.1 is changed to 𝑘𝑘1 , −𝑘𝑘1.
Step 1. User A uses nonces 𝑘𝑘1 and −𝑘𝑘1 to generate two signatures
Step 2. The two transactions’ messages and signatures are collected from the bitcoin block
Step 3. User A’s private key is calculated from the collected data
1288 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
In this threat, the private key recovery for when two users have reused two nonces, as
mentioned in Section 2.7.2, is changed into the private key recovery for when nonces that
complement each other are used. When User A has used nonces 𝑘𝑘1 and 𝑘𝑘2 and User B uses
one pair from among (𝑘𝑘1 , −𝑘𝑘2 ), (−𝑘𝑘1 , 𝑘𝑘2 ), and (−𝑘𝑘1 , −𝑘𝑘2 ), private key recovery is possible.
Fig. 3 shows the private key recovery when User A uses nonces 𝑘𝑘1 and 𝑘𝑘2 and User B uses
(−𝑘𝑘1 , −𝑘𝑘2 ).
Table 6 shows the threats by which anyone can recover a user’s private key through a
bad/inverse RNG.
Fig. 4 shows cases in which a user’s private key can be recovered when the user uses a
duplicated nonce or nonces that complement each other, as in the attack types shown in Table
6. Furthermore, the r value of signature used by the user is a duplicated signature. Figs. 2 and 3
show the recovery of user’s nonces and private keys that belong to these attack types.
1290 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
Fig. 5 shows the private key recovery of users who use duplicated signatures. The first step
is to verify whether the signature that was generated by the user is one of the duplicated
signatures that were generated by the attack types in Table 6. If the signature is one of the
duplicated signatures, the nonce that was used to generate the signature can be calculated, and
the nonce can be used to recover the user’s private key. Because two nonces can generate one
signature value, two private keys and two public keys are generated with the nonces. Therefore,
the two generated public keys and the user’s actual public key can be compared to determine
the user’s actual private key. Shown below is a description of the private key recovery from
Fig. 5.
Step 1. New public keys 𝑄𝑄1 and 𝑄𝑄2 are generated from the two recovered private keys 𝑑𝑑1
and 𝑑𝑑2
Step 2. The generated public keys 𝑄𝑄1 and 𝑄𝑄2 are compared to the user’s public key to
determine the user’s private key
Even if a signature is not a duplicated signature when it is generated, the user’s private key
can be recovered if the r value of signature becomes a duplicated signature. Furthermore,
recovery of private keys that generate duplicated signatures can only occur if the user
generates two or more signatures, but recovery of private keys that use duplicated signatures
can occur even if the user generates only one signature.
In this study, the bitcoin core was used to participate in bitcoin and synchronize the entire
bitcoin block data, as shown in Fig. 6. The synchronized block data was saved as a file named
“blkxxxxx.dat”. It was synchronized up to the 481,614th chain included in the block on
August 22, 2017, and the total size of the synchronized data was approximately 121 GB.
1292 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
Fig. 7 shows a part of the “blk00974.dat” file that has more than 130 block data including
the 481,614th block. The total size of the 481,614th block is 999,263 (0xF3F5F) bytes, and it
includes data on 1,652 (0x674) transactions.
Fig. 8 shows the blocks and signature data that are stored in each “blkxxxxx.dat” file.
During signature value extraction, the entire data file must be divided into blocks, each block
into transactions, and each transaction into an input and output. The ultimately divided inputs
include signature values and public keys, and the outputs include the public keys’ hash values.
Therefore, each transaction is a message, and the input can be analyzed to extract the signature
value and public key.
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1293
The process of extracting messages from the block data can be divided into two types
according to the number of inputs included in the transaction. The left side of Fig. 9 shows the
case of a single input. An area in the input script contains the signature value, but it must be
filled with a different value because the message is from before the signature has been
performed. Therefore, the area is filled as shown below. All of the outputs are combined, as
shown in the figure, and the message is used.
The right side of Fig. 9 shows a case with two inputs. Therefore, two messages must exist,
and the messages are organized as shown below. The ‘0x00’ in the length means a value of
size 1 byte, and ‘–’ means no value.
• i-st Message
Input #i’s Script Length: 0x19
Input #i’s Script: 0x76A914 || RIPEMD160[SHA256(sender’s pubkey)] || 0x88AC
Others’ Script Length: 0x00
Others’ Script: -
Transactions that have two or more inputs contain a message that is similar to that above,
and all outputs are added after the input, as in the case of a single input.
1294 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
To collect signature values from the block data, the bitcoin Wiki and the bitcoin API were
referenced to write the data collecting source code. The source code consists of “main,”
“divide_blocks,” “divide_transactions,” and “extract_sign” functions. Shown below is a
summary of the source code’s structure and roles.
The “main” function, shown in Table 8, extracts the signature values of all “blkxxxxx.dat”
files. Namely, each file is read and transferred to the extraction function, and this process is
repeated. By executing this function, all signature values and public keys are extracted.
return all_signs
The “divide_blocks” function in Table 9 divides all the blocks stored in a single file. In this
process, a magic number is used to find the beginning of a block, and the block’s size is used to
find the end of the block. By executing this function, all the divided blocks in the file are
returned.
return blkArray
The “divide_transactions” function in Table 10 takes a block array and extracts the
scripSig from the transaction input included in each block. Data are not extracted from the
output, but the size of the output must be calculated to divide the transactions. By passing the
scriptSig through the “extract_sign” function, the signature value (r, s) and public key are
divided. By executing this function, a set of the signature value (r, s) and public key is
returned.
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1295
return signs
The “extract_sign” function in Table 11 extracts the signature value and public key from
the scriptSig. By executing this function, a set that adds the signature value (r, s) and public
key to the sign set that was received as input is returned.
Table 13 shows a list and the description of parameters used in the bitcoin user private key
recovery presented in the following sections.
Table 16 shows the recovery of private keys and nonces of users who have generated
duplicated signatures via the data in Tables 14 and 15. To confirm that the recovered private
key (d’) matches the user’s actual private key, a new public key (𝑄𝑄𝑥𝑥 ’, 𝑄𝑄𝑦𝑦 ’) was generated.
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1297
Because the newly generated value matches that of the public key (𝑄𝑄𝑥𝑥 ,𝑄𝑄𝑦𝑦 ) in Table 14, the
recovered private key is the same as the user’s actual private key. To confirm that the
recovered nonce (k’) is the nonce used in the actual signature, a new signature value (r’) was
generated. Because the newly generated value matches the r signature value in Table 14, the
recovered nonce is the same as the nonce used in the actual signature.
In the analyzed block data, 1,194 private keys generated duplicated signatures, and these
private keys can be recovered from the block data by attackers.
The nonce that corresponds to the r value of signature in Table 17 can be found, and this is
presented in Table 18. Therefore, an attacker can use the nonce to find the user’s private key.
Table 19 shows the recovery of a user’s private key using a nonce that corresponds to the
duplicated signature shown in Table 18. ‘k’ and ‘-k’ are the nonces that can generate the same
value as the r value of signature in Table 18, and the private keys are calculated for both cases.
1298 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
The public keys (𝑄𝑄1 , 𝑄𝑄 2 ) calculated from the two private keys (𝑑𝑑1 ,𝑑𝑑2 ) are compared to the
user’s actual public key (Q) in Table 17 to determine the private key. A comparison between
the two public keys (𝑄𝑄1 , 𝑄𝑄 2) and the user’s actual public key demonstrates that 𝑑𝑑1 is the user’s
actual private key.
An analysis of the block data indicated that 621 private keys used duplicated signatures.
These private keys can be recovered from the block data by attackers.
Table 20 shows the number of private keys that generated or used duplicated signatures,
and the number of private keys that could be recovered from the analyzed block data;
239,039,487 private keys were used in the block data that was analyzed in this study; 1,815
private keys could be recovered owing to the generation and use of duplicated signatures.
Table 22 shows the recovery of a user’s private key with nonce. ‘k’ and ‘-k’ are the nonces
that can generate the same value as the r value of signature in Table 18, and the private keys
are calculated for both cases. The public keys (𝑸𝑸𝟏𝟏 , 𝑸𝑸𝟐𝟐 ) calculated from the two private keys
KSII TRANSACTIONS ON INTERNET AND INFORMATION SYSTEMS VOL. 14, NO. 3, March 2020 1299
(𝒅𝒅𝟏𝟏 ,𝒅𝒅𝟐𝟐 ) are compared to the user’s actual public key (Q) in Table 21 to determine the private
key. A comparison between the two public keys (𝑸𝑸𝟏𝟏 , 𝑸𝑸𝟐𝟐 ) and the user’s actual public key
demonstrates that 𝒅𝒅𝟐𝟐 is the user’s actual private key.
6. Conclusion
A user private key recovery scenario that could occur because of the characteristics of
blockchain systems where all transaction information is shared was presented herein. It
demonstrated the possibility of recovering private keys in an actual bitcoin environment. The
analysis of the actual bitcoin environment showed that 1,815 among 239,039,487 private keys
could be recovered. As bitcoin usage increases, a larger number of private keys could be
recovered from the overall block data. Because the blockchain grants property ownership
rights to the private key owner, private key leaks can result in property theft. Therefore, to
provide secure and efficient blockchain systems to the financial sector, continued research on
the prevention of private key recovery threats is necessitated.
Acknowledgment
This research was supported by the MSIT(Ministry of Science and ICT), Korea, under the
ITRC(Information Technology Research Center) support program (IITP-2019-2016-0-00304)
supervised by the IITP(Institute for Information & communications Technology Planning &
Evaluation)
References
[1] Dong Sup Kim, “Current Status and Implications of Distributed Ledger Technology and Digital
Currency,” Payment Systems Research Team, The Bank of Korea, Jan. 2016.
Article (CrossRefLink).
[2] Korea Internet & Security Agency, “A Study on the Applications and Use Cases of Blockchain
Technology,” KISA-WP-2016-0040, Nov. 2016. Article (CrossRefLink).
[3] IBK Economic Research Institute, “A Study on the Understanding of Blockchain and the
Utilization of Financial Industry,” Jul. 2017. Article (CrossRefLink).
[4] LG CNS, “Cryptocurrency and Blockchain Hacking Cases,” IT Solutions/Security, Nov. 2018.
Article (CrossRefLink).
[5] Nicolas T. Courtios, Pinar Emirdag, Filippo Valsorda, “Private Key Recovery Attacks: On
Extreme Fragility of Popular Bitcoin Key Management, Wallet and Cold Storage Solutions in
Presence of Poor RNG Events,” Cryptology ePrint Archive, Oct. 2014.
Article (CrossRefLink).
1300 Ko et al.: Private Key Recovery on Bitcoin with Duplicated Signatures
[6] Michael Brengel, Christian Rossow, “Identifying Key Leakage of Bitcoin Users,” RAID 2018:
Research in Attacks, Intrusions, and Defenses, pp. 623-643, Sep. 2018. Article (CrossRefLink).
[7] TTA, “Security Requirements for Digital Hospital,” TTAK.KO-12.0305, pp.6-7, Nov. 2016.
Article (CrossRefLink).
[8] Information Technology Laboratory National Institute of Standards and Technology, “Digital
Signature Standard (DSS),” FIPS PUB 168-4, pp.26-30, Jul. 2013. Article (CrossRefLink).
[9] American Bankers Association Standards Department, “Public Key Cryptography for The
Financial Services Industry: The Elliptic Curve Digital Signature Algorithm (ECDSA),” American
National Standard X9.62-1998, Sep. 1998. Article (CrossRefLink).
[10] William Stallings, Cryptography & Network Security 5th ed, Pearson Education, Mar. 2010.
[11] Korea Internet & Security Agency, “Hash Function”. Article (CrossRefLink).
[12] Ilias Giechaskiel, Cas Cremers, Kasper B. Rasmussen, “On Bitcoin Security in the Presence of
Broken Cryptographic Primitives,” Lecture Notes in Computer Science, vol. 9879, pp. 201-222,
2016. Article (CrossRefLink).
[13] Quynh Dang, “Recommendation for Applications Using Approved Hash Algorithms,” NIST
Special Publication 800-107, NIST Computer Security Division Information Technology
Laboratory, Aug. 2012. Article (CrossRefLink).
[14] Satoshi Nakamoto, “Bitcoin: A Peer-to-Peer Electronic Cash System,” pp. 1-9, 2009.
Article (CrossRefLink).
[15] Blockchain.com, “Block at depth 579952 in the Bitcoin blockchain,” Jun. 2019.
Article (CrossRefLink).
[16] Bitcoin Core. Article (CrossRefLink).
[17] CCN, “Bitcoin for Mere Mortals: Blocks,” Nov. 2014. Article (CrossRefLink).
Ju-Seong Ko received Korea B.S. degree in Department of Cyber Security from Ajou
University. He is currently pursuing the M.S. degree in Department of Computer
Engineering with Ajou University, Korea. His research interests include Cryptographic
protocols and Blockchain & Fintech analysis.