Implementation of high speed hash function Keccak on GPU

Thuong Nguyen Dat, Keisuke Iwai, Takashi Matsubara, Takakazu KurokawaInternational Journal of Networking and Computing 2019

Abstract

Nowadays, a hash function is used for password management. The hash function is desired to possess the following three characteristics: Pre-Image Resistance, Second Pre-Image Resistance, and Collision Resistance. They are set on the assumption that it is computationally difficult to find the original message from a given hash value. However, the security level of the password management will be further reduced by implementing a high speed hash function on GPU. In this paper, the implementation of high speed hash function Keccak-512 using the integrated development environment CUDA for GPU is proposed. The following four techniques are used in order to speed up its implementation. The first one is reforming lookup tables from 2 dimensional arrays to 1 dimensional arrays at step $\rho$ and $\pi$. The second is an investigation into the effect of using constant memory and shared memory for constant values. The third is the finding out the optimal configuration of blocks-threads, then evaluate the implementation according to the occupancy. And the last one is using CUDA streams with overlapping to hide the overhead of data transfer and GPU processing.

Introduction

The security of modern password management relies heavily on the computational "hardness" of hash functions. Ideally, it should be prohibitively expensive for an attacker to reverse a hash via brute force. However, the massive parallelism of Graphics Processing Units (GPUs) has shifted the landscape, allowing for billions of attempts per second. As Keccak (the basis for SHA-3) becomes more prevalent, understanding its performance limits on consumer hardware is vital for both developers and security professionals. This research pushes the boundaries of Keccak-512 implementation on the NVIDIA CUDA platform to evaluate the remaining "safety margin" against GPU-accelerated attacks.

The Keccak Architecture

Keccak utilizes a "sponge construction" consisting of two phases: absorbing and squeezing. In the absorbing phase, the input message is padded and XORed into the state. In the squeezing phase, the hash value is extracted from the state.

The absorbing phase of the Keccak sponge construction, showing how message blocks are XORed into the state.

The internal state of Keccak is organized as a 3D array of bits, typically $5 \times 5 \times w$, where $w$ is the lane size (64 bits for Keccak-512). The core of the algorithm consists of multiple rounds of a permutation function $f$, which includes five steps: $\theta, \rho, \pi, \chi,$ and $\iota$.

GPU Optimization Techniques

To achieve maximum throughput on an NVIDIA GeForce GTX 1080, the authors implemented four primary optimization techniques:

  1. Reforming Lookup Tables: Traditional implementations use 2D arrays for rotation offsets in the $\rho$ and $\pi$ steps. By flattening these into 1D arrays, the authors eliminated the need for coordinate-to-index arithmetic ($i \cdot N + j$) during kernel execution. This reduces latency and register pressure, allowing more threads to run concurrently.
The 3D state structure of Keccak (5x5x64 bits), which the authors optimized by flattening its indexing.
  1. Strategic Memory Allocation: The GPU features several memory tiers. Benchmarking revealed that storing rotation offsets in Constant memory and round constants in Shared memory provided the optimal balance. Constant memory is highly efficient for "broadcast" reads where all threads access the same value, while Shared memory excels when threads access different table values within the same round.
  2. Occupancy Optimization: The authors performed a grid search to find the optimal CUDA block and thread configuration. For the Pascal architecture (GTX 1080), 128 threads per block maximized "occupancy"—the ratio of active warps to the maximum supported warps—ensuring the GPU's execution units remained saturated.
  3. CUDA Streams and Overlapping: To mitigate the latency of data transfer between the CPU (Host) and GPU (Device), asynchronous CUDA streams were employed. This allows the GPU to process one data chunk while simultaneously uploading the next and downloading previous results.

Key Results

The optimized implementation achieved a peak throughput of 64.58 GB/s, representing a 14x speedup over previous academic benchmarks. In practical password-cracking simulations, the proposed method reached 909.6 MH/s (Mega Hashes per second), outperforming the industry-standard tool Hashcat 5.1.0 (769.6 MH/s) by approximately 18% on identical hardware.

Analysis showed that the transition from 2D to 1D lookup tables provided a ~1.1x speedup, while the refined memory allocation strategy improved performance by over 10x compared to a naive implementation using only Global memory.

Conclusion and Future Work

This study demonstrates that Keccak-512 can be processed at extreme speeds on consumer-grade GPUs through careful memory and architectural tuning. While these results highlight potential vulnerabilities in password security, the study focused primarily on hashing speed. Future work should address the "matching logic" bottleneck—the phase where generated hashes are compared against target lists—and investigate the portability of these optimizations to newer GPU architectures like Ampere or Blackwell, which feature different cache and register behaviors.

Summary updated

BibTeX
@article{dat2019implementation,
  author = {Thuong Nguyen Dat and Keisuke Iwai and Takashi Matsubara and Takakazu Kurokawa},
  title = {{Implementation of high speed hash function Keccak on GPU}},
  journal = {International Journal of Networking and Computing},
  year = {2019},
  doi = {10.15803/ijnc.9.2\_370},
}
Figure