forked from michelp/pgsodium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdf.sql
43 lines (32 loc) · 1.63 KB
/
kdf.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
BEGIN;
SELECT plan(7);
SELECT crypto_kdf_keygen() kdfkey \gset
SELECT length(crypto_kdf_derive_from_key(64, 1, '__auth__', :'kdfkey'::bytea)) kdfsubkeylen \gset
SELECT is(:kdfsubkeylen, 64, 'kdf byte derived subkey');
SELECT length(crypto_kdf_derive_from_key(32, 1, '__auth__', :'kdfkey'::bytea)) kdfsubkeylen \gset
SELECT is(:kdfsubkeylen, 32, 'kdf 32 byte derived subkey');
SELECT is(crypto_kdf_derive_from_key(32, 2, '__auth__', :'kdfkey'::bytea),
crypto_kdf_derive_from_key(32, 2, '__auth__', :'kdfkey'::bytea), 'kdf subkeys are deterministic.');
SELECT throws_ok($$SELECT crypto_kdf_derive_from_key(NULL, 2, '__aut__', 'bad'::bytea)$$,
'22000', 'pgsodium_crypto_kdf_derive_from_key: subkey size cannot be NULL',
'kdf null key size.');
SELECT throws_ok($$SELECT crypto_kdf_derive_from_key(32, NULL, '__aut__', 'bad'::bytea)$$,
'22000', 'pgsodium_crypto_kdf_derive_from_key: subkey id cannot be NULL',
'kdf null key size.');
SELECT throws_ok($$SELECT crypto_kdf_derive_from_key(32, 1, NULL, 'bad'::bytea)$$,
'22000', 'pgsodium_crypto_kdf_derive_from_key: subkey context cannot be NULL',
'kdf null key size.');
SELECT throws_ok($$SELECT crypto_kdf_derive_from_key(32, 1, '__aut__', NULL::bytea)$$,
'22000', 'pgsodium_crypto_kdf_derive_from_key: primary key cannot be NULL',
'kdf null key size.');
SELECT * FROM finish();
ROLLBACK;
\if :serverkeys
BEGIN;
SELECT plan(1);
select id as kdf_key_id from create_key('kdf') \gset
SELECT lives_ok(format($$select crypto_kdf_derive_from_key(32, 42, 'pgsodium', %L::uuid)$$, :'kdf_key_id'),
'crypto_kdf_derive_from_key by uuid');
SELECT * FROM finish();
ROLLBACK;
\endif