Re: convert binary string to datum

From: Ron Peterson <ron(dot)peterson(at)yellowbank(dot)com>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: convert binary string to datum
Date: 2007-10-13 18:15:06
Message-ID: 20071013181506.GC18834@yellowbank.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2007-10-13_13:44:33-0400 Gregory Stark <stark(at)enterprisedb(dot)com>:
> "Ron Peterson" <ron(dot)peterson(at)yellowbank(dot)com> writes:
>
> > I think I can get where I want to go without completely figuring that out
> > right now though...
>
> What are you trying to do?

I've implemented the RSA PKCS #1 v2.1 public key cryptography standard
in C. Now I'm working on implementing these functions in PostgreSQL.
So, for example:

select * from generate_rsa_key();

would return a tuple of three very large integers: the modulus, the
public exponent, and the private exponent. (Truly secure applications
would do this operation on the client, and only export the public key
(modulus, public exponent) to the server - but that's another matter)

My first thought was to just do something like:

CREATE TYPE __full_key AS ( n bytea, e bytea, d bytea );

CREATE OR REPLACE FUNCTION
generate_rsa_key( )
RETURNS
__full_key
AS
'y_pgcrypto.so', 'y_pg_generate_rsa_keys'
LANGUAGE
C
STRICT
IMMUTABLE;

Instead, I think I'll create two new types: rsa_full_key (modulus, pub
exponent, priv exponent) and rsa_part_key (modulus, exponent), that will
use hex as input and output for the large integers, like:

n: 86161f738222dccb5b7fbb55cf8d7bf70bb71204408807427fb352ad8768f3a61124da267f9a9938b1ca5f16190c428ce0366eb841d11e99bdb93aabbf6caec42c3c0e7469fa6ebaaf12aa8b717049a753685095728ce48a4f557eaae7c00d9ff9f6f962251ebddd60f8886fde8f79f7d2fefe66d73418f7cacea079b87b204bb0cdcd3318c472222c1dcd79078fedf984cdf3f8d8feb1cba2ad034f8e1bade70d21683e1bc8baec4afc6d05fa29249a470dcba92792978268360c82fb6432d42bf50f897a1864bff7d4bdf8d86e079e37dfd282f5369f8b4674bcc4bf027cdd0ae7e88aabfee8965c7a23875ae4682a188985afb2a3cd5dcb658666cba31553
e: e12d05c431077bd41ceb79df72bad01c541ca602a8e4091efd74970490626348c21061f5d9b334844109021d6b513b0f3d245dd51fcef89a8c1c9d520d67d92e05def4bdd2d0ca08812f41f3440735ef372355b94ca72ae167cba47a04953785690cba8902f584f12f4195df2d121668b1879a27f8adab7c766d51817e7518a7fd6843e0ee5abad1e60a3968b5b54f13abbfb01c0190e01af51b7ca3d8db0ea221952138d842e376e48a47686af45c0df52caf8ad87d836cb5c26742ee95da3aafd2d0c2cf42d32a0b4f62be3cd5ecf3ff4d72cd9c977f37f09830e5ec3155c3d62a99b075fc80f21ed87744fe35833fc692dfa4bfea06f7fbe13729bbe16e17
d: 5e7501e60b6691280279689ada8a317a5c1a09ef8fab8362ea7d60f24dc36ff3c0e7d7eb0eb6266be7f854c6c59d4d76f34dc349d049a5c8980410b9fe793e94c766e7051db05d54742991649befd0a4587887d60be30a75e57ede3a2aeee9b014997ecceaaf8e00badaa2e3e106b6ab3c5e9fa1aaa8f566077f8bcf906580338b94cc4f357cc4ea1a9c3afe199e7f52c54b0514e081cc9467756aa16a6d75b38655ed80739173d99525ed05c8cef5015b1d7a2e89358ab64e335a107e5efe57d7d9644107f062243d681af084fffcbcfc84e3b13c202de98c96e0c0fdea1990d2a4e993d138dd229ee23f90536f69d1de0bafcc2cc372552eda08d74e7b0287

I know how to create a user-defined type in C, which is probably the
better solution anyway; but I was initially thinking I'd just have a
keygen function that output a tuple containing the integers as bytea
values. I'm getting tripped trying to do that though.

--
Ron Peterson
https://www.yellowbank.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2007-10-13 18:26:02 Re: convert binary string to datum
Previous Message Gregory Stark 2007-10-13 17:44:33 Re: convert binary string to datum