@@ -266,48 +266,6 @@ ossl_dh_get_params(VALUE self)
266
266
return hash ;
267
267
}
268
268
269
- /*
270
- * call-seq:
271
- * dh.public_key -> aDH
272
- *
273
- * Returns a new DH instance that carries just the public information, i.e.
274
- * the prime _p_ and the generator _g_, but no public/private key yet. Such
275
- * a pair may be generated using DH#generate_key!. The "public key" needed
276
- * for a key exchange with DH#compute_key is considered as per-session
277
- * information and may be retrieved with DH#pub_key once a key pair has
278
- * been generated.
279
- * If the current instance already contains private information (and thus a
280
- * valid public/private key pair), this information will no longer be present
281
- * in the new instance generated by DH#public_key. This feature is helpful for
282
- * publishing the Diffie-Hellman parameters without leaking any of the private
283
- * per-session information.
284
- *
285
- * === Example
286
- * dh = OpenSSL::PKey::DH.new(2048) # has public and private key set
287
- * public_key = dh.public_key # contains only prime and generator
288
- * parameters = public_key.to_der # it's safe to publish this
289
- */
290
- static VALUE
291
- ossl_dh_to_public_key (VALUE self )
292
- {
293
- EVP_PKEY * pkey ;
294
- DH * orig_dh , * dh ;
295
- VALUE obj ;
296
-
297
- obj = rb_obj_alloc (rb_obj_class (self ));
298
- GetPKey (obj , pkey );
299
-
300
- GetDH (self , orig_dh );
301
- dh = DHparams_dup (orig_dh );
302
- if (!dh )
303
- ossl_raise (eDHError , "DHparams_dup" );
304
- if (!EVP_PKEY_assign_DH (pkey , dh )) {
305
- DH_free (dh );
306
- ossl_raise (eDHError , "EVP_PKEY_assign_DH" );
307
- }
308
- return obj ;
309
- }
310
-
311
269
/*
312
270
* call-seq:
313
271
* dh.params_ok? -> true | false
@@ -384,14 +342,20 @@ Init_ossl_dh(void)
384
342
* The per-session private key, an OpenSSL::BN.
385
343
*
386
344
* === Example of a key exchange
387
- * dh1 = OpenSSL::PKey::DH.new(2048)
388
- * der = dh1.public_key.to_der #you may send this publicly to the participating party
389
- * dh2 = OpenSSL::PKey::DH.new(der)
390
- * dh2.generate_key! #generate the per-session key pair
391
- * symm_key1 = dh1.compute_key(dh2.pub_key)
392
- * symm_key2 = dh2.compute_key(dh1.pub_key)
345
+ * # you may send the parameters (der) and own public key (pub1) publicly
346
+ * # to the participating party
347
+ * dh1 = OpenSSL::PKey::DH.new(2048)
348
+ * der = dh1.to_der
349
+ * pub1 = dh1.pub_key
350
+ *
351
+ * # the other party generates its per-session key pair
352
+ * dhparams = OpenSSL::PKey::DH.new(der)
353
+ * dh2 = OpenSSL::PKey.generate_key(dhparams)
354
+ * pub2 = dh2.pub_key
393
355
*
394
- * puts symm_key1 == symm_key2 # => true
356
+ * symm_key1 = dh1.compute_key(pub2)
357
+ * symm_key2 = dh2.compute_key(pub1)
358
+ * puts symm_key1 == symm_key2 # => true
395
359
*/
396
360
cDH = rb_define_class_under (mPKey , "DH" , cPKey );
397
361
rb_define_method (cDH , "initialize" , ossl_dh_initialize , -1 );
@@ -402,7 +366,6 @@ Init_ossl_dh(void)
402
366
rb_define_alias (cDH , "to_pem" , "export" );
403
367
rb_define_alias (cDH , "to_s" , "export" );
404
368
rb_define_method (cDH , "to_der" , ossl_dh_to_der , 0 );
405
- rb_define_method (cDH , "public_key" , ossl_dh_to_public_key , 0 );
406
369
rb_define_method (cDH , "params_ok?" , ossl_dh_check_params , 0 );
407
370
408
371
DEF_OSSL_PKEY_BN (cDH , dh , p );
0 commit comments