pq_crypto 0.6.0 → 0.6.2
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 +12 -0
- data/SECURITY.md +7 -0
- data/ext/pqcrypto/extconf.rb +2 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +139 -0
- data/ext/pqcrypto/pqcrypto_secure.c +532 -0
- data/ext/pqcrypto/pqcrypto_secure.h +20 -0
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +4 -4
- data/ext/pqcrypto/vendor/mldsa-native/README.md +23 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +114 -58
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +498 -461
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +145 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +456 -422
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +47 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +26 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +56 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +17 -24
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +33 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +67 -87
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +19 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +13 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +84 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +6 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +22 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +16 -10
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +2 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +4 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +60 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +48 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +18 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +658 -582
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +5 -100
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +26 -25
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +334 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +8 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/{xkcp.h → keccak_f1600_x4_avx2.h} +11 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +44 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +454 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +37 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +213 -196
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +248 -64
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S +84 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S +86 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S +103 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S +111 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S +75 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +23 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S +137 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +520 -516
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +34 -33
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +202 -242
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +25 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +112 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S +238 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S +190 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +9 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +10 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +130 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +109 -180
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +169 -150
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +56 -40
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +149 -164
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +52 -57
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +132 -167
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +57 -424
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +167 -474
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +308 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +22 -29
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +37 -43
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +511 -367
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +456 -417
- data/lib/pq_crypto/hybrid_kem.rb +1 -1
- data/lib/pq_crypto/internal.rb +23 -0
- data/lib/pq_crypto/kem.rb +27 -34
- data/lib/pq_crypto/pkcs8/der.rb +68 -0
- data/lib/pq_crypto/pkcs8/private_key_choice.rb +186 -0
- data/lib/pq_crypto/pkcs8.rb +51 -468
- data/lib/pq_crypto/serialization.rb +19 -29
- data/lib/pq_crypto/signature.rb +28 -35
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +10 -0
- data/script/vendor_libs.rb +3 -3
- metadata +44 -35
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +0 -376
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +0 -204
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +0 -259
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +0 -1077
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +0 -987
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +0 -488
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +0 -16
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +0 -753
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +0 -129
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +0 -145
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +0 -177
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +0 -653
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +0 -79
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +0 -53
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +0 -55
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +0 -85
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +0 -102
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +0 -110
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +0 -72
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +0 -69
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +0 -189
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +0 -135
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +0 -128
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +0 -2311
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +0 -2383
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +0 -239
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +0 -131
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +0 -139
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +0 -155
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +0 -187
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +0 -61
data/lib/pq_crypto/signature.rb
CHANGED
|
@@ -189,7 +189,7 @@ module PQCrypto
|
|
|
189
189
|
builder = PQCrypto.__send__(:_native_mldsa_mu_builder_new, tr, context)
|
|
190
190
|
builder_consumed = false
|
|
191
191
|
mu = nil
|
|
192
|
-
sig_bytes =
|
|
192
|
+
sig_bytes = Internal.binary_string(signature)
|
|
193
193
|
begin
|
|
194
194
|
_drain_io_into_builder(io, builder, chunk_size)
|
|
195
195
|
mu = PQCrypto.__send__(:_native_mldsa_mu_builder_finalize, builder)
|
|
@@ -230,7 +230,7 @@ module PQCrypto
|
|
|
230
230
|
end
|
|
231
231
|
|
|
232
232
|
def validate_context!(context)
|
|
233
|
-
ctx =
|
|
233
|
+
ctx = Internal.binary_string(context)
|
|
234
234
|
if ctx.bytesize > 255
|
|
235
235
|
raise ArgumentError, "context must be at most 255 bytes (FIPS 204)"
|
|
236
236
|
end
|
|
@@ -264,7 +264,7 @@ module PQCrypto
|
|
|
264
264
|
|
|
265
265
|
def initialize(algorithm, bytes)
|
|
266
266
|
@algorithm = algorithm
|
|
267
|
-
@bytes =
|
|
267
|
+
@bytes = Internal.binary_string(bytes)
|
|
268
268
|
validate_length!
|
|
269
269
|
end
|
|
270
270
|
|
|
@@ -291,7 +291,7 @@ module PQCrypto
|
|
|
291
291
|
def verify(message, signature, context: "".b)
|
|
292
292
|
context = Signature.send(:validate_context!, context)
|
|
293
293
|
begin
|
|
294
|
-
PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :verify),
|
|
294
|
+
PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :verify), Internal.binary_string(message), Internal.binary_string(signature), @bytes, context)
|
|
295
295
|
rescue ArgumentError => e
|
|
296
296
|
raise InvalidKeyError, e.message
|
|
297
297
|
end
|
|
@@ -315,7 +315,7 @@ module PQCrypto
|
|
|
315
315
|
|
|
316
316
|
def ==(other)
|
|
317
317
|
return false unless other.is_a?(PublicKey) && other.algorithm == algorithm
|
|
318
|
-
|
|
318
|
+
Internal.constant_time_equal?(other.send(:bytes_for_native), @bytes)
|
|
319
319
|
end
|
|
320
320
|
|
|
321
321
|
alias eql? ==
|
|
@@ -345,14 +345,14 @@ module PQCrypto
|
|
|
345
345
|
|
|
346
346
|
def initialize(algorithm, bytes, seed: nil)
|
|
347
347
|
@algorithm = algorithm
|
|
348
|
-
@bytes =
|
|
349
|
-
@seed = seed.nil? ? nil :
|
|
348
|
+
@bytes = Internal.binary_string(bytes)
|
|
349
|
+
@seed = seed.nil? ? nil : Internal.binary_string(seed)
|
|
350
350
|
validate_length!
|
|
351
351
|
validate_seed_length! if @seed
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
def self.from_seed(algorithm, seed)
|
|
355
|
-
seed_bytes =
|
|
355
|
+
seed_bytes = Internal.binary_string(seed)
|
|
356
356
|
_public_key, expanded = PQCrypto.__send__(Signature.send(:native_method_for, algorithm, :keypair_from_seed), seed_bytes)
|
|
357
357
|
new(algorithm, expanded, seed: seed_bytes)
|
|
358
358
|
rescue ArgumentError => e
|
|
@@ -372,39 +372,17 @@ module PQCrypto
|
|
|
372
372
|
end
|
|
373
373
|
|
|
374
374
|
def to_pkcs8_der(format: :expanded, passphrase: nil, iterations: PKCS8::ENCRYPTED_PKCS8_DEFAULT_ITERATIONS)
|
|
375
|
-
|
|
376
|
-
when :expanded
|
|
377
|
-
PKCS8.encode_der(@algorithm, @bytes, format: :expanded, passphrase: passphrase, iterations: iterations)
|
|
378
|
-
when :seed
|
|
379
|
-
ensure_seed_available!(format)
|
|
380
|
-
PKCS8.encode_der(@algorithm, @seed, format: :seed, passphrase: passphrase, iterations: iterations)
|
|
381
|
-
when :both
|
|
382
|
-
ensure_seed_available!(format)
|
|
383
|
-
PKCS8.encode_der(@algorithm, [@seed, @bytes], format: :both, passphrase: passphrase, iterations: iterations)
|
|
384
|
-
else
|
|
385
|
-
raise SerializationError, "Unsupported PKCS#8 private key format: #{format.inspect}"
|
|
386
|
-
end
|
|
375
|
+
PKCS8.encode_der(@algorithm, pkcs8_material(format), format: format, passphrase: passphrase, iterations: iterations)
|
|
387
376
|
end
|
|
388
377
|
|
|
389
378
|
def to_pkcs8_pem(format: :expanded, passphrase: nil, iterations: PKCS8::ENCRYPTED_PKCS8_DEFAULT_ITERATIONS)
|
|
390
|
-
|
|
391
|
-
when :expanded
|
|
392
|
-
PKCS8.encode_pem(@algorithm, @bytes, format: :expanded, passphrase: passphrase, iterations: iterations)
|
|
393
|
-
when :seed
|
|
394
|
-
ensure_seed_available!(format)
|
|
395
|
-
PKCS8.encode_pem(@algorithm, @seed, format: :seed, passphrase: passphrase, iterations: iterations)
|
|
396
|
-
when :both
|
|
397
|
-
ensure_seed_available!(format)
|
|
398
|
-
PKCS8.encode_pem(@algorithm, [@seed, @bytes], format: :both, passphrase: passphrase, iterations: iterations)
|
|
399
|
-
else
|
|
400
|
-
raise SerializationError, "Unsupported PKCS#8 private key format: #{format.inspect}"
|
|
401
|
-
end
|
|
379
|
+
PKCS8.encode_pem(@algorithm, pkcs8_material(format), format: format, passphrase: passphrase, iterations: iterations)
|
|
402
380
|
end
|
|
403
381
|
|
|
404
382
|
def sign(message, context: "".b)
|
|
405
383
|
context = Signature.send(:validate_context!, context)
|
|
406
384
|
begin
|
|
407
|
-
PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :sign),
|
|
385
|
+
PQCrypto.__send__(Signature.send(:native_method_for, @algorithm, :sign), Internal.binary_string(message), @bytes, context)
|
|
408
386
|
rescue ArgumentError => e
|
|
409
387
|
raise InvalidKeyError, e.message
|
|
410
388
|
end
|
|
@@ -422,7 +400,7 @@ module PQCrypto
|
|
|
422
400
|
|
|
423
401
|
def ==(other)
|
|
424
402
|
return false unless other.is_a?(SecretKey) && other.algorithm == algorithm
|
|
425
|
-
|
|
403
|
+
Internal.constant_time_equal?(other.send(:bytes_for_native), @bytes)
|
|
426
404
|
end
|
|
427
405
|
|
|
428
406
|
alias eql? ==
|
|
@@ -446,8 +424,23 @@ module PQCrypto
|
|
|
446
424
|
raise InvalidKeyError, "Invalid signature secret key length" unless @bytes.bytesize == expected
|
|
447
425
|
end
|
|
448
426
|
|
|
427
|
+
def pkcs8_material(format)
|
|
428
|
+
case format
|
|
429
|
+
when :expanded
|
|
430
|
+
@bytes
|
|
431
|
+
when :seed
|
|
432
|
+
ensure_seed_available!(format)
|
|
433
|
+
@seed
|
|
434
|
+
when :both
|
|
435
|
+
ensure_seed_available!(format)
|
|
436
|
+
[@seed, @bytes]
|
|
437
|
+
else
|
|
438
|
+
raise SerializationError, "Unsupported PKCS#8 private key format: #{format.inspect}"
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
|
|
449
442
|
def validate_seed_length!
|
|
450
|
-
expected = PKCS8::
|
|
443
|
+
expected = PKCS8::PrivateKeyChoice.seed_bytes(@algorithm)
|
|
451
444
|
raise InvalidKeyError, "Invalid signature seed length" unless @seed.bytesize == expected
|
|
452
445
|
end
|
|
453
446
|
|
data/lib/pq_crypto/version.rb
CHANGED
data/lib/pq_crypto.rb
CHANGED
|
@@ -30,9 +30,12 @@ end
|
|
|
30
30
|
|
|
31
31
|
require_relative "pq_crypto/errors"
|
|
32
32
|
require_relative "pq_crypto/version"
|
|
33
|
+
require_relative "pq_crypto/internal"
|
|
33
34
|
require_relative "pq_crypto/algorithm_registry"
|
|
34
35
|
require_relative "pq_crypto/serialization"
|
|
35
36
|
require_relative "pq_crypto/spki"
|
|
37
|
+
require_relative "pq_crypto/pkcs8/der"
|
|
38
|
+
require_relative "pq_crypto/pkcs8/private_key_choice"
|
|
36
39
|
require_relative "pq_crypto/pkcs8"
|
|
37
40
|
require_relative "pq_crypto/kem"
|
|
38
41
|
require_relative "pq_crypto/signature"
|
|
@@ -93,6 +96,13 @@ module PQCrypto
|
|
|
93
96
|
public_key_from_pqc_container_pem
|
|
94
97
|
secret_key_from_pqc_container_der
|
|
95
98
|
secret_key_from_pqc_container_pem
|
|
99
|
+
pkcs8_private_key_info_to_der
|
|
100
|
+
pkcs8_private_key_info_from_der
|
|
101
|
+
pkcs8_encrypt_der
|
|
102
|
+
pkcs8_decrypt_der
|
|
103
|
+
pkcs8_encrypted_der?
|
|
104
|
+
pkcs8_der_to_pem
|
|
105
|
+
pkcs8_pem_to_der
|
|
96
106
|
__test_ml_kem_keypair_from_seed
|
|
97
107
|
__test_ml_kem_encapsulate_from_seed
|
|
98
108
|
__test_ml_kem_512_encapsulate_from_seed
|
data/script/vendor_libs.rb
CHANGED
|
@@ -21,9 +21,9 @@ PINS = {
|
|
|
21
21
|
},
|
|
22
22
|
mldsa: {
|
|
23
23
|
repo: "https://github.com/pq-code-package/mldsa-native.git",
|
|
24
|
-
ref: "v1.0.0-
|
|
25
|
-
commit: "
|
|
26
|
-
tree_sha256: "
|
|
24
|
+
ref: "v1.0.0-beta2",
|
|
25
|
+
commit: "9b0ee84f4cf399043eca59eca4e5f8531ca1d61b",
|
|
26
|
+
tree_sha256: "2887f59926c18a877e8c5a5e30727e84497c357032093d00d7135aedf53f011e",
|
|
27
27
|
target: "mldsa-native",
|
|
28
28
|
source_dir: "mldsa"
|
|
29
29
|
}
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pq_crypto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roman Haydarov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- ext/pqcrypto/vendor/mldsa-native/META.yml
|
|
85
85
|
- ext/pqcrypto/vendor/mldsa-native/README.md
|
|
86
86
|
- ext/pqcrypto/vendor/mldsa-native/SECURITY.md
|
|
87
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/README.md
|
|
87
88
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c
|
|
88
89
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h
|
|
89
90
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S
|
|
@@ -102,11 +103,11 @@ files:
|
|
|
102
103
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h
|
|
103
104
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h
|
|
104
105
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h
|
|
105
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/
|
|
106
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/
|
|
107
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/
|
|
108
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/
|
|
109
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/
|
|
106
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S
|
|
107
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S
|
|
108
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S
|
|
109
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S
|
|
110
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S
|
|
110
111
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c
|
|
111
112
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h
|
|
112
113
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h
|
|
@@ -120,31 +121,34 @@ files:
|
|
|
120
121
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S
|
|
121
122
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c
|
|
122
123
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c
|
|
124
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S
|
|
125
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S
|
|
123
126
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h
|
|
124
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/
|
|
125
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/
|
|
126
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/
|
|
127
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h
|
|
128
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h
|
|
129
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S
|
|
130
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccakf1600_constants.c
|
|
127
131
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h
|
|
128
132
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c
|
|
129
133
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h
|
|
130
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
131
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
132
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
133
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
134
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
135
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
136
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
137
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
138
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
139
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
140
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
141
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
142
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
143
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
134
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt_aarch64_asm.S
|
|
135
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S
|
|
136
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S
|
|
137
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S
|
|
138
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt_aarch64_asm.S
|
|
139
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery_aarch64_asm.S
|
|
140
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_aarch64_asm.S
|
|
141
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_aarch64_asm.S
|
|
142
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_aarch64_asm.S
|
|
143
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_aarch64_asm.S
|
|
144
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_aarch64_asm.S
|
|
145
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_aarch64_asm.S
|
|
146
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_aarch64_asm.S
|
|
147
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_aarch64_asm.S
|
|
144
148
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c
|
|
145
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
146
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
147
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/
|
|
149
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_aarch64_asm.S
|
|
150
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_aarch64_asm.S
|
|
151
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_aarch64_asm.S
|
|
148
152
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c
|
|
149
153
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c
|
|
150
154
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h
|
|
@@ -153,14 +157,14 @@ files:
|
|
|
153
157
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h
|
|
154
158
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c
|
|
155
159
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h
|
|
156
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
157
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
158
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
159
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
160
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
161
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
162
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
163
|
-
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/
|
|
160
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt_avx2_asm.S
|
|
161
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt_avx2_asm.S
|
|
162
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack_avx2_asm.S
|
|
163
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4_avx2_asm.S
|
|
164
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5_avx2_asm.S
|
|
165
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7_avx2_asm.S
|
|
166
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_avx2_asm.S
|
|
167
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2_asm.S
|
|
164
168
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c
|
|
165
169
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c
|
|
166
170
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c
|
|
@@ -181,6 +185,8 @@ files:
|
|
|
181
185
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h
|
|
182
186
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c
|
|
183
187
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h
|
|
188
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c
|
|
189
|
+
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h
|
|
184
190
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h
|
|
185
191
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h
|
|
186
192
|
- ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h
|
|
@@ -314,9 +320,12 @@ files:
|
|
|
314
320
|
- lib/pq_crypto/algorithm_registry.rb
|
|
315
321
|
- lib/pq_crypto/errors.rb
|
|
316
322
|
- lib/pq_crypto/hybrid_kem.rb
|
|
323
|
+
- lib/pq_crypto/internal.rb
|
|
317
324
|
- lib/pq_crypto/kem.rb
|
|
318
325
|
- lib/pq_crypto/key.rb
|
|
319
326
|
- lib/pq_crypto/pkcs8.rb
|
|
327
|
+
- lib/pq_crypto/pkcs8/der.rb
|
|
328
|
+
- lib/pq_crypto/pkcs8/private_key_choice.rb
|
|
320
329
|
- lib/pq_crypto/serialization.rb
|
|
321
330
|
- lib/pq_crypto/signature.rb
|
|
322
331
|
- lib/pq_crypto/spki.rb
|