USD

Build Security into Blockchain Applications - Part 1: How Blockchain Works and Uses Private Keys

By Stephen Evanczuk

Contributed By Digi-Key's North American Editors

Editor’s Note: The details of blockchain technology and its transaction methods are complex, but Part 1 of a two-part series will provide an overview of blockchain structure and its transaction process. This will provide the context for understanding why protection of private keys lies at the core of blockchain security and will lead into the introduction of a turnkey solution for securing private keys. Part 2 will show how developers can more easily protect blockchain transactions using this turnkey, hardware-based solution.

Security concerns have driven development of blockchain technology, which is familiar to many developers in the context of cryptocurrencies. However, blockchain technology can also offer developers a secure infrastructure with broad applicability. Its decentralized architecture eliminates the need for a central authority, relying instead on private keys and cryptography methods to protect assets and their exchange between parties. Consequently, the security of a blockchain system depends critically on the security of keys and their proper use in robust algorithms

Although appropriate algorithms are readily available, implementation requires significant expertise and experience to develop a secure solution and integrate it in the target application. Developers need a more accessible approach for ensuring key security in emerging blockchain applications.

This article briefly describes why blockchain is of such interest and how the technology works, before introducing a hardware-based solution for blockchain security from Infineon Technologies.

The rise of blockchain

Blockchain technology has captured attention in nearly every segment of society with applications as far ranging as cryptocurrencies, identity protection, supply chain management, and voting. Often called distributed ledger technology, its combination of decentralization, authentication, and record preservation attracts interest through its ability to eliminate any central authority for oversight or intermediary for execution of transactions.

Financial institutions are attracted by its potential to enable faster, lower cost payment mechanisms than those available with current technologies and practices. Outside of fintech, companies concerned about validation of identity and traceability of transactions are attracted by blockchain's ability to maintain a record trail that is authenticated and effectively immutable (it never changes). The immutability of a blockchain lies in the way it is constructed, and its authenticity lies in the way transactions are executed.

At its core, this technology fundamentally depends on the ability to protect secret keys involved in building the blocks that convey transactions. Although the details of blockchain technology and its transaction methods are well beyond the scope of this article, a cursory review of blockchain structure and its transaction process can provide the context for understanding why protection of private keys is central to blockchain security. Note, however, that real-world blockchain systems rely on substantially more sophisticated structures and protocols than suggested in this simplified, conceptual overview of blockchain technology.

Immutable chains

A blockchain, as the name suggests, is a chain of blocks used to record a set of transactions. The structural details and protocols used in public blockchains, such as Bitcoin and Ethereum, can differ substantially from private blockchains accessed by an individual organization. There are also semi-private blockchains, called permissioned blockchains, that are accessed by a cooperating group of entities.

In each type of blockchain, however, the foundations of the block build on a few common elements (Figure 1):

  • The previous block's hash value (Prev_Hash), which serves the links in the chain of blocks
  • The block's associated transactions, represented by the root (Tx_Root) of a tree called a hash tree, or Merkle tree, comprising hashes (Hashi) of transactions (Txi)
  • A nonce that plays a role in generation of valid blocks
  • A timestamp that records the time the block was created

Diagram of simplified view of a Bitcoin blockchainFigure 1: In a simplified view of a Bitcoin blockchain, each block contains a timestamp, an arbitrary nonce, a hash tree or Merkel tree, and a hash of the previous block (Prev_Hash) in the chain. (Image source: Wikimedia Commons/CC-BY-SA-3.0)

The inclusion of the Prev_Hash value in a blockchain provides the framework for the integrity of a blockchain as a whole. A hacker's modification of some past transaction in blockn-1 would invalidate the hash contained in blockn even if the hacker corrected the Merkle tree and Tx_Root in blockn-1. As described below, the distributed nature of blockchain systems addresses such hash mismatches.

The nonce plays a role in the block creation rules that make blockchains effectively immutable. Public blockchains like Bitcoin and Ethereum cryptocurrencies enforce artificial constraints on the value of a new block's own hash value before it can be used to extend the chain. When a set of Prev_Hash transactions are gathered for construction of a new block, these rules typically require that the final hash for a newly constructed block fall below some specified maximum value. The hash algorithms used in blockchain systems generate the same result for the same input, but the smallest change in the input returns an entirely new result that is unpredictable.

The nonce provides a way to change the hash value without impacting the elements of critical importance to the blockchain system and its users. Finding the hash that conforms to the blockchain's rules then becomes a brute force effort using different values for the nonce. By working through a series of different values for the nonce and rehashing the block each time, a hash value conforming to the rules will eventually be found. For good reason, those who perform this work are called blockchain miners.

This final acceptable nonce is called the proof of work because it represents the successful completion of the very computationally intensive mining process. This process and proof of work also reflect the decentralized nature of blockchain systems. After finding an acceptable nonce, the miner earns the right (and associated remuneration in cryptocurrency mining) to extend the blockchain with their newly created block.

Other miners and blockchain users can easily confirm the validity of the new block by computing the hash with the block and the nonce found by the successful miner.

In the decentralized architecture of blockchains, individual nodes in the blockchain distributed network analyze every block and transaction against the same set of rules applied during mining. Consequently, blockchains can self-correct because nodes will ignore any block that is invalid because of an error in construction or a hash that is nonconforming or simply incorrect. Cryptocurrencies and other blockchain systems take full advantage of this consensus building aspect of blockchain decentralization to employ additional mechanisms that further complicate hackers' attempts to subvert the process.

The combination of compute intensive proof of work rules and consensus-based block validation processes presents an insurmountable obstacle to a hacker hoping to modify a past transaction in a blockchain. Any hacker hoping to rebuild a chain starting from the modified block needs to somehow complete the proof of work at a faster rate than the community of miners. In this alone, hackers find themselves dealing with a virtual arms race of processing resources that has moved from use of graphics processing units on personal computers to field-programmable gate arrays to specialized application specific integrated circuits. Besides the hurdle of a large investment in computing resources, the attendant power consumption requirements alone would be prohibitive.

After all that processing effort and power utilization, hackers still face the likelihood that their modified chain will simply be rejected out of hand by the consensus-based mechanisms. Substantial differences in results in a run of blocks are few and far between, resulting in major, headline-provoking disruptions in the affected blockchain system, potentially requiring a rare hard fork that would create an entirely new version of the system.

Authenticating transactions

All of the previous discussion about blockchain structure and processes has assumed that the transactions represented by a Merkle tree in a block are valid. If invalid transactions somehow find their way into the blockchain system, efforts such as proof of work and decentralized block validation are for naught. Indeed, the fundamental motivation for blockchain technology lies in its ability to reliably include a set of valid transactions into an immutable blockchain. From this perspective, block generation begins when the user requests a transaction. Rather than a central authority approving the transaction, blockchain technology relies on cryptographic methods using private keys owned by the requesting user.

To initiate a request, users digitally sign their requests using their private keys and submit the request to a pool containing other unconfirmed transactions (Figure 2). In turn, the blockchain miner pulls a set of unconfirmed transactions from this pool and verifies that each request originates from the respective private key owner by using the requestor's public key included in each unconfirmed transaction. In cryptocurrencies, transaction requests with invalid signatures are quickly bypassed by miners attempting to outrace other miners trying to create the next block in the blockchain.

Diagram of private/public key pairs provide the basis for blockchain transactionFigure 2: Private/public key pairs provide the basis for blockchain transaction signing by the requester (left) and verification by the blockchain miner (right). (Image source: Wikimedia Commons/CC-BY-SA-3.0)

Ensuring private keys remain private

In blockchain's decentralized architecture, possession of the private key for a set of transactions grants ownership of those transactions. No customer service representative stands ready to trace lost funds or comply with federal rules for their restoration. For this reason, lost or stolen private keys are frequently the reason behind headlines about massive cryptocurrency losses, and analysts project this trend to continue.

Blockchain technology's fundamental reliance on private keys for transaction signing and verification drives the critical need to protect these secrets. For the user, a poorly secured key is potentially an open door for loss of control of their participation in a blockchain system.

Hackers have used phishing attacks and other familiar approaches to gain access to unencrypted private keys stored carelessly on mobile devices or computers. Often, encrypted keys are just as vulnerable. Key generation software typically allows users to enter a passphrase used to encrypt the key on the user's device. Security researchers have found that this approach suffers a problem common to all password-based approaches: Users too often encrypt their key with a weak, easily guessed passphrase.

Even when the user takes the necessary precautions with a private key, the key could already be compromised due to faults in the key generation software. Software-based key generators often rely on random number generators (RNGs) that operate with predictable patterns that a thief can uncover with a simple script. Worse, coding errors or faults in key generation algorithms can leave keys vulnerable to anyone familiar with that key generation software utility.

Even a perfect implementation of a robust algorithm is no guarantee of protection. Users still face the real risk that the system running that idealized code is also running software that has been fully penetrated by hackers. As the key generation software runs, it shares memory and processor cycles with the compromised software, providing hackers with visibility into the secret data.

Processors that offer a trusted execution environment (TEE) provide a further degree of protection by running trusted and untrusted code in separate execution spaces. This approach reduces the chance that algorithms and secret data such as private keys can be attacked through vulnerabilities in operating systems, middleware, or other applications.

Even if they are built with secure execution and key protection capabilities, many hardware devices remain vulnerable to more sophisticated microarchitectural and physical attacks. Microarchitectural attacks take advantages of weakness in the processor design. These types of attacks gained widespread attention with Meltdown and Spectre, which exploited vulnerabilities in microprocessor memory access and instruction processing.

Physical attacks range from side-channel exploits that monitor power usage, electromagnetic emission, or timing characteristics to expose protected information. In other physical attacks, hackers induce faults with lasers or cause power supply glitches to infer internal signals. In more direct physical attacks, hackers decap semiconductor devices and use microprobes in an attempt to read data and instruction sequences.

Protection from this wide range of security threats requires a security controller that combines fundamental security features with deeper protection against the broad array of microarchitectural and physical methods used to attack semiconductor devices. Built around this type of security controller, the Infineon Blockchain Security 2Go starter kit (BLOCKCHAINSTARTKITTOBO1) provides an immediate solution to the critical challenge of securing private keys used to sign transactions for inclusion in a blockchain (Figure 3).

Diagram of Infineon Blockchain Security 2Go smartcardFigure 3: The Infineon Blockchain Security 2Go smartcard simplifies blockchain security including transaction signing without exposing valuable private keys. (Image source: Infineon)

Rather than spending time building secure signing methods, blockchain system integrators can simply provide users smartcards from the Blockchain Security 2Go starter kit, or from the Infineon Security 2GO 10 card package (BLOCKCHAIN10CARDSTOBO1).

Conclusion

Blockchain technology has broad applicability, beyond cryptocurrencies. However, it is also complex and depends upon private keys that need robust security mechanisms to prevent loss of control of users' transactions and the compromise of the blockchain system.

While designers have the option to spend time building secure signing methods, the Infineon Blockchain Security 2Go starter kit provides a turnkey blockchain security solution that saves time and resources.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Stephen Evanczuk

Stephen Evanczuk has more than 20 years of experience writing for and about the electronics industry on a wide range of topics including hardware, software, systems, and applications including the IoT. He received his Ph.D. in neuroscience on neuronal networks and worked in the aerospace industry on massively distributed secure systems and algorithm acceleration methods. Currently, when he's not writing articles on technology and engineering, he's working on applications of deep learning to recognition and recommendation systems.

About this publisher

Digi-Key's North American Editors