English | 中文
ISAAC
ISAAC is a cryptographically secure pseudorandom number generator (CSPRNG) and stream cipher designed by Robert J. Jenkins Jr. in 1996. This Go implementation provides both 32-bit and 64-bit versions of ISAAC, with a generic implementation that supports both types.
Features
- Pure Go implementation
- Generic implementation supporting both
uint32
and uint64
types
- Cryptographically secure
- Fast and efficient
- Thread-safe
- No external dependencies
- Fixed-size array state for better performance
Installation
go get github.com/lbbniu/isaac
Usage
Basic Usage
package main
import (
"fmt"
"github.com/lbbniu/isaac"
)
func main() {
// Create a new ISAAC instance with uint32
rng := isaac.New[uint32]()
// Generate random numbers
for i := 0; i < 5; i++ {
fmt.Println(rng.Rand())
}
}
Using uint64
// Create a new ISAAC instance with uint64
rng := isaac.New[uint64]()
Seeding
// Create a new ISAAC instance
rng := isaac.New[uint32]()
// Seed with a fixed-size array
var seed [isaac.Words]uint32
rng.Seed(seed)
Refilling
// Create a new ISAAC instance
rng := isaac.New[uint32]()
// Get a batch of random numbers
var result [isaac.Words]uint32
rng.Refill(&result)
Implementation Details
The implementation includes:
- Generic implementation in
isaac.go
with fixed-size array state
- 32-bit specific implementation in
isaac32.go
- 64-bit specific implementation in
isaac64.go
- Comprehensive test coverage with test vectors from GNU Coreutils
Security
ISAAC is designed to be cryptographically secure. However, please note:
- Always use a cryptographically secure seed
- Do not reuse the same seed for different purposes
- Consider using a more modern CSPRNG for new applications
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
References