iodine 0.8.4 → 0.8.6
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 +4 -4
- data/CHANGELOG.md +43 -1
- data/README.md +1 -1
- data/exe/iodine +5 -5
- data/ext/iodine/fio-stl.h +311 -145
- data/ext/iodine/fio-stl.md +59 -24
- data/ext/iodine/iodine_caller.h +1 -1
- data/ext/iodine/iodine_cli.h +4 -0
- data/ext/iodine/iodine_connection.h +34 -17
- data/ext/iodine/iodine_crypto.h +117 -0
- data/ext/iodine/iodine_listener.h +2 -1
- data/ext/iodine/iodine_minimap.h +17 -17
- data/ext/iodine/iodine_tls.h +21 -7
- data/ext/iodine/iodine_utils.h +26 -17
- data/lib/iodine/benchmark.rb +20 -3
- data/lib/iodine/documentation.rb +174 -7
- data/lib/iodine/version.rb +1 -1
- metadata +2 -2
data/ext/iodine/iodine_utils.h
CHANGED
|
@@ -247,8 +247,6 @@ FIO_SFUNC VALUE iodine_utils_is_eq(VALUE mod, VALUE a, VALUE b) { // clang-forma
|
|
|
247
247
|
Randomness and Friends
|
|
248
248
|
***************************************************************************** */
|
|
249
249
|
|
|
250
|
-
FIO_DEFINE_RANDOM128_FN(static, iodine_random, 11, 0)
|
|
251
|
-
|
|
252
250
|
FIO_SFUNC VALUE iodine_utils_hmac512(VALUE self, VALUE secret, VALUE massage) {
|
|
253
251
|
rb_check_type(secret, RUBY_T_STRING);
|
|
254
252
|
rb_check_type(massage, RUBY_T_STRING);
|
|
@@ -420,12 +418,20 @@ FIO_SFUNC VALUE iodine_utils_risky_hash(int argc, VALUE *argv, VALUE self) {
|
|
|
420
418
|
/**
|
|
421
419
|
* Computes facil.io Risky256 Hash (non-cryptographic, 256-bit).
|
|
422
420
|
*
|
|
421
|
+
* When `key:` is given, computes the keyed (single pass) variant instead.
|
|
422
|
+
*
|
|
423
423
|
* @param data [String] Input data to hash
|
|
424
|
+
* @param key: [String] Optional secret key (keyed hashing)
|
|
424
425
|
* @return [String] 32-byte binary hash
|
|
425
426
|
*/
|
|
426
|
-
FIO_SFUNC VALUE iodine_utils_risky256(VALUE
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
FIO_SFUNC VALUE iodine_utils_risky256(int argc, VALUE *argv, VALUE self) {
|
|
428
|
+
fio_buf_info_s data = FIO_BUF_INFO0, key = FIO_BUF_INFO0;
|
|
429
|
+
iodine_rb2c_arg(argc,
|
|
430
|
+
argv,
|
|
431
|
+
IODINE_ARG_BUF(data, 0, "data", 1),
|
|
432
|
+
IODINE_ARG_BUF(key, 0, "key", 0));
|
|
433
|
+
fio_u256 h = key.buf ? fio_risky256_keyed(key.buf, key.len, data.buf, data.len)
|
|
434
|
+
: fio_risky256(data.buf, data.len);
|
|
429
435
|
return rb_str_new((const char *)h.u8, 32);
|
|
430
436
|
(void)self;
|
|
431
437
|
}
|
|
@@ -433,14 +439,21 @@ FIO_SFUNC VALUE iodine_utils_risky256(VALUE self, VALUE data) {
|
|
|
433
439
|
/**
|
|
434
440
|
* Computes facil.io Risky512 Hash (non-cryptographic, 512-bit).
|
|
435
441
|
*
|
|
436
|
-
* First 256 bits are identical to risky256 (SHAKE-style extension)
|
|
442
|
+
* First 256 bits are identical to risky256 (SHAKE-style extension), also when
|
|
443
|
+
* the same `key:` is given to both.
|
|
437
444
|
*
|
|
438
445
|
* @param data [String] Input data to hash
|
|
446
|
+
* @param key: [String] Optional secret key (keyed hashing)
|
|
439
447
|
* @return [String] 64-byte binary hash
|
|
440
448
|
*/
|
|
441
|
-
FIO_SFUNC VALUE iodine_utils_risky512(VALUE
|
|
442
|
-
|
|
443
|
-
|
|
449
|
+
FIO_SFUNC VALUE iodine_utils_risky512(int argc, VALUE *argv, VALUE self) {
|
|
450
|
+
fio_buf_info_s data = FIO_BUF_INFO0, key = FIO_BUF_INFO0;
|
|
451
|
+
iodine_rb2c_arg(argc,
|
|
452
|
+
argv,
|
|
453
|
+
IODINE_ARG_BUF(data, 0, "data", 1),
|
|
454
|
+
IODINE_ARG_BUF(key, 0, "key", 0));
|
|
455
|
+
fio_u512 h = key.buf ? fio_risky512_keyed(key.buf, key.len, data.buf, data.len)
|
|
456
|
+
: fio_risky512(data.buf, data.len);
|
|
444
457
|
return rb_str_new((const char *)h.u8, 64);
|
|
445
458
|
(void)self;
|
|
446
459
|
}
|
|
@@ -573,7 +586,7 @@ FIO_SFUNC VALUE iodine_utils_hmac_poly(VALUE self,
|
|
|
573
586
|
|
|
574
587
|
FIO_SFUNC VALUE iodine_utils_uuid(int argc, VALUE *argv, VALUE self) {
|
|
575
588
|
VALUE r = Qnil;
|
|
576
|
-
fio_u128 rand =
|
|
589
|
+
fio_u128 rand = fio_rand128();
|
|
577
590
|
fio_buf_info_s secret = {0};
|
|
578
591
|
fio_buf_info_s info = {0};
|
|
579
592
|
FIO_STR_INFO_TMP_VAR(str, 128);
|
|
@@ -641,7 +654,7 @@ FIO_SFUNC VALUE iodine_utils_random(int argc, VALUE *argv, VALUE self) {
|
|
|
641
654
|
if ((size - 1) > 0x0FFFFFFF)
|
|
642
655
|
rb_raise(rb_eRangeError, "`bytes` count is out of range.");
|
|
643
656
|
r = rb_str_buf_new(size);
|
|
644
|
-
|
|
657
|
+
fio_rand_bytes(RSTRING_PTR(r), size);
|
|
645
658
|
rb_str_set_len(r, size);
|
|
646
659
|
return r;
|
|
647
660
|
(void)self;
|
|
@@ -915,16 +928,12 @@ static void Init_Iodine_Utils(void) {
|
|
|
915
928
|
rb_define_singleton_method(m, "sha1", iodine_utils_sha1, 1);
|
|
916
929
|
rb_define_singleton_method(m, "crc32", iodine_utils_crc32, -1);
|
|
917
930
|
rb_define_singleton_method(m, "risky_hash", iodine_utils_risky_hash, -1);
|
|
918
|
-
rb_define_singleton_method(m, "risky256", iodine_utils_risky256, 1);
|
|
919
|
-
rb_define_singleton_method(m, "risky512", iodine_utils_risky512, 1);
|
|
931
|
+
rb_define_singleton_method(m, "risky256", iodine_utils_risky256, -1);
|
|
932
|
+
rb_define_singleton_method(m, "risky512", iodine_utils_risky512, -1);
|
|
920
933
|
rb_define_singleton_method(m, "risky256_hmac", iodine_utils_risky256_hmac, 2);
|
|
921
934
|
rb_define_singleton_method(m, "risky512_hmac", iodine_utils_risky512_hmac, 2);
|
|
922
935
|
rb_define_singleton_method(m, "secure_random", iodine_utils_secure_random, -1);
|
|
923
936
|
rb_define_singleton_method(m, "blake2b", iodine_utils_blake2b, -1);
|
|
924
937
|
rb_define_singleton_method(m, "blake2s", iodine_utils_blake2s, -1);
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
fio_state_callback_add(FIO_CALL_IN_CHILD, iodine_random_on_fork, NULL);
|
|
929
938
|
} // clang-format on
|
|
930
939
|
#endif /* H___IODINE_UTILS___H */
|
data/lib/iodine/benchmark.rb
CHANGED
|
@@ -186,6 +186,7 @@ module Iodine
|
|
|
186
186
|
# hmac512 => HMAC-SHA512 (compared against OpenSSL HMAC-SHA512)
|
|
187
187
|
# risky256_hmac => keyed MAC on non-crypto Risky Hash — NOT for security-critical use
|
|
188
188
|
# risky512_hmac => keyed MAC on non-crypto Risky Hash — NOT for security-critical use
|
|
189
|
+
# risky256(key:) / risky512(key:) => single pass keyed Risky Hash — NOT for security-critical use
|
|
189
190
|
#
|
|
190
191
|
# Payload: 512 bytes of the benchmark file itself (representative of a
|
|
191
192
|
# short-to-medium authenticated payload).
|
|
@@ -194,7 +195,7 @@ module Iodine
|
|
|
194
195
|
benchmark_payload = (File.exist?(__FILE__) ? IO.binread(__FILE__)[0...512] : 'my message payload')
|
|
195
196
|
|
|
196
197
|
puts "HMAC benchmarks — all MACs ranked — #{benchmark_payload.bytesize}-byte message, #{benchmark_secret.bytesize}-byte secret"
|
|
197
|
-
puts " [WARNING: risky256_hmac / risky512_hmac are NOT suitable for security-critical authentication]"
|
|
198
|
+
puts " [WARNING: risky256_hmac / risky512_hmac / keyed risky256 / risky512 are NOT suitable for security-critical authentication]"
|
|
198
199
|
|
|
199
200
|
# Pre-create OpenSSL digest objects outside the hot loop. Compare the
|
|
200
201
|
# same Base64 output format as Iodine's hmac* methods.
|
|
@@ -212,6 +213,13 @@ module Iodine
|
|
|
212
213
|
bm.report('Iodine::Utils.risky512_hmac (non-crypto, 64B)') do
|
|
213
214
|
Iodine::Utils.risky512_hmac(benchmark_secret, benchmark_payload)
|
|
214
215
|
end
|
|
216
|
+
# Keyed Risky Hash — single pass alternative to the HMAC construction
|
|
217
|
+
bm.report('Iodine::Utils.risky256(key:) (non-crypto, 32B)') do
|
|
218
|
+
Iodine::Utils.risky256(benchmark_payload, key: benchmark_secret)
|
|
219
|
+
end
|
|
220
|
+
bm.report('Iodine::Utils.risky512(key:) (non-crypto, 64B)') do
|
|
221
|
+
Iodine::Utils.risky512(benchmark_payload, key: benchmark_secret)
|
|
222
|
+
end
|
|
215
223
|
# Poly1305 MAC — no direct OpenSSL equivalent; shown for reference only
|
|
216
224
|
bm.report('Iodine::Utils.hmac128 (Poly1305) ') do
|
|
217
225
|
Iodine::Utils.hmac128(benchmark_secret, benchmark_payload)
|
|
@@ -1476,7 +1484,7 @@ module Iodine
|
|
|
1476
1484
|
|
|
1477
1485
|
# Benchmarks Iodine's non-cryptographic hash functions.
|
|
1478
1486
|
#
|
|
1479
|
-
# Tests risky_hash (64-bit), risky256, risky512, and crc32 against
|
|
1487
|
+
# Tests risky_hash (64-bit), risky256, risky512 (unkeyed and keyed), and crc32 against
|
|
1480
1488
|
# Ruby stdlib equivalents where available.
|
|
1481
1489
|
#
|
|
1482
1490
|
# FAIRNESS NOTES:
|
|
@@ -1509,6 +1517,8 @@ module Iodine
|
|
|
1509
1517
|
# Label width — wide enough for 'Iodine risky512 (non-crypto, 64B)'
|
|
1510
1518
|
lw = 32
|
|
1511
1519
|
|
|
1520
|
+
key = Iodine::Utils.secure_random(bytes: 32)
|
|
1521
|
+
|
|
1512
1522
|
sizes.each do |size_name, size|
|
|
1513
1523
|
data = Iodine::Utils.random(size)
|
|
1514
1524
|
|
|
@@ -1534,6 +1544,13 @@ module Iodine
|
|
|
1534
1544
|
x.report('Iodine risky512 (non-crypto, 64B)'.ljust(lw)) do
|
|
1535
1545
|
Iodine::Utils.risky512(data)
|
|
1536
1546
|
end
|
|
1547
|
+
# keyed variants (single pass) — e.g., hash flooding resistant keys
|
|
1548
|
+
x.report('Iodine risky256 keyed (32B)'.ljust(lw)) do
|
|
1549
|
+
Iodine::Utils.risky256(data, key: key)
|
|
1550
|
+
end
|
|
1551
|
+
x.report('Iodine risky512 keyed (64B)'.ljust(lw)) do
|
|
1552
|
+
Iodine::Utils.risky512(data, key: key)
|
|
1553
|
+
end
|
|
1537
1554
|
# Zlib.crc32 — direct equivalent for crc32 (same ITU-T V.42 polynomial)
|
|
1538
1555
|
x.report('Zlib.crc32'.ljust(lw)) do
|
|
1539
1556
|
Zlib.crc32(data)
|
|
@@ -1651,7 +1668,7 @@ module Iodine
|
|
|
1651
1668
|
# - crypto_kdf (HKDF key derivation)
|
|
1652
1669
|
# - crypto_totp (TOTP generation/verification)
|
|
1653
1670
|
# - compression (Deflate, Gzip, Brotli)
|
|
1654
|
-
# - non_crypto_hashing (risky_hash, crc32, risky256, risky512)
|
|
1671
|
+
# - non_crypto_hashing (risky_hash, crc32, risky256, risky512, keyed variants)
|
|
1655
1672
|
# - crypto_pqkem (X25519+ML-KEM-768 post-quantum hybrid KEM)
|
|
1656
1673
|
def self.crypto_all
|
|
1657
1674
|
puts "\n" + '=' * 70
|
data/lib/iodine/documentation.rb
CHANGED
|
@@ -1049,7 +1049,14 @@ module Iodine
|
|
|
1049
1049
|
# checksums, data deduplication, and other non-security applications.
|
|
1050
1050
|
# The output is deterministic and consistent across platforms.
|
|
1051
1051
|
#
|
|
1052
|
+
# When `key:` is given, the keyed variant is computed in a single pass
|
|
1053
|
+
# (about the cost of an unkeyed hash, cheaper than {risky256_hmac}). Use a
|
|
1054
|
+
# secret key with at least 128 bits of entropy when hashing
|
|
1055
|
+
# attacker-influenced data (e.g., to resist hash flooding) or for fast key
|
|
1056
|
+
# derivation where the output stays private.
|
|
1057
|
+
#
|
|
1052
1058
|
# @param data [String] the data to hash
|
|
1059
|
+
# @param key [String, nil] optional secret key (keyed hashing)
|
|
1053
1060
|
# @return [String] 32-byte binary hash digest
|
|
1054
1061
|
#
|
|
1055
1062
|
# @note This hash function is NOT cryptographically secure. Do not use
|
|
@@ -1058,7 +1065,10 @@ module Iodine
|
|
|
1058
1065
|
# @example
|
|
1059
1066
|
# hash = Iodine::Utils.risky256("hello world")
|
|
1060
1067
|
# puts hash.bytesize # => 32
|
|
1061
|
-
|
|
1068
|
+
#
|
|
1069
|
+
# # Keyed
|
|
1070
|
+
# tag = Iodine::Utils.risky256("hello world", key: secret)
|
|
1071
|
+
def self.risky256(data, key: nil); end
|
|
1062
1072
|
|
|
1063
1073
|
# Computes a 512-bit (64-byte) non-cryptographic hash using Risky Hash.
|
|
1064
1074
|
#
|
|
@@ -1066,7 +1076,11 @@ module Iodine
|
|
|
1066
1076
|
# the output are identical to risky256 (truncation-safe). The second
|
|
1067
1077
|
# 256 bits extend the hash without increasing collision resistance.
|
|
1068
1078
|
#
|
|
1079
|
+
# When `key:` is given, the keyed variant is computed; its first 256 bits
|
|
1080
|
+
# match {risky256} with the same `key:`.
|
|
1081
|
+
#
|
|
1069
1082
|
# @param data [String] the data to hash
|
|
1083
|
+
# @param key [String, nil] optional secret key (keyed hashing)
|
|
1070
1084
|
# @return [String] 64-byte binary hash digest
|
|
1071
1085
|
#
|
|
1072
1086
|
# @note This hash function is NOT cryptographically secure. Do not use
|
|
@@ -1078,7 +1092,7 @@ module Iodine
|
|
|
1078
1092
|
#
|
|
1079
1093
|
# # First 32 bytes match risky256
|
|
1080
1094
|
# hash[0, 32] == Iodine::Utils.risky256("hello world") # => true
|
|
1081
|
-
def self.risky512(data); end
|
|
1095
|
+
def self.risky512(data, key: nil); end
|
|
1082
1096
|
|
|
1083
1097
|
# Computes a 256-bit (32-byte) keyed HMAC using Risky Hash.
|
|
1084
1098
|
#
|
|
@@ -1564,14 +1578,41 @@ module Iodine
|
|
|
1564
1578
|
# @param cookies [Hash] (HTTP/WebSocket only) Cookies to send.
|
|
1565
1579
|
# @param body [String] (HTTP only) Request body.
|
|
1566
1580
|
# @param method [String] (HTTP only) HTTP method (defaults to GET).
|
|
1581
|
+
# @param verify [Boolean] (TLS only) If `true`, the server's certificate is
|
|
1582
|
+
# verified (see below). Defaults to `false`.
|
|
1567
1583
|
# @return [Iodine::Connection] The new connection object.
|
|
1568
1584
|
#
|
|
1585
|
+
# **Server verification is opt-in.** By default, TLS client connections
|
|
1586
|
+
# encrypt traffic but do **not** verify the server's certificate (a warning
|
|
1587
|
+
# is logged). This suits small (micro-service) networks where services don't
|
|
1588
|
+
# carry their own certificates. To verify the server, use any of:
|
|
1589
|
+
#
|
|
1590
|
+
# - `verify: true` - verifies against the system's trust store, unless the
|
|
1591
|
+
# TLS object already trusts specific certificates (these are kept);
|
|
1592
|
+
# - a `trust` URL query: `?trust=sys` (or `?trust=system`) for the system's
|
|
1593
|
+
# trust store, or `?trust=ca.pem` for a CA file (`.pem` is appended when
|
|
1594
|
+
# missing). For HTTP clients the URL query is also sent to the server as
|
|
1595
|
+
# the request query, so prefer `verify:` (or {Iodine::TLS#trust}) there;
|
|
1596
|
+
# - `tls: Iodine::TLS.new.trust` (system trust store) or
|
|
1597
|
+
# `tls: Iodine::TLS.new.trust("ca.pem")`.
|
|
1598
|
+
#
|
|
1599
|
+
# Once trust is set, the certificate must also match the URL's host. Note
|
|
1600
|
+
# that `verify: true` and `trust` URL hints update the {Iodine::TLS} object
|
|
1601
|
+
# passed as `tls:` (later connections using it verify too). `verify:` is
|
|
1602
|
+
# ignored for non-TLS connections.
|
|
1603
|
+
#
|
|
1604
|
+
# @example Verified HTTPS request (system trust store)
|
|
1605
|
+
# Iodine::Connection.new("https://example.com/", handler: MyHandler, verify: true)
|
|
1606
|
+
#
|
|
1607
|
+
# @example Verified with a private CA
|
|
1608
|
+
# Iodine::Connection.new("tls://service.internal:4000/?trust=./internal-ca.pem", handler: MyHandler)
|
|
1609
|
+
#
|
|
1569
1610
|
# @example WebSocket client with embedded TLS
|
|
1570
1611
|
# Iodine::Connection.new("wss://example.com/socket", handler: MyHandler, tls_io: :iodine)
|
|
1571
1612
|
#
|
|
1572
1613
|
# @example WebSocket client with OpenSSL
|
|
1573
1614
|
# Iodine::Connection.new("wss://example.com/socket", handler: MyHandler, tls_io: :openssl)
|
|
1574
|
-
def initialize(url, handler: nil, tls: nil, tls_io: nil, headers: nil, cookies: nil, body: nil, method: nil); end
|
|
1615
|
+
def initialize(url, handler: nil, tls: nil, tls_io: nil, headers: nil, cookies: nil, body: nil, method: nil, verify: false); end
|
|
1575
1616
|
|
|
1576
1617
|
# Unless `env` is manually set, Iodine will attempt to create a default `env` object that will follow the Rack Server specification for HTTP connections.
|
|
1577
1618
|
#
|
|
@@ -1846,6 +1887,11 @@ module Iodine
|
|
|
1846
1887
|
# @return [Integer] the current position
|
|
1847
1888
|
def seek(pos = nil); end
|
|
1848
1889
|
|
|
1890
|
+
# (HTTP Only) Moves the body's read position back to the start, so `rack.input` can be read again.
|
|
1891
|
+
#
|
|
1892
|
+
# @return [Integer] the new position (always `0`)
|
|
1893
|
+
def rewind; end
|
|
1894
|
+
|
|
1849
1895
|
# (HTTP Only) Releases the body's resources, freeing the in-memory buffer and closing any temporary file.
|
|
1850
1896
|
#
|
|
1851
1897
|
# Subsequent body reads will return `nil` and `length` will return `0`. The connection itself remains open.
|
|
@@ -1986,10 +2032,21 @@ module Iodine
|
|
|
1986
2032
|
|
|
1987
2033
|
# @!group Misc
|
|
1988
2034
|
|
|
1989
|
-
# Returns the raw peer IP address
|
|
1990
|
-
#
|
|
2035
|
+
# Returns the raw peer IP address (without a port), or the socket path for
|
|
2036
|
+
# named Unix sockets.
|
|
2037
|
+
# @return [String, nil]
|
|
1991
2038
|
def peer_addr; end
|
|
1992
2039
|
|
|
2040
|
+
# Returns the local (this side's) IP address (without a port), or the
|
|
2041
|
+
# socket path for named Unix sockets.
|
|
2042
|
+
#
|
|
2043
|
+
# This is a socket-level value, available for HTTP, WebSocket, SSE and raw
|
|
2044
|
+
# connections alike. Behind a proxy or load balancer it reports the address
|
|
2045
|
+
# the proxy connected to, not the host the client requested (use the
|
|
2046
|
+
# `Host` header for that).
|
|
2047
|
+
# @return [String, nil]
|
|
2048
|
+
def local_addr; end
|
|
2049
|
+
|
|
1993
2050
|
# Returns the published peer address (may differ with proxies).
|
|
1994
2051
|
# @return [String]
|
|
1995
2052
|
def from; end
|
|
@@ -2227,9 +2284,27 @@ module Iodine
|
|
|
2227
2284
|
|
|
2228
2285
|
# Assigns the TLS context a public certificate, allowing remote parties to validate the connection's identity.
|
|
2229
2286
|
#
|
|
2230
|
-
#
|
|
2287
|
+
# On servers, a self signed certificate (ECDSA P-256 on the `:iodine` backend)
|
|
2288
|
+
# is created for `name` if either (or both) of the `cert` (public certificate) or
|
|
2289
|
+
# `key` (private key) arguments are missing. This is fine for development, but
|
|
2290
|
+
# browsers will warn - use a CA issued certificate in production.
|
|
2231
2291
|
#
|
|
2232
|
-
#
|
|
2292
|
+
# Servers may hold several certificates; both TLS backends select one per
|
|
2293
|
+
# handshake using the client's SNI host name:
|
|
2294
|
+
#
|
|
2295
|
+
# 1. a case-insensitive exact match of `name`;
|
|
2296
|
+
# 2. else a single-label wildcard (`*.example.com` matches `www.example.com`,
|
|
2297
|
+
# but neither `example.com` nor `a.b.example.com`);
|
|
2298
|
+
# 3. else the default certificate: the one added with an empty `name`, else the
|
|
2299
|
+
# first one added.
|
|
2300
|
+
#
|
|
2301
|
+
# Re-adding a `name` replaces its certificate. An omitted `name` defaults to
|
|
2302
|
+
# `"localhost"`.
|
|
2303
|
+
#
|
|
2304
|
+
# On clients, the (default) certificate is presented when the server requests
|
|
2305
|
+
# one (mutual TLS / client certificate authentication), with its whole chain.
|
|
2306
|
+
# Use client certificates with PEM files: a name-only client entry presents no
|
|
2307
|
+
# certificate on the `:iodine` backend.
|
|
2233
2308
|
#
|
|
2234
2309
|
# Iodine::TLS#add_cert(name = nil,
|
|
2235
2310
|
# cert = nil,
|
|
@@ -2638,6 +2713,7 @@ module Iodine
|
|
|
2638
2713
|
# - {ChaCha20Poly1305} - AEAD symmetric encryption (12-byte nonce)
|
|
2639
2714
|
# - {XChaCha20Poly1305} - AEAD symmetric encryption (24-byte nonce, safe for random)
|
|
2640
2715
|
# - {Ed25519} - Digital signatures (with key conversion to X25519)
|
|
2716
|
+
# - {P256} / {P384} - ECDSA digital signatures (ES256 / ES384, OpenSSL compatible)
|
|
2641
2717
|
# - {X25519} - Key exchange and public-key encryption (ECIES with ChaCha20, AES-128, or AES-256)
|
|
2642
2718
|
# - {HKDF} - Key derivation (RFC 5869)
|
|
2643
2719
|
# - {X25519MLKEM768} - Post-quantum hybrid key encapsulation (X25519 + ML-KEM-768)
|
|
@@ -2877,6 +2953,97 @@ module Iodine
|
|
|
2877
2953
|
def self.to_x25519_public(ed_public_key:); end
|
|
2878
2954
|
end
|
|
2879
2955
|
|
|
2956
|
+
# ECDSA P-256 digital signatures (ES256: SHA-256, 128-bit security level).
|
|
2957
|
+
#
|
|
2958
|
+
# Interoperable with OpenSSL / JOSE tooling: secret keys are 32-byte
|
|
2959
|
+
# big-endian scalars, public keys are uncompressed SEC 1 points
|
|
2960
|
+
# (`0x04 || x || y`, 65 bytes; {verify} also accepts 33-byte compressed
|
|
2961
|
+
# points) and signatures are DER encoded (at most 72 bytes; JWS ES256
|
|
2962
|
+
# uses raw `r || s` instead). Messages are hashed with SHA-256 internally.
|
|
2963
|
+
#
|
|
2964
|
+
# Signatures are randomized (a fresh nonce per signature), so signing the
|
|
2965
|
+
# same data twice produces different, equally valid signatures.
|
|
2966
|
+
#
|
|
2967
|
+
# @note facil.io's P-256 / P-384 implementation has not been independently
|
|
2968
|
+
# audited. Prefer {Ed25519} when you control both sides.
|
|
2969
|
+
module P256
|
|
2970
|
+
# Generates a new P-256 key pair.
|
|
2971
|
+
#
|
|
2972
|
+
# @return [Array<String, String>] [secret_key (32 bytes), public_key (65 bytes)]
|
|
2973
|
+
#
|
|
2974
|
+
# @example
|
|
2975
|
+
# secret_key, public_key = Iodine::Base::Crypto::P256.keypair
|
|
2976
|
+
def self.keypair; end
|
|
2977
|
+
|
|
2978
|
+
# Derives the (uncompressed) public key from a P-256 secret key.
|
|
2979
|
+
#
|
|
2980
|
+
# @param secret_key [String] 32-byte secret key
|
|
2981
|
+
# @return [String] 65-byte public key
|
|
2982
|
+
# @raise [ArgumentError] if secret_key is not 32 bytes or out of range
|
|
2983
|
+
def self.public_key(secret_key:); end
|
|
2984
|
+
|
|
2985
|
+
# Signs a message (hashed with SHA-256) using ECDSA P-256.
|
|
2986
|
+
#
|
|
2987
|
+
# @param data [String] Message to sign
|
|
2988
|
+
# @param secret_key [String] 32-byte secret key
|
|
2989
|
+
# @return [String] DER encoded signature
|
|
2990
|
+
# @raise [ArgumentError] if secret_key is not 32 bytes or invalid
|
|
2991
|
+
#
|
|
2992
|
+
# @example
|
|
2993
|
+
# signature = Iodine::Base::Crypto::P256.sign("data", secret_key: sk)
|
|
2994
|
+
def self.sign(data, secret_key:); end
|
|
2995
|
+
|
|
2996
|
+
# Verifies a DER encoded ECDSA P-256 signature.
|
|
2997
|
+
#
|
|
2998
|
+
# @param data [String] Original message
|
|
2999
|
+
# @param signature [String] DER encoded signature
|
|
3000
|
+
# @param public_key [String] 65-byte (or 33-byte compressed) public key
|
|
3001
|
+
# @return [Boolean] `true` if valid, `false` otherwise (including
|
|
3002
|
+
# malformed signatures or keys)
|
|
3003
|
+
#
|
|
3004
|
+
# @example
|
|
3005
|
+
# valid = Iodine::Base::Crypto::P256.verify("data", signature, public_key: pk)
|
|
3006
|
+
def self.verify(data, signature, public_key:); end
|
|
3007
|
+
end
|
|
3008
|
+
|
|
3009
|
+
# ECDSA P-384 digital signatures (ES384: SHA-384, 192-bit security level).
|
|
3010
|
+
#
|
|
3011
|
+
# Same API and encodings as {P256}, with 48-byte secret keys, 97-byte
|
|
3012
|
+
# uncompressed public keys (49-byte compressed accepted by {verify}),
|
|
3013
|
+
# DER signatures of at most 104 bytes, and SHA-384 message hashing.
|
|
3014
|
+
#
|
|
3015
|
+
# @note facil.io's P-256 / P-384 implementation has not been independently
|
|
3016
|
+
# audited. Prefer {Ed25519} when you control both sides.
|
|
3017
|
+
module P384
|
|
3018
|
+
# Generates a new P-384 key pair.
|
|
3019
|
+
#
|
|
3020
|
+
# @return [Array<String, String>] [secret_key (48 bytes), public_key (97 bytes)]
|
|
3021
|
+
def self.keypair; end
|
|
3022
|
+
|
|
3023
|
+
# Derives the (uncompressed) public key from a P-384 secret key.
|
|
3024
|
+
#
|
|
3025
|
+
# @param secret_key [String] 48-byte secret key
|
|
3026
|
+
# @return [String] 97-byte public key
|
|
3027
|
+
# @raise [ArgumentError] if secret_key is not 48 bytes or out of range
|
|
3028
|
+
def self.public_key(secret_key:); end
|
|
3029
|
+
|
|
3030
|
+
# Signs a message (hashed with SHA-384) using ECDSA P-384.
|
|
3031
|
+
#
|
|
3032
|
+
# @param data [String] Message to sign
|
|
3033
|
+
# @param secret_key [String] 48-byte secret key
|
|
3034
|
+
# @return [String] DER encoded signature
|
|
3035
|
+
# @raise [ArgumentError] if secret_key is not 48 bytes or invalid
|
|
3036
|
+
def self.sign(data, secret_key:); end
|
|
3037
|
+
|
|
3038
|
+
# Verifies a DER encoded ECDSA P-384 signature.
|
|
3039
|
+
#
|
|
3040
|
+
# @param data [String] Original message
|
|
3041
|
+
# @param signature [String] DER encoded signature
|
|
3042
|
+
# @param public_key [String] 97-byte (or 49-byte compressed) public key
|
|
3043
|
+
# @return [Boolean] `true` if valid, `false` otherwise
|
|
3044
|
+
def self.verify(data, signature, public_key:); end
|
|
3045
|
+
end
|
|
3046
|
+
|
|
2880
3047
|
# X25519 key exchange (ECDH) and public-key encryption (ECIES).
|
|
2881
3048
|
#
|
|
2882
3049
|
# X25519 provides secure key agreement and can be combined with
|
data/lib/iodine/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: iodine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Boaz Segev
|
|
@@ -134,7 +134,7 @@ metadata:
|
|
|
134
134
|
homepage_uri: https://github.com/boazsegev/iodine
|
|
135
135
|
source_code_uri: https://github.com/boazsegev/iodine
|
|
136
136
|
changelog_uri: https://github.com/boazsegev/iodine/blob/master/CHANGELOG.md
|
|
137
|
-
post_install_message: Thank you for installing Iodine 0.8.
|
|
137
|
+
post_install_message: Thank you for installing Iodine 0.8.6.
|
|
138
138
|
rdoc_options: []
|
|
139
139
|
require_paths:
|
|
140
140
|
- lib
|