diff options
author | Bruce Momjian | 2005-08-13 02:06:21 +0000 |
---|---|---|
committer | Bruce Momjian | 2005-08-13 02:06:21 +0000 |
commit | 87688ddf87a384f7107240bdd8b1754010d774b5 (patch) | |
tree | 23e9c4d6baad7734efad9af4e6972602af98347a /contrib/pgcrypto/pgp.h | |
parent | abecf1afc206e1f46d9202c7ba2122f06a799f8d (diff) |
The large one adds support for RSA keys and reorganizes
the pubkey functions a bit. The actual RSA-specific code
there is tiny, most of the patch consists of reorg of the
pubkey code, as lots of it was written as elgamal-only.
---------------------------------------------------------------------------
The SHLIB section was copy-pasted from somewhere and contains
several unnecessary libs. This cleans it up a bit.
-lcrypt
we don't use system crypt()
-lssl, -lssleay32
no SSL here
-lz in win32 section
already added on previous line
-ldes
The chance anybody has it is pretty low.
And the chance pgcrypto works with it is even lower.
Also trim the win32 section.
---------------------------------------------------------------------------
It is already disabled in Makefile, remove code too.
---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
o pgp_mpi_free: Accept NULLs
o pgp_mpi_cksum: result should be 16bit
o Remove function name from error messages - to be similar to other
SQL functions, and it does not match anyway the called function
o remove couple junk lines
---------------------------------------------------------------------------
o Support for RSA encryption
o Big reorg to better separate generic and algorithm-specific code.
o Regression tests for RSA.
---------------------------------------------------------------------------
o Tom stuck a CVS id into file. I doubt the usefulness of it,
but if it needs to be in the file then rather at the end.
Also tag it as comment for asciidoc.
o Mention bytea vs. text difference
o Couple clarifications
---------------------------------------------------------------------------
There is a choice whether to update it with pgp functions or
remove it. I decided to remove it, updating is pointless.
I've tried to keep the core of pgcrypto relatively independent
from main PostgreSQL, to make it easy to use externally if needed,
and that is good. Eg. that made development of PGP functions much
nicer.
But I have no plans to release it as generic library, so keeping such
doc
up-to-date is waste of time. If anyone is interested in using it in
other products, he can probably bother to read the source too.
Commented source is another thing - I'll try to make another pass
over code to see if there is anything non-obvious that would need
more comments.
---------------------------------------------------------------------------
Marko Kreen
Diffstat (limited to 'contrib/pgcrypto/pgp.h')
-rw-r--r-- | contrib/pgcrypto/pgp.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/contrib/pgcrypto/pgp.h b/contrib/pgcrypto/pgp.h index 93a06d46f22..769a248d18e 100644 --- a/contrib/pgcrypto/pgp.h +++ b/contrib/pgcrypto/pgp.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.2 2005/07/18 17:09:01 tgl Exp $ + * $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.3 2005/08/13 02:06:20 momjian Exp $ */ enum @@ -173,14 +173,44 @@ struct PGP_PubKey { uint8 ver; uint8 time[4]; uint8 algo; - /* public */ - PGP_MPI *elg_p; - PGP_MPI *elg_g; - PGP_MPI *elg_y; - /* secret */ - PGP_MPI *elg_x; + + /* public part */ + union { + struct { + PGP_MPI *p; + PGP_MPI *g; + PGP_MPI *y; + } elg; + struct { + PGP_MPI *n; + PGP_MPI *e; + } rsa; + struct { + PGP_MPI *p; + PGP_MPI *q; + PGP_MPI *g; + PGP_MPI *y; + } dsa; + } pub; + + /* secret part */ + union { + struct { + PGP_MPI *x; + } elg; + struct { + PGP_MPI *d; + PGP_MPI *p; + PGP_MPI *q; + PGP_MPI *u; + } rsa; + struct { + PGP_MPI *x; + } dsa; + } sec; uint8 key_id[8]; + int can_encrypt; }; int pgp_init(PGP_Context ** ctx); @@ -240,7 +270,7 @@ int pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src); int pgp_key_alloc(PGP_PubKey **pk_p); void pgp_key_free(PGP_PubKey *pk); -int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey *pk); +int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p); int pgp_parse_pubenc_sesskey(PGP_Context *ctx, PullFilter *pkt); int pgp_create_pkt_reader(PullFilter **pf_p, PullFilter *src, int len, @@ -266,6 +296,8 @@ int pgp_elgamal_encrypt(PGP_PubKey *pk, PGP_MPI *m, PGP_MPI **c1, PGP_MPI **c2); int pgp_elgamal_decrypt(PGP_PubKey *pk, PGP_MPI *c1, PGP_MPI *c2, PGP_MPI **m); +int pgp_rsa_encrypt(PGP_PubKey *pk, PGP_MPI *m, PGP_MPI **c); +int pgp_rsa_decrypt(PGP_PubKey *pk, PGP_MPI *c, PGP_MPI **m); extern struct PullFilterOps pgp_decrypt_filter; |