Class: Ccrypto::Java::CrystalKyberEngine
- Inherits:
-
Object
- Object
- Ccrypto::Java::CrystalKyberEngine
- Defined in:
- lib/ccrypto/java/engines/crystal_kyber_engine.rb
Overview
class CrystalKyberKeyBundle
Class Method Summary collapse
- .find_config(conf) ⇒ Object
- .get_available_session_keysize ⇒ Object
- .get_session_keysize_param(keysize, with_aes = false) ⇒ Object
- .supported_configs ⇒ Object
- .supported_params ⇒ Object
Instance Method Summary collapse
- #generate_keypair(&block) ⇒ Object
-
#initialize(*args, &block) ⇒ CrystalKyberEngine
constructor
A new instance of CrystalKyberEngine.
Constructor Details
#initialize(*args, &block) ⇒ CrystalKyberEngine
Returns a new instance of CrystalKyberEngine.
242 243 244 245 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 242 def initialize(*args, &block) @config = args.first raise KeypairEngineException, "1st parameter must be a #{Ccrypto::KeypairConfig.class} object" if not @config.is_a?(Ccrypto::KeypairConfig) end |
Class Method Details
.find_config(conf) ⇒ Object
221 222 223 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 221 def self.find_config(conf) supported_configs.select { |k,v| k == conf }.first[1] end |
.get_available_session_keysize ⇒ Object
225 226 227 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 225 def self.get_available_session_keysize [512, 768, 1024].freeze end |
.get_session_keysize_param(keysize, with_aes = false) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 229 def self.get_session_keysize_param(keysize, with_aes = false) case keysize.to_i when 512, 768, 1024 if with_aes supported_configs["kyber#{keysize.to_i}_aes".to_sym] else supported_configs["kyber#{keysize.to_i}".to_sym] end else raise KeypairEngineException, "Crystal Kyber only has keysizes of 512,768 and 1024" end end |
.supported_configs ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 202 def self.supported_configs if @supportedConfig.nil? @supportedConfig = {} { kyber512: KyberParameters::kyber512, kyber768: KyberParameters::kyber768, kyber1024: KyberParameters::kyber1024, kyber512_aes: KyberParameters::kyber512_aes, kyber768_aes: KyberParameters::kyber768_aes, kyber1024_aes: KyberParameters::kyber1024_aes, }.each do |k,kp| conf = Ccrypto::CrystalKyberConfig.new(k) conf.provider_config = { params: kp } @supportedConfig[k] = conf end end @supportedConfig.freeze end |
.supported_params ⇒ Object
198 199 200 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 198 def self.supported_params supported_configs.keys end |
Instance Method Details
#generate_keypair(&block) ⇒ Object
247 248 249 250 251 252 253 254 255 |
# File 'lib/ccrypto/java/engines/crystal_kyber_engine.rb', line 247 def generate_keypair(&block) rand = java.security.SecureRandom.getInstanceStrong kpg = org.bouncycastle.pqc.crypto.crystals.kyber.KyberKeyPairGenerator.new kpg.init(KyberKeyGenerationParameters.new(rand, @config.provider_config[:params])) CrystalKyberKeyBundle.new(kpg.generateKeyPair(), @config) end |