ruby-fastpbkdf2 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +314 -0
- data/ext/fastpbkdf2/endian.h +71 -0
- data/ext/fastpbkdf2/extconf.rb +59 -0
- data/ext/fastpbkdf2/fastpbkdf2.c +402 -0
- data/ext/fastpbkdf2/fastpbkdf2.h +71 -0
- data/ext/fastpbkdf2/fastpbkdf2_ruby.c +142 -0
- data/ext/fastpbkdf2/fastpbkdf2_ruby.o +0 -0
- data/ext/fastpbkdf2/fastpbkdf2_wrapper.c +16 -0
- data/ext/fastpbkdf2/fastpbkdf2_wrapper.h +48 -0
- data/ext/fastpbkdf2/fastpbkdf2_wrapper.o +0 -0
- data/lib/fastpbkdf2/fastpbkdf2.bundle +0 -0
- data/lib/fastpbkdf2/version.rb +3 -0
- data/lib/fastpbkdf2.rb +31 -0
- data/vendor/fastpbkdf2/LICENSE +117 -0
- data/vendor/fastpbkdf2/fastpbkdf2.c +402 -0
- data/vendor/fastpbkdf2/fastpbkdf2.h +71 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc98f8d63fd80c7c18a56d3d1d271800a66308e3be78c32d084e3a410643b068
|
4
|
+
data.tar.gz: 910d3f78a855d522fcc64efe404f544d93e0fcbe777f8dfc1acd53e8e2a79367
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aad0ef15387bc02cc1bffa64deb1d963785c251357afc312faf35b28dd358e54bddf411d3b146c74a8f58154b7225d66d6a153d441f48b37b01149026ced65d4
|
7
|
+
data.tar.gz: 7a8f3fec4077bef7e7d52850c5519caa3986c74eeb94c494aaa43fa2ac5ab9f0f998a3909e23ac0538d2ca3931b7f8592e3436903e15f83ee43fc75cfbdec7e5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.0.1] - 2025-07-25
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Initial release of ruby-fastpbkdf2 gem
|
15
|
+
- Ruby C extension bindings for fastpbkdf2 C library
|
16
|
+
- Support for PBKDF2-HMAC-SHA1, SHA256, and SHA512 algorithms
|
17
|
+
- Short method aliases: `FastPBKDF2.sha1`, `FastPBKDF2.sha256`, `FastPBKDF2.sha512`
|
18
|
+
- Descriptive method names: `FastPBKDF2.pbkdf2_hmac_sha1`, etc.
|
19
|
+
- Generic interface: `FastPBKDF2.pbkdf2_hmac(algorithm, ...)`
|
20
|
+
- Comprehensive test suite with 94% coverage (50 tests)
|
21
|
+
- Performance benchmarks showing 1.47x speedup over OpenSSL
|
22
|
+
- Cross-platform compilation support (macOS, Linux, Windows)
|
23
|
+
- CI/CD pipeline with GitHub Actions
|
24
|
+
- Code quality tooling with qlty and RuboCop
|
25
|
+
- Memory leak prevention and proper C/Ruby memory management
|
26
|
+
- Full input validation and error handling
|
27
|
+
- Compatible with Ruby 2.7+
|
28
|
+
|
29
|
+
### Performance
|
30
|
+
|
31
|
+
- 1.47x faster than Ruby's built-in OpenSSL PBKDF2 implementation
|
32
|
+
- Optimized for iOS backup key derivation scenarios
|
33
|
+
- Efficient memory usage with proper cleanup
|
34
|
+
|
35
|
+
### Documentation
|
36
|
+
|
37
|
+
- Comprehensive README with usage examples
|
38
|
+
- API documentation with parameter descriptions
|
39
|
+
- Development setup and contribution guidelines
|
40
|
+
- Performance benchmarks and use cases
|
41
|
+
|
42
|
+
[Unreleased]: https://github.com/twilightcoders/ruby-fastpbkdf2/compare/v0.0.1...HEAD
|
43
|
+
[0.0.1]: https://github.com/twilightcoders/ruby-fastpbkdf2/releases/tag/v0.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Your Name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,314 @@
|
|
1
|
+
[](https://badge.fury.io/rb/ruby-fastpbkdf2)
|
2
|
+
[](https://github.com/twilightcoders/ruby-fastpbkdf2/actions/workflows/ci.yml)
|
3
|
+
[](https://qlty.sh/gh/TwilightCoders/projects/ruby-fastpbkdf2)
|
4
|
+
[](https://qlty.sh/gh/TwilightCoders/projects/ruby-fastpbkdf2/metrics/code?sort=coverageRating)
|
5
|
+

|
6
|
+
|
7
|
+
# ruby-fastpbkdf2
|
8
|
+
|
9
|
+
A Ruby gem providing high-performance PBKDF2 key derivation through Ruby bindings for the [fastpbkdf2](https://github.com/ctz/fastpbkdf2) C library. Delivers **1.5x faster** performance than Ruby's built-in OpenSSL PBKDF2 implementation.
|
10
|
+
|
11
|
+
## Quick Start
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install ruby-fastpbkdf2
|
15
|
+
```
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'fastpbkdf2'
|
19
|
+
|
20
|
+
# Short method names (recommended)
|
21
|
+
key = FastPBKDF2.sha256('password', 'salt', 100000, 32)
|
22
|
+
|
23
|
+
# Full method names
|
24
|
+
key = FastPBKDF2.pbkdf2_hmac_sha256('password', 'salt', 100000, 32)
|
25
|
+
|
26
|
+
# Generic method with algorithm selection
|
27
|
+
key = FastPBKDF2.pbkdf2_hmac('sha256', 'password', 'salt', 100000, 32)
|
28
|
+
```
|
29
|
+
|
30
|
+
## Features
|
31
|
+
|
32
|
+
- **High Performance**: 1.5x faster than Ruby's OpenSSL PBKDF2
|
33
|
+
- **Multiple Algorithms**: SHA1, SHA256, and SHA512 support
|
34
|
+
- **Clean API**: Both short (`sha256`) and descriptive (`pbkdf2_hmac_sha256`) method names
|
35
|
+
- **Cross-Platform**: Compiles on macOS, Linux, and Windows
|
36
|
+
- **Drop-in Replacement**: Compatible with existing PBKDF2 workflows
|
37
|
+
- **Comprehensive Tests**: 94% test coverage with performance benchmarks
|
38
|
+
|
39
|
+
## Performance
|
40
|
+
|
41
|
+
Real-world benchmarks on macOS (x86_64) show consistent performance improvements across all scenarios:
|
42
|
+
|
43
|
+
### Low Security (1,000 iterations)
|
44
|
+
|
45
|
+
| Algorithm | FastPBKDF2 | OpenSSL | Speedup | Use Case |
|
46
|
+
| --------- | ---------- | ------- | --------- | ------------------------ |
|
47
|
+
| SHA1 | 0.12ms | 0.21ms | **1.75x** | Basic web authentication |
|
48
|
+
| SHA256 | 0.23ms | 0.35ms | **1.52x** | Basic web authentication |
|
49
|
+
| SHA512 | 0.33ms | 0.46ms | **1.39x** | Basic web authentication |
|
50
|
+
|
51
|
+
### Medium Security (10,000 iterations)
|
52
|
+
|
53
|
+
| Algorithm | FastPBKDF2 | OpenSSL | Speedup | Use Case |
|
54
|
+
| --------- | ---------- | ------- | --------- | -------------------- |
|
55
|
+
| SHA1 | 1.19ms | 2.09ms | **1.76x** | File encryption keys |
|
56
|
+
| SHA256 | 2.35ms | 3.44ms | **1.46x** | File encryption keys |
|
57
|
+
| SHA512 | 3.29ms | 4.60ms | **1.40x** | File encryption keys |
|
58
|
+
|
59
|
+
### High Security (100,000 iterations)
|
60
|
+
|
61
|
+
| Algorithm | FastPBKDF2 | OpenSSL | Speedup | Use Case |
|
62
|
+
| --------- | ---------- | ------- | --------- | --------------------- |
|
63
|
+
| SHA1 | 11.87ms | 20.96ms | **1.77x** | iOS backup encryption |
|
64
|
+
| SHA256 | 23.25ms | 34.26ms | **1.47x** | iOS backup encryption |
|
65
|
+
| SHA512 | 32.78ms | 45.79ms | **1.40x** | iOS backup encryption |
|
66
|
+
|
67
|
+
### Maximum Security (1,000,000 iterations)
|
68
|
+
|
69
|
+
| Algorithm | FastPBKDF2 | OpenSSL | Speedup | Use Case |
|
70
|
+
| --------- | ---------- | -------- | --------- | -------------------------- |
|
71
|
+
| SHA1 | 118.79ms | 209.42ms | **1.76x** | Maximum security scenarios |
|
72
|
+
| SHA256 | 233.13ms | 342.83ms | **1.47x** | Maximum security scenarios |
|
73
|
+
| SHA512 | 329.52ms | 459.69ms | **1.40x** | Maximum security scenarios |
|
74
|
+
|
75
|
+
_Benchmarks run on macOS (x86_64), Ruby 3.3.5, averaged across 3 runs each. Results may vary by platform and hardware._
|
76
|
+
|
77
|
+
## API Reference
|
78
|
+
|
79
|
+
### Short Method Names (Recommended)
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# SHA1 (outputs 20 bytes by default)
|
83
|
+
key = FastPBKDF2.sha1(password, salt, iterations, length)
|
84
|
+
|
85
|
+
# SHA256 (outputs 32 bytes by default)
|
86
|
+
key = FastPBKDF2.sha256(password, salt, iterations, length)
|
87
|
+
|
88
|
+
# SHA512 (outputs 64 bytes by default)
|
89
|
+
key = FastPBKDF2.sha512(password, salt, iterations, length)
|
90
|
+
```
|
91
|
+
|
92
|
+
### Descriptive Method Names
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
key = FastPBKDF2.pbkdf2_hmac_sha1(password, salt, iterations, length)
|
96
|
+
key = FastPBKDF2.pbkdf2_hmac_sha256(password, salt, iterations, length)
|
97
|
+
key = FastPBKDF2.pbkdf2_hmac_sha512(password, salt, iterations, length)
|
98
|
+
```
|
99
|
+
|
100
|
+
### Generic Method
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
# Algorithm can be string or symbol, case insensitive
|
104
|
+
key = FastPBKDF2.pbkdf2_hmac('sha256', password, salt, iterations) # Uses default length
|
105
|
+
key = FastPBKDF2.pbkdf2_hmac(:SHA256, password, salt, iterations, 16) # Custom length
|
106
|
+
```
|
107
|
+
|
108
|
+
### Parameters
|
109
|
+
|
110
|
+
- **password**: String or binary password data
|
111
|
+
- **salt**: String or binary salt data
|
112
|
+
- **iterations**: Integer number of iterations (must be > 0)
|
113
|
+
- **length**: Integer output key length in bytes (must be > 0)
|
114
|
+
|
115
|
+
All methods return a binary string (ASCII-8BIT encoding) containing the derived key.
|
116
|
+
|
117
|
+
## Use Cases
|
118
|
+
|
119
|
+
### iOS Backup Decryption
|
120
|
+
|
121
|
+
Original motivation - enables fast iOS backup key derivation in Ruby:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# High iteration count for iOS backup security
|
125
|
+
backup_key = FastPBKDF2.sha256(user_password, backup_salt, 100_000, 32)
|
126
|
+
```
|
127
|
+
|
128
|
+
### Password Hashing
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
# Web application password derivation
|
132
|
+
salt = SecureRandom.random_bytes(32)
|
133
|
+
password_hash = FastPBKDF2.sha256(user_password, salt, 10_000, 32)
|
134
|
+
```
|
135
|
+
|
136
|
+
### Cryptographic Key Derivation
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# File encryption key from password
|
140
|
+
encryption_key = FastPBKDF2.sha256(passphrase, file_salt, 50_000, 32)
|
141
|
+
```
|
142
|
+
|
143
|
+
## Installation
|
144
|
+
|
145
|
+
### From RubyGems
|
146
|
+
|
147
|
+
```bash
|
148
|
+
gem install ruby-fastpbkdf2
|
149
|
+
```
|
150
|
+
|
151
|
+
### From Source
|
152
|
+
|
153
|
+
```bash
|
154
|
+
git clone https://github.com/twilightcoders/ruby-fastpbkdf2.git
|
155
|
+
cd ruby-fastpbkdf2
|
156
|
+
bundle install
|
157
|
+
rake compile
|
158
|
+
rake spec
|
159
|
+
gem build fastpbkdf2.gemspec
|
160
|
+
gem install ruby-fastpbkdf2-0.0.1.gem
|
161
|
+
```
|
162
|
+
|
163
|
+
### Requirements
|
164
|
+
|
165
|
+
- Ruby 2.7 or higher
|
166
|
+
- C compiler (GCC, Clang, or MSVC)
|
167
|
+
- OpenSSL development headers (libssl-dev on Ubuntu, openssl on macOS)
|
168
|
+
|
169
|
+
The gem compiles the fastpbkdf2 C library during installation, so no external dependencies are required at runtime.
|
170
|
+
|
171
|
+
## Cross-Platform Compatibility
|
172
|
+
|
173
|
+
This gem is designed to compile and run across major platforms:
|
174
|
+
|
175
|
+
### ✅ Supported Platforms
|
176
|
+
|
177
|
+
- **macOS**: Intel (x86_64) and Apple Silicon (arm64)
|
178
|
+
- **Linux**: x86_64, arm64, i686 (most distributions)
|
179
|
+
- **Windows**: x64, x86 (with DevKit or Visual Studio)
|
180
|
+
|
181
|
+
- **Unix variants**: FreeBSD, OpenBSD, NetBSD (with compatible toolchain)
|
182
|
+
### Platform-Specific Features
|
183
|
+
|
184
|
+
- **OpenMP Support**: Automatically enabled on Linux for parallel processing (disabled on macOS due to clang limitations)
|
185
|
+
- **SIMD Optimizations**: The underlying fastpbkdf2 C library includes architecture-specific optimizations
|
186
|
+
- **Compiler Detection**: Automatically adapts compilation flags for GCC, Clang, and MSVC
|
187
|
+
|
188
|
+
### Build Requirements by Platform
|
189
|
+
#### macOS
|
190
|
+
```bash
|
191
|
+
|
192
|
+
# Xcode Command Line Tools (includes clang and OpenSSL)
|
193
|
+
xcode-select --install
|
194
|
+
```
|
195
|
+
#### Linux (Ubuntu/Debian)
|
196
|
+
|
197
|
+
```bash
|
198
|
+
sudo apt-get update
|
199
|
+
sudo apt-get install build-essential libssl-dev ruby-dev
|
200
|
+
```
|
201
|
+
|
202
|
+
```bash
|
203
|
+
sudo yum install gcc openssl-devel ruby-devel make
|
204
|
+
# OR on newer systems:
|
205
|
+
|
206
|
+
sudo dnf install gcc openssl-devel ruby-devel make
|
207
|
+
|
208
|
+
```
|
209
|
+
#### Windows
|
210
|
+
|
211
|
+
```bash
|
212
|
+
# Using RubyInstaller with DevKit
|
213
|
+
# Ensure you have the DevKit installed, then:
|
214
|
+
gem install ruby-fastpbkdf2
|
215
|
+
```
|
216
|
+
|
217
|
+
#### FreeBSD/OpenBSD/NetBSD
|
218
|
+
|
219
|
+
```bash
|
220
|
+
# Install required packages (exact commands vary by OS)
|
221
|
+
# Generally need: gcc or clang, openssl, ruby-dev equivalent
|
222
|
+
```
|
223
|
+
|
224
|
+
The gem's `extconf.rb` automatically detects the platform and adjusts compilation settings accordingly.
|
225
|
+
|
226
|
+
## Development
|
227
|
+
|
228
|
+
### Setup
|
229
|
+
|
230
|
+
```bash
|
231
|
+
git clone https://github.com/twilightcoders/ruby-fastpbkdf2.git
|
232
|
+
cd ruby-fastpbkdf2
|
233
|
+
bundle install
|
234
|
+
```
|
235
|
+
|
236
|
+
### Building
|
237
|
+
|
238
|
+
```bash
|
239
|
+
rake compile # Compile C extension
|
240
|
+
rake clean && rake compile # Clean rebuild
|
241
|
+
```
|
242
|
+
|
243
|
+
### Testing
|
244
|
+
|
245
|
+
```bash
|
246
|
+
rake spec # Run test suite
|
247
|
+
rspec --format documentation # Detailed test output
|
248
|
+
```
|
249
|
+
|
250
|
+
### Code Quality
|
251
|
+
|
252
|
+
```bash
|
253
|
+
qlty check # Run code quality checks
|
254
|
+
rubocop # Ruby style checking
|
255
|
+
```
|
256
|
+
|
257
|
+
### Benchmarking
|
258
|
+
|
259
|
+
Performance benchmarks are integrated into the test suite:
|
260
|
+
|
261
|
+
```bash
|
262
|
+
rspec spec/performance_spec.rb --format documentation
|
263
|
+
```
|
264
|
+
|
265
|
+
## Architecture
|
266
|
+
|
267
|
+
### C Extension
|
268
|
+
|
269
|
+
The gem uses Ruby's native extension API to wrap the fastpbkdf2 C library:
|
270
|
+
|
271
|
+
- **C Functions**: Direct bindings to `fastpbkdf2_hmac_sha1/256/512`
|
272
|
+
- **Method Aliases**: C-level aliases provide short method names (`sha1`, `sha256`, `sha512`)
|
273
|
+
- **Error Handling**: Proper Ruby exception raising for invalid inputs
|
274
|
+
- **Memory Management**: Safe handling of binary data between C and Ruby
|
275
|
+
|
276
|
+
### Ruby Wrapper
|
277
|
+
|
278
|
+
The Ruby layer provides convenience methods and maintains API compatibility:
|
279
|
+
|
280
|
+
- **Generic Interface**: Algorithm selection via string/symbol
|
281
|
+
- **Default Lengths**: Sensible defaults for each hash algorithm
|
282
|
+
- **Input Validation**: Ruby-level parameter checking
|
283
|
+
- **Compatibility**: Backward-compatible constant aliasing
|
284
|
+
|
285
|
+
## Contributing
|
286
|
+
|
287
|
+
1. Fork the repository
|
288
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
289
|
+
3. Make your changes with tests
|
290
|
+
4. Ensure tests pass (`rake spec`)
|
291
|
+
5. Check code quality (`qlty check`)
|
292
|
+
6. Commit your changes (`git commit -am 'Add amazing feature'`)
|
293
|
+
7. Push to the branch (`git push origin feature/amazing-feature`)
|
294
|
+
8. Create a Pull Request
|
295
|
+
|
296
|
+
## License
|
297
|
+
|
298
|
+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
299
|
+
|
300
|
+
The bundled fastpbkdf2 C library is in the public domain (CC0).
|
301
|
+
|
302
|
+
## Acknowledgments
|
303
|
+
|
304
|
+
- **fastpbkdf2**: Original C library by Joseph Birr-Pixton
|
305
|
+
- **python-fastpbkdf2**: Python bindings inspiration by Terry Chia (Ayrx)
|
306
|
+
- **Ruby Core**: Excellent C extension API and documentation
|
307
|
+
|
308
|
+
## Changelog
|
309
|
+
|
310
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
|
311
|
+
|
312
|
+
---
|
313
|
+
|
314
|
+
**Note**: This gem was developed to solve PBKDF2 performance bottlenecks in iOS backup decryption for the [imessage_utils](https://github.com/twilightcoders/imessage_utils) project.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
* endian.h - Cross-platform endian compatibility header
|
3
|
+
*
|
4
|
+
* This file provides endian.h compatibility for platforms that don't have it
|
5
|
+
* (like Windows and macOS). It gets included by fastpbkdf2.c when __GNUC__ is defined.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef FASTPBKDF2_ENDIAN_H
|
9
|
+
#define FASTPBKDF2_ENDIAN_H
|
10
|
+
|
11
|
+
#ifdef __APPLE__
|
12
|
+
/* macOS approach: use system headers to define endian macros */
|
13
|
+
#include <machine/endian.h>
|
14
|
+
#include <libkern/OSByteOrder.h>
|
15
|
+
|
16
|
+
/* Define the Linux-style endian macros that fastpbkdf2.c expects */
|
17
|
+
#ifndef __BYTE_ORDER
|
18
|
+
#define __BYTE_ORDER BYTE_ORDER
|
19
|
+
#endif
|
20
|
+
#ifndef __LITTLE_ENDIAN
|
21
|
+
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
22
|
+
#endif
|
23
|
+
#ifndef __BIG_ENDIAN
|
24
|
+
#define __BIG_ENDIAN BIG_ENDIAN
|
25
|
+
#endif
|
26
|
+
|
27
|
+
#elif defined(_WIN32)
|
28
|
+
/* Windows doesn't have endian.h, but it's always little-endian on x86/x64 */
|
29
|
+
#ifndef __BYTE_ORDER
|
30
|
+
#define __BYTE_ORDER 1234
|
31
|
+
#endif
|
32
|
+
#ifndef __LITTLE_ENDIAN
|
33
|
+
#define __LITTLE_ENDIAN 1234
|
34
|
+
#endif
|
35
|
+
#ifndef __BIG_ENDIAN
|
36
|
+
#define __BIG_ENDIAN 4321
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#else
|
40
|
+
/* Linux and other Unix systems - include the real system endian.h */
|
41
|
+
#if __has_include(<endian.h>)
|
42
|
+
#include_next <endian.h>
|
43
|
+
#elif __has_include(<sys/endian.h>)
|
44
|
+
#include <sys/endian.h>
|
45
|
+
#else
|
46
|
+
/* Fallback definitions for systems without endian headers */
|
47
|
+
#ifndef __BYTE_ORDER
|
48
|
+
#ifdef __BYTE_ORDER__
|
49
|
+
#define __BYTE_ORDER __BYTE_ORDER__
|
50
|
+
#else
|
51
|
+
#define __BYTE_ORDER 1234 /* Assume little-endian */
|
52
|
+
#endif
|
53
|
+
#endif
|
54
|
+
#ifndef __LITTLE_ENDIAN
|
55
|
+
#ifdef __ORDER_LITTLE_ENDIAN__
|
56
|
+
#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
57
|
+
#else
|
58
|
+
#define __LITTLE_ENDIAN 1234
|
59
|
+
#endif
|
60
|
+
#endif
|
61
|
+
#ifndef __BIG_ENDIAN
|
62
|
+
#ifdef __ORDER_BIG_ENDIAN__
|
63
|
+
#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
64
|
+
#else
|
65
|
+
#define __BIG_ENDIAN 4321
|
66
|
+
#endif
|
67
|
+
#endif
|
68
|
+
#endif
|
69
|
+
#endif
|
70
|
+
|
71
|
+
#endif /* FASTPBKDF2_ENDIAN_H */
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
# Configure OpenSSL paths for different platforms
|
4
|
+
if RUBY_PLATFORM =~ /darwin/
|
5
|
+
# macOS: Check common Homebrew paths for OpenSSL
|
6
|
+
openssl_paths = [
|
7
|
+
'/opt/homebrew/opt/openssl@3', # Apple Silicon Homebrew
|
8
|
+
'/usr/local/opt/openssl@3', # Intel Homebrew
|
9
|
+
'/opt/homebrew/opt/openssl', # Apple Silicon Homebrew (fallback)
|
10
|
+
'/usr/local/opt/openssl' # Intel Homebrew (fallback)
|
11
|
+
]
|
12
|
+
|
13
|
+
openssl_found = false
|
14
|
+
openssl_paths.each do |path|
|
15
|
+
if Dir.exist?(path)
|
16
|
+
dir_config('openssl', "#{path}/include", "#{path}/lib")
|
17
|
+
openssl_found = true
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
unless openssl_found
|
23
|
+
puts "Warning: OpenSSL not found in standard Homebrew locations"
|
24
|
+
puts "Trying system paths..."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Check for OpenSSL (required by fastpbkdf2)
|
29
|
+
unless have_library('crypto', 'HMAC_CTX_new')
|
30
|
+
abort "OpenSSL libcrypto is required but not found"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Set compilation flags
|
34
|
+
$CFLAGS << ' -std=c99 -O3 -Wall -Wextra -pedantic'
|
35
|
+
|
36
|
+
# Platform-specific flags for fastpbkdf2.c compatibility
|
37
|
+
if RUBY_PLATFORM =~ /darwin/
|
38
|
+
$CFLAGS << ' -D__APPLE__' # Ensure Apple-specific code paths are used
|
39
|
+
end
|
40
|
+
|
41
|
+
# Suppress various warnings for cleaner compilation
|
42
|
+
$CFLAGS << ' -Wno-deprecated-declarations' # OpenSSL 3.0 deprecation warnings
|
43
|
+
$CFLAGS << ' -Wno-undef' # Undefined macros in fastpbkdf2.c
|
44
|
+
$CFLAGS << ' -Wno-c2x-extensions' # Ruby 3.3+ C2x attribute warnings
|
45
|
+
$CFLAGS << ' -Wno-strict-prototypes' # Ruby 3.3+ ANYARGS deprecation warnings
|
46
|
+
|
47
|
+
# Check for optional OpenMP support
|
48
|
+
# Note: macOS clang doesn't support -fopenmp flag
|
49
|
+
if RUBY_PLATFORM !~ /darwin/ && (have_library('gomp') || have_library('omp'))
|
50
|
+
$CFLAGS << ' -fopenmp -DWITH_OPENMP'
|
51
|
+
$LDFLAGS << ' -fopenmp'
|
52
|
+
end
|
53
|
+
|
54
|
+
# Use wrapper approach - compile fastpbkdf2_wrapper.c instead of copying files
|
55
|
+
# The wrapper handles platform compatibility without modifying vendor files
|
56
|
+
$objs = ['fastpbkdf2_wrapper.o', 'fastpbkdf2_ruby.o']
|
57
|
+
|
58
|
+
# Create the Makefile
|
59
|
+
create_makefile('fastpbkdf2/fastpbkdf2')
|