File tree Expand file tree Collapse file tree 11 files changed +108
-47
lines changed
Expand file tree Collapse file tree 11 files changed +108
-47
lines changed Original file line number Diff line number Diff line change 11CREATE SCHEMA IF NOT EXISTS pgsodium;
22CREATE EXTENSION IF NOT EXISTS pgsodium WITH SCHEMA pgsodium;
3-
3+ s
44-- This is a demonstration user to show that the pgsodium_keyiduser
55-- role can be used to access only encrpytion functions by key_id,
66-- this role can never access raw encrpytion keys.
Original file line number Diff line number Diff line change 1- #! /bin/sh
1+ #! /bin/bash
22
3- # YOU MUST EDIT THIS FILE!!!
4-
5- # after editing this file below WITH YOUR KEY, remove the exit on the
6- # next line
7- exit
8-
9- # YOU MUST EDIT THIS FILE!!!
10- # DO NOT USE THIS TEST KEY CHECKED INTO GIT!!!
11-
12- # your secret key goes here
13- echo 130cdceb74d7174fcbffbcb4a3397f3551b990fed92e452279ea3922cf715a0a
14-
15- # YOU MUST EDIT THIS FILE!!!
16- # DO NOT USE THIS TEST KEY CHECKED INTO GIT!!!
3+ FILE=$( PGDATA) /pgsodium_root.key
174
5+ if [ ! -f " $FILE " ]; then
6+ head -c 32 /dev/urandom | hex > $FILE
7+ fi
8+ echo cat $FILE
Original file line number Diff line number Diff line change 11# pgsodium extension
22comment = 'Postgres extension for libsodium functions'
3- default_version = '1.2 .0'
3+ default_version = '1.3 .0'
44relocatable = true
55requires = ''
Original file line number Diff line number Diff line change 1+ CREATE FUNCTION crypto_secretstream_keygen ()
2+ RETURNS bytea
3+ AS ' $libdir/pgsodium' , ' pgsodium_crypto_secretstream_xchacha20poly1305_keygen'
4+ LANGUAGE C VOLATILE;
5+
Original file line number Diff line number Diff line change @@ -36,33 +36,3 @@ pgsodium_crypto_kdf_derive_from_key(PG_FUNCTION_ARGS)
3636 PG_RETURN_BYTEA_P (result );
3737}
3838
39- PG_FUNCTION_INFO_V1 (pgsodium_crypto_kx_keypair );
40- Datum
41- pgsodium_crypto_kx_keypair (PG_FUNCTION_ARGS )
42- {
43- TupleDesc tupdesc ;
44- Datum values [2 ];
45- bool nulls [2 ] = {false, false};
46- HeapTuple tuple ;
47- Datum result ;
48- bytea * publickey ;
49- bytea * secretkey ;
50- size_t public_size = crypto_kx_PUBLICKEYBYTES + VARHDRSZ ;
51- size_t secret_size = crypto_kx_SECRETKEYBYTES + VARHDRSZ ;
52- if (get_call_result_type (fcinfo , NULL , & tupdesc ) != TYPEFUNC_COMPOSITE )
53- ereport (ERROR ,
54- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
55- errmsg ("function returning record called in context "
56- "that cannot accept type record" )));
57- publickey = _pgsodium_zalloc_bytea (public_size );
58- secretkey = _pgsodium_zalloc_bytea (secret_size );
59- crypto_kx_keypair (
60- PGSODIUM_UCHARDATA (publickey ),
61- PGSODIUM_UCHARDATA (secretkey ));
62- values [0 ] = PointerGetDatum (publickey );
63- values [1 ] = PointerGetDatum (secretkey );
64- tuple = heap_form_tuple (tupdesc , values , nulls );
65- result = HeapTupleGetDatum (tuple );
66- return result ;
67- }
68-
Original file line number Diff line number Diff line change @@ -125,3 +125,32 @@ pgsodium_crypto_kx_server_session_keys(PG_FUNCTION_ARGS)
125125 return result ;
126126}
127127
128+ PG_FUNCTION_INFO_V1 (pgsodium_crypto_kx_keypair );
129+ Datum
130+ pgsodium_crypto_kx_keypair (PG_FUNCTION_ARGS )
131+ {
132+ TupleDesc tupdesc ;
133+ Datum values [2 ];
134+ bool nulls [2 ] = {false, false};
135+ HeapTuple tuple ;
136+ Datum result ;
137+ bytea * publickey ;
138+ bytea * secretkey ;
139+ size_t public_size = crypto_kx_PUBLICKEYBYTES + VARHDRSZ ;
140+ size_t secret_size = crypto_kx_SECRETKEYBYTES + VARHDRSZ ;
141+ if (get_call_result_type (fcinfo , NULL , & tupdesc ) != TYPEFUNC_COMPOSITE )
142+ ereport (ERROR ,
143+ (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
144+ errmsg ("function returning record called in context "
145+ "that cannot accept type record" )));
146+ publickey = _pgsodium_zalloc_bytea (public_size );
147+ secretkey = _pgsodium_zalloc_bytea (secret_size );
148+ crypto_kx_keypair (
149+ PGSODIUM_UCHARDATA (publickey ),
150+ PGSODIUM_UCHARDATA (secretkey ));
151+ values [0 ] = PointerGetDatum (publickey );
152+ values [1 ] = PointerGetDatum (secretkey );
153+ tuple = heap_form_tuple (tupdesc , values , nulls );
154+ result = HeapTupleGetDatum (tuple );
155+ return result ;
156+ }
Original file line number Diff line number Diff line change @@ -114,6 +114,10 @@ Datum pgsodium_crypto_auth_verify(PG_FUNCTION_ARGS);
114114Datum pgsodium_crypto_auth_by_id (PG_FUNCTION_ARGS );
115115Datum pgsodium_crypto_auth_verify_by_id (PG_FUNCTION_ARGS );
116116
117+ /* Secret streams */
118+
119+ Datum pgsodium_crypto_secretstream_xchacha20poly1305_keygen (PG_FUNCTION_ARGS );
120+
117121/* AEAD */
118122
119123Datum pgsodium_crypto_aead_ietf_keygen (PG_FUNCTION_ARGS );
@@ -194,4 +198,11 @@ Datum pgsodium_crypto_hash_sha512(PG_FUNCTION_ARGS);
194198
195199Datum pgsodium_derive (PG_FUNCTION_ARGS );
196200
201+ /* Streaming */
202+
203+ Datum pgsodium_crypto_stream_xchacha20_keygen (PG_FUNCTION_ARGS );
204+ Datum pgsodium_crypto_stream_xchacha20_noncegen (PG_FUNCTION_ARGS );
205+ Datum pgsodium_crypto_stream_xchacha20 (PG_FUNCTION_ARGS );
206+ Datum pgsodium_crypto_stream_xchacha20_xor (PG_FUNCTION_ARGS );
207+
197208#endif /* PGSODIUM_H */
Original file line number Diff line number Diff line change 1+
2+ #include "pgsodium.h"
3+
4+ PG_FUNCTION_INFO_V1 (pgsodium_crypto_secretstream_xchacha20poly1305_keygen );
5+ Datum
6+ pgsodium_crypto_secretstream_xchacha20poly1305_keygen (PG_FUNCTION_ARGS )
7+ {
8+ size_t result_size = VARHDRSZ + crypto_secretstream_xchacha20poly1305_KEYBYTES ;
9+ bytea * result = _pgsodium_zalloc_bytea (result_size );
10+ crypto_secretstream_xchacha20poly1305_keygen (PGSODIUM_UCHARDATA (result ));
11+ PG_RETURN_BYTEA_P (result );
12+ }
13+
Original file line number Diff line number Diff line change 1+
2+ #include "pgsodium.h"
3+
4+ PG_FUNCTION_INFO_V1 (pgsodium_crypto_stream_xchacha20_keygen );
5+ Datum
6+ pgsodium_crypto_stream_xchacha20_keygen (PG_FUNCTION_ARGS )
7+ {
8+ size_t result_size = VARHDRSZ + crypto_stream_xchacha20_KEYBYTES ;
9+ bytea * result = _pgsodium_zalloc_bytea (result_size );
10+ crypto_stream_xchacha20_keygen (PGSODIUM_UCHARDATA (result ));
11+ PG_RETURN_BYTEA_P (result );
12+ }
13+
14+ PG_FUNCTION_INFO_V1 (pgsodium_crypto_stream_xchacha20_noncegen );
15+ Datum
16+ pgsodium_crypto_stream_xchacha20_noncegen (PG_FUNCTION_ARGS )
17+ {
18+ int result_size = VARHDRSZ + crypto_stream_xchacha20_NONCEBYTES ;
19+ bytea * result = _pgsodium_zalloc_bytea (result_size );
20+ randombytes_buf (VARDATA (result ), crypto_stream_xchacha20_NONCEBYTES );
21+ PG_RETURN_BYTEA_P (result );
22+ }
23+
24+ PG_FUNCTION_INFO_V1 (pgsodium_crypto_stream_xchacha20 );
25+ Datum
26+ pgsodium_crypto_stream_xchacha20 (PG_FUNCTION_ARGS )
27+ {
28+ }
29+
30+ PG_FUNCTION_INFO_V1_xor (pgsodium_crypto_stream_xchacha20 );
31+ Datum
32+ pgsodium_crypto_stream_xchacha20_xor (PG_FUNCTION_ARGS )
33+ {
34+ }
35+
Original file line number Diff line number Diff line change 1+ BEGIN ;
2+ SELECT plan(1 );
3+
4+ SELECT crypto_secretstream_keygen() streamkey \gset
5+
6+ ROLLBACK ;
You can’t perform that action at this time.
0 commit comments