Debian Codegraph @

contrib/pgcrypto/expected/crypt-shacrypt.out

raw
1 --
2 -- crypt() and gensalt: sha256crypt, sha512crypt
3 --
4 -- $5$ is sha256crypt
5 SELECT crypt('', '$5$Szzz0yzz');
6 crypt
7 ---------------------------------------------------------
8 $5$Szzz0yzz$cA.ZFZKqblRYjdsbrWtVTYa/qSwPQnt2uh0LBtyYAAD
9 (1 row)
10
11 SELECT crypt('foox', '$5$Szzz0yzz');
12 crypt
13 ---------------------------------------------------------
14 $5$Szzz0yzz$7hI0rUWkO2QdBkzamh.vP.MIPlbZiwSvu2smhSi6064
15 (1 row)
16
17 CREATE TABLE ctest (data text, res text, salt text);
18 INSERT INTO ctest VALUES ('password', '', '');
19 -- generate a salt for sha256crypt, default rounds
20 UPDATE ctest SET salt = gen_salt('sha256crypt');
21 UPDATE ctest SET res = crypt(data, salt);
22 SELECT res = crypt(data, res) AS "worked"
23 FROM ctest;
24 worked
25 --------
26 t
27 (1 row)
28
29 -- generate a salt for sha256crypt, rounds 9999
30 UPDATE ctest SET salt = gen_salt('sha256crypt', 9999);
31 UPDATE ctest SET res = crypt(data, salt);
32 SELECT res = crypt(data, res) AS "worked"
33 FROM ctest;
34 worked
35 --------
36 t
37 (1 row)
38
39 -- should fail, below supported minimum rounds value
40 UPDATE ctest SET salt = gen_salt('sha256crypt', 10);
41 ERROR: gen_salt: Incorrect number of rounds
42 -- should fail, exceeds supported maximum rounds value
43 UPDATE ctest SET salt = gen_salt('sha256crypt', 1000000000);
44 ERROR: gen_salt: Incorrect number of rounds
45 TRUNCATE ctest;
46 -- $6$ is sha512crypt
47 SELECT crypt('', '$6$Szzz0yzz');
48 crypt
49 ----------------------------------------------------------------------------------------------------
50 $6$Szzz0yzz$EGj.JLAovFyAtCJx3YD1DXD1yTXoO9gv4qgLyHBsJJ1lkpnLB8ZPHekm1qXjJCOBc/8thCuHpxNN8Y5xzRYU5.
51 (1 row)
52
53 SELECT crypt('foox', '$6$Szzz0yzz');
54 crypt
55 ----------------------------------------------------------------------------------------------------
56 $6$Szzz0yzz$KqDw1Y8kze.VFapkvTc9Y5fbqzltjeRz1aPGC/pkHRhFQZ2aM6PmZpXQjcD7AOH88Bq0CSD.VlmymQzcBMEUl0
57 (1 row)
58
59 INSERT INTO ctest VALUES ('password', '', '');
60 -- generate a salt for sha512crypt, default rounds
61 UPDATE ctest SET salt = gen_salt('sha512crypt');
62 UPDATE ctest SET res = crypt(data, salt);
63 SELECT res = crypt(data, res) AS "worked"
64 FROM ctest;
65 worked
66 --------
67 t
68 (1 row)
69
70 -- generate a salt for sha512crypt, rounds 9999
71 UPDATE ctest SET salt = gen_salt('sha512crypt', 9999);
72 UPDATE ctest SET res = crypt(data, salt);
73 SELECT res = crypt(data, res) AS "worked"
74 FROM ctest;
75 worked
76 --------
77 t
78 (1 row)
79
80 -- should fail, below supported minimum rounds value
81 UPDATE ctest SET salt = gen_salt('sha512crypt', 10);
82 ERROR: gen_salt: Incorrect number of rounds
83 -- should fail, exceeds supported maximum rounds value
84 UPDATE ctest SET salt = gen_salt('sha512crypt', 1000000000);
85 ERROR: gen_salt: Incorrect number of rounds
86 -- Extended tests taken from public domain code at
87 -- https://www.akkadia.org/drepper/SHA-crypt.txt
88 --
89 -- We adapt the tests defined there to make sure we are compatible with the reference
90 -- implementation.
91 -- This tests sha256crypt (magic byte $5$ with salt and rounds)
92 SELECT crypt('Hello world!', '$5$saltstring')
93 = '$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5' AS result;
94 result
95 --------
96 t
97 (1 row)
98
99 SELECT crypt('Hello world!', '$5$rounds=10000$saltstringsaltstring')
100 = '$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA' AS result;
101 result
102 --------
103 t
104 (1 row)
105
106 SELECT crypt('This is just a test', '$5$rounds=5000$toolongsaltstring')
107 = '$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5' AS result;
108 result
109 --------
110 t
111 (1 row)
112
113 SELECT crypt('a very much longer text to encrypt. This one even stretches over more'
114 'than one line.', '$5$rounds=1400$anotherlongsaltstring')
115 = '$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1' AS result;
116 result
117 --------
118 t
119 (1 row)
120
121 SELECT crypt('we have a short salt string but not a short password', '$5$rounds=77777$short')
122 = '$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/' AS result;
123 result
124 --------
125 t
126 (1 row)
127
128 SELECT crypt('a short string', '$5$rounds=123456$asaltof16chars..')
129 = '$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD' AS result;
130 result
131 --------
132 t
133 (1 row)
134
135 SELECT crypt('the minimum number is still observed', '$5$rounds=10$roundstoolow')
136 = '$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL972bIC' AS result;
137 NOTICE: rounds=10 is below supported value (1000), using 1000 instead
138 result
139 --------
140 t
141 (1 row)
142
143 -- The following tests sha512crypt (magic byte $6$ with salt and rounds)
144 SELECT crypt('Hello world!', '$6$saltstring')
145 = '$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1' AS result;
146 result
147 --------
148 t
149 (1 row)
150
151 SELECT crypt('Hello world!', '$6$rounds=10000$saltstringsaltstring')
152 = '$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sbHbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v.' AS result;
153 result
154 --------
155 t
156 (1 row)
157
158 SELECT crypt('This is just a test', '$6$rounds=5000$toolongsaltstring')
159 = '$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQzQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0' AS result;
160 result
161 --------
162 t
163 (1 row)
164
165 SELECT crypt('a very much longer text to encrypt. This one even stretches over more'
166 'than one line.', '$6$rounds=1400$anotherlongsaltstring')
167 = '$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1' AS result;
168 result
169 --------
170 t
171 (1 row)
172
173 SELECT crypt('we have a short salt string but not a short password', '$6$rounds=77777$short')
174 = '$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0gge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0' AS result;
175 result
176 --------
177 t
178 (1 row)
179
180 SELECT crypt('a short string', '$6$rounds=123456$asaltof16chars..')
181 = '$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1' AS result;
182 result
183 --------
184 t
185 (1 row)
186
187 SELECT crypt('the minimum number is still observed', '$6$rounds=10$roundstoolow')
188 = '$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1xhLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX.' AS result;
189 NOTICE: rounds=10 is below supported value (1000), using 1000 instead
190 result
191 --------
192 t
193 (1 row)
194
195 -- cleanup
196 DROP TABLE ctest;