Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a8eb1a

Browse files
author
Neil Conway
committed
pgcrypto update:
* test error handling* add tests for des, 3des, cast5* add some tests to blowfish, rijndael* Makefile: ability to specify different tests for different crypto libraries, so we can skip des, 3des and cast5 for builtin.Marko Kreen
1 parent19b6768 commit6a8eb1a

File tree

13 files changed

+418
-1
lines changed

13 files changed

+418
-1
lines changed

‎contrib/pgcrypto/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# $PostgreSQL: pgsql/contrib/pgcrypto/Makefile,v 1.13 2005/03/21 05:17:16 neilc Exp $
2+
# $PostgreSQL: pgsql/contrib/pgcrypto/Makefile,v 1.14 2005/03/21 05:24:51 neilc Exp $
33
#
44

55
# either 'builtin', 'openssl'
@@ -26,12 +26,14 @@ ifeq ($(cryptolib), builtin)
2626
CRYPTO_CFLAGS =
2727
CRYPTO_LDFLAGS =
2828
SRCS = md5.c sha1.c internal.c blf.c rijndael.c
29+
EXTRA_TESTS =
2930
endif
3031

3132
ifeq ($(cryptolib), openssl)
3233
CRYPTO_CFLAGS = -I/usr/include/openssl
3334
CRYPTO_LDFLAGS = -lcrypto
3435
SRCS = openssl.c
36+
EXTRA_TESTS = des 3des cast5
3537
endif
3638

3739
ifeq ($(cryptsrc), builtin)
@@ -63,6 +65,7 @@ PG_CPPFLAGS= $(CRYPTO_CFLAGS) -I$(srcdir)
6365
SHLIB_LINK =$(CRYPTO_LDFLAGS)
6466

6567
REGRESS = init md5 sha1 hmac-md5 hmac-sha1 blowfish rijndael\
68+
$(EXTRA_TESTS)\
6669
crypt-des crypt-md5 crypt-blowfish crypt-xdes
6770

6871

‎contrib/pgcrypto/expected/3des.out

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--
2+
-- 3DES cipher
3+
--
4+
-- test vector from somewhere
5+
SELECT encode(encrypt(
6+
decode('80 00 00 00 00 00 00 00', 'hex'),
7+
decode('01 01 01 01 01 01 01 01
8+
01 01 01 01 01 01 01 01
9+
01 01 01 01 01 01 01 01', 'hex'),
10+
'3des-ecb/pad:none'), 'hex');
11+
encode
12+
------------------
13+
95f8a5e5dd31d900
14+
(1 row)
15+
16+
-- val 95 F8 A5 E5 DD 31 D9 00
17+
select encode(encrypt('', 'foo', '3des'), 'hex');
18+
encode
19+
------------------
20+
9b641a6936249eb4
21+
(1 row)
22+
23+
-- 10 bytes key
24+
select encode(encrypt('foo', '0123456789', '3des'), 'hex');
25+
encode
26+
------------------
27+
6f02b7076a366504
28+
(1 row)
29+
30+
-- 22 bytes key
31+
select encode(encrypt('foo', '0123456789012345678901', '3des'), 'hex');
32+
encode
33+
------------------
34+
a44360e699269817
35+
(1 row)
36+
37+
-- decrypt
38+
select decrypt(encrypt('foo', '0123456', '3des'), '0123456', '3des');
39+
decrypt
40+
---------
41+
foo
42+
(1 row)
43+
44+
-- iv
45+
select encode(encrypt_iv('foo', '0123456', 'abcd', '3des'), 'hex');
46+
encode
47+
------------------
48+
df27c264fb24ed7a
49+
(1 row)
50+
51+
select decrypt_iv(decode('df27c264fb24ed7a', 'hex'), '0123456', 'abcd', '3des');
52+
decrypt_iv
53+
------------
54+
foo
55+
(1 row)
56+

‎contrib/pgcrypto/expected/blowfish.out

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,55 @@ decode('37363534333231204e6f77206973207468652074696d6520666f722000', 'hex'),
106106
3ea6357a0ee7fad6d0c4b63464f2aafa40c2e91b4b7e1bba8114932fd92b5c8f111e7e50e7b2e541
107107
(1 row)
108108

109+
-- blowfish-448
110+
SELECT encode(encrypt(
111+
decode('fedcba9876543210', 'hex'),
112+
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff', 'hex'),
113+
'bf-ecb/pad:none'), 'hex');
114+
encode
115+
------------------
116+
c04504012e4e1f53
117+
(1 row)
118+
119+
-- result: c04504012e4e1f53
120+
-- empty data
121+
select encode(encrypt('', 'foo', 'bf'), 'hex');
122+
encode
123+
------------------
124+
1871949bb2311c8e
125+
(1 row)
126+
127+
-- 10 bytes key
128+
select encode(encrypt('foo', '0123456789', 'bf'), 'hex');
129+
encode
130+
------------------
131+
42f58af3b2c03f46
132+
(1 row)
133+
134+
-- 22 bytes key
135+
select encode(encrypt('foo', '0123456789012345678901', 'bf'), 'hex');
136+
encode
137+
------------------
138+
86ab6f0bc72b5f22
139+
(1 row)
140+
141+
-- decrypt
142+
select decrypt(encrypt('foo', '0123456', 'bf'), '0123456', 'bf');
143+
decrypt
144+
---------
145+
foo
146+
(1 row)
147+
148+
-- iv
149+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'bf'), 'hex');
150+
encode
151+
------------------
152+
95c7e89322525d59
153+
(1 row)
154+
155+
select decrypt_iv(decode('95c7e89322525d59', 'hex'), '0123456', 'abcd', 'bf');
156+
decrypt_iv
157+
------------
158+
foo
159+
(1 row)
160+

‎contrib/pgcrypto/expected/cast5.out

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--
2+
-- Cast5 cipher
3+
--
4+
-- test vectors from RFC2144
5+
-- 128 bit key
6+
SELECT encode(encrypt(
7+
decode('01 23 45 67 89 AB CD EF', 'hex'),
8+
decode('01 23 45 67 12 34 56 78 23 45 67 89 34 56 78 9A', 'hex'),
9+
'cast5-ecb/pad:none'), 'hex');
10+
encode
11+
------------------
12+
238b4fe5847e44b2
13+
(1 row)
14+
15+
-- result: 23 8B 4F E5 84 7E 44 B2
16+
-- 80 bit key
17+
SELECT encode(encrypt(
18+
decode('01 23 45 67 89 AB CD EF', 'hex'),
19+
decode('01 23 45 67 12 34 56 78 23 45', 'hex'),
20+
'cast5-ecb/pad:none'), 'hex');
21+
encode
22+
------------------
23+
eb6a711a2c02271b
24+
(1 row)
25+
26+
-- result: EB 6A 71 1A 2C 02 27 1B
27+
-- 40 bit key
28+
SELECT encode(encrypt(
29+
decode('01 23 45 67 89 AB CD EF', 'hex'),
30+
decode('01 23 45 67 12', 'hex'),
31+
'cast5-ecb/pad:none'), 'hex');
32+
encode
33+
------------------
34+
7ac816d16e9b302e
35+
(1 row)
36+
37+
-- result: 7A C8 16 D1 6E 9B 30 2E
38+
-- cbc
39+
-- empty data
40+
select encode(encrypt('', 'foo', 'cast5'), 'hex');
41+
encode
42+
------------------
43+
a48bd1aabde4de10
44+
(1 row)
45+
46+
-- 10 bytes key
47+
select encode(encrypt('foo', '0123456789', 'cast5'), 'hex');
48+
encode
49+
------------------
50+
b07f19255e60cb6d
51+
(1 row)
52+
53+
-- decrypt
54+
select decrypt(encrypt('foo', '0123456', 'cast5'), '0123456', 'cast5');
55+
decrypt
56+
---------
57+
foo
58+
(1 row)
59+
60+
-- iv
61+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'cast5'), 'hex');
62+
encode
63+
------------------
64+
384a970695ce016a
65+
(1 row)
66+
67+
select decrypt_iv(decode('384a970695ce016a', 'hex'),
68+
'0123456', 'abcd', 'cast5');
69+
decrypt_iv
70+
------------
71+
foo
72+
(1 row)
73+

‎contrib/pgcrypto/expected/des.out

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--
2+
-- DES cipher
3+
--
4+
-- no official test vectors atm
5+
-- from blowfish.sql
6+
SELECT encode(encrypt(
7+
decode('0123456789abcdef', 'hex'),
8+
decode('fedcba9876543210', 'hex'),
9+
'des-ecb/pad:none'), 'hex');
10+
encode
11+
------------------
12+
ed39d950fa74bcc4
13+
(1 row)
14+
15+
-- empty data
16+
select encode(encrypt('', 'foo', 'des'), 'hex');
17+
encode
18+
------------------
19+
752111e37a2d7ac3
20+
(1 row)
21+
22+
-- 8 bytes key
23+
select encode(encrypt('foo', '01234589', 'des'), 'hex');
24+
encode
25+
------------------
26+
dec0f9c602b647a8
27+
(1 row)
28+
29+
-- decrypt
30+
select decrypt(encrypt('foo', '0123456', 'des'), '0123456', 'des');
31+
decrypt
32+
---------
33+
foo
34+
(1 row)
35+
36+
-- iv
37+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'des'), 'hex');
38+
encode
39+
------------------
40+
50735067b073bb93
41+
(1 row)
42+
43+
select decrypt_iv(decode('50735067b073bb93', 'hex'), '0123456', 'abcd', 'des');
44+
decrypt_iv
45+
------------
46+
foo
47+
(1 row)
48+

‎contrib/pgcrypto/expected/init.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ SELECT decode('666f6f', 'hex');
1515
foo
1616
(1 row)
1717

18+
-- check error handling
19+
select gen_salt('foo');
20+
ERROR: gen_salt: Unknown salt algorithm
21+
select digest('foo', 'foo');
22+
ERROR: Cannot use "foo": No such hash algorithm
23+
select hmac('foo', 'foo', 'foo');
24+
ERROR: Cannot use "foo": No such hash algorithm
25+
select encrypt('foo', 'foo', 'foo');
26+
ERROR: Cannot use "foo": No such cipher algorithm

‎contrib/pgcrypto/expected/rijndael.out

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,45 @@ decode('000102030405060708090a0b0c0d0e0f101112131415161718191a1b', 'hex'),
6767
4facb6a041d53e0a5a73289170901fe7
6868
(1 row)
6969

70+
-- empty data
71+
select encode(encrypt('', 'foo', 'aes'), 'hex');
72+
encode
73+
----------------------------------
74+
b48cc3338a2eb293b6007ef72c360d48
75+
(1 row)
76+
77+
-- 10 bytes key
78+
select encode(encrypt('foo', '0123456789', 'aes'), 'hex');
79+
encode
80+
----------------------------------
81+
f397f03d2819b7172b68d0706fda4693
82+
(1 row)
83+
84+
-- 22 bytes key
85+
select encode(encrypt('foo', '0123456789012345678901', 'aes'), 'hex');
86+
encode
87+
----------------------------------
88+
5c9db77af02b4678117bcd8a71ae7f53
89+
(1 row)
90+
91+
-- decrypt
92+
select decrypt(encrypt('foo', '0123456', 'aes'), '0123456', 'aes');
93+
decrypt
94+
---------
95+
foo
96+
(1 row)
97+
98+
-- iv
99+
select encode(encrypt_iv('foo', '0123456', 'abcd', 'aes'), 'hex');
100+
encode
101+
----------------------------------
102+
2c24cb7da91d6d5699801268b0f5adad
103+
(1 row)
104+
105+
select decrypt_iv(decode('2c24cb7da91d6d5699801268b0f5adad', 'hex'),
106+
'0123456', 'abcd', 'aes');
107+
decrypt_iv
108+
------------
109+
foo
110+
(1 row)
111+

‎contrib/pgcrypto/sql/3des.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--
2+
-- 3DES cipher
3+
--
4+
5+
-- test vector from somewhere
6+
SELECT encode(encrypt(
7+
decode('80 00 00 00 00 00 00 00','hex'),
8+
decode('01 01 01 01 01 01 01 01
9+
01 01 01 01 01 01 01 01
10+
01 01 01 01 01 01 01 01','hex'),
11+
'3des-ecb/pad:none'),'hex');
12+
-- val 95 F8 A5 E5 DD 31 D9 00
13+
14+
select encode(encrypt('','foo','3des'),'hex');
15+
-- 10 bytes key
16+
select encode(encrypt('foo','0123456789','3des'),'hex');
17+
-- 22 bytes key
18+
select encode(encrypt('foo','0123456789012345678901','3des'),'hex');
19+
20+
-- decrypt
21+
select decrypt(encrypt('foo','0123456','3des'),'0123456','3des');
22+
23+
-- iv
24+
select encode(encrypt_iv('foo','0123456','abcd','3des'),'hex');
25+
select decrypt_iv(decode('df27c264fb24ed7a','hex'),'0123456','abcd','3des');
26+

‎contrib/pgcrypto/sql/blowfish.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,24 @@ decode('6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc', 'hex'
6464
decode('37363534333231204e6f77206973207468652074696d6520666f722000','hex'),
6565
'bf-cbc'),'hex');
6666

67+
-- blowfish-448
68+
SELECT encode(encrypt(
69+
decode('fedcba9876543210','hex'),
70+
decode('f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455667704689104c2fd3b2f584023641aba61761f1f1f1f0e0e0e0effffffffffffffff','hex'),
71+
'bf-ecb/pad:none'),'hex');
72+
-- result: c04504012e4e1f53
73+
74+
-- empty data
75+
select encode(encrypt('','foo','bf'),'hex');
76+
-- 10 bytes key
77+
select encode(encrypt('foo','0123456789','bf'),'hex');
78+
-- 22 bytes key
79+
select encode(encrypt('foo','0123456789012345678901','bf'),'hex');
80+
81+
-- decrypt
82+
select decrypt(encrypt('foo','0123456','bf'),'0123456','bf');
83+
84+
-- iv
85+
select encode(encrypt_iv('foo','0123456','abcd','bf'),'hex');
86+
select decrypt_iv(decode('95c7e89322525d59','hex'),'0123456','abcd','bf');
87+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp