PostgreSQL Source Code: contrib/pgcrypto/px-crypt.c Source File (original) (raw)

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

33

35#include "px.h"

36

37static char *

39 char *buf, unsigned len)

40{

41 char *res;

42

44 if (res == NULL || strlen(res) > len - 1)

45 return NULL;

46 strcpy(buf, res);

47 return buf;

48}

49

50static char *

52 char *buf, unsigned len)

53{

54 char *res;

55

57 return res;

58}

59

60static char *

62 char *buf, unsigned len)

63{

64 char *res;

65

67 return res;

68}

69

70static char *

72 char *buf, unsigned len)

73{

74 char *res;

75

77 return res;

78}

79

81{

84 char *(*crypt) (const char *psw, const char *salt,

85 char *buf, unsigned len);

86};

87

92 {"$2$", 3, NULL},

98 {NULL, 0, NULL}

99};

100

101char *

102px_crypt(const char *psw, const char *salt, char *buf, unsigned len)

103{

105

107

109 {

110 if (c->id_len)

111 break;

112 if (strncmp(salt, c->id, c->id_len) == 0)

113 break;

114 }

115

116 if (c->crypt == NULL)

117 return NULL;

118

119 return c->crypt(psw, salt, buf, len);

120}

121

122

123

124

125

127{

129 char *(*gen) (unsigned long count, const char *input, int size,

130 char *output, int output_size);

135};

136

142 {

146 },

147 {

151 },

152 {NULL, NULL, 0, 0, 0, 0}

153};

154

155int

157{

159 char *p;

160 char rbuf[16];

161

163

166 break;

167

168 if (g->name == NULL)

170

172 {

173 if (rounds == 0)

175

178 }

179

182

184 px_memset(rbuf, 0, sizeof(rbuf));

185

186 if (p == NULL)

188

189 return strlen(p);

190}

char * _crypt_blowfish_rn(const char *key, const char *setting, char *output, int size)

char * px_crypt_des(const char *key, const char *setting)

char * _crypt_gensalt_sha512_rn(unsigned long count, char const *input, int size, char *output, int output_size)

char * _crypt_gensalt_traditional_rn(unsigned long count, const char *input, int size, char *output, int output_size)

char * _crypt_gensalt_sha256_rn(unsigned long count, const char *input, int size, char *output, int output_size)

char * _crypt_gensalt_md5_rn(unsigned long count, const char *input, int size, char *output, int output_size)

char * _crypt_gensalt_blowfish_rn(unsigned long count, const char *input, int size, char *output, int output_size)

char * _crypt_gensalt_extended_rn(unsigned long count, const char *input, int size, char *output, int output_size)

char * px_crypt_md5(const char *pw, const char *salt, char *passwd, unsigned dstlen)

char * px_crypt_shacrypt(const char *pw, const char *salt, char *passwd, unsigned dstlen)

void CheckBuiltinCryptoMode(void)

bool pg_strong_random(void *buf, size_t len)

int pg_strcasecmp(const char *s1, const char *s2)

static char * run_crypt_des(const char *psw, const char *salt, char *buf, unsigned len)

int px_gen_salt(const char *salt_type, char *buf, int rounds)

static const struct px_crypt_algo px_crypt_list[]

static char * run_crypt_bf(const char *psw, const char *salt, char *buf, unsigned len)

static struct generator gen_list[]

char * px_crypt(const char *psw, const char *salt, char *buf, unsigned len)

static char * run_crypt_md5(const char *psw, const char *salt, char *buf, unsigned len)

static char * run_crypt_sha(const char *psw, const char *salt, char *buf, unsigned len)

#define PX_SHACRYPT_ROUNDS_MAX

#define PX_SHACRYPT_ROUNDS_MIN

#define PX_SHACRYPT_SALT_MAX_LEN

#define PX_SHACRYPT_ROUNDS_DEFAULT

void px_memset(void *ptr, int c, size_t len)

#define PXE_BAD_SALT_ROUNDS

#define PXE_UNKNOWN_SALT_ALGO

char *(* gen)(unsigned long count, const char *input, int size, char *output, int output_size)