Class: MLKEM::CLI
- Inherits:
-
Thor
- Object
- Thor
- MLKEM::CLI
- Defined in:
- lib/ml_kem/cli.rb
Overview
Command Line Interface (CLI) for ML-KEM key encapsulation mechanism. Supports key generation, encapsulation, and decapsulation via Thor commands.
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Ensures the CLI exits with a non-zero status code on failure.
Instance Method Summary collapse
-
#decaps ⇒ Object
Decapsulates a ciphertext to recover the shared secret using the private key.
-
#encaps ⇒ Object
Encapsulates a shared secret using the given public key.
-
#keygen ⇒ Object
Generates a public/private key pair and stores them in PEM format.
Class Method Details
.exit_on_failure? ⇒ Boolean
Ensures the CLI exits with a non-zero status code on failure
23 24 25 |
# File 'lib/ml_kem/cli.rb', line 23 def self.exit_on_failure? true end |
Instance Method Details
#decaps ⇒ Object
Decapsulates a ciphertext to recover the shared secret using the private key.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ml_kem/cli.rb', line 94 def decaps mlkem = create_mlkem_instance private_key_pem = File.read([:sk]) private_key = decode_pem(private_key_pem) ciphertext_base64 = File.read([:ciphertext]) ciphertext = Base64.decode64(ciphertext_base64) secret = mlkem.decaps(private_key, ciphertext) File.write([:sharedkey], Base64.strict_encode64(secret)) puts "Decapsulation complete. Shared secret written to #{[:sharedkey]}" end |
#encaps ⇒ Object
Encapsulates a shared secret using the given public key.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ml_kem/cli.rb', line 68 def encaps mlkem = create_mlkem_instance public_key_pem = File.read([:pk]) public_key = decode_pem(public_key_pem) secret, ciphertext = mlkem.encaps(public_key) File.write([:ciphertext], Base64.strict_encode64(ciphertext)) File.write([:sharedkey], Base64.strict_encode64(secret)) puts "Encapsulation complete:\n Ciphertext: #{[:ciphertext]}\n Shared Secret: #{[:sharedkey]}" end |
#keygen ⇒ Object
Generates a public/private key pair and stores them in PEM format.
45 46 47 48 49 50 51 52 53 |
# File 'lib/ml_kem/cli.rb', line 45 def keygen mlkem = create_mlkem_instance public_key, private_key = mlkem.keygen File.write([:pk], encode_pem(public_key, "PUBLIC KEY")) File.write([:sk], encode_pem(private_key, "PRIVATE KEY")) puts "Keys generated:\n Public Key: #{[:pk]}\n Private Key: #{[:sk]}" end |