70{
73
74
76
81
85
86
92 const char *fp =
NULL;
95 unsigned int block;
99
100
103
105 elog(
ERROR,
"null value for password rejected");
106
108 elog(
ERROR,
"null value for salt rejected");
109
110
111
112
114 elog(
ERROR,
"insufficient result buffer size to encrypt password");
115
116
119
120
123
124
125
126
127
130
131
132
133
134
135
136
141
142
143
144
145
149 errmsg(
"invalid format of salt"),
150 errhint(
"magic byte format for shacrypt is either \"$5$\" or \"$6$\""));
151
152
153
154
155
156
157
159 {
162 }
164 {
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
186 {
190
194 errmsg(
"could not parse salt options"));
195
197
198
199
200
201
202
203
204
205
206
207
208
210 {
213 errmsg(
"rounds=%d exceeds maximum supported value (%d), using %d instead",
217 }
219 {
222 errmsg(
"rounds=%d is below supported value (%d), using %d instead",
226 }
227
230 }
231
232
233
234
235
237 {
239 {
240
244
248
249
251
253 break;
254 }
255
257 {
258
262
266
268
270 break;
271 }
272
274 elog(
ERROR,
"unknown crypt identifier \"%c\"", salt[1]);
275 }
276
279
280
281
282
283
284
285
286
287
288
289
290
291
292
296 {
297
298
299
300
301
302
303
304
305
306
309 elog(
ERROR,
"bogus magic byte found in salt string");
310
313 elog(
ERROR,
"bogus magic byte found in salt string");
314
315
316
317
318
321 elog(
ERROR,
"invalid rounds option specified in salt string");
322
324 {
327 else
330 errmsg(
"invalid character in salt string: \"%.*s\"",
332 }
333 else
334 {
335
336
337
338
339
340
341
342
343
345 break;
346 }
347 }
348
351 elog(
DEBUG1,
"using salt \"%s\", salt len = %d, rounds = %u",
353
354
355
356
357
359 elog(
ERROR,
"unexpected length of salt string");
360
361
362
363
364
365
368
369
370
371
372
373
374
375
380
381
382
383
386
387
388
389
390
392
393
394
395
396
397
398
399
400
402 while (block)
403 {
407
408
409 block >>= 1;
410 }
411
412
414
415
417
418
419
420
421
422 for (block =
len; block > 0; block--)
424
425
427
428
429
430
431
432
433
434
436 {
438 }
439
440
444
445
446
447
449
450
451
452
453
454
455 for (block = 16 +
sha_buf[0]; block > 0; block--)
457
458
459
460
462
463
464
465
466
467
468
469
470
471
474
478
479
481
482
483
484
485
486
487
488
489
490
491
492 for (block = 0; block <
rounds; block++)
493 {
494
495
496
497
499
500
502
503
504
505
506
510
511
512 if ((block % 3) != 0)
514
515
516 if ((block % 7) != 0)
518
519
520
521
522
526
527
529 }
530
533
536
539
542
543
545
546#define b64_from_24bit(B2, B1, B0, N) \
547 do { \
548 unsigned int w = ((B2) << 16) | ((B1) << 8) | (B0); \
549 int i = (N); \
550 while (i-- > 0) \
551 { \
552 appendStringInfoCharMacro(out_buf, _crypt_itoa64[w & 0x3f]); \
553 w >>= 6; \
554 } \
555 } while (0)
556
558 {
560 {
572
573 break;
574 }
575
577 {
600
601 break;
602 }
603
605
606 elog(
ERROR,
"unsupported digest length");
607 }
608
609
610
611
612
613
614
615
616
617
619
620
624
625
627
631
634
637
640 errmsg(
"cannot create encrypted password"));
642}
#define b64_from_24bit(B2, B1, B0, N)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
void * palloc0(Size size)
#define CHECK_FOR_INTERRUPTS()
int px_find_digest(const char *name, PX_MD **res)
#define PX_SHACRYPT_ROUNDS_MAX
#define PX_SHACRYPT_BUF_LEN
#define PX_SHACRYPT_ROUNDS_MIN
#define PX_SHACRYPT_DIGEST_MAX_LEN
#define PX_SHACRYPT_SALT_MAX_LEN
#define PX_SHACRYPT_ROUNDS_DEFAULT
void px_memset(void *ptr, int c, size_t len)
#define px_md_finish(md, buf)
#define px_md_update(md, data, dlen)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
void destroyStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
StringInfo makeStringInfoExt(int initsize)
void appendStringInfoString(StringInfo str, const char *s)
#define appendStringInfoCharMacro(str, ch)