[patch 3/7] Elgamal speedup

From: Marko Kreen <marko(at)l-t(dot)ee>
To: pgsql-patches(at)postgresql(dot)org
Subject: [patch 3/7] Elgamal speedup
Date: 2005-08-01 21:15:03
Message-ID: 20050801211513.351968000@grue
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

I was bit hasty making the random exponent 'k' a prime. Further researh
shows that Elgamal encryption has no specific needs in respect to k,
any random number is fine.

It is bit different for signing, there it needs to be 'relatively prime'
to p - 1, that means GCD(k, p-1) == 1, which is also a lot lighter than
full primality. As we don't do signing, this can be ignored.

This brings major speedup to Elgamal encryption.

Index: pgsql/contrib/pgcrypto/pgp-mpi-openssl.c
===================================================================
*** pgsql.orig/contrib/pgcrypto/pgp-mpi-openssl.c
--- pgsql/contrib/pgcrypto/pgp-mpi-openssl.c
*************** pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_
*** 120,126 ****
* generate k
*/
k_bits = decide_k_bits(BN_num_bits(p));
! if (!BN_generate_prime(k, k_bits, 0, NULL, NULL, NULL, NULL))
goto err;

/*
--- 120,126 ----
* generate k
*/
k_bits = decide_k_bits(BN_num_bits(p));
! if (!BN_rand(k, k_bits, 0, 0))
goto err;

/*

--

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Marko Kreen 2005-08-01 21:15:04 [patch 4/7] small fixes
Previous Message Marko Kreen 2005-08-01 21:15:02 [patch 2/7] remove last pieces of system crypt()